dialysis_solution_service.go 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. package service
  2. import (
  3. "XT_New/models"
  4. )
  5. func GetPatientSolutionGroupList(patient_id int64, orgid int64) (solution []*models.DialysisSolution, err error) {
  6. err = XTReadDB().Where("patient_id = ? and status = 1 and user_org_id = ?", patient_id, orgid).Group("mode_id").Find(&solution).Error
  7. return solution, err
  8. }
  9. func GetNewPatientSolutionByModeId(patient_id int64, mode_id int64, orgid int64) (models.DialysisSolution, error) {
  10. solution := models.DialysisSolution{}
  11. 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
  12. return solution, err
  13. }
  14. func UpdateDialysisSolutionStatus(id int64, mode_id int64, orgid int64, patient_id int64) error {
  15. err := XTWriteDB().Model(&models.DialysisSolution{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Update(map[string]interface{}{"solution_status": 1}).Error
  16. 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
  17. return err
  18. }
  19. func UpdateDialysisSolutionStatusTwo(id int64, mode_id int64, orgid int64, patient_id int64) error {
  20. 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
  21. return err
  22. }
  23. func GetLastPatientDialysisSolution(patient_id int64, orgid int64) (models.DialysisSolution, error) {
  24. solution := models.DialysisSolution{}
  25. err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status = 1", patient_id, orgid).Last(&solution).Error
  26. return solution, err
  27. }
  28. func GetPatientDialysisSolutionGroupList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64) (schedule []*models.VmBloodSchedule, total int64, err error) {
  29. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  30. offset := (page - 1) * limit
  31. if scheduleDate > 0 {
  32. db = db.Where("schedule_date = ?", scheduleDate)
  33. }
  34. if schedule_type > 0 {
  35. db = db.Where("schedule_type = ?", schedule_type)
  36. }
  37. if partition_id > 0 {
  38. db = db.Where("partition_id = ?", partition_id)
  39. }
  40. if orgID > 0 {
  41. db = db.Where("user_org_id = ?", orgID)
  42. }
  43. if len(keywords) > 0 {
  44. keywords = "%" + keywords + "%"
  45. 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)
  46. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  47. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  48. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  49. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error
  50. } else {
  51. err = db.Count(&total).Offset(offset).Limit(limit).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).Find(&schedule).Error
  55. }
  56. return schedule, total, err
  57. }
  58. func GetDialysisAdviceTemplateList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64) (schedule []*models.VmBloodSchedule, total int64, err error) {
  59. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  60. offset := (page - 1) * limit
  61. if scheduleDate > 0 {
  62. db = db.Where("schedule_date = ?", scheduleDate)
  63. }
  64. if schedule_type > 0 {
  65. db = db.Where("schedule_type = ?", schedule_type)
  66. }
  67. if partition_id > 0 {
  68. db = db.Where("partition_id = ?", partition_id)
  69. }
  70. if orgID > 0 {
  71. db = db.Where("user_org_id = ?", orgID)
  72. }
  73. if len(keywords) > 0 {
  74. keywords = "%" + keywords + "%"
  75. 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)
  76. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  77. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  78. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  79. } else {
  80. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  81. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  82. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  83. }
  84. return schedule, total, err
  85. }
  86. func GetAllLongAdviceList(user_org_id int64) (advice []*models.DoctorAdvice, err error) {
  87. err = XTReadDB().Where("user_org_id = ? and advice_type = 1 and status = 1", user_org_id).Find(&advice).Error
  88. return advice, err
  89. }
  90. func GetAllHisAdviceTemplateList(user_org_id int64) (advice []*models.HisPrescriptionAdviceTemplate, err error) {
  91. err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&advice).Error
  92. return advice, err
  93. }
  94. func SaveDialysisSetting(setting models.XtDialysisSetting) error {
  95. err := XTWriteDB().Create(&setting).Error
  96. return err
  97. }
  98. func GetDialysisSetting(orgid int64) (models.XtDialysisSetting, error) {
  99. setting := models.XtDialysisSetting{}
  100. err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error
  101. return setting, err
  102. }
  103. func GetDialysisParameterList(keywords string, limit int64, page int64, partition_id int64, schedule_type int64, scheduleDate int64, orgID int64) (schedule []*models.VmBloodSchedule, total int64, err error) {
  104. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  105. offset := (page - 1) * limit
  106. if scheduleDate > 0 {
  107. db = db.Where("schedule_date = ?", scheduleDate)
  108. }
  109. if schedule_type > 0 {
  110. db = db.Where("schedule_type = ?", schedule_type)
  111. }
  112. if partition_id > 0 {
  113. db = db.Where("partition_id = ?", partition_id)
  114. }
  115. if orgID > 0 {
  116. db = db.Where("user_org_id = ?", orgID)
  117. }
  118. if len(keywords) > 0 {
  119. keywords = "%" + keywords + "%"
  120. 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)
  121. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  122. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  123. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  124. Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  125. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  126. } else {
  127. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  128. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  129. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  130. Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate).
  131. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  132. }
  133. return schedule, total, err
  134. }
  135. func GetDialysisGoodTotalCount(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
  136. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  137. if scheduleDate > 0 {
  138. db = db.Where("schedule_date = ?", scheduleDate)
  139. }
  140. if schedule_type > 0 {
  141. db = db.Where("schedule_type = ?", schedule_type)
  142. }
  143. if partition_id > 0 {
  144. db = db.Where("partition_id = ?", partition_id)
  145. }
  146. if orgID > 0 {
  147. db = db.Where("user_org_id = ?", orgID)
  148. }
  149. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  150. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  151. Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate).
  152. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  153. return schedule, err
  154. }
  155. func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
  156. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  157. if scheduleDate > 0 {
  158. db = db.Where("schedule_date = ?", scheduleDate)
  159. }
  160. if schedule_type > 0 {
  161. db = db.Where("schedule_type = ?", schedule_type)
  162. }
  163. if partition_id > 0 {
  164. db = db.Where("partition_id = ?", partition_id)
  165. }
  166. if orgID > 0 {
  167. db = db.Where("user_org_id = ?", orgID)
  168. }
  169. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  170. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  171. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  172. Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  173. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  174. return schedule, err
  175. }
  176. func GetAllDrugMap(org_id int64) (list []*BaseDrugLib, err error) {
  177. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  178. return list, err
  179. }
  180. func GetDialysisParameterGoodList(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) {
  181. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  182. if scheduleDate > 0 {
  183. db = db.Where("schedule_date = ?", scheduleDate)
  184. }
  185. if schedule_type > 0 {
  186. db = db.Where("schedule_type = ?", schedule_type)
  187. }
  188. if partition_id > 0 {
  189. db = db.Where("partition_id = ?", partition_id)
  190. }
  191. if orgID > 0 {
  192. db = db.Where("user_org_id = ?", orgID)
  193. }
  194. err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  195. Preload("DialysisPrescription", "status = 1 and user_org_id = ?", orgID).
  196. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  197. Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  198. Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate).
  199. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error
  200. return schedule, err
  201. }