123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- package service
-
- import (
- "XT_New/models"
- "fmt"
- "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) {
- fmt.Println("ids23322332323232wode", len(ids))
- 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)
- 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("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)
- }
- fmt.Println("idArray23233223323232233232", len(idArray))
- 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).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).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 GetAllHisAdviceTemplateList(user_org_id int64) (advice []*models.HisPrescriptionAdviceTemplate, err error) {
-
- 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 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.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("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("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 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("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 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("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 GetDialysisAdviceSchedulistTwo(orgID int64, schedule_type int64, partition_id int64, 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 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) {
- fmt.Println("ids23322332323232hhha", ids)
- 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("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", 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("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", 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", orgID).Preload("GoodInfo", "org_id =? and status = 1", orgID)
- })
- })
- }).Find(&schedule).Error
-
- return schedule, err
- }
|