schedule_api_controller.go 171KB

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