schedule_api_controller.go 168KB

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