dialysis_solution_service.go 33KB

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