schedule_api_controller.go 139KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/jinzhu/gorm"
  10. "reflect"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "github.com/astaxie/beego"
  15. )
  16. type ScheduleApiController struct {
  17. BaseAuthAPIController
  18. }
  19. func ScheduleApiRegistRouters() {
  20. beego.Router("/api/schedule/weekpanel", &ScheduleApiController{}, "Get:GetWeekPanels")
  21. beego.Router("/api/schedule/schedules", &ScheduleApiController{}, "Get:GetSchedules")
  22. beego.Router("/api/excel_date/init", &ScheduleApiController{}, "Get:GetInitExcelInitDate")
  23. beego.Router("/api/schedule/patients", &ScheduleApiController{}, "Get:GetPatients")
  24. beego.Router("/api/schedule/create", &ScheduleApiController{}, "Post:CreateSchedule")
  25. beego.Router("/api/schedule/delete", &ScheduleApiController{}, "Delete:DeleteSchedule")
  26. beego.Router("/api/schedule/change", &ScheduleApiController{}, "Put:ChangeSchedule")
  27. beego.Router("/api/schedule/urgentinit", &ScheduleApiController{}, "Get:UrgentScheduleData")
  28. beego.Router("/api/schedule/print/initdata", &ScheduleApiController{}, "get:PrintInitData")
  29. beego.Router("/api/schedule/search", &ScheduleApiController{}, "get:SearchSchedulePatients")
  30. beego.Router("/api/schedule/week", &ScheduleApiController{}, "get:GetWeekDaySchedule")
  31. beego.Router("/api/schedule/export", &ScheduleApiController{}, "post:ExportSchedule")
  32. beego.Router("/api/schedule_template/export", &ScheduleApiController{}, "post:ExportScheduleTemplate")
  33. beego.Router("/api/schedule_template/search", &ScheduleApiController{}, "get:SearchTemplateSchedulePatients")
  34. beego.Router("/api/schedule_template/cancel", &ScheduleApiController{}, "post:CancelScheduleTemplate")
  35. beego.Router("/api/schedule/getnextscheduleweekday", &ScheduleApiController{}, "Get:GetNextWeekDaySchedule")
  36. beego.Router("/api/schedule/getnextscheduleweekdayone", &ScheduleApiController{}, "Get:GetNextWeekDayScheduleOne")
  37. beego.Router("/api/schedule/getthreeweeklist", &ScheduleApiController{}, "Get:GetThreeWeekList")
  38. beego.Router("/api/schedule/getallzones", &ScheduleApiController{}, "Get:GetAllZones")
  39. beego.Router("/api/schedule/copypatientschedules", &ScheduleApiController{}, "Get:GetCopyPatientSchedules")
  40. beego.Router("/api/schedule/saveremindprint", &ScheduleApiController{}, "Get:SaveRemindPrint")
  41. beego.Router("/api/schedule/getremindprintlist", &ScheduleApiController{}, "Get:GetRemindPrintList")
  42. beego.Router("/api/schedule/getbloodschedulelist", &ScheduleApiController{}, "Get:GetBloodScheduleList")
  43. beego.Router("/api/schedule/getprintlist", &ScheduleApiController{}, "Get:GetPrintList")
  44. beego.Router("/api/schedule/getallzonelist", &ScheduleApiController{}, "Get:GetAllZoneList")
  45. beego.Router("/api/schedule/getpatientschedulecount", &ScheduleApiController{}, "Get:GetPatientScheduleCount")
  46. beego.Router("/api/schedule/weekpanelone", &ScheduleApiController{}, "Get:GetWeekPanelsOne")
  47. beego.Router("/api/schedule/schedulesone", &ScheduleApiController{}, "Get:GetScheduleOne")
  48. beego.Router("/api/schedule/scheduletwo", &ScheduleApiController{}, "Get:GetScheduleTwo")
  49. beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
  50. beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
  51. beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
  52. beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
  53. beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
  54. beego.Router("/api/schedule/synchroschedule", &ScheduleApiController{}, "Get:SynchroSchedule")
  55. beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
  56. beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
  57. beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatient")
  58. beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
  59. beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
  60. beego.Router("/api/patient/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSmartSchTemplate")
  61. beego.Router("/api/device/get", &ScheduleApiController{}, "Get:GetDevicesNumbers")
  62. beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
  63. beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
  64. }
  65. func (c *ScheduleApiController) BatchPostSmartSch() {
  66. patient_id, _ := c.GetInt64("patient_id")
  67. adminInfo := c.GetAdminUserInfo()
  68. patientInfo, _ := service.FindPatientById(adminInfo.CurrentOrgId, patient_id)
  69. if patientInfo.ID == 0 {
  70. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  71. return
  72. }
  73. dataBody := make(map[string]interface{}, 0)
  74. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  75. if err != nil {
  76. utils.ErrorLog(err.Error())
  77. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  78. return
  79. }
  80. //数据校验
  81. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  82. schs, _ := dataBody["smart_schs"].([]interface{})
  83. if len(schs) > 0 {
  84. for _, item := range schs {
  85. items := item.(map[string]interface{})
  86. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  87. utils.ErrorLog("id")
  88. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  89. return
  90. }
  91. var schedule models.Schedule
  92. //var oldSchedule *models.Schedule
  93. sch_id := int64(items["sch_id"].(float64))
  94. if sch_id > 0 { //修改排班信息
  95. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  96. fmt.Println("2222222")
  97. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  98. utils.ErrorLog("mode_id")
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. modeId := int64(items["mode_id"].(float64))
  103. if modeId < 1 {
  104. utils.ErrorLog("modeId < 1")
  105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  106. return
  107. }
  108. schedule.ModeId = modeId
  109. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  110. if err != nil {
  111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  112. return
  113. }
  114. if order != nil {
  115. week_type, _ := items["week_type"].(string)
  116. week_name, _ := items["week_name"].(string)
  117. switch week_type {
  118. case "1":
  119. json := make(map[string]interface{})
  120. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  121. json["state"] = 0
  122. c.Data["json"] = json
  123. c.ServeJSON()
  124. break
  125. case "2":
  126. json := make(map[string]interface{})
  127. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  128. json["state"] = 0
  129. c.Data["json"] = json
  130. c.ServeJSON()
  131. break
  132. case "3":
  133. json := make(map[string]interface{})
  134. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  135. json["state"] = 0
  136. c.Data["json"] = json
  137. c.ServeJSON()
  138. break
  139. }
  140. return
  141. }
  142. if order != nil {
  143. week_type, _ := items["week_type"].(string)
  144. week_name, _ := items["week_name"].(string)
  145. switch week_type {
  146. case "1":
  147. json := make(map[string]interface{})
  148. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  149. json["state"] = 0
  150. c.Data["json"] = json
  151. c.ServeJSON()
  152. break
  153. case "2":
  154. json := make(map[string]interface{})
  155. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  156. json["state"] = 0
  157. c.Data["json"] = json
  158. c.ServeJSON()
  159. break
  160. case "3":
  161. json := make(map[string]interface{})
  162. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  163. json["state"] = 0
  164. c.Data["json"] = json
  165. c.ServeJSON()
  166. break
  167. }
  168. return
  169. }
  170. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  171. utils.ErrorLog("schedule_type")
  172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  173. return
  174. }
  175. scheduleType := int64(items["schedule_type"].(float64))
  176. if scheduleType < 1 || scheduleType > 3 {
  177. utils.ErrorLog("scheduleType < 3")
  178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  179. return
  180. }
  181. schedule.ScheduleType = scheduleType
  182. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  183. utils.ErrorLog("bed_id")
  184. fmt.Println("~~~~~~333333333")
  185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  186. return
  187. }
  188. bedId := int64(items["bed_id"].(float64))
  189. if bedId < 1 {
  190. utils.ErrorLog("bedId < 1")
  191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  192. return
  193. }
  194. schedule.BedId = bedId
  195. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  196. utils.ErrorLog("zone_id")
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. partitionId := int64(items["zone_id"].(float64))
  201. if partitionId < 1 {
  202. utils.ErrorLog("partitionId < 1")
  203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  204. return
  205. }
  206. schedule.PartitionId = partitionId
  207. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  208. if bed == nil {
  209. week_type, _ := items["week_type"].(string)
  210. week_name, _ := items["week_name"].(string)
  211. switch week_type {
  212. case "1":
  213. json := make(map[string]interface{})
  214. json["msg"] = "本周" + week_name + "的机号不存在,无法保存"
  215. json["state"] = 0
  216. c.Data["json"] = json
  217. c.ServeJSON()
  218. break
  219. case "2":
  220. json := make(map[string]interface{})
  221. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  222. json["state"] = 0
  223. c.Data["json"] = json
  224. c.ServeJSON()
  225. break
  226. case "3":
  227. json := make(map[string]interface{})
  228. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  229. json["state"] = 0
  230. c.Data["json"] = json
  231. c.ServeJSON()
  232. break
  233. }
  234. return
  235. }
  236. if bed.ZoneID != schedule.PartitionId {
  237. week_type, _ := items["week_type"].(string)
  238. week_name, _ := items["week_name"].(string)
  239. switch week_type {
  240. case "1":
  241. json := make(map[string]interface{})
  242. json["msg"] = "本周" + week_name + "所选机号不在选择分区中,无法保存"
  243. json["state"] = 0
  244. c.Data["json"] = json
  245. c.ServeJSON()
  246. break
  247. case "2":
  248. json := make(map[string]interface{})
  249. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  250. json["state"] = 0
  251. c.Data["json"] = json
  252. c.ServeJSON()
  253. break
  254. case "3":
  255. json := make(map[string]interface{})
  256. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  257. json["state"] = 0
  258. c.Data["json"] = json
  259. c.ServeJSON()
  260. break
  261. }
  262. return
  263. }
  264. startTime := schedule.ScheduleDate
  265. endTime := startTime + 86399
  266. //一天只有排班一次
  267. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  268. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  269. week_type, _ := items["week_type"].(string)
  270. week_name, _ := items["week_name"].(string)
  271. switch week_type {
  272. case "1":
  273. json := make(map[string]interface{})
  274. json["msg"] = "本周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  275. json["state"] = 0
  276. c.Data["json"] = json
  277. c.ServeJSON()
  278. break
  279. case "2":
  280. json := make(map[string]interface{})
  281. json["msg"] = "下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  282. json["state"] = 0
  283. c.Data["json"] = json
  284. c.ServeJSON()
  285. break
  286. case "3":
  287. json := make(map[string]interface{})
  288. json["msg"] = "下下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  289. json["state"] = 0
  290. c.Data["json"] = json
  291. c.ServeJSON()
  292. break
  293. }
  294. return
  295. }
  296. //同天同位置只能排一个
  297. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  298. if err != nil {
  299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  300. return
  301. }
  302. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  303. week_type, _ := items["week_type"].(string)
  304. week_name, _ := items["week_name"].(string)
  305. switch week_type {
  306. case "1":
  307. json := make(map[string]interface{})
  308. json["msg"] = "本周" + week_name + "所先位置排班已经存在,无法保存"
  309. json["state"] = 0
  310. c.Data["json"] = json
  311. c.ServeJSON()
  312. break
  313. case "2":
  314. json := make(map[string]interface{})
  315. json["msg"] = "下周" + week_name + "所先位置排班已经存在,无法保存"
  316. json["state"] = 0
  317. c.Data["json"] = json
  318. c.ServeJSON()
  319. break
  320. case "3":
  321. json := make(map[string]interface{})
  322. json["msg"] = "下下周" + week_name + "所先位置排班已经存在,无法保存"
  323. json["state"] = 0
  324. c.Data["json"] = json
  325. c.ServeJSON()
  326. break
  327. }
  328. return
  329. }
  330. } else { //新的排班信息
  331. fmt.Println("111111111")
  332. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  333. fmt.Println("33333333")
  334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  335. return
  336. }
  337. scheduleDate, _ := items["schedule_date"].(string)
  338. if len(scheduleDate) == 0 {
  339. utils.ErrorLog("len(schedule_date) == 0")
  340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  341. return
  342. }
  343. timeLayout := "2006-01-02"
  344. loc, _ := time.LoadLocation("Local")
  345. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  346. if err != nil {
  347. utils.ErrorLog(err.Error())
  348. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  349. return
  350. }
  351. schedule.ScheduleDate = theTime.Unix()
  352. //existSch,_ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId,schedule.ScheduleDate,patient_id)
  353. //
  354. //if existSch.ID > 0{
  355. // fmt.Println("555555555")
  356. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  357. // return
  358. //
  359. //}
  360. timeNow := time.Now().Format("2006-01-02")
  361. if timeNow > scheduleDate {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  363. return
  364. }
  365. scheduleType := int64(items["schedule_type"].(float64))
  366. if scheduleType < 1 || scheduleType > 3 {
  367. utils.ErrorLog("scheduleType < 3")
  368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  369. return
  370. }
  371. schedule.ScheduleType = scheduleType
  372. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  373. fmt.Println("~~~~~~22222")
  374. utils.ErrorLog("bed_id")
  375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  376. return
  377. }
  378. bedId := int64(items["bed_id"].(float64))
  379. if bedId < 1 {
  380. utils.ErrorLog("bedId < 1")
  381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  382. return
  383. }
  384. schedule.BedId = bedId
  385. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  386. utils.ErrorLog("zone_id")
  387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  388. return
  389. }
  390. partitionId := int64(items["zone_id"].(float64))
  391. if partitionId < 1 {
  392. utils.ErrorLog("zone_id < 1")
  393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  394. return
  395. }
  396. schedule.PartitionId = partitionId
  397. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  398. utils.ErrorLog("schedule_week")
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  400. return
  401. }
  402. scheduleWeek := int64(items["schedule_week"].(float64))
  403. if scheduleWeek < 1 || scheduleWeek > 7 {
  404. utils.ErrorLog("scheduleWeek < 1")
  405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  406. return
  407. }
  408. schedule.ScheduleWeek = scheduleWeek
  409. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  410. utils.ErrorLog("mode_id")
  411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  412. return
  413. }
  414. modeId := int64(items["mode_id"].(float64))
  415. if modeId < 1 && modeId > 14 {
  416. utils.ErrorLog("modeId < 1")
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  418. return
  419. }
  420. //校验当天改床位是否有排班,如果有排班则不能替换排班
  421. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  422. fmt.Println(sch.PatientId)
  423. fmt.Println(schedule.PatientId)
  424. if sch.ID > 0 && sch.PatientId != patient_id {
  425. week_type, _ := items["week_type"].(string)
  426. week_name, _ := items["week_name"].(string)
  427. switch week_type {
  428. case "1":
  429. json := make(map[string]interface{})
  430. json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  431. json["state"] = 0
  432. c.Data["json"] = json
  433. c.ServeJSON()
  434. break
  435. case "2":
  436. json := make(map[string]interface{})
  437. json["msg"] = "下周" + week_name + "该床位已经有人排班,无法保存"
  438. json["state"] = 0
  439. c.Data["json"] = json
  440. c.ServeJSON()
  441. break
  442. case "3":
  443. json := make(map[string]interface{})
  444. json["msg"] = "下下周" + week_name + "该床位已经有人排班,无法保存"
  445. json["state"] = 0
  446. c.Data["json"] = json
  447. c.ServeJSON()
  448. break
  449. }
  450. return
  451. }
  452. //daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  453. //if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  454. // week_type, _ := items["week_type"].(string)
  455. // week_name, _ := items["week_name"].(string)
  456. //
  457. // switch week_type {
  458. // case "1":
  459. // json := make(map[string]interface{})
  460. // json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  461. // json["state"] = 0
  462. // c.Data["json"] = json
  463. // c.ServeJSON()
  464. // break
  465. // case "2":
  466. // json := make(map[string]interface{})
  467. // json["msg"] = "下周" + week_name + "当天该患者已经排班,无法保存"
  468. // json["state"] = 0
  469. // c.Data["json"] = json
  470. // c.ServeJSON()
  471. // break
  472. // case "3":
  473. // json := make(map[string]interface{})
  474. // json["msg"] = "下下周" + week_name + "当天该患者已经排班,无法保存"
  475. // json["state"] = 0
  476. // c.Data["json"] = json
  477. // c.ServeJSON()
  478. // break
  479. // }
  480. //
  481. // return
  482. //
  483. //
  484. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  485. // return
  486. //}
  487. //
  488. }
  489. }
  490. }
  491. }
  492. ////删除数据
  493. if dataBody["del_schs"] != nil && reflect.TypeOf(dataBody["del_schs"]).String() == "[]interface {}" {
  494. schs, _ := dataBody["del_schs"].([]interface{})
  495. if len(schs) > 0 {
  496. for _, item := range schs {
  497. items := item.(map[string]interface{})
  498. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  499. utils.ErrorLog("id")
  500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  501. return
  502. }
  503. var schedule models.Schedule
  504. sch_id := int64(items["sch_id"].(float64))
  505. if sch_id > 0 { //修改排班信息
  506. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  507. schedule.Status = 0
  508. service.SaveSch(schedule)
  509. }
  510. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  511. }
  512. }
  513. }
  514. ////修改或保存数据
  515. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  516. schs, _ := dataBody["smart_schs"].([]interface{})
  517. if len(schs) > 0 {
  518. for _, item := range schs {
  519. items := item.(map[string]interface{})
  520. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  521. utils.ErrorLog("id")
  522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  523. return
  524. }
  525. var schedule models.Schedule
  526. //var oldSchedule *models.Schedule
  527. sch_id := int64(items["sch_id"].(float64))
  528. if sch_id > 0 { //修改排班信息
  529. fmt.Println("!!!!!!!")
  530. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  531. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  532. fmt.Println(reflect.TypeOf(items["mode_id"]))
  533. utils.ErrorLog("mode_id")
  534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  535. return
  536. }
  537. modeId := int64(items["mode_id"].(float64))
  538. if modeId < 1 {
  539. utils.ErrorLog("modeId < 1")
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. schedule.ModeId = modeId
  544. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  545. if err != nil {
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  547. return
  548. }
  549. if order != nil {
  550. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  551. return
  552. }
  553. if order != nil {
  554. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  555. return
  556. }
  557. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  558. utils.ErrorLog("schedule_type")
  559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  560. return
  561. }
  562. scheduleType := int64(items["schedule_type"].(float64))
  563. if scheduleType < 1 || scheduleType > 3 {
  564. utils.ErrorLog("scheduleType < 3")
  565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  566. return
  567. }
  568. schedule.ScheduleType = scheduleType
  569. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  570. utils.ErrorLog("bed_id")
  571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  572. return
  573. }
  574. bedId := int64(items["bed_id"].(float64))
  575. if bedId < 1 {
  576. utils.ErrorLog("bedId < 1")
  577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  578. return
  579. }
  580. schedule.BedId = bedId
  581. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  582. utils.ErrorLog("zone_id")
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  584. return
  585. }
  586. partitionId := int64(items["zone_id"].(float64))
  587. if partitionId < 1 {
  588. utils.ErrorLog("partitionId < 1")
  589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  590. return
  591. }
  592. schedule.PartitionId = partitionId
  593. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  594. if bed == nil {
  595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  596. return
  597. }
  598. if bed.ZoneID != schedule.PartitionId {
  599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  600. return
  601. }
  602. startTime := schedule.ScheduleDate
  603. endTime := startTime + 86399
  604. //一天只有排班一次
  605. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  606. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  608. return
  609. }
  610. //同天同位置只能排一个
  611. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  612. if err != nil {
  613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  614. return
  615. }
  616. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  618. return
  619. }
  620. var DialysisMachineName string
  621. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  622. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  623. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  624. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  625. if filedRecordOne.IsShow == 1 {
  626. DialysisMachineName = so.DialysisDialyszers
  627. }
  628. if filedRecordThree.IsShow == 1 {
  629. if len(DialysisMachineName) > 0 {
  630. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  631. } else {
  632. DialysisMachineName = so.DialyzerPerfusionApparatus
  633. }
  634. }
  635. if filedRecordTwo.IsShow == 1 {
  636. if len(DialysisMachineName) > 0 {
  637. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  638. } else {
  639. DialysisMachineName = so.DialysisIrrigation
  640. }
  641. }
  642. schedule.DialysisMachineName = DialysisMachineName
  643. schedule.IsExport = 3000
  644. service.SaveSch(schedule)
  645. } else { //新的排班信息
  646. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  648. return
  649. }
  650. scheduleDate, _ := items["schedule_date"].(string)
  651. if len(scheduleDate) == 0 {
  652. utils.ErrorLog("len(schedule_date) == 0")
  653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  654. return
  655. }
  656. timeLayout := "2006-01-02"
  657. loc, _ := time.LoadLocation("Local")
  658. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  659. if err != nil {
  660. utils.ErrorLog(err.Error())
  661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  662. return
  663. }
  664. schedule.ScheduleDate = theTime.Unix()
  665. timeNow := time.Now().Format("2006-01-02")
  666. if timeNow > scheduleDate {
  667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  668. return
  669. }
  670. scheduleType := int64(items["schedule_type"].(float64))
  671. if scheduleType < 1 || scheduleType > 3 {
  672. utils.ErrorLog("scheduleType < 3")
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  674. return
  675. }
  676. schedule.ScheduleType = scheduleType
  677. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  678. utils.ErrorLog("bed_id")
  679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  680. return
  681. }
  682. bedId := int64(items["bed_id"].(float64))
  683. if bedId < 1 {
  684. utils.ErrorLog("bedId < 1")
  685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  686. return
  687. }
  688. schedule.BedId = bedId
  689. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  690. utils.ErrorLog("zone_id")
  691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  692. return
  693. }
  694. partitionId := int64(items["zone_id"].(float64))
  695. if partitionId < 1 {
  696. utils.ErrorLog("zone_id < 1")
  697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  698. return
  699. }
  700. schedule.PartitionId = partitionId
  701. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  702. utils.ErrorLog("schedule_week")
  703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  704. return
  705. }
  706. scheduleWeek := int64(items["schedule_week"].(float64))
  707. if scheduleWeek < 1 || scheduleWeek > 7 {
  708. utils.ErrorLog("scheduleWeek < 1")
  709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  710. return
  711. }
  712. schedule.ScheduleWeek = scheduleWeek
  713. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  714. fmt.Println(reflect.TypeOf(items["mode_id"]))
  715. utils.ErrorLog("mode_id")
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  717. return
  718. }
  719. modeId := int64(items["mode_id"].(float64))
  720. if modeId < 1 && modeId > 14 {
  721. utils.ErrorLog("modeId < 1")
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. //校验当天改床位是否有排班,如果有排班则不能替换排班
  726. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  727. if sch.ID > 0 && sch.PatientId != patient_id {
  728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  729. return
  730. }
  731. var DialysisMachineName string
  732. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  733. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  734. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  735. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  736. if filedRecordOne.IsShow == 1 {
  737. DialysisMachineName = so.DialysisDialyszers
  738. }
  739. if filedRecordThree.IsShow == 1 {
  740. if len(schedule.DialysisMachineName) > 0 {
  741. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  742. } else {
  743. DialysisMachineName = so.DialyzerPerfusionApparatus
  744. }
  745. }
  746. if filedRecordTwo.IsShow == 1 {
  747. if len(DialysisMachineName) > 0 {
  748. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  749. } else {
  750. DialysisMachineName = so.DialysisIrrigation
  751. }
  752. }
  753. schedule.DialysisMachineName = DialysisMachineName
  754. //判断当前保存的患者是否已经有排班
  755. existSchedule, _ := service.GetScheduleByDate(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  756. if existSchedule.ID > 0 {
  757. existSchedule.ModeId = modeId
  758. existSchedule.BedId = schedule.BedId
  759. existSchedule.PartitionId = schedule.PartitionId
  760. existSchedule.ScheduleType = schedule.ScheduleType
  761. existSchedule.DialysisMachineName = schedule.DialysisMachineName
  762. existSchedule.IsExport = 3001
  763. service.SaveSmartSch(existSchedule)
  764. } else {
  765. schedule.ModeId = modeId
  766. schedule.PatientId = patient_id
  767. schedule.CreatedTime = time.Now().Unix()
  768. schedule.UpdatedTime = time.Now().Unix()
  769. schedule.Status = 1
  770. schedule.UserOrgId = adminInfo.CurrentOrgId
  771. var DialysisMachineName string
  772. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  773. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  774. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  775. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  776. if filedRecordOne.IsShow == 1 {
  777. DialysisMachineName = so.DialysisDialyszers
  778. }
  779. if filedRecordThree.IsShow == 1 {
  780. if len(DialysisMachineName) > 0 {
  781. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  782. } else {
  783. DialysisMachineName = so.DialyzerPerfusionApparatus
  784. }
  785. }
  786. if filedRecordTwo.IsShow == 1 {
  787. if len(DialysisMachineName) > 0 {
  788. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  789. } else {
  790. DialysisMachineName = so.DialysisIrrigation
  791. }
  792. }
  793. schedule.DialysisMachineName = DialysisMachineName
  794. //schedule.DialysisMachineName = schedule.DialysisMachineName
  795. daySchedule, _ := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  796. if daySchedule.ID > 0 {
  797. daySchedule.ModeId = schedule.ModeId
  798. daySchedule.ScheduleType = schedule.ScheduleType
  799. daySchedule.PartitionId = schedule.PartitionId
  800. daySchedule.BedId = schedule.BedId
  801. daySchedule.DialysisMachineName = schedule.DialysisMachineName
  802. existSchedule.IsExport = 3002
  803. service.SaveSch(daySchedule)
  804. } else {
  805. existSchedule.IsExport = 3003
  806. service.CreateSchedule(&schedule)
  807. }
  808. }
  809. }
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "msg": "保存成功",
  812. })
  813. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  814. }
  815. }
  816. }
  817. }
  818. func HandleRedis(org_id int64, sch_date int64) {
  819. redis := service.RedisClient()
  820. //处方
  821. keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":prescriptions_list_all"
  822. redis.Set(keyOne, "", time.Second)
  823. //医嘱
  824. keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":advice_list_all"
  825. redis.Set(keyTwo, "", time.Second)
  826. keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_befores_list_all"
  827. redis.Set(keySix, "", time.Second)
  828. keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_after_dislysis_list_all"
  829. redis.Set(keyThree, "", time.Second)
  830. keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":monitor_record_list_all"
  831. redis.Set(keyFour, "", time.Second)
  832. keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":treatment_summarys_list_all"
  833. redis.Set(keyFive, "", time.Second)
  834. keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":dialysis_orders_list_all"
  835. redis.Set(keySeven, "", time.Second)
  836. defer redis.Close()
  837. }
  838. func (c *ScheduleApiController) GetSmartSch() {
  839. patient_id, _ := c.GetInt64("patient_id")
  840. fmt.Println("~~~~~~")
  841. fmt.Println(patient_id)
  842. fmt.Println("~~~~~~")
  843. adminUserInfo := c.GetAdminUserInfo()
  844. sch, err := service.GetSmartSchPatientByPatientID(adminUserInfo.CurrentOrgId, patient_id)
  845. if err != nil {
  846. utils.ErrorLog(err.Error())
  847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  848. return
  849. }
  850. c.ServeSuccessJSON(map[string]interface{}{
  851. "sch": sch,
  852. })
  853. }
  854. func (c *ScheduleApiController) GetPatient() {
  855. keyWord := c.GetString("keyword")
  856. adminUserInfo := c.GetAdminUserInfo()
  857. patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  858. if err != nil {
  859. utils.ErrorLog(err.Error())
  860. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  861. return
  862. }
  863. c.ServeSuccessJSON(map[string]interface{}{
  864. "patient": patient,
  865. })
  866. }
  867. func (c *ScheduleApiController) GetPatientSchTemplate() {
  868. //patient_id, _ := c.GetInt64("patient_id",0)
  869. keyWord := c.GetString("keyword")
  870. adminUserInfo := c.GetAdminUserInfo()
  871. patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  872. if err != nil {
  873. utils.ErrorLog(err.Error())
  874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  875. return
  876. }
  877. c.ServeSuccessJSON(map[string]interface{}{
  878. "patient": patient,
  879. })
  880. }
  881. func (c *ScheduleApiController) GetPatientSmartSch() {
  882. patient_id, _ := c.GetInt64("patient_id", 0)
  883. adminUserInfo := c.GetAdminUserInfo()
  884. schs, err := service.GetSmartSchPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  885. if err != nil {
  886. utils.ErrorLog(err.Error())
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  888. return
  889. }
  890. c.ServeSuccessJSON(map[string]interface{}{
  891. "schedules": schs,
  892. })
  893. }
  894. func (c *ScheduleApiController) GetPatientSmartSchTemplate() {
  895. patient_id, _ := c.GetInt64("patient_id", 0)
  896. adminUserInfo := c.GetAdminUserInfo()
  897. mode, _ := service.GetOrgPatientScheduleTemplateModeTwo(adminUserInfo.CurrentOrgId)
  898. if mode.ID > 0 {
  899. if mode.Mode == 0 {
  900. //schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id)
  901. c.ServeSuccessJSON(map[string]interface{}{
  902. "status": 0,
  903. })
  904. } else if mode.Mode == 1 {
  905. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 1)
  906. c.ServeSuccessJSON(map[string]interface{}{
  907. "status": 0,
  908. "schedules_template": schs,
  909. })
  910. } else if mode.Mode == 2 {
  911. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 2)
  912. c.ServeSuccessJSON(map[string]interface{}{
  913. "status": 1,
  914. "schedules_template": schs,
  915. })
  916. } else if mode.Mode == 3 {
  917. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 3)
  918. c.ServeSuccessJSON(map[string]interface{}{
  919. "status": 1,
  920. "schedules_template": schs,
  921. })
  922. } else if mode.Mode == 4 {
  923. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 4)
  924. c.ServeSuccessJSON(map[string]interface{}{
  925. "status": 1,
  926. "schedules_template": schs,
  927. })
  928. }
  929. } else {
  930. c.ServeSuccessJSON(map[string]interface{}{
  931. "status": 0,
  932. })
  933. }
  934. }
  935. func (c *ScheduleApiController) GetDevicesNumbers() {
  936. sch_type, _ := c.GetInt("sch_type", 0)
  937. zone_id, _ := c.GetInt64("zone_id", 0)
  938. patient_id, _ := c.GetInt64("patient_id", 0)
  939. schedule_date := c.GetString("schedule_date")
  940. timeLayout := "2006-01-02"
  941. loc, _ := time.LoadLocation("Local")
  942. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  943. if err != nil {
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  945. return
  946. }
  947. recordDateTime := theTime.Unix()
  948. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, sch_type, zone_id, patient_id)
  949. if getDeviceNumbersErr != nil {
  950. c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  952. return
  953. }
  954. c.ServeSuccessJSON(map[string]interface{}{
  955. "devices": deviceNumbers,
  956. })
  957. }
  958. func (c *ScheduleApiController) GetWeekPanels() {
  959. data, _ := c.GetInt64("data", 1)
  960. patitionIdStr := c.GetString("patitionid")
  961. var ids []string
  962. if len(patitionIdStr) > 0 {
  963. ids = strings.Split(patitionIdStr, ",")
  964. }
  965. adminInfo := c.GetAdminUserInfo()
  966. thisTime := time.Now()
  967. year, monthTime, day := thisTime.Date()
  968. month := int(monthTime)
  969. _, theWeek := thisTime.ISOWeek()
  970. lastWeek := thisTime.AddDate(0, 0, -7)
  971. nextWeek := thisTime.AddDate(0, 0, 7)
  972. nextSecWeek := thisTime.AddDate(0, 0, 14)
  973. _, theLastWeek := lastWeek.ISOWeek()
  974. _, theNextWeek := nextWeek.ISOWeek()
  975. _, theNextSecWeek := nextSecWeek.ISOWeek()
  976. weekDay := int(thisTime.Weekday())
  977. if weekDay == 0 {
  978. weekDay = 7
  979. }
  980. weekEnd := 7 - weekDay
  981. weekStart := weekEnd - 6
  982. weekDays := make([]string, 0)
  983. for index := weekStart; index <= weekEnd; index++ {
  984. theDay := thisTime.AddDate(0, 0, index)
  985. indexYear, indexMonthTime, indexDay := theDay.Date()
  986. indexMonth := int(indexMonthTime)
  987. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  988. weekDays = append(weekDays, indexWeek)
  989. }
  990. returnData := map[string]interface{}{
  991. "year": year,
  992. "month": month,
  993. "day": day,
  994. "theWeek": theWeek,
  995. "theNextWeek": theNextWeek,
  996. "theNextSecWeek": theNextSecWeek,
  997. "theLastWeek": theLastWeek,
  998. "weekDay": weekDay,
  999. "weekDays": weekDays,
  1000. }
  1001. if data == 1 {
  1002. fmt.Println(ids)
  1003. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, ids)
  1004. fmt.Println("````~~")
  1005. fmt.Println(partitions)
  1006. returnData["partitions"] = partitions
  1007. }
  1008. c.ServeSuccessJSON(returnData)
  1009. return
  1010. }
  1011. func (c *ScheduleApiController) GetSchedules() {
  1012. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  1013. partition_id, _ := c.GetInt64("partition_id")
  1014. schedule_type, _ := c.GetInt64("schedule_type")
  1015. adminInfo := c.GetAdminUserInfo()
  1016. thisTime := time.Now()
  1017. today := thisTime.Format("2006-01-02")
  1018. if week < 1 || week > 4 {
  1019. week = 2
  1020. }
  1021. if week == 1 {
  1022. thisTime = thisTime.AddDate(0, 0, -7)
  1023. } else if week == 3 {
  1024. thisTime = thisTime.AddDate(0, 0, 7)
  1025. } else if week == 4 {
  1026. thisTime = thisTime.AddDate(0, 0, 14)
  1027. }
  1028. weekDay := int(thisTime.Weekday())
  1029. if weekDay == 0 {
  1030. weekDay = 7
  1031. }
  1032. weekEnd := 7 - weekDay
  1033. weekStart := weekEnd - 6
  1034. weekTitle := make([]string, 0)
  1035. days := make([]string, 0)
  1036. for index := weekStart; index <= weekEnd; index++ {
  1037. theDay := thisTime.AddDate(0, 0, index)
  1038. indexYear, indexMonthTime, indexDay := theDay.Date()
  1039. indexMonth := int(indexMonthTime)
  1040. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1041. weekTitle = append(weekTitle, indexWeek)
  1042. days = append(days, theDay.Format("2006-01-02"))
  1043. }
  1044. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  1045. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  1046. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1047. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1048. timeLayout := "2006-01-02 15:04:05"
  1049. loc, _ := time.LoadLocation("Local")
  1050. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1051. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1052. weekStartPoint := theStarTime.Unix()
  1053. weekEndPoint := theEndTime.Unix()
  1054. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  1055. c.ServeSuccessJSON(map[string]interface{}{
  1056. "days": days,
  1057. "weekTitle": weekTitle,
  1058. "schdules": schdules,
  1059. "today": today,
  1060. })
  1061. return
  1062. }
  1063. func (c *ScheduleApiController) GetPatients() {
  1064. keywords := c.GetString("keywords", "")
  1065. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  1066. contagion, _ := c.GetInt64("contagion", 0)
  1067. adminInfo := c.GetAdminUserInfo()
  1068. thisTime := time.Now()
  1069. weekDay := int(thisTime.Weekday())
  1070. if weekDay == 0 {
  1071. weekDay = 7
  1072. }
  1073. thisWeekEnd := 7 - weekDay
  1074. weekStartPoint := thisWeekEnd - 6
  1075. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  1076. weekEndPoint := thisWeekEnd + 7
  1077. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  1078. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  1079. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1080. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1081. fmt.Println(weekStartTime, weekEndTime)
  1082. timeLayout := "2006-01-02 15:04:05"
  1083. loc, _ := time.LoadLocation("Local")
  1084. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1085. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1086. weekStart := theStarTime.Unix()
  1087. weekEnd := theEndTime.Unix()
  1088. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  1089. fmt.Println("patinets23233232323232232322323wode", patients)
  1090. c.ServeSuccessJSON(map[string]interface{}{
  1091. "patients": patients,
  1092. })
  1093. return
  1094. }
  1095. func (c *ScheduleApiController) CreateSchedule() {
  1096. patientID, _ := c.GetInt64("patient_id", 0)
  1097. if patientID <= 0 {
  1098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1099. return
  1100. }
  1101. adminUserInfo := c.GetAdminUserInfo()
  1102. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  1103. if patientInfo.ID == 0 {
  1104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1105. return
  1106. }
  1107. var schedule models.Schedule
  1108. dataBody := make(map[string]interface{}, 0)
  1109. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1110. if err != nil {
  1111. utils.ErrorLog(err.Error())
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1113. return
  1114. }
  1115. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  1116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1117. return
  1118. }
  1119. scheduleDate, _ := dataBody["schedule_date"].(string)
  1120. if len(scheduleDate) == 0 {
  1121. utils.ErrorLog("len(schedule_date) == 0")
  1122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1123. return
  1124. }
  1125. timeLayout := "2006-01-02"
  1126. loc, _ := time.LoadLocation("Local")
  1127. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  1128. if err != nil {
  1129. utils.ErrorLog(err.Error())
  1130. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1131. return
  1132. }
  1133. schedule.ScheduleDate = theTime.Unix()
  1134. timeNow := time.Now().Format("2006-01-02")
  1135. if timeNow > scheduleDate {
  1136. utils.ErrorLog(timeNow)
  1137. utils.ErrorLog(scheduleDate)
  1138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1139. return
  1140. }
  1141. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1142. utils.ErrorLog("schedule_type")
  1143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1144. return
  1145. }
  1146. scheduleType := int64(dataBody["schedule_type"].(float64))
  1147. if scheduleType < 1 || scheduleType > 3 {
  1148. utils.ErrorLog("scheduleType < 3")
  1149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1150. return
  1151. }
  1152. schedule.ScheduleType = scheduleType
  1153. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1154. utils.ErrorLog("bed_id")
  1155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1156. return
  1157. }
  1158. bedId := int64(dataBody["bed_id"].(float64))
  1159. if bedId < 1 {
  1160. utils.ErrorLog("bedId < 1")
  1161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1162. return
  1163. }
  1164. schedule.BedId = bedId
  1165. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1166. utils.ErrorLog("partition_id")
  1167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1168. return
  1169. }
  1170. partitionId := int64(dataBody["partition_id"].(float64))
  1171. if partitionId < 1 {
  1172. utils.ErrorLog("partitionId < 1")
  1173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1174. return
  1175. }
  1176. schedule.PartitionId = partitionId
  1177. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1178. utils.ErrorLog("schedule_week")
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1183. if scheduleWeek < 1 || scheduleWeek > 7 {
  1184. utils.ErrorLog("scheduleWeek < 1")
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1186. return
  1187. }
  1188. schedule.ScheduleWeek = scheduleWeek
  1189. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1190. utils.ErrorLog("mode_id")
  1191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1192. return
  1193. }
  1194. modeId := int64(dataBody["mode_id"].(float64))
  1195. if modeId < 1 && modeId > 14 {
  1196. utils.ErrorLog("modeId < 1")
  1197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1198. return
  1199. }
  1200. schedule.ModeId = modeId
  1201. schedule.PatientId = patientID
  1202. schedule.CreatedTime = time.Now().Unix()
  1203. schedule.UpdatedTime = time.Now().Unix()
  1204. schedule.Status = 1
  1205. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1206. schedule.IsExport = 5
  1207. var DialysisMachineName string
  1208. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1209. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1210. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1211. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1212. if filedRecordOne.IsShow == 1 {
  1213. DialysisMachineName = so.DialysisDialyszers
  1214. }
  1215. if filedRecordThree.IsShow == 1 {
  1216. if len(DialysisMachineName) > 0 {
  1217. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1218. } else {
  1219. DialysisMachineName = so.DialyzerPerfusionApparatus
  1220. }
  1221. }
  1222. if filedRecordTwo.IsShow == 1 {
  1223. if len(DialysisMachineName) > 0 {
  1224. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1225. } else {
  1226. DialysisMachineName = so.DialysisIrrigation
  1227. }
  1228. }
  1229. schedule.DialysisMachineName = DialysisMachineName
  1230. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1231. if bed == nil {
  1232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1233. return
  1234. }
  1235. if bed.ZoneID != schedule.PartitionId {
  1236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1237. return
  1238. }
  1239. scheduleDateStart := scheduleDate + " 00:00:00"
  1240. scheduleDateEnd := scheduleDate + " 23:59:59"
  1241. timeLayout = "2006-01-02 15:04:05"
  1242. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1243. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1244. startTime := theStartTime.Unix()
  1245. endTime := theEndTime.Unix()
  1246. //一天只有排班一次
  1247. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1248. if daySchedule.ID > 0 {
  1249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1250. return
  1251. }
  1252. //同天同位置只能排一个
  1253. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1256. return
  1257. }
  1258. if pointSchedule.ID > 0 {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1260. return
  1261. }
  1262. redis := service.RedisClient()
  1263. schedule.IsExport = 1000
  1264. err = service.CreateSchedule(&schedule)
  1265. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1266. redis.Set(key, "", time.Second)
  1267. //处方
  1268. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1269. redis.Set(keyOne, "", time.Second)
  1270. //医嘱
  1271. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1272. redis.Set(keyTwo, "", time.Second)
  1273. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1274. redis.Set(keySix, "", time.Second)
  1275. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1276. redis.Set(keyThree, "", time.Second)
  1277. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1278. redis.Set(keyFour, "", time.Second)
  1279. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1280. redis.Set(keyFive, "", time.Second)
  1281. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1282. redis.Set(keySeven, "", time.Second)
  1283. fmt.Println(err)
  1284. defer redis.Close()
  1285. if err != nil {
  1286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  1287. return
  1288. }
  1289. schedule.Patient = patientInfo.Name
  1290. c.ServeSuccessJSON(map[string]interface{}{
  1291. "msg": "ok",
  1292. "schedule": schedule,
  1293. })
  1294. return
  1295. }
  1296. func (c *ScheduleApiController) DeleteSchedule() {
  1297. id, _ := c.GetInt64("id", 0)
  1298. if id <= 0 {
  1299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1300. return
  1301. }
  1302. adminINfo := c.GetAdminUserInfo()
  1303. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1304. timeNow := time.Now().Format("2006-01-02")
  1305. timeTemplate := "2006-01-02"
  1306. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1307. timeStr := tm.Format(timeTemplate)
  1308. if timeNow > timeStr {
  1309. utils.ErrorLog(timeNow)
  1310. utils.ErrorLog(timeStr)
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1312. return
  1313. }
  1314. if schedule == nil {
  1315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1316. return
  1317. }
  1318. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1319. if err != nil {
  1320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1321. return
  1322. }
  1323. if order != nil {
  1324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1325. return
  1326. }
  1327. schedule.Status = 0
  1328. schedule.UpdatedTime = time.Now().Unix()
  1329. err = service.UpdateSchedule(schedule)
  1330. redis := service.RedisClient()
  1331. //处方
  1332. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1333. redis.Set(keyOne, "", time.Second)
  1334. //医嘱
  1335. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1336. redis.Set(keyTwo, "", time.Second)
  1337. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1338. redis.Set(keySix, "", time.Second)
  1339. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1340. redis.Set(keyThree, "", time.Second)
  1341. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1342. redis.Set(keyFour, "", time.Second)
  1343. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1344. redis.Set(keyFive, "", time.Second)
  1345. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1346. redis.Set(keySeven, "", time.Second)
  1347. fmt.Println(err)
  1348. defer redis.Close()
  1349. if err != nil {
  1350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  1351. return
  1352. }
  1353. c.ServeSuccessJSON(map[string]interface{}{
  1354. "msg": "ok",
  1355. "schedule": &schedule,
  1356. })
  1357. }
  1358. func (c *ScheduleApiController) ChangeSchedule() {
  1359. id, _ := c.GetInt64("id", 0)
  1360. if id <= 0 {
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. adminINfo := c.GetAdminUserInfo()
  1365. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1366. if schedule == nil {
  1367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1368. return
  1369. }
  1370. dataBody := make(map[string]interface{}, 0)
  1371. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1372. if err != nil {
  1373. utils.ErrorLog(err.Error())
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1375. return
  1376. }
  1377. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  1378. utils.ErrorLog("change_action")
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1380. return
  1381. }
  1382. changeAction := dataBody["change_action"].(string)
  1383. if changeAction == "change_mode" {
  1384. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1385. utils.ErrorLog("mode_id")
  1386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  1387. return
  1388. }
  1389. modeId := int64(dataBody["mode_id"].(float64))
  1390. if modeId < 1 {
  1391. utils.ErrorLog("modeId < 1")
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  1393. return
  1394. }
  1395. schedule.ModeId = modeId
  1396. so, _ := service.GetDialysisSolutionTwo(adminINfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1397. filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
  1398. filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
  1399. filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
  1400. var DialysisMachineName string
  1401. if filedRecordOne.IsShow == 1 {
  1402. DialysisMachineName = so.DialysisDialyszers
  1403. fmt.Println("1111")
  1404. fmt.Println(DialysisMachineName)
  1405. }
  1406. if filedRecordThree.IsShow == 1 {
  1407. if len(schedule.DialysisMachineName) > 0 {
  1408. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1409. fmt.Println("22222")
  1410. fmt.Println(DialysisMachineName)
  1411. } else {
  1412. DialysisMachineName = so.DialyzerPerfusionApparatus
  1413. fmt.Println("333333")
  1414. fmt.Println(DialysisMachineName)
  1415. }
  1416. }
  1417. if filedRecordTwo.IsShow == 1 {
  1418. if len(DialysisMachineName) > 0 {
  1419. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1420. fmt.Println("55555555")
  1421. fmt.Println(DialysisMachineName)
  1422. } else {
  1423. DialysisMachineName = so.DialysisIrrigation
  1424. fmt.Println("66666666")
  1425. fmt.Println(DialysisMachineName)
  1426. }
  1427. }
  1428. schedule.DialysisMachineName = DialysisMachineName
  1429. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1430. if err != nil {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1432. return
  1433. }
  1434. if order != nil {
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  1436. return
  1437. }
  1438. } else if changeAction == "change_device" {
  1439. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1440. if err != nil {
  1441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1442. return
  1443. }
  1444. if order != nil {
  1445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  1446. return
  1447. }
  1448. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1449. utils.ErrorLog("schedule_type")
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1451. return
  1452. }
  1453. scheduleType := int64(dataBody["schedule_type"].(float64))
  1454. if scheduleType < 1 || scheduleType > 3 {
  1455. utils.ErrorLog("scheduleType < 3")
  1456. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1457. return
  1458. }
  1459. schedule.ScheduleType = scheduleType
  1460. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1461. utils.ErrorLog("bed_id")
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1463. return
  1464. }
  1465. bedId := int64(dataBody["bed_id"].(float64))
  1466. if bedId < 1 {
  1467. utils.ErrorLog("bedId < 1")
  1468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1469. return
  1470. }
  1471. schedule.BedId = bedId
  1472. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1473. utils.ErrorLog("partition_id")
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1475. return
  1476. }
  1477. partitionId := int64(dataBody["partition_id"].(float64))
  1478. if partitionId < 1 {
  1479. utils.ErrorLog("partitionId < 1")
  1480. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1481. return
  1482. }
  1483. schedule.PartitionId = partitionId
  1484. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  1485. if bed == nil {
  1486. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1487. return
  1488. }
  1489. if bed.ZoneID != schedule.PartitionId {
  1490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1491. return
  1492. }
  1493. startTime := schedule.ScheduleDate
  1494. endTime := startTime + 86399
  1495. //一天只有排班一次
  1496. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  1497. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  1498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1499. return
  1500. }
  1501. //同天同位置只能排一个
  1502. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1503. if err != nil {
  1504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1505. return
  1506. }
  1507. if pointSchedule.ID > 0 {
  1508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1509. return
  1510. }
  1511. } else {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1513. return
  1514. }
  1515. schedule.UpdatedTime = time.Now().Unix()
  1516. err = service.UpdateSchedule(schedule)
  1517. prescription := models.DialysisPrescription{
  1518. ModeId: schedule.ModeId,
  1519. }
  1520. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  1521. if errcode == gorm.ErrRecordNotFound {
  1522. if err != nil {
  1523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1524. return
  1525. }
  1526. c.ServeSuccessJSON(map[string]interface{}{
  1527. "msg": "ok",
  1528. "schedule": &schedule,
  1529. })
  1530. } else if errcode == nil {
  1531. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  1532. if err != nil {
  1533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1534. return
  1535. }
  1536. c.ServeSuccessJSON(map[string]interface{}{
  1537. "msg": "ok",
  1538. "schedule": &schedule,
  1539. })
  1540. }
  1541. }
  1542. // /api/schedule/print/initdata [get]
  1543. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  1544. func (this *ScheduleApiController) PrintInitData() {
  1545. dateStr := this.GetString("date")
  1546. //week_type, _ := this.GetInt64("type", 0)
  1547. var date *time.Time
  1548. if len(dateStr) == 0 {
  1549. now := time.Now()
  1550. date = &now
  1551. } else {
  1552. var parseErr error
  1553. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  1554. if parseErr != nil {
  1555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1556. return
  1557. }
  1558. }
  1559. adminUserInfo := this.GetAdminUserInfo()
  1560. // 获取本周的排班
  1561. var monday time.Time
  1562. var sunday time.Time
  1563. //switch week_type {
  1564. //case 1:
  1565. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  1566. // break
  1567. //case 2:
  1568. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  1569. //
  1570. // break
  1571. //case 3:
  1572. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  1573. // break
  1574. //}
  1575. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1576. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1577. if getScheduleErr != nil {
  1578. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  1579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1580. return
  1581. }
  1582. thisTime := date
  1583. weekDay := int(thisTime.Weekday())
  1584. if weekDay == 0 {
  1585. weekDay = 7
  1586. }
  1587. weekEnd := 7 - weekDay
  1588. weekStart := weekEnd - 6
  1589. days := make([]string, 0)
  1590. for index := weekStart; index <= weekEnd; index++ {
  1591. theDay := thisTime.AddDate(0, 0, index)
  1592. days = append(days, theDay.Format("2006-01-02"))
  1593. }
  1594. this.ServeSuccessJSON(map[string]interface{}{
  1595. "total": total,
  1596. "schedules": schedules,
  1597. "monday": monday.Unix(),
  1598. "days": days,
  1599. })
  1600. }
  1601. func (this *ScheduleApiController) UrgentScheduleData() {
  1602. schedule_type, _ := this.GetInt("type", 0)
  1603. schedule_date := this.GetString("date")
  1604. var date *time.Time
  1605. if len(schedule_date) == 0 {
  1606. now := time.Now()
  1607. date = &now
  1608. } else {
  1609. var parseErr error
  1610. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1611. if parseErr != nil {
  1612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1613. return
  1614. }
  1615. }
  1616. adminUserInfo := this.GetAdminUserInfo()
  1617. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1618. if getDeviceNumbersErr != nil {
  1619. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1621. return
  1622. }
  1623. // today := utils.ZeroHourTimeOfDay(time.Now())
  1624. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1625. if getSchedulesErr != nil {
  1626. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  1627. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1628. return
  1629. }
  1630. this.ServeSuccessJSON(map[string]interface{}{
  1631. "device_numbers": deviceNumbers,
  1632. "schedules": schedules,
  1633. })
  1634. }
  1635. func (this *ScheduleApiController) SearchSchedulePatients() {
  1636. keywords := this.GetString("keywords")
  1637. week_type, _ := this.GetInt64("week_type", 0)
  1638. start_sch := this.GetString("start_sch")
  1639. end_sch := this.GetString("end_sch")
  1640. thisTime1 := time.Now()
  1641. thisTime2 := time.Now()
  1642. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1643. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1644. var start_time string
  1645. var end_time string
  1646. switch week_type {
  1647. case 1:
  1648. timeLayout := "2006-01-02"
  1649. loc, _ := time.LoadLocation("Local")
  1650. var startSchTime int64
  1651. if len(start_sch) > 0 {
  1652. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
  1653. startSchTime = theTime.Unix()
  1654. }
  1655. var endSchTime int64
  1656. if len(end_sch) > 0 {
  1657. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
  1658. endSchTime = theTime.Unix()
  1659. }
  1660. adminUserInfo := this.GetAdminUserInfo()
  1661. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
  1662. this.ServeSuccessJSON(map[string]interface{}{
  1663. "schdules": list,
  1664. })
  1665. break
  1666. case 2:
  1667. days := make([]string, 0)
  1668. weekDay1 := int(thisTime1.Weekday())
  1669. if weekDay1 == 0 {
  1670. weekDay1 = 7
  1671. }
  1672. weekEnd1 := 7 - weekDay1
  1673. weekStart1 := weekEnd1 - 6
  1674. for index := weekStart1; index <= weekEnd1; index++ {
  1675. fmt.Println(index)
  1676. theDay := thisTime1.AddDate(0, 0, index)
  1677. days = append(days, theDay.Format("2006-01-02"))
  1678. }
  1679. fmt.Println(days)
  1680. start_time = days[0]
  1681. end_time = days[len(days)-1]
  1682. timeLayout := "2006-01-02"
  1683. loc, _ := time.LoadLocation("Local")
  1684. var theStartTime int64
  1685. if len(start_time) > 0 {
  1686. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1687. theStartTime = theTime.Unix()
  1688. }
  1689. var theEndtTime int64
  1690. if len(end_time) > 0 {
  1691. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1692. theEndtTime = theTime.Unix()
  1693. }
  1694. adminUserInfo := this.GetAdminUserInfo()
  1695. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1696. this.ServeSuccessJSON(map[string]interface{}{
  1697. "schdules": list,
  1698. })
  1699. break
  1700. case 3:
  1701. days := make([]string, 0)
  1702. weekDay2 := int(thisTime2.Weekday())
  1703. if weekDay2 == 0 {
  1704. weekDay2 = 7
  1705. }
  1706. weekEnd2 := 7 - weekDay2
  1707. weekStart2 := weekEnd2 - 6
  1708. for index := weekStart2; index <= weekEnd2; index++ {
  1709. theDay := thisTime2.AddDate(0, 0, index)
  1710. days = append(days, theDay.Format("2006-01-02"))
  1711. }
  1712. start_time = days[0]
  1713. end_time = days[len(days)-1]
  1714. timeLayout := "2006-01-02"
  1715. loc, _ := time.LoadLocation("Local")
  1716. var theStartTime int64
  1717. if len(start_time) > 0 {
  1718. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1719. theStartTime = theTime.Unix()
  1720. }
  1721. var theEndtTime int64
  1722. if len(end_time) > 0 {
  1723. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1724. theEndtTime = theTime.Unix()
  1725. }
  1726. adminUserInfo := this.GetAdminUserInfo()
  1727. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1728. this.ServeSuccessJSON(map[string]interface{}{
  1729. "schdules": list,
  1730. })
  1731. break
  1732. }
  1733. }
  1734. func (this *ScheduleApiController) GetWeekDaySchedule() {
  1735. week_type, _ := this.GetInt64("week_type", -1)
  1736. week_time, _ := this.GetInt64("week_time")
  1737. thisTime := time.Now()
  1738. weekDay := int(thisTime.Weekday())
  1739. if weekDay == 0 {
  1740. weekDay = 7
  1741. }
  1742. weekEnd := 7 - weekDay
  1743. weekStart := weekEnd - 6
  1744. weekTitle := make([]string, 0)
  1745. days := make([]string, 0)
  1746. for index := weekStart; index <= weekEnd; index++ {
  1747. theDay := thisTime.AddDate(0, 0, index)
  1748. indexYear, indexMonthTime, indexDay := theDay.Date()
  1749. indexMonth := int(indexMonthTime)
  1750. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1751. weekTitle = append(weekTitle, indexWeek)
  1752. days = append(days, theDay.Format("2006-01-02"))
  1753. }
  1754. fmt.Println(days)
  1755. var targetDayStr string
  1756. var startTime string
  1757. var endTime string
  1758. switch week_type {
  1759. case 0:
  1760. {
  1761. startTime = days[0]
  1762. endTime = days[6]
  1763. }
  1764. case 1:
  1765. targetDayStr = days[0]
  1766. break
  1767. case 2:
  1768. targetDayStr = days[1]
  1769. break
  1770. case 3:
  1771. targetDayStr = days[2]
  1772. break
  1773. case 4:
  1774. targetDayStr = days[3]
  1775. break
  1776. case 5:
  1777. targetDayStr = days[4]
  1778. break
  1779. case 6:
  1780. targetDayStr = days[5]
  1781. break
  1782. case 7:
  1783. targetDayStr = days[6]
  1784. break
  1785. }
  1786. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  1787. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  1788. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  1789. fmt.Println(startDay, endDay)
  1790. if parseErr != nil {
  1791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1792. return
  1793. }
  1794. orgId := this.GetAdminUserInfo().CurrentOrgId
  1795. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  1796. this.ServeSuccessJSON(map[string]interface{}{
  1797. "schdules": list,
  1798. "day": targetDayStr,
  1799. })
  1800. }
  1801. func Struct2Map(obj interface{}) map[string]interface{} {
  1802. t := reflect.TypeOf(obj)
  1803. v := reflect.ValueOf(obj)
  1804. var data = make(map[string]interface{})
  1805. for i := 0; i < t.NumField(); i++ {
  1806. data[t.Field(i).Name] = v.Field(i).Interface()
  1807. }
  1808. return data
  1809. }
  1810. func (this *ScheduleApiController) ExportSchedule() {
  1811. dataBody := make(map[string]interface{}, 0)
  1812. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1813. if err != nil {
  1814. utils.ErrorLog(err.Error())
  1815. return
  1816. }
  1817. utils.ErrorLog("%v", dataBody)
  1818. export_time := time.Now().Unix()
  1819. var schedules []*models.Schedule
  1820. var failed_total int
  1821. var total_schedule []interface{}
  1822. var patients []*models.Patients
  1823. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1824. start_time := dataBody["start_time"].(string)
  1825. end_time := dataBody["end_time"].(string)
  1826. delete_type := int64(dataBody["delete_type"].(float64))
  1827. fmt.Println("delete_type", delete_type)
  1828. timeLayout := "2006-01-02"
  1829. loc, _ := time.LoadLocation("Local")
  1830. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1831. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1832. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  1833. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  1834. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  1835. tempSchedule := dataBody["failed_schedule"].([]interface{})
  1836. failed_total = len(tempSchedule)
  1837. }
  1838. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1839. tempSchedule := dataBody["schedule"].([]interface{})
  1840. total_schedule = tempSchedule
  1841. for _, schMap := range tempSchedule {
  1842. schMapM := schMap.(map[string]interface{})
  1843. var sch models.Schedule
  1844. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1845. utils.ErrorLog("name")
  1846. return
  1847. }
  1848. name, _ := schMapM["name"].(string)
  1849. fmt.Println(name)
  1850. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1851. err_log := models.ExportErrLog{
  1852. LogType: 2,
  1853. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1854. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1855. Status: 1,
  1856. CreateTime: time.Now().Unix(),
  1857. UpdateTime: time.Now().Unix(),
  1858. ExportTime: export_time,
  1859. }
  1860. service.CreateExportErrLog(&err_log)
  1861. continue
  1862. } else {
  1863. var patient []*models.Patients
  1864. for _, item := range patients {
  1865. if strings.Replace(item.Name, " ", "", -1) == name {
  1866. patient = append(patient, item)
  1867. }
  1868. }
  1869. if len(patient) == 0 { //错误日志
  1870. err_log := models.ExportErrLog{
  1871. LogType: 2,
  1872. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1873. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1874. Status: 1,
  1875. CreateTime: time.Now().Unix(),
  1876. UpdateTime: time.Now().Unix(),
  1877. ExportTime: export_time,
  1878. }
  1879. service.CreateExportErrLog(&err_log)
  1880. continue
  1881. } else if len(patient) == 1 { //
  1882. sch.PatientId = patient[0].ID
  1883. } else if len(patient) > 1 { //出现同名的情况
  1884. err_log := models.ExportErrLog{
  1885. LogType: 2,
  1886. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1887. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1888. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  1889. Status: 1,
  1890. CreateTime: time.Now().Unix(),
  1891. UpdateTime: time.Now().Unix(),
  1892. ExportTime: export_time,
  1893. }
  1894. service.CreateExportErrLog(&err_log)
  1895. continue
  1896. }
  1897. }
  1898. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1899. utils.ErrorLog("schedule_type")
  1900. return
  1901. }
  1902. schedule_type := int64(schMapM["schedule_type"].(float64))
  1903. if schedule_type <= 0 { //班次格式有误,插入日志
  1904. log := models.ExportLog{
  1905. LogType: 2,
  1906. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1907. TotalNum: int64(len(total_schedule) + failed_total),
  1908. FailNum: 1 + int64(failed_total),
  1909. SuccessNum: int64(len(schedules)),
  1910. CreateTime: time.Now().Unix(),
  1911. UpdateTime: time.Now().Unix(),
  1912. ExportTime: export_time,
  1913. Status: 1,
  1914. }
  1915. service.CreateExportLog(&log)
  1916. err_log := models.ExportErrLog{
  1917. LogType: 2,
  1918. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1919. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1920. Status: 1,
  1921. CreateTime: time.Now().Unix(),
  1922. UpdateTime: time.Now().Unix(),
  1923. ExportTime: export_time,
  1924. }
  1925. service.CreateExportErrLog(&err_log)
  1926. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1927. return
  1928. } else {
  1929. sch.ScheduleType = schedule_type
  1930. }
  1931. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  1932. utils.ErrorLog("partition_name")
  1933. return
  1934. }
  1935. partition_name, _ := schMapM["partition_name"].(string)
  1936. if len(partition_name) == 0 { //分区为空
  1937. log := models.ExportLog{
  1938. LogType: 2,
  1939. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1940. TotalNum: int64(len(total_schedule) + failed_total),
  1941. FailNum: 1 + int64(failed_total),
  1942. SuccessNum: int64(len(schedules)),
  1943. CreateTime: time.Now().Unix(),
  1944. UpdateTime: time.Now().Unix(),
  1945. ExportTime: export_time,
  1946. Status: 1,
  1947. }
  1948. service.CreateExportLog(&log)
  1949. err_log := models.ExportErrLog{
  1950. LogType: 2,
  1951. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1952. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1953. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1954. Status: 1,
  1955. CreateTime: time.Now().Unix(),
  1956. UpdateTime: time.Now().Unix(),
  1957. ExportTime: export_time,
  1958. }
  1959. service.CreateExportErrLog(&err_log)
  1960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1961. return
  1962. } else {
  1963. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1964. if err == nil {
  1965. sch.PartitionId = zone.ID
  1966. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  1967. log := models.ExportLog{
  1968. LogType: 2,
  1969. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1970. TotalNum: int64(len(total_schedule) + failed_total),
  1971. FailNum: 1 + int64(failed_total),
  1972. SuccessNum: int64(len(schedules)),
  1973. CreateTime: time.Now().Unix(),
  1974. UpdateTime: time.Now().Unix(),
  1975. ExportTime: export_time,
  1976. Status: 1,
  1977. }
  1978. service.CreateExportLog(&log)
  1979. err_log := models.ExportErrLog{
  1980. LogType: 2,
  1981. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1982. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1983. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1984. Status: 1,
  1985. CreateTime: time.Now().Unix(),
  1986. UpdateTime: time.Now().Unix(),
  1987. ExportTime: export_time,
  1988. }
  1989. service.CreateExportErrLog(&err_log)
  1990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1991. return
  1992. }
  1993. }
  1994. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1995. utils.ErrorLog("device_number_name")
  1996. return
  1997. }
  1998. device_number_name, _ := schMapM["device_number_name"].(string)
  1999. if len(device_number_name) == 0 { //分区为空
  2000. log := models.ExportLog{
  2001. LogType: 2,
  2002. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2003. TotalNum: int64(len(total_schedule) + failed_total),
  2004. FailNum: 1 + int64(failed_total),
  2005. SuccessNum: int64(len(schedules)),
  2006. CreateTime: time.Now().Unix(),
  2007. UpdateTime: time.Now().Unix(),
  2008. ExportTime: export_time,
  2009. Status: 1,
  2010. }
  2011. service.CreateExportLog(&log)
  2012. err_log := models.ExportErrLog{
  2013. LogType: 2,
  2014. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2015. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2016. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2017. Status: 1,
  2018. CreateTime: time.Now().Unix(),
  2019. UpdateTime: time.Now().Unix(),
  2020. ExportTime: export_time,
  2021. }
  2022. service.CreateExportErrLog(&err_log)
  2023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2024. return
  2025. } else {
  2026. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  2027. if err == nil {
  2028. if len(device) == 0 { //没查到数据,插入错误日志
  2029. log := models.ExportLog{
  2030. LogType: 2,
  2031. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2032. TotalNum: int64(len(total_schedule) + failed_total),
  2033. FailNum: 1 + int64(failed_total),
  2034. SuccessNum: int64(len(schedules)),
  2035. CreateTime: time.Now().Unix(),
  2036. UpdateTime: time.Now().Unix(),
  2037. ExportTime: export_time,
  2038. Status: 1,
  2039. }
  2040. service.CreateExportLog(&log)
  2041. err_log := models.ExportErrLog{
  2042. LogType: 2,
  2043. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2044. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2045. Status: 1,
  2046. CreateTime: time.Now().Unix(),
  2047. UpdateTime: time.Now().Unix(),
  2048. ExportTime: export_time,
  2049. }
  2050. service.CreateExportErrLog(&err_log)
  2051. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2052. return
  2053. } else if len(device) == 1 {
  2054. sch.BedId = device[0].ID
  2055. } else if len(device) > 1 { //出现重名,插入错误日志
  2056. log := models.ExportLog{
  2057. LogType: 2,
  2058. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2059. TotalNum: int64(len(total_schedule) + failed_total),
  2060. FailNum: 1 + int64(failed_total),
  2061. SuccessNum: int64(len(schedules)),
  2062. CreateTime: time.Now().Unix(),
  2063. UpdateTime: time.Now().Unix(),
  2064. ExportTime: export_time,
  2065. Status: 1,
  2066. }
  2067. service.CreateExportLog(&log)
  2068. err_log := models.ExportErrLog{
  2069. LogType: 2,
  2070. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2071. ErrMsg: "出现两个床位号相同的床位",
  2072. Status: 1,
  2073. CreateTime: time.Now().Unix(),
  2074. UpdateTime: time.Now().Unix(),
  2075. ExportTime: export_time,
  2076. }
  2077. service.CreateExportErrLog(&err_log)
  2078. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2079. return
  2080. }
  2081. }
  2082. }
  2083. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2084. utils.ErrorLog("schedule_week")
  2085. return
  2086. }
  2087. schedule_week, _ := schMapM["schedule_week"].(string)
  2088. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2089. log := models.ExportLog{
  2090. LogType: 2,
  2091. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2092. TotalNum: int64(len(total_schedule) + failed_total),
  2093. FailNum: 1 + int64(failed_total),
  2094. SuccessNum: int64(len(schedules)),
  2095. CreateTime: time.Now().Unix(),
  2096. UpdateTime: time.Now().Unix(),
  2097. ExportTime: export_time,
  2098. Status: 1,
  2099. }
  2100. service.CreateExportLog(&log)
  2101. err_log := models.ExportErrLog{
  2102. LogType: 2,
  2103. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2104. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2105. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2106. Status: 1,
  2107. CreateTime: time.Now().Unix(),
  2108. UpdateTime: time.Now().Unix(),
  2109. ExportTime: export_time,
  2110. }
  2111. service.CreateExportErrLog(&err_log)
  2112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2113. return
  2114. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2115. log := models.ExportLog{
  2116. LogType: 2,
  2117. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2118. TotalNum: int64(len(total_schedule) + failed_total),
  2119. FailNum: 1 + int64(failed_total),
  2120. SuccessNum: int64(len(schedules)),
  2121. CreateTime: time.Now().Unix(),
  2122. UpdateTime: time.Now().Unix(),
  2123. ExportTime: export_time,
  2124. Status: 1,
  2125. }
  2126. service.CreateExportLog(&log)
  2127. err_log := models.ExportErrLog{
  2128. LogType: 2,
  2129. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2130. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2131. Status: 1,
  2132. CreateTime: time.Now().Unix(),
  2133. UpdateTime: time.Now().Unix(),
  2134. ExportTime: export_time,
  2135. }
  2136. service.CreateExportErrLog(&err_log)
  2137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2138. return
  2139. } else {
  2140. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2141. sch.ScheduleWeek = schedule_week
  2142. }
  2143. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  2144. utils.ErrorLog("schedule_date")
  2145. return
  2146. }
  2147. schedule_date, _ := schMapM["schedule_date"].(string)
  2148. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  2149. log := models.ExportLog{
  2150. LogType: 2,
  2151. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2152. TotalNum: int64(len(total_schedule) + failed_total),
  2153. FailNum: 1 + int64(failed_total),
  2154. SuccessNum: int64(len(schedules)),
  2155. CreateTime: time.Now().Unix(),
  2156. UpdateTime: time.Now().Unix(),
  2157. ExportTime: export_time,
  2158. Status: 1,
  2159. }
  2160. service.CreateExportLog(&log)
  2161. err_log := models.ExportErrLog{
  2162. LogType: 2,
  2163. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2164. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2165. Status: 1,
  2166. CreateTime: time.Now().Unix(),
  2167. UpdateTime: time.Now().Unix(),
  2168. ExportTime: export_time,
  2169. }
  2170. service.CreateExportErrLog(&err_log)
  2171. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2172. return
  2173. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  2174. log := models.ExportLog{
  2175. LogType: 2,
  2176. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2177. TotalNum: int64(len(total_schedule) + failed_total),
  2178. FailNum: 1 + int64(failed_total),
  2179. SuccessNum: int64(len(schedules)),
  2180. CreateTime: time.Now().Unix(),
  2181. UpdateTime: time.Now().Unix(),
  2182. ExportTime: export_time,
  2183. Status: 1,
  2184. }
  2185. service.CreateExportLog(&log)
  2186. err_log := models.ExportErrLog{
  2187. LogType: 2,
  2188. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2189. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2190. Status: 1,
  2191. CreateTime: time.Now().Unix(),
  2192. UpdateTime: time.Now().Unix(),
  2193. ExportTime: export_time,
  2194. }
  2195. service.CreateExportErrLog(&err_log)
  2196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2197. return
  2198. } else {
  2199. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2200. sch.ScheduleDate = date.Unix()
  2201. }
  2202. sch.CreatedTime = time.Now().Unix()
  2203. sch.UpdatedTime = time.Now().Unix()
  2204. sch.ModeId = 1
  2205. sch.Status = 1
  2206. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  2207. sch.IsExport = 1
  2208. var DialysisMachineName string
  2209. so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
  2210. filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
  2211. filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
  2212. filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
  2213. if filedRecordOne.IsShow == 1 {
  2214. DialysisMachineName = so.DialysisDialyszers
  2215. }
  2216. if filedRecordThree.IsShow == 1 {
  2217. if len(DialysisMachineName) > 0 {
  2218. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2219. } else {
  2220. DialysisMachineName = so.DialyzerPerfusionApparatus
  2221. }
  2222. }
  2223. if filedRecordTwo.IsShow == 1 {
  2224. if len(DialysisMachineName) > 0 {
  2225. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  2226. } else {
  2227. DialysisMachineName = so.DialysisIrrigation
  2228. }
  2229. }
  2230. sch.DialysisMachineName = DialysisMachineName
  2231. schedules = append(schedules, &sch)
  2232. }
  2233. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2234. if len(schedules) > 0 {
  2235. schedule_date := time.Now().Format("2006-01-02")
  2236. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2237. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  2238. service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
  2239. if err == nil {
  2240. for _, item := range schedules {
  2241. if item.ScheduleDate > clear_schedule_date {
  2242. //查询该患者是否转出获取死亡
  2243. fmt.Println("11111323242423")
  2244. //查找当天日期是否存在
  2245. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  2246. if errcode == gorm.ErrRecordNotFound {
  2247. //查询该床位是否有患者
  2248. fmt.Println("errcodes")
  2249. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  2250. fmt.Println("errcodes")
  2251. fmt.Println(errcodes)
  2252. fmt.Println(sch)
  2253. if errcodes == gorm.ErrRecordNotFound {
  2254. fmt.Println("1111111")
  2255. service.CreateSchedule(item)
  2256. } else if errcodes == nil {
  2257. fmt.Println("1111222222222")
  2258. //清除当天该床位已有的患者
  2259. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  2260. service.CreateSchedule(item)
  2261. }
  2262. } else if errcode == nil {
  2263. schedule := models.XtSchedule{
  2264. PartitionId: item.PartitionId,
  2265. BedId: item.BedId,
  2266. PatientId: item.PatientId,
  2267. ScheduleDate: item.ScheduleDate,
  2268. ScheduleType: item.ScheduleType,
  2269. ScheduleWeek: item.ScheduleWeek,
  2270. ModeId: 1,
  2271. Status: 1,
  2272. DialysisMachineName: item.DialysisMachineName,
  2273. }
  2274. fmt.Println("1111222222223333333333333333332")
  2275. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  2276. }
  2277. }
  2278. }
  2279. log := models.ExportLog{
  2280. LogType: 2,
  2281. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2282. TotalNum: int64(len(total_schedule) + failed_total),
  2283. FailNum: int64(len(errLogs) + failed_total),
  2284. SuccessNum: int64(len(schedules)),
  2285. CreateTime: time.Now().Unix(),
  2286. UpdateTime: time.Now().Unix(),
  2287. ExportTime: export_time,
  2288. Status: 1,
  2289. }
  2290. service.CreateExportLog(&log)
  2291. if failed_total > 0 {
  2292. err_log := models.ExportErrLog{
  2293. LogType: 2,
  2294. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2295. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2296. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2297. Status: 1,
  2298. CreateTime: time.Now().Unix(),
  2299. UpdateTime: time.Now().Unix(),
  2300. ExportTime: export_time,
  2301. }
  2302. service.CreateExportErrLog(&err_log)
  2303. }
  2304. this.ServeSuccessJSON(map[string]interface{}{
  2305. "msg": "导入成功",
  2306. "total_num": len(total_schedule) + failed_total,
  2307. "success_num": len(schedules),
  2308. "fail_num": int64(len(errLogs)),
  2309. })
  2310. } else {
  2311. log := models.ExportLog{
  2312. LogType: 2,
  2313. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2314. TotalNum: int64(len(total_schedule) + failed_total),
  2315. FailNum: int64(len(errLogs) + failed_total),
  2316. SuccessNum: int64(len(schedules)),
  2317. CreateTime: time.Now().Unix(),
  2318. UpdateTime: time.Now().Unix(),
  2319. ExportTime: export_time,
  2320. Status: 1,
  2321. }
  2322. service.CreateExportLog(&log)
  2323. if failed_total > 0 {
  2324. err_log := models.ExportErrLog{
  2325. LogType: 2,
  2326. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2327. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2328. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2329. Status: 1,
  2330. CreateTime: time.Now().Unix(),
  2331. UpdateTime: time.Now().Unix(),
  2332. ExportTime: export_time,
  2333. }
  2334. service.CreateExportErrLog(&err_log)
  2335. }
  2336. this.ServeSuccessJSON(map[string]interface{}{
  2337. "msg": "导入成功",
  2338. "total_num": len(total_schedule),
  2339. "success_num": len(schedules),
  2340. "fail_num": int64(len(errLogs)),
  2341. })
  2342. }
  2343. } else {
  2344. log := models.ExportLog{
  2345. LogType: 2,
  2346. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2347. TotalNum: int64(len(total_schedule) + failed_total),
  2348. FailNum: int64(len(errLogs) + failed_total),
  2349. SuccessNum: int64(len(schedules)),
  2350. CreateTime: time.Now().Unix(),
  2351. UpdateTime: time.Now().Unix(),
  2352. ExportTime: export_time,
  2353. Status: 1,
  2354. }
  2355. service.CreateExportLog(&log)
  2356. if failed_total > 0 {
  2357. err_log := models.ExportErrLog{
  2358. LogType: 2,
  2359. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2360. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2361. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2362. Status: 1,
  2363. CreateTime: time.Now().Unix(),
  2364. UpdateTime: time.Now().Unix(),
  2365. ExportTime: export_time,
  2366. }
  2367. service.CreateExportErrLog(&err_log)
  2368. }
  2369. this.ServeSuccessJSON(map[string]interface{}{
  2370. "msg": "导入成功",
  2371. "total_num": len(total_schedule),
  2372. "success_num": len(schedules),
  2373. "fail_num": int64(len(errLogs)),
  2374. })
  2375. }
  2376. }
  2377. }
  2378. func (this *ScheduleApiController) ExportScheduleTemplate() {
  2379. dataBody := make(map[string]interface{}, 0)
  2380. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2381. if err != nil {
  2382. utils.ErrorLog(err.Error())
  2383. return
  2384. }
  2385. utils.ErrorLog("%v", dataBody)
  2386. export_time := time.Now().Unix()
  2387. var schedules []*models.PatientScheduleTemplateItem
  2388. var total_schedule []interface{}
  2389. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  2390. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  2391. tempSchedule := dataBody["schedule"].([]interface{})
  2392. total_schedule = tempSchedule
  2393. for _, schMap := range tempSchedule {
  2394. schMapM := schMap.(map[string]interface{})
  2395. var sch models.PatientScheduleTemplateItem
  2396. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  2397. utils.ErrorLog("name")
  2398. return
  2399. }
  2400. name, _ := schMapM["name"].(string)
  2401. fmt.Println(name)
  2402. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2403. err_log := models.ExportErrLog{
  2404. LogType: 3,
  2405. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2406. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  2407. Status: 1,
  2408. CreateTime: time.Now().Unix(),
  2409. UpdateTime: time.Now().Unix(),
  2410. ExportTime: export_time,
  2411. }
  2412. service.CreateExportErrLog(&err_log)
  2413. continue
  2414. } else {
  2415. var patient []*models.Patients
  2416. for _, item := range patients {
  2417. if strings.Replace(item.Name, " ", "", -1) == name {
  2418. patient = append(patient, item)
  2419. }
  2420. }
  2421. if len(patient) == 0 { //错误日志
  2422. err_log := models.ExportErrLog{
  2423. LogType: 3,
  2424. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2425. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  2426. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  2427. Status: 1,
  2428. CreateTime: time.Now().Unix(),
  2429. UpdateTime: time.Now().Unix(),
  2430. ExportTime: export_time,
  2431. }
  2432. service.CreateExportErrLog(&err_log)
  2433. continue
  2434. } else if len(patient) == 1 { //
  2435. sch.PatientID = patient[0].ID
  2436. } else if len(patient) > 1 { //出现同名的情况
  2437. err_log := models.ExportErrLog{
  2438. LogType: 3,
  2439. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2440. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  2441. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  2442. Status: 1,
  2443. CreateTime: time.Now().Unix(),
  2444. UpdateTime: time.Now().Unix(),
  2445. ExportTime: export_time,
  2446. }
  2447. service.CreateExportErrLog(&err_log)
  2448. continue
  2449. }
  2450. }
  2451. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  2452. utils.ErrorLog("schedule_type")
  2453. return
  2454. }
  2455. schedule_type := int64(schMapM["schedule_type"].(float64))
  2456. if schedule_type <= 0 { //班次格式有误,插入日志
  2457. log := models.ExportLog{
  2458. LogType: 3,
  2459. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2460. TotalNum: int64(len(total_schedule)),
  2461. FailNum: 1,
  2462. SuccessNum: int64(len(schedules)),
  2463. CreateTime: time.Now().Unix(),
  2464. UpdateTime: time.Now().Unix(),
  2465. ExportTime: export_time,
  2466. Status: 1,
  2467. }
  2468. service.CreateExportLog(&log)
  2469. err_log := models.ExportErrLog{
  2470. LogType: 3,
  2471. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2472. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  2473. Status: 1,
  2474. CreateTime: time.Now().Unix(),
  2475. UpdateTime: time.Now().Unix(),
  2476. ExportTime: export_time,
  2477. }
  2478. service.CreateExportErrLog(&err_log)
  2479. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2480. return
  2481. } else {
  2482. sch.TimeType = int8(schedule_type)
  2483. }
  2484. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  2485. utils.ErrorLog("template_id")
  2486. return
  2487. }
  2488. template_id := int64(schMapM["template_id"].(float64))
  2489. sch.TemplateID = template_id
  2490. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2491. utils.ErrorLog("device_number_name")
  2492. return
  2493. }
  2494. partition_name, _ := schMapM["partition_name"].(string)
  2495. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2496. device_number_name, _ := schMapM["device_number_name"].(string)
  2497. if len(device_number_name) == 0 { //分区为空
  2498. log := models.ExportLog{
  2499. LogType: 3,
  2500. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2501. TotalNum: int64(len(total_schedule)),
  2502. FailNum: 1,
  2503. SuccessNum: int64(len(schedules)),
  2504. CreateTime: time.Now().Unix(),
  2505. UpdateTime: time.Now().Unix(),
  2506. ExportTime: export_time,
  2507. Status: 1,
  2508. }
  2509. service.CreateExportLog(&log)
  2510. err_log := models.ExportErrLog{
  2511. LogType: 3,
  2512. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2513. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2514. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2515. Status: 1,
  2516. CreateTime: time.Now().Unix(),
  2517. UpdateTime: time.Now().Unix(),
  2518. ExportTime: export_time,
  2519. }
  2520. service.CreateExportErrLog(&err_log)
  2521. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2522. return
  2523. } else {
  2524. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  2525. if err == nil {
  2526. if len(device) == 0 { //没查到数据,插入错误日志
  2527. log := models.ExportLog{
  2528. LogType: 3,
  2529. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2530. TotalNum: int64(len(total_schedule)),
  2531. FailNum: 1,
  2532. SuccessNum: int64(len(schedules)),
  2533. CreateTime: time.Now().Unix(),
  2534. UpdateTime: time.Now().Unix(),
  2535. ExportTime: export_time,
  2536. Status: 1,
  2537. }
  2538. service.CreateExportLog(&log)
  2539. err_log := models.ExportErrLog{
  2540. LogType: 3,
  2541. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2542. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2543. Status: 1,
  2544. CreateTime: time.Now().Unix(),
  2545. UpdateTime: time.Now().Unix(),
  2546. ExportTime: export_time,
  2547. }
  2548. service.CreateExportErrLog(&err_log)
  2549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2550. return
  2551. } else if len(device) == 1 {
  2552. sch.DeviceNumberID = device[0].ID
  2553. } else if len(device) > 1 { //出现重名,插入错误日志
  2554. log := models.ExportLog{
  2555. LogType: 3,
  2556. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2557. TotalNum: int64(len(total_schedule)),
  2558. FailNum: 1,
  2559. SuccessNum: int64(len(schedules)),
  2560. CreateTime: time.Now().Unix(),
  2561. UpdateTime: time.Now().Unix(),
  2562. ExportTime: export_time,
  2563. Status: 1,
  2564. }
  2565. service.CreateExportLog(&log)
  2566. err_log := models.ExportErrLog{
  2567. LogType: 3,
  2568. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2569. ErrMsg: "出现两个床位号相同的床位",
  2570. Status: 1,
  2571. CreateTime: time.Now().Unix(),
  2572. UpdateTime: time.Now().Unix(),
  2573. ExportTime: export_time,
  2574. }
  2575. service.CreateExportErrLog(&err_log)
  2576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2577. return
  2578. }
  2579. }
  2580. }
  2581. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2582. utils.ErrorLog("schedule_week")
  2583. return
  2584. }
  2585. schedule_week, _ := schMapM["schedule_week"].(string)
  2586. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2587. log := models.ExportLog{
  2588. LogType: 3,
  2589. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2590. TotalNum: int64(len(total_schedule)),
  2591. FailNum: 1,
  2592. SuccessNum: int64(len(schedules)),
  2593. CreateTime: time.Now().Unix(),
  2594. UpdateTime: time.Now().Unix(),
  2595. ExportTime: export_time,
  2596. Status: 1,
  2597. }
  2598. service.CreateExportLog(&log)
  2599. err_log := models.ExportErrLog{
  2600. LogType: 3,
  2601. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2602. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2603. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2604. Status: 1,
  2605. CreateTime: time.Now().Unix(),
  2606. UpdateTime: time.Now().Unix(),
  2607. ExportTime: export_time,
  2608. }
  2609. service.CreateExportErrLog(&err_log)
  2610. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2611. return
  2612. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2613. log := models.ExportLog{
  2614. LogType: 3,
  2615. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2616. TotalNum: int64(len(total_schedule)),
  2617. FailNum: 1,
  2618. SuccessNum: int64(len(schedules)),
  2619. CreateTime: time.Now().Unix(),
  2620. UpdateTime: time.Now().Unix(),
  2621. ExportTime: export_time,
  2622. Status: 1,
  2623. }
  2624. service.CreateExportLog(&log)
  2625. err_log := models.ExportErrLog{
  2626. LogType: 3,
  2627. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2628. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2629. Status: 1,
  2630. CreateTime: time.Now().Unix(),
  2631. UpdateTime: time.Now().Unix(),
  2632. ExportTime: export_time,
  2633. }
  2634. service.CreateExportErrLog(&err_log)
  2635. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2636. return
  2637. } else {
  2638. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2639. sch.Weekday = int8(schedule_week)
  2640. }
  2641. treat_mode, _ := schMapM["treat_mode"].(string)
  2642. treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
  2643. sch.CreateTime = time.Now().Unix()
  2644. sch.ModifyTime = time.Now().Unix()
  2645. sch.TreatMode = treat_mode_int
  2646. sch.Status = 1
  2647. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  2648. sch.IsExport = 1
  2649. schedules = append(schedules, &sch)
  2650. }
  2651. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2652. //for _, item := range schedules {
  2653. //
  2654. //}
  2655. if len(schedules) > 0 {
  2656. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  2657. if err == nil {
  2658. for _, item := range schedules {
  2659. //判斷某個模板下,當天是否有排版,沒有的話就新增
  2660. total := service.ExportScheduleTemplate(item)
  2661. if total == 0 {
  2662. service.CreateScheduleTemplate(item)
  2663. }
  2664. }
  2665. ////查询已经转出或者死亡的患者
  2666. //patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  2667. //for _, it := range patientList {
  2668. // timeStr := time.Now().Format("2006-01-02")
  2669. // timeLayout := "2006-01-02 15:04:05"
  2670. // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2671. // timenow := timeStringToTime.Unix()
  2672. // service.UpdateScheduleByDeathTime(it.ID, timenow)
  2673. // service.UpdateScheduleItemByPatientId(it.ID)
  2674. //}
  2675. log := models.ExportLog{
  2676. LogType: 3,
  2677. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2678. TotalNum: int64(len(total_schedule)),
  2679. FailNum: int64(len(errLogs)),
  2680. SuccessNum: int64(len(schedules)),
  2681. CreateTime: time.Now().Unix(),
  2682. UpdateTime: time.Now().Unix(),
  2683. ExportTime: export_time,
  2684. Status: 1,
  2685. }
  2686. service.CreateExportLog(&log)
  2687. this.ServeSuccessJSON(map[string]interface{}{
  2688. "msg": "导入成功",
  2689. "total_num": len(total_schedule),
  2690. "success_num": len(schedules),
  2691. "fail_num": int64(len(errLogs)),
  2692. })
  2693. } else {
  2694. log := models.ExportLog{
  2695. LogType: 3,
  2696. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2697. TotalNum: int64(len(total_schedule)),
  2698. FailNum: int64(len(errLogs)),
  2699. SuccessNum: int64(len(schedules)),
  2700. CreateTime: time.Now().Unix(),
  2701. UpdateTime: time.Now().Unix(),
  2702. ExportTime: export_time,
  2703. Status: 1,
  2704. }
  2705. service.CreateExportLog(&log)
  2706. this.ServeSuccessJSON(map[string]interface{}{
  2707. "msg": "导入成功",
  2708. "total_num": len(total_schedule),
  2709. "success_num": len(schedules),
  2710. "fail_num": int64(len(errLogs)),
  2711. })
  2712. }
  2713. } else {
  2714. log := models.ExportLog{
  2715. LogType: 3,
  2716. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2717. TotalNum: int64(len(total_schedule)),
  2718. FailNum: int64(len(errLogs)),
  2719. SuccessNum: int64(len(schedules)),
  2720. CreateTime: time.Now().Unix(),
  2721. UpdateTime: time.Now().Unix(),
  2722. ExportTime: export_time,
  2723. Status: 1,
  2724. }
  2725. service.CreateExportLog(&log)
  2726. this.ServeSuccessJSON(map[string]interface{}{
  2727. "msg": "导入成功",
  2728. "total_num": len(total_schedule),
  2729. "success_num": len(schedules),
  2730. "fail_num": int64(len(errLogs)),
  2731. })
  2732. }
  2733. }
  2734. }
  2735. func (c *ScheduleApiController) GetInitExcelInitDate() {
  2736. thisTime := time.Now()
  2737. thisTime1 := time.Now()
  2738. thisTime2 := time.Now()
  2739. thisTime3 := time.Now()
  2740. thisTime4 := time.Now()
  2741. thisTime1 = thisTime1.AddDate(0, 0, 7)
  2742. thisTime2 = thisTime2.AddDate(0, 0, 14)
  2743. thisTime3 = thisTime3.AddDate(0, 0, 21)
  2744. thisTime4 = thisTime4.AddDate(0, 0, 28)
  2745. weekDay := int(thisTime.Weekday())
  2746. if weekDay == 0 {
  2747. weekDay = 7
  2748. }
  2749. weekEnd := 7 - weekDay
  2750. weekStart := weekEnd - 6
  2751. days := make([]string, 0)
  2752. for index := weekStart; index <= weekEnd; index++ {
  2753. theDay := thisTime.AddDate(0, 0, index)
  2754. days = append(days, theDay.Format("2006-01-02"))
  2755. }
  2756. weekDay1 := int(thisTime1.Weekday())
  2757. if weekDay1 == 0 {
  2758. weekDay1 = 7
  2759. }
  2760. weekEnd1 := 7 - weekDay1
  2761. weekStart1 := weekEnd1 - 6
  2762. for index := weekStart1; index <= weekEnd1; index++ {
  2763. theDay := thisTime1.AddDate(0, 0, index)
  2764. days = append(days, theDay.Format("2006-01-02"))
  2765. }
  2766. weekDay2 := int(thisTime2.Weekday())
  2767. if weekDay2 == 0 {
  2768. weekDay2 = 7
  2769. }
  2770. weekEnd2 := 7 - weekDay2
  2771. weekStart2 := weekEnd2 - 6
  2772. for index := weekStart2; index <= weekEnd2; index++ {
  2773. theDay := thisTime2.AddDate(0, 0, index)
  2774. days = append(days, theDay.Format("2006-01-02"))
  2775. }
  2776. weekDay3 := int(thisTime3.Weekday())
  2777. if weekDay3 == 0 {
  2778. weekDay3 = 7
  2779. }
  2780. weekEnd3 := 7 - weekDay3
  2781. weekStart3 := weekEnd3 - 6
  2782. for index := weekStart3; index <= weekEnd3; index++ {
  2783. theDay := thisTime3.AddDate(0, 0, index)
  2784. days = append(days, theDay.Format("2006-01-02"))
  2785. }
  2786. weekDay4 := int(thisTime4.Weekday())
  2787. if weekDay4 == 0 {
  2788. weekDay4 = 7
  2789. }
  2790. weekEnd4 := 7 - weekDay4
  2791. weekStart4 := weekEnd4 - 6
  2792. for index := weekStart4; index <= weekEnd4; index++ {
  2793. theDay := thisTime4.AddDate(0, 0, index)
  2794. days = append(days, theDay.Format("2006-01-02"))
  2795. }
  2796. c.ServeSuccessJSON(map[string]interface{}{
  2797. "days": days,
  2798. })
  2799. return
  2800. }
  2801. func GetWeekString(week string) string {
  2802. var weekStr string
  2803. switch week {
  2804. case "Sunday":
  2805. weekStr = "周日"
  2806. break
  2807. case "Monday":
  2808. weekStr = "周一"
  2809. break
  2810. case "Tuesday":
  2811. weekStr = "周二"
  2812. break
  2813. case "Wednesday":
  2814. weekStr = "周三"
  2815. break
  2816. case "Thursday":
  2817. weekStr = "周四"
  2818. break
  2819. case "Friday":
  2820. weekStr = "周五"
  2821. break
  2822. case "Saturday":
  2823. weekStr = "周六"
  2824. break
  2825. default:
  2826. weekStr = ""
  2827. break
  2828. }
  2829. return weekStr
  2830. }
  2831. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  2832. template_id, _ := c.GetInt64("template_id", 0)
  2833. keywords := c.GetString("keywords")
  2834. adminInfo := c.GetAdminUserInfo()
  2835. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  2836. c.ServeSuccessJSON(map[string]interface{}{
  2837. "schdules": scheduleItems,
  2838. })
  2839. }
  2840. func (c *ScheduleApiController) CancelScheduleTemplate() {
  2841. item_id, _ := c.GetInt64("id")
  2842. adminInfo := c.GetAdminUserInfo()
  2843. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  2844. if err == nil {
  2845. c.ServeSuccessJSON(map[string]interface{}{
  2846. "msg": "取消成功",
  2847. })
  2848. return
  2849. } else {
  2850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2851. return
  2852. }
  2853. }
  2854. func (this *ScheduleApiController) GetNextWeekDayScheduleOne() {
  2855. week_type, _ := this.GetInt64("week_type", -1)
  2856. week_time, _ := this.GetInt64("week_time")
  2857. record_date := this.GetString("record_date")
  2858. zons := this.GetString("zone")
  2859. zone := strings.Split(zons, ",")
  2860. start_time, _ := this.GetInt64("start_time")
  2861. end_time, _ := this.GetInt64("end_time")
  2862. timeLayout := "2006-01-02"
  2863. loc, _ := time.LoadLocation("Local")
  2864. //theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2865. //theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2866. adminUserInfo := this.GetAdminUserInfo()
  2867. var theStartTIme int64
  2868. if len(record_date) > 0 {
  2869. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2870. if err != nil {
  2871. utils.ErrorLog(err.Error())
  2872. }
  2873. theStartTIme = theTime.Unix()
  2874. }
  2875. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2876. for _, item := range schedule {
  2877. order, _ := service.GetLastDialysisOrder(adminUserInfo.CurrentOrgId, item.PatientId, theStartTIme)
  2878. item.XtDialysisOrderSix = order
  2879. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  2880. dialysisprescription, _ := service.GetLastDialysisSolution(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId, item.ScheduleDate)
  2881. item.DialysisPrescription = dialysisprescription
  2882. }
  2883. }
  2884. if err != nil {
  2885. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2886. return
  2887. }
  2888. this.ServeSuccessJSON(map[string]interface{}{
  2889. "schedule": schedule,
  2890. })
  2891. }
  2892. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  2893. week_type, _ := this.GetInt64("week_type", -1)
  2894. week_time, _ := this.GetInt64("week_time")
  2895. record_date := this.GetString("record_date")
  2896. zons := this.GetString("zone")
  2897. zone := strings.Split(zons, ",")
  2898. start_time := this.GetString("start_time")
  2899. end_time := this.GetString("end_time")
  2900. timeLayout := "2006-01-02"
  2901. loc, _ := time.LoadLocation("Local")
  2902. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2903. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2904. adminUserInfo := this.GetAdminUserInfo()
  2905. var theStartTIme int64
  2906. if len(record_date) > 0 {
  2907. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2908. if err != nil {
  2909. utils.ErrorLog(err.Error())
  2910. }
  2911. theStartTIme = theTime.Unix()
  2912. }
  2913. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2914. if err != nil {
  2915. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2916. return
  2917. }
  2918. this.ServeSuccessJSON(map[string]interface{}{
  2919. "schedule": schedule,
  2920. })
  2921. }
  2922. func (this *ScheduleApiController) GetThreeWeekList() {
  2923. start_time := this.GetString("start_time")
  2924. end_time := this.GetString("end_time")
  2925. partition_id, _ := this.GetInt64("partition_id")
  2926. schedule_type, _ := this.GetInt64("schedule_type")
  2927. fmt.Println(partition_id, schedule_type)
  2928. timeLayout := "2006-01-02"
  2929. loc, _ := time.LoadLocation("Local")
  2930. var theStartTIme int64
  2931. if len(start_time) > 0 {
  2932. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2933. if err != nil {
  2934. utils.ErrorLog(err.Error())
  2935. }
  2936. theStartTIme = theTime.Unix()
  2937. }
  2938. var theEndtTIme int64
  2939. if len(end_time) > 0 {
  2940. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2941. if err != nil {
  2942. utils.ErrorLog(err.Error())
  2943. }
  2944. theEndtTIme = theTime.Unix()
  2945. }
  2946. adminUserInfo := this.GetAdminUserInfo()
  2947. orgId := adminUserInfo.CurrentOrgId
  2948. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  2949. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  2950. if err != nil {
  2951. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2952. return
  2953. }
  2954. this.ServeSuccessJSON(map[string]interface{}{
  2955. "list": list,
  2956. "partitions": partitions,
  2957. })
  2958. }
  2959. func (this *ScheduleApiController) GetAllZones() {
  2960. adminUserInfo := this.GetAdminUserInfo()
  2961. orgId := adminUserInfo.CurrentOrgId
  2962. zones, err := service.GetAllZoneOne(orgId)
  2963. if err != nil {
  2964. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2965. return
  2966. }
  2967. this.ServeSuccessJSON(map[string]interface{}{
  2968. "zones": zones,
  2969. })
  2970. }
  2971. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  2972. adminUserInfo := this.GetAdminUserInfo()
  2973. orgId := adminUserInfo.CurrentOrgId
  2974. start_time, _ := this.GetInt64("start_time")
  2975. fmt.Println("start_time", start_time)
  2976. end_time, _ := this.GetInt64("end_time")
  2977. fmt.Println("end_time", end_time)
  2978. copy_startime, _ := this.GetInt64("copy_startime")
  2979. fmt.Println("copy_startime", copy_startime)
  2980. copy_endtime, _ := this.GetInt64("copy_endtime")
  2981. //获取本周患者排班
  2982. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  2983. //先清除复制周的排班
  2984. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  2985. fmt.Println(errcode)
  2986. var err error
  2987. for _, item := range schedules {
  2988. //fmt.Println(item.StartTime+604800)
  2989. //礼拜1
  2990. if item.ScheduleWeek == 1 {
  2991. item.ScheduleDate = copy_startime
  2992. }
  2993. if item.ScheduleWeek == 2 {
  2994. item.ScheduleDate = copy_startime + 86400
  2995. }
  2996. if item.ScheduleWeek == 3 {
  2997. item.ScheduleDate = copy_startime + 172800
  2998. }
  2999. if item.ScheduleWeek == 4 {
  3000. item.ScheduleDate = copy_startime + 259200
  3001. }
  3002. if item.ScheduleWeek == 5 {
  3003. item.ScheduleDate = copy_startime + 345600
  3004. }
  3005. if item.ScheduleWeek == 6 {
  3006. item.ScheduleDate = copy_startime + 432000
  3007. }
  3008. //礼拜天
  3009. if item.ScheduleWeek == 7 {
  3010. item.ScheduleDate = copy_endtime
  3011. }
  3012. schedule := models.XtSchedule{
  3013. UserOrgId: item.UserOrgId,
  3014. PartitionId: item.PartitionId,
  3015. BedId: item.BedId,
  3016. PatientId: item.PatientId,
  3017. ScheduleDate: item.ScheduleDate,
  3018. ScheduleType: item.ScheduleType,
  3019. ScheduleWeek: item.ScheduleWeek,
  3020. ModeId: item.ModeId,
  3021. Status: 1,
  3022. CreatedTime: time.Now().Unix(),
  3023. }
  3024. var DialysisMachineName string
  3025. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3026. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  3027. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  3028. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  3029. if filedRecordOne.IsShow == 1 {
  3030. DialysisMachineName = so.DialysisDialyszers
  3031. }
  3032. if filedRecordThree.IsShow == 1 {
  3033. if len(DialysisMachineName) > 0 {
  3034. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3035. } else {
  3036. DialysisMachineName = so.DialyzerPerfusionApparatus
  3037. }
  3038. }
  3039. if filedRecordTwo.IsShow == 1 {
  3040. if len(DialysisMachineName) > 0 {
  3041. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3042. } else {
  3043. DialysisMachineName = so.DialysisIrrigation
  3044. }
  3045. }
  3046. schedule.DialysisMachineName = DialysisMachineName
  3047. schedule.IsExport = 4000
  3048. err = service.AddPatientSchedule(&schedule)
  3049. }
  3050. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3051. timeStr := time.Now().Format("2006-01-02")
  3052. timeLayout := "2006-01-02 15:04:05"
  3053. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3054. timenow := timeStringToTime.Unix()
  3055. for _, it := range patientList {
  3056. service.UpdateScheduleByDeathTime(it.ID, timenow)
  3057. service.UpdateScheduleItemByPatientId(it.ID)
  3058. }
  3059. if err != nil {
  3060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3061. return
  3062. }
  3063. this.ServeSuccessJSON(map[string]interface{}{
  3064. "msg": "msg",
  3065. })
  3066. return
  3067. //查询复制中的排班日期是否存在
  3068. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  3069. //
  3070. //if errcode == gorm.ErrRecordNotFound {
  3071. // //如果没有直接新增
  3072. //
  3073. // for _, item := range schedules {
  3074. // //fmt.Println(item.StartTime+604800)
  3075. // //礼拜1
  3076. // if item.ScheduleWeek == 1 {
  3077. // item.ScheduleDate = copy_startime
  3078. // }
  3079. // if item.ScheduleWeek == 2 {
  3080. // item.ScheduleDate = copy_startime + 86400
  3081. // }
  3082. // if item.ScheduleWeek == 3 {
  3083. // item.ScheduleDate = copy_startime + 172800
  3084. // }
  3085. // if item.ScheduleWeek == 4 {
  3086. // item.ScheduleDate = copy_startime + 259200
  3087. // }
  3088. // if item.ScheduleWeek == 5 {
  3089. // item.ScheduleDate = copy_startime + 345600
  3090. // }
  3091. //
  3092. // if item.ScheduleWeek == 6 {
  3093. // item.ScheduleDate = copy_startime + 432000
  3094. // }
  3095. // //礼拜天
  3096. // if item.ScheduleWeek == 0 {
  3097. // item.ScheduleDate = copy_endtime
  3098. // }
  3099. // schedule := models.XtSchedule{
  3100. // UserOrgId: item.UserOrgId,
  3101. // PartitionId: item.PartitionId,
  3102. // BedId: item.BedId,
  3103. // PatientId: item.PatientId,
  3104. // ScheduleDate: item.ScheduleDate,
  3105. // ScheduleType: item.ScheduleType,
  3106. // ScheduleWeek: item.ScheduleWeek,
  3107. // ModeId: item.ModeId,
  3108. // Status: 1,
  3109. // CreatedTime: time.Now().Unix(),
  3110. // }
  3111. //
  3112. // err := service.AddPatientSchedule(&schedule)
  3113. // if err != nil {
  3114. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3115. // return
  3116. // }
  3117. // this.ServeSuccessJSON(map[string]interface{}{
  3118. // "schedule": schedule,
  3119. // })
  3120. // }
  3121. //} else if errcode == nil {
  3122. //
  3123. // //先清除复制周的排班
  3124. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3125. // fmt.Println(errcode)
  3126. // for _, item := range schedules {
  3127. // //fmt.Println(item.StartTime+604800)
  3128. // //礼拜1
  3129. // if item.ScheduleWeek == 1 {
  3130. // item.ScheduleDate = copy_startime
  3131. // }
  3132. // if item.ScheduleWeek == 2 {
  3133. // item.ScheduleDate = copy_startime + 86400
  3134. // }
  3135. // if item.ScheduleWeek == 3 {
  3136. // item.ScheduleDate = copy_startime + 172800
  3137. // }
  3138. // if item.ScheduleWeek == 4 {
  3139. // item.ScheduleDate = copy_startime + 259200
  3140. // }
  3141. // if item.ScheduleWeek == 5 {
  3142. // item.ScheduleDate = copy_startime + 345600
  3143. // }
  3144. //
  3145. // if item.ScheduleWeek == 6 {
  3146. // item.ScheduleDate = copy_startime + 432000
  3147. // }
  3148. // //礼拜天
  3149. // if item.ScheduleWeek == 0 {
  3150. // item.ScheduleDate = copy_endtime
  3151. // }
  3152. // schedule := models.XtSchedule{
  3153. // UserOrgId: item.UserOrgId,
  3154. // PartitionId: item.PartitionId,
  3155. // BedId: item.BedId,
  3156. // PatientId: item.PatientId,
  3157. // ScheduleDate: item.ScheduleDate,
  3158. // ScheduleType: item.ScheduleType,
  3159. // ScheduleWeek: item.ScheduleWeek,
  3160. // ModeId: item.ModeId,
  3161. // Status: 1,
  3162. // CreatedTime: time.Now().Unix(),
  3163. // }
  3164. //
  3165. // err := service.AddPatientSchedule(&schedule)
  3166. // if err != nil {
  3167. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3168. // return
  3169. // }
  3170. // this.ServeSuccessJSON(map[string]interface{}{
  3171. // "schedule": schedule,
  3172. // })
  3173. // }
  3174. //}
  3175. }
  3176. func (this *ScheduleApiController) SaveRemindPrint() {
  3177. id, _ := this.GetInt64("id")
  3178. anticoagulants, _ := this.GetInt64("anticoagulant")
  3179. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  3180. classes, _ := this.GetInt64("classes")
  3181. dialyzers, _ := this.GetInt64("dialyzers")
  3182. doctor_advice, _ := this.GetInt64("doctor_advice")
  3183. mode, _ := this.GetInt64("mode")
  3184. name, _ := this.GetInt64("name")
  3185. number, _ := this.GetInt64("number")
  3186. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  3187. prescription_status, _ := this.GetInt64("prescription_status")
  3188. week, _ := this.GetInt64("week")
  3189. zone, _ := this.GetInt64("zone")
  3190. adminUserInfo := this.GetAdminUserInfo()
  3191. orgId := adminUserInfo.CurrentOrgId
  3192. setting := models.XtRemindPrintSetting{
  3193. Anticoagulant: anticoagulants,
  3194. Classes: classes,
  3195. AnticoagulantZongliang: anticoagulant_zongliang,
  3196. Dialyzers: dialyzers,
  3197. DoctorAdvice: doctor_advice,
  3198. Mode: mode,
  3199. Name: name,
  3200. Number: number,
  3201. PerfusionApparatus: perfusion_apparatus,
  3202. PrescriptionStatus: prescription_status,
  3203. Week: week,
  3204. Zone: zone,
  3205. UserOrgId: orgId,
  3206. Status: 1,
  3207. Ctime: time.Now().Unix(),
  3208. }
  3209. _, errcode := service.GetSettingById(id)
  3210. if errcode == gorm.ErrRecordNotFound {
  3211. err := service.CreateSetting(&setting)
  3212. if err != nil {
  3213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3214. return
  3215. }
  3216. this.ServeSuccessJSON(map[string]interface{}{
  3217. "setting": setting,
  3218. })
  3219. } else if errcode == nil {
  3220. err := service.UpdatedRemindPrint(&setting, id)
  3221. if err != nil {
  3222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3223. return
  3224. }
  3225. this.ServeSuccessJSON(map[string]interface{}{
  3226. "setting": setting,
  3227. })
  3228. }
  3229. }
  3230. func (this *ScheduleApiController) GetRemindPrintList() {
  3231. adminUserInfo := this.GetAdminUserInfo()
  3232. orgId := adminUserInfo.CurrentOrgId
  3233. list, err := service.GetRemindPrintList(orgId)
  3234. if err != nil {
  3235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3236. return
  3237. }
  3238. this.ServeSuccessJSON(map[string]interface{}{
  3239. "list": list,
  3240. })
  3241. }
  3242. func (this *ScheduleApiController) GetBloodScheduleList() {
  3243. week_type, _ := this.GetInt64("week_type", -1)
  3244. week_time, _ := this.GetInt64("week_time")
  3245. zones := this.GetString("zone")
  3246. zone := strings.Split(zones, ",")
  3247. thisTime := time.Now()
  3248. weekDay := int(thisTime.Weekday())
  3249. if weekDay == 0 {
  3250. weekDay = 7
  3251. }
  3252. weekEnd := 7 - weekDay
  3253. weekStart := weekEnd - 6
  3254. weekTitle := make([]string, 0)
  3255. days := make([]string, 0)
  3256. for index := weekStart; index <= weekEnd; index++ {
  3257. theDay := thisTime.AddDate(0, 0, index)
  3258. indexYear, indexMonthTime, indexDay := theDay.Date()
  3259. indexMonth := int(indexMonthTime)
  3260. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3261. weekTitle = append(weekTitle, indexWeek)
  3262. days = append(days, theDay.Format("2006-01-02"))
  3263. }
  3264. fmt.Println(days)
  3265. var targetDayStr string
  3266. var startTime string
  3267. switch week_type {
  3268. case 0:
  3269. startTime = days[0]
  3270. targetDayStr = days[6]
  3271. break
  3272. case 1:
  3273. targetDayStr = days[0]
  3274. break
  3275. case 2:
  3276. targetDayStr = days[1]
  3277. break
  3278. case 3:
  3279. targetDayStr = days[2]
  3280. break
  3281. case 4:
  3282. targetDayStr = days[3]
  3283. break
  3284. case 5:
  3285. targetDayStr = days[4]
  3286. break
  3287. case 6:
  3288. targetDayStr = days[5]
  3289. break
  3290. case 7:
  3291. targetDayStr = days[6]
  3292. break
  3293. }
  3294. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  3295. if parseErr != nil {
  3296. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3297. return
  3298. }
  3299. orgId := this.GetAdminUserInfo().CurrentOrgId
  3300. if week_type > 0 {
  3301. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  3302. for _, item := range list {
  3303. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3304. item.XtDialysisOrderSix = order
  3305. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3306. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3307. item.DialysisPrescription = solution
  3308. }
  3309. }
  3310. if err != nil {
  3311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3312. return
  3313. }
  3314. this.ServeSuccessJSON(map[string]interface{}{
  3315. "list": list,
  3316. "day": targetDayStr,
  3317. })
  3318. }
  3319. if week_type == 0 {
  3320. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  3321. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  3322. for _, item := range list {
  3323. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3324. item.XtDialysisOrderSix = order
  3325. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3326. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3327. item.DialysisPrescription = solution
  3328. }
  3329. }
  3330. if err != nil {
  3331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3332. return
  3333. }
  3334. this.ServeSuccessJSON(map[string]interface{}{
  3335. "list": list,
  3336. "day": targetDayStr,
  3337. })
  3338. }
  3339. }
  3340. func (this *ScheduleApiController) GetPrintList() {
  3341. adminUserInfo := this.GetAdminUserInfo()
  3342. orgId := adminUserInfo.CurrentOrgId
  3343. list, err := service.GetRemindPrintList(orgId)
  3344. if err != nil {
  3345. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3346. return
  3347. }
  3348. this.ServeSuccessJSON(map[string]interface{}{
  3349. "list": list,
  3350. })
  3351. }
  3352. func (this *ScheduleApiController) GetAllZoneList() {
  3353. adminUserInfo := this.GetAdminUserInfo()
  3354. orgId := adminUserInfo.CurrentOrgId
  3355. zoneList, err := service.GetAllZoneOne(orgId)
  3356. if err != nil {
  3357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3358. return
  3359. }
  3360. this.ServeSuccessJSON(map[string]interface{}{
  3361. "zoneList": zoneList,
  3362. })
  3363. }
  3364. func (this *ScheduleApiController) GetPatientScheduleCount() {
  3365. patitionIdStr := this.GetString("partition_id")
  3366. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3367. ids := strings.Split(patitionIdStr, ",")
  3368. adminUserInfo := this.GetAdminUserInfo()
  3369. orgId := adminUserInfo.CurrentOrgId
  3370. thisTime := time.Now()
  3371. weekDay := int(thisTime.Weekday())
  3372. if week < 1 || week > 4 {
  3373. week = 2
  3374. }
  3375. if week == 1 {
  3376. thisTime = thisTime.AddDate(0, 0, -7)
  3377. } else if week == 3 {
  3378. thisTime = thisTime.AddDate(0, 0, 7)
  3379. } else if week == 4 {
  3380. thisTime = thisTime.AddDate(0, 0, 14)
  3381. }
  3382. if weekDay == 0 {
  3383. weekDay = 7
  3384. }
  3385. weekEnd := 7 - weekDay
  3386. weekStart := weekEnd - 6
  3387. weekTitle := make([]string, 0)
  3388. days := make([]string, 0)
  3389. for index := weekStart; index <= weekEnd; index++ {
  3390. theDay := thisTime.AddDate(0, 0, index)
  3391. indexYear, indexMonthTime, indexDay := theDay.Date()
  3392. indexMonth := int(indexMonthTime)
  3393. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3394. weekTitle = append(weekTitle, indexWeek)
  3395. days = append(days, theDay.Format("2006-01-02"))
  3396. }
  3397. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3398. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3399. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3400. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3401. timeLayout := "2006-01-02 15:04:05"
  3402. loc, _ := time.LoadLocation("Local")
  3403. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3404. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3405. weekStartPoint := theStarTime.Unix()
  3406. weekEndPoint := theEndTime.Unix()
  3407. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  3408. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  3409. if err != nil {
  3410. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3411. return
  3412. }
  3413. this.ServeSuccessJSON(map[string]interface{}{
  3414. "list": list,
  3415. "total": total,
  3416. })
  3417. }
  3418. func (c *ScheduleApiController) GetWeekPanelsOne() {
  3419. data, _ := c.GetInt64("data", 1)
  3420. patitionIdStr := c.GetString("patitionid")
  3421. ids := strings.Split(patitionIdStr, ",")
  3422. adminInfo := c.GetAdminUserInfo()
  3423. thisTime := time.Now()
  3424. year, monthTime, day := thisTime.Date()
  3425. month := int(monthTime)
  3426. _, theWeek := thisTime.ISOWeek()
  3427. weekDay := int(thisTime.Weekday())
  3428. if weekDay == 0 {
  3429. weekDay = 7
  3430. }
  3431. weekEnd := 7 - weekDay
  3432. weekStart := weekEnd - 6
  3433. weekDays := make([]string, 0)
  3434. for index := weekStart; index <= weekEnd; index++ {
  3435. theDay := thisTime.AddDate(0, 0, index)
  3436. indexYear, indexMonthTime, indexDay := theDay.Date()
  3437. indexMonth := int(indexMonthTime)
  3438. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3439. weekDays = append(weekDays, indexWeek)
  3440. }
  3441. returnData := map[string]interface{}{
  3442. "year": year,
  3443. "month": month,
  3444. "day": day,
  3445. "theWeek": theWeek,
  3446. "weekDay": weekDay,
  3447. "weekDays": weekDays,
  3448. }
  3449. if data == 1 {
  3450. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  3451. returnData["partitions"] = partitions
  3452. }
  3453. c.ServeSuccessJSON(returnData)
  3454. return
  3455. }
  3456. func (c *ScheduleApiController) GetScheduleOne() {
  3457. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3458. patitionIdStr := c.GetString("patitionid")
  3459. ids := strings.Split(patitionIdStr, ",")
  3460. fmt.Println("patitonStr", ids)
  3461. schedule_type, _ := c.GetInt64("schedule_type")
  3462. adminInfo := c.GetAdminUserInfo()
  3463. thisTime := time.Now()
  3464. today := thisTime.Format("2006-01-02")
  3465. if week < 1 || week > 4 {
  3466. week = 2
  3467. }
  3468. if week == 1 {
  3469. thisTime = thisTime.AddDate(0, 0, -7)
  3470. } else if week == 3 {
  3471. thisTime = thisTime.AddDate(0, 0, 7)
  3472. } else if week == 4 {
  3473. thisTime = thisTime.AddDate(0, 0, 14)
  3474. }
  3475. weekDay := int(thisTime.Weekday())
  3476. if weekDay == 0 {
  3477. weekDay = 7
  3478. }
  3479. weekEnd := 7 - weekDay
  3480. weekStart := weekEnd - 6
  3481. weekTitle := make([]string, 0)
  3482. days := make([]string, 0)
  3483. for index := weekStart; index <= weekEnd; index++ {
  3484. theDay := thisTime.AddDate(0, 0, index)
  3485. indexYear, indexMonthTime, indexDay := theDay.Date()
  3486. indexMonth := int(indexMonthTime)
  3487. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3488. weekTitle = append(weekTitle, indexWeek)
  3489. days = append(days, theDay.Format("2006-01-02"))
  3490. }
  3491. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3492. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3493. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3494. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3495. timeLayout := "2006-01-02 15:04:05"
  3496. loc, _ := time.LoadLocation("Local")
  3497. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3498. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3499. weekStartPoint := theStarTime.Unix()
  3500. weekEndPoint := theEndTime.Unix()
  3501. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  3502. c.ServeSuccessJSON(map[string]interface{}{
  3503. "days": days,
  3504. "weekTitle": weekTitle,
  3505. "schdules": schdules,
  3506. "today": today,
  3507. })
  3508. return
  3509. }
  3510. func (c *ScheduleApiController) GetScheduleTwo() {
  3511. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3512. patitionIdStr := c.GetString("patitionid")
  3513. ids := strings.Split(patitionIdStr, ",")
  3514. schedule_type, _ := c.GetInt64("schedule_type")
  3515. adminInfo := c.GetAdminUserInfo()
  3516. weekDateStr := c.GetString("week_date")
  3517. WeekDayIds := strings.Split(weekDateStr, ",")
  3518. thisTime := time.Now()
  3519. today := thisTime.Format("2006-01-02")
  3520. if week < 1 || week > 4 {
  3521. week = 2
  3522. }
  3523. if week == 1 {
  3524. thisTime = thisTime.AddDate(0, 0, -7)
  3525. } else if week == 3 {
  3526. thisTime = thisTime.AddDate(0, 0, 7)
  3527. } else if week == 4 {
  3528. thisTime = thisTime.AddDate(0, 0, 14)
  3529. }
  3530. weekDay := int(thisTime.Weekday())
  3531. if weekDay == 0 {
  3532. weekDay = 7
  3533. }
  3534. weekEnd := 7 - weekDay
  3535. weekStart := weekEnd - 6
  3536. weekTitle := make([]string, 0)
  3537. days := make([]string, 0)
  3538. for index := weekStart; index <= weekEnd; index++ {
  3539. theDay := thisTime.AddDate(0, 0, index)
  3540. indexYear, indexMonthTime, indexDay := theDay.Date()
  3541. indexMonth := int(indexMonthTime)
  3542. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3543. weekTitle = append(weekTitle, indexWeek)
  3544. days = append(days, theDay.Format("2006-01-02"))
  3545. }
  3546. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3547. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3548. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3549. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3550. timeLayout := "2006-01-02 15:04:05"
  3551. loc, _ := time.LoadLocation("Local")
  3552. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3553. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3554. weekStartPoint := theStarTime.Unix()
  3555. weekEndPoint := theEndTime.Unix()
  3556. schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  3557. c.ServeSuccessJSON(map[string]interface{}{
  3558. "days": days,
  3559. "weekTitle": weekTitle,
  3560. "schdules": schdules,
  3561. "today": today,
  3562. })
  3563. return
  3564. }
  3565. func (c *ScheduleApiController) SaveScheduleTemplate() {
  3566. template_id, _ := c.GetInt64("template_id")
  3567. orgId := c.GetAdminUserInfo().CurrentOrgId
  3568. template := models.ScheduleTemplate{
  3569. TemplateId: template_id,
  3570. UserOrgId: orgId,
  3571. Status: 1,
  3572. Ctime: time.Now().Unix(),
  3573. }
  3574. _, errcodes := service.GetScheudleTemplateById(orgId)
  3575. if errcodes == gorm.ErrRecordNotFound {
  3576. service.CreateXtscheduleTemplate(&template)
  3577. } else if errcodes == nil {
  3578. service.UpdateXtScheduleTemplate(&template, orgId)
  3579. }
  3580. c.ServeSuccessJSON(map[string]interface{}{
  3581. "template": template,
  3582. })
  3583. return
  3584. }
  3585. func (c *ScheduleApiController) GetScheduleTemplate() {
  3586. adminUserInfo := c.GetAdminUserInfo()
  3587. orgId := adminUserInfo.CurrentOrgId
  3588. template, _ := service.GetScheduleTemplate(orgId)
  3589. c.ServeSuccessJSON(map[string]interface{}{
  3590. "template": template,
  3591. })
  3592. return
  3593. }
  3594. func (c *ScheduleApiController) ChangeFuncPrint() {
  3595. adminUserInfo := c.GetAdminUserInfo()
  3596. orgId := adminUserInfo.CurrentOrgId
  3597. is_open, _ := c.GetInt64("is_open")
  3598. dataPrint := models.XtDataPrint{
  3599. UserOrgId: orgId,
  3600. IsOpen: is_open,
  3601. Status: 1,
  3602. Ctime: time.Now().Unix(),
  3603. }
  3604. _, errcode := service.GetDataPrintByOrgId(orgId)
  3605. if errcode == gorm.ErrRecordNotFound {
  3606. service.CreateDataPrint(&dataPrint)
  3607. c.ServeSuccessJSON(map[string]interface{}{
  3608. "dataPrint": dataPrint,
  3609. })
  3610. return
  3611. } else if errcode == nil {
  3612. service.UpdteDataPrint(orgId, &dataPrint)
  3613. c.ServeSuccessJSON(map[string]interface{}{
  3614. "dataPrint": dataPrint,
  3615. })
  3616. return
  3617. }
  3618. }
  3619. func (c *ScheduleApiController) GetDataPrint() {
  3620. adminUserInfo := c.GetAdminUserInfo()
  3621. orgId := adminUserInfo.CurrentOrgId
  3622. dataPrint, _ := service.GetDataPrint(orgId)
  3623. c.ServeSuccessJSON(map[string]interface{}{
  3624. "dataPrint": dataPrint,
  3625. })
  3626. return
  3627. }
  3628. func (c *ScheduleApiController) GetNextWeekPanels() {
  3629. start_time, _ := c.GetInt64("start_time")
  3630. fmt.Println("start_time", start_time)
  3631. end_time, _ := c.GetInt64("end_time")
  3632. fmt.Println("end_time", end_time)
  3633. orgId := c.GetAdminUserInfo().CurrentOrgId
  3634. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  3635. c.ServeSuccessJSON(map[string]interface{}{
  3636. "schedule": schedule,
  3637. })
  3638. }
  3639. func (c *ScheduleApiController) SynchroSchedule() {
  3640. template_id, _ := c.GetInt64("template_id")
  3641. copy_startime, _ := c.GetInt64("copy_startime")
  3642. copy_endtime, _ := c.GetInt64("copy_endtime")
  3643. orgId := c.GetAdminUserInfo().CurrentOrgId
  3644. //根据模板ID获取模板数据
  3645. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  3646. fmt.Println(len(list))
  3647. //数据去重操作
  3648. list = RemoveRepeatedScheduleTemplate(list)
  3649. recordDateStr := time.Now().Format("2006-01-02")
  3650. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3651. nowtime := recordDate.Unix()
  3652. fmt.Println("今日时间", nowtime)
  3653. fmt.Println("后期日期", copy_startime)
  3654. var tuesday int64
  3655. var wednesday int64
  3656. var thursday int64
  3657. var friday int64
  3658. var saturday int64
  3659. //
  3660. //如果选择的开始日期大于当前日期
  3661. if copy_startime > nowtime {
  3662. //清空该时间段的所有排班数据
  3663. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  3664. tuesday = copy_startime + 86400
  3665. wednesday = copy_startime + 172800
  3666. thursday = copy_startime + 259200
  3667. friday = copy_startime + 345600
  3668. saturday = copy_startime + 432000
  3669. for _, item := range list {
  3670. if item.Weekday == 1 {
  3671. item.ScheduleDate = copy_startime
  3672. }
  3673. if item.Weekday == 2 {
  3674. item.ScheduleDate = tuesday
  3675. }
  3676. if item.Weekday == 3 {
  3677. item.ScheduleDate = wednesday
  3678. }
  3679. if item.Weekday == 4 {
  3680. item.ScheduleDate = thursday
  3681. }
  3682. if item.Weekday == 5 {
  3683. item.ScheduleDate = friday
  3684. }
  3685. if item.Weekday == 6 {
  3686. item.ScheduleDate = saturday
  3687. }
  3688. if item.Weekday == 7 {
  3689. item.ScheduleDate = copy_endtime
  3690. }
  3691. //根据床位号获取区号
  3692. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3693. item.ZoneId = number.ZoneID
  3694. }
  3695. for _, item := range list {
  3696. schedule := models.XtSchedule{
  3697. UserOrgId: orgId,
  3698. PartitionId: item.ZoneId,
  3699. BedId: item.DeviceNumberID,
  3700. PatientId: item.PatientID,
  3701. ScheduleDate: item.ScheduleDate,
  3702. ScheduleType: item.TimeType,
  3703. ScheduleWeek: item.Weekday,
  3704. ModeId: item.TreatMode,
  3705. Status: 1,
  3706. CreatedTime: time.Now().Unix(),
  3707. UpdatedTime: 0,
  3708. IsExport: 2000,
  3709. }
  3710. var DialysisMachineName string
  3711. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3712. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3713. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3714. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3715. if filedRecordOne.IsShow == 1 {
  3716. DialysisMachineName = so.DialysisDialyszers
  3717. }
  3718. if filedRecordThree.IsShow == 1 {
  3719. if len(DialysisMachineName) > 0 {
  3720. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3721. } else {
  3722. DialysisMachineName = so.DialyzerPerfusionApparatus
  3723. }
  3724. }
  3725. if filedRecordTwo.IsShow == 1 {
  3726. if len(DialysisMachineName) > 0 {
  3727. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3728. } else {
  3729. DialysisMachineName = so.DialysisIrrigation
  3730. }
  3731. }
  3732. schedule.DialysisMachineName = DialysisMachineName
  3733. service.CreatePatientSchedule(&schedule)
  3734. }
  3735. }
  3736. //如果选择的日期小于当前日期,只同步今日以后的数据
  3737. if copy_startime <= nowtime {
  3738. //清空今日以后的数据
  3739. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  3740. var tuesday int64
  3741. var wednesday int64
  3742. var thursday int64
  3743. var friday int64
  3744. var saturday int64
  3745. tuesday = copy_startime + 86400
  3746. wednesday = copy_startime + 172800
  3747. thursday = copy_startime + 259200
  3748. friday = copy_startime + 345600
  3749. saturday = copy_startime + 432000
  3750. for _, item := range list {
  3751. if item.Weekday == 1 {
  3752. item.ScheduleDate = copy_startime
  3753. }
  3754. if item.Weekday == 2 {
  3755. item.ScheduleDate = tuesday
  3756. }
  3757. if item.Weekday == 3 {
  3758. item.ScheduleDate = wednesday
  3759. }
  3760. if item.Weekday == 4 {
  3761. item.ScheduleDate = thursday
  3762. }
  3763. if item.Weekday == 5 {
  3764. item.ScheduleDate = friday
  3765. }
  3766. if item.Weekday == 6 {
  3767. item.ScheduleDate = saturday
  3768. }
  3769. if item.Weekday == 7 {
  3770. item.ScheduleDate = copy_endtime
  3771. }
  3772. //根据床位号获取区号
  3773. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3774. item.ZoneId = number.ZoneID
  3775. }
  3776. for _, item := range list {
  3777. // 同步今日以后的数据
  3778. if item.ScheduleDate > nowtime {
  3779. schedule := models.XtSchedule{
  3780. UserOrgId: orgId,
  3781. PartitionId: item.ZoneId,
  3782. BedId: item.DeviceNumberID,
  3783. PatientId: item.PatientID,
  3784. ScheduleDate: item.ScheduleDate,
  3785. ScheduleType: item.TimeType,
  3786. ScheduleWeek: item.Weekday,
  3787. ModeId: item.TreatMode,
  3788. Status: 1,
  3789. CreatedTime: time.Now().Unix(),
  3790. UpdatedTime: 0,
  3791. }
  3792. var DialysisMachineName string
  3793. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3794. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3795. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3796. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3797. if filedRecordOne.IsShow == 1 {
  3798. DialysisMachineName = so.DialysisDialyszers
  3799. }
  3800. if filedRecordThree.IsShow == 1 {
  3801. if len(DialysisMachineName) > 0 {
  3802. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3803. } else {
  3804. DialysisMachineName = so.DialyzerPerfusionApparatus
  3805. }
  3806. }
  3807. if filedRecordTwo.IsShow == 1 {
  3808. if len(schedule.DialysisMachineName) > 0 {
  3809. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3810. } else {
  3811. DialysisMachineName = so.DialysisIrrigation
  3812. }
  3813. }
  3814. schedule.DialysisMachineName = DialysisMachineName
  3815. service.CreatePatientSchedule(&schedule)
  3816. }
  3817. }
  3818. }
  3819. returnData := make(map[string]interface{}, 0)
  3820. returnData["list"] = list
  3821. c.ServeSuccessJSON(returnData)
  3822. return
  3823. }
  3824. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  3825. orgId := c.GetAdminUserInfo().CurrentOrgId
  3826. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  3827. c.ServeSuccessJSON(map[string]interface{}{
  3828. "schedule": tempalate,
  3829. })
  3830. }
  3831. func (c *ScheduleApiController) GetSolutionSchedule() {
  3832. orgId := c.GetAdminUserInfo().CurrentOrgId
  3833. solution, _ := service.GetSolutionSchedule(orgId)
  3834. c.ServeSuccessJSON(map[string]interface{}{
  3835. "solution": solution,
  3836. })
  3837. return
  3838. }
  3839. func RemoveRepeatedScheduleTemplate(arr []*models.VmPatientScheduleTemplateItem) (newArr []*models.VmPatientScheduleTemplateItem) {
  3840. newArr = make([]*models.VmPatientScheduleTemplateItem, 0)
  3841. for i := 0; i < len(arr); i++ {
  3842. repeat := false
  3843. for j := i + 1; j < len(arr); j++ {
  3844. if arr[i].TemplateID == arr[j].TemplateID && arr[i].PatientID == arr[j].PatientID && arr[i].Weekday == arr[j].Weekday {
  3845. repeat = true
  3846. break
  3847. }
  3848. }
  3849. if !repeat {
  3850. newArr = append(newArr, arr[i])
  3851. }
  3852. }
  3853. return
  3854. }