dialysis_solution_service.go 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. )
  6. func GetPatientSolutionGroupList(patient_id int64, orgid int64) (solution []*models.DialysisSolution, err error) {
  7. err = XTReadDB().Where("patient_id = ? and status = 1 and user_org_id = ?", patient_id, orgid).Group("mode_id").Find(&solution).Error
  8. return solution, err
  9. }
  10. func GetNewPatientSolutionByModeId(patient_id int64, mode_id int64, orgid int64) (models.DialysisSolution, error) {
  11. solution := models.DialysisSolution{}
  12. 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
  13. return solution, err
  14. }
  15. func UpdateDialysisSolutionStatus(id int64, mode_id int64, orgid int64, patient_id int64) error {
  16. err := XTWriteDB().Model(&models.DialysisSolution{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Update(map[string]interface{}{"solution_status": 1}).Error
  17. 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
  18. return err
  19. }
  20. func UpdateDialysisSolutionStatusTwo(id int64, mode_id int64, orgid int64, patient_id int64) error {
  21. 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
  22. return err
  23. }
  24. func GetLastPatientDialysisSolution(patient_id int64, orgid int64) (models.DialysisSolution, error) {
  25. solution := models.DialysisSolution{}
  26. err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status = 1", patient_id, orgid).Last(&solution).Error
  27. return solution, err
  28. }
  29. 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) {
  30. db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1")
  31. offset := (page - 1) * limit
  32. if scheduleDate > 0 {
  33. db = db.Where("schedule_date = ?", scheduleDate)
  34. }
  35. if schedule_type > 0 {
  36. db = db.Where("schedule_type = ?", schedule_type)
  37. }
  38. if partition_id > 0 {
  39. db = db.Where("partition_id = ?", partition_id)
  40. }
  41. if orgID > 0 {
  42. db = db.Where("user_org_id = ?", orgID)
  43. }
  44. if len(keywords) > 0 {
  45. keywords = "%" + keywords + "%"
  46. 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)
  47. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  48. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  49. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  50. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error
  51. } else {
  52. err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID).
  53. Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).
  54. Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).
  55. Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error
  56. }
  57. fmt.Println("err2332232323233223232332", err)
  58. fmt.Println("total99999999999999999999", total)
  59. fmt.Println("scheudle23323233232", schedule)
  60. return schedule, total, err
  61. }