common_service.go 80KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  9. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
  10. return inspection, err
  11. }
  12. func GetInspectionMinor(projectid int64, orgid int64) (inspection []*models.XtInspectionReference, err error) {
  13. err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1 and org_id = ?", projectid, orgid).Find(&inspection).Error
  14. return inspection, err
  15. }
  16. func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
  17. reference := models.XtInspectionReference{}
  18. err := XTReadDB().Model(&reference).Where("id=? and status = 1", id).Find(&reference).Error
  19. return reference, err
  20. }
  21. func GetConfigurationById(major int64, moni int64, orgid int64) (*models.XtQualityControlStandard, error) {
  22. standard := models.XtQualityControlStandard{}
  23. err := XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).Find(&standard).Error
  24. if err == gorm.ErrRecordNotFound {
  25. return nil, err
  26. }
  27. if err != nil {
  28. return nil, err
  29. }
  30. return &standard, nil
  31. }
  32. func GetConfigurationByIdTwo(major int64, moni int64, orgid int64) (standard models.XtQualityControlStandard, err error) {
  33. err = XTReadDB().Model(&standard).Where("inspection_major = ? and inspection_minor = ? and user_org_id = ? and status = 1", major, moni, orgid).First(&standard).Error
  34. return standard, err
  35. }
  36. func SaveInspection(standard *models.XtQualityControlStandard) error {
  37. err := XTWriteDB().Create(&standard).Error
  38. return err
  39. }
  40. func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  41. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  42. if orgid > 0 {
  43. db = db.Where("x.user_org_id = ?", orgid)
  44. }
  45. table := XTReadDB().Table("xt_inspection_reference as s")
  46. fmt.Println(table)
  47. offset := (page - 1) * limit
  48. 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,s.unit,s.project_name,s.item_name").Count(&total).
  49. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
  50. return standard, total, err
  51. }
  52. func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
  53. standard := models.XtQualityControlStandard{}
  54. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  55. return standard, err
  56. }
  57. func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
  58. err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
  59. return standard, err
  60. }
  61. func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
  62. 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, "updated_time": time.Now().Unix()}).Error
  63. return err
  64. }
  65. func DeleteConfiguration(id int64) (err error) {
  66. err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  67. return err
  68. }
  69. func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
  70. diseases := models.XtInspectionReference{}
  71. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  72. if err == gorm.ErrRecordNotFound {
  73. return nil, err
  74. }
  75. if err != nil {
  76. return nil, err
  77. }
  78. return &diseases, nil
  79. }
  80. func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
  81. err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
  82. return reference, err
  83. }
  84. func GetInspectionMajorById(marjor int64, orgid int64) (*models.XtCheckConfiguration, error) {
  85. configuration := models.XtCheckConfiguration{}
  86. err := XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).Find(&configuration).Error
  87. if err == gorm.ErrRecordNotFound {
  88. return nil, err
  89. }
  90. if err != nil {
  91. return nil, err
  92. }
  93. return &configuration, nil
  94. }
  95. func GetInspectionMajorByIdTwo(marjor int64, orgid int64) (configuration models.XtCheckConfiguration, err error) {
  96. err = XTReadDB().Model(&configuration).Where("inspection_major = ? and user_org_id = ? and status =1", marjor, orgid).First(&configuration).Error
  97. return configuration, err
  98. }
  99. func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
  100. err := XTWriteDB().Create(&configuration).Error
  101. return err
  102. }
  103. func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  104. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  105. table := XTReadDB().Table("xt_inspection_reference as r")
  106. fmt.Println(table)
  107. if orgid > 0 {
  108. db = db.Where("x.user_org_id = ?", orgid)
  109. }
  110. offset := (page - 1) * limit
  111. 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).
  112. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
  113. return check, total, err
  114. }
  115. func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
  116. configuration := models.XtCheckConfiguration{}
  117. err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
  118. return configuration, err
  119. }
  120. func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
  121. 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
  122. return err
  123. }
  124. func DeleteCheck(id int64) error {
  125. err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  126. return err
  127. }
  128. func GetDialysiTotal(startime int64, endtime int64, orgid int64) (order []*models.DialysisOrder, total int64, err error) {
  129. err = XTReadDB().Model(&order).Where("dialysis_date >= ? and dialysis_date<=? and user_org_id = ?", startime, endtime, orgid).Count(&total).Find(&order).Error
  130. return order, total, err
  131. }
  132. func GetDialysisCountMode(starttime int64, endtime int64, orgid int64) (counts []*models.PatientPrescriptionCountStruct, err error) {
  133. //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
  134. //return counts, err
  135. 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
  136. return counts, err
  137. }
  138. func GetTotalRollOut(starttime int64, endtime int64, orgid int64) (counts []*models.PatientLapseto, total int64, err error) {
  139. db := readDb.Table("xt_patient_lapseto as x").Where("x.status = 1")
  140. table := readDb.Table("xt_dialysis_order as s")
  141. fmt.Println(table)
  142. 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
  143. return counts, total, err
  144. }
  145. func GetTotalRollOutPatients(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
  146. db := XTReadDB().Table("x.patients as x")
  147. 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 group by s.patient_id", startime, endtime, orgid).Scan(&patients).Error
  148. return patients, err
  149. }
  150. func GetTotalRollOutPatientsTwo(orgid int64, startime int64, endtime int64) (patients []*models.XtPatients, err error) {
  151. db := XTReadDB().Table("x.patients as x")
  152. 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 group by s.patient_id", startime, endtime, orgid).Scan(&patients).Error
  153. return patients, err
  154. }
  155. func GetPatientTotalCount(orgID int64) (total int64) {
  156. readDb.Model(&models.XtPatients{}).Where("user_org_id=? and status=1", orgID).Count(&total)
  157. return
  158. }
  159. func GetPatientTotalCountTwo(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.XtDialysisOrder, total int64, err error) {
  160. 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
  161. return dialysisorder, total, err
  162. }
  163. func GetManPatientTotalCount(orgid int64, starttime int64, endtime int64) (dialysisorder []*models.SgjDialysisOrder, total int64, err error) {
  164. db := XTReadDB().Table("xt_dialysis_order as s").Where("s.status = 1")
  165. table := XTReadDB().Table("xt_patients as x")
  166. fmt.Println("table", table)
  167. 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
  168. return dialysisorder, total, err
  169. }
  170. func GetManPatientTotal(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  171. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and gender = 1", orgid).Count(&total).Find(&patients).Error
  172. return patients, total, err
  173. }
  174. //func GetPatientInfectiousCount(orgid int64, starttime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  175. // 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
  176. // return counts, err
  177. //}
  178. func GetPatientInfectiousCount(orgid int64, startime int64, endtime int64) (counts []*models.PatientContagionsCountStruct, err error) {
  179. 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 s.is_infectious = 2 and s.created_time>=? and s.created_time<=?", orgid, startime, endtime).Select("x.disease_id,count(x.disease_id) as count").Group("x.disease_id").Scan(&counts).Error
  180. return counts, err
  181. }
  182. func GetPatientOtherInfectious(orgid int64) (patients []*models.XtPatients, total int64, err error) {
  183. err = XTReadDB().Model(&patients).Where("user_org_id = ? and status = 1 and is_infectious = 1", orgid).Count(&total).Find(&patients).Error
  184. return patients, total, err
  185. }
  186. func GetTotalAgeCount(orgid int64) (counts []*models.PatientAgeCountStruct, err error) {
  187. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  188. SELECT
  189. CASE
  190. 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'
  191. 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'
  192. 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'
  193. 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'
  194. ELSE '150'
  195. END
  196. AS nnd FROM xt_patients as s where s.user_org_id=? and s.status=1
  197. )a GROUP BY nnd`, orgid).Scan(&counts)
  198. return
  199. }
  200. func GetTotalAgeCountTwo(orgid int64, starttime int64, endtime int64) (counts []*models.PatientAgeCountStruct, err error) {
  201. readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  202. SELECT
  203. CASE
  204. 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'
  205. END
  206. 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<=?
  207. )a GROUP BY nnd`, orgid, starttime, endtime).Scan(&counts)
  208. return
  209. }
  210. func GetTotalDialysisAgeCount(orgid int64) (patients []*models.XtPatients, err error) {
  211. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Find(&patients).Error
  212. return patients, err
  213. }
  214. func GetDialysisAgeData(orgID int64) (counts []*models.DialysisAgePieDataStruct, err error) {
  215. loc, _ := time.LoadLocation("Local")
  216. nowTime := time.Now()
  217. nowDay := nowTime.Format("2006-01-02")
  218. dayTime, err := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  219. fmt.Println("datTime", dayTime)
  220. if err != nil {
  221. return
  222. }
  223. oneYearPoint := dayTime.AddDate(-12, 0, 0).Unix()
  224. fiveYearPoint := dayTime.AddDate(-36, 0, 0).Unix()
  225. tenYearPoint := dayTime.AddDate(-60, 0, 0).Unix()
  226. twentyYearPoint := dayTime.AddDate(-61, 0, 0).Unix()
  227. db := readDb.Table("xt_patients").Where("status=1")
  228. countSQL := "SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(" +
  229. "SELECT " +
  230. "CASE " +
  231. " WHEN first_dialysis_date<>0 AND first_dialysis_date>? THEN '1'" +
  232. " WHEN first_dialysis_date<>0 AND first_dialysis_date>? && first_dialysis_date<=? THEN '2'" +
  233. " WHEN first_dialysis_date<>0 AND first_dialysis_date>? && first_dialysis_date<=? THEN '3'" +
  234. " WHEN first_dialysis_date<>0 AND first_dialysis_date>? && first_dialysis_date<=? THEN '4'" +
  235. " WHEN first_dialysis_date<>0 AND first_dialysis_date<=? THEN '5'" +
  236. " ELSE '0'" +
  237. "END AS nnd FROM xt_patients WHERE status=1"
  238. countParams := make([]interface{}, 0)
  239. countParams = append(countParams, oneYearPoint)
  240. countParams = append(countParams, fiveYearPoint)
  241. countParams = append(countParams, oneYearPoint)
  242. countParams = append(countParams, tenYearPoint)
  243. countParams = append(countParams, fiveYearPoint)
  244. countParams = append(countParams, twentyYearPoint)
  245. countParams = append(countParams, tenYearPoint)
  246. countParams = append(countParams, twentyYearPoint)
  247. if orgID > 0 {
  248. db = db.Where("user_org_id=?", orgID)
  249. countSQL += " AND user_org_id=?"
  250. countParams = append(countParams, orgID)
  251. }
  252. countSQL += ")a GROUP BY nnd"
  253. err = readDb.Raw(countSQL, countParams...).Scan(&counts).Error
  254. return
  255. //readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM(
  256. // SELECT
  257. // CASE
  258. // WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) >= 0
  259. // WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 12 THEN '0~12' WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 12
  260. // WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 36 THEN '12~36' WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 36
  261. // WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) <= 60 THEN '36~60' WHEN TIMESTAMPDIFF( YEAR, DATE( DATE_ADD( FROM_UNIXTIME( 0 ), INTERVAL p.first_dialysis_date SECOND ) ), curdate( ) ) > 60
  262. // ELSE '150'
  263. // END
  264. // AS nnd FROM xt_patients as p where p.user_org_id=? and p.status=1
  265. // )a GROUP BY nnd`, orgID).Scan(&counts)
  266. //return
  267. }
  268. func GetCurentOrgPatients(orgid int64) (patients []*models.XtPatients, err error) {
  269. err = XTReadDB().Where("user_org_id = ? and status =1", orgid).Order("created_time desc").Find(&patients).Error
  270. return patients, err
  271. }
  272. func GetDialysisList(startime int64, endtime int64, page int64, limit int64, orgid int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  273. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  274. table := XTReadDB().Table("xt_patients as s")
  275. fmt.Println("table", table)
  276. if orgid > 0 {
  277. db = db.Where("p.user_org_id = ?", orgid)
  278. }
  279. if startime > 0 {
  280. db = db.Where("p.record_date >= ?", startime)
  281. }
  282. if endtime > 0 {
  283. db = db.Where("p.record_date <=?", endtime)
  284. }
  285. offset := (page - 1) * limit
  286. err = db.Group("p.patient_id,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
  287. return prescription, total, err
  288. }
  289. func GetAllDialysisList(startime int64, endtime int64, orgid int64) (prescription []*models.BloodDialysisPrescription, err error) {
  290. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  291. table := XTReadDB().Table("xt_patients as s")
  292. fmt.Println(table)
  293. if orgid > 0 {
  294. db = db.Where("p.user_org_id = ?", orgid)
  295. }
  296. if startime > 0 {
  297. db = db.Where("p.record_date >= ?", startime)
  298. }
  299. if endtime > 0 {
  300. db = db.Where("p.record_date <=?", endtime)
  301. }
  302. err = db.Group("p.patient_id,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").Scan(&prescription).Error
  303. return prescription, err
  304. }
  305. func GetDialysisPatientList(startime int64, endtime int64, page int64, limit int64, orgid int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  306. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  307. table := XTReadDB().Table("xt_patients as s")
  308. fmt.Println("table", table)
  309. if orgid > 0 {
  310. db = db.Where("p.user_org_id = ?", orgid)
  311. }
  312. if startime > 0 {
  313. db = db.Where("p.record_date >= ?", startime)
  314. }
  315. if endtime > 0 {
  316. db = db.Where("p.record_date <=?", endtime)
  317. }
  318. offset := (page - 1) * limit
  319. err = db.Group("p.patient_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
  320. return prescription, total, err
  321. }
  322. func GetLastSort(orgid int64) (models.XtQualityControlStandard, error) {
  323. standard := models.XtQualityControlStandard{}
  324. err := XTReadDB().Model(&standard).Where("user_org_id = ? and status =1", orgid).Last(&standard).Error
  325. return standard, err
  326. }
  327. func GetLastCheckList(orgid int64) (models.XtCheckConfiguration, error) {
  328. configuration := models.XtCheckConfiguration{}
  329. err := XTReadDB().Model(&configuration).Where("user_org_id = ? and status =1", orgid).Last(&configuration).Error
  330. return configuration, err
  331. }
  332. func GetDialysisDetailById(id int64, orgid int64, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  333. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  334. table := XTReadDB().Table("xt_patients as s")
  335. fmt.Println(table)
  336. if id > 0 {
  337. db = db.Where("p.patient_id = ?", id)
  338. }
  339. if orgid > 0 {
  340. db = db.Where("p.user_org_id = ?", orgid)
  341. }
  342. if startime > 0 {
  343. db = db.Where("p.record_date >= ?", startime)
  344. }
  345. if endtime > 0 {
  346. db = db.Where("p.record_date <=?", endtime)
  347. }
  348. offset := (page - 1) * limit
  349. 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
  350. return prescription, total, err
  351. }
  352. func GetPrescritionByName(orgid int64, keywords string, startime int64, endtime int64, limit int64, page int64) (prescription []*models.BloodDialysisPrescription, total int64, err error) {
  353. db := XTReadDB().Table("xt_dialysis_prescription as p").Where("p.status =1 ")
  354. table := XTReadDB().Table("xt_patients as s")
  355. fmt.Println(table)
  356. if len(keywords) > 0 {
  357. likeKey := "%" + keywords + "%"
  358. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  359. }
  360. if orgid > 0 {
  361. db = db.Where("p.user_org_id = ?", orgid)
  362. }
  363. if startime > 0 {
  364. db = db.Where("p.record_date >= ?", startime)
  365. }
  366. if endtime > 0 {
  367. db = db.Where("p.record_date <=?", endtime)
  368. }
  369. offset := (page - 1) * limit
  370. 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
  371. return prescription, total, err
  372. }
  373. func GetStatistics(orgID int64, startime int64, endtime int64, lapseto int64, limit int64, page int64, modeID int64) (dtd []*DialysisTotalDataStruct, ttd []*DialysisTotalDataStruct, total int64, err error) {
  374. db := readDb
  375. sql := "s.mode_id,from_unixtime(s.record_date, '%Y%m%d') as date, count(s.record_date) as number"
  376. datesql := "s.record_date as date"
  377. group := "from_unixtime(s.record_date, '%Y%m%d')"
  378. db = db.Table("xt_dialysis_prescription as s")
  379. if orgID > 0 {
  380. db = db.Where("s.user_org_id = ?", orgID)
  381. }
  382. if modeID > 0 {
  383. db = db.Where("s.mode_id=?", modeID)
  384. }
  385. if startime > 0 {
  386. db = db.Where("s.record_date>=?", startime)
  387. }
  388. if endtime > 0 {
  389. db = db.Where("s.record_date<=?", endtime)
  390. }
  391. db = db.Where("s.status=1")
  392. if lapseto > 0 {
  393. joinString := "JOIN xt_patients as p ON s.patient_id=p.id and p.lapseto=? and p.status=1"
  394. joinParams := make([]interface{}, 0)
  395. joinParams = append(joinParams, lapseto)
  396. if orgID > 0 {
  397. joinString += "AND p.user_org_id=?"
  398. joinParams = append(joinParams, orgID)
  399. }
  400. db = db.Joins(joinString, joinParams...)
  401. }
  402. err = db.Select("s.mode_id, count(s.mode_id) as number").Group("s.mode_id").Order("s.mode_id asc").Find(&ttd).Error
  403. if err != nil {
  404. return
  405. }
  406. offset := (page - 1) * limit
  407. var ds []*DialysisTotalDataStruct
  408. err = db.Select(datesql).Group(group).Count(&total).Order("date asc").Offset(offset).Limit(limit).Find(&ds).Error
  409. if err != nil {
  410. return
  411. }
  412. dates := make([]string, 0)
  413. if len(ds) > 0 {
  414. for _, d := range ds {
  415. dates = append(dates, d.Date)
  416. }
  417. db = db.Where("s.record_date IN (?)", dates)
  418. }
  419. err = db.Select(sql).Group(group + ", s.mode_id").Order("date asc, mode_id").Find(&dtd).Error
  420. return
  421. }
  422. func GetInspectionTotalCount(orgid int64) (configuration []*models.CheckConfiguration, err error) {
  423. var count int
  424. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status = 1")
  425. table := XTReadDB().Table("xt_inspection_reference as s")
  426. if orgid > 0 {
  427. db = db.Where("x.user_org_id = ?", orgid)
  428. }
  429. fmt.Println(table)
  430. 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
  431. return configuration, err
  432. }
  433. func GetInspectionProjectCount(orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  434. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  435. table := XTReadDB().Table("xt_inspection_reference as r")
  436. fmt.Println(table)
  437. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  438. fmt.Println(d)
  439. if orgid > 0 {
  440. db = db.Where("x.org_id = ?", orgid)
  441. }
  442. if startime > 0 {
  443. db = db.Where("x.inspect_date >=?", startime)
  444. }
  445. if endtime > 0 {
  446. db = db.Where("x.inspect_date <=?", endtime)
  447. }
  448. 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("project_id,patient_id").Scan(&projectCounts).Error
  449. return
  450. }
  451. func GetInspectionDetailById(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  452. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  453. table := XTReadDB().Table("xt_inspection_reference as r")
  454. fmt.Println(table)
  455. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  456. fmt.Println(d)
  457. if id > 0 {
  458. db = db.Where("x.patient_id=?", id)
  459. }
  460. if orgid > 0 {
  461. db = db.Where("x.org_id = ?", orgid)
  462. }
  463. if startime > 0 {
  464. db = db.Where("x.inspect_date >=?", startime)
  465. }
  466. if endtime > 0 {
  467. db = db.Where("x.inspect_date <=?", endtime)
  468. }
  469. 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").Group("project_id,patient_id").Scan(&projectCounts).Error
  470. return
  471. }
  472. func GetSearchPatientInfo(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.UserInspectionProjectCounts, err error) {
  473. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  474. table := XTReadDB().Table("xt_inspection_reference as r")
  475. fmt.Println(table)
  476. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  477. fmt.Println(d)
  478. p := XTReadDB().Table("xt_patients as p")
  479. fmt.Println(p)
  480. if len(keywords) > 0 {
  481. likeKey := "%" + keywords + "%"
  482. db = db.Where("p.name LIKE ? OR p.dialysis_no LIKE ?", likeKey, likeKey)
  483. }
  484. if orgid > 0 {
  485. db = db.Where("x.org_id = ?", orgid)
  486. }
  487. if startime > 0 {
  488. db = db.Where("x.inspect_date >=?", startime)
  489. }
  490. if endtime > 0 {
  491. db = db.Where("x.inspect_date <=?", endtime)
  492. }
  493. 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
  494. return
  495. }
  496. func GetMajorInspectionByOrgid(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  497. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  498. table := XTReadDB().Table("xt_inspection_reference ar r")
  499. fmt.Println(table)
  500. 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
  501. return checkconfiguration, err
  502. }
  503. func GetDefaultByOrgId(orgid int64) (checkconfiguration []*models.CheckConfiguration, err error) {
  504. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  505. table := XTReadDB().Table("xt_inspection_reference ar r")
  506. fmt.Println(table)
  507. 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
  508. return checkconfiguration, err
  509. }
  510. func GetPatientListData(orgid int64, startime int64, endtime int64, limit int64, page int64) (inspection []*models.PatientsInspection, total int64, err error) {
  511. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  512. table := XTReadDB().Table("xt_patients as s")
  513. fmt.Println("table", table)
  514. if orgid > 0 {
  515. db = db.Where("x.org_id = ?", orgid)
  516. }
  517. if startime > 0 {
  518. db = db.Where("x.inspect_date >= ?", startime)
  519. }
  520. if endtime > 0 {
  521. db = db.Where("x.inspect_date <=?", endtime)
  522. }
  523. offset := (page - 1) * limit
  524. 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
  525. return inspection, total, err
  526. }
  527. func GetPatientListInfo(orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  528. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  529. table := XTReadDB().Table("xt_inspection_reference as r")
  530. fmt.Println(table)
  531. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  532. pa := XTReadDB().Table("xt_patients as s")
  533. fmt.Println(pa)
  534. fmt.Println(d)
  535. if orgid > 0 {
  536. db = db.Where("x.org_id = ?", orgid)
  537. }
  538. if startime > 0 {
  539. db = db.Where("x.inspect_date >=?", startime)
  540. }
  541. if endtime > 0 {
  542. db = db.Where("x.inspect_date <=?", endtime)
  543. }
  544. err = db.Select("count(distinct x.inspect_date) as count,x.patient_id,x.project_id,r.project_name,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
  545. return
  546. }
  547. func GetPatientDetailCheck(id int64, orgid int64, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  548. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  549. table := XTReadDB().Table("xt_inspection_reference as r")
  550. fmt.Println(table)
  551. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  552. pa := XTReadDB().Table("xt_patients as s")
  553. fmt.Println(pa)
  554. fmt.Println(d)
  555. if id > 0 {
  556. db = db.Where("s.id = ?", id)
  557. }
  558. if orgid > 0 {
  559. db = db.Where("x.org_id = ?", orgid)
  560. }
  561. if startime > 0 {
  562. db = db.Where("x.inspect_date >=?", startime)
  563. }
  564. if endtime > 0 {
  565. db = db.Where("x.inspect_date <=?", endtime)
  566. }
  567. 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
  568. return
  569. }
  570. func GetSearchDetailCheck(orgid int64, keywords string, startime int64, endtime int64) (projectCounts []*models.PatientInspectionProjectCount, err error) {
  571. db := XTReadDB().Table("xt_inspection as x").Where("x.status = 1")
  572. table := XTReadDB().Table("xt_inspection_reference as r")
  573. fmt.Println(table)
  574. d := XTReadDB().Table("xt_check_configuration as t").Where("t.status = 1")
  575. pa := XTReadDB().Table("xt_patients as s")
  576. fmt.Println(pa)
  577. fmt.Println(d)
  578. if len(keywords) > 0 {
  579. likeKey := "%" + keywords + "%"
  580. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", likeKey, likeKey)
  581. }
  582. if orgid > 0 {
  583. db = db.Where("x.org_id = ?", orgid)
  584. }
  585. if startime > 0 {
  586. db = db.Where("x.inspect_date >=?", startime)
  587. }
  588. if endtime > 0 {
  589. db = db.Where("x.inspect_date <=?", endtime)
  590. }
  591. 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
  592. return
  593. }
  594. func GetNormDataByOrgId(orgid int64) (standard []*models.QualityControlStandard, err error) {
  595. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  596. if orgid > 0 {
  597. db = db.Where("x.user_org_id = ?", orgid)
  598. }
  599. table := XTReadDB().Table("xt_inspection_reference as s")
  600. fmt.Println(table)
  601. 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,s.unit,s.project_name,s.item_name").
  602. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
  603. return standard, err
  604. }
  605. func GetNormData(orgid int64) (standard []*models.QualityControlStandard, err error) {
  606. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  607. if orgid > 0 {
  608. db = db.Where("x.user_org_id = ?", orgid)
  609. }
  610. table := XTReadDB().Table("xt_inspection_reference as s")
  611. fmt.Println(table)
  612. 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,s.unit,s.project_name,s.item_name").
  613. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Scan(&standard).Error
  614. return standard, err
  615. }
  616. func GetItemNameGroup(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  617. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  618. table := XTReadDB().Table("xt_inspection_reference as r")
  619. fmt.Println(table)
  620. if orgid > 0 {
  621. db = db.Where("x.org_id = ?", orgid)
  622. }
  623. if startime > 0 {
  624. db = db.Where("x.inspect_date >=?", startime)
  625. }
  626. if endtime > 0 {
  627. db = db.Where("x.inspect_date <=?", endtime)
  628. }
  629. 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
  630. return inspection, err
  631. }
  632. func GetFirstQuarter(orgid int64, startime int64, endtime int64) (inspection []*models.XtPatientInspection, err error) {
  633. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  634. table := XTReadDB().Table("xt_inspection_reference as r")
  635. fmt.Println(table)
  636. if orgid > 0 {
  637. db = db.Where("x.org_id = ?", orgid)
  638. }
  639. if startime > 0 {
  640. db = db.Where("x.inspect_date >=?", startime)
  641. }
  642. if endtime > 0 {
  643. db = db.Where("x.inspect_date <=?", endtime)
  644. }
  645. 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
  646. return inspection, err
  647. }
  648. func GetQuarterTotalCount(orgid int64, startime int64, endtime int64, lapseto int64) (inspection []*models.VmPatientInspection, err error) {
  649. db := XTReadDB().Table("xt_inspection as x ").Where("x.status = 1")
  650. table := XTReadDB().Table("xt_inspection_reference as r")
  651. fmt.Println(table)
  652. d := XTReadDB().Table("xt_patients as s")
  653. fmt.Println(d)
  654. d2 := XTReadDB().Table("xt_quality_control_standard as p")
  655. fmt.Println(d2)
  656. if orgid > 0 {
  657. db = db.Where("x.org_id = ?", orgid)
  658. }
  659. if startime > 0 {
  660. db = db.Where("x.inspect_date >=?", startime)
  661. }
  662. if endtime > 0 {
  663. db = db.Where("x.inspect_date <=?", endtime)
  664. }
  665. if lapseto == 0 {
  666. db = db.Where("s.lapseto = 1 or s.lapseto = 2")
  667. }
  668. if lapseto > 0 {
  669. db = db.Where("s.lapseto = ?", lapseto)
  670. }
  671. 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>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 and x.inspect_date >=? and x.inspect_date <=? then 1 else 0 end) as count,x.id,x.patient_id,x.org_id,x.project_id,x.item_id,x.item_name,x.project_name,x.inspect_value,x.inspect_date,r.range_min,r.range_max,p.sort", startime, endtime, startime, endtime).Joins("left join xt_inspection_reference as r on r.id = x.item_id").Joins("left join xt_patients as s on s.id = x.patient_id").Joins("left join xt_quality_control_standard as p on p.inspection_minor = x.item_id").Order("p.sort asc").Scan(&inspection).Error
  672. return inspection, err
  673. }
  674. 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) {
  675. if lapseto == 0 {
  676. d := XTReadDB().Table("xt_patients as s")
  677. fmt.Println("d", d)
  678. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  679. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  680. "SELECT " +
  681. "CASE " +
  682. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  683. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  684. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  685. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  686. " ELSE '其他'" +
  687. "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)"
  688. countParams := make([]interface{}, 0)
  689. countParams = append(countParams, firststart)
  690. countParams = append(countParams, firstend)
  691. countParams = append(countParams, sencondstart)
  692. countParams = append(countParams, sencondend)
  693. countParams = append(countParams, threestart)
  694. countParams = append(countParams, threeend)
  695. countParams = append(countParams, fourstart)
  696. countParams = append(countParams, fourend)
  697. if orgid > 0 {
  698. db = db.Where("x.org_id=?", orgid)
  699. countSQL += " AND x.org_id=?"
  700. countParams = append(countParams, orgid)
  701. }
  702. if modetype > 0 {
  703. db = db.Where("x.item_id = ?", modetype)
  704. countSQL += " AND x.item_id=?"
  705. countParams = append(countParams, modetype)
  706. }
  707. if startime > 0 {
  708. db = db.Where("x.inspect_date >= ?", startime)
  709. countSQL += " AND x.inspect_date >=?"
  710. countParams = append(countParams, startime)
  711. }
  712. if endtime > 0 {
  713. db = db.Where("x.inspect_date <= ?", endtime)
  714. countSQL += " AND x.inspect_date <=?"
  715. countParams = append(countParams, endtime)
  716. }
  717. countSQL += ")a GROUP BY nnd"
  718. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  719. }
  720. if lapseto == 1 {
  721. d := XTReadDB().Table("xt_patients as s")
  722. fmt.Println("d", d)
  723. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  724. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  725. "SELECT " +
  726. "CASE " +
  727. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  728. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  729. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  730. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  731. "ELSE '其他'" +
  732. "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)"
  733. countParams := make([]interface{}, 0)
  734. countParams = append(countParams, firststart)
  735. countParams = append(countParams, firstend)
  736. countParams = append(countParams, sencondstart)
  737. countParams = append(countParams, sencondend)
  738. countParams = append(countParams, threestart)
  739. countParams = append(countParams, threeend)
  740. countParams = append(countParams, fourstart)
  741. countParams = append(countParams, fourend)
  742. if orgid > 0 {
  743. db = db.Where("x.org_id=?", orgid)
  744. countSQL += " AND x.org_id=?"
  745. countParams = append(countParams, orgid)
  746. }
  747. if modetype > 0 {
  748. db = db.Where("x.item_id = ?", modetype)
  749. countSQL += " AND x.item_id=?"
  750. countParams = append(countParams, modetype)
  751. }
  752. if startime > 0 {
  753. db = db.Where("x.inspect_date >= ?", startime)
  754. countSQL += " AND x.inspect_date >=?"
  755. countParams = append(countParams, startime)
  756. }
  757. if endtime > 0 {
  758. db = db.Where("x.inspect_date <= ?", endtime)
  759. countSQL += " AND x.inspect_date <=?"
  760. countParams = append(countParams, endtime)
  761. }
  762. countSQL += ")a GROUP BY nnd"
  763. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  764. }
  765. if lapseto == 2 {
  766. d := XTReadDB().Table("xt_patients as s")
  767. fmt.Println("d", d)
  768. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  769. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  770. "SELECT " +
  771. "CASE " +
  772. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第一季度'" +
  773. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第二季度'" +
  774. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第三季度'" +
  775. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '第四季度'" +
  776. " ELSE '其他'" +
  777. "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)"
  778. countParams := make([]interface{}, 0)
  779. countParams = append(countParams, firststart)
  780. countParams = append(countParams, firstend)
  781. countParams = append(countParams, sencondstart)
  782. countParams = append(countParams, sencondend)
  783. countParams = append(countParams, threestart)
  784. countParams = append(countParams, threeend)
  785. countParams = append(countParams, fourstart)
  786. countParams = append(countParams, fourend)
  787. if orgid > 0 {
  788. db = db.Where("x.org_id=?", orgid)
  789. countSQL += " AND x.org_id=?"
  790. countParams = append(countParams, orgid)
  791. }
  792. if modetype > 0 {
  793. db = db.Where("x.item_id = ?", modetype)
  794. countSQL += " AND x.item_id=?"
  795. countParams = append(countParams, modetype)
  796. }
  797. if startime > 0 {
  798. db = db.Where("x.inspect_date >= ?", startime)
  799. countSQL += " AND x.inspect_date >=?"
  800. countParams = append(countParams, startime)
  801. }
  802. if endtime > 0 {
  803. db = db.Where("x.inspect_date <= ?", endtime)
  804. countSQL += " AND x.inspect_date <=?"
  805. countParams = append(countParams, endtime)
  806. }
  807. countSQL += ")a GROUP BY nnd"
  808. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  809. }
  810. return
  811. }
  812. 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) {
  813. if lapseto == 0 {
  814. d := XTReadDB().Table("xt_patients as s")
  815. fmt.Println("d", d)
  816. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  817. table := XTReadDB().Table("xt_inspection_reference as r")
  818. fmt.Println(table)
  819. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  820. "SELECT " +
  821. "CASE " +
  822. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
  823. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
  824. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
  825. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
  826. " ELSE '其他'" +
  827. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  828. countParams := make([]interface{}, 0)
  829. countParams = append(countParams, firststart)
  830. countParams = append(countParams, firstend)
  831. countParams = append(countParams, sencondstart)
  832. countParams = append(countParams, sencondend)
  833. countParams = append(countParams, threestart)
  834. countParams = append(countParams, threeend)
  835. countParams = append(countParams, fourstart)
  836. countParams = append(countParams, fourend)
  837. if orgid > 0 {
  838. db = db.Where("x.org_id=?", orgid)
  839. countSQL += " AND x.org_id=?"
  840. countParams = append(countParams, orgid)
  841. }
  842. if modetype > 0 {
  843. db = db.Where("x.item_id = ?", modetype)
  844. countSQL += " AND x.item_id=?"
  845. countParams = append(countParams, modetype)
  846. }
  847. if startime > 0 {
  848. db = db.Where("x.inspect_date >= ? ", startime)
  849. countSQL += " AND x.inspect_date >=?"
  850. countParams = append(countParams, startime)
  851. }
  852. if endtime > 0 {
  853. db = db.Where("x.inspect_date <= ?", endtime)
  854. countSQL += " AND x.inspect_date <=?"
  855. countParams = append(countParams, endtime)
  856. }
  857. countSQL += ")a GROUP BY nnd"
  858. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  859. }
  860. if lapseto == 1 {
  861. d := XTReadDB().Table("xt_patients as s")
  862. fmt.Println("d", d)
  863. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  864. table := XTReadDB().Table("xt_inspection_reference as r")
  865. fmt.Println(table)
  866. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  867. "SELECT " +
  868. "CASE " +
  869. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
  870. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
  871. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
  872. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
  873. " ELSE '其他'" +
  874. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  875. countParams := make([]interface{}, 0)
  876. countParams = append(countParams, firststart)
  877. countParams = append(countParams, firstend)
  878. countParams = append(countParams, sencondstart)
  879. countParams = append(countParams, sencondend)
  880. countParams = append(countParams, threestart)
  881. countParams = append(countParams, threeend)
  882. countParams = append(countParams, fourstart)
  883. countParams = append(countParams, fourend)
  884. if orgid > 0 {
  885. db = db.Where("x.org_id=?", orgid)
  886. countSQL += " AND x.org_id=?"
  887. countParams = append(countParams, orgid)
  888. }
  889. if modetype > 0 {
  890. db = db.Where("x.item_id = ?", modetype)
  891. countSQL += " AND x.item_id=?"
  892. countParams = append(countParams, modetype)
  893. }
  894. if startime > 0 {
  895. db = db.Where("x.inspect_date >= ? ", startime)
  896. countSQL += " AND x.inspect_date >=?"
  897. countParams = append(countParams, startime)
  898. }
  899. if endtime > 0 {
  900. db = db.Where("x.inspect_date <= ?", endtime)
  901. countSQL += " AND x.inspect_date <=?"
  902. countParams = append(countParams, endtime)
  903. }
  904. countSQL += ")a GROUP BY nnd"
  905. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  906. }
  907. if lapseto == 2 {
  908. d := XTReadDB().Table("xt_patients as s")
  909. fmt.Println("d", d)
  910. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  911. table := XTReadDB().Table("xt_inspection_reference as r")
  912. fmt.Println(table)
  913. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  914. "SELECT " +
  915. "CASE " +
  916. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第一季度'" +
  917. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第二季度'" +
  918. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第三季度'" +
  919. " WHEN x.inspect_date>=? AND x.inspect_date<=? AND x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '第四季度'" +
  920. " ELSE '其他'" +
  921. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  922. countParams := make([]interface{}, 0)
  923. countParams = append(countParams, firststart)
  924. countParams = append(countParams, firstend)
  925. countParams = append(countParams, sencondstart)
  926. countParams = append(countParams, sencondend)
  927. countParams = append(countParams, threestart)
  928. countParams = append(countParams, threeend)
  929. countParams = append(countParams, fourstart)
  930. countParams = append(countParams, fourend)
  931. if orgid > 0 {
  932. db = db.Where("x.org_id=?", orgid)
  933. countSQL += " AND x.org_id=?"
  934. countParams = append(countParams, orgid)
  935. }
  936. if modetype > 0 {
  937. db = db.Where("x.item_id = ?", modetype)
  938. countSQL += " AND x.item_id=?"
  939. countParams = append(countParams, modetype)
  940. }
  941. if startime > 0 {
  942. db = db.Where("x.inspect_date >= ? ", startime)
  943. countSQL += " AND x.inspect_date >=?"
  944. countParams = append(countParams, startime)
  945. }
  946. if endtime > 0 {
  947. db = db.Where("x.inspect_date <= ?", endtime)
  948. countSQL += " AND x.inspect_date <=?"
  949. countParams = append(countParams, endtime)
  950. }
  951. countSQL += ")a GROUP BY nnd"
  952. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  953. }
  954. return
  955. }
  956. 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) {
  957. if lapseto == 0 {
  958. d := XTReadDB().Table("xt_patients as s")
  959. fmt.Println("d", d)
  960. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  961. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  962. "SELECT " +
  963. "CASE " +
  964. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  965. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  966. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  967. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  968. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  969. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  970. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  971. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  972. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  973. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  974. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  975. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  976. " ELSE '其他'" +
  977. "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)"
  978. countParams := make([]interface{}, 0)
  979. countParams = append(countParams, januaryStartStrUnix)
  980. countParams = append(countParams, januaryEndStrUnix)
  981. countParams = append(countParams, febStartStrStrUnix)
  982. countParams = append(countParams, febEndStrUnix)
  983. countParams = append(countParams, marchStartStrUnix)
  984. countParams = append(countParams, marchEndStrUnix)
  985. countParams = append(countParams, aprStartStrUnix)
  986. countParams = append(countParams, aprEndStrsUnix)
  987. countParams = append(countParams, mayStartStrUnix)
  988. countParams = append(countParams, mayEndStrsUnix)
  989. countParams = append(countParams, junStartStrUnix)
  990. countParams = append(countParams, junEndStrsUnix)
  991. countParams = append(countParams, julStartStrUnix)
  992. countParams = append(countParams, julEndStrsUnix)
  993. countParams = append(countParams, augStartStrUnix)
  994. countParams = append(countParams, augEndStrsUnix)
  995. countParams = append(countParams, sepStartStrUnix)
  996. countParams = append(countParams, sepEndStrsUnix)
  997. countParams = append(countParams, octStartStrUnix)
  998. countParams = append(countParams, octEndStrsUnix)
  999. countParams = append(countParams, novStartStrUnix)
  1000. countParams = append(countParams, novEndStrsUnix)
  1001. countParams = append(countParams, decStartStrUnix)
  1002. countParams = append(countParams, decEndStrsUnix)
  1003. if orgid > 0 {
  1004. db = db.Where("x.org_id=?", orgid)
  1005. countSQL += " AND x.org_id=?"
  1006. countParams = append(countParams, orgid)
  1007. }
  1008. if modetype > 0 {
  1009. db = db.Where("x.item_id = ?", modetype)
  1010. countSQL += " AND x.item_id=?"
  1011. countParams = append(countParams, modetype)
  1012. }
  1013. if januaryStartStrUnix > 0 {
  1014. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1015. countSQL += " AND x.inspect_date >=?"
  1016. countParams = append(countParams, januaryStartStrUnix)
  1017. }
  1018. if decEndStrsUnix > 0 {
  1019. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1020. countSQL += " AND x.inspect_date <=?"
  1021. countParams = append(countParams, decEndStrsUnix)
  1022. }
  1023. countSQL += ")a GROUP BY nnd"
  1024. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1025. }
  1026. if lapseto == 1 {
  1027. d := XTReadDB().Table("xt_patients as s")
  1028. fmt.Println("d", d)
  1029. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1030. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1031. "SELECT " +
  1032. "CASE " +
  1033. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1034. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1035. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1036. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1037. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1038. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1039. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1040. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1041. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1042. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1043. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1044. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1045. " ELSE '其他'" +
  1046. "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)"
  1047. countParams := make([]interface{}, 0)
  1048. countParams = append(countParams, januaryStartStrUnix)
  1049. countParams = append(countParams, januaryEndStrUnix)
  1050. countParams = append(countParams, febStartStrStrUnix)
  1051. countParams = append(countParams, febEndStrUnix)
  1052. countParams = append(countParams, marchStartStrUnix)
  1053. countParams = append(countParams, marchEndStrUnix)
  1054. countParams = append(countParams, aprStartStrUnix)
  1055. countParams = append(countParams, aprEndStrsUnix)
  1056. countParams = append(countParams, mayStartStrUnix)
  1057. countParams = append(countParams, mayEndStrsUnix)
  1058. countParams = append(countParams, junStartStrUnix)
  1059. countParams = append(countParams, junEndStrsUnix)
  1060. countParams = append(countParams, julStartStrUnix)
  1061. countParams = append(countParams, julEndStrsUnix)
  1062. countParams = append(countParams, augStartStrUnix)
  1063. countParams = append(countParams, augEndStrsUnix)
  1064. countParams = append(countParams, sepStartStrUnix)
  1065. countParams = append(countParams, sepEndStrsUnix)
  1066. countParams = append(countParams, octStartStrUnix)
  1067. countParams = append(countParams, octEndStrsUnix)
  1068. countParams = append(countParams, novStartStrUnix)
  1069. countParams = append(countParams, novEndStrsUnix)
  1070. countParams = append(countParams, decStartStrUnix)
  1071. countParams = append(countParams, decEndStrsUnix)
  1072. if orgid > 0 {
  1073. db = db.Where("x.org_id=?", orgid)
  1074. countSQL += " AND x.org_id=?"
  1075. countParams = append(countParams, orgid)
  1076. }
  1077. if modetype > 0 {
  1078. db = db.Where("x.item_id = ?", modetype)
  1079. countSQL += " AND x.item_id=?"
  1080. countParams = append(countParams, modetype)
  1081. }
  1082. if januaryStartStrUnix > 0 {
  1083. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1084. countSQL += " AND x.inspect_date >=?"
  1085. countParams = append(countParams, januaryStartStrUnix)
  1086. }
  1087. if decEndStrsUnix > 0 {
  1088. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1089. countSQL += " AND x.inspect_date <=?"
  1090. countParams = append(countParams, decEndStrsUnix)
  1091. }
  1092. countSQL += ")a GROUP BY nnd"
  1093. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1094. }
  1095. if lapseto == 2 {
  1096. d := XTReadDB().Table("xt_patients as s")
  1097. fmt.Println("d", d)
  1098. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1099. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1100. "SELECT " +
  1101. "CASE " +
  1102. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '一月'" +
  1103. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '二月'" +
  1104. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '三月'" +
  1105. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '四月'" +
  1106. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '五月'" +
  1107. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '六月'" +
  1108. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '七月'" +
  1109. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '八月'" +
  1110. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '九月'" +
  1111. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十月'" +
  1112. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十一月'" +
  1113. " WHEN x.inspect_date>=? AND x.inspect_date<=? THEN '十二月'" +
  1114. " ELSE '其他'" +
  1115. "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)"
  1116. countParams := make([]interface{}, 0)
  1117. countParams = append(countParams, januaryStartStrUnix)
  1118. countParams = append(countParams, januaryEndStrUnix)
  1119. countParams = append(countParams, febStartStrStrUnix)
  1120. countParams = append(countParams, febEndStrUnix)
  1121. countParams = append(countParams, marchStartStrUnix)
  1122. countParams = append(countParams, marchEndStrUnix)
  1123. countParams = append(countParams, aprStartStrUnix)
  1124. countParams = append(countParams, aprEndStrsUnix)
  1125. countParams = append(countParams, mayStartStrUnix)
  1126. countParams = append(countParams, mayEndStrsUnix)
  1127. countParams = append(countParams, junStartStrUnix)
  1128. countParams = append(countParams, junEndStrsUnix)
  1129. countParams = append(countParams, julStartStrUnix)
  1130. countParams = append(countParams, julEndStrsUnix)
  1131. countParams = append(countParams, augStartStrUnix)
  1132. countParams = append(countParams, augEndStrsUnix)
  1133. countParams = append(countParams, sepStartStrUnix)
  1134. countParams = append(countParams, sepEndStrsUnix)
  1135. countParams = append(countParams, octStartStrUnix)
  1136. countParams = append(countParams, octEndStrsUnix)
  1137. countParams = append(countParams, novStartStrUnix)
  1138. countParams = append(countParams, novEndStrsUnix)
  1139. countParams = append(countParams, decStartStrUnix)
  1140. countParams = append(countParams, decEndStrsUnix)
  1141. if orgid > 0 {
  1142. db = db.Where("x.org_id=?", orgid)
  1143. countSQL += " AND x.org_id=?"
  1144. countParams = append(countParams, orgid)
  1145. }
  1146. if modetype > 0 {
  1147. db = db.Where("x.item_id = ?", modetype)
  1148. countSQL += " AND x.item_id=?"
  1149. countParams = append(countParams, modetype)
  1150. }
  1151. if januaryStartStrUnix > 0 {
  1152. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1153. countSQL += " AND x.inspect_date >=?"
  1154. countParams = append(countParams, januaryStartStrUnix)
  1155. }
  1156. if decEndStrsUnix > 0 {
  1157. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1158. countSQL += " AND x.inspect_date <=?"
  1159. countParams = append(countParams, decEndStrsUnix)
  1160. }
  1161. countSQL += ")a GROUP BY nnd"
  1162. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1163. }
  1164. return
  1165. }
  1166. 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) {
  1167. fmt.Println("lapseto=======", lapseto)
  1168. if lapseto == 0 {
  1169. d := XTReadDB().Table("xt_patients as s")
  1170. fmt.Println("d", d)
  1171. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1172. table := XTReadDB().Table("xt_inspection_reference as r")
  1173. fmt.Println(table)
  1174. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1175. "SELECT " +
  1176. "CASE " +
  1177. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '一月'" +
  1178. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '二月'" +
  1179. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '三月'" +
  1180. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '四月'" +
  1181. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '五月'" +
  1182. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '六月'" +
  1183. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '七月'" +
  1184. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '八月'" +
  1185. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '九月'" +
  1186. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十月'" +
  1187. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十一月'" +
  1188. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十二月'" +
  1189. " ELSE '其他'" +
  1190. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  1191. countParams := make([]interface{}, 0)
  1192. countParams = append(countParams, januaryStartStrUnix)
  1193. countParams = append(countParams, januaryEndStrUnix)
  1194. countParams = append(countParams, febStartStrStrUnix)
  1195. countParams = append(countParams, febEndStrUnix)
  1196. countParams = append(countParams, marchStartStrUnix)
  1197. countParams = append(countParams, marchEndStrUnix)
  1198. countParams = append(countParams, aprStartStrUnix)
  1199. countParams = append(countParams, aprEndStrsUnix)
  1200. countParams = append(countParams, mayStartStrUnix)
  1201. countParams = append(countParams, mayEndStrsUnix)
  1202. countParams = append(countParams, junStartStrUnix)
  1203. countParams = append(countParams, junEndStrsUnix)
  1204. countParams = append(countParams, julStartStrUnix)
  1205. countParams = append(countParams, julEndStrsUnix)
  1206. countParams = append(countParams, augStartStrUnix)
  1207. countParams = append(countParams, augEndStrsUnix)
  1208. countParams = append(countParams, sepStartStrUnix)
  1209. countParams = append(countParams, sepEndStrsUnix)
  1210. countParams = append(countParams, octStartStrUnix)
  1211. countParams = append(countParams, octEndStrsUnix)
  1212. countParams = append(countParams, novStartStrUnix)
  1213. countParams = append(countParams, novEndStrsUnix)
  1214. countParams = append(countParams, decStartStrUnix)
  1215. countParams = append(countParams, decEndStrsUnix)
  1216. if orgid > 0 {
  1217. db = db.Where("x.org_id=?", orgid)
  1218. countSQL += " AND x.org_id=?"
  1219. countParams = append(countParams, orgid)
  1220. }
  1221. if modetype > 0 {
  1222. db = db.Where("x.item_id = ?", modetype)
  1223. countSQL += " AND x.item_id=?"
  1224. countParams = append(countParams, modetype)
  1225. }
  1226. if januaryStartStrUnix > 0 {
  1227. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1228. countSQL += " AND x.inspect_date >=?"
  1229. countParams = append(countParams, januaryStartStrUnix)
  1230. }
  1231. if decEndStrsUnix > 0 {
  1232. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1233. countSQL += " AND x.inspect_date <=?"
  1234. countParams = append(countParams, decEndStrsUnix)
  1235. }
  1236. countSQL += ")a GROUP BY nnd"
  1237. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1238. }
  1239. if lapseto == 1 {
  1240. d := XTReadDB().Table("xt_patients as s")
  1241. fmt.Println("d", d)
  1242. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1243. table := XTReadDB().Table("xt_inspection_reference as r")
  1244. fmt.Println(table)
  1245. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1246. "SELECT " +
  1247. "CASE " +
  1248. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '一月'" +
  1249. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '二月'" +
  1250. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '三月'" +
  1251. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '四月'" +
  1252. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '五月'" +
  1253. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '六月'" +
  1254. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '七月'" +
  1255. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '八月'" +
  1256. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '九月'" +
  1257. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十月'" +
  1258. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十一月'" +
  1259. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十二月'" +
  1260. " ELSE '其他'" +
  1261. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  1262. countParams := make([]interface{}, 0)
  1263. countParams = append(countParams, januaryStartStrUnix)
  1264. countParams = append(countParams, januaryEndStrUnix)
  1265. countParams = append(countParams, febStartStrStrUnix)
  1266. countParams = append(countParams, febEndStrUnix)
  1267. countParams = append(countParams, marchStartStrUnix)
  1268. countParams = append(countParams, marchEndStrUnix)
  1269. countParams = append(countParams, aprStartStrUnix)
  1270. countParams = append(countParams, aprEndStrsUnix)
  1271. countParams = append(countParams, mayStartStrUnix)
  1272. countParams = append(countParams, mayEndStrsUnix)
  1273. countParams = append(countParams, junStartStrUnix)
  1274. countParams = append(countParams, junEndStrsUnix)
  1275. countParams = append(countParams, julStartStrUnix)
  1276. countParams = append(countParams, julEndStrsUnix)
  1277. countParams = append(countParams, augStartStrUnix)
  1278. countParams = append(countParams, augEndStrsUnix)
  1279. countParams = append(countParams, sepStartStrUnix)
  1280. countParams = append(countParams, sepEndStrsUnix)
  1281. countParams = append(countParams, octStartStrUnix)
  1282. countParams = append(countParams, octEndStrsUnix)
  1283. countParams = append(countParams, novStartStrUnix)
  1284. countParams = append(countParams, novEndStrsUnix)
  1285. countParams = append(countParams, decStartStrUnix)
  1286. countParams = append(countParams, decEndStrsUnix)
  1287. if orgid > 0 {
  1288. db = db.Where("x.org_id=?", orgid)
  1289. countSQL += " AND x.org_id=?"
  1290. countParams = append(countParams, orgid)
  1291. }
  1292. if modetype > 0 {
  1293. db = db.Where("x.item_id = ?", modetype)
  1294. countSQL += " AND x.item_id=?"
  1295. countParams = append(countParams, modetype)
  1296. }
  1297. if januaryStartStrUnix > 0 {
  1298. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1299. countSQL += " AND x.inspect_date >=?"
  1300. countParams = append(countParams, januaryStartStrUnix)
  1301. }
  1302. if decEndStrsUnix > 0 {
  1303. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1304. countSQL += " AND x.inspect_date <=?"
  1305. countParams = append(countParams, decEndStrsUnix)
  1306. }
  1307. countSQL += ")a GROUP BY nnd"
  1308. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1309. }
  1310. if lapseto == 2 {
  1311. d := XTReadDB().Table("xt_patients as s")
  1312. fmt.Println("d", d)
  1313. db := readDb.Table("xt_inspection as x ").Where("x.status=1")
  1314. table := XTReadDB().Table("xt_inspection_reference as r")
  1315. fmt.Println(table)
  1316. countSQL := "SELECT nnd AS 'total',COUNT(*) AS 'count' FROM(" +
  1317. "SELECT " +
  1318. "CASE " +
  1319. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '一月'" +
  1320. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '二月'" +
  1321. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '三月'" +
  1322. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '四月'" +
  1323. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '五月'" +
  1324. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '六月'" +
  1325. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '七月'" +
  1326. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '八月'" +
  1327. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '九月'" +
  1328. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十月'" +
  1329. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十一月'" +
  1330. " WHEN x.inspect_date>=? AND x.inspect_date<=? and x.inspect_value+0>=r.range_min+0 and x.inspect_value +0 <= r.range_max+0 THEN '十二月'" +
  1331. " ELSE '其他'" +
  1332. "END AS nnd FROM xt_inspection as x left join xt_inspection_reference as r on r.id = 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.range_min + 0 AND x.inspect_value + 0 <= r.range_max + 0)"
  1333. countParams := make([]interface{}, 0)
  1334. countParams = append(countParams, januaryStartStrUnix)
  1335. countParams = append(countParams, januaryEndStrUnix)
  1336. countParams = append(countParams, febStartStrStrUnix)
  1337. countParams = append(countParams, febEndStrUnix)
  1338. countParams = append(countParams, marchStartStrUnix)
  1339. countParams = append(countParams, marchEndStrUnix)
  1340. countParams = append(countParams, aprStartStrUnix)
  1341. countParams = append(countParams, aprEndStrsUnix)
  1342. countParams = append(countParams, mayStartStrUnix)
  1343. countParams = append(countParams, mayEndStrsUnix)
  1344. countParams = append(countParams, junStartStrUnix)
  1345. countParams = append(countParams, junEndStrsUnix)
  1346. countParams = append(countParams, julStartStrUnix)
  1347. countParams = append(countParams, julEndStrsUnix)
  1348. countParams = append(countParams, augStartStrUnix)
  1349. countParams = append(countParams, augEndStrsUnix)
  1350. countParams = append(countParams, sepStartStrUnix)
  1351. countParams = append(countParams, sepEndStrsUnix)
  1352. countParams = append(countParams, octStartStrUnix)
  1353. countParams = append(countParams, octEndStrsUnix)
  1354. countParams = append(countParams, novStartStrUnix)
  1355. countParams = append(countParams, novEndStrsUnix)
  1356. countParams = append(countParams, decStartStrUnix)
  1357. countParams = append(countParams, decEndStrsUnix)
  1358. if orgid > 0 {
  1359. db = db.Where("x.org_id=?", orgid)
  1360. countSQL += " AND x.org_id=?"
  1361. countParams = append(countParams, orgid)
  1362. }
  1363. if modetype > 0 {
  1364. db = db.Where("x.item_id = ?", modetype)
  1365. countSQL += " AND x.item_id=?"
  1366. countParams = append(countParams, modetype)
  1367. }
  1368. if januaryStartStrUnix > 0 {
  1369. db = db.Where("x.inspect_date >= ?", januaryStartStrUnix)
  1370. countSQL += " AND x.inspect_date >=?"
  1371. countParams = append(countParams, januaryStartStrUnix)
  1372. }
  1373. if decEndStrsUnix > 0 {
  1374. db = db.Where("x.inspect_date <= ?", decEndStrsUnix)
  1375. countSQL += " AND x.inspect_date <=?"
  1376. countParams = append(countParams, decEndStrsUnix)
  1377. }
  1378. countSQL += ")a GROUP BY nnd"
  1379. err = readDb.Raw(countSQL, countParams...).Scan(&inspection).Error
  1380. }
  1381. return
  1382. }
  1383. func GetPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64, page int64, limit int64) (inspection []*models.PatientInspectionCount, total int64, err error) {
  1384. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1385. table := readDb.Table("xt_patients as s")
  1386. fmt.Println(table)
  1387. d := readDb.Table(" xt_inspection_reference as r")
  1388. fmt.Println(d)
  1389. if orgid > 0 {
  1390. db = db.Where("x.org_id = ?", orgid)
  1391. }
  1392. if lapstor == 0 {
  1393. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  1394. }
  1395. if lapstor == 1 {
  1396. db = db.Where("s.lapseto = 1")
  1397. }
  1398. if lapstor == 2 {
  1399. db = db.Where("s.lapseto = 2")
  1400. }
  1401. if startime > 0 {
  1402. db = db.Where("x.inspect_date >=?", startime)
  1403. }
  1404. if endtime > 0 {
  1405. db = db.Where("x.inspect_date <=?", endtime)
  1406. }
  1407. offset := (page - 1) * limit
  1408. err = db.Select("x.id,x.patient_id,s.name,s.dialysis_no").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").Group("x.patient_id").Count(&total).Offset(offset).Limit(limit).Scan(&inspection).Error
  1409. return inspection, total, err
  1410. }
  1411. func GetLastPatientsControl(orgid int64, lapstor int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  1412. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1413. table := readDb.Table("xt_patients as s")
  1414. fmt.Println(table)
  1415. d := readDb.Table(" xt_inspection_reference as r")
  1416. fmt.Println(d)
  1417. d2 := readDb.Table("xt_quality_control_standard as d")
  1418. fmt.Println("d2", d2)
  1419. if orgid > 0 {
  1420. db = db.Where("x.org_id = ?", orgid)
  1421. }
  1422. if lapstor == 0 {
  1423. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  1424. }
  1425. if lapstor == 1 {
  1426. table = table.Where("s.lapseto = 1")
  1427. }
  1428. if lapstor == 2 {
  1429. table = table.Where("s.lapseto = 2")
  1430. }
  1431. if startime > 0 {
  1432. db = db.Where("x.inspect_date >=?", startime)
  1433. }
  1434. if endtime > 0 {
  1435. db = db.Where("x.inspect_date <=?", endtime)
  1436. }
  1437. 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
  1438. return inspection, err
  1439. }
  1440. func GetPatientContor(lapstor, orgid int64, keywords string, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  1441. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1442. table := readDb.Table("xt_patients as s")
  1443. fmt.Println(table)
  1444. d := readDb.Table(" xt_inspection_reference as r")
  1445. fmt.Println(d)
  1446. d2 := readDb.Table("xt_quality_control_standard as d")
  1447. fmt.Println("d2", d2)
  1448. if len(keywords) > 0 {
  1449. db = db.Where("s.name LIKE ? OR s.dialysis_no LIKE ?", keywords, keywords)
  1450. }
  1451. if orgid > 0 {
  1452. db = db.Where("x.org_id = ?", orgid)
  1453. }
  1454. if lapstor == 0 {
  1455. table = table.Where("s.lapseto = 1 or s.lapseto = 2")
  1456. }
  1457. if lapstor == 1 {
  1458. table = table.Where("s.lapseto = 1")
  1459. }
  1460. if lapstor == 2 {
  1461. table = table.Where("s.lapseto = 2")
  1462. }
  1463. if startime > 0 {
  1464. db = db.Where("x.inspect_date >=?", startime)
  1465. }
  1466. if endtime > 0 {
  1467. db = db.Where("x.inspect_date <=?", endtime)
  1468. }
  1469. 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
  1470. return inspection, err
  1471. }
  1472. func GetPatientNames(orgid int64, patientname string) (models.XtPatients, error) {
  1473. patients := models.XtPatients{}
  1474. err := readDb.Where("user_org_id = ? and (name=? or dialysis_no=?) and status = 1", orgid, patientname, patientname).Find(&patients).Error
  1475. return patients, err
  1476. }
  1477. func GetQualityControlById(orgid int64, patientid int64, startime int64, endtime int64, itemid int64) (inspection []*models.PatientInspectionCount, err error) {
  1478. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1479. table := readDb.Table("xt_patients as s")
  1480. fmt.Println(table)
  1481. d := readDb.Table(" xt_inspection_reference as r")
  1482. fmt.Println(d)
  1483. d2 := readDb.Table("xt_quality_control_standard as d")
  1484. fmt.Println("d2", d2)
  1485. if orgid > 0 {
  1486. db = db.Where("x.org_id = ?", orgid)
  1487. }
  1488. if patientid > 0 {
  1489. db = db.Where("x.patient_id = ?", patientid)
  1490. }
  1491. if startime > 0 {
  1492. db = db.Where("x.inspect_date >=?", startime)
  1493. }
  1494. if endtime > 0 {
  1495. db = db.Where("x.inspect_date <=?", endtime)
  1496. }
  1497. if itemid > 0 {
  1498. db = db.Where("x.item_id = ?", itemid)
  1499. }
  1500. 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").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
  1501. return inspection, err
  1502. }
  1503. func GetLastPatientsControlTwo(orgid int64, patientid int64, startime int64, endtime int64) (inspection []*models.PatientInspectionCount, err error) {
  1504. db := readDb.Table("xt_inspection as x").Where("x.status =1")
  1505. table := readDb.Table("xt_patients as s")
  1506. fmt.Println(table)
  1507. d := readDb.Table(" xt_inspection_reference as r")
  1508. fmt.Println(d)
  1509. d2 := readDb.Table("xt_quality_control_standard as d")
  1510. fmt.Println("d2", d2)
  1511. if orgid > 0 {
  1512. db = db.Where("x.org_id = ?", orgid)
  1513. }
  1514. if patientid > 0 {
  1515. db = db.Where("x.patient_id = ?", patientid)
  1516. }
  1517. if startime > 0 {
  1518. db = db.Where("x.inspect_date >=?", startime)
  1519. }
  1520. if endtime > 0 {
  1521. db = db.Where("x.inspect_date <=?", endtime)
  1522. }
  1523. 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
  1524. return inspection, err
  1525. }