package service import ( "XT_New/models" "github.com/jinzhu/gorm" ) 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, ids []string) (schedule []*models.VmBloodSchedule, total int64, err error) { db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1") offset := (page - 1) * limit if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } if partition_id > 0 { db = db.Where("xt_schedule.partition_id = ?", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } if len(ids) >= 1 { db = db.Where("xt_schedule.id in(?)", ids) } if len(keywords) > 0 { keywords = "%" + keywords + "%" db = db.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).Preload("DialysisPrescription", "status=1 and user_org_id =? and record_date =?", orgID, scheduleDate) 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).Find(&schedule).Error } else { err = db.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("DialysisPrescription", "status=1 and user_org_id =? and record_date =?", orgID, scheduleDate). Preload("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID).Count(&total).Offset(offset).Limit(limit).Find(&schedule).Error } return schedule, total, err } 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) { db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1") offset := (page - 1) * limit if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } if partition_id > 0 { db = db.Where("xt_schedule.partition_id = ?", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } if len(idArray) >= 1 { db = db.Where("xt_schedule.id in(?)", idArray) } 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("HisDoctorAdvice", "status=1 and user_org_id =? and advice_date =?", orgID, scheduleDate).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("HisDoctorAdvice", "status=1 and user_org_id =? and advice_date =?", orgID, scheduleDate).Find(&schedule).Error } return schedule, total, err } func GetAllLongAdviceList(user_org_id int64) (advice []*models.DoctorAdvice, err error) { err = XTReadDB().Where("user_org_id = ? and advice_type = 1 and status = 1 and stop_state!=1", user_org_id).Find(&advice).Error return advice, err } func GetHisLongAdviceList(user_org_id int64) (advice []*models.HisDoctorAdviceTemplate, err error) { err = XTReadDB().Where("org_id = ? and status=1", user_org_id).Find(&advice).Error return advice, err } func GetAllHisAdviceTemplateList(user_org_id int64, keywords string) (advice []*models.HisPrescriptionAdviceTemplate, err error) { keywords = "%" + keywords + "%" if len(keywords) > 0 { err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_name like ?", user_org_id, keywords).Find(&advice).Error return advice, err } else { err = XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Find(&advice).Error return advice, err } } func SaveDialysisSetting(setting models.XtDialysisSetting) error { err := XTWriteDB().Create(&setting).Error return err } func GetDialysisSetting(orgid int64) (models.XtDialysisSetting, error) { setting := models.XtDialysisSetting{} err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&setting).Error return setting, err } func GetDialysisParameterList(keywords string, limit int64, page int64, partition_id []string, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodSchedule, total int64, err error) { db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1") offset := (page - 1) * limit if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } //if partition_id > 0 { // db = db.Where("xt_schedule.partition_id = ?", partition_id) //} if len(partition_id) > 0 { db = db.Where("xt_schedule.partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } if len(ids) >= 1 { db = db.Where("xt_schedule.id in(?)", ids) } 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("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID). Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate) }). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate). Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate). Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", 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("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID). Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate). Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate). Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate) }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error } return schedule, total, err } func GetDialysisGoodTotalCount(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) { db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1") 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 len(partition_id) > 0 { db = db.Where("partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("DialysisSolution", "status = 1 AND user_org_id = ? AND solution_status = 1", orgID). Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error return schedule, err } func GetDialysisAdviceSchedulist(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) { db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1") 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 len(partition_id) > 0 { db = db.Where("partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate). Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID) }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error return schedule, err } func GetDialysisAdviceSchedulistTwo(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) { db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("status = 1") 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 len(partition_id) > 0 { db = db.Where("partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } err = db.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("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID) }) }) }).Find(&schedule).Error return schedule, err } 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) { db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1") offset := (page - 1) * limit if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } if partition_id > 0 { db = db.Where("xt_schedule.partition_id = ?", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } if len(idArray) >= 1 { db = db.Where("xt_schedule.id in(?)", idArray) } 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("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and 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("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and type = 1", orgID).Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("Drug", "org_id =? and status = 1", orgID) }) }) }).Find(&schedule).Error } return schedule, total, err } func GetAllDrugMap(org_id int64) (list []*BaseDrugLib, err error) { err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&list).Error return list, err } func GetDialysisParameterGoodList(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodSchedule, err error) { db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("status = 1") 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) } err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DialysisSolution", "status=1 and user_org_id = ? and solution_status = 1", orgID). Preload("DialysisPrescription", "status = 1 and user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate). Preload("HisDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ?", orgID, scheduleDate). Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error return schedule, err } func SaveHisDialysis(orgid int64, ids []string) error { goodsType := models.BloodGoodsType{} err := XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 1}).Error err = XTWriteDB().Model(&goodsType).Where("org_id = ? and status = 1 and id not in(?)", orgid, ids).Update(map[string]interface{}{"is_open": 0}).Error return err } 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) { db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1") offset := (page - 1) * limit if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } if partition_id > 0 { db = db.Where("xt_schedule.partition_id = ?", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } if len(ids) >= 1 { db = db.Where("xt_schedule.id in(?)", ids) } if len(keywords) > 0 { keywords = "%" + keywords + "%" db = db.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("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and record_date = ? and type =3", orgID, scheduleDate).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB { return db.Where("org_id = ? and status = 1", orgID) }) }).Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB { 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) }) }) }) 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).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("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and record_date = ? and type =3", orgID, scheduleDate).Preload("GoodInfo", func(db *gorm.DB) *gorm.DB { return db.Where("org_id = ? and status = 1", orgID) }) }).Preload("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB { 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) }) }) }).Find(&schedule).Error } return schedule, total, err } func GetHisDialysisGoodCount(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) { db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1") if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } if partition_id > 0 { db = db.Where("xt_schedule.partition_id = ?", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } err = db. 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("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB { 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) }) }) }).Find(&schedule).Error return schedule, err } func GeAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) { err = XTReadDB().Where("user_org_id = ? and status = 1 and advice_date = ?", user_org_id, advice_date).Find(&advice).Error return advice, err } func GetHisAdviceListToday(user_org_id int64, advice_date int64) (advice []*models.HisDoctorAdviceFourty, err error) { 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 return advice, err } func GetDialysisAdviceSchedulistSeven(orgID int64, schedule_type int64, partition_id int64, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) { db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1") 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) } err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate). Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID) }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error return schedule, err } func GetDialysisAdviceSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleOne, err error) { db := XTReadDB().Model(&models.VmBloodScheduleOne{}).Where("status = 1") if scheduleDate > 0 { db = db.Where("schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("schedule_type = ?", schedule_type) } if len(partition_id) > 0 { db = db.Where("partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 2", orgID, scheduleDate). Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID) }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error return schedule, err } func GetDialysisProjectSchedulistTen(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleSix, err error) { db := XTReadDB().Model(&models.VmBloodScheduleSix{}).Where("status = 1") if scheduleDate > 0 { db = db.Where("schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("schedule_type = ?", schedule_type) } if len(partition_id) > 0 { db = db.Where("partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and record_date = ? and type =3", orgID, scheduleDate).Preload("Good", "org_id =? and status = 1", orgID) }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error return schedule, err } func GetHisDialysisGoodCountTwo(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmBloodScheduleTwo, err error) { db := XTReadDB().Model(&models.VmBloodScheduleTwo{}).Where("xt_schedule.status = 1") if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } if len(partition_id) > 0 { db = db.Where("xt_schedule.partition_id in (?)", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } err = db. 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("HisPrescriptionTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1", orgID).Preload("HisPrescriptionInfoTemplateSix", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and type = 2", orgID).Preload("HisPrescriptionProjectTemplateSeven", func(db *gorm.DB) *gorm.DB { 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) }) }) }).Find(&schedule).Error return schedule, err } func GetLongDialysisAdviceToday(orgID int64, schedule_type int64, partition_id []string, scheduleDate int64) (schedule []*models.VmLongBloodSchedule, err error) { db := XTReadDB().Model(&models.VmLongBloodSchedule{}).Where("status = 1") if scheduleDate > 0 { db = db.Where("schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("schedule_type = ?", schedule_type) } if len(partition_id) > 0 { db = db.Where("partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } err = db.Preload("SchedualPatient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_type = 1", orgID). Preload("HisDoctorAdvice", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and advice_date = ?", orgID, scheduleDate).Preload("Drug", "org_id =? and status = 1", orgID) }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error return schedule, err } func GetDialysisGatherList(keywords string, limit int64, page int64, partition_id []string, schedule_type int64, scheduleDate int64, orgID int64, ids []string) (schedule []*models.VmBloodSchedule, total int64, err error) { db := XTReadDB().Model(&models.VmBloodSchedule{}).Where("xt_schedule.status = 1") offset := (page - 1) * limit if scheduleDate > 0 { db = db.Where("xt_schedule.schedule_date = ?", scheduleDate) } if schedule_type > 0 { db = db.Where("xt_schedule.schedule_type = ?", schedule_type) } //if partition_id > 0 { // db = db.Where("xt_schedule.partition_id = ?", partition_id) //} if len(partition_id) > 0 { db = db.Where("xt_schedule.partition_id in(?)", partition_id) } if orgID > 0 { db = db.Where("xt_schedule.user_org_id = ?", orgID) } if len(ids) >= 1 { db = db.Where("xt_schedule.id in(?)", ids) } 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("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID). Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate) }). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate). Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate). Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", 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("DialysisSolution", "status = 1 AND user_org_id = ? and solution_status = 1", orgID). Preload("DialysisPrescription", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("ReceiveTreatmentAsses", "status = 1 AND user_org_id = ? and record_date = ?", orgID, scheduleDate). Preload("XtAssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Preload("XtDoctorAdvice", "status = 1 AND user_org_id = ? and advice_date = ? and advice_type = 1", orgID, scheduleDate). Preload("XtDoctorAdviceOne", "status = 1 AND user_org_id = ? and advice_date = ? and (advice_type = 2 or advice_type =3)", orgID, scheduleDate). Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? and status = 1 and assessment_date < ?", orgID, scheduleDate) }).Preload("DeviceNumber.Zone", "status = 1 AND org_id = ?", orgID).Find(&schedule).Error } return schedule, total, err }