common_service.go 185KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628
  1. package service
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. "XT_New/models"
  7. "github.com/jinzhu/gorm"
  8. )
  9. func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  10. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
  11. return inspection, err
  12. }
  13. func GetInspectionMinor(projectid int64, orgid int64) (inspection []*models.XtInspectionReference, err error) {
  14. err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1 and org_id = ?", projectid, orgid).Find(&inspection).Error
  15. return inspection, err
  16. }
  17. func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
  18. reference := models.XtInspectionReference{}
  19. err := XTReadDB().Model(&reference).Where("id=? and status = 1", id).Find(&reference).Error
  20. return reference, err
  21. }
  22. func GetItemid(id int64) (models.XtInspectionReference, error) {
  23. reference := models.XtInspectionReference{}
  24. err = XTReadDB().Model(&reference).Where("id = ? and status = 1", id).Find(&reference).Error
  25. return reference, err
  26. }
  27. func GetConfigurationById(major int64, moni int64, orgid int64) (*models.XtQualityControlStandard, error) {
  28. standard := models.XtQualityControlStandard{}
  29. err := XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).Find(&standard).Error
  30. if err == gorm.ErrRecordNotFound {
  31. return nil, err
  32. }
  33. if err != nil {
  34. return nil, err
  35. }
  36. return &standard, nil
  37. }
  38. func GetConfigurationByIdTwo(major int64, moni int64, orgid int64) (standard models.XtQualityControlStandard, err error) {
  39. err = XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).First(&standard).Error
  40. return standard, err
  41. }
  42. func SaveInspection(standard *models.XtQualityControlStandard) error {
  43. err := XTWriteDB().Create(&standard).Error
  44. return err
  45. }
  46. func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  47. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  48. if orgid > 0 {
  49. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  50. }
  51. table := XTReadDB().Table("xt_inspection_reference as s")
  52. fmt.Println(table)
  53. offset := (page - 1) * limit
  54. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").Count(&total).
  55. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
  56. return standard, total, err
  57. }
  58. func GetDefaultBloodPressure(orgid int64) (standard []*models.XtQualityControlStandard, err error) {
  59. err = XTReadDB().Model(&standard).Where("user_org_id = ? and status = 1 and is_status = 0", orgid).Find(&standard).Error
  60. return standard, err
  61. }
  62. func GetConfigurationListTwo(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  63. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  64. if orgid > 0 {
  65. db = db.Where("x.user_org_id = ? and x.is_status =1", orgid)
  66. }
  67. table := XTReadDB().Table("xt_inspection_reference as s")
  68. fmt.Println(table)
  69. offset := (page - 1) * limit
  70. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,x.range_value,x.range_type,s.unit,s.project_name,s.item_name,x.is_status").
  71. Joins("left join xt_inspection_reference as s on s.item_id = x.inspection_minor and s.project_id = x.inspection_major").Where("s.org_id = ? and s.status = 1", orgid).Count(&total).Offset(offset).Limit(limit).Scan(&standard).Error
  72. return standard, total, err
  73. }
  74. func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
  75. standard := models.XtQualityControlStandard{}
  76. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  77. return standard, err
  78. }
  79. func GetIdByItemId(itemid int64, orgid int64) (models.XtInspectionReference, error) {
  80. reference := models.XtInspectionReference{}
  81. err := XTReadDB().Model(&reference).Where("item_id = ? and org_id = ?", itemid, orgid).Find(&reference).Error
  82. return reference, err
  83. }
  84. func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
  85. err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
  86. return standard, err
  87. }
  88. func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
  89. err := XTWriteDB().Model(&st).Where("id = ?", id).Updates(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "range_value": st.RangeValue, "range_type": st.RangeType, "updated_time": time.Now().Unix()}).Error
  90. return err
  91. }
  92. func DeleteConfiguration(id int64) (err error) {
  93. err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  94. return err
  95. }
  96. func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
  97. diseases := models.XtInspectionReference{}
  98. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  99. if err == gorm.ErrRecordNotFound {
  100. return nil, err
  101. }
  102. if err != nil {
  103. return nil, err
  104. }
  105. return &diseases, nil
  106. }
  107. func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
  108. err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
  109. return reference, err
  110. }
  111. func GetInspectionMajorById(marjor int64, orgid int64) (*models.XtCheckConfiguration, error) {
  112. configuration := models.XtCheckConfiguration{}
  113. err := XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).Find(&configuration).Error
  114. if err == gorm.ErrRecordNotFound {
  115. return nil, err
  116. }
  117. if err != nil {
  118. return nil, err
  119. }
  120. return &configuration, nil
  121. }
  122. func GetInspectionMajorByIdTwo(marjor int64, orgid int64) (configuration models.XtCheckConfiguration, err error) {
  123. err = XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).First(&configuration).Error
  124. return configuration, err
  125. }
  126. func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
  127. err := XTWriteDB().Create(&configuration).Error
  128. return err
  129. }
  130. func GetAllChekcListTwo(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  131. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  132. table := XTReadDB().Table("xt_inspection_reference as r")
  133. fmt.Println(table)
  134. if orgid > 0 {
  135. db = db.Where("x.user_org_id = ?", orgid)
  136. }
  137. offset := (page - 1) * limit
  138. err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
  139. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
  140. return check, total, err
  141. }
  142. func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  143. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  144. table := XTReadDB().Table("xt_inspection_reference as r")
  145. fmt.Println(table)
  146. if orgid > 0 {
  147. db = db.Where("x.user_org_id = ?", orgid)
  148. }
  149. offset := (page - 1) * limit
  150. err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
  151. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Where("r.org_id = ? and r.status = 1", orgid).Offset(offset).Limit(limit).Scan(&check).Error
  152. return check, total, err
  153. }
  154. func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
  155. configuration := models.XtCheckConfiguration{}
  156. err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
  157. return configuration, err
  158. }
  159. func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
  160. err := XTWriteDB().Model(&con).Where("id=?", id).Updates(map[string]interface{}{"inspection_major": con.InspectionMajor, "inspection_frequency": con.InspectionFrequency, "sort": con.Sort, "updated_time": time.Now().Unix()}).Error
  161. return err
  162. }
  163. func DeleteCheck(id int64) error {
  164. err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  165. return err
  166. }
  167. //
  168. //func GetDialysiTotal(startime int64, endtime int64, orgid int64,lapsetotype int64,sourcetype int64) (order []*models.DialysisOrder, total int64, err error) {
  169. // err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
  170. // return order, total, err
  171. //}
  172. func GetDialysiTotal(startime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (models.PatientPrescriptionCountStruct, error) {
  173. counts := models.PatientPrescriptionCountStruct{}
  174. db := XTReadDB().Table("xt_dialysis_order as x").Select("count(x.id) as count").Joins("Join xt_dialysis_prescription as prescription On x.dialysis_date = prescription.record_date AND x.patient_id = prescription.patient_id AND prescription.status = 1 AND prescription.mode_id > 0").Where("x.dialysis_date >= ? and x.dialysis_date<=? and x.user_org_id = ? AND x.status = 1", startime, endtime, orgid)
  175. if lapsetotype > 0 {
  176. err = db.Where("x.user_org_id = ? and s.lapseto = ?", startime, endtime, orgid, lapsetotype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  177. }
  178. if lapsetotype == 0 {
  179. err = db.Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  180. }
  181. if sourcetype > 0 {
  182. err = db.Where("x.user_org_id = ? and s.source = ?", startime, endtime, orgid, sourcetype).Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  183. }
  184. if sourcetype == 0 {
  185. err = db.Joins("left join xt_patients as s on s.id= x.patient_id").Scan(&counts).Error
  186. }
  187. return counts, err
  188. }
  189. func GetDialysisCountMode(starttime int64, endtime int64, orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
  190. db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1")
  191. if starttime > 0 {
  192. db = db.Where("o.dialysis_date >=?", starttime)
  193. }
  194. if endtime > 0 {
  195. db = db.Where("o.dialysis_date<=?", endtime)
  196. }
  197. if orgid > 0 {
  198. db = db.Where("o.user_org_id = ?", orgid)
  199. }
  200. if lapsetotype > 0 {
  201. db = db.Where("p.lapseto = ?", lapsetotype)
  202. }
  203. if sourcetype > 0 {
  204. db = db.Where("p.source = ?", sourcetype)
  205. }
  206. err = db.Select("s.mode_id,count(s.mode_id) as count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.status= 1 AND s.record_date >= ? AND s.record_date <= ? AND s.mode_id > 0 ", starttime, endtime).Joins("left join xt_patients as p on o.patient_id = p.id").Group("s.mode_id").Scan(&counts).Error
  207. return counts, err
  208. }
  209. func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
  210. db := readDb.Table("xt_patient_lapseto as x").Where("x.status = 1")
  211. table := readDb.Table("xt_dialysis_order as s")
  212. fmt.Println(table)
  213. err = db.Select("x.patient_id,x.lapseto_type").Joins("left join xt_dialysis_order as s on s.patient_id = x.patient_id").Where("x.lapseto_time >=? and x.lapseto_time <= ? and x.lapseto_type = 2 and s.user_org_id = ?", starttime, endtime, orgid).Group("x.patient_id").Count(&total).Scan(&counts).Error
  214. return counts, total, err
  215. }
  216. func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
  217. db := XTReadDB().Table("xt_patients as x")
  218. if sourcetype == 0 {
  219. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
  220. }
  221. if sourcetype > 0 {
  222. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 1 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
  223. }
  224. return patients, err
  225. }
  226. func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, err error) {
  227. db := XTReadDB().Table("xt_patients as x")
  228. if sourcetype == 0 {
  229. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1", startime, endtime, orgid).Scan(&patients).Error
  230. }
  231. if sourcetype > 0 {
  232. err = db.Raw("select x.id,x.`name`,s.lapseto_type,s.lapseto_time from xt_patients as x left join xt_patient_lapseto AS s ON s.patient_id = x.id where s.lapseto_time >=? and s.lapseto_time <=? and x.user_org_id = ? and s.lapseto_type = 2 and x.status = 1 and x.source = ?", startime, endtime, orgid, sourcetype).Scan(&patients).Error
  233. }
  234. return patients, err
  235. }
  236. func GetPatientTotalCount(orgID int64, lapsetotype int64, sourcetype int64) (total int64) {
  237. db := readDb.Table("xt_patients as x")
  238. //if lapsetotype > 0 {
  239. // db = db.Where("x.lapseto = ?", lapsetotype)
  240. //}
  241. //if sourcetype > 0 {
  242. // db = db.Where("x.source = ?", sourcetype)
  243. //}
  244. db.Where("x.user_org_id=? and x.status=1", orgID).Count(&total)
  245. return
  246. }
  247. func GetPatientTotalCountTwo(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.XtDialysisOrder, total int64, err error) {
  248. err = XTReadDB().Model(&dialysisorder).Group("patient_id").Where("user_org_id = ? and dialysis_date >= ? and dialysis_date <=? and status =1", orgid, starttime, endtime).Count(&total).Find(&dialysisorder).Error
  249. return dialysisorder, total, err
  250. }
  251. func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.SgjDialysisOrder, total int64, err error) {
  252. db := XTReadDB().Table("xt_dialysis_order as s").Where("s.status = 1")
  253. table := XTReadDB().Table("xt_patients as x")
  254. fmt.Println("table", table)
  255. err = db.Select("s.dialysis_date,s.prescription_id").Joins("left join xt_patients as x on x.id = s.patient_id").Where("s.dialysis_date>=? and s.dialysis_date<=? and s.user_org_id = ? and s.status = 1 and x.gender = 1", starttime, endtime, orgid).Group("s.patient_id").Count(&total).Scan(&dialysisorder).Error
  256. return dialysisorder, total, err
  257. }
  258. func GetManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
  259. db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
  260. if lapsetotype > 0 {
  261. db = db.Where("x.lapseto = ?", lapsetotype)
  262. }
  263. if sourcetype > 0 {
  264. db = db.Where("x.source = ?", sourcetype)
  265. }
  266. err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 1", orgid).Count(&total).Find(&patients).Error
  267. return patients, total, err
  268. }
  269. func GetWoManPatientTotal(orgid int64, lapsetotype int64, sourcetype int64) (patients []*models.XtPatients, total int64, err error) {
  270. db := XTReadDB().Table("xt_patients as x").Where("x.status = 1")
  271. if lapsetotype > 0 {
  272. db = db.Where("x.lapseto = ?", lapsetotype)
  273. }
  274. if sourcetype > 0 {
  275. db = db.Where("x.source = ?", sourcetype)
  276. }
  277. err = db.Where("x.user_org_id = ? and x.status = 1 and x.gender = 2", orgid).Count(&total).Find(&patients).Error
  278. return patients, total, err
  279. }
  280. //func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  281. // err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_dialysis_order as o on o.patient_id = x.patient_id").Joins("join xt_patients as s on s.id = x.patient_id").Where("o.user_org_id = ? and o.status =1 and o.dialysis_date>=? and o.dialysis_date <=? and x.status =1 and s.is_infectious = 2", orgid, starttime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  282. // return counts, err
  283. //}
  284. func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientContagionsCountStruct, err error) {
  285. if lapsetotype == 0 {
  286. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  287. }
  288. if sourcetype == 0 {
  289. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  290. }
  291. if lapsetotype > 0 {
  292. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.lapseto = ?", orgid, startime, endtime, lapsetotype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  293. }
  294. if sourcetype > 0 {
  295. err = readDb.Table("xt_patients_infectious_diseases as x").Joins("join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.status = 1 and x.status = 1 and x.updated_time>=? and x.updated_time<=? and s.source = ?", orgid, startime, endtime, sourcetype).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  296. }
  297. return counts, err
  298. }
  299. func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  300. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and is_infectious = 1", orgid).Count(&total).Find(&patients).Error
  301. return patients, total, err
  302. }
  303. func GetTotalAgeCount(orgid int64, lapsetotype int64, sourcetype int64) (counts []*models.PatientAgeCountStruct, err error) {
  304. if lapsetotype == 0 || sourcetype == 0 {
  305. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  306. SELECT
  307. CASE
  308. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  309. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  310. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  311. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  312. ELSE '150'
  313. END
  314. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1
  315. )a GROUP BY nnd`, orgid).Scan(&counts)
  316. }
  317. if lapsetotype > 0 {
  318. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  319. SELECT
  320. CASE
  321. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  322. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  323. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  324. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  325. ELSE '150'
  326. END
  327. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.lapseto = ?
  328. )a GROUP BY nnd`, orgid, lapsetotype).Scan(&counts)
  329. }
  330. if sourcetype > 0 {
  331. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  332. SELECT
  333. CASE
  334. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=20 THEN '20'
  335. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=40 THEN '40'
  336. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=60 THEN '60'
  337. WHEN ( substring( now( ), 1, 4 ) - substring( id_card_no, 7, 4 ) ) - ( substring( id_card_no, 11, 4 ) - date_format( now( ), '%m%d' ) > 0 )<=80 THEN '80'
  338. ELSE '150'
  339. END
  340. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1 and s.source = ?
  341. )a GROUP BY nnd`, orgid, sourcetype).Scan(&counts)
  342. }
  343. return
  344. }
  345. func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
  346. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  347. SELECT
  348. CASE
  349. when (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')>0) and (substring(now(),1,4)-substring(id_card_no,7,4))-(substring(id_card_no,11,4)-date_format(now(),'%m%d')<20) THEN '20'
  350. END
  351. AS nnd FROM xt_patients as s left join xt_dialysis_order as o on o.patient_id = s.id where s.user_org_id=? and s.status=1 and o.dialysis_date>= ? and o.dialysis_date<=?
  352. )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
  353. return
  354. }
  355. func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err error) {
  356. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  357. return patients, err
  358. }
  359. func GetDialysisAgeData(orgID int64, lapsetotype int64, sourcetype int64) (counts []*models.DialysisAgePieDataStruct, err error) {
  360. if lapsetotype == 0 || sourcetype == 0 {
  361. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  362. SELECT
  363. CASE
  364. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  365. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  366. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  367. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  368. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0)a GROUP BY nnd`, orgID).Scan(&counts)
  369. }
  370. if lapsetotype > 0 {
  371. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  372. SELECT
  373. CASE
  374. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  375. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  376. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  377. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  378. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.lapseto = ?)a GROUP BY nnd`, orgID, lapsetotype).Scan(&counts)
  379. }
  380. if sourcetype > 0 {
  381. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  382. SELECT
  383. CASE
  384. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '1'
  385. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '2'
  386. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36 AND TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '3'
  387. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  388. END AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1 and p.first_dialysis_date <> 0 and p.source = ?)a GROUP BY nnd`, orgID, sourcetype).Scan(&counts)
  389. }
  390. return
  391. }
  392. func GetCurentOrgPatients(orgid int64) (patients []*models.BloodXtPatients, err error) {
  393. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Order("created_time desc").Find(&patients).Error
  394. return patients, err
  395. }
  396. func TotalDialysisCount(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  397. db := XTReadDB().Table("xt_dialysis_order as o")
  398. err = db.Raw("select count(o.id) as count,o.patient_id from xt_dialysis_order as o left join xt_schedule AS x ON x.patient_id = o.patient_id where o.status = 1 and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and x.schedule_date = o.dialysis_date and x.status = 1", startime, endtime, orgid).Group("o.patient_id").Scan(&order).Error
  399. return order, err
  400. }
  401. func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  402. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  403. if orgid > 0 {
  404. db = db.Where("o.user_org_id = ?", orgid)
  405. }
  406. if startime > 0 {
  407. db = db.Where("o.dialysis_date>=?", startime)
  408. }
  409. if endtime > 0 {
  410. db = db.Where("o.dialysis_date<=?", endtime)
  411. }
  412. offset := (page - 1) * limit
  413. err = db.Group("s.patient_id,s.mode_id").Select("s.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0").Joins("join xt_patients as p on p.id = o.patient_id").Where("s.status = 1").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  414. return order, total, err
  415. }
  416. func GetDialysisScheduleList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrderSchedule, err error) {
  417. db := XTReadDB().Table("xt_schedule as o").Where("o.status = 1")
  418. if orgid > 0 {
  419. db = db.Where("o.user_org_id = ?", orgid)
  420. }
  421. if startime > 0 {
  422. db = db.Where("o.schedule_date>=?", startime)
  423. }
  424. if endtime > 0 {
  425. db = db.Where("o.schedule_date<=?", endtime)
  426. }
  427. err = db.Group("o.patient_id,o.mode_id").Select("o.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_patients as p on p.id = o.patient_id").Where("o.status = 1").Scan(&order).Error
  428. return order, err
  429. }
  430. func GetAllDialysisList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrder, err error) {
  431. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  432. if orgid > 0 {
  433. db = db.Where("o.user_org_id = ?", orgid)
  434. }
  435. if startime > 0 {
  436. db = db.Where("o.dialysis_date>=?", startime)
  437. }
  438. if endtime > 0 {
  439. db = db.Where("o.dialysis_date<=?", endtime)
  440. }
  441. err = db.Group("s.patient_id,s.mode_id").Select("s.mode_id,s.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0").Joins("join xt_patients as p on p.id = o.patient_id").Where("s.status = 1 ").Scan(&order).Error
  442. return order, err
  443. }
  444. func GetDialysisPatientList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  445. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  446. db = db.Where("o.user_org_id = ?", orgid)
  447. if startime > 0 {
  448. db = db.Where("o.dialysis_date>=?", startime)
  449. }
  450. if endtime > 0 {
  451. db = db.Where("o.dialysis_date<=?", endtime)
  452. }
  453. offset := (page - 1) * limit
  454. err = db.Group("s.patient_id").Select("s.mode_id,o.patient_id,p.name,p.id_card_no,p.dialysis_no,p.total_dialysis,p.user_sys_before_count").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0 AND s.status =1").Joins("join xt_patients as p on p.id = o.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  455. return order, total, err
  456. }
  457. func GetLastSort(orgid int64) (models.XtQualityControlStandard, error) {
  458. standard := models.XtQualityControlStandard{}
  459. err := XTReadDB().Model(&standard).Where("user_org_id = ? and status =1 and is_status = 1", orgid).Last(&standard).Error
  460. return standard, err
  461. }
  462. func GetLastCheckList(orgid int64) (models.XtCheckConfiguration, error) {
  463. configuration := models.XtCheckConfiguration{}
  464. err := XTReadDB().Model(&configuration).Where("user_org_id = ? and status =1", orgid).Last(&configuration).Error
  465. return configuration, err
  466. }
  467. func GetDialysisDetailById(id int64, orgid int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  468. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  469. table := XTReadDB().Table("xt_patients as s")
  470. fmt.Println(table)
  471. if id > 0 {
  472. db = db.Where("p.patient_id = ?", id)
  473. }
  474. if orgid > 0 {
  475. db = db.Where("p.user_org_id = ?", orgid)
  476. }
  477. if startime > 0 {
  478. db = db.Where("p.record_date >= ?", startime)
  479. }
  480. if endtime > 0 {
  481. db = db.Where("p.record_date <=?", endtime)
  482. }
  483. offset := (page - 1) * limit
  484. err = db.Group("p.mode_id").Select("p.mode_id,p.patient_id,s.name,s.id_card_no,s.dialysis_no,s.total_dialysis,s.user_sys_before_count").Joins("left join xt_patients as s on s.id = p.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&prescription).Error
  485. return prescription, total, err
  486. }
  487. func GetPrescritionByName(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  488. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  489. table := XTReadDB().Table("xt_patients as s")
  490. fmt.Println(table)
  491. //if len(keywords) > 0 {
  492. // likeKey := "%" + keywords + "%"
  493. // db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  494. //}
  495. if patient_id > 0 {
  496. db = db.Where("s.id = ?", patient_id)
  497. }
  498. if orgid > 0 {
  499. db = db.Where("p.user_org_id = ?", orgid)
  500. }
  501. if startime > 0 {
  502. db = db.Where("p.record_date >= ?", startime)
  503. }
  504. if endtime > 0 {
  505. db = db.Where("p.record_date <=?", endtime)
  506. }
  507. offset := (page - 1) * limit
  508. err = db.Group("p.mode_id").Select("p.mode_id,p.patient_id,s.name,s.id_card_no,s.dialysis_no,s.total_dialysis,s.user_sys_before_count").Joins("left join xt_patients as s on s.id = p.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&prescription).Error
  509. return prescription, total, err
  510. }
  511. func GetTreateInfo(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64) (blood []*models.TreatDialysisOrder, total int64, err error) {
  512. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  513. sql := "from_unixtime(o.dialysis_date, '%Y%m%d') AS date"
  514. if orgID > 0 {
  515. db = db.Where("o.user_org_id = ?", orgID)
  516. }
  517. if startime > 0 {
  518. db = db.Where("o.dialysis_date >=?", startime)
  519. }
  520. if endtime > 0 {
  521. db = db.Where("o.dialysis_date<=?", endtime)
  522. }
  523. if lapseto == 0 {
  524. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  525. }
  526. if lapseto > 0 {
  527. db = db.Where("p.lapseto = ?", lapseto)
  528. }
  529. err = db.Group("o.dialysis_date").Select(sql).Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id AND s.record_date = o.dialysis_date AND s.mode_id > 0").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.record_date = o.dialysis_date and s.status =1").Scan(&blood).Error
  530. return blood, total, err
  531. }
  532. func GetTreatList(orgid int64, startime int64, endtime int64, lapseto int64) (ttd []*models.TreatTotalStruct, err error) {
  533. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1 ")
  534. p := XTReadDB().Table("xt_patients as p")
  535. fmt.Println(p)
  536. if orgid > 0 {
  537. db = db.Where("o.user_org_id = ?", orgid)
  538. }
  539. if startime > 0 {
  540. db = db.Where("o.dialysis_date>=?", startime)
  541. }
  542. if endtime > 0 {
  543. db = db.Where("o.dialysis_date<=?", endtime)
  544. }
  545. //if lapseto == 0 {
  546. // db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  547. //}
  548. if lapseto > 0 {
  549. db = db.Where("p.lapseto = ?", lapseto)
  550. }
  551. err = db.Select("s.mode_id, count(s.mode_id) as number").Joins("join xt_dialysis_prescription as s on s.patient_id = o.patient_id and s.record_date = o.dialysis_date and s.mode_id > 0").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.record_date = o.dialysis_date and s.status = 1").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  552. return ttd, err
  553. }
  554. func GetStatistics(orgID int64, startime int64, endtime int64, modeID int64) (dtd []*DialysisTotalDataStruct, ttd []*DialysisTotalDataStruct, err error) {
  555. db := readDb
  556. sql := "s.mode_id,from_unixtime(o.dialysis_date, '%Y%m%d') as date, count(o.dialysis_date) as number"
  557. datesql := " o.dialysis_date as date"
  558. group := "from_unixtime(o.dialysis_date, '%Y%m%d')"
  559. db = db.Table(" xt_dialysis_order AS o").Joins("join xt_dialysis_prescription as s on o.patient_id = s.patient_id AND o.dialysis_date = s.record_date AND s.mode_id > 0")
  560. if orgID > 0 {
  561. db = db.Where("o.user_org_id = ?", orgID)
  562. }
  563. if modeID > 0 {
  564. db = db.Where("s.mode_id=?", modeID)
  565. }
  566. if startime > 0 {
  567. db = db.Where("o.dialysis_date>=?", startime)
  568. }
  569. if endtime > 0 {
  570. db = db.Where("o.dialysis_date<=?", endtime)
  571. }
  572. db = db.Where("o.status=1")
  573. err = db.Select("s.mode_id, count(s.mode_id) as number").Order("s.mode_id asc").Find(&ttd).Error
  574. if err != nil {
  575. return
  576. }
  577. var ds []*DialysisTotalDataStruct
  578. err = db.Select(datesql).Group(group).Find(&ds).Error
  579. if err != nil {
  580. return
  581. }
  582. dates := make([]string, 0)
  583. if len(ds) > 0 {
  584. for _, d := range ds {
  585. dates = append(dates, d.Date)
  586. }
  587. db = db.Where("o.dialysis_date IN (?)", dates)
  588. }
  589. err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, s.mode_id").Find(&dtd).Error
  590. return
  591. }
  592. func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfiguration, err error) {
  593. var count int
  594. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status = 1")
  595. table := XTReadDB().Table("xt_inspection_reference as s")
  596. if orgid > 0 {
  597. db = db.Where("x.user_org_id = ?", orgid)
  598. }
  599. fmt.Println(table)
  600. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,s.project_name").Joins("left join xt_inspection_reference as s on s.project_id = x.inspection_major").Count(&count).Order("x.sort asc").Scan(&configuration).Error
  601. return configuration, err
  602. }
  603. func GetInspectionProjectCount(orgid int64, startime int64, endtime int64, patientid int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  604. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  605. table := XTReadDB().Table("xt_inspection_reference as r")
  606. fmt.Println(table)
  607. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  608. fmt.Println(d)
  609. if orgid > 0 {
  610. db = db.Where("x.org_id = ?", orgid)
  611. }
  612. if startime > 0 {
  613. db = db.Where("x.inspect_date >=?", startime)
  614. }
  615. if endtime > 0 {
  616. db = db.Where("x.inspect_date <=?", endtime)
  617. }
  618. if patientid > 0 {
  619. db = db.Where("x.patient_id = ?", patientid)
  620. }
  621. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("x.project_id,x.patient_id").Scan(&projectCounts).Error
  622. return
  623. }
  624. func GetInspectionDetailById(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  625. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  626. table := XTReadDB().Table("xt_inspection_reference as r")
  627. fmt.Println(table)
  628. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  629. fmt.Println(d)
  630. if id > 0 {
  631. db = db.Where("x.patient_id=?", id)
  632. }
  633. if orgid > 0 {
  634. db = db.Where("x.org_id = ?", orgid)
  635. }
  636. if startime > 0 {
  637. db = db.Where("x.inspect_date >=?", startime)
  638. }
  639. if endtime > 0 {
  640. db = db.Where("x.inspect_date <=?", endtime)
  641. }
  642. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency,t.sort").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  643. return
  644. }
  645. func GetSearchPatientInfo(orgid int64, keywords int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  646. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  647. table := XTReadDB().Table("xt_inspection_reference as r")
  648. fmt.Println(table)
  649. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  650. fmt.Println(d)
  651. p := XTReadDB().Table("xt_patients as p")
  652. fmt.Println(p)
  653. //if len(keywords) > 0 {
  654. // likeKey := "%" + keywords + "%"
  655. // db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
  656. //}
  657. if keywords > 0 {
  658. db = db.Where("x.patient_id = ?", keywords)
  659. }
  660. if orgid > 0 {
  661. db = db.Where("x.org_id = ?", orgid)
  662. }
  663. if startime > 0 {
  664. db = db.Where("x.inspect_date >=?", startime)
  665. }
  666. if endtime > 0 {
  667. db = db.Where("x.inspect_date <=?", endtime)
  668. }
  669. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,t.inspection_frequency").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as p on p.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  670. return
  671. }
  672. func GetMajorInspectionByOrgid(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  673. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  674. table := XTReadDB().Table("xt_inspection_reference ar r")
  675. fmt.Println(table)
  676. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
  677. return checkconfiguration, err
  678. }
  679. func GetDefaultByOrgId(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  680. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  681. table := XTReadDB().Table("xt_inspection_reference ar r")
  682. fmt.Println(table)
  683. err = db.Group("x.inspection_major").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Where("x.user_org_id = ?", orgid).Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Scan(&checkconfiguration).Error
  684. return checkconfiguration, err
  685. }
  686. func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.PatientsInspection, total int64, err error) {
  687. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  688. table := XTReadDB().Table("xt_patients as s")
  689. fmt.Println("table", table)
  690. if orgid > 0 {
  691. db = db.Where("x.org_id = ?", orgid)
  692. }
  693. if startime > 0 {
  694. db = db.Where("x.inspect_date >= ?", startime)
  695. }
  696. if endtime > 0 {
  697. db = db.Where("x.inspect_date <=?", endtime)
  698. }
  699. offset := (page - 1) * limit
  700. err = db.Group("x.patient_id").Select("x.id,x.patient_id,x.project_id,x.project_name,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  701. return inspection, total, err
  702. }
  703. func GetPatientListInfo(orgid int64, startime int64, endtime int64, limit int64, page int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  704. patients, _, err := GetPatientListData(orgid, startime, endtime, limit, page)
  705. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  706. table := XTReadDB().Table("xt_inspection_reference as r")
  707. fmt.Println(table)
  708. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  709. pa := XTReadDB().Table("xt_patients as s")
  710. fmt.Println(pa)
  711. fmt.Println(d)
  712. if orgid > 0 {
  713. db = db.Where("x.org_id = ?", orgid)
  714. }
  715. if startime > 0 {
  716. db = db.Where("x.inspect_date >=?", startime)
  717. }
  718. if endtime > 0 {
  719. db = db.Where("x.inspect_date <=?", endtime)
  720. }
  721. //if len(ds) > 0 {
  722. // for _, d := range ds {
  723. // dates = append(dates, d.Date)
  724. // }
  725. //
  726. // db = db.Where("o.dialysis_date IN (?)", dates)
  727. //
  728. ////}
  729. selectContent := "CASE"
  730. dates := make([]string, 0)
  731. for _, item := range patients {
  732. selectContent = selectContent + " WHEN x.patient_id =" + strconv.FormatInt(item.PatientId, 10) + " THEN " + "'" + item.Name + "'"
  733. dates = append(dates, strconv.FormatInt(item.PatientId, 10))
  734. }
  735. db = db.Where("x.patient_id in(?)", dates)
  736. err = db.Select(selectContent + "ELSE '未知' END AS name,count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("x.project_id,x.patient_id").Scan(&projectCounts).Error
  737. //err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  738. return
  739. }
  740. func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  741. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  742. if id > 0 {
  743. db = db.Where("s.id = ?", id)
  744. }
  745. if orgid > 0 {
  746. db = db.Where("x.org_id = ?", orgid)
  747. }
  748. if startime > 0 {
  749. db = db.Where("x.inspect_date >=?", startime)
  750. }
  751. if endtime > 0 {
  752. db = db.Where("x.inspect_date <=?", endtime)
  753. }
  754. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  755. return
  756. }
  757. func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  758. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  759. table := XTReadDB().Table("xt_inspection_reference as r")
  760. fmt.Println(table)
  761. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  762. pa := XTReadDB().Table("xt_patients as s")
  763. fmt.Println(pa)
  764. fmt.Println(d)
  765. if len(keywords) > 0 {
  766. likeKey := "%" + keywords + "%"
  767. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  768. }
  769. if orgid > 0 {
  770. db = db.Where("x.org_id = ?", orgid)
  771. }
  772. if startime > 0 {
  773. db = db.Where("x.inspect_date >=?", startime)
  774. }
  775. if endtime > 0 {
  776. db = db.Where("x.inspect_date <=?", endtime)
  777. }
  778. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,s.name").Joins("left join xt_check_configuration as t on t.inspection_major = x.project_id").Joins("left join xt_inspection_reference as r on r.project_id = x.project_id").Joins("left join xt_patients as s on s.id = x.patient_id").Group("project_id,patient_id").Scan(&projectCounts).Error
  779. return
  780. }
  781. func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
  782. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  783. if orgid > 0 {
  784. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  785. }
  786. table := XTReadDB().Table("xt_inspection_reference as s")
  787. fmt.Println(table)
  788. err = db.Order("x.sort asc,x.created_time asc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name,x.range_value,x.range_type,x.is_status").
  789. Joins("left join xt_inspection_reference as s on (s.item_id = x.inspection_minor AND s.org_id > 0) OR (s.id = x.inspection_minor AND s.org_id = 0)").Scan(&standard).Error
  790. return standard, err
  791. }
  792. func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
  793. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  794. if orgid >= 0 {
  795. db = db.Where("x.user_org_id = ? and x.is_status = 1", orgid)
  796. }
  797. table := XTReadDB().Table("xt_inspection_reference as s")
  798. fmt.Println(table)
  799. err = db.Order("x.sort asc,x.created_time asc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name").
  800. Joins("left join xt_inspection_reference as s on (s.item_id = x.inspection_minor AND s.org_id > 0) OR (s.id = x.inspection_minor AND s.org_id = 0)").Scan(&standard).Error
  801. return standard, err
  802. }
  803. func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  804. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  805. table := XTReadDB().Table("xt_inspection_reference as r")
  806. fmt.Println(table)
  807. if orgid > 0 {
  808. db = db.Where("x.org_id = ?", orgid)
  809. }
  810. if startime > 0 {
  811. db = db.Where("x.inspect_date >=?", startime)
  812. }
  813. if endtime > 0 {
  814. db = db.Where("x.inspect_date <=?", endtime)
  815. }
  816. err = db.Group("x.item_id").Select(" count(x.item_id ) AS count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
  817. return inspection, err
  818. }
  819. func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  820. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  821. table := XTReadDB().Table("xt_inspection_reference as r")
  822. fmt.Println(table)
  823. if orgid > 0 {
  824. db = db.Where("x.org_id = ?", orgid)
  825. }
  826. if startime > 0 {
  827. db = db.Where("x.inspect_date >=?", startime)
  828. }
  829. if endtime > 0 {
  830. db = db.Where("x.inspect_date <=?", endtime)
  831. }
  832. err = db.Group("x.item_id").Select("count(x.item_id) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_type,x.inspect_value,x.inspect_date,r.range_min,r.range_max").Where("x.inspect_value+0 >= r.range_min+0 and x.inspect_value+0 <= r.range_max+0").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Scan(&inspection).Error
  833. return inspection, err
  834. }
  835. func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  836. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  837. if orgid > 0 {
  838. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and r.range_type = 1 and q.user_org_id = ? and q.is_status = 1", orgid, orgid)
  839. }
  840. if startime > 0 {
  841. db = db.Where("x.inspect_date >=?", startime)
  842. }
  843. if endtime > 0 {
  844. db = db.Where("x.inspect_date <=?", endtime)
  845. }
  846. if lapseto > 0 && origin > 0 {
  847. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  848. }
  849. if lapseto > 0 && origin == 0 {
  850. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  851. }
  852. if lapseto == 0 && origin > 0 {
  853. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  854. }
  855. err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when x.inspect_value+0>=q.min_range+0 and x.inspect_value +0 <= q.large_range+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  856. return inspection, err
  857. }
  858. func GetQuarterTotalCountTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  859. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  860. q := XTReadDB().Table("x.xt_quality_control_standard as q")
  861. fmt.Println(q)
  862. if orgid > 0 {
  863. db = db.Where("x.org_id = ? and r.range_type = 2 and q.user_org_id = ? and q.is_status = 1 and x.inspect_value <>''", orgid, orgid)
  864. }
  865. if startime > 0 {
  866. db = db.Where("x.inspect_date >=?", startime)
  867. }
  868. if endtime > 0 {
  869. db = db.Where("x.inspect_date <=?", endtime)
  870. }
  871. if lapseto > 0 && origin > 0 {
  872. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  873. }
  874. if lapseto > 0 && origin == 0 {
  875. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  876. }
  877. if lapseto == 0 && origin > 0 {
  878. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  879. }
  880. err = db.Group("x.item_id").Select("sum(case when x.inspect_date >=? and x.inspect_date<=? then 1 else 0 end) as total,sum(case when q.range_value = x.inspect_value and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.item_id,q.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on ( r.item_id = x.item_id AND r.org_id > 0) OR ( x.item_id = r.id AND r.org_id = 0 ) ").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  881. return inspection, err
  882. }
  883. func GetProjectList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
  884. if lapseto == 0 {
  885. d := XTReadDB().Table("xt_patients as s")
  886. fmt.Println("d", d)
  887. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  888. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  889. "SELECT " +
  890. "CASE " +
  891. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  892. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  893. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  894. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  895. " ELSE '其他'" +
  896. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and x.inspect_value <> 0"
  897. countParams := make([]interface{}, 0)
  898. countParams = append(countParams, firststart)
  899. countParams = append(countParams, firstend)
  900. countParams = append(countParams, sencondstart)
  901. countParams = append(countParams, sencondend)
  902. countParams = append(countParams, threestart)
  903. countParams = append(countParams, threeend)
  904. countParams = append(countParams, fourstart)
  905. countParams = append(countParams, fourend)
  906. if orgid > 0 {
  907. db = db.Where("x.org_id=?", orgid)
  908. countSQL += " AND x.org_id=?"
  909. countParams = append(countParams, orgid)
  910. }
  911. if modetype > 0 {
  912. db = db.Where("x.item_id = ?", modetype)
  913. countSQL += " AND x.item_id=?"
  914. countParams = append(countParams, modetype)
  915. }
  916. if startime > 0 {
  917. db = db.Where("x.inspect_date >= ?", startime)
  918. countSQL += " AND x.inspect_date >=?"
  919. countParams = append(countParams, startime)
  920. }
  921. if endtime > 0 {
  922. db = db.Where("x.inspect_date <= ?", endtime)
  923. countSQL += " AND x.inspect_date <=?"
  924. countParams = append(countParams, endtime)
  925. }
  926. countSQL += ")a GROUP BY nnd"
  927. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  928. }
  929. if lapseto == 1 {
  930. d := XTReadDB().Table("xt_patients as s")
  931. fmt.Println("d", d)
  932. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  933. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  934. "SELECT " +
  935. "CASE " +
  936. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  937. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  938. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  939. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  940. "ELSE '其他'" +
  941. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  942. countParams := make([]interface{}, 0)
  943. countParams = append(countParams, firststart)
  944. countParams = append(countParams, firstend)
  945. countParams = append(countParams, sencondstart)
  946. countParams = append(countParams, sencondend)
  947. countParams = append(countParams, threestart)
  948. countParams = append(countParams, threeend)
  949. countParams = append(countParams, fourstart)
  950. countParams = append(countParams, fourend)
  951. if orgid > 0 {
  952. db = db.Where("x.org_id=?", orgid)
  953. countSQL += " AND x.org_id=?"
  954. countParams = append(countParams, orgid)
  955. }
  956. if modetype > 0 {
  957. db = db.Where("x.item_id = ?", modetype)
  958. countSQL += " AND x.item_id=?"
  959. countParams = append(countParams, modetype)
  960. }
  961. if startime > 0 {
  962. db = db.Where("x.inspect_date >= ?", startime)
  963. countSQL += " AND x.inspect_date >=?"
  964. countParams = append(countParams, startime)
  965. }
  966. if endtime > 0 {
  967. db = db.Where("x.inspect_date <= ?", endtime)
  968. countSQL += " AND x.inspect_date <=?"
  969. countParams = append(countParams, endtime)
  970. }
  971. countSQL += ")a GROUP BY nnd"
  972. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  973. }
  974. if lapseto == 2 {
  975. d := XTReadDB().Table("xt_patients as s")
  976. fmt.Println("d", d)
  977. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  978. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  979. "SELECT " +
  980. "CASE " +
  981. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  982. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  983. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  984. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  985. " ELSE '其他'" +
  986. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  987. countParams := make([]interface{}, 0)
  988. countParams = append(countParams, firststart)
  989. countParams = append(countParams, firstend)
  990. countParams = append(countParams, sencondstart)
  991. countParams = append(countParams, sencondend)
  992. countParams = append(countParams, threestart)
  993. countParams = append(countParams, threeend)
  994. countParams = append(countParams, fourstart)
  995. countParams = append(countParams, fourend)
  996. if orgid > 0 {
  997. db = db.Where("x.org_id=?", orgid)
  998. countSQL += " AND x.org_id=?"
  999. countParams = append(countParams, orgid)
  1000. }
  1001. if modetype > 0 {
  1002. db = db.Where("x.item_id = ?", modetype)
  1003. countSQL += " AND x.item_id=?"
  1004. countParams = append(countParams, modetype)
  1005. }
  1006. if startime > 0 {
  1007. db = db.Where("x.inspect_date >= ?", startime)
  1008. countSQL += " AND x.inspect_date >=?"
  1009. countParams = append(countParams, startime)
  1010. }
  1011. if endtime > 0 {
  1012. db = db.Where("x.inspect_date <= ?", endtime)
  1013. countSQL += " AND x.inspect_date <=?"
  1014. countParams = append(countParams, endtime)
  1015. }
  1016. countSQL += ")a GROUP BY nnd"
  1017. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1018. }
  1019. return
  1020. }
  1021. func GetProjectStandList(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
  1022. if lapseto == 0 {
  1023. d := XTReadDB().Table("xt_patients as s")
  1024. fmt.Println("d", d)
  1025. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  1026. table := XTReadDB().Table("xt_inspection_reference as r")
  1027. q := XTReadDB().Table("xt_quality_control_standard as r")
  1028. fmt.Println("q", q)
  1029. fmt.Println(table)
  1030. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1031. "SELECT " +
  1032. "CASE " +
  1033. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第一季度'" +
  1034. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第二季度'" +
  1035. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第三季度'" +
  1036. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第四季度'" +
  1037. " ELSE '其他'" +
  1038. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value + 0 >= r.min_range + 0 AND x.inspect_value + 0 <= r.large_range+0)"
  1039. countParams := make([]interface{}, 0)
  1040. countParams = append(countParams, firststart)
  1041. countParams = append(countParams, firstend)
  1042. countParams = append(countParams, sencondstart)
  1043. countParams = append(countParams, sencondend)
  1044. countParams = append(countParams, threestart)
  1045. countParams = append(countParams, threeend)
  1046. countParams = append(countParams, fourstart)
  1047. countParams = append(countParams, fourend)
  1048. if orgid > 0 {
  1049. db = db.Where("x.org_id=?", orgid)
  1050. countSQL += " AND x.org_id=?"
  1051. countParams = append(countParams, orgid)
  1052. }
  1053. if orgid > 0 {
  1054. db = db.Where("r.user_org_id=?", orgid)
  1055. countSQL += " AND r.user_org_id=?"
  1056. countParams = append(countParams, orgid)
  1057. }
  1058. if modetype > 0 {
  1059. db = db.Where("x.item_id = ?", modetype)
  1060. countSQL += " AND x.item_id=?"
  1061. countParams = append(countParams, modetype)
  1062. }
  1063. if startime > 0 {
  1064. db = db.Where("x.inspect_date >= ? ", startime)
  1065. countSQL += " AND x.inspect_date >=?"
  1066. countParams = append(countParams, startime)
  1067. }
  1068. if endtime > 0 {
  1069. db = db.Where("x.inspect_date <= ?", endtime)
  1070. countSQL += " AND x.inspect_date <=?"
  1071. countParams = append(countParams, endtime)
  1072. }
  1073. countSQL += ")a GROUP BY nnd"
  1074. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1075. }
  1076. if lapseto == 1 {
  1077. d := XTReadDB().Table("xt_patients as s")
  1078. fmt.Println("d", d)
  1079. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  1080. table := XTReadDB().Table("xt_inspection_reference as r")
  1081. q := XTReadDB().Table("xt_quality_control_standard as r")
  1082. fmt.Println("q", q)
  1083. fmt.Println(table)
  1084. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1085. "SELECT " +
  1086. "CASE " +
  1087. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第一季度'" +
  1088. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第二季度'" +
  1089. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第三季度'" +
  1090. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.min_range+0 and x.inspect_value +0 <= r.large_range+0 THEN '第四季度'" +
  1091. " ELSE '其他'" +
  1092. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value + 0 >= r.min_range + 0 AND x.inspect_value + 0 <= r.large_range+0)"
  1093. countParams := make([]interface{}, 0)
  1094. countParams = append(countParams, firststart)
  1095. countParams = append(countParams, firstend)
  1096. countParams = append(countParams, sencondstart)
  1097. countParams = append(countParams, sencondend)
  1098. countParams = append(countParams, threestart)
  1099. countParams = append(countParams, threeend)
  1100. countParams = append(countParams, fourstart)
  1101. countParams = append(countParams, fourend)
  1102. if orgid > 0 {
  1103. db = db.Where("x.org_id=?", orgid)
  1104. countSQL += " AND x.org_id=?"
  1105. countParams = append(countParams, orgid)
  1106. }
  1107. if orgid > 0 {
  1108. db = db.Where("r.user_org_id=?", orgid)
  1109. countSQL += " AND r.user_org_id=?"
  1110. countParams = append(countParams, orgid)
  1111. }
  1112. if modetype > 0 {
  1113. db = db.Where("x.item_id = ?", modetype)
  1114. countSQL += " AND x.item_id=?"
  1115. countParams = append(countParams, modetype)
  1116. }
  1117. if startime > 0 {
  1118. db = db.Where("x.inspect_date >= ? ", startime)
  1119. countSQL += " AND x.inspect_date >=?"
  1120. countParams = append(countParams, startime)
  1121. }
  1122. if endtime > 0 {
  1123. db = db.Where("x.inspect_date <= ?", endtime)
  1124. countSQL += " AND x.inspect_date <=?"
  1125. countParams = append(countParams, endtime)
  1126. }
  1127. countSQL += ")a GROUP BY nnd"
  1128. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1129. }
  1130. return
  1131. }
  1132. func GetProjectStandListOne(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCount, err error) {
  1133. if lapseto == 0 {
  1134. d := XTReadDB().Table("xt_patients as s")
  1135. fmt.Println("d", d)
  1136. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1137. table := XTReadDB().Table("xt_inspection_reference as r")
  1138. q := XTReadDB().Table("xt_quality_control_standard as r")
  1139. fmt.Println("q", q)
  1140. fmt.Println(table)
  1141. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1142. "SELECT " +
  1143. "CASE " +
  1144. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1145. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1146. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1147. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1148. " ELSE '其他'" +
  1149. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value = r.range_value) and r.status = 1"
  1150. countParams := make([]interface{}, 0)
  1151. countParams = append(countParams, firststart)
  1152. countParams = append(countParams, firstend)
  1153. countParams = append(countParams, sencondstart)
  1154. countParams = append(countParams, sencondend)
  1155. countParams = append(countParams, threestart)
  1156. countParams = append(countParams, threeend)
  1157. countParams = append(countParams, fourstart)
  1158. countParams = append(countParams, fourend)
  1159. if orgid > 0 {
  1160. db = db.Where("x.org_id=?", orgid)
  1161. countSQL += " AND x.org_id=?"
  1162. countParams = append(countParams, orgid)
  1163. }
  1164. if orgid > 0 {
  1165. db = db.Where("r.user_org_id=?", orgid)
  1166. countSQL += " AND r.user_org_id=?"
  1167. countParams = append(countParams, orgid)
  1168. }
  1169. if modetype > 0 {
  1170. db = db.Where("x.item_id = ?", modetype)
  1171. countSQL += " AND x.item_id=?"
  1172. countParams = append(countParams, modetype)
  1173. }
  1174. if startime > 0 {
  1175. db = db.Where("x.inspect_date >= ? ", startime)
  1176. countSQL += " AND x.inspect_date >=?"
  1177. countParams = append(countParams, startime)
  1178. }
  1179. if endtime > 0 {
  1180. db = db.Where("x.inspect_date <= ?", endtime)
  1181. countSQL += " AND x.inspect_date <=?"
  1182. countParams = append(countParams, endtime)
  1183. }
  1184. countSQL += ")a GROUP BY nnd"
  1185. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1186. }
  1187. if lapseto == 1 {
  1188. d := XTReadDB().Table("xt_patients as s")
  1189. fmt.Println("d", d)
  1190. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1191. table := XTReadDB().Table("xt_inspection_reference as r")
  1192. q := XTReadDB().Table("xt_quality_control_standard as r")
  1193. fmt.Println("q", q)
  1194. fmt.Println(table)
  1195. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1196. "SELECT " +
  1197. "CASE " +
  1198. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1199. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1200. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1201. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1202. " ELSE '其他'" +
  1203. "END AS nnd FROM xt_inspection as x left join xt_quality_control_standard as r on (r.inspection_minor = x.item_id AND r.user_org_id > 0) OR ( x.item_id = r.inspection_minor AND r.user_org_id = 0) left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value = r.range_value) and r.status = 1"
  1204. countParams := make([]interface{}, 0)
  1205. countParams = append(countParams, firststart)
  1206. countParams = append(countParams, firstend)
  1207. countParams = append(countParams, sencondstart)
  1208. countParams = append(countParams, sencondend)
  1209. countParams = append(countParams, threestart)
  1210. countParams = append(countParams, threeend)
  1211. countParams = append(countParams, fourstart)
  1212. countParams = append(countParams, fourend)
  1213. if orgid > 0 {
  1214. db = db.Where("x.org_id=?", orgid)
  1215. countSQL += " AND x.org_id=?"
  1216. countParams = append(countParams, orgid)
  1217. }
  1218. if orgid > 0 {
  1219. db = db.Where("r.user_org_id=?", orgid)
  1220. countSQL += " AND r.user_org_id=?"
  1221. countParams = append(countParams, orgid)
  1222. }
  1223. if modetype > 0 {
  1224. db = db.Where("x.item_id = ?", modetype)
  1225. countSQL += " AND x.item_id=?"
  1226. countParams = append(countParams, modetype)
  1227. }
  1228. if startime > 0 {
  1229. db = db.Where("x.inspect_date >= ? ", startime)
  1230. countSQL += " AND x.inspect_date >=?"
  1231. countParams = append(countParams, startime)
  1232. }
  1233. if endtime > 0 {
  1234. db = db.Where("x.inspect_date <= ?", endtime)
  1235. countSQL += " AND x.inspect_date <=?"
  1236. countParams = append(countParams, endtime)
  1237. }
  1238. countSQL += ")a GROUP BY nnd"
  1239. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1240. }
  1241. return
  1242. }
  1243. func GetMonthProjectList(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountOne, err error) {
  1244. if lapseto == 0 {
  1245. d := XTReadDB().Table("xt_patients as s")
  1246. fmt.Println("d", d)
  1247. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1")
  1248. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1249. "SELECT " +
  1250. "CASE " +
  1251. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1252. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1253. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1254. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1255. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1256. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1257. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1258. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1259. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1260. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1261. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1262. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1263. " ELSE '其他'" +
  1264. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1265. countParams := make([]interface{}, 0)
  1266. countParams = append(countParams, januaryStartStrUnix)
  1267. countParams = append(countParams, januaryEndStrUnix)
  1268. countParams = append(countParams, febStartStrStrUnix)
  1269. countParams = append(countParams, febEndStrUnix)
  1270. countParams = append(countParams, marchStartStrUnix)
  1271. countParams = append(countParams, marchEndStrUnix)
  1272. countParams = append(countParams, aprStartStrUnix)
  1273. countParams = append(countParams, aprEndStrsUnix)
  1274. countParams = append(countParams, mayStartStrUnix)
  1275. countParams = append(countParams, mayEndStrsUnix)
  1276. countParams = append(countParams, junStartStrUnix)
  1277. countParams = append(countParams, junEndStrsUnix)
  1278. countParams = append(countParams, julStartStrUnix)
  1279. countParams = append(countParams, julEndStrsUnix)
  1280. countParams = append(countParams, augStartStrUnix)
  1281. countParams = append(countParams, augEndStrsUnix)
  1282. countParams = append(countParams, sepStartStrUnix)
  1283. countParams = append(countParams, sepEndStrsUnix)
  1284. countParams = append(countParams, octStartStrUnix)
  1285. countParams = append(countParams, octEndStrsUnix)
  1286. countParams = append(countParams, novStartStrUnix)
  1287. countParams = append(countParams, novEndStrsUnix)
  1288. countParams = append(countParams, decStartStrUnix)
  1289. countParams = append(countParams, decEndStrsUnix)
  1290. if orgid > 0 {
  1291. db = db.Where("x.org_id=?", orgid)
  1292. countSQL += " AND x.org_id=?"
  1293. countParams = append(countParams, orgid)
  1294. }
  1295. if modetype > 0 {
  1296. db = db.Where("x.item_id = ?", modetype)
  1297. countSQL += " AND x.item_id=?"
  1298. countParams = append(countParams, modetype)
  1299. }
  1300. if januaryStartStrUnix > 0 {
  1301. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1302. countSQL += " AND x.inspect_date >=?"
  1303. countParams = append(countParams, januaryStartStrUnix)
  1304. }
  1305. if decEndStrsUnix > 0 {
  1306. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1307. countSQL += " AND x.inspect_date <=?"
  1308. countParams = append(countParams, decEndStrsUnix)
  1309. }
  1310. countSQL += ")a GROUP BY nnd"
  1311. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1312. }
  1313. if lapseto == 1 {
  1314. d := XTReadDB().Table("xt_patients as s")
  1315. fmt.Println("d", d)
  1316. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1 ")
  1317. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1318. "SELECT " +
  1319. "CASE " +
  1320. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1321. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1322. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1323. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1324. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1325. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1326. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1327. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1328. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1329. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1330. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1331. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1332. " ELSE '其他'" +
  1333. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  1334. countParams := make([]interface{}, 0)
  1335. countParams = append(countParams, januaryStartStrUnix)
  1336. countParams = append(countParams, januaryEndStrUnix)
  1337. countParams = append(countParams, febStartStrStrUnix)
  1338. countParams = append(countParams, febEndStrUnix)
  1339. countParams = append(countParams, marchStartStrUnix)
  1340. countParams = append(countParams, marchEndStrUnix)
  1341. countParams = append(countParams, aprStartStrUnix)
  1342. countParams = append(countParams, aprEndStrsUnix)
  1343. countParams = append(countParams, mayStartStrUnix)
  1344. countParams = append(countParams, mayEndStrsUnix)
  1345. countParams = append(countParams, junStartStrUnix)
  1346. countParams = append(countParams, junEndStrsUnix)
  1347. countParams = append(countParams, julStartStrUnix)
  1348. countParams = append(countParams, julEndStrsUnix)
  1349. countParams = append(countParams, augStartStrUnix)
  1350. countParams = append(countParams, augEndStrsUnix)
  1351. countParams = append(countParams, sepStartStrUnix)
  1352. countParams = append(countParams, sepEndStrsUnix)
  1353. countParams = append(countParams, octStartStrUnix)
  1354. countParams = append(countParams, octEndStrsUnix)
  1355. countParams = append(countParams, novStartStrUnix)
  1356. countParams = append(countParams, novEndStrsUnix)
  1357. countParams = append(countParams, decStartStrUnix)
  1358. countParams = append(countParams, decEndStrsUnix)
  1359. if orgid > 0 {
  1360. db = db.Where("x.org_id=?", orgid)
  1361. countSQL += " AND x.org_id=?"
  1362. countParams = append(countParams, orgid)
  1363. }
  1364. if modetype > 0 {
  1365. db = db.Where("x.item_id = ?", modetype)
  1366. countSQL += " AND x.item_id=?"
  1367. countParams = append(countParams, modetype)
  1368. }
  1369. if januaryStartStrUnix > 0 {
  1370. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1371. countSQL += " AND x.inspect_date >=?"
  1372. countParams = append(countParams, januaryStartStrUnix)
  1373. }
  1374. if decEndStrsUnix > 0 {
  1375. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1376. countSQL += " AND x.inspect_date <=?"
  1377. countParams = append(countParams, decEndStrsUnix)
  1378. }
  1379. countSQL += ")a GROUP BY nnd"
  1380. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1381. }
  1382. if lapseto == 2 {
  1383. d := XTReadDB().Table("xt_patients as s")
  1384. fmt.Println("d", d)
  1385. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_value <> 0 and x.inspect_type = 1")
  1386. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1387. "SELECT " +
  1388. "CASE " +
  1389. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1390. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1391. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1392. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1393. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1394. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1395. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1396. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1397. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1398. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1399. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1400. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1401. " ELSE '其他'" +
  1402. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1403. countParams := make([]interface{}, 0)
  1404. countParams = append(countParams, januaryStartStrUnix)
  1405. countParams = append(countParams, januaryEndStrUnix)
  1406. countParams = append(countParams, febStartStrStrUnix)
  1407. countParams = append(countParams, febEndStrUnix)
  1408. countParams = append(countParams, marchStartStrUnix)
  1409. countParams = append(countParams, marchEndStrUnix)
  1410. countParams = append(countParams, aprStartStrUnix)
  1411. countParams = append(countParams, aprEndStrsUnix)
  1412. countParams = append(countParams, mayStartStrUnix)
  1413. countParams = append(countParams, mayEndStrsUnix)
  1414. countParams = append(countParams, junStartStrUnix)
  1415. countParams = append(countParams, junEndStrsUnix)
  1416. countParams = append(countParams, julStartStrUnix)
  1417. countParams = append(countParams, julEndStrsUnix)
  1418. countParams = append(countParams, augStartStrUnix)
  1419. countParams = append(countParams, augEndStrsUnix)
  1420. countParams = append(countParams, sepStartStrUnix)
  1421. countParams = append(countParams, sepEndStrsUnix)
  1422. countParams = append(countParams, octStartStrUnix)
  1423. countParams = append(countParams, octEndStrsUnix)
  1424. countParams = append(countParams, novStartStrUnix)
  1425. countParams = append(countParams, novEndStrsUnix)
  1426. countParams = append(countParams, decStartStrUnix)
  1427. countParams = append(countParams, decEndStrsUnix)
  1428. if orgid > 0 {
  1429. db = db.Where("x.org_id=?", orgid)
  1430. countSQL += " AND x.org_id=?"
  1431. countParams = append(countParams, orgid)
  1432. }
  1433. if modetype > 0 {
  1434. db = db.Where("x.item_id = ?", modetype)
  1435. countSQL += " AND x.item_id=?"
  1436. countParams = append(countParams, modetype)
  1437. }
  1438. if januaryStartStrUnix > 0 {
  1439. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1440. countSQL += " AND x.inspect_date >=?"
  1441. countParams = append(countParams, januaryStartStrUnix)
  1442. }
  1443. if decEndStrsUnix > 0 {
  1444. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1445. countSQL += " AND x.inspect_date <=?"
  1446. countParams = append(countParams, decEndStrsUnix)
  1447. }
  1448. countSQL += ")a GROUP BY nnd"
  1449. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1450. }
  1451. return
  1452. }
  1453. func GetMonthProjectListOne(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountOne, err error) {
  1454. if lapseto == 0 {
  1455. d := XTReadDB().Table("xt_patients as s")
  1456. fmt.Println("d", d)
  1457. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1458. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1459. "SELECT " +
  1460. "CASE " +
  1461. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1462. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1463. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1464. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1465. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1466. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1467. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1468. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1469. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1470. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1471. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1472. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1473. " ELSE '其他'" +
  1474. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1475. countParams := make([]interface{}, 0)
  1476. countParams = append(countParams, januaryStartStrUnix)
  1477. countParams = append(countParams, januaryEndStrUnix)
  1478. countParams = append(countParams, febStartStrStrUnix)
  1479. countParams = append(countParams, febEndStrUnix)
  1480. countParams = append(countParams, marchStartStrUnix)
  1481. countParams = append(countParams, marchEndStrUnix)
  1482. countParams = append(countParams, aprStartStrUnix)
  1483. countParams = append(countParams, aprEndStrsUnix)
  1484. countParams = append(countParams, mayStartStrUnix)
  1485. countParams = append(countParams, mayEndStrsUnix)
  1486. countParams = append(countParams, junStartStrUnix)
  1487. countParams = append(countParams, junEndStrsUnix)
  1488. countParams = append(countParams, julStartStrUnix)
  1489. countParams = append(countParams, julEndStrsUnix)
  1490. countParams = append(countParams, augStartStrUnix)
  1491. countParams = append(countParams, augEndStrsUnix)
  1492. countParams = append(countParams, sepStartStrUnix)
  1493. countParams = append(countParams, sepEndStrsUnix)
  1494. countParams = append(countParams, octStartStrUnix)
  1495. countParams = append(countParams, octEndStrsUnix)
  1496. countParams = append(countParams, novStartStrUnix)
  1497. countParams = append(countParams, novEndStrsUnix)
  1498. countParams = append(countParams, decStartStrUnix)
  1499. countParams = append(countParams, decEndStrsUnix)
  1500. if orgid > 0 {
  1501. db = db.Where("x.org_id=?", orgid)
  1502. countSQL += " AND x.org_id=?"
  1503. countParams = append(countParams, orgid)
  1504. }
  1505. if modetype > 0 {
  1506. db = db.Where("x.item_id = ?", modetype)
  1507. countSQL += " AND x.item_id=?"
  1508. countParams = append(countParams, modetype)
  1509. }
  1510. if januaryStartStrUnix > 0 {
  1511. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1512. countSQL += " AND x.inspect_date >=?"
  1513. countParams = append(countParams, januaryStartStrUnix)
  1514. }
  1515. if decEndStrsUnix > 0 {
  1516. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1517. countSQL += " AND x.inspect_date <=?"
  1518. countParams = append(countParams, decEndStrsUnix)
  1519. }
  1520. countSQL += ")a GROUP BY nnd"
  1521. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1522. }
  1523. if lapseto == 1 {
  1524. d := XTReadDB().Table("xt_patients as s")
  1525. fmt.Println("d", d)
  1526. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and and x.inspect_type = 2")
  1527. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1528. "SELECT " +
  1529. "CASE " +
  1530. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1531. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1532. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1533. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1534. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1535. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1536. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1537. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1538. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1539. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1540. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1541. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1542. " ELSE '其他'" +
  1543. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1)"
  1544. countParams := make([]interface{}, 0)
  1545. countParams = append(countParams, januaryStartStrUnix)
  1546. countParams = append(countParams, januaryEndStrUnix)
  1547. countParams = append(countParams, febStartStrStrUnix)
  1548. countParams = append(countParams, febEndStrUnix)
  1549. countParams = append(countParams, marchStartStrUnix)
  1550. countParams = append(countParams, marchEndStrUnix)
  1551. countParams = append(countParams, aprStartStrUnix)
  1552. countParams = append(countParams, aprEndStrsUnix)
  1553. countParams = append(countParams, mayStartStrUnix)
  1554. countParams = append(countParams, mayEndStrsUnix)
  1555. countParams = append(countParams, junStartStrUnix)
  1556. countParams = append(countParams, junEndStrsUnix)
  1557. countParams = append(countParams, julStartStrUnix)
  1558. countParams = append(countParams, julEndStrsUnix)
  1559. countParams = append(countParams, augStartStrUnix)
  1560. countParams = append(countParams, augEndStrsUnix)
  1561. countParams = append(countParams, sepStartStrUnix)
  1562. countParams = append(countParams, sepEndStrsUnix)
  1563. countParams = append(countParams, octStartStrUnix)
  1564. countParams = append(countParams, octEndStrsUnix)
  1565. countParams = append(countParams, novStartStrUnix)
  1566. countParams = append(countParams, novEndStrsUnix)
  1567. countParams = append(countParams, decStartStrUnix)
  1568. countParams = append(countParams, decEndStrsUnix)
  1569. if orgid > 0 {
  1570. db = db.Where("x.org_id=?", orgid)
  1571. countSQL += " AND x.org_id=?"
  1572. countParams = append(countParams, orgid)
  1573. }
  1574. if modetype > 0 {
  1575. db = db.Where("x.item_id = ?", modetype)
  1576. countSQL += " AND x.item_id=?"
  1577. countParams = append(countParams, modetype)
  1578. }
  1579. if januaryStartStrUnix > 0 {
  1580. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1581. countSQL += " AND x.inspect_date >=?"
  1582. countParams = append(countParams, januaryStartStrUnix)
  1583. }
  1584. if decEndStrsUnix > 0 {
  1585. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1586. countSQL += " AND x.inspect_date <=?"
  1587. countParams = append(countParams, decEndStrsUnix)
  1588. }
  1589. countSQL += ")a GROUP BY nnd"
  1590. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1591. }
  1592. if lapseto == 2 {
  1593. d := XTReadDB().Table("xt_patients as s")
  1594. fmt.Println("d", d)
  1595. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1596. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1597. "SELECT " +
  1598. "CASE " +
  1599. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1600. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1601. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1602. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1603. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1604. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1605. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1606. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1607. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1608. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1609. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1610. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1611. " ELSE '其他'" +
  1612. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1613. countParams := make([]interface{}, 0)
  1614. countParams = append(countParams, januaryStartStrUnix)
  1615. countParams = append(countParams, januaryEndStrUnix)
  1616. countParams = append(countParams, febStartStrStrUnix)
  1617. countParams = append(countParams, febEndStrUnix)
  1618. countParams = append(countParams, marchStartStrUnix)
  1619. countParams = append(countParams, marchEndStrUnix)
  1620. countParams = append(countParams, aprStartStrUnix)
  1621. countParams = append(countParams, aprEndStrsUnix)
  1622. countParams = append(countParams, mayStartStrUnix)
  1623. countParams = append(countParams, mayEndStrsUnix)
  1624. countParams = append(countParams, junStartStrUnix)
  1625. countParams = append(countParams, junEndStrsUnix)
  1626. countParams = append(countParams, julStartStrUnix)
  1627. countParams = append(countParams, julEndStrsUnix)
  1628. countParams = append(countParams, augStartStrUnix)
  1629. countParams = append(countParams, augEndStrsUnix)
  1630. countParams = append(countParams, sepStartStrUnix)
  1631. countParams = append(countParams, sepEndStrsUnix)
  1632. countParams = append(countParams, octStartStrUnix)
  1633. countParams = append(countParams, octEndStrsUnix)
  1634. countParams = append(countParams, novStartStrUnix)
  1635. countParams = append(countParams, novEndStrsUnix)
  1636. countParams = append(countParams, decStartStrUnix)
  1637. countParams = append(countParams, decEndStrsUnix)
  1638. if orgid > 0 {
  1639. db = db.Where("x.org_id=?", orgid)
  1640. countSQL += " AND x.org_id=?"
  1641. countParams = append(countParams, orgid)
  1642. }
  1643. if modetype > 0 {
  1644. db = db.Where("x.item_id = ?", modetype)
  1645. countSQL += " AND x.item_id=?"
  1646. countParams = append(countParams, modetype)
  1647. }
  1648. if januaryStartStrUnix > 0 {
  1649. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1650. countSQL += " AND x.inspect_date >=?"
  1651. countParams = append(countParams, januaryStartStrUnix)
  1652. }
  1653. if decEndStrsUnix > 0 {
  1654. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1655. countSQL += " AND x.inspect_date <=?"
  1656. countParams = append(countParams, decEndStrsUnix)
  1657. }
  1658. countSQL += ")a GROUP BY nnd"
  1659. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1660. }
  1661. return
  1662. }
  1663. func GetProjectListOne(orgid int64, lapseto int64, modetype int64, startime int64, endtime int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountOne, err error) {
  1664. if lapseto == 0 {
  1665. d := XTReadDB().Table("xt_patients as s")
  1666. fmt.Println("d", d)
  1667. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1668. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1669. "SELECT " +
  1670. "CASE " +
  1671. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1672. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1673. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1674. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1675. " ELSE '其他'" +
  1676. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2)"
  1677. countParams := make([]interface{}, 0)
  1678. countParams = append(countParams, firststart)
  1679. countParams = append(countParams, firstend)
  1680. countParams = append(countParams, sencondstart)
  1681. countParams = append(countParams, sencondend)
  1682. countParams = append(countParams, threestart)
  1683. countParams = append(countParams, threeend)
  1684. countParams = append(countParams, fourstart)
  1685. countParams = append(countParams, fourend)
  1686. if orgid > 0 {
  1687. db = db.Where("x.org_id=?", orgid)
  1688. countSQL += " AND x.org_id=?"
  1689. countParams = append(countParams, orgid)
  1690. }
  1691. if modetype > 0 {
  1692. db = db.Where("x.item_id = ?", modetype)
  1693. countSQL += " AND x.item_id=?"
  1694. countParams = append(countParams, modetype)
  1695. }
  1696. if startime > 0 {
  1697. db = db.Where("x.inspect_date >= ?", startime)
  1698. countSQL += " AND x.inspect_date >=?"
  1699. countParams = append(countParams, startime)
  1700. }
  1701. if endtime > 0 {
  1702. db = db.Where("x.inspect_date <= ?", endtime)
  1703. countSQL += " AND x.inspect_date <=?"
  1704. countParams = append(countParams, endtime)
  1705. }
  1706. countSQL += ")a GROUP BY nnd"
  1707. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1708. }
  1709. if lapseto == 1 {
  1710. d := XTReadDB().Table("xt_patients as s")
  1711. fmt.Println("d", d)
  1712. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1713. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1714. "SELECT " +
  1715. "CASE " +
  1716. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1717. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1718. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1719. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1720. " ELSE '其他'" +
  1721. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1722. countParams := make([]interface{}, 0)
  1723. countParams = append(countParams, firststart)
  1724. countParams = append(countParams, firstend)
  1725. countParams = append(countParams, sencondstart)
  1726. countParams = append(countParams, sencondend)
  1727. countParams = append(countParams, threestart)
  1728. countParams = append(countParams, threeend)
  1729. countParams = append(countParams, fourstart)
  1730. countParams = append(countParams, fourend)
  1731. if orgid > 0 {
  1732. db = db.Where("x.org_id=?", orgid)
  1733. countSQL += " AND x.org_id=?"
  1734. countParams = append(countParams, orgid)
  1735. }
  1736. if modetype > 0 {
  1737. db = db.Where("x.item_id = ?", modetype)
  1738. countSQL += " AND x.item_id=?"
  1739. countParams = append(countParams, modetype)
  1740. }
  1741. if startime > 0 {
  1742. db = db.Where("x.inspect_date >= ?", startime)
  1743. countSQL += " AND x.inspect_date >=?"
  1744. countParams = append(countParams, startime)
  1745. }
  1746. if endtime > 0 {
  1747. db = db.Where("x.inspect_date <= ?", endtime)
  1748. countSQL += " AND x.inspect_date <=?"
  1749. countParams = append(countParams, endtime)
  1750. }
  1751. countSQL += ")a GROUP BY nnd"
  1752. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1753. }
  1754. if lapseto == 2 {
  1755. d := XTReadDB().Table("xt_patients as s")
  1756. fmt.Println("d", d)
  1757. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1758. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1759. "SELECT " +
  1760. "CASE " +
  1761. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1762. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1763. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1764. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1765. " ELSE '其他'" +
  1766. "END AS nnd FROM xt_inspection as x left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2)"
  1767. countParams := make([]interface{}, 0)
  1768. countParams = append(countParams, firststart)
  1769. countParams = append(countParams, firstend)
  1770. countParams = append(countParams, sencondstart)
  1771. countParams = append(countParams, sencondend)
  1772. countParams = append(countParams, threestart)
  1773. countParams = append(countParams, threeend)
  1774. countParams = append(countParams, fourstart)
  1775. countParams = append(countParams, fourend)
  1776. if orgid > 0 {
  1777. db = db.Where("x.org_id=?", orgid)
  1778. countSQL += " AND x.org_id=?"
  1779. countParams = append(countParams, orgid)
  1780. }
  1781. if modetype > 0 {
  1782. db = db.Where("x.item_id = ?", modetype)
  1783. countSQL += " AND x.item_id=?"
  1784. countParams = append(countParams, modetype)
  1785. }
  1786. if startime > 0 {
  1787. db = db.Where("x.inspect_date >= ?", startime)
  1788. countSQL += " AND x.inspect_date >=?"
  1789. countParams = append(countParams, startime)
  1790. }
  1791. if endtime > 0 {
  1792. db = db.Where("x.inspect_date <= ?", endtime)
  1793. countSQL += " AND x.inspect_date <=?"
  1794. countParams = append(countParams, endtime)
  1795. }
  1796. countSQL += ")a GROUP BY nnd"
  1797. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1798. }
  1799. return
  1800. }
  1801. func GetMonthProjectListTwo(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
  1802. if lapseto == 0 {
  1803. d := XTReadDB().Table("xt_patients as s")
  1804. fmt.Println("d", d)
  1805. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1806. table := XTReadDB().Table("xt_quality_control_standard as r")
  1807. fmt.Println(table)
  1808. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1809. "SELECT " +
  1810. "CASE " +
  1811. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1812. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1813. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1814. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1815. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1816. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1817. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1818. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1819. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1820. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1821. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1822. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1823. " ELSE '其他'" +
  1824. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1825. countParams := make([]interface{}, 0)
  1826. countParams = append(countParams, januaryStartStrUnix)
  1827. countParams = append(countParams, januaryEndStrUnix)
  1828. countParams = append(countParams, febStartStrStrUnix)
  1829. countParams = append(countParams, febEndStrUnix)
  1830. countParams = append(countParams, marchStartStrUnix)
  1831. countParams = append(countParams, marchEndStrUnix)
  1832. countParams = append(countParams, aprStartStrUnix)
  1833. countParams = append(countParams, aprEndStrsUnix)
  1834. countParams = append(countParams, mayStartStrUnix)
  1835. countParams = append(countParams, mayEndStrsUnix)
  1836. countParams = append(countParams, junStartStrUnix)
  1837. countParams = append(countParams, junEndStrsUnix)
  1838. countParams = append(countParams, julStartStrUnix)
  1839. countParams = append(countParams, julEndStrsUnix)
  1840. countParams = append(countParams, augStartStrUnix)
  1841. countParams = append(countParams, augEndStrsUnix)
  1842. countParams = append(countParams, sepStartStrUnix)
  1843. countParams = append(countParams, sepEndStrsUnix)
  1844. countParams = append(countParams, octStartStrUnix)
  1845. countParams = append(countParams, octEndStrsUnix)
  1846. countParams = append(countParams, novStartStrUnix)
  1847. countParams = append(countParams, novEndStrsUnix)
  1848. countParams = append(countParams, decStartStrUnix)
  1849. countParams = append(countParams, decEndStrsUnix)
  1850. if orgid > 0 {
  1851. db = db.Where("x.org_id=?", orgid)
  1852. countSQL += " AND x.org_id=?"
  1853. countParams = append(countParams, orgid)
  1854. }
  1855. if orgid > 0 {
  1856. db = db.Where("r.user_org_id=?", orgid)
  1857. countSQL += " AND r.user_org_id=?"
  1858. countParams = append(countParams, orgid)
  1859. }
  1860. if modetype > 0 {
  1861. db = db.Where("x.item_id = ?", modetype)
  1862. countSQL += " AND x.item_id=?"
  1863. countParams = append(countParams, modetype)
  1864. }
  1865. if januaryStartStrUnix > 0 {
  1866. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1867. countSQL += " AND x.inspect_date >=?"
  1868. countParams = append(countParams, januaryStartStrUnix)
  1869. }
  1870. if decEndStrsUnix > 0 {
  1871. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1872. countSQL += " AND x.inspect_date <=?"
  1873. countParams = append(countParams, decEndStrsUnix)
  1874. }
  1875. countSQL += ")a GROUP BY nnd"
  1876. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1877. }
  1878. if lapseto == 1 {
  1879. d := XTReadDB().Table("xt_patients as s")
  1880. fmt.Println("d", d)
  1881. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1882. table := XTReadDB().Table("xt_quality_control_standard as r")
  1883. fmt.Println(table)
  1884. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1885. "SELECT " +
  1886. "CASE " +
  1887. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1888. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1889. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1890. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1891. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1892. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1893. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1894. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1895. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1896. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1897. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1898. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1899. " ELSE '其他'" +
  1900. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1901. countParams := make([]interface{}, 0)
  1902. countParams = append(countParams, januaryStartStrUnix)
  1903. countParams = append(countParams, januaryEndStrUnix)
  1904. countParams = append(countParams, febStartStrStrUnix)
  1905. countParams = append(countParams, febEndStrUnix)
  1906. countParams = append(countParams, marchStartStrUnix)
  1907. countParams = append(countParams, marchEndStrUnix)
  1908. countParams = append(countParams, aprStartStrUnix)
  1909. countParams = append(countParams, aprEndStrsUnix)
  1910. countParams = append(countParams, mayStartStrUnix)
  1911. countParams = append(countParams, mayEndStrsUnix)
  1912. countParams = append(countParams, junStartStrUnix)
  1913. countParams = append(countParams, junEndStrsUnix)
  1914. countParams = append(countParams, julStartStrUnix)
  1915. countParams = append(countParams, julEndStrsUnix)
  1916. countParams = append(countParams, augStartStrUnix)
  1917. countParams = append(countParams, augEndStrsUnix)
  1918. countParams = append(countParams, sepStartStrUnix)
  1919. countParams = append(countParams, sepEndStrsUnix)
  1920. countParams = append(countParams, octStartStrUnix)
  1921. countParams = append(countParams, octEndStrsUnix)
  1922. countParams = append(countParams, novStartStrUnix)
  1923. countParams = append(countParams, novEndStrsUnix)
  1924. countParams = append(countParams, decStartStrUnix)
  1925. countParams = append(countParams, decEndStrsUnix)
  1926. if orgid > 0 {
  1927. db = db.Where("x.org_id=?", orgid)
  1928. countSQL += " AND x.org_id=?"
  1929. countParams = append(countParams, orgid)
  1930. }
  1931. if orgid > 0 {
  1932. db = db.Where("r.user_org_id=?", orgid)
  1933. countSQL += " AND r.user_org_id=?"
  1934. countParams = append(countParams, orgid)
  1935. }
  1936. if modetype > 0 {
  1937. db = db.Where("x.item_id = ?", modetype)
  1938. countSQL += " AND x.item_id=?"
  1939. countParams = append(countParams, modetype)
  1940. }
  1941. if januaryStartStrUnix > 0 {
  1942. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1943. countSQL += " AND x.inspect_date >=?"
  1944. countParams = append(countParams, januaryStartStrUnix)
  1945. }
  1946. if decEndStrsUnix > 0 {
  1947. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1948. countSQL += " AND x.inspect_date <=?"
  1949. countParams = append(countParams, decEndStrsUnix)
  1950. }
  1951. countSQL += ")a GROUP BY nnd"
  1952. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1953. }
  1954. if lapseto == 2 {
  1955. d := XTReadDB().Table("xt_patients as s")
  1956. fmt.Println("d", d)
  1957. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1958. table := XTReadDB().Table("xt_quality_control_standard as r")
  1959. fmt.Println(table)
  1960. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1961. "SELECT " +
  1962. "CASE " +
  1963. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '一月'" +
  1964. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '二月'" +
  1965. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '三月'" +
  1966. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '四月'" +
  1967. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '五月'" +
  1968. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '六月'" +
  1969. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '七月'" +
  1970. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '八月'" +
  1971. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '九月'" +
  1972. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十月'" +
  1973. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十一月'" +
  1974. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 THEN '十二月'" +
  1975. " ELSE '其他'" +
  1976. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value +0 >= r.min_range +0 and x.inspect_value +0 <= r.large_range +0 )"
  1977. countParams := make([]interface{}, 0)
  1978. countParams = append(countParams, januaryStartStrUnix)
  1979. countParams = append(countParams, januaryEndStrUnix)
  1980. countParams = append(countParams, febStartStrStrUnix)
  1981. countParams = append(countParams, febEndStrUnix)
  1982. countParams = append(countParams, marchStartStrUnix)
  1983. countParams = append(countParams, marchEndStrUnix)
  1984. countParams = append(countParams, aprStartStrUnix)
  1985. countParams = append(countParams, aprEndStrsUnix)
  1986. countParams = append(countParams, mayStartStrUnix)
  1987. countParams = append(countParams, mayEndStrsUnix)
  1988. countParams = append(countParams, junStartStrUnix)
  1989. countParams = append(countParams, junEndStrsUnix)
  1990. countParams = append(countParams, julStartStrUnix)
  1991. countParams = append(countParams, julEndStrsUnix)
  1992. countParams = append(countParams, augStartStrUnix)
  1993. countParams = append(countParams, augEndStrsUnix)
  1994. countParams = append(countParams, sepStartStrUnix)
  1995. countParams = append(countParams, sepEndStrsUnix)
  1996. countParams = append(countParams, octStartStrUnix)
  1997. countParams = append(countParams, octEndStrsUnix)
  1998. countParams = append(countParams, novStartStrUnix)
  1999. countParams = append(countParams, novEndStrsUnix)
  2000. countParams = append(countParams, decStartStrUnix)
  2001. countParams = append(countParams, decEndStrsUnix)
  2002. if orgid > 0 {
  2003. db = db.Where("x.org_id=?", orgid)
  2004. countSQL += " AND x.org_id=?"
  2005. countParams = append(countParams, orgid)
  2006. }
  2007. if orgid > 0 {
  2008. db = db.Where("r.user_org_id=?", orgid)
  2009. countSQL += " AND r.user_org_id=?"
  2010. countParams = append(countParams, orgid)
  2011. }
  2012. if modetype > 0 {
  2013. db = db.Where("x.item_id = ?", modetype)
  2014. countSQL += " AND x.item_id=?"
  2015. countParams = append(countParams, modetype)
  2016. }
  2017. if januaryStartStrUnix > 0 {
  2018. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2019. countSQL += " AND x.inspect_date >=?"
  2020. countParams = append(countParams, januaryStartStrUnix)
  2021. }
  2022. if decEndStrsUnix > 0 {
  2023. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2024. countSQL += " AND x.inspect_date <=?"
  2025. countParams = append(countParams, decEndStrsUnix)
  2026. }
  2027. countSQL += ")a GROUP BY nnd"
  2028. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2029. }
  2030. return
  2031. }
  2032. func GetMonthProjectListThree(orgid int64, lapseto int64, modetype int64, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCount, err error) {
  2033. if lapseto == 0 {
  2034. d := XTReadDB().Table("xt_patients as s")
  2035. fmt.Println("d", d)
  2036. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2037. table := XTReadDB().Table("xt_quality_control_standard as r")
  2038. fmt.Println(table)
  2039. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2040. "SELECT " +
  2041. "CASE " +
  2042. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2043. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2044. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2045. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2046. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2047. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2048. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2049. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2050. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2051. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2052. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2053. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2054. " ELSE '其他'" +
  2055. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1 or s.lapseto = 2) and (x.inspect_value = r.range_value)"
  2056. countParams := make([]interface{}, 0)
  2057. countParams = append(countParams, januaryStartStrUnix)
  2058. countParams = append(countParams, januaryEndStrUnix)
  2059. countParams = append(countParams, febStartStrStrUnix)
  2060. countParams = append(countParams, febEndStrUnix)
  2061. countParams = append(countParams, marchStartStrUnix)
  2062. countParams = append(countParams, marchEndStrUnix)
  2063. countParams = append(countParams, aprStartStrUnix)
  2064. countParams = append(countParams, aprEndStrsUnix)
  2065. countParams = append(countParams, mayStartStrUnix)
  2066. countParams = append(countParams, mayEndStrsUnix)
  2067. countParams = append(countParams, junStartStrUnix)
  2068. countParams = append(countParams, junEndStrsUnix)
  2069. countParams = append(countParams, julStartStrUnix)
  2070. countParams = append(countParams, julEndStrsUnix)
  2071. countParams = append(countParams, augStartStrUnix)
  2072. countParams = append(countParams, augEndStrsUnix)
  2073. countParams = append(countParams, sepStartStrUnix)
  2074. countParams = append(countParams, sepEndStrsUnix)
  2075. countParams = append(countParams, octStartStrUnix)
  2076. countParams = append(countParams, octEndStrsUnix)
  2077. countParams = append(countParams, novStartStrUnix)
  2078. countParams = append(countParams, novEndStrsUnix)
  2079. countParams = append(countParams, decStartStrUnix)
  2080. countParams = append(countParams, decEndStrsUnix)
  2081. if orgid > 0 {
  2082. db = db.Where("x.org_id=?", orgid)
  2083. countSQL += " AND x.org_id=?"
  2084. countParams = append(countParams, orgid)
  2085. }
  2086. if orgid > 0 {
  2087. db = db.Where("r.user_org_id=?", orgid)
  2088. countSQL += " AND r.user_org_id=?"
  2089. countParams = append(countParams, orgid)
  2090. }
  2091. if modetype > 0 {
  2092. db = db.Where("x.item_id = ?", modetype)
  2093. countSQL += " AND x.item_id=?"
  2094. countParams = append(countParams, modetype)
  2095. }
  2096. if januaryStartStrUnix > 0 {
  2097. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2098. countSQL += " AND x.inspect_date >=?"
  2099. countParams = append(countParams, januaryStartStrUnix)
  2100. }
  2101. if decEndStrsUnix > 0 {
  2102. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2103. countSQL += " AND x.inspect_date <=?"
  2104. countParams = append(countParams, decEndStrsUnix)
  2105. }
  2106. countSQL += ")a GROUP BY nnd"
  2107. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2108. }
  2109. if lapseto == 1 {
  2110. d := XTReadDB().Table("xt_patients as s")
  2111. fmt.Println("d", d)
  2112. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2113. table := XTReadDB().Table("xt_quality_control_standard as r")
  2114. fmt.Println(table)
  2115. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2116. "SELECT " +
  2117. "CASE " +
  2118. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2119. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2120. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2121. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2122. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2123. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2124. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2125. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2126. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2127. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2128. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2129. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2130. " ELSE '其他'" +
  2131. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 1) and (x.inspect_value = r.range_value)"
  2132. countParams := make([]interface{}, 0)
  2133. countParams = append(countParams, januaryStartStrUnix)
  2134. countParams = append(countParams, januaryEndStrUnix)
  2135. countParams = append(countParams, febStartStrStrUnix)
  2136. countParams = append(countParams, febEndStrUnix)
  2137. countParams = append(countParams, marchStartStrUnix)
  2138. countParams = append(countParams, marchEndStrUnix)
  2139. countParams = append(countParams, aprStartStrUnix)
  2140. countParams = append(countParams, aprEndStrsUnix)
  2141. countParams = append(countParams, mayStartStrUnix)
  2142. countParams = append(countParams, mayEndStrsUnix)
  2143. countParams = append(countParams, junStartStrUnix)
  2144. countParams = append(countParams, junEndStrsUnix)
  2145. countParams = append(countParams, julStartStrUnix)
  2146. countParams = append(countParams, julEndStrsUnix)
  2147. countParams = append(countParams, augStartStrUnix)
  2148. countParams = append(countParams, augEndStrsUnix)
  2149. countParams = append(countParams, sepStartStrUnix)
  2150. countParams = append(countParams, sepEndStrsUnix)
  2151. countParams = append(countParams, octStartStrUnix)
  2152. countParams = append(countParams, octEndStrsUnix)
  2153. countParams = append(countParams, novStartStrUnix)
  2154. countParams = append(countParams, novEndStrsUnix)
  2155. countParams = append(countParams, decStartStrUnix)
  2156. countParams = append(countParams, decEndStrsUnix)
  2157. if orgid > 0 {
  2158. db = db.Where("x.org_id=?", orgid)
  2159. countSQL += " AND x.org_id=?"
  2160. countParams = append(countParams, orgid)
  2161. }
  2162. if orgid > 0 {
  2163. db = db.Where("r.user_org_id=?", orgid)
  2164. countSQL += " AND r.user_org_id=?"
  2165. countParams = append(countParams, orgid)
  2166. }
  2167. if modetype > 0 {
  2168. db = db.Where("x.item_id = ?", modetype)
  2169. countSQL += " AND x.item_id=?"
  2170. countParams = append(countParams, modetype)
  2171. }
  2172. if januaryStartStrUnix > 0 {
  2173. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2174. countSQL += " AND x.inspect_date >=?"
  2175. countParams = append(countParams, januaryStartStrUnix)
  2176. }
  2177. if decEndStrsUnix > 0 {
  2178. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2179. countSQL += " AND x.inspect_date <=?"
  2180. countParams = append(countParams, decEndStrsUnix)
  2181. }
  2182. countSQL += ")a GROUP BY nnd"
  2183. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2184. }
  2185. if lapseto == 2 {
  2186. d := XTReadDB().Table("xt_patients as s")
  2187. fmt.Println("d", d)
  2188. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2189. table := XTReadDB().Table("xt_quality_control_standard as r")
  2190. fmt.Println(table)
  2191. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2192. "SELECT " +
  2193. "CASE " +
  2194. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2195. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2196. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2197. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2198. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2199. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2200. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2201. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2202. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2203. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2204. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2205. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2206. " ELSE '其他'" +
  2207. "END AS nnd FROM xt_inspection as x LEFT JOIN xt_quality_control_standard AS r ON r.inspection_minor = x.item_id left join xt_patients as s on s.id = x.patient_id WHERE x.status=1 and (s.lapseto = 2) and (x.inspect_value = r.range_value)"
  2208. countParams := make([]interface{}, 0)
  2209. countParams = append(countParams, januaryStartStrUnix)
  2210. countParams = append(countParams, januaryEndStrUnix)
  2211. countParams = append(countParams, febStartStrStrUnix)
  2212. countParams = append(countParams, febEndStrUnix)
  2213. countParams = append(countParams, marchStartStrUnix)
  2214. countParams = append(countParams, marchEndStrUnix)
  2215. countParams = append(countParams, aprStartStrUnix)
  2216. countParams = append(countParams, aprEndStrsUnix)
  2217. countParams = append(countParams, mayStartStrUnix)
  2218. countParams = append(countParams, mayEndStrsUnix)
  2219. countParams = append(countParams, junStartStrUnix)
  2220. countParams = append(countParams, junEndStrsUnix)
  2221. countParams = append(countParams, julStartStrUnix)
  2222. countParams = append(countParams, julEndStrsUnix)
  2223. countParams = append(countParams, augStartStrUnix)
  2224. countParams = append(countParams, augEndStrsUnix)
  2225. countParams = append(countParams, sepStartStrUnix)
  2226. countParams = append(countParams, sepEndStrsUnix)
  2227. countParams = append(countParams, octStartStrUnix)
  2228. countParams = append(countParams, octEndStrsUnix)
  2229. countParams = append(countParams, novStartStrUnix)
  2230. countParams = append(countParams, novEndStrsUnix)
  2231. countParams = append(countParams, decStartStrUnix)
  2232. countParams = append(countParams, decEndStrsUnix)
  2233. if orgid > 0 {
  2234. db = db.Where("x.org_id=?", orgid)
  2235. countSQL += " AND x.org_id=?"
  2236. countParams = append(countParams, orgid)
  2237. }
  2238. if orgid > 0 {
  2239. db = db.Where("r.user_org_id=?", orgid)
  2240. countSQL += " AND r.user_org_id=?"
  2241. countParams = append(countParams, orgid)
  2242. }
  2243. if modetype > 0 {
  2244. db = db.Where("x.item_id = ?", modetype)
  2245. countSQL += " AND x.item_id=?"
  2246. countParams = append(countParams, modetype)
  2247. }
  2248. if januaryStartStrUnix > 0 {
  2249. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2250. countSQL += " AND x.inspect_date >=?"
  2251. countParams = append(countParams, januaryStartStrUnix)
  2252. }
  2253. if decEndStrsUnix > 0 {
  2254. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2255. countSQL += " AND x.inspect_date <=?"
  2256. countParams = append(countParams, decEndStrsUnix)
  2257. }
  2258. countSQL += ")a GROUP BY nnd"
  2259. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2260. }
  2261. return
  2262. }
  2263. func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2264. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2265. table := readDb.Table("xt_patients as s")
  2266. fmt.Println(table)
  2267. d := readDb.Table(" xt_inspection_reference as r")
  2268. fmt.Println(d)
  2269. if orgid > 0 {
  2270. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2271. }
  2272. if lapstor == 0 {
  2273. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2274. }
  2275. if lapstor == 1 {
  2276. db = db.Where("s.lapseto = 1")
  2277. }
  2278. if lapstor == 2 {
  2279. db = db.Where("s.lapseto = 2")
  2280. }
  2281. if startime > 0 {
  2282. db = db.Where("x.inspect_date >=?", startime)
  2283. }
  2284. if endtime > 0 {
  2285. db = db.Where("x.inspect_date <=?", endtime)
  2286. }
  2287. offset := (page - 1) * limit
  2288. err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as r on x.item_id = r.inspection_minor ").Where("r.user_org_id = ? and r.status = 1 and r.is_status = 1", orgid).Group("x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  2289. return inspection, total, err
  2290. }
  2291. //func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2292. //
  2293. // db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2294. // table := readDb.Table("xt_patients as s")
  2295. // fmt.Println(table)
  2296. // d := readDb.Table(" xt_inspection_reference as r")
  2297. // fmt.Println(d)
  2298. //
  2299. // if orgid > 0 {
  2300. // db = db.Where("x.org_id = ?", orgid)
  2301. // }
  2302. // if lapstor == 0 {
  2303. // table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2304. // }
  2305. // if lapstor == 1 {
  2306. // db = db.Where("s.lapseto = 1")
  2307. // }
  2308. // if lapstor == 2 {
  2309. // db = db.Where("s.lapseto = 2")
  2310. // }
  2311. // if startime > 0 {
  2312. // db = db.Where("x.inspect_date >=?", startime)
  2313. // }
  2314. // if endtime > 0 {
  2315. // db = db.Where("x.inspect_date <=?", endtime)
  2316. // }
  2317. // offset := (page - 1) * limit
  2318. // err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no,x.inspect_date").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0 )").Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  2319. //
  2320. // return inspection, total, err
  2321. //}
  2322. func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2323. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2324. table := readDb.Table("xt_patients as s")
  2325. //fmt.Println(table)
  2326. d := readDb.Table(" xt_inspection_reference as r")
  2327. fmt.Println(d)
  2328. d2 := readDb.Table("xt_quality_control_standard as d")
  2329. fmt.Println("d2", d2)
  2330. if orgid > 0 {
  2331. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1", orgid)
  2332. }
  2333. if lapstor == 0 {
  2334. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2335. }
  2336. if lapstor == 1 {
  2337. table = table.Where("s.lapseto = 1")
  2338. }
  2339. if lapstor == 2 {
  2340. table = table.Where("s.lapseto = 2")
  2341. }
  2342. if startime > 0 {
  2343. db = db.Where("x.inspect_date >=?", startime)
  2344. }
  2345. if endtime > 0 {
  2346. db = db.Where("x.inspect_date <=?", endtime)
  2347. }
  2348. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Where("d.min_range<>''and d.user_org_id = ? and d.is_status =1 and NOT EXISTS(SELECT 1 FROM xt_inspection AS x2 WHERE x2.patient_id = x.patient_id AND x2.org_id = ? AND x2.item_id = x.item_id AND x2.inspect_date > x.inspect_date)", orgid, orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2349. return inspection, err
  2350. }
  2351. func GetTotalPatientsControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2352. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2353. table := readDb.Table("xt_quality_control_standard as s")
  2354. fmt.Println(table)
  2355. if orgid > 0 {
  2356. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2357. }
  2358. if startime > 0 {
  2359. db = db.Where("x.inspect_date >=?", startime)
  2360. }
  2361. if endtime > 0 {
  2362. db = db.Where("x.inspect_date <=?", endtime)
  2363. }
  2364. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("s.status = 1 and s.is_status =1").Count(&total).Scan(&inspection).Error
  2365. return inspection, total, err
  2366. }
  2367. func GetStandControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2368. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2369. table := readDb.Table("xt_quality_control_standard as s")
  2370. fmt.Println(table)
  2371. if orgid > 0 {
  2372. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1 ", orgid)
  2373. }
  2374. if startime > 0 {
  2375. db = db.Where("x.inspect_date >=?", startime)
  2376. }
  2377. if endtime > 0 {
  2378. db = db.Where("x.inspect_date <=?", endtime)
  2379. }
  2380. db = db.Where("s.status = 1 and s.is_status = 1")
  2381. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value+0 >= s.min_range + 0 and x.inspect_value+0 <= s.large_range + 0 ").Count(&total).Scan(&inspection).Error
  2382. return inspection, total, err
  2383. }
  2384. func GetStandControlOne(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2385. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2386. table := readDb.Table("xt_quality_control_standard as s")
  2387. fmt.Println(table)
  2388. if orgid > 0 {
  2389. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2 ", orgid)
  2390. }
  2391. if startime > 0 {
  2392. db = db.Where("x.inspect_date >=?", startime)
  2393. }
  2394. if endtime > 0 {
  2395. db = db.Where("x.inspect_date <=?", endtime)
  2396. }
  2397. db = db.Where("s.status = 1 and s.is_status = 1")
  2398. err = db.Select("x.id").Joins("RIGHT JOIN xt_quality_control_standard as s on x.project_id = s.inspection_major and x.item_id = s.inspection_minor and x.org_id = s.user_org_id ").Where("x.inspect_value = s.range_value").Count(&total).Scan(&inspection).Error
  2399. return inspection, total, err
  2400. }
  2401. func GetInfectiousPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2402. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2403. table := readDb.Table("xt_patients as s")
  2404. fmt.Println(table)
  2405. d := readDb.Table(" xt_inspection_reference as r")
  2406. fmt.Println(d)
  2407. d2 := readDb.Table("xt_quality_control_standard as d")
  2408. fmt.Println("d2", d2)
  2409. if orgid > 0 {
  2410. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2411. }
  2412. if lapstor == 0 {
  2413. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2414. }
  2415. if lapstor == 1 {
  2416. table = table.Where("s.lapseto = 1")
  2417. }
  2418. if lapstor == 2 {
  2419. table = table.Where("s.lapseto = 2")
  2420. }
  2421. if startime > 0 {
  2422. db = db.Where("x.inspect_date >=?", startime)
  2423. }
  2424. if endtime > 0 {
  2425. db = db.Where("x.inspect_date <=?", endtime)
  2426. }
  2427. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2428. return inspection, err
  2429. }
  2430. func GetInfectiousControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2431. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2432. table := readDb.Table("xt_patients as s")
  2433. fmt.Println(table)
  2434. d := readDb.Table(" xt_inspection_reference as r")
  2435. fmt.Println(d)
  2436. d2 := readDb.Table("xt_quality_control_standard as d")
  2437. fmt.Println("d2", d2)
  2438. if orgid > 0 {
  2439. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2440. }
  2441. if lapstor == 0 {
  2442. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2443. }
  2444. if lapstor == 1 {
  2445. table = table.Where("s.lapseto = 1")
  2446. }
  2447. if lapstor == 2 {
  2448. table = table.Where("s.lapseto = 2")
  2449. }
  2450. if startime > 0 {
  2451. db = db.Where("x.inspect_date >=?", startime)
  2452. }
  2453. if endtime > 0 {
  2454. db = db.Where("x.inspect_date <=?", endtime)
  2455. }
  2456. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.min_range,d.large_range,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.item_id = x.item_id AND r.org_id > 0 OR ( x.item_id = r.id AND r.org_id = 0)").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Where("d.range_value <>''and d.user_org_id = ? and d.is_status = 1", orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2457. return inspection, err
  2458. }
  2459. func GetPatientContor(lapstor, orgid int64, keywords string, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2460. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2461. table := readDb.Table("xt_patients as s")
  2462. fmt.Println(table)
  2463. d := readDb.Table(" xt_inspection_reference as r")
  2464. fmt.Println(d)
  2465. d2 := readDb.Table("xt_quality_control_standard as d")
  2466. fmt.Println("d2", d2)
  2467. if len(keywords) > 0 {
  2468. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", keywords, keywords)
  2469. }
  2470. if orgid > 0 {
  2471. db = db.Where("x.org_id = ?", orgid)
  2472. }
  2473. if lapstor == 0 {
  2474. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2475. }
  2476. if lapstor == 1 {
  2477. table = table.Where("s.lapseto = 1")
  2478. }
  2479. if lapstor == 2 {
  2480. table = table.Where("s.lapseto = 2")
  2481. }
  2482. if startime > 0 {
  2483. db = db.Where("x.inspect_date >=?", startime)
  2484. }
  2485. if endtime > 0 {
  2486. db = db.Where("x.inspect_date <=?", endtime)
  2487. }
  2488. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2489. return inspection, err
  2490. }
  2491. func GetPatientNames(orgid int64, patientid int64) (models.XtPatients, error) {
  2492. patients := models.XtPatients{}
  2493. err := readDb.Where("user_org_id = ? and id = ? and status = 1", orgid, patientid).Find(&patients).Error
  2494. return patients, err
  2495. }
  2496. func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime int64, itemid int64, inspectdate int64) (inspection []*models.PatientInspectionCount, err error) {
  2497. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2498. table := readDb.Table("xt_patients as s")
  2499. fmt.Println(table)
  2500. d := readDb.Table(" xt_inspection_reference as r")
  2501. fmt.Println(d)
  2502. d2 := readDb.Table("xt_quality_control_standard as d")
  2503. fmt.Println("d2", d2)
  2504. if orgid > 0 {
  2505. db = db.Where("x.org_id = ?", orgid)
  2506. }
  2507. if patientid > 0 {
  2508. db = db.Where("x.patient_id = ?", patientid)
  2509. }
  2510. //if startime > 0 {
  2511. // db = db.Where("x.inspect_date >=?", startime)
  2512. //}
  2513. //if endtime > 0 {
  2514. // db = db.Where("x.inspect_date <=?", endtime)
  2515. //}
  2516. if itemid > 0 {
  2517. db = db.Where("x.item_id = ?", itemid)
  2518. }
  2519. if inspectdate > 0 {
  2520. db = db.Where("x.inspect_date = ?", inspectdate)
  2521. }
  2522. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
  2523. return inspection, err
  2524. }
  2525. func GetPatientComplianceDetail(orgid int64, patientid int64, startime int64, endtime int64, itemid int64) (inspection []*models.PatientInspectionCount, err error) {
  2526. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2527. table := readDb.Table("xt_patients as s")
  2528. fmt.Println(table)
  2529. d := readDb.Table(" xt_inspection_reference as r")
  2530. fmt.Println(d)
  2531. d2 := readDb.Table("xt_quality_control_standard as d")
  2532. fmt.Println("d2", d2)
  2533. if orgid > 0 {
  2534. db = db.Where("x.org_id = ? and (x.inspect_value <> '' or x.inspect_value+0 <> 0)", orgid)
  2535. }
  2536. if patientid > 0 {
  2537. db = db.Where("x.patient_id = ?", patientid)
  2538. }
  2539. if startime > 0 {
  2540. db = db.Where("x.inspect_date >=?", startime)
  2541. }
  2542. if endtime > 0 {
  2543. db = db.Where("x.inspect_date <=?", endtime)
  2544. }
  2545. if itemid > 0 {
  2546. db = db.Where("x.item_id = ?", itemid)
  2547. }
  2548. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,r.unit,d.range_value,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date asc").Scan(&inspection).Error
  2549. return inspection, err
  2550. }
  2551. func GetLastPatientsControlTwo(orgid int64, patientid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2552. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2553. table := readDb.Table("xt_patients as s")
  2554. fmt.Println(table)
  2555. d := readDb.Table(" xt_inspection_reference as r")
  2556. fmt.Println(d)
  2557. d2 := readDb.Table("xt_quality_control_standard as d")
  2558. fmt.Println("d2", d2)
  2559. if orgid > 0 {
  2560. db = db.Where("x.org_id = ?", orgid)
  2561. }
  2562. if patientid > 0 {
  2563. db = db.Where("x.patient_id = ?", patientid)
  2564. }
  2565. if startime > 0 {
  2566. db = db.Where("x.inspect_date >=?", startime)
  2567. }
  2568. if endtime > 0 {
  2569. db = db.Where("x.inspect_date <=?", endtime)
  2570. }
  2571. err = db.Group("x.id").Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,s.dialysis_no,r.range_max,r.range_min,d.sort,d.large_range,d.min_range,d.range_type").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_quality_control_standard as d on d.inspection_minor = x.item_id").Order("x.inspect_date desc").Scan(&inspection).Error
  2572. return inspection, err
  2573. }
  2574. func GetBloodPressureDetail(id int64) (models.XtQualityControlStandard, error) {
  2575. standard := models.XtQualityControlStandard{}
  2576. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  2577. return standard, err
  2578. }
  2579. func UpdateBloodPressure(st *models.XtQualityControlStandard, id int64) error {
  2580. err := XTWriteDB().Model(&st).Where("id=?", id).Update(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "updated_time": st.UpdatedTime}).Error
  2581. return err
  2582. }
  2583. func GetSystolicBloodPressure(orgid int64, startime int64, endtime int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2584. db := XTReadDB().Table("xt_monitoring_record as x")
  2585. err = db.Select("x.id,x.systolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2586. return record, total, err
  2587. }
  2588. func GetSystolicBloodPressureTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2589. db := XTReadDB().Table("xt_monitoring_record as x")
  2590. if lapseto > 0 && origin > 0 {
  2591. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  2592. }
  2593. if lapseto > 0 && origin == 0 {
  2594. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  2595. }
  2596. if lapseto == 0 && origin > 0 {
  2597. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  2598. }
  2599. err = db.Select("x.id,x.systolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2600. return record, total, err
  2601. }
  2602. func GetStandSystolicBloodPressure(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.XTMonitoringRecord, total int64, err error) {
  2603. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  2604. err = db.Select("x.id,s.sort").Joins("left join xt_quality_control_standard as s on s.user_org_id = x.user_org_id").Where("s.status = 1 and s.is_status = 0 and s.user_org_id = ? and x.user_org_id =? and x.monitoring_date>=? and x.monitoring_date <=? and s.inspection_minor = -1 and s.inspection_major = 0 and x.systolic_blood_pressure <> 0 and x.systolic_blood_pressure +0 >= s.min_range +0 and x.systolic_blood_pressure +0 <= s.large_range +0", orgid, orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2605. return record, total, err
  2606. }
  2607. func GetDiastolicBloodPressure(orgid int64, startime int64, endtime int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2608. db := XTReadDB().Table("xt_monitoring_record as x")
  2609. err = db.Select("x.id,x.diastolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.diastolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2610. return record, total, err
  2611. }
  2612. func GetDiastolicBloodPressureTwo(orgid int64, startime int64, endtime int64, lapseto int64, origin int64) (record []*models.VmMonitoringRecord, total int64, err error) {
  2613. db := XTReadDB().Table("xt_monitoring_record as x")
  2614. if lapseto > 0 && origin > 0 {
  2615. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ? AND p.source = ?", lapseto, origin)
  2616. }
  2617. if lapseto > 0 && origin == 0 {
  2618. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.lapseto = ?", lapseto)
  2619. }
  2620. if lapseto == 0 && origin > 0 {
  2621. db = db.Joins("inner join xt_patients as p on p.id = x.patient_id AND p.source = ?", origin)
  2622. }
  2623. err = db.Select("x.id,x.diastolic_blood_pressure").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.diastolic_blood_pressure <> 0", orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2624. return record, total, err
  2625. }
  2626. func GetDiastolicStandPressure(orgid int64, startime int64, endtime int64) (record []*models.XTMonitoringRecord, total int64, err error) {
  2627. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  2628. err = db.Select("x.id,s.sort").Joins("left join xt_quality_control_standard as s on s.user_org_id = x.user_org_id").Where("s.status = 1 and s.is_status = 0 and s.user_org_id = ? and x.user_org_id =? and x.monitoring_date>=? and x.monitoring_date <=? and s.inspection_minor = -2 and s.inspection_major = 0 and x.diastolic_blood_pressure <> 0 and x.diastolic_blood_pressure +0 >= s.min_range +0 and x.diastolic_blood_pressure +0 <= s.large_range +0", orgid, orgid, startime, endtime).Group("x.monitoring_date,x.patient_id").Count(&total).Scan(&record).Error
  2629. return record, total, err
  2630. }
  2631. func GetQuarterTargeStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2632. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2633. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2634. "SELECT " +
  2635. "CASE " +
  2636. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '1'" +
  2637. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '2'" +
  2638. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '3'" +
  2639. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '4'" +
  2640. " ELSE '其他'" +
  2641. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0"
  2642. countParams := make([]interface{}, 0)
  2643. countParams = append(countParams, firststart)
  2644. countParams = append(countParams, firstend)
  2645. countParams = append(countParams, sencondstart)
  2646. countParams = append(countParams, sencondend)
  2647. countParams = append(countParams, threestart)
  2648. countParams = append(countParams, threeend)
  2649. countParams = append(countParams, fourstart)
  2650. countParams = append(countParams, fourend)
  2651. if orgid > 0 {
  2652. db = db.Where("x.org_id=?", orgid)
  2653. countSQL += " AND x.org_id=?"
  2654. countParams = append(countParams, orgid)
  2655. db = db.Where("x.inspect_date>=?", firststart)
  2656. countSQL += " AND x.inspect_date>=?"
  2657. countParams = append(countParams, firststart)
  2658. db = db.Where("x.inspect_date<=?", fourend)
  2659. countSQL += " AND x.inspect_date<=?"
  2660. countParams = append(countParams, fourend)
  2661. }
  2662. countSQL += ")a GROUP BY nnd"
  2663. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2664. return
  2665. }
  2666. func GetQuarterTargeNoStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2667. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2668. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2669. "SELECT " +
  2670. "CASE " +
  2671. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '1'" +
  2672. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '2'" +
  2673. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '3'" +
  2674. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '4'" +
  2675. " ELSE '其他'" +
  2676. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0)"
  2677. countParams := make([]interface{}, 0)
  2678. countParams = append(countParams, firststart)
  2679. countParams = append(countParams, firstend)
  2680. countParams = append(countParams, sencondstart)
  2681. countParams = append(countParams, sencondend)
  2682. countParams = append(countParams, threestart)
  2683. countParams = append(countParams, threeend)
  2684. countParams = append(countParams, fourstart)
  2685. countParams = append(countParams, fourend)
  2686. if orgid > 0 {
  2687. db = db.Where("x.org_id=?", orgid)
  2688. countSQL += " AND x.org_id=?"
  2689. countParams = append(countParams, orgid)
  2690. db = db.Where("x.inspect_date>=?", firststart)
  2691. countSQL += " AND x.inspect_date>=?"
  2692. countParams = append(countParams, firststart)
  2693. db = db.Where("x.inspect_date<=?", fourend)
  2694. countSQL += " AND x.inspect_date<=?"
  2695. countParams = append(countParams, fourend)
  2696. }
  2697. countSQL += ")a GROUP BY nnd"
  2698. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2699. return
  2700. }
  2701. func GetContagionQuarterTargeStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2702. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2703. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2704. "SELECT " +
  2705. "CASE " +
  2706. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '1'" +
  2707. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '2'" +
  2708. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '3'" +
  2709. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '4'" +
  2710. " ELSE '其他'" +
  2711. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value = s.range_value"
  2712. countParams := make([]interface{}, 0)
  2713. countParams = append(countParams, firststart)
  2714. countParams = append(countParams, firstend)
  2715. countParams = append(countParams, sencondstart)
  2716. countParams = append(countParams, sencondend)
  2717. countParams = append(countParams, threestart)
  2718. countParams = append(countParams, threeend)
  2719. countParams = append(countParams, fourstart)
  2720. countParams = append(countParams, fourend)
  2721. if orgid > 0 {
  2722. db = db.Where("x.org_id=?", orgid)
  2723. countSQL += " AND x.org_id=?"
  2724. countParams = append(countParams, orgid)
  2725. db = db.Where("x.inspect_date>=?", firststart)
  2726. countSQL += " AND x.inspect_date>=?"
  2727. countParams = append(countParams, firststart)
  2728. db = db.Where("x.inspect_date<=?", fourend)
  2729. countSQL += " AND x.inspect_date<=?"
  2730. countParams = append(countParams, fourend)
  2731. }
  2732. countSQL += ")a GROUP BY nnd"
  2733. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2734. return
  2735. }
  2736. func GetContagionTargeNoStand(orgid int64, firststart int64, firstend int64, sencondstart int64, sencondend int64, threestart int64, threeend int64, fourstart int64, fourend int64) (inspection []*models.ProjectCountTwo, err error) {
  2737. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2738. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2739. "SELECT " +
  2740. "CASE " +
  2741. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '1'" +
  2742. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '2'" +
  2743. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '3'" +
  2744. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '4'" +
  2745. " ELSE '其他'" +
  2746. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value <> s.range_value"
  2747. countParams := make([]interface{}, 0)
  2748. countParams = append(countParams, firststart)
  2749. countParams = append(countParams, firstend)
  2750. countParams = append(countParams, sencondstart)
  2751. countParams = append(countParams, sencondend)
  2752. countParams = append(countParams, threestart)
  2753. countParams = append(countParams, threeend)
  2754. countParams = append(countParams, fourstart)
  2755. countParams = append(countParams, fourend)
  2756. if orgid > 0 {
  2757. db = db.Where("x.org_id=?", orgid)
  2758. countSQL += " AND x.org_id=?"
  2759. countParams = append(countParams, orgid)
  2760. db = db.Where("x.inspect_date>=?", firststart)
  2761. countSQL += " AND x.inspect_date>=?"
  2762. countParams = append(countParams, firststart)
  2763. db = db.Where("x.inspect_date<=?", fourend)
  2764. countSQL += " AND x.inspect_date<=?"
  2765. countParams = append(countParams, fourend)
  2766. }
  2767. countSQL += ")a GROUP BY nnd"
  2768. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2769. return
  2770. }
  2771. func GetMonthTargetStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2772. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2773. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2774. "SELECT " +
  2775. "CASE " +
  2776. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '1'" +
  2777. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '2'" +
  2778. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '3'" +
  2779. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '4'" +
  2780. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '5'" +
  2781. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '6'" +
  2782. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '7'" +
  2783. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '8'" +
  2784. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '9'" +
  2785. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '10'" +
  2786. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '11'" +
  2787. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0 THEN '12'" +
  2788. " ELSE '其他'" +
  2789. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and x.inspect_value + 0 >= s.min_range + 0 AND x.inspect_value + 0 <= s.large_range + 0"
  2790. countParams := make([]interface{}, 0)
  2791. countParams = append(countParams, januaryStartStrUnix)
  2792. countParams = append(countParams, januaryEndStrUnix)
  2793. countParams = append(countParams, febStartStrStrUnix)
  2794. countParams = append(countParams, febEndStrUnix)
  2795. countParams = append(countParams, marchStartStrUnix)
  2796. countParams = append(countParams, marchEndStrUnix)
  2797. countParams = append(countParams, aprStartStrUnix)
  2798. countParams = append(countParams, aprEndStrsUnix)
  2799. countParams = append(countParams, mayStartStrUnix)
  2800. countParams = append(countParams, mayEndStrsUnix)
  2801. countParams = append(countParams, junStartStrUnix)
  2802. countParams = append(countParams, junEndStrsUnix)
  2803. countParams = append(countParams, julStartStrUnix)
  2804. countParams = append(countParams, julEndStrsUnix)
  2805. countParams = append(countParams, augStartStrUnix)
  2806. countParams = append(countParams, augEndStrsUnix)
  2807. countParams = append(countParams, sepStartStrUnix)
  2808. countParams = append(countParams, sepEndStrsUnix)
  2809. countParams = append(countParams, octStartStrUnix)
  2810. countParams = append(countParams, octEndStrsUnix)
  2811. countParams = append(countParams, novStartStrUnix)
  2812. countParams = append(countParams, novEndStrsUnix)
  2813. countParams = append(countParams, decStartStrUnix)
  2814. countParams = append(countParams, decEndStrsUnix)
  2815. if orgId > 0 {
  2816. db = db.Where("x.org_id=?", orgId)
  2817. countSQL += " AND x.org_id=?"
  2818. countParams = append(countParams, orgId)
  2819. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2820. countSQL += " AND x.inspect_date>=?"
  2821. countParams = append(countParams, januaryStartStrUnix)
  2822. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2823. countSQL += " AND x.inspect_date<=?"
  2824. countParams = append(countParams, decEndStrsUnix)
  2825. }
  2826. countSQL += ")a GROUP BY nnd"
  2827. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2828. return
  2829. }
  2830. func GetMonthTargetNoStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2831. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2832. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2833. "SELECT " +
  2834. "CASE " +
  2835. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '1'" +
  2836. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '2'" +
  2837. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '3'" +
  2838. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '4'" +
  2839. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '5'" +
  2840. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '6'" +
  2841. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '7'" +
  2842. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '8'" +
  2843. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '9'" +
  2844. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '10'" +
  2845. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '11'" +
  2846. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0) THEN '12'" +
  2847. " ELSE '其他'" +
  2848. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value+0<>0 and x.status = 1 and x.inspect_type = 1 and s.is_status = 1 and s.status = 1 and (x.inspect_value + 0 < s.min_range + 0 or x.inspect_value + 0 > s.large_range + 0)"
  2849. countParams := make([]interface{}, 0)
  2850. countParams = append(countParams, januaryStartStrUnix)
  2851. countParams = append(countParams, januaryEndStrUnix)
  2852. countParams = append(countParams, febStartStrStrUnix)
  2853. countParams = append(countParams, febEndStrUnix)
  2854. countParams = append(countParams, marchStartStrUnix)
  2855. countParams = append(countParams, marchEndStrUnix)
  2856. countParams = append(countParams, aprStartStrUnix)
  2857. countParams = append(countParams, aprEndStrsUnix)
  2858. countParams = append(countParams, mayStartStrUnix)
  2859. countParams = append(countParams, mayEndStrsUnix)
  2860. countParams = append(countParams, junStartStrUnix)
  2861. countParams = append(countParams, junEndStrsUnix)
  2862. countParams = append(countParams, julStartStrUnix)
  2863. countParams = append(countParams, julEndStrsUnix)
  2864. countParams = append(countParams, augStartStrUnix)
  2865. countParams = append(countParams, augEndStrsUnix)
  2866. countParams = append(countParams, sepStartStrUnix)
  2867. countParams = append(countParams, sepEndStrsUnix)
  2868. countParams = append(countParams, octStartStrUnix)
  2869. countParams = append(countParams, octEndStrsUnix)
  2870. countParams = append(countParams, novStartStrUnix)
  2871. countParams = append(countParams, novEndStrsUnix)
  2872. countParams = append(countParams, decStartStrUnix)
  2873. countParams = append(countParams, decEndStrsUnix)
  2874. if orgId > 0 {
  2875. db = db.Where("x.org_id=?", orgId)
  2876. countSQL += " AND x.org_id=?"
  2877. countParams = append(countParams, orgId)
  2878. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2879. countSQL += " AND x.inspect_date>=?"
  2880. countParams = append(countParams, januaryStartStrUnix)
  2881. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2882. countSQL += " AND x.inspect_date<=?"
  2883. countParams = append(countParams, decEndStrsUnix)
  2884. }
  2885. countSQL += ")a GROUP BY nnd"
  2886. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2887. return
  2888. }
  2889. func GetMonthcontagionTargeStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2890. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2891. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2892. "SELECT " +
  2893. "CASE " +
  2894. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '1'" +
  2895. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '2'" +
  2896. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '3'" +
  2897. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '4'" +
  2898. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '5'" +
  2899. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '6'" +
  2900. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '7'" +
  2901. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '8'" +
  2902. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '9'" +
  2903. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '10'" +
  2904. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '11'" +
  2905. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = s.range_value THEN '12'" +
  2906. " ELSE '其他'" +
  2907. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value = s.range_value"
  2908. countParams := make([]interface{}, 0)
  2909. countParams = append(countParams, januaryStartStrUnix)
  2910. countParams = append(countParams, januaryEndStrUnix)
  2911. countParams = append(countParams, febStartStrStrUnix)
  2912. countParams = append(countParams, febEndStrUnix)
  2913. countParams = append(countParams, marchStartStrUnix)
  2914. countParams = append(countParams, marchEndStrUnix)
  2915. countParams = append(countParams, aprStartStrUnix)
  2916. countParams = append(countParams, aprEndStrsUnix)
  2917. countParams = append(countParams, mayStartStrUnix)
  2918. countParams = append(countParams, mayEndStrsUnix)
  2919. countParams = append(countParams, junStartStrUnix)
  2920. countParams = append(countParams, junEndStrsUnix)
  2921. countParams = append(countParams, julStartStrUnix)
  2922. countParams = append(countParams, julEndStrsUnix)
  2923. countParams = append(countParams, augStartStrUnix)
  2924. countParams = append(countParams, augEndStrsUnix)
  2925. countParams = append(countParams, sepStartStrUnix)
  2926. countParams = append(countParams, sepEndStrsUnix)
  2927. countParams = append(countParams, octStartStrUnix)
  2928. countParams = append(countParams, octEndStrsUnix)
  2929. countParams = append(countParams, novStartStrUnix)
  2930. countParams = append(countParams, novEndStrsUnix)
  2931. countParams = append(countParams, decStartStrUnix)
  2932. countParams = append(countParams, decEndStrsUnix)
  2933. if orgId > 0 {
  2934. db = db.Where("x.org_id=?", orgId)
  2935. countSQL += " AND x.org_id=?"
  2936. countParams = append(countParams, orgId)
  2937. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2938. countSQL += " AND x.inspect_date>=?"
  2939. countParams = append(countParams, januaryStartStrUnix)
  2940. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  2941. countSQL += " AND x.inspect_date<=?"
  2942. countParams = append(countParams, decEndStrsUnix)
  2943. }
  2944. countSQL += ")a GROUP BY nnd"
  2945. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2946. return
  2947. }
  2948. func GetMonthcontagionTargeNoStand(orgId, januaryStartStrUnix int64, januaryEndStrUnix int64, febStartStrStrUnix int64, febEndStrUnix int64, marchStartStrUnix int64, marchEndStrUnix int64, aprStartStrUnix int64, aprEndStrsUnix int64, mayStartStrUnix int64, mayEndStrsUnix int64, junStartStrUnix int64, junEndStrsUnix int64, julStartStrUnix int64, julEndStrsUnix int64, augStartStrUnix int64, augEndStrsUnix int64, sepStartStrUnix int64, sepEndStrsUnix int64, octStartStrUnix int64, octEndStrsUnix int64, novStartStrUnix int64, novEndStrsUnix int64, decStartStrUnix int64, decEndStrsUnix int64) (inspection []*models.ProjectCountTwo, err error) {
  2949. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  2950. countSQL := "SELECT nnd AS 'name',COUNT(*) AS 'count' FROM(" +
  2951. "SELECT " +
  2952. "CASE " +
  2953. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '1'" +
  2954. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '2'" +
  2955. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '3'" +
  2956. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '4'" +
  2957. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '5'" +
  2958. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '6'" +
  2959. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '7'" +
  2960. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '8'" +
  2961. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '9'" +
  2962. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '10'" +
  2963. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '11'" +
  2964. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value <> s.range_value THEN '12'" +
  2965. " ELSE '其他'" +
  2966. "END AS nnd FROM xt_inspection as x right join xt_quality_control_standard AS s ON x.project_id = s.inspection_major AND x.item_id = s.inspection_minor AND x.org_id = s.user_org_id where x.inspect_value<>'' and x.status = 1 and x.inspect_type = 2 and s.is_status = 1 and s.status = 1 and x.inspect_value <> s.range_value"
  2967. countParams := make([]interface{}, 0)
  2968. countParams = append(countParams, januaryStartStrUnix)
  2969. countParams = append(countParams, januaryEndStrUnix)
  2970. countParams = append(countParams, febStartStrStrUnix)
  2971. countParams = append(countParams, febEndStrUnix)
  2972. countParams = append(countParams, marchStartStrUnix)
  2973. countParams = append(countParams, marchEndStrUnix)
  2974. countParams = append(countParams, aprStartStrUnix)
  2975. countParams = append(countParams, aprEndStrsUnix)
  2976. countParams = append(countParams, mayStartStrUnix)
  2977. countParams = append(countParams, mayEndStrsUnix)
  2978. countParams = append(countParams, junStartStrUnix)
  2979. countParams = append(countParams, junEndStrsUnix)
  2980. countParams = append(countParams, julStartStrUnix)
  2981. countParams = append(countParams, julEndStrsUnix)
  2982. countParams = append(countParams, augStartStrUnix)
  2983. countParams = append(countParams, augEndStrsUnix)
  2984. countParams = append(countParams, sepStartStrUnix)
  2985. countParams = append(countParams, sepEndStrsUnix)
  2986. countParams = append(countParams, octStartStrUnix)
  2987. countParams = append(countParams, octEndStrsUnix)
  2988. countParams = append(countParams, novStartStrUnix)
  2989. countParams = append(countParams, novEndStrsUnix)
  2990. countParams = append(countParams, decStartStrUnix)
  2991. countParams = append(countParams, decEndStrsUnix)
  2992. if orgId > 0 {
  2993. db = db.Where("x.org_id=?", orgId)
  2994. countSQL += " AND x.org_id=?"
  2995. countParams = append(countParams, orgId)
  2996. db = db.Where("x.inspect_date>=?", januaryStartStrUnix)
  2997. countSQL += " AND x.inspect_date>=?"
  2998. countParams = append(countParams, januaryStartStrUnix)
  2999. db = db.Where("x.inspect_date<=?", decStartStrUnix)
  3000. countSQL += " AND x.inspect_date<=?"
  3001. countParams = append(countParams, decEndStrsUnix)
  3002. }
  3003. countSQL += ")a GROUP BY nnd"
  3004. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  3005. return
  3006. }
  3007. func GetQuarterBloodList(orgid int64, januaryStartStrUnix int64, januaryEndStrUnix int64) (record []*models.VmMonitoringRecord, err error) {
  3008. db := XTReadDB().Table("xt_monitoring_record as x")
  3009. err = db.Select("x.id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.monitoring_date,x.patient_id,x.user_org_id").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0 and x.diastolic_blood_pressure <> 0", orgid, januaryStartStrUnix, januaryEndStrUnix).Group("x.monitoring_date,x.patient_id").Scan(&record).Error
  3010. return record, err
  3011. }
  3012. func GetTaregetNoStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3013. db := XTReadDB().Table("xt_inspection as x")
  3014. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value+0 < d.min_range+0 or x.inspect_value+0 > d.large_range + 0)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3015. return inspection, err
  3016. }
  3017. func GetConfigurationNoStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3018. db := XTReadDB().Table("xt_inspection as x")
  3019. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 2 and x.org_id = ? and x.inspect_value <> '' and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value <> d.range_value)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3020. return inspection, err
  3021. }
  3022. func GetInspectNoStandList(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.XtPatientsInspection, err error) {
  3023. db := XTReadDB().Table("xt_inspection as x")
  3024. offset := (page - 1) * limit
  3025. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value+0 < d.min_range+0 or x.inspect_value+0 > d.large_range + 0)", orgid, startime, endtime, orgid).Group("x.id").Offset(offset).Limit(limit).Order("x.inspect_date DESC").Scan(&inspection).Error
  3026. return inspection, err
  3027. }
  3028. func GetTargetStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3029. db := XTReadDB().Table("xt_inspection as x")
  3030. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and x.inspect_value+0 >=d.min_range+0 and x.inspect_value+0 <= d.large_range + 0", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3031. return inspection, err
  3032. }
  3033. func GetConfigurationStandDetail(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientsInspection, err error) {
  3034. db := XTReadDB().Table("xt_inspection as x")
  3035. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 2 and x.org_id = ? and x.inspect_value <> '' and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and (x.inspect_value = d.range_value)", orgid, startime, endtime, orgid).Group("x.id").Order("x.inspect_date DESC").Scan(&inspection).Error
  3036. return inspection, err
  3037. }
  3038. func GetStandList(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.XtPatientsInspection, err error) {
  3039. db := XTReadDB().Table("xt_inspection as x")
  3040. offset := (page - 1) * limit
  3041. err = db.Select("x.id,x.patient_id,x.item_id,x.item_name,x.inspect_value,x.inspect_date,s.name,d.sort,d.min_range,d.large_range,d.range_value,d.range_type,x.inspect_type,x.org_id").Joins("left join xt_patients AS s ON s.id = x.patient_id").Joins("RIGHT JOIN xt_quality_control_standard AS d ON d.inspection_minor = x.item_id AND d.inspection_major = x.project_id AND x.org_id = d.user_org_id").Where("x.status = 1 and x.inspect_type = 1 and x.org_id = ? and x.inspect_value + 0 <> 0 and x.inspect_date >=? and x.inspect_date<=? and d.user_org_id = ? and d.is_status=1 and d.status = 1 and x.inspect_value+0 >=d.min_range+0 and x.inspect_value+0 <= d.large_range + 0", orgid, startime, endtime, orgid).Group("x.id").Offset(offset).Limit(limit).Order("x.inspect_date DESC").Scan(&inspection).Error
  3042. return inspection, err
  3043. }
  3044. func GetDiastolicStand(orgid int64, startime int64, endtime int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3045. db := XTReadDB().Table("xt_monitoring_record as x")
  3046. offset := (page - 1) * limit
  3047. err = db.Select("x.id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.user_org_id = ? and x.monitoring_date >=? and x.monitoring_date<=? and x.status = 1 and x.systolic_blood_pressure <> 0 and x.diastolic_blood_pressure <> 0)", orgid, startime, endtime).Offset(offset).Limit(limit).Group("x.monitoring_date,x.patient_id").Scan(&record).Error
  3048. return record, err
  3049. }
  3050. func GetInspectionMoninList(id int64, orgid int64, patientid int64) (models.XtInspection, error) {
  3051. inspection := models.XtInspection{}
  3052. err = XTReadDB().Model(&inspection).Where("item_id=? and org_id = ? and status = 1 and patient_id = ?", id, orgid, patientid).Last(&inspection).Error
  3053. return inspection, err
  3054. }
  3055. func TotalSysStandCountTwo(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64) (record []*models.XTMonitoringRecords, err error) {
  3056. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3057. if orgid > 0 {
  3058. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3059. }
  3060. if startime > 0 {
  3061. db = db.Where("x.monitoring_date>=?", startime)
  3062. }
  3063. if endtime > 0 {
  3064. db = db.Where("x.monitoring_date<=?", endtime)
  3065. }
  3066. if sysmin > 0 {
  3067. db = db.Where(" x.systolic_blood_pressure>=?", sysmin)
  3068. }
  3069. if syslarge > 0 {
  3070. db = db.Where("x.systolic_blood_pressure<=?", syslarge)
  3071. }
  3072. if diamin > 0 {
  3073. db = db.Where(" x.diastolic_blood_pressure>=?", diamin)
  3074. }
  3075. if dialarge > 0 {
  3076. db = db.Where("x.diastolic_blood_pressure<=?", dialarge)
  3077. }
  3078. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1").Group("x.monitoring_date,x.patient_id").Order("x.monitoring_date desc").Scan(&record).Error
  3079. return record, err
  3080. }
  3081. func TotalSysStandCount(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3082. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3083. if orgid > 0 {
  3084. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3085. }
  3086. if startime > 0 {
  3087. db = db.Where("x.monitoring_date>=?", startime)
  3088. }
  3089. if endtime > 0 {
  3090. db = db.Where("x.monitoring_date<=?", endtime)
  3091. }
  3092. if sysmin > 0 {
  3093. db = db.Where(" x.systolic_blood_pressure>=?", sysmin)
  3094. }
  3095. if syslarge > 0 {
  3096. db = db.Where("x.systolic_blood_pressure<=?", syslarge)
  3097. }
  3098. if diamin > 0 {
  3099. db = db.Where(" x.diastolic_blood_pressure>=?", diamin)
  3100. }
  3101. if dialarge > 0 {
  3102. db = db.Where("x.diastolic_blood_pressure<=?", dialarge)
  3103. }
  3104. offset := (page - 1) * limit
  3105. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1").Group("x.monitoring_date,x.patient_id").Offset(offset).Limit(limit).Order("x.monitoring_date desc").Scan(&record).Error
  3106. return record, err
  3107. }
  3108. func TotalSysNoStandCountTwo(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64) (record []*models.XTMonitoringRecords, err error) {
  3109. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3110. if orgid > 0 {
  3111. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3112. }
  3113. if startime > 0 {
  3114. db = db.Where("x.monitoring_date>=?", startime)
  3115. }
  3116. if endtime > 0 {
  3117. db = db.Where("x.monitoring_date<=?", endtime)
  3118. }
  3119. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1 and(x.systolic_blood_pressure<=? or x.systolic_blood_pressure>=?) or (x.diastolic_blood_pressure<=? or x.diastolic_blood_pressure>=?)", sysmin, syslarge, diamin, dialarge).Group("x.monitoring_date,x.patient_id").Order("x.monitoring_date desc").Scan(&record).Error
  3120. return record, err
  3121. }
  3122. func TotalSysNoStandCount(orgid int64, startime int64, endtime int64, sysmin int64, syslarge int64, diamin int64, dialarge int64, page int64, limit int64) (record []*models.XTMonitoringRecords, err error) {
  3123. db := XTReadDB().Table("xt_monitoring_record as x").Where("x.status = 1")
  3124. if orgid > 0 {
  3125. db = db.Where("x.user_org_id = ? and x.systolic_blood_pressure<>0 and x.diastolic_blood_pressure<>0 ", orgid)
  3126. }
  3127. if startime > 0 {
  3128. db = db.Where("x.monitoring_date>=?", startime)
  3129. }
  3130. if endtime > 0 {
  3131. db = db.Where("x.monitoring_date<=?", endtime)
  3132. }
  3133. offset := (page - 1) * limit
  3134. err = db.Select("x.id,x.user_org_id,x.systolic_blood_pressure,x.diastolic_blood_pressure,x.patient_id,x.monitoring_date,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.status = 1 and(x.systolic_blood_pressure<=? or x.systolic_blood_pressure>=?) or (x.diastolic_blood_pressure<=? or x.diastolic_blood_pressure>=?)", sysmin, syslarge, diamin, dialarge).Group("x.monitoring_date,x.patient_id").Offset(offset).Limit(limit).Order("x.monitoring_date desc").Scan(&record).Error
  3135. return record, err
  3136. }
  3137. func GetModeIdCount(startime int64, endtime int64, orgid int64, page int64, limit int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3138. table := XTReadDB().Table("xt_schedule as s")
  3139. fmt.Println("table", table)
  3140. db := XTReadDB().Table("xt_dialysis_order as o")
  3141. if orgid > 0 {
  3142. db = db.Where("o.user_org_id = ?", orgid)
  3143. }
  3144. if startime > 0 {
  3145. db = db.Where("o.dialysis_date>=?", startime)
  3146. }
  3147. if endtime > 0 {
  3148. db = db.Where("o.dialysis_date<=?", endtime)
  3149. }
  3150. //offset := (page - 1) * limit
  3151. err = db.Group(" s.patient_id,s.mode_id").Select("s.mode_id, s.patient_id, count(o.id) as count").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Scan(&order).Error
  3152. return order, err
  3153. }
  3154. func GetScheduleModeIdCount(startime int64, endtime int64, orgid int64, page int64, limit int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3155. db := XTReadDB().Table("xt_schedule as s").Where("s.status = 1")
  3156. if orgid > 0 {
  3157. db = db.Where("s.user_org_id = ?", orgid)
  3158. }
  3159. if startime > 0 {
  3160. db = db.Where("s.schedule_date>=?", startime)
  3161. }
  3162. if endtime > 0 {
  3163. db = db.Where("s.schedule_date<=?", endtime)
  3164. }
  3165. err = db.Group(" s.patient_id,s.mode_id").Select("s.mode_id,s.patient_id,count(s.id) as count").Scan(&order).Error
  3166. return order, err
  3167. }
  3168. func GetTreatModeList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisModeIdCount, err error) {
  3169. table := XTReadDB().Table("xt_schedule as s")
  3170. fmt.Println("table", table)
  3171. db := XTReadDB().Table("xt_dialysis_order as o")
  3172. if orgid > 0 {
  3173. db = db.Where("o.user_org_id = ?", orgid)
  3174. }
  3175. if startime > 0 {
  3176. db = db.Where("o.dialysis_date>=?", startime)
  3177. }
  3178. if endtime > 0 {
  3179. db = db.Where("o.dialysis_date<=?", endtime)
  3180. }
  3181. err = db.Group("s.mode_id").Select("s.mode_id, s.patient_id").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Scan(&order).Error
  3182. return order, err
  3183. }
  3184. func GetCountModeId(startime int64, endtime int64, modeid int64, orgid int64) (order []*models.BloodTreateModeIdCount, err error) {
  3185. table := XTReadDB().Table("xt_schedule as s")
  3186. fmt.Println("table", table)
  3187. db := XTReadDB().Table("xt_dialysis_order as o")
  3188. if orgid > 0 {
  3189. db = db.Where("o.user_org_id = ?", orgid)
  3190. }
  3191. if startime > 0 {
  3192. db = db.Where("o.dialysis_date>=?", startime)
  3193. }
  3194. if endtime > 0 {
  3195. db = db.Where("o.dialysis_date<=?", endtime)
  3196. }
  3197. err = db.Group("o.dialysis_date,s.mode_id").Select("s.mode_id, count(s.mode_id) as count,o.dialysis_date").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 and s.mode_id = ? and o.dialysis_date <> ''", modeid).Scan(&order).Error
  3198. return order, err
  3199. }
  3200. func GetCountRollout(orgid int64, startime int64, endtime int64, lapsetotype int64, sourcetype int64) (lapseto []*models.BloodLapsetoCount, err error) {
  3201. table := XTReadDB().Table("xt_patients as s")
  3202. fmt.Println(table)
  3203. db := XTReadDB().Table("xt_patient_lapseto as x").Where("x.status = 1")
  3204. if startime > 0 {
  3205. db = db.Where("x.lapseto_time >=?", startime)
  3206. }
  3207. if endtime > 0 {
  3208. db = db.Where("x.lapseto_time<=?", endtime)
  3209. }
  3210. if lapsetotype == 0 || sourcetype == 0 {
  3211. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ?", orgid).Scan(&lapseto).Error
  3212. }
  3213. if lapsetotype > 0 {
  3214. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.lapseto = ?", orgid, lapsetotype).Scan(&lapseto).Error
  3215. }
  3216. if sourcetype > 0 {
  3217. err = db.Group("x.lapseto_time,x.lapseto_type").Select("count(x.id) as count,x.lapseto_type,x.lapseto_time").Joins("left join xt_patients as s on s.id = x.patient_id").Where("s.user_org_id = ? and s.source = ?", orgid, sourcetype).Scan(&lapseto).Error
  3218. }
  3219. return lapseto, err
  3220. }
  3221. func GetCheckExaminePercent(start_time int64, end_time int64, org_id int64, name_type int64) (total int64) {
  3222. switch name_type {
  3223. case 1:
  3224. key := "%" + "血常规" + "%"
  3225. readDb.Model(&models.Inspection{}).Where("inspect_date >= ? AND inspect_date <= ? AND user_org_id = ? AND status = 1 AND (item_name Like ? Or project_name Like ?)", start_time, end_time, org_id, key).Group("patient_id").Count(&total)
  3226. break
  3227. case 2:
  3228. //key := "%" + "肝功能" + "%"
  3229. //key1 := "%" + "肾功能" + "%"
  3230. //key2 := "%" + "电解质" + "%"
  3231. //key3 := "%" + "血脂" + "%"
  3232. //readDb.Model(&models.Inspection{}).Where("inspect_date >= ? AND inspect_date <= ? AND user_org_id = ? AND status = 1 AND ((item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?))", start_time, end_time, org_id, key, key, key1, key1, key2, key2, key3, key3).Group("patient_id").Count(&total)
  3233. break
  3234. case 3:
  3235. //key := "%" + "肝功能" + "%"
  3236. //readDb.Model(&models.Inspection{}).Where("inspect_date >= ? AND inspect_date <= ? AND user_org_id = ? AND status = 1 AND ((item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?) Or (item_name Like ? Or project_name Like ?))", start_time, end_time, org_id, key, key, key1, key1, key2, key2, key3, key3).Group("patient_id").Count(&total)
  3237. break
  3238. case 4:
  3239. break
  3240. case 5:
  3241. break
  3242. case 6:
  3243. break
  3244. }
  3245. return
  3246. }
  3247. func GetAllPatientCount(orgid int64) (total int64, err error) {
  3248. err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Count(&total).Error
  3249. return
  3250. }
  3251. func GetPatientInspectionList(user_org_id int64) (inspection []*models.XtInspection, err error) {
  3252. err = XTReadDB().Where("inspect_date>=? and inspect_date<=? and org_id = ? and status=1", 1704038400, 1711814400, user_org_id).Group("patient_id").Find(&inspection).Error
  3253. return inspection, err
  3254. }