schedule_api_controller.go 162KB

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