schedule_api_controller.go 185KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "XT_New/enums"
  10. "XT_New/models"
  11. "XT_New/service"
  12. "XT_New/utils"
  13. "github.com/jinzhu/gorm"
  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/getschedulethreeone", &ScheduleApiController{}, "Get:GetScheduleThreeList")
  50. beego.Router("/api/schedule/postscheduletemplate", &ScheduleApiController{}, "Get:SaveScheduleTemplate")
  51. beego.Router("/api/schedule/getscheduletemplate", &ScheduleApiController{}, "Get:GetScheduleTemplate")
  52. beego.Router("/api/order/changefuncprint", &ScheduleApiController{}, "Get:ChangeFuncPrint")
  53. beego.Router("/api/order/getdataprint", &ScheduleApiController{}, "Get:GetDataPrint")
  54. beego.Router("/api/schedule/getnextweekpanels", &ScheduleApiController{}, "Get:GetNextWeekPanels")
  55. beego.Router("/api/schedule/synchroschedule", &ScheduleApiController{}, "Get:SynchroSchedule")
  56. beego.Router("/api/schedule/getpatientscheduletemplate", &ScheduleApiController{}, "Get:GetPatientScheduleTempalate")
  57. beego.Router("/api/schedule/getsolutionschedule", &ScheduleApiController{}, "Get:GetSolutionSchedule")
  58. beego.Router("/api/schedule/smartpatientsch", &ScheduleApiController{}, "Get:GetPatient")
  59. beego.Router("/api/schedule/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSchTemplate")
  60. beego.Router("/api/patient/smartpatientsch", &ScheduleApiController{}, "Get:GetPatientSmartSch")
  61. beego.Router("/api/patient/smartpatientschtemplate", &ScheduleApiController{}, "Get:GetPatientSmartSchTemplate")
  62. beego.Router("/api/device/get", &ScheduleApiController{}, "Get:GetDevicesNumbers")
  63. beego.Router("/api/smartsch/batch", &ScheduleApiController{}, "Post:BatchPostSmartSch")
  64. beego.Router("/api/smartsch/get", &ScheduleApiController{}, "Get:GetSmartSch")
  65. beego.Router("/api/sch/exchange", &ScheduleApiController{}, "Get:ExchangeSch")
  66. beego.Router("/api/sch/coversch", &ScheduleApiController{}, "Get:CoverSch")
  67. beego.Router("/api/schedule/delete_two", &ScheduleApiController{}, "Delete:DeleteScheduleTwo")
  68. beego.Router("/api/schedule/create_two", &ScheduleApiController{}, "Post:CreateScheduleTwo")
  69. beego.Router("/api/schedule/changeschedule", &ScheduleApiController{}, "Put:ChangeScheduleTen")
  70. beego.Router("/api/schedule/getordernumber", &ScheduleApiController{}, "Get:GetNumberListById")
  71. }
  72. func (c *ScheduleApiController) CoverSch() {
  73. id_one, _ := c.GetInt64("id_one")
  74. id_two, _ := c.GetInt64("id_two")
  75. sch, _ := service.GetScheduleTen(c.GetAdminUserInfo().CurrentOrgId, id_one)
  76. orgId := c.GetAdminUserInfo().CurrentOrgId
  77. //针对凤凰医院
  78. if orgId == 10579 || orgId == 10344 || orgId == 10206 {
  79. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, orgId)
  80. if len(advice) > 0 {
  81. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, orgId)
  82. }
  83. }
  84. if orgId == 10206 || orgId == 10344 {
  85. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, orgId)
  86. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, orgId)
  87. if len(hisAdvice) > 0 {
  88. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, orgId)
  89. }
  90. if len(project) > 0 {
  91. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, orgId)
  92. }
  93. }
  94. sch_two, _ := service.GetScheduleTen(c.GetAdminUserInfo().CurrentOrgId, id_two)
  95. //order, _ := service.GetDialysisOrder(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  96. //if order.ID > 0 {
  97. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  98. // return
  99. //}
  100. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  101. if order.ID > 0 {
  102. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  103. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  104. redis := service.RedisClient()
  105. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  106. redis.Set(key, "", time.Second)
  107. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  108. //清空key 值
  109. redis.Set(keyOne, "", time.Second)
  110. }
  111. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  112. if orderOne.ID > 0 {
  113. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  114. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  115. redis := service.RedisClient()
  116. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  117. redis.Set(key, "", time.Second)
  118. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  119. //清空key 值
  120. redis.Set(keyOne, "", time.Second)
  121. }
  122. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  123. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  124. count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
  125. if count > 0 {
  126. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  127. return
  128. }
  129. }
  130. var new_sch models.Schedule
  131. new_sch = sch
  132. new_sch.BedId = sch_two.BedId
  133. new_sch.ScheduleDate = sch_two.ScheduleDate
  134. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  135. new_sch.PartitionId = sch_two.PartitionId
  136. new_sch.ScheduleType = sch_two.ScheduleType
  137. new_sch.ID = 0
  138. //删除原来的排班
  139. err := service.SaveSchTwo(sch, sch_two)
  140. //生成新的排班
  141. if err == nil {
  142. err2 := service.SaveSch(&new_sch)
  143. if err2 == nil {
  144. //去除当天患者排班中重复数据,保留最后一条数据
  145. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  146. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  147. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "msg": "覆盖成功",
  150. "new_sch": new_sch,
  151. })
  152. } else {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  154. return
  155. }
  156. } else {
  157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  158. return
  159. }
  160. }
  161. func (c *ScheduleApiController) ExchangeSch() {
  162. id_one, _ := c.GetInt64("id_one")
  163. id_two, _ := c.GetInt64("id_two")
  164. sch, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_one)
  165. sch_two, _ := service.GetSchedule(c.GetAdminUserInfo().CurrentOrgId, id_two)
  166. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  167. //if order2.ID > 0 {
  168. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  169. // return
  170. //}
  171. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  172. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  173. count, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch_two.ScheduleDate, sch.PatientId)
  174. if count > 0 {
  175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  176. return
  177. }
  178. count1, _ := service.GetScheduleCountByDate(c.GetAdminUserInfo().CurrentOrgId, sch.ScheduleDate, sch_two.PatientId)
  179. if count1 > 0 {
  180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  181. return
  182. }
  183. }
  184. err := service.UpdateScheduleThree(sch, sch_two)
  185. fmt.Println("id_one======================", sch.PatientId)
  186. fmt.Println("id_one======================", sch_two.PatientId)
  187. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  188. if order.ID > 0 {
  189. //查询该患者的排班机位
  190. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  191. service.UpdateDialysiOrderByPatientId(order.ID, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  192. redis := service.RedisClient()
  193. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  194. redis.Set(key, "", time.Second)
  195. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  196. //清空key 值
  197. redis.Set(keyOne, "", time.Second)
  198. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  199. //return
  200. }
  201. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  202. if orderOne.ID > 0 {
  203. //查询该患者的排班机位
  204. pSchedule, _ := service.GetPscheduleDate(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  205. service.UpdateDialysiOrderByPatientId(orderOne.ID, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  206. redis := service.RedisClient()
  207. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  208. redis.Set(key, "", time.Second)
  209. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  210. //清空key 值
  211. redis.Set(keyOne, "", time.Second)
  212. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  213. //return
  214. }
  215. if err == nil {
  216. //去除当天患者排班中重复数据,保留最后一条数据
  217. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  218. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  219. c.ServeSuccessJSON(map[string]interface{}{
  220. "msg": "交换成功",
  221. })
  222. } else {
  223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  224. return
  225. }
  226. }
  227. func (c *ScheduleApiController) BatchPostSmartSch() {
  228. patient_id, _ := c.GetInt64("patient_id")
  229. adminInfo := c.GetAdminUserInfo()
  230. patientInfo, _ := service.FindPatientById(adminInfo.CurrentOrgId, patient_id)
  231. if patientInfo.ID == 0 {
  232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  233. return
  234. }
  235. dataBody := make(map[string]interface{}, 0)
  236. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  237. if err != nil {
  238. utils.ErrorLog(err.Error())
  239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  240. return
  241. }
  242. //drugOutConfig, _ := service.FindDrugOutConfigById(adminInfo.CurrentOrgId)
  243. //
  244. //recordDateStr := time.Now().Format("2006-01-02")
  245. //
  246. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  247. //退库
  248. //if drugOutConfig.IsOpen == 1 {
  249. // hisAdvice, _ := service.GetPatientDrugCountToday(patient_id, recordDate.Unix(), adminInfo.CurrentOrgId)
  250. //
  251. // if len(hisAdvice) > 0 {
  252. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  253. // return
  254. // }
  255. //}
  256. //list, _ := service.GetPatientGoodCountToday(patient_id, recordDate.Unix(), adminInfo.CurrentOrgId)
  257. //if len(list) > 0 {
  258. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  259. // return
  260. //}
  261. //数据校验
  262. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  263. schs, _ := dataBody["smart_schs"].([]interface{})
  264. if len(schs) > 0 {
  265. for _, item := range schs {
  266. items := item.(map[string]interface{})
  267. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  268. utils.ErrorLog("id")
  269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  270. return
  271. }
  272. var schedule models.Schedule
  273. //var oldSchedule *models.Schedule
  274. sch_id := int64(items["sch_id"].(float64))
  275. if sch_id > 0 { //修改排班信息
  276. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  277. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  278. utils.ErrorLog("mode_id")
  279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  280. return
  281. }
  282. modeId := int64(items["mode_id"].(float64))
  283. if modeId < 1 {
  284. utils.ErrorLog("modeId < 1")
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  286. return
  287. }
  288. schedule.ModeId = modeId
  289. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  290. if err != nil {
  291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. return
  293. }
  294. if order != nil {
  295. week_type, _ := items["week_type"].(string)
  296. week_name, _ := items["week_name"].(string)
  297. switch week_type {
  298. case "1":
  299. json := make(map[string]interface{})
  300. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  301. json["state"] = 0
  302. c.Data["json"] = json
  303. c.ServeJSON()
  304. break
  305. case "2":
  306. json := make(map[string]interface{})
  307. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  308. json["state"] = 0
  309. c.Data["json"] = json
  310. c.ServeJSON()
  311. break
  312. case "3":
  313. json := make(map[string]interface{})
  314. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  315. json["state"] = 0
  316. c.Data["json"] = json
  317. c.ServeJSON()
  318. break
  319. }
  320. return
  321. }
  322. if order != nil {
  323. week_type, _ := items["week_type"].(string)
  324. week_name, _ := items["week_name"].(string)
  325. switch week_type {
  326. case "1":
  327. json := make(map[string]interface{})
  328. json["msg"] = "本周" + week_name + "的床位已经有人上机,无法保存"
  329. json["state"] = 0
  330. c.Data["json"] = json
  331. c.ServeJSON()
  332. break
  333. case "2":
  334. json := make(map[string]interface{})
  335. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  336. json["state"] = 0
  337. c.Data["json"] = json
  338. c.ServeJSON()
  339. break
  340. case "3":
  341. json := make(map[string]interface{})
  342. json["msg"] = "下周" + week_name + "的床位已经有人上机,无法保存"
  343. json["state"] = 0
  344. c.Data["json"] = json
  345. c.ServeJSON()
  346. break
  347. }
  348. return
  349. }
  350. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  351. utils.ErrorLog("schedule_type")
  352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  353. return
  354. }
  355. scheduleType := int64(items["schedule_type"].(float64))
  356. if scheduleType < 1 || scheduleType > 3 {
  357. utils.ErrorLog("scheduleType < 3")
  358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  359. return
  360. }
  361. schedule.ScheduleType = scheduleType
  362. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  363. utils.ErrorLog("bed_id")
  364. fmt.Println("~~~~~~333333333")
  365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  366. return
  367. }
  368. bedId := int64(items["bed_id"].(float64))
  369. if bedId < 1 {
  370. utils.ErrorLog("bedId < 1")
  371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  372. return
  373. }
  374. schedule.BedId = bedId
  375. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  376. utils.ErrorLog("zone_id")
  377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  378. return
  379. }
  380. partitionId := int64(items["zone_id"].(float64))
  381. if partitionId < 1 {
  382. utils.ErrorLog("partitionId < 1")
  383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  384. return
  385. }
  386. schedule.PartitionId = partitionId
  387. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  388. if bed == nil {
  389. week_type, _ := items["week_type"].(string)
  390. week_name, _ := items["week_name"].(string)
  391. switch week_type {
  392. case "1":
  393. json := make(map[string]interface{})
  394. json["msg"] = "本周" + week_name + "的机号不存在,无法保存"
  395. json["state"] = 0
  396. c.Data["json"] = json
  397. c.ServeJSON()
  398. break
  399. case "2":
  400. json := make(map[string]interface{})
  401. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  402. json["state"] = 0
  403. c.Data["json"] = json
  404. c.ServeJSON()
  405. break
  406. case "3":
  407. json := make(map[string]interface{})
  408. json["msg"] = "下周" + week_name + "的机号不存在,无法保存"
  409. json["state"] = 0
  410. c.Data["json"] = json
  411. c.ServeJSON()
  412. break
  413. }
  414. return
  415. }
  416. if bed.ZoneID != schedule.PartitionId {
  417. week_type, _ := items["week_type"].(string)
  418. week_name, _ := items["week_name"].(string)
  419. switch week_type {
  420. case "1":
  421. json := make(map[string]interface{})
  422. json["msg"] = "本周" + week_name + "所选机号不在选择分区中,无法保存"
  423. json["state"] = 0
  424. c.Data["json"] = json
  425. c.ServeJSON()
  426. break
  427. case "2":
  428. json := make(map[string]interface{})
  429. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  430. json["state"] = 0
  431. c.Data["json"] = json
  432. c.ServeJSON()
  433. break
  434. case "3":
  435. json := make(map[string]interface{})
  436. json["msg"] = "下周" + week_name + "所选机号不在选择分区中,无法保存"
  437. json["state"] = 0
  438. c.Data["json"] = json
  439. c.ServeJSON()
  440. break
  441. }
  442. return
  443. }
  444. startTime := schedule.ScheduleDate
  445. endTime := startTime + 86399
  446. //一天只有排班一次
  447. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  448. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  449. week_type, _ := items["week_type"].(string)
  450. week_name, _ := items["week_name"].(string)
  451. switch week_type {
  452. case "1":
  453. json := make(map[string]interface{})
  454. json["msg"] = "本周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  455. json["state"] = 0
  456. c.Data["json"] = json
  457. c.ServeJSON()
  458. break
  459. case "2":
  460. json := make(map[string]interface{})
  461. json["msg"] = "下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  462. json["state"] = 0
  463. c.Data["json"] = json
  464. c.ServeJSON()
  465. break
  466. case "3":
  467. json := make(map[string]interface{})
  468. json["msg"] = "下下周" + week_name + "已有排班,同一天不可有两次排班,无法保存"
  469. json["state"] = 0
  470. c.Data["json"] = json
  471. c.ServeJSON()
  472. break
  473. }
  474. return
  475. }
  476. //同天同位置只能排一个
  477. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  478. if err != nil {
  479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  480. return
  481. }
  482. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  483. week_type, _ := items["week_type"].(string)
  484. week_name, _ := items["week_name"].(string)
  485. switch week_type {
  486. case "1":
  487. json := make(map[string]interface{})
  488. json["msg"] = "本周" + week_name + "所先位置排班已经存在,无法保存"
  489. json["state"] = 0
  490. c.Data["json"] = json
  491. c.ServeJSON()
  492. break
  493. case "2":
  494. json := make(map[string]interface{})
  495. json["msg"] = "下周" + week_name + "所先位置排班已经存在,无法保存"
  496. json["state"] = 0
  497. c.Data["json"] = json
  498. c.ServeJSON()
  499. break
  500. case "3":
  501. json := make(map[string]interface{})
  502. json["msg"] = "下下周" + week_name + "所先位置排班已经存在,无法保存"
  503. json["state"] = 0
  504. c.Data["json"] = json
  505. c.ServeJSON()
  506. break
  507. }
  508. return
  509. }
  510. } else { //新的排班信息
  511. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  513. return
  514. }
  515. scheduleDate, _ := items["schedule_date"].(string)
  516. if len(scheduleDate) == 0 {
  517. utils.ErrorLog("len(schedule_date) == 0")
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  519. return
  520. }
  521. timeLayout := "2006-01-02"
  522. loc, _ := time.LoadLocation("Local")
  523. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  524. if err != nil {
  525. utils.ErrorLog(err.Error())
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  527. return
  528. }
  529. schedule.ScheduleDate = theTime.Unix()
  530. //existSch,_ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId,schedule.ScheduleDate,patient_id)
  531. //
  532. //if existSch.ID > 0{
  533. // fmt.Println("555555555")
  534. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  535. // return
  536. //
  537. //}
  538. timeNow := time.Now().Format("2006-01-02")
  539. if timeNow > scheduleDate {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  541. return
  542. }
  543. scheduleType := int64(items["schedule_type"].(float64))
  544. if scheduleType < 1 || scheduleType > 3 {
  545. utils.ErrorLog("scheduleType < 3")
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  547. return
  548. }
  549. schedule.ScheduleType = scheduleType
  550. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. bedId := int64(items["bed_id"].(float64))
  555. if bedId < 1 {
  556. utils.ErrorLog("bedId < 1")
  557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  558. return
  559. }
  560. schedule.BedId = bedId
  561. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  562. utils.ErrorLog("zone_id")
  563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  564. return
  565. }
  566. partitionId := int64(items["zone_id"].(float64))
  567. if partitionId < 1 {
  568. utils.ErrorLog("zone_id < 1")
  569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  570. return
  571. }
  572. schedule.PartitionId = partitionId
  573. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  574. utils.ErrorLog("schedule_week")
  575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  576. return
  577. }
  578. scheduleWeek := int64(items["schedule_week"].(float64))
  579. if scheduleWeek < 1 || scheduleWeek > 7 {
  580. utils.ErrorLog("scheduleWeek < 1")
  581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  582. return
  583. }
  584. schedule.ScheduleWeek = scheduleWeek
  585. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  586. utils.ErrorLog("mode_id")
  587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  588. return
  589. }
  590. modeId := int64(items["mode_id"].(float64))
  591. if modeId < 1 && modeId > 14 {
  592. utils.ErrorLog("modeId < 1")
  593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  594. return
  595. }
  596. //校验当天改床位是否有排班,如果有排班则不能替换排班
  597. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  598. fmt.Println(sch.PatientId)
  599. fmt.Println(schedule.PatientId)
  600. if sch.ID > 0 && sch.PatientId != patient_id {
  601. week_type, _ := items["week_type"].(string)
  602. week_name, _ := items["week_name"].(string)
  603. switch week_type {
  604. case "1":
  605. json := make(map[string]interface{})
  606. json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  607. json["state"] = 0
  608. c.Data["json"] = json
  609. c.ServeJSON()
  610. break
  611. case "2":
  612. json := make(map[string]interface{})
  613. json["msg"] = "下周" + week_name + "该床位已经有人排班,无法保存"
  614. json["state"] = 0
  615. c.Data["json"] = json
  616. c.ServeJSON()
  617. break
  618. case "3":
  619. json := make(map[string]interface{})
  620. json["msg"] = "下下周" + week_name + "该床位已经有人排班,无法保存"
  621. json["state"] = 0
  622. c.Data["json"] = json
  623. c.ServeJSON()
  624. break
  625. }
  626. return
  627. }
  628. //daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  629. //if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  630. // week_type, _ := items["week_type"].(string)
  631. // week_name, _ := items["week_name"].(string)
  632. //
  633. // switch week_type {
  634. // case "1":
  635. // json := make(map[string]interface{})
  636. // json["msg"] = "本周" + week_name + "该床位已经有人排班,无法保存"
  637. // json["state"] = 0
  638. // c.Data["json"] = json
  639. // c.ServeJSON()
  640. // break
  641. // case "2":
  642. // json := make(map[string]interface{})
  643. // json["msg"] = "下周" + week_name + "当天该患者已经排班,无法保存"
  644. // json["state"] = 0
  645. // c.Data["json"] = json
  646. // c.ServeJSON()
  647. // break
  648. // case "3":
  649. // json := make(map[string]interface{})
  650. // json["msg"] = "下下周" + week_name + "当天该患者已经排班,无法保存"
  651. // json["state"] = 0
  652. // c.Data["json"] = json
  653. // c.ServeJSON()
  654. // break
  655. // }
  656. //
  657. // return
  658. //
  659. //
  660. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  661. // return
  662. //}
  663. //
  664. }
  665. }
  666. }
  667. }
  668. ////删除数据
  669. if dataBody["del_schs"] != nil && reflect.TypeOf(dataBody["del_schs"]).String() == "[]interface {}" {
  670. schs, _ := dataBody["del_schs"].([]interface{})
  671. if len(schs) > 0 {
  672. for _, item := range schs {
  673. items := item.(map[string]interface{})
  674. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  675. utils.ErrorLog("id")
  676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  677. return
  678. }
  679. var schedule models.Schedule
  680. sch_id := int64(items["sch_id"].(float64))
  681. if sch_id > 0 { //修改排班信息
  682. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  683. order, _ := service.GetDialysisOrderByPatientAndBed(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.BedId, schedule.PatientId)
  684. if order.ID > 0 {
  685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  686. return
  687. }
  688. schedule.Status = 0
  689. //针对凤凰医院
  690. if adminInfo.CurrentOrgId == 10579 || adminInfo.CurrentOrgId == 10344 || adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10679 {
  691. advice, _ := service.GetDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  692. if len(advice) > 0 {
  693. service.UpdateAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  694. }
  695. }
  696. //if adminInfo.CurrentOrgId == 10206 || adminInfo.CurrentOrgId == 10344 {
  697. // hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  698. // project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  699. // if len(hisAdvice) > 0 {
  700. // service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  701. // }
  702. // if len(project) > 0 {
  703. // service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, adminInfo.CurrentOrgId)
  704. // }
  705. //}
  706. service.SaveSch(&schedule)
  707. }
  708. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  709. //去除当天患者排班中重复数据,保留最后一条数据
  710. service.UpdateRepeatSchStatus(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  711. }
  712. }
  713. }
  714. ////修改或保存数据
  715. if dataBody["smart_schs"] != nil && reflect.TypeOf(dataBody["smart_schs"]).String() == "[]interface {}" {
  716. schs, _ := dataBody["smart_schs"].([]interface{})
  717. if len(schs) > 0 {
  718. for _, item := range schs {
  719. items := item.(map[string]interface{})
  720. if items["sch_id"] == nil || reflect.TypeOf(items["sch_id"]).String() != "float64" {
  721. utils.ErrorLog("id")
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  723. return
  724. }
  725. var schedule models.Schedule
  726. //var oldSchedule *models.Schedule
  727. sch_id := int64(items["sch_id"].(float64))
  728. if sch_id > 0 { //修改排班信息
  729. fmt.Println("!!!!!!!")
  730. schedule, _ = service.GetScheduleTwo(adminInfo.CurrentOrgId, sch_id)
  731. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  732. fmt.Println(reflect.TypeOf(items["mode_id"]))
  733. utils.ErrorLog("mode_id")
  734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  735. return
  736. }
  737. modeId := int64(items["mode_id"].(float64))
  738. if modeId < 1 {
  739. utils.ErrorLog("modeId < 1")
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. schedule.ModeId = modeId
  744. order, err := service.GetOneDialysisOrder(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  745. if err != nil {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  747. return
  748. }
  749. if order != nil {
  750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  751. return
  752. }
  753. if order != nil {
  754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  755. return
  756. }
  757. if items["schedule_type"] == nil || reflect.TypeOf(items["schedule_type"]).String() != "float64" {
  758. utils.ErrorLog("schedule_type")
  759. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  760. return
  761. }
  762. scheduleType := int64(items["schedule_type"].(float64))
  763. if scheduleType < 1 || scheduleType > 3 {
  764. utils.ErrorLog("scheduleType < 3")
  765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  766. return
  767. }
  768. schedule.ScheduleType = scheduleType
  769. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  770. utils.ErrorLog("bed_id")
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. bedId := int64(items["bed_id"].(float64))
  775. if bedId < 1 {
  776. utils.ErrorLog("bedId < 1")
  777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  778. return
  779. }
  780. schedule.BedId = bedId
  781. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  782. utils.ErrorLog("zone_id")
  783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  784. return
  785. }
  786. partitionId := int64(items["zone_id"].(float64))
  787. if partitionId < 1 {
  788. utils.ErrorLog("partitionId < 1")
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  790. return
  791. }
  792. schedule.PartitionId = partitionId
  793. bed, _ := service.GetDeviceNumberByID(adminInfo.CurrentOrgId, schedule.BedId)
  794. if bed == nil {
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  796. return
  797. }
  798. if bed.ZoneID != schedule.PartitionId {
  799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  800. return
  801. }
  802. startTime := schedule.ScheduleDate
  803. endTime := startTime + 86399
  804. //一天只有排班一次
  805. daySchedule, err := service.GetDaySchedule(adminInfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  806. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  808. return
  809. }
  810. //同天同位置只能排一个
  811. pointSchedule, err := service.GetPointSchedule(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  812. if err != nil {
  813. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  814. return
  815. }
  816. if pointSchedule.ID > 0 && pointSchedule.PatientId != patient_id {
  817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  818. return
  819. }
  820. var DialysisMachineName string
  821. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  822. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  823. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  824. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  825. if filedRecordOne.IsShow == 1 {
  826. DialysisMachineName = so.DialysisDialyszers
  827. }
  828. if filedRecordThree.IsShow == 1 {
  829. if len(DialysisMachineName) > 0 {
  830. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  831. } else {
  832. DialysisMachineName = so.DialyzerPerfusionApparatus
  833. }
  834. }
  835. if filedRecordTwo.IsShow == 1 {
  836. if len(DialysisMachineName) > 0 {
  837. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  838. } else {
  839. DialysisMachineName = so.DialysisIrrigation
  840. }
  841. }
  842. schedule.DialysisMachineName = DialysisMachineName
  843. schedule.IsExport = 3000
  844. service.SaveSch(&schedule)
  845. //去除当天患者排班中重复数据,保留最后一条数据
  846. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  847. } else { //新的排班信息
  848. if items["schedule_date"] == nil || reflect.TypeOf(items["schedule_date"]).String() != "string" {
  849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  850. return
  851. }
  852. scheduleDate, _ := items["schedule_date"].(string)
  853. if len(scheduleDate) == 0 {
  854. utils.ErrorLog("len(schedule_date) == 0")
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. return
  857. }
  858. timeLayout := "2006-01-02"
  859. loc, _ := time.LoadLocation("Local")
  860. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  861. if err != nil {
  862. utils.ErrorLog(err.Error())
  863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  864. return
  865. }
  866. schedule.ScheduleDate = theTime.Unix()
  867. timeNow := time.Now().Format("2006-01-02")
  868. if timeNow > scheduleDate {
  869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  870. return
  871. }
  872. scheduleType := int64(items["schedule_type"].(float64))
  873. if scheduleType < 1 || scheduleType > 3 {
  874. utils.ErrorLog("scheduleType < 3")
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  876. return
  877. }
  878. schedule.ScheduleType = scheduleType
  879. if items["bed_id"] == nil || reflect.TypeOf(items["bed_id"]).String() != "float64" {
  880. utils.ErrorLog("bed_id")
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  882. return
  883. }
  884. bedId := int64(items["bed_id"].(float64))
  885. if bedId < 1 {
  886. utils.ErrorLog("bedId < 1")
  887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  888. return
  889. }
  890. schedule.BedId = bedId
  891. if items["zone_id"] == nil || reflect.TypeOf(items["zone_id"]).String() != "float64" {
  892. utils.ErrorLog("zone_id")
  893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  894. return
  895. }
  896. partitionId := int64(items["zone_id"].(float64))
  897. if partitionId < 1 {
  898. utils.ErrorLog("zone_id < 1")
  899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  900. return
  901. }
  902. schedule.PartitionId = partitionId
  903. if items["schedule_week"] == nil || reflect.TypeOf(items["schedule_week"]).String() != "float64" {
  904. utils.ErrorLog("schedule_week")
  905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  906. return
  907. }
  908. scheduleWeek := int64(items["schedule_week"].(float64))
  909. if scheduleWeek < 1 || scheduleWeek > 7 {
  910. utils.ErrorLog("scheduleWeek < 1")
  911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  912. return
  913. }
  914. schedule.ScheduleWeek = scheduleWeek
  915. if items["mode_id"] == nil || reflect.TypeOf(items["mode_id"]).String() != "float64" {
  916. fmt.Println(reflect.TypeOf(items["mode_id"]))
  917. utils.ErrorLog("mode_id")
  918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  919. return
  920. }
  921. modeId := int64(items["mode_id"].(float64))
  922. if modeId < 1 && modeId > 14 {
  923. utils.ErrorLog("modeId < 1")
  924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  925. return
  926. }
  927. //校验当天改床位是否有排班,如果有排班则不能替换排班
  928. sch, _ := service.GetScheduleByZoneAndBed(adminInfo.CurrentOrgId, partitionId, bedId, schedule.ScheduleDate, schedule.ScheduleType)
  929. if sch.ID > 0 && sch.PatientId != patient_id {
  930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorSchedualcRepeatBed)
  931. return
  932. }
  933. var DialysisMachineName string
  934. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  935. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  936. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  937. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  938. if filedRecordOne.IsShow == 1 {
  939. DialysisMachineName = so.DialysisDialyszers
  940. }
  941. if filedRecordThree.IsShow == 1 {
  942. if len(schedule.DialysisMachineName) > 0 {
  943. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  944. } else {
  945. DialysisMachineName = so.DialyzerPerfusionApparatus
  946. }
  947. }
  948. if filedRecordTwo.IsShow == 1 {
  949. if len(DialysisMachineName) > 0 {
  950. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  951. } else {
  952. DialysisMachineName = so.DialysisIrrigation
  953. }
  954. }
  955. schedule.DialysisMachineName = DialysisMachineName
  956. //判断当前保存的患者是否已经有排班
  957. existSchedule, _ := service.GetScheduleByDate(adminInfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  958. if existSchedule.ID > 0 {
  959. existSchedule.ModeId = modeId
  960. existSchedule.BedId = schedule.BedId
  961. existSchedule.PartitionId = schedule.PartitionId
  962. existSchedule.ScheduleType = schedule.ScheduleType
  963. existSchedule.DialysisMachineName = schedule.DialysisMachineName
  964. existSchedule.IsExport = 3001
  965. service.SaveSmartSch(existSchedule)
  966. } else {
  967. schedule.ModeId = modeId
  968. schedule.PatientId = patient_id
  969. schedule.CreatedTime = time.Now().Unix()
  970. schedule.UpdatedTime = time.Now().Unix()
  971. schedule.Status = 1
  972. schedule.UserOrgId = adminInfo.CurrentOrgId
  973. var DialysisMachineName string
  974. so, _ := service.GetDialysisSolutionTwo(adminInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  975. filedRecordOne, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器")
  976. filedRecordTwo, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "灌流器")
  977. filedRecordThree, _ := service.FindFiledBy(adminInfo.CurrentOrgId, "透析器/灌流器")
  978. if filedRecordOne.IsShow == 1 {
  979. DialysisMachineName = so.DialysisDialyszers
  980. }
  981. if filedRecordThree.IsShow == 1 {
  982. if len(DialysisMachineName) > 0 {
  983. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  984. } else {
  985. DialysisMachineName = so.DialyzerPerfusionApparatus
  986. }
  987. }
  988. if filedRecordTwo.IsShow == 1 {
  989. if len(DialysisMachineName) > 0 {
  990. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  991. } else {
  992. DialysisMachineName = so.DialysisIrrigation
  993. }
  994. }
  995. schedule.DialysisMachineName = DialysisMachineName
  996. //schedule.DialysisMachineName = schedule.DialysisMachineName
  997. daySchedule, _ := service.GetDaySchedule(adminInfo.CurrentOrgId, theTime.Unix(), theTime.Unix(), patient_id)
  998. if daySchedule.ID > 0 {
  999. daySchedule.ModeId = schedule.ModeId
  1000. daySchedule.ScheduleType = schedule.ScheduleType
  1001. daySchedule.PartitionId = schedule.PartitionId
  1002. daySchedule.BedId = schedule.BedId
  1003. daySchedule.DialysisMachineName = schedule.DialysisMachineName
  1004. existSchedule.IsExport = 3002
  1005. service.SaveSch(&daySchedule)
  1006. } else {
  1007. existSchedule.IsExport = 3003
  1008. service.CreateScheduleTwo(&schedule)
  1009. }
  1010. }
  1011. }
  1012. //去除当天患者排班中重复数据,保留最后一条数据
  1013. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  1014. c.ServeSuccessJSON(map[string]interface{}{
  1015. "msg": "保存成功",
  1016. })
  1017. HandleRedis(adminInfo.CurrentOrgId, schedule.ScheduleDate)
  1018. }
  1019. } else {
  1020. c.ServeSuccessJSON(map[string]interface{}{
  1021. "msg": "保存成功",
  1022. })
  1023. }
  1024. }
  1025. }
  1026. func HandleRedis(org_id int64, sch_date int64) {
  1027. redis := service.RedisClient()
  1028. //处方
  1029. keyOne := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":prescriptions_list_all"
  1030. redis.Set(keyOne, "", time.Second)
  1031. //医嘱
  1032. keyTwo := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":advice_list_all"
  1033. redis.Set(keyTwo, "", time.Second)
  1034. keySix := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_befores_list_all"
  1035. redis.Set(keySix, "", time.Second)
  1036. keyThree := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":assessment_after_dislysis_list_all"
  1037. redis.Set(keyThree, "", time.Second)
  1038. keyFour := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":monitor_record_list_all"
  1039. redis.Set(keyFour, "", time.Second)
  1040. keyFive := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":treatment_summarys_list_all"
  1041. redis.Set(keyFive, "", time.Second)
  1042. keySeven := strconv.FormatInt(org_id, 10) + ":" + strconv.FormatInt(sch_date, 10) + ":dialysis_orders_list_all"
  1043. redis.Set(keySeven, "", time.Second)
  1044. defer redis.Close()
  1045. }
  1046. func (c *ScheduleApiController) GetSmartSch() {
  1047. patient_id, _ := c.GetInt64("patient_id")
  1048. fmt.Println("~~~~~~")
  1049. fmt.Println(patient_id)
  1050. fmt.Println("~~~~~~")
  1051. adminUserInfo := c.GetAdminUserInfo()
  1052. sch, err := service.GetSmartSchPatientByPatientID(adminUserInfo.CurrentOrgId, patient_id)
  1053. if err != nil {
  1054. utils.ErrorLog(err.Error())
  1055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1056. return
  1057. }
  1058. c.ServeSuccessJSON(map[string]interface{}{
  1059. "sch": sch,
  1060. })
  1061. }
  1062. func (c *ScheduleApiController) GetPatient() {
  1063. keyWord := c.GetString("keyword")
  1064. adminUserInfo := c.GetAdminUserInfo()
  1065. patient, err := service.GetSmartSchPatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  1066. if err != nil {
  1067. utils.ErrorLog(err.Error())
  1068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1069. return
  1070. }
  1071. c.ServeSuccessJSON(map[string]interface{}{
  1072. "patient": patient,
  1073. })
  1074. }
  1075. func (c *ScheduleApiController) GetPatientSchTemplate() {
  1076. //patient_id, _ := c.GetInt64("patient_id",0)
  1077. keyWord := c.GetString("keyword")
  1078. adminUserInfo := c.GetAdminUserInfo()
  1079. patient, err := service.GetSmartSchTemplatePatientByKeyWord(adminUserInfo.CurrentOrgId, keyWord)
  1080. if err != nil {
  1081. utils.ErrorLog(err.Error())
  1082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1083. return
  1084. }
  1085. c.ServeSuccessJSON(map[string]interface{}{
  1086. "patient": patient,
  1087. })
  1088. }
  1089. func (c *ScheduleApiController) GetPatientSmartSch() {
  1090. patient_id, _ := c.GetInt64("patient_id", 0)
  1091. adminUserInfo := c.GetAdminUserInfo()
  1092. schs, err := service.GetSmartSchPatientByID(adminUserInfo.CurrentOrgId, patient_id)
  1093. if err != nil {
  1094. utils.ErrorLog(err.Error())
  1095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1096. return
  1097. }
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "schedules": schs,
  1100. })
  1101. }
  1102. func (c *ScheduleApiController) GetPatientSmartSchTemplate() {
  1103. patient_id, _ := c.GetInt64("patient_id", 0)
  1104. adminUserInfo := c.GetAdminUserInfo()
  1105. mode, _ := service.GetOrgPatientScheduleTemplateModeTwo(adminUserInfo.CurrentOrgId)
  1106. if mode.ID > 0 {
  1107. if mode.Mode == 0 {
  1108. //schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id)
  1109. c.ServeSuccessJSON(map[string]interface{}{
  1110. "status": 0,
  1111. })
  1112. } else if mode.Mode == 1 {
  1113. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 1)
  1114. c.ServeSuccessJSON(map[string]interface{}{
  1115. "status": 0,
  1116. "schedules_template": schs,
  1117. })
  1118. } else if mode.Mode == 2 {
  1119. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 2)
  1120. c.ServeSuccessJSON(map[string]interface{}{
  1121. "status": 1,
  1122. "schedules_template": schs,
  1123. })
  1124. } else if mode.Mode == 3 {
  1125. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 3)
  1126. c.ServeSuccessJSON(map[string]interface{}{
  1127. "status": 1,
  1128. "schedules_template": schs,
  1129. })
  1130. } else if mode.Mode == 4 {
  1131. schs, _ := service.GetSmartSchTemplatePatientByID(adminUserInfo.CurrentOrgId, patient_id, 4)
  1132. c.ServeSuccessJSON(map[string]interface{}{
  1133. "status": 1,
  1134. "schedules_template": schs,
  1135. })
  1136. }
  1137. } else {
  1138. c.ServeSuccessJSON(map[string]interface{}{
  1139. "status": 0,
  1140. })
  1141. }
  1142. }
  1143. func (c *ScheduleApiController) GetDevicesNumbers() {
  1144. sch_type, _ := c.GetInt("sch_type", 0)
  1145. zone_id, _ := c.GetInt64("zone_id", 0)
  1146. patient_id, _ := c.GetInt64("patient_id", 0)
  1147. schedule_date := c.GetString("schedule_date")
  1148. timeLayout := "2006-01-02"
  1149. loc, _ := time.LoadLocation("Local")
  1150. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  1151. if err != nil {
  1152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1153. return
  1154. }
  1155. recordDateTime := theTime.Unix()
  1156. deviceNumbers, getDeviceNumbersErr := service.GetAllAvaildDeviceNumbersByZone(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, sch_type, zone_id, patient_id)
  1157. if getDeviceNumbersErr != nil {
  1158. c.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1160. return
  1161. }
  1162. c.ServeSuccessJSON(map[string]interface{}{
  1163. "devices": deviceNumbers,
  1164. })
  1165. }
  1166. func (c *ScheduleApiController) GetWeekPanels() {
  1167. data, _ := c.GetInt64("data", 1)
  1168. patitionIdStr := c.GetString("patitionid")
  1169. var ids []string
  1170. if len(patitionIdStr) > 0 {
  1171. ids = strings.Split(patitionIdStr, ",")
  1172. }
  1173. adminInfo := c.GetAdminUserInfo()
  1174. thisTime := time.Now()
  1175. year, monthTime, day := thisTime.Date()
  1176. month := int(monthTime)
  1177. _, theWeek := thisTime.ISOWeek()
  1178. lastWeek := thisTime.AddDate(0, 0, -7)
  1179. nextWeek := thisTime.AddDate(0, 0, 7)
  1180. nextSecWeek := thisTime.AddDate(0, 0, 14)
  1181. _, theLastWeek := lastWeek.ISOWeek()
  1182. _, theNextWeek := nextWeek.ISOWeek()
  1183. _, theNextSecWeek := nextSecWeek.ISOWeek()
  1184. weekDay := int(thisTime.Weekday())
  1185. if weekDay == 0 {
  1186. weekDay = 7
  1187. }
  1188. weekEnd := 7 - weekDay
  1189. weekStart := weekEnd - 6
  1190. weekDays := make([]string, 0)
  1191. for index := weekStart; index <= weekEnd; index++ {
  1192. theDay := thisTime.AddDate(0, 0, index)
  1193. indexYear, indexMonthTime, indexDay := theDay.Date()
  1194. indexMonth := int(indexMonthTime)
  1195. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1196. weekDays = append(weekDays, indexWeek)
  1197. }
  1198. returnData := map[string]interface{}{
  1199. "year": year,
  1200. "month": month,
  1201. "day": day,
  1202. "theWeek": theWeek,
  1203. "theNextWeek": theNextWeek,
  1204. "theNextSecWeek": theNextSecWeek,
  1205. "theLastWeek": theLastWeek,
  1206. "weekDay": weekDay,
  1207. "weekDays": weekDays,
  1208. }
  1209. if data == 1 {
  1210. partitions, _ := service.GetSchedulePartitionPanelOne(adminInfo.CurrentOrgId, ids)
  1211. returnData["partitions"] = partitions
  1212. }
  1213. c.ServeSuccessJSON(returnData)
  1214. return
  1215. }
  1216. func (c *ScheduleApiController) GetSchedules() {
  1217. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  1218. partition_id, _ := c.GetInt64("partition_id")
  1219. schedule_type, _ := c.GetInt64("schedule_type")
  1220. is_before, _ := c.GetInt64("is_before")
  1221. start_time := c.GetString("start_time")
  1222. end_time := c.GetString("end_time")
  1223. adminInfo := c.GetAdminUserInfo()
  1224. thisTime := time.Now()
  1225. today := thisTime.Format("2006-01-02")
  1226. if week < 1 || week > 4 {
  1227. week = 2
  1228. }
  1229. if week == 1 {
  1230. thisTime = thisTime.AddDate(0, 0, -7)
  1231. } else if week == 3 {
  1232. thisTime = thisTime.AddDate(0, 0, 7)
  1233. } else if week == 4 {
  1234. thisTime = thisTime.AddDate(0, 0, 14)
  1235. }
  1236. weekDay := int(thisTime.Weekday())
  1237. if weekDay == 0 {
  1238. weekDay = 7
  1239. }
  1240. weekEnd := 7 - weekDay
  1241. weekStart := weekEnd - 6
  1242. weekTitle := make([]string, 0)
  1243. days := make([]string, 0)
  1244. for index := weekStart; index <= weekEnd; index++ {
  1245. theDay := thisTime.AddDate(0, 0, index)
  1246. indexYear, indexMonthTime, indexDay := theDay.Date()
  1247. indexMonth := int(indexMonthTime)
  1248. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  1249. weekTitle = append(weekTitle, indexWeek)
  1250. days = append(days, theDay.Format("2006-01-02"))
  1251. }
  1252. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  1253. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  1254. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1255. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1256. timeLayout := "2006-01-02 15:04:05"
  1257. loc, _ := time.LoadLocation("Local")
  1258. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1259. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1260. weekStartPoint := theStarTime.Unix()
  1261. weekEndPoint := theEndTime.Unix()
  1262. if is_before > 0 {
  1263. timeLayout := "2006-01-02 15:04:05"
  1264. loc, _ := time.LoadLocation("Local")
  1265. theStarTime, _ := time.ParseInLocation(timeLayout, start_time, loc)
  1266. theEndTime, _ := time.ParseInLocation(timeLayout, end_time, loc)
  1267. weekStartPoint = theStarTime.Unix()
  1268. weekEndPoint = theEndTime.Unix()
  1269. }
  1270. schdules, _ := service.GetWeekScheduleOne(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, partition_id, schedule_type)
  1271. c.ServeSuccessJSON(map[string]interface{}{
  1272. "days": days,
  1273. "weekTitle": weekTitle,
  1274. "schdules": schdules,
  1275. "today": today,
  1276. })
  1277. return
  1278. }
  1279. func (c *ScheduleApiController) GetPatients() {
  1280. keywords := c.GetString("keywords", "")
  1281. schedule, _ := c.GetInt64("schedule", 0) //1已2未
  1282. contagion, _ := c.GetInt64("contagion", 0)
  1283. adminInfo := c.GetAdminUserInfo()
  1284. thisTime := time.Now()
  1285. weekDay := int(thisTime.Weekday())
  1286. if weekDay == 0 {
  1287. weekDay = 7
  1288. }
  1289. thisWeekEnd := 7 - weekDay
  1290. weekStartPoint := thisWeekEnd - 6
  1291. weekStartDay := thisTime.AddDate(0, 0, weekStartPoint)
  1292. weekEndPoint := thisWeekEnd + 7
  1293. weekEndDay := thisTime.AddDate(0, 0, weekEndPoint)
  1294. fmt.Println(weekStartPoint, weekStartDay, weekEndPoint, weekEndDay)
  1295. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  1296. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  1297. fmt.Println(weekStartTime, weekEndTime)
  1298. timeLayout := "2006-01-02 15:04:05"
  1299. loc, _ := time.LoadLocation("Local")
  1300. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  1301. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  1302. weekStart := theStarTime.Unix()
  1303. weekEnd := theEndTime.Unix()
  1304. patients, _ := service.GetPatientWithScheduleAndSolution(adminInfo.CurrentOrgId, keywords, weekStart, weekEnd, schedule, contagion)
  1305. c.ServeSuccessJSON(map[string]interface{}{
  1306. "patients": patients,
  1307. })
  1308. return
  1309. }
  1310. func (c *ScheduleApiController) CreateSchedule() {
  1311. patientID, _ := c.GetInt64("patient_id", 0)
  1312. if patientID <= 0 {
  1313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1314. return
  1315. }
  1316. adminUserInfo := c.GetAdminUserInfo()
  1317. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  1318. if patientInfo.ID == 0 {
  1319. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1320. return
  1321. }
  1322. var schedule models.Schedule
  1323. dataBody := make(map[string]interface{}, 0)
  1324. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1325. if err != nil {
  1326. utils.ErrorLog(err.Error())
  1327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1328. return
  1329. }
  1330. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  1331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1332. return
  1333. }
  1334. scheduleDate, _ := dataBody["schedule_date"].(string)
  1335. if len(scheduleDate) == 0 {
  1336. utils.ErrorLog("len(schedule_date) == 0")
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. timeLayout := "2006-01-02"
  1341. loc, _ := time.LoadLocation("Local")
  1342. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  1343. if err != nil {
  1344. utils.ErrorLog(err.Error())
  1345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1346. return
  1347. }
  1348. schedule.ScheduleDate = theTime.Unix()
  1349. timeNow := time.Now().Format("2006-01-02")
  1350. if timeNow > scheduleDate {
  1351. utils.ErrorLog(timeNow)
  1352. utils.ErrorLog(scheduleDate)
  1353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1354. return
  1355. }
  1356. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1357. utils.ErrorLog("schedule_type")
  1358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1359. return
  1360. }
  1361. scheduleType := int64(dataBody["schedule_type"].(float64))
  1362. if scheduleType < 1 || scheduleType > 3 {
  1363. utils.ErrorLog("scheduleType < 3")
  1364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1365. return
  1366. }
  1367. schedule.ScheduleType = scheduleType
  1368. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1369. utils.ErrorLog("bed_id")
  1370. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1371. return
  1372. }
  1373. bedId := int64(dataBody["bed_id"].(float64))
  1374. if bedId < 1 {
  1375. utils.ErrorLog("bedId < 1")
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1377. return
  1378. }
  1379. schedule.BedId = bedId
  1380. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1381. utils.ErrorLog("partition_id")
  1382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1383. return
  1384. }
  1385. partitionId := int64(dataBody["partition_id"].(float64))
  1386. if partitionId < 1 {
  1387. utils.ErrorLog("partitionId < 1")
  1388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1389. return
  1390. }
  1391. schedule.PartitionId = partitionId
  1392. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1393. utils.ErrorLog("schedule_week")
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1395. return
  1396. }
  1397. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1398. if scheduleWeek < 1 || scheduleWeek > 7 {
  1399. utils.ErrorLog("scheduleWeek < 1")
  1400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1401. return
  1402. }
  1403. schedule.ScheduleWeek = scheduleWeek
  1404. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1405. utils.ErrorLog("mode_id")
  1406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1407. return
  1408. }
  1409. modeId := int64(dataBody["mode_id"].(float64))
  1410. if modeId < 1 && modeId > 14 {
  1411. utils.ErrorLog("modeId < 1")
  1412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1413. return
  1414. }
  1415. schedule.ModeId = modeId
  1416. schedule.PatientId = patientID
  1417. schedule.CreatedTime = time.Now().Unix()
  1418. schedule.UpdatedTime = time.Now().Unix()
  1419. schedule.Status = 1
  1420. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1421. schedule.IsExport = 5
  1422. var DialysisMachineName string
  1423. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1424. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1425. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1426. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1427. if filedRecordOne.IsShow == 1 {
  1428. DialysisMachineName = so.DialysisDialyszers
  1429. }
  1430. if filedRecordThree.IsShow == 1 {
  1431. if len(DialysisMachineName) > 0 {
  1432. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1433. } else {
  1434. DialysisMachineName = so.DialyzerPerfusionApparatus
  1435. }
  1436. }
  1437. if filedRecordTwo.IsShow == 1 {
  1438. if len(DialysisMachineName) > 0 {
  1439. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1440. } else {
  1441. DialysisMachineName = so.DialysisIrrigation
  1442. }
  1443. }
  1444. schedule.DialysisMachineName = DialysisMachineName
  1445. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1446. if bed == nil {
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1448. return
  1449. }
  1450. if bed.ZoneID != schedule.PartitionId {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1452. return
  1453. }
  1454. scheduleDateStart := scheduleDate + " 00:00:00"
  1455. scheduleDateEnd := scheduleDate + " 23:59:59"
  1456. timeLayout = "2006-01-02 15:04:05"
  1457. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1458. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1459. startTime := theStartTime.Unix()
  1460. endTime := theEndTime.Unix()
  1461. //一天只有排班一次
  1462. daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1463. if daySchedule.ID > 0 {
  1464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1465. return
  1466. }
  1467. //同天同位置只能排一个
  1468. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1469. if err != nil {
  1470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1471. return
  1472. }
  1473. if pointSchedule.ID > 0 {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1475. return
  1476. }
  1477. redis := service.RedisClient()
  1478. schedule.IsExport = 1000
  1479. err = service.CreateScheduleTwo(&schedule)
  1480. //记录日志
  1481. byterequest, _ := json.Marshal(schedule)
  1482. scheduleLog := models.XtScheduleLog{
  1483. UserOrgId: adminUserInfo.CurrentOrgId,
  1484. RecordDate: schedule.ScheduleDate,
  1485. Status: 1,
  1486. PatientId: schedule.PatientId,
  1487. Ctime: time.Now().Unix(),
  1488. Mtime: 0,
  1489. ErrLog: string(byterequest),
  1490. Source: "电脑端新增排班",
  1491. Module: 1,
  1492. AdminUserId: adminUserInfo.AdminUser.Id,
  1493. }
  1494. service.CreateScheduleLog(scheduleLog)
  1495. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1496. redis.Set(key, "", time.Second)
  1497. //处方
  1498. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1499. redis.Set(keyOne, "", time.Second)
  1500. //医嘱
  1501. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1502. redis.Set(keyTwo, "", time.Second)
  1503. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1504. redis.Set(keySix, "", time.Second)
  1505. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1506. redis.Set(keyThree, "", time.Second)
  1507. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1508. redis.Set(keyFour, "", time.Second)
  1509. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1510. redis.Set(keyFive, "", time.Second)
  1511. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1512. redis.Set(keySeven, "", time.Second)
  1513. fmt.Println(err)
  1514. defer redis.Close()
  1515. if err != nil {
  1516. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateScheduleFail)
  1517. return
  1518. }
  1519. schedule.Patient = patientInfo.Name
  1520. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "msg": "ok",
  1523. "schedule": schedule,
  1524. })
  1525. return
  1526. }
  1527. func (c *ScheduleApiController) CreateScheduleTwo() {
  1528. patientID, _ := c.GetInt64("patient_id", 0)
  1529. id, _ := c.GetInt64("id_two", 0)
  1530. if id <= 0 {
  1531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1532. return
  1533. }
  1534. adminINfo := c.GetAdminUserInfo()
  1535. schedule_two, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1536. timeNow := time.Now().Format("2006-01-02")
  1537. timeTemplate := "2006-01-02"
  1538. tm := time.Unix(int64(schedule_two.ScheduleDate), 0)
  1539. timeStr := tm.Format(timeTemplate)
  1540. if timeNow > timeStr {
  1541. utils.ErrorLog(timeNow)
  1542. utils.ErrorLog(timeStr)
  1543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1544. return
  1545. }
  1546. //if schedule_two == nil {
  1547. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1548. // return
  1549. //}
  1550. //order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule_two.ScheduleDate, schedule_two.PatientId)
  1551. //if err != nil {
  1552. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1553. // return
  1554. //}
  1555. //
  1556. //if order != nil {
  1557. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1558. // return
  1559. //}
  1560. schedule_two.Status = 0
  1561. schedule_two.UpdatedTime = time.Now().Unix()
  1562. if patientID <= 0 {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1564. return
  1565. }
  1566. adminUserInfo := c.GetAdminUserInfo()
  1567. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patientID)
  1568. if patientInfo.ID == 0 {
  1569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1570. return
  1571. }
  1572. var schedule models.Schedule
  1573. dataBody := make(map[string]interface{}, 0)
  1574. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1575. if err != nil {
  1576. utils.ErrorLog(err.Error())
  1577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1578. return
  1579. }
  1580. if dataBody["schedule_date"] == nil || reflect.TypeOf(dataBody["schedule_date"]).String() != "string" {
  1581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1582. return
  1583. }
  1584. scheduleDate, _ := dataBody["schedule_date"].(string)
  1585. if len(scheduleDate) == 0 {
  1586. utils.ErrorLog("len(schedule_date) == 0")
  1587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1588. return
  1589. }
  1590. timeLayout := "2006-01-02"
  1591. loc, _ := time.LoadLocation("Local")
  1592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", scheduleDate+" 00:00:00", loc)
  1593. if err != nil {
  1594. utils.ErrorLog(err.Error())
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1596. return
  1597. }
  1598. schedule.ScheduleDate = theTime.Unix()
  1599. timeNow = time.Now().Format("2006-01-02")
  1600. if timeNow > scheduleDate {
  1601. utils.ErrorLog(timeNow)
  1602. utils.ErrorLog(scheduleDate)
  1603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1604. return
  1605. }
  1606. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  1607. utils.ErrorLog("schedule_type")
  1608. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1609. return
  1610. }
  1611. scheduleType := int64(dataBody["schedule_type"].(float64))
  1612. if scheduleType < 1 || scheduleType > 3 {
  1613. utils.ErrorLog("scheduleType < 3")
  1614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1615. return
  1616. }
  1617. schedule.ScheduleType = scheduleType
  1618. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  1619. utils.ErrorLog("bed_id")
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1621. return
  1622. }
  1623. bedId := int64(dataBody["bed_id"].(float64))
  1624. if bedId < 1 {
  1625. utils.ErrorLog("bedId < 1")
  1626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1627. return
  1628. }
  1629. schedule.BedId = bedId
  1630. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  1631. utils.ErrorLog("partition_id")
  1632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1633. return
  1634. }
  1635. partitionId := int64(dataBody["partition_id"].(float64))
  1636. if partitionId < 1 {
  1637. utils.ErrorLog("partitionId < 1")
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. schedule.PartitionId = partitionId
  1642. if dataBody["schedule_week"] == nil || reflect.TypeOf(dataBody["schedule_week"]).String() != "float64" {
  1643. utils.ErrorLog("schedule_week")
  1644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1645. return
  1646. }
  1647. scheduleWeek := int64(dataBody["schedule_week"].(float64))
  1648. if scheduleWeek < 1 || scheduleWeek > 7 {
  1649. utils.ErrorLog("scheduleWeek < 1")
  1650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1651. return
  1652. }
  1653. schedule.ScheduleWeek = scheduleWeek
  1654. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  1655. utils.ErrorLog("mode_id")
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1657. return
  1658. }
  1659. modeId := int64(dataBody["mode_id"].(float64))
  1660. if modeId < 1 && modeId > 14 {
  1661. utils.ErrorLog("modeId < 1")
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1663. return
  1664. }
  1665. schedule.ModeId = modeId
  1666. schedule.PatientId = patientID
  1667. schedule.CreatedTime = time.Now().Unix()
  1668. schedule.UpdatedTime = time.Now().Unix()
  1669. schedule.Status = 1
  1670. schedule.UserOrgId = adminUserInfo.CurrentOrgId
  1671. schedule.IsExport = 5
  1672. var DialysisMachineName string
  1673. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  1674. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  1675. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  1676. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  1677. if filedRecordOne.IsShow == 1 {
  1678. DialysisMachineName = so.DialysisDialyszers
  1679. }
  1680. if filedRecordThree.IsShow == 1 {
  1681. if len(DialysisMachineName) > 0 {
  1682. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  1683. } else {
  1684. DialysisMachineName = so.DialyzerPerfusionApparatus
  1685. }
  1686. }
  1687. if filedRecordTwo.IsShow == 1 {
  1688. if len(DialysisMachineName) > 0 {
  1689. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  1690. } else {
  1691. DialysisMachineName = so.DialysisIrrigation
  1692. }
  1693. }
  1694. schedule.DialysisMachineName = DialysisMachineName
  1695. bed, _ := service.GetDeviceNumberByID(adminUserInfo.CurrentOrgId, schedule.BedId)
  1696. if bed == nil {
  1697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  1698. return
  1699. }
  1700. if bed.ZoneID != schedule.PartitionId {
  1701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  1702. return
  1703. }
  1704. //scheduleDateStart := scheduleDate + " 00:00:00"
  1705. //scheduleDateEnd := scheduleDate + " 23:59:59"
  1706. timeLayout = "2006-01-02 15:04:05"
  1707. //theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1708. //theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1709. //startTime := theStartTime.Unix()
  1710. //endTime := theEndTime.Unix()
  1711. ////一天只有排班一次
  1712. //daySchedule, err := service.GetDaySchedule(adminUserInfo.CurrentOrgId, startTime, endTime, patientID)
  1713. //if daySchedule.ID > 0 {
  1714. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  1715. // return
  1716. //}
  1717. //同天同位置只能排一个
  1718. pointSchedule, err := service.GetPointSchedule(adminUserInfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  1719. if err != nil {
  1720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1721. return
  1722. }
  1723. if pointSchedule.ID > 0 {
  1724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  1725. return
  1726. }
  1727. schedule.IsExport = 1000
  1728. err = service.CreateSchedule(&schedule, id)
  1729. lastSchedule, _ := service.GetLastSchedule(patientID, adminUserInfo.CurrentOrgId)
  1730. //查询上机床位号 更改床位号
  1731. order, err := service.GetOneDialysisOrderOne(adminINfo.CurrentOrgId, schedule_two.ScheduleDate, schedule_two.PatientId)
  1732. scheduleObj, _ := service.GetPatientScheduleByPatientId(patientID, adminUserInfo.CurrentOrgId, schedule_two.ScheduleDate)
  1733. if order.ID > 0 {
  1734. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  1735. redis := service.RedisClient()
  1736. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_order"
  1737. redis.Set(key, "", time.Second)
  1738. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1739. //清空key 值
  1740. redis.Set(keyOne, "", time.Second)
  1741. keySix := "scheduals_" + timeNow + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1742. redis.Set(keySix, "", time.Second)
  1743. }
  1744. redis := service.RedisClient()
  1745. key := "scheduals_" + scheduleDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1746. redis.Set(key, "", time.Second)
  1747. //处方
  1748. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1749. redis.Set(keyOne, "", time.Second)
  1750. //医嘱
  1751. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1752. redis.Set(keyTwo, "", time.Second)
  1753. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1754. redis.Set(keySix, "", time.Second)
  1755. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1756. redis.Set(keyThree, "", time.Second)
  1757. keyFour := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1758. redis.Set(keyFour, "", time.Second)
  1759. keyFive := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1760. redis.Set(keyFive, "", time.Second)
  1761. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1762. redis.Set(keySeven, "", time.Second)
  1763. defer redis.Close()
  1764. schedule.Patient = patientInfo.Name
  1765. //去除当天患者排班中重复数据,保留最后一条数据
  1766. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  1767. c.ServeSuccessJSON(map[string]interface{}{
  1768. "msg": "ok",
  1769. "schedule": schedule,
  1770. "schedule_two": schedule_two,
  1771. "lastSchedule": lastSchedule,
  1772. })
  1773. return
  1774. }
  1775. func (c *ScheduleApiController) DeleteSchedule() {
  1776. id, _ := c.GetInt64("id", 0)
  1777. if id <= 0 {
  1778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1779. return
  1780. }
  1781. adminINfo := c.GetAdminUserInfo()
  1782. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  1783. timeNow := time.Now().Format("2006-01-02")
  1784. timeTemplate := "2006-01-02"
  1785. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  1786. timeStr := tm.Format(timeTemplate)
  1787. if timeNow > timeStr {
  1788. utils.ErrorLog(timeNow)
  1789. utils.ErrorLog(timeStr)
  1790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  1791. return
  1792. }
  1793. if schedule == nil {
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  1795. return
  1796. }
  1797. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  1798. if err != nil {
  1799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. return
  1801. }
  1802. if order != nil {
  1803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysis)
  1804. return
  1805. }
  1806. schedule.Status = 0
  1807. schedule.UpdatedTime = time.Now().Unix()
  1808. //如果使用的是保存出库功能
  1809. drugOutConfig, _ := service.FindDrugOutConfigById(adminINfo.CurrentOrgId)
  1810. //退库
  1811. if drugOutConfig.IsOpen == 1 {
  1812. hisAdvice, _ := service.GetPatientDrugCountToday(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1813. if len(hisAdvice) > 0 {
  1814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  1815. return
  1816. }
  1817. //for _, item := range hisAdvice {
  1818. // creater := adminINfo.AdminUser.Id
  1819. // err = service.DrugAutoAddCancelInfo(item, creater)
  1820. // if err != nil {
  1821. // err = fmt.Errorf("!:%v", err)
  1822. // return
  1823. // }
  1824. //}
  1825. ////查询是否有出库记录
  1826. //service.GetPatientGoodStockCount(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1827. }
  1828. //查询该患者当天是否开耗材
  1829. list, _ := service.GetPatientGoodCountToday(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1830. if len(list) > 0 {
  1831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorAdivceCode)
  1832. return
  1833. //operation_time := time.Now().Unix()
  1834. //creater := c.GetAdminUserInfo().AdminUser.Id
  1835. ////创建退库单
  1836. //timeStr := time.Now().Format("2006-01-02")
  1837. //timeArr := strings.Split(timeStr, "-")
  1838. //total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1839. //total = total + 1
  1840. //orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1841. //houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  1842. //cancelStock := models.CancelStock{
  1843. // OrderNumber: orderNumber,
  1844. // OperaTime: operation_time,
  1845. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1846. // Creater: creater,
  1847. // Ctime: time.Now().Unix(),
  1848. // Status: 1,
  1849. // ReturnTime: schedule.ScheduleDate,
  1850. // Type: 1,
  1851. // StorehouseId: houseConfig.StorehouseOutInfo,
  1852. // IsCheck: 1,
  1853. //}
  1854. //_, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(schedule.ScheduleDate, c.GetAdminUserInfo().CurrentOrgId)
  1855. //if msgerrkonde == gorm.ErrRecordNotFound {
  1856. // service.AddSigleCancelStock(&cancelStock)
  1857. //}
  1858. //cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1859. ////进行退库操作
  1860. //for _, item := range list {
  1861. // good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  1862. // manufacturer, _ := service.GetManufactureById(item.Manufacturer)
  1863. // deaerler, _ := service.GetDealerById(item.Dealer)
  1864. // //回退库存
  1865. // service.UpDateWarehouseInfoByStockDelete(item.WarehouseInfotId, item.Count, item.PatientId, item.SysRecordTime, item.GoodId)
  1866. // goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId)
  1867. // var flush_count int64
  1868. // for _, it := range goodList {
  1869. // flush_count += it.StockCount
  1870. // }
  1871. // cancelStockInfo := models.CancelStockInfo{
  1872. // GoodId: item.GoodId,
  1873. // CancelStockId: cancel.ID,
  1874. // GoodTypeId: good.GoodTypeId,
  1875. // Count: item.Count,
  1876. // Price: item.Price,
  1877. // Total: 0,
  1878. // ProductDate: item.ProductDate,
  1879. // ExpiryDate: item.ExpiryDate,
  1880. // Ctime: time.Now().Unix(),
  1881. // Status: 1,
  1882. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1883. // OrderNumber: cancel.OrderNumber,
  1884. // Type: 0,
  1885. // Dealer: deaerler.DealerName,
  1886. // Manufacturer: manufacturer.ManufacturerName,
  1887. // Number: item.Number,
  1888. // RegisterAccount: "",
  1889. // Remark: "",
  1890. // WarehouseInfoId: item.WarehouseInfotId,
  1891. // PatientId: item.PatientId,
  1892. // RecordDate: item.SysRecordTime,
  1893. // StorehouseId: houseConfig.StorehouseOutInfo,
  1894. // IsCheck: 1,
  1895. // }
  1896. //
  1897. // service.CreateCancelStockInfoOne(&cancelStockInfo)
  1898. //
  1899. // cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  1900. //
  1901. // flow := models.VmStockFlow{
  1902. // WarehousingId: item.WarehouseInfotId,
  1903. // GoodId: item.GoodId,
  1904. // Number: item.Number,
  1905. // LicenseNumber: item.LicenseNumber,
  1906. // Count: item.Count,
  1907. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1908. // PatientId: item.PatientId,
  1909. // SystemTime: item.SysRecordTime,
  1910. // ConsumableType: 7,
  1911. // IsSys: 0,
  1912. // WarehousingOrder: "",
  1913. // WarehouseOutId: item.WarehouseOutId,
  1914. // WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
  1915. // IsEdit: 0,
  1916. // CancelStockId: cancel.ID,
  1917. // CancelOrderNumber: cancel.OrderNumber,
  1918. // Manufacturer: manufacturer.ID,
  1919. // Dealer: 0,
  1920. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  1921. // UpdateCreator: 0,
  1922. // Status: 1,
  1923. // Ctime: time.Now().Unix(),
  1924. // Mtime: 0,
  1925. // Price: item.Price,
  1926. // WarehousingDetailId: item.WarehouseInfotId,
  1927. // WarehouseOutDetailId: item.ID,
  1928. // CancelOutDetailId: cancelInfo.ID,
  1929. // ProductDate: item.ProductDate,
  1930. // ExpireDate: item.ExpiryDate,
  1931. // StorehouseId: houseConfig.StorehouseOutInfo,
  1932. // OverCount: flush_count,
  1933. // }
  1934. // service.CreateStockFlowOne(flow)
  1935. //
  1936. // //退库数量增加
  1937. // service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.GoodId, houseConfig.StorehouseOutInfo, item.Count)
  1938. // //出库数量减少
  1939. // service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, item.Count)
  1940. //
  1941. // //更新库存
  1942. // service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  1943. //
  1944. // //更新基础库库存
  1945. // service.UpdateGoodInfoSumCountSix(item.GoodId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  1946. //}
  1947. }
  1948. err = service.UpdateSchedule(schedule)
  1949. //记录日志
  1950. byterequest, _ := json.Marshal(schedule)
  1951. scheduleLog := models.XtScheduleLog{
  1952. UserOrgId: adminINfo.CurrentOrgId,
  1953. RecordDate: schedule.ScheduleDate,
  1954. Status: 1,
  1955. PatientId: schedule.PatientId,
  1956. Ctime: time.Now().Unix(),
  1957. Mtime: 0,
  1958. ErrLog: string(byterequest),
  1959. Source: "电脑端删除排班",
  1960. Module: 5,
  1961. AdminUserId: adminINfo.AdminUser.Id,
  1962. }
  1963. service.CreateScheduleLog(scheduleLog)
  1964. //针对凤凰医院
  1965. if adminINfo.CurrentOrgId == 10579 || adminINfo.CurrentOrgId == 10344 || adminINfo.CurrentOrgId == 10206 || adminINfo.CurrentOrgId == 10679 {
  1966. advice, _ := service.GetDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1967. if len(advice) > 0 {
  1968. service.UpdateAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1969. }
  1970. }
  1971. if adminINfo.CurrentOrgId == 10206 || adminINfo.CurrentOrgId == 10344 {
  1972. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1973. project, _ := service.GetHisPrescriptionProjectList(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1974. if len(hisAdvice) > 0 {
  1975. service.UpdateHisAdviceObj(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1976. }
  1977. if len(project) > 0 {
  1978. service.UpdateProjectObj(schedule.PatientId, schedule.ScheduleDate, adminINfo.CurrentOrgId)
  1979. }
  1980. }
  1981. redis := service.RedisClient()
  1982. //处方
  1983. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  1984. redis.Set(keyOne, "", time.Second)
  1985. //医嘱
  1986. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  1987. redis.Set(keyTwo, "", time.Second)
  1988. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  1989. redis.Set(keySix, "", time.Second)
  1990. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  1991. redis.Set(keyThree, "", time.Second)
  1992. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  1993. redis.Set(keyFour, "", time.Second)
  1994. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  1995. redis.Set(keyFive, "", time.Second)
  1996. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  1997. redis.Set(keySeven, "", time.Second)
  1998. fmt.Println(err)
  1999. defer redis.Close()
  2000. if err != nil {
  2001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  2002. return
  2003. }
  2004. c.ServeSuccessJSON(map[string]interface{}{
  2005. "msg": "ok",
  2006. "schedule": &schedule,
  2007. })
  2008. }
  2009. func (c *ScheduleApiController) ChangeSchedule() {
  2010. id, _ := c.GetInt64("id", 0)
  2011. if id <= 0 {
  2012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2013. return
  2014. }
  2015. adminINfo := c.GetAdminUserInfo()
  2016. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  2017. if schedule == nil {
  2018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  2019. return
  2020. }
  2021. dataBody := make(map[string]interface{}, 0)
  2022. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2023. if err != nil {
  2024. utils.ErrorLog(err.Error())
  2025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2026. return
  2027. }
  2028. if dataBody["change_action"] == nil || reflect.TypeOf(dataBody["change_action"]).String() != "string" {
  2029. utils.ErrorLog("change_action")
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2031. return
  2032. }
  2033. changeAction := dataBody["change_action"].(string)
  2034. if changeAction == "change_mode" {
  2035. if dataBody["mode_id"] == nil || reflect.TypeOf(dataBody["mode_id"]).String() != "float64" {
  2036. utils.ErrorLog("mode_id")
  2037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  2038. return
  2039. }
  2040. modeId := int64(dataBody["mode_id"].(float64))
  2041. if modeId < 1 {
  2042. utils.ErrorLog("modeId < 1")
  2043. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrongForSchMode)
  2044. return
  2045. }
  2046. schedule.ModeId = modeId
  2047. so, _ := service.GetDialysisSolutionTwo(adminINfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  2048. filedRecordOne, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器")
  2049. filedRecordTwo, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "灌流器")
  2050. filedRecordThree, _ := service.FindFiledBy(adminINfo.CurrentOrgId, "透析器/灌流器")
  2051. var DialysisMachineName string
  2052. if filedRecordOne.IsShow == 1 {
  2053. DialysisMachineName = so.DialysisDialyszers
  2054. //fmt.Println("1111")
  2055. fmt.Println(DialysisMachineName)
  2056. }
  2057. if filedRecordThree.IsShow == 1 {
  2058. if len(schedule.DialysisMachineName) > 0 {
  2059. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2060. //fmt.Println("22222")
  2061. fmt.Println(DialysisMachineName)
  2062. } else {
  2063. DialysisMachineName = so.DialyzerPerfusionApparatus
  2064. //fmt.Println("333333")
  2065. fmt.Println(DialysisMachineName)
  2066. }
  2067. }
  2068. if filedRecordTwo.IsShow == 1 {
  2069. if len(DialysisMachineName) > 0 {
  2070. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  2071. //fmt.Println("55555555")
  2072. fmt.Println(DialysisMachineName)
  2073. } else {
  2074. DialysisMachineName = so.DialysisIrrigation
  2075. //fmt.Println("66666666")
  2076. fmt.Println(DialysisMachineName)
  2077. }
  2078. }
  2079. schedule.DialysisMachineName = DialysisMachineName
  2080. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  2081. if err != nil {
  2082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2083. return
  2084. }
  2085. if order != nil {
  2086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeMode)
  2087. return
  2088. }
  2089. //记录日志
  2090. byterequest, _ := json.Marshal(schedule)
  2091. scheduleLog := models.XtScheduleLog{
  2092. UserOrgId: adminINfo.CurrentOrgId,
  2093. RecordDate: schedule.ScheduleDate,
  2094. Status: 1,
  2095. PatientId: schedule.PatientId,
  2096. Ctime: time.Now().Unix(),
  2097. Mtime: 0,
  2098. ErrLog: string(byterequest),
  2099. Source: "电脑端改变模式排班",
  2100. Module: 1,
  2101. AdminUserId: adminINfo.AdminUser.Id,
  2102. }
  2103. service.CreateScheduleLog(scheduleLog)
  2104. } else if changeAction == "change_device" {
  2105. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  2106. if err != nil {
  2107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2108. return
  2109. }
  2110. if order != nil {
  2111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeDeviceNumber)
  2112. return
  2113. }
  2114. if dataBody["schedule_type"] == nil || reflect.TypeOf(dataBody["schedule_type"]).String() != "float64" {
  2115. utils.ErrorLog("schedule_type")
  2116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2117. return
  2118. }
  2119. scheduleType := int64(dataBody["schedule_type"].(float64))
  2120. if scheduleType < 1 || scheduleType > 3 {
  2121. utils.ErrorLog("scheduleType < 3")
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2123. return
  2124. }
  2125. schedule.ScheduleType = scheduleType
  2126. if dataBody["bed_id"] == nil || reflect.TypeOf(dataBody["bed_id"]).String() != "float64" {
  2127. utils.ErrorLog("bed_id")
  2128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2129. return
  2130. }
  2131. bedId := int64(dataBody["bed_id"].(float64))
  2132. if bedId < 1 {
  2133. utils.ErrorLog("bedId < 1")
  2134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2135. return
  2136. }
  2137. schedule.BedId = bedId
  2138. if dataBody["partition_id"] == nil || reflect.TypeOf(dataBody["partition_id"]).String() != "float64" {
  2139. utils.ErrorLog("partition_id")
  2140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2141. return
  2142. }
  2143. partitionId := int64(dataBody["partition_id"].(float64))
  2144. if partitionId < 1 {
  2145. utils.ErrorLog("partitionId < 1")
  2146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2147. return
  2148. }
  2149. schedule.PartitionId = partitionId
  2150. bed, _ := service.GetDeviceNumberByID(adminINfo.CurrentOrgId, schedule.BedId)
  2151. if bed == nil {
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotExist)
  2153. return
  2154. }
  2155. if bed.ZoneID != schedule.PartitionId {
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeviceNumberNotTheZone)
  2157. return
  2158. }
  2159. startTime := schedule.ScheduleDate
  2160. endTime := startTime + 86399
  2161. //一天只有排班一次
  2162. daySchedule, err := service.GetDaySchedule(adminINfo.CurrentOrgId, startTime, endTime, schedule.PatientId)
  2163. if daySchedule.ID > 0 && daySchedule.ID != schedule.ID {
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleAgainOneDay)
  2165. return
  2166. }
  2167. //同天同位置只能排一个
  2168. pointSchedule, err := service.GetPointSchedule(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.ScheduleWeek, schedule.ScheduleType, schedule.BedId)
  2169. if err != nil {
  2170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2171. return
  2172. }
  2173. if pointSchedule.ID > 0 {
  2174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePointScheduleExist)
  2175. return
  2176. }
  2177. //记录日志
  2178. byterequest, _ := json.Marshal(schedule)
  2179. scheduleLog := models.XtScheduleLog{
  2180. UserOrgId: adminINfo.CurrentOrgId,
  2181. RecordDate: schedule.ScheduleDate,
  2182. Status: 1,
  2183. PatientId: schedule.PatientId,
  2184. Ctime: time.Now().Unix(),
  2185. Mtime: 0,
  2186. ErrLog: string(byterequest),
  2187. Source: "电脑端改变分区床位",
  2188. Module: 4,
  2189. AdminUserId: adminINfo.AdminUser.Id,
  2190. }
  2191. service.CreateScheduleLog(scheduleLog)
  2192. } else {
  2193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2194. return
  2195. }
  2196. schedule.UpdatedTime = time.Now().Unix()
  2197. err = service.UpdateSchedule(schedule)
  2198. prescription := models.DialysisPrescription{
  2199. ModeId: schedule.ModeId,
  2200. }
  2201. _, errcode := service.GetDialysisPrescribe(schedule.UserOrgId, schedule.PatientId, schedule.ScheduleDate)
  2202. if errcode == gorm.ErrRecordNotFound {
  2203. if err != nil {
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  2205. return
  2206. }
  2207. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  2208. c.ServeSuccessJSON(map[string]interface{}{
  2209. "msg": "ok",
  2210. "schedule": &schedule,
  2211. })
  2212. } else if errcode == nil {
  2213. err = service.UpdatedDialysisPrescription(&prescription, schedule.ScheduleDate, schedule.PatientId, schedule.UserOrgId)
  2214. if err != nil {
  2215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChangeScheduleFail)
  2216. return
  2217. }
  2218. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  2219. c.ServeSuccessJSON(map[string]interface{}{
  2220. "msg": "ok",
  2221. "schedule": &schedule,
  2222. })
  2223. }
  2224. }
  2225. // /api/schedule/print/initdata [get]
  2226. // @param date:string yyyy-MM-dd 要打印的那一周中的任一天
  2227. func (this *ScheduleApiController) PrintInitData() {
  2228. dateStr := this.GetString("date")
  2229. //week_type, _ := this.GetInt64("type", 0)
  2230. var date *time.Time
  2231. if len(dateStr) == 0 {
  2232. now := time.Now()
  2233. date = &now
  2234. } else {
  2235. var parseErr error
  2236. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", dateStr)
  2237. if parseErr != nil {
  2238. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2239. return
  2240. }
  2241. }
  2242. adminUserInfo := this.GetAdminUserInfo()
  2243. // 获取本周的排班
  2244. var monday time.Time
  2245. var sunday time.Time
  2246. //switch week_type {
  2247. //case 1:
  2248. monday, sunday = utils.GetMondayAndSundayOfWeekDate(date)
  2249. // break
  2250. //case 2:
  2251. // monday, sunday = utils.GetMondayAndSundayOfNextWeekDate(date)
  2252. //
  2253. // break
  2254. //case 3:
  2255. // monday, sunday = utils.GetMondayAndSundayOfNextNextWeekDate(date)
  2256. // break
  2257. //}
  2258. schedules, getScheduleErr := service.GetPrinitWeekSchedules(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  2259. total, getScheduleErr := service.GetPrinitWeekTotal(adminUserInfo.CurrentOrgId, monday.Unix(), sunday.Unix())
  2260. if getScheduleErr != nil {
  2261. this.ErrorLog("获取周排班失败:%v", getScheduleErr)
  2262. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2263. return
  2264. }
  2265. thisTime := date
  2266. weekDay := int(thisTime.Weekday())
  2267. if weekDay == 0 {
  2268. weekDay = 7
  2269. }
  2270. weekEnd := 7 - weekDay
  2271. weekStart := weekEnd - 6
  2272. days := make([]string, 0)
  2273. for index := weekStart; index <= weekEnd; index++ {
  2274. theDay := thisTime.AddDate(0, 0, index)
  2275. days = append(days, theDay.Format("2006-01-02"))
  2276. }
  2277. this.ServeSuccessJSON(map[string]interface{}{
  2278. "total": total,
  2279. "schedules": schedules,
  2280. "monday": monday.Unix(),
  2281. "days": days,
  2282. })
  2283. }
  2284. func (this *ScheduleApiController) UrgentScheduleData() {
  2285. schedule_type, _ := this.GetInt("type", 0)
  2286. schedule_date := this.GetString("date")
  2287. var date *time.Time
  2288. if len(schedule_date) == 0 {
  2289. now := time.Now()
  2290. date = &now
  2291. } else {
  2292. var parseErr error
  2293. date, parseErr = utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2294. if parseErr != nil {
  2295. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2296. return
  2297. }
  2298. }
  2299. adminUserInfo := this.GetAdminUserInfo()
  2300. deviceNumbers, getDeviceNumbersErr := service.MobileGetAllDeviceNumbersForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  2301. if getDeviceNumbersErr != nil {
  2302. this.ErrorLog("获取所有床位失败:%v", getDeviceNumbersErr)
  2303. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2304. return
  2305. }
  2306. // today := utils.ZeroHourTimeOfDay(time.Now())
  2307. schedules, getSchedulesErr := service.MobileGetOtherSchedulesForUrgentSchedule(adminUserInfo.CurrentOrgId, date.Unix(), schedule_type)
  2308. if getSchedulesErr != nil {
  2309. this.ErrorLog("获取所有排班失败:%v", getSchedulesErr)
  2310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2311. return
  2312. }
  2313. this.ServeSuccessJSON(map[string]interface{}{
  2314. "device_numbers": deviceNumbers,
  2315. "schedules": schedules,
  2316. })
  2317. }
  2318. func (this *ScheduleApiController) SearchSchedulePatients() {
  2319. keywords := this.GetString("keywords")
  2320. week_type, _ := this.GetInt64("week_type", 0)
  2321. start_sch := this.GetString("start_sch")
  2322. end_sch := this.GetString("end_sch")
  2323. thisTime1 := time.Now()
  2324. thisTime2 := time.Now()
  2325. thisTime1 = thisTime1.AddDate(0, 0, 7)
  2326. thisTime2 = thisTime2.AddDate(0, 0, 14)
  2327. var start_time string
  2328. var end_time string
  2329. switch week_type {
  2330. case 1:
  2331. timeLayout := "2006-01-02"
  2332. loc, _ := time.LoadLocation("Local")
  2333. var startSchTime int64
  2334. if len(start_sch) > 0 {
  2335. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_sch+" 00:00:00", loc)
  2336. startSchTime = theTime.Unix()
  2337. }
  2338. var endSchTime int64
  2339. if len(end_sch) > 0 {
  2340. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_sch+" 00:00:00", loc)
  2341. endSchTime = theTime.Unix()
  2342. }
  2343. adminUserInfo := this.GetAdminUserInfo()
  2344. list, _ := service.GetSchedualPatientsByKeywords(keywords, adminUserInfo.CurrentOrgId, startSchTime, endSchTime)
  2345. this.ServeSuccessJSON(map[string]interface{}{
  2346. "schdules": list,
  2347. })
  2348. break
  2349. case 2:
  2350. days := make([]string, 0)
  2351. weekDay1 := int(thisTime1.Weekday())
  2352. if weekDay1 == 0 {
  2353. weekDay1 = 7
  2354. }
  2355. weekEnd1 := 7 - weekDay1
  2356. weekStart1 := weekEnd1 - 6
  2357. for index := weekStart1; index <= weekEnd1; index++ {
  2358. fmt.Println(index)
  2359. theDay := thisTime1.AddDate(0, 0, index)
  2360. days = append(days, theDay.Format("2006-01-02"))
  2361. }
  2362. fmt.Println(days)
  2363. start_time = days[0]
  2364. end_time = days[len(days)-1]
  2365. timeLayout := "2006-01-02"
  2366. loc, _ := time.LoadLocation("Local")
  2367. var theStartTime int64
  2368. if len(start_time) > 0 {
  2369. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2370. theStartTime = theTime.Unix()
  2371. }
  2372. var theEndtTime int64
  2373. if len(end_time) > 0 {
  2374. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2375. theEndtTime = theTime.Unix()
  2376. }
  2377. adminUserInfo := this.GetAdminUserInfo()
  2378. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  2379. this.ServeSuccessJSON(map[string]interface{}{
  2380. "schdules": list,
  2381. })
  2382. break
  2383. case 3:
  2384. days := make([]string, 0)
  2385. weekDay2 := int(thisTime2.Weekday())
  2386. if weekDay2 == 0 {
  2387. weekDay2 = 7
  2388. }
  2389. weekEnd2 := 7 - weekDay2
  2390. weekStart2 := weekEnd2 - 6
  2391. for index := weekStart2; index <= weekEnd2; index++ {
  2392. theDay := thisTime2.AddDate(0, 0, index)
  2393. days = append(days, theDay.Format("2006-01-02"))
  2394. }
  2395. start_time = days[0]
  2396. end_time = days[len(days)-1]
  2397. timeLayout := "2006-01-02"
  2398. loc, _ := time.LoadLocation("Local")
  2399. var theStartTime int64
  2400. if len(start_time) > 0 {
  2401. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2402. theStartTime = theTime.Unix()
  2403. }
  2404. var theEndtTime int64
  2405. if len(end_time) > 0 {
  2406. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2407. theEndtTime = theTime.Unix()
  2408. }
  2409. adminUserInfo := this.GetAdminUserInfo()
  2410. list, _ := service.GetSchedualPatientsByKeywordsAndWeek(keywords, adminUserInfo.CurrentOrgId, theStartTime, theEndtTime)
  2411. this.ServeSuccessJSON(map[string]interface{}{
  2412. "schdules": list,
  2413. })
  2414. break
  2415. }
  2416. }
  2417. func (this *ScheduleApiController) GetWeekDaySchedule() {
  2418. week_type, _ := this.GetInt64("week_type", -1)
  2419. week_time, _ := this.GetInt64("week_time")
  2420. thisTime := time.Now()
  2421. weekDay := int(thisTime.Weekday())
  2422. if weekDay == 0 {
  2423. weekDay = 7
  2424. }
  2425. weekEnd := 7 - weekDay
  2426. weekStart := weekEnd - 6
  2427. weekTitle := make([]string, 0)
  2428. days := make([]string, 0)
  2429. for index := weekStart; index <= weekEnd; index++ {
  2430. theDay := thisTime.AddDate(0, 0, index)
  2431. indexYear, indexMonthTime, indexDay := theDay.Date()
  2432. indexMonth := int(indexMonthTime)
  2433. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  2434. weekTitle = append(weekTitle, indexWeek)
  2435. days = append(days, theDay.Format("2006-01-02"))
  2436. }
  2437. fmt.Println(days)
  2438. var targetDayStr string
  2439. var startTime string
  2440. var endTime string
  2441. switch week_type {
  2442. case 0:
  2443. {
  2444. startTime = days[0]
  2445. endTime = days[6]
  2446. }
  2447. case 1:
  2448. targetDayStr = days[0]
  2449. break
  2450. case 2:
  2451. targetDayStr = days[1]
  2452. break
  2453. case 3:
  2454. targetDayStr = days[2]
  2455. break
  2456. case 4:
  2457. targetDayStr = days[3]
  2458. break
  2459. case 5:
  2460. targetDayStr = days[4]
  2461. break
  2462. case 6:
  2463. targetDayStr = days[5]
  2464. break
  2465. case 7:
  2466. targetDayStr = days[6]
  2467. break
  2468. }
  2469. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  2470. startDay, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  2471. endDay, _ := utils.ParseTimeStringToTime("2006-01-02", endTime)
  2472. fmt.Println(startDay, endDay)
  2473. if parseErr != nil {
  2474. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2475. return
  2476. }
  2477. orgId := this.GetAdminUserInfo().CurrentOrgId
  2478. list, _ := service.GetWeekDayScheduleTwo(orgId, targetDay.Unix(), targetDay, week_time)
  2479. this.ServeSuccessJSON(map[string]interface{}{
  2480. "schdules": list,
  2481. "day": targetDayStr,
  2482. })
  2483. }
  2484. func Struct2Map(obj interface{}) map[string]interface{} {
  2485. t := reflect.TypeOf(obj)
  2486. v := reflect.ValueOf(obj)
  2487. var data = make(map[string]interface{})
  2488. for i := 0; i < t.NumField(); i++ {
  2489. data[t.Field(i).Name] = v.Field(i).Interface()
  2490. }
  2491. return data
  2492. }
  2493. func (this *ScheduleApiController) ExportSchedule() {
  2494. dataBody := make(map[string]interface{}, 0)
  2495. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2496. if err != nil {
  2497. utils.ErrorLog(err.Error())
  2498. return
  2499. }
  2500. utils.ErrorLog("%v", dataBody)
  2501. export_time := time.Now().Unix()
  2502. var schedules []*models.Schedule
  2503. var failed_total int
  2504. var total_schedule []interface{}
  2505. var patients []*models.Patients
  2506. patients, _, _ = service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  2507. start_time := dataBody["start_time"].(string)
  2508. end_time := dataBody["end_time"].(string)
  2509. delete_type := int64(dataBody["delete_type"].(float64))
  2510. fmt.Println("delete_type", delete_type)
  2511. timeLayout := "2006-01-02"
  2512. loc, _ := time.LoadLocation("Local")
  2513. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2514. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  2515. fmt.Println("theTimeStart", theTimeStart.Unix())
  2516. fmt.Println("theTimeEnd", theTimeEnd.Unix())
  2517. if dataBody["failed_schedule"] != nil || reflect.TypeOf(dataBody["failed_schedule"]).String() == "[]interface {}" {
  2518. tempSchedule := dataBody["failed_schedule"].([]interface{})
  2519. failed_total = len(tempSchedule)
  2520. }
  2521. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  2522. tempSchedule := dataBody["schedule"].([]interface{})
  2523. total_schedule = tempSchedule
  2524. for _, schMap := range tempSchedule {
  2525. schMapM := schMap.(map[string]interface{})
  2526. var sch models.Schedule
  2527. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  2528. utils.ErrorLog("name")
  2529. return
  2530. }
  2531. name, _ := schMapM["name"].(string)
  2532. fmt.Println(name)
  2533. if len(name) == 0 { //名字为空则生成一条导入错误日志
  2534. err_log := models.ExportErrLog{
  2535. LogType: 2,
  2536. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2537. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  2538. Status: 1,
  2539. CreateTime: time.Now().Unix(),
  2540. UpdateTime: time.Now().Unix(),
  2541. ExportTime: export_time,
  2542. }
  2543. service.CreateExportErrLog(&err_log)
  2544. continue
  2545. } else {
  2546. var patient []*models.Patients
  2547. for _, item := range patients {
  2548. if strings.Replace(item.Name, " ", "", -1) == name {
  2549. patient = append(patient, item)
  2550. }
  2551. }
  2552. if len(patient) == 0 { //错误日志
  2553. err_log := models.ExportErrLog{
  2554. LogType: 2,
  2555. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2556. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  2557. Status: 1,
  2558. CreateTime: time.Now().Unix(),
  2559. UpdateTime: time.Now().Unix(),
  2560. ExportTime: export_time,
  2561. }
  2562. service.CreateExportErrLog(&err_log)
  2563. continue
  2564. } else if len(patient) == 1 { //
  2565. sch.PatientId = patient[0].ID
  2566. } else if len(patient) > 1 { //出现同名的情况
  2567. err_log := models.ExportErrLog{
  2568. LogType: 2,
  2569. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2570. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  2571. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列,患者姓名为\"" + name + "\"在在当前机构中存在重名,无法确定到具体患者",
  2572. Status: 1,
  2573. CreateTime: time.Now().Unix(),
  2574. UpdateTime: time.Now().Unix(),
  2575. ExportTime: export_time,
  2576. }
  2577. service.CreateExportErrLog(&err_log)
  2578. continue
  2579. }
  2580. }
  2581. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  2582. utils.ErrorLog("schedule_type")
  2583. return
  2584. }
  2585. schedule_type := int64(schMapM["schedule_type"].(float64))
  2586. if schedule_type <= 0 { //班次格式有误,插入日志
  2587. log := models.ExportLog{
  2588. LogType: 2,
  2589. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2590. TotalNum: int64(len(total_schedule) + failed_total),
  2591. FailNum: 1 + int64(failed_total),
  2592. SuccessNum: int64(len(schedules)),
  2593. CreateTime: time.Now().Unix(),
  2594. UpdateTime: time.Now().Unix(),
  2595. ExportTime: export_time,
  2596. Status: 1,
  2597. }
  2598. service.CreateExportLog(&log)
  2599. err_log := models.ExportErrLog{
  2600. LogType: 2,
  2601. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2602. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  2603. Status: 1,
  2604. CreateTime: time.Now().Unix(),
  2605. UpdateTime: time.Now().Unix(),
  2606. ExportTime: export_time,
  2607. }
  2608. service.CreateExportErrLog(&err_log)
  2609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2610. return
  2611. } else {
  2612. sch.ScheduleType = schedule_type
  2613. }
  2614. if schMapM["partition_name"] == nil || reflect.TypeOf(schMapM["partition_name"]).String() != "string" {
  2615. utils.ErrorLog("partition_name")
  2616. return
  2617. }
  2618. partition_name, _ := schMapM["partition_name"].(string)
  2619. if len(partition_name) == 0 { //分区为空
  2620. log := models.ExportLog{
  2621. LogType: 2,
  2622. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2623. TotalNum: int64(len(total_schedule) + failed_total),
  2624. FailNum: 1 + int64(failed_total),
  2625. SuccessNum: int64(len(schedules)),
  2626. CreateTime: time.Now().Unix(),
  2627. UpdateTime: time.Now().Unix(),
  2628. ExportTime: export_time,
  2629. Status: 1,
  2630. }
  2631. service.CreateExportLog(&log)
  2632. err_log := models.ExportErrLog{
  2633. LogType: 2,
  2634. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2635. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2636. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  2637. Status: 1,
  2638. CreateTime: time.Now().Unix(),
  2639. UpdateTime: time.Now().Unix(),
  2640. ExportTime: export_time,
  2641. }
  2642. service.CreateExportErrLog(&err_log)
  2643. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2644. return
  2645. } else {
  2646. zone, err := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  2647. if err == nil {
  2648. sch.PartitionId = zone.ID
  2649. } else if err == gorm.ErrRecordNotFound { //查不到数据,插入错误日志
  2650. log := models.ExportLog{
  2651. LogType: 2,
  2652. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2653. TotalNum: int64(len(total_schedule) + failed_total),
  2654. FailNum: 1 + int64(failed_total),
  2655. SuccessNum: int64(len(schedules)),
  2656. CreateTime: time.Now().Unix(),
  2657. UpdateTime: time.Now().Unix(),
  2658. ExportTime: export_time,
  2659. Status: 1,
  2660. }
  2661. service.CreateExportLog(&log)
  2662. err_log := models.ExportErrLog{
  2663. LogType: 2,
  2664. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2665. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2666. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第1列所属的分区格式有误",
  2667. Status: 1,
  2668. CreateTime: time.Now().Unix(),
  2669. UpdateTime: time.Now().Unix(),
  2670. ExportTime: export_time,
  2671. }
  2672. service.CreateExportErrLog(&err_log)
  2673. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2674. return
  2675. }
  2676. }
  2677. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  2678. utils.ErrorLog("device_number_name")
  2679. return
  2680. }
  2681. device_number_name, _ := schMapM["device_number_name"].(string)
  2682. if len(device_number_name) == 0 { //分区为空
  2683. log := models.ExportLog{
  2684. LogType: 2,
  2685. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2686. TotalNum: int64(len(total_schedule) + failed_total),
  2687. FailNum: 1 + int64(failed_total),
  2688. SuccessNum: int64(len(schedules)),
  2689. CreateTime: time.Now().Unix(),
  2690. UpdateTime: time.Now().Unix(),
  2691. ExportTime: export_time,
  2692. Status: 1,
  2693. }
  2694. service.CreateExportLog(&log)
  2695. err_log := models.ExportErrLog{
  2696. LogType: 2,
  2697. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2698. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2699. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2700. Status: 1,
  2701. CreateTime: time.Now().Unix(),
  2702. UpdateTime: time.Now().Unix(),
  2703. ExportTime: export_time,
  2704. }
  2705. service.CreateExportErrLog(&err_log)
  2706. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2707. return
  2708. } else {
  2709. device, err := service.FindDeviceByName(device_number_name, this.GetAdminUserInfo().CurrentOrgId, sch.PartitionId)
  2710. if err == nil {
  2711. if len(device) == 0 { //没查到数据,插入错误日志
  2712. log := models.ExportLog{
  2713. LogType: 2,
  2714. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2715. TotalNum: int64(len(total_schedule) + failed_total),
  2716. FailNum: 1 + int64(failed_total),
  2717. SuccessNum: int64(len(schedules)),
  2718. CreateTime: time.Now().Unix(),
  2719. UpdateTime: time.Now().Unix(),
  2720. ExportTime: export_time,
  2721. Status: 1,
  2722. }
  2723. service.CreateExportLog(&log)
  2724. err_log := models.ExportErrLog{
  2725. LogType: 2,
  2726. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2727. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  2728. Status: 1,
  2729. CreateTime: time.Now().Unix(),
  2730. UpdateTime: time.Now().Unix(),
  2731. ExportTime: export_time,
  2732. }
  2733. service.CreateExportErrLog(&err_log)
  2734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2735. return
  2736. } else if len(device) == 1 {
  2737. sch.BedId = device[0].ID
  2738. } else if len(device) > 1 { //出现重名,插入错误日志
  2739. log := models.ExportLog{
  2740. LogType: 2,
  2741. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2742. TotalNum: int64(len(total_schedule) + failed_total),
  2743. FailNum: 1 + int64(failed_total),
  2744. SuccessNum: int64(len(schedules)),
  2745. CreateTime: time.Now().Unix(),
  2746. UpdateTime: time.Now().Unix(),
  2747. ExportTime: export_time,
  2748. Status: 1,
  2749. }
  2750. service.CreateExportLog(&log)
  2751. err_log := models.ExportErrLog{
  2752. LogType: 2,
  2753. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2754. ErrMsg: "出现两个床位号相同的床位",
  2755. Status: 1,
  2756. CreateTime: time.Now().Unix(),
  2757. UpdateTime: time.Now().Unix(),
  2758. ExportTime: export_time,
  2759. }
  2760. service.CreateExportErrLog(&err_log)
  2761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2762. return
  2763. }
  2764. }
  2765. }
  2766. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  2767. utils.ErrorLog("schedule_week")
  2768. return
  2769. }
  2770. schedule_week, _ := schMapM["schedule_week"].(string)
  2771. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  2772. log := models.ExportLog{
  2773. LogType: 2,
  2774. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2775. TotalNum: int64(len(total_schedule) + failed_total),
  2776. FailNum: 1 + int64(failed_total),
  2777. SuccessNum: int64(len(schedules)),
  2778. CreateTime: time.Now().Unix(),
  2779. UpdateTime: time.Now().Unix(),
  2780. ExportTime: export_time,
  2781. Status: 1,
  2782. }
  2783. service.CreateExportLog(&log)
  2784. err_log := models.ExportErrLog{
  2785. LogType: 2,
  2786. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2787. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  2788. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2789. Status: 1,
  2790. CreateTime: time.Now().Unix(),
  2791. UpdateTime: time.Now().Unix(),
  2792. ExportTime: export_time,
  2793. }
  2794. service.CreateExportErrLog(&err_log)
  2795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2796. return
  2797. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  2798. log := models.ExportLog{
  2799. LogType: 2,
  2800. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2801. TotalNum: int64(len(total_schedule) + failed_total),
  2802. FailNum: 1 + int64(failed_total),
  2803. SuccessNum: int64(len(schedules)),
  2804. CreateTime: time.Now().Unix(),
  2805. UpdateTime: time.Now().Unix(),
  2806. ExportTime: export_time,
  2807. Status: 1,
  2808. }
  2809. service.CreateExportLog(&log)
  2810. err_log := models.ExportErrLog{
  2811. LogType: 2,
  2812. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2813. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2814. Status: 1,
  2815. CreateTime: time.Now().Unix(),
  2816. UpdateTime: time.Now().Unix(),
  2817. ExportTime: export_time,
  2818. }
  2819. service.CreateExportErrLog(&err_log)
  2820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2821. return
  2822. } else {
  2823. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  2824. sch.ScheduleWeek = schedule_week
  2825. }
  2826. if schMapM["schedule_date"] == nil || reflect.TypeOf(schMapM["schedule_date"]).String() != "string" {
  2827. utils.ErrorLog("schedule_date")
  2828. return
  2829. }
  2830. schedule_date, _ := schMapM["schedule_date"].(string)
  2831. if len(schedule_date) == 0 { //周几为空则生成一条导入错误日志
  2832. log := models.ExportLog{
  2833. LogType: 2,
  2834. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2835. TotalNum: int64(len(total_schedule) + failed_total),
  2836. FailNum: 1 + int64(failed_total),
  2837. SuccessNum: int64(len(schedules)),
  2838. CreateTime: time.Now().Unix(),
  2839. UpdateTime: time.Now().Unix(),
  2840. ExportTime: export_time,
  2841. Status: 1,
  2842. }
  2843. service.CreateExportLog(&log)
  2844. err_log := models.ExportErrLog{
  2845. LogType: 2,
  2846. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2847. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2848. Status: 1,
  2849. CreateTime: time.Now().Unix(),
  2850. UpdateTime: time.Now().Unix(),
  2851. ExportTime: export_time,
  2852. }
  2853. service.CreateExportErrLog(&err_log)
  2854. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2855. return
  2856. } else if schedule_date == "0" { //周几不符合格式则生成一条导入错误日志
  2857. log := models.ExportLog{
  2858. LogType: 2,
  2859. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2860. TotalNum: int64(len(total_schedule) + failed_total),
  2861. FailNum: 1 + int64(failed_total),
  2862. SuccessNum: int64(len(schedules)),
  2863. CreateTime: time.Now().Unix(),
  2864. UpdateTime: time.Now().Unix(),
  2865. ExportTime: export_time,
  2866. Status: 1,
  2867. }
  2868. service.CreateExportLog(&log)
  2869. err_log := models.ExportErrLog{
  2870. LogType: 2,
  2871. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2872. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  2873. Status: 1,
  2874. CreateTime: time.Now().Unix(),
  2875. UpdateTime: time.Now().Unix(),
  2876. ExportTime: export_time,
  2877. }
  2878. service.CreateExportErrLog(&err_log)
  2879. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  2880. return
  2881. } else {
  2882. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2883. sch.ScheduleDate = date.Unix()
  2884. }
  2885. sch.CreatedTime = time.Now().Unix()
  2886. sch.UpdatedTime = time.Now().Unix()
  2887. sch.ModeId = 1
  2888. sch.Status = 1
  2889. sch.UserOrgId = this.GetAdminUserInfo().CurrentOrgId
  2890. sch.IsExport = 1
  2891. var DialysisMachineName string
  2892. so, _ := service.GetDialysisSolutionTwo(sch.UserOrgId, sch.PatientId, sch.ModeId)
  2893. filedRecordOne, _ := service.FindFiledBy(sch.UserOrgId, "透析器")
  2894. filedRecordTwo, _ := service.FindFiledBy(sch.UserOrgId, "灌流器")
  2895. filedRecordThree, _ := service.FindFiledBy(sch.UserOrgId, "透析器/灌流器")
  2896. if filedRecordOne.IsShow == 1 {
  2897. DialysisMachineName = so.DialysisDialyszers
  2898. }
  2899. if filedRecordThree.IsShow == 1 {
  2900. if len(DialysisMachineName) > 0 {
  2901. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  2902. } else {
  2903. DialysisMachineName = so.DialyzerPerfusionApparatus
  2904. }
  2905. }
  2906. if filedRecordTwo.IsShow == 1 {
  2907. if len(DialysisMachineName) > 0 {
  2908. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  2909. } else {
  2910. DialysisMachineName = so.DialysisIrrigation
  2911. }
  2912. }
  2913. sch.DialysisMachineName = DialysisMachineName
  2914. schedules = append(schedules, &sch)
  2915. }
  2916. errLogs, _ := service.FindSchedualExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  2917. if len(schedules) > 0 {
  2918. schedule_date := time.Now().Format("2006-01-02")
  2919. date, _ := utils.ParseTimeStringToTime("2006-01-02", schedule_date)
  2920. clear_schedule_date := date.Unix() //根据日期去清除,该日期未来的排班数据
  2921. service.UpdateScheduleByExport(this.GetAdminUserInfo().CurrentOrgId, clear_schedule_date)
  2922. if err == nil {
  2923. for _, item := range schedules {
  2924. if item.ScheduleDate > clear_schedule_date {
  2925. //查询该患者是否转出获取死亡
  2926. //查找当天日期是否存在
  2927. _, errcode := service.GetTodayScheduleIsExistOne(item.PatientId, item.ScheduleDate, item.UserOrgId)
  2928. if errcode == gorm.ErrRecordNotFound {
  2929. //查询该床位是否有患者
  2930. sch, errcodes := service.GetPatientByBed(item.ScheduleDate, item.BedId, item.ScheduleType, item.UserOrgId)
  2931. if errcodes == gorm.ErrRecordNotFound {
  2932. service.CreateScheduleTwo(item)
  2933. } else if errcodes == nil {
  2934. //清除当天该床位已有的患者
  2935. service.ModeFyScheduleById(sch.ScheduleDate, sch.BedId, sch.ScheduleType, sch.UserOrgId)
  2936. service.CreateScheduleTwo(item)
  2937. }
  2938. } else if errcode == nil {
  2939. schedule := models.XtSchedule{
  2940. PartitionId: item.PartitionId,
  2941. BedId: item.BedId,
  2942. PatientId: item.PatientId,
  2943. ScheduleDate: item.ScheduleDate,
  2944. ScheduleType: item.ScheduleType,
  2945. ScheduleWeek: item.ScheduleWeek,
  2946. ModeId: 1,
  2947. Status: 1,
  2948. DialysisMachineName: item.DialysisMachineName,
  2949. }
  2950. service.UpdateScheduleByOrgIdOne(item.PatientId, item.ScheduleDate, item.UserOrgId, &schedule)
  2951. }
  2952. }
  2953. }
  2954. log := models.ExportLog{
  2955. LogType: 2,
  2956. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2957. TotalNum: int64(len(total_schedule) + failed_total),
  2958. FailNum: int64(len(errLogs) + failed_total),
  2959. SuccessNum: int64(len(schedules)),
  2960. CreateTime: time.Now().Unix(),
  2961. UpdateTime: time.Now().Unix(),
  2962. ExportTime: export_time,
  2963. Status: 1,
  2964. }
  2965. service.CreateExportLog(&log)
  2966. if failed_total > 0 {
  2967. err_log := models.ExportErrLog{
  2968. LogType: 2,
  2969. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2970. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  2971. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  2972. Status: 1,
  2973. CreateTime: time.Now().Unix(),
  2974. UpdateTime: time.Now().Unix(),
  2975. ExportTime: export_time,
  2976. }
  2977. service.CreateExportErrLog(&err_log)
  2978. }
  2979. this.ServeSuccessJSON(map[string]interface{}{
  2980. "msg": "导入成功",
  2981. "total_num": len(total_schedule) + failed_total,
  2982. "success_num": len(schedules),
  2983. "fail_num": int64(len(errLogs)),
  2984. })
  2985. } else {
  2986. log := models.ExportLog{
  2987. LogType: 2,
  2988. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  2989. TotalNum: int64(len(total_schedule) + failed_total),
  2990. FailNum: int64(len(errLogs) + failed_total),
  2991. SuccessNum: int64(len(schedules)),
  2992. CreateTime: time.Now().Unix(),
  2993. UpdateTime: time.Now().Unix(),
  2994. ExportTime: export_time,
  2995. Status: 1,
  2996. }
  2997. service.CreateExportLog(&log)
  2998. if failed_total > 0 {
  2999. err_log := models.ExportErrLog{
  3000. LogType: 2,
  3001. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3002. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  3003. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  3004. Status: 1,
  3005. CreateTime: time.Now().Unix(),
  3006. UpdateTime: time.Now().Unix(),
  3007. ExportTime: export_time,
  3008. }
  3009. service.CreateExportErrLog(&err_log)
  3010. }
  3011. this.ServeSuccessJSON(map[string]interface{}{
  3012. "msg": "导入成功",
  3013. "total_num": len(total_schedule),
  3014. "success_num": len(schedules),
  3015. "fail_num": int64(len(errLogs)),
  3016. })
  3017. }
  3018. } else {
  3019. log := models.ExportLog{
  3020. LogType: 2,
  3021. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3022. TotalNum: int64(len(total_schedule) + failed_total),
  3023. FailNum: int64(len(errLogs) + failed_total),
  3024. SuccessNum: int64(len(schedules)),
  3025. CreateTime: time.Now().Unix(),
  3026. UpdateTime: time.Now().Unix(),
  3027. ExportTime: export_time,
  3028. Status: 1,
  3029. }
  3030. service.CreateExportLog(&log)
  3031. if failed_total > 0 {
  3032. err_log := models.ExportErrLog{
  3033. LogType: 2,
  3034. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3035. ErrMsg: "当前日期(" + time.Now().Format("2006-01-02") + " " + GetWeekString(time.Now().Weekday().String()) +
  3036. ")及以前的排班数据" + strconv.FormatInt(int64(failed_total), 10) + "条,不执行导入",
  3037. Status: 1,
  3038. CreateTime: time.Now().Unix(),
  3039. UpdateTime: time.Now().Unix(),
  3040. ExportTime: export_time,
  3041. }
  3042. service.CreateExportErrLog(&err_log)
  3043. }
  3044. this.ServeSuccessJSON(map[string]interface{}{
  3045. "msg": "导入成功",
  3046. "total_num": len(total_schedule),
  3047. "success_num": len(schedules),
  3048. "fail_num": int64(len(errLogs)),
  3049. })
  3050. }
  3051. }
  3052. }
  3053. func (this *ScheduleApiController) ExportScheduleTemplate() {
  3054. dataBody := make(map[string]interface{}, 0)
  3055. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3056. if err != nil {
  3057. utils.ErrorLog(err.Error())
  3058. return
  3059. }
  3060. utils.ErrorLog("%v", dataBody)
  3061. export_time := time.Now().Unix()
  3062. var schedules []*models.PatientScheduleTemplateItem
  3063. var total_schedule []interface{}
  3064. patients, _, _ := service.GetAllPatientList(this.GetAdminUserInfo().CurrentOrgId)
  3065. if dataBody["schedule"] != nil || reflect.TypeOf(dataBody["schedule"]).String() == "[]interface {}" {
  3066. tempSchedule := dataBody["schedule"].([]interface{})
  3067. total_schedule = tempSchedule
  3068. for _, schMap := range tempSchedule {
  3069. schMapM := schMap.(map[string]interface{})
  3070. var sch models.PatientScheduleTemplateItem
  3071. if schMapM["name"] == nil || reflect.TypeOf(schMapM["name"]).String() != "string" {
  3072. utils.ErrorLog("name")
  3073. return
  3074. }
  3075. name, _ := schMapM["name"].(string)
  3076. fmt.Println(name)
  3077. if len(name) == 0 { //名字为空则生成一条导入错误日志
  3078. err_log := models.ExportErrLog{
  3079. LogType: 3,
  3080. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3081. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名不能为空",
  3082. Status: 1,
  3083. CreateTime: time.Now().Unix(),
  3084. UpdateTime: time.Now().Unix(),
  3085. ExportTime: export_time,
  3086. }
  3087. service.CreateExportErrLog(&err_log)
  3088. continue
  3089. } else {
  3090. var patient []*models.Patients
  3091. for _, item := range patients {
  3092. if strings.Replace(item.Name, " ", "", -1) == name {
  3093. patient = append(patient, item)
  3094. }
  3095. }
  3096. if len(patient) == 0 { //错误日志
  3097. err_log := models.ExportErrLog{
  3098. LogType: 3,
  3099. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3100. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列的姓名在系统中不存在,请在系统中添加该病人",
  3101. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在系统中不存在,请在系统中添加该患者",
  3102. Status: 1,
  3103. CreateTime: time.Now().Unix(),
  3104. UpdateTime: time.Now().Unix(),
  3105. ExportTime: export_time,
  3106. }
  3107. service.CreateExportErrLog(&err_log)
  3108. continue
  3109. } else if len(patient) == 1 { //
  3110. sch.PatientID = patient[0].ID
  3111. } else if len(patient) > 1 { //出现同名的情况
  3112. err_log := models.ExportErrLog{
  3113. LogType: 3,
  3114. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3115. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列" + "患者姓名为" + name + "在当前机构中存在重名,无法确定到具体患者",
  3116. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行,第" + schMapM["row"].(string) + "列患者姓名为\"" + name + "\"在当前机构中存在重名,无法确定到具体患者",
  3117. Status: 1,
  3118. CreateTime: time.Now().Unix(),
  3119. UpdateTime: time.Now().Unix(),
  3120. ExportTime: export_time,
  3121. }
  3122. service.CreateExportErrLog(&err_log)
  3123. continue
  3124. }
  3125. }
  3126. if schMapM["schedule_type"] == nil && reflect.TypeOf(schMapM["schedule_type"]).String() != "float64" {
  3127. utils.ErrorLog("schedule_type")
  3128. return
  3129. }
  3130. schedule_type := int64(schMapM["schedule_type"].(float64))
  3131. if schedule_type <= 0 { //班次格式有误,插入日志
  3132. log := models.ExportLog{
  3133. LogType: 3,
  3134. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3135. TotalNum: int64(len(total_schedule)),
  3136. FailNum: 1,
  3137. SuccessNum: int64(len(schedules)),
  3138. CreateTime: time.Now().Unix(),
  3139. UpdateTime: time.Now().Unix(),
  3140. ExportTime: export_time,
  3141. Status: 1,
  3142. }
  3143. service.CreateExportLog(&log)
  3144. err_log := models.ExportErrLog{
  3145. LogType: 3,
  3146. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3147. ErrMsg: "第2行第" + schMapM["row"].(string) + "列的班次格式有误",
  3148. Status: 1,
  3149. CreateTime: time.Now().Unix(),
  3150. UpdateTime: time.Now().Unix(),
  3151. ExportTime: export_time,
  3152. }
  3153. service.CreateExportErrLog(&err_log)
  3154. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3155. return
  3156. } else {
  3157. sch.TimeType = int8(schedule_type)
  3158. }
  3159. if schMapM["template_id"] == nil && reflect.TypeOf(schMapM["template_id"]).String() != "float64" {
  3160. utils.ErrorLog("template_id")
  3161. return
  3162. }
  3163. template_id := int64(schMapM["template_id"].(float64))
  3164. sch.TemplateID = template_id
  3165. if schMapM["device_number_name"] == nil || reflect.TypeOf(schMapM["device_number_name"]).String() != "string" {
  3166. utils.ErrorLog("device_number_name")
  3167. return
  3168. }
  3169. partition_name, _ := schMapM["partition_name"].(string)
  3170. zone, _ := service.FindDeviceZoneByName(partition_name, this.GetAdminUserInfo().CurrentOrgId)
  3171. device_number_name, _ := schMapM["device_number_name"].(string)
  3172. if len(device_number_name) == 0 { //分区为空
  3173. log := models.ExportLog{
  3174. LogType: 3,
  3175. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3176. TotalNum: int64(len(total_schedule)),
  3177. FailNum: 1,
  3178. SuccessNum: int64(len(schedules)),
  3179. CreateTime: time.Now().Unix(),
  3180. UpdateTime: time.Now().Unix(),
  3181. ExportTime: export_time,
  3182. Status: 1,
  3183. }
  3184. service.CreateExportLog(&log)
  3185. err_log := models.ExportErrLog{
  3186. LogType: 3,
  3187. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3188. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  3189. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  3190. Status: 1,
  3191. CreateTime: time.Now().Unix(),
  3192. UpdateTime: time.Now().Unix(),
  3193. ExportTime: export_time,
  3194. }
  3195. service.CreateExportErrLog(&err_log)
  3196. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3197. return
  3198. } else {
  3199. device, err := service.FindDeviceByNameTwo(device_number_name, this.GetAdminUserInfo().CurrentOrgId, zone.ID)
  3200. if err == nil {
  3201. if len(device) == 0 { //没查到数据,插入错误日志
  3202. log := models.ExportLog{
  3203. LogType: 3,
  3204. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3205. TotalNum: int64(len(total_schedule)),
  3206. FailNum: 1,
  3207. SuccessNum: int64(len(schedules)),
  3208. CreateTime: time.Now().Unix(),
  3209. UpdateTime: time.Now().Unix(),
  3210. ExportTime: export_time,
  3211. Status: 1,
  3212. }
  3213. service.CreateExportLog(&log)
  3214. err_log := models.ExportErrLog{
  3215. LogType: 3,
  3216. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3217. ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)), 10) + "行第2列机号格式有误",
  3218. Status: 1,
  3219. CreateTime: time.Now().Unix(),
  3220. UpdateTime: time.Now().Unix(),
  3221. ExportTime: export_time,
  3222. }
  3223. service.CreateExportErrLog(&err_log)
  3224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3225. return
  3226. } else if len(device) == 1 {
  3227. sch.DeviceNumberID = device[0].ID
  3228. } else if len(device) > 1 { //出现重名,插入错误日志
  3229. log := models.ExportLog{
  3230. LogType: 3,
  3231. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3232. TotalNum: int64(len(total_schedule)),
  3233. FailNum: 1,
  3234. SuccessNum: int64(len(schedules)),
  3235. CreateTime: time.Now().Unix(),
  3236. UpdateTime: time.Now().Unix(),
  3237. ExportTime: export_time,
  3238. Status: 1,
  3239. }
  3240. service.CreateExportLog(&log)
  3241. err_log := models.ExportErrLog{
  3242. LogType: 3,
  3243. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3244. ErrMsg: "出现两个床位号相同的床位",
  3245. Status: 1,
  3246. CreateTime: time.Now().Unix(),
  3247. UpdateTime: time.Now().Unix(),
  3248. ExportTime: export_time,
  3249. }
  3250. service.CreateExportErrLog(&err_log)
  3251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3252. return
  3253. }
  3254. }
  3255. }
  3256. if schMapM["schedule_week"] == nil || reflect.TypeOf(schMapM["schedule_week"]).String() != "string" {
  3257. utils.ErrorLog("schedule_week")
  3258. return
  3259. }
  3260. schedule_week, _ := schMapM["schedule_week"].(string)
  3261. if len(schedule_week) == 0 { //周几为空则生成一条导入错误日志
  3262. log := models.ExportLog{
  3263. LogType: 3,
  3264. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3265. TotalNum: int64(len(total_schedule)),
  3266. FailNum: 1,
  3267. SuccessNum: int64(len(schedules)),
  3268. CreateTime: time.Now().Unix(),
  3269. UpdateTime: time.Now().Unix(),
  3270. ExportTime: export_time,
  3271. Status: 1,
  3272. }
  3273. service.CreateExportLog(&log)
  3274. err_log := models.ExportErrLog{
  3275. LogType: 3,
  3276. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3277. //ErrMsg: "第" + strconv.FormatInt(int64(schMapM["index"].(float64)) ,10)+ "行" + "的姓名不能为空",
  3278. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  3279. Status: 1,
  3280. CreateTime: time.Now().Unix(),
  3281. UpdateTime: time.Now().Unix(),
  3282. ExportTime: export_time,
  3283. }
  3284. service.CreateExportErrLog(&err_log)
  3285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3286. return
  3287. } else if schedule_week == "0" { //周几不符合格式则生成一条导入错误日志
  3288. log := models.ExportLog{
  3289. LogType: 3,
  3290. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3291. TotalNum: int64(len(total_schedule)),
  3292. FailNum: 1,
  3293. SuccessNum: int64(len(schedules)),
  3294. CreateTime: time.Now().Unix(),
  3295. UpdateTime: time.Now().Unix(),
  3296. ExportTime: export_time,
  3297. Status: 1,
  3298. }
  3299. service.CreateExportLog(&log)
  3300. err_log := models.ExportErrLog{
  3301. LogType: 3,
  3302. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3303. ErrMsg: "第1行第" + schMapM["row"].(string) + "列的星期名格式有误",
  3304. Status: 1,
  3305. CreateTime: time.Now().Unix(),
  3306. UpdateTime: time.Now().Unix(),
  3307. ExportTime: export_time,
  3308. }
  3309. service.CreateExportErrLog(&err_log)
  3310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3311. return
  3312. } else {
  3313. schedule_week, _ := strconv.ParseInt(schedule_week, 10, 64)
  3314. sch.Weekday = int8(schedule_week)
  3315. }
  3316. treat_mode, _ := schMapM["treat_mode"].(string)
  3317. treat_mode_int, _ := strconv.ParseInt(treat_mode, 10, 64)
  3318. sch.CreateTime = time.Now().Unix()
  3319. sch.ModifyTime = time.Now().Unix()
  3320. sch.TreatMode = treat_mode_int
  3321. sch.Status = 1
  3322. sch.OrgID = this.GetAdminUserInfo().CurrentOrgId
  3323. sch.IsExport = 1
  3324. schedules = append(schedules, &sch)
  3325. }
  3326. errLogs, _ := service.FindSchedualTemplateExportLog(this.GetAdminUserInfo().CurrentOrgId, export_time)
  3327. //for _, item := range schedules {
  3328. //
  3329. //}
  3330. if len(schedules) > 0 {
  3331. err := service.UpdateScheduleTemplateStatus(this.GetAdminUserInfo().CurrentOrgId)
  3332. if err == nil {
  3333. for _, item := range schedules {
  3334. //判斷某個模板下,當天是否有排版,沒有的話就新增
  3335. total := service.ExportScheduleTemplate(item)
  3336. if total == 0 {
  3337. service.CreateScheduleTemplate(item)
  3338. }
  3339. }
  3340. ////查询已经转出或者死亡的患者
  3341. //patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3342. //for _, it := range patientList {
  3343. // timeStr := time.Now().Format("2006-01-02")
  3344. // timeLayout := "2006-01-02 15:04:05"
  3345. // timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3346. // timenow := timeStringToTime.Unix()
  3347. // service.UpdateScheduleByDeathTime(it.ID, timenow)
  3348. // service.UpdateScheduleItemByPatientId(it.ID)
  3349. //}
  3350. log := models.ExportLog{
  3351. LogType: 3,
  3352. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3353. TotalNum: int64(len(total_schedule)),
  3354. FailNum: int64(len(errLogs)),
  3355. SuccessNum: int64(len(schedules)),
  3356. CreateTime: time.Now().Unix(),
  3357. UpdateTime: time.Now().Unix(),
  3358. ExportTime: export_time,
  3359. Status: 1,
  3360. }
  3361. service.CreateExportLog(&log)
  3362. this.ServeSuccessJSON(map[string]interface{}{
  3363. "msg": "导入成功",
  3364. "total_num": len(total_schedule),
  3365. "success_num": len(schedules),
  3366. "fail_num": int64(len(errLogs)),
  3367. })
  3368. } else {
  3369. log := models.ExportLog{
  3370. LogType: 3,
  3371. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3372. TotalNum: int64(len(total_schedule)),
  3373. FailNum: int64(len(errLogs)),
  3374. SuccessNum: int64(len(schedules)),
  3375. CreateTime: time.Now().Unix(),
  3376. UpdateTime: time.Now().Unix(),
  3377. ExportTime: export_time,
  3378. Status: 1,
  3379. }
  3380. service.CreateExportLog(&log)
  3381. this.ServeSuccessJSON(map[string]interface{}{
  3382. "msg": "导入成功",
  3383. "total_num": len(total_schedule),
  3384. "success_num": len(schedules),
  3385. "fail_num": int64(len(errLogs)),
  3386. })
  3387. }
  3388. } else {
  3389. log := models.ExportLog{
  3390. LogType: 3,
  3391. UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3392. TotalNum: int64(len(total_schedule)),
  3393. FailNum: int64(len(errLogs)),
  3394. SuccessNum: int64(len(schedules)),
  3395. CreateTime: time.Now().Unix(),
  3396. UpdateTime: time.Now().Unix(),
  3397. ExportTime: export_time,
  3398. Status: 1,
  3399. }
  3400. service.CreateExportLog(&log)
  3401. this.ServeSuccessJSON(map[string]interface{}{
  3402. "msg": "导入成功",
  3403. "total_num": len(total_schedule),
  3404. "success_num": len(schedules),
  3405. "fail_num": int64(len(errLogs)),
  3406. })
  3407. }
  3408. }
  3409. }
  3410. func (c *ScheduleApiController) GetInitExcelInitDate() {
  3411. thisTime := time.Now()
  3412. thisTime1 := time.Now()
  3413. thisTime2 := time.Now()
  3414. thisTime3 := time.Now()
  3415. thisTime4 := time.Now()
  3416. thisTime1 = thisTime1.AddDate(0, 0, 7)
  3417. thisTime2 = thisTime2.AddDate(0, 0, 14)
  3418. thisTime3 = thisTime3.AddDate(0, 0, 21)
  3419. thisTime4 = thisTime4.AddDate(0, 0, 28)
  3420. weekDay := int(thisTime.Weekday())
  3421. if weekDay == 0 {
  3422. weekDay = 7
  3423. }
  3424. weekEnd := 7 - weekDay
  3425. weekStart := weekEnd - 6
  3426. days := make([]string, 0)
  3427. for index := weekStart; index <= weekEnd; index++ {
  3428. theDay := thisTime.AddDate(0, 0, index)
  3429. days = append(days, theDay.Format("2006-01-02"))
  3430. }
  3431. weekDay1 := int(thisTime1.Weekday())
  3432. if weekDay1 == 0 {
  3433. weekDay1 = 7
  3434. }
  3435. weekEnd1 := 7 - weekDay1
  3436. weekStart1 := weekEnd1 - 6
  3437. for index := weekStart1; index <= weekEnd1; index++ {
  3438. theDay := thisTime1.AddDate(0, 0, index)
  3439. days = append(days, theDay.Format("2006-01-02"))
  3440. }
  3441. weekDay2 := int(thisTime2.Weekday())
  3442. if weekDay2 == 0 {
  3443. weekDay2 = 7
  3444. }
  3445. weekEnd2 := 7 - weekDay2
  3446. weekStart2 := weekEnd2 - 6
  3447. for index := weekStart2; index <= weekEnd2; index++ {
  3448. theDay := thisTime2.AddDate(0, 0, index)
  3449. days = append(days, theDay.Format("2006-01-02"))
  3450. }
  3451. weekDay3 := int(thisTime3.Weekday())
  3452. if weekDay3 == 0 {
  3453. weekDay3 = 7
  3454. }
  3455. weekEnd3 := 7 - weekDay3
  3456. weekStart3 := weekEnd3 - 6
  3457. for index := weekStart3; index <= weekEnd3; index++ {
  3458. theDay := thisTime3.AddDate(0, 0, index)
  3459. days = append(days, theDay.Format("2006-01-02"))
  3460. }
  3461. weekDay4 := int(thisTime4.Weekday())
  3462. if weekDay4 == 0 {
  3463. weekDay4 = 7
  3464. }
  3465. weekEnd4 := 7 - weekDay4
  3466. weekStart4 := weekEnd4 - 6
  3467. for index := weekStart4; index <= weekEnd4; index++ {
  3468. theDay := thisTime4.AddDate(0, 0, index)
  3469. days = append(days, theDay.Format("2006-01-02"))
  3470. }
  3471. c.ServeSuccessJSON(map[string]interface{}{
  3472. "days": days,
  3473. })
  3474. return
  3475. }
  3476. func GetWeekString(week string) string {
  3477. var weekStr string
  3478. switch week {
  3479. case "Sunday":
  3480. weekStr = "周日"
  3481. break
  3482. case "Monday":
  3483. weekStr = "周一"
  3484. break
  3485. case "Tuesday":
  3486. weekStr = "周二"
  3487. break
  3488. case "Wednesday":
  3489. weekStr = "周三"
  3490. break
  3491. case "Thursday":
  3492. weekStr = "周四"
  3493. break
  3494. case "Friday":
  3495. weekStr = "周五"
  3496. break
  3497. case "Saturday":
  3498. weekStr = "周六"
  3499. break
  3500. default:
  3501. weekStr = ""
  3502. break
  3503. }
  3504. return weekStr
  3505. }
  3506. func (c *ScheduleApiController) SearchTemplateSchedulePatients() {
  3507. template_id, _ := c.GetInt64("template_id", 0)
  3508. keywords := c.GetString("keywords")
  3509. adminInfo := c.GetAdminUserInfo()
  3510. scheduleItems, _ := service.GetTemplateSchedualPatientsByKeywords(keywords, adminInfo.CurrentOrgId, template_id)
  3511. c.ServeSuccessJSON(map[string]interface{}{
  3512. "schdules": scheduleItems,
  3513. })
  3514. }
  3515. func (c *ScheduleApiController) CancelScheduleTemplate() {
  3516. item_id, _ := c.GetInt64("id")
  3517. adminInfo := c.GetAdminUserInfo()
  3518. err := service.UpdateNewScheduleTemplateStatus(item_id, adminInfo.CurrentOrgId)
  3519. if err == nil {
  3520. c.ServeSuccessJSON(map[string]interface{}{
  3521. "msg": "取消成功",
  3522. })
  3523. return
  3524. } else {
  3525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeExportError)
  3526. return
  3527. }
  3528. }
  3529. func (this *ScheduleApiController) GetNextWeekDayScheduleOne() {
  3530. week_type, _ := this.GetInt64("week_type", -1)
  3531. week_time, _ := this.GetInt64("week_time")
  3532. record_date := this.GetString("record_date")
  3533. zons := this.GetString("zone")
  3534. zone := strings.Split(zons, ",")
  3535. start_time, _ := this.GetInt64("start_time")
  3536. end_time, _ := this.GetInt64("end_time")
  3537. timeLayout := "2006-01-02"
  3538. loc, _ := time.LoadLocation("Local")
  3539. //theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3540. //theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  3541. ids := this.GetString("ids")
  3542. var idStr []string
  3543. if len(ids) > 0 {
  3544. idStr = strings.Split(ids, ",")
  3545. }
  3546. adminUserInfo := this.GetAdminUserInfo()
  3547. var theStartTIme int64
  3548. if len(record_date) > 0 {
  3549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3550. if err != nil {
  3551. utils.ErrorLog(err.Error())
  3552. }
  3553. theStartTIme = theTime.Unix()
  3554. }
  3555. schedule, err := service.GetNextWeekDayScheduleSix(week_type, week_time, start_time, end_time, adminUserInfo.CurrentOrgId, zone, theStartTIme, idStr)
  3556. for _, item := range schedule {
  3557. order, _ := service.GetLastDialysisOrder(adminUserInfo.CurrentOrgId, item.PatientId, theStartTIme)
  3558. item.XtDialysisOrderSix = order
  3559. solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId)
  3560. item.DialysisSolution = solutionLastWeek
  3561. prescription, _ := service.GetLastDialysisPrescriptionTwo(adminUserInfo.CurrentOrgId, item.PatientId, item.ModeId, item.ScheduleDate)
  3562. item.DialysisPrescription = prescription
  3563. }
  3564. if err != nil {
  3565. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3566. return
  3567. }
  3568. this.ServeSuccessJSON(map[string]interface{}{
  3569. "schedule": schedule,
  3570. })
  3571. }
  3572. func (this *ScheduleApiController) GetNextWeekDaySchedule() {
  3573. week_type, _ := this.GetInt64("week_type", -1)
  3574. week_time, _ := this.GetInt64("week_time")
  3575. record_date := this.GetString("record_date")
  3576. zons := this.GetString("zone")
  3577. zone := strings.Split(zons, ",")
  3578. start_time := this.GetString("start_time")
  3579. end_time := this.GetString("end_time")
  3580. timeLayout := "2006-01-02"
  3581. loc, _ := time.LoadLocation("Local")
  3582. theTimeStart, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3583. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  3584. ids := this.GetString("ids")
  3585. var idStr []string
  3586. if len(ids) > 0 {
  3587. idStr = strings.Split(ids, ",")
  3588. }
  3589. adminUserInfo := this.GetAdminUserInfo()
  3590. var theStartTIme int64
  3591. if len(record_date) > 0 {
  3592. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3593. if err != nil {
  3594. utils.ErrorLog(err.Error())
  3595. }
  3596. theStartTIme = theTime.Unix()
  3597. }
  3598. schedule, err := service.GetNextWeekDaySchedule(week_type, week_time, theTimeStart.Unix(), theTimeEnd.Unix(), adminUserInfo.CurrentOrgId, zone, theStartTIme, idStr)
  3599. for _, item := range schedule {
  3600. AssessmentBefor, _ := service.GetAssessmentBeforListLastWeek(item.ScheduleDate, item.PatientId, item.UserOrgId)
  3601. item.XtAssessmentBeforeDislysis = AssessmentBefor
  3602. doctorAdvices, _ := service.GetDoctorAdviceLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
  3603. item.DoctorAdvice = doctorAdvices
  3604. hisDoctorAdvice, _ := service.GetHisDoctorAdviceListLastWeek(item.UserOrgId, item.PatientId, item.ScheduleDate)
  3605. item.HisDoctorAdviceInfo = hisDoctorAdvice
  3606. solutionLastWeek, _ := service.GetDialysisSolutionLastWeek(item.UserOrgId, item.PatientId, item.ModeId)
  3607. item.DialysisSolution = solutionLastWeek
  3608. templateList, _ := service.GetHisPrescriptionTemplateList(item.UserOrgId, item.PatientId, item.ModeId)
  3609. item.HisPrescriptionTemplate = templateList
  3610. }
  3611. if err != nil {
  3612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3613. return
  3614. }
  3615. this.ServeSuccessJSON(map[string]interface{}{
  3616. "schedule": schedule,
  3617. })
  3618. }
  3619. func (this *ScheduleApiController) GetThreeWeekList() {
  3620. start_time := this.GetString("start_time")
  3621. end_time := this.GetString("end_time")
  3622. partition_id, _ := this.GetInt64("partition_id")
  3623. schedule_type, _ := this.GetInt64("schedule_type")
  3624. fmt.Println(partition_id, schedule_type)
  3625. timeLayout := "2006-01-02"
  3626. loc, _ := time.LoadLocation("Local")
  3627. var theStartTIme int64
  3628. if len(start_time) > 0 {
  3629. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3630. if err != nil {
  3631. utils.ErrorLog(err.Error())
  3632. }
  3633. theStartTIme = theTime.Unix()
  3634. }
  3635. var theEndtTIme int64
  3636. if len(end_time) > 0 {
  3637. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  3638. if err != nil {
  3639. utils.ErrorLog(err.Error())
  3640. }
  3641. theEndtTIme = theTime.Unix()
  3642. }
  3643. adminUserInfo := this.GetAdminUserInfo()
  3644. orgId := adminUserInfo.CurrentOrgId
  3645. partitions, _ := service.GetSchedulePartitionPanel(orgId)
  3646. list, err := service.GetThreeWeekList(theStartTIme, theEndtTIme, orgId, schedule_type, partition_id)
  3647. if err != nil {
  3648. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3649. return
  3650. }
  3651. this.ServeSuccessJSON(map[string]interface{}{
  3652. "list": list,
  3653. "partitions": partitions,
  3654. })
  3655. }
  3656. func (this *ScheduleApiController) GetAllZones() {
  3657. adminUserInfo := this.GetAdminUserInfo()
  3658. orgId := adminUserInfo.CurrentOrgId
  3659. zones, err := service.GetAllZoneOne(orgId)
  3660. devicenumber, err := service.GetAllBedNumberList(orgId)
  3661. if err != nil {
  3662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3663. return
  3664. }
  3665. this.ServeSuccessJSON(map[string]interface{}{
  3666. "zones": zones,
  3667. "devicenumber": devicenumber,
  3668. })
  3669. }
  3670. func (this *ScheduleApiController) GetCopyPatientSchedules() {
  3671. adminUserInfo := this.GetAdminUserInfo()
  3672. orgId := adminUserInfo.CurrentOrgId
  3673. start_time, _ := this.GetInt64("start_time")
  3674. end_time, _ := this.GetInt64("end_time")
  3675. copy_startime, _ := this.GetInt64("copy_startime")
  3676. copy_endtime, _ := this.GetInt64("copy_endtime")
  3677. //获取本周患者排班
  3678. schedules, _ := service.GetWeekSchedules(orgId, start_time, end_time)
  3679. //先清除复制周的排班
  3680. errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3681. fmt.Println(errcode)
  3682. var err error
  3683. for _, item := range schedules {
  3684. //fmt.Println(item.StartTime+604800)
  3685. //礼拜1
  3686. if item.ScheduleWeek == 1 {
  3687. item.ScheduleDate = copy_startime
  3688. }
  3689. if item.ScheduleWeek == 2 {
  3690. item.ScheduleDate = copy_startime + 86400
  3691. }
  3692. if item.ScheduleWeek == 3 {
  3693. item.ScheduleDate = copy_startime + 172800
  3694. }
  3695. if item.ScheduleWeek == 4 {
  3696. item.ScheduleDate = copy_startime + 259200
  3697. }
  3698. if item.ScheduleWeek == 5 {
  3699. item.ScheduleDate = copy_startime + 345600
  3700. }
  3701. if item.ScheduleWeek == 6 {
  3702. item.ScheduleDate = copy_startime + 432000
  3703. }
  3704. //礼拜天
  3705. if item.ScheduleWeek == 7 {
  3706. item.ScheduleDate = copy_endtime
  3707. }
  3708. schedule := models.XtSchedule{
  3709. UserOrgId: item.UserOrgId,
  3710. PartitionId: item.PartitionId,
  3711. BedId: item.BedId,
  3712. PatientId: item.PatientId,
  3713. ScheduleDate: item.ScheduleDate,
  3714. ScheduleType: item.ScheduleType,
  3715. ScheduleWeek: item.ScheduleWeek,
  3716. ModeId: item.ModeId,
  3717. Status: 1,
  3718. CreatedTime: time.Now().Unix(),
  3719. }
  3720. var DialysisMachineName string
  3721. so, _ := service.GetDialysisSolutionTwo(adminUserInfo.CurrentOrgId, schedule.PatientId, schedule.ModeId)
  3722. filedRecordOne, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器")
  3723. filedRecordTwo, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "灌流器")
  3724. filedRecordThree, _ := service.FindFiledBy(adminUserInfo.CurrentOrgId, "透析器/灌流器")
  3725. if filedRecordOne.IsShow == 1 {
  3726. DialysisMachineName = so.DialysisDialyszers
  3727. }
  3728. if filedRecordThree.IsShow == 1 {
  3729. if len(DialysisMachineName) > 0 {
  3730. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3731. } else {
  3732. DialysisMachineName = so.DialyzerPerfusionApparatus
  3733. }
  3734. }
  3735. if filedRecordTwo.IsShow == 1 {
  3736. if len(DialysisMachineName) > 0 {
  3737. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  3738. } else {
  3739. DialysisMachineName = so.DialysisIrrigation
  3740. }
  3741. }
  3742. schedule.DialysisMachineName = DialysisMachineName
  3743. schedule.IsExport = 4000
  3744. err = service.AddPatientSchedule(&schedule)
  3745. }
  3746. patientList, _ := service.GetDeathPatient(this.GetAdminUserInfo().CurrentOrgId)
  3747. timeStr := time.Now().Format("2006-01-02")
  3748. timeLayout := "2006-01-02 15:04:05"
  3749. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  3750. timenow := timeStringToTime.Unix()
  3751. for _, it := range patientList {
  3752. service.UpdateScheduleByDeathTime(it.ID, timenow)
  3753. service.UpdateScheduleItemByPatientId(it.ID)
  3754. }
  3755. if err != nil {
  3756. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3757. return
  3758. }
  3759. this.ServeSuccessJSON(map[string]interface{}{
  3760. "msg": "msg",
  3761. })
  3762. return
  3763. //查询复制中的排班日期是否存在
  3764. //_, errcode := service.GetLastWeekSchedule(orgId, copy_startime, copy_endtime)
  3765. //
  3766. //if errcode == gorm.ErrRecordNotFound {
  3767. // //如果没有直接新增
  3768. //
  3769. // for _, item := range schedules {
  3770. // //fmt.Println(item.StartTime+604800)
  3771. // //礼拜1
  3772. // if item.ScheduleWeek == 1 {
  3773. // item.ScheduleDate = copy_startime
  3774. // }
  3775. // if item.ScheduleWeek == 2 {
  3776. // item.ScheduleDate = copy_startime + 86400
  3777. // }
  3778. // if item.ScheduleWeek == 3 {
  3779. // item.ScheduleDate = copy_startime + 172800
  3780. // }
  3781. // if item.ScheduleWeek == 4 {
  3782. // item.ScheduleDate = copy_startime + 259200
  3783. // }
  3784. // if item.ScheduleWeek == 5 {
  3785. // item.ScheduleDate = copy_startime + 345600
  3786. // }
  3787. //
  3788. // if item.ScheduleWeek == 6 {
  3789. // item.ScheduleDate = copy_startime + 432000
  3790. // }
  3791. // //礼拜天
  3792. // if item.ScheduleWeek == 0 {
  3793. // item.ScheduleDate = copy_endtime
  3794. // }
  3795. // schedule := models.XtSchedule{
  3796. // UserOrgId: item.UserOrgId,
  3797. // PartitionId: item.PartitionId,
  3798. // BedId: item.BedId,
  3799. // PatientId: item.PatientId,
  3800. // ScheduleDate: item.ScheduleDate,
  3801. // ScheduleType: item.ScheduleType,
  3802. // ScheduleWeek: item.ScheduleWeek,
  3803. // ModeId: item.ModeId,
  3804. // Status: 1,
  3805. // CreatedTime: time.Now().Unix(),
  3806. // }
  3807. //
  3808. // err := service.AddPatientSchedule(&schedule)
  3809. // if err != nil {
  3810. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3811. // return
  3812. // }
  3813. // this.ServeSuccessJSON(map[string]interface{}{
  3814. // "schedule": schedule,
  3815. // })
  3816. // }
  3817. //} else if errcode == nil {
  3818. //
  3819. // //先清除复制周的排班
  3820. // errcode := service.UpdatePatientSchedule(orgId, copy_startime, copy_endtime)
  3821. // fmt.Println(errcode)
  3822. // for _, item := range schedules {
  3823. // //fmt.Println(item.StartTime+604800)
  3824. // //礼拜1
  3825. // if item.ScheduleWeek == 1 {
  3826. // item.ScheduleDate = copy_startime
  3827. // }
  3828. // if item.ScheduleWeek == 2 {
  3829. // item.ScheduleDate = copy_startime + 86400
  3830. // }
  3831. // if item.ScheduleWeek == 3 {
  3832. // item.ScheduleDate = copy_startime + 172800
  3833. // }
  3834. // if item.ScheduleWeek == 4 {
  3835. // item.ScheduleDate = copy_startime + 259200
  3836. // }
  3837. // if item.ScheduleWeek == 5 {
  3838. // item.ScheduleDate = copy_startime + 345600
  3839. // }
  3840. //
  3841. // if item.ScheduleWeek == 6 {
  3842. // item.ScheduleDate = copy_startime + 432000
  3843. // }
  3844. // //礼拜天
  3845. // if item.ScheduleWeek == 0 {
  3846. // item.ScheduleDate = copy_endtime
  3847. // }
  3848. // schedule := models.XtSchedule{
  3849. // UserOrgId: item.UserOrgId,
  3850. // PartitionId: item.PartitionId,
  3851. // BedId: item.BedId,
  3852. // PatientId: item.PatientId,
  3853. // ScheduleDate: item.ScheduleDate,
  3854. // ScheduleType: item.ScheduleType,
  3855. // ScheduleWeek: item.ScheduleWeek,
  3856. // ModeId: item.ModeId,
  3857. // Status: 1,
  3858. // CreatedTime: time.Now().Unix(),
  3859. // }
  3860. //
  3861. // err := service.AddPatientSchedule(&schedule)
  3862. // if err != nil {
  3863. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3864. // return
  3865. // }
  3866. // this.ServeSuccessJSON(map[string]interface{}{
  3867. // "schedule": schedule,
  3868. // })
  3869. // }
  3870. //}
  3871. }
  3872. func (this *ScheduleApiController) SaveRemindPrint() {
  3873. id, _ := this.GetInt64("id")
  3874. anticoagulants, _ := this.GetInt64("anticoagulant")
  3875. anticoagulant_zongliang, _ := this.GetInt64("anticoagulant_zongliang")
  3876. classes, _ := this.GetInt64("classes")
  3877. dialyzers, _ := this.GetInt64("dialyzers")
  3878. doctor_advice, _ := this.GetInt64("doctor_advice")
  3879. mode, _ := this.GetInt64("mode")
  3880. name, _ := this.GetInt64("name")
  3881. number, _ := this.GetInt64("number")
  3882. perfusion_apparatus, _ := this.GetInt64("perfusion_apparatus")
  3883. prescription_status, _ := this.GetInt64("prescription_status")
  3884. week, _ := this.GetInt64("week")
  3885. zone, _ := this.GetInt64("zone")
  3886. adminUserInfo := this.GetAdminUserInfo()
  3887. orgId := adminUserInfo.CurrentOrgId
  3888. setting := models.XtRemindPrintSetting{
  3889. Anticoagulant: anticoagulants,
  3890. Classes: classes,
  3891. AnticoagulantZongliang: anticoagulant_zongliang,
  3892. Dialyzers: dialyzers,
  3893. DoctorAdvice: doctor_advice,
  3894. Mode: mode,
  3895. Name: name,
  3896. Number: number,
  3897. PerfusionApparatus: perfusion_apparatus,
  3898. PrescriptionStatus: prescription_status,
  3899. Week: week,
  3900. Zone: zone,
  3901. UserOrgId: orgId,
  3902. Status: 1,
  3903. Ctime: time.Now().Unix(),
  3904. }
  3905. _, errcode := service.GetSettingById(id)
  3906. if errcode == gorm.ErrRecordNotFound {
  3907. err := service.CreateSetting(&setting)
  3908. if err != nil {
  3909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3910. return
  3911. }
  3912. this.ServeSuccessJSON(map[string]interface{}{
  3913. "setting": setting,
  3914. })
  3915. } else if errcode == nil {
  3916. err := service.UpdatedRemindPrint(&setting, id)
  3917. if err != nil {
  3918. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3919. return
  3920. }
  3921. this.ServeSuccessJSON(map[string]interface{}{
  3922. "setting": setting,
  3923. })
  3924. }
  3925. }
  3926. func (this *ScheduleApiController) GetRemindPrintList() {
  3927. adminUserInfo := this.GetAdminUserInfo()
  3928. orgId := adminUserInfo.CurrentOrgId
  3929. list, err := service.GetRemindPrintList(orgId)
  3930. if err != nil {
  3931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3932. return
  3933. }
  3934. this.ServeSuccessJSON(map[string]interface{}{
  3935. "list": list,
  3936. })
  3937. }
  3938. func (this *ScheduleApiController) GetBloodScheduleList() {
  3939. week_type, _ := this.GetInt64("week_type", -1)
  3940. week_time, _ := this.GetInt64("week_time")
  3941. zones := this.GetString("zone")
  3942. zone := strings.Split(zones, ",")
  3943. limit, _ := this.GetInt64("limit")
  3944. page, _ := this.GetInt64("page")
  3945. ids := this.GetString("ids")
  3946. var idStr []string
  3947. if len(ids) > 0 {
  3948. idStr = strings.Split(ids, ",")
  3949. }
  3950. thisTime := time.Now()
  3951. weekDay := int(thisTime.Weekday())
  3952. if weekDay == 0 {
  3953. weekDay = 7
  3954. }
  3955. weekEnd := 7 - weekDay
  3956. weekStart := weekEnd - 6
  3957. weekTitle := make([]string, 0)
  3958. days := make([]string, 0)
  3959. for index := weekStart; index <= weekEnd; index++ {
  3960. theDay := thisTime.AddDate(0, 0, index)
  3961. indexYear, indexMonthTime, indexDay := theDay.Date()
  3962. indexMonth := int(indexMonthTime)
  3963. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  3964. weekTitle = append(weekTitle, indexWeek)
  3965. days = append(days, theDay.Format("2006-01-02"))
  3966. }
  3967. var targetDayStr string
  3968. var startTime string
  3969. switch week_type {
  3970. case 0:
  3971. startTime = days[0]
  3972. targetDayStr = days[6]
  3973. break
  3974. case 1:
  3975. targetDayStr = days[0]
  3976. break
  3977. case 2:
  3978. targetDayStr = days[1]
  3979. break
  3980. case 3:
  3981. targetDayStr = days[2]
  3982. break
  3983. case 4:
  3984. targetDayStr = days[3]
  3985. break
  3986. case 5:
  3987. targetDayStr = days[4]
  3988. break
  3989. case 6:
  3990. targetDayStr = days[5]
  3991. break
  3992. case 7:
  3993. targetDayStr = days[6]
  3994. break
  3995. }
  3996. targetDay, parseErr := utils.ParseTimeStringToTime("2006-01-02", targetDayStr)
  3997. if parseErr != nil {
  3998. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3999. return
  4000. }
  4001. orgId := this.GetAdminUserInfo().CurrentOrgId
  4002. if week_type > 0 {
  4003. list, total, err := service.GetWeekDayScheduleByIdThee(orgId, targetDay.Unix(), week_time, zone, limit, page, idStr)
  4004. for _, item := range list {
  4005. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  4006. item.XtDialysisOrderSix = order
  4007. advicehisList, _ := service.GetHisDoctorAdviceList(orgId, item.PatientId, targetDay.Unix())
  4008. item.HisDoctorAdviceInfo = advicehisList
  4009. advices, _ := service.GetDoctorAdviceListSchedule(orgId, item.PatientId)
  4010. item.DoctorAdvice = advices
  4011. prescription, _ := service.GetLastDialysisPrescriptionTwo(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  4012. item.DialysisPrescription = prescription
  4013. dialysisSolution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId)
  4014. item.DialysisSolution = dialysisSolution
  4015. lastDialysisAfter, _ := service.GetLastDialysisAfter(orgId, item.PatientId, item.ScheduleDate)
  4016. item.LastAfterWeight = lastDialysisAfter
  4017. assessmentBeforFourty, _ := service.GetAssessmentBeforFourty(orgId, item.PatientId, item.ScheduleDate)
  4018. item.XtAssessmentBeforeDislysis = assessmentBeforFourty
  4019. templateList, _ := service.GetHisPrescriptionTemplateList(orgId, item.PatientId, item.ModeId)
  4020. item.HisPrescriptionTemplate = templateList
  4021. }
  4022. if err != nil {
  4023. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4024. return
  4025. }
  4026. this.ServeSuccessJSON(map[string]interface{}{
  4027. "list": list,
  4028. "day": targetDayStr,
  4029. "total": total,
  4030. })
  4031. }
  4032. if week_type == 0 {
  4033. startDate, _ := utils.ParseTimeStringToTime("2006-01-02", startTime)
  4034. list, total, err := service.GetWeekDayScheduleByIdTwo(orgId, targetDay.Unix(), week_time, startDate.Unix(), zone, limit, page, idStr)
  4035. for _, item := range list {
  4036. order, _ := service.GetLastDialysisOrder(orgId, item.PatientId, targetDay.Unix())
  4037. item.XtDialysisOrderSix = order
  4038. advicehisList, _ := service.GetHisDoctorAdviceList(orgId, item.PatientId, targetDay.Unix())
  4039. item.HisDoctorAdviceInfo = advicehisList
  4040. advices, _ := service.GetDoctorAdviceListSchedule(orgId, item.PatientId)
  4041. item.DoctorAdvice = advices
  4042. prescription, _ := service.GetLastDialysisPrescriptionTwo(orgId, item.PatientId, item.ModeId, item.ScheduleDate)
  4043. item.DialysisPrescription = prescription
  4044. dialysisSolution, _ := service.GetLastDialysisSolution(orgId, item.PatientId, item.ModeId)
  4045. item.DialysisSolution = dialysisSolution
  4046. lastDialysisAfter, _ := service.GetLastDialysisAfter(orgId, item.PatientId, item.ScheduleDate)
  4047. item.LastAfterWeight = lastDialysisAfter
  4048. assessmentBeforFourty, _ := service.GetAssessmentBeforFourty(orgId, item.PatientId, item.ScheduleDate)
  4049. item.XtAssessmentBeforeDislysis = assessmentBeforFourty
  4050. templateList, _ := service.GetHisPrescriptionTemplateList(orgId, item.PatientId, item.ModeId)
  4051. item.HisPrescriptionTemplate = templateList
  4052. }
  4053. if err != nil {
  4054. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4055. return
  4056. }
  4057. this.ServeSuccessJSON(map[string]interface{}{
  4058. "list": list,
  4059. "day": targetDayStr,
  4060. "total": total,
  4061. })
  4062. }
  4063. }
  4064. func (this *ScheduleApiController) GetPrintList() {
  4065. adminUserInfo := this.GetAdminUserInfo()
  4066. orgId := adminUserInfo.CurrentOrgId
  4067. list, err := service.GetRemindPrintList(orgId)
  4068. if err != nil {
  4069. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4070. return
  4071. }
  4072. this.ServeSuccessJSON(map[string]interface{}{
  4073. "list": list,
  4074. })
  4075. }
  4076. func (this *ScheduleApiController) GetAllZoneList() {
  4077. adminUserInfo := this.GetAdminUserInfo()
  4078. orgId := adminUserInfo.CurrentOrgId
  4079. zoneList, err := service.GetAllZoneOne(orgId)
  4080. if err != nil {
  4081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4082. return
  4083. }
  4084. this.ServeSuccessJSON(map[string]interface{}{
  4085. "zoneList": zoneList,
  4086. })
  4087. }
  4088. func (this *ScheduleApiController) GetPatientScheduleCount() {
  4089. patitionIdStr := this.GetString("partition_id")
  4090. week, _ := this.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4091. ids := strings.Split(patitionIdStr, ",")
  4092. adminUserInfo := this.GetAdminUserInfo()
  4093. orgId := adminUserInfo.CurrentOrgId
  4094. thisTime := time.Now()
  4095. weekDay := int(thisTime.Weekday())
  4096. if week < 1 || week > 4 {
  4097. week = 2
  4098. }
  4099. if week == 1 {
  4100. thisTime = thisTime.AddDate(0, 0, -7)
  4101. } else if week == 3 {
  4102. thisTime = thisTime.AddDate(0, 0, 7)
  4103. } else if week == 4 {
  4104. thisTime = thisTime.AddDate(0, 0, 14)
  4105. }
  4106. if weekDay == 0 {
  4107. weekDay = 7
  4108. }
  4109. weekEnd := 7 - weekDay
  4110. weekStart := weekEnd - 6
  4111. weekTitle := make([]string, 0)
  4112. days := make([]string, 0)
  4113. for index := weekStart; index <= weekEnd; index++ {
  4114. theDay := thisTime.AddDate(0, 0, index)
  4115. indexYear, indexMonthTime, indexDay := theDay.Date()
  4116. indexMonth := int(indexMonthTime)
  4117. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4118. weekTitle = append(weekTitle, indexWeek)
  4119. days = append(days, theDay.Format("2006-01-02"))
  4120. }
  4121. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4122. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4123. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4124. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4125. timeLayout := "2006-01-02 15:04:05"
  4126. loc, _ := time.LoadLocation("Local")
  4127. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4128. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4129. weekStartPoint := theStarTime.Unix()
  4130. weekEndPoint := theEndTime.Unix()
  4131. list, err := service.GetPatientScheduleCount(orgId, weekStartPoint, weekEndPoint, ids)
  4132. _, total, _ := service.GetTotalBedNumber(orgId, ids)
  4133. if err != nil {
  4134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4135. return
  4136. }
  4137. this.ServeSuccessJSON(map[string]interface{}{
  4138. "list": list,
  4139. "total": total,
  4140. })
  4141. }
  4142. func (c *ScheduleApiController) GetWeekPanelsOne() {
  4143. data, _ := c.GetInt64("data", 1)
  4144. patitionIdStr := c.GetString("patitionid")
  4145. ids := strings.Split(patitionIdStr, ",")
  4146. adminInfo := c.GetAdminUserInfo()
  4147. thisTime := time.Now()
  4148. year, monthTime, day := thisTime.Date()
  4149. month := int(monthTime)
  4150. _, theWeek := thisTime.ISOWeek()
  4151. weekDay := int(thisTime.Weekday())
  4152. if weekDay == 0 {
  4153. weekDay = 7
  4154. }
  4155. weekEnd := 7 - weekDay
  4156. weekStart := weekEnd - 6
  4157. weekDays := make([]string, 0)
  4158. for index := weekStart; index <= weekEnd; index++ {
  4159. theDay := thisTime.AddDate(0, 0, index)
  4160. indexYear, indexMonthTime, indexDay := theDay.Date()
  4161. indexMonth := int(indexMonthTime)
  4162. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4163. weekDays = append(weekDays, indexWeek)
  4164. }
  4165. returnData := map[string]interface{}{
  4166. "year": year,
  4167. "month": month,
  4168. "day": day,
  4169. "theWeek": theWeek,
  4170. "weekDay": weekDay,
  4171. "weekDays": weekDays,
  4172. }
  4173. if data == 1 {
  4174. partitions, _ := service.GetSchedulePartitionPanelTwo(adminInfo.CurrentOrgId, ids)
  4175. returnData["partitions"] = partitions
  4176. }
  4177. c.ServeSuccessJSON(returnData)
  4178. return
  4179. }
  4180. func (c *ScheduleApiController) GetScheduleOne() {
  4181. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4182. patitionIdStr := c.GetString("patitionid")
  4183. ids := strings.Split(patitionIdStr, ",")
  4184. //fmt.Println("patitonStr", ids)
  4185. schedule_type, _ := c.GetInt64("schedule_type")
  4186. is_before, _ := c.GetInt64("is_before")
  4187. start_time := c.GetString("start_time")
  4188. end_time := c.GetString("end_time")
  4189. adminInfo := c.GetAdminUserInfo()
  4190. thisTime := time.Now()
  4191. today := thisTime.Format("2006-01-02")
  4192. if week < 1 || week > 4 {
  4193. week = 2
  4194. }
  4195. if week == 1 {
  4196. thisTime = thisTime.AddDate(0, 0, -7)
  4197. } else if week == 3 {
  4198. thisTime = thisTime.AddDate(0, 0, 7)
  4199. } else if week == 4 {
  4200. thisTime = thisTime.AddDate(0, 0, 14)
  4201. }
  4202. weekDay := int(thisTime.Weekday())
  4203. if weekDay == 0 {
  4204. weekDay = 7
  4205. }
  4206. weekEnd := 7 - weekDay
  4207. weekStart := weekEnd - 6
  4208. weekTitle := make([]string, 0)
  4209. days := make([]string, 0)
  4210. for index := weekStart; index <= weekEnd; index++ {
  4211. theDay := thisTime.AddDate(0, 0, index)
  4212. indexYear, indexMonthTime, indexDay := theDay.Date()
  4213. indexMonth := int(indexMonthTime)
  4214. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4215. weekTitle = append(weekTitle, indexWeek)
  4216. days = append(days, theDay.Format("2006-01-02"))
  4217. }
  4218. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4219. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4220. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4221. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4222. timeLayout := "2006-01-02 15:04:05"
  4223. loc, _ := time.LoadLocation("Local")
  4224. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4225. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4226. weekStartPoint := theStarTime.Unix()
  4227. weekEndPoint := theEndTime.Unix()
  4228. if is_before > 0 {
  4229. timeLayout := "2006-01-02 15:04:05"
  4230. loc, _ := time.LoadLocation("Local")
  4231. theStarTime, _ := time.ParseInLocation(timeLayout, start_time, loc)
  4232. theEndTime, _ := time.ParseInLocation(timeLayout, end_time, loc)
  4233. weekStartPoint = theStarTime.Unix()
  4234. weekEndPoint = theEndTime.Unix()
  4235. }
  4236. schdules, _ := service.GetWeekScheduleTwo(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  4237. timenow := time.Now().Format("2006-01-02")
  4238. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timenow)
  4239. if adminInfo.CurrentOrgId == 10346 || adminInfo.CurrentOrgId == 10585 || adminInfo.CurrentOrgId == 10495 {
  4240. if len(schdules) > 0 {
  4241. //获取长期医嘱里面的透析器灌流器
  4242. for _, item := range schdules {
  4243. if item.ScheduleDate >= timeNewDate.Unix() {
  4244. solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
  4245. service.UpdateScheduleByDialysis(item.PatientId, item.ModeId, item.ScheduleDate, item.UserOrgId, solution.DialyzerPerfusionApparatus, item.ScheduleType)
  4246. }
  4247. }
  4248. }
  4249. }
  4250. //查询排班里面的空透析器
  4251. if adminInfo.CurrentOrgId == 10375 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 9538 {
  4252. schedulesFive, _ := service.GetWeekScheduleFive(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  4253. for _, item := range schedulesFive {
  4254. if item.ScheduleDate >= timeNewDate.Unix() {
  4255. solution, _ := service.GetLongSolutionByModeId(item.PatientId, item.ModeId, item.UserOrgId)
  4256. var DialysisMachineName string
  4257. if len(solution.DialysisDialyszers) > 0 {
  4258. DialysisMachineName = solution.DialysisDialyszers
  4259. }
  4260. if len(solution.DialyzerPerfusionApparatus) > 0 {
  4261. DialysisMachineName = DialysisMachineName + "," + solution.DialyzerPerfusionApparatus
  4262. }
  4263. if len(solution.DialysisIrrigation) > 0 {
  4264. DialysisMachineName = DialysisMachineName + "," + solution.DialysisIrrigation
  4265. }
  4266. item.DialysisMachineName = DialysisMachineName
  4267. service.UpdateSchOne(item.ID, item.DialysisMachineName)
  4268. }
  4269. if item.ScheduleDate < timeNewDate.Unix() {
  4270. prescriptionList, _ := service.GetDialysisPrescriptionList(item.PatientId, item.UserOrgId, item.ScheduleDate)
  4271. var DialysisMachineName string
  4272. if len(prescriptionList.DialysisDialyszers) > 0 {
  4273. DialysisMachineName = prescriptionList.DialysisDialyszers
  4274. }
  4275. if len(prescriptionList.DialyzerPerfusionApparatus) > 0 {
  4276. DialysisMachineName = DialysisMachineName + "," + prescriptionList.DialyzerPerfusionApparatus
  4277. }
  4278. if len(prescriptionList.DialysisIrrigation) > 0 {
  4279. DialysisMachineName = DialysisMachineName + "," + prescriptionList.DialysisIrrigation
  4280. }
  4281. item.DialysisMachineName = DialysisMachineName
  4282. service.UpdateSchOne(item.ID, item.DialysisMachineName)
  4283. }
  4284. }
  4285. }
  4286. schedulesGroup, _ := service.GetScheduleTotalCount(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type)
  4287. c.ServeSuccessJSON(map[string]interface{}{
  4288. "days": days,
  4289. "weekTitle": weekTitle,
  4290. "schdules": schdules,
  4291. "today": today,
  4292. "schedulesGroup": schedulesGroup,
  4293. })
  4294. return
  4295. }
  4296. func (c *ScheduleApiController) GetScheduleTwo() {
  4297. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4298. patitionIdStr := c.GetString("patitionid")
  4299. ids := strings.Split(patitionIdStr, ",")
  4300. schedule_type, _ := c.GetInt64("schedule_type")
  4301. adminInfo := c.GetAdminUserInfo()
  4302. weekDateStr := c.GetString("week_date")
  4303. WeekDayIds := strings.Split(weekDateStr, ",")
  4304. thisTime := time.Now()
  4305. today := thisTime.Format("2006-01-02")
  4306. if week < 1 || week > 4 {
  4307. week = 2
  4308. }
  4309. if week == 1 {
  4310. thisTime = thisTime.AddDate(0, 0, -7)
  4311. } else if week == 3 {
  4312. thisTime = thisTime.AddDate(0, 0, 7)
  4313. } else if week == 4 {
  4314. thisTime = thisTime.AddDate(0, 0, 14)
  4315. }
  4316. weekDay := int(thisTime.Weekday())
  4317. if weekDay == 0 {
  4318. weekDay = 7
  4319. }
  4320. weekEnd := 7 - weekDay
  4321. weekStart := weekEnd - 6
  4322. weekTitle := make([]string, 0)
  4323. days := make([]string, 0)
  4324. for index := weekStart; index <= weekEnd; index++ {
  4325. theDay := thisTime.AddDate(0, 0, index)
  4326. indexYear, indexMonthTime, indexDay := theDay.Date()
  4327. indexMonth := int(indexMonthTime)
  4328. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4329. weekTitle = append(weekTitle, indexWeek)
  4330. days = append(days, theDay.Format("2006-01-02"))
  4331. }
  4332. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4333. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4334. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4335. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4336. timeLayout := "2006-01-02 15:04:05"
  4337. loc, _ := time.LoadLocation("Local")
  4338. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4339. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4340. weekStartPoint := theStarTime.Unix()
  4341. weekEndPoint := theEndTime.Unix()
  4342. schdules, _ := service.GetWeekScheduleThree(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  4343. c.ServeSuccessJSON(map[string]interface{}{
  4344. "days": days,
  4345. "weekTitle": weekTitle,
  4346. "schdules": schdules,
  4347. "today": today,
  4348. })
  4349. return
  4350. }
  4351. func (c *ScheduleApiController) GetScheduleThreeList() {
  4352. week, _ := c.GetInt64("weekTime", 0) //1:last, 2:this 3:next 4 nextTwo
  4353. patitionIdStr := c.GetString("patitionid")
  4354. ids := strings.Split(patitionIdStr, ",")
  4355. schedule_type, _ := c.GetInt64("schedule_type")
  4356. adminInfo := c.GetAdminUserInfo()
  4357. weekDateStr := c.GetString("week_date")
  4358. WeekDayIds := strings.Split(weekDateStr, ",")
  4359. thisTime := time.Now()
  4360. today := thisTime.Format("2006-01-02")
  4361. if week < 1 || week > 4 {
  4362. week = 2
  4363. }
  4364. if week == 1 {
  4365. thisTime = thisTime.AddDate(0, 0, -7)
  4366. } else if week == 3 {
  4367. thisTime = thisTime.AddDate(0, 0, 7)
  4368. } else if week == 4 {
  4369. thisTime = thisTime.AddDate(0, 0, 14)
  4370. }
  4371. weekDay := int(thisTime.Weekday())
  4372. if weekDay == 0 {
  4373. weekDay = 7
  4374. }
  4375. weekEnd := 7 - weekDay
  4376. weekStart := weekEnd - 6
  4377. weekTitle := make([]string, 0)
  4378. days := make([]string, 0)
  4379. for index := weekStart; index <= weekEnd; index++ {
  4380. theDay := thisTime.AddDate(0, 0, index)
  4381. indexYear, indexMonthTime, indexDay := theDay.Date()
  4382. indexMonth := int(indexMonthTime)
  4383. indexWeek := strconv.Itoa(indexYear) + "." + strconv.Itoa(indexMonth) + "." + strconv.Itoa(indexDay)
  4384. weekTitle = append(weekTitle, indexWeek)
  4385. days = append(days, theDay.Format("2006-01-02"))
  4386. }
  4387. weekStartDay := thisTime.AddDate(0, 0, weekStart)
  4388. weekEndDay := thisTime.AddDate(0, 0, weekEnd)
  4389. weekStartTime := weekStartDay.Format("2006-01-02") + " 00:00:00"
  4390. weekEndTime := weekEndDay.Format("2006-01-02") + " 23:59:59"
  4391. timeLayout := "2006-01-02 15:04:05"
  4392. loc, _ := time.LoadLocation("Local")
  4393. theStarTime, _ := time.ParseInLocation(timeLayout, weekStartTime, loc)
  4394. theEndTime, _ := time.ParseInLocation(timeLayout, weekEndTime, loc)
  4395. weekStartPoint := theStarTime.Unix()
  4396. weekEndPoint := theEndTime.Unix()
  4397. schdules, _ := service.GetWeekScheduleFour(adminInfo.CurrentOrgId, weekStartPoint, weekEndPoint, ids, schedule_type, WeekDayIds)
  4398. if len(schdules) > 0 {
  4399. for _, item := range schdules {
  4400. listObj, _ := service.GetNextScheduleByList(item.PatientId, item.ScheduleDate, item.UserOrgId)
  4401. item.SchedulePatientsOne = listObj
  4402. }
  4403. }
  4404. c.ServeSuccessJSON(map[string]interface{}{
  4405. "days": days,
  4406. "weekTitle": weekTitle,
  4407. "schdules": schdules,
  4408. "today": today,
  4409. })
  4410. return
  4411. }
  4412. func (c *ScheduleApiController) SaveScheduleTemplate() {
  4413. template_id, _ := c.GetInt64("template_id")
  4414. orgId := c.GetAdminUserInfo().CurrentOrgId
  4415. template := models.ScheduleTemplate{
  4416. TemplateId: template_id,
  4417. UserOrgId: orgId,
  4418. Status: 1,
  4419. Ctime: time.Now().Unix(),
  4420. }
  4421. _, errcodes := service.GetScheudleTemplateById(orgId)
  4422. if errcodes == gorm.ErrRecordNotFound {
  4423. service.CreateXtscheduleTemplate(&template)
  4424. } else if errcodes == nil {
  4425. service.UpdateXtScheduleTemplate(&template, orgId)
  4426. }
  4427. c.ServeSuccessJSON(map[string]interface{}{
  4428. "template": template,
  4429. })
  4430. return
  4431. }
  4432. func (c *ScheduleApiController) GetScheduleTemplate() {
  4433. adminUserInfo := c.GetAdminUserInfo()
  4434. orgId := adminUserInfo.CurrentOrgId
  4435. template, _ := service.GetScheduleTemplate(orgId)
  4436. c.ServeSuccessJSON(map[string]interface{}{
  4437. "template": template,
  4438. })
  4439. return
  4440. }
  4441. func (c *ScheduleApiController) ChangeFuncPrint() {
  4442. adminUserInfo := c.GetAdminUserInfo()
  4443. orgId := adminUserInfo.CurrentOrgId
  4444. is_open, _ := c.GetInt64("is_open")
  4445. dataPrint := models.XtDataPrint{
  4446. UserOrgId: orgId,
  4447. IsOpen: is_open,
  4448. Status: 1,
  4449. Ctime: time.Now().Unix(),
  4450. }
  4451. _, errcode := service.GetDataPrintByOrgId(orgId)
  4452. if errcode == gorm.ErrRecordNotFound {
  4453. service.CreateDataPrint(&dataPrint)
  4454. c.ServeSuccessJSON(map[string]interface{}{
  4455. "dataPrint": dataPrint,
  4456. })
  4457. return
  4458. } else if errcode == nil {
  4459. service.UpdteDataPrint(orgId, &dataPrint)
  4460. c.ServeSuccessJSON(map[string]interface{}{
  4461. "dataPrint": dataPrint,
  4462. })
  4463. return
  4464. }
  4465. }
  4466. func (c *ScheduleApiController) GetDataPrint() {
  4467. adminUserInfo := c.GetAdminUserInfo()
  4468. orgId := adminUserInfo.CurrentOrgId
  4469. dataPrint, _ := service.GetDataPrint(orgId)
  4470. c.ServeSuccessJSON(map[string]interface{}{
  4471. "dataPrint": dataPrint,
  4472. })
  4473. return
  4474. }
  4475. func (c *ScheduleApiController) GetNextWeekPanels() {
  4476. start_time, _ := c.GetInt64("start_time")
  4477. fmt.Println("start_time", start_time)
  4478. end_time, _ := c.GetInt64("end_time")
  4479. fmt.Println("end_time", end_time)
  4480. orgId := c.GetAdminUserInfo().CurrentOrgId
  4481. schedule, _ := service.GetNextWeekPanels(start_time, end_time, orgId)
  4482. c.ServeSuccessJSON(map[string]interface{}{
  4483. "schedule": schedule,
  4484. })
  4485. }
  4486. func (c *ScheduleApiController) SynchroSchedule() {
  4487. template_id, _ := c.GetInt64("template_id")
  4488. copy_startime, _ := c.GetInt64("copy_startime")
  4489. copy_endtime, _ := c.GetInt64("copy_endtime")
  4490. orgId := c.GetAdminUserInfo().CurrentOrgId
  4491. //根据模板ID获取模板数据
  4492. list, _ := service.GetTemplateListByTemplateId(template_id, orgId)
  4493. fmt.Println(len(list))
  4494. //数据去重操作
  4495. list = RemoveRepeatedScheduleTemplate(list)
  4496. recordDateStr := time.Now().Format("2006-01-02")
  4497. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4498. nowtime := recordDate.Unix()
  4499. fmt.Println("今日时间", nowtime)
  4500. fmt.Println("后期日期", copy_startime)
  4501. var tuesday int64
  4502. var wednesday int64
  4503. var thursday int64
  4504. var friday int64
  4505. var saturday int64
  4506. //
  4507. //如果选择的开始日期大于当前日期
  4508. if copy_startime > nowtime {
  4509. //清空该时间段的所有排班数据
  4510. service.DeletePatientSchedule(copy_startime, copy_endtime, orgId)
  4511. tuesday = copy_startime + 86400
  4512. wednesday = copy_startime + 172800
  4513. thursday = copy_startime + 259200
  4514. friday = copy_startime + 345600
  4515. saturday = copy_startime + 432000
  4516. for _, item := range list {
  4517. if item.Weekday == 1 {
  4518. item.ScheduleDate = copy_startime
  4519. }
  4520. if item.Weekday == 2 {
  4521. item.ScheduleDate = tuesday
  4522. }
  4523. if item.Weekday == 3 {
  4524. item.ScheduleDate = wednesday
  4525. }
  4526. if item.Weekday == 4 {
  4527. item.ScheduleDate = thursday
  4528. }
  4529. if item.Weekday == 5 {
  4530. item.ScheduleDate = friday
  4531. }
  4532. if item.Weekday == 6 {
  4533. item.ScheduleDate = saturday
  4534. }
  4535. if item.Weekday == 7 {
  4536. item.ScheduleDate = copy_endtime
  4537. }
  4538. //根据床位号获取区号
  4539. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  4540. item.ZoneId = number.ZoneID
  4541. }
  4542. for _, item := range list {
  4543. schedule := models.XtSchedule{
  4544. UserOrgId: orgId,
  4545. PartitionId: item.ZoneId,
  4546. BedId: item.DeviceNumberID,
  4547. PatientId: item.PatientID,
  4548. ScheduleDate: item.ScheduleDate,
  4549. ScheduleType: item.TimeType,
  4550. ScheduleWeek: item.Weekday,
  4551. ModeId: item.TreatMode,
  4552. Status: 1,
  4553. CreatedTime: time.Now().Unix(),
  4554. UpdatedTime: 0,
  4555. IsExport: 200000,
  4556. }
  4557. var DialysisMachineName string
  4558. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  4559. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  4560. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  4561. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  4562. if filedRecordOne.IsShow == 1 {
  4563. DialysisMachineName = so.DialysisDialyszers
  4564. }
  4565. if filedRecordThree.IsShow == 1 {
  4566. if len(DialysisMachineName) > 0 {
  4567. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  4568. } else {
  4569. DialysisMachineName = so.DialyzerPerfusionApparatus
  4570. }
  4571. }
  4572. if filedRecordTwo.IsShow == 1 {
  4573. if len(DialysisMachineName) > 0 {
  4574. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  4575. } else {
  4576. DialysisMachineName = so.DialysisIrrigation
  4577. }
  4578. }
  4579. schedule.DialysisMachineName = DialysisMachineName
  4580. service.CreatePatientSchedule(&schedule)
  4581. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  4582. }
  4583. }
  4584. //如果选择的日期小于当前日期,只同步今日以后的数据
  4585. if copy_startime <= nowtime {
  4586. //清空今日以后的数据
  4587. service.DeletePatientScheduleToday(nowtime, copy_endtime, orgId)
  4588. var tuesday int64
  4589. var wednesday int64
  4590. var thursday int64
  4591. var friday int64
  4592. var saturday int64
  4593. tuesday = copy_startime + 86400
  4594. wednesday = copy_startime + 172800
  4595. thursday = copy_startime + 259200
  4596. friday = copy_startime + 345600
  4597. saturday = copy_startime + 432000
  4598. for _, item := range list {
  4599. if item.Weekday == 1 {
  4600. item.ScheduleDate = copy_startime
  4601. }
  4602. if item.Weekday == 2 {
  4603. item.ScheduleDate = tuesday
  4604. }
  4605. if item.Weekday == 3 {
  4606. item.ScheduleDate = wednesday
  4607. }
  4608. if item.Weekday == 4 {
  4609. item.ScheduleDate = thursday
  4610. }
  4611. if item.Weekday == 5 {
  4612. item.ScheduleDate = friday
  4613. }
  4614. if item.Weekday == 6 {
  4615. item.ScheduleDate = saturday
  4616. }
  4617. if item.Weekday == 7 {
  4618. item.ScheduleDate = copy_endtime
  4619. }
  4620. //根据床位号获取区号
  4621. number, _ := service.GetBedNumberById(item.DeviceNumberID, orgId)
  4622. item.ZoneId = number.ZoneID
  4623. }
  4624. for _, item := range list {
  4625. // 同步今日以后的数据
  4626. if item.ScheduleDate > nowtime {
  4627. schedule := models.XtSchedule{
  4628. UserOrgId: orgId,
  4629. PartitionId: item.ZoneId,
  4630. BedId: item.DeviceNumberID,
  4631. PatientId: item.PatientID,
  4632. ScheduleDate: item.ScheduleDate,
  4633. ScheduleType: item.TimeType,
  4634. ScheduleWeek: item.Weekday,
  4635. ModeId: item.TreatMode,
  4636. Status: 1,
  4637. CreatedTime: time.Now().Unix(),
  4638. UpdatedTime: 0,
  4639. }
  4640. var DialysisMachineName string
  4641. so, _ := service.GetDialysisSolutionTwo(c.GetAdminUserInfo().CurrentOrgId, schedule.PatientId, schedule.ModeId)
  4642. filedRecordOne, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器")
  4643. filedRecordTwo, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "灌流器")
  4644. filedRecordThree, _ := service.FindFiledBy(c.GetAdminUserInfo().CurrentOrgId, "透析器/灌流器")
  4645. if filedRecordOne.IsShow == 1 {
  4646. DialysisMachineName = so.DialysisDialyszers
  4647. }
  4648. if filedRecordThree.IsShow == 1 {
  4649. if len(DialysisMachineName) > 0 {
  4650. DialysisMachineName = DialysisMachineName + "," + so.DialyzerPerfusionApparatus
  4651. } else {
  4652. DialysisMachineName = so.DialyzerPerfusionApparatus
  4653. }
  4654. }
  4655. if filedRecordTwo.IsShow == 1 {
  4656. if len(schedule.DialysisMachineName) > 0 {
  4657. DialysisMachineName = DialysisMachineName + "," + so.DialysisIrrigation
  4658. } else {
  4659. DialysisMachineName = so.DialysisIrrigation
  4660. }
  4661. }
  4662. schedule.DialysisMachineName = DialysisMachineName
  4663. service.CreatePatientSchedule(&schedule)
  4664. }
  4665. }
  4666. }
  4667. returnData := make(map[string]interface{}, 0)
  4668. returnData["list"] = list
  4669. c.ServeSuccessJSON(returnData)
  4670. return
  4671. }
  4672. func (c *ScheduleApiController) GetPatientScheduleTempalate() {
  4673. orgId := c.GetAdminUserInfo().CurrentOrgId
  4674. tempalate, _ := service.GetPatientScheduleTempalate(orgId)
  4675. c.ServeSuccessJSON(map[string]interface{}{
  4676. "schedule": tempalate,
  4677. })
  4678. }
  4679. func (c *ScheduleApiController) GetSolutionSchedule() {
  4680. orgId := c.GetAdminUserInfo().CurrentOrgId
  4681. solution, _ := service.GetSolutionSchedule(orgId)
  4682. c.ServeSuccessJSON(map[string]interface{}{
  4683. "solution": solution,
  4684. })
  4685. return
  4686. }
  4687. func RemoveRepeatedScheduleTemplate(arr []*models.VmPatientScheduleTemplateItem) (newArr []*models.VmPatientScheduleTemplateItem) {
  4688. newArr = make([]*models.VmPatientScheduleTemplateItem, 0)
  4689. for i := 0; i < len(arr); i++ {
  4690. repeat := false
  4691. for j := i + 1; j < len(arr); j++ {
  4692. if arr[i].TemplateID == arr[j].TemplateID && arr[i].PatientID == arr[j].PatientID && arr[i].Weekday == arr[j].Weekday {
  4693. repeat = true
  4694. break
  4695. }
  4696. }
  4697. if !repeat {
  4698. newArr = append(newArr, arr[i])
  4699. }
  4700. }
  4701. return
  4702. }
  4703. func (c *ScheduleApiController) DeleteScheduleTwo() {
  4704. id, _ := c.GetInt64("id", 0)
  4705. if id <= 0 {
  4706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4707. return
  4708. }
  4709. adminINfo := c.GetAdminUserInfo()
  4710. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  4711. timeNow := time.Now().Format("2006-01-02")
  4712. timeTemplate := "2006-01-02"
  4713. tm := time.Unix(int64(schedule.ScheduleDate), 0)
  4714. timeStr := tm.Format(timeTemplate)
  4715. if timeNow > timeStr {
  4716. utils.ErrorLog(timeNow)
  4717. utils.ErrorLog(timeStr)
  4718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCantSetScheduleBeforeNow)
  4719. return
  4720. }
  4721. if schedule == nil {
  4722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  4723. return
  4724. }
  4725. order, err := service.GetOneDialysisOrder(adminINfo.CurrentOrgId, schedule.ScheduleDate, schedule.PatientId)
  4726. if err != nil {
  4727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4728. return
  4729. }
  4730. if order != nil {
  4731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDelScheduleFailByDialysisTwo)
  4732. return
  4733. }
  4734. schedule.Status = 0
  4735. schedule.UpdatedTime = time.Now().Unix()
  4736. err = service.UpdateSchedule(schedule)
  4737. if err == nil {
  4738. redis := service.RedisClient()
  4739. //处方
  4740. keyOne := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":prescriptions_list_all"
  4741. redis.Set(keyOne, "", time.Second)
  4742. //医嘱
  4743. keyTwo := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":advice_list_all"
  4744. redis.Set(keyTwo, "", time.Second)
  4745. keySix := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_befores_list_all"
  4746. redis.Set(keySix, "", time.Second)
  4747. keyThree := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":assessment_after_dislysis_list_all"
  4748. redis.Set(keyThree, "", time.Second)
  4749. keyFour := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":monitor_record_list_all"
  4750. redis.Set(keyFour, "", time.Second)
  4751. keyFive := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":treatment_summarys_list_all"
  4752. redis.Set(keyFive, "", time.Second)
  4753. keySeven := strconv.FormatInt(adminINfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(schedule.ScheduleDate, 10) + ":dialysis_orders_list_all"
  4754. redis.Set(keySeven, "", time.Second)
  4755. defer redis.Close()
  4756. if err != nil {
  4757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteScheduleFail)
  4758. return
  4759. }
  4760. c.ServeSuccessJSON(map[string]interface{}{
  4761. "msg": "ok",
  4762. "schedule": &schedule,
  4763. })
  4764. } else {
  4765. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4766. return
  4767. }
  4768. }
  4769. func (c *ScheduleApiController) ChangeScheduleTen() {
  4770. id, _ := c.GetInt64("id", 0)
  4771. bed_id, _ := c.GetInt64("bed_id")
  4772. mode_id, _ := c.GetInt64("mode_id")
  4773. schedule_type, _ := c.GetInt64("schedule_type")
  4774. if id <= 0 {
  4775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4776. return
  4777. }
  4778. adminINfo := c.GetAdminUserInfo()
  4779. schedule, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  4780. //获取分区号
  4781. number, _ := service.GetZoneId(bed_id, adminINfo.CurrentOrgId)
  4782. if schedule == nil {
  4783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeScheduleNotExist)
  4784. return
  4785. }
  4786. //如果透析模式相等 床位号相等,班次相等
  4787. if mode_id == schedule.ModeId && bed_id == schedule.BedId && schedule_type == schedule.ScheduleType && number.ZoneID == schedule.PartitionId {
  4788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorScheduleCode)
  4789. return
  4790. } else {
  4791. //如果床位未发生改变
  4792. if bed_id == schedule.BedId {
  4793. //查询该床位今天是否存在排班
  4794. sch, _ := service.GetScheduleByBedId(bed_id, schedule_type, adminINfo.CurrentOrgId, schedule.ScheduleDate)
  4795. if sch.ID == 0 {
  4796. ////删除排班
  4797. //service.UpdateScheduleByScheduleId(id)
  4798. //五四的床位
  4799. xtSchedule := models.XtSchedule{
  4800. UserOrgId: adminINfo.CurrentOrgId,
  4801. PartitionId: number.ZoneID,
  4802. BedId: bed_id,
  4803. PatientId: schedule.PatientId,
  4804. ScheduleDate: schedule.ScheduleDate,
  4805. ScheduleType: schedule_type,
  4806. ScheduleWeek: schedule.ScheduleWeek,
  4807. ModeId: mode_id,
  4808. Status: 1,
  4809. CreatedTime: time.Now().Unix(),
  4810. UpdatedTime: 0,
  4811. IsExport: 999999,
  4812. DialysisMachineName: "",
  4813. }
  4814. //service.CreateNewSchedule(xtSchedule)
  4815. service.UpdateScheduleSixTy(id, xtSchedule)
  4816. }
  4817. if schedule_type != schedule.ScheduleType && sch.ID > 0 {
  4818. //存在排班
  4819. if sch.ID > 0 {
  4820. xtSchedule := models.XtSchedule{
  4821. UserOrgId: adminINfo.CurrentOrgId,
  4822. PartitionId: number.ZoneID,
  4823. BedId: sch.BedId,
  4824. PatientId: schedule.PatientId,
  4825. ScheduleDate: sch.ScheduleDate,
  4826. ScheduleType: sch.ScheduleType,
  4827. ScheduleWeek: sch.ScheduleWeek,
  4828. ModeId: sch.ModeId,
  4829. Status: 1,
  4830. CreatedTime: time.Now().Unix(),
  4831. UpdatedTime: time.Now().Unix(),
  4832. IsExport: 8888,
  4833. DialysisMachineName: "",
  4834. }
  4835. fmt.Println("汪涵我我我哦", id)
  4836. //赵云的ID
  4837. // 该床位存在的患者
  4838. service.UpdateScheduleSixTy(id, xtSchedule)
  4839. //赵云的排班
  4840. msch := models.XtSchedule{
  4841. UserOrgId: adminINfo.CurrentOrgId,
  4842. PartitionId: schedule.PartitionId,
  4843. BedId: schedule.BedId,
  4844. PatientId: sch.PatientId,
  4845. ScheduleDate: schedule.ScheduleDate,
  4846. ScheduleType: schedule.ScheduleType,
  4847. ScheduleWeek: schedule.ScheduleWeek,
  4848. ModeId: schedule.ModeId,
  4849. IsExport: 88888,
  4850. CreatedTime: time.Now().Unix(),
  4851. UpdatedTime: time.Now().Unix(),
  4852. }
  4853. // 历史床位的患者
  4854. service.UpdateScheduleSixTy(sch.ID, msch)
  4855. }
  4856. }
  4857. }
  4858. //如果床位发生改变
  4859. if bed_id != schedule.BedId {
  4860. //查询该床位今天是否存在排班
  4861. sch, _ := service.GetScheduleByBedId(bed_id, schedule_type, adminINfo.CurrentOrgId, schedule.ScheduleDate)
  4862. if sch.ID == 0 {
  4863. ////删除排班
  4864. //service.UpdateScheduleByScheduleId(id)
  4865. //五四的床位
  4866. xtSchedule := models.XtSchedule{
  4867. UserOrgId: adminINfo.CurrentOrgId,
  4868. PartitionId: number.ZoneID,
  4869. BedId: bed_id,
  4870. PatientId: schedule.PatientId,
  4871. ScheduleDate: schedule.ScheduleDate,
  4872. ScheduleType: schedule_type,
  4873. ScheduleWeek: schedule.ScheduleWeek,
  4874. ModeId: mode_id,
  4875. Status: 1,
  4876. CreatedTime: time.Now().Unix(),
  4877. UpdatedTime: 0,
  4878. IsExport: 999999,
  4879. DialysisMachineName: "",
  4880. }
  4881. //service.CreateNewSchedule(xtSchedule)
  4882. service.UpdateScheduleSixTy(id, xtSchedule)
  4883. }
  4884. //存在排班
  4885. if sch.ID > 0 {
  4886. xtSchedule := models.XtSchedule{
  4887. UserOrgId: adminINfo.CurrentOrgId,
  4888. PartitionId: number.ZoneID,
  4889. BedId: sch.BedId,
  4890. PatientId: schedule.PatientId,
  4891. ScheduleDate: sch.ScheduleDate,
  4892. ScheduleType: sch.ScheduleType,
  4893. ScheduleWeek: sch.ScheduleWeek,
  4894. ModeId: sch.ModeId,
  4895. Status: 1,
  4896. CreatedTime: time.Now().Unix(),
  4897. UpdatedTime: time.Now().Unix(),
  4898. IsExport: 8888,
  4899. DialysisMachineName: "",
  4900. }
  4901. //赵云的ID
  4902. // 该床位存在的患者
  4903. service.UpdateScheduleSixTy(id, xtSchedule)
  4904. //赵云的排班
  4905. msch := models.XtSchedule{
  4906. UserOrgId: adminINfo.CurrentOrgId,
  4907. PartitionId: schedule.PartitionId,
  4908. BedId: schedule.BedId,
  4909. PatientId: sch.PatientId,
  4910. ScheduleDate: schedule.ScheduleDate,
  4911. ScheduleType: schedule.ScheduleType,
  4912. ScheduleWeek: schedule.ScheduleWeek,
  4913. ModeId: schedule.ModeId,
  4914. IsExport: 88888,
  4915. CreatedTime: time.Now().Unix(),
  4916. UpdatedTime: time.Now().Unix(),
  4917. }
  4918. // 历史床位的患者
  4919. service.UpdateScheduleSixTy(sch.ID, msch)
  4920. }
  4921. }
  4922. }
  4923. //去除当天患者排班中重复数据,保留最后一条数据
  4924. service.UpdateRepeatSchStatus(schedule.UserOrgId, schedule.ScheduleDate)
  4925. scheduletwo, _ := service.GetSchedule(adminINfo.CurrentOrgId, id)
  4926. c.ServeSuccessJSON(map[string]interface{}{
  4927. "msg": "ok",
  4928. "schedule": scheduletwo,
  4929. })
  4930. }
  4931. func (c *ScheduleApiController) GetNumberListById() {
  4932. id, _ := c.GetInt64("id")
  4933. orgId := c.GetAdminUserInfo().CurrentOrgId
  4934. number, _ := service.GetNumberListById(id, orgId)
  4935. c.ServeSuccessJSON(map[string]interface{}{
  4936. "number": number,
  4937. })
  4938. }