1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954 |
- package service
-
- import (
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "XT_New/models"
-
- "github.com/jinzhu/gorm"
- )
-
- // GetSchedulePartitionPanel 取出排班面板,分区-机号
- func GetSchedulePartitionPanel(orgID int64) (partitions []*models.Partition, err error) {
-
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Order("").Find(&partitions).Error
-
- return
- }
-
- func GetSchedulePartitionPanelOne(orgID int64, partionId []string) (partitions []*models.Partition, err error) {
-
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
- //}
-
- return
- }
-
- func GetSchedulePartitionPanelTwo(orgID int64, schIDs []string) (partitions []*models.Partition, err error) {
-
- if len(schIDs) == 0 {
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", "org_id=? and status=1", orgID).Where("org_id=? and status=1", orgID).Find(&partitions).Error
- }
- if len(schIDs) > 0 {
- err = readDb.Model(&models.DeviceZone{}).Preload("Jihaos", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id=? and status=1 and zone_id in (?)", orgID, schIDs).Order("sort desc")
- }).Where("org_id=? and status=1 and id in(?)", orgID, schIDs).Find(&partitions).Error
- }
-
- return
- }
-
- func GetPatientWithScheduleAndSolution(orgID int64, keywords string, weekStart, weekEnd, schedule, contagion int64) (patients []*models.Patients, err error) {
- db := readDb.Table("xt_patients as p").
- Preload("DialysisSolutions", "user_org_id=? and initiate_mode=1 and affirm_state=1 and parent_id=0 and status=1", orgID).
- Preload("Schedules", "user_org_id=? and schedule_date>=? and schedule_date<= ? and status=1", orgID, weekStart, weekEnd).
- Preload("Contagions", "status=1").
- Where("p.user_org_id=? and p.lapseto=1 and p.status=1", orgID)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("p.name LIKE ? or p.first_letter LIKE ?", likeKey, likeKey)
- }
-
- if schedule == 1 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.schedule_date>=? and iss.schedule_date<= ? and iss.status=1", weekStart, weekEnd).QueryExpr())
- } else if schedule == 2 {
- db = db.Where("NOT EXISTS (?)", readDb.Table("xt_schedule as iss").Where("iss.patient_id=p.id and iss.schedule_date>=? and iss.schedule_date<= ? and iss.status=1", weekStart, weekEnd).QueryExpr())
- }
- if contagion > 0 {
- db = db.Where("EXISTS (?)", readDb.Table("xt_patients_infectious_diseases as pid").Where("pid.patient_id=p.id and pid.disease_id=? and pid.status=1", contagion).QueryExpr())
- }
-
- err = db.Find(&patients).Error
- return
- }
-
- func GetPatientWithScheduleAndSolutionTwo(orgID int64, keywords string, weekStart, weekEnd, schedule, contagion int64) (patients []*models.Patients, err error) {
- db := readDb.Table("xt_patients as p").
- Preload("DialysisSolutions", "user_org_id=? and initiate_mode=1 and affirm_state=1 and parent_id=0 and status=1", orgID).
- //Preload("Schedules", "user_org_id=? and schedule_date>=? and schedule_date<= ? and status=1", orgID, weekStart, weekEnd).
- Where("p.user_org_id=? and p.lapseto=1 and p.status=1", orgID)
- if len(keywords) > 0 {
- likeKey := "%" + keywords + "%"
- db = db.Where("p.name LIKE ?", likeKey)
- }
-
- err = db.Find(&patients).Error
- return
- }
-
- func GetWeekSchedule(orgID int64, start, end int64) (schedules []*models.Schedule, err error) {
-
- err = readDb.Table("xt_schedule as s").Preload("PatientInfectiousDiseases", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time,s.dialysis_machine_name, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetWeekScheduleOne(orgID int64, start, end int64, partionid int64, scheduletype int64) (schedules []*models.Schedule, err error) {
-
- db := readDb.Table("xt_schedule as s")
- if partionid > 0 {
- db = db.Where("s.partition_id = ?", partionid)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time,s.dialysis_machine_name, s.updated_time, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetWeekScheduleTwo(orgID int64, start, end int64, schIds []string, scheduletype int64) (schedules []*models.ScheduleTwo, err error) {
-
- db := readDb.Table("xt_schedule as s")
- if len(schIds) > 0 {
- db = db.Where("s.partition_id in (?)", schIds)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time,s.dialysis_machine_name, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetWeekScheduleFive(orgID int64, start, end int64, schIds []string, scheduletype int64) (schedules []*models.ScheduleTwo, err error) {
-
- db := readDb.Table("xt_schedule as s").Where("s.status=1 and s.dialysis_machine_name=''")
- if len(schIds) > 0 {
- db = db.Where("s.partition_id in (?)", schIds)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time,s.dialysis_machine_name, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func UpdateSchOne(id int64, dialysis_machine_name string) (err error) {
- err = writeDb.Model(&models.ScheduleTwo{}).Where("status=1 AND id = ?", id).Updates(map[string]interface{}{"dialysis_machine_name": dialysis_machine_name}).Error
- return
- }
-
- func GetScheduleTotalCount(orgID int64, start, end int64, schIds []string, scheduletype int64) (schedules []*models.MySchedule, err error) {
-
- db := readDb.Table("xt_schedule as s").Where("status= 1 and (mode_id = 2 or mode_id= 3)")
- if len(schIds) > 0 {
- db = db.Where("s.partition_id in (?)", schIds)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- if orgID > 0 {
- db = db.Where("s.user_org_id = ?", orgID)
- }
- if start > 0 {
- db = db.Where("s.schedule_date>=?", start)
- }
- if end > 0 {
- db = db.Where("s.schedule_date<=?", end)
- }
-
- err = db.Select("Count(id) as count,schedule_date,mode_id,user_org_id,schedule_week,schedule_type").Group("schedule_date,schedule_type,mode_id").Find(&schedules).Error
-
- return schedules, err
-
- }
-
- func GetWeekScheduleThree(orgID int64, start, end int64, schIds []string, scheduletype int64, WeekDayIds []string) (schedules []*models.ScheduleTwo, err error) {
-
- db := readDb.Table("xt_schedule as s")
-
- if len(schIds) > 0 {
- db = db.Where("s.partition_id in (?)", schIds)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- if len(WeekDayIds) > 0 {
- db = db.Where("s.schedule_week in(?)", WeekDayIds)
- }
- err = db.Preload("PatientInfectiousDiseases", "status = 1 ").
- Preload("DialysisSolution", "status= 1 and solution_status = 1").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time,s.dialysis_machine_name, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetWeekScheduleFour(orgID int64, start, end int64, schIds []string, scheduletype int64, WeekDayIds []string) (schedules []*models.ScheduleThree, err error) {
-
- db := readDb.Table("xt_schedule as s")
-
- if len(schIds) > 0 {
- db = db.Where("s.partition_id in (?)", schIds)
- }
- if scheduletype > 0 {
- db = db.Where("s.schedule_type = ?", scheduletype)
- }
- if len(WeekDayIds) > 0 {
- db = db.Where("s.schedule_week in(?)", WeekDayIds)
- }
- err = db.Preload("DeviceNumber", "status = 1 and org_id =?", orgID).
- Preload("DialysisSolution", "status= 1 and solution_status = 1").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date>=? and s.schedule_date<=? and s.status=1", orgID, start, end).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time,s.dialysis_machine_name, p.name as patient").
- Order("updated_time asc").
- Find(&schedules).Error
- return
- }
-
- func GetDaySchedule(orgID, start, end, patientID int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and patient_id=? and schedule_date>=? and schedule_date<=? and status=1", orgID, patientID, start, end).First(&schedule).Error
- return
- }
-
- func GetDayScheduleTwo(orgID, start, patientID int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and patient_id=? and schedule_date = ? and status=1", orgID, patientID, start).Preload("DialysisOrder", "status = 1").First(&schedule).Error
- return
- }
-
- func GetDayScheduleByBedid(orgID, start, bed_id int64, schedule_type int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and schedule_date=? and bed_id=? and status=1 AND schedule_type = ?", orgID, start, bed_id, schedule_type).Preload("DialysisOrder", "status = 1").First(&schedule).Error
- return
- }
-
- func GetDayScheduleByOrder(orgID, start, bed_id int64, schedule_type int64) (schedule models.DialysisOrder, err error) {
- err = readDb.Model(&models.DialysisOrder{}).Where("user_org_id=? and dialysis_date=? and bed_id=? and status=1 AND schedual_type = ?", orgID, start, bed_id, schedule_type).First(&schedule).Error
- return
- }
- func GetSourceSch(orgId int64, patient_id int64, record_date int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and schedule_date=? and patient_id =? and status=1", orgId, record_date, patient_id).First(&schedule).Error
- return
-
- }
- func GetPatientScheduleFormDay(orgID, start, end, patientID int64) (schedules []*models.PatientSchedule, err error) {
-
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgID).
- Preload("DeviceNumber", "org_id=? and status=1", orgID).
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.schedule_date < ? and s.status=1", patientID, orgID, start, end).
- Find(&schedules).Error
-
- return
- }
-
- func GetNextSchedule(orgID, end, patientID int64) (schedules []*models.PatientSchedule, err error) {
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgID).
- Preload("DeviceNumber", "org_id=? and status=1", orgID).
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", patientID, orgID, end).
- Find(&schedules).Error
-
- return
- }
-
- func GetNextScheduleByList(patient_id int64, schedule_date int64, user_org_id int64) (models.SchedulePatientsOne, error) {
-
- patientsOne := models.SchedulePatientsOne{}
- err := XTReadDB().Where("patient_id = ? and schedule_date >? and user_org_id = ? and status=1", patient_id, schedule_date, user_org_id).Order("schedule_date asc").First(&patientsOne).Error
- return patientsOne, err
- }
-
- func GetPointSchedule(orgID, scheduleDate, scheduleWeek, scheduleType, bedId int64) (schedule models.Schedule, err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id=? and schedule_date=? and bed_id=? and schedule_week=? AND schedule_type=? and status=1", orgID, scheduleDate, bedId, scheduleWeek, scheduleType).First(&schedule).Error
-
- if err == gorm.ErrRecordNotFound {
- err = nil
- return
- }
- return
- }
-
- func CreateSchedule(m *models.Schedule, id int64) (err error) {
- utx := XTWriteDB().Begin()
- schedule := models.XtSchedule{}
- err = utx.Model(&schedule).Where("id=? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
- if err != nil {
- utx.Rollback()
- return err
- }
- err = utx.Create(&m).Error
- if err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
- return err
- }
-
- func DeleteScheduleExist(scheduleData int64, user_org_id int64) (models.XtSchedule, error) {
- schedule := models.XtSchedule{}
- err := XTWriteDB().Model(&schedule).Where("schedule_date= ? and user_org_id = ? and status = 1", scheduleData, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return schedule, err
- }
-
- func GetTodayScheduleIsExist(patientid int64, schedudate int64, orgid int64, mode_id int64, schedule_type int64) (*models.XtSchedule, error) {
- var scheudle models.XtSchedule
- var err error
- err = XTReadDB().Model(&scheudle).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1 and mode_id = ? and schedule_type = ?", patientid, schedudate, orgid, mode_id, schedule_type).Find(&scheudle).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &scheudle, nil
- }
-
- func GetTodayScheduleIsExistOne(patientid int64, schedudate int64, orgid int64) (*models.XtSchedule, error) {
- var scheudle models.XtSchedule
- var err error
- err = XTReadDB().Model(&scheudle).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, schedudate, orgid).Find(&scheudle).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &scheudle, nil
- }
-
- func GetPatientByBed(schedule_date int64, bed_id int64, scheduletype int64, orgid int64) (*models.XtSchedule, error) {
- var scheudle models.XtSchedule
- var err error
- err = XTReadDB().Model(&scheudle).Where(" schedule_date= ? and bed_id = ? and schedule_type = ? and user_org_id = ? and status = 1", schedule_date, bed_id, scheduletype, orgid).Find(&scheudle).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &scheudle, nil
- }
-
- func ModeFyScheduleById(schedule_date int64, bedid int64, scheduletype int64, orgid int64) error {
-
- schedule := models.XtSchedule{}
- err := XTWriteDB().Model(&schedule).Where("schedule_date = ? and bed_id =? and schedule_type = ? and status = 1 and user_org_id = ?", schedule_date, bedid, scheduletype, orgid).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func ModeScheduleByTime(startime int64, endtime int64, orgid int64) error {
-
- schedule := models.XtSchedule{}
-
- err := XTWriteDB().Model(&schedule).Where("schedule_date >? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func ModeScheduleByTimeOne(startime int64, endtime int64, orgid int64) error {
-
- schedule := models.XtSchedule{}
-
- err := XTWriteDB().Model(&schedule).Where("schedule_date >=? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func UpdateScheduleByOrgId(patientid int64, scheduledate int64, orgid int64, mode_id int64, schedule_type int64, sch *models.XtSchedule) error {
- err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1 and mode_id = ? and schedule_type = ?", patientid, scheduledate, orgid, mode_id, schedule_type).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func UpdateScheduleByOrgIdOne(patientid int64, scheduledate int64, orgid int64, sch *models.XtSchedule) error {
- err := XTWriteDB().Model(&sch).Where("patient_id = ? and schedule_date= ? and user_org_id = ? and status = 1", patientid, scheduledate, orgid).Updates(map[string]interface{}{"partition_id": sch.PartitionId, "bed_id": sch.BedId, "schedule_type": sch.ScheduleType, "schedule_week": sch.ScheduleWeek, "mode_id": sch.ModeId, "updated_time": time.Now().Unix(), "dialysis_machine_name": sch.DialysisMachineName}).Error
- return err
- }
-
- func GetSchedule(orgID, id int64) (*models.Schedule, error) {
- var schedule models.Schedule
- var err error
- err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func GetScheduleNight(orgID, id int64) (*models.Schedule, error) {
- var schedule models.Schedule
- var err error
- err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=?", id, orgID).First(&schedule).Error
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func UpdateSchedule(m *models.Schedule) error {
- utx := XTWriteDB().Begin()
- err := utx.Save(&m).Error
- utx.Commit()
- return err
- }
-
- func UpdateScheduleOne(id int64, schedule models.Schedule) error {
- utx := XTWriteDB().Begin()
- err := XTWriteDB().Model(&schedule).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"partition_id": schedule.PartitionId, "bed_id": schedule.BedId, "schedule_type": schedule.ScheduleType}).Error
- utx.Commit()
- return err
- }
-
- // 参数一:当前操作的患者的排班 参数二被替换床位对应的排班
- func UpdateScheduleTwo(schone models.Schedule, schtwo models.Schedule) (err error) {
- utx := XTWriteDB().Begin()
- //床位
- var tempBedID int64
- var tempBedIDTwo int64
-
- //分區
- var tempPID int64
- var tempPIDTwo int64
-
- //上下午
- var tempTypeID int64
- var tempTypeTwo int64
-
- tempBedID = schone.BedId
- tempBedIDTwo = schtwo.BedId
-
- tempPID = schone.PartitionId
- tempPIDTwo = schtwo.PartitionId
-
- tempTypeID = schone.ScheduleType
- tempTypeTwo = schtwo.ScheduleType
-
- schone.BedId = tempBedIDTwo
- schtwo.BedId = tempBedID
-
- schone.PartitionId = tempPIDTwo
- schtwo.PartitionId = tempPID
-
- schone.ScheduleType = tempTypeTwo
- schtwo.ScheduleType = tempTypeID
-
- if err = utx.Model(&models.Schedule{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"partition_id": schone.PartitionId, "bed_id": schone.BedId, "schedule_type": schone.ScheduleType, "is_export": 90000}).Error; err != nil {
- utx.Rollback()
- return err
- }
-
- if err = utx.Model(&models.Schedule{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"partition_id": schtwo.PartitionId, "bed_id": schtwo.BedId, "schedule_type": schtwo.ScheduleType, "is_export": 90000}).Error; err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
- return err
- }
-
- func UpdateScheduleThree(schone *models.Schedule, schtwo *models.Schedule) (err error) {
- utx := XTWriteDB().Begin()
- //床位
- var tempBedID int64
- var tempBedIDTwo int64
-
- //分區
- var tempPID int64
- var tempPIDTwo int64
-
- //上下午
- var tempTypeID int64
- var tempTypeTwo int64
-
- //日期
- var sch_date_one int64
- var sch_date_two int64
-
- //周数
- var sch_week_one int64
- var sch_week_two int64
-
- //原数据
- tempBedID = schone.BedId
- tempBedIDTwo = schtwo.BedId
-
- tempPID = schone.PartitionId
- tempPIDTwo = schtwo.PartitionId
-
- tempTypeID = schone.ScheduleType
- tempTypeTwo = schtwo.ScheduleType
-
- sch_date_one = schone.ScheduleDate
- sch_date_two = schtwo.ScheduleDate
-
- sch_week_one = schone.ScheduleWeek
- sch_week_two = schtwo.ScheduleWeek
-
- //交换数据
- schone.BedId = tempBedIDTwo
- schtwo.BedId = tempBedID
-
- schone.PartitionId = tempPIDTwo
- schtwo.PartitionId = tempPID
-
- schone.ScheduleType = tempTypeTwo
- schtwo.ScheduleType = tempTypeID
-
- schone.ScheduleDate = sch_date_two
- schtwo.ScheduleDate = sch_date_one
-
- schone.ScheduleWeek = sch_week_two
- schtwo.ScheduleWeek = sch_week_one
-
- if err = utx.Model(&models.Schedule{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"partition_id": schone.PartitionId, "bed_id": schone.BedId, "schedule_type": schone.ScheduleType, "schedule_date": schone.ScheduleDate, "schedule_week": schone.ScheduleWeek, "is_export": 80000}).Error; err != nil {
- utx.Rollback()
- return err
- }
-
- if err = utx.Model(&models.Schedule{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"partition_id": schtwo.PartitionId, "bed_id": schtwo.BedId, "schedule_type": schtwo.ScheduleType, "schedule_date": schtwo.ScheduleDate, "schedule_week": schtwo.ScheduleWeek, "is_export": 80000}).Error; err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
-
- return err
- }
-
- func GetPatientScheduleFormToday(orgId, id, start int64) (schedules []*models.PatientSchedule, err error) {
-
- err = readDb.Table("xt_schedule as s").
- Preload("DeviceZone", "org_id=? and status=1", orgId).
- Preload("DeviceNumber", "org_id=? and status=1", orgId).
- Where("s.patient_id =? and s.user_org_id=? and s.schedule_date>=? and s.status=1", id, orgId, start).
- Find(&schedules).Error
-
- return
- }
-
- type WeekSchedulePrintVM struct {
- ID int64 `gorm:"column:id" json:"id"`
- ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
- DeviceNumberID int64 `gorm:"column:bed_id" json:"device_number_id"`
- PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
- ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
- ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
- ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
- ModeID int64 `gorm:"column:mode_id" json:"mode_id"`
-
- Patient *models.Patients `gorm:"ForeignKey:PatientID" json:"patient"`
- DeviceNumber *models.DeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
- Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
- Mode *models.TreatmentMode `gorm:"ForeignKey:ModeID" json:"mode"`
- }
-
- type WeekSchedulePrintPatients struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
- Name string `gorm:"column:name" json:"name" form:"name"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- }
-
- func (WeekSchedulePrintPatients) TableName() string {
- return "xt_patients"
- }
-
- type WeekSchedulePrintDeviceNumber struct {
- ID int64 `gorm:"column:id" json:"id"`
- OrgID int64 `gorm:"column:org_id" json:"-"`
- Number string `gorm:"column:number" json:"number"`
- GroupID int64 `gorm:"column:group_id" json:"group_id"`
- ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- CreateTime int64 `gorm:"column:ctime" json:"-"`
- ModifyTime int64 `gorm:"column:mtime" json:"-"`
- Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
- }
-
- func (WeekSchedulePrintDeviceNumber) TableName() string {
- return "xt_device_number"
- }
-
- type WeekSchedulePrintVMTwo struct {
- ID int64 `gorm:"column:id" json:"id"`
- ZoneID int64 `gorm:"column:partition_id" json:"zone_id"`
- DeviceNumberID int64 `gorm:"column:bed_id" json:"device_number_id"`
- PatientID int64 `gorm:"column:patient_id" json:"patient_id"`
- ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date"`
- ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
- ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
- ModeID int64 `gorm:"column:mode_id" json:"mode_id"`
- Patient *WeekSchedulePrintPatients `gorm:"ForeignKey:PatientID" json:"patient"`
- DeviceNumber *WeekSchedulePrintDeviceNumber `gorm:"ForeignKey:DeviceNumberID" json:"device_number"`
- Zone *models.DeviceZone `gorm:"ForeignKey:ZoneID" json:"zone"`
- //Mode *models.TreatmentMode `gorm:"ForeignKey:ModeID" json:"mode"`
- Mode *models.XtTreatmentMode `json:"mode" gorm:"foreignkey:ModeID,ModeID;AssociationForeignKey:ModeID,ModeID"`
- }
-
- type PrintCount struct {
- ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type"`
- ScheduleWeek int64 `gorm:"column:schedule_week" json:"schedule_week"`
- Count int64
- }
-
- func GetPrinitWeekSchedules(orgID int64, start, end int64) ([]*WeekSchedulePrintVMTwo, error) {
- var schedules []*WeekSchedulePrintVMTwo
- err := readDb.Table("xt_schedule as s").
- Preload("Patient", "status = 1 and user_org_id = ?", orgID).
- Preload("DeviceNumber", "status = 1 and org_id = ?", orgID).
- Preload("Zone", "status = 1 and org_id = ?", orgID).
- Preload("Mode", "status = 1").
- // Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id = ? and s.schedule_date >= ? and s.schedule_date <= ? and s.status = 1", orgID, start, end).
- // Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id").
- Find(&schedules).Error
- return schedules, err
- }
-
- func GetPrinitWeekTotal(orgid int64, startime int64, endtime int64) (print []*PrintCount, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- err = db.Select("x.schedule_type,x.schedule_week,count(x.patient_id) as count").Group("x.schedule_date,x.schedule_type").Scan(&print).Error
- return print, err
- }
-
- func GetBloodPrintWeekTotal(orgid int64, startime int64, endtime int64) (print []*PrintCount, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- db = db.Where("x.mode_id = 2")
- err = db.Select("x.schedule_type,x.schedule_week,count(x.patient_id) as count").Group("x.schedule_date,x.schedule_type").Scan(&print).Error
- return print, err
- }
-
- func GetPerfusionWeekTotal(orgid int64, startime int64, endtime int64) (print []*PrintCount, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- db = db.Where("x.mode_id = 3")
- err = db.Select("x.schedule_type,x.schedule_week,count(x.patient_id) as count").Group("x.schedule_date,x.schedule_type").Scan(&print).Error
- return print, err
- }
-
- // func ExchangeScheduleTimeWithWeekSchedules(orgID int64, nextWeekSchs []*models.Schedule, nextTwoWeekSchs []*models.Schedule) error {
- // templateMode, getTemplateModeErr := GetOrgPatientScheduleTemplateMode(orgID)
- // if getTemplateModeErr != nil {
- // return getTemplateModeErr
- // }
- // if templateMode == nil {
- // return errors.New("模板模式不存在")
- // }
-
- // tx := writeDb.Begin()
-
- // updateTime := time.Now().Unix()
-
- // for _, sch := range nextWeekSchs {
- // sch.PatientInfectiousDiseases = nil
-
- // date := time.Unix(sch.ScheduleDate, 0)
- // sch.ScheduleDate = date.AddDate(0, 0, 7).Unix()
- // sch.UpdatedTime = updateTime
-
- // updateSchErr := tx.Save(sch).Error
- // if updateSchErr != nil {
- // tx.Rollback()
- // return updateSchErr
- // }
- // }
-
- // for _, sch := range nextTwoWeekSchs {
- // sch.PatientInfectiousDiseases = nil
-
- // date := time.Unix(sch.ScheduleDate, 0)
- // sch.ScheduleDate = date.AddDate(0, 0, -7).Unix()
- // sch.UpdatedTime = updateTime
-
- // updateSchErr := tx.Save(sch).Error
- // if updateSchErr != nil {
- // tx.Rollback()
- // return updateSchErr
- // }
- // }
-
- // templateMode.ModifyTime = updateTime
- // templateMode.ExecuteTimes += 1
- // updateModeErr := tx.Save(templateMode).Error
- // if updateModeErr != nil {
- // tx.Rollback()
- // return updateModeErr
- // }
-
- // tx.Commit()
- // return nil
- // }
-
- func GetSchedualPatientsByKeywordsAndWeek(keywords string, org_id int64, start_time int64, end_time int64) (schedule []*models.Schedule, err error) {
- likeKey := "%" + keywords + "%"
- err = readDb.
- Table("xt_schedule as s").
- Preload("PatientInfectiousDiseases", "status = 1 ").
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("TreatmentMode", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id AND (p.name LIKE ? OR p.dialysis_no LIKE ? OR p.first_letter LIKE ?)", likeKey, likeKey, likeKey).
- Where("s.user_org_id=? and s.schedule_date >= ? and s.schedule_date <= ? and s.status=1", org_id, start_time, end_time).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("schedule_date asc").
- Find(&schedule).Error
- return
-
- }
-
- func GetSchedualPatientsByKeywords(keywords string, org_id int64, startime int64, endtime int64) (schedule []*models.Schedule, err error) {
- likeKey := "%" + keywords + "%"
-
- err = readDb.
- Table("xt_schedule as s").
- Preload("PatientInfectiousDiseases", "status = 1 ").
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("TreatmentMode", "status = 1 ").
- Joins("JOIN xt_patients as p ON p.id = s.patient_id AND (p.name LIKE ? OR p.dialysis_no LIKE ? OR p.first_letter LIKE ?)", likeKey, likeKey, likeKey).
- Where("s.user_org_id=? and s.schedule_date >= ? and s.schedule_date <= ? and s.status=1", org_id, startime, endtime).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("schedule_date asc").
- Find(&schedule).Error
- return
-
- }
-
- func GetWeekDayScheduleTwo(orgID int64, scheduleDate int64, scheduleDates *time.Time, weektime int64) (schedules []*models.WeekSchedule, err error) {
-
- db := readDb.Table("xt_schedule as s ").Where("s.status =1")
- if orgID > 0 {
- db = db.Where("s.user_org_id = ?", orgID)
- }
- if scheduleDate > 0 {
- db = db.Where("s.schedule_date = ?", scheduleDate)
-
- }
- if weektime > 0 {
- db = db.Where("s.schedule_type = ?", weektime)
- }
- err = db.
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1").Order("id asc")
- }).
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("s.partition_id asc").
- Find(&schedules).Error
-
- for _, item := range schedules {
- _, config := FindDoctorAdviceRecordByOrgId(item.UserOrgId)
- if config.IsOpenRemind > 0 {
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- advices, _ := GetLastLongAdviceByGroupNoOther(item.UserOrgId, item.PatientId)
- advices_two, _ := GetLastLongAdviceByGroupNoThreeOther(item.UserOrgId, item.PatientId)
- for _, advice := range advices {
- advice.IsCheck = 1
- if advice.FrequencyType == 3 {
- week := int(scheduleDates.Weekday())
-
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- } else if advice.FrequencyType == 1 {
- advice_three = append(advice_three, advice)
- }
- }
-
- for _, advice := range advices_two {
- now := scheduleDates.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := scheduleDates.AddDate(0, 0, int(count)).Unix()
- advices, _ := FindAllDoctorAdviceByTimeOther(now, oldTime, item.PatientId, item.UserOrgId, advice.TemplateId)
- if len(advices) == 0 {
- advice_three = append(advice_three, advice)
- }
- }
-
- item.DoctorAdvice = append(item.DoctorAdvice, advice_three...)
- }
- }
- return
- }
-
- func GetWeekDaySchedule(orgID int64, scheduleDate int64, scheduleDates *time.Time) (schedules []*models.WeekSchedule, err error) {
-
- err = readDb.
- Table("xt_schedule as s").
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("DialysisPrescription", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1").Order("id asc")
- }).
- Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Where("s.user_org_id=? and s.schedule_date = ? and s.status=1", orgID, scheduleDate).
- Select("s.id, s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient").
- Order("schedule_type").
- Find(&schedules).Error
-
- for _, item := range schedules {
- _, config := FindDoctorAdviceRecordByOrgId(item.UserOrgId)
- if config.IsOpenRemind > 0 {
- //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
- var advice_three []*models.DoctorAdvice
- advices, _ := GetLastLongAdviceByGroupNoOther(item.UserOrgId, item.PatientId)
- advices_two, _ := GetLastLongAdviceByGroupNoThreeOther(item.UserOrgId, item.PatientId)
- for _, advice := range advices {
- advice.IsCheck = 1
- if advice.FrequencyType == 3 {
- week := int(scheduleDates.Weekday())
- fmt.Println(advice.WeekDay)
- switch week {
- case 1:
- if strings.Index(advice.WeekDay, "周一") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 2:
- if strings.Index(advice.WeekDay, "周二") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 3:
- if strings.Index(advice.WeekDay, "周三") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 4:
- if strings.Index(advice.WeekDay, "周四") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 5:
- if strings.Index(advice.WeekDay, "周五") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 6:
- if strings.Index(advice.WeekDay, "周六") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- case 0:
- if strings.Index(advice.WeekDay, "周日") > -1 {
- advice_three = append(advice_three, advice)
- }
- break
- }
- } else if advice.FrequencyType == 1 {
- advice_three = append(advice_three, advice)
- }
- }
-
- for _, advice := range advices_two {
- now := scheduleDates.Unix()
- dayStr := strconv.FormatInt(advice.DayCount, 10)
- dayStr2 := "-" + dayStr
- count, _ := strconv.ParseInt(dayStr2, 10, 64)
- oldTime := scheduleDates.AddDate(0, 0, int(count)).Unix()
- advices, _ := FindAllDoctorAdviceByTimeOther(now, oldTime, item.PatientId, item.UserOrgId, advice.TemplateId)
- if len(advices) == 0 {
- advice_three = append(advice_three, advice)
- }
- }
-
- item.DoctorAdvice = append(item.DoctorAdvice, advice_three...)
- }
- }
- return
- }
-
- func GetWeekDayScheduleById(orgid int64, scheduleDate int64, scheduleType int64, zone int64) (list []*models.VmSchedulesRemind, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduleDate > 0 {
- db = db.Where("x.schedule_date = ?", scheduleDate)
- }
- if scheduleType > 0 {
- db = db.Where("x.schedule_type = ?", scheduleType)
- }
- if zone > 0 {
- db = db.Where("x.partition_id = ?", zone)
- }
-
- err = db.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.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("DialysisOrder", "status = 1").Preload("DoctorAdvice", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1 and parent_id = 0").Preload("ChildDoctorAdvice", "status = 1")
- }).Preload("HisDoctorAdviceInfo", "status = 1").Preload("DialysisPrescription", "status = 1").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1 and solution_status =1").Order("id asc")
- }).Find(&list).Error
-
- return list, err
- }
-
- func GetWeekDayScheduleByIdThee(orgid int64, scheduleDate int64, scheduleType int64, zone []string, limit int64, page int64, ids []string) (list []*models.VmSchedulesRemind, total int64, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- offset := (page - 1) * limit
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduleDate > 0 {
- db = db.Where("x.schedule_date = ?", scheduleDate)
- }
- if scheduleType > 0 {
- db = db.Where("x.schedule_type = ?", scheduleType)
- }
- if len(zone) > 0 {
- db = db.Where("x.partition_id in (?)", zone)
- }
-
- if len(ids) > 0 {
- db = db.Where("x.patient_id in(?)", ids)
- }
-
- err = db.Offset(offset).Limit(limit).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.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Count(&total).Find(&list).Error
-
- return list, total, err
- }
-
- func GetWeekDayScheduleByIdTwo(orgid int64, scheduleDate int64, scheduleType int64, startDate int64, zone []string, limit int64, page int64, ids []string) (list []*models.VmSchedulesRemind, total int64, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- offset := (page - 1) * limit
-
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduleDate > 0 {
- db = db.Where("x.schedule_date >=? and x.schedule_date<=?", startDate, scheduleDate)
- }
- if scheduleType > 0 {
- db = db.Where("x.schedule_type = ?", scheduleType)
- }
- if len(zone) > 0 {
- db = db.Where("x.partition_id in (?)", zone)
- }
- if len(ids) > 0 {
- db = db.Where("x.patient_id in(?)", ids)
- }
-
- err = db.Offset(offset).Limit(limit).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.is_export,x.mode_id").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Count(&total).Find(&list).Error
-
- return list, total, err
- }
-
- func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
- newArr = make([]*models.DoctorAdvice, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].ID == arr[j].ID {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func GetLastLongAdviceByGroupNoOther(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 GetLastLongAdviceByGroupNoThreeOther(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 FindAllDoctorAdviceByTimeOther(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 FindSchPatientNameByName(name string, user_org_id int64) (patient []*models.Patients, err error) {
- err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND name = ? AND status = 1", user_org_id, name).Find(&patient).Error
- return
- }
-
- func UpdateScheduleStatus(date int64, org_id int64) (err error) {
- err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND schedule_date > ? AND status = 1", org_id, date).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func FindDeviceZoneByName(name string, org_id int64) (zone models.DeviceZone, err error) {
- err = readDb.Model(&models.DeviceZone{}).Where("org_id = ? AND name = ? AND status = 1", org_id, name).First(&zone).Error
- return
- }
-
- func FindDeviceByName(device_name string, org_id int64, zone_id int64) (devices []*models.DeviceNumber, err error) {
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id = ? AND number = ? AND zone_id = ? AND status = 1", org_id, device_name, zone_id).Find(&devices).Error
- return
- }
-
- func FindSchedualExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 2", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func FindDeviceByNameTwo(device_name string, org_id int64, zone_id int64) (devices []*models.DeviceNumber, err error) {
- err = readDb.Model(&models.DeviceNumber{}).Where("org_id = ? AND number = ? AND status = 1 AND zone_id = ?", org_id, device_name, zone_id).Find(&devices).Error
- return
- }
-
- func UpdateScheduleTemplateStatus(org_id int64) (err error) {
- err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("org_id = ? AND status = 1", org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func CreateScheduleTemplate(m *models.PatientScheduleTemplateItem) error {
- return writeDb.Model(&models.PatientScheduleTemplateItem{}).Create(&m).Error
- }
-
- func ExportScheduleTemplate(m *models.PatientScheduleTemplateItem) (total int64) {
- readDb.Model(&models.PatientScheduleTemplateItem{}).Where("template_id = ? AND patient_id = ? AND weekday = ? AND org_id = ? and status =1", m.TemplateID, m.PatientID, m.Weekday, m.OrgID).Count(&total)
- return
- }
-
- func FindSchedualTemplateExportLog(org_id int64, export_time int64) (errLogs []*models.ExportErrLog, err error) {
- err = readDb.Model(&models.ExportErrLog{}).Where("user_org_id = ? AND export_time = ? AND log_type = 3", org_id, export_time).Find(&errLogs).Error
- return
- }
-
- func GetDialysisOrderByBedId(orgID, start, bed_id int64, schedule_type int64) (*models.DialysisOrder, error) {
- order := models.DialysisOrder{}
- err = readDb.Model(&order).Where("user_org_id=? and dialysis_date=? and bed_id=? and status=1 AND schedual_type = ?", orgID, start, bed_id, schedule_type).Find(&order).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &order, nil
-
- }
-
- type VMDeviceNumber struct {
- ID int64 `gorm:"column:id" json:"id"`
- OrgID int64 `gorm:"column:org_id" json:"-"`
- Number string `gorm:"column:number" json:"number"`
- GroupID int64 `gorm:"column:group_id" json:"group_id"`
- ZoneID int64 `gorm:"column:zone_id" json:"zone_id"`
- Status int8 `json:"-"`
- CreateTime int64 `gorm:"column:ctime" json:"-"`
- ModifyTime int64 `gorm:"column:mtime" json:"-"`
- DeviceZone models.DeviceZone `json:"zone" gorm:"foreignkey:ID;AssociationForeignKey:ZoneID;"`
- }
-
- func (VMDeviceNumber) TableName() string {
- return "xt_device_number"
- }
-
- type VMPatientScheduleTemplateItem struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- OrgID int64 `gorm:"column:org_id" json:"-" form:"org_id"`
- TemplateID int64 `gorm:"column:template_id" json:"template_id" form:"template_id"`
- DeviceNumberID int64 `gorm:"column:device_number_id" json:"device_number_id" form:"device_number_id"`
- PatientID int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
- TreatMode int64 `gorm:"column:treat_mode" json:"treat_mode" form:"treat_mode"` // 治疗模式
- Weekday int8 `gorm:"column :weekday" json:"weekday" form:"weekday"` // 周一-周日 1-7
- TimeType int8 `gorm:"column:time_type" json:"time_type" form:"time_type"` // 上下晚 123
- Status int8 `gorm:"column:status" json:"status" form:"status"`
- CreateTime int64 `gorm:"column:ctime" json:"-" form:"ctime"`
- ModifyTime int64 `gorm:"column:mtime" json:"-" form:"mtime"`
- IsExport int64 `gorm:"column:is_export" json:"is_export" form:"is_export"`
-
- Patient string `gorm:"-" json:"patient" form:"patient"`
- DeviceNumber VMDeviceNumber `json:"number" gorm:"foreignkey:ID;AssociationForeignKey:DeviceNumberID;"`
-
- PatientInfectiousDiseases []*models.InfectiousDiseases `json:"patient_contagions" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
- }
-
- func (VMPatientScheduleTemplateItem) TableName() string {
- return "xt_patient_schedule_template_item"
- }
-
- func GetTemplateSchedualPatientsByKeywords(keywords string, org_id int64, template_id int64) (schedule []*VMPatientScheduleTemplateItem, err error) {
- likeKey := "%" + keywords + "%"
-
- err = readDb.
- Table("xt_patient_schedule_template_item as s").
- Preload("PatientInfectiousDiseases", "status = 1 ").
- Preload("DeviceNumber", func(db *gorm.DB) *gorm.DB {
- return db.Where("org_id = ? AND status = 1", org_id).Preload("DeviceZone", "org_id = ? AND status = 1", org_id)
- }).
- Joins("JOIN xt_patients as p ON p.id = s.patient_id AND (p.name LIKE ? OR p.dialysis_no LIKE ?)", likeKey, likeKey).
- Where("s.template_id = ? AND s.org_id=? and s.status=1", template_id, org_id).
- Select("s.id, s.org_id, s.template_id, s.device_number_id, s.patient_id, s.treat_mode, s.weekday, s.time_type, s.status, s.ctime, s.mtime, p.name as patient").
- Order("weekday asc").
- Find(&schedule).Error
- return
-
- }
-
- func UpdateNewScheduleTemplateStatus(id int64, org_id int64) (err error) {
- err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("org_id = ? AND id = ?", org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
- return
- }
-
- func GetNextWeekDaySchedule(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string, record_date int64, ids []string) (schedules []*models.WeekScheduleSix, err error) {
-
- db := XTReadDB().Table("xt_schedule as s ").Where("s.status =1")
- if orgID > 0 {
- db = db.Where("s.user_org_id = ?", orgID)
- }
- if weektype == 0 {
- if startime > 0 {
- db = db.Where("s.schedule_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("s.schedule_date <= ?", endtime)
- }
- }
-
- if weektype > 0 {
- if record_date > 0 {
- db = db.Where("s.schedule_date = ?", record_date)
- }
- }
-
- if weektime > 0 {
- db = db.Where("s.schedule_type = ?", weektime)
- }
- if weektype > 0 {
- db = db.Where("s.schedule_week = ?", weektype)
- }
- if len(zone) > 0 {
- db = db.Where("s.partition_id in (?)", zone)
- }
- if len(ids) > 0 {
- db = db.Where("s.patient_id in (?)", ids)
- }
- err = db.
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Select("s.id,s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient,p.id_card_no as id_card_no,p.dialysis_no as dialysis_no,p.gender as gender,p.phone as phone").
- Order("s.partition_id desc").
- Find(&schedules).Error
- return schedules, err
- }
-
- func GetThreeWeekList(startime int64, endtime int64, orgid int64, scheduletype int64, partionid int64) (schedule []*models.VmSchedule, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status =1")
- if startime > 0 {
- db = db.Where("x.schedule_date >=?", startime)
- }
- if endtime > 0 {
- db = db.Where("x.schedule_date <=?", endtime)
- }
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if scheduletype > 0 {
- db = db.Where("x.schedule_type = ?", scheduletype)
- }
- if partionid > 0 {
- db = db.Where("x.partition_id = ?", partionid)
- }
- err = db.Select("x.schedule_date,x.schedule_type,x.schedule_week,x.bed_id,x.partition_id,t.name,n.number,z.name,x.dialysis_machine_name,x.mode_id").Joins("left join xt_patients as t on t.id = x.patient_id and t.user_org_id = ? and t.status = 1", orgid).Joins("left join xt_device_zone as z on z.id = x.partition_id and z.org_id = ? and z.status =1", orgid).Joins("left join xt_device_number as n on n.id = x.bed_id and n.org_id = ? and n.status =1", orgid).Scan(&schedule).Error
-
- return schedule, err
- }
-
- func UpdatedDialysisPrescription(prescription *models.DialysisPrescription, recordDate int64, patientid int64, orgid int64) error {
-
- err := XTWriteDB().Model(&prescription).Where("record_date = ? and patient_id = ? and user_org_id = ?", recordDate, patientid, orgid).Update(map[string]interface{}{"mode_id": prescription.ModeId, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetWeekSchedules(orgid int64, startime int64, endtime int64) (scheudle []*models.XtSchedule, err error) {
-
- err = XTReadDB().Model(&scheudle).Where("user_org_id = ? and status = 1 and schedule_date>=? and schedule_date<=?", orgid, startime, endtime).Find(&scheudle).Error
- return scheudle, err
- }
-
- func GetLastWeekSchedule(orgid int64, startime int64, endtime int64) (*models.XtSchedule, error) {
- schedule := models.XtSchedule{}
- err := XTReadDB().Where("user_org_id = ? and status =1 and schedule_date>=? and schedule_date<=?", orgid, startime, endtime).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
- func AddPatientSchedule(schedule *models.XtSchedule) error {
- utx := XTWriteDB().Begin()
- err := utx.Create(&schedule).Error
- utx.Commit()
- return err
- }
-
- func UpdatePatientSchedule(orgid int64, startime int64, endtime int64) error {
-
- schedule := models.XtSchedule{}
- err := XTWriteDB().Model(&schedule).Where("user_org_id = ? and schedule_date>=? and schedule_date<=? and status =1", orgid, startime, endtime).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetSettingById(id int64) (*models.XtRemindPrintSetting, error) {
- setting := models.XtRemindPrintSetting{}
- err := XTReadDB().Model(&setting).Where("id = ? and status = 1", id).Find(&setting).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &setting, nil
- }
-
- func CreateSetting(setting *models.XtRemindPrintSetting) error {
-
- err := XTWriteDB().Create(&setting).Error
- return err
- }
-
- func UpdatedRemindPrint(set *models.XtRemindPrintSetting, id int64) error {
-
- err := XTWriteDB().Model(&set).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"prescription_status": set.PrescriptionStatus, "week": set.Week, "name": set.Name, "zone": set.Zone, "classes": set.Classes, "number": set.Number, "mode": set.Mode, "dialyzers": set.Dialyzers, "perfusion_apparatus": set.PerfusionApparatus, "anticoagulant": set.Anticoagulant, "doctor_advice": set.DoctorAdvice, "anticoagulant_zongliang": set.AnticoagulantZongliang}).Error
- return err
- }
-
- func GetRemindPrintList(id int64) (models.XtRemindPrintSetting, error) {
-
- setting := models.XtRemindPrintSetting{}
- err := XTReadDB().Model(&setting).Where("user_org_id = ? and status =1", id).Find(&setting).Error
- return setting, err
- }
-
- func GetScheudleTemplateById(orgid int64) (*models.ScheduleTemplate, error) {
-
- schedule := models.ScheduleTemplate{}
- err := XTReadDB().Model(&schedule).Where("user_org_id = ? and status = 1", orgid).Find(&schedule).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &schedule, nil
- }
-
- func CreateXtscheduleTemplate(template *models.ScheduleTemplate) error {
-
- err := XTWriteDB().Create(&template).Error
- return err
- }
-
- func UpdateXtScheduleTemplate(template *models.ScheduleTemplate, orgid int64) error {
-
- err := XTWriteDB().Model(&template).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"template_id": template.TemplateId}).Error
- return err
- }
-
- func GetScheduleTemplate(orgid int64) (models.ScheduleTemplate, error) {
-
- template := models.ScheduleTemplate{}
- err := XTReadDB().Where("user_org_id = ? and status = 1", orgid).Find(&template).Error
- return template, err
- }
-
- func GetDataPrintByOrgId(orgid int64) (*models.XtDataPrint, error) {
-
- dataPrint := models.XtDataPrint{}
-
- err := XTReadDB().Model(&dataPrint).Where("user_org_id = ? and status = 1", orgid).Find(&dataPrint).Error
-
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &dataPrint, nil
- }
-
- func CreateDataPrint(dataPrint *models.XtDataPrint) error {
-
- err := XTWriteDB().Create(&dataPrint).Error
- return err
- }
-
- func UpdteDataPrint(orgid int64, dataPrint *models.XtDataPrint) error {
-
- err := XTWriteDB().Model(&dataPrint).Where("user_org_id = ? and status = 1", orgid).Updates(map[string]interface{}{"is_open": dataPrint.IsOpen}).Error
- return err
- }
-
- func GetDataPrint(orgid int64) (models.XtDataPrint, error) {
- dataPrint := models.XtDataPrint{}
- err := XTReadDB().Model(&dataPrint).Where("user_org_id = ? and status = 1", orgid).Find(&dataPrint).Error
- return dataPrint, err
- }
-
- func GetNextWeekPanels(startime int64, endtime int64, orgid int64) (schedule []*models.XtSchedule, err error) {
-
- err = XTReadDB().Model(&schedule).Where("schedule_date >=? and schedule_date<=? and status = 1 and user_org_id = ?", startime, endtime, orgid).Preload("LastAfterWeight", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? and status = 1 and assessment_date>=1704038400 and assessment_date < ?", orgid, endtime)
- }).Find(&schedule).Error
- return schedule, err
- }
-
- func GetTemplateListByTemplateId(id int64, orgid int64) (list []*models.VmPatientScheduleTemplateItem, err error) {
-
- err = XTReadDB().Where("template_id =? and org_id = ? and status = 1", id, orgid).Find(&list).Error
- return list, err
- }
-
- func DeletePatientSchedule(startime int64, endtime int64, org_id int64) (models.XtSchedule, error) {
-
- schedule := models.XtSchedule{}
- err := XTWriteDB().Model(&schedule).Where("schedule_date>=? and schedule_date<=? and user_org_id = ? and status = 1", startime, endtime, org_id).Updates(map[string]interface{}{"status": 0}).Error
- return schedule, err
- }
-
- func DeletePatientScheduleToday(startime int64, endtime int64, org_id int64) (models.XtSchedule, error) {
-
- schedule := models.XtSchedule{}
- err := XTWriteDB().Model(&schedule).Where("schedule_date>? and schedule_date<=? and user_org_id = ? and status = 1", startime, endtime, org_id).Updates(map[string]interface{}{"status": 0}).Error
- return schedule, err
- }
-
- func GetBedNumberById(id int64, org_id int64) (models.DeviceNumber, error) {
-
- number := models.DeviceNumber{}
-
- err := XTReadDB().Where("id = ? and status = 1 and org_id =?", id, org_id).Find(&number).Error
- return number, err
- }
-
- func CreatePatientSchedule(schedule *models.XtSchedule) error {
-
- utx := XTWriteDB().Begin()
- err := utx.Create(&schedule).Error
- utx.Commit()
- return err
- }
-
- func GetPatientScheduleTempalate(orgid int64) (models.PatientScheduleTemplateMode, error) {
-
- mode := models.PatientScheduleTemplateMode{}
- err := XTReadDB().Where("org_id = ? and status =1", orgid).Find(&mode).Error
- return mode, err
- }
-
- func GetSolutionSchedule(orgid int64) (solution []*models.VmDialysisSolution, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and status = 1", orgid).Group("patient_id,mode_id").Order("created_time desc").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? and status = 1", orgid).Order("id asc")
- }).Find(&solution).Error
- return solution, err
- }
-
- func GetSolutionScheduleBySchedule(orgid int64, zonid int64, classtype int64, schedule_date int64) (schedule []*models.XtScheduleList, err error) {
-
- db := XTReadDB().Model(&schedule).Where("status = 1")
- if orgid > 0 {
- db = db.Where("user_org_id =?", orgid)
- }
- if zonid > 0 {
- db = db.Where("partition_id = ?", zonid)
- }
- if classtype > 0 {
- db = db.Where("schedule_type = ?", classtype)
- }
- if schedule_date > 0 {
- db = db.Where("schedule_date = ?", schedule_date)
- }
- err = db.Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? and status = 1", orgid).Group("patient_id,mode_id").Order("created_time asc").Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? and status = 1", orgid).Order("id asc")
- })
- }).Find(&schedule).Error
- return schedule, err
- }
-
- func GetDeathPatient(orgid int64) (patient []*models.XtPatients, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and (lapseto = 2 || lapseto = 3) and status = 1", orgid).Find(&patient).Error
- return patient, err
- }
-
- func GetInitPrintData(patient_id int64, scheduleDate int64, orgid int64) (list []*models.VmSchedulesRemind, err error) {
-
- db := XTReadDB().Table("xt_schedule as x").Where("x.status = 1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- if patient_id > 0 {
- db = db.Where("x.patient_id = ?", patient_id)
- }
- if scheduleDate > 0 {
- db = db.Where("x.schedule_date >=? and x.schedule_date<=?", scheduleDate, scheduleDate)
- }
- err = db.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.is_export").Preload("XtPatients", "status = 1").Preload("DeviceZone", "status = 1").Preload("DeviceNumber", "status = 1").Preload("XtAssessmentBeforeDislysis", "status = 1 and assessment_date =? and patient_id = ?", scheduleDate, patient_id).Preload("DialysisPrescription", "status = 1 and record_date = ? and patient_id = ?", scheduleDate, patient_id).Preload("DialysisSolution", func(db *gorm.DB) *gorm.DB {
- return db.Where("status =1 and patient_id = ?", patient_id).Order("id asc")
- }).Find(&list).Error
-
- return list, err
- }
-
- func GetLastWeightAfter(patient_id int64, scheduleDate int64, orgid int64) (models.AssessmentAfterDislysis, error) {
- dislysis := models.AssessmentAfterDislysis{}
- err := XTReadDB().Where("user_org_id = ? and patient_id = ? and assessment_date < ? and status = 1", orgid, patient_id, scheduleDate).Order("id desc").First(&dislysis).Error
- return dislysis, err
- }
-
- func GetScheduleTwo(orgID, id int64) (models.Schedule, error) {
- var schedule models.Schedule
- var err error
- err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
- return schedule, err
- }
-
- func UpdateSchDName(sch models.Schedule) (err error) {
- err = writeDb.Model(&models.Schedule{}).Where("status=1 AND id = ?", sch.ID).Updates(map[string]interface{}{"dialysis_machine_name": sch.DialysisMachineName}).Error
- return
- }
-
- func GetDialysisOrderByBedIdTwo(orgID, start, bed_id int64, schedule_type int64) (models.DialysisOrder, error) {
- order := models.DialysisOrder{}
- err = readDb.Model(&order).Where("user_org_id=? and dialysis_date=? and bed_id=? and status=1 AND schedual_type = ?", orgID, start, bed_id, schedule_type).Find(&order).Error
- return order, nil
-
- }
-
- func ChangeScheduleClass(schedule models.Schedule) error {
-
- err := XTWriteDB().Model(&schedule).Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status = 1", schedule.PatientId, schedule.ScheduleDate, schedule.UserOrgId).Update(map[string]interface{}{"schedule_type": schedule.ScheduleType}).Error
- return err
- }
-
- func GetLastDialysisOrder(org_id int64, patient_id int64, dialysis_date int64) (models.XtDialysisOrderSix, error) {
-
- order := models.XtDialysisOrderSix{}
- err := XTReadDB().Where("user_org_id = ? and patient_id = ? and dialysis_date < ? and status = 1", org_id, patient_id, dialysis_date).Order("id desc").First(&order).Error
- return order, err
- }
-
- func GetHisDoctorAdviceList(org_id int64, patient_id int64, dialysis_date int64) (adviceInfo []*models.HisDoctorAdviceInfo, err error) {
-
- err = XTReadDB().Where("patient_id=? and user_org_id = ? and advice_date= ? and status=1", patient_id, org_id, dialysis_date).Find(&adviceInfo).Error
-
- return adviceInfo, err
- }
-
- func GetMobileDoctorAdviceList(org_id int64, patient_id int64, dialysis_date int64) (advice []*models.DoctorAdvice, err error) {
-
- err = XTReadDB().Where("patient_id=? and user_org_id = ? and advice_date= ? and status=1 and advice_type =2", patient_id, org_id, dialysis_date).Find(&advice).Error
-
- return advice, err
- }
-
- func UpdateHisAdviceList(id int64, creater int64) (models.HisDoctorAdvice, error) {
-
- doctorAdvice := models.HisDoctorAdvice{}
- 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 doctorAdvice, err
- }
-
- func UpdateAdviceList(id int64, creater int64) (models.DoctorAdvice, error) {
-
- advice := models.DoctorAdvice{}
-
- 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 advice, err
- }
-
- func GetDoctorAdviceListSchedule(org_id int64, patient_id int64) (advices []*models.DoctorAdvice, err error) {
-
- err = XTReadDB().Where("patient_id=? and user_org_id = ? and status=1 and parent_id=0 and advice_type =1", patient_id, org_id).Preload("ChildDoctorAdvice", "status = 1").Find(&advices).Error
- return advices, err
- }
-
- func GetLastDialysisPrescriptionTwo(org_id int64, patient_id int64, mode_id int64, schedule_date int64) (models.NewDialysisPrescription, error) {
-
- dialysisprescription := models.NewDialysisPrescription{}
-
- if org_id == 10340 {
- err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode_id = ? and status = 1 and record_date <= ?", org_id, patient_id, mode_id, schedule_date).Order("id desc").Last(&dialysisprescription).Error
- return dialysisprescription, err
- } else {
- err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode_id = ? and status = 1 and record_date = ?", org_id, patient_id, mode_id, schedule_date).Order("id desc").First(&dialysisprescription).Error
- return dialysisprescription, err
- }
-
- }
-
- func GetLastDialysisSolution(org_id int64, patient_id int64, mode_id int64) (models.DialysisSolution, error) {
- dialysisSolution := models.DialysisSolution{}
- err := XTReadDB().Where("user_org_id =? and patient_id = ? and mode_id = ? and status=1 and solution_status=1", org_id, patient_id, mode_id).Find(&dialysisSolution).Error
- return dialysisSolution, err
- }
-
- func GetLastDialysisAfter(org_id int64, patient_id int64, schedule_date int64) (models.AssessmentAfterDislysis, error) {
-
- dislysis := models.AssessmentAfterDislysis{}
- err := XTReadDB().Where("user_org_id = ? and patient_id =? and assessment_date <= ? and status=1", org_id, patient_id, schedule_date).Order("id desc").Last(&dislysis).Error
- return dislysis, err
- }
-
- func GetDoctorAdviceLastWeek(org_id int64, patient_id int64, schedule_date int64) (advice []*models.DoctorAdvice, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and patient_id = ? and status= 1 and parent_id = 0 and advice_date = ?", org_id, patient_id, schedule_date).Preload("ChildDoctorAdvice", "status = 1 and advice_date = ?", schedule_date).Find(&advice).Error
- return advice, err
- }
-
- func GetHisDoctorAdviceListLastWeek(org_id int64, patient_id int64, schedule_date int64) (advice []*models.HisDoctorAdviceInfo, err error) {
-
- err = XTReadDB().Where("user_org_id = ? and patient_id = ? and advice_date = ? and status= 1", org_id, patient_id, schedule_date).Find(&advice).Error
- return advice, err
- }
-
- func GetDialysisSolutionLastWeek(user_org_id int64, patient_id int64, mode_id int64) (models.DialysisSolution, error) {
-
- solution := models.DialysisSolution{}
-
- err := XTReadDB().Where("user_org_id =? and status = 1 and patient_id = ? and mode_id = ? and solution_status = 1", user_org_id, patient_id, mode_id).Find(&solution).Error
-
- return solution, err
- }
-
- func GetNextWeekDayScheduleSix(weektype int64, weektime int64, startime int64, endtime int64, orgID int64, zone []string, record_date int64, ids []string) (schedules []*models.WeekScheduleSeven, err error) {
-
- db := XTReadDB().Table("xt_schedule as s ").Where("s.status =1")
- if orgID > 0 {
- db = db.Where("s.user_org_id = ?", orgID)
- }
- if weektype == 0 {
- if startime > 0 {
- db = db.Where("s.schedule_date >= ?", startime)
- }
- if endtime > 0 {
- db = db.Where("s.schedule_date <= ?", endtime)
- }
- }
-
- if weektype > 0 {
- if record_date > 0 {
- db = db.Where("s.schedule_date = ?", record_date)
- }
-
- }
-
- if weektime > 0 {
- db = db.Where("s.schedule_type = ?", weektime)
- }
- if weektype > 0 {
- db = db.Where("s.schedule_week = ?", weektype)
- }
- if len(zone) > 0 {
- db = db.Where("s.partition_id in (?)", zone)
- }
- if len(ids) > 0 {
- db = db.Where("s.patient_id in(?)", ids)
- }
- err = db.
- Preload("DeviceZone", "status = 1 ").
- Preload("DeviceNumber", "status = 1 ").
- Preload("XtAssessmentBeforeDislysis", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 and assessment_date = ?", record_date)
- }).Joins("JOIN xt_patients as p ON p.id = s.patient_id").
- Select("s.id,s.user_org_id, s.partition_id, s.bed_id, s.patient_id, s.schedule_date, s.schedule_type, s.schedule_week, s.mode_id, s.status, s.created_time, s.updated_time, p.name as patient,p.id_card_no as id_card_no,p.dialysis_no as dialysis_no,p.gender as gender,p.phone as phone").
- Order("s.partition_id desc").
- Find(&schedules).Error
- return schedules, err
- }
-
- func GetAssessmentBeforListLastWeek(schedule_date int64, patient_id int64, org_id int64) (models.XtAssessmentBeforeDislysis, error) {
-
- dislysis := models.XtAssessmentBeforeDislysis{}
- err := XTReadDB().Where("assessment_date = ? and patient_id = ? and user_org_id =? and status = 1", schedule_date, patient_id, org_id).Find(&dislysis).Error
- return dislysis, err
- }
-
- func GetLastDialysisSolutionType(org_id int64, patient_id int64, mode_id int64) (models.NewDialysisSolutionOne, error) {
-
- dialysisprescription := models.NewDialysisSolutionOne{}
- err := XTReadDB().Where("user_org_id = ? and patient_id = ? and mode_id = ? and status = 1 and solution_status =1", org_id, patient_id, mode_id).First(&dialysisprescription).Error
- return dialysisprescription, err
-
- }
-
- func GetScheduleTen(orgID, id int64) (models.Schedule, error) {
- var schedule models.Schedule
- var err error
- err = readDb.Model(&models.Schedule{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
- return schedule, err
- }
-
- func GetDialysisOrderByPatientAndBed(org_id int64, record_date int64, bed_id int64, patient_id int64) (order models.DialysisOrder, err error) {
- err = readDb.Model(&models.DialysisOrder{}).Where("user_org_id = ? AND status = 1 AND dialysis_date = ? AND bed_id = ? AND patient_id = ?", org_id, record_date, bed_id, patient_id).First(&order).Error
- return
- }
-
- func GetScheduleTemplateTen(orgID, id int64) (models.PatientScheduleTemplateItem, error) {
- var schedule models.PatientScheduleTemplateItem
- var err error
- err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where("id = ? and user_org_id=? and status=1", id, orgID).First(&schedule).Error
- return schedule, err
- }
-
- func GetScheduleTemplateCountByDate(org_id int64, week_day int8, patient_id int64, template_id int64) (total int64, err error) {
- err = readDb.Model(&models.PatientScheduleTemplateItem{}).Where(" org_id = ? AND weekday = ? AND status = 1 AND patient_id = ? AND template_id = ?", org_id, week_day, patient_id, template_id).Count(&total).Error
- return
- }
-
- func SaveSchTemplateTwo(sch models.PatientScheduleTemplateItem, sch_two models.PatientScheduleTemplateItem, new_sch models.PatientScheduleTemplateItem) (err error) {
- utx := writeDb.Begin()
- if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("status=1 AND id = ?", sch.ID).Updates(map[string]interface{}{"status": 0}).Error; err != nil {
- utx.Rollback()
- return err
- }
- if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("status=1 AND id = ?", sch_two.ID).Updates(map[string]interface{}{"status": 0}).Error; err != nil {
- utx.Rollback()
- return err
- }
- if err = utx.Save(&new_sch).Error; err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
-
- return err
- }
-
- func SaveSchTemplate(sch models.PatientScheduleTemplateItem, sch_two models.PatientScheduleTemplateItem) (err error) {
- utx := writeDb.Begin()
- if err = utx.Save(&sch).Error; err != nil {
- utx.Rollback()
- return err
- }
-
- if err = utx.Save(&sch_two).Error; err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
-
- return err
- }
-
- func UpdateScheduleTemplateThree(schone models.PatientScheduleTemplateItem, schtwo models.PatientScheduleTemplateItem) error {
- utx := XTWriteDB().Begin()
- //床位
- var tempBedID int64
- var tempBedIDTwo int64
-
- //上下午
- var tempTypeID int8
- var tempTypeTwo int8
-
- //周数
- var sch_week_one int8
- var sch_week_two int8
-
- tempBedID = schone.DeviceNumberID
- tempBedIDTwo = schtwo.DeviceNumberID
-
- tempTypeID = schone.TimeType
- tempTypeTwo = schtwo.TimeType
-
- sch_week_one = schone.Weekday
- sch_week_two = schtwo.Weekday
-
- schone.DeviceNumberID = tempBedIDTwo
- schtwo.DeviceNumberID = tempBedID
-
- schone.TimeType = tempTypeTwo
- schtwo.TimeType = tempTypeID
-
- schone.Weekday = sch_week_two
- schtwo.Weekday = sch_week_one
- if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", schone.ID).Updates(map[string]interface{}{"device_number_id": schone.DeviceNumberID, "time_type": schone.TimeType, "weekday": schone.Weekday, "is_export": 70000}).Error; err != nil {
- utx.Rollback()
- return err
- }
- if err = utx.Model(&models.PatientScheduleTemplateItem{}).Where("id = ?", schtwo.ID).Updates(map[string]interface{}{"device_number_id": schtwo.DeviceNumberID, "time_type": schtwo.TimeType, "weekday": schtwo.Weekday, "is_export": 70000}).Error; err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
-
- return err
- }
-
- func GetScheduleTemplateForDeviceNumberTwo(orgID int64, deviceNumberID int64, template_id int64, week_type int64, time_type int64, patient_id int64) (models.PatientScheduleTemplateItem, error) {
- var item models.PatientScheduleTemplateItem
- err := readDb.Model(&models.PatientScheduleTemplateItem{}).Where("device_number_id = ? AND org_id = ? AND status = 1 AND template_id = ? AND weekday = ? AND time_type = ? AND patient_id = ?", deviceNumberID, orgID, template_id, week_type, time_type, patient_id).First(&item).Error
- return item, err
- }
-
- func ClearSchedules(user_org_id int64, start_time int64) (err error) {
- err = writeDb.Table("xt_schedule as s").
- Where("s.schedule_date > ? AND s.status = 1 AND "+
- "s.user_org_id = ?", start_time, user_org_id).
- Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return
- }
-
- func CreateScheduleTwo(m *models.Schedule) error {
- utx := XTWriteDB().Begin()
- err = utx.Create(&m).Error
- if err != nil {
- utx.Rollback()
- return err
- }
- utx.Commit()
- return err
- }
-
- func GetLongSolutionByModeId(patient_id int64, mode_id int64, user_org_id int64) (models.DialysisSolution, error) {
-
- solution := models.DialysisSolution{}
-
- err := XTReadDB().Where("patient_id = ? and mode_id = ? and user_org_id = ? and status= 1 and solution_status =1", patient_id, mode_id, user_org_id).Find(&solution).Error
- return solution, err
- }
-
- func UpdateScheduleByDialysis(patient_id int64, mode_id int64, schedule_date int64, user_org_id int64, dialyzer_perfusion_apparatus string, schedule_type int64) error {
-
- schedule := models.XtSchedule{}
-
- err := XTWriteDB().Model(&schedule).Where("patient_id = ? and mode_id = ? and schedule_date = ? and user_org_id = ? and schedule_type = ?", patient_id, mode_id, schedule_date, user_org_id, schedule_type).Updates(map[string]interface{}{"dialysis_machine_name": dialyzer_perfusion_apparatus}).Error
-
- return err
- }
-
- func GetScheduleByBedId(bed_id int64, schedule_type int64, user_org_id int64, schedule_date int64) (models.XtSchedule, error) {
-
- schedule := models.XtSchedule{}
-
- err := XTReadDB().Model(&schedule).Where("bed_id = ? and schedule_type =? and user_org_id = ? and schedule_date = ? and status =1", bed_id, schedule_type, user_org_id, schedule_date).Find(&schedule).Error
-
- return schedule, err
- }
-
- func UpdateScheduleByScheduleId(id int64) error {
-
- err := XTWriteDB().Model(&models.XtSchedule{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
-
- return err
- }
-
- func UpdateScheduleSixTy(id int64, schedules models.XtSchedule) error {
-
- err := XTWriteDB().Model(&models.XtSchedule{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"mode_id": schedules.ModeId, "partition_id": schedules.PartitionId, "bed_id": schedules.BedId, "patient_id": schedules.PatientId, "schedule_date": schedules.ScheduleDate, "schedule_type": schedules.ScheduleType, "schedule_week": schedules.ScheduleWeek}).Error
-
- return err
- }
-
- func CreateNewSchedule(schedule models.XtSchedule) error {
-
- err := XTWriteDB().Create(&schedule).Error
-
- return err
- }
-
- func GetNumberListById(id int64, org_id int64) (number []*models.DeviceNumber, err error) {
-
- err = XTReadDB().Where("zone_id = ? and org_id = ? and status= 1", id, org_id).Find(&number).Error
-
- return number, err
- }
-
- func CreateScheduleLog(log models.XtScheduleLog) error {
-
- err := XTWriteDB().Create(&log).Error
-
- return err
- }
-
- func GetDoctorAdviceListTwenty(patient_id int64, schedule_date int64, user_org_id int64) (advice []*models.XtDoctorAdvice, err error) {
-
- err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id = ? and status=1", patient_id, schedule_date, user_org_id).Find(&advice).Error
- return advice, err
- }
-
- func GetHisDoctorAdviceListTwenty(patient_id int64, schedule_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, schedule_date, user_org_id).Find(&advice).Error
- return advice, err
- }
-
- func GetHisDoctorAdviceListTwentyOne(patient_id int64, schedule_date int64, user_org_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
-
- err = XTReadDB().Where("patient_id = ? and advice_date = ? and user_org_id = ? and status=1", patient_id, schedule_date, user_org_id).Find(&advice).Error
- return advice, err
- }
-
- func GetHisPrescriptionProjectList(patient_id int64, record_date int64, user_org_id int64) (project []*models.HisPrescriptionProject, err error) {
- err = XTReadDB().Where("patient_id = ? and record_date = ? and user_org_id = ? and status=1", patient_id, record_date, user_org_id).Find(&project).Error
- return project, err
- }
-
- func UpdateProjectObj(patient_id int64, schedule_date int64, user_org_id int64) (err error) {
-
- err = XTWriteDB().Model(&models.HisPrescriptionProject{}).Where("patient_id = ? and record_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
-
- err = XTWriteDB().Model(&models.HisPrescription{}).Where("patient_id = ? and status=1 and record_date = ? and user_org_id =?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
-
- err = XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("patient_id = ? and status=1 and record_date = ? and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func UpdateAdviceObj(patient_id int64, schedule_date int64, user_org_id int64) (err error) {
-
- err = XTWriteDB().Model(&models.XtDoctorAdvice{}).Where("patient_id = ? and advice_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func UpdateHisAdviceObj(patient_id int64, schedule_date int64, user_org_id int64) (err error) {
-
- err = XTWriteDB().Model(&models.HisDoctorAdvice{}).Where("patient_id = ? and advice_date =? and status=1 and user_org_id = ?", patient_id, schedule_date, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
- return err
- }
-
- func GetLastSchedule(patient_id int64, user_org_id int64) (models.XtSchedule, error) {
-
- schedule := models.XtSchedule{}
- err := XTReadDB().Where("patient_id = ? and status =1 and user_org_id = ?", patient_id, user_org_id).Find(&schedule).Error
- return schedule, err
- }
-
- func GetPatientScheduleToday(patient_id int64, schedule_date int64, user_org_id int64) (models.XtSchedule, error) {
-
- schedule := models.XtSchedule{}
- err = XTReadDB().Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status=0", patient_id, schedule_date, user_org_id).Find(&schedule).Error
- return schedule, err
- }
-
- func UpdateRepeatSchStatus(user_org_id int64, schedule_date int64) {
- var schedules []models.XtSchedule
- // Find duplicate records based on patient_id, schedule_date, and user_org_id
- XTReadDB().Where("user_org_id = ? AND schedule_date = ? AND status = ?", user_org_id, schedule_date, 1).
- Group("patient_id, schedule_date").
- Having("COUNT(*) > 1").
- Select("patient_id, schedule_date, MAX(id) as max_id").
- Find(&schedules)
-
- for _, schedule := range schedules {
- // Update records with status = 0 where id is less than max_id
- XTReadDB().Model(&models.XtSchedule{}).Where("patient_id = ? AND schedule_date = ? AND id < ?", schedule.PatientId, schedule.ScheduleDate, schedule.MaxId).Update("status", 0)
-
- }
-
- }
-
- func GetSchedulePatientIdByPatient(patient_id int64, schedule_date int64, user_org_id int64) (models.Schedule, error) {
-
- schedule := models.Schedule{}
- err := XTReadDB().Where("patient_id = ? and schedule_date = ? and user_org_id = ? and status =1", patient_id, schedule_date, user_org_id).Find(&schedule).Error
- return schedule, err
- }
-
- func UpdateMobileSchedule(id_two int64, mode_id int64, bed_id int64, zone_id int64, schedule_type int64, id int64) error {
-
- schedule := models.Schedule{}
-
- err = XTWriteDB().Model(&schedule).Where("id = ? and status=1", id).Updates(map[string]interface{}{"patient_id": id_two, "mode_id": mode_id, "bed_id": bed_id, "partition_id": zone_id, "schedule_type": schedule_type}).Error
-
- return err
- }
-
- func GetPatientGoodCountToday(patient_id int64, schedule_date int64, user_org_id int64) (list []*models.WarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("patient_id =? and sys_record_time=? and org_id = ? and status=1 and count>0", patient_id, schedule_date, user_org_id).Find(&list).Error
- return list, err
- }
-
- func GetPatientDrugCountToday(patient_id int64, schedule_date int64, user_org_id int64) (list []*models.DrugWarehouseOutInfo, err error) {
-
- err = XTReadDB().Where("patient_id =? and sys_record_time=? and org_id = ? and status=1", patient_id, schedule_date, user_org_id).Find(&list).Error
- return list, err
- }
|