dialysis_solution_service.go 25KB

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