dialysis_solution_service.go 25KB

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