dialysis_solution_service.go 27KB

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