dialysis_parameter_service.go 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. )
  7. type VMDialysisSchedule struct {
  8. ID int64 `gorm:"column:id" json:"id" form:"id"`
  9. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  10. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  11. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  12. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  13. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  14. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  15. ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week" form:"schedule_week"`
  16. ModeId int64 `gorm:"column:mode_id" json:"mode_id" form:"mode_id"`
  17. Status int64 `gorm:"column:status" json:"status" form:"status"`
  18. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  19. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  20. MonitorPatients models.MonitorPatients `gorm:"ForeignKey:PatientId" json:"patient"`
  21. DeviceNumber models.DeviceNumber `gorm:"ForeignKey:BedId" json:"device_number"`
  22. DeviceZone models.DeviceZone `gorm:"ForeignKey:PartitionId" json:"device_zone"`
  23. TreatmentMode models.TreatmentMode `gorm:"ForeignKey:ModeId" json:"treatment_mode"`
  24. DialysisOrder models.MonitorDialysisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  25. Prescription models.DialysisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  26. AssessmentBeforeDislysis models.PredialysisEvaluation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  27. AssessmentAfterDislysis AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  28. MonitoringRecord []models.MonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  29. //Patient string `gorm:"-" json:"patient" form:"patient"`
  30. //SchedualPatient SchedualPatient `gorm:"ForeignKey:PatientId"`
  31. //DeviceNumber DeviceNumber `gorm:"ForeignKey:BedId"`
  32. //DeviceZone DeviceZone `gorm:"ForeignKey:PartitionId"`
  33. //TreatmentMode TreatmentMode `gorm:"ForeignKey:ModeId"`
  34. }
  35. func (VMDialysisSchedule) TableName() string {
  36. return "xt_schedule"
  37. }
  38. type MonitorDialysisSchedule struct {
  39. ID int64 `gorm:"column:id" json:"id"`
  40. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id"`
  41. PartitionId int64 `gorm:"column:partition_id" json:"partition_id"`
  42. BedId int64 `gorm:"column:bed_id" json:"bed_id"`
  43. PatientId int64 `gorm:"column:patient_id" json:"patient_id"`
  44. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
  45. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
  46. ModeId int64 `gorm:"column:mode_id" json:"mode_id"`
  47. Status int64 `gorm:"column:status" json:"status"`
  48. MonitorPatients models.MonitorPatients `gorm:"ForeignKey:PatientId" json:"patient"`
  49. DeviceNumber models.DeviceNumber `gorm:"ForeignKey:BedId" json:"device_number"`
  50. DeviceZone models.DeviceZone `gorm:"ForeignKey:PartitionId" json:"device_zone"`
  51. TreatmentMode models.TreatmentMode `gorm:"ForeignKey:ModeId" json:"treatment_mode"`
  52. DialysisOrder models.MonitorDialysisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"dialysis_order"`
  53. Prescription models.DialysisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"prescription"`
  54. AssessmentBeforeDislysis models.PredialysisEvaluation `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_before_dislysis"`
  55. AssessmentAfterDislysis models.AssessmentAfterDislysis `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"assessment_after_dislysis"`
  56. MonitoringRecord []models.MonitoringRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  57. }
  58. func (MonitorDialysisSchedule) TableName() string {
  59. return "xt_schedule"
  60. }
  61. func GetDialysisParametersByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, schedulDate int64) ([]*VMDialysisSchedule, error, int64) {
  62. fmt.Println("scheduletye ======================", schedulType)
  63. var patients []*models.Patients
  64. getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
  65. if getPatientErr != nil {
  66. return nil, getPatientErr, 0
  67. }
  68. patientIDs := make([]int64, len(patients))
  69. for index, patient := range patients {
  70. patientIDs[index] = patient.ID
  71. }
  72. db := readDb.
  73. Model(&VMDialysisSchedule{}).
  74. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  75. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  76. Preload("TreatmentMode", "status = 1").
  77. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, schedulDate).
  78. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  79. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  80. Preload("MonitoringRecord", "status = 1 AND user_org_id = ? AND monitoring_date = ?", orgID, schedulDate).
  81. Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, schedulDate).
  82. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  83. db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
  84. if schedulType > 0 {
  85. db = db.Where("schedule_type = ?", schedulType)
  86. }
  87. if partitionType > 0 {
  88. db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
  89. }
  90. if schedulDate > 0 {
  91. db = db.Where("schedule_date = ?", schedulDate)
  92. }
  93. var schedules []*VMDialysisSchedule
  94. total := int64(0)
  95. err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  96. return schedules, err, total
  97. }
  98. func GetDialysisParameter(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64) (schedule []*MonitorDialysisSchedule, err error, total int64) {
  99. db := readDb.
  100. Model(&MonitorDialysisSchedule{}).
  101. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  102. Preload("TreatmentMode", "status = 1").
  103. Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, schedulDate).
  104. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  105. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate).
  106. Preload("MonitoringRecord", "status = 1 AND user_org_id = ? AND monitoring_date = ?", orgID, schedulDate).
  107. Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, schedulDate).
  108. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  109. db = db.Where("xt_schedule.status = 1 AND user_org_id = ?", orgID)
  110. if schedulDate > 0 {
  111. db = db.Where("schedule_date = ?", schedulDate)
  112. }
  113. if schedulType > 0 {
  114. db = db.Where("schedule_type = ?", schedulType)
  115. }
  116. if partitionType > 0 {
  117. db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ? and xt_device_number.status = 1", partitionType)
  118. }
  119. offset := (page - 1) * limit
  120. err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&schedule).Error
  121. return schedule, err, total
  122. }
  123. func GetDialysisBatchParameters(schIDs []string, orgID int64) (schedule []*models.DialysisParameter, err error) {
  124. db := readDb.
  125. Model(&models.DialysisSchedule{}).
  126. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  127. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  128. Preload("TreatmentMode", "status = 1").
  129. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  130. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  131. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  132. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  133. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  134. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  135. db = db.Where("xt_schedule.status = 1 AND id in (?)", schIDs)
  136. var schedules []*models.DialysisParameter
  137. err = db.Order("schedule_date desc").Find(&schedules).Error
  138. return schedules, err
  139. }
  140. func GetWareHouseOutList(startime int64, endtime int64, orgid int64) (warehouse []*models.XtWarehouseOutInfo, err error) {
  141. db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status = 1")
  142. if startime > 0 {
  143. db = db.Where("x.sys_record_time >=?", startime)
  144. }
  145. if endtime > 0 {
  146. db = db.Where("x.sys_record_time<=?", endtime)
  147. }
  148. if orgid > 0 {
  149. db = db.Where("x.org_id = ?", orgid)
  150. }
  151. err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.count,x.warehouse_out_order_number,x.sys_record_time,s.specification_name,t.type_name").Joins("left join xt_good_information as s on s.id = x.good_id").Where("s.status = 1 and s.org_id = ?", orgid).Joins("left join xt_goods_type as t on t.id = x.good_type_id").Order("x.id desc").Scan(&warehouse).Error
  152. return warehouse, err
  153. }
  154. func GetAllMaterial(startime int64, endtime int64, orgid int64) (reducedetail []*models.XtAutomaticReduceDetail, err error) {
  155. db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
  156. if startime > 0 {
  157. db = db.Where("x.record_time>=?", startime)
  158. }
  159. if endtime > 0 {
  160. db = db.Where("x.record_time<=?", endtime)
  161. }
  162. if orgid > 0 {
  163. db = db.Where("x.org_id = ?", orgid)
  164. }
  165. err = db.Select("x.patient_id,x.record_time,x.good_id,t.type_name").Joins("left join xt_goods_type as t on t.id = x.good_type_id").Group("x.good_type_id").Scan(&reducedetail).Error
  166. return reducedetail, err
  167. }
  168. func GetCollectList(limit int64, page int64, partitionType int64, schedulType int64, schedulDate int64, orgID int64, keyword string) ([]*models.DialysisParameter, error, int64) {
  169. var patients []*models.Patients
  170. getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error
  171. if getPatientErr != nil {
  172. return nil, getPatientErr, 0
  173. }
  174. patientIDs := make([]int64, len(patients))
  175. for index, patient := range patients {
  176. patientIDs[index] = patient.ID
  177. }
  178. db := readDb.
  179. Model(&models.DialysisSchedule{}).
  180. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  181. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  182. Preload("TreatmentMode", "status = 1").
  183. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  184. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  185. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  186. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  187. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  188. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  189. db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
  190. if schedulType > 0 {
  191. db = db.Where("schedule_type = ?", schedulType)
  192. }
  193. if partitionType > 0 {
  194. db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ? and d_n.status = 1", partitionType)
  195. // db = db.Where("partition_id = ?", partitionType)
  196. }
  197. if schedulDate > 0 {
  198. db = db.Where("schedule_date = ?", schedulDate)
  199. }
  200. var schedules []*models.DialysisParameter
  201. total := int64(0)
  202. err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error
  203. return schedules, err, total
  204. }
  205. func GetDialysisConsumables(startime int64, endtime int64, orgid int64) (reducedetail []*models.XtAutomaticReduceDetail, err error) {
  206. db := XTReadDB().Table("xt_automatic_reduce_detail as x").Where("x.status = 1")
  207. table := XTReadDB().Table("xt_warehouse_out_info as f").Where("f.status = 1 and f.org_id = ?", orgid)
  208. fmt.Println(table)
  209. if startime > 0 {
  210. db = db.Where("x.record_time >=?", startime)
  211. }
  212. if endtime > 0 {
  213. db = db.Where("x.record_time <=?", endtime)
  214. }
  215. if orgid > 0 {
  216. db = db.Where("x.org_id =?", orgid)
  217. }
  218. err = db.Select("x.patient_id,x.count,x.good_id,x.good_type_id,t.specification_name,s.type_name").Joins("left join xt_good_information as t on t.id = x.good_id").Where("t.org_id = ? and t.status = 1", orgid).Joins("left join xt_goods_type as s on s.id = x.good_type_id").Joins("left join xt_warehouse_out_info as f on f.id = x.warehouse_out_id").Scan(&reducedetail).Error
  219. return reducedetail, err
  220. }
  221. func GetBatchCollection(orgID int64, schIDs []string) (schedules []*models.DialysisParameter, err error) {
  222. db := readDb.
  223. Model(&models.DialysisSchedule{}).
  224. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  225. // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).
  226. Preload("TreatmentMode", "status = 1").
  227. Preload("Prescription", "status = 1 AND user_org_id = ?", orgID).
  228. Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID).
  229. Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
  230. Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID).
  231. Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
  232. Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID)
  233. db = db.Where("xt_schedule.status = 1 AND id in (?)", schIDs)
  234. err = db.Order("schedule_date desc").Find(&schedules).Error
  235. return schedules, err
  236. }
  237. func GetAnticoagulantCount(startime int64, endtime int64, orgid int64) (prescriptionCount []*models.DialysisPrescriptionCount, err error) {
  238. db := XTReadDB().Table("xt_dialysis_prescription as x").Where("x.status = 1")
  239. if orgid > 0 {
  240. db = db.Where("x.user_org_id = ? and x.anticoagulant <> 0", orgid)
  241. }
  242. if startime > 0 {
  243. db = db.Where("x.record_date >= ?", startime)
  244. }
  245. if endtime > 0 {
  246. db = db.Where("x.record_date<=?", endtime)
  247. }
  248. err = db.Select("x.patient_id,x.anticoagulant,x.record_date,count(id) as count").Group("x.anticoagulant").Scan(&prescriptionCount).Error
  249. return prescriptionCount, err
  250. }
  251. func GetDialysisTodaySchedulePatient(orgid int64, startime int64, page int64, limit int64, keywords string, schedulType int64, partiontype int64) (schedule []*models.XtScheduleTwo, err error) {
  252. //offset := (page - 1) * limit
  253. //err = XTReadDB().Model(&schedule).Where("user_org_id = ? and schedule_date = ? and status = 1", orgid, startime).Offset(offset).Limit(limit).Order("id desc").Find(&schedule).Error
  254. //return schedule, err
  255. keywords = "%" + keywords + "%"
  256. offset := (page - 1) * limit
  257. db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
  258. if schedulType > 0 {
  259. db = db.Where("x.schedule_type = ?", schedulType)
  260. }
  261. if partiontype > 0 {
  262. db = db.Where("x.partition_id = ?", partiontype)
  263. }
  264. table := XTReadDB().Table("xt_patients as s")
  265. fmt.Println(table)
  266. if len(keywords) > 0 {
  267. err = db.Group("x.id").Select("x.id,x.patient_id,x.mode_id,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.user_org_id = ? and x.schedule_date = ? and x.status = 1 and s.name like ?", orgid, startime, keywords).Offset(offset).Limit(limit).Order("id desc").Scan(&schedule).Error
  268. //db = db.Where("s.name like ?", keywords)
  269. } else {
  270. err = db.Group("x.id").Select("x.id,x.patient_id,x.mode_id,s.name").Joins("left join xt_patients as s on s.id = x.patient_id").Where("x.user_org_id = ? and x.schedule_date = ? and x.status = 1", orgid, startime).Offset(offset).Limit(limit).Order("id desc").Scan(&schedule).Error
  271. }
  272. return schedule, err
  273. }
  274. func GetToDayDialysisPrescription(patientid int64, orgid int64, startime int64) (*models.XtDialysisPrescription, error) {
  275. prescription := models.XtDialysisPrescription{}
  276. err := XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and record_date = ? and status = 1", patientid, orgid, startime).Find(&prescription).Error
  277. if err == gorm.ErrRecordNotFound {
  278. return nil, err
  279. }
  280. if err != nil {
  281. return nil, err
  282. }
  283. return &prescription, nil
  284. }
  285. func GetLastDialysisPrescription(patientid int64, orgid int64) (models.XtDialysisPrescription, error) {
  286. prescription := models.XtDialysisPrescription{}
  287. err = XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Last(&prescription).Error
  288. return prescription, err
  289. }
  290. func GetLastAssessmentBeforDialysis(patientid int64, orgid int64) (models.PredialysisEvaluation, error) {
  291. evaluation := models.PredialysisEvaluation{}
  292. err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and status = 1", patientid, orgid).Last(&evaluation).Error
  293. return evaluation, err
  294. }
  295. func GetDialysisPrescriptionList(patientid int64, orgid int64, startime int64) (models.DialysisPrescriptionParameter, error) {
  296. prescription := models.DialysisPrescriptionParameter{}
  297. err := XTReadDB().Model(&prescription).Where("patient_id = ? and user_org_id = ? and status = 1 and record_date = ?", patientid, orgid, startime).Find(&prescription).Error
  298. return prescription, err
  299. }
  300. func GetTodayAssessmentBeforDialysis(patientid int64, orgid int64, startime int64) (*models.PredialysisEvaluationParameter, error) {
  301. evaluation := models.PredialysisEvaluationParameter{}
  302. err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and assessment_date = ? and status = 1", patientid, orgid, startime).Find(&evaluation).Error
  303. if err == gorm.ErrRecordNotFound {
  304. return nil, err
  305. }
  306. if err != nil {
  307. return nil, err
  308. }
  309. return &evaluation, nil
  310. }
  311. func GetAssessmentBeforDialysisByStartime(patientid int64, orgid int64, startime int64) (models.PredialysisEvaluation, error) {
  312. evaluation := models.PredialysisEvaluation{}
  313. err := XTReadDB().Model(&evaluation).Where("patient_id = ? and user_org_id = ? and assessment_date = ? and status = 1", patientid, orgid, startime).Find(&evaluation).Error
  314. return evaluation, err
  315. }
  316. func GetAotoMaticReduceByPatientId(patientid int64, orgid int64, startime int64, endtime int64) (*models.BloodAutomaticReduceDetail, error) {
  317. detail := models.BloodAutomaticReduceDetail{}
  318. err := XTReadDB().Model(&detail).Where("patient_id = ? and org_id =? and record_time >=? and record_time <=? and status = 1", patientid, orgid, startime, endtime).Find(&detail).Error
  319. if err == gorm.ErrRecordNotFound {
  320. return nil, err
  321. }
  322. if err != nil {
  323. return nil, err
  324. }
  325. return &detail, nil
  326. }
  327. func GetMaticReduece(patientid int64, orgid int64) (models.BloodAutomaticReduceDetail, error) {
  328. detail := models.BloodAutomaticReduceDetail{}
  329. err := XTReadDB().Model(&detail).Where("patient_id = ? and org_id= ? and status = 1", patientid, orgid).Last(&detail).Error
  330. return detail, err
  331. }
  332. func GetMaticeReduceByPatientId(patientid int64, orgid int64, startime int64, endtime int64) (models.BloodAutomaticReduceDetail, error) {
  333. detail := models.BloodAutomaticReduceDetail{}
  334. err := XTReadDB().Model(&detail).Where("patient_id = ? and org_id = ? and record_time >=? and record_time<=? and status =1", patientid, orgid, startime, endtime).Find(&detail).Error
  335. return detail, err
  336. }
  337. func PCGetDialysisGoodsTwo(orgID int64, scheduleDate int64, schedule_type int64, partition_id int64, page int64, limit int64, keywords string) ([]*MDialysisGoodsVM, error, int64) {
  338. var vms []*MDialysisGoodsVM
  339. var total int64
  340. db := readDb.
  341. Model(&models.Schedule{}).Select("patient_id,mode_id").
  342. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  343. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  344. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  345. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  346. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ?", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  347. }).
  348. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  349. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time = ? AND count > 0", orgID, scheduleDate)
  350. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  351. if scheduleDate != 0 {
  352. db = db.Where("schedule_date = ?", scheduleDate)
  353. }
  354. if len(keywords) != 0 {
  355. keywords = "%" + keywords + "%"
  356. 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)
  357. } else {
  358. if schedule_type != 0 {
  359. db = db.Where("schedule_type = ?", schedule_type)
  360. }
  361. if partition_id != 0 {
  362. db = db.Where("partition_id = ?", partition_id)
  363. }
  364. db = db.Count(&total)
  365. offset := (page - 1) * limit
  366. db = db.Offset(offset).Limit(limit)
  367. }
  368. err := db.Find(&vms).Error
  369. return vms, err, total
  370. }
  371. func PCGetDialysisGoodsThree(orgID int64, scheduleDate int64) ([]*MDialysisGoodsVM, error) {
  372. var vms []*MDialysisGoodsVM
  373. db := readDb.
  374. Model(&models.Schedule{}).
  375. Select("patient_id,mode_id").
  376. Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  377. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  378. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  379. Preload("DialysisBeforePrepare", func(db *gorm.DB) *gorm.DB {
  380. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND user_org_id = ? AND record_date = ? AND count > 0 ", orgID, scheduleDate)
  381. }).
  382. Preload("AutomaticReduceDetail", func(db *gorm.DB) *gorm.DB {
  383. return db.Preload("VMGoodInfo", "status = 1 AND org_id = ? ", orgID).Preload("GoodsType", "status = 1 AND (org_id = ? OR org_id = 0) ", orgID).Where("status = 1 AND org_id = ? AND record_time = ? AND count > 0", orgID, scheduleDate)
  384. }).Where("xt_schedule.status = 1 AND xt_schedule.user_org_id = ?", orgID)
  385. if scheduleDate != 0 {
  386. db = db.Where("schedule_date = ?", scheduleDate)
  387. }
  388. err = db.Find(&vms).Error
  389. return vms, err
  390. }