dialysis_solution_service.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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 int64, 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 orgID > 0 {
  174. db = db.Where("user_org_id = ?", orgID)
  175. }
  176. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  177. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  178. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  179. Preload("DialysisSolution", "status = 1 AND user_org_id = ? AND solution_status = 1", orgID).
  180. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  181. return schedule, err
  182. }
  183. func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) {
  184. db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1")
  185. if scheduleDate > 0 {
  186. db = db.Where("schedule_date = ?", scheduleDate)
  187. }
  188. if schedule_type > 0 {
  189. db = db.Where("schedule_type = ?", schedule_type)
  190. }
  191. if partition_id > 0 {
  192. db = db.Where("partition_id = ?", partition_id)
  193. }
  194. if orgID > 0 {
  195. db = db.Where("user_org_id = ?", orgID)
  196. }
  197. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  198. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  199. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  200. Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB {
  201. return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID)
  202. }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  203. return schedule, err
  204. }
  205. func GetDialysisAdviceSchedulistTwo(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  206. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("status = 1")
  207. if scheduleDate > 0 {
  208. db = db.Where("schedule_date = ?", scheduleDate)
  209. }
  210. if schedule_type > 0 {
  211. db = db.Where("schedule_type = ?", schedule_type)
  212. }
  213. if partition_id > 0 {
  214. db = db.Where("partition_id = ?", partition_id)
  215. }
  216. if orgID > 0 {
  217. db = db.Where("user_org_id = ?", orgID)
  218. }
  219. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  220. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  221. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  222. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  223. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  224. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  225. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  226. })
  227. })
  228. }).Find(&schedule).Error
  229. return schedule, err
  230. }
  231. 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) {
  232. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  233. offset := (page - 1) * limit
  234. if scheduleDate > 0 {
  235. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  236. }
  237. if schedule_type > 0 {
  238. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  239. }
  240. if partition_id > 0 {
  241. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  242. }
  243. if orgID > 0 {
  244. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  245. }
  246. if len(idArray) >= 1 {
  247. db = db.Where("xt_schedule.id in(?)", idArray)
  248. }
  249. if len(keywords) > 0 {
  250. keywords = "%" + keywords + "%"
  251. 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)
  252. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  253. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  254. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  255. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  256. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  257. return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  258. return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID)
  259. })
  260. })
  261. }).Find(&schedule).Error
  262. } else {
  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. }
  274. return schedule, total, err
  275. }
  276. func GetAllDrugMap(org_id int64) (list []*BaseDrugLib, err error) {
  277. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  278. return list, err
  279. }
  280. func GetDialysisParameterGoodList(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
  281. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  282. if scheduleDate > 0 {
  283. db = db.Where("schedule_date = ?", scheduleDate)
  284. }
  285. if schedule_type > 0 {
  286. db = db.Where("schedule_type = ?", schedule_type)
  287. }
  288. if partition_id > 0 {
  289. db = db.Where("partition_id = ?", partition_id)
  290. }
  291. if orgID > 0 {
  292. db = db.Where("user_org_id = ?", orgID)
  293. }
  294. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  295. Preload("DialysisSolution", "status=1 and user_org_id = ? and solution_status = 1", orgID).
  296. Preload("DialysisPrescription", "status = 1 and user_org_id = ?", orgID).
  297. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  298. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  299. Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  300. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  301. return schedule, err
  302. }
  303. func SaveHisDialysis(orgid int64, ids []string) error {
  304. goodsType := models.BloodGoodsType{}
  305. err := XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 1}).Error
  306. err = XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id not in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 0}).Error
  307. return err
  308. }
  309. 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) {
  310. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  311. offset := (page - 1) * limit
  312. if scheduleDate > 0 {
  313. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  314. }
  315. if schedule_type > 0 {
  316. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  317. }
  318. if partition_id > 0 {
  319. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  320. }
  321. if orgID > 0 {
  322. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  323. }
  324. if len(ids) >= 1 {
  325. db = db.Where("xt_schedule.id in(?)", ids)
  326. }
  327. if len(keywords) > 0 {
  328. keywords = "%" + keywords + "%"
  329. db = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  330. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  331. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  332. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  333. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  334. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  335. 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)
  336. })
  337. })
  338. })
  339. 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)
  340. err = db.Count(&total).Offset(offset).Limit(limit).Find(&schedule).Error
  341. } else {
  342. err = db.Count(&total).Offset(offset).Limit(limit).
  343. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  344. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  345. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  346. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  347. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  348. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  349. 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)
  350. })
  351. })
  352. }).Find(&schedule).Error
  353. }
  354. return schedule, total, err
  355. }
  356. func GetHisDialysisGoodCount(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) {
  357. db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1")
  358. if scheduleDate > 0 {
  359. db = db.Where("xt_schedule.schedule_date = ?", scheduleDate)
  360. }
  361. if schedule_type > 0 {
  362. db = db.Where("xt_schedule.schedule_type = ?", schedule_type)
  363. }
  364. if partition_id > 0 {
  365. db = db.Where("xt_schedule.partition_id = ?", partition_id)
  366. }
  367. if orgID > 0 {
  368. db = db.Where("xt_schedule.user_org_id = ?", orgID)
  369. }
  370. err = db.
  371. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  372. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  373. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  374. Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB {
  375. return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB {
  376. return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB {
  377. 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)
  378. })
  379. })
  380. }).Find(&schedule).Error
  381. return schedule, err
  382. }
  383. func GeAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) {
  384. err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Find(&advice).Error
  385. return advice, err
  386. }
  387. func GetHisAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.HisDoctorAdviceFourty, err error) {
  388. 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
  389. return advice, err
  390. }