123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- package service
-
- import (
- "XT_New/models"
- )
-
- 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
- }
-
- return schedule, total, err
- }
-
- func GetDialysisAdviceTemplateList(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).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", 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) (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("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("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("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("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("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 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("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
- }
|