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. if len(partition_id) > 0 {
  174. db = db.Where("partition_id in(?)", partition_id)
  175. }
  176. if orgID > 0 {
  177. db = db.Where("user_org_id = ?", orgID)
  178. }
  179. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  180. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  181. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  182. Preload("DialysisSolution", "status = 1 AND user_org_id = ? AND solution_status = 1", orgID).
  183. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  184. return schedule, err
  185. }
  186. func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
  187. db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
  188. if scheduleDate > 0 {
  189. db = db.Where("schedule_date = ?", scheduleDate)
  190. }
  191. if schedule_type > 0 {
  192. db = db.Where("schedule_type = ?", schedule_type)
  193. }
  194. //if partition_id > 0 {
  195. // db = db.Where("partition_id = ?", partition_id)
  196. //}
  197. if len(partition_id) > 0 {
  198. db = db.Where("partition_id in(?)", partition_id)
  199. }
  200. if orgID > 0 {
  201. db = db.Where("user_org_id = ?", orgID)
  202. }
  203. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  204. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  205. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate).
  206. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  207. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  208. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  209. return schedule, err
  210. }
  211. func GetDialysisAdviceSchedulistTwo(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  212. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("status = 1")
  213. if scheduleDate > 0 {
  214. db = db.Where("schedule_date = ?", scheduleDate)
  215. }
  216. if schedule_type > 0 {
  217. db = db.Where("schedule_type = ?", schedule_type)
  218. }
  219. //if partition_id > 0 {
  220. // db = db.Where("partition_id = ?", partition_id)
  221. //}
  222. if len(partition_id) > 0 {
  223. db = db.Where("partition_id in(?)", partition_id)
  224. }
  225. if orgID > 0 {
  226. db = db.Where("user_org_id = ?", orgID)
  227. }
  228. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  229. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  230. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  231. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  232. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  233. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  234. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  235. })
  236. })
  237. }).Find(&schedule).Error
  238. return schedule, err
  239. }
  240. 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) {
  241. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  242. offset := (page - 1) * limit
  243. if scheduleDate > 0 {
  244. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  245. }
  246. if schedule_type > 0 {
  247. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  248. }
  249. if partition_id > 0 {
  250. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  251. }
  252. if orgID > 0 {
  253. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  254. }
  255. if len(idArray) >= 1 {
  256. db = db.Where("xt_schedule.id in(?)", idArray)
  257. }
  258. if len(keywords) > 0 {
  259. keywords = "%" + keywords + "%"
  260. 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)
  261. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  262. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  263. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  264. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  265. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  266. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  267. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  268. })
  269. })
  270. }).Find(&schedule).Error
  271. } else {
  272. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  273. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  274. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  275. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  276. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  277. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  278. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  279. })
  280. })
  281. }).Find(&schedule).Error
  282. }
  283. return schedule, total, err
  284. }
  285. func GetAllDrugMap(org_id int64) (list []*BaseDrugLib, err error) {
  286. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  287. return list, err
  288. }
  289. func GetDialysisParameterGoodList(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
  290. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  291. if scheduleDate > 0 {
  292. db = db.Where("schedule_date = ?", scheduleDate)
  293. }
  294. if schedule_type > 0 {
  295. db = db.Where("schedule_type = ?", schedule_type)
  296. }
  297. if partition_id > 0 {
  298. db = db.Where("partition_id = ?", partition_id)
  299. }
  300. if orgID > 0 {
  301. db = db.Where("user_org_id = ?", orgID)
  302. }
  303. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  304. Preload("DialysisSolution", "status=1 and user_org_id = ? and solution_status = 1", orgID).
  305. Preload("DialysisPrescription", "status = 1 and user_org_id = ?", orgID).
  306. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  307. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  308. Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  309. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  310. return schedule, err
  311. }
  312. func SaveHisDialysis(orgid int64, ids []string) error {
  313. goodsType := models.BloodGoodsType{}
  314. err := XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 1}).Error
  315. err = XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id not in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 0}).Error
  316. return err
  317. }
  318. 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) {
  319. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  320. offset := (page - 1) * limit
  321. if scheduleDate > 0 {
  322. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  323. }
  324. if schedule_type > 0 {
  325. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  326. }
  327. if partition_id > 0 {
  328. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  329. }
  330. if orgID > 0 {
  331. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  332. }
  333. if len(ids) >= 1 {
  334. db = db.Where("xt_schedule.id in(?)", ids)
  335. }
  336. if len(keywords) > 0 {
  337. keywords = "%" + keywords + "%"
  338. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  339. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  340. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  341. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  342. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  343. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  344. 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)
  345. })
  346. })
  347. })
  348. 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)
  349. err = db.Count(&total).Offset(offset).Limit(limit).Find(&schedule).Error
  350. } else {
  351. err = db.Count(&total).Offset(offset).Limit(limit).
  352. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  353. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  354. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  355. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  356. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  357. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  358. 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)
  359. })
  360. })
  361. }).Find(&schedule).Error
  362. }
  363. return schedule, total, err
  364. }
  365. func GetHisDialysisGoodCount(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  366. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  367. if scheduleDate > 0 {
  368. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  369. }
  370. if schedule_type > 0 {
  371. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  372. }
  373. if partition_id > 0 {
  374. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  375. }
  376. if orgID > 0 {
  377. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  378. }
  379. err = db.
  380. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  381. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  382. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  383. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  384. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  385. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  386. 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)
  387. })
  388. })
  389. }).Find(&schedule).Error
  390. return schedule, err
  391. }
  392. func GeAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  393. err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Find(&advice).Error
  394. return advice, err
  395. }
  396. func GetHisAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.HisDoctorAdviceFourty, err error) {
  397. 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
  398. return advice, err
  399. }
  400. func GetDialysisAdviceSchedulistSeven(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
  401. db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
  402. if scheduleDate > 0 {
  403. db = db.Where("schedule_date = ?", scheduleDate)
  404. }
  405. if schedule_type > 0 {
  406. db = db.Where("schedule_type = ?", schedule_type)
  407. }
  408. if partition_id > 0 {
  409. db = db.Where("partition_id = ?", partition_id)
  410. }
  411. if orgID > 0 {
  412. db = db.Where("user_org_id = ?", orgID)
  413. }
  414. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  415. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  416. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate).
  417. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  418. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  419. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  420. return schedule, err
  421. }
  422. func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
  423. db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
  424. if scheduleDate > 0 {
  425. db = db.Where("schedule_date = ?", scheduleDate)
  426. }
  427. if schedule_type > 0 {
  428. db = db.Where("schedule_type = ?", schedule_type)
  429. }
  430. if len(partition_id) > 0 {
  431. db = db.Where("partition_id in(?)", partition_id)
  432. }
  433. if orgID > 0 {
  434. db = db.Where("user_org_id = ?", orgID)
  435. }
  436. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  437. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  438. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate).
  439. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  440. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  441. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  442. return schedule, err
  443. }
  444. func GetHisDialysisGoodCountTwo(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  445. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  446. if scheduleDate > 0 {
  447. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  448. }
  449. if schedule_type > 0 {
  450. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  451. }
  452. if len(partition_id) > 0 {
  453. db = db.Where("xt_schedule.partition_id in (?)", partition_id)
  454. }
  455. if orgID > 0 {
  456. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  457. }
  458. err = db.
  459. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  460. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  461. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  462. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  463. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  464. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  465. 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)
  466. })
  467. })
  468. }).Find(&schedule).Error
  469. return schedule, err
  470. }