common_service.go 125KB

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