schedule_api_controller.go 164KB

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