dialysis_solution_service.go 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. package service
  2. import (
  3. "XT_New/models"
  4. "github.com/jinzhu/gorm"
  5. )
  6. func GetPatientSolutionGroupList(patient_id int64, orgid int64) (solution []*models.DialysisSolution, err error) {
  7. err = XTReadDB().Where("patient_id = ? and status = 1 and user_org_id = ?", patient_id, orgid).Group("mode_id").Find(&solution).Error
  8. return solution, err
  9. }
  10. func GetNewPatientSolutionByModeId(patient_id int64, mode_id int64, orgid int64) (models.DialysisSolution, error) {
  11. solution := models.DialysisSolution{}
  12. err := XTReadDB().Where("patient_id = ? and mode_id = ? and user_org_id = ? and status = 1", patient_id, mode_id, orgid).Order("updated_time desc").First(&solution).Error
  13. return solution, err
  14. }
  15. func UpdateDialysisSolutionStatus(id int64, mode_id int64, orgid int64, patient_id int64) error {
  16. err := XTWriteDB().Model(&models.DialysisSolution{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Update(map[string]interface{}{"solution_status": 1}).Error
  17. err = XTWriteDB().Model(&models.DialysisSolution{}).Where("id <> ? and mode_id = ? and user_org_id = ? and status = 1 and patient_id = ?", id, mode_id, orgid, patient_id).Update(map[string]interface{}{"solution_status": 2}).Error
  18. return err
  19. }
  20. func UpdateDialysisSolutionStatusTwo(id int64, mode_id int64, orgid int64, patient_id int64) error {
  21. err = XTWriteDB().Model(&models.DialysisSolution{}).Where("id <> ? and mode_id = ? and user_org_id = ? and status = 1 and patient_id = ?", id, mode_id, orgid, patient_id).Update(map[string]interface{}{"solution_status": 2}).Error
  22. return err
  23. }
  24. func GetLastPatientDialysisSolution(patient_id int64, orgid int64) (models.DialysisSolution, error) {
  25. solution := models.DialysisSolution{}
  26. err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status = 1", patient_id, orgid).Last(&solution).Error
  27. return solution, err
  28. }
  29. func GetPatientDialysisSolutionGroupList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodSchedule, total int64, err error) {
  30. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1")
  31. offset := (page - 1) * limit
  32. if scheduleDate > 0 {
  33. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  34. }
  35. if schedule_type > 0 {
  36. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  37. }
  38. if partition_id > 0 {
  39. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  40. }
  41. if orgID > 0 {
  42. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  43. }
  44. if len(ids) >= 1 {
  45. db = db.Where("xt_schedule.id in(?)", ids)
  46. }
  47. if len(keywords) > 0 {
  48. keywords = "%" + keywords + "%"
  49. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  50. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  51. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  52. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Preload("DialysisPrescription", "status=1 and user_org_id =? and record_date =?", orgID, scheduleDate)
  53. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  54. err = db.Count(&total).Offset(offset).Limit(limit).Find(&schedule).Error
  55. } else {
  56. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  57. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  58. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  59. Preload("DialysisPrescription", "status=1 and user_org_id =? and record_date =?", orgID, scheduleDate).
  60. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Count(&total).Offset(offset).Limit(limit).Find(&schedule).Error
  61. }
  62. return schedule, total, err
  63. }
  64. func GetDialysisAdviceTemplateList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64, idArray []string) (schedule []*models.VmBloodSchedule, total int64, err error) {
  65. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1")
  66. offset := (page - 1) * limit
  67. if scheduleDate > 0 {
  68. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  69. }
  70. if schedule_type > 0 {
  71. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  72. }
  73. if partition_id > 0 {
  74. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  75. }
  76. if orgID > 0 {
  77. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  78. }
  79. if len(idArray) >= 1 {
  80. db = db.Where("xt_schedule.id in(?)", idArray)
  81. }
  82. if len(keywords) > 0 {
  83. keywords = "%" + keywords + "%"
  84. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  85. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  86. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  87. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  88. Preload("DialysisSolution", "status=1 and solution_status =1 and user_org_id=?", orgID).
  89. Preload("DialysisPrescription", "status=1 and record_date = ? and user_org_id=?", scheduleDate, orgID).
  90. Preload("HisDoctorAdvice", "status=1 and user_org_id =? and advice_date =?", orgID, scheduleDate).Find(&schedule).Error
  91. } else {
  92. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  93. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  94. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  95. Preload("DialysisSolution", "status=1 and solution_status =1 and user_org_id=?", orgID).
  96. Preload("DialysisPrescription", "status=1 and record_date = ? and user_org_id=?", scheduleDate, orgID).
  97. Preload("HisDoctorAdvice", "status=1 and user_org_id =? and advice_date =?", orgID, scheduleDate).Find(&schedule).Error
  98. }
  99. return schedule, total, err
  100. }
  101. func GetAllLongAdviceList(user_org_id int64) (advice []*models.DoctorAdvice, err error) {
  102. err = XTReadDB().Where("user_org_id = ? and advice_type = 1 and status = 1 and stop_state!=1", user_org_id).Find(&advice).Error
  103. return advice, err
  104. }
  105. func GetHisLongAdviceList(user_org_id int64) (advice []*models.HisDoctorAdviceTemplate, err error) {
  106. err = XTReadDB().Where("org_id = ? and status=1", user_org_id).Find(&advice).Error
  107. return advice, err
  108. }
  109. func GetAllHisAdviceTemplateList(user_org_id int64, keywords string) (advice []*models.HisPrescriptionAdviceTemplate, err error) {
  110. keywords = "%" + keywords + "%"
  111. if len(keywords) > 0 {
  112. err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_name like ?", user_org_id, keywords).Find(&advice).Error
  113. return advice, err
  114. } else {
  115. err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&advice).Error
  116. return advice, err
  117. }
  118. }
  119. func SaveDialysisSetting(setting models.XtDialysisSetting) error {
  120. err := XTWriteDB().Create(&setting).Error
  121. return err
  122. }
  123. func GetDialysisSetting(orgid int64) (models.XtDialysisSetting, error) {
  124. setting := models.XtDialysisSetting{}
  125. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
  126. return setting, err
  127. }
  128. func GetDialysisParameterList(keywords string, limit int64, page int64, partition_id []string, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodSchedule, total int64, err error) {
  129. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1")
  130. offset := (page - 1) * limit
  131. if scheduleDate > 0 {
  132. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  133. }
  134. if schedule_type > 0 {
  135. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  136. }
  137. //if partition_id > 0 {
  138. // db = db.Where("xt_schedule.partition_id = ?", partition_id)
  139. //}
  140. if len(partition_id) > 0 {
  141. db = db.Where("xt_schedule.partition_id in(?)", partition_id)
  142. }
  143. if orgID > 0 {
  144. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  145. }
  146. if len(ids) >= 1 {
  147. db = db.Where("xt_schedule.id in(?)", ids)
  148. }
  149. if len(keywords) > 0 {
  150. keywords = "%" + keywords + "%"
  151. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  152. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  153. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  154. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).
  155. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  156. Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  157. Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  158. Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  159. Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
  160. return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate)
  161. }).
  162. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate).
  163. Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate).
  164. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  165. } else {
  166. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  167. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  168. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).
  169. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  170. Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  171. Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  172. Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  173. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate).
  174. Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate).
  175. Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
  176. return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate)
  177. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  178. }
  179. return schedule, total, err
  180. }
  181. func GetDialysisGoodTotalCount(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
  182. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  183. if scheduleDate > 0 {
  184. db = db.Where("schedule_date = ?", scheduleDate)
  185. }
  186. if schedule_type > 0 {
  187. db = db.Where("schedule_type = ?", schedule_type)
  188. }
  189. //if partition_id > 0 {
  190. // db = db.Where("partition_id = ?", partition_id)
  191. //}
  192. if len(partition_id) > 0 {
  193. db = db.Where("partition_id in(?)", partition_id)
  194. }
  195. if orgID > 0 {
  196. db = db.Where("user_org_id = ?", orgID)
  197. }
  198. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  199. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  200. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  201. Preload("DialysisSolution", "status = 1 AND user_org_id = ? AND solution_status = 1", orgID).
  202. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  203. return schedule, err
  204. }
  205. func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
  206. db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
  207. if scheduleDate > 0 {
  208. db = db.Where("schedule_date = ?", scheduleDate)
  209. }
  210. if schedule_type > 0 {
  211. db = db.Where("schedule_type = ?", schedule_type)
  212. }
  213. //if partition_id > 0 {
  214. // db = db.Where("partition_id = ?", partition_id)
  215. //}
  216. if len(partition_id) > 0 {
  217. db = db.Where("partition_id in(?)", partition_id)
  218. }
  219. if orgID > 0 {
  220. db = db.Where("user_org_id = ?", orgID)
  221. }
  222. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  223. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  224. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate).
  225. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  226. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  227. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  228. return schedule, err
  229. }
  230. func GetDialysisAdviceSchedulistTwo(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  231. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("status = 1")
  232. if scheduleDate > 0 {
  233. db = db.Where("schedule_date = ?", scheduleDate)
  234. }
  235. if schedule_type > 0 {
  236. db = db.Where("schedule_type = ?", schedule_type)
  237. }
  238. //if partition_id > 0 {
  239. // db = db.Where("partition_id = ?", partition_id)
  240. //}
  241. if len(partition_id) > 0 {
  242. db = db.Where("partition_id in(?)", partition_id)
  243. }
  244. if orgID > 0 {
  245. db = db.Where("user_org_id = ?", orgID)
  246. }
  247. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  248. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  249. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  250. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  251. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  252. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  253. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  254. })
  255. })
  256. }).Find(&schedule).Error
  257. return schedule, err
  258. }
  259. func GetDialysisAdviceSchedulistSix(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64, idArray []string) (schedule []*models.VmBloodScheduleTwo, total int64, err error) {
  260. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  261. offset := (page - 1) * limit
  262. if scheduleDate > 0 {
  263. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  264. }
  265. if schedule_type > 0 {
  266. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  267. }
  268. if partition_id > 0 {
  269. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  270. }
  271. if orgID > 0 {
  272. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  273. }
  274. if len(idArray) >= 1 {
  275. db = db.Where("xt_schedule.id in(?)", idArray)
  276. }
  277. if len(keywords) > 0 {
  278. keywords = "%" + keywords + "%"
  279. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  280. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  281. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  282. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  283. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  284. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  285. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  286. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  287. })
  288. })
  289. }).Find(&schedule).Error
  290. } else {
  291. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  292. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  293. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  294. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  295. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  296. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  297. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  298. })
  299. })
  300. }).Find(&schedule).Error
  301. }
  302. return schedule, total, err
  303. }
  304. func GetAllDrugMap(org_id int64) (list []*BaseDrugLib, err error) {
  305. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  306. return list, err
  307. }
  308. func GetDialysisParameterGoodList(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
  309. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  310. if scheduleDate > 0 {
  311. db = db.Where("schedule_date = ?", scheduleDate)
  312. }
  313. if schedule_type > 0 {
  314. db = db.Where("schedule_type = ?", schedule_type)
  315. }
  316. if partition_id > 0 {
  317. db = db.Where("partition_id = ?", partition_id)
  318. }
  319. if orgID > 0 {
  320. db = db.Where("user_org_id = ?", orgID)
  321. }
  322. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  323. Preload("DialysisSolution", "status=1 and user_org_id = ? and solution_status = 1", orgID).
  324. Preload("DialysisPrescription", "status = 1 and user_org_id = ?", orgID).
  325. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  326. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  327. Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  328. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  329. return schedule, err
  330. }
  331. func SaveHisDialysis(orgid int64, ids []string) error {
  332. goodsType := models.BloodGoodsType{}
  333. err := XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 1}).Error
  334. err = XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id not in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 0}).Error
  335. return err
  336. }
  337. func GetHisPatientDialysisSolutionGroupList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodScheduleTwo, total int64, err error) {
  338. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  339. offset := (page - 1) * limit
  340. if scheduleDate > 0 {
  341. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  342. }
  343. if schedule_type > 0 {
  344. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  345. }
  346. if partition_id > 0 {
  347. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  348. }
  349. if orgID > 0 {
  350. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  351. }
  352. if len(ids) >= 1 {
  353. db = db.Where("xt_schedule.id in(?)", ids)
  354. }
  355. if len(keywords) > 0 {
  356. keywords = "%" + keywords + "%"
  357. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  358. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  359. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  360. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  361. return db.Where("user_org_id = ? and status = 1 and record_date = ? and type =3", orgID, scheduleDate).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  362. return db.Where("org_id = ? and status = 1", orgID)
  363. })
  364. }).Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  365. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  366. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  367. return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
  368. })
  369. })
  370. })
  371. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  372. err = db.Count(&total).Offset(offset).Limit(limit).Find(&schedule).Error
  373. } else {
  374. err = db.Count(&total).Offset(offset).Limit(limit).
  375. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  376. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  377. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  378. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  379. return db.Where("user_org_id = ? and status = 1 and record_date = ? and type =3", orgID, scheduleDate).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB {
  380. return db.Where("org_id = ? and status = 1", orgID)
  381. })
  382. }).Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  383. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  384. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  385. return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
  386. })
  387. })
  388. }).Find(&schedule).Error
  389. }
  390. return schedule, total, err
  391. }
  392. func GetHisDialysisGoodCount(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  393. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  394. if scheduleDate > 0 {
  395. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  396. }
  397. if schedule_type > 0 {
  398. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  399. }
  400. if partition_id > 0 {
  401. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  402. }
  403. if orgID > 0 {
  404. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  405. }
  406. err = db.
  407. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  408. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  409. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  410. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  411. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  412. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  413. return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
  414. })
  415. })
  416. }).Find(&schedule).Error
  417. return schedule, err
  418. }
  419. func GeAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  420. err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Find(&advice).Error
  421. return advice, err
  422. }
  423. func GetHisAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.HisDoctorAdviceFourty, err error) {
  424. err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Preload("Drug", "org_id = ? and status=1", user_org_id).Find(&advice).Error
  425. return advice, err
  426. }
  427. func GetDialysisAdviceSchedulistSeven(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
  428. db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
  429. if scheduleDate > 0 {
  430. db = db.Where("schedule_date = ?", scheduleDate)
  431. }
  432. if schedule_type > 0 {
  433. db = db.Where("schedule_type = ?", schedule_type)
  434. }
  435. if partition_id > 0 {
  436. db = db.Where("partition_id = ?", partition_id)
  437. }
  438. if orgID > 0 {
  439. db = db.Where("user_org_id = ?", orgID)
  440. }
  441. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  442. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  443. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate).
  444. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  445. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  446. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  447. return schedule, err
  448. }
  449. func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
  450. db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
  451. if scheduleDate > 0 {
  452. db = db.Where("schedule_date = ?", scheduleDate)
  453. }
  454. if schedule_type > 0 {
  455. db = db.Where("schedule_type = ?", schedule_type)
  456. }
  457. if len(partition_id) > 0 {
  458. db = db.Where("partition_id in(?)", partition_id)
  459. }
  460. if orgID > 0 {
  461. db = db.Where("user_org_id = ?", orgID)
  462. }
  463. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  464. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  465. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate).
  466. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  467. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  468. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  469. return schedule, err
  470. }
  471. func GetDialysisProjectSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleSix, err error) {
  472. db := XTReadDB().Model(&models.VmBloodScheduleSix{}).Where("status = 1")
  473. if scheduleDate > 0 {
  474. db = db.Where("schedule_date = ?", scheduleDate)
  475. }
  476. if schedule_type > 0 {
  477. db = db.Where("schedule_type = ?", schedule_type)
  478. }
  479. if len(partition_id) > 0 {
  480. db = db.Where("partition_id in(?)", partition_id)
  481. }
  482. if orgID > 0 {
  483. db = db.Where("user_org_id = ?", orgID)
  484. }
  485. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  486. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  487. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  488. return db.Where("user_org_id = ? and status = 1 and record_date = ? and type =3", orgID, scheduleDate).Preload("Good", "org_id =? and status = 1", orgID)
  489. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  490. return schedule, err
  491. }
  492. func GetHisDialysisGoodCountTwo(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  493. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  494. if scheduleDate > 0 {
  495. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  496. }
  497. if schedule_type > 0 {
  498. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  499. }
  500. if len(partition_id) > 0 {
  501. db = db.Where("xt_schedule.partition_id in (?)", partition_id)
  502. }
  503. if orgID > 0 {
  504. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  505. }
  506. err = db.
  507. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  508. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  509. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  510. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  511. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  512. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  513. return db.Where("user_org_id = ? and status = 1 and type = 3 and (frequency_type =1 or (frequency_type =2 and day_count >0) or (frequency_type =3 and week_day<>''))", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
  514. })
  515. })
  516. }).Find(&schedule).Error
  517. return schedule, err
  518. }
  519. func GetLongDialysisAdviceToday(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmLongBloodSchedule, err error) {
  520. db := XTReadDB().Model(&models.VmLongBloodSchedule{}).Where("status = 1")
  521. if scheduleDate > 0 {
  522. db = db.Where("schedule_date = ?", scheduleDate)
  523. }
  524. if schedule_type > 0 {
  525. db = db.Where("schedule_type = ?", schedule_type)
  526. }
  527. if len(partition_id) > 0 {
  528. db = db.Where("partition_id in(?)", partition_id)
  529. }
  530. if orgID > 0 {
  531. db = db.Where("user_org_id = ?", orgID)
  532. }
  533. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  534. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  535. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_type = 1", orgID).
  536. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  537. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  538. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  539. return schedule, err
  540. }
  541. func GetDialysisGatherList(keywords string, limit int64, page int64, partition_id []string, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodSchedule, total int64, err error) {
  542. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1")
  543. offset := (page - 1) * limit
  544. if scheduleDate > 0 {
  545. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  546. }
  547. if schedule_type > 0 {
  548. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  549. }
  550. //if partition_id > 0 {
  551. // db = db.Where("xt_schedule.partition_id = ?", partition_id)
  552. //}
  553. if len(partition_id) > 0 {
  554. db = db.Where("xt_schedule.partition_id in(?)", partition_id)
  555. }
  556. if orgID > 0 {
  557. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  558. }
  559. if len(ids) >= 1 {
  560. db = db.Where("xt_schedule.id in(?)", ids)
  561. }
  562. if len(keywords) > 0 {
  563. keywords = "%" + keywords + "%"
  564. db = db.Joins("JOIN xt_patients AS patient ON patient.id=xt_schedule.patient_id AND patient.status = 1 AND patient.user_org_id = ? AND patient.name Like ?", orgID, keywords)
  565. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  566. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  567. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).
  568. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  569. Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  570. Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  571. Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  572. Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
  573. return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate)
  574. }).
  575. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate).
  576. Preload("LongDoctorAdvice", "status = 1 AND user_org_id = ? and advice_type =1", orgID).
  577. Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate).
  578. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  579. } else {
  580. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  581. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  582. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).
  583. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  584. Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  585. Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  586. Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  587. Preload("LongDoctorAdvice", "status = 1 AND user_org_id = ? and advice_type =1", orgID).
  588. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate).
  589. Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate).
  590. Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
  591. return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate)
  592. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  593. }
  594. return schedule, total, err
  595. }