common_service.go 127KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "time"
  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 = ?", 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").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 GetConfigurationListTwo(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  59. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  60. if orgid > 0 {
  61. db = db.Where("x.user_org_id = ?", orgid)
  62. }
  63. table := XTReadDB().Table("xt_inspection_reference as s")
  64. fmt.Println(table)
  65. offset := (page - 1) * limit
  66. 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").Count(&total).
  67. 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).Offset(offset).Limit(limit).Scan(&standard).Error
  68. return standard, total, err
  69. }
  70. func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
  71. standard := models.XtQualityControlStandard{}
  72. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  73. return standard, err
  74. }
  75. func GetIdByItemId(itemid int64, orgid int64) (models.XtInspectionReference, error) {
  76. reference := models.XtInspectionReference{}
  77. err := XTReadDB().Model(&reference).Where("item_id = ? and org_id = ?", itemid, orgid).Find(&reference).Error
  78. return reference, err
  79. }
  80. func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
  81. err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
  82. return standard, err
  83. }
  84. func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
  85. 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
  86. return err
  87. }
  88. func DeleteConfiguration(id int64) (err error) {
  89. err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  90. return err
  91. }
  92. func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
  93. diseases := models.XtInspectionReference{}
  94. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  95. if err == gorm.ErrRecordNotFound {
  96. return nil, err
  97. }
  98. if err != nil {
  99. return nil, err
  100. }
  101. return &diseases, nil
  102. }
  103. func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
  104. err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
  105. return reference, err
  106. }
  107. func GetInspectionMajorById(marjor int64, orgid int64) (*models.XtCheckConfiguration, error) {
  108. configuration := models.XtCheckConfiguration{}
  109. err := XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).Find(&configuration).Error
  110. if err == gorm.ErrRecordNotFound {
  111. return nil, err
  112. }
  113. if err != nil {
  114. return nil, err
  115. }
  116. return &configuration, nil
  117. }
  118. func GetInspectionMajorByIdTwo(marjor int64, orgid int64) (configuration models.XtCheckConfiguration, err error) {
  119. err = XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).First(&configuration).Error
  120. return configuration, err
  121. }
  122. func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
  123. err := XTWriteDB().Create(&configuration).Error
  124. return err
  125. }
  126. func GetAllChekcListTwo(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  127. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  128. table := XTReadDB().Table("xt_inspection_reference as r")
  129. fmt.Println(table)
  130. if orgid > 0 {
  131. db = db.Where("x.user_org_id = ?", orgid)
  132. }
  133. offset := (page - 1) * limit
  134. 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).
  135. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
  136. return check, total, err
  137. }
  138. func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  139. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  140. table := XTReadDB().Table("xt_inspection_reference as r")
  141. fmt.Println(table)
  142. if orgid > 0 {
  143. db = db.Where("x.user_org_id = ?", orgid)
  144. }
  145. offset := (page - 1) * limit
  146. 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).
  147. 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
  148. return check, total, err
  149. }
  150. func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
  151. configuration := models.XtCheckConfiguration{}
  152. err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
  153. return configuration, err
  154. }
  155. func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
  156. 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
  157. return err
  158. }
  159. func DeleteCheck(id int64) error {
  160. err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  161. return err
  162. }
  163. func GetDialysiTotal(startime int64, endtime int64, orgid int64) (order []*models.DialysisOrder, total int64, err error) {
  164. err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
  165. return order, total, err
  166. }
  167. func GetDialysisCountMode(starttime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
  168. //err = readDb.Table("xt_dialysis_prescription as p").Where("p.record_date>= ? and p.record_date<=? and p.user_org_id=?", starttime, endtime, orgid).Select("p.mode_id,count(p.mode_id) as count").Group("p.mode_id").Scan(&counts).Error
  169. //return counts, err
  170. err = readDb.Table("xt_dialysis_order as o left join xt_schedule as s on s.patient_id = o.patient_id").Where("s.schedule_date = o.dialysis_date and o.dialysis_date>=? and o.dialysis_date<=? and o.user_org_id = ? and o.status = 1 and s.status = 1", starttime, endtime, orgid).Select("s.mode_id,count(s.mode_id) as count").Group("s.mode_id").Scan(&counts).Error
  171. return counts, err
  172. }
  173. func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
  174. db := readDb.Table("xt_patient_lapseto as x").Where("x.status = 1")
  175. table := readDb.Table("xt_dialysis_order as s")
  176. fmt.Println(table)
  177. 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
  178. return counts, total, err
  179. }
  180. func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
  181. db := XTReadDB().Table("x.patients as x")
  182. 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
  183. return patients, err
  184. }
  185. func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
  186. db := XTReadDB().Table("x.patients as x")
  187. 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
  188. return patients, err
  189. }
  190. func GetPatientTotalCount(orgID int64) (total int64) {
  191. readDb.Model(&models.XtPatients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
  192. return
  193. }
  194. func GetPatientTotalCountTwo(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.XtDialysisOrder, total int64, err error) {
  195. 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
  196. return dialysisorder, total, err
  197. }
  198. func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.SgjDialysisOrder, total int64, err error) {
  199. db := XTReadDB().Table("xt_dialysis_order as s").Where("s.status = 1")
  200. table := XTReadDB().Table("xt_patients as x")
  201. fmt.Println("table", table)
  202. 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
  203. return dialysisorder, total, err
  204. }
  205. func GetManPatientTotal(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  206. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and gender = 1", orgid).Count(&total).Find(&patients).Error
  207. return patients, total, err
  208. }
  209. //func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  210. // 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
  211. // return counts, err
  212. //}
  213. func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  214. 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
  215. return counts, err
  216. }
  217. func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  218. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and is_infectious = 1", orgid).Count(&total).Find(&patients).Error
  219. return patients, total, err
  220. }
  221. func GetTotalAgeCount(orgid int64) (counts []*models.PatientAgeCountStruct, err error) {
  222. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  223. SELECT
  224. CASE
  225. 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'
  226. 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'
  227. 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'
  228. 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'
  229. ELSE '150'
  230. END
  231. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1
  232. )a GROUP BY nnd`, orgid).Scan(&counts)
  233. return
  234. }
  235. func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
  236. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  237. SELECT
  238. CASE
  239. 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'
  240. END
  241. 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<=?
  242. )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
  243. return
  244. }
  245. func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err error) {
  246. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  247. return patients, err
  248. }
  249. func GetDialysisAgeData(orgID int64) (counts []*models.DialysisAgePieDataStruct, err error) {
  250. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  251. SELECT
  252. CASE
  253. 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'
  254. 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'
  255. 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'
  256. WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60 THEN '4'
  257. 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)
  258. return
  259. }
  260. func GetCurentOrgPatients(orgid int64) (patients []*models.XtPatients, err error) {
  261. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Order("created_time desc").Find(&patients).Error
  262. return patients, err
  263. }
  264. func TotalDialysisCount(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrderCount, err error) {
  265. db := XTReadDB().Table("xt_dialysis_order as o")
  266. 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
  267. return order, err
  268. }
  269. func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  270. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  271. table := XTReadDB().Table("xt_schedule as s")
  272. fmt.Println(table)
  273. d := XTReadDB().Table("xt_patients as p")
  274. fmt.Println(d)
  275. if orgid > 0 {
  276. db = db.Where("o.user_org_id = ?", orgid)
  277. }
  278. if startime > 0 {
  279. db = db.Where("o.dialysis_date>=?", startime)
  280. }
  281. if endtime > 0 {
  282. db = db.Where("o.dialysis_date<=?", endtime)
  283. }
  284. offset := (page - 1) * limit
  285. 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("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  286. return order, total, err
  287. }
  288. func GetAllDialysisList(startime int64, endtime int64, orgid int64) (order []*models.BloodDialysisOrder, err error) {
  289. table := XTReadDB().Table("xt_schedule as s")
  290. fmt.Println(table)
  291. d := XTReadDB().Table("xt_patients as p")
  292. fmt.Println(d)
  293. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  294. if orgid > 0 {
  295. db = db.Where("o.user_org_id = ?", orgid)
  296. }
  297. if startime > 0 {
  298. db = db.Where("o.dialysis_date>=?", startime)
  299. }
  300. if endtime > 0 {
  301. db = db.Where("o.dialysis_date<=?", endtime)
  302. }
  303. 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("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1 ").Scan(&order).Error
  304. return order, err
  305. }
  306. func GetDialysisPatientList(startime int64, endtime int64, page int64, limit int64, orgid int64) (order []*models.BloodDialysisOrder, total int64, err error) {
  307. table := XTReadDB().Table("xt_schedule as s")
  308. fmt.Println(table)
  309. d := XTReadDB().Table("xt_patients as p")
  310. fmt.Println(d)
  311. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  312. if orgid > 0 {
  313. db = db.Where("o.user_org_id = ?", orgid)
  314. }
  315. if startime > 0 {
  316. db = db.Where("o.dialysis_date>=?", startime)
  317. }
  318. if endtime > 0 {
  319. db = db.Where("o.dialysis_date<=?", endtime)
  320. }
  321. offset := (page - 1) * limit
  322. 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("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1 ").Count(&total).Offset(offset).Limit(limit).Scan(&order).Error
  323. return order, total, err
  324. }
  325. func GetLastSort(orgid int64) (models.XtQualityControlStandard, error) {
  326. standard := models.XtQualityControlStandard{}
  327. err := XTReadDB().Model(&standard).Where("user_org_id = ? and status =1", orgid).Last(&standard).Error
  328. return standard, err
  329. }
  330. func GetLastCheckList(orgid int64) (models.XtCheckConfiguration, error) {
  331. configuration := models.XtCheckConfiguration{}
  332. err := XTReadDB().Model(&configuration).Where("user_org_id = ? and status =1", orgid).Last(&configuration).Error
  333. return configuration, err
  334. }
  335. func GetDialysisDetailById(id int64, orgid int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  336. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  337. table := XTReadDB().Table("xt_patients as s")
  338. fmt.Println(table)
  339. if id > 0 {
  340. db = db.Where("p.patient_id = ?", id)
  341. }
  342. if orgid > 0 {
  343. db = db.Where("p.user_org_id = ?", orgid)
  344. }
  345. if startime > 0 {
  346. db = db.Where("p.record_date >= ?", startime)
  347. }
  348. if endtime > 0 {
  349. db = db.Where("p.record_date <=?", endtime)
  350. }
  351. offset := (page - 1) * limit
  352. 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
  353. return prescription, total, err
  354. }
  355. func GetPrescritionByName(orgid int64, patient_id int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  356. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  357. table := XTReadDB().Table("xt_patients as s")
  358. fmt.Println(table)
  359. //if len(keywords) > 0 {
  360. // likeKey := "%" + keywords + "%"
  361. // db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  362. //}
  363. if patient_id > 0 {
  364. db = db.Where("s.id = ?", patient_id)
  365. }
  366. if orgid > 0 {
  367. db = db.Where("p.user_org_id = ?", orgid)
  368. }
  369. if startime > 0 {
  370. db = db.Where("p.record_date >= ?", startime)
  371. }
  372. if endtime > 0 {
  373. db = db.Where("p.record_date <=?", endtime)
  374. }
  375. offset := (page - 1) * limit
  376. 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
  377. return prescription, total, err
  378. }
  379. func GetTreateInfo(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64) (blood []*models.TreatDialysisOrder, total int64, err error) {
  380. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  381. table := XTReadDB().Table("xt_schedule as s")
  382. fmt.Println(table)
  383. p := XTReadDB().Table("xt_patients as p")
  384. fmt.Println(p)
  385. sql := "from_unixtime(o.dialysis_date, '%Y%m%d') AS date"
  386. if orgID > 0 {
  387. db = db.Where("o.user_org_id = ?", orgID)
  388. }
  389. if startime > 0 {
  390. db = db.Where("o.dialysis_date >=?", startime)
  391. }
  392. if endtime > 0 {
  393. db = db.Where("o.dialysis_date<=?", endtime)
  394. }
  395. if lapseto == 0 {
  396. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  397. }
  398. if lapseto > 0 {
  399. db = db.Where("p.lapseto = ?", lapseto)
  400. }
  401. offset := (page - 1) * limit
  402. err = db.Group("o.dialysis_date").Select(sql).Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1").Count(&total).Offset(offset).Limit(limit).Scan(&blood).Error
  403. return blood, total, err
  404. }
  405. func GetTreatList(orgid int64, startime int64, endtime int64, lapseto int64) (ttd []*models.TreatTotalStruct, err error) {
  406. db := XTReadDB().Table("xt_dialysis_order as o").Where("o.status = 1")
  407. table := XTReadDB().Table("xt_schedule as s")
  408. fmt.Println(table)
  409. p := XTReadDB().Table("xt_patients as p")
  410. fmt.Println(p)
  411. if orgid > 0 {
  412. db = db.Where("o.user_org_id = ?", orgid)
  413. }
  414. if startime > 0 {
  415. db = db.Where("o.dialysis_date>=?", startime)
  416. }
  417. if endtime > 0 {
  418. db = db.Where("o.dialysis_date<=?", endtime)
  419. }
  420. if lapseto == 0 {
  421. db = db.Where("p.lapseto = 1 or p.lapseto = 2")
  422. }
  423. if lapseto > 0 {
  424. db = db.Where("p.lapseto = ?", lapseto)
  425. }
  426. err = db.Select("s.mode_id, count(s.mode_id) as number").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id").Where("s.schedule_date = o.dialysis_date and s.status = 1").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  427. return ttd, err
  428. }
  429. func GetStatistics(orgID int64, startime int64, endtime int64, modeID int64) (dtd []*DialysisTotalDataStruct, ttd []*DialysisTotalDataStruct, err error) {
  430. db := readDb
  431. sql := "s.mode_id,from_unixtime(o.dialysis_date, '%Y%m%d') as date, count(o.dialysis_date) as number"
  432. datesql := " o.dialysis_date as date"
  433. group := "from_unixtime(o.dialysis_date, '%Y%m%d')"
  434. db = db.Table(" xt_dialysis_order AS o").Joins("left join xt_schedule as s on o.patient_id = s.patient_id").Where("s.schedule_date = o.dialysis_date and s.status =1")
  435. if orgID > 0 {
  436. db = db.Where("o.user_org_id = ?", orgID)
  437. }
  438. if modeID > 0 {
  439. db = db.Where("s.mode_id=?", modeID)
  440. }
  441. if startime > 0 {
  442. db = db.Where("o.dialysis_date>=?", startime)
  443. }
  444. if endtime > 0 {
  445. db = db.Where("o.dialysis_date<=?", endtime)
  446. }
  447. db = db.Where("o.status=1")
  448. err = db.Select("s.mode_id, count(s.mode_id) as number").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  449. if err != nil {
  450. return
  451. }
  452. var ds []*DialysisTotalDataStruct
  453. err = db.Select(datesql).Group(group).Find(&ds).Error
  454. if err != nil {
  455. return
  456. }
  457. dates := make([]string, 0)
  458. if len(ds) > 0 {
  459. for _, d := range ds {
  460. dates = append(dates, d.Date)
  461. }
  462. db = db.Where("o.dialysis_date IN (?)", dates)
  463. }
  464. err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, s.mode_id").Find(&dtd).Error
  465. return
  466. }
  467. func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfiguration, err error) {
  468. var count int
  469. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status = 1")
  470. table := XTReadDB().Table("xt_inspection_reference as s")
  471. if orgid > 0 {
  472. db = db.Where("x.user_org_id = ?", orgid)
  473. }
  474. fmt.Println(table)
  475. 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
  476. return configuration, err
  477. }
  478. func GetInspectionProjectCount(orgid int64, startime int64, endtime int64, patientid int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  479. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  480. table := XTReadDB().Table("xt_inspection_reference as r")
  481. fmt.Println(table)
  482. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  483. fmt.Println(d)
  484. if orgid > 0 {
  485. db = db.Where("x.org_id = ?", orgid)
  486. }
  487. if startime > 0 {
  488. db = db.Where("x.inspect_date >=?", startime)
  489. }
  490. if endtime > 0 {
  491. db = db.Where("x.inspect_date <=?", endtime)
  492. }
  493. if patientid > 0 {
  494. db = db.Where("x.patient_id = ?", patientid)
  495. }
  496. 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
  497. return
  498. }
  499. func GetInspectionDetailById(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  500. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  501. table := XTReadDB().Table("xt_inspection_reference as r")
  502. fmt.Println(table)
  503. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  504. fmt.Println(d)
  505. if id > 0 {
  506. db = db.Where("x.patient_id=?", id)
  507. }
  508. if orgid > 0 {
  509. db = db.Where("x.org_id = ?", orgid)
  510. }
  511. if startime > 0 {
  512. db = db.Where("x.inspect_date >=?", startime)
  513. }
  514. if endtime > 0 {
  515. db = db.Where("x.inspect_date <=?", endtime)
  516. }
  517. 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
  518. return
  519. }
  520. func GetSearchPatientInfo(orgid int64, keywords int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  521. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  522. table := XTReadDB().Table("xt_inspection_reference as r")
  523. fmt.Println(table)
  524. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  525. fmt.Println(d)
  526. p := XTReadDB().Table("xt_patients as p")
  527. fmt.Println(p)
  528. //if len(keywords) > 0 {
  529. // likeKey := "%" + keywords + "%"
  530. // db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
  531. //}
  532. if keywords > 0 {
  533. db = db.Where("x.patient_id = ?", keywords)
  534. }
  535. if orgid > 0 {
  536. db = db.Where("x.org_id = ?", orgid)
  537. }
  538. if startime > 0 {
  539. db = db.Where("x.inspect_date >=?", startime)
  540. }
  541. if endtime > 0 {
  542. db = db.Where("x.inspect_date <=?", endtime)
  543. }
  544. 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
  545. return
  546. }
  547. func GetMajorInspectionByOrgid(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  548. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  549. table := XTReadDB().Table("xt_inspection_reference ar r")
  550. fmt.Println(table)
  551. 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
  552. return checkconfiguration, err
  553. }
  554. func GetDefaultByOrgId(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  555. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  556. table := XTReadDB().Table("xt_inspection_reference ar r")
  557. fmt.Println(table)
  558. 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
  559. return checkconfiguration, err
  560. }
  561. func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.PatientsInspection, total int64, err error) {
  562. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  563. table := XTReadDB().Table("xt_patients as s")
  564. fmt.Println("table", table)
  565. if orgid > 0 {
  566. db = db.Where("x.org_id = ?", orgid)
  567. }
  568. if startime > 0 {
  569. db = db.Where("x.inspect_date >= ?", startime)
  570. }
  571. if endtime > 0 {
  572. db = db.Where("x.inspect_date <=?", endtime)
  573. }
  574. offset := (page - 1) * limit
  575. 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
  576. return inspection, total, err
  577. }
  578. func GetPatientListInfo(orgid int64, startime int64, endtime int64, limit int64, page int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  579. patients, _, err := GetPatientListData(orgid, startime, endtime, limit, page)
  580. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  581. table := XTReadDB().Table("xt_inspection_reference as r")
  582. fmt.Println(table)
  583. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  584. pa := XTReadDB().Table("xt_patients as s")
  585. fmt.Println(pa)
  586. fmt.Println(d)
  587. if orgid > 0 {
  588. db = db.Where("x.org_id = ?", orgid)
  589. }
  590. if startime > 0 {
  591. db = db.Where("x.inspect_date >=?", startime)
  592. }
  593. if endtime > 0 {
  594. db = db.Where("x.inspect_date <=?", endtime)
  595. }
  596. //if len(ds) > 0 {
  597. // for _, d := range ds {
  598. // dates = append(dates, d.Date)
  599. // }
  600. //
  601. // db = db.Where("o.dialysis_date IN (?)", dates)
  602. //
  603. ////}
  604. selectContent := "CASE"
  605. dates := make([]string, 0)
  606. for _, item := range patients {
  607. selectContent = selectContent + " WHEN x.patient_id =" + strconv.FormatInt(item.PatientId, 10) + " THEN " + "'" + item.Name + "'"
  608. dates = append(dates, strconv.FormatInt(item.PatientId, 10))
  609. }
  610. db = db.Where("x.patient_id in(?)", dates)
  611. 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
  612. //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
  613. return
  614. }
  615. func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  616. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  617. table := XTReadDB().Table("xt_inspection_reference as r")
  618. fmt.Println(table)
  619. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  620. pa := XTReadDB().Table("xt_patients as s")
  621. fmt.Println(pa)
  622. fmt.Println(d)
  623. if id > 0 {
  624. db = db.Where("s.id = ?", id)
  625. }
  626. if orgid > 0 {
  627. db = db.Where("x.org_id = ?", orgid)
  628. }
  629. if startime > 0 {
  630. db = db.Where("x.inspect_date >=?", startime)
  631. }
  632. if endtime > 0 {
  633. db = db.Where("x.inspect_date <=?", endtime)
  634. }
  635. 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
  636. return
  637. }
  638. func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  639. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  640. table := XTReadDB().Table("xt_inspection_reference as r")
  641. fmt.Println(table)
  642. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  643. pa := XTReadDB().Table("xt_patients as s")
  644. fmt.Println(pa)
  645. fmt.Println(d)
  646. if len(keywords) > 0 {
  647. likeKey := "%" + keywords + "%"
  648. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  649. }
  650. if orgid > 0 {
  651. db = db.Where("x.org_id = ?", orgid)
  652. }
  653. if startime > 0 {
  654. db = db.Where("x.inspect_date >=?", startime)
  655. }
  656. if endtime > 0 {
  657. db = db.Where("x.inspect_date <=?", endtime)
  658. }
  659. 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
  660. return
  661. }
  662. func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
  663. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  664. if orgid > 0 {
  665. db = db.Where("x.user_org_id = ?", orgid)
  666. }
  667. table := XTReadDB().Table("xt_inspection_reference as s")
  668. fmt.Println(table)
  669. 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").
  670. 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
  671. return standard, err
  672. }
  673. func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
  674. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  675. if orgid >= 0 {
  676. db = db.Where("x.user_org_id = ?", orgid)
  677. }
  678. table := XTReadDB().Table("xt_inspection_reference as s")
  679. fmt.Println(table)
  680. 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").
  681. 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
  682. return standard, err
  683. }
  684. func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  685. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  686. table := XTReadDB().Table("xt_inspection_reference as r")
  687. fmt.Println(table)
  688. if orgid > 0 {
  689. db = db.Where("x.org_id = ?", orgid)
  690. }
  691. if startime > 0 {
  692. db = db.Where("x.inspect_date >=?", startime)
  693. }
  694. if endtime > 0 {
  695. db = db.Where("x.inspect_date <=?", endtime)
  696. }
  697. 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
  698. return inspection, err
  699. }
  700. func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  701. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  702. table := XTReadDB().Table("xt_inspection_reference as r")
  703. fmt.Println(table)
  704. if orgid > 0 {
  705. db = db.Where("x.org_id = ?", orgid)
  706. }
  707. if startime > 0 {
  708. db = db.Where("x.inspect_date >=?", startime)
  709. }
  710. if endtime > 0 {
  711. db = db.Where("x.inspect_date <=?", endtime)
  712. }
  713. 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
  714. return inspection, err
  715. }
  716. func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  717. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  718. table := XTReadDB().Table("xt_inspection_reference as r")
  719. fmt.Println(table)
  720. d := XTReadDB().Table("xt_patients as s")
  721. fmt.Println(d)
  722. q := XTReadDB().Table("x.xt_quality_control_standard as q")
  723. fmt.Println(q)
  724. if orgid > 0 {
  725. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and r.range_type = 1 and q.user_org_id = ?", orgid, orgid)
  726. }
  727. if startime > 0 {
  728. db = db.Where("x.inspect_date >=?", startime)
  729. }
  730. if endtime > 0 {
  731. db = db.Where("x.inspect_date <=?", endtime)
  732. }
  733. if lapseto == 0 {
  734. db = db.Where("s.lapseto = 1 or s.lapseto = 2")
  735. }
  736. if lapseto > 0 {
  737. db = db.Where("s.lapseto = ?", lapseto)
  738. }
  739. 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_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  740. return inspection, err
  741. }
  742. func GetQuarterTotalCountTwo(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspectionTwo, err error) {
  743. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  744. table := XTReadDB().Table("xt_inspection_reference as r")
  745. fmt.Println(table)
  746. d := XTReadDB().Table("xt_patients as s")
  747. fmt.Println(d)
  748. q := XTReadDB().Table("x.xt_quality_control_standard as q")
  749. fmt.Println(q)
  750. if orgid > 0 {
  751. db = db.Where("x.org_id = ? and r.range_type = 2 and q.user_org_id = ? and x.inspect_value <>''", orgid, orgid)
  752. }
  753. if startime > 0 {
  754. db = db.Where("x.inspect_date >=?", startime)
  755. }
  756. if endtime > 0 {
  757. db = db.Where("x.inspect_date <=?", endtime)
  758. }
  759. if lapseto == 0 {
  760. db = db.Where("s.lapseto = 1 or s.lapseto = 2")
  761. }
  762. if lapseto > 0 {
  763. db = db.Where("s.lapseto = ?", lapseto)
  764. }
  765. 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_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as q on q.inspection_minor = x.item_id").Scan(&inspection).Error
  766. return inspection, err
  767. }
  768. 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) {
  769. if lapseto == 0 {
  770. d := XTReadDB().Table("xt_patients as s")
  771. fmt.Println("d", d)
  772. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  773. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  774. "SELECT " +
  775. "CASE " +
  776. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  777. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  778. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  779. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  780. " ELSE '其他'" +
  781. "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"
  782. countParams := make([]interface{}, 0)
  783. countParams = append(countParams, firststart)
  784. countParams = append(countParams, firstend)
  785. countParams = append(countParams, sencondstart)
  786. countParams = append(countParams, sencondend)
  787. countParams = append(countParams, threestart)
  788. countParams = append(countParams, threeend)
  789. countParams = append(countParams, fourstart)
  790. countParams = append(countParams, fourend)
  791. if orgid > 0 {
  792. db = db.Where("x.org_id=?", orgid)
  793. countSQL += " AND x.org_id=?"
  794. countParams = append(countParams, orgid)
  795. }
  796. if modetype > 0 {
  797. db = db.Where("x.item_id = ?", modetype)
  798. countSQL += " AND x.item_id=?"
  799. countParams = append(countParams, modetype)
  800. }
  801. if startime > 0 {
  802. db = db.Where("x.inspect_date >= ?", startime)
  803. countSQL += " AND x.inspect_date >=?"
  804. countParams = append(countParams, startime)
  805. }
  806. if endtime > 0 {
  807. db = db.Where("x.inspect_date <= ?", endtime)
  808. countSQL += " AND x.inspect_date <=?"
  809. countParams = append(countParams, endtime)
  810. }
  811. countSQL += ")a GROUP BY nnd"
  812. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  813. }
  814. if lapseto == 1 {
  815. d := XTReadDB().Table("xt_patients as s")
  816. fmt.Println("d", d)
  817. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  818. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  819. "SELECT " +
  820. "CASE " +
  821. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  822. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  823. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  824. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  825. "ELSE '其他'" +
  826. "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)"
  827. countParams := make([]interface{}, 0)
  828. countParams = append(countParams, firststart)
  829. countParams = append(countParams, firstend)
  830. countParams = append(countParams, sencondstart)
  831. countParams = append(countParams, sencondend)
  832. countParams = append(countParams, threestart)
  833. countParams = append(countParams, threeend)
  834. countParams = append(countParams, fourstart)
  835. countParams = append(countParams, fourend)
  836. if orgid > 0 {
  837. db = db.Where("x.org_id=?", orgid)
  838. countSQL += " AND x.org_id=?"
  839. countParams = append(countParams, orgid)
  840. }
  841. if modetype > 0 {
  842. db = db.Where("x.item_id = ?", modetype)
  843. countSQL += " AND x.item_id=?"
  844. countParams = append(countParams, modetype)
  845. }
  846. if startime > 0 {
  847. db = db.Where("x.inspect_date >= ?", startime)
  848. countSQL += " AND x.inspect_date >=?"
  849. countParams = append(countParams, startime)
  850. }
  851. if endtime > 0 {
  852. db = db.Where("x.inspect_date <= ?", endtime)
  853. countSQL += " AND x.inspect_date <=?"
  854. countParams = append(countParams, endtime)
  855. }
  856. countSQL += ")a GROUP BY nnd"
  857. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  858. }
  859. if lapseto == 2 {
  860. d := XTReadDB().Table("xt_patients as s")
  861. fmt.Println("d", d)
  862. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  863. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  864. "SELECT " +
  865. "CASE " +
  866. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  867. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  868. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  869. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  870. " ELSE '其他'" +
  871. "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)"
  872. countParams := make([]interface{}, 0)
  873. countParams = append(countParams, firststart)
  874. countParams = append(countParams, firstend)
  875. countParams = append(countParams, sencondstart)
  876. countParams = append(countParams, sencondend)
  877. countParams = append(countParams, threestart)
  878. countParams = append(countParams, threeend)
  879. countParams = append(countParams, fourstart)
  880. countParams = append(countParams, fourend)
  881. if orgid > 0 {
  882. db = db.Where("x.org_id=?", orgid)
  883. countSQL += " AND x.org_id=?"
  884. countParams = append(countParams, orgid)
  885. }
  886. if modetype > 0 {
  887. db = db.Where("x.item_id = ?", modetype)
  888. countSQL += " AND x.item_id=?"
  889. countParams = append(countParams, modetype)
  890. }
  891. if startime > 0 {
  892. db = db.Where("x.inspect_date >= ?", startime)
  893. countSQL += " AND x.inspect_date >=?"
  894. countParams = append(countParams, startime)
  895. }
  896. if endtime > 0 {
  897. db = db.Where("x.inspect_date <= ?", endtime)
  898. countSQL += " AND x.inspect_date <=?"
  899. countParams = append(countParams, endtime)
  900. }
  901. countSQL += ")a GROUP BY nnd"
  902. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  903. }
  904. return
  905. }
  906. 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) {
  907. if lapseto == 0 {
  908. d := XTReadDB().Table("xt_patients as s")
  909. fmt.Println("d", d)
  910. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  911. table := XTReadDB().Table("xt_inspection_reference as r")
  912. q := XTReadDB().Table("xt_quality_control_standard as r")
  913. fmt.Println("q", q)
  914. fmt.Println(table)
  915. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  916. "SELECT " +
  917. "CASE " +
  918. " 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 '第一季度'" +
  919. " 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 '第二季度'" +
  920. " 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 '第三季度'" +
  921. " 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 '第四季度'" +
  922. " ELSE '其他'" +
  923. "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)"
  924. countParams := make([]interface{}, 0)
  925. countParams = append(countParams, firststart)
  926. countParams = append(countParams, firstend)
  927. countParams = append(countParams, sencondstart)
  928. countParams = append(countParams, sencondend)
  929. countParams = append(countParams, threestart)
  930. countParams = append(countParams, threeend)
  931. countParams = append(countParams, fourstart)
  932. countParams = append(countParams, fourend)
  933. if orgid > 0 {
  934. db = db.Where("x.org_id=?", orgid)
  935. countSQL += " AND x.org_id=?"
  936. countParams = append(countParams, orgid)
  937. }
  938. if orgid > 0 {
  939. db = db.Where("r.user_org_id=?", orgid)
  940. countSQL += " AND r.user_org_id=?"
  941. countParams = append(countParams, orgid)
  942. }
  943. if modetype > 0 {
  944. db = db.Where("x.item_id = ?", modetype)
  945. countSQL += " AND x.item_id=?"
  946. countParams = append(countParams, modetype)
  947. }
  948. if startime > 0 {
  949. db = db.Where("x.inspect_date >= ? ", startime)
  950. countSQL += " AND x.inspect_date >=?"
  951. countParams = append(countParams, startime)
  952. }
  953. if endtime > 0 {
  954. db = db.Where("x.inspect_date <= ?", endtime)
  955. countSQL += " AND x.inspect_date <=?"
  956. countParams = append(countParams, endtime)
  957. }
  958. countSQL += ")a GROUP BY nnd"
  959. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  960. }
  961. if lapseto == 1 {
  962. d := XTReadDB().Table("xt_patients as s")
  963. fmt.Println("d", d)
  964. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value<> ''")
  965. table := XTReadDB().Table("xt_inspection_reference as r")
  966. q := XTReadDB().Table("xt_quality_control_standard as r")
  967. fmt.Println("q", q)
  968. fmt.Println(table)
  969. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  970. "SELECT " +
  971. "CASE " +
  972. " 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 '第一季度'" +
  973. " 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 '第二季度'" +
  974. " 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 '第三季度'" +
  975. " 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 '第四季度'" +
  976. " ELSE '其他'" +
  977. "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)"
  978. countParams := make([]interface{}, 0)
  979. countParams = append(countParams, firststart)
  980. countParams = append(countParams, firstend)
  981. countParams = append(countParams, sencondstart)
  982. countParams = append(countParams, sencondend)
  983. countParams = append(countParams, threestart)
  984. countParams = append(countParams, threeend)
  985. countParams = append(countParams, fourstart)
  986. countParams = append(countParams, fourend)
  987. if orgid > 0 {
  988. db = db.Where("x.org_id=?", orgid)
  989. countSQL += " AND x.org_id=?"
  990. countParams = append(countParams, orgid)
  991. }
  992. if orgid > 0 {
  993. db = db.Where("r.user_org_id=?", orgid)
  994. countSQL += " AND r.user_org_id=?"
  995. countParams = append(countParams, orgid)
  996. }
  997. if modetype > 0 {
  998. db = db.Where("x.item_id = ?", modetype)
  999. countSQL += " AND x.item_id=?"
  1000. countParams = append(countParams, modetype)
  1001. }
  1002. if startime > 0 {
  1003. db = db.Where("x.inspect_date >= ? ", startime)
  1004. countSQL += " AND x.inspect_date >=?"
  1005. countParams = append(countParams, startime)
  1006. }
  1007. if endtime > 0 {
  1008. db = db.Where("x.inspect_date <= ?", endtime)
  1009. countSQL += " AND x.inspect_date <=?"
  1010. countParams = append(countParams, endtime)
  1011. }
  1012. countSQL += ")a GROUP BY nnd"
  1013. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1014. }
  1015. return
  1016. }
  1017. 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) {
  1018. if lapseto == 0 {
  1019. d := XTReadDB().Table("xt_patients as s")
  1020. fmt.Println("d", d)
  1021. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1022. table := XTReadDB().Table("xt_inspection_reference as r")
  1023. q := XTReadDB().Table("xt_quality_control_standard as r")
  1024. fmt.Println("q", q)
  1025. fmt.Println(table)
  1026. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1027. "SELECT " +
  1028. "CASE " +
  1029. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1030. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1031. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1032. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1033. " ELSE '其他'" +
  1034. "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"
  1035. countParams := make([]interface{}, 0)
  1036. countParams = append(countParams, firststart)
  1037. countParams = append(countParams, firstend)
  1038. countParams = append(countParams, sencondstart)
  1039. countParams = append(countParams, sencondend)
  1040. countParams = append(countParams, threestart)
  1041. countParams = append(countParams, threeend)
  1042. countParams = append(countParams, fourstart)
  1043. countParams = append(countParams, fourend)
  1044. if orgid > 0 {
  1045. db = db.Where("x.org_id=?", orgid)
  1046. countSQL += " AND x.org_id=?"
  1047. countParams = append(countParams, orgid)
  1048. }
  1049. if orgid > 0 {
  1050. db = db.Where("r.user_org_id=?", orgid)
  1051. countSQL += " AND r.user_org_id=?"
  1052. countParams = append(countParams, orgid)
  1053. }
  1054. if modetype > 0 {
  1055. db = db.Where("x.item_id = ?", modetype)
  1056. countSQL += " AND x.item_id=?"
  1057. countParams = append(countParams, modetype)
  1058. }
  1059. if startime > 0 {
  1060. db = db.Where("x.inspect_date >= ? ", startime)
  1061. countSQL += " AND x.inspect_date >=?"
  1062. countParams = append(countParams, startime)
  1063. }
  1064. if endtime > 0 {
  1065. db = db.Where("x.inspect_date <= ?", endtime)
  1066. countSQL += " AND x.inspect_date <=?"
  1067. countParams = append(countParams, endtime)
  1068. }
  1069. countSQL += ")a GROUP BY nnd"
  1070. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1071. }
  1072. if lapseto == 1 {
  1073. d := XTReadDB().Table("xt_patients as s")
  1074. fmt.Println("d", d)
  1075. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_type = 2")
  1076. table := XTReadDB().Table("xt_inspection_reference as r")
  1077. q := XTReadDB().Table("xt_quality_control_standard as r")
  1078. fmt.Println("q", q)
  1079. fmt.Println(table)
  1080. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1081. "SELECT " +
  1082. "CASE " +
  1083. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第一季度'" +
  1084. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第二季度'" +
  1085. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第三季度'" +
  1086. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value = r.range_value THEN '第四季度'" +
  1087. " ELSE '其他'" +
  1088. "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"
  1089. countParams := make([]interface{}, 0)
  1090. countParams = append(countParams, firststart)
  1091. countParams = append(countParams, firstend)
  1092. countParams = append(countParams, sencondstart)
  1093. countParams = append(countParams, sencondend)
  1094. countParams = append(countParams, threestart)
  1095. countParams = append(countParams, threeend)
  1096. countParams = append(countParams, fourstart)
  1097. countParams = append(countParams, fourend)
  1098. if orgid > 0 {
  1099. db = db.Where("x.org_id=?", orgid)
  1100. countSQL += " AND x.org_id=?"
  1101. countParams = append(countParams, orgid)
  1102. }
  1103. if orgid > 0 {
  1104. db = db.Where("r.user_org_id=?", orgid)
  1105. countSQL += " AND r.user_org_id=?"
  1106. countParams = append(countParams, orgid)
  1107. }
  1108. if modetype > 0 {
  1109. db = db.Where("x.item_id = ?", modetype)
  1110. countSQL += " AND x.item_id=?"
  1111. countParams = append(countParams, modetype)
  1112. }
  1113. if startime > 0 {
  1114. db = db.Where("x.inspect_date >= ? ", startime)
  1115. countSQL += " AND x.inspect_date >=?"
  1116. countParams = append(countParams, startime)
  1117. }
  1118. if endtime > 0 {
  1119. db = db.Where("x.inspect_date <= ?", endtime)
  1120. countSQL += " AND x.inspect_date <=?"
  1121. countParams = append(countParams, endtime)
  1122. }
  1123. countSQL += ")a GROUP BY nnd"
  1124. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1125. }
  1126. return
  1127. }
  1128. 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) {
  1129. if lapseto == 0 {
  1130. d := XTReadDB().Table("xt_patients as s")
  1131. fmt.Println("d", d)
  1132. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1")
  1133. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1134. "SELECT " +
  1135. "CASE " +
  1136. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1137. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1138. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1139. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1140. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1141. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1142. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1143. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1144. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1145. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1146. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1147. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1148. " ELSE '其他'" +
  1149. "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)"
  1150. countParams := make([]interface{}, 0)
  1151. countParams = append(countParams, januaryStartStrUnix)
  1152. countParams = append(countParams, januaryEndStrUnix)
  1153. countParams = append(countParams, febStartStrStrUnix)
  1154. countParams = append(countParams, febEndStrUnix)
  1155. countParams = append(countParams, marchStartStrUnix)
  1156. countParams = append(countParams, marchEndStrUnix)
  1157. countParams = append(countParams, aprStartStrUnix)
  1158. countParams = append(countParams, aprEndStrsUnix)
  1159. countParams = append(countParams, mayStartStrUnix)
  1160. countParams = append(countParams, mayEndStrsUnix)
  1161. countParams = append(countParams, junStartStrUnix)
  1162. countParams = append(countParams, junEndStrsUnix)
  1163. countParams = append(countParams, julStartStrUnix)
  1164. countParams = append(countParams, julEndStrsUnix)
  1165. countParams = append(countParams, augStartStrUnix)
  1166. countParams = append(countParams, augEndStrsUnix)
  1167. countParams = append(countParams, sepStartStrUnix)
  1168. countParams = append(countParams, sepEndStrsUnix)
  1169. countParams = append(countParams, octStartStrUnix)
  1170. countParams = append(countParams, octEndStrsUnix)
  1171. countParams = append(countParams, novStartStrUnix)
  1172. countParams = append(countParams, novEndStrsUnix)
  1173. countParams = append(countParams, decStartStrUnix)
  1174. countParams = append(countParams, decEndStrsUnix)
  1175. if orgid > 0 {
  1176. db = db.Where("x.org_id=?", orgid)
  1177. countSQL += " AND x.org_id=?"
  1178. countParams = append(countParams, orgid)
  1179. }
  1180. if modetype > 0 {
  1181. db = db.Where("x.item_id = ?", modetype)
  1182. countSQL += " AND x.item_id=?"
  1183. countParams = append(countParams, modetype)
  1184. }
  1185. if januaryStartStrUnix > 0 {
  1186. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1187. countSQL += " AND x.inspect_date >=?"
  1188. countParams = append(countParams, januaryStartStrUnix)
  1189. }
  1190. if decEndStrsUnix > 0 {
  1191. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1192. countSQL += " AND x.inspect_date <=?"
  1193. countParams = append(countParams, decEndStrsUnix)
  1194. }
  1195. countSQL += ")a GROUP BY nnd"
  1196. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1197. }
  1198. if lapseto == 1 {
  1199. d := XTReadDB().Table("xt_patients as s")
  1200. fmt.Println("d", d)
  1201. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_value <> 0 and x.inspect_type = 1 ")
  1202. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1203. "SELECT " +
  1204. "CASE " +
  1205. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1206. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1207. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1208. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1209. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1210. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1211. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1212. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1213. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1214. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1215. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1216. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1217. " ELSE '其他'" +
  1218. "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)"
  1219. countParams := make([]interface{}, 0)
  1220. countParams = append(countParams, januaryStartStrUnix)
  1221. countParams = append(countParams, januaryEndStrUnix)
  1222. countParams = append(countParams, febStartStrStrUnix)
  1223. countParams = append(countParams, febEndStrUnix)
  1224. countParams = append(countParams, marchStartStrUnix)
  1225. countParams = append(countParams, marchEndStrUnix)
  1226. countParams = append(countParams, aprStartStrUnix)
  1227. countParams = append(countParams, aprEndStrsUnix)
  1228. countParams = append(countParams, mayStartStrUnix)
  1229. countParams = append(countParams, mayEndStrsUnix)
  1230. countParams = append(countParams, junStartStrUnix)
  1231. countParams = append(countParams, junEndStrsUnix)
  1232. countParams = append(countParams, julStartStrUnix)
  1233. countParams = append(countParams, julEndStrsUnix)
  1234. countParams = append(countParams, augStartStrUnix)
  1235. countParams = append(countParams, augEndStrsUnix)
  1236. countParams = append(countParams, sepStartStrUnix)
  1237. countParams = append(countParams, sepEndStrsUnix)
  1238. countParams = append(countParams, octStartStrUnix)
  1239. countParams = append(countParams, octEndStrsUnix)
  1240. countParams = append(countParams, novStartStrUnix)
  1241. countParams = append(countParams, novEndStrsUnix)
  1242. countParams = append(countParams, decStartStrUnix)
  1243. countParams = append(countParams, decEndStrsUnix)
  1244. if orgid > 0 {
  1245. db = db.Where("x.org_id=?", orgid)
  1246. countSQL += " AND x.org_id=?"
  1247. countParams = append(countParams, orgid)
  1248. }
  1249. if modetype > 0 {
  1250. db = db.Where("x.item_id = ?", modetype)
  1251. countSQL += " AND x.item_id=?"
  1252. countParams = append(countParams, modetype)
  1253. }
  1254. if januaryStartStrUnix > 0 {
  1255. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1256. countSQL += " AND x.inspect_date >=?"
  1257. countParams = append(countParams, januaryStartStrUnix)
  1258. }
  1259. if decEndStrsUnix > 0 {
  1260. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1261. countSQL += " AND x.inspect_date <=?"
  1262. countParams = append(countParams, decEndStrsUnix)
  1263. }
  1264. countSQL += ")a GROUP BY nnd"
  1265. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1266. }
  1267. if lapseto == 2 {
  1268. d := XTReadDB().Table("xt_patients as s")
  1269. fmt.Println("d", d)
  1270. db := readDb.Table("xt_inspection as x ").Where("x.status=1 x.inspect_value <> 0 and x.inspect_type = 1")
  1271. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1272. "SELECT " +
  1273. "CASE " +
  1274. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1275. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1276. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1277. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1278. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1279. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1280. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1281. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1282. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1283. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1284. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1285. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1286. " ELSE '其他'" +
  1287. "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)"
  1288. countParams := make([]interface{}, 0)
  1289. countParams = append(countParams, januaryStartStrUnix)
  1290. countParams = append(countParams, januaryEndStrUnix)
  1291. countParams = append(countParams, febStartStrStrUnix)
  1292. countParams = append(countParams, febEndStrUnix)
  1293. countParams = append(countParams, marchStartStrUnix)
  1294. countParams = append(countParams, marchEndStrUnix)
  1295. countParams = append(countParams, aprStartStrUnix)
  1296. countParams = append(countParams, aprEndStrsUnix)
  1297. countParams = append(countParams, mayStartStrUnix)
  1298. countParams = append(countParams, mayEndStrsUnix)
  1299. countParams = append(countParams, junStartStrUnix)
  1300. countParams = append(countParams, junEndStrsUnix)
  1301. countParams = append(countParams, julStartStrUnix)
  1302. countParams = append(countParams, julEndStrsUnix)
  1303. countParams = append(countParams, augStartStrUnix)
  1304. countParams = append(countParams, augEndStrsUnix)
  1305. countParams = append(countParams, sepStartStrUnix)
  1306. countParams = append(countParams, sepEndStrsUnix)
  1307. countParams = append(countParams, octStartStrUnix)
  1308. countParams = append(countParams, octEndStrsUnix)
  1309. countParams = append(countParams, novStartStrUnix)
  1310. countParams = append(countParams, novEndStrsUnix)
  1311. countParams = append(countParams, decStartStrUnix)
  1312. countParams = append(countParams, decEndStrsUnix)
  1313. if orgid > 0 {
  1314. db = db.Where("x.org_id=?", orgid)
  1315. countSQL += " AND x.org_id=?"
  1316. countParams = append(countParams, orgid)
  1317. }
  1318. if modetype > 0 {
  1319. db = db.Where("x.item_id = ?", modetype)
  1320. countSQL += " AND x.item_id=?"
  1321. countParams = append(countParams, modetype)
  1322. }
  1323. if januaryStartStrUnix > 0 {
  1324. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1325. countSQL += " AND x.inspect_date >=?"
  1326. countParams = append(countParams, januaryStartStrUnix)
  1327. }
  1328. if decEndStrsUnix > 0 {
  1329. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1330. countSQL += " AND x.inspect_date <=?"
  1331. countParams = append(countParams, decEndStrsUnix)
  1332. }
  1333. countSQL += ")a GROUP BY nnd"
  1334. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1335. }
  1336. return
  1337. }
  1338. 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) {
  1339. if lapseto == 0 {
  1340. d := XTReadDB().Table("xt_patients as s")
  1341. fmt.Println("d", d)
  1342. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1343. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1344. "SELECT " +
  1345. "CASE " +
  1346. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1347. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1348. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1349. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1350. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1351. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1352. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1353. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1354. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1355. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1356. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1357. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1358. " ELSE '其他'" +
  1359. "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)"
  1360. countParams := make([]interface{}, 0)
  1361. countParams = append(countParams, januaryStartStrUnix)
  1362. countParams = append(countParams, januaryEndStrUnix)
  1363. countParams = append(countParams, febStartStrStrUnix)
  1364. countParams = append(countParams, febEndStrUnix)
  1365. countParams = append(countParams, marchStartStrUnix)
  1366. countParams = append(countParams, marchEndStrUnix)
  1367. countParams = append(countParams, aprStartStrUnix)
  1368. countParams = append(countParams, aprEndStrsUnix)
  1369. countParams = append(countParams, mayStartStrUnix)
  1370. countParams = append(countParams, mayEndStrsUnix)
  1371. countParams = append(countParams, junStartStrUnix)
  1372. countParams = append(countParams, junEndStrsUnix)
  1373. countParams = append(countParams, julStartStrUnix)
  1374. countParams = append(countParams, julEndStrsUnix)
  1375. countParams = append(countParams, augStartStrUnix)
  1376. countParams = append(countParams, augEndStrsUnix)
  1377. countParams = append(countParams, sepStartStrUnix)
  1378. countParams = append(countParams, sepEndStrsUnix)
  1379. countParams = append(countParams, octStartStrUnix)
  1380. countParams = append(countParams, octEndStrsUnix)
  1381. countParams = append(countParams, novStartStrUnix)
  1382. countParams = append(countParams, novEndStrsUnix)
  1383. countParams = append(countParams, decStartStrUnix)
  1384. countParams = append(countParams, decEndStrsUnix)
  1385. if orgid > 0 {
  1386. db = db.Where("x.org_id=?", orgid)
  1387. countSQL += " AND x.org_id=?"
  1388. countParams = append(countParams, orgid)
  1389. }
  1390. if modetype > 0 {
  1391. db = db.Where("x.item_id = ?", modetype)
  1392. countSQL += " AND x.item_id=?"
  1393. countParams = append(countParams, modetype)
  1394. }
  1395. if januaryStartStrUnix > 0 {
  1396. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1397. countSQL += " AND x.inspect_date >=?"
  1398. countParams = append(countParams, januaryStartStrUnix)
  1399. }
  1400. if decEndStrsUnix > 0 {
  1401. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1402. countSQL += " AND x.inspect_date <=?"
  1403. countParams = append(countParams, decEndStrsUnix)
  1404. }
  1405. countSQL += ")a GROUP BY nnd"
  1406. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1407. }
  1408. if lapseto == 1 {
  1409. d := XTReadDB().Table("xt_patients as s")
  1410. fmt.Println("d", d)
  1411. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and and x.inspect_type = 2")
  1412. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1413. "SELECT " +
  1414. "CASE " +
  1415. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1416. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1417. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1418. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1419. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1420. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1421. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1422. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1423. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1424. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1425. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1426. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1427. " ELSE '其他'" +
  1428. "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)"
  1429. countParams := make([]interface{}, 0)
  1430. countParams = append(countParams, januaryStartStrUnix)
  1431. countParams = append(countParams, januaryEndStrUnix)
  1432. countParams = append(countParams, febStartStrStrUnix)
  1433. countParams = append(countParams, febEndStrUnix)
  1434. countParams = append(countParams, marchStartStrUnix)
  1435. countParams = append(countParams, marchEndStrUnix)
  1436. countParams = append(countParams, aprStartStrUnix)
  1437. countParams = append(countParams, aprEndStrsUnix)
  1438. countParams = append(countParams, mayStartStrUnix)
  1439. countParams = append(countParams, mayEndStrsUnix)
  1440. countParams = append(countParams, junStartStrUnix)
  1441. countParams = append(countParams, junEndStrsUnix)
  1442. countParams = append(countParams, julStartStrUnix)
  1443. countParams = append(countParams, julEndStrsUnix)
  1444. countParams = append(countParams, augStartStrUnix)
  1445. countParams = append(countParams, augEndStrsUnix)
  1446. countParams = append(countParams, sepStartStrUnix)
  1447. countParams = append(countParams, sepEndStrsUnix)
  1448. countParams = append(countParams, octStartStrUnix)
  1449. countParams = append(countParams, octEndStrsUnix)
  1450. countParams = append(countParams, novStartStrUnix)
  1451. countParams = append(countParams, novEndStrsUnix)
  1452. countParams = append(countParams, decStartStrUnix)
  1453. countParams = append(countParams, decEndStrsUnix)
  1454. if orgid > 0 {
  1455. db = db.Where("x.org_id=?", orgid)
  1456. countSQL += " AND x.org_id=?"
  1457. countParams = append(countParams, orgid)
  1458. }
  1459. if modetype > 0 {
  1460. db = db.Where("x.item_id = ?", modetype)
  1461. countSQL += " AND x.item_id=?"
  1462. countParams = append(countParams, modetype)
  1463. }
  1464. if januaryStartStrUnix > 0 {
  1465. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1466. countSQL += " AND x.inspect_date >=?"
  1467. countParams = append(countParams, januaryStartStrUnix)
  1468. }
  1469. if decEndStrsUnix > 0 {
  1470. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1471. countSQL += " AND x.inspect_date <=?"
  1472. countParams = append(countParams, decEndStrsUnix)
  1473. }
  1474. countSQL += ")a GROUP BY nnd"
  1475. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1476. }
  1477. if lapseto == 2 {
  1478. d := XTReadDB().Table("xt_patients as s")
  1479. fmt.Println("d", d)
  1480. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1481. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1482. "SELECT " +
  1483. "CASE " +
  1484. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1485. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1486. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1487. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1488. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1489. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1490. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1491. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1492. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1493. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1494. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1495. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1496. " ELSE '其他'" +
  1497. "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)"
  1498. countParams := make([]interface{}, 0)
  1499. countParams = append(countParams, januaryStartStrUnix)
  1500. countParams = append(countParams, januaryEndStrUnix)
  1501. countParams = append(countParams, febStartStrStrUnix)
  1502. countParams = append(countParams, febEndStrUnix)
  1503. countParams = append(countParams, marchStartStrUnix)
  1504. countParams = append(countParams, marchEndStrUnix)
  1505. countParams = append(countParams, aprStartStrUnix)
  1506. countParams = append(countParams, aprEndStrsUnix)
  1507. countParams = append(countParams, mayStartStrUnix)
  1508. countParams = append(countParams, mayEndStrsUnix)
  1509. countParams = append(countParams, junStartStrUnix)
  1510. countParams = append(countParams, junEndStrsUnix)
  1511. countParams = append(countParams, julStartStrUnix)
  1512. countParams = append(countParams, julEndStrsUnix)
  1513. countParams = append(countParams, augStartStrUnix)
  1514. countParams = append(countParams, augEndStrsUnix)
  1515. countParams = append(countParams, sepStartStrUnix)
  1516. countParams = append(countParams, sepEndStrsUnix)
  1517. countParams = append(countParams, octStartStrUnix)
  1518. countParams = append(countParams, octEndStrsUnix)
  1519. countParams = append(countParams, novStartStrUnix)
  1520. countParams = append(countParams, novEndStrsUnix)
  1521. countParams = append(countParams, decStartStrUnix)
  1522. countParams = append(countParams, decEndStrsUnix)
  1523. if orgid > 0 {
  1524. db = db.Where("x.org_id=?", orgid)
  1525. countSQL += " AND x.org_id=?"
  1526. countParams = append(countParams, orgid)
  1527. }
  1528. if modetype > 0 {
  1529. db = db.Where("x.item_id = ?", modetype)
  1530. countSQL += " AND x.item_id=?"
  1531. countParams = append(countParams, modetype)
  1532. }
  1533. if januaryStartStrUnix > 0 {
  1534. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1535. countSQL += " AND x.inspect_date >=?"
  1536. countParams = append(countParams, januaryStartStrUnix)
  1537. }
  1538. if decEndStrsUnix > 0 {
  1539. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1540. countSQL += " AND x.inspect_date <=?"
  1541. countParams = append(countParams, decEndStrsUnix)
  1542. }
  1543. countSQL += ")a GROUP BY nnd"
  1544. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1545. }
  1546. return
  1547. }
  1548. 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) {
  1549. if lapseto == 0 {
  1550. d := XTReadDB().Table("xt_patients as s")
  1551. fmt.Println("d", d)
  1552. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1553. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1554. "SELECT " +
  1555. "CASE " +
  1556. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1557. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1558. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1559. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1560. " ELSE '其他'" +
  1561. "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)"
  1562. countParams := make([]interface{}, 0)
  1563. countParams = append(countParams, firststart)
  1564. countParams = append(countParams, firstend)
  1565. countParams = append(countParams, sencondstart)
  1566. countParams = append(countParams, sencondend)
  1567. countParams = append(countParams, threestart)
  1568. countParams = append(countParams, threeend)
  1569. countParams = append(countParams, fourstart)
  1570. countParams = append(countParams, fourend)
  1571. if orgid > 0 {
  1572. db = db.Where("x.org_id=?", orgid)
  1573. countSQL += " AND x.org_id=?"
  1574. countParams = append(countParams, orgid)
  1575. }
  1576. if modetype > 0 {
  1577. db = db.Where("x.item_id = ?", modetype)
  1578. countSQL += " AND x.item_id=?"
  1579. countParams = append(countParams, modetype)
  1580. }
  1581. if startime > 0 {
  1582. db = db.Where("x.inspect_date >= ?", startime)
  1583. countSQL += " AND x.inspect_date >=?"
  1584. countParams = append(countParams, startime)
  1585. }
  1586. if endtime > 0 {
  1587. db = db.Where("x.inspect_date <= ?", endtime)
  1588. countSQL += " AND x.inspect_date <=?"
  1589. countParams = append(countParams, endtime)
  1590. }
  1591. countSQL += ")a GROUP BY nnd"
  1592. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1593. }
  1594. if lapseto == 1 {
  1595. d := XTReadDB().Table("xt_patients as s")
  1596. fmt.Println("d", d)
  1597. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1598. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1599. "SELECT " +
  1600. "CASE " +
  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. " ELSE '其他'" +
  1606. "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)"
  1607. countParams := make([]interface{}, 0)
  1608. countParams = append(countParams, firststart)
  1609. countParams = append(countParams, firstend)
  1610. countParams = append(countParams, sencondstart)
  1611. countParams = append(countParams, sencondend)
  1612. countParams = append(countParams, threestart)
  1613. countParams = append(countParams, threeend)
  1614. countParams = append(countParams, fourstart)
  1615. countParams = append(countParams, fourend)
  1616. if orgid > 0 {
  1617. db = db.Where("x.org_id=?", orgid)
  1618. countSQL += " AND x.org_id=?"
  1619. countParams = append(countParams, orgid)
  1620. }
  1621. if modetype > 0 {
  1622. db = db.Where("x.item_id = ?", modetype)
  1623. countSQL += " AND x.item_id=?"
  1624. countParams = append(countParams, modetype)
  1625. }
  1626. if startime > 0 {
  1627. db = db.Where("x.inspect_date >= ?", startime)
  1628. countSQL += " AND x.inspect_date >=?"
  1629. countParams = append(countParams, startime)
  1630. }
  1631. if endtime > 0 {
  1632. db = db.Where("x.inspect_date <= ?", endtime)
  1633. countSQL += " AND x.inspect_date <=?"
  1634. countParams = append(countParams, endtime)
  1635. }
  1636. countSQL += ")a GROUP BY nnd"
  1637. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1638. }
  1639. if lapseto == 2 {
  1640. d := XTReadDB().Table("xt_patients as s")
  1641. fmt.Println("d", d)
  1642. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1643. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1644. "SELECT " +
  1645. "CASE " +
  1646. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  1647. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  1648. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  1649. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  1650. " ELSE '其他'" +
  1651. "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)"
  1652. countParams := make([]interface{}, 0)
  1653. countParams = append(countParams, firststart)
  1654. countParams = append(countParams, firstend)
  1655. countParams = append(countParams, sencondstart)
  1656. countParams = append(countParams, sencondend)
  1657. countParams = append(countParams, threestart)
  1658. countParams = append(countParams, threeend)
  1659. countParams = append(countParams, fourstart)
  1660. countParams = append(countParams, fourend)
  1661. if orgid > 0 {
  1662. db = db.Where("x.org_id=?", orgid)
  1663. countSQL += " AND x.org_id=?"
  1664. countParams = append(countParams, orgid)
  1665. }
  1666. if modetype > 0 {
  1667. db = db.Where("x.item_id = ?", modetype)
  1668. countSQL += " AND x.item_id=?"
  1669. countParams = append(countParams, modetype)
  1670. }
  1671. if startime > 0 {
  1672. db = db.Where("x.inspect_date >= ?", startime)
  1673. countSQL += " AND x.inspect_date >=?"
  1674. countParams = append(countParams, startime)
  1675. }
  1676. if endtime > 0 {
  1677. db = db.Where("x.inspect_date <= ?", endtime)
  1678. countSQL += " AND x.inspect_date <=?"
  1679. countParams = append(countParams, endtime)
  1680. }
  1681. countSQL += ")a GROUP BY nnd"
  1682. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1683. }
  1684. return
  1685. }
  1686. 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) {
  1687. if lapseto == 0 {
  1688. d := XTReadDB().Table("xt_patients as s")
  1689. fmt.Println("d", d)
  1690. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1691. table := XTReadDB().Table("xt_quality_control_standard as r")
  1692. fmt.Println(table)
  1693. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1694. "SELECT " +
  1695. "CASE " +
  1696. " 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 '一月'" +
  1697. " 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 '二月'" +
  1698. " 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 '三月'" +
  1699. " 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 '四月'" +
  1700. " 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 '五月'" +
  1701. " 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 '六月'" +
  1702. " 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 '七月'" +
  1703. " 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 '八月'" +
  1704. " 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 '九月'" +
  1705. " 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 '十月'" +
  1706. " 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 '十一月'" +
  1707. " 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 '十二月'" +
  1708. " ELSE '其他'" +
  1709. "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 )"
  1710. countParams := make([]interface{}, 0)
  1711. countParams = append(countParams, januaryStartStrUnix)
  1712. countParams = append(countParams, januaryEndStrUnix)
  1713. countParams = append(countParams, febStartStrStrUnix)
  1714. countParams = append(countParams, febEndStrUnix)
  1715. countParams = append(countParams, marchStartStrUnix)
  1716. countParams = append(countParams, marchEndStrUnix)
  1717. countParams = append(countParams, aprStartStrUnix)
  1718. countParams = append(countParams, aprEndStrsUnix)
  1719. countParams = append(countParams, mayStartStrUnix)
  1720. countParams = append(countParams, mayEndStrsUnix)
  1721. countParams = append(countParams, junStartStrUnix)
  1722. countParams = append(countParams, junEndStrsUnix)
  1723. countParams = append(countParams, julStartStrUnix)
  1724. countParams = append(countParams, julEndStrsUnix)
  1725. countParams = append(countParams, augStartStrUnix)
  1726. countParams = append(countParams, augEndStrsUnix)
  1727. countParams = append(countParams, sepStartStrUnix)
  1728. countParams = append(countParams, sepEndStrsUnix)
  1729. countParams = append(countParams, octStartStrUnix)
  1730. countParams = append(countParams, octEndStrsUnix)
  1731. countParams = append(countParams, novStartStrUnix)
  1732. countParams = append(countParams, novEndStrsUnix)
  1733. countParams = append(countParams, decStartStrUnix)
  1734. countParams = append(countParams, decEndStrsUnix)
  1735. if orgid > 0 {
  1736. db = db.Where("x.org_id=?", orgid)
  1737. countSQL += " AND x.org_id=?"
  1738. countParams = append(countParams, orgid)
  1739. }
  1740. if orgid > 0 {
  1741. db = db.Where("r.user_org_id=?", orgid)
  1742. countSQL += " AND r.user_org_id=?"
  1743. countParams = append(countParams, orgid)
  1744. }
  1745. if modetype > 0 {
  1746. db = db.Where("x.item_id = ?", modetype)
  1747. countSQL += " AND x.item_id=?"
  1748. countParams = append(countParams, modetype)
  1749. }
  1750. if januaryStartStrUnix > 0 {
  1751. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1752. countSQL += " AND x.inspect_date >=?"
  1753. countParams = append(countParams, januaryStartStrUnix)
  1754. }
  1755. if decEndStrsUnix > 0 {
  1756. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1757. countSQL += " AND x.inspect_date <=?"
  1758. countParams = append(countParams, decEndStrsUnix)
  1759. }
  1760. countSQL += ")a GROUP BY nnd"
  1761. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1762. }
  1763. if lapseto == 1 {
  1764. d := XTReadDB().Table("xt_patients as s")
  1765. fmt.Println("d", d)
  1766. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1767. table := XTReadDB().Table("xt_quality_control_standard as r")
  1768. fmt.Println(table)
  1769. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1770. "SELECT " +
  1771. "CASE " +
  1772. " 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 '一月'" +
  1773. " 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 '二月'" +
  1774. " 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 '三月'" +
  1775. " 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 '四月'" +
  1776. " 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 '五月'" +
  1777. " 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 '六月'" +
  1778. " 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 '七月'" +
  1779. " 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 '八月'" +
  1780. " 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 '九月'" +
  1781. " 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 '十月'" +
  1782. " 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 '十一月'" +
  1783. " 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 '十二月'" +
  1784. " ELSE '其他'" +
  1785. "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 )"
  1786. countParams := make([]interface{}, 0)
  1787. countParams = append(countParams, januaryStartStrUnix)
  1788. countParams = append(countParams, januaryEndStrUnix)
  1789. countParams = append(countParams, febStartStrStrUnix)
  1790. countParams = append(countParams, febEndStrUnix)
  1791. countParams = append(countParams, marchStartStrUnix)
  1792. countParams = append(countParams, marchEndStrUnix)
  1793. countParams = append(countParams, aprStartStrUnix)
  1794. countParams = append(countParams, aprEndStrsUnix)
  1795. countParams = append(countParams, mayStartStrUnix)
  1796. countParams = append(countParams, mayEndStrsUnix)
  1797. countParams = append(countParams, junStartStrUnix)
  1798. countParams = append(countParams, junEndStrsUnix)
  1799. countParams = append(countParams, julStartStrUnix)
  1800. countParams = append(countParams, julEndStrsUnix)
  1801. countParams = append(countParams, augStartStrUnix)
  1802. countParams = append(countParams, augEndStrsUnix)
  1803. countParams = append(countParams, sepStartStrUnix)
  1804. countParams = append(countParams, sepEndStrsUnix)
  1805. countParams = append(countParams, octStartStrUnix)
  1806. countParams = append(countParams, octEndStrsUnix)
  1807. countParams = append(countParams, novStartStrUnix)
  1808. countParams = append(countParams, novEndStrsUnix)
  1809. countParams = append(countParams, decStartStrUnix)
  1810. countParams = append(countParams, decEndStrsUnix)
  1811. if orgid > 0 {
  1812. db = db.Where("x.org_id=?", orgid)
  1813. countSQL += " AND x.org_id=?"
  1814. countParams = append(countParams, orgid)
  1815. }
  1816. if orgid > 0 {
  1817. db = db.Where("r.user_org_id=?", orgid)
  1818. countSQL += " AND r.user_org_id=?"
  1819. countParams = append(countParams, orgid)
  1820. }
  1821. if modetype > 0 {
  1822. db = db.Where("x.item_id = ?", modetype)
  1823. countSQL += " AND x.item_id=?"
  1824. countParams = append(countParams, modetype)
  1825. }
  1826. if januaryStartStrUnix > 0 {
  1827. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1828. countSQL += " AND x.inspect_date >=?"
  1829. countParams = append(countParams, januaryStartStrUnix)
  1830. }
  1831. if decEndStrsUnix > 0 {
  1832. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1833. countSQL += " AND x.inspect_date <=?"
  1834. countParams = append(countParams, decEndStrsUnix)
  1835. }
  1836. countSQL += ")a GROUP BY nnd"
  1837. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1838. }
  1839. if lapseto == 2 {
  1840. d := XTReadDB().Table("xt_patients as s")
  1841. fmt.Println("d", d)
  1842. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 1")
  1843. table := XTReadDB().Table("xt_quality_control_standard as r")
  1844. fmt.Println(table)
  1845. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1846. "SELECT " +
  1847. "CASE " +
  1848. " 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 '一月'" +
  1849. " 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 '二月'" +
  1850. " 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 '三月'" +
  1851. " 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 '四月'" +
  1852. " 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 '五月'" +
  1853. " 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 '六月'" +
  1854. " 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 '七月'" +
  1855. " 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 '八月'" +
  1856. " 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 '九月'" +
  1857. " 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 '十月'" +
  1858. " 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 '十一月'" +
  1859. " 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 '十二月'" +
  1860. " ELSE '其他'" +
  1861. "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 )"
  1862. countParams := make([]interface{}, 0)
  1863. countParams = append(countParams, januaryStartStrUnix)
  1864. countParams = append(countParams, januaryEndStrUnix)
  1865. countParams = append(countParams, febStartStrStrUnix)
  1866. countParams = append(countParams, febEndStrUnix)
  1867. countParams = append(countParams, marchStartStrUnix)
  1868. countParams = append(countParams, marchEndStrUnix)
  1869. countParams = append(countParams, aprStartStrUnix)
  1870. countParams = append(countParams, aprEndStrsUnix)
  1871. countParams = append(countParams, mayStartStrUnix)
  1872. countParams = append(countParams, mayEndStrsUnix)
  1873. countParams = append(countParams, junStartStrUnix)
  1874. countParams = append(countParams, junEndStrsUnix)
  1875. countParams = append(countParams, julStartStrUnix)
  1876. countParams = append(countParams, julEndStrsUnix)
  1877. countParams = append(countParams, augStartStrUnix)
  1878. countParams = append(countParams, augEndStrsUnix)
  1879. countParams = append(countParams, sepStartStrUnix)
  1880. countParams = append(countParams, sepEndStrsUnix)
  1881. countParams = append(countParams, octStartStrUnix)
  1882. countParams = append(countParams, octEndStrsUnix)
  1883. countParams = append(countParams, novStartStrUnix)
  1884. countParams = append(countParams, novEndStrsUnix)
  1885. countParams = append(countParams, decStartStrUnix)
  1886. countParams = append(countParams, decEndStrsUnix)
  1887. if orgid > 0 {
  1888. db = db.Where("x.org_id=?", orgid)
  1889. countSQL += " AND x.org_id=?"
  1890. countParams = append(countParams, orgid)
  1891. }
  1892. if orgid > 0 {
  1893. db = db.Where("r.user_org_id=?", orgid)
  1894. countSQL += " AND r.user_org_id=?"
  1895. countParams = append(countParams, orgid)
  1896. }
  1897. if modetype > 0 {
  1898. db = db.Where("x.item_id = ?", modetype)
  1899. countSQL += " AND x.item_id=?"
  1900. countParams = append(countParams, modetype)
  1901. }
  1902. if januaryStartStrUnix > 0 {
  1903. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1904. countSQL += " AND x.inspect_date >=?"
  1905. countParams = append(countParams, januaryStartStrUnix)
  1906. }
  1907. if decEndStrsUnix > 0 {
  1908. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1909. countSQL += " AND x.inspect_date <=?"
  1910. countParams = append(countParams, decEndStrsUnix)
  1911. }
  1912. countSQL += ")a GROUP BY nnd"
  1913. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1914. }
  1915. return
  1916. }
  1917. 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) {
  1918. if lapseto == 0 {
  1919. d := XTReadDB().Table("xt_patients as s")
  1920. fmt.Println("d", d)
  1921. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1922. table := XTReadDB().Table("xt_quality_control_standard as r")
  1923. fmt.Println(table)
  1924. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1925. "SELECT " +
  1926. "CASE " +
  1927. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  1928. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  1929. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  1930. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  1931. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  1932. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  1933. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  1934. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  1935. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  1936. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  1937. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  1938. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  1939. " ELSE '其他'" +
  1940. "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)"
  1941. countParams := make([]interface{}, 0)
  1942. countParams = append(countParams, januaryStartStrUnix)
  1943. countParams = append(countParams, januaryEndStrUnix)
  1944. countParams = append(countParams, febStartStrStrUnix)
  1945. countParams = append(countParams, febEndStrUnix)
  1946. countParams = append(countParams, marchStartStrUnix)
  1947. countParams = append(countParams, marchEndStrUnix)
  1948. countParams = append(countParams, aprStartStrUnix)
  1949. countParams = append(countParams, aprEndStrsUnix)
  1950. countParams = append(countParams, mayStartStrUnix)
  1951. countParams = append(countParams, mayEndStrsUnix)
  1952. countParams = append(countParams, junStartStrUnix)
  1953. countParams = append(countParams, junEndStrsUnix)
  1954. countParams = append(countParams, julStartStrUnix)
  1955. countParams = append(countParams, julEndStrsUnix)
  1956. countParams = append(countParams, augStartStrUnix)
  1957. countParams = append(countParams, augEndStrsUnix)
  1958. countParams = append(countParams, sepStartStrUnix)
  1959. countParams = append(countParams, sepEndStrsUnix)
  1960. countParams = append(countParams, octStartStrUnix)
  1961. countParams = append(countParams, octEndStrsUnix)
  1962. countParams = append(countParams, novStartStrUnix)
  1963. countParams = append(countParams, novEndStrsUnix)
  1964. countParams = append(countParams, decStartStrUnix)
  1965. countParams = append(countParams, decEndStrsUnix)
  1966. if orgid > 0 {
  1967. db = db.Where("x.org_id=?", orgid)
  1968. countSQL += " AND x.org_id=?"
  1969. countParams = append(countParams, orgid)
  1970. }
  1971. if orgid > 0 {
  1972. db = db.Where("r.user_org_id=?", orgid)
  1973. countSQL += " AND r.user_org_id=?"
  1974. countParams = append(countParams, orgid)
  1975. }
  1976. if modetype > 0 {
  1977. db = db.Where("x.item_id = ?", modetype)
  1978. countSQL += " AND x.item_id=?"
  1979. countParams = append(countParams, modetype)
  1980. }
  1981. if januaryStartStrUnix > 0 {
  1982. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1983. countSQL += " AND x.inspect_date >=?"
  1984. countParams = append(countParams, januaryStartStrUnix)
  1985. }
  1986. if decEndStrsUnix > 0 {
  1987. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1988. countSQL += " AND x.inspect_date <=?"
  1989. countParams = append(countParams, decEndStrsUnix)
  1990. }
  1991. countSQL += ")a GROUP BY nnd"
  1992. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1993. }
  1994. if lapseto == 1 {
  1995. d := XTReadDB().Table("xt_patients as s")
  1996. fmt.Println("d", d)
  1997. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  1998. table := XTReadDB().Table("xt_quality_control_standard as r")
  1999. fmt.Println(table)
  2000. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2001. "SELECT " +
  2002. "CASE " +
  2003. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2004. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2005. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2006. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2007. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2008. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2009. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2010. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2011. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2012. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2013. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2014. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2015. " ELSE '其他'" +
  2016. "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)"
  2017. countParams := make([]interface{}, 0)
  2018. countParams = append(countParams, januaryStartStrUnix)
  2019. countParams = append(countParams, januaryEndStrUnix)
  2020. countParams = append(countParams, febStartStrStrUnix)
  2021. countParams = append(countParams, febEndStrUnix)
  2022. countParams = append(countParams, marchStartStrUnix)
  2023. countParams = append(countParams, marchEndStrUnix)
  2024. countParams = append(countParams, aprStartStrUnix)
  2025. countParams = append(countParams, aprEndStrsUnix)
  2026. countParams = append(countParams, mayStartStrUnix)
  2027. countParams = append(countParams, mayEndStrsUnix)
  2028. countParams = append(countParams, junStartStrUnix)
  2029. countParams = append(countParams, junEndStrsUnix)
  2030. countParams = append(countParams, julStartStrUnix)
  2031. countParams = append(countParams, julEndStrsUnix)
  2032. countParams = append(countParams, augStartStrUnix)
  2033. countParams = append(countParams, augEndStrsUnix)
  2034. countParams = append(countParams, sepStartStrUnix)
  2035. countParams = append(countParams, sepEndStrsUnix)
  2036. countParams = append(countParams, octStartStrUnix)
  2037. countParams = append(countParams, octEndStrsUnix)
  2038. countParams = append(countParams, novStartStrUnix)
  2039. countParams = append(countParams, novEndStrsUnix)
  2040. countParams = append(countParams, decStartStrUnix)
  2041. countParams = append(countParams, decEndStrsUnix)
  2042. if orgid > 0 {
  2043. db = db.Where("x.org_id=?", orgid)
  2044. countSQL += " AND x.org_id=?"
  2045. countParams = append(countParams, orgid)
  2046. }
  2047. if orgid > 0 {
  2048. db = db.Where("r.user_org_id=?", orgid)
  2049. countSQL += " AND r.user_org_id=?"
  2050. countParams = append(countParams, orgid)
  2051. }
  2052. if modetype > 0 {
  2053. db = db.Where("x.item_id = ?", modetype)
  2054. countSQL += " AND x.item_id=?"
  2055. countParams = append(countParams, modetype)
  2056. }
  2057. if januaryStartStrUnix > 0 {
  2058. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2059. countSQL += " AND x.inspect_date >=?"
  2060. countParams = append(countParams, januaryStartStrUnix)
  2061. }
  2062. if decEndStrsUnix > 0 {
  2063. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2064. countSQL += " AND x.inspect_date <=?"
  2065. countParams = append(countParams, decEndStrsUnix)
  2066. }
  2067. countSQL += ")a GROUP BY nnd"
  2068. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2069. }
  2070. if lapseto == 2 {
  2071. d := XTReadDB().Table("xt_patients as s")
  2072. fmt.Println("d", d)
  2073. db := readDb.Table("xt_inspection as x ").Where("x.status=1 and x.inspect_type = 2")
  2074. table := XTReadDB().Table("xt_quality_control_standard as r")
  2075. fmt.Println(table)
  2076. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  2077. "SELECT " +
  2078. "CASE " +
  2079. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '一月'" +
  2080. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '二月'" +
  2081. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '三月'" +
  2082. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '四月'" +
  2083. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '五月'" +
  2084. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '六月'" +
  2085. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '七月'" +
  2086. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '八月'" +
  2087. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '九月'" +
  2088. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十月'" +
  2089. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十一月'" +
  2090. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value = r.range_value THEN '十二月'" +
  2091. " ELSE '其他'" +
  2092. "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)"
  2093. countParams := make([]interface{}, 0)
  2094. countParams = append(countParams, januaryStartStrUnix)
  2095. countParams = append(countParams, januaryEndStrUnix)
  2096. countParams = append(countParams, febStartStrStrUnix)
  2097. countParams = append(countParams, febEndStrUnix)
  2098. countParams = append(countParams, marchStartStrUnix)
  2099. countParams = append(countParams, marchEndStrUnix)
  2100. countParams = append(countParams, aprStartStrUnix)
  2101. countParams = append(countParams, aprEndStrsUnix)
  2102. countParams = append(countParams, mayStartStrUnix)
  2103. countParams = append(countParams, mayEndStrsUnix)
  2104. countParams = append(countParams, junStartStrUnix)
  2105. countParams = append(countParams, junEndStrsUnix)
  2106. countParams = append(countParams, julStartStrUnix)
  2107. countParams = append(countParams, julEndStrsUnix)
  2108. countParams = append(countParams, augStartStrUnix)
  2109. countParams = append(countParams, augEndStrsUnix)
  2110. countParams = append(countParams, sepStartStrUnix)
  2111. countParams = append(countParams, sepEndStrsUnix)
  2112. countParams = append(countParams, octStartStrUnix)
  2113. countParams = append(countParams, octEndStrsUnix)
  2114. countParams = append(countParams, novStartStrUnix)
  2115. countParams = append(countParams, novEndStrsUnix)
  2116. countParams = append(countParams, decStartStrUnix)
  2117. countParams = append(countParams, decEndStrsUnix)
  2118. if orgid > 0 {
  2119. db = db.Where("x.org_id=?", orgid)
  2120. countSQL += " AND x.org_id=?"
  2121. countParams = append(countParams, orgid)
  2122. }
  2123. if orgid > 0 {
  2124. db = db.Where("r.user_org_id=?", orgid)
  2125. countSQL += " AND r.user_org_id=?"
  2126. countParams = append(countParams, orgid)
  2127. }
  2128. if modetype > 0 {
  2129. db = db.Where("x.item_id = ?", modetype)
  2130. countSQL += " AND x.item_id=?"
  2131. countParams = append(countParams, modetype)
  2132. }
  2133. if januaryStartStrUnix > 0 {
  2134. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  2135. countSQL += " AND x.inspect_date >=?"
  2136. countParams = append(countParams, januaryStartStrUnix)
  2137. }
  2138. if decEndStrsUnix > 0 {
  2139. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  2140. countSQL += " AND x.inspect_date <=?"
  2141. countParams = append(countParams, decEndStrsUnix)
  2142. }
  2143. countSQL += ")a GROUP BY nnd"
  2144. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  2145. }
  2146. return
  2147. }
  2148. func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2149. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2150. table := readDb.Table("xt_patients as s")
  2151. fmt.Println(table)
  2152. d := readDb.Table(" xt_inspection_reference as r")
  2153. fmt.Println(d)
  2154. if orgid > 0 {
  2155. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2156. }
  2157. if lapstor == 0 {
  2158. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2159. }
  2160. if lapstor == 1 {
  2161. db = db.Where("s.lapseto = 1")
  2162. }
  2163. if lapstor == 2 {
  2164. db = db.Where("s.lapseto = 2")
  2165. }
  2166. if startime > 0 {
  2167. db = db.Where("x.inspect_date >=?", startime)
  2168. }
  2169. if endtime > 0 {
  2170. db = db.Where("x.inspect_date <=?", endtime)
  2171. }
  2172. offset := (page - 1) * limit
  2173. 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", orgid).Group("x.inspect_date").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  2174. return inspection, total, err
  2175. }
  2176. //func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2177. //
  2178. // db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2179. // table := readDb.Table("xt_patients as s")
  2180. // fmt.Println(table)
  2181. // d := readDb.Table(" xt_inspection_reference as r")
  2182. // fmt.Println(d)
  2183. //
  2184. // if orgid > 0 {
  2185. // db = db.Where("x.org_id = ?", orgid)
  2186. // }
  2187. // if lapstor == 0 {
  2188. // table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2189. // }
  2190. // if lapstor == 1 {
  2191. // db = db.Where("s.lapseto = 1")
  2192. // }
  2193. // if lapstor == 2 {
  2194. // db = db.Where("s.lapseto = 2")
  2195. // }
  2196. // if startime > 0 {
  2197. // db = db.Where("x.inspect_date >=?", startime)
  2198. // }
  2199. // if endtime > 0 {
  2200. // db = db.Where("x.inspect_date <=?", endtime)
  2201. // }
  2202. // offset := (page - 1) * limit
  2203. // 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
  2204. //
  2205. // return inspection, total, err
  2206. //}
  2207. func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2208. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2209. table := readDb.Table("xt_patients as s")
  2210. fmt.Println(table)
  2211. d := readDb.Table(" xt_inspection_reference as r")
  2212. fmt.Println(d)
  2213. d2 := readDb.Table("xt_quality_control_standard as d")
  2214. fmt.Println("d2", d2)
  2215. if orgid > 0 {
  2216. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1", orgid)
  2217. }
  2218. if lapstor == 0 {
  2219. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2220. }
  2221. if lapstor == 1 {
  2222. table = table.Where("s.lapseto = 1")
  2223. }
  2224. if lapstor == 2 {
  2225. table = table.Where("s.lapseto = 2")
  2226. }
  2227. if startime > 0 {
  2228. db = db.Where("x.inspect_date >=?", startime)
  2229. }
  2230. if endtime > 0 {
  2231. db = db.Where("x.inspect_date <=?", endtime)
  2232. }
  2233. 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 = ?", orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2234. return inspection, err
  2235. }
  2236. func GetTotalPatientsControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2237. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2238. table := readDb.Table("xt_quality_control_standard as s")
  2239. fmt.Println(table)
  2240. if orgid > 0 {
  2241. db = db.Where("x.org_id = ? and x.inspect_value <> ''", orgid)
  2242. }
  2243. if startime > 0 {
  2244. db = db.Where("x.inspect_date >=?", startime)
  2245. }
  2246. if endtime > 0 {
  2247. db = db.Where("x.inspect_date <=?", endtime)
  2248. }
  2249. 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").Count(&total).Scan(&inspection).Error
  2250. return inspection, total, err
  2251. }
  2252. func GetStandControl(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2253. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2254. table := readDb.Table("xt_quality_control_standard as s")
  2255. fmt.Println(table)
  2256. if orgid > 0 {
  2257. db = db.Where("x.org_id = ? and x.inspect_value+0 <> 0 and x.inspect_type = 1 ", orgid)
  2258. }
  2259. if startime > 0 {
  2260. db = db.Where("x.inspect_date >=?", startime)
  2261. }
  2262. if endtime > 0 {
  2263. db = db.Where("x.inspect_date <=?", endtime)
  2264. }
  2265. db = db.Where("s.status = 1")
  2266. 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
  2267. return inspection, total, err
  2268. }
  2269. func GetStandControlOne(orgid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  2270. db := readDb.Table("xt_inspection as x").Where("x.status = 1")
  2271. table := readDb.Table("xt_quality_control_standard as s")
  2272. fmt.Println(table)
  2273. if orgid > 0 {
  2274. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2 ", orgid)
  2275. }
  2276. if startime > 0 {
  2277. db = db.Where("x.inspect_date >=?", startime)
  2278. }
  2279. if endtime > 0 {
  2280. db = db.Where("x.inspect_date <=?", endtime)
  2281. }
  2282. db = db.Where("s.status = 1")
  2283. 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
  2284. return inspection, total, err
  2285. }
  2286. func GetInfectiousPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2287. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2288. table := readDb.Table("xt_patients as s")
  2289. fmt.Println(table)
  2290. d := readDb.Table(" xt_inspection_reference as r")
  2291. fmt.Println(d)
  2292. d2 := readDb.Table("xt_quality_control_standard as d")
  2293. fmt.Println("d2", d2)
  2294. if orgid > 0 {
  2295. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2296. }
  2297. if lapstor == 0 {
  2298. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2299. }
  2300. if lapstor == 1 {
  2301. table = table.Where("s.lapseto = 1")
  2302. }
  2303. if lapstor == 2 {
  2304. table = table.Where("s.lapseto = 2")
  2305. }
  2306. if startime > 0 {
  2307. db = db.Where("x.inspect_date >=?", startime)
  2308. }
  2309. if endtime > 0 {
  2310. db = db.Where("x.inspect_date <=?", endtime)
  2311. }
  2312. 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
  2313. return inspection, err
  2314. }
  2315. func GetInfectiousControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2316. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2317. table := readDb.Table("xt_patients as s")
  2318. fmt.Println(table)
  2319. d := readDb.Table(" xt_inspection_reference as r")
  2320. fmt.Println(d)
  2321. d2 := readDb.Table("xt_quality_control_standard as d")
  2322. fmt.Println("d2", d2)
  2323. if orgid > 0 {
  2324. db = db.Where("x.org_id = ? and x.inspect_value <> '' and x.inspect_type = 2", orgid)
  2325. }
  2326. if lapstor == 0 {
  2327. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2328. }
  2329. if lapstor == 1 {
  2330. table = table.Where("s.lapseto = 1")
  2331. }
  2332. if lapstor == 2 {
  2333. table = table.Where("s.lapseto = 2")
  2334. }
  2335. if startime > 0 {
  2336. db = db.Where("x.inspect_date >=?", startime)
  2337. }
  2338. if endtime > 0 {
  2339. db = db.Where("x.inspect_date <=?", endtime)
  2340. }
  2341. 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 = ?", orgid).Order("x.inspect_date desc").Scan(&inspection).Error
  2342. return inspection, err
  2343. }
  2344. func GetPatientContor(lapstor, orgid int64, keywords string, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2345. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2346. table := readDb.Table("xt_patients as s")
  2347. fmt.Println(table)
  2348. d := readDb.Table(" xt_inspection_reference as r")
  2349. fmt.Println(d)
  2350. d2 := readDb.Table("xt_quality_control_standard as d")
  2351. fmt.Println("d2", d2)
  2352. if len(keywords) > 0 {
  2353. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", keywords, keywords)
  2354. }
  2355. if orgid > 0 {
  2356. db = db.Where("x.org_id = ?", orgid)
  2357. }
  2358. if lapstor == 0 {
  2359. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  2360. }
  2361. if lapstor == 1 {
  2362. table = table.Where("s.lapseto = 1")
  2363. }
  2364. if lapstor == 2 {
  2365. table = table.Where("s.lapseto = 2")
  2366. }
  2367. if startime > 0 {
  2368. db = db.Where("x.inspect_date >=?", startime)
  2369. }
  2370. if endtime > 0 {
  2371. db = db.Where("x.inspect_date <=?", endtime)
  2372. }
  2373. 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
  2374. return inspection, err
  2375. }
  2376. func GetPatientNames(orgid int64, patientid int64) (models.XtPatients, error) {
  2377. patients := models.XtPatients{}
  2378. err := readDb.Where("user_org_id = ? and id = ? and status = 1", orgid, patientid).Find(&patients).Error
  2379. return patients, err
  2380. }
  2381. func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime int64, itemid int64, inspectdate int64) (inspection []*models.PatientInspectionCount, err error) {
  2382. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2383. table := readDb.Table("xt_patients as s")
  2384. fmt.Println(table)
  2385. d := readDb.Table(" xt_inspection_reference as r")
  2386. fmt.Println(d)
  2387. d2 := readDb.Table("xt_quality_control_standard as d")
  2388. fmt.Println("d2", d2)
  2389. if orgid > 0 {
  2390. db = db.Where("x.org_id = ?", orgid)
  2391. }
  2392. if patientid > 0 {
  2393. db = db.Where("x.patient_id = ?", patientid)
  2394. }
  2395. //if startime > 0 {
  2396. // db = db.Where("x.inspect_date >=?", startime)
  2397. //}
  2398. //if endtime > 0 {
  2399. // db = db.Where("x.inspect_date <=?", endtime)
  2400. //}
  2401. if itemid > 0 {
  2402. db = db.Where("x.item_id = ?", itemid)
  2403. }
  2404. if inspectdate > 0 {
  2405. db = db.Where("x.inspect_date = ?", inspectdate)
  2406. }
  2407. 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
  2408. return inspection, err
  2409. }
  2410. func GetPatientComplianceDetail(orgid int64, patientid int64, startime int64, endtime int64, itemid int64) (inspection []*models.PatientInspectionCount, err error) {
  2411. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2412. table := readDb.Table("xt_patients as s")
  2413. fmt.Println(table)
  2414. d := readDb.Table(" xt_inspection_reference as r")
  2415. fmt.Println(d)
  2416. d2 := readDb.Table("xt_quality_control_standard as d")
  2417. fmt.Println("d2", d2)
  2418. if orgid > 0 {
  2419. db = db.Where("x.org_id = ? and (x.inspect_value <> '' or x.inspect_value+0 <> 0)", orgid)
  2420. }
  2421. if patientid > 0 {
  2422. db = db.Where("x.patient_id = ?", patientid)
  2423. }
  2424. if startime > 0 {
  2425. db = db.Where("x.inspect_date >=?", startime)
  2426. }
  2427. if endtime > 0 {
  2428. db = db.Where("x.inspect_date <=?", endtime)
  2429. }
  2430. if itemid > 0 {
  2431. db = db.Where("x.item_id = ?", itemid)
  2432. }
  2433. 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
  2434. return inspection, err
  2435. }
  2436. func GetLastPatientsControlTwo(orgid int64, patientid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  2437. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  2438. table := readDb.Table("xt_patients as s")
  2439. fmt.Println(table)
  2440. d := readDb.Table(" xt_inspection_reference as r")
  2441. fmt.Println(d)
  2442. d2 := readDb.Table("xt_quality_control_standard as d")
  2443. fmt.Println("d2", d2)
  2444. if orgid > 0 {
  2445. db = db.Where("x.org_id = ?", orgid)
  2446. }
  2447. if patientid > 0 {
  2448. db = db.Where("x.patient_id = ?", patientid)
  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.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
  2457. return inspection, err
  2458. }