schedule_api_controller.go 156KB

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