package service import ( "XT_New/models" "fmt" ) func GetPatientSolutionGroupList(patient_id int64, orgid int64) (solution []*models.DialysisSolution, err error) { err = XTReadDB().Where("patient_id = ? and status = 1 and user_org_id = ?", patient_id, orgid).Group("mode_id").Find(&solution).Error return solution, err } func GetNewPatientSolutionByModeId(patient_id int64, mode_id int64, orgid int64) (models.DialysisSolution, error) { solution := models.DialysisSolution{} 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 return solution, err } func UpdateDialysisSolutionStatus(id int64, mode_id int64, orgid int64, patient_id int64) error { err := XTWriteDB().Model(&models.DialysisSolution{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgid).Update(map[string]interface{}{"solution_status": 1}).Error 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 return err } func UpdateDialysisSolutionStatusTwo(id int64, mode_id int64, orgid int64, patient_id int64) error { 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 return err } func GetLastPatientDialysisSolution(patient_id int64, orgid int64) (models.DialysisSolution, error) { solution := models.DialysisSolution{} err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status = 1", patient_id, orgid).Last(&solution).Error return solution, err } 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) { db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1") offset := (page - 1) * limit if scheduleDate > 0 { db = db.Where("schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("schedule_type = ?", schedule_type) } if partition_id > 0 { db = db.Where("partition_id = ?", partition_id) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } if len(keywords) > 0 { keywords = "%" + keywords + "%" 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) err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID). Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error } else { err = db.Count(&total).Offset(offset).Limit(limit).Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID). Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Find(&schedule).Error } fmt.Println("err2332232323233223232332", err) fmt.Println("total99999999999999999999", total) fmt.Println("scheudle23323233232", schedule) return schedule, total, err }