12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- package service
-
- import (
- "XT_New/models"
- "fmt"
- "time"
-
- "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 = ?", 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("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", 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 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 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 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.PredialysisEvaluation{}).Create(&check).Error
- if err != nil {
- tx.Rollback()
- }
- tx.Commit()
- return errors
- }
-
- //修改透析处方
- func UpDateDialysisPrescription(dialysisPrescription *models.DialysisPrescription) error {
- err := writeDb.Save(&dialysisPrescription).Error
- return err
- }
-
- //修改接诊评估
- func UpadateReceiveTreatmentAsses(receiveTreatmentAsses *models.ReceiveTreatmentAsses) error {
- err := writeDb.Save(receiveTreatmentAsses).Error
- return 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 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 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 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) 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.XtDialysisOrder, error) {
- orders := models.XtDialysisOrder{}
- 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,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,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").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 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 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("DeviceZone", "status = 1 AND org_id = ?", orgID).
- Preload("TreatmentMode", "status = 1").
- Preload("DialysisOrder", "status = 1 AND user_org_id = ?", orgID).
- // Preload("DialysisOrder.MonitoringRecords", "status = 1 AND user_org_id = ?", orgID).
- 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) (schedule []*models.DialysisSchedule, err error, total int64) {
- 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 = ?", orgID)
- db = db.Where("xt_schedule.status = 1 AND user_org_id = ?", orgID)
- if schedulDate > 0 {
- db = db.Where("schedule_date = ?", schedulDate)
- }
- if schedulType > 0 {
- db = db.Where("schedule_type = ?", schedulType)
- }
- 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 = ? and xt_device_number.status = 1", partitionType)
- // db = db.Where("partition_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) ([]*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{}).
- 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 = ?", orgID)
- db = db.Where("xt_schedule.status = 1 AND patient_id in (?)", patientIDs)
- if schedulType > 0 {
- db = db.Where("schedule_type = ?", schedulType)
- }
- 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 = ? and d_n.status = 1", 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").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 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) {
-
- 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.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
- return es, err
- }
-
- 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) {
- ut := writeDb.Begin()
- err = ut.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
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
-
- return 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 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 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) {
-
- ut := writeDb.Begin()
- err = ut.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
- if err != nil {
- ut.Rollback()
- return
- }
- err = ut.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
- if err != nil {
- ut.Rollback()
- return
- }
- ut.Commit()
- return err
- }
-
- func BatchCheckOldDoctorAdvice(m *models.DoctorAdvice, ids []string) (err error) {
-
- ut := writeDb.Begin()
- err = writeDb.Model(&models.DoctorAdvice{}).Where("status = 1 AND id IN (?)", ids).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 IN (?)", ids).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 ModifyScheduleMode(mode_id int64, patient_id int64, recordDate int64, org_id int64) {
- 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}).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 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, number string) (user models.AutomaticReduceDetail, err error) {
- err = readDb.Model(&models.AutomaticReduceDetail{}).Where("good_id = ? AND good_type_id = ? AND patient_id = ? AND org_id = ? AND warehouse_out_order_number = ? ", good_id, good_type_id, id, org_id, number).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 []*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", orgId, patient_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advice).Error
- return
- }
-
- func GetLastLongAdviceByGroupNoThree(orgId int64, patient_id 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
- }
-
- 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 frequency_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
- }
|