schedule_api_controller.go 164KB

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