package service import ( "encoding/json" "fmt" "strconv" "strings" "time" "XT_New/models" "github.com/jinzhu/gorm" ) // GetPatientList 返回患者的列表 func GetSchedualPatientList(orgID int64, schedulDate int64, schedulType int64, partitionType int64, keywords string, page int64, limit int64) (schedule []*models.DialysisSchedule, err error) { var total int64 //if len(keywords) > 0 { // likeKey := "%" + keywords + "%" // //db = db.Preload("MonitorPatients", "status = 1 AND user_org_id = ? AND `name` LIKE ? ", orgID, likeKey).Preload("DeviceNumber", "status = 1 AND org_id = ? ", orgID).Preload("PredialysisEvaluation", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, schedulDate).Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, schedulDate).Preload("MonitoringRecord", "status = 1 AND user_org_id = ? AND monitoring_date = ?", orgID, schedulDate).Where("status = 1 AND user_org_id = ? ", orgID) // db = readDb. // Model(&models.MonitorDialysisSchedule{}). // Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID). // Preload("TreatmentMode", "status = 1"). // Preload("Prescription", "status = 1 AND user_org_id = ?", orgID). // Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID). // Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID). // Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID). // Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID). // Preload("MonitorPatients", "status = 1 AND user_org_id = ? AND `name` LIKE ?", orgID,likeKey) // // //} else { //} db := readDb. Model(&models.MonitorDialysisSchedule{}). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, schedulDate). Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate). Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, schedulDate). Preload("MonitoringRecord", "status = 1 AND user_org_id = ? AND monitoring_date = ?", orgID, schedulDate). Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, schedulDate). Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID) db = db.Where("status = 1") if schedulDate > 0 { db = db.Where("schedule_date = ?", schedulDate) } db = db.Count(&total) fmt.Println(total) if schedulType > 0 { db = db.Where("schedule_type = ?", schedulType) } if partitionType > 0 { db = db.Where("partition_id = ?", partitionType) } offset := (page - 1) * limit errors := db.Offset(offset).Limit(limit).Find(&schedule).Error return schedule, errors } // 用户基本信息 func FindPatientInfoById(orgID int64, id int64, time int64) (patient models.SchedualPatient2, err error) { err = readDb.Preload("DialysisSchedule", func(db *gorm.DB) *gorm.DB { return db.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Preload("DeviceZone", "status = 1 AND org_id = ?", orgID).Where("patient_id = ? AND user_org_id = ? AND schedule_date = ? ", id, orgID, time) }).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&patient).Error return } // 透析处方 func FindPatientPrescribeById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescription, err error) { err = readDb.Model(&models.DialysisPrescription{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate).First(&patient).Error return } // 透析方案中的透析处方 func FindDialysisSolution(orgID int64, patientsId int64) (patient models.DialysisSolution, err error) { err = readDb.Model(&models.DialysisSolution{}).Where("patient_id = ? and user_org_id=? and status=1", patientsId, orgID).Last(&patient).Error return } // 透析方案中的透析模式 func FindTreatmentModeById(modeId int64) (mode models.TreatmentMode, err error) { err = readDb.Model(&models.TreatmentMode{}).Where("id = ? AND status=1", modeId).First(&mode).Error return } // 接诊评估 func FindReceiverTreatmentAccessRecordById(orgID int64, patientsId int64, recordDate int64) (receiveTreatmentAsses models.ReceiveTreatmentAsses, err error) { err = readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ?", patientsId, orgID, recordDate).First(&receiveTreatmentAsses).Error return } // 透前评估 func FindPredialysisEvaluationById(orgID int64, patientsId int64, recordDate int64) (patient models.PredialysisEvaluation, err error) { err = readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ?", patientsId, orgID, recordDate).First(&patient).Error return } func FindPredialysisName(id int64, orgid int64) (models.Dataconfig, error) { dataconfig := models.Dataconfig{} err := readDb.Where("value = ? and org_id =? and status = 1", id, orgid).Find(&dataconfig).Error return dataconfig, err } // 临时医嘱 func FindDoctorAdviceById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) { err = readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? AND advice_type = 2", patientsId, orgID, recordDate).Find(&patient).Error return } func FindDoctorAdviceByInfo(orgID int64, patientsId int64, recordDate int64) (advices []*models.XtDoctorAdvice, err error) { //db := readDb.Table("xt_doctor_advice as a").Where("a.status = ?", 1) //err = db.Group("a.advice_name").Select("a.id,a.user_org_id,a.patient_id,a.advice_type,a.advice_date,a.start_time,a.advice_name,a.advice_desc,a.reminder_date,a.single_dose,a.single_dose_unit,a.prescribing_number,a.prescribing_number_unit,a.delivery_way,a.execution_frequency,a.advice_doctor,a.status,a.created_time,a.updated_time,a.advice_affirm,a.remark,a.stop_time,a.stop_reason,a.stop_doctor,a.stop_state,a.parent_id,a.execution_time,a.execution_staff,a.execution_state,a.checker,a.record_date,a.dialysis_order_id,a.check_time,a.check_state,a.drug_spec,a.drug_spec_unit,a.groupno,a.remind_type,a.frequency_type,a.day_count,a.week_day,a.template_id,r.user_name,s.user_name").Joins(" left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = a.execution_staff").Joins("left join sgj_users.sgj_user_admin_role as s on s.admin_user_id = a.checker").Where("a.user_org_id = ? and a.patient_id = ? and a.advice_date = ?", orgID, patientsId, recordDate).Find(&advices).Error //return err = readDb.Model(&models.DoctorAdvice{}). Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and advice_type = 2", patientsId, orgID, recordDate). Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time asc, groupno desc, advice_order desc, id asc"). Find(&advices).Error return } func GetTotalDialysisCout(orgid int64, patientid int64) (order []*models.DialysisOrder, total int64, err error) { err = readDb.Model(&order).Where("user_org_id = ? and patient_id = ? and status = 1", orgid, patientid).Find(&order).Count(&total).Error return order, total, err } // 临时医嘱 func FindDoctorAdviceOrderById(orgID int64, patientsId int64, recordDate int64) (patient []*models.DoctorAdvice, err error) { err = readDb.Model(&models.DoctorAdvice{}). Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? and (advice_type = 2 or advice_type = 3)", patientsId, orgID, recordDate). Select("id, user_org_id, patient_id, advice_type, advice_date, record_date, start_time, advice_name,advice_desc, reminder_date, drug_spec, drug_spec_unit, single_dose, single_dose_unit, prescribing_number, prescribing_number_unit, delivery_way, execution_frequency, advice_doctor, status, created_time,updated_time, advice_affirm, remark, stop_time, stop_reason, stop_doctor, stop_state, parent_id, execution_time, execution_staff, execution_state, checker, check_state, check_time, groupno, IF(parent_id > 0, parent_id, id) as advice_order").Order("start_time asc, groupno desc, advice_order desc, id asc"). Find(&patient).Error return } // 双人核对 func FindDoubleCheckById(orgID int64, patientsId int64, recordDate int64) (patient models.DoubleCheck, err error) { err = readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? and user_org_id=? and status=1 and check_date = ? ", patientsId, orgID, recordDate).First(&patient).Error return } // 透析监测 func FindAllMonitorRecord(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) { err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientsId, orgID, recordDate).Order("operate_time ASC").Find(&record).Error return } func FindAllMonitor(orgID int64, patientsId int64, recordDate int64) (record []*models.MonitoringRecord, err error) { err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? and user_org_id=? and status=1 and monitoring_date = ?", patientsId, orgID, recordDate).Order("operate_time ASC").Find(&record).Error return } // 透后评估 func FindAssessmentAfterDislysisById(orgID int64, patientsId int64, recordDate int64) (patient models.AssessmentAfterDislysis, err error) { err = readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date =?", patientsId, orgID, recordDate).First(&patient).Error return } // 治疗小结 func FindTreatmentSummaryById(orgID int64, patientsId int64, recordDate int64) (patient models.TreatmentSummary, err error) { err = readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? and user_org_id=? and status=1 and assessment_date = ? ", patientsId, orgID, recordDate).First(&patient).Error return } // 机构叫号配置 func FindQueueCallInfo(orgID int64) (queueConfig models.QueueCallConfig, err error) { err = readDb.Model(&models.QueueCallConfig{}).Where("org_id=? ", orgID).First(&queueConfig).Error return } // 修改机构叫号配置 func UpDateQueueCallInfo(queueConfig models.QueueCallConfig) error { err := writeDb.Save(&queueConfig).Error return err } // 所有设备信息 func FindAllDeviceInfo(orgID int64) (device []*models.Device, err error) { err = readDb.Model(&models.Device{}).Where("org_id=? and status=1 and device_type = 1", orgID).Find(&device).Error return device, err } // 所有设备区域 func GetAllDeviceZone(orgId int64) (error, []*models.DeviceZone) { var zone []*models.DeviceZone err := readDb.Model(&zone).Where("org_id = ? AND status = 1", orgId).Find(&zone).Error return err, zone } // 获取所有子药物 func FindAllSubDoctorAdvice(id int64, parentId int64) (error, []models.DoctorAdvice) { var subAdvies []models.DoctorAdvice err := readDb.Model(&subAdvies).Where("patient_id = ? AND parent_id = ?", id, parentId).Find(&subAdvies).Error return err, subAdvies } func FindAdivceById(orgId int64, patientId int64, id int64) (error, models.DoctorAdvice) { advices := models.DoctorAdvice{} err := readDb.Model(&advices).Where("user_org_id = ? AND patient_id = ? AND id = ? AND status = 1", orgId, patientId, id).Find(&advices).Error return err, advices } func FindSubAdivceById(patientId int64, parentId int64) []*models.DoctorAdvice { var subAdvices []*models.DoctorAdvice readDb.Model(&subAdvices).Where("patient_id = ? AND parent_id = ?", patientId, parentId).Find(&subAdvices) return subAdvices } func AddSigleRecord(prescription *models.DialysisPrescription) (err error) { tx := writeDb.Begin() errors := tx.Model(&models.DialysisPrescription{}).Create(&prescription).Error if err != nil { tx.Rollback() } tx.Commit() return errors } func AddSigleRecordOne(prescription *models.DialysisPrescription) (err error) { errors := XTWriteDB().Model(&models.DialysisPrescription{}).Create(&prescription).Error return errors } func UpdateAddSigleRecord(id int64, target_ultrafiltration float64) error { err := XTWriteDB().Model(&models.DialysisPrescription{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"target_ultrafiltration": target_ultrafiltration, "prescription_water": target_ultrafiltration}).Error return err } func AddSigleSummaryRecord(summary *models.TreatmentSummary) (err error) { tx := writeDb.Begin() errors := tx.Model(&models.TreatmentSummary{}).Create(&summary).Error if err != nil { tx.Rollback() } tx.Commit() return errors } func AddSigleReceiveTreatmentAssesRecord(receiveTreatmentAsses *models.ReceiveTreatmentAsses) (err error) { tx := writeDb.Begin() errors := tx.Model(&models.ReceiveTreatmentAsses{}).Create(&receiveTreatmentAsses).Error if err != nil { tx.Rollback() } tx.Commit() return errors } func AddSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) (err error) { tx := writeDb.Begin() errors := tx.Model(&models.AssessmentAfterDislysis{}).Create(&assessmentAfterDislysis).Error if err != nil { tx.Rollback() } tx.Commit() return errors } func GetSigleAssessmentAfterDislysisRecord(patient_id int64, assesment_date int64, user_org_id int64) (models.AssessmentAfterDislysis, error) { afterDislysis := models.AssessmentAfterDislysis{} err := XTReadDB().Where("patient_id=? and assessment_date = ? and user_org_id = ? and status=1", patient_id, assesment_date, user_org_id).Find(&afterDislysis).Error return afterDislysis, err } func AddSigleAssessmentBeforeDislysisRecord(assessmentBeforeDislysis *models.PredialysisEvaluation) (err error) { tx := writeDb.Begin() errors := tx.Model(&models.PredialysisEvaluation{}).Create(&assessmentBeforeDislysis).Error if err != nil { tx.Rollback() } tx.Commit() return errors } func AddSigleDoubleCheck(check *models.DoubleCheck) (err error) { tx := writeDb.Begin() errors := tx.Model(&models.DoubleCheck{}).Create(&check).Error if err != nil { tx.Rollback() } tx.Commit() return errors } // 修改透析处方 func UpDateDialysisPrescription(dialysisPrescription *models.DialysisPrescription) error { tx := writeDb.Begin() err := writeDb.Save(&dialysisPrescription).Error if err != nil { tx.Rollback() } tx.Commit() return err } // 修改接诊评估 func UpadateReceiveTreatmentAsses(receiveTreatmentAsses *models.ReceiveTreatmentAsses) error { err := writeDb.Save(receiveTreatmentAsses).Error return err } func GetPredialysisEvaluation(patient_id int64, org_id int64) (models.PredialysisEvaluation, error) { evaluation := models.PredialysisEvaluation{} err := XTReadDB().Where("patient_id = ? and user_org_id = ? and status =1 and symptom_before_dialysis!=''", patient_id, org_id).Last(&evaluation).Error return evaluation, err } // 修改透前评估 func UpadatePredialysisEvaluation(predialysisEvaluation *models.PredialysisEvaluation) error { err := writeDb.Save(&predialysisEvaluation).Error return err } // 修改双人核对 func UpdateDoubleCheck(check *models.DoubleCheck) error { err := writeDb.Save(&check).Error return err } // 修改透后评估 func UpdateAssessmentAfterDislysisRecord(assessmentAfterDislysis *models.AssessmentAfterDislysis) error { err := writeDb.Save(&assessmentAfterDislysis).Error return err } func UpdatePredialysisEvaluation(predialysisevaluation *models.PredialysisEvaluation, id int64) error { err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"systolic_blood_pressure": predialysisevaluation.SystolicBloodPressure}).Error return err } func UpdatePredialysisEvaluationTwo(predialysisevaluation *models.PredialysisEvaluation, id int64) error { err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"diastolic_blood_pressure": predialysisevaluation.DiastolicBloodPressure}).Error return err } func UpdatePredialysisEvaluationThree(predialysisevaluation *models.PredialysisEvaluation, id int64) error { err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"pulse_frequency": predialysisevaluation.PulseFrequency}).Error return err } func UpdatePredialysisEvaluationFour(predialysisevaluation *models.PredialysisEvaluation, id int64) error { err := writeDb.Model(&predialysisevaluation).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"temperature": predialysisevaluation.Temperature}).Error return err } // 修改 func UpdateSummeRecord(treatmentSummary *models.TreatmentSummary) error { err := writeDb.Save(&treatmentSummary).Error return err } // func UpdateDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error { // tx := writeDb.Begin() // err := tx.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND id = ? AND status = 1 ", patientId, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1, "checker": m.Checker}).Error // if err != nil { // tx.Rollback() // } // tx.Commit() // return err // } func ExceDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error { err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error return err } func ExecBatchDoctorAdvice(patient_id int64, orgid int64, ids []string, creater int64) error { err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND user_org_id = ? and id in(?) AND status = 1 ", patient_id, orgid, ids).Updates(map[string]interface{}{"execution_time": time.Now().Unix(), "execution_staff": creater, "execution_state": 1}).Error return err } func ExceHidDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error { err := writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1, "is_mobile": 2}).Error return err } func ExceHisBatchDotorAdvice(patientid int64, orgid int64, ids []string, creater int64) error { err := writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND user_org_id = ? and id in(?) AND status = 1 ", patientid, orgid, ids).Updates(map[string]interface{}{"execution_time": time.Now().Unix(), "execution_staff": creater, "execution_state": 1}).Error return err } func CheckDoctorAdviceById(m *models.DoctorAdvice, id int64, patientId int64) error { err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error return err } func CheckHisBathDoctorAdviceById(patientId int64, orgid int64, creater int64, ids []string) error { err := writeDb.Model(&models.HisDoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and id in(?)", patientId, orgid, ids).Updates(map[string]interface{}{"check_time": time.Now().Unix(), "checker": creater, "check_state": 1}).Error return err } func CheckBatchDoctorAdviceById(patientId int64, ids []string, orgid int64, creater int64) error { err := writeDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and id in(?)", patientId, orgid, ids).Updates(map[string]interface{}{"check_time": time.Now().Unix(), "checker": creater, "check_state": 1}).Error return err } func CheckHisDoctorAdviceById(m *models.HisDoctorAdviceInfo, id int64, patientId int64) error { err := writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("patient_id = ? AND (id = ? Or parent_id=?) AND status = 1 ", patientId, id, id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error return err } func CreateMonitor(m *models.MonitoringRecord) (err error) { return writeDb.Create(m).Error } func UpdateMonitor(m *models.MonitoringRecord) (err error) { return writeDb.Save(m).Error } func DelMonitor(patientId int64, recordId int64) error { tx := writeDb.Begin() updateTime := time.Now().Unix() err := tx.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND id = ? AND status = 1 ", patientId, recordId).Updates(map[string]interface{}{"status": 0, "updated_time": updateTime}).Error if err != nil { tx.Rollback() } tx.Commit() return err } //修改长期处方 func UpdateSolution(solution *models.DialysisSolution) { writeDb.Save(&solution) } // 创建长期处方 func CreateSolution(solution *models.DialysisSolution) { writeDb.Create(&solution) } func SavePrescriptionAndCreateSolution(solution *models.DialysisSolution, prescription *models.DialysisPrescription) (err error) { tx := writeDb.Begin() if prescription.ID > 0 { err = tx.Save(&prescription).Error } else { err = tx.Model(&models.DialysisPrescription{}).Create(&prescription).Error } if err != nil { tx.Rollback() return } err = tx.Create(&solution).Error if err != nil { tx.Rollback() return } tx.Commit() return } // 透析处方 func FindDialysisPrescriptionByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DialysisPrescription) { dialysisPrescription := models.DialysisPrescription{} err := readDb.Model(&dialysisPrescription).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ? ", id, recordDate, orgId).Find(&dialysisPrescription).Error return err, &dialysisPrescription } func FindReceiveTreatmentAssesByReordDate(id int64, recordDate int64, orgId int64) (error, *models.ReceiveTreatmentAsses) { receiveTreatmentAsses := models.ReceiveTreatmentAsses{} err := readDb.Model(&receiveTreatmentAsses).Where("patient_id = ? AND record_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).Find(&receiveTreatmentAsses).Error return err, &receiveTreatmentAsses } // 透前评估 func FindPredialysisEvaluationByReordDate(id int64, recordDate int64, orgId int64) (error, *models.PredialysisEvaluation) { dialysisEvaluation := models.PredialysisEvaluation{} err := readDb.Model(&models.PredialysisEvaluation{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&dialysisEvaluation).Error return err, &dialysisEvaluation } // 双人核对 func FindDoubleCheckByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoubleCheck) { check := models.DoubleCheck{} err := readDb.Model(&models.DoubleCheck{}).Where("patient_id = ? AND check_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&check).Error return err, &check } func FindAssessmentAfterDislysisByReordDate(id int64, recordDate int64, orgId int64) (error, *models.AssessmentAfterDislysis) { assessmentAfterDislysis := models.AssessmentAfterDislysis{} err := readDb.Model(&models.AssessmentAfterDislysis{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&assessmentAfterDislysis).Error return err, &assessmentAfterDislysis } func FindTreatmentSummaryByReordDate(id int64, recordDate int64, orgId int64) (error, *models.TreatmentSummary) { summary := models.TreatmentSummary{} err := readDb.Model(&models.TreatmentSummary{}).Where("patient_id = ? AND assessment_date = ? AND status = 1 AND user_org_id = ?", id, recordDate, orgId).First(&summary).Error return err, &summary } func FindDoctorAdviceByReordDate(id int64, recordDate int64, orgId int64) (error, *models.DoctorAdvice) { advice := models.DoctorAdvice{} err := readDb.Model(&models.DoctorAdvice{}).Where("patient_id = ? AND record_date = ? AND parent_id = 0 AND status = 1 AND user_org_id = ? ", id, recordDate, orgId).First(&advice).Error return err, &advice } func FindDialysisRecordById(orgId int64, id int64, recordDate int64) (error, *models.DialysisOrder) { var count int64 dialysisRecord := models.DialysisOrder{} err := readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? AND dialysis_date = ?", orgId, id, recordDate).Find(&dialysisRecord).Count(&count).Error if count <= 0 { return err, nil } return err, &dialysisRecord } func FindDialysisSchedualById(orgId int64, id int64, recordDate int64) (error, *models.Schedule) { var count int64 schedule := models.Schedule{} err := readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ?", orgId, id, recordDate).Find(&schedule).Count(&count).Error if count <= 0 { return err, nil } return err, &schedule } func CreateDialysisRecord(id int64, orgId int64, record *models.DialysisOrder) error { err := writeDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND patient_id = ? ", orgId, id).Create(&record).Error if err != nil { return err } dialysisPrescriptionErr := UpDateRecordIdToDialysisPrescription(id, orgId, record.DialysisDate, record.ID) if dialysisPrescriptionErr != nil { return dialysisPrescriptionErr } receiveTreatmentAssesErr := UpDateRecordIdToReceiveTreatmentAsses(id, orgId, record.DialysisDate, record.ID) if receiveTreatmentAssesErr != nil { return receiveTreatmentAssesErr } predialysisEvaluationErr := UpDateRecordIdToPredialysisEvaluation(id, orgId, record.DialysisDate, record.ID) if predialysisEvaluationErr != nil { return predialysisEvaluationErr } treatmentSummaryErr := UpDateRecordIdToTreatmentSummary(id, orgId, record.DialysisDate, record.ID) if treatmentSummaryErr != nil { return treatmentSummaryErr } doubleCheckErr := UpDateRecordIdToDoubleCheck(id, orgId, record.DialysisDate, record.ID) if doubleCheckErr != nil { return doubleCheckErr } adviceErrr := UpDateRecordIdToDoctorAdvice(id, orgId, record.DialysisDate, record.ID) if adviceErrr != nil { return adviceErrr } //透析监测 records, err := FindAllMonitorRecord(orgId, id, record.DialysisDate) if err != nil { return err } var Ids []int64 for _, item := range records { Ids = append(Ids, item.ID) } monitorErr := UpDateRecordIdToMonitor(Ids, record.ID) if monitorErr != nil { return monitorErr } return nil } func ModifyDialysisRecord(id int64, finishNurse int64, end_time int64, admin_user_id int64, puncture_point_haematoma int64, internal_fistula string, catheter string, cruor string, mission string, condenser string) error { err := writeDb.Model(&models.DialysisOrder{}).Where("id = ? AND status = 1 ", id).Updates(map[string]interface{}{"updated_time": time.Now().Unix(), "stage": 2, "finish_nurse": finishNurse, "end_time": end_time, "finish_creator": admin_user_id, "finish_modifier": admin_user_id, "puncture_point_haematoma": puncture_point_haematoma, "blood_access_internal_fistula": internal_fistula, "catheter": catheter, "cruor": cruor, "mission": mission, "condenser": condenser}).Error return err } //func ModifyDialysisRecord(id int64, finishNurse int64, end_time int64, admin_user_id int64) error { // err := writeDb.Model(&models.DialysisOrder{}).Where("id = ? AND status = 1 ", id).Updates(map[string]interface{}{"updated_time": time.Now().Unix(), "stage": 2, "finish_nurse": finishNurse, "end_time": end_time, "finish_creator": admin_user_id, "finish_modifier": admin_user_id}).Error // return err // //} func UpdateSolutionByPatientId(id int64) error { err := writeDb.Model(&models.Patients{}).Where("id = ? AND status = 1 ", id).UpdateColumn("total_dialysis", gorm.Expr("total_dialysis + ?", 1)).Error return err } // 更新透析处方记录ID func UpDateRecordIdToDialysisPrescription(patientId int64, orgId int64, recordTime int64, recordId int64) error { errors := writeDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"record_id": recordId}).Error return errors } func UpDateRecordIdToReceiveTreatmentAsses(patientId int64, orgId int64, recordTime int64, recordId int64) error { errors := writeDb.Model(&models.ReceiveTreatmentAsses{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"record_id": recordId}).Error return errors } func UpDateRecordIdToPredialysisEvaluation(patientId int64, orgId int64, recordTime int64, recordId int64) error { errors := writeDb.Model(&models.PredialysisEvaluation{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error return errors } func UpDateRecordIdToAssessmentAfterDislysis(patientId int64, orgId int64, recordTime int64, recordId int64) error { errors := writeDb.Model(&models.AssessmentAfterDislysis{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error return errors } func UpDateRecordIdToTreatmentSummary(patientId int64, orgId int64, recordTime int64, recordId int64) error { errors := writeDb.Model(&models.TreatmentSummary{}).Where("user_org_id = ? AND patient_id = ? AND assessment_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error return errors } func UpDateRecordIdToMonitor(Ids []int64, recordId int64) error { errors := writeDb.Model(&models.MonitoringRecord{}).Where("id IN (?)", Ids).Update(map[string]interface{}{"dialysis_order_id": recordId}).Error return errors } func UpDateRecordIdToDoubleCheck(patientId int64, orgId int64, recordTime int64, recordId int64) error { errors := writeDb.Model(&models.DoubleCheck{}).Where("user_org_id = ? AND patient_id = ? AND check_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error return errors } func UpDateRecordIdToDoctorAdvice(patientId int64, orgId int64, recordTime int64, recordId int64) error { errors := writeDb.Model(&models.DoctorAdvice{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patientId, recordTime).Updates(map[string]interface{}{"dialysis_order_id": recordId}).Error return errors } // 透析处方 func FindPatientPrescribeWidyDevideById(orgID int64, patientsId int64, recordDate int64) (patient models.DialysisPrescriptionAddtional, err error) { err = readDb.Preload("Device", "status = 1 AND org_id = ?", orgID). Model(&models.DialysisPrescriptionAddtional{}). Where("patient_id = ? and user_org_id=? and status=1 and record_date = ? ", patientsId, orgID, recordDate). First(&patient).Error return } func FindDialysisMode(orgID int64, patientId int64, scheduleDate int64) (models.XtSchedule, error) { schedule := models.XtSchedule{} err = readDb.Where("user_org_id = ? and patient_id = ? and schedule_date = ? ", orgID, patientId, scheduleDate).Find(&schedule).Error return schedule, err } func FindDialysisMacher(orgid int64, patientid int64, dialysisDate int64) (models.XtDialysisOrders, error) { orders := models.XtDialysisOrders{} db := readDb.Table("xt_dialysis_order as o").Where("o.status = 1") table := readDb.Table("xt_device_number as n") fmt.Print("table", table) err := db.Select("o.id,o.dialysis_date,o.user_org_id,o.patient_id,o.prescription_id,o.stage,o.remark,o.bed_id,o.start_nurse,o.finish_nurse,o.status,o.created_time,o.updated_time,o.start_time,o.end_time,o.puncture_nurse,o.creator,o.modifier,o.finish_creator,o.finish_modifier,o.schedual_type,o.quality_nurse_id,o.blood_drawing,n.number,r.user_name").Joins("left join xt_device_number as n on n.id = o.bed_id").Joins("left join sgj_users.sgj_user_admin_role as r on r.admin_user_id = o.start_nurse").Where("o.user_org_id = ? and o.patient_id = ? and o.dialysis_date =?", orgid, patientid, dialysisDate).Scan(&orders).Error return orders, err } func FindPunctureNurse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) { role := models.App_Roles{} //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error //return role, err db := UserReadDB().Table("sgj_user_admin_role as r") err := db.Select("r.id,r.admin_user_id,r.org_id,r.role_id,r.user_name,r.avatar,r.user_type,r.user_title,r.intro,r.status,r.ctime,e.url").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = r.admin_user_id").Where("r.admin_user_id = ? and r.app_id = ? and r.org_id = ?", adminid, appid, orgid).Find(&role).Error return role, err } func FindeStartNuse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) { role := models.App_Roles{} db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1") err := db.Select("r.id,r.admin_user_id,r.org_id,r.role_id,r.user_name,r.avatar,r.user_type,r.user_title,r.intro,r.status,r.ctime,e.url").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = r.admin_user_id").Where("r.admin_user_id = ? and r.app_id = ? and r.org_id = ?", adminid, appid, orgid).Find(&role).Error //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error return role, err } func FindeQualityNurse(adminid int64, appid int64, orgid int64) (models.App_Roles, error) { role := models.App_Roles{} db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1") err := db.Select("r.id,r.admin_user_id,r.org_id,r.role_id,r.user_name,r.avatar,r.user_type,r.user_title,r.intro,r.status,r.ctime,e.url").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = r.admin_user_id").Where("r.admin_user_id = ? and r.app_id = ? and r.org_id = ?", adminid, appid, orgid).Find(&role).Error return role, err } func FindDialysisWay(orgid int64, patientid int64, recorddate int64) (models.DialysisPrescription, error) { prescription := models.DialysisPrescription{} err := readDb.Where("user_org_id = ? and patient_id = ? and record_date = ? and status =1", orgid, patientid, recorddate).Find(&prescription).Error return prescription, err } func FindDoctorOrder(orgid int64, patientid int64, adviceDate int64) (models.XtDoctorAdvice, error) { advices := models.XtDoctorAdvice{} db := readDb.Table("xt_doctor_advice as a").Where("a.status = ?", 1) err := db.Select("a.id,a.user_org_id,a.patient_id,a.advice_type,a.advice_date,a.start_time,a.advice_name,a.advice_desc,a.reminder_date,a.single_dose,a.single_dose_unit,a.prescribing_number,a.prescribing_number_unit,a.delivery_way,a.execution_frequency,a.advice_doctor,a.status,a.created_time,a.updated_time,a.advice_affirm,a.remark,a.stop_time,a.stop_reason,a.stop_doctor,a.stop_state,a.parent_id,a.execution_time,a.execution_staff,a.execution_state,a.checker,a.record_date,a.dialysis_order_id,a.check_time,a.check_state,a.drug_spec,a.drug_spec_unit,a.groupno,a.remind_type,a.frequency_type,a.day_count,a.week_day,a.template_id").Where("a.user_org_id = ? and a.patient_id = ? and a.advice_date = ?", orgid, patientid, adviceDate).Find(&advices).Error return advices, err } func FindDoctor(adminuserid int64, appid int64, orgid int64) (models.App_Role, error) { role := models.App_Role{} err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminuserid, appid, orgid).Find(&role).Error return role, err } func FindDoctorName(adminid int64, appid int64, orgid int64) (models.App_Roles, error) { role := models.App_Roles{} db := UserReadDB().Table("sgj_user_admin_role as r").Where("r.status = 1") err := db.Select("r.id,r.admin_user_id,r.org_id,r.role_id,r.user_name,r.avatar,r.user_type,r.user_title,r.intro,r.status,r.ctime,e.url").Joins("left join sgj_user_admin_electronic_signature as e on e.creator = r.admin_user_id").Where("r.admin_user_id = ? and r.app_id = ? and r.org_id = ?", adminid, appid, orgid).Find(&role).Error //err := UserReadDB().Where("admin_user_id = ? and app_id = ? and org_id = ?", adminid, appid, orgid).Find(&role).Error return role, err } // ///////////// 新 18-10-22 func GetDialysisScheduals(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) { var vms []*MDialysisScheduleVM db := readDb. Table("xt_schedule"). 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("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate). Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate). Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate). Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate). Preload("Advices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate). Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Where("status = 1 AND user_org_id = ?", orgID) if scheduleDate != 0 { db = db.Where("schedule_date = ?", scheduleDate) } err := db.Find(&vms).Error return vms, err } func GetDialysisSchedualsOne(orgID int64, scheduleDate int64) ([]*MDialysisScheduleVM, error) { var vms []*MDialysisScheduleVM db := readDb. Table("xt_schedule"). Preload("DeviceNumber", "org_id = ?", orgID). Preload("DeviceNumber.Zone", "org_id = ?", orgID). //Preload("DialysisOrder", "status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate). //Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate). //Preload("Prescription", "status = 1 AND user_org_id = ? AND record_date = ?", orgID, scheduleDate). //Preload("TreatmentSummary", "status = 1 AND user_org_id = ? AND assessment_date = ? ", orgID, scheduleDate). //Preload("Advices", "status = 1 AND user_org_id = ? AND advice_date = ? ", orgID, scheduleDate). //Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date = ?", orgID, scheduleDate). Where("status = 1 AND user_org_id = ?", orgID) if scheduleDate != 0 { db = db.Where("schedule_date = ?", scheduleDate) } err := db.Find(&vms).Error return vms, err } func GetLastAcceptsAssessment(patient int64, orgId int64) (error, models.ReceiveTreatmentAsses) { var receiveTreatmentAsses models.ReceiveTreatmentAsses err := readDb.Model(&models.ReceiveTreatmentAsses{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient, orgId).Last(&receiveTreatmentAsses).Error return err, receiveTreatmentAsses } func GetDialysisWatch(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) (schedule []*models.DialysisSchedule, err error, total int64) { db := readDb.Model(&models.MonitorDialysisSchedule{}) if start > 0 && end > 0 { db = db.Preload("DeviceNumber", "org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB { return db.Where("status = 1 AND user_org_id = ? and monitoring_date >=? and monitoring_date<=? ", orgID, start, end).Order("operate_time asc") }) db = db.Where("xt_schedule.status = 1") } if schedulDate > 0 { db = db.Preload("DeviceNumber", "org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("MonitoringRecord", func(db *gorm.DB) *gorm.DB { return db.Where("status = 1 AND user_org_id = ? and monitoring_date >=? and monitoring_date<=? ", orgID, schedulDate, schedulDate).Order("operate_time asc") }) db = db.Where("xt_schedule.status = 1") db = db.Where("schedule_date = ?", schedulDate) } if schedulType > 0 { db = db.Where("schedule_type = ?", schedulType) } if start > 0 { db = db.Where("schedule_date >= ?", start) } if end > 0 { db = db.Where("schedule_date <= ?", end) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } if partitionType > 0 { db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ?", partitionType) } offset := (page - 1) * limit err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error return schedule, err, total } //func GetDialysisWatchByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64) (schedules []*models.DialysisSchedule, err error, total int64) { // db := readDb.Model(&models.DialysisSchedule{}).Where("status = 1") // // if schedulType > 0 { // db = db.Where("scheudle_type = ?", schedulType) // } // // if partitionType > 0 { // db = db.Where("partition_id = ?", partitionType) // } // // err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error // return schedules, err, total //} func GetDialysisWatchByKeyword(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) ([]*models.DialysisSchedule, error, int64) { var patients []*models.Patients getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error if getPatientErr != nil { return nil, getPatientErr, 0 } patientIDs := make([]int64, len(patients)) for index, patient := range patients { patientIDs[index] = patient.ID } db := readDb.Model(&models.DialysisSchedule{}) if start > 0 && end > 0 { db = db.Preload("DeviceNumber", "org_id = ?", orgID). // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("Prescription", "status = 1 AND user_org_id = ? and record_date>=? and record_date<=?", orgID, start, end). Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ? and assessment_date>=? and assessment_date<=?", orgID, start, end). Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ? and assessment_date>=? and assessment_date<=?", orgID, start, end). Preload("MonitoringRecord", "status = 1 AND user_org_id = ? and monitoring_date>=? and monitoring_date<=?", orgID, start, end). Preload("DialysisOrder", "status = 1 AND user_org_id = ? and dialysis_date >= ? and dialysis_date<=?", orgID, start, end). Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID) } else { db = db.Preload("DeviceNumber", "org_id = ?", orgID). // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("Prescription", "status = 1 AND user_org_id = ?", orgID). Preload("AssessmentBeforeDislysis", "status = 1 AND user_org_id = ?", orgID). Preload("AssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID). Preload("MonitoringRecord", "status = 1 AND user_org_id = ?", orgID). Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID). Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID) } db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs) if schedulType > 0 { db = db.Where("schedule_type = ?", schedulType) } if start > 0 { db = db.Where("schedule_date >= ?", start) } if end > 0 { db = db.Where("schedule_date<=?", end) } if partitionType > 0 { db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ?", partitionType) // db = db.Where("partition_id = ?", partitionType) } var schedules []*models.DialysisSchedule total := int64(0) err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error return schedules, err, total } func GetAdminUserES(orgID int64, appID int64, ids []int64) (es []*models.AdminUserElectronicSignature, err error) { err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id=? and creator in (?) and status=1", orgID, appID, ids).Find(&es).Error return } // //func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) { // // db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1") // table := readUserDb.Table("sgj_user_admin_electronic_signature as s") // fmt.Println("table", table) // err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error // return admin, err //} func GetAdminUserEsOne(orgid int64) (admin []*models.UserAdminRoles, err error) { db := readUserDb.Table("sgj_user_admin_role as x") table := readUserDb.Table("sgj_user_admin_electronic_signature as s") fmt.Println("table", table) err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ?", orgid).Scan(&admin).Error return admin, err } func GetAdminUserEsTwo(orgid int64, aapid int64) (admin []*models.UserAdminRoles, err error) { db := readUserDb.Table("sgj_user_admin_role as x") table := readUserDb.Table("sgj_user_admin_electronic_signature as s") fmt.Println("table", table) err = db.Select("x.id,x.admin_user_id,x.user_name,x.org_id,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id").Where("x.org_id = ? and x.app_id =? and x.status=1", orgid, aapid).Group("user_name").Scan(&admin).Error return admin, err } func UpDateDialysisPrescriptionDoctorSign(patient int64, date int64, orgId int64, doctor_id int64) (err error) { err = writeDb.Model(&models.DialysisPrescription{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? ", orgId, patient, date).Updates(map[string]interface{}{"prescription_doctor": doctor_id}).Error return } func GetAllAdminUserES(orgID int64, appId int64) (es []*models.AdminUserElectronicSignature, err error) { err = readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id = ? and status=1", orgID, appId).Find(&es).Error return } func GetAllStarfEs(orgid int64) (es []*models.SgjUserAdminRoles, err error) { redis := RedisClient() defer redis.Close() // cur_date := time.Now().Format("2006-01-02") key := strconv.FormatInt(orgid, 10) + ":starfes" starfes_str, _ := redis.Get(key).Result() redis.Set(key, "", time.Second) if len(starfes_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis db := readUserDb.Table("sgj_user_admin_role as x").Where("x.status = 1") err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,s.creator,s.url,s.hash").Joins("left join sgj_user_admin_electronic_signature as s on s.creator = x.admin_user_id and s.status = 1").Where("x.org_id = ?", orgid).Scan(&es).Error if err != nil { if err == gorm.ErrRecordNotFound { if len(es) <= 0 { redis.Set(key, "starfes_str_null", time.Second*60*60*18) } return nil, nil } else { return nil, err } } else { if len(es) > 0 { //缓存数据 starfes_str, err := json.Marshal(es) if err == nil { redis.Set(key, starfes_str, time.Second*60*60*18) return es, nil } } else { redis.Set(key, "starfes_str_null", time.Second*60*60*18) return es, nil } return es, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if starfes_str == "starfes_str_null" { return es, nil } else { json.Unmarshal([]byte(starfes_str), &es) return es, nil } } } func FindLastMonitorRecord(patient_id int64, org_id int64) (record models.MonitoringRecord, err error) { err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ?", patient_id, org_id).Last(&record).Error return } func FindLastMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) { err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ? AND monitoring_date = ?", patient_id, org_id, monitoring_date).Last(&record).Error return } func FindFirstMonitorRecordToday(patient_id int64, org_id int64, monitoring_date int64) (record models.MonitoringRecord, err error) { err = readDb.Model(&models.MonitoringRecord{}).Where("patient_id = ? AND status = 1 AND user_org_id = ? AND monitoring_date = ?", patient_id, org_id, monitoring_date).First(&record).Error return } func ExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) { err = writeDb.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1 AND execution_state = 2", groupNo, org_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error return err } func GetExceDoctorAdviceGroupNo(groupNo int64, org_id int64) (advice []*models.DoctorAdvice, err error) { err = XTReadDB().Where("groupno = ? AND user_org_id = ? AND status = 1", groupNo, org_id).Find(&advice).Error return advice, err } func ExceOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) { ut := writeDb.Begin() err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id = ?", advice_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error if err != nil { ut.Rollback() return } err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id = ?", advice_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func CheckDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) { ut := writeDb.Begin() err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1 AND check_state = 0", groupNo, org_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func CheckDoctorAdviceByGroupNoOne(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) { ut := writeDb.Begin() err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1", groupNo, org_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func CheckOldDoctorAdvice(m *models.DoctorAdvice, advice_id int64) (err error) { ut := writeDb.Begin() err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND id = ?", advice_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error if err != nil { ut.Rollback() return } err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id = ?", advice_id).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func DeleteDoctorAdviceByGroupNo(m *models.DoctorAdvice) (err error) { ut := writeDb.Begin() err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ?", m.GroupNo, m.UserOrgId).Update(map[string]interface{}{"UpdatedTime": m.UpdatedTime, "Status": 0, "modifier": m.Modifier}).Error if err != nil { ut.Rollback() return } ut.Commit() return } func GetDialysisBoard(orgID int64, scheduleDate int64, offset, limit int64) ([]*models.DialysisBoardVM, error) { var boards []*models.DialysisBoardVM db := readDb. Table("xt_schedule"). Preload("Patient", "status = 1 AND user_org_id = ?", orgID). Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID). Preload("DeviceZone", "status = 1 AND org_id = ?", orgID). Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID). Preload("SigninAndWeigh", "status = 1 AND user_org_id = ?", orgID). Preload("NextSchedules", func(db *gorm.DB) *gorm.DB { return db.Where("user_org_id = ? AND schedule_date > ? AND status = 1", orgID, scheduleDate). Order("schedule_date asc, id asc") }). Where("status = 1 AND user_org_id = ?", orgID) if scheduleDate != 0 { db = db.Where("schedule_date = ?", scheduleDate) } err := db.Offset(offset).Limit(limit).Find(&boards).Error return boards, err } func GetOneDialysisOrder(orgID, orderData int64, patient_id int64) (*models.DialysisOrder, error) { var order models.DialysisOrder var err error err = readDb.Model(&models.DialysisOrder{}).Where("user_org_id=? and dialysis_date=? and status=1 and patient_id = ?", orgID, orderData, patient_id).First(&order).Error if err == gorm.ErrRecordNotFound { return nil, nil } if err != nil { return nil, err } return &order, nil } func GetOneDialysisOrderOne(orgID, orderData int64, patient_id int64) (models.DialysisOrder, error) { order := models.DialysisOrder{} err := readDb.Where("user_org_id=? and dialysis_date=? and status=1 and patient_id = ?", orgID, orderData, patient_id).Find(&order).Error return order, err } func GetPatientScheduleByPatientId(patient_id int64, user_org_id int64, schedule_date int64) (models.XtSchedule, error) { schedule := models.XtSchedule{} err := XTReadDB().Where("patient_id = ? and user_org_id = ? and schedule_date = ? and status=1", patient_id, user_org_id, schedule_date).Find(&schedule).Error return schedule, err } func GetPscheduleDate(schedule_date int64, patient_id int64, user_org_id int64) (models.XtSchedule, error) { schedule := models.XtSchedule{} err := XTReadDB().Where("schedule_date = ? and patient_id = ? and user_org_id =? and status =1", schedule_date, patient_id, user_org_id).Find(&schedule).Error return schedule, err } func UpdateDialysiOrderByPatientId(id int64, schedule_type int64, partion_id int64, bed_id int64) error { err := XTWriteDB().Model(&models.DialysisOrder{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"schedual_type": schedule_type, "zone_id": partion_id, "bed_id": bed_id}).Error return err } func GetOrgInfoTemplate(orgID int64) (models.GobalTemplate, error) { var templateInfo models.GobalTemplate var err error err = readDb.Model(&models.GobalTemplate{}).Where("org_id=? and status=1", orgID).First(&templateInfo).Error return templateInfo, err } func FindAdminRoleTypeById(orgId int64, adminUserId int64, appId int64) (models.App_Role, error) { var appRole models.App_Role var err error err = readUserDb.Model(&models.App_Role{}).Where("org_id =? and app_id = ? and admin_user_id = ? and status=1", orgId, appId, adminUserId).First(&appRole).Error return appRole, err } func BatchExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) { err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?) AND execution_state = 2", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?) AND execution_state = 2 ", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime, "execution_staff": m.ExecutionStaff, "execution_state": 1}).Error return err } func BatchCheckOldDoctorAdvice(m *models.DoctorAdvice, ids []string, org_id int64, date int64) (err error) { err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?) AND user_org_id = ? AND advice_date = ?", ids, org_id, date).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?) AND user_org_id = ? AND advice_date = ?", ids, org_id, date).Updates(map[string]interface{}{"check_time": m.CheckTime, "checker": m.Checker, "check_state": 1}).Error return err } func ModifyScheduleMode(mode_id int64, patient_id int64, recordDate int64, org_id int64, dialysis_machine_name string) { ut := writeDb.Begin() err = writeDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND schedule_date = ?", org_id, patient_id, recordDate).Updates(map[string]interface{}{"updated_time": time.Now().Unix(), "mode_id": mode_id, "dialysis_machine_name": dialysis_machine_name}).Error if err != nil { ut.Rollback() return } ut.Commit() } func ModifyScheduleModeOne(mode_id int64, patient_id int64, recordDate int64, org_id int64, dialysis_machine_name string) { ut := writeDb.Begin() err = writeDb.Model(&models.Schedule{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND schedule_date >= ? mode_id= ?", org_id, patient_id, recordDate, mode_id).Updates(map[string]interface{}{"updated_time": time.Now().Unix(), "dialysis_machine_name": dialysis_machine_name}).Error if err != nil { ut.Rollback() return } ut.Commit() } func FindDialysisOrderById(id int64) (error, *models.DialysisOrder) { dialysisRecord := models.DialysisOrder{} err := readDb.Model(&models.DialysisOrder{}).Where("id = ? AND status = 1", id).Find(&dialysisRecord).Error return err, &dialysisRecord } func ModifyExceDoctorAdviceByGroupNo(m *models.DoctorAdvice, groupNo int64, org_id int64) (err error) { ut := writeDb.Begin() err = ut.Model(&models.DoctorAdvice{}).Where("groupno = ? AND user_org_id = ? AND status = 1 AND execution_state = 1", groupNo, org_id).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func ModifyExceDoctorAdviceByGroupNoOne(m *models.DoctorAdvice, ids []string) (err error) { ut := writeDb.Begin() err = ut.Model(&models.DoctorAdvice{}).Where("id in(?) and status =1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func BatchModifyExceOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) { ut := writeDb.Begin() err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?) AND execution_state = 1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error if err != nil { ut.Rollback() return } err = ut.Model(&models.DoctorAdvice{}).Where("status = 1 AND parent_id IN (?) AND execution_state = 1 ", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func UpdateOrderCount(good_type_id int64, good_id int64, number string, org_id int64) { writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count - ?", 1)) } func UpdateOrderInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) { writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"good_id": newNiprocart, "warehouse_out_id": out.ID, "warehouse_out_order_number": out.WarehouseOutOrderNumber}) } func FindOrderInfoByGoodId(good_type_id int64, good_id int64, number string, org_id int64) (err error, out models.WarehouseOutInfo) { err = writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).Find(&out).Error return } func FindGoodUserById(good_type_id int64, good_id int64, id int64, org_id int64, record_time int64) (user models.AutomaticReduceDetail, err error) { err = readDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND patient_id = ? AND org_id = ? AND record_time = ? ", good_id, good_type_id, id, org_id, record_time).First(&user).Error return } func FindOldOrderInfoByGoodId(time int64, org_id int64) (err error, out models.WarehouseOutInfo) { err = readDb.Model(&models.WarehouseOutInfo{}).Where(" org_id = ? AND status = 1 AND sys_record_time = ? ", org_id, time).First(&out).Error return } func FindStockOutOrderNumberByTime(time int64, org_id int64) (err error, out models.WarehouseOut) { err = readDb.Model(&models.WarehouseOut{}).Where(" org_id = ? AND status = 1 AND warehouse_out_time = ? ", org_id, time).First(&out).Error return } func UpdateDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, newNiprocart int64, out *models.WarehouseOutInfo) { writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"good_id": newNiprocart, "warehouse_out_id": out.ID, "warehouse_out_order_number": out.WarehouseOutOrderNumber}) } func FindPatientIsOpenRemindById(patient_id int64, org_id int64) (patients models.Patients, err error) { err = readDb.Model(&models.Patients{}).Where("status = 1 AND id = ? AND user_org_id = ?", patient_id, org_id).First(&patients).Error return } func GetMaxLongAdviceGroupID(orgId int64, patient_id int64) (group int64) { var advice models.DoctorAdvice err := readDb.Table("xt_doctor_advice").Where("user_org_id=? AND patient_id = ? AND status = 1 AND advice_type = 1 AND frequency_type > 0", orgId, patient_id).Select("max(groupno) as groupno").First(&advice).Error if err != nil { fmt.Println(err) group = 0 } group = advice.GroupNo return } func GetLastLongAdviceByGroupNo(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) { err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND stop_state = 2 AND parent_id = 0 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0)", advice_date).Find(&advice).Error return } func GetLastLongAdviceByGroupNoOne(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) { redis := RedisClient() defer redis.Close() key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":long_advice" long_advice_str, _ := redis.Get(key).Result() if len(long_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND stop_state = 2 AND parent_id = 0 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0) ", advice_date).Find(&advice).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } else { if len(advice) > 0 { //缓存数据 starfes_str, err := json.Marshal(advice) if err == nil { redis.Set(key, starfes_str, time.Second*60*60*18) return advice, nil } } else { redis.Set(key, "null", time.Second*60*60*18) return advice, nil } return advice, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if long_advice_str == "null" { return advice, nil } else { json.Unmarshal([]byte(long_advice_str), &advice) return advice, nil } } err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND stop_state = 2 AND parent_id = 0 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0) ", advice_date).Find(&advice).Error return } func GetLastLongAdviceByGroupNoThree(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) { err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND frequency_type = 2 AND stop_state = 2 AND parent_id = 0 and (push_start_time>=? or push_start_time = 0) ", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time>=? or push_start_time = 0) ", advice_date).Find(&advice).Error return } func GetLastLongAdviceByGroupNoFour(orgId int64, patient_id int64, advice_date int64) (advice []*models.DoctorAdvice, err error) { //err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND frequency_type = 2 AND stop_state = 2 AND parent_id = 0 ", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error //return redis := RedisClient() defer redis.Close() key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":long_advice" long_advice_str, _ := redis.Get(key).Result() if len(long_advice_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND frequency_type = 2 AND stop_state = 2 AND parent_id = 0 and (push_start_time >=? or push_start_time = 0)", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0)", advice_date).Find(&advice).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } else { if len(advice) > 0 { //缓存数据 starfes_str, err := json.Marshal(advice) if err == nil { redis.Set(key, starfes_str, time.Second*60*60*18) return advice, nil } } else { redis.Set(key, "null", time.Second*60*60*18) return advice, nil } return advice, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if long_advice_str == "null" { return advice, nil } else { json.Unmarshal([]byte(long_advice_str), &advice) return advice, nil } } err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 1 AND stop_state = 2 AND parent_id = 0 AND frequency_type <> 0 and (push_start_time >=? or push_start_time = 0)", orgId, patient_id, advice_date).Preload("ChildDoctorAdvice", "status = 1 and (push_start_time >=? or push_start_time = 0)", advice_date).Find(&advice).Error return } func FindAllDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, temp_id string) (advice []*models.DoctorAdvice, err error) { err = readDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_type = 2 AND advice_date > ? AND advice_date <= ? AND template_id = ? ", orgId, patient_id, end, now, temp_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error return } func UpdateScheduleModeId(patient_id int64, org_id int64, date int64, mode_id int64) (err error) { err = writeDb.Model(&models.Schedule{}).Where("status =1 AND user_org_id = ? AND patient_id = ? AND schedule_date = ?", org_id, patient_id, date).Updates(map[string]interface{}{"mode_id": mode_id, "updated_time": time.Now().Unix()}).Error return } func UpdateAssessmentAfterDate(patient_id int64, org_id int64, date int64, actual_treatment_hour int64, actual_treatment_minute int64) (err error) { err = writeDb.Model(&models.AssessmentAfterDislysis{}).Where("status =1 AND user_org_id = ? AND patient_id = ? AND assessment_date = ?", org_id, patient_id, date).Updates(map[string]interface{}{"actual_treatment_hour": actual_treatment_hour, "actual_treatment_minute": actual_treatment_minute}).Error return } func UpdateAssessmentAfterDateOne(patient_id int64, org_id int64, date int64, actual_treatment_hour int64, actual_treatment_minute int64, BreathingRate string) (err error) { err = writeDb.Model(&models.AssessmentAfterDislysis{}).Where("status =1 AND user_org_id = ? AND patient_id = ? AND assessment_date = ?", org_id, patient_id, date).Updates(map[string]interface{}{"actual_treatment_hour": actual_treatment_hour, "actual_treatment_minute": actual_treatment_minute, "breathing_rate": BreathingRate}).Error return } func CreateDialysisBeforePrepare(beforePrepares []*models.DialysisBeforePrepare) (err error) { if len(beforePrepares) > 0 { utx := writeDb.Begin() if len(beforePrepares) > 0 { thisSQL := "INSERT INTO dialysis_before_prepare (user_org_id, patient_id, record_date, good_id, good_type_id,count,ctime,mtime,creater,modifier,status,commdity_code) VALUES " insertParams := make([]string, 0) insertData := make([]interface{}, 0) for _, prepare := range beforePrepares { insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?)") insertData = append(insertData, prepare.UserOrgId) insertData = append(insertData, prepare.PatientId) insertData = append(insertData, prepare.RecordDate) insertData = append(insertData, prepare.GoodId) insertData = append(insertData, prepare.GoodTypeId) insertData = append(insertData, prepare.Count) insertData = append(insertData, prepare.Ctime) insertData = append(insertData, prepare.Mtime) insertData = append(insertData, prepare.Creater) insertData = append(insertData, prepare.Modifier) insertData = append(insertData, 1) insertData = append(insertData, prepare.CommdityCode) } thisSQL += strings.Join(insertParams, ", ") err = utx.Exec(thisSQL, insertData...).Error if err != nil { utx.Rollback() return } } utx.Commit() } return } func UpdateDialysisBeforePrepare(info *models.DialysisBeforePrepare) (err error) { err = writeDb.Save(&info).Error return err } func UpdateDialysisBeforePrepareTwo(info *models.DialysisBeforePrepare) (err error) { err = writeDb.Model(&models.DialysisBeforePrepare{}). Where("status = 1 and good_id = ? AND good_type_id = ? AND patient_id = ? AND user_org_id = ? AND record_date = ?", info.GoodId, info.GoodTypeId, info.PatientId, info.UserOrgId, info.RecordDate). Updates(map[string]interface{}{"count": info.Count, "updated_time": time.Now().Unix(), "modifier": info.Modifier, "commdity_code": info.CommdityCode, "status": 1}).Error return err } func UpdateAutoReduceDetailSix(detail *models.AutomaticReduceDetail) (err error) { err = writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? and good_type_id = ? And patient_id = ? and org_id =? and record_time = ?", detail.GoodId, detail.GoodTypeId, detail.PatientId, detail.OrgId, detail.RecordTime).Updates(map[string]interface{}{"count": detail.Count, "mtime": detail.Mtime, "status": 1}).Error return err } func UpdateOrderCountSub(good_type_id int64, good_id int64, number string, org_id int64, count int64) { writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count - ?", count)) } func UpdateOrderCountAdd(good_type_id int64, good_id int64, number string, org_id int64, count int64) { writeDb.Model(&models.WarehouseOutInfo{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, number).UpdateColumn("count", gorm.Expr("count + ?", count)) } func UpdateUserInfoDetails(good_type_id int64, good_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.WarehouseOutInfo) { writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"count": count, "status": 1}) //writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber).UpdateColumn("count", count) } func UpdateDrugUserInfoDetails(drug_id int64, time int64, org_id int64, patient_id int64, count int64, out *models.DrugWarehouseOutInfo) { writeDb.Model(&models.DrugAutomaticReduceDetail{}).Where("drug_id = ? AND org_id = ? AND status = 1 AND warehouse_out_order_number = ? AND patient_id = ?", drug_id, org_id, out.WarehouseOutOrderNumber, patient_id).Updates(map[string]interface{}{"count": count}) //writeDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND org_id = ? AND status = 1 AND is_sys = 1 AND warehouse_out_order_number = ? ", good_id, good_type_id, org_id, out.WarehouseOutOrderNumber).UpdateColumn("count", count) } func FindDialysisBeforePrepare(patient_id int64, good_id int64, good_type_id int64, user_org_id int64, record_time int64) (count int64) { readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND good_id = ? AND good_type_id = ? AND record_date = ? AND status = 1 AND count<> 0", user_org_id, patient_id, good_id, good_type_id, record_time).Count(&count) return } func GetExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.DoctorAdvice, err error) { err = readDb.Model(&doctorAdvice).Where("user_org_id = ? and patient_id = ? AND (id = ? Or parent_id=?) and status = 1", orgid, patientid, id, id).Find(&doctorAdvice).Error return doctorAdvice, err } func GetHisExecutionDoctors(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) { err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and patient_id = ? AND (id = ? Or parent_id=?) and status = 1", orgid, patientid, id, id).Find(&doctorAdvice).Error return doctorAdvice, err } func GetHisExecutionDoctorsTwo(orgid int64, patientid int64, id int64) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) { err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and patient_id = ? AND id = ? and status = 1 and execution_state = 1", orgid, patientid, id).Find(&doctorAdvice).Error return doctorAdvice, err } func FindHisDoctorAdviceById(orgID int64, id int64) (advice models.HisDoctorAdviceInfo, err error) { err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error return } func FindHisDoctorAdviceByIdTwo(orgID int64, id int64, tx *gorm.DB) (advice models.HisDoctorAdviceInfo, err error) { err = tx.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error if err != gorm.ErrRecordNotFound { if err != nil { tx.Rollback() return } } return } func FindHisDoctorAdviceByIds(orgID int64, ids []string) (advice []*models.HisDoctorAdviceInfo, err error) { err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id=? and status=1 and id in (?)", orgID, ids).Find(&advice).Error return } func SaveHisDoctorAdvice(advice *models.HisDoctorAdviceInfo) (err error) { err = writeDb.Save(&advice).Error return } func SaveHisDoctorAdviceOne(advice *models.HisDoctorAdviceInfo, tx *gorm.DB) (err error) { err = tx.Save(&advice).Error if err != nil { tx.Rollback() return } return } func GetGoodInfoMation(orgid int64) (goodinfo []*models.GoodInfo, err error) { err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "stock_count > 0 and status = 1").Find(&goodinfo).Error //err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Find(&goodinfo).Error return goodinfo, err } func GetGoodInfoMationSix(orgid int64, storehouse_id int64) (goodinfo []*models.GoodInfo, err error) { err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "stock_count > 0 and status = 1 and storehouse_id = ?", storehouse_id).Order("sort asc").Find(&goodinfo).Error return goodinfo, err } func GetGoodInfoMationSeven(orgid int64, storehouse_id int64) (goodinfo []*models.GoodInfo, err error) { err = XTReadDB().Model(&goodinfo).Where("org_id = ? and status = 1 AND find_in_set('停用',good_status) = 0", orgid).Preload("GoodSotckInfo", "status = 1 and storehouse_id = ? and stock_count>0", storehouse_id).Find(&goodinfo).Error return goodinfo, err } func GetDialysisBeforePrepare(goodTypeId int64, goodId int64, orgid int64, patientId int64) (*models.DialysisBeforePrepare, error) { prepare := models.DialysisBeforePrepare{} err := XTReadDB().Where("good_type_id = ? and good_id = ? and user_org_id = ? and status =1 and patient_id = ?", goodTypeId, goodId, orgid, patientId).Last(&prepare).Error if err == gorm.ErrRecordNotFound { return nil, err } if err != nil { return nil, err } return &prepare, nil } func CreateDialysisBeforePrepareOne(prepare *models.DialysisBeforePrepare) error { err := XTWriteDB().Create(&prepare).Error return err } func ModifyExceDoctorAdviceById(m *models.HisDoctorAdviceInfo, ids []string) (err error) { ut := writeDb.Begin() err = ut.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id IN (?) AND execution_state = 1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error if err != nil { ut.Rollback() return } err = ut.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND parent_id IN (?) AND execution_state = 1 ", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func FindHisDoctorAdviceByIdOne(orgID int64, ids []string) (advice []models.HisDoctorAdviceInfo, err error) { err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id IN (?) AND user_org_id = ? AND status = 1", ids, orgID).Find(&advice).Error return } func ModifyHisPrescriptionProject(m *models.HisPrescriptionProject, ids []string) (err error) { ut := writeDb.Begin() err = ut.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id IN (?) AND execution_state = 1", ids).Updates(map[string]interface{}{"execution_time": m.ExecutionTime}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func FindHisProjectById(orgID int64, id int64) (advice models.HisPrescriptionProject, err error) { err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id=? and status=1 and id = ?", orgID, id).First(&advice).Error return } func SaveHisProject(advice *models.HisPrescriptionProject) (err error) { err = writeDb.Save(&advice).Error return } func FindAllHisProjectById(orgID int64, patient_id int64, record_time int64) (advice []*models.HisPrescriptionProject, err error) { err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1 and user_org_id = ?", orgID).Preload("XtHisProjectTeam", "user_org_id=? and status=1", orgID).Preload("GoodInfo", "status = 1 and org_id = ?", orgID).Where("user_org_id=? and status=1 and patient_id = ? AND record_date = ?", orgID, patient_id, record_time).Find(&advice).Error return } func GetAllPcPatientListByListSeven(orgID int64) (patients []*MSchedualPatientVMList, err error) { err = readDb.Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error return patients, err } func GetAllPcPatientListByListEight(orgID int64) (patients []*MSchedualPatientVMList, err error) { err = readDb.Where("user_org_id=? and status=1", orgID).Find(&patients).Error return patients, err } func GetAllPcPatientListByList(orgID int64) (patients []*MSchedualPatientVMList, err error) { redis := RedisClient() defer redis.Close() key := strconv.FormatInt(orgID, 10) + ":" + ":patient_list_all" patient_info_str, _ := redis.Get(key).Result() if len(patient_info_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis err = readDb.Where("user_org_id=? and status=1 and lapseto = 1", orgID).Find(&patients).Error if err != nil { if err == gorm.ErrRecordNotFound { if len(patients) <= 0 { redis.Set(key, "null", time.Second*60*60*18) } return nil, nil } else { return nil, err } } else { if len(patients) > 0 { //缓存数据 patient_info_json, err := json.Marshal(&patients) if err == nil { redis.Set(key, patient_info_json, time.Second*60*60*18) } } else { redis.Set(key, "null", time.Second*60*60*18) } return patients, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if patient_info_str == "null" { return nil, nil } else { json.Unmarshal([]byte(patient_info_str), &patients) return patients, nil } } } func GetAllPcAdvicestByList(orgID int64, scheduleDate int64) (advices []*VMDoctorAdvice, err error) { redis := RedisClient() defer redis.Close() key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":advice_list_all" advice_list_str, _ := redis.Get(key).Result() if len(advice_list_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis err = readDb.Where("status = 1 AND user_org_id = ? AND advice_type = 2 AND advice_date = ?", orgID, scheduleDate).Find(&advices).Error if err != nil { if err == gorm.ErrRecordNotFound { if len(advices) <= 0 { redis.Set(key, "null", time.Second*60*60*18) } return nil, nil } else { return nil, err } } else { if len(advices) > 0 { //缓存数据 advice_list_str, err := json.Marshal(&advices) if err == nil { redis.Set(key, advice_list_str, time.Second*60*60*18) } } else { redis.Set(key, "null", time.Second*60*60*18) } return advices, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if advice_list_str == "null" { return nil, nil } else { json.Unmarshal([]byte(advice_list_str), &advices) return advices, nil } } } func GetAllPcDialysisOrdersByList(orgID int64, scheduleDate int64) (dialysisOrders []*MDialysisOrderVMList, err error) { redis := RedisClient() defer redis.Close() key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":dialysis_orders_list_all" dialysis_orders_list_all, _ := redis.Get(key).Result() if len(dialysis_orders_list_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis err = readDb.Preload("DeviceNumber", "status = 1 AND org_id = ?", orgID).Where("status = 1 AND user_org_id = ? AND dialysis_date = ?", orgID, scheduleDate).Find(&dialysisOrders).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } else { if len(dialysisOrders) > 0 { //缓存数据 dialysis_orders_list_all, err := json.Marshal(&dialysisOrders) if err == nil { redis.Set(key, dialysis_orders_list_all, time.Second*60*60*18) } } else { redis.Set(key, "null", time.Second*60*60*18) } return dialysisOrders, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if dialysis_orders_list_all == "null" { return nil, nil } else { json.Unmarshal([]byte(dialysis_orders_list_all), &dialysisOrders) return dialysisOrders, nil } } } func GetAllPcAssessmentAfterDislysisByList(orgID int64, scheduleDate int64) (assessmentAfterDislysis []*AssessmentAfterDislysis, err error) { redis := RedisClient() defer redis.Close() key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":assessment_after_dislysis_list_all" assessment_after_dislysis__all, _ := redis.Get(key).Result() if len(assessment_after_dislysis__all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&assessmentAfterDislysis).Error if err != nil { if err == gorm.ErrRecordNotFound { if len(assessmentAfterDislysis) <= 0 { redis.Set(key, "null", time.Second*60*60*18) } return nil, nil } else { return nil, err } } else { if len(assessmentAfterDislysis) > 0 { //缓存数据 assessment_after_dislysis__all, err := json.Marshal(&assessmentAfterDislysis) if err == nil { redis.Set(key, assessment_after_dislysis__all, time.Second*60*60*18) } } else { redis.Set(key, "null", time.Second*60*60*18) } return assessmentAfterDislysis, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if assessment_after_dislysis__all == "null" { return nil, nil } else { json.Unmarshal([]byte(assessment_after_dislysis__all), &assessmentAfterDislysis) return assessmentAfterDislysis, nil } } } func GetAllPcTreatmentSummarysByList(orgID int64, scheduleDate int64) (treatmentSummarys []*VMTreatmentSummary, err error) { redis := RedisClient() defer redis.Close() key := strconv.FormatInt(orgID, 10) + ":" + strconv.FormatInt(scheduleDate, 10) + ":treatment_summarys_list_all" treatment_summarys_all, _ := redis.Get(key).Result() if len(treatment_summarys_all) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis err = readDb.Where("status = 1 AND user_org_id = ? AND assessment_date = ?", orgID, scheduleDate).Find(&treatmentSummarys).Error if err != nil { if err == gorm.ErrRecordNotFound { if len(treatment_summarys_all) <= 0 { redis.Set(key, "null", time.Second*60*60*18) } return nil, nil } else { return nil, err } } else { if len(treatmentSummarys) > 0 { //缓存数据 treatment_summarys_all, err := json.Marshal(&treatmentSummarys) if err == nil { redis.Set(key, treatment_summarys_all, time.Second*60*60*18) } } else { redis.Set(key, "null", time.Second*60*60*18) } return treatmentSummarys, nil } } else { //缓存数据了数据,将redis缓存的json字符串转为map if treatment_summarys_all == "null" { return nil, nil } else { json.Unmarshal([]byte(treatment_summarys_all), &treatmentSummarys) return treatmentSummarys, nil } } } func UpdateTeamProjectExceStatus(ids []int64, admin_user_id int64, execution_time int64) (err error) { ut := writeDb.Begin() db := ut.Model(&models.HisPrescriptionProject{}) err = db.Where("status = 1 AND id IN (?)", ids).Updates(map[string]interface{}{"execution_time": execution_time, "execution_state": 1, "execution_staff": admin_user_id}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func UpdateTeamProjectCheckStatus(ids []int64, patient_id int64, record_date int64, user_org_id int64, admin_user_id int64, check_time int64) (err error) { ut := writeDb.Begin() err = ut.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id IN (?) AND patient_id = ? AND user_org_id = ? AND record_date = ?", ids, patient_id, user_org_id, record_date).Updates(map[string]interface{}{"check_time": check_time, "check_state": 1, "checker": admin_user_id}).Error if err != nil { ut.Rollback() return } ut.Commit() return err } func GetCheckTeamProject(team_id int64, patient_id int64, record_date int64, user_org_id int64) (ps []*models.HisPrescriptionProject, err error) { err = readDb.Model(&models.HisPrescriptionProject{}).Joins("JOIN xt_his_project as p On p.id = his_prescription_project.project_id AND p.cost_classify = 3").Where("his_prescription_project.team_id IN (?) AND his_prescription_project.patient_id = ? AND his_prescription_project.user_org_id = ? AND his_prescription_project.record_date = ? AND his_prescription_project.status = 1", team_id, patient_id, user_org_id, record_date).Find(&ps).Error return } func GetAdminUserRoleInformation(orgid int64) (models.SgjOrgFollow, error) { follow := models.SgjOrgFollow{} db := UserReadDB().Table("sgj_org_follow as f").Where("f.status = 1") table := UserReadDB().Table("sgj_admin as a").Where("a.status = 1") fmt.Println(table) if orgid > 0 { db = db.Where("org_id = ?", orgid) } if orgid == 0 { db = db.Where("org_id = ?", 0) } err := db.Select("f.org_id,f.admin_user_id,a.name,a.phone,a.camera,a.wechat,a.qqchat,a.email,a.wechat_link").Joins("left join sgj_admin as a on a.id = f.admin_user_id").Scan(&follow).Error return follow, err } func GetOrgFollowIsExist(orgid int64) (*models.SgjOrgFollowOne, error) { follow := models.SgjOrgFollowOne{} err := UserReadDB().Where("org_id = ? and status = 1", orgid).Find(&follow).Error if err == gorm.ErrRecordNotFound { return nil, err } if err != nil { return nil, err } return &follow, nil } func UpdatePatientSign(patient_id int64, dialysis_date int64, order models.DialysisOrder, orgid int64) error { err := XTWriteDB().Model(&order).Where("patient_id = ? and dialysis_date= ? and status = 1 and user_org_id = ?", patient_id, dialysis_date, orgid).Update(map[string]interface{}{"url": order.Url, "hash": order.Hash}).Error return err } func GetPatientSign(patient_id int64, dialysis_date int64, orgid int64) (models.DialysisOrder, error) { order := models.DialysisOrder{} err := XTReadDB().Where("patient_id=? and dialysis_date = ? and user_org_id = ? and status = 1", patient_id, dialysis_date, orgid).Find(&order).Error return order, err } func GetScheduleByPatient(patient_id int64, schedule_date int64, orgid int64) (models.XtScheduleSix, error) { schedule := models.XtScheduleSix{} err := XTReadDB().Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status = 1", patient_id, schedule_date, orgid).Find(&schedule).Error return schedule, err } func GetSchedulePrintList(page int64, limit int64, schedulType int64, partitionType int64, keywords string, schedule_date int64, orgID int64) (list []*models.DialysisScheduleSix, total int64, err error) { db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1") table := XTReadDB().Table("xt_patients as p").Where("p.status = 1") fmt.Println("table", table) if schedulType > 0 { db = db.Where("x.schedule_type = ?", schedulType) } if partitionType > 0 { db = db.Where("x.partition_id = ?", partitionType) } if orgID > 0 { db = db.Where("x.user_org_id = ?", orgID) } if schedule_date > 0 { db = db.Where("x.schedule_date = ?", schedule_date) } db = db.Joins("left join xt_patients as p on p.id = x.patient_id") likeKey := "%" + keywords + "%" if len(keywords) > 0 { db = db.Where("p.name like ?", likeKey) } err = db.Count(&total).Select("x.id,x.user_org_id,x.partition_id,x.bed_id,x.patient_id,x.schedule_date,x.schedule_type,x.schedule_week,x.mode_id,x.status,p.name").Offset(limit * (page - 1)).Limit(limit).Order("x.schedule_date desc").Find(&list).Error return list, total, err } func GetSchedulePrintListOne(page int64, limit int64, schedulType int64, partitionType int64, keywords string, schedule_date int64, orgID int64) (list []*models.DialysisScheduleSeven, err error) { db := XTReadDB().Model(&list).Where("status = 1") if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } if schedulType > 0 { db = db.Where("schedule_type = ?", schedulType) } if partitionType > 0 { db = db.Where("partition_id = ?", partitionType) } err = db.Group("schedule_type,partition_id").Find(&list).Error return list, err } func GetDialysisRecordOrder(org_id int64, patient_id int64, dialysis_date int64) (models.MDialysisOrderForListSix, error) { order := models.MDialysisOrderForListSix{} err := XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date = ? and status =1 ", org_id, patient_id, dialysis_date).Find(&order).Error return order, err } func GetSolutionListByOrgId(orgid int64) (list []*models.DialysisSolution, err error) { err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Group("patient_id,mode_id").Order("id desc").Find(&list).Error return list, err } func GetScheduleTypeById(org_id int64, schedule_date int64, schedule_type int64) (list []*models.XtScheduleSeven, err error) { db := XTReadDB().Model(&list).Where("status = 1") if org_id > 0 { db = db.Where("user_org_id = ?", org_id) } if schedule_date > 0 { db = db.Where("schedule_date = ?", schedule_date) } if schedule_type > 0 { db = db.Where("schedule_type = ?", schedule_type) } err = db.Select("partition_id,count(id) as count").Group("partition_id").Scan(&list).Error return list, err } func GetHisExcutionDoctorAdviceListGroupList(patients []string, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) { err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Group("drug_id").Find(&advice).Error return advice, err } func GetHisExcutionDoctorAdviceList(patients []string, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) { err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Find(&advice).Error return advice, err } func UpdateHisDoctorAdviceExecution(info models.HisDoctorAdviceInfo, id int64) error { err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Update(map[string]interface{}{"execution_staff": info.ExecutionStaff, "execution_state": info.ExecutionState, "execution_time": info.ExecutionTime, "updated_time": info.ExecutionTime}).Error return err } func UpdateDoctorAdviceExecution(info models.DoctorAdvice, id int64) error { err := XTWriteDB().Model(&models.DoctorAdvice{}).Where("id = ? and status = 1", id).Update(map[string]interface{}{"execution_staff": info.ExecutionStaff, "execution_state": info.ExecutionState, "execution_time": info.ExecutionTime, "updated_time": info.ExecutionTime}).Error return err } func GetExcutionDoctorAdviceGroupList(patients []string, advice_date int64, user_org_id int64) (advice []*models.DoctorAdviceThrity, err error) { err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Group("drug_id").Find(&advice).Error return advice, err } func GetExcutionDoctorAdviceList(patients []string, advice_date int64, user_org_id int64) (advice []*models.DoctorAdviceThrity, err error) { err = XTReadDB().Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1 and execution_state = 2", patients, advice_date, user_org_id).Find(&advice).Error return advice, err } func GetHisCheckDoctorAdvice(orgid int64, patinentids []string, advice_date int64) (advice []*models.HisDoctorAdviceThirty, err error) { err = XTReadDB().Where("user_org_id = ? and patient_id in(?) and advice_date = ? and status =1", orgid, patinentids, advice_date).Find(&advice).Error return advice, err } func CheckDoctorAdvice(id int64, creater int64) (models.DoctorAdviceThrity, error) { doctoradvice := models.DoctorAdviceThrity{} err := XTWriteDB().Model(&doctoradvice).Where("id = ? and status = 1", id).Update(map[string]interface{}{"checker": creater, "check_time": time.Now().Unix()}).Error return doctoradvice, err } func CheckHisDoctorAdvice(id int64, creater int64) (models.HisDoctorAdviceThirty, error) { doctoradvice := models.HisDoctorAdviceThirty{} err := XTWriteDB().Model(&doctoradvice).Where("id = ? and status = 1", id).Update(map[string]interface{}{"checker": creater, "check_time": time.Now().Unix()}).Error return doctoradvice, err } func GetCheckDoctorAdvice(orgid int64, patinentids []string, advice_date int64) (advice []*models.DoctorAdviceThrity, err error) { err = XTReadDB().Where("user_org_id = ? and patient_id in(?) and advice_date = ? and status=1", orgid, patinentids, advice_date).Find(&advice).Error return advice, err } func SettleHisNewDoctorAdvice(patinentids []string, advice_date int64, orgid int64) (advice []*models.HisDoctorAdviceThirty, err error) { err = XTWriteDB().Model(&advice).Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1", patinentids, advice_date, orgid).Update(map[string]interface{}{"is_settle": 1}).Error return advice, err } func SettleNewDoctorAdvice(patinentids []string, advice_date int64, orgid int64) (advice []*models.DoctorAdviceThrity, err error) { err = XTWriteDB().Model(&advice).Where("patient_id in(?) and advice_date = ? and user_org_id = ? and status = 1", patinentids, advice_date, orgid).Update(map[string]interface{}{"is_settle": 1}).Error return advice, err } func GetHisMobileAdviceGroupList(orgid int64, ids []string) (advice []*models.HisDoctorAdvice, err error) { err = XTReadDB().Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Group("drug_id").Find(&advice).Error return advice, err } func GetHisMobileAdviceList(orgid int64, ids []string) (advice []*models.HisDoctorAdvice, err error) { err = XTReadDB().Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Find(&advice).Error return advice, err } func ExectionMobileAdvice(orgid int64, ids []string, execution_time int64, execution_staff int64) error { advice := models.HisDoctorAdvice{} err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"execution_time": execution_time, "execution_staff": execution_staff, "execution_state": 1, "is_mobile": 3}).Error return err } func GetBloodMobileAdviceGroupList(orgid int64, ids []string) (advice []*models.DoctorAdviceThrity, err error) { err = XTReadDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Group("drug_id").Find(&advice).Error return advice, err } func GetBloodMobileAdviceList(orgid int64, ids []string) (advice []*models.DoctorAdviceThrity, err error) { err = XTReadDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Find(&advice).Error return advice, err } func FindAllDoctorAdviceByIds(orgID int64, ids []string) (advice []models.DoctorAdvice, err error) { err = readDb.Model(&models.DoctorAdvice{}).Where("user_org_id=? AND id in(?) AND status = 1", orgID, ids).Find(&advice).Error return } func ExectionBloodMobileAdvice(orgid int64, ids []string, execution_time int64, execution_staff int64) error { advice := models.DoctorAdviceThrity{} err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"execution_time": execution_time, "execution_staff": execution_staff, "execution_state": 1}).Error return err } func UpdateSettleMobileHisAdvice(orgid int64, ids []string) error { advice := models.HisDoctorAdviceThirty{} err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status =1", orgid, ids).Updates(map[string]interface{}{"is_settle": 1}).Error return err } func UpdateSettleMobileBloodAdvice(orgid int64, ids []string) error { advice := models.DoctorAdvice{} err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status =1", orgid, ids).Updates(map[string]interface{}{"is_settle": 1}).Error return err } func CheckBloodDoctorAdvice(orgid int64, ids []string, advice models.DoctorAdvice) error { err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"check_time": advice.CheckTime, "checker": advice.Checker, "check_state": 1}).Error return err } func CheckHisMobileDoctorAdvice(orgid int64, ids []string, advice models.HisDoctorAdviceThirty) error { err := XTWriteDB().Model(&advice).Where("user_org_id = ? and id in(?) and status = 1", orgid, ids).Updates(map[string]interface{}{"check_time": advice.CheckTime, "checker": advice.Checker, "check_state": 1}).Error return err } func GetLastOrder(user_org_id int64, patient_id int64, dialysis_date int64) (models.DialysisOrderTwenty, error) { twenty := models.DialysisOrderTwenty{} err := XTReadDB().Where("user_org_id = ? and patient_id =? and dialysis_date < ? and status = 1", user_org_id, patient_id, dialysis_date).Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB { return db.Preload("DeviceZone", "status =1").Where("org_id = ? AND status = 1", user_org_id) }).Order("id desc").First(&twenty).Error return twenty, err } func UpdateDoctorSix(start_time int64, patient_id int64, dialysis_date int64, user_org_id int64) (models.DoctorAdvice, error) { advice := models.DoctorAdvice{} err := XTWriteDB().Model(&advice).Where("patient_id = ? and advice_date=? and user_org_id =? and status=1 and advice_name ='低分子肝素钠注射液'", patient_id, dialysis_date, user_org_id).Updates(map[string]interface{}{"execution_time": start_time}).Error return advice, err } func GetTodayInforMation(orgid int64, record_date int64) (list []*NewDeviceInformation, err error) { err = UserReadDB().Where("user_org_id = ? and date = ? and status = 1", orgid, record_date).Find(&list).Error return list, err } func GetFiledConfig(orgid int64) (models.FiledConfig, error) { config := models.FiledConfig{} err := XTReadDB().Where("filed_name = 'dialyzer_perfusion_apparatus' and org_id = ? and module =1 and is_show = 1", orgid).First(&config).Error return config, err } func GetDoctorAdviceCheckList(patient_id int64, advice_date int64, user_org_id int64) (doctor []*models.DoctorAdvice, err error) { err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id =? and status= 1 and checker= 0", patient_id, advice_date, user_org_id).Find(&doctor).Error return doctor, err } func UpdateDoctorAdviceList(id int64, checker int64) error { advice := models.DoctorAdvice{} err := XTWriteDB().Model(&advice).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": checker, "check_state": 1, "check_time": time.Now().Unix()}).Error return err } func UpdateLastMonitorRecordToday(accumulated_blood_volume float64, id int64) error { err := XTWriteDB().Model(&models.MonitoringRecord{}).Where(" id = ? and status= 1", id).Update(map[string]interface{}{"accumulated_blood_volume": accumulated_blood_volume}).Error return err } func GetDialysisFinish(user_org_id int64, record_date int64, module int64, patient_id int64) (models.XtDialysisFinish, error) { finish := models.XtDialysisFinish{} err := XTReadDB().Where("user_org_id = ? and record_date = ? and status =1 and module = ? and patient_id = ?", user_org_id, record_date, module, patient_id).Find(&finish).Error return finish, err } func CreateDialysisFinish(finish models.XtDialysisFinish) error { err := XTWriteDB().Create(&finish).Error return err } func GetDialysisInformationSetting(user_org_id int64) (models.XtDialysisInformaitonSetting, error) { setting := models.XtDialysisInformaitonSetting{} err := XTReadDB().Where("user_org_id =? and status = 1", user_org_id).Find(&setting).Error return setting, err } func CreatedDialysisInformation(information models.XtDialysisInformation) error { err := XTWriteDB().Create(&information).Error return err } func GetDialysisInoformationById(patient_id int64, record_date int64, user_org_id int64, module int64) (models.XtDialysisInformation, error) { information := models.XtDialysisInformation{} err := XTReadDB().Where("patient_id = ? and record_date = ? and user_org_id = ? and module = ? and status = 1", patient_id, record_date, user_org_id, module).Find(&information).Error return information, err } func UpdateDialysisInformationById(patient_id int64, record_date int64, user_org_id int64, module int64, advice_date int64, remark string) error { information := models.XtDialysisInformation{} err := XTWriteDB().Model(&information).Where("patient_id = ? and record_date = ? and user_org_id =? and module = ? and status=1", patient_id, record_date, user_org_id, module).Update(map[string]interface{}{"application_date": advice_date, "remark": remark}).Error return err } func UpdateDoctorAdviceByExcecute(id int64, user_org_id int64) error { err := XTWriteDB().Model(models.DoctorAdvice{}).Where("id = ? and user_org_id = ? and status =1", id, user_org_id).Updates(map[string]interface{}{"execution_time": 0, "execution_staff": 0, "execution_state": 2}).Error return err } func UpdateInformationSettingById(orgid int64, week_day int64) error { err := XTWriteDB().Model(&models.XtDialysisInformaitonSetting{}).Where("user_org_id = ? and status =1", orgid).Updates(map[string]interface{}{"week_day": week_day}).Error return err } func CreateInformationSetting(setting models.XtDialysisInformaitonSetting) error { err := XTWriteDB().Create(&setting).Error return err } func GetInformationSettingByOrgId(user_org_id int64) (models.XtDialysisInformaitonSetting, error) { setting := models.XtDialysisInformaitonSetting{} err := XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&setting).Error return setting, err } func GetDialysisInformationSettingList(user_org_id int64) (infor []*models.XtDialysisInformaitonSetting, err error) { err = XTReadDB().Where("user_org_id = ? and status =1", user_org_id).Find(&infor).Error return infor, err } func GetDialysisInformationIsNoCheck(user_org_id int64, limit int64, page int64, application_status int64) (infor []*models.DialysisInformation, total int64, err error) { db := XTReadDB().Model(&infor).Where("status= 1") if application_status > 0 { db = db.Where("application_status = ?", application_status) } if user_org_id > 0 { db = db.Where("user_org_id = ?", user_org_id) } err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Find(&infor).Error return infor, total, err } func GetDialysisInformationIsNoCheckOne(user_org_id int64, limit int64, page int64, application_status int64) (infor []*models.DialysisInformation, total int64, err error) { db := XTReadDB().Model(&infor).Where("status= 1") if application_status > 0 { db = db.Where("application_status = ? or application_status= 3", application_status) } if user_org_id > 0 { db = db.Where("user_org_id = ?", user_org_id) } err = db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Find(&infor).Error return infor, total, err } func CheckDialysisInformation(id int64, application_status int64, timenow int64, checker int64) (models.DialysisInformation, error) { information := models.DialysisInformation{} err := XTWriteDB().Model(&information).Where("id=? and status = 1", id).Updates(map[string]interface{}{"application_status": application_status, "check_time": timenow, "checker": checker}).Error return information, err } func GetDialysisWatchByKeywordFlow(orgID int64, keyword string, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) ([]*models.DialysisScheduleFlow, error, int64) { var patients []*models.Patients getPatientErr := readDb.Model(&models.Patients{}).Where("status = 1 AND user_org_id = ? AND (name like ? OR dialysis_no like ?)", orgID, "%"+keyword+"%", "%"+keyword+"%").Find(&patients).Error if getPatientErr != nil { return nil, getPatientErr, 0 } patientIDs := make([]int64, len(patients)) for index, patient := range patients { patientIDs[index] = patient.ID } db := readDb.Model(&models.DialysisScheduleFlow{}) if start > 0 && end > 0 { db = db.Preload("DeviceNumber", "org_id = ?", orgID). // Preload("DeviceZone", "status = 1 AND org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("DialysisFinish", "status = 1 AND user_org_id = ? and record_date >= ? and record_date<=?", orgID, start, end). Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID) } else { db = db.Preload("DeviceNumber", "org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("DialysisFinish", "status = 1 AND user_org_id = ?", orgID). Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID) } db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs) if schedulType > 0 { db = db.Where("schedule_type = ?", schedulType) } if start > 0 { db = db.Where("schedule_date >= ?", start) } if end > 0 { db = db.Where("schedule_date<=?", end) } if partitionType > 0 { db = db.Joins("inner join xt_device_number as d_n on d_n.id = xt_schedule.bed_id and d_n.zone_id = ?", partitionType) } var schedules []*models.DialysisScheduleFlow total := int64(0) err := db.Count(&total).Offset(limit * (page - 1)).Limit(limit).Order("schedule_date desc").Find(&schedules).Error return schedules, err, total } func GetDialysisWatchFlow(orgID int64, schedulDate int64, schedulType int64, partitionType int64, page int64, limit int64, start int64, end int64) (schedule []*models.DialysisScheduleFlow, err error, total int64) { db := readDb.Model(&models.DialysisScheduleFlow{}) if schedulDate > 0 { db = db.Preload("DeviceNumber", "org_id = ?", orgID). Preload("TreatmentMode", "status = 1"). Preload("DialysisFinish", "status = 1 AND user_org_id = ? and record_date =?", orgID, schedulDate). Preload("MonitorPatients", "status = 1 AND user_org_id = ?", orgID) db = db.Where("xt_schedule.status = 1") db = db.Where("schedule_date = ?", schedulDate) } if schedulType > 0 { db = db.Where("schedule_type = ?", schedulType) } if start > 0 { db = db.Where("schedule_date >= ?", start) } if end > 0 { db = db.Where("schedule_date <= ?", end) } if orgID > 0 { db = db.Where("user_org_id = ?", orgID) } if partitionType > 0 { db = db.Joins("inner join xt_device_number on xt_device_number.id = xt_schedule.bed_id and xt_device_number.zone_id = ?", partitionType) } offset := (page - 1) * limit err = db.Count(&total).Offset(offset).Limit(limit).Order("bed_id desc").Find(&schedule).Error return schedule, err, total } func GetPrescriptionInfo(user_org_id int64, patient_id int64, record_date int64) (models.HisPrescriptionInfo, error) { info := models.HisPrescriptionInfo{} err := XTReadDB().Where("user_org_id = ? and patient_id =? and record_date = ? and status=1", user_org_id, patient_id, record_date).Find(&info).Error return info, err } func FindLastSchedule(user_org_id int64, patient_id int64, schedule_date int64) (models.XtSchedules, error) { schedules := models.XtSchedules{} err := XTReadDB().Where("user_org_id = ? and patient_id = ? and schedule_date < ? and status =1", user_org_id, patient_id, schedule_date).Order("schedule_date desc").First(&schedules).Error return schedules, err } func GetMonitorPatients(patient_id int64) (*models.MonitorPatients, error) { patients := models.MonitorPatients{} err := XTReadDB().Where("id = ? and status = 1", patient_id).Find(&patients).Error return &patients, err } func GetMonitorDialysisOrderObj(patient_id int64, schedule_date int64) (*models.MonitorDialysisOrder, error) { order := models.MonitorDialysisOrder{} err := XTReadDB().Where("patient_id = ? and dialysis_date = ? and status = 1", patient_id, schedule_date).Find(&order).Error return &order, err } func GetMonitorDialysisPrescription(patient_id int64, record_date int64) (*models.DialysisPrescription, error) { prescription := models.DialysisPrescription{} err := XTReadDB().Where("patient_id = ? and status =1 and record_date = ?", patient_id, record_date).Find(&prescription).Error return &prescription, err } func GetMonitorPredialysisEvaluation(patient_id int64, record_date int64) (*models.PredialysisEvaluation, error) { evaluation := models.PredialysisEvaluation{} err := XTReadDB().Where("patient_id = ? and status =1 and assessment_date = ?", patient_id, record_date).Find(&evaluation).Error return &evaluation, err } func GetMonitorAssessmentAfterDislysis(patient_id int64, record_date int64) (*models.AssessmentAfterDislysis, error) { dislysis := models.AssessmentAfterDislysis{} err = XTReadDB().Where("patient_id = ? and status =1 and assessment_date = ?", patient_id, record_date).Find(&dislysis).Error return &dislysis, err } func GetMonitoringRecordList(patient_id int64, record_date int64) (record []*models.MonitoringRecord, err error) { err = XTReadDB().Where("patient_id = ? and monitoring_date=? and status =1", patient_id, record_date).Find(&record).Error return record, err } func GetDoctorAdviceListNoExecution(patient_id int64, dialysis_date int64, user_org_id int64) (doctor []*models.XtDoctorAdvice, err error) { err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id = ? and execution_state = 2 and status =1", patient_id, dialysis_date, user_org_id).Find(&doctor).Error return doctor, err } func UpdateDoctorAdviceNoExecution(id int64, creator int64, end_time int64) error { err := XTWriteDB().Model(&models.XtDoctorAdvice{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"execution_state": 1, "execution_staff": creator, "execution_time": end_time}).Error return err } func CreatePrescriptionLog(log models.XtDialysisPrescriptionLog) error { ut := writeDb.Begin() err := ut.Create(&log).Error if err != nil { ut.Rollback() return err } ut.Commit() return err } func CreateBeforLog(log models.XtAssessmentBeforeDislysisLog) error { err := XTWriteDB().Create(&log).Error return err } func CreateAfterDialysisLog(log models.XtAssessmentAfterDialysisLog) error { err := XTWriteDB().Create(&log).Error return err } func CreateDoctorAdviceLog(log models.XtDoctorAdviceLog) error { err := XTWriteDB().Create(&log).Error return err } func CreateMonitorRecordLog(log models.XtMonitorRecordLog) error { err := XTWriteDB().Create(&log).Error return err } func GetAllHisAdviceList(patient_id int64, advice_date int64, user_org_id int64) (advice []*models.HisDoctorAdvice, err error) { err = XTReadDB().Where("patient_id = ? and advice_date =? and user_org_id = ? and status =1", patient_id, advice_date, user_org_id).Find(&advice).Error return advice, err } func BatchCheckHisAdvice(id int64, creater int64) error { err := XTWriteDB().Model(&models.HisDoctorAdvice{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"checker": creater, "check_state": 1, "check_time": time.Now().Unix()}).Error return err } func BatchAdviceList(id int64, creater int64) error { err := XTWriteDB().Model(&models.DoctorAdvice{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": creater, "check_state": 1, "check_time": time.Now().Unix()}).Error return err } func GetMobileProjectList(patient_id int64, advice_date int64, user_org_id int64) (project []*models.HisPrescriptionProject, err error) { err = XTReadDB().Where("patient_id = ? and status=1 and record_date = ? and user_org_id = ?", patient_id, advice_date, user_org_id).Find(&project).Error return project, err } func BatchCheckProject(id int64, creater int64) error { err = XTWriteDB().Model(&models.HisPrescriptionProject{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"checker": creater, "check_state": 1, "check_time": time.Now().Unix()}).Error return err } func GetAllAdviceList(patient_id int64, advice_date int64, user_org_id int64) (advice []*models.DoctorAdvice, err error) { err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id = ? and status=1", patient_id, advice_date, user_org_id).Find(&advice).Error return advice, err } func GetHistoryWarehouseOutInfo(patient_id int64, user_org_id int64, record_time int64, good_id int64, tx *gorm.DB) (outInfo []*models.WarehouseOutInfo, err error) { err = tx.Where("patient_id = ? and org_id = ? and sys_record_time = ? and status =1 and good_id = ?", patient_id, user_org_id, record_time, good_id).Find(&outInfo).Error if err != gorm.ErrRecordNotFound { if err != nil { tx.Rollback() return } } return outInfo, err } func GetDialysisAutoGoodInfo(patient_id int64, record_time int64, org_id int64, tx *gorm.DB, good_id int64) (detail []*models.AutomaticReduceDetail, err error) { err = tx.Where("patient_id = ? and record_time=? and org_id=? and status= 1 and good_id = ?", patient_id, record_time, org_id, good_id).Find(&detail).Error if err != gorm.ErrRecordNotFound { if err != nil { tx.Commit() return } } return detail, err } func CreateDialysisPrepare(prepare models.DialysisBeforePrepare, tx *gorm.DB) error { err := tx.Create(&prepare).Error if err != nil { tx.Commit() return err } return err } func ModfiyAddDialysisAuto(patient_id int64, record_date int64, count int64, good_id int64, tx *gorm.DB) error { err = tx.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? and record_date = ? and good_id = ? and status = 1", patient_id, record_date, good_id).UpdateColumn("count", gorm.Expr("count + ?", count)).Error if err != nil { tx.Rollback() return err } return err } func ModfiyReduceDialysisAuto(patient_id int64, record_date int64, count int64, good_id int64, tx *gorm.DB) error { err = tx.Model(&models.DialysisBeforePrepare{}).Where("patient_id = ? and record_date = ? and good_id = ? and status = 1", patient_id, record_date, good_id).UpdateColumn("count", gorm.Expr("count - ?", count)).Error if err != nil { tx.Rollback() return err } return err } func GetHisExecutionDoctorsThree(orgid int64, patientid int64, id int64, tx *gorm.DB) (doctorAdvice []*models.HisDoctorAdviceInfo, err error) { err = tx.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and patient_id = ? AND id = ? and status = 1 and execution_state = 1", orgid, patientid, id).Find(&doctorAdvice).Error if err != gorm.ErrRecordNotFound { if err != nil { tx.Rollback() return doctorAdvice, err } } return doctorAdvice, err } func CreateMobileAdivce(advice models.DoctorAdvice) error { err := XTWriteDB().Create(&advice).Error return err } func CreateMobileAdivceOne(advice models.XtDoctorAdviceOne) error { err := XTWriteDB().Create(&advice).Error return err } func GetLongDoctorAdviceByPatient(patient_id int64, org_id int64) (advice []*models.XtDoctorAdvice, err error) { err = XTReadDB().Where("patient_id = ? and user_org_id = ? and status=1 and advice_type =1", patient_id, org_id).Order("start_time asc").Find(&advice).Error return advice, err } func GetLastLongAdviceList(user_org_id int64) (models.XtDoctorAdvice, error) { advice := models.XtDoctorAdvice{} err := XTReadDB().Where("user_org_id =? and status=1 and advice_type =1", user_org_id).Last(&advice).Error return advice, err } func DeleteSelfAdviceSubAdvice(id int64) (models.XtDoctorAdviceOne, error) { adviceOne := models.XtDoctorAdviceOne{} err2 := XTWriteDB().Model(&adviceOne).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error return adviceOne, err2 } func UpdateMobileDoctorAdviceById(id int64, advice models.XtDoctorAdviceOne) error { err := XTWriteDB().Model(&models.XtDoctorAdviceOne{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_name": advice.AdviceName, "advice_date": advice.AdviceDate, "start_time": advice.StartTime, "advice_desc": advice.AdviceDesc, "single_dose": advice.SingleDose, "single_dose_unit": advice.SingleDoseUnit, "prescribing_number": advice.PrescribingNumber, "prescribing_number_unit": advice.PrescribingNumberUnit, "delivery_way": advice.DeliveryWay, "execution_frequency": advice.ExecutionFrequency, "remark": advice.Remark}).Error return err } func UpdateMobileDoctorAdviceByIdOne(id int64, advice models.XtDoctorAdviceOne) error { err := XTWriteDB().Model(&models.XtDoctorAdviceOne{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_name": advice.AdviceName, "advice_date": advice.AdviceDate, "start_time": advice.StartTime, "advice_desc": advice.AdviceDesc, "single_dose": advice.SingleDose, "single_dose_unit": advice.SingleDoseUnit, "prescribing_number": advice.PrescribingNumber, "prescribing_number_unit": advice.PrescribingNumberUnit, "delivery_way": advice.DeliveryWay, "execution_frequency": advice.ExecutionFrequency, "remark": advice.Remark, "frequency_type": advice.FrequencyType, "week_day": advice.WeekDay, "day_count": advice.DayCount}).Error return err } func CreateMobileMGroupAdvice(orgId int64, advices []*models.GroupAdvice, groupNo int64) (list []*models.GroupAdvice, err error) { if groupNo <= 0 { group := GetMaxAdviceGroupID(orgId) groupNo = group + 1 } tx := writeDb.Begin() defer func() { if r := recover(); r != nil { tx.Rollback() } }() for _, advice := range advices { advice.GroupNo = groupNo advice.Status = 1 template_id := strconv.FormatInt(groupNo, 10) advice.TemplateId = "M" + template_id if err = tx.Create(advice).Error; err != nil { tx.Rollback() return } list = append(list, advice) if len(advice.Children) > 0 { for _, child := range advice.Children { child.GroupNo = groupNo child.ParentId = advice.ID fmt.Println(child) if err = tx.Create(&child).Error; err != nil { tx.Rollback() return } list = append(list, child) } } } tx.Commit() return } func GetTodayPrescription(patient_id int64, user_org_id int64, record_date int64) (models.DialysisPrescription, error) { prescription := models.DialysisPrescription{} err := XTReadDB().Where("patient_id = ? and user_org_id = ? and record_date =? and status=1", patient_id, user_org_id, record_date).Find(&prescription).Error return prescription, err } func GetMobilePatientMonitor(patient_id int64, record_date int64, user_org_id int64) (monitor []*models.MonitoringRecord, err error) { err = XTReadDB().Where("patient_id = ? and monitoring_date = ? and user_org_id =? and status=1", patient_id, record_date, user_org_id).Order("operate_time asc").Find(&monitor).Error return monitor, err } func ModifyDialysisPatientMonitor(id int64, ultrafiltration_rate float64) error { err := XTWriteDB().Model(&models.MonitoringRecord{}).Where("id =? and status=1", id).Updates(map[string]interface{}{"ultrafiltration_rate": ultrafiltration_rate}).Error return err } func ModifyDialysisPatientReplascementRate(id int64, replacement_rate float64) error { err := XTWriteDB().Model(&models.MonitoringRecord{}).Where("id =? and status=1", id).Updates(map[string]interface{}{"replacement_rate": replacement_rate}).Error return err } func ModifyPatientUltrafiltrationVolume(id int64, ultrafiltration_volume float64) error { err := XTWriteDB().Model(&models.MonitoringRecord{}).Where("id =? and status=1", id).Updates(map[string]interface{}{"ultrafiltration_volume": ultrafiltration_volume}).Error return err } func ModifyPatientDisplacementQuantity(id int64, displacement_quantity float64) error { err := XTWriteDB().Model(&models.MonitoringRecord{}).Where("id = ? and status=1", id).Updates(map[string]interface{}{"displacement_quantity": displacement_quantity}).Error return err } func StopLongAdvice(id int64, stop_time int64) (models.DoctorAdvice, error) { advice := models.DoctorAdvice{} err := XTWriteDB().Model(&advice).Where("id=? and status=1", id).Updates(map[string]interface{}{"stop_time": stop_time, "stop_state": 1, "updated_time": time.Now().Unix()}).Error return advice, err }