schedule_api_controller.go 140KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425
  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. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, ids)
  1003. returnData["partitions"] = partitions
  1004. }
  1005. c.ServeSuccessJSON(returnData)
  1006. return
  1007. }
  1008. func (c *ScheduleApiController) GetSchedules() {
  1009. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  1010. partition_id, _ := c.GetInt64("partition_id")
  1011. schedule_type, _ := c.GetInt64("schedule_type")
  1012. adminInfo := c.GetAdminUserInfo()
  1013. thisTime := time.Now()
  1014. today := thisTime.Format("2006-01-02")
  1015. if week < 1 || week > 4 {
  1016. week = 2
  1017. }
  1018. if week == 1 {
  1019. thisTime = thisTime.AddDate(0, 0, -7)
  1020. } else if week == 3 {
  1021. thisTime = thisTime.AddDate(0, 0, 7)
  1022. } else if week == 4 {
  1023. thisTime = thisTime.AddDate(0, 0, 14)
  1024. }
  1025. weekDay := int(thisTime.Weekday())
  1026. if weekDay == 0 {
  1027. weekDay = 7
  1028. }
  1029. weekEnd := 7 - weekDay
  1030. weekStart := weekEnd - 6
  1031. weekTitle := make([]string, 0)
  1032. days := make([]string, 0)
  1033. for index := weekStart; index <= weekEnd; index++ {
  1034. theDay := thisTime.AddDate(0, 0, index)
  1035. indexYear, indexMonthTime, indexDay := theDay.Date()
  1036. indexMonth := int(indexMonthTime)
  1037. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1038. weekTitle = append(weekTitle, indexWeek)
  1039. days = append(days, theDay.Format("2006-01-02"))
  1040. }
  1041. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  1042. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  1043. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1044. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1045. timeLayout := "2006-01-02 15:04:05"
  1046. loc, _ := time.LoadLocation("Local")
  1047. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1048. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1049. weekStartPoint := theStarTime.Unix()
  1050. weekEndPoint := theEndTime.Unix()
  1051. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  1052. c.ServeSuccessJSON(map[string]interface{}{
  1053. "days": days,
  1054. "weekTitle": weekTitle,
  1055. "schdules": schdules,
  1056. "today": today,
  1057. })
  1058. return
  1059. }
  1060. func (c *ScheduleApiController) GetPatients() {
  1061. keywords := c.GetString("keywords", "")
  1062. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  1063. contagion, _ := c.GetInt64("contagion", 0)
  1064. adminInfo := c.GetAdminUserInfo()
  1065. thisTime := time.Now()
  1066. weekDay := int(thisTime.Weekday())
  1067. if weekDay == 0 {
  1068. weekDay = 7
  1069. }
  1070. thisWeekEnd := 7 - weekDay
  1071. weekStartPoint := thisWeekEnd - 6
  1072. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  1073. weekEndPoint := thisWeekEnd + 7
  1074. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  1075. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  1076. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1077. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1078. fmt.Println(weekStartTime, weekEndTime)
  1079. timeLayout := "2006-01-02 15:04:05"
  1080. loc, _ := time.LoadLocation("Local")
  1081. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1082. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1083. weekStart := theStarTime.Unix()
  1084. weekEnd := theEndTime.Unix()
  1085. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  1086. fmt.Println("patinets23233232323232232322323wode", patients)
  1087. c.ServeSuccessJSON(map[string]interface{}{
  1088. "patients": patients,
  1089. })
  1090. return
  1091. }
  1092. func (c *ScheduleApiController) CreateSchedule() {
  1093. patientID, _ := c.GetInt64("patient_id", 0)
  1094. if patientID <= 0 {
  1095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1096. return
  1097. }
  1098. adminUserInfo := c.GetAdminUserInfo()
  1099. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  1100. if patientInfo.ID == 0 {
  1101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1102. return
  1103. }
  1104. var schedule models.Schedule
  1105. dataBody := make(map[string]interface{}, 0)
  1106. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1107. if err != nil {
  1108. utils.ErrorLog(err.Error())
  1109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1110. return
  1111. }
  1112. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  1113. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1114. return
  1115. }
  1116. scheduleDate, _ := dataBody["schedule_date"].(string)
  1117. if len(scheduleDate) == 0 {
  1118. utils.ErrorLog("len(schedule_date) == 0")
  1119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1120. return
  1121. }
  1122. timeLayout := "2006-01-02"
  1123. loc, _ := time.LoadLocation("Local")
  1124. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  1125. if err != nil {
  1126. utils.ErrorLog(err.Error())
  1127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1128. return
  1129. }
  1130. schedule.ScheduleDate = theTime.Unix()
  1131. timeNow := time.Now().Format("2006-01-02")
  1132. if timeNow > scheduleDate {
  1133. utils.ErrorLog(timeNow)
  1134. utils.ErrorLog(scheduleDate)
  1135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1136. return
  1137. }
  1138. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1139. utils.ErrorLog("schedule_type")
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1141. return
  1142. }
  1143. scheduleType := int64(dataBody["schedule_type"].(float64))
  1144. if scheduleType < 1 || scheduleType > 3 {
  1145. utils.ErrorLog("scheduleType < 3")
  1146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1147. return
  1148. }
  1149. schedule.ScheduleType = scheduleType
  1150. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1151. utils.ErrorLog("bed_id")
  1152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1153. return
  1154. }
  1155. bedId := int64(dataBody["bed_id"].(float64))
  1156. if bedId < 1 {
  1157. utils.ErrorLog("bedId < 1")
  1158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1159. return
  1160. }
  1161. schedule.BedId = bedId
  1162. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1163. utils.ErrorLog("partition_id")
  1164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1165. return
  1166. }
  1167. partitionId := int64(dataBody["partition_id"].(float64))
  1168. if partitionId < 1 {
  1169. utils.ErrorLog("partitionId < 1")
  1170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1171. return
  1172. }
  1173. schedule.PartitionId = partitionId
  1174. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1175. utils.ErrorLog("schedule_week")
  1176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1177. return
  1178. }
  1179. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1180. if scheduleWeek < 1 || scheduleWeek > 7 {
  1181. utils.ErrorLog("scheduleWeek < 1")
  1182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1183. return
  1184. }
  1185. schedule.ScheduleWeek = scheduleWeek
  1186. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1187. utils.ErrorLog("mode_id")
  1188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1189. return
  1190. }
  1191. modeId := int64(dataBody["mode_id"].(float64))
  1192. if modeId < 1 && modeId > 14 {
  1193. utils.ErrorLog("modeId < 1")
  1194. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1195. return
  1196. }
  1197. schedule.ModeId = modeId
  1198. schedule.PatientId = patientID
  1199. schedule.CreatedTime = time.Now().Unix()
  1200. schedule.UpdatedTime = time.Now().Unix()
  1201. schedule.Status = 1
  1202. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1203. schedule.IsExport = 5
  1204. var DialysisMachineName string
  1205. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1206. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1207. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1208. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1209. if filedRecordOne.IsShow == 1 {
  1210. DialysisMachineName = so.DialysisDialyszers
  1211. }
  1212. if filedRecordThree.IsShow == 1 {
  1213. if len(DialysisMachineName) > 0 {
  1214. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1215. } else {
  1216. DialysisMachineName = so.DialyzerPerfusionApparatus
  1217. }
  1218. }
  1219. if filedRecordTwo.IsShow == 1 {
  1220. if len(DialysisMachineName) > 0 {
  1221. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1222. } else {
  1223. DialysisMachineName = so.DialysisIrrigation
  1224. }
  1225. }
  1226. schedule.DialysisMachineName = DialysisMachineName
  1227. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1228. if bed == nil {
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1230. return
  1231. }
  1232. if bed.ZoneID != schedule.PartitionId {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1234. return
  1235. }
  1236. scheduleDateStart := scheduleDate + " 00:00:00"
  1237. scheduleDateEnd := scheduleDate + " 23:59:59"
  1238. timeLayout = "2006-01-02 15:04:05"
  1239. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1240. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1241. startTime := theStartTime.Unix()
  1242. endTime := theEndTime.Unix()
  1243. //一天只有排班一次
  1244. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1245. if daySchedule.ID > 0 {
  1246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1247. return
  1248. }
  1249. //同天同位置只能排一个
  1250. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1253. return
  1254. }
  1255. if pointSchedule.ID > 0 {
  1256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1257. return
  1258. }
  1259. redis := service.RedisClient()
  1260. schedule.IsExport = 1000
  1261. err = service.CreateSchedule(&schedule)
  1262. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1263. redis.Set(key, "", time.Second)
  1264. //处方
  1265. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1266. redis.Set(keyOne, "", time.Second)
  1267. //医嘱
  1268. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1269. redis.Set(keyTwo, "", time.Second)
  1270. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1271. redis.Set(keySix, "", time.Second)
  1272. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1273. redis.Set(keyThree, "", time.Second)
  1274. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1275. redis.Set(keyFour, "", time.Second)
  1276. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1277. redis.Set(keyFive, "", time.Second)
  1278. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1279. redis.Set(keySeven, "", time.Second)
  1280. fmt.Println(err)
  1281. defer redis.Close()
  1282. if err != nil {
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  1284. return
  1285. }
  1286. schedule.Patient = patientInfo.Name
  1287. c.ServeSuccessJSON(map[string]interface{}{
  1288. "msg": "ok",
  1289. "schedule": schedule,
  1290. })
  1291. return
  1292. }
  1293. func (c *ScheduleApiController) DeleteSchedule() {
  1294. id, _ := c.GetInt64("id", 0)
  1295. if id <= 0 {
  1296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1297. return
  1298. }
  1299. adminINfo := c.GetAdminUserInfo()
  1300. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1301. timeNow := time.Now().Format("2006-01-02")
  1302. timeTemplate := "2006-01-02"
  1303. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1304. timeStr := tm.Format(timeTemplate)
  1305. if timeNow > timeStr {
  1306. utils.ErrorLog(timeNow)
  1307. utils.ErrorLog(timeStr)
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1309. return
  1310. }
  1311. if schedule == nil {
  1312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1313. return
  1314. }
  1315. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1316. if err != nil {
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1318. return
  1319. }
  1320. if order != nil {
  1321. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1322. return
  1323. }
  1324. schedule.Status = 0
  1325. schedule.UpdatedTime = time.Now().Unix()
  1326. err = service.UpdateSchedule(schedule)
  1327. redis := service.RedisClient()
  1328. //处方
  1329. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1330. redis.Set(keyOne, "", time.Second)
  1331. //医嘱
  1332. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1333. redis.Set(keyTwo, "", time.Second)
  1334. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1335. redis.Set(keySix, "", time.Second)
  1336. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1337. redis.Set(keyThree, "", time.Second)
  1338. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1339. redis.Set(keyFour, "", time.Second)
  1340. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1341. redis.Set(keyFive, "", time.Second)
  1342. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1343. redis.Set(keySeven, "", time.Second)
  1344. fmt.Println(err)
  1345. defer redis.Close()
  1346. if err != nil {
  1347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  1348. return
  1349. }
  1350. c.ServeSuccessJSON(map[string]interface{}{
  1351. "msg": "ok",
  1352. "schedule": &schedule,
  1353. })
  1354. }
  1355. func (c *ScheduleApiController) ChangeSchedule() {
  1356. id, _ := c.GetInt64("id", 0)
  1357. if id <= 0 {
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. adminINfo := c.GetAdminUserInfo()
  1362. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1363. if schedule == nil {
  1364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1365. return
  1366. }
  1367. dataBody := make(map[string]interface{}, 0)
  1368. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1369. if err != nil {
  1370. utils.ErrorLog(err.Error())
  1371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1372. return
  1373. }
  1374. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  1375. utils.ErrorLog("change_action")
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1377. return
  1378. }
  1379. changeAction := dataBody["change_action"].(string)
  1380. if changeAction == "change_mode" {
  1381. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1382. utils.ErrorLog("mode_id")
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  1384. return
  1385. }
  1386. modeId := int64(dataBody["mode_id"].(float64))
  1387. if modeId < 1 {
  1388. utils.ErrorLog("modeId < 1")
  1389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  1390. return
  1391. }
  1392. schedule.ModeId = modeId
  1393. so, _ := service.GetDialysisSolutionTwo(adminINfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1394. filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
  1395. filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
  1396. filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
  1397. var DialysisMachineName string
  1398. if filedRecordOne.IsShow == 1 {
  1399. DialysisMachineName = so.DialysisDialyszers
  1400. fmt.Println("1111")
  1401. fmt.Println(DialysisMachineName)
  1402. }
  1403. if filedRecordThree.IsShow == 1 {
  1404. if len(schedule.DialysisMachineName) > 0 {
  1405. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1406. fmt.Println("22222")
  1407. fmt.Println(DialysisMachineName)
  1408. } else {
  1409. DialysisMachineName = so.DialyzerPerfusionApparatus
  1410. fmt.Println("333333")
  1411. fmt.Println(DialysisMachineName)
  1412. }
  1413. }
  1414. if filedRecordTwo.IsShow == 1 {
  1415. if len(DialysisMachineName) > 0 {
  1416. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1417. fmt.Println("55555555")
  1418. fmt.Println(DialysisMachineName)
  1419. } else {
  1420. DialysisMachineName = so.DialysisIrrigation
  1421. fmt.Println("66666666")
  1422. fmt.Println(DialysisMachineName)
  1423. }
  1424. }
  1425. schedule.DialysisMachineName = DialysisMachineName
  1426. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1427. if err != nil {
  1428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1429. return
  1430. }
  1431. if order != nil {
  1432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  1433. return
  1434. }
  1435. } else if changeAction == "change_device" {
  1436. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1437. if err != nil {
  1438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1439. return
  1440. }
  1441. if order != nil {
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  1443. return
  1444. }
  1445. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1446. utils.ErrorLog("schedule_type")
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1448. return
  1449. }
  1450. scheduleType := int64(dataBody["schedule_type"].(float64))
  1451. if scheduleType < 1 || scheduleType > 3 {
  1452. utils.ErrorLog("scheduleType < 3")
  1453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1454. return
  1455. }
  1456. schedule.ScheduleType = scheduleType
  1457. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1458. utils.ErrorLog("bed_id")
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1460. return
  1461. }
  1462. bedId := int64(dataBody["bed_id"].(float64))
  1463. if bedId < 1 {
  1464. utils.ErrorLog("bedId < 1")
  1465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1466. return
  1467. }
  1468. schedule.BedId = bedId
  1469. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1470. utils.ErrorLog("partition_id")
  1471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1472. return
  1473. }
  1474. partitionId := int64(dataBody["partition_id"].(float64))
  1475. if partitionId < 1 {
  1476. utils.ErrorLog("partitionId < 1")
  1477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1478. return
  1479. }
  1480. schedule.PartitionId = partitionId
  1481. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  1482. if bed == nil {
  1483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1484. return
  1485. }
  1486. if bed.ZoneID != schedule.PartitionId {
  1487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1488. return
  1489. }
  1490. startTime := schedule.ScheduleDate
  1491. endTime := startTime + 86399
  1492. //一天只有排班一次
  1493. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  1494. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  1495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1496. return
  1497. }
  1498. //同天同位置只能排一个
  1499. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1500. if err != nil {
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1502. return
  1503. }
  1504. if pointSchedule.ID > 0 {
  1505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1506. return
  1507. }
  1508. } else {
  1509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1510. return
  1511. }
  1512. schedule.UpdatedTime = time.Now().Unix()
  1513. err = service.UpdateSchedule(schedule)
  1514. prescription := models.DialysisPrescription{
  1515. ModeId: schedule.ModeId,
  1516. }
  1517. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  1518. if errcode == gorm.ErrRecordNotFound {
  1519. if err != nil {
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1521. return
  1522. }
  1523. c.ServeSuccessJSON(map[string]interface{}{
  1524. "msg": "ok",
  1525. "schedule": &schedule,
  1526. })
  1527. } else if errcode == nil {
  1528. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  1529. if err != nil {
  1530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  1531. return
  1532. }
  1533. c.ServeSuccessJSON(map[string]interface{}{
  1534. "msg": "ok",
  1535. "schedule": &schedule,
  1536. })
  1537. }
  1538. }
  1539. // /api/schedule/print/initdata [get]
  1540. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  1541. func (this *ScheduleApiController) PrintInitData() {
  1542. dateStr := this.GetString("date")
  1543. //week_type, _ := this.GetInt64("type", 0)
  1544. var date *time.Time
  1545. if len(dateStr) == 0 {
  1546. now := time.Now()
  1547. date = &now
  1548. } else {
  1549. var parseErr error
  1550. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  1551. if parseErr != nil {
  1552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1553. return
  1554. }
  1555. }
  1556. adminUserInfo := this.GetAdminUserInfo()
  1557. // 获取本周的排班
  1558. var monday time.Time
  1559. var sunday time.Time
  1560. //switch week_type {
  1561. //case 1:
  1562. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  1563. // break
  1564. //case 2:
  1565. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  1566. //
  1567. // break
  1568. //case 3:
  1569. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  1570. // break
  1571. //}
  1572. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1573. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  1574. if getScheduleErr != nil {
  1575. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  1576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1577. return
  1578. }
  1579. thisTime := date
  1580. weekDay := int(thisTime.Weekday())
  1581. if weekDay == 0 {
  1582. weekDay = 7
  1583. }
  1584. weekEnd := 7 - weekDay
  1585. weekStart := weekEnd - 6
  1586. days := make([]string, 0)
  1587. for index := weekStart; index <= weekEnd; index++ {
  1588. theDay := thisTime.AddDate(0, 0, index)
  1589. days = append(days, theDay.Format("2006-01-02"))
  1590. }
  1591. this.ServeSuccessJSON(map[string]interface{}{
  1592. "total": total,
  1593. "schedules": schedules,
  1594. "monday": monday.Unix(),
  1595. "days": days,
  1596. })
  1597. }
  1598. func (this *ScheduleApiController) UrgentScheduleData() {
  1599. schedule_type, _ := this.GetInt("type", 0)
  1600. schedule_date := this.GetString("date")
  1601. var date *time.Time
  1602. if len(schedule_date) == 0 {
  1603. now := time.Now()
  1604. date = &now
  1605. } else {
  1606. var parseErr error
  1607. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  1608. if parseErr != nil {
  1609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1610. return
  1611. }
  1612. }
  1613. adminUserInfo := this.GetAdminUserInfo()
  1614. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1615. if getDeviceNumbersErr != nil {
  1616. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1617. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1618. return
  1619. }
  1620. // today := utils.ZeroHourTimeOfDay(time.Now())
  1621. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  1622. if getSchedulesErr != nil {
  1623. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  1624. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1625. return
  1626. }
  1627. this.ServeSuccessJSON(map[string]interface{}{
  1628. "device_numbers": deviceNumbers,
  1629. "schedules": schedules,
  1630. })
  1631. }
  1632. func (this *ScheduleApiController) SearchSchedulePatients() {
  1633. keywords := this.GetString("keywords")
  1634. week_type, _ := this.GetInt64("week_type", 0)
  1635. start_sch := this.GetString("start_sch")
  1636. end_sch := this.GetString("end_sch")
  1637. thisTime1 := time.Now()
  1638. thisTime2 := time.Now()
  1639. thisTime1 = thisTime1.AddDate(0, 0, 7)
  1640. thisTime2 = thisTime2.AddDate(0, 0, 14)
  1641. var start_time string
  1642. var end_time string
  1643. switch week_type {
  1644. case 1:
  1645. timeLayout := "2006-01-02"
  1646. loc, _ := time.LoadLocation("Local")
  1647. var startSchTime int64
  1648. if len(start_sch) > 0 {
  1649. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
  1650. startSchTime = theTime.Unix()
  1651. }
  1652. var endSchTime int64
  1653. if len(end_sch) > 0 {
  1654. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
  1655. endSchTime = theTime.Unix()
  1656. }
  1657. adminUserInfo := this.GetAdminUserInfo()
  1658. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
  1659. this.ServeSuccessJSON(map[string]interface{}{
  1660. "schdules": list,
  1661. })
  1662. break
  1663. case 2:
  1664. days := make([]string, 0)
  1665. weekDay1 := int(thisTime1.Weekday())
  1666. if weekDay1 == 0 {
  1667. weekDay1 = 7
  1668. }
  1669. weekEnd1 := 7 - weekDay1
  1670. weekStart1 := weekEnd1 - 6
  1671. for index := weekStart1; index <= weekEnd1; index++ {
  1672. fmt.Println(index)
  1673. theDay := thisTime1.AddDate(0, 0, index)
  1674. days = append(days, theDay.Format("2006-01-02"))
  1675. }
  1676. fmt.Println(days)
  1677. start_time = days[0]
  1678. end_time = days[len(days)-1]
  1679. timeLayout := "2006-01-02"
  1680. loc, _ := time.LoadLocation("Local")
  1681. var theStartTime int64
  1682. if len(start_time) > 0 {
  1683. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1684. theStartTime = theTime.Unix()
  1685. }
  1686. var theEndtTime int64
  1687. if len(end_time) > 0 {
  1688. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1689. theEndtTime = theTime.Unix()
  1690. }
  1691. adminUserInfo := this.GetAdminUserInfo()
  1692. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1693. this.ServeSuccessJSON(map[string]interface{}{
  1694. "schdules": list,
  1695. })
  1696. break
  1697. case 3:
  1698. days := make([]string, 0)
  1699. weekDay2 := int(thisTime2.Weekday())
  1700. if weekDay2 == 0 {
  1701. weekDay2 = 7
  1702. }
  1703. weekEnd2 := 7 - weekDay2
  1704. weekStart2 := weekEnd2 - 6
  1705. for index := weekStart2; index <= weekEnd2; index++ {
  1706. theDay := thisTime2.AddDate(0, 0, index)
  1707. days = append(days, theDay.Format("2006-01-02"))
  1708. }
  1709. start_time = days[0]
  1710. end_time = days[len(days)-1]
  1711. timeLayout := "2006-01-02"
  1712. loc, _ := time.LoadLocation("Local")
  1713. var theStartTime int64
  1714. if len(start_time) > 0 {
  1715. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1716. theStartTime = theTime.Unix()
  1717. }
  1718. var theEndtTime int64
  1719. if len(end_time) > 0 {
  1720. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1721. theEndtTime = theTime.Unix()
  1722. }
  1723. adminUserInfo := this.GetAdminUserInfo()
  1724. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  1725. this.ServeSuccessJSON(map[string]interface{}{
  1726. "schdules": list,
  1727. })
  1728. break
  1729. }
  1730. }
  1731. func (this *ScheduleApiController) GetWeekDaySchedule() {
  1732. week_type, _ := this.GetInt64("week_type", -1)
  1733. week_time, _ := this.GetInt64("week_time")
  1734. thisTime := time.Now()
  1735. weekDay := int(thisTime.Weekday())
  1736. if weekDay == 0 {
  1737. weekDay = 7
  1738. }
  1739. weekEnd := 7 - weekDay
  1740. weekStart := weekEnd - 6
  1741. weekTitle := make([]string, 0)
  1742. days := make([]string, 0)
  1743. for index := weekStart; index <= weekEnd; index++ {
  1744. theDay := thisTime.AddDate(0, 0, index)
  1745. indexYear, indexMonthTime, indexDay := theDay.Date()
  1746. indexMonth := int(indexMonthTime)
  1747. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1748. weekTitle = append(weekTitle, indexWeek)
  1749. days = append(days, theDay.Format("2006-01-02"))
  1750. }
  1751. fmt.Println(days)
  1752. var targetDayStr string
  1753. var startTime string
  1754. var endTime string
  1755. switch week_type {
  1756. case 0:
  1757. {
  1758. startTime = days[0]
  1759. endTime = days[6]
  1760. }
  1761. case 1:
  1762. targetDayStr = days[0]
  1763. break
  1764. case 2:
  1765. targetDayStr = days[1]
  1766. break
  1767. case 3:
  1768. targetDayStr = days[2]
  1769. break
  1770. case 4:
  1771. targetDayStr = days[3]
  1772. break
  1773. case 5:
  1774. targetDayStr = days[4]
  1775. break
  1776. case 6:
  1777. targetDayStr = days[5]
  1778. break
  1779. case 7:
  1780. targetDayStr = days[6]
  1781. break
  1782. }
  1783. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  1784. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  1785. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  1786. fmt.Println(startDay, endDay)
  1787. if parseErr != nil {
  1788. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1789. return
  1790. }
  1791. orgId := this.GetAdminUserInfo().CurrentOrgId
  1792. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  1793. this.ServeSuccessJSON(map[string]interface{}{
  1794. "schdules": list,
  1795. "day": targetDayStr,
  1796. })
  1797. }
  1798. func Struct2Map(obj interface{}) map[string]interface{} {
  1799. t := reflect.TypeOf(obj)
  1800. v := reflect.ValueOf(obj)
  1801. var data = make(map[string]interface{})
  1802. for i := 0; i < t.NumField(); i++ {
  1803. data[t.Field(i).Name] = v.Field(i).Interface()
  1804. }
  1805. return data
  1806. }
  1807. func (this *ScheduleApiController) ExportSchedule() {
  1808. dataBody := make(map[string]interface{}, 0)
  1809. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1810. if err != nil {
  1811. utils.ErrorLog(err.Error())
  1812. return
  1813. }
  1814. utils.ErrorLog("%v", dataBody)
  1815. export_time := time.Now().Unix()
  1816. var schedules []*models.Schedule
  1817. var failed_total int
  1818. var total_schedule []interface{}
  1819. var patients []*models.Patients
  1820. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  1821. start_time := dataBody["start_time"].(string)
  1822. end_time := dataBody["end_time"].(string)
  1823. delete_type := int64(dataBody["delete_type"].(float64))
  1824. fmt.Println("delete_type", delete_type)
  1825. timeLayout := "2006-01-02"
  1826. loc, _ := time.LoadLocation("Local")
  1827. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1828. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  1829. fmt.Println("theTimeStart23232322332322323", theTimeStart.Unix())
  1830. fmt.Println("theTimeStart23232322332322323", theTimeEnd.Unix())
  1831. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  1832. tempSchedule := dataBody["failed_schedule"].([]interface{})
  1833. failed_total = len(tempSchedule)
  1834. }
  1835. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  1836. tempSchedule := dataBody["schedule"].([]interface{})
  1837. total_schedule = tempSchedule
  1838. for _, schMap := range tempSchedule {
  1839. schMapM := schMap.(map[string]interface{})
  1840. var sch models.Schedule
  1841. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  1842. utils.ErrorLog("name")
  1843. return
  1844. }
  1845. name, _ := schMapM["name"].(string)
  1846. fmt.Println(name)
  1847. if len(name) == 0 { //名字为空则生成一条导入错误日志
  1848. err_log := models.ExportErrLog{
  1849. LogType: 2,
  1850. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1851. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  1852. Status: 1,
  1853. CreateTime: time.Now().Unix(),
  1854. UpdateTime: time.Now().Unix(),
  1855. ExportTime: export_time,
  1856. }
  1857. service.CreateExportErrLog(&err_log)
  1858. continue
  1859. } else {
  1860. var patient []*models.Patients
  1861. for _, item := range patients {
  1862. if strings.Replace(item.Name, " ", "", -1) == name {
  1863. patient = append(patient, item)
  1864. }
  1865. }
  1866. if len(patient) == 0 { //错误日志
  1867. err_log := models.ExportErrLog{
  1868. LogType: 2,
  1869. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1870. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  1871. Status: 1,
  1872. CreateTime: time.Now().Unix(),
  1873. UpdateTime: time.Now().Unix(),
  1874. ExportTime: export_time,
  1875. }
  1876. service.CreateExportErrLog(&err_log)
  1877. continue
  1878. } else if len(patient) == 1 { //
  1879. sch.PatientId = patient[0].ID
  1880. } else if len(patient) > 1 { //出现同名的情况
  1881. err_log := models.ExportErrLog{
  1882. LogType: 2,
  1883. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1884. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  1885. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  1886. Status: 1,
  1887. CreateTime: time.Now().Unix(),
  1888. UpdateTime: time.Now().Unix(),
  1889. ExportTime: export_time,
  1890. }
  1891. service.CreateExportErrLog(&err_log)
  1892. continue
  1893. }
  1894. }
  1895. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  1896. utils.ErrorLog("schedule_type")
  1897. return
  1898. }
  1899. schedule_type := int64(schMapM["schedule_type"].(float64))
  1900. if schedule_type <= 0 { //班次格式有误,插入日志
  1901. log := models.ExportLog{
  1902. LogType: 2,
  1903. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1904. TotalNum: int64(len(total_schedule) + failed_total),
  1905. FailNum: 1 + int64(failed_total),
  1906. SuccessNum: int64(len(schedules)),
  1907. CreateTime: time.Now().Unix(),
  1908. UpdateTime: time.Now().Unix(),
  1909. ExportTime: export_time,
  1910. Status: 1,
  1911. }
  1912. service.CreateExportLog(&log)
  1913. err_log := models.ExportErrLog{
  1914. LogType: 2,
  1915. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1916. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  1917. Status: 1,
  1918. CreateTime: time.Now().Unix(),
  1919. UpdateTime: time.Now().Unix(),
  1920. ExportTime: export_time,
  1921. }
  1922. service.CreateExportErrLog(&err_log)
  1923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1924. return
  1925. } else {
  1926. sch.ScheduleType = schedule_type
  1927. }
  1928. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  1929. utils.ErrorLog("partition_name")
  1930. return
  1931. }
  1932. partition_name, _ := schMapM["partition_name"].(string)
  1933. if len(partition_name) == 0 { //分区为空
  1934. log := models.ExportLog{
  1935. LogType: 2,
  1936. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1937. TotalNum: int64(len(total_schedule) + failed_total),
  1938. FailNum: 1 + int64(failed_total),
  1939. SuccessNum: int64(len(schedules)),
  1940. CreateTime: time.Now().Unix(),
  1941. UpdateTime: time.Now().Unix(),
  1942. ExportTime: export_time,
  1943. Status: 1,
  1944. }
  1945. service.CreateExportLog(&log)
  1946. err_log := models.ExportErrLog{
  1947. LogType: 2,
  1948. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1949. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1950. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1951. Status: 1,
  1952. CreateTime: time.Now().Unix(),
  1953. UpdateTime: time.Now().Unix(),
  1954. ExportTime: export_time,
  1955. }
  1956. service.CreateExportErrLog(&err_log)
  1957. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1958. return
  1959. } else {
  1960. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  1961. if err == nil {
  1962. sch.PartitionId = zone.ID
  1963. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  1964. log := models.ExportLog{
  1965. LogType: 2,
  1966. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1967. TotalNum: int64(len(total_schedule) + failed_total),
  1968. FailNum: 1 + int64(failed_total),
  1969. SuccessNum: int64(len(schedules)),
  1970. CreateTime: time.Now().Unix(),
  1971. UpdateTime: time.Now().Unix(),
  1972. ExportTime: export_time,
  1973. Status: 1,
  1974. }
  1975. service.CreateExportLog(&log)
  1976. err_log := models.ExportErrLog{
  1977. LogType: 2,
  1978. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  1979. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  1980. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  1981. Status: 1,
  1982. CreateTime: time.Now().Unix(),
  1983. UpdateTime: time.Now().Unix(),
  1984. ExportTime: export_time,
  1985. }
  1986. service.CreateExportErrLog(&err_log)
  1987. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  1988. return
  1989. }
  1990. }
  1991. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  1992. utils.ErrorLog("device_number_name")
  1993. return
  1994. }
  1995. device_number_name, _ := schMapM["device_number_name"].(string)
  1996. if len(device_number_name) == 0 { //分区为空
  1997. log := models.ExportLog{
  1998. LogType: 2,
  1999. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2000. TotalNum: int64(len(total_schedule) + failed_total),
  2001. FailNum: 1 + int64(failed_total),
  2002. SuccessNum: int64(len(schedules)),
  2003. CreateTime: time.Now().Unix(),
  2004. UpdateTime: time.Now().Unix(),
  2005. ExportTime: export_time,
  2006. Status: 1,
  2007. }
  2008. service.CreateExportLog(&log)
  2009. err_log := models.ExportErrLog{
  2010. LogType: 2,
  2011. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2012. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2013. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2014. Status: 1,
  2015. CreateTime: time.Now().Unix(),
  2016. UpdateTime: time.Now().Unix(),
  2017. ExportTime: export_time,
  2018. }
  2019. service.CreateExportErrLog(&err_log)
  2020. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2021. return
  2022. } else {
  2023. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  2024. if err == nil {
  2025. if len(device) == 0 { //没查到数据,插入错误日志
  2026. log := models.ExportLog{
  2027. LogType: 2,
  2028. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2029. TotalNum: int64(len(total_schedule) + failed_total),
  2030. FailNum: 1 + int64(failed_total),
  2031. SuccessNum: int64(len(schedules)),
  2032. CreateTime: time.Now().Unix(),
  2033. UpdateTime: time.Now().Unix(),
  2034. ExportTime: export_time,
  2035. Status: 1,
  2036. }
  2037. service.CreateExportLog(&log)
  2038. err_log := models.ExportErrLog{
  2039. LogType: 2,
  2040. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2041. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2042. Status: 1,
  2043. CreateTime: time.Now().Unix(),
  2044. UpdateTime: time.Now().Unix(),
  2045. ExportTime: export_time,
  2046. }
  2047. service.CreateExportErrLog(&err_log)
  2048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2049. return
  2050. } else if len(device) == 1 {
  2051. sch.BedId = device[0].ID
  2052. } else if len(device) > 1 { //出现重名,插入错误日志
  2053. log := models.ExportLog{
  2054. LogType: 2,
  2055. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2056. TotalNum: int64(len(total_schedule) + failed_total),
  2057. FailNum: 1 + int64(failed_total),
  2058. SuccessNum: int64(len(schedules)),
  2059. CreateTime: time.Now().Unix(),
  2060. UpdateTime: time.Now().Unix(),
  2061. ExportTime: export_time,
  2062. Status: 1,
  2063. }
  2064. service.CreateExportLog(&log)
  2065. err_log := models.ExportErrLog{
  2066. LogType: 2,
  2067. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2068. ErrMsg: "出现两个床位号相同的床位",
  2069. Status: 1,
  2070. CreateTime: time.Now().Unix(),
  2071. UpdateTime: time.Now().Unix(),
  2072. ExportTime: export_time,
  2073. }
  2074. service.CreateExportErrLog(&err_log)
  2075. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2076. return
  2077. }
  2078. }
  2079. }
  2080. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2081. utils.ErrorLog("schedule_week")
  2082. return
  2083. }
  2084. schedule_week, _ := schMapM["schedule_week"].(string)
  2085. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2086. log := models.ExportLog{
  2087. LogType: 2,
  2088. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2089. TotalNum: int64(len(total_schedule) + failed_total),
  2090. FailNum: 1 + int64(failed_total),
  2091. SuccessNum: int64(len(schedules)),
  2092. CreateTime: time.Now().Unix(),
  2093. UpdateTime: time.Now().Unix(),
  2094. ExportTime: export_time,
  2095. Status: 1,
  2096. }
  2097. service.CreateExportLog(&log)
  2098. err_log := models.ExportErrLog{
  2099. LogType: 2,
  2100. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2101. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2102. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2103. Status: 1,
  2104. CreateTime: time.Now().Unix(),
  2105. UpdateTime: time.Now().Unix(),
  2106. ExportTime: export_time,
  2107. }
  2108. service.CreateExportErrLog(&err_log)
  2109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2110. return
  2111. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2112. log := models.ExportLog{
  2113. LogType: 2,
  2114. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2115. TotalNum: int64(len(total_schedule) + failed_total),
  2116. FailNum: 1 + int64(failed_total),
  2117. SuccessNum: int64(len(schedules)),
  2118. CreateTime: time.Now().Unix(),
  2119. UpdateTime: time.Now().Unix(),
  2120. ExportTime: export_time,
  2121. Status: 1,
  2122. }
  2123. service.CreateExportLog(&log)
  2124. err_log := models.ExportErrLog{
  2125. LogType: 2,
  2126. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2127. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2128. Status: 1,
  2129. CreateTime: time.Now().Unix(),
  2130. UpdateTime: time.Now().Unix(),
  2131. ExportTime: export_time,
  2132. }
  2133. service.CreateExportErrLog(&err_log)
  2134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2135. return
  2136. } else {
  2137. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2138. sch.ScheduleWeek = schedule_week
  2139. }
  2140. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  2141. utils.ErrorLog("schedule_date")
  2142. return
  2143. }
  2144. schedule_date, _ := schMapM["schedule_date"].(string)
  2145. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  2146. log := models.ExportLog{
  2147. LogType: 2,
  2148. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2149. TotalNum: int64(len(total_schedule) + failed_total),
  2150. FailNum: 1 + int64(failed_total),
  2151. SuccessNum: int64(len(schedules)),
  2152. CreateTime: time.Now().Unix(),
  2153. UpdateTime: time.Now().Unix(),
  2154. ExportTime: export_time,
  2155. Status: 1,
  2156. }
  2157. service.CreateExportLog(&log)
  2158. err_log := models.ExportErrLog{
  2159. LogType: 2,
  2160. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2161. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2162. Status: 1,
  2163. CreateTime: time.Now().Unix(),
  2164. UpdateTime: time.Now().Unix(),
  2165. ExportTime: export_time,
  2166. }
  2167. service.CreateExportErrLog(&err_log)
  2168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2169. return
  2170. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  2171. log := models.ExportLog{
  2172. LogType: 2,
  2173. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2174. TotalNum: int64(len(total_schedule) + failed_total),
  2175. FailNum: 1 + int64(failed_total),
  2176. SuccessNum: int64(len(schedules)),
  2177. CreateTime: time.Now().Unix(),
  2178. UpdateTime: time.Now().Unix(),
  2179. ExportTime: export_time,
  2180. Status: 1,
  2181. }
  2182. service.CreateExportLog(&log)
  2183. err_log := models.ExportErrLog{
  2184. LogType: 2,
  2185. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2186. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2187. Status: 1,
  2188. CreateTime: time.Now().Unix(),
  2189. UpdateTime: time.Now().Unix(),
  2190. ExportTime: export_time,
  2191. }
  2192. service.CreateExportErrLog(&err_log)
  2193. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2194. return
  2195. } else {
  2196. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2197. sch.ScheduleDate = date.Unix()
  2198. }
  2199. sch.CreatedTime = time.Now().Unix()
  2200. sch.UpdatedTime = time.Now().Unix()
  2201. sch.ModeId = 1
  2202. sch.Status = 1
  2203. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  2204. sch.IsExport = 1
  2205. var DialysisMachineName string
  2206. so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
  2207. filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
  2208. filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
  2209. filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
  2210. if filedRecordOne.IsShow == 1 {
  2211. DialysisMachineName = so.DialysisDialyszers
  2212. }
  2213. if filedRecordThree.IsShow == 1 {
  2214. if len(DialysisMachineName) > 0 {
  2215. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2216. } else {
  2217. DialysisMachineName = so.DialyzerPerfusionApparatus
  2218. }
  2219. }
  2220. if filedRecordTwo.IsShow == 1 {
  2221. if len(DialysisMachineName) > 0 {
  2222. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  2223. } else {
  2224. DialysisMachineName = so.DialysisIrrigation
  2225. }
  2226. }
  2227. sch.DialysisMachineName = DialysisMachineName
  2228. schedules = append(schedules, &sch)
  2229. }
  2230. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2231. if len(schedules) > 0 {
  2232. schedule_date := time.Now().Format("2006-01-02")
  2233. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2234. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  2235. service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
  2236. if err == nil {
  2237. for _, item := range schedules {
  2238. if item.ScheduleDate > clear_schedule_date {
  2239. //查询该患者是否转出获取死亡
  2240. fmt.Println("11111323242423")
  2241. //查找当天日期是否存在
  2242. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  2243. if errcode == gorm.ErrRecordNotFound {
  2244. //查询该床位是否有患者
  2245. fmt.Println("errcodes")
  2246. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  2247. fmt.Println("errcodes")
  2248. fmt.Println(errcodes)
  2249. fmt.Println(sch)
  2250. if errcodes == gorm.ErrRecordNotFound {
  2251. fmt.Println("1111111")
  2252. service.CreateSchedule(item)
  2253. } else if errcodes == nil {
  2254. fmt.Println("1111222222222")
  2255. //清除当天该床位已有的患者
  2256. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  2257. service.CreateSchedule(item)
  2258. }
  2259. } else if errcode == nil {
  2260. schedule := models.XtSchedule{
  2261. PartitionId: item.PartitionId,
  2262. BedId: item.BedId,
  2263. PatientId: item.PatientId,
  2264. ScheduleDate: item.ScheduleDate,
  2265. ScheduleType: item.ScheduleType,
  2266. ScheduleWeek: item.ScheduleWeek,
  2267. ModeId: 1,
  2268. Status: 1,
  2269. DialysisMachineName: item.DialysisMachineName,
  2270. }
  2271. fmt.Println("1111222222223333333333333333332")
  2272. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  2273. }
  2274. }
  2275. }
  2276. log := models.ExportLog{
  2277. LogType: 2,
  2278. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2279. TotalNum: int64(len(total_schedule) + failed_total),
  2280. FailNum: int64(len(errLogs) + failed_total),
  2281. SuccessNum: int64(len(schedules)),
  2282. CreateTime: time.Now().Unix(),
  2283. UpdateTime: time.Now().Unix(),
  2284. ExportTime: export_time,
  2285. Status: 1,
  2286. }
  2287. service.CreateExportLog(&log)
  2288. if failed_total > 0 {
  2289. err_log := models.ExportErrLog{
  2290. LogType: 2,
  2291. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2292. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2293. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2294. Status: 1,
  2295. CreateTime: time.Now().Unix(),
  2296. UpdateTime: time.Now().Unix(),
  2297. ExportTime: export_time,
  2298. }
  2299. service.CreateExportErrLog(&err_log)
  2300. }
  2301. this.ServeSuccessJSON(map[string]interface{}{
  2302. "msg": "导入成功",
  2303. "total_num": len(total_schedule) + failed_total,
  2304. "success_num": len(schedules),
  2305. "fail_num": int64(len(errLogs)),
  2306. })
  2307. } else {
  2308. log := models.ExportLog{
  2309. LogType: 2,
  2310. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2311. TotalNum: int64(len(total_schedule) + failed_total),
  2312. FailNum: int64(len(errLogs) + failed_total),
  2313. SuccessNum: int64(len(schedules)),
  2314. CreateTime: time.Now().Unix(),
  2315. UpdateTime: time.Now().Unix(),
  2316. ExportTime: export_time,
  2317. Status: 1,
  2318. }
  2319. service.CreateExportLog(&log)
  2320. if failed_total > 0 {
  2321. err_log := models.ExportErrLog{
  2322. LogType: 2,
  2323. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2324. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2325. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2326. Status: 1,
  2327. CreateTime: time.Now().Unix(),
  2328. UpdateTime: time.Now().Unix(),
  2329. ExportTime: export_time,
  2330. }
  2331. service.CreateExportErrLog(&err_log)
  2332. }
  2333. this.ServeSuccessJSON(map[string]interface{}{
  2334. "msg": "导入成功",
  2335. "total_num": len(total_schedule),
  2336. "success_num": len(schedules),
  2337. "fail_num": int64(len(errLogs)),
  2338. })
  2339. }
  2340. } else {
  2341. log := models.ExportLog{
  2342. LogType: 2,
  2343. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2344. TotalNum: int64(len(total_schedule) + failed_total),
  2345. FailNum: int64(len(errLogs) + failed_total),
  2346. SuccessNum: int64(len(schedules)),
  2347. CreateTime: time.Now().Unix(),
  2348. UpdateTime: time.Now().Unix(),
  2349. ExportTime: export_time,
  2350. Status: 1,
  2351. }
  2352. service.CreateExportLog(&log)
  2353. if failed_total > 0 {
  2354. err_log := models.ExportErrLog{
  2355. LogType: 2,
  2356. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2357. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2358. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2359. Status: 1,
  2360. CreateTime: time.Now().Unix(),
  2361. UpdateTime: time.Now().Unix(),
  2362. ExportTime: export_time,
  2363. }
  2364. service.CreateExportErrLog(&err_log)
  2365. }
  2366. this.ServeSuccessJSON(map[string]interface{}{
  2367. "msg": "导入成功",
  2368. "total_num": len(total_schedule),
  2369. "success_num": len(schedules),
  2370. "fail_num": int64(len(errLogs)),
  2371. })
  2372. }
  2373. }
  2374. }
  2375. func (this *ScheduleApiController) ExportScheduleTemplate() {
  2376. dataBody := make(map[string]interface{}, 0)
  2377. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2378. if err != nil {
  2379. utils.ErrorLog(err.Error())
  2380. return
  2381. }
  2382. utils.ErrorLog("%v", dataBody)
  2383. export_time := time.Now().Unix()
  2384. var schedules []*models.PatientScheduleTemplateItem
  2385. var total_schedule []interface{}
  2386. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  2387. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  2388. tempSchedule := dataBody["schedule"].([]interface{})
  2389. total_schedule = tempSchedule
  2390. for _, schMap := range tempSchedule {
  2391. schMapM := schMap.(map[string]interface{})
  2392. var sch models.PatientScheduleTemplateItem
  2393. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  2394. utils.ErrorLog("name")
  2395. return
  2396. }
  2397. name, _ := schMapM["name"].(string)
  2398. fmt.Println(name)
  2399. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2400. err_log := models.ExportErrLog{
  2401. LogType: 3,
  2402. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2403. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  2404. Status: 1,
  2405. CreateTime: time.Now().Unix(),
  2406. UpdateTime: time.Now().Unix(),
  2407. ExportTime: export_time,
  2408. }
  2409. service.CreateExportErrLog(&err_log)
  2410. continue
  2411. } else {
  2412. var patient []*models.Patients
  2413. for _, item := range patients {
  2414. if strings.Replace(item.Name, " ", "", -1) == name {
  2415. patient = append(patient, item)
  2416. }
  2417. }
  2418. if len(patient) == 0 { //错误日志
  2419. err_log := models.ExportErrLog{
  2420. LogType: 3,
  2421. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2422. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  2423. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  2424. Status: 1,
  2425. CreateTime: time.Now().Unix(),
  2426. UpdateTime: time.Now().Unix(),
  2427. ExportTime: export_time,
  2428. }
  2429. service.CreateExportErrLog(&err_log)
  2430. continue
  2431. } else if len(patient) == 1 { //
  2432. sch.PatientID = patient[0].ID
  2433. } else if len(patient) > 1 { //出现同名的情况
  2434. err_log := models.ExportErrLog{
  2435. LogType: 3,
  2436. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2437. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  2438. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  2439. Status: 1,
  2440. CreateTime: time.Now().Unix(),
  2441. UpdateTime: time.Now().Unix(),
  2442. ExportTime: export_time,
  2443. }
  2444. service.CreateExportErrLog(&err_log)
  2445. continue
  2446. }
  2447. }
  2448. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  2449. utils.ErrorLog("schedule_type")
  2450. return
  2451. }
  2452. schedule_type := int64(schMapM["schedule_type"].(float64))
  2453. if schedule_type <= 0 { //班次格式有误,插入日志
  2454. log := models.ExportLog{
  2455. LogType: 3,
  2456. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2457. TotalNum: int64(len(total_schedule)),
  2458. FailNum: 1,
  2459. SuccessNum: int64(len(schedules)),
  2460. CreateTime: time.Now().Unix(),
  2461. UpdateTime: time.Now().Unix(),
  2462. ExportTime: export_time,
  2463. Status: 1,
  2464. }
  2465. service.CreateExportLog(&log)
  2466. err_log := models.ExportErrLog{
  2467. LogType: 3,
  2468. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2469. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  2470. Status: 1,
  2471. CreateTime: time.Now().Unix(),
  2472. UpdateTime: time.Now().Unix(),
  2473. ExportTime: export_time,
  2474. }
  2475. service.CreateExportErrLog(&err_log)
  2476. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2477. return
  2478. } else {
  2479. sch.TimeType = int8(schedule_type)
  2480. }
  2481. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  2482. utils.ErrorLog("template_id")
  2483. return
  2484. }
  2485. template_id := int64(schMapM["template_id"].(float64))
  2486. sch.TemplateID = template_id
  2487. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2488. utils.ErrorLog("device_number_name")
  2489. return
  2490. }
  2491. partition_name, _ := schMapM["partition_name"].(string)
  2492. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2493. device_number_name, _ := schMapM["device_number_name"].(string)
  2494. if len(device_number_name) == 0 { //分区为空
  2495. log := models.ExportLog{
  2496. LogType: 3,
  2497. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2498. TotalNum: int64(len(total_schedule)),
  2499. FailNum: 1,
  2500. SuccessNum: int64(len(schedules)),
  2501. CreateTime: time.Now().Unix(),
  2502. UpdateTime: time.Now().Unix(),
  2503. ExportTime: export_time,
  2504. Status: 1,
  2505. }
  2506. service.CreateExportLog(&log)
  2507. err_log := models.ExportErrLog{
  2508. LogType: 3,
  2509. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2510. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2511. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2512. Status: 1,
  2513. CreateTime: time.Now().Unix(),
  2514. UpdateTime: time.Now().Unix(),
  2515. ExportTime: export_time,
  2516. }
  2517. service.CreateExportErrLog(&err_log)
  2518. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2519. return
  2520. } else {
  2521. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  2522. if err == nil {
  2523. if len(device) == 0 { //没查到数据,插入错误日志
  2524. log := models.ExportLog{
  2525. LogType: 3,
  2526. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2527. TotalNum: int64(len(total_schedule)),
  2528. FailNum: 1,
  2529. SuccessNum: int64(len(schedules)),
  2530. CreateTime: time.Now().Unix(),
  2531. UpdateTime: time.Now().Unix(),
  2532. ExportTime: export_time,
  2533. Status: 1,
  2534. }
  2535. service.CreateExportLog(&log)
  2536. err_log := models.ExportErrLog{
  2537. LogType: 3,
  2538. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2539. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2540. Status: 1,
  2541. CreateTime: time.Now().Unix(),
  2542. UpdateTime: time.Now().Unix(),
  2543. ExportTime: export_time,
  2544. }
  2545. service.CreateExportErrLog(&err_log)
  2546. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2547. return
  2548. } else if len(device) == 1 {
  2549. sch.DeviceNumberID = device[0].ID
  2550. } else if len(device) > 1 { //出现重名,插入错误日志
  2551. log := models.ExportLog{
  2552. LogType: 3,
  2553. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2554. TotalNum: int64(len(total_schedule)),
  2555. FailNum: 1,
  2556. SuccessNum: int64(len(schedules)),
  2557. CreateTime: time.Now().Unix(),
  2558. UpdateTime: time.Now().Unix(),
  2559. ExportTime: export_time,
  2560. Status: 1,
  2561. }
  2562. service.CreateExportLog(&log)
  2563. err_log := models.ExportErrLog{
  2564. LogType: 3,
  2565. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2566. ErrMsg: "出现两个床位号相同的床位",
  2567. Status: 1,
  2568. CreateTime: time.Now().Unix(),
  2569. UpdateTime: time.Now().Unix(),
  2570. ExportTime: export_time,
  2571. }
  2572. service.CreateExportErrLog(&err_log)
  2573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2579. utils.ErrorLog("schedule_week")
  2580. return
  2581. }
  2582. schedule_week, _ := schMapM["schedule_week"].(string)
  2583. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2584. log := models.ExportLog{
  2585. LogType: 3,
  2586. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2587. TotalNum: int64(len(total_schedule)),
  2588. FailNum: 1,
  2589. SuccessNum: int64(len(schedules)),
  2590. CreateTime: time.Now().Unix(),
  2591. UpdateTime: time.Now().Unix(),
  2592. ExportTime: export_time,
  2593. Status: 1,
  2594. }
  2595. service.CreateExportLog(&log)
  2596. err_log := models.ExportErrLog{
  2597. LogType: 3,
  2598. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2599. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2600. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2601. Status: 1,
  2602. CreateTime: time.Now().Unix(),
  2603. UpdateTime: time.Now().Unix(),
  2604. ExportTime: export_time,
  2605. }
  2606. service.CreateExportErrLog(&err_log)
  2607. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2608. return
  2609. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2610. log := models.ExportLog{
  2611. LogType: 3,
  2612. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2613. TotalNum: int64(len(total_schedule)),
  2614. FailNum: 1,
  2615. SuccessNum: int64(len(schedules)),
  2616. CreateTime: time.Now().Unix(),
  2617. UpdateTime: time.Now().Unix(),
  2618. ExportTime: export_time,
  2619. Status: 1,
  2620. }
  2621. service.CreateExportLog(&log)
  2622. err_log := models.ExportErrLog{
  2623. LogType: 3,
  2624. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2625. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2626. Status: 1,
  2627. CreateTime: time.Now().Unix(),
  2628. UpdateTime: time.Now().Unix(),
  2629. ExportTime: export_time,
  2630. }
  2631. service.CreateExportErrLog(&err_log)
  2632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2633. return
  2634. } else {
  2635. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2636. sch.Weekday = int8(schedule_week)
  2637. }
  2638. treat_mode, _ := schMapM["treat_mode"].(string)
  2639. treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
  2640. sch.CreateTime = time.Now().Unix()
  2641. sch.ModifyTime = time.Now().Unix()
  2642. sch.TreatMode = treat_mode_int
  2643. sch.Status = 1
  2644. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  2645. sch.IsExport = 1
  2646. schedules = append(schedules, &sch)
  2647. }
  2648. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2649. //for _, item := range schedules {
  2650. //
  2651. //}
  2652. if len(schedules) > 0 {
  2653. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  2654. if err == nil {
  2655. for _, item := range schedules {
  2656. //判斷某個模板下,當天是否有排版,沒有的話就新增
  2657. total := service.ExportScheduleTemplate(item)
  2658. if total == 0 {
  2659. service.CreateScheduleTemplate(item)
  2660. }
  2661. }
  2662. ////查询已经转出或者死亡的患者
  2663. //patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  2664. //for _, it := range patientList {
  2665. // timeStr := time.Now().Format("2006-01-02")
  2666. // timeLayout := "2006-01-02 15:04:05"
  2667. // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2668. // timenow := timeStringToTime.Unix()
  2669. // service.UpdateScheduleByDeathTime(it.ID, timenow)
  2670. // service.UpdateScheduleItemByPatientId(it.ID)
  2671. //}
  2672. log := models.ExportLog{
  2673. LogType: 3,
  2674. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2675. TotalNum: int64(len(total_schedule)),
  2676. FailNum: int64(len(errLogs)),
  2677. SuccessNum: int64(len(schedules)),
  2678. CreateTime: time.Now().Unix(),
  2679. UpdateTime: time.Now().Unix(),
  2680. ExportTime: export_time,
  2681. Status: 1,
  2682. }
  2683. service.CreateExportLog(&log)
  2684. this.ServeSuccessJSON(map[string]interface{}{
  2685. "msg": "导入成功",
  2686. "total_num": len(total_schedule),
  2687. "success_num": len(schedules),
  2688. "fail_num": int64(len(errLogs)),
  2689. })
  2690. } else {
  2691. log := models.ExportLog{
  2692. LogType: 3,
  2693. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2694. TotalNum: int64(len(total_schedule)),
  2695. FailNum: int64(len(errLogs)),
  2696. SuccessNum: int64(len(schedules)),
  2697. CreateTime: time.Now().Unix(),
  2698. UpdateTime: time.Now().Unix(),
  2699. ExportTime: export_time,
  2700. Status: 1,
  2701. }
  2702. service.CreateExportLog(&log)
  2703. this.ServeSuccessJSON(map[string]interface{}{
  2704. "msg": "导入成功",
  2705. "total_num": len(total_schedule),
  2706. "success_num": len(schedules),
  2707. "fail_num": int64(len(errLogs)),
  2708. })
  2709. }
  2710. } else {
  2711. log := models.ExportLog{
  2712. LogType: 3,
  2713. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2714. TotalNum: int64(len(total_schedule)),
  2715. FailNum: int64(len(errLogs)),
  2716. SuccessNum: int64(len(schedules)),
  2717. CreateTime: time.Now().Unix(),
  2718. UpdateTime: time.Now().Unix(),
  2719. ExportTime: export_time,
  2720. Status: 1,
  2721. }
  2722. service.CreateExportLog(&log)
  2723. this.ServeSuccessJSON(map[string]interface{}{
  2724. "msg": "导入成功",
  2725. "total_num": len(total_schedule),
  2726. "success_num": len(schedules),
  2727. "fail_num": int64(len(errLogs)),
  2728. })
  2729. }
  2730. }
  2731. }
  2732. func (c *ScheduleApiController) GetInitExcelInitDate() {
  2733. thisTime := time.Now()
  2734. thisTime1 := time.Now()
  2735. thisTime2 := time.Now()
  2736. thisTime3 := time.Now()
  2737. thisTime4 := time.Now()
  2738. thisTime1 = thisTime1.AddDate(0, 0, 7)
  2739. thisTime2 = thisTime2.AddDate(0, 0, 14)
  2740. thisTime3 = thisTime3.AddDate(0, 0, 21)
  2741. thisTime4 = thisTime4.AddDate(0, 0, 28)
  2742. weekDay := int(thisTime.Weekday())
  2743. if weekDay == 0 {
  2744. weekDay = 7
  2745. }
  2746. weekEnd := 7 - weekDay
  2747. weekStart := weekEnd - 6
  2748. days := make([]string, 0)
  2749. for index := weekStart; index <= weekEnd; index++ {
  2750. theDay := thisTime.AddDate(0, 0, index)
  2751. days = append(days, theDay.Format("2006-01-02"))
  2752. }
  2753. weekDay1 := int(thisTime1.Weekday())
  2754. if weekDay1 == 0 {
  2755. weekDay1 = 7
  2756. }
  2757. weekEnd1 := 7 - weekDay1
  2758. weekStart1 := weekEnd1 - 6
  2759. for index := weekStart1; index <= weekEnd1; index++ {
  2760. theDay := thisTime1.AddDate(0, 0, index)
  2761. days = append(days, theDay.Format("2006-01-02"))
  2762. }
  2763. weekDay2 := int(thisTime2.Weekday())
  2764. if weekDay2 == 0 {
  2765. weekDay2 = 7
  2766. }
  2767. weekEnd2 := 7 - weekDay2
  2768. weekStart2 := weekEnd2 - 6
  2769. for index := weekStart2; index <= weekEnd2; index++ {
  2770. theDay := thisTime2.AddDate(0, 0, index)
  2771. days = append(days, theDay.Format("2006-01-02"))
  2772. }
  2773. weekDay3 := int(thisTime3.Weekday())
  2774. if weekDay3 == 0 {
  2775. weekDay3 = 7
  2776. }
  2777. weekEnd3 := 7 - weekDay3
  2778. weekStart3 := weekEnd3 - 6
  2779. for index := weekStart3; index <= weekEnd3; index++ {
  2780. theDay := thisTime3.AddDate(0, 0, index)
  2781. days = append(days, theDay.Format("2006-01-02"))
  2782. }
  2783. weekDay4 := int(thisTime4.Weekday())
  2784. if weekDay4 == 0 {
  2785. weekDay4 = 7
  2786. }
  2787. weekEnd4 := 7 - weekDay4
  2788. weekStart4 := weekEnd4 - 6
  2789. for index := weekStart4; index <= weekEnd4; index++ {
  2790. theDay := thisTime4.AddDate(0, 0, index)
  2791. days = append(days, theDay.Format("2006-01-02"))
  2792. }
  2793. c.ServeSuccessJSON(map[string]interface{}{
  2794. "days": days,
  2795. })
  2796. return
  2797. }
  2798. func GetWeekString(week string) string {
  2799. var weekStr string
  2800. switch week {
  2801. case "Sunday":
  2802. weekStr = "周日"
  2803. break
  2804. case "Monday":
  2805. weekStr = "周一"
  2806. break
  2807. case "Tuesday":
  2808. weekStr = "周二"
  2809. break
  2810. case "Wednesday":
  2811. weekStr = "周三"
  2812. break
  2813. case "Thursday":
  2814. weekStr = "周四"
  2815. break
  2816. case "Friday":
  2817. weekStr = "周五"
  2818. break
  2819. case "Saturday":
  2820. weekStr = "周六"
  2821. break
  2822. default:
  2823. weekStr = ""
  2824. break
  2825. }
  2826. return weekStr
  2827. }
  2828. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  2829. template_id, _ := c.GetInt64("template_id", 0)
  2830. keywords := c.GetString("keywords")
  2831. adminInfo := c.GetAdminUserInfo()
  2832. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  2833. c.ServeSuccessJSON(map[string]interface{}{
  2834. "schdules": scheduleItems,
  2835. })
  2836. }
  2837. func (c *ScheduleApiController) CancelScheduleTemplate() {
  2838. item_id, _ := c.GetInt64("id")
  2839. adminInfo := c.GetAdminUserInfo()
  2840. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  2841. if err == nil {
  2842. c.ServeSuccessJSON(map[string]interface{}{
  2843. "msg": "取消成功",
  2844. })
  2845. return
  2846. } else {
  2847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2848. return
  2849. }
  2850. }
  2851. func (this *ScheduleApiController) GetNextWeekDayScheduleOne() {
  2852. week_type, _ := this.GetInt64("week_type", -1)
  2853. week_time, _ := this.GetInt64("week_time")
  2854. record_date := this.GetString("record_date")
  2855. zons := this.GetString("zone")
  2856. zone := strings.Split(zons, ",")
  2857. start_time, _ := this.GetInt64("start_time")
  2858. end_time, _ := this.GetInt64("end_time")
  2859. timeLayout := "2006-01-02"
  2860. loc, _ := time.LoadLocation("Local")
  2861. //theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2862. //theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2863. adminUserInfo := this.GetAdminUserInfo()
  2864. var theStartTIme int64
  2865. if len(record_date) > 0 {
  2866. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2867. if err != nil {
  2868. utils.ErrorLog(err.Error())
  2869. }
  2870. theStartTIme = theTime.Unix()
  2871. }
  2872. schedule, err := service.GetNextWeekDayScheduleSix(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2873. for _, item := range schedule {
  2874. order, _ := service.GetLastDialysisOrder(adminUserInfo.CurrentOrgId, item.PatientId, theStartTIme)
  2875. item.XtDialysisOrderSix = order
  2876. solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId)
  2877. item.DialysisSolution = solutionLastWeek
  2878. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  2879. dialysisprescription, _ := service.GetLastDialysisSolution(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId, item.ScheduleDate)
  2880. item.DialysisPrescription = dialysisprescription
  2881. }
  2882. }
  2883. if err != nil {
  2884. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2885. return
  2886. }
  2887. this.ServeSuccessJSON(map[string]interface{}{
  2888. "schedule": schedule,
  2889. })
  2890. }
  2891. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  2892. week_type, _ := this.GetInt64("week_type", -1)
  2893. week_time, _ := this.GetInt64("week_time")
  2894. record_date := this.GetString("record_date")
  2895. zons := this.GetString("zone")
  2896. zone := strings.Split(zons, ",")
  2897. start_time := this.GetString("start_time")
  2898. end_time := this.GetString("end_time")
  2899. timeLayout := "2006-01-02"
  2900. loc, _ := time.LoadLocation("Local")
  2901. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2902. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2903. adminUserInfo := this.GetAdminUserInfo()
  2904. var theStartTIme int64
  2905. if len(record_date) > 0 {
  2906. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2907. if err != nil {
  2908. utils.ErrorLog(err.Error())
  2909. }
  2910. theStartTIme = theTime.Unix()
  2911. }
  2912. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme)
  2913. for _, item := range schedule {
  2914. AssessmentBefor, _ := service.GetAssessmentBeforListLastWeek(item.ScheduleDate, item.PatientId, item.UserOrgId)
  2915. item.XtAssessmentBeforeDislysis = AssessmentBefor
  2916. doctorAdvices, _ := service.GetDoctorAdviceLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
  2917. item.DoctorAdvice = doctorAdvices
  2918. hisDoctorAdvice, _ := service.GetHisDoctorAdviceListLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
  2919. item.HisDoctorAdviceInfo = hisDoctorAdvice
  2920. solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(item.UserOrgId, item.PatientId, item.ModeId)
  2921. item.DialysisSolution = solutionLastWeek
  2922. }
  2923. if err != nil {
  2924. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2925. return
  2926. }
  2927. this.ServeSuccessJSON(map[string]interface{}{
  2928. "schedule": schedule,
  2929. })
  2930. }
  2931. func (this *ScheduleApiController) GetThreeWeekList() {
  2932. start_time := this.GetString("start_time")
  2933. end_time := this.GetString("end_time")
  2934. partition_id, _ := this.GetInt64("partition_id")
  2935. schedule_type, _ := this.GetInt64("schedule_type")
  2936. fmt.Println(partition_id, schedule_type)
  2937. timeLayout := "2006-01-02"
  2938. loc, _ := time.LoadLocation("Local")
  2939. var theStartTIme int64
  2940. if len(start_time) > 0 {
  2941. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2942. if err != nil {
  2943. utils.ErrorLog(err.Error())
  2944. }
  2945. theStartTIme = theTime.Unix()
  2946. }
  2947. var theEndtTIme int64
  2948. if len(end_time) > 0 {
  2949. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2950. if err != nil {
  2951. utils.ErrorLog(err.Error())
  2952. }
  2953. theEndtTIme = theTime.Unix()
  2954. }
  2955. adminUserInfo := this.GetAdminUserInfo()
  2956. orgId := adminUserInfo.CurrentOrgId
  2957. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  2958. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  2959. if err != nil {
  2960. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2961. return
  2962. }
  2963. this.ServeSuccessJSON(map[string]interface{}{
  2964. "list": list,
  2965. "partitions": partitions,
  2966. })
  2967. }
  2968. func (this *ScheduleApiController) GetAllZones() {
  2969. adminUserInfo := this.GetAdminUserInfo()
  2970. orgId := adminUserInfo.CurrentOrgId
  2971. zones, err := service.GetAllZoneOne(orgId)
  2972. if err != nil {
  2973. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2974. return
  2975. }
  2976. this.ServeSuccessJSON(map[string]interface{}{
  2977. "zones": zones,
  2978. })
  2979. }
  2980. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  2981. adminUserInfo := this.GetAdminUserInfo()
  2982. orgId := adminUserInfo.CurrentOrgId
  2983. start_time, _ := this.GetInt64("start_time")
  2984. fmt.Println("start_time", start_time)
  2985. end_time, _ := this.GetInt64("end_time")
  2986. fmt.Println("end_time", end_time)
  2987. copy_startime, _ := this.GetInt64("copy_startime")
  2988. fmt.Println("copy_startime", copy_startime)
  2989. copy_endtime, _ := this.GetInt64("copy_endtime")
  2990. //获取本周患者排班
  2991. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  2992. //先清除复制周的排班
  2993. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  2994. fmt.Println(errcode)
  2995. var err error
  2996. for _, item := range schedules {
  2997. //fmt.Println(item.StartTime+604800)
  2998. //礼拜1
  2999. if item.ScheduleWeek == 1 {
  3000. item.ScheduleDate = copy_startime
  3001. }
  3002. if item.ScheduleWeek == 2 {
  3003. item.ScheduleDate = copy_startime + 86400
  3004. }
  3005. if item.ScheduleWeek == 3 {
  3006. item.ScheduleDate = copy_startime + 172800
  3007. }
  3008. if item.ScheduleWeek == 4 {
  3009. item.ScheduleDate = copy_startime + 259200
  3010. }
  3011. if item.ScheduleWeek == 5 {
  3012. item.ScheduleDate = copy_startime + 345600
  3013. }
  3014. if item.ScheduleWeek == 6 {
  3015. item.ScheduleDate = copy_startime + 432000
  3016. }
  3017. //礼拜天
  3018. if item.ScheduleWeek == 7 {
  3019. item.ScheduleDate = copy_endtime
  3020. }
  3021. schedule := models.XtSchedule{
  3022. UserOrgId: item.UserOrgId,
  3023. PartitionId: item.PartitionId,
  3024. BedId: item.BedId,
  3025. PatientId: item.PatientId,
  3026. ScheduleDate: item.ScheduleDate,
  3027. ScheduleType: item.ScheduleType,
  3028. ScheduleWeek: item.ScheduleWeek,
  3029. ModeId: item.ModeId,
  3030. Status: 1,
  3031. CreatedTime: time.Now().Unix(),
  3032. }
  3033. var DialysisMachineName string
  3034. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3035. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  3036. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  3037. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  3038. if filedRecordOne.IsShow == 1 {
  3039. DialysisMachineName = so.DialysisDialyszers
  3040. }
  3041. if filedRecordThree.IsShow == 1 {
  3042. if len(DialysisMachineName) > 0 {
  3043. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3044. } else {
  3045. DialysisMachineName = so.DialyzerPerfusionApparatus
  3046. }
  3047. }
  3048. if filedRecordTwo.IsShow == 1 {
  3049. if len(DialysisMachineName) > 0 {
  3050. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3051. } else {
  3052. DialysisMachineName = so.DialysisIrrigation
  3053. }
  3054. }
  3055. schedule.DialysisMachineName = DialysisMachineName
  3056. schedule.IsExport = 4000
  3057. err = service.AddPatientSchedule(&schedule)
  3058. }
  3059. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3060. timeStr := time.Now().Format("2006-01-02")
  3061. timeLayout := "2006-01-02 15:04:05"
  3062. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3063. timenow := timeStringToTime.Unix()
  3064. for _, it := range patientList {
  3065. service.UpdateScheduleByDeathTime(it.ID, timenow)
  3066. service.UpdateScheduleItemByPatientId(it.ID)
  3067. }
  3068. if err != nil {
  3069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3070. return
  3071. }
  3072. this.ServeSuccessJSON(map[string]interface{}{
  3073. "msg": "msg",
  3074. })
  3075. return
  3076. //查询复制中的排班日期是否存在
  3077. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  3078. //
  3079. //if errcode == gorm.ErrRecordNotFound {
  3080. // //如果没有直接新增
  3081. //
  3082. // for _, item := range schedules {
  3083. // //fmt.Println(item.StartTime+604800)
  3084. // //礼拜1
  3085. // if item.ScheduleWeek == 1 {
  3086. // item.ScheduleDate = copy_startime
  3087. // }
  3088. // if item.ScheduleWeek == 2 {
  3089. // item.ScheduleDate = copy_startime + 86400
  3090. // }
  3091. // if item.ScheduleWeek == 3 {
  3092. // item.ScheduleDate = copy_startime + 172800
  3093. // }
  3094. // if item.ScheduleWeek == 4 {
  3095. // item.ScheduleDate = copy_startime + 259200
  3096. // }
  3097. // if item.ScheduleWeek == 5 {
  3098. // item.ScheduleDate = copy_startime + 345600
  3099. // }
  3100. //
  3101. // if item.ScheduleWeek == 6 {
  3102. // item.ScheduleDate = copy_startime + 432000
  3103. // }
  3104. // //礼拜天
  3105. // if item.ScheduleWeek == 0 {
  3106. // item.ScheduleDate = copy_endtime
  3107. // }
  3108. // schedule := models.XtSchedule{
  3109. // UserOrgId: item.UserOrgId,
  3110. // PartitionId: item.PartitionId,
  3111. // BedId: item.BedId,
  3112. // PatientId: item.PatientId,
  3113. // ScheduleDate: item.ScheduleDate,
  3114. // ScheduleType: item.ScheduleType,
  3115. // ScheduleWeek: item.ScheduleWeek,
  3116. // ModeId: item.ModeId,
  3117. // Status: 1,
  3118. // CreatedTime: time.Now().Unix(),
  3119. // }
  3120. //
  3121. // err := service.AddPatientSchedule(&schedule)
  3122. // if err != nil {
  3123. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3124. // return
  3125. // }
  3126. // this.ServeSuccessJSON(map[string]interface{}{
  3127. // "schedule": schedule,
  3128. // })
  3129. // }
  3130. //} else if errcode == nil {
  3131. //
  3132. // //先清除复制周的排班
  3133. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3134. // fmt.Println(errcode)
  3135. // for _, item := range schedules {
  3136. // //fmt.Println(item.StartTime+604800)
  3137. // //礼拜1
  3138. // if item.ScheduleWeek == 1 {
  3139. // item.ScheduleDate = copy_startime
  3140. // }
  3141. // if item.ScheduleWeek == 2 {
  3142. // item.ScheduleDate = copy_startime + 86400
  3143. // }
  3144. // if item.ScheduleWeek == 3 {
  3145. // item.ScheduleDate = copy_startime + 172800
  3146. // }
  3147. // if item.ScheduleWeek == 4 {
  3148. // item.ScheduleDate = copy_startime + 259200
  3149. // }
  3150. // if item.ScheduleWeek == 5 {
  3151. // item.ScheduleDate = copy_startime + 345600
  3152. // }
  3153. //
  3154. // if item.ScheduleWeek == 6 {
  3155. // item.ScheduleDate = copy_startime + 432000
  3156. // }
  3157. // //礼拜天
  3158. // if item.ScheduleWeek == 0 {
  3159. // item.ScheduleDate = copy_endtime
  3160. // }
  3161. // schedule := models.XtSchedule{
  3162. // UserOrgId: item.UserOrgId,
  3163. // PartitionId: item.PartitionId,
  3164. // BedId: item.BedId,
  3165. // PatientId: item.PatientId,
  3166. // ScheduleDate: item.ScheduleDate,
  3167. // ScheduleType: item.ScheduleType,
  3168. // ScheduleWeek: item.ScheduleWeek,
  3169. // ModeId: item.ModeId,
  3170. // Status: 1,
  3171. // CreatedTime: time.Now().Unix(),
  3172. // }
  3173. //
  3174. // err := service.AddPatientSchedule(&schedule)
  3175. // if err != nil {
  3176. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3177. // return
  3178. // }
  3179. // this.ServeSuccessJSON(map[string]interface{}{
  3180. // "schedule": schedule,
  3181. // })
  3182. // }
  3183. //}
  3184. }
  3185. func (this *ScheduleApiController) SaveRemindPrint() {
  3186. id, _ := this.GetInt64("id")
  3187. anticoagulants, _ := this.GetInt64("anticoagulant")
  3188. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  3189. classes, _ := this.GetInt64("classes")
  3190. dialyzers, _ := this.GetInt64("dialyzers")
  3191. doctor_advice, _ := this.GetInt64("doctor_advice")
  3192. mode, _ := this.GetInt64("mode")
  3193. name, _ := this.GetInt64("name")
  3194. number, _ := this.GetInt64("number")
  3195. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  3196. prescription_status, _ := this.GetInt64("prescription_status")
  3197. week, _ := this.GetInt64("week")
  3198. zone, _ := this.GetInt64("zone")
  3199. adminUserInfo := this.GetAdminUserInfo()
  3200. orgId := adminUserInfo.CurrentOrgId
  3201. setting := models.XtRemindPrintSetting{
  3202. Anticoagulant: anticoagulants,
  3203. Classes: classes,
  3204. AnticoagulantZongliang: anticoagulant_zongliang,
  3205. Dialyzers: dialyzers,
  3206. DoctorAdvice: doctor_advice,
  3207. Mode: mode,
  3208. Name: name,
  3209. Number: number,
  3210. PerfusionApparatus: perfusion_apparatus,
  3211. PrescriptionStatus: prescription_status,
  3212. Week: week,
  3213. Zone: zone,
  3214. UserOrgId: orgId,
  3215. Status: 1,
  3216. Ctime: time.Now().Unix(),
  3217. }
  3218. _, errcode := service.GetSettingById(id)
  3219. if errcode == gorm.ErrRecordNotFound {
  3220. err := service.CreateSetting(&setting)
  3221. if err != nil {
  3222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3223. return
  3224. }
  3225. this.ServeSuccessJSON(map[string]interface{}{
  3226. "setting": setting,
  3227. })
  3228. } else if errcode == nil {
  3229. err := service.UpdatedRemindPrint(&setting, id)
  3230. if err != nil {
  3231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3232. return
  3233. }
  3234. this.ServeSuccessJSON(map[string]interface{}{
  3235. "setting": setting,
  3236. })
  3237. }
  3238. }
  3239. func (this *ScheduleApiController) GetRemindPrintList() {
  3240. adminUserInfo := this.GetAdminUserInfo()
  3241. orgId := adminUserInfo.CurrentOrgId
  3242. list, err := service.GetRemindPrintList(orgId)
  3243. if err != nil {
  3244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3245. return
  3246. }
  3247. this.ServeSuccessJSON(map[string]interface{}{
  3248. "list": list,
  3249. })
  3250. }
  3251. func (this *ScheduleApiController) GetBloodScheduleList() {
  3252. week_type, _ := this.GetInt64("week_type", -1)
  3253. week_time, _ := this.GetInt64("week_time")
  3254. zones := this.GetString("zone")
  3255. zone := strings.Split(zones, ",")
  3256. thisTime := time.Now()
  3257. weekDay := int(thisTime.Weekday())
  3258. if weekDay == 0 {
  3259. weekDay = 7
  3260. }
  3261. weekEnd := 7 - weekDay
  3262. weekStart := weekEnd - 6
  3263. weekTitle := make([]string, 0)
  3264. days := make([]string, 0)
  3265. for index := weekStart; index <= weekEnd; index++ {
  3266. theDay := thisTime.AddDate(0, 0, index)
  3267. indexYear, indexMonthTime, indexDay := theDay.Date()
  3268. indexMonth := int(indexMonthTime)
  3269. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3270. weekTitle = append(weekTitle, indexWeek)
  3271. days = append(days, theDay.Format("2006-01-02"))
  3272. }
  3273. fmt.Println(days)
  3274. var targetDayStr string
  3275. var startTime string
  3276. switch week_type {
  3277. case 0:
  3278. startTime = days[0]
  3279. targetDayStr = days[6]
  3280. break
  3281. case 1:
  3282. targetDayStr = days[0]
  3283. break
  3284. case 2:
  3285. targetDayStr = days[1]
  3286. break
  3287. case 3:
  3288. targetDayStr = days[2]
  3289. break
  3290. case 4:
  3291. targetDayStr = days[3]
  3292. break
  3293. case 5:
  3294. targetDayStr = days[4]
  3295. break
  3296. case 6:
  3297. targetDayStr = days[5]
  3298. break
  3299. case 7:
  3300. targetDayStr = days[6]
  3301. break
  3302. }
  3303. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  3304. if parseErr != nil {
  3305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3306. return
  3307. }
  3308. orgId := this.GetAdminUserInfo().CurrentOrgId
  3309. if week_type > 0 {
  3310. list, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone)
  3311. for _, item := range list {
  3312. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3313. item.XtDialysisOrderSix = order
  3314. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3315. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3316. item.DialysisPrescription = solution
  3317. }
  3318. }
  3319. if err != nil {
  3320. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3321. return
  3322. }
  3323. this.ServeSuccessJSON(map[string]interface{}{
  3324. "list": list,
  3325. "day": targetDayStr,
  3326. })
  3327. }
  3328. if week_type == 0 {
  3329. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  3330. list, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone)
  3331. for _, item := range list {
  3332. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  3333. item.XtDialysisOrderSix = order
  3334. if orgId == 9671 || orgId == 9675 || orgId == 10340 {
  3335. solution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3336. item.DialysisPrescription = solution
  3337. }
  3338. }
  3339. if err != nil {
  3340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3341. return
  3342. }
  3343. this.ServeSuccessJSON(map[string]interface{}{
  3344. "list": list,
  3345. "day": targetDayStr,
  3346. })
  3347. }
  3348. }
  3349. func (this *ScheduleApiController) GetPrintList() {
  3350. adminUserInfo := this.GetAdminUserInfo()
  3351. orgId := adminUserInfo.CurrentOrgId
  3352. list, err := service.GetRemindPrintList(orgId)
  3353. if err != nil {
  3354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3355. return
  3356. }
  3357. this.ServeSuccessJSON(map[string]interface{}{
  3358. "list": list,
  3359. })
  3360. }
  3361. func (this *ScheduleApiController) GetAllZoneList() {
  3362. adminUserInfo := this.GetAdminUserInfo()
  3363. orgId := adminUserInfo.CurrentOrgId
  3364. zoneList, err := service.GetAllZoneOne(orgId)
  3365. if err != nil {
  3366. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3367. return
  3368. }
  3369. this.ServeSuccessJSON(map[string]interface{}{
  3370. "zoneList": zoneList,
  3371. })
  3372. }
  3373. func (this *ScheduleApiController) GetPatientScheduleCount() {
  3374. patitionIdStr := this.GetString("partition_id")
  3375. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3376. ids := strings.Split(patitionIdStr, ",")
  3377. adminUserInfo := this.GetAdminUserInfo()
  3378. orgId := adminUserInfo.CurrentOrgId
  3379. thisTime := time.Now()
  3380. weekDay := int(thisTime.Weekday())
  3381. if week < 1 || week > 4 {
  3382. week = 2
  3383. }
  3384. if week == 1 {
  3385. thisTime = thisTime.AddDate(0, 0, -7)
  3386. } else if week == 3 {
  3387. thisTime = thisTime.AddDate(0, 0, 7)
  3388. } else if week == 4 {
  3389. thisTime = thisTime.AddDate(0, 0, 14)
  3390. }
  3391. if weekDay == 0 {
  3392. weekDay = 7
  3393. }
  3394. weekEnd := 7 - weekDay
  3395. weekStart := weekEnd - 6
  3396. weekTitle := make([]string, 0)
  3397. days := make([]string, 0)
  3398. for index := weekStart; index <= weekEnd; index++ {
  3399. theDay := thisTime.AddDate(0, 0, index)
  3400. indexYear, indexMonthTime, indexDay := theDay.Date()
  3401. indexMonth := int(indexMonthTime)
  3402. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3403. weekTitle = append(weekTitle, indexWeek)
  3404. days = append(days, theDay.Format("2006-01-02"))
  3405. }
  3406. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3407. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3408. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3409. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3410. timeLayout := "2006-01-02 15:04:05"
  3411. loc, _ := time.LoadLocation("Local")
  3412. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3413. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3414. weekStartPoint := theStarTime.Unix()
  3415. weekEndPoint := theEndTime.Unix()
  3416. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  3417. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  3418. if err != nil {
  3419. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3420. return
  3421. }
  3422. this.ServeSuccessJSON(map[string]interface{}{
  3423. "list": list,
  3424. "total": total,
  3425. })
  3426. }
  3427. func (c *ScheduleApiController) GetWeekPanelsOne() {
  3428. data, _ := c.GetInt64("data", 1)
  3429. patitionIdStr := c.GetString("patitionid")
  3430. ids := strings.Split(patitionIdStr, ",")
  3431. adminInfo := c.GetAdminUserInfo()
  3432. thisTime := time.Now()
  3433. year, monthTime, day := thisTime.Date()
  3434. month := int(monthTime)
  3435. _, theWeek := thisTime.ISOWeek()
  3436. weekDay := int(thisTime.Weekday())
  3437. if weekDay == 0 {
  3438. weekDay = 7
  3439. }
  3440. weekEnd := 7 - weekDay
  3441. weekStart := weekEnd - 6
  3442. weekDays := make([]string, 0)
  3443. for index := weekStart; index <= weekEnd; index++ {
  3444. theDay := thisTime.AddDate(0, 0, index)
  3445. indexYear, indexMonthTime, indexDay := theDay.Date()
  3446. indexMonth := int(indexMonthTime)
  3447. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3448. weekDays = append(weekDays, indexWeek)
  3449. }
  3450. returnData := map[string]interface{}{
  3451. "year": year,
  3452. "month": month,
  3453. "day": day,
  3454. "theWeek": theWeek,
  3455. "weekDay": weekDay,
  3456. "weekDays": weekDays,
  3457. }
  3458. if data == 1 {
  3459. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  3460. returnData["partitions"] = partitions
  3461. }
  3462. c.ServeSuccessJSON(returnData)
  3463. return
  3464. }
  3465. func (c *ScheduleApiController) GetScheduleOne() {
  3466. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3467. patitionIdStr := c.GetString("patitionid")
  3468. ids := strings.Split(patitionIdStr, ",")
  3469. fmt.Println("patitonStr", ids)
  3470. schedule_type, _ := c.GetInt64("schedule_type")
  3471. adminInfo := c.GetAdminUserInfo()
  3472. thisTime := time.Now()
  3473. today := thisTime.Format("2006-01-02")
  3474. if week < 1 || week > 4 {
  3475. week = 2
  3476. }
  3477. if week == 1 {
  3478. thisTime = thisTime.AddDate(0, 0, -7)
  3479. } else if week == 3 {
  3480. thisTime = thisTime.AddDate(0, 0, 7)
  3481. } else if week == 4 {
  3482. thisTime = thisTime.AddDate(0, 0, 14)
  3483. }
  3484. weekDay := int(thisTime.Weekday())
  3485. if weekDay == 0 {
  3486. weekDay = 7
  3487. }
  3488. weekEnd := 7 - weekDay
  3489. weekStart := weekEnd - 6
  3490. weekTitle := make([]string, 0)
  3491. days := make([]string, 0)
  3492. for index := weekStart; index <= weekEnd; index++ {
  3493. theDay := thisTime.AddDate(0, 0, index)
  3494. indexYear, indexMonthTime, indexDay := theDay.Date()
  3495. indexMonth := int(indexMonthTime)
  3496. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3497. weekTitle = append(weekTitle, indexWeek)
  3498. days = append(days, theDay.Format("2006-01-02"))
  3499. }
  3500. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3501. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3502. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3503. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3504. timeLayout := "2006-01-02 15:04:05"
  3505. loc, _ := time.LoadLocation("Local")
  3506. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3507. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3508. weekStartPoint := theStarTime.Unix()
  3509. weekEndPoint := theEndTime.Unix()
  3510. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  3511. c.ServeSuccessJSON(map[string]interface{}{
  3512. "days": days,
  3513. "weekTitle": weekTitle,
  3514. "schdules": schdules,
  3515. "today": today,
  3516. })
  3517. return
  3518. }
  3519. func (c *ScheduleApiController) GetScheduleTwo() {
  3520. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  3521. patitionIdStr := c.GetString("patitionid")
  3522. ids := strings.Split(patitionIdStr, ",")
  3523. schedule_type, _ := c.GetInt64("schedule_type")
  3524. adminInfo := c.GetAdminUserInfo()
  3525. weekDateStr := c.GetString("week_date")
  3526. WeekDayIds := strings.Split(weekDateStr, ",")
  3527. thisTime := time.Now()
  3528. today := thisTime.Format("2006-01-02")
  3529. if week < 1 || week > 4 {
  3530. week = 2
  3531. }
  3532. if week == 1 {
  3533. thisTime = thisTime.AddDate(0, 0, -7)
  3534. } else if week == 3 {
  3535. thisTime = thisTime.AddDate(0, 0, 7)
  3536. } else if week == 4 {
  3537. thisTime = thisTime.AddDate(0, 0, 14)
  3538. }
  3539. weekDay := int(thisTime.Weekday())
  3540. if weekDay == 0 {
  3541. weekDay = 7
  3542. }
  3543. weekEnd := 7 - weekDay
  3544. weekStart := weekEnd - 6
  3545. weekTitle := make([]string, 0)
  3546. days := make([]string, 0)
  3547. for index := weekStart; index <= weekEnd; index++ {
  3548. theDay := thisTime.AddDate(0, 0, index)
  3549. indexYear, indexMonthTime, indexDay := theDay.Date()
  3550. indexMonth := int(indexMonthTime)
  3551. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3552. weekTitle = append(weekTitle, indexWeek)
  3553. days = append(days, theDay.Format("2006-01-02"))
  3554. }
  3555. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  3556. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  3557. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  3558. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  3559. timeLayout := "2006-01-02 15:04:05"
  3560. loc, _ := time.LoadLocation("Local")
  3561. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  3562. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  3563. weekStartPoint := theStarTime.Unix()
  3564. weekEndPoint := theEndTime.Unix()
  3565. schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  3566. c.ServeSuccessJSON(map[string]interface{}{
  3567. "days": days,
  3568. "weekTitle": weekTitle,
  3569. "schdules": schdules,
  3570. "today": today,
  3571. })
  3572. return
  3573. }
  3574. func (c *ScheduleApiController) SaveScheduleTemplate() {
  3575. template_id, _ := c.GetInt64("template_id")
  3576. orgId := c.GetAdminUserInfo().CurrentOrgId
  3577. template := models.ScheduleTemplate{
  3578. TemplateId: template_id,
  3579. UserOrgId: orgId,
  3580. Status: 1,
  3581. Ctime: time.Now().Unix(),
  3582. }
  3583. _, errcodes := service.GetScheudleTemplateById(orgId)
  3584. if errcodes == gorm.ErrRecordNotFound {
  3585. service.CreateXtscheduleTemplate(&template)
  3586. } else if errcodes == nil {
  3587. service.UpdateXtScheduleTemplate(&template, orgId)
  3588. }
  3589. c.ServeSuccessJSON(map[string]interface{}{
  3590. "template": template,
  3591. })
  3592. return
  3593. }
  3594. func (c *ScheduleApiController) GetScheduleTemplate() {
  3595. adminUserInfo := c.GetAdminUserInfo()
  3596. orgId := adminUserInfo.CurrentOrgId
  3597. template, _ := service.GetScheduleTemplate(orgId)
  3598. c.ServeSuccessJSON(map[string]interface{}{
  3599. "template": template,
  3600. })
  3601. return
  3602. }
  3603. func (c *ScheduleApiController) ChangeFuncPrint() {
  3604. adminUserInfo := c.GetAdminUserInfo()
  3605. orgId := adminUserInfo.CurrentOrgId
  3606. is_open, _ := c.GetInt64("is_open")
  3607. dataPrint := models.XtDataPrint{
  3608. UserOrgId: orgId,
  3609. IsOpen: is_open,
  3610. Status: 1,
  3611. Ctime: time.Now().Unix(),
  3612. }
  3613. _, errcode := service.GetDataPrintByOrgId(orgId)
  3614. if errcode == gorm.ErrRecordNotFound {
  3615. service.CreateDataPrint(&dataPrint)
  3616. c.ServeSuccessJSON(map[string]interface{}{
  3617. "dataPrint": dataPrint,
  3618. })
  3619. return
  3620. } else if errcode == nil {
  3621. service.UpdteDataPrint(orgId, &dataPrint)
  3622. c.ServeSuccessJSON(map[string]interface{}{
  3623. "dataPrint": dataPrint,
  3624. })
  3625. return
  3626. }
  3627. }
  3628. func (c *ScheduleApiController) GetDataPrint() {
  3629. adminUserInfo := c.GetAdminUserInfo()
  3630. orgId := adminUserInfo.CurrentOrgId
  3631. dataPrint, _ := service.GetDataPrint(orgId)
  3632. c.ServeSuccessJSON(map[string]interface{}{
  3633. "dataPrint": dataPrint,
  3634. })
  3635. return
  3636. }
  3637. func (c *ScheduleApiController) GetNextWeekPanels() {
  3638. start_time, _ := c.GetInt64("start_time")
  3639. fmt.Println("start_time", start_time)
  3640. end_time, _ := c.GetInt64("end_time")
  3641. fmt.Println("end_time", end_time)
  3642. orgId := c.GetAdminUserInfo().CurrentOrgId
  3643. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  3644. c.ServeSuccessJSON(map[string]interface{}{
  3645. "schedule": schedule,
  3646. })
  3647. }
  3648. func (c *ScheduleApiController) SynchroSchedule() {
  3649. template_id, _ := c.GetInt64("template_id")
  3650. copy_startime, _ := c.GetInt64("copy_startime")
  3651. copy_endtime, _ := c.GetInt64("copy_endtime")
  3652. orgId := c.GetAdminUserInfo().CurrentOrgId
  3653. //根据模板ID获取模板数据
  3654. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  3655. fmt.Println(len(list))
  3656. //数据去重操作
  3657. list = RemoveRepeatedScheduleTemplate(list)
  3658. recordDateStr := time.Now().Format("2006-01-02")
  3659. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3660. nowtime := recordDate.Unix()
  3661. fmt.Println("今日时间", nowtime)
  3662. fmt.Println("后期日期", copy_startime)
  3663. var tuesday int64
  3664. var wednesday int64
  3665. var thursday int64
  3666. var friday int64
  3667. var saturday int64
  3668. //
  3669. //如果选择的开始日期大于当前日期
  3670. if copy_startime > nowtime {
  3671. //清空该时间段的所有排班数据
  3672. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  3673. tuesday = copy_startime + 86400
  3674. wednesday = copy_startime + 172800
  3675. thursday = copy_startime + 259200
  3676. friday = copy_startime + 345600
  3677. saturday = copy_startime + 432000
  3678. for _, item := range list {
  3679. if item.Weekday == 1 {
  3680. item.ScheduleDate = copy_startime
  3681. }
  3682. if item.Weekday == 2 {
  3683. item.ScheduleDate = tuesday
  3684. }
  3685. if item.Weekday == 3 {
  3686. item.ScheduleDate = wednesday
  3687. }
  3688. if item.Weekday == 4 {
  3689. item.ScheduleDate = thursday
  3690. }
  3691. if item.Weekday == 5 {
  3692. item.ScheduleDate = friday
  3693. }
  3694. if item.Weekday == 6 {
  3695. item.ScheduleDate = saturday
  3696. }
  3697. if item.Weekday == 7 {
  3698. item.ScheduleDate = copy_endtime
  3699. }
  3700. //根据床位号获取区号
  3701. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3702. item.ZoneId = number.ZoneID
  3703. }
  3704. for _, item := range list {
  3705. schedule := models.XtSchedule{
  3706. UserOrgId: orgId,
  3707. PartitionId: item.ZoneId,
  3708. BedId: item.DeviceNumberID,
  3709. PatientId: item.PatientID,
  3710. ScheduleDate: item.ScheduleDate,
  3711. ScheduleType: item.TimeType,
  3712. ScheduleWeek: item.Weekday,
  3713. ModeId: item.TreatMode,
  3714. Status: 1,
  3715. CreatedTime: time.Now().Unix(),
  3716. UpdatedTime: 0,
  3717. IsExport: 2000,
  3718. }
  3719. var DialysisMachineName string
  3720. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3721. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3722. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3723. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3724. if filedRecordOne.IsShow == 1 {
  3725. DialysisMachineName = so.DialysisDialyszers
  3726. }
  3727. if filedRecordThree.IsShow == 1 {
  3728. if len(DialysisMachineName) > 0 {
  3729. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3730. } else {
  3731. DialysisMachineName = so.DialyzerPerfusionApparatus
  3732. }
  3733. }
  3734. if filedRecordTwo.IsShow == 1 {
  3735. if len(DialysisMachineName) > 0 {
  3736. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3737. } else {
  3738. DialysisMachineName = so.DialysisIrrigation
  3739. }
  3740. }
  3741. schedule.DialysisMachineName = DialysisMachineName
  3742. service.CreatePatientSchedule(&schedule)
  3743. }
  3744. }
  3745. //如果选择的日期小于当前日期,只同步今日以后的数据
  3746. if copy_startime <= nowtime {
  3747. //清空今日以后的数据
  3748. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  3749. var tuesday int64
  3750. var wednesday int64
  3751. var thursday int64
  3752. var friday int64
  3753. var saturday int64
  3754. tuesday = copy_startime + 86400
  3755. wednesday = copy_startime + 172800
  3756. thursday = copy_startime + 259200
  3757. friday = copy_startime + 345600
  3758. saturday = copy_startime + 432000
  3759. for _, item := range list {
  3760. if item.Weekday == 1 {
  3761. item.ScheduleDate = copy_startime
  3762. }
  3763. if item.Weekday == 2 {
  3764. item.ScheduleDate = tuesday
  3765. }
  3766. if item.Weekday == 3 {
  3767. item.ScheduleDate = wednesday
  3768. }
  3769. if item.Weekday == 4 {
  3770. item.ScheduleDate = thursday
  3771. }
  3772. if item.Weekday == 5 {
  3773. item.ScheduleDate = friday
  3774. }
  3775. if item.Weekday == 6 {
  3776. item.ScheduleDate = saturday
  3777. }
  3778. if item.Weekday == 7 {
  3779. item.ScheduleDate = copy_endtime
  3780. }
  3781. //根据床位号获取区号
  3782. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  3783. item.ZoneId = number.ZoneID
  3784. }
  3785. for _, item := range list {
  3786. // 同步今日以后的数据
  3787. if item.ScheduleDate > nowtime {
  3788. schedule := models.XtSchedule{
  3789. UserOrgId: orgId,
  3790. PartitionId: item.ZoneId,
  3791. BedId: item.DeviceNumberID,
  3792. PatientId: item.PatientID,
  3793. ScheduleDate: item.ScheduleDate,
  3794. ScheduleType: item.TimeType,
  3795. ScheduleWeek: item.Weekday,
  3796. ModeId: item.TreatMode,
  3797. Status: 1,
  3798. CreatedTime: time.Now().Unix(),
  3799. UpdatedTime: 0,
  3800. }
  3801. var DialysisMachineName string
  3802. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3803. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  3804. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  3805. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  3806. if filedRecordOne.IsShow == 1 {
  3807. DialysisMachineName = so.DialysisDialyszers
  3808. }
  3809. if filedRecordThree.IsShow == 1 {
  3810. if len(DialysisMachineName) > 0 {
  3811. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  3812. } else {
  3813. DialysisMachineName = so.DialyzerPerfusionApparatus
  3814. }
  3815. }
  3816. if filedRecordTwo.IsShow == 1 {
  3817. if len(schedule.DialysisMachineName) > 0 {
  3818. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3819. } else {
  3820. DialysisMachineName = so.DialysisIrrigation
  3821. }
  3822. }
  3823. schedule.DialysisMachineName = DialysisMachineName
  3824. service.CreatePatientSchedule(&schedule)
  3825. }
  3826. }
  3827. }
  3828. returnData := make(map[string]interface{}, 0)
  3829. returnData["list"] = list
  3830. c.ServeSuccessJSON(returnData)
  3831. return
  3832. }
  3833. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  3834. orgId := c.GetAdminUserInfo().CurrentOrgId
  3835. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  3836. c.ServeSuccessJSON(map[string]interface{}{
  3837. "schedule": tempalate,
  3838. })
  3839. }
  3840. func (c *ScheduleApiController) GetSolutionSchedule() {
  3841. orgId := c.GetAdminUserInfo().CurrentOrgId
  3842. solution, _ := service.GetSolutionSchedule(orgId)
  3843. c.ServeSuccessJSON(map[string]interface{}{
  3844. "solution": solution,
  3845. })
  3846. return
  3847. }
  3848. func RemoveRepeatedScheduleTemplate(arr []*models.VmPatientScheduleTemplateItem) (newArr []*models.VmPatientScheduleTemplateItem) {
  3849. newArr = make([]*models.VmPatientScheduleTemplateItem, 0)
  3850. for i := 0; i < len(arr); i++ {
  3851. repeat := false
  3852. for j := i + 1; j < len(arr); j++ {
  3853. if arr[i].TemplateID == arr[j].TemplateID && arr[i].PatientID == arr[j].PatientID && arr[i].Weekday == arr[j].Weekday {
  3854. repeat = true
  3855. break
  3856. }
  3857. }
  3858. if !repeat {
  3859. newArr = append(newArr, arr[i])
  3860. }
  3861. }
  3862. return
  3863. }