123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "encoding/json"
- "fmt"
- "strconv"
- "strings"
- "time"
-
- "github.com/astaxie/beego"
- )
-
- func PatientScheduleTemplateAPIControllerRegistRouters() {
- beego.Router("/api/schtemp/p/initdata", &PatientScheduleTemplateAPIController{}, "get:InitData")
- beego.Router("/api/schtemp/p/setmode", &PatientScheduleTemplateAPIController{}, "post:SetMode")
- beego.Router("/api/schtemp/p/update_sch", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedules")
-
- beego.Router("/api/patients/list", &PatientScheduleTemplateAPIController{}, "get:GetPatientList")
-
- beego.Router("/api/schedule/update_schtemplate", &PatientScheduleTemplateAPIController{}, "post:UpdateSchedulesTemplate")
- beego.Router("/api/schtemplate_device/get", &ScheduleApiController{}, "Get:GetTemplateDevicesNumbers")
-
- beego.Router("/api/schtemplate/exchange", &ScheduleApiController{}, "Get:ExchangeSchTemplate")
- beego.Router("/api/schtemplate/coversch", &ScheduleApiController{}, "Get:CoverSchTemplate")
- beego.Router("/api/schtemplate/change", &ScheduleApiController{}, "post:DeleteAndAddScheduleTemplateTwo")
-
- beego.Router("/api/schtemplate/save", &ScheduleApiController{}, "post:SaveSchTemplate")
-
- }
- func (c *ScheduleApiController) SaveSchTemplate() {
- templates, _ := service.GetOrgPatientScheduleTemplateIDs(c.GetAdminUserInfo().CurrentOrgId)
- mode, _ := service.GetPatientScheduleTempalate(c.GetAdminUserInfo().CurrentOrgId)
- t := time.Now()
- yearDay := t.YearDay()
- yearFirstDay := t.AddDate(0, 0, -yearDay+1)
- firstDayInWeek := int(yearFirstDay.Weekday())
-
- //今年第一周有几天
- firstWeekDays := 1
- if firstDayInWeek != 0 {
- firstWeekDays = 7 - firstDayInWeek + 1
- }
- var week int
- if yearDay <= firstWeekDays {
- week = 1
- } else {
- week = (yearDay-firstWeekDays)/7 + 2
- }
- var schedules []models.Schedule
- fmt.Println(week)
- if mode.Mode == 1 {
- for _, item := range templates {
- if item.Week > 0 {
- timeArr := WeekIntervalTime(0) //获取本周的周一到周日
- nextTimeArr := WeekIntervalTime(1) //获取下周的周一到周日
- nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
-
- t := time.Now()
-
- week_day, _ := strconv.Atoi(t.Weekday().String())
-
- if week_day == 0 {
- week_day = 7
- }
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- //处理本周,先判断当前属于周几
- for _, item := range items {
- var schedule models.Schedule
- if int(item.Weekday) > week_day {
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- }
- //处理下周
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- //处理下下周,先判断当前属于周几
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- }
- }
- } else if mode.Mode == 2 {
- for _, item := range templates {
- if item.Week > 0 {
- switch item.Week - week {
- case -1: //当前模板是上周的模板
- ////根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
- ////如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
- ////如果是双周模板:则修改下周数据
- ////如果是三周模板:则修改下下周数据
- ////如果是四周模板:则不用修改数据
- //nextTimeArr := WeekIntervalTime(1) //获取下周的周一到周日
- //t := time.Now()
- //week_day,_ := strconv.Atoi(t.Weekday().String())
- //if week_day == 0{
- // week_day = 7
- //}
- //items, _ := service.GetTemplateListByTemplateId(item.ID,item.OrgID)
- //var schedules []models.Schedule
- ////处理下周
- //for _,item := range items{
- // var schedule models.Schedule
- // schedule.IsExport = 400000
- // var DialysisMachineName string
- // so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- // filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- // filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- // filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- // if filedRecordOne.IsShow == 1 {
- // DialysisMachineName = so.DialysisDialyszers
- // }
- // if filedRecordThree.IsShow == 1 {
- // if len(DialysisMachineName) > 0 {
- // DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- // } else {
- // DialysisMachineName = so.DialyzerPerfusionApparatus
- // }
- // }
- // if filedRecordTwo.IsShow == 1 {
- // if len(DialysisMachineName) > 0 {
- // DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- // } else {
- // DialysisMachineName = so.DialysisIrrigation
- // }
- // }
- // schedule.DialysisMachineName = DialysisMachineName
- // schedule.ScheduleType = item.TimeType
- // schedule.ModeId = item.TreatMode
- // schedule.ScheduleWeek = item.Weekday
- // schedule.BedId = item.DeviceNumberID
- // formatTime,_:=time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)])
- // schedule.ScheduleDate =formatTime.Unix()
- // schedule.UserOrgId = item.OrgID
- // schedule.Status = 1
- // schedule.CreatedTime = time.Now().Unix()
- // schedule.UpdatedTime = time.Now().Unix()
- // device,_ := service.GetDeviceByID(item.OrgID,item.DeviceNumberID)
- // schedule.PartitionId = device.DeviceZoneID
- // schedules = append(schedules,schedule)
- //}
-
- break
- case 0:
- //当前修改的模板是本周的模板
- //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
- //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
- //如果是双周模板:则修改下下周数据
- //如果是三周模板:则修改本周除了当天未来的数据
- //如果是四周模板:则修改本周除了当天未来的数据
- //TimeArr :=WeekIntervalTime(0)
- t := time.Now()
- week_day, _ := strconv.Atoi(t.Weekday().String())
- if week_day == 0 {
- week_day = 7
- }
-
- timeArr := WeekIntervalTime(0) //获取本周的周一到周日
- items_two, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- //处理本周,先判断当前属于周几
- for _, item := range items_two {
- var schedule models.Schedule
- if int(item.Weekday) > week_day {
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- }
-
- nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- //处理下下周
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
-
- break
- case 1:
- //当前修改的模板是本周的模板
- //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
- //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
- //如果是双周模板:则修改下下周数据
- //如果是三周模板:则修改本周除了当天未来的数据
- //如果是四周模板:则修改本周除了当天未来的数据
- //TimeArr :=WeekIntervalTime(0)
- nextTimeArr := WeekIntervalTime(1) //获取下下周的周一到周日
- t := time.Now()
- week_day, _ := strconv.Atoi(t.Weekday().String())
- if week_day == 0 {
- week_day = 7
- }
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- //处理下下周
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nextTimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
-
- break
- case 2:
- //当前修改的模板是下下周的模板
- //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
- //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
- //如果是双周模板:则修改本周数据,下下周数据
- //如果是三周模板:则修改下下周的数据
- //如果是四周模板:则修改本周除了当天未来的数据
- //nextTwoTimeArr :=WeekIntervalTime(2)
-
- timeArr := WeekIntervalTime(0) //获取本周的周一到周日
-
- t := time.Now()
-
- week_day, _ := strconv.Atoi(t.Weekday().String())
-
- if week_day == 0 {
- week_day = 7
- }
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- var schedules []models.Schedule
- //处理本周,先判断当前属于周几
- for _, item := range items {
- var schedule models.Schedule
- if int(item.Weekday) > week_day {
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- }
-
- nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
-
- items_two, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- //处理下下周
- for _, item := range items_two {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
-
- break
- }
- }
- }
- } else if mode.Mode == 3 {
- for _, item := range templates {
- if item.Week > 0 {
- switch item.Week - week {
- //case -1:
- // //当前模板是上周的模板
- // //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
- // //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
- // //如果是双周模板:则修改下周数据
- // //如果是三周模板:则修改下下周数据
- // //如果是四周模板:则不用修改数据
- // //TimeArr :=WeekIntervalTime(0)
- // nextnextTimeArr := WeekIntervalTime(2) //获取下下周的周一到周日
- // t := time.Now()
- // week_day,_ := strconv.Atoi(t.Weekday().String())
- // if week_day == 0{
- // week_day = 7
- // }
- // items, _ := service.GetTemplateListByTemplateId(item.ID,item.OrgID)
- // var schedules []models.Schedule
- // //处理下周
- // for _,item := range items{
- // var schedule models.Schedule
- // schedule.IsExport = 400000
- // var DialysisMachineName string
- // so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- // filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- // filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- // filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- // if filedRecordOne.IsShow == 1 {
- // DialysisMachineName = so.DialysisDialyszers
- // }
- // if filedRecordThree.IsShow == 1 {
- // if len(DialysisMachineName) > 0 {
- // DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- // } else {
- // DialysisMachineName = so.DialyzerPerfusionApparatus
- // }
- // }
- // if filedRecordTwo.IsShow == 1 {
- // if len(DialysisMachineName) > 0 {
- // DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- // } else {
- // DialysisMachineName = so.DialysisIrrigation
- // }
- // }
- // schedule.DialysisMachineName = DialysisMachineName
- // schedule.ScheduleType = item.TimeType
- // schedule.ModeId = item.TreatMode
- // schedule.ScheduleWeek = item.Weekday
- // schedule.BedId = item.DeviceNumberID
- // formatTime,_:=time.Parse("2006-01-02", nextnextTimeArr[int(item.Weekday)])
- // schedule.ScheduleDate =formatTime.Unix()
- // schedule.UserOrgId = item.OrgID
- // schedule.Status = 1
- // schedule.CreatedTime = time.Now().Unix()
- // schedule.UpdatedTime = time.Now().Unix()
- // device,_ := service.GetDeviceByID(item.OrgID,item.DeviceNumberID)
- // schedule.PartitionId = device.DeviceZoneID
- // schedules = append(schedules,schedule)
- // }
- //
- // break
- case 0:
- timeArr := WeekIntervalTime(0) //获取本周的周一到周日
-
- t := time.Now()
-
- week_day, _ := strconv.Atoi(t.Weekday().String())
-
- if week_day == 0 {
- week_day = 7
- }
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- var schedules []models.Schedule
- //处理本周,先判断当前属于周几
- for _, item := range items {
- var schedule models.Schedule
- if int(item.Weekday) > week_day {
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- }
-
- break
- case 1:
- nexttimeArr := WeekIntervalTime(1) //获取本周的周一到周日
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- var schedules []models.Schedule
- //处理下周
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nexttimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- break
- case 2:
- //当前修改的模板是下下周的模板
- //根据模板类型,来判断需要修改哪几周数据,模板类型:单周模板,双周模板,三周模板,四周模板
- //如果是单周模板:则修改本周除了当天未来的数据,下周,下下周数据
- //如果是双周模板:则修改本周数据,下下周数据
- //如果是三周模板:则修改下下周的数据
- //如果是四周模板:则修改本周除了当天未来的数据
- //nextTwoTimeArr :=WeekIntervalTime(2)
- nextnexttimeArr := WeekIntervalTime(2) //获取本周的周一到周日
- t := time.Now()
- week_day, _ := strconv.Atoi(t.Weekday().String())
- if week_day == 0 {
- week_day = 7
- }
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- var schedules []models.Schedule
- //处理下下周
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nextnexttimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- break
- }
- }
- }
- } else if mode.Mode == 4 {
- for _, item := range templates {
- if item.Week > 0 {
- switch item.Week - week {
- case 0:
- timeArr := WeekIntervalTime(0) //获取本周的周一到周日
- t := time.Now()
- week_day, _ := strconv.Atoi(t.Weekday().String())
-
- if week_day == 0 {
- week_day = 7
- }
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- var schedules []models.Schedule
- //处理本周,先判断当前属于周几
- for _, item := range items {
- var schedule models.Schedule
- if int(item.Weekday) > week_day {
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", timeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- }
-
- break
- case 1:
- nexttimeArr := WeekIntervalTime(1) //获取本周的周一到周日
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- var schedules []models.Schedule
- //处理下周,先判断当前属于周几
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nexttimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- break
- case 2:
- nextnexttimeArr := WeekIntervalTime(2) //获取本周的周一到周日
- items, _ := service.GetTemplateListByTemplateId(item.ID, item.OrgID)
- var schedules []models.Schedule
- //处理下下周,先判断当前属于周几
- for _, item := range items {
- var schedule models.Schedule
- schedule.IsExport = 400000
- var DialysisMachineName string
- so, _ := service.GetDialysisSolutionTwo(item.OrgID, item.PatientID, item.TreatMode)
- filedRecordOne, _ := service.FindFiledBy(item.OrgID, "透析器")
- filedRecordTwo, _ := service.FindFiledBy(item.OrgID, "灌流器")
- filedRecordThree, _ := service.FindFiledBy(item.OrgID, "透析器/灌流器")
- if filedRecordOne.IsShow == 1 {
- DialysisMachineName = so.DialysisDialyszers
- }
- if filedRecordThree.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialyzerPerfusionApparatus
- } else {
- DialysisMachineName = so.DialyzerPerfusionApparatus
- }
- }
- if filedRecordTwo.IsShow == 1 {
- if len(DialysisMachineName) > 0 {
- DialysisMachineName = DialysisMachineName + "*" + so.DialysisIrrigation
- } else {
- DialysisMachineName = so.DialysisIrrigation
- }
- }
- schedule.DialysisMachineName = DialysisMachineName
- schedule.ScheduleType = item.TimeType
- schedule.ModeId = item.TreatMode
- schedule.ScheduleWeek = item.Weekday
- schedule.BedId = item.DeviceNumberID
- formatTime, _ := time.Parse("2006-01-02", nextnexttimeArr[int(item.Weekday)])
- schedule.ScheduleDate = formatTime.Unix()
- schedule.UserOrgId = item.OrgID
- schedule.Status = 1
- schedule.CreatedTime = time.Now().Unix()
- schedule.UpdatedTime = time.Now().Unix()
- device, _ := service.GetDeviceByID(item.OrgID, item.DeviceNumberID)
- schedule.PartitionId = device.DeviceZoneID
- schedules = append(schedules, schedule)
- }
- break
- }
- }
- }
- }
- //清除今天以后的排班数据病并同步数据
- err := service.ClearAndCreateSyncSch(c.GetAdminUserInfo().CurrentOrgId, time.Now().Unix(), schedules)
- if err == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "msg": "同步成功",
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSyncWrong)
- return
- }
- }
-
- func (c *ScheduleApiController) CoverSchTemplate() {
- templateID, _ := c.GetInt64("template_id")
- week_type_one, _ := c.GetInt64("week_type_one")
- time_type_one, _ := c.GetInt64("time_type_one")
- device_id_one, _ := c.GetInt64("device_id_one")
- patient_id_one, _ := c.GetInt64("patient_id_one")
-
- week_type_two, _ := c.GetInt64("week_type_two")
- time_type_two, _ := c.GetInt64("time_type_two")
- device_id_two, _ := c.GetInt64("device_id_two")
- patient_id_two, _ := c.GetInt64("patient_id_two")
-
- sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one)
- sch_two, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_two, templateID, week_type_two, time_type_two, patient_id_two)
- if sch.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
- if sch_two.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
- //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
- if sch.Weekday != sch_two.Weekday && sch.PatientID != sch_two.PatientID {
- count, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.Weekday, sch.PatientID, sch.TemplateID)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
- }
-
- var new_sch models.PatientScheduleTemplateItem
- new_sch = sch
- new_sch.DeviceNumberID = sch_two.DeviceNumberID
- new_sch.Weekday = sch_two.Weekday
- new_sch.TimeType = sch_two.TimeType
- new_sch.ID = 0
- //删除原来的排班并生成新的排班
- err := service.SaveSchTemplateTwo(sch, sch_two, new_sch)
- if err == nil {
- templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId)
- if getTemplateItemsErr != nil {
- c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "items": templates,
- "msg": "覆盖成功",
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
- func (c *ScheduleApiController) ExchangeSchTemplate() {
- templateID, _ := c.GetInt64("template_id")
- week_type_one, _ := c.GetInt64("week_type_one")
- time_type_one, _ := c.GetInt64("time_type_one")
- device_id_one, _ := c.GetInt64("device_id_one")
- patient_id_one, _ := c.GetInt64("patient_id_one")
-
- week_type_two, _ := c.GetInt64("week_type_two")
- time_type_two, _ := c.GetInt64("time_type_two")
- device_id_two, _ := c.GetInt64("device_id_two")
- patient_id_two, _ := c.GetInt64("patient_id_two")
- sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one)
- sch_two, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_two, templateID, week_type_two, time_type_two, patient_id_two)
- if sch.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
- if sch_two.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
-
- //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
- if sch.Weekday != sch_two.Weekday && sch.PatientID != sch_two.PatientID {
- count, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.Weekday, sch.PatientID, sch.TemplateID)
- if count > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
- count1, _ := service.GetScheduleTemplateCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch.Weekday, sch_two.PatientID, sch_two.TemplateID)
- if count1 > 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
- return
- }
- }
-
- err := service.UpdateScheduleTemplateThree(sch, sch_two)
- if err == nil {
- templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId)
- if getTemplateItemsErr != nil {
- c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "items": templates,
- "msg": "交换成功",
- })
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
- func (c *ScheduleApiController) DeleteAndAddScheduleTemplateTwo() {
-
- templateID, _ := c.GetInt64("template_id")
- week_type_one, _ := c.GetInt64("week_type_one")
- time_type_one, _ := c.GetInt64("time_type_one")
- device_id_one, _ := c.GetInt64("device_id_one")
- patient_id_one, _ := c.GetInt64("patient_id_one")
- week_type_two, _ := c.GetInt8("week_type_two")
- time_type_two, _ := c.GetInt8("time_type_two")
- device_id_two, _ := c.GetInt64("device_id_two")
- patient_id_two, _ := c.GetInt64("patient_id_two")
- mode_id, _ := c.GetInt64("mode_id")
-
- sch, _ := service.GetScheduleTemplateForDeviceNumberTwo(c.GetAdminUserInfo().CurrentOrgId, device_id_one, templateID, week_type_one, time_type_one, patient_id_one)
- if sch.ID == 0 {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- return
- }
- // 先删除后新增
- sch.Status = 0
- //service.SaveSchTemplate(sch)
- item := models.PatientScheduleTemplateItem{
- DeviceNumberID: device_id_two,
- PatientID: patient_id_two,
- TreatMode: mode_id,
- Weekday: week_type_two,
- TimeType: time_type_two,
- Status: 1,
- OrgID: c.GetAdminUserInfo().CurrentOrgId,
- TemplateID: templateID,
- CreateTime: time.Now().Unix(),
- ModifyTime: 0,
- IsExport: 40000,
- }
- err := service.SaveSchTemplate(sch, item)
-
- if err == nil {
-
- templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(c.GetAdminUserInfo().CurrentOrgId)
- if getTemplateItemsErr != nil {
- c.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "items": templates,
- })
-
- } else {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- }
-
- func (c *ScheduleApiController) GetTemplateDevicesNumbers() {
- sch_type, _ := c.GetInt("sch_type", 0)
- zone_id, _ := c.GetInt64("zone_id", 0)
- patient_id, _ := c.GetInt64("patient_id", 0)
- template_id, _ := c.GetInt64("template_id", 0)
-
- weekday, _ := c.GetInt64("weekday")
-
- deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildTemplateDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, weekday, sch_type, zone_id, patient_id, template_id)
- if getDeviceNumbersErr != nil {
- c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "devices": deviceNumbers,
- })
-
- }
-
- // type TestCtr struct {
- // BaseAPIController
- // }
-
- // func (this *TestCtr) Test() {
- // now := time.Now().AddDate(0, 0, 7)
-
- // weekday := int(now.Weekday())
- // if weekday == 0 {
- // weekday = 7
- // }
-
- // monday := now.AddDate(0, 0, 1-weekday)
- // sunday := now.AddDate(0, 0, 7-weekday)
-
- // // this.TraceLog("%v", weekday)
- // this.ServeSuccessJSON(map[string]interface{}{
- // "weekday": weekday,
- // "monday": monday.Format("2006-01-02"),
- // "sunday": sunday.Format("2006-01-02"),
- // })
- // }
-
- // ------- 患者排班模板 --------
- type PatientScheduleTemplateAPIController struct {
- BaseAuthAPIController
- }
-
- // /api/schtemp/p/initdata [get]
- func (this *PatientScheduleTemplateAPIController) InitData() {
- adminUserInfo := this.GetAdminUserInfo()
-
- patitionIdStr := this.GetString("patitionid")
- var ids []string
- if len(patitionIdStr) > 0 {
- ids = strings.Split(patitionIdStr, ",")
- }
-
- mode, getModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
- if getModeErr != nil {
- this.ErrorLog("获取排班模板启用模式失败:%v", getModeErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- now := time.Now()
- if mode == nil {
- mode = &models.PatientScheduleTemplateMode{
- OrgID: adminUserInfo.CurrentOrgId,
- Mode: 0,
- ExecuteTimes: 0,
- Status: 1,
- CreateTime: now.Unix(),
- ModifyTime: now.Unix(),
- }
- createModeErr := service.SavePatientScheduleTemplateMode(mode)
- if createModeErr != nil {
- this.ErrorLog("创建排班模板启用模式失败:%v", createModeErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- deviceNumbers, getDeviceNumbersErr := service.GetScheduleValidDeviceNumbers(adminUserInfo.CurrentOrgId, ids)
-
- fmt.Println("deviceNumbers233323232332232323223233223323232323", deviceNumbers)
- if getDeviceNumbersErr != nil {
- this.ErrorLog("获取床位号失败:%v", getDeviceNumbersErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- templates, getTemplatesErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
- if getTemplatesErr != nil {
- this.ErrorLog("获取排班模板及其排班列表失败:%v", getTemplatesErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if len(templates) == 0 {
- firstTemp, secondTemp, thirdTemp, fourTemp, createTempErr := service.CreateTwoPatientScheduleTemplates(adminUserInfo.CurrentOrgId)
- if createTempErr != nil {
- this.ErrorLog("创建4个排班模板失败:%v", createTempErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- templates = append(templates, firstTemp, secondTemp, thirdTemp, fourTemp)
-
- } else if len(templates) == 1 {
- temp, thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplate(adminUserInfo.CurrentOrgId)
- if createTempErr != nil {
- this.ErrorLog("创建3个排班模板失败:%v", createTempErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- templates = append(templates, temp, thirdTemp, fourTemp)
- } else if len(templates) == 2 {
- thirdTemp, fourTemp, createTempErr := service.CreatePatientScheduleTemplateTwo(adminUserInfo.CurrentOrgId)
- if createTempErr != nil {
- this.ErrorLog("创建2个排班模板失败:%v", createTempErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- templates = append(templates, thirdTemp, fourTemp)
- } else if len(templates) == 3 {
- temp, createTempErr := service.CreatePatientScheduleTemplateThree(adminUserInfo.CurrentOrgId)
- if createTempErr != nil {
- this.ErrorLog("创建1个排班模板失败:%v", createTempErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- templates = append(templates, temp)
- }
-
- patients, getPatientsErr := service.PatientScheduleTemplateGetAllValidPatient(adminUserInfo.CurrentOrgId)
- if getPatientsErr != nil {
- this.ErrorLog("获取患者列表失败失败:%v", getPatientsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- // 获取本周的排班
- //monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
- //schedules, getScheduleErr := service.GetWeekSchedule(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
- //if getScheduleErr != nil {
- // this.ErrorLog("获取本周排班失败:%v", getScheduleErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- //}
-
- this.ServeSuccessJSON(map[string]interface{}{
- "template_mode": mode,
- "device_numbers": deviceNumbers,
- "templates": templates,
- "patients": patients,
- //"schedules": schedules,
- })
- }
-
- // /api/schtemp/p/setmode [post]
- // @param mode:int 0.不启用模板 1.单周模板 2.双周模板 3.三周模版 4.四周模版
- func (this *PatientScheduleTemplateAPIController) SetMode() {
- mode, _ := this.GetInt8("mode")
- week_time, _ := this.GetInt8("week_time")
-
- if mode != 1 && mode != 2 && mode != 0 && mode != 3 && mode != 4 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- if mode > 0 {
- if week_time == 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- }
-
- adminUserInfo := this.GetAdminUserInfo()
-
- templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
- if getTemplateModeErr != nil {
- this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if templateMode == nil {
- this.ErrorLog("获取不到排班模板启用模式")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- templateMode.Week = int64(week_time)
- templateMode.OriginalWeek = int64(week_time)
-
- if mode != templateMode.Mode {
- if templateMode.Mode == 0 { // 0 -> 1 或 0 -> 2 则直接清除下四周的排班
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(0 -> 1 或 0 -> 2)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if mode == 0 { // 1 -> 0 或 2 -> 0 则不处理排班,但清除所有模板item
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateModeAndClearAllTemplateItems(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 0 或 2 -> 0)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if templateMode.Mode == 1 && mode == 2 { // 1 -> 2 清除第二周排班
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateModeAndClearNextTwoWeekSchedules(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if templateMode.Mode == 1 && mode == 3 {
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SaveTemplateMode(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if templateMode.Mode == 1 && mode == 4 {
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SaveTemplateMode(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if templateMode.Mode == 2 && mode == 1 { // 2 -> 1 清除第二周模板item,清除第二周排班
- templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- if getTemplateIDsErr != nil {
- this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- firstWeekItems, getFirstWeekItemsErr := service.GetOrgPatientScheduleTemplateItemsWithoutPatientByTemplateID(adminUserInfo.CurrentOrgId, templateIDs[0].ID)
- if getFirstWeekItemsErr != nil {
- this.ErrorLog("获取排班模板排班失败:%v", getFirstWeekItemsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateMode2To1(templateMode, templateIDs[1].ID, firstWeekItems)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 2)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- } else if templateMode.Mode == 2 && mode == 3 { //
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SaveTemplateMode(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- } else if templateMode.Mode == 2 && mode == 4 { //
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SaveTemplateMode(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- } else if templateMode.Mode == 3 && mode == 1 { // 3 -> 1 清除第三,二周模板item,清除第三,二周排班
- templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- if getTemplateIDsErr != nil {
- this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateMode3To1(templateMode, templateIDs[1].ID, templateIDs[2].ID)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 3)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- } else if templateMode.Mode == 3 && mode == 2 { // 3 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
- templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- if getTemplateIDsErr != nil {
- this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateMode3To2(templateMode, templateIDs[2].ID)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(2 -> 3)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if templateMode.Mode == 3 && mode == 4 { // 2 -> 1 清除第二周模板item,清除第二周排班
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SaveTemplateMode(templateMode)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- } else if templateMode.Mode == 4 && mode == 1 { // 4 -> 1 清除第三周模板item,清除第三周排班,将第一周的排班重复到第二周
- templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- if getTemplateIDsErr != nil {
- this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateMode4To1(templateMode, templateIDs[1].ID, templateIDs[2].ID, templateIDs[3].ID)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(1 -> 4)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if templateMode.Mode == 4 && mode == 2 { // 4 -> 2
- templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- if getTemplateIDsErr != nil {
- this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateMode4To2(templateMode, templateIDs[2].ID, templateIDs[3].ID)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(2 -> 4)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- } else if templateMode.Mode == 4 && mode == 3 { // 4 -> 3
- templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- if getTemplateIDsErr != nil {
- this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- templateMode.Mode = mode
- templateMode.ExecuteTimes = 0
- templateMode.ModifyTime = time.Now().Unix()
- updateErr := service.SavePatientScheduleTemplateMode4To3(templateMode, templateIDs[3].ID)
- if updateErr != nil {
- this.ErrorLog("更新排班模板启用方式(3 -> 4)时失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
- templates, _ := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- //处理第几周数问题
- if mode == 0 {
- service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, 0)
- service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
- service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
- service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
-
- } else if mode == 1 {
- service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
- service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, 0)
- service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
- service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
-
- } else if mode == 2 {
- service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
- service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
- service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, 0)
- service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
-
- } else if mode == 3 {
- service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
- service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
- service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
- service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, 0)
-
- } else if mode == 4 {
- service.UpdateTemplateItemWeek(templates[0].OrgID, templates[0].ID, week_time)
- service.UpdateTemplateItemWeek(templates[1].OrgID, templates[1].ID, week_time+1)
- service.UpdateTemplateItemWeek(templates[2].OrgID, templates[2].ID, week_time+2)
- service.UpdateTemplateItemWeek(templates[3].OrgID, templates[3].ID, week_time+3)
- }
-
- } else {
- fmt.Println("~~~~~~~~")
- service.UpdateTemplateItemModeWeek(adminUserInfo.CurrentOrgId, templateMode.ID, templateMode.OriginalWeek)
-
- }
-
- this.ServeSuccessJSON(nil)
- }
-
- // /api/schtemp/p/update_sch [post]
- // @param template_id:int
- // @param add_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ])
- // @param del_schs:array'json ([ {device_number_id, weekday, time_type} ])
- // @param change_schs:array'json ([ {device_number_id, patient_id, mode(treat_mode), weekday, time_type} ])
- func (this *PatientScheduleTemplateAPIController) UpdateSchedules() {
- templateID, _ := this.GetInt64("template_id")
- addSchedulesJSON := this.GetString("add_schs")
- delSchedulesJSON := this.GetString("del_schs")
- changeSchedulesJSON := this.GetString("change_schs")
-
- var addSchedules []*ParamModelSchedule
- var delSchedules []*ParamModelSchedule
- var changeSchedules []*ParamModelSchedule
- parseErr := json.Unmarshal([]byte(addSchedulesJSON), &addSchedules)
- if parseErr != nil {
- this.ErrorLog("解析增加排班的数组参数失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- parseErr = json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
- if parseErr != nil {
- this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- parseErr = json.Unmarshal([]byte(changeSchedulesJSON), &changeSchedules)
- if parseErr != nil {
- this.ErrorLog("解析修改排班的数组参数失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetAdminUserInfo()
- templateIDs, getTemplateIDsErr := service.GetOrgPatientScheduleTemplateIDs(adminUserInfo.CurrentOrgId)
- if getTemplateIDsErr != nil {
- this.ErrorLog("获取排班模板失败:%v", getTemplateIDsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- isTemplateIDExist := false
- for _, templateIDObject := range templateIDs {
- if templateIDObject.ID == templateID {
- isTemplateIDExist = true
- break
- }
- }
- if isTemplateIDExist == false {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleTemplateNotExist)
- return
- }
- }
-
- addTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(addSchedules))
- delTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(delSchedules))
- changeTemplateItems := make([]*models.PatientScheduleTemplateItem, 0, len(changeSchedules))
- for _, sch := range addSchedules {
- if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- addTemplateItems = append(addTemplateItems, &models.PatientScheduleTemplateItem{
- DeviceNumberID: sch.DeviceNumberID,
- PatientID: sch.PatientID,
- TreatMode: sch.Mode,
- Weekday: sch.Weekday,
- TimeType: sch.TimeType,
- })
- }
- for _, sch := range delSchedules {
- if sch.DeviceNumberID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- delTemplateItems = append(delTemplateItems, &models.PatientScheduleTemplateItem{
- DeviceNumberID: sch.DeviceNumberID,
- Weekday: sch.Weekday,
- TimeType: sch.TimeType,
- })
- }
- for _, sch := range changeSchedules {
- if sch.DeviceNumberID <= 0 || sch.PatientID <= 0 || sch.Weekday < 1 || sch.Weekday > 7 || sch.TimeType < 1 || sch.TimeType > 3 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- changeTemplateItems = append(changeTemplateItems, &models.PatientScheduleTemplateItem{
- DeviceNumberID: sch.DeviceNumberID,
- PatientID: sch.PatientID,
- TreatMode: sch.Mode,
- Weekday: sch.Weekday,
- TimeType: sch.TimeType,
- })
- }
-
- templateMode, getTemplateModeErr := service.GetOrgPatientScheduleTemplateMode(adminUserInfo.CurrentOrgId)
- if getTemplateModeErr != nil {
- this.ErrorLog("获取排班模板启用模式失败:%v", getTemplateModeErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if templateMode == nil {
- this.ErrorLog("获取不到排班模板启用模式")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- //shouldUpdateNextWeekSchedules := false
- //shouldUpdateNextSecondWeekSchedules := false
- //shouldUpdateNextThirdWeekSchedules := false
- //shouldUpdateNextFourWeekSchedules := false
- //
- if templateMode.Mode == 0 {
- this.ErrorLog("当前未开启排班模板,所以更新模板的操作将被无视")
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //判断当前用的是模版几
- //templateIDIndex := 1
- //for index, templateIDObject := range templateIDs {
- // if templateIDObject.ID == templateID {
- // //templateIDIndex = index + 1
- // }
- //}
- //if templateMode.Mode == 1 {
- // if templateIDIndex == 1 {
- // shouldUpdateNextWeekSchedules = true
- // shouldUpdateNextSecondWeekSchedules = true
- // } else {
- // this.ErrorLog("当前开启的是单周模板,所以不会更新第二个模板")
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- //} else if templateMode.Mode == 2 { // mode == 2 => 开启双周模板时,只需更新一周排班
- // if templateIDIndex == 1 {
- // if templateMode.ExecuteTimes%2 == 0 {
- // shouldUpdateNextWeekSchedules = true
- // shouldUpdateNextSecondWeekSchedules = false
- // } else {
- // shouldUpdateNextWeekSchedules = false
- // shouldUpdateNextSecondWeekSchedules = true
- // }
- //
- // } else {
- // if templateMode.ExecuteTimes%2 == 0 {
- // shouldUpdateNextWeekSchedules = false
- // shouldUpdateNextSecondWeekSchedules = true
- // } else {
- // shouldUpdateNextWeekSchedules = true
- // shouldUpdateNextSecondWeekSchedules = false
- // }
- //
- // }
- //} else if templateMode.Mode == 3 { // mode == 2 => 开启双周模板时,只需更新一周排班
- // if templateIDIndex == 1 { //当前修改的是第一个模版
- // if templateMode.ExecuteTimes%3 == 0 {
- // shouldUpdateNextWeekSchedules = true
- // shouldUpdateNextSecondWeekSchedules = false
- // shouldUpdateNextThirdWeekSchedules = false
- // } else if templateMode.ExecuteTimes%3 == 1 {
- // shouldUpdateNextWeekSchedules = false
- // shouldUpdateNextSecondWeekSchedules = true
- // shouldUpdateNextThirdWeekSchedules = false
- // } else {
- // shouldUpdateNextWeekSchedules = false
- // shouldUpdateNextSecondWeekSchedules = false
- // shouldUpdateNextThirdWeekSchedules = true
- // }
- // } else if templateIDIndex == 2 {
- // if templateMode.ExecuteTimes%2 == 0 {
- // shouldUpdateNextWeekSchedules = false
- // shouldUpdateNextSecondWeekSchedules = true
- // } else {
- // shouldUpdateNextWeekSchedules = true
- // shouldUpdateNextSecondWeekSchedules = false
- // }
- //
- // } else {
- //
- // }
- //}
-
- updateErr := service.UpdateScheduleTemplate(adminUserInfo.CurrentOrgId, templateID, addTemplateItems, delTemplateItems, changeTemplateItems, false, false)
- if updateErr != nil {
- this.ErrorLog("更新排班模板排班失败:%v", updateErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- return
- }
-
- templates, getTemplateItemsErr := service.GetOrgPatientScheduleTemplateItems(adminUserInfo.CurrentOrgId)
-
- if getTemplateItemsErr != nil {
- this.ErrorLog("获取排班模板排班失败:%v", getTemplateItemsErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "items": templates,
- })
- }
- func WeekIntervalTime(week int) []string {
- now := time.Now()
- offset := int(time.Monday - now.Weekday())
- //周日做特殊判断 因为time.Monday = 0
- if offset > 0 {
- offset = -6
- }
- var timeArr []string
- year, month, day := now.Date()
- thisWeek := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- startTime := thisWeek.AddDate(0, 0, offset+7*week).Format("2006-01-02") + " 00:00:00"
- twoTime := thisWeek.AddDate(0, 0, offset+1+7*week).Format("2006-01-02") + " 00:00:00"
- threeTime := thisWeek.AddDate(0, 0, offset+2+7*week).Format("2006-01-02") + " 00:00:00"
- fourTime := thisWeek.AddDate(0, 0, offset+3+7*week).Format("2006-01-02") + " 00:00:00"
- fiveTime := thisWeek.AddDate(0, 0, offset+4+7*week).Format("2006-01-02") + " 00:00:00"
- SixTime := thisWeek.AddDate(0, 0, offset+5+7*week).Format("2006-01-02") + " 00:00:00"
- endTime := thisWeek.AddDate(0, 0, offset+6+7*week).Format("2006-01-02") + " 00:00:00"
- timeArr = append(timeArr, startTime)
- timeArr = append(timeArr, twoTime)
- timeArr = append(timeArr, threeTime)
- timeArr = append(timeArr, fourTime)
- timeArr = append(timeArr, fiveTime)
- timeArr = append(timeArr, SixTime)
- timeArr = append(timeArr, endTime)
- return timeArr
- }
-
- type ParamModelSchedule struct {
- DeviceNumberID int64 `json:"device_number_id"`
- PatientID int64 `json:"patient_id"`
- Mode int64 `json:"mode"`
- Weekday int8 `json:"weekday"`
- TimeType int8 `json:"time_type"`
- }
-
- func (this *PatientScheduleTemplateAPIController) GetPatientList() {
- patients, err := service.GetSchTemplatePatientList(this.GetAdminUserInfo().CurrentOrgId)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "list": patients,
- })
-
- }
-
- type ParamModelEditSchedule struct {
- ID int64 `json:"sch_id"`
- DeviceNumberID int64 `json:"jihao_id"`
- PatientID int64 `json:"patient_id"`
- Mode int64 `json:"mode_id"`
- Weekday int64 `json:"schedule_week"`
- TimeType int64 `json:"time_type"`
- TemplateID int64 `json:"t_id"`
- Title string `json:"title"`
- }
-
- func (this *PatientScheduleTemplateAPIController) UpdateSchedulesTemplate() {
- addOrEditSchedulesJSON := this.GetString("edit_schs")
- delSchedulesJSON := this.GetString("del_schs")
-
- fmt.Println(addOrEditSchedulesJSON)
- var addOrEditSchedules []*ParamModelEditSchedule
- var delSchedules []*ParamModelEditSchedule
-
- parseErr := json.Unmarshal([]byte(addOrEditSchedulesJSON), &addOrEditSchedules)
- json.Unmarshal([]byte(delSchedulesJSON), &delSchedules)
-
- fmt.Println(parseErr)
- if parseErr != nil {
- this.ErrorLog("解析增加编辑排班的数组参数失败:%v", parseErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- //if parseDelErr != nil {
- // this.ErrorLog("解析删除排班的数组参数失败:%v", parseErr)
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- //}
- for _, item := range delSchedules {
- src_template, _ := service.GetScheduleTemplateItem(item.ID)
- src_template.Status = 0
- service.SaveSchTemplateItem(src_template)
- }
- for _, item := range addOrEditSchedules {
- if item.ID > 0 { //已经存在的数据
- src_template, _ := service.GetScheduleTemplateItem(item.ID)
- src_template.DeviceNumberID = item.DeviceNumberID
- src_template.TimeType = int8(item.TimeType)
- src_template.TreatMode = item.Mode
- schItem, _ := service.GetScheduleTemplateThree(this.GetAdminUserInfo().CurrentOrgId, src_template.DeviceNumberID, src_template.TemplateID, int64(src_template.Weekday), int64(src_template.TimeType), src_template.PatientID)
- if schItem.ID > 0 {
- json := make(map[string]interface{})
- json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班无法保存,可能存在重复排班"
- json["state"] = 0
- this.Data["json"] = json
- this.ServeJSON()
- break
- }
- service.SaveSchTemplateItem(src_template)
- } else {
- schItemTwo, _ := service.GetScheduleTemplateTwo(this.GetAdminUserInfo().CurrentOrgId, item.TemplateID, item.Weekday, item.PatientID)
- fmt.Println("222222")
- if schItemTwo.ID > 0 { //当天存在排班,存在则为修改
- fmt.Println("333333333")
- src_template, _ := service.GetScheduleTemplateItem(schItemTwo.ID)
- src_template.DeviceNumberID = item.DeviceNumberID
- src_template.TimeType = int8(item.TimeType)
- src_template.TreatMode = item.Mode
- service.SaveSchTemplateItem(src_template)
-
- } else {
- schItem, _ := service.GetScheduleTemplateOne(this.GetAdminUserInfo().CurrentOrgId, item.DeviceNumberID, item.TemplateID, item.Weekday, item.TimeType)
- if schItem.ID == 0 { //床位未被占用
- var template models.PatientScheduleTemplateItem
- template.TreatMode = item.Mode
- template.TemplateID = int64(item.TemplateID)
- template.TimeType = int8(item.TimeType)
- template.DeviceNumberID = item.DeviceNumberID
- template.CreateTime = time.Now().Unix()
- template.ModifyTime = time.Now().Unix()
- template.OrgID = this.GetAdminUserInfo().CurrentOrgId
- template.PatientID = item.PatientID
- template.Weekday = int8(item.Weekday)
- template.Status = 1
- service.SaveSchTemplateItem(template)
- } else { //床位被占用 1.被自己占用,2。被别人占用
- if schItem.PatientID != 0 && schItem.PatientID == item.PatientID { //当天该患者已经存在排班则设为修改操作
- src_template, _ := service.GetScheduleTemplateItem(schItem.ID)
- src_template.DeviceNumberID = item.DeviceNumberID
- src_template.TimeType = int8(item.TimeType)
- src_template.TreatMode = item.Mode
- service.SaveSchTemplateItem(src_template)
-
- } else if schItem.PatientID != 0 && schItem.PatientID != item.PatientID { //当天该床位被其他人占用,则无法保存
- //fmt.Println("7777777")
- json := make(map[string]interface{})
- json["msg"] = item.Title + "周" + strconv.FormatInt(item.Weekday, 10) + "的床位已经有人排班,无法保存"
- json["state"] = 0
- this.Data["json"] = json
- this.ServeJSON()
- break
- }
- }
-
- }
-
- }
- }
-
- templates, _ := service.GetOrgPatientScheduleTemplateItems(this.GetAdminUserInfo().CurrentOrgId)
- this.ServeSuccessJSON(map[string]interface{}{
- "items": templates,
- })
- }
-
- //func (c *ScheduleApiController) DeleteScheduleTemplateTwo() {
- // id, _ := c.GetInt64("id", 0)
- // if id <= 0 {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- // return
- // }
- //
- // adminINfo := c.GetAdminUserInfo()
- //
- // schedule, _ := service.GetSc(adminINfo.CurrentOrgId, id)
- // timeNow := time.Now().Format("2006-01-02")
- // timeTemplate := "2006-01-02"
- //
- // tm := time.Unix(int64(schedule.ScheduleDate), 0)
- // timeStr := tm.Format(timeTemplate)
- // if timeNow > timeStr {
- //
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
- // return
- // }
- // if schedule == nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
- // return
- // }
- //
- // order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
- // if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- // return
- // }
- //
- // if order != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo)
- // return
- // }
- //
- // schedule.Status = 0
- // schedule.UpdatedTime = time.Now().Unix()
- // err = service.UpdateSchedule(schedule)
- // redis := service.RedisClient()
- //
- // //处方
- // keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
- // redis.Set(keyOne, "", time.Second)
- //
- // //医嘱
- // keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
- // redis.Set(keyTwo, "", time.Second)
- //
- // keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
- // redis.Set(keySix, "", time.Second)
- // keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
- // redis.Set(keyThree, "", time.Second)
- //
- // keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
- // redis.Set(keyFour, "", time.Second)
- //
- // keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
- // redis.Set(keyFive, "", time.Second)
- //
- // keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
- // redis.Set(keySeven, "", time.Second)
- // fmt.Println(err)
- // defer redis.Close()
- // if err != nil {
- // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
- // return
- // }
- //
- // c.ServeSuccessJSON(map[string]interface{}{
- // "msg": "ok",
- // "schedule": &schedule,
- // })
- //}
|