dialysis_solution_service.go 31KB

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