123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- package service
-
- import (
- "XT_New/models"
- "XT_New/utils"
- "fmt"
- "github.com/jinzhu/gorm"
- "github.com/robfig/cron"
- "strconv"
- "time"
- )
-
-
- var createWeekDisinfectionCronJob *cron.Cron
-
- func init() {
- createWeekDisinfectionCronJob = cron.New()
-
- spec := "0 55 23 * * ?"
-
-
- createWeekDisinfectionCronJob.AddFunc(spec, func() {
-
- AutoCreateWeekDisinfectionJob()
- })
- }
-
- func BeginAutoCreateWeekDisinfectionJob() {
-
- createWeekDisinfectionCronJob.Start()
- }
-
- func AutoCreateWeekDisinfectionJob() {
- timeStr := time.Now().Format("2006-01-02")
- timeLayout := "2006-01-02 15:04:05"
- fmt.Println("timeStr:", timeStr)
- timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
- timenow := timeStringToTime.Unix()
- fmt.Println("timenow是什么", timenow)
-
- org, errs := GetAllOrgID(timenow)
- fmt.Print("错误是什么", errs)
-
- for _, item := range org {
-
- remander, errs := GetRemanderDatas(item.UserOrgId)
- fmt.Print("查询自动使用登记错误", errs)
-
- if remander.IsRun == 1 {
- fmt.Println("机构id", item.UserOrgId)
-
- order, _ := GetAllPatientByOrgID(item.UserOrgId, timenow)
- for _, it := range order {
-
-
-
- patients, err := GetPatientInformation(it.PatientId, it.UserOrgId)
- fmt.Println("查询病人信息报错", err)
- var con = ""
- if patients.IsInfectious == 0 {
- con = ""
- }
- if patients.IsInfectious == 1 {
- con = "无"
- }
- if patients.IsInfectious == 2 {
- con = "有"
- }
-
-
-
-
- schedules, _ := GetAllPatientSchedule(it.PatientId, it.UserOrgId, timenow)
- fmt.Println("班次", schedules.ScheduleType)
-
- prescription, _ := GetDialysisPrescription(it.PatientId, it.UserOrgId, timenow)
- fmt.Println("透析模式", prescription.ModeId)
-
-
- dislysis, err := GetAssessmentAfterDissData(it.PatientId, it.UserOrgId, timenow)
- fmt.Println("透后评估错误", err)
- fmt.Print("透析时长", dislysis.ActualTreatmentHour+'h'+dislysis.ActualTreatmentMinute+'m'+'i'+'n')
-
- addmacher, _ := GetEquimentID(schedules.BedId, it.UserOrgId)
-
- fmt.Println(" 设备id", addmacher.ID)
-
-
-
- fmt.Println("班次", it.SchedualType)
-
- plan, errplan := GetDisinfection(addmacher.UnitType, it.SchedualType, it.UserOrgId)
- fmt.Print("plan", plan)
- fmt.Println("错误是什么", errplan)
- if errplan == gorm.ErrRecordNotFound {
- fmt.Println("该设备无消毒计划")
- continue
- } else if errplan == nil {
-
-
-
-
-
-
-
-
-
-
-
-
- information, errcode := GetInfor(it.PatientId, timenow, it.UserOrgId, it.SchedualType)
-
- fmt.Println("information", information)
- if errcode == gorm.ErrRecordNotFound {
- information := models.DeviceInformation{
- Date: timenow,
- Zone: schedules.PartitionId,
- Class: it.SchedualType,
- BedNumber: schedules.BedId,
- PatientId: schedules.PatientId,
- DialysisMode: prescription.ModeId,
- LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
- Disinfection: 1,
- DialysisConcentration: 1,
- DisinfectionStatus: 1,
- Move: 1,
- UserOrgId: it.UserOrgId,
- DisinfectType: plan.Way,
- DisinfectantType: plan.MachineDisinfectant,
- FluidPath: plan.DisinfectanWay,
- Disinfectant: plan.Disinfectant,
- Ctime: time.Now().Unix(),
- Status: 1,
- SignName: it.FinishNurse,
- EquimentId: addmacher.ID,
- DisinfectionResidue: 2,
- Bed: addmacher.BedNumber,
- StartTime: it.StartTime,
- EndTime: it.EndTime,
- Contagion: con,
- WeightLoss: dislysis.WeightLoss,
- Hyperfiltratio: dislysis.ActualUltrafiltration,
- DialysisHour: strconv.FormatInt(dislysis.ActualTreatmentHour, 10),
- MachineRun: 1,
- }
- err := CreateInformation(&information)
- fmt.Println("报错", err)
- } else if errcode == nil {
-
- } else {
-
- }
- } else {
-
- return
- }
- }
- }
-
-
- if remander.IsRun == 2 {
- fmt.Print("已关闭")
- }
- }
-
- }
-
-
-
-
-
-
-
-
-
-
- func GetAllOrgID(time int64) (schedule []*models.XtSchedule, err error) {
-
- err = XTReadDB().Raw("select user_org_id,id,partition_id,bed_id,patient_id,schedule_date,schedule_type,schedule_week,mode_id from xt_schedule where schedule_date = ? group by user_org_id", time).Scan(&schedule).Error
-
- return schedule, err
- }
-
- func GetAllPatientByOrgID(orgid int64, timenow int64) (order []*models.DialysisOrder, err error) {
-
- err = XTReadDB().Where("user_org_id = ? AND dialysis_date = ? AND stage = 2 AND status = ?", orgid, timenow, 1).Find(&order).Error
- return order, err
- }
-
- func CreateInformation(information *models.DeviceInformation) error {
- err := UserWriteDB().Create(&information).Error
- return err
- }
-
- func GetAllPatientSchedule(patientid int64, orgID int64, timenow int64) (models.Schedule, error) {
- schedules := models.Schedule{}
- err := XTReadDB().Where("patient_id = ? AND user_org_id = ? AND schedule_date = ?", patientid, orgID, timenow).Find(&schedules).Error
- return schedules, err
- }
-
- func GetInfor(patientid int64, timenow int64, orgid int64, class int64) (*models.DeviceInformation, error) {
- var pre models.DeviceInformation
- var err error
- err = readUserDb.Model(&pre).Where("patient_id = ? AND date = ? AND user_org_id = ? AND class = ? AND status = 1", patientid, timenow, orgid, class).Find(&pre).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &pre, nil
- }
-
- func GetDisinfection(equitType int64, scheduleType int64, orgID int64) (*models.DevicePlan, error) {
- var plan models.DevicePlan
- var err error
- err = readUserDb.Model(&plan).Where("device_type = ? AND classtime = ? AND user_org_id = ? AND status = 1", equitType, scheduleType, orgID).Find(&plan).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &plan, nil
- }
-
- func GetDialysisPrescription(patientid int64, orgID int64, timenow int64) (models.DialysisPrescription, error) {
- prescription := models.DialysisPrescription{}
- err := XTReadDB().Model(&prescription).Where("patient_id = ? AND user_org_id = ? AND record_date = ?", patientid, orgID, timenow).Find(&prescription).Error
- return prescription, err
- }
-
- func GetAssessmentAfterDissData(patientid int64, orgID int64, timenow int64) (models.XtAssessmentAfterDislysis, error) {
- dislysis := models.XtAssessmentAfterDislysis{}
- err := XTReadDB().Where("patient_id = ? AND user_org_id = ? AND assessment_date = ?", patientid, orgID, timenow).Find(&dislysis).Error
- return dislysis, err
- }
-
- func GetEquimentID(bedId int64, orgID int64) (models.DeviceAddmacher, error) {
- addmacher := models.DeviceAddmacher{}
- err := readUserDb.Model(&addmacher).Where("bed_id = ? AND user_org_id = ? AND status = ?", bedId, orgID, 1).Find(&addmacher).Error
- return addmacher, err
- }
-
- func GetAddmacher(equitmentid int64, orgid int64) (models.DeviceEquimentname, error) {
- equimentname := models.DeviceEquimentname{}
- err := readUserDb.Model(&equimentname).Where("equitment_id = ? AND user_org_id = ? AND status = 1", equitmentid, orgid).Find(&equimentname).Error
- return equimentname, err
- }
-
- func GetPatientInformation(id int64, orgid int64) (models.Patients, error) {
- patients := models.Patients{}
- err := XTReadDB().Where("id = ? AND user_org_id = ?", id, orgid).Find(&patients).Error
- return patients, err
- }
-
- func GetRemanderDatas(orgid int64) (remander models.DeviceRemander, err error) {
-
- err = UserReadDB().Model(&models.DeviceRemander{}).Where("user_org_id = ? and status = 1", orgid).Find(&remander).Error
- return
- }
|