123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698 |
- 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("DialysisSolution", "status=1 and solution_status =1 and user_org_id=?", orgID).
- Preload("DialysisPrescription", "status=1 and record_date = ? and user_org_id=?", scheduleDate, 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("DialysisSolution", "status=1 and solution_status =1 and user_org_id=?", orgID).
- Preload("DialysisPrescription", "status=1 and record_date = ? and user_org_id=?", scheduleDate, 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
- }
|