dialysis_api_controller.go 381KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "math"
  13. "net/http"
  14. "net/url"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  501. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  502. returnData := map[string]interface{}{
  503. "patient": patient,
  504. "schedual": schedual,
  505. "prescription": dialysisPrescribe,
  506. "solution": dialysisSolution,
  507. "last_prescription": lastDialysisPrescribe,
  508. "receiver_treatment_access": receiverTreatmentAccess,
  509. "predialysis_evaluation": predialysisEvaluation,
  510. "doctor_advices": doctorAdvices,
  511. "double_check": doubleCheck,
  512. "assessment_after_dislysis": assessmentAfterDislysis,
  513. "treatment_summary": treatmentSummary,
  514. "monitor_records": monitorRecords,
  515. "dialysis_order": dialysisOrder,
  516. "operators": operators,
  517. "last_predialysis_evaluation": lastPredialysisEvaluation,
  518. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  519. "last_monitor_record": lastMonitorRecord,
  520. "config": gobalConfig,
  521. "dry_weight": lastDryWeightDislysis,
  522. "system_prescription": systemDialysisPrescribe,
  523. "his_advices": his_advices,
  524. "is_open_config": is_open_config,
  525. "stockType": stockType,
  526. "prepare": prepare,
  527. "lastAssessment": lastAssessment,
  528. "prescribeOne": prescribeOne,
  529. "is_project_open_config": is_project_open_config,
  530. "project": projects,
  531. "team_projects": team_projects,
  532. "is_advice_open": is_advice_open,
  533. "prescription_open": prescriptionConfig.IsOpen,
  534. "lastOrder": lastOrder,
  535. "remind_lists": remind_lists,
  536. "lastDialysisPrescription": lastDialysisPrescription,
  537. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  538. "dryWeightList": dryWeightList,
  539. }
  540. this.ServeSuccessJSON(returnData)
  541. }
  542. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  543. adminInfo := c.GetMobileAdminUserInfo()
  544. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  545. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  546. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  547. returnData := map[string]interface{}{
  548. "admin_users": adminUsers,
  549. "devices": devices,
  550. "device_numbers": device_numbers,
  551. }
  552. c.ServeSuccessJSON(returnData)
  553. }
  554. func (c *DialysisAPIController) PostAtreatmentInfo() {
  555. id, _ := c.GetInt64("patient", 0)
  556. recordDateStr := c.GetString("record_date")
  557. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  558. summaryContent := c.GetString("summaryContent")
  559. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  560. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  561. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  562. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  563. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  564. nursingRecord := c.GetString("nursing_record")
  565. fmt.Println("护理记录", nursingRecord)
  566. specialRecord := c.GetString("special_record")
  567. fmt.Println("特殊记录", specialRecord)
  568. adminUserInfo := c.GetMobileAdminUserInfo()
  569. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  570. checkStaffId = adminUserInfo.AdminUser.Id
  571. deboardNurseId = adminUserInfo.AdminUser.Id
  572. treatDoctor = adminUserInfo.AdminUser.Id
  573. if id <= 0 {
  574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  575. return
  576. }
  577. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  578. if patient.ID == 0 {
  579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  580. return
  581. }
  582. if len(recordDateStr) == 0 {
  583. recordDateStr = time.Now().Format("2006-01-02")
  584. }
  585. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  586. if parseDateErr != nil {
  587. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. summary := models.TreatmentSummary{
  592. UserOrgId: adminUserInfo.Org.Id,
  593. PatientId: id,
  594. AssessmentDate: recordDate.Unix(),
  595. Mission: propagandaAndEducationContent,
  596. DialysisSummary: summaryContent,
  597. SjNurse: changeMedicalNurseId,
  598. ZlNurse: treatNurseId,
  599. HdNurse: checkStaffId,
  600. XjNurse: deboardNurseId,
  601. ZlDoctor: treatDoctor,
  602. CreatedTime: time.Now().Unix(),
  603. Status: 1,
  604. NursingRecord: nursingRecord,
  605. SpecialRecord: specialRecord,
  606. }
  607. // 查询信息规挡的设置天数
  608. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  609. if infor.ID > 0 && infor.WeekDay > 0 {
  610. var cha_time int64
  611. timeNowStr := time.Now().Format("2006-01-02")
  612. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  613. //今日的日期减去设置的日期
  614. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  615. if cha_time >= recordDate.Unix() {
  616. //查询审核是否允许
  617. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  618. //申请状态不允许的情况 拒绝修改
  619. if infor.ApplicationStatus != 1 {
  620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  621. return
  622. }
  623. }
  624. }
  625. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  626. if treatmentSummary.ID == 0 { //新增
  627. summary.Creater = adminUserInfo.AdminUser.Id
  628. service.AddSigleSummaryRecord(&summary)
  629. finish := models.XtDialysisFinish{
  630. IsFinish: 1,
  631. UserOrgId: adminUserInfo.Org.Id,
  632. Status: 1,
  633. Ctime: time.Now().Unix(),
  634. Mtime: 0,
  635. Module: 10,
  636. RecordDate: recordDate.Unix(),
  637. Sourse: 1,
  638. PatientId: id,
  639. }
  640. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  641. if dialysisFinish.ID == 0 {
  642. service.CreateDialysisFinish(finish)
  643. }
  644. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  645. redis := service.RedisClient()
  646. //清空key 值
  647. redis.Set(key, "", time.Second)
  648. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  649. redis.Set(keyOne, "", time.Second)
  650. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  651. redis.Set(keyThree, "", time.Second)
  652. defer redis.Close()
  653. c.ServeSuccessJSON(map[string]interface{}{
  654. "summary": summary,
  655. })
  656. } else { //修改
  657. summary.Creater = treatmentSummary.Creater
  658. summary.CreatedTime = treatmentSummary.CreatedTime
  659. summary.Modifier = adminUserInfo.AdminUser.Id
  660. summary.ID = treatmentSummary.ID
  661. service.UpdateSummeRecord(&summary)
  662. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  663. redis := service.RedisClient()
  664. //清空key 值
  665. redis.Set(key, "", time.Second)
  666. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  667. redis.Set(keyOne, "", time.Second)
  668. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  669. redis.Set(keyThree, "", time.Second)
  670. defer redis.Close()
  671. c.ServeSuccessJSON(map[string]interface{}{
  672. "summary": summary,
  673. })
  674. }
  675. }
  676. func (c *DialysisAPIController) PostDoubleCheck() {
  677. id, _ := c.GetInt64("patient", 0)
  678. recordDateStr := c.GetString("record_date")
  679. checkTimeStr := c.GetString("check_time")
  680. firstCheckTimeStr := c.GetString("first_check_time")
  681. creater, _ := c.GetInt64("creater", 0)
  682. modifier, _ := c.GetInt64("modifier", 0)
  683. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  684. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  685. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  686. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  687. dialysis_item_desc := c.GetString("dialysis_item_desc")
  688. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  689. vascular_access_desc := c.GetString("vascular_access_desc")
  690. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  691. collator, _ := c.GetInt64("collator", 0)
  692. employee_number := c.GetString("employee_number")
  693. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  694. needle_batch_number := c.GetString("needle_batch_number")
  695. if id <= 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  697. return
  698. }
  699. adminUserInfo := c.GetMobileAdminUserInfo()
  700. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  701. if patient.ID == 0 {
  702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  703. return
  704. }
  705. if len(recordDateStr) == 0 {
  706. recordDateStr = time.Now().Format("2006-01-02")
  707. }
  708. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  709. if parseDateErr != nil {
  710. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  712. return
  713. }
  714. var checkDate int64
  715. if len(checkTimeStr) == 0 {
  716. checkDate = 0
  717. } else {
  718. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  719. checkDate = checkDateUnix.Unix()
  720. }
  721. var firstCheckDate int64
  722. if len(firstCheckTimeStr) == 0 {
  723. firstCheckDate = 0
  724. } else {
  725. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  726. firstCheckDate = firstCheckDateUnix.Unix()
  727. }
  728. //if adminUserInfo.Org.Id == 10340 {
  729. //
  730. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  731. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  732. // if check.ID == 0 {
  733. // if employee_number != list.JobNumber {
  734. // c.ServeSuccessJSON(map[string]interface{}{
  735. // "doubleCheck": check,
  736. // "msg": "2",
  737. // })
  738. // return
  739. // }
  740. // }
  741. // if check.ID > 0 {
  742. // if employee_number != list.JobNumber {
  743. // c.ServeSuccessJSON(map[string]interface{}{
  744. // "doubleCheck": check,
  745. // "msg": "2",
  746. // })
  747. // return
  748. // }
  749. // }
  750. //
  751. //}
  752. doubleCheck := models.DoubleCheck{
  753. UserOrgId: adminUserInfo.Org.Id,
  754. PatientId: id,
  755. DialysisItemCheck: dialysis_item_check,
  756. DialysisParameterCheck: dialysis_parameter_check,
  757. VascularAccessVerification: vascular_access_verification,
  758. PipelineConnectionCheck: pipeline_connection_check,
  759. DialysisItemDesc: dialysis_item_desc,
  760. DialysisParameterDesc: dialysis_parameter_desc,
  761. VascularAccessDesc: vascular_access_desc,
  762. PipelineConnectionDesc: pipeline_connection_desc,
  763. Collator: collator,
  764. Status: 1,
  765. CreatedTime: time.Now().Unix(),
  766. CheckDate: recordDate.Unix(),
  767. UpdatedTime: time.Now().Unix(),
  768. EmployeeNumber: employee_number,
  769. DialyzerBatchNumber: dialyzer_batch_number,
  770. NeedleBatchNumber: needle_batch_number,
  771. }
  772. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  773. if check.ID == 0 { //新增
  774. doubleCheck.FirstCheckTime = firstCheckDate
  775. doubleCheck.CheckTime = checkDate
  776. doubleCheck.Creater = creater
  777. doubleCheck.Modifier = modifier
  778. if adminUserInfo.Org.Id == 10340 {
  779. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  780. doubleCheck.Creater = order.StartNurse
  781. }
  782. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  783. //查询未核对的医嘱
  784. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  785. for _, advice := range doctorList {
  786. if advice.ExecutionStaff == modifier {
  787. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  788. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  789. return
  790. }
  791. }
  792. }
  793. // 查询信息规挡的设置天数
  794. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  795. if infor.ID > 0 && infor.WeekDay > 0 {
  796. var cha_time int64
  797. timeNowStr := time.Now().Format("2006-01-02")
  798. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  799. //今日的日期减去设置的日期
  800. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  801. if cha_time >= recordDate.Unix() {
  802. //查询审核是否允许
  803. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  804. //申请状态不允许的情况 拒绝修改
  805. if infor.ApplicationStatus != 1 {
  806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  807. return
  808. }
  809. }
  810. }
  811. err := service.AddSigleDoubleCheck(&doubleCheck)
  812. finish := models.XtDialysisFinish{
  813. IsFinish: 1,
  814. UserOrgId: adminUserInfo.Org.Id,
  815. Status: 1,
  816. Ctime: time.Now().Unix(),
  817. Mtime: 0,
  818. Module: 5,
  819. RecordDate: recordDate.Unix(),
  820. Sourse: 1,
  821. PatientId: id,
  822. }
  823. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  824. if dialysisFinish.ID == 0 {
  825. service.CreateDialysisFinish(finish)
  826. }
  827. //针对长沙南雅
  828. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  829. //查询未核对的医嘱
  830. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  831. if len(doctorList) > 0 && modifier > 0 {
  832. for _, advice := range doctorList {
  833. service.UpdateDoctorAdviceList(advice.ID, modifier)
  834. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  835. redis := service.RedisClient()
  836. //清空key 值
  837. redis.Set(key, "", time.Second)
  838. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  839. redis.Set(keyTwo, "", time.Second)
  840. theTime := time.Now()
  841. recordDate := theTime.Format("2006-01-02")
  842. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  843. redis.Set(keyFour, "", time.Second)
  844. defer redis.Close()
  845. }
  846. }
  847. }
  848. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  849. redis := service.RedisClient()
  850. //清空key 值
  851. redis.Set(key, "", time.Second)
  852. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  853. redis.Set(keyOne, "", time.Second)
  854. defer redis.Close()
  855. if err == nil {
  856. c.ServeSuccessJSON(map[string]interface{}{
  857. "doubleCheck": &doubleCheck,
  858. })
  859. }
  860. } else { //修改
  861. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  862. if infor.ID > 0 {
  863. var cha_time int64
  864. timeNowStr := time.Now().Format("2006-01-02")
  865. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  866. //今日的日期减去设置的日期
  867. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  868. if cha_time >= recordDate.Unix() {
  869. //查询审核是否允许
  870. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  871. //申请状态不允许的情况 拒绝修改
  872. if infor.ApplicationStatus != 1 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  874. return
  875. }
  876. }
  877. }
  878. doubleCheck.FirstCheckTime = firstCheckDate
  879. doubleCheck.CheckTime = checkDate
  880. doubleCheck.Creater = creater
  881. doubleCheck.Modifier = modifier
  882. doubleCheck.CreatedTime = check.CreatedTime
  883. doubleCheck.ID = check.ID
  884. doubleCheck.EmployeeNumber = employee_number
  885. doubleCheck.NeedleBatchNumber = needle_batch_number
  886. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  887. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  888. //查询未核对的医嘱
  889. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  890. for _, advice := range doctorList {
  891. if advice.ExecutionStaff == modifier {
  892. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  893. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  894. return
  895. }
  896. }
  897. }
  898. err := service.UpdateDoubleCheck(&doubleCheck)
  899. //针对长沙南雅
  900. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  901. //查询未核对的医嘱
  902. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  903. if len(doctorList) > 0 && modifier > 0 {
  904. for _, advice := range doctorList {
  905. service.UpdateDoctorAdviceList(advice.ID, modifier)
  906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  907. redis := service.RedisClient()
  908. //清空key 值
  909. redis.Set(key, "", time.Second)
  910. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  911. redis.Set(keyTwo, "", time.Second)
  912. theTime := time.Now()
  913. recordDate := theTime.Format("2006-01-02")
  914. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  915. redis.Set(keyFour, "", time.Second)
  916. defer redis.Close()
  917. }
  918. }
  919. }
  920. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  921. redis := service.RedisClient()
  922. //清空key 值
  923. redis.Set(key, "", time.Second)
  924. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  925. redis.Set(keyOne, "", time.Second)
  926. defer redis.Close()
  927. if err == nil {
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "doubleCheck": &doubleCheck,
  930. "msg": "1",
  931. })
  932. }
  933. }
  934. }
  935. func (c *DialysisAPIController) PostAcceptsAssessment() {
  936. id, _ := c.GetInt64("patient", 0)
  937. recordDateStr := c.GetString("record_date")
  938. way, _ := c.GetInt64("way", 0)
  939. consciousness, _ := c.GetInt64("consciousness", 0)
  940. appetite, _ := c.GetInt64("appetite", 0)
  941. condition, _ := c.GetInt64("condition", 0)
  942. posture, _ := c.GetInt64("posture")
  943. sick_condition, _ := c.GetInt64("sick_condition", 0)
  944. danger_level, _ := c.GetInt64("danger_level", 0)
  945. intake, _ := c.GetInt64("intake", 0)
  946. nutrition, _ := c.GetInt64("nutrition", 0)
  947. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  948. psychological_assessment_other := c.GetString("psychological_assessment_other")
  949. score := c.GetString("score")
  950. sick_condition_other := c.GetString("sick_condition_other")
  951. //precaution, _ := c.GetInt64("precaution", 0)
  952. precaution := c.GetString("precaution")
  953. precaution_other := c.GetString("precaution_other")
  954. psychological_other := c.GetString("psychological_other")
  955. admission_number := c.GetString("admission_number")
  956. tumble, _ := c.GetInt64("tumble")
  957. diacrisis := c.GetString("diacrisis")
  958. his_department := c.GetString("his_department")
  959. his_bed := c.GetString("his_bed")
  960. if id <= 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  962. return
  963. }
  964. adminUserInfo := c.GetMobileAdminUserInfo()
  965. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  966. if patient.ID == 0 {
  967. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  968. return
  969. }
  970. //now := time.Now()
  971. //year, month, day := now.Date()
  972. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  973. //todayTimeStamp := today_time.Unix()
  974. if len(recordDateStr) == 0 {
  975. recordDateStr = time.Now().Format("2006-01-02")
  976. }
  977. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  978. if parseDateErr != nil {
  979. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  981. return
  982. }
  983. // 查询信息规挡的设置天数
  984. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  985. if infor.ID > 0 && infor.WeekDay > 0 {
  986. var cha_time int64
  987. timeNowStr := time.Now().Format("2006-01-02")
  988. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  989. //今日的日期减去设置的日期
  990. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  991. if cha_time >= recordDate.Unix() {
  992. //查询审核是否允许
  993. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  994. //申请状态不允许的情况 拒绝修改
  995. if infor.ApplicationStatus != 1 {
  996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  997. return
  998. }
  999. }
  1000. }
  1001. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1002. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1003. UserOrgId: adminUserInfo.Org.Id,
  1004. PatientId: id,
  1005. RecordDate: recordDate.Unix(),
  1006. Way: way,
  1007. Consciousness: consciousness,
  1008. Appetite: appetite,
  1009. Condition: condition,
  1010. SickCondition: sick_condition,
  1011. DangerLevel: danger_level,
  1012. Intake: intake,
  1013. Nutrition: nutrition,
  1014. PsychologicalAssessment: psychological_assessment,
  1015. PsychologicalAssessmentOther: psychological_assessment_other,
  1016. SickConditionOther: sick_condition_other,
  1017. Posture: posture,
  1018. CreatedTime: time.Now().Unix(),
  1019. UpdateTime: time.Now().Unix(),
  1020. Status: 1,
  1021. Score: score,
  1022. Precaution: precaution,
  1023. PrecautionOther: precaution_other,
  1024. PsychologicalOther: psychological_other,
  1025. AdmissionNumber: admission_number,
  1026. Tumble: tumble,
  1027. Diacrisis: diacrisis,
  1028. HisBed: his_bed,
  1029. HisDepartment: his_department,
  1030. }
  1031. if receiveTreatment.ID == 0 { //新增
  1032. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1033. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1034. finish := models.XtDialysisFinish{
  1035. IsFinish: 1,
  1036. UserOrgId: adminUserInfo.Org.Id,
  1037. Status: 1,
  1038. Ctime: time.Now().Unix(),
  1039. Mtime: 0,
  1040. Module: 2,
  1041. RecordDate: recordDate.Unix(),
  1042. Sourse: 1,
  1043. PatientId: id,
  1044. }
  1045. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1046. if dialysisFinish.ID == 0 {
  1047. service.CreateDialysisFinish(finish)
  1048. }
  1049. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1050. redis := service.RedisClient()
  1051. defer redis.Close()
  1052. //清空key 值
  1053. redis.Set(key, "", time.Second)
  1054. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1055. redis.Set(keyOne, "", time.Second)
  1056. if err == nil {
  1057. c.ServeSuccessJSON(map[string]interface{}{
  1058. "receiveTreatmentAsses": receiveTreatmentAsses,
  1059. })
  1060. }
  1061. } else { //修改
  1062. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1063. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1064. // if getPermissionErr != nil {
  1065. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1066. // return
  1067. // } else if headNursePermission == nil {
  1068. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1069. // return
  1070. // }
  1071. //}
  1072. // 查询信息规挡的设置天数
  1073. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1074. if infor.ID > 0 && infor.WeekDay > 0 {
  1075. var cha_time int64
  1076. timeNowStr := time.Now().Format("2006-01-02")
  1077. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1078. //今日的日期减去设置的日期
  1079. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1080. if cha_time >= recordDate.Unix() {
  1081. //查询审核是否允许
  1082. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1083. //申请状态不允许的情况 拒绝修改
  1084. if infor.ApplicationStatus != 1 {
  1085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1086. return
  1087. }
  1088. }
  1089. }
  1090. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1091. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1092. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1093. receiveTreatmentAsses.ID = receiveTreatment.ID
  1094. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1095. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1096. redis := service.RedisClient()
  1097. defer redis.Close()
  1098. //清空key 值
  1099. redis.Set(key, "", time.Second)
  1100. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1101. redis.Set(keyOne, "", time.Second)
  1102. if err == nil {
  1103. c.ServeSuccessJSON(map[string]interface{}{
  1104. "receiveTreatmentAsses": receiveTreatmentAsses,
  1105. })
  1106. }
  1107. }
  1108. }
  1109. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1110. id, _ := c.GetInt64("patient", 0)
  1111. recordDateStr := c.GetString("record_date")
  1112. weightAfter, _ := c.GetFloat("weight_after", 0)
  1113. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1114. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1115. fmt.Println("weight_loss", weightReduce)
  1116. temperature, _ := c.GetFloat("temperature", 0)
  1117. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1118. breathing_rate := c.GetString("breathing_rate")
  1119. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1120. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1121. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1122. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1123. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1124. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1125. cruor := c.GetString("cruor")
  1126. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1127. internalFistula := c.GetString("internal_fistula")
  1128. catheter := c.GetString("catheter")
  1129. complications := c.GetString("complication")
  1130. remark := c.GetString("remark")
  1131. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1132. dialysis_intakes := c.GetString("dialysis_intakes")
  1133. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1134. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1135. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1136. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1137. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1138. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1139. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1140. patientGose, _ := c.GetInt64("patient_gose", 0)
  1141. inpatientDepartment := c.GetString("inpatient_department")
  1142. observationContent := c.GetString("observation_content")
  1143. observationContentOther := c.GetString("observation_content_other")
  1144. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1145. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1146. in_advance_reason := c.GetString("in_advance_reason")
  1147. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1148. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1149. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1150. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1151. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1152. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1153. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1154. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1155. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1156. is_eat, _ := c.GetInt64("is_eat", 0)
  1157. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1158. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1159. channels, _ := c.GetInt64("channel", 0)
  1160. return_blood, _ := c.GetInt64("return_blood", 0)
  1161. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1162. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1163. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1164. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1165. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1166. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1167. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1168. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1169. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1170. setting_pressure := c.GetString("setting_pressure")
  1171. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1172. diastolic_pressure := c.GetString("diastolic_pressure")
  1173. other_complication := c.GetString("other_complication")
  1174. ktv := c.GetString("ktv")
  1175. urr := c.GetString("urr")
  1176. hypertenison, _ := c.GetInt64("hypertenison")
  1177. hypopiesia, _ := c.GetInt64("hypopiesia")
  1178. leave_office_method, _ := c.GetInt64("leave_office_method")
  1179. lapse, _ := c.GetInt64("lapse")
  1180. consciousness, _ := c.GetInt64("consciousness")
  1181. fallrisk, _ := c.GetInt64("fallrisk")
  1182. machine_run := c.GetString("machine_run")
  1183. after_urea := c.GetString("after_urea")
  1184. pip_coagulation := c.GetString("pip_coagulation")
  1185. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1186. transfusion_volume := c.GetString("transfusion_volume")
  1187. last_after_weight := c.GetString("last_after_weight")
  1188. if id <= 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1190. return
  1191. }
  1192. adminUserInfo := c.GetMobileAdminUserInfo()
  1193. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1194. if patient.ID == 0 {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1196. return
  1197. }
  1198. if len(recordDateStr) == 0 {
  1199. recordDateStr = time.Now().Format("2006-01-02")
  1200. }
  1201. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1202. fmt.Println("parseDateErr", parseDateErr)
  1203. if parseDateErr != nil {
  1204. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. //now := time.Now()
  1209. //year, month, day := now.Date()
  1210. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1211. //todayTimeStamp := today_time.Unix()
  1212. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1213. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1214. UserOrgId: adminUserInfo.Org.Id,
  1215. PatientId: id,
  1216. AssessmentDate: recordDate.Unix(),
  1217. Temperature: temperature,
  1218. PulseFrequency: pulse_frequency,
  1219. BreathingRate: breathing_rate,
  1220. SystolicBloodPressure: systolic_blood_pressure,
  1221. DiastolicBloodPressure: diastolic_blood_pressure,
  1222. ActualUltrafiltration: actual_ultrafiltration,
  1223. ActualDisplacement: actual_displacement,
  1224. ActualTreatmentHour: actualtreatHour,
  1225. ActualTreatmentMinute: actualtreatmin,
  1226. WeightAfter: weightAfter,
  1227. AdditionalWeight: additionalWeight,
  1228. WeightLoss: weightReduce,
  1229. Cruor: cruor,
  1230. SymptomAfterDialysis: symptomsAfterDialysi,
  1231. InternalFistula: internalFistula,
  1232. Catheter: catheter,
  1233. Complication: complications,
  1234. DialysisIntakes: dialysateVolume,
  1235. CreatedTime: time.Now().Unix(),
  1236. UpdatedTime: time.Now().Unix(),
  1237. Status: 1,
  1238. Remark: remark,
  1239. BloodAccessPartId: blood_access_part_id,
  1240. BloodAccessPartOperaId: blood_access_part_opera_id,
  1241. DialysisIntakesUnit: dialysis_intakes_unit,
  1242. PuncturePointOozingBlood: puncturePointOozingBlood,
  1243. PuncturePointHaematoma: puncturePointHaematoma,
  1244. InternalFistulaTremorAc: internalFistulaTremorAc,
  1245. PatientGose: patientGose,
  1246. InpatientDepartment: inpatientDepartment,
  1247. ObservationContent: observationContent,
  1248. ObservationContentOther: observationContentOther,
  1249. DialysisProcess: dialysis_process,
  1250. InAdvanceMinute: in_advance_minute,
  1251. InAdvanceReason: in_advance_reason,
  1252. HemostasisMinute: hemostasis_minute,
  1253. HemostasisOpera: hemostasis_opera,
  1254. TremorNoise: tremor_noise,
  1255. DisequilibriumSyndrome: disequilibrium_syndrome,
  1256. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1257. ArterialTube: arterial_tube,
  1258. IntravenousTube: intravenous_tube,
  1259. Dialyzer: dialyzer,
  1260. InAdvanceReasonOther: in_advance_reason_other,
  1261. IsEat: is_eat,
  1262. CvcA: cvc_a,
  1263. CvcV: cvc_v,
  1264. Channel: channels,
  1265. ReturnBlood: return_blood,
  1266. RehydrationVolume: rehydration_volume,
  1267. DialysisDuring: dialysis_during,
  1268. StrokeVolume: stroke_volume,
  1269. BloodFlow: blood_flow,
  1270. SealingFluidDispose: sealing_fluid_dispose,
  1271. SealingFluidSpecial: sealing_fluid_special,
  1272. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1273. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1274. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1275. SettingPressure: setting_pressure,
  1276. DiastolicPressure: diastolic_pressure,
  1277. OtherComplication: other_complication,
  1278. Ktv: ktv,
  1279. Urr: urr,
  1280. Hypopiesia: hypopiesia,
  1281. Hypertenison: hypertenison,
  1282. Lapse: lapse,
  1283. LeaveOfficeMethod: leave_office_method,
  1284. Consciousness: consciousness,
  1285. Fallrisk: fallrisk,
  1286. MachineRun: machine_run,
  1287. AfterUrea: after_urea,
  1288. PipCoagulation: pip_coagulation,
  1289. AccumulatedBloodVolume: accumulated_blood_volume,
  1290. TransfusionVolume: transfusion_volume,
  1291. LastAfterWeight: last_after_weight,
  1292. }
  1293. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1294. // 查询信息规挡的设置天数
  1295. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1296. if infor.ID > 0 && infor.WeekDay > 0 {
  1297. var cha_time int64
  1298. timeNowStr := time.Now().Format("2006-01-02")
  1299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1300. //今日的日期减去设置的日期
  1301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1302. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1303. if cha_time >= recordDate.Unix() {
  1304. //查询审核是否允许
  1305. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1306. //申请状态不允许的情况 拒绝修改
  1307. if infor.ApplicationStatus != 1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1309. return
  1310. }
  1311. }
  1312. }
  1313. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1314. if assessmentAfter.ID == 0 { //新增
  1315. if appRole.UserType == 2 || appRole.UserType == 1 {
  1316. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1317. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1318. } else {
  1319. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1320. }
  1321. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1322. //记录日志
  1323. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1324. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1325. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1326. PatientId: assessmentAfterDislysis.PatientId,
  1327. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1328. Status: 1,
  1329. ErrLog: string(byterequest),
  1330. AdminUserId: adminUserInfo.AdminUser.Id,
  1331. Ctime: 0,
  1332. Mtime: 0,
  1333. Source: "手机端保存透后评估",
  1334. }
  1335. service.CreateAfterDialysisLog(afterDialysisLog)
  1336. finish := models.XtDialysisFinish{
  1337. IsFinish: 1,
  1338. UserOrgId: adminUserInfo.Org.Id,
  1339. Status: 1,
  1340. Ctime: time.Now().Unix(),
  1341. Mtime: 0,
  1342. Module: 9,
  1343. RecordDate: recordDate.Unix(),
  1344. Sourse: 1,
  1345. PatientId: id,
  1346. }
  1347. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1348. if dialysisFinish.ID == 0 {
  1349. service.CreateDialysisFinish(finish)
  1350. }
  1351. redis := service.RedisClient()
  1352. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1353. redis.Set(keyTwo, "", time.Second)
  1354. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1355. //清空key 值
  1356. redis.Set(key, "", time.Second)
  1357. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1358. redis.Set(keyOne, "", time.Second)
  1359. defer redis.Close()
  1360. if err == nil {
  1361. c.ServeSuccessJSON(map[string]interface{}{
  1362. "assessmentAfterDislysis": assessmentAfterDislysis,
  1363. })
  1364. }
  1365. return
  1366. } else { //修改
  1367. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1368. if infor.ID > 0 && infor.WeekDay > 0 {
  1369. var cha_time int64
  1370. timeNowStr := time.Now().Format("2006-01-02")
  1371. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1372. //今日的日期减去设置的日期
  1373. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1374. if cha_time >= recordDate.Unix() {
  1375. //查询审核是否允许
  1376. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1377. //申请状态不允许的情况 拒绝修改
  1378. if infor.ApplicationStatus != 1 {
  1379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1380. return
  1381. }
  1382. }
  1383. }
  1384. if appRole.UserType == 2 || appRole.UserType == 1 {
  1385. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1386. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1387. } else {
  1388. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1389. if assessmentAfterDislysis.Creater == 0 {
  1390. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1391. }
  1392. }
  1393. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1394. assessmentAfterDislysis.ID = assessmentAfter.ID
  1395. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1396. //记录日志
  1397. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1398. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1399. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1400. PatientId: assessmentAfterDislysis.PatientId,
  1401. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1402. Status: 1,
  1403. ErrLog: string(byterequest),
  1404. AdminUserId: adminUserInfo.AdminUser.Id,
  1405. Ctime: time.Now().Unix(),
  1406. Mtime: 0,
  1407. Source: "手机端修改保存透后评估",
  1408. }
  1409. service.CreateAfterDialysisLog(afterDialysisLog)
  1410. redis := service.RedisClient()
  1411. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1412. redis.Set(keyTwo, "", time.Second)
  1413. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1414. //清空key 值
  1415. redis.Set(key, "", time.Second)
  1416. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1417. redis.Set(keyOne, "", time.Second)
  1418. if err == nil {
  1419. c.ServeSuccessJSON(map[string]interface{}{
  1420. "assessmentAfterDislysis": assessmentAfterDislysis,
  1421. })
  1422. return
  1423. }
  1424. }
  1425. return
  1426. }
  1427. func (c *DialysisAPIController) PostDialysisPrescription() {
  1428. id, _ := c.GetInt64("patient", 0)
  1429. recordDateStr := c.GetString("record_date")
  1430. if id <= 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. return
  1433. }
  1434. adminUserInfo := c.GetMobileAdminUserInfo()
  1435. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1436. if patient.ID == 0 {
  1437. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1438. return
  1439. }
  1440. if len(recordDateStr) == 0 {
  1441. recordDateStr = time.Now().Format("2006-01-02")
  1442. }
  1443. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1444. if parseDateErr != nil {
  1445. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1447. return
  1448. }
  1449. mode_id, _ := c.GetInt64("mode_id", 0)
  1450. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1451. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1452. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1453. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1454. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1455. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1456. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1457. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1458. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1459. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1460. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1461. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1462. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1463. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1464. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1465. kalium, _ := c.GetFloat("kalium", 0)
  1466. sodium, _ := c.GetFloat("sodium", 0)
  1467. calcium, _ := c.GetFloat("calcium", 0)
  1468. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1469. glucose, _ := c.GetFloat("glucose", 0)
  1470. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1471. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1472. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1473. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1474. conductivity, _ := c.GetFloat("conductivity", 0)
  1475. remark := c.GetString("remark")
  1476. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1477. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1478. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1479. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1480. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1481. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1482. special_medicine_other := c.GetString("special_medicine_other")
  1483. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1484. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1485. blood_access, _ := c.GetInt64("blood_access", 0)
  1486. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1487. body_fluid_other := c.GetString("body_fluid_other")
  1488. niprocart, _ := c.GetInt64("niprocart", 0)
  1489. jms, _ := c.GetInt64("jms", 0)
  1490. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1491. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1492. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1493. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1494. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1495. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1496. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1497. injector, _ := c.GetInt64("injector", 0)
  1498. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1499. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1500. safe_package, _ := c.GetInt64("package", 0)
  1501. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1502. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1503. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1504. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1505. blood := c.GetString("blood")
  1506. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1507. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1508. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1509. displace_speed := c.GetString("displace_speed")
  1510. illness, _ := c.GetInt64("illness")
  1511. amylaceum := c.GetString("amylaceum")
  1512. single_time := c.GetString("single_time")
  1513. single_water := c.GetString("single_water")
  1514. replacement_flow := c.GetString("replacement_flow")
  1515. plasma_separator := c.GetString("plasma_separator")
  1516. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1517. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1518. oxygen_flow := c.GetString("oxygen_flow")
  1519. oxygen_time := c.GetString("oxygen_time")
  1520. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1521. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1522. puncture_needle := c.GetString("puncture_needle")
  1523. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1524. epo := c.GetString("epo")
  1525. epo_count, _ := c.GetFloat("epo_count", 0)
  1526. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1527. admin_user_id, _ := c.GetInt64("admin_user_id")
  1528. is_water := c.GetString("is_water")
  1529. var is_war int64
  1530. if is_water == "是" {
  1531. is_war = 1
  1532. }
  1533. if is_water == "否" {
  1534. is_war = 2
  1535. }
  1536. if is_water == "请选择" {
  1537. is_war = 0
  1538. }
  1539. drhy_water := c.GetString("drhy_water")
  1540. dry_water_hour := c.GetString("dry_water_hour")
  1541. water_machine := c.GetString("water_machine")
  1542. add_amount, _ := c.GetFloat("add_amount")
  1543. reduce_amount, _ := c.GetFloat("reduce_amount")
  1544. dialysis_remark := c.GetString("dialysis_remark")
  1545. prescribing_number, _ := c.GetFloat("prescribing_number")
  1546. prescription_sodium := c.GetString("prescription_sodium")
  1547. start_sodium := c.GetString("start_sodium")
  1548. sodium_curve := c.GetString("sodium_curve")
  1549. treatment_remark := c.GetString("treatment_remark")
  1550. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1551. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1552. prescription_water, _ := c.GetFloat("prescription_water")
  1553. dialysis_strainer := c.GetString("dialysis_strainer")
  1554. chaptalization := c.GetString("chaptalization")
  1555. washing_time := c.GetString("washing_time")
  1556. warsh_count := c.GetString("warsh_count")
  1557. blood_access_part_id := c.GetString("blood_access_part_id")
  1558. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1559. dialyzate := c.GetString("dialyzate")
  1560. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1561. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1562. //
  1563. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1564. // if appRole.UserType == 3 {
  1565. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1566. // if getPermissionErr != nil {
  1567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1568. // return
  1569. // } else if headNursePermission == nil {
  1570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1571. // return
  1572. // }
  1573. // }
  1574. //}
  1575. // 查询信息规挡的设置天数
  1576. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1577. if infor.ID > 0 && infor.WeekDay > 0 {
  1578. var cha_time int64
  1579. timeNowStr := time.Now().Format("2006-01-02")
  1580. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1581. //今日的日期减去设置的日期
  1582. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1583. if cha_time >= recordDate.Unix() {
  1584. //查询审核是否允许
  1585. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1586. //申请状态不允许的情况 拒绝修改
  1587. if infor.ApplicationStatus != 1 {
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1589. return
  1590. }
  1591. }
  1592. }
  1593. if mode_id > 0 {
  1594. var str string
  1595. //查找该机构用的是什么透析器
  1596. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1597. if filedConfig.ID > 0 {
  1598. str = dialyzerPerfusionApparatus
  1599. } else {
  1600. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1601. }
  1602. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1603. }
  1604. //TODO 需要根据角色去判断
  1605. prescription := models.DialysisPrescription{
  1606. UserOrgId: adminUserInfo.Org.Id,
  1607. PatientId: id,
  1608. RecordDate: recordDate.Unix(),
  1609. ModeId: mode_id,
  1610. DialysisDuration: dialysis_duration,
  1611. Dialyzer: dialyzer,
  1612. PerfusionApparatus: perfusion_apparatus,
  1613. BloodFlowVolume: blood_flow_volume,
  1614. DewaterAmount: dewater_amount,
  1615. DisplaceLiqui: displace_liqui,
  1616. ReplacementWay: replacement_way,
  1617. Anticoagulant: anticoagulant,
  1618. AnticoagulantShouji: anticoagulant_shouji,
  1619. AnticoagulantWeichi: anticoagulant_weichi,
  1620. AnticoagulantZongliang: anticoagulant_zongliang,
  1621. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1622. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1623. Kalium: kalium,
  1624. Sodium: sodium,
  1625. Calcium: calcium,
  1626. Bicarbonate: bicarbonate,
  1627. Glucose: glucose,
  1628. // DryWeight: dry_weight,
  1629. DialysateFlow: dialysate_flow,
  1630. DialysateTemperature: dialysate_temperature,
  1631. // PrescriptionDoctor: prescription_doctor,
  1632. ReplacementTotal: replacement_total,
  1633. Conductivity: conductivity,
  1634. Remark: remark,
  1635. Status: 1,
  1636. CreatedTime: time.Now().Unix(),
  1637. UpdatedTime: time.Now().Unix(),
  1638. DialysisDurationMinute: dialysisDurationMinute,
  1639. DialysisDurationHour: dialysisDurationHour,
  1640. TargetUltrafiltration: targetUltrafiltration,
  1641. DialysateFormulation: dialysateFormulation,
  1642. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1643. BodyFluid: body_fluid,
  1644. SpecialMedicine: special_medicine,
  1645. SpecialMedicineOther: special_medicine_other,
  1646. DisplaceLiquiPart: displace_liqui_part,
  1647. DisplaceLiquiValue: displace_liqui_value,
  1648. BloodAccess: blood_access,
  1649. Ultrafiltration: ultrafiltration,
  1650. BodyFluidOther: body_fluid_other,
  1651. Niprocart: niprocart,
  1652. Jms: jms,
  1653. FistulaNeedleSet: fistula_needle_set,
  1654. FistulaNeedleSet16: fistula_needle_set_16,
  1655. Hemoperfusion: hemoperfusion,
  1656. DialyserSterilised: dialyser_sterilised,
  1657. Filtryzer: filtryzer,
  1658. Dialyzers: dialyzers,
  1659. Injector: injector,
  1660. Bloodlines: bloodlines,
  1661. TubingHemodialysis: tubing_hemodialysis,
  1662. Package: safe_package,
  1663. ALiquid: a_liquid,
  1664. TargetKtv: target_ktv,
  1665. PreImpulse: pre_impulse,
  1666. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1667. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1668. Blood: blood,
  1669. DialysisDialyszers: dialysis_dialyszers,
  1670. DialysisIrrigation: dialysis_irrigation,
  1671. AntioxidantCommodityName: antioxidant_commodity_name,
  1672. DisplaceSpeed: displace_speed,
  1673. Illness: illness,
  1674. Amylaceum: amylaceum,
  1675. SingleTime: single_time,
  1676. SingleWater: single_water,
  1677. ReplacementFlow: replacement_flow,
  1678. PlasmaSeparator: plasma_separator,
  1679. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1680. OxygenUptake: oxygen_uptake,
  1681. OxygenFlow: oxygen_flow,
  1682. OxygenTime: oxygen_time,
  1683. HemodialysisPipelines: hemodialysis_pipelines,
  1684. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1685. PunctureNeedle: puncture_needle,
  1686. PunctureNeedleCount: puncture_needle_count,
  1687. Epo: epo,
  1688. EpoCount: epo_count,
  1689. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1690. AdminUserId: admin_user_id,
  1691. IsWater: is_war,
  1692. DrhyWater: drhy_water,
  1693. DryWaterHour: dry_water_hour,
  1694. WaterMachine: water_machine,
  1695. AddAmount: add_amount,
  1696. ReduceAmount: reduce_amount,
  1697. DialysisRemark: dialysis_remark,
  1698. PrescribingNumber: prescribing_number,
  1699. StartSodium: start_sodium,
  1700. SodiumCurve: sodium_curve,
  1701. TreatmentRemark: treatment_remark,
  1702. PrescriptionSodium: prescription_sodium,
  1703. DialysisFluidFlow: dialysis_fluid_flow,
  1704. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1705. PrescriptionWater: prescription_water,
  1706. DialysisStrainer: dialysis_strainer,
  1707. Chaptalization: chaptalization,
  1708. WashingTime: washing_time,
  1709. WarshCount: warsh_count,
  1710. BloodAccessPartId: blood_access_part_id,
  1711. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1712. Dialyzate: dialyzate,
  1713. }
  1714. //查询最近透析准备表里是否存在 透析器 灌流器
  1715. //
  1716. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1717. //
  1718. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1719. //
  1720. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1721. //if len(mation)>0{
  1722. // for _, item := range splitStr {
  1723. // for _,it := range mation{
  1724. // if(item == it.SpecificationName){
  1725. //
  1726. // //查询最近一次的透析器
  1727. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1728. //
  1729. // if errcode == gorm.ErrRecordNotFound{
  1730. // //插入数据
  1731. // prepare := models.DialysisBeforePrepare{
  1732. // UserOrgId: adminUserInfo.Org.Id,
  1733. // PatientId: id,
  1734. // RecordDate: recordDate.Unix(),
  1735. // GoodTypeId: it.GoodTypeId,
  1736. // GoodId: it.ID,
  1737. // Count: 1,
  1738. // Ctime: time.Now().Unix(),
  1739. // Creater: adminUserInfo.AdminUser.Id,
  1740. // Status:1,
  1741. //
  1742. // }
  1743. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1744. // fmt.Println("",errcode)
  1745. // }
  1746. // }
  1747. // }
  1748. //
  1749. // }
  1750. //
  1751. // for _, item := range splitIrrigation {
  1752. // for _,it := range mation{
  1753. // if(item == it.SpecificationName){
  1754. // //查询最近一次的透析器
  1755. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1756. // if errcode == gorm.ErrRecordNotFound{
  1757. // //插入数据
  1758. // prepare := models.DialysisBeforePrepare{
  1759. // UserOrgId: adminUserInfo.Org.Id,
  1760. // PatientId: id,
  1761. // RecordDate: recordDate.Unix(),
  1762. // GoodTypeId: it.GoodTypeId,
  1763. // GoodId: it.ID,
  1764. // Count: 1,
  1765. // Ctime: time.Now().Unix(),
  1766. // Creater: adminUserInfo.AdminUser.Id,
  1767. // Status:1,
  1768. //
  1769. // }
  1770. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1771. // fmt.Println(errcode)
  1772. // }
  1773. // }
  1774. // }
  1775. // }
  1776. //}
  1777. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1778. if dialysisPrescription.ID == 0 { //新增
  1779. if appRole.UserType == 2 || appRole.UserType == 1 {
  1780. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1781. }
  1782. prescription.Creater = adminUserInfo.AdminUser.Id
  1783. //针对河间咸得
  1784. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1785. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1786. prescription.DisplaceLiquiPart = 0
  1787. prescription.DisplaceLiquiValue = 0
  1788. }
  1789. }
  1790. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1791. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1792. }
  1793. err := service.AddSigleRecord(&prescription)
  1794. //记录日志
  1795. byterequest, _ := json.Marshal(prescription)
  1796. prescriptionLog := models.XtDialysisPrescriptionLog{
  1797. UserOrgId: prescription.UserOrgId,
  1798. Ctime: time.Now().Unix(),
  1799. Mtime: 0,
  1800. ErrLog: string(byterequest),
  1801. AdminUserId: adminUserInfo.AdminUser.Id,
  1802. RecordDate: prescription.RecordDate,
  1803. PatientId: prescription.PatientId,
  1804. Source: "手机端新增保存处方",
  1805. Status: 1,
  1806. }
  1807. service.CreatePrescriptionLog(prescriptionLog)
  1808. finish := models.XtDialysisFinish{
  1809. IsFinish: 1,
  1810. UserOrgId: adminUserInfo.Org.Id,
  1811. Status: 1,
  1812. Ctime: time.Now().Unix(),
  1813. Mtime: 0,
  1814. Module: 1,
  1815. RecordDate: recordDate.Unix(),
  1816. Sourse: 1,
  1817. PatientId: id,
  1818. }
  1819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1820. if dialysisFinish.ID == 0 {
  1821. service.CreateDialysisFinish(finish)
  1822. }
  1823. //长沙南雅医院,自动生成抗凝剂的临时处方
  1824. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1825. if prescribing_number == 0 {
  1826. prescribing_number = 1
  1827. }
  1828. if prescribing_number == 0 && id == 14682 {
  1829. prescribing_number = 2
  1830. }
  1831. if prescribing_number == 0 && id == 18560 {
  1832. prescribing_number = 2
  1833. }
  1834. advice := models.DoctorAdvice{
  1835. UserOrgId: adminUserInfo.Org.Id,
  1836. PatientId: id,
  1837. GroupNo: 0,
  1838. AdviceType: 2,
  1839. RecordDate: recordDate.Unix(),
  1840. AdviceDate: recordDate.Unix(),
  1841. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1842. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1843. AdviceDesc: "",
  1844. ReminderDate: 0,
  1845. SingleDose: anticoagulant_zongliang,
  1846. SingleDoseUnit: "iu",
  1847. DrugSpec: 0,
  1848. DrugSpecUnit: "",
  1849. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1850. PrescribingNumberUnit: "支",
  1851. DeliveryWay: "静脉注射",
  1852. ExecutionFrequency: "上机前",
  1853. AdviceDoctor: 0,
  1854. Status: 1,
  1855. CreatedTime: time.Now().Unix(),
  1856. UpdatedTime: time.Now().Unix(),
  1857. IsPrescription: 1,
  1858. ExecutionState: 2,
  1859. StopState: 2,
  1860. IsSettle: 2,
  1861. }
  1862. // 查询排班信息
  1863. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1864. if schedulePatient.ID > 0 {
  1865. if schedulePatient.ScheduleType == 1 {
  1866. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1867. }
  1868. if schedulePatient.ScheduleType == 2 {
  1869. advice.StartTime = recordDate.Unix() + 10*60*60
  1870. }
  1871. }
  1872. // 抗凝剂名称
  1873. switch anticoagulant {
  1874. case 1:
  1875. advice.AdviceName = "无肝素"
  1876. break
  1877. case 2:
  1878. advice.AdviceName = "普通肝素"
  1879. break
  1880. case 3:
  1881. advice.AdviceName = "低分子肝素"
  1882. break
  1883. case 4:
  1884. advice.AdviceName = "阿加曲班"
  1885. break
  1886. case 5:
  1887. advice.AdviceName = "枸橼酸钠"
  1888. break
  1889. case 6:
  1890. advice.AdviceName = "低分子肝素钙"
  1891. break
  1892. case 7:
  1893. advice.AdviceName = "低分子肝素钠"
  1894. break
  1895. case 8:
  1896. advice.AdviceName = "依诺肝素"
  1897. break
  1898. case 9:
  1899. advice.AdviceName = "达肝素"
  1900. break
  1901. case 10:
  1902. advice.AdviceName = "体外抗凝"
  1903. break
  1904. case 11:
  1905. advice.AdviceName = "那曲肝素"
  1906. break
  1907. case 12:
  1908. advice.AdviceName = "无抗凝剂"
  1909. break
  1910. }
  1911. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1912. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1913. advice.AdviceDoctor = appRole.AdminUserId
  1914. }
  1915. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1916. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1917. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1918. advice.AdviceName = "低分子肝素钠注射液"
  1919. // 修改患者临时医嘱里的抗凝剂医嘱
  1920. advice.ID = advicePrescription.ID
  1921. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1922. } else {
  1923. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1924. advice.AdviceName = "低分子肝素钠注射液"
  1925. // 新增患者临时医嘱里的抗凝剂医嘱
  1926. service.CreateDoctorAdvice(&advice)
  1927. }
  1928. }
  1929. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1930. redis := service.RedisClient()
  1931. defer redis.Close()
  1932. //清空key 值
  1933. redis.Set(key, "", time.Second)
  1934. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1935. redis.Set(keyOne, "", time.Second)
  1936. }
  1937. //获取key,清空redis
  1938. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1939. redis := service.RedisClient()
  1940. //清空key 值
  1941. redis.Set(key, "", time.Second)
  1942. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1943. //清空key 值
  1944. redis.Set(keyOne, "", time.Second)
  1945. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1946. //清空key 值
  1947. redis.Set(keyTwo, "", time.Second)
  1948. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1949. redis.Set(keySix, "", time.Second)
  1950. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1951. redis.Set(keySeven, "", time.Second)
  1952. if err == nil {
  1953. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1954. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1955. //清空key 值
  1956. redis.Set(keyThree, "", time.Second)
  1957. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1958. //清空key 值
  1959. redis.Set(keyFour, "", time.Second)
  1960. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1961. redis.Set(keyFive, "", time.Second)
  1962. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1963. redis.Set(keySix, "", time.Second)
  1964. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1965. redis.Set(keySeven, "", time.Second)
  1966. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1967. //清空key 值
  1968. redis.Set(keyOne, "", time.Second)
  1969. if updateErr != nil {
  1970. utils.ErrorLog("%v", updateErr)
  1971. }
  1972. defer redis.Close()
  1973. c.ServeSuccessJSON(map[string]interface{}{
  1974. "prescription": prescription,
  1975. })
  1976. }
  1977. } else { //修改
  1978. //if mode_id > 0 {
  1979. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1980. //}
  1981. //if template.TemplateId == 1 {
  1982. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1983. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1984. // if getPermissionErr != nil {
  1985. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1986. // return
  1987. // } else if headNursePermission == nil {
  1988. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1989. // return
  1990. // }
  1991. // }
  1992. //}
  1993. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1994. prescription.Modifier = adminUserInfo.AdminUser.Id
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. prescription_doctor := adminUserInfo.AdminUser.Id
  1997. prescription.PrescriptionDoctor = prescription_doctor
  1998. } else {
  1999. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2000. }
  2001. if dialysisPrescription.Creater == 0 { //体重称
  2002. prescription.Creater = adminUserInfo.AdminUser.Id
  2003. } else {
  2004. prescription.Creater = dialysisPrescription.Creater
  2005. if adminUserInfo.Org.Id == 9882 {
  2006. if appRole.UserType == 2 || appRole.UserType == 1 {
  2007. prescription_doctor := adminUserInfo.AdminUser.Id
  2008. prescription.PrescriptionDoctor = prescription_doctor
  2009. prescription.Creater = prescription_doctor
  2010. }
  2011. }
  2012. }
  2013. prescription.ID = dialysisPrescription.ID
  2014. err := service.UpDateDialysisPrescription(&prescription)
  2015. //记录日志
  2016. byterequest, _ := json.Marshal(prescription)
  2017. prescriptionLog := models.XtDialysisPrescriptionLog{
  2018. UserOrgId: prescription.UserOrgId,
  2019. Ctime: time.Now().Unix(),
  2020. Mtime: 0,
  2021. ErrLog: string(byterequest),
  2022. AdminUserId: adminUserInfo.AdminUser.Id,
  2023. RecordDate: prescription.RecordDate,
  2024. PatientId: prescription.PatientId,
  2025. Source: "手机端修改处方",
  2026. Status: 1,
  2027. }
  2028. service.CreatePrescriptionLog(prescriptionLog)
  2029. finish := models.XtDialysisFinish{
  2030. IsFinish: 1,
  2031. UserOrgId: adminUserInfo.Org.Id,
  2032. Status: 1,
  2033. Ctime: time.Now().Unix(),
  2034. Mtime: 0,
  2035. Module: 1,
  2036. RecordDate: recordDate.Unix(),
  2037. Sourse: 1,
  2038. PatientId: id,
  2039. }
  2040. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2041. if dialysisFinish.ID == 0 {
  2042. service.CreateDialysisFinish(finish)
  2043. }
  2044. //修改处方
  2045. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2046. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2047. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2048. if advicePrescription.ID > 0 {
  2049. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2050. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2051. redis := service.RedisClient()
  2052. defer redis.Close()
  2053. //清空key 值
  2054. redis.Set(key, "", time.Second)
  2055. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2056. redis.Set(keyOne, "", time.Second)
  2057. }
  2058. }
  2059. //获取key,清空redis
  2060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2061. redis := service.RedisClient()
  2062. //清空key 值
  2063. redis.Set(key, "", time.Second)
  2064. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2065. //清空key 值
  2066. redis.Set(keyOne, "", time.Second)
  2067. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2068. redis.Set(keySix, "", time.Second)
  2069. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2070. redis.Set(keySeven, "", time.Second)
  2071. if err == nil {
  2072. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2073. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2074. //清空key 值
  2075. redis.Set(keyOne, "", time.Second)
  2076. defer redis.Close()
  2077. if updateErr != nil {
  2078. utils.ErrorLog("%v", updateErr)
  2079. }
  2080. c.ServeSuccessJSON(map[string]interface{}{
  2081. "prescription": prescription,
  2082. })
  2083. }
  2084. }
  2085. }
  2086. func (c *DialysisAPIController) Finish() {
  2087. id, _ := c.GetInt64("patient", 0)
  2088. recordDateStr := c.GetString("record_date")
  2089. nurseID, _ := c.GetInt64("nurse")
  2090. end_time := c.GetString("end_time")
  2091. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2092. internal_fistula := c.GetString("blood_access_internal_fistula")
  2093. catheter := c.GetString("catheter")
  2094. cruor := c.GetString("cruor")
  2095. mission := c.GetString("mission")
  2096. condenser := c.GetString("condenser")
  2097. if id <= 0 || nurseID <= 0 {
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2099. return
  2100. }
  2101. adminUserInfo := c.GetMobileAdminUserInfo()
  2102. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2103. if patient.ID == 0 {
  2104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2105. return
  2106. }
  2107. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2108. if getNurseErr != nil {
  2109. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2111. return
  2112. } else if nurse == nil {
  2113. c.ErrorLog("护士不存在")
  2114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2115. return
  2116. }
  2117. if len(recordDateStr) == 0 {
  2118. recordDateStr = time.Now().Format("2006-01-02")
  2119. }
  2120. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2121. if parseDateErr != nil {
  2122. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2124. return
  2125. }
  2126. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2127. if parseEndDateErr != nil {
  2128. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2130. return
  2131. }
  2132. // 查询信息规挡的设置天数
  2133. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2134. if infor.ID > 0 && infor.WeekDay > 0 {
  2135. var cha_time int64
  2136. timeNowStr := time.Now().Format("2006-01-02")
  2137. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2138. //今日的日期减去设置的日期
  2139. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2140. if cha_time >= recordDate.Unix() {
  2141. //查询审核是否允许
  2142. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2143. //申请状态不允许的情况 拒绝修改
  2144. if infor.ApplicationStatus != 1 {
  2145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2146. return
  2147. }
  2148. }
  2149. }
  2150. //now := time.Now()
  2151. //year, month, day := now.Date()
  2152. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2153. //todayTimeStamp := today_time.Unix()
  2154. // 获取当天的第一条透析纪录
  2155. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2156. if getMonitorRecordsErr != nil {
  2157. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2159. return
  2160. }
  2161. // 获取当前的最后一条透析纪录
  2162. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2163. if getMonitorRecordsErr != nil {
  2164. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2166. return
  2167. }
  2168. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2169. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2170. if getAADErr != nil {
  2171. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2173. return
  2174. }
  2175. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2176. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2177. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2178. if assessmentAfterDislysis != nil {
  2179. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2180. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2181. } else {
  2182. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2183. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2184. tempassessmentAfterDislysis.Status = 1
  2185. tempassessmentAfterDislysis.PatientId = id
  2186. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2187. }
  2188. //长沙南雅
  2189. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2190. //获取最后一条透析处方数据
  2191. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2192. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2193. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2194. }
  2195. if dialysisOrder.Stage == 1 {
  2196. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2197. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2198. fmt.Println(value)
  2199. a, b := math.Modf(value)
  2200. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2201. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2202. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2203. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2204. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2205. }
  2206. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2207. //var num1 int64
  2208. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2209. //fmt.Println(num1)
  2210. //sub := float64(num1 / 3600)
  2211. //fmt.Println(sub)
  2212. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2213. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2214. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2215. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2216. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2217. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2218. if adminUserInfo.Org.Id != 10375 {
  2219. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2220. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2221. }
  2222. if adminUserInfo.Org.Id != 10445 {
  2223. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2224. }
  2225. //北方营口医院
  2226. if adminUserInfo.Org.Id == 10445 {
  2227. //获取最后一条透析处方数据
  2228. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2229. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2230. } else {
  2231. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2232. }
  2233. //新化博翔
  2234. if adminUserInfo.Org.Id == 10447 {
  2235. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2236. }
  2237. //阳春
  2238. if adminUserInfo.Org.Id == 10485 {
  2239. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2240. }
  2241. if adminUserInfo.Org.Id == 10551 {
  2242. //获取最后一条透析处方数据
  2243. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2244. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2245. }
  2246. if adminUserInfo.Org.Id == 10580 {
  2247. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2248. }
  2249. }
  2250. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10215 || adminUserInfo.Org.Id == 10233 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 10243 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10414 || adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10223 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 {
  2251. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2252. if evaluation.SystolicBloodPressure == 0 {
  2253. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2254. pre := models.PredialysisEvaluation{
  2255. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2256. }
  2257. fmt.Println("prew", pre)
  2258. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2259. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2260. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2261. redis := service.RedisClient()
  2262. redis.Set(key, "", time.Second)
  2263. redis.Set(keyOne, "", time.Second)
  2264. defer redis.Close()
  2265. fmt.Println(getNurseErr)
  2266. }
  2267. if evaluation.DiastolicBloodPressure == 0 {
  2268. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2269. pres := models.PredialysisEvaluation{
  2270. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2271. }
  2272. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2273. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2274. redis := service.RedisClient()
  2275. redis.Set(key, "", time.Second)
  2276. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2277. redis.Set(keyOne, "", time.Second)
  2278. defer redis.Close()
  2279. fmt.Println(getNurseErr)
  2280. }
  2281. if evaluation.PulseFrequency == 0 {
  2282. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2283. press := models.PredialysisEvaluation{
  2284. PulseFrequency: evaluation.PulseFrequency,
  2285. }
  2286. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2287. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2288. redis := service.RedisClient()
  2289. redis.Set(key, "", time.Second)
  2290. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2291. redis.Set(keyOne, "", time.Second)
  2292. defer redis.Close()
  2293. fmt.Println(getNurseErr)
  2294. }
  2295. if evaluation.Temperature == 0 {
  2296. evaluation.Temperature = fmonitorRecords.Temperature
  2297. press := models.PredialysisEvaluation{
  2298. Temperature: evaluation.Temperature,
  2299. }
  2300. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2301. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2302. redis := service.RedisClient()
  2303. redis.Set(key, "", time.Second)
  2304. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2305. redis.Set(keyOne, "", time.Second)
  2306. defer redis.Close()
  2307. fmt.Println(getNurseErr)
  2308. }
  2309. }
  2310. if adminUserInfo.Org.Id == 9583 {
  2311. //获取透析处方的最后一条数据
  2312. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2313. if diaerr != nil {
  2314. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2316. return
  2317. }
  2318. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2319. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2320. }
  2321. }
  2322. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2323. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2324. }
  2325. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2326. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2327. }
  2328. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2329. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2330. }
  2331. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2332. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2333. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2334. }
  2335. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2336. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2337. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2338. }
  2339. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2340. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2341. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2342. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2343. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2344. }
  2345. if lastAssessmentAfterDislysis != nil {
  2346. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2347. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2348. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2349. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2350. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2351. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2352. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2353. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2354. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2355. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2356. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2357. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2358. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2359. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2360. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2361. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2362. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2363. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2364. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2365. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2366. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2367. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2368. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2369. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2370. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2371. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2372. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2373. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2374. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2375. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2376. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2377. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2378. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2379. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2380. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2381. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2382. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2383. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2384. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2385. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2386. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2387. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2388. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2389. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2390. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2391. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2392. if tempassessmentAfterDislysis.PatientId == 18695 {
  2393. tempassessmentAfterDislysis.ActualDisplacement = 0
  2394. }
  2395. if adminUserInfo.Org.Id != 10375 {
  2396. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2397. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2398. }
  2399. }
  2400. finish := models.XtDialysisFinish{
  2401. IsFinish: 1,
  2402. UserOrgId: adminUserInfo.Org.Id,
  2403. Status: 1,
  2404. Ctime: time.Now().Unix(),
  2405. Mtime: 0,
  2406. Module: 9,
  2407. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2408. Sourse: 1,
  2409. PatientId: tempassessmentAfterDislysis.PatientId,
  2410. }
  2411. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2412. if dialysisFinish.ID == 0 {
  2413. service.CreateDialysisFinish(finish)
  2414. }
  2415. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2416. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2417. redis := service.RedisClient()
  2418. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2419. redis.Set(keyOne, "", time.Second)
  2420. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2421. redis.Set(keyTwo, "", time.Second)
  2422. defer redis.Close()
  2423. //清空key 值
  2424. redis.Set(key, "", time.Second)
  2425. if err != nil {
  2426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2427. return
  2428. }
  2429. if dialysisOrder == nil {
  2430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2431. return
  2432. }
  2433. if dialysisOrder.Stage == 2 {
  2434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2435. return
  2436. }
  2437. if dialysisOrder.Stage == 1 {
  2438. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2439. finish := models.XtDialysisFinish{
  2440. IsFinish: 1,
  2441. UserOrgId: adminUserInfo.Org.Id,
  2442. Status: 1,
  2443. Ctime: time.Now().Unix(),
  2444. Mtime: 0,
  2445. Module: 8,
  2446. RecordDate: recordDate.Unix(),
  2447. Sourse: 1,
  2448. PatientId: id,
  2449. }
  2450. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2451. if dialysisFinish.ID == 0 {
  2452. service.CreateDialysisFinish(finish)
  2453. }
  2454. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2455. redis := service.RedisClient()
  2456. defer redis.Close()
  2457. //清空key 值
  2458. redis.Set(key, "", time.Second)
  2459. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2460. redis.Set(keyOne, "", time.Second)
  2461. //结束时候透析次数加1
  2462. service.UpdateSolutionByPatientId(id)
  2463. //下机完自动消毒,针对长沙南雅
  2464. if dialysisOrder.Stage == 1 {
  2465. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2466. //根据床位号获取设备型号
  2467. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2468. //查询使用消毒最后一条消毒记录
  2469. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2470. fmt.Println("err", err)
  2471. if err == gorm.ErrRecordNotFound {
  2472. //查找排班
  2473. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2474. //查询改设备是否有消毒计划
  2475. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2476. //根据床位号获取设备id
  2477. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2478. //查询病人信息
  2479. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2480. var con = ""
  2481. if patients.IsInfectious == 0 {
  2482. con = ""
  2483. }
  2484. if patients.IsInfectious == 1 {
  2485. con = "无"
  2486. }
  2487. if patients.IsInfectious == 2 {
  2488. con = "有"
  2489. }
  2490. if errcode == nil {
  2491. var end_time int64
  2492. end_time = endDate.Unix() + plan.DisinfecTime*60
  2493. //新增消毒
  2494. information := models.DeviceInformation{
  2495. Date: dialysisOrder.DialysisDate,
  2496. Zone: dialysisOrder.ZoneId,
  2497. Class: dialysisOrder.SchedualType,
  2498. BedNumber: dialysisOrder.BedID,
  2499. PatientId: dialysisOrder.PatientId,
  2500. DialysisMode: scheduleByPatient.ModeId,
  2501. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2502. Disinfection: 1,
  2503. DialysisConcentration: 1,
  2504. DisinfectionStatus: 1,
  2505. Move: 1,
  2506. UserOrgId: dialysisOrder.UserOrgId,
  2507. DisinfectType: plan.Way,
  2508. DisinfectantType: plan.MachineDisinfectant,
  2509. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2510. Disinfectant: plan.Disinfectant,
  2511. Ctime: time.Now().Unix(),
  2512. Status: 1,
  2513. SignName: nurseID,
  2514. EquimentId: addmacher.ID,
  2515. DisinfectionResidue: 2,
  2516. Bed: addmacher.BedNumber,
  2517. StartTime: dialysisOrder.StartTime,
  2518. EndTime: dialysisOrder.EndTime,
  2519. Contagion: con,
  2520. WeightLoss: 0,
  2521. Hyperfiltratio: 0,
  2522. DialysisHour: "",
  2523. MachineRun: 1,
  2524. DisinfecStartime: endDate.Unix(),
  2525. DisinfecEndtime: end_time,
  2526. }
  2527. err := service.CreateInformationTwo(&information)
  2528. fmt.Println("报错", err)
  2529. }
  2530. }
  2531. }
  2532. }
  2533. dialysisOrder.Stage = 2
  2534. dialysisOrder.FinishNurse = nurseID
  2535. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2536. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2537. dialysisOrder.EndTime = endDate.Unix()
  2538. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2539. // 长沙南雅需求
  2540. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2541. //获取最后1条监测的数据
  2542. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2543. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2544. var accumulatedBloodVolume float64
  2545. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2546. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2547. fmt.Println(err)
  2548. // 查询未执行的医嘱
  2549. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2550. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2551. for _, item := range doctorAdvice {
  2552. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2553. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2554. redis := service.RedisClient()
  2555. //清空key 值
  2556. redis.Set(key, "", time.Second)
  2557. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2558. redis.Set(keyTwo, "", time.Second)
  2559. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2560. redis.Set(keyThree, "", time.Second)
  2561. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2562. theTime := toTime.Format("2006-01-02")
  2563. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2564. redis.Set(keyFour, "", time.Second)
  2565. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2566. redis.Set(keyFive, "", time.Second)
  2567. defer redis.Close()
  2568. }
  2569. }
  2570. go func() {
  2571. ssoDomain := beego.AppConfig.String("call_domain")
  2572. api := ssoDomain + "/index/downpatient"
  2573. values := make(url.Values)
  2574. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2575. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2576. values.Set("patient_id", strconv.FormatInt(id, 10))
  2577. http.PostForm(api, values)
  2578. }()
  2579. if err == nil {
  2580. c.ServeSuccessJSON(map[string]interface{}{
  2581. "dialysisOrder": dialysisOrder,
  2582. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2583. })
  2584. } else {
  2585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2586. }
  2587. }
  2588. }
  2589. func (c *DialysisAPIController) GetAllZone() {
  2590. adminUserInfo := c.GetMobileAdminUserInfo()
  2591. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2592. if err == nil {
  2593. c.ServeSuccessJSON(map[string]interface{}{
  2594. "zone": zone,
  2595. })
  2596. }
  2597. }
  2598. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2599. adminUserInfo := c.GetMobileAdminUserInfo()
  2600. page, _ := c.GetInt64("page", 1)
  2601. limit, _ := c.GetInt64("limit", 10)
  2602. schedulType, _ := c.GetInt64("schedul_type", 0)
  2603. startTime, _ := c.GetInt64("schedul_time", 0)
  2604. partitionType, _ := c.GetInt64("partition_type", 0)
  2605. keywords := c.GetString("keywords")
  2606. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2607. if err == nil {
  2608. c.ServeSuccessJSON(map[string]interface{}{
  2609. "schedule": dialysisSchedule,
  2610. })
  2611. }
  2612. return
  2613. }
  2614. // /m/api/dialysis/start [post]
  2615. // @param patient_id:int
  2616. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2617. // @param nurse:int 上机护士
  2618. // @param bed:int 床位号
  2619. func (this *DialysisAPIController) StartDialysis() {
  2620. patientID, _ := this.GetInt64("patient_id")
  2621. recordDateStr := this.GetString("record_date")
  2622. nurseID, _ := this.GetInt64("start_nurse")
  2623. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2624. blood_drawing, _ := this.GetInt64("blood_drawing")
  2625. schedual_type, _ := this.GetInt64("schedual_type")
  2626. bedID, _ := this.GetInt64("bed")
  2627. start_time := this.GetString("start_time")
  2628. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2629. change_nurse, _ := this.GetInt64("change_nurse")
  2630. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2631. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2632. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2633. puncture_needle := this.GetString("puncture_needle")
  2634. puncture_way := this.GetString("puncture_way")
  2635. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2636. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2637. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2638. zone_id, _ := this.GetInt64("zone_id")
  2639. elecsign := this.GetString("url")
  2640. nuclein_date_str := this.GetString("nuclein_date_str")
  2641. schedule_remark := this.GetString("schedule_remark")
  2642. order_remark := this.GetString("order_remark")
  2643. catheter_operation := this.GetString("catheter_operation")
  2644. blood_flow_volume := this.GetString("blood_flow_volume")
  2645. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2647. return
  2648. }
  2649. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2650. if parseStartDateErr != nil {
  2651. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2652. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2653. return
  2654. }
  2655. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2656. if parseErr != nil {
  2657. this.ErrorLog("时间解析失败:%v", parseErr)
  2658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2659. return
  2660. }
  2661. adminUserInfo := this.GetMobileAdminUserInfo()
  2662. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2663. if getPatientErr != nil {
  2664. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2666. return
  2667. } else if patient == nil {
  2668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2669. return
  2670. }
  2671. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2672. if getNurseErr != nil {
  2673. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2674. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2675. return
  2676. } else if nurse == nil {
  2677. this.ErrorLog("护士不存在")
  2678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2682. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2683. if getDeviceNumberErr != nil {
  2684. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2685. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2686. return
  2687. } else if deviceNumber == nil {
  2688. this.ErrorLog("床位号不存在")
  2689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2690. return
  2691. }
  2692. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2693. if getRecordErr != nil {
  2694. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2696. return
  2697. } else if dialysisRecord != nil {
  2698. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2699. return
  2700. }
  2701. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2702. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2703. timeLayout := "2006-01-02 15:04:05"
  2704. loc, _ := time.LoadLocation("Local")
  2705. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2706. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2707. schedulestartTime := theStartTime.Unix()
  2708. scheduleendTime := theEndTime.Unix()
  2709. var theNucleinDate int64
  2710. timeLayoutOne := "2006-01-02"
  2711. if len(nuclein_date_str) > 0 {
  2712. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2713. if err != nil {
  2714. utils.ErrorLog(err.Error())
  2715. }
  2716. theNucleinDate = theTime.Unix()
  2717. }
  2718. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2719. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2720. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2721. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2722. //查询该床位是否有人用了
  2723. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2724. if err == gorm.ErrRecordNotFound { //空床位
  2725. // 修改了床位逻辑
  2726. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2727. if daySchedule.ID > 0 {
  2728. daySchedule.PartitionId = deviceNumber.ZoneID
  2729. daySchedule.BedId = bedID
  2730. daySchedule.ScheduleType = schedual_type
  2731. daySchedule.UpdatedTime = time.Now().Unix()
  2732. xtSchedule := models.Schedule{
  2733. PartitionId: deviceNumber.ZoneID,
  2734. BedId: bedID,
  2735. ScheduleType: schedual_type,
  2736. UpdatedTime: time.Now().Unix(),
  2737. }
  2738. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2739. if err != nil {
  2740. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2741. return
  2742. }
  2743. }
  2744. } else if err == nil {
  2745. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2746. if order.ID > 0 { //该机位被其他人占用了
  2747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2748. return
  2749. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2750. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2751. if daySchedule.ID > 0 {
  2752. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2753. if err != nil {
  2754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2755. return
  2756. }
  2757. }
  2758. }
  2759. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2761. return
  2762. }
  2763. //else if order.ID == 0 { //该床位没被占用
  2764. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2765. // if daySchedule.ID > 0 {
  2766. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2767. // //daySchedule.BedId = bedID
  2768. // //daySchedule.ScheduleType = schedual_type
  2769. // //daySchedule.UpdatedTime = time.Now().Unix()
  2770. // //err := service.UpdateSchedule(&daySchedule)
  2771. // xtSchedule := models.Schedule{
  2772. // PartitionId: deviceNumber.ZoneID,
  2773. // BedId: bedID,
  2774. // ScheduleType: schedual_type,
  2775. // UpdatedTime: time.Now().Unix(),
  2776. // }
  2777. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2778. // if err != nil {
  2779. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2780. // return
  2781. // }
  2782. // }
  2783. //}
  2784. //}
  2785. } else if err != nil {
  2786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2787. return
  2788. }
  2789. // 查询信息规挡的设置天数
  2790. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2791. if infor.ID > 0 && infor.WeekDay > 0 {
  2792. var cha_time int64
  2793. timeNowStr := time.Now().Format("2006-01-02")
  2794. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2795. //今日的日期减去设置的日期
  2796. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2797. if cha_time >= recordDate.Unix() {
  2798. //查询审核是否允许
  2799. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2800. //申请状态不允许的情况 拒绝修改
  2801. if infor.ApplicationStatus != 1 {
  2802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2803. return
  2804. }
  2805. }
  2806. }
  2807. dialysisRecord = &models.DialysisOrder{
  2808. DialysisDate: recordDate.Unix(),
  2809. UserOrgId: adminUserInfo.Org.Id,
  2810. PatientId: patientID,
  2811. Stage: 1,
  2812. BedID: bedID,
  2813. StartNurse: nurseID,
  2814. Status: 1,
  2815. StartTime: startDate.Unix(),
  2816. CreatedTime: time.Now().Unix(),
  2817. UpdatedTime: time.Now().Unix(),
  2818. PunctureNurse: puncture_nurse,
  2819. Creator: adminUserInfo.AdminUser.Id,
  2820. Modifier: adminUserInfo.AdminUser.Id,
  2821. SchedualType: schedual_type,
  2822. WashpipeNurse: washpipe_nurse,
  2823. ChangeNurse: change_nurse,
  2824. DifficultPunctureNurse: difficult_puncture_nurse,
  2825. NewFistulaNurse: new_fistula_nurse,
  2826. ZoneId: zone_id,
  2827. QualityNurseId: quality_nurse_id,
  2828. PunctureNeedle: puncture_needle,
  2829. PunctureWay: puncture_way,
  2830. DialysisIrrigation: dialysis_irrigation,
  2831. DialysisDialyszers: dialysis_dialyszers,
  2832. BloodAccessId: blood_access_id,
  2833. Url: elecsign,
  2834. NucleinDate: theNucleinDate,
  2835. ScheduleRemark: schedule_remark,
  2836. OrderRemark: order_remark,
  2837. CatheterOperation: catheter_operation,
  2838. BloodFlowVolume: blood_flow_volume,
  2839. }
  2840. //查询该床位是否有人用了
  2841. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2842. if errorscode == gorm.ErrRecordNotFound {
  2843. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2844. finish := models.XtDialysisFinish{
  2845. IsFinish: 1,
  2846. UserOrgId: adminUserInfo.Org.Id,
  2847. Status: 1,
  2848. Ctime: time.Now().Unix(),
  2849. Mtime: 0,
  2850. Module: 6,
  2851. RecordDate: schedulestartTime,
  2852. Sourse: 1,
  2853. PatientId: patientID,
  2854. }
  2855. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2856. if dialysisFinish.ID == 0 {
  2857. service.CreateDialysisFinish(finish)
  2858. }
  2859. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2860. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2861. //统计该患者总次数
  2862. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2863. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2864. }
  2865. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2866. //统计该患者总次数
  2867. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2868. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2869. }
  2870. redis := service.RedisClient()
  2871. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2872. redis.Set(key, "", time.Second)
  2873. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2874. //清空key 值
  2875. redis.Set(keyOne, "", time.Second)
  2876. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2877. //清空key 值
  2878. redis.Set(keyTwo, "", time.Second)
  2879. if createErr != nil {
  2880. this.ErrorLog("上机失败:%v", createErr)
  2881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2882. return
  2883. }
  2884. }
  2885. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2886. var tempdispose string
  2887. // 只针对中能建
  2888. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2889. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2890. }
  2891. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2892. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2893. }
  2894. var ultrafiltration_rate float64
  2895. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2896. //后期预增脱水量
  2897. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2898. if prescription.ID > 0 {
  2899. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2900. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2901. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2902. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2903. }
  2904. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2905. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2906. }
  2907. //针对医师汇
  2908. if adminUserInfo.Org.Id == 10121 {
  2909. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2910. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2911. }
  2912. //针对通道
  2913. if adminUserInfo.Org.Id == 10234 {
  2914. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2915. }
  2916. //针对监利大垸医院
  2917. if template.TemplateId == 41 {
  2918. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2919. }
  2920. //针对肇庆三鹤血液透析中心
  2921. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2922. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2923. }
  2924. if adminUserInfo.Org.Id == 10469 {
  2925. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2926. }
  2927. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2928. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2929. }
  2930. // 只针对方济医院
  2931. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2932. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2933. ultrafiltration_rate = value
  2934. }
  2935. //针对
  2936. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2937. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2938. ultrafiltration_rate = ultrafiltration_rate / 1000
  2939. }
  2940. if adminUserInfo.Org.Id == 10551 {
  2941. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2942. ultrafiltration_rate = ultrafiltration_rate / 1000
  2943. }
  2944. if adminUserInfo.Org.Id == 10612 {
  2945. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2946. ultrafiltration_rate = ultrafiltration_rate / 1000
  2947. }
  2948. }
  2949. }
  2950. record := models.MonitoringRecord{
  2951. UserOrgId: adminUserInfo.Org.Id,
  2952. PatientId: patientID,
  2953. DialysisOrderId: dialysisRecord.ID,
  2954. MonitoringDate: schedulestartTime,
  2955. OperateTime: startDate.Unix(),
  2956. // MonitoringTime: recordTime,
  2957. MonitoringNurse: nurseID,
  2958. Dispose: tempdispose,
  2959. UltrafiltrationRate: ultrafiltration_rate,
  2960. UltrafiltrationVolume: 0,
  2961. Status: 1,
  2962. CreatedTime: time.Now().Unix(),
  2963. UpdatedTime: time.Now().Unix(),
  2964. }
  2965. //只针对广慈医院
  2966. if template.TemplateId == 26 || template.TemplateId == 25 || template.TemplateId == 28 || adminUserInfo.Org.Id == 9987 || adminUserInfo.Org.Id == 9526 || template.TemplateId == 32 || adminUserInfo.Org.Id == 9918 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 4 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10517 {
  2967. // 查询病人是否有透前评估数据
  2968. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2969. //如果有数据就插入
  2970. if errcode == nil {
  2971. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2972. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2973. record.BreathingRate = befor.BreathingRate
  2974. record.PulseFrequency = befor.PulseFrequency
  2975. record.Temperature = befor.Temperature
  2976. }
  2977. }
  2978. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2979. if newdialysisRecord.ID > 0 {
  2980. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2981. record.Temperature = 36.5
  2982. record.ArterialPressure = -100
  2983. record.DialysateTemperature = 36.5
  2984. record.Conductivity = 14
  2985. record.BreathingRate = "20"
  2986. record.VenousPressure = 80
  2987. record.TransmembranePressure = 60
  2988. record.Dispose = catheter_operation
  2989. }
  2990. //针对新化博翔
  2991. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2992. record.BloodOxygenSaturation = "99"
  2993. record.Conductivity = 14
  2994. record.DialysateTemperature = 36.5
  2995. record.BreathingRate = "20"
  2996. }
  2997. //针对兰溪人民医院的需求
  2998. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2999. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3000. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3001. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3002. record.Temperature = befor.Temperature
  3003. record.PulseFrequency = befor.PulseFrequency
  3004. record.BreathingRate = befor.BreathingRate
  3005. }
  3006. //新化博翔
  3007. if adminUserInfo.Org.Id == 10447 {
  3008. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3009. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3010. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3011. record.BreathingRate = befor.BreathingRate
  3012. }
  3013. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3014. record.PulseFrequency = 80
  3015. record.Temperature = 36.5
  3016. }
  3017. //诊断灵山圣康
  3018. if adminUserInfo.Org.Id == 10375 {
  3019. record.Conductivity = 13.8
  3020. record.DialysateTemperature = 37
  3021. record.DialysateFlow = 500
  3022. record.BloodFlowVolume = 200
  3023. record.BreathingRate = "18"
  3024. record.SodiumConcentration = 140
  3025. }
  3026. //江成肾病医院
  3027. if adminUserInfo.Org.Id == 10517 {
  3028. record.SodiumConcentration = 138
  3029. record.DialysateTemperature = 36.5
  3030. }
  3031. err := service.CreateMonitor(&record)
  3032. //记录日志
  3033. byterequest, _ := json.Marshal(record)
  3034. monitorRecordLog := models.XtMonitorRecordLog{
  3035. RecordDate: record.MonitoringDate,
  3036. PatientId: record.PatientId,
  3037. Module: 1,
  3038. AdminUserId: adminUserInfo.AdminUser.Id,
  3039. Ctime: time.Now().Unix(),
  3040. Mtime: 0,
  3041. Status: 1,
  3042. UserOrgId: record.UserOrgId,
  3043. ErrLog: string(byterequest),
  3044. Source: "执行上机时新增监测",
  3045. }
  3046. service.CreateMonitorRecordLog(monitorRecordLog)
  3047. finish := models.XtDialysisFinish{
  3048. IsFinish: 1,
  3049. UserOrgId: adminUserInfo.Org.Id,
  3050. Status: 1,
  3051. Ctime: time.Now().Unix(),
  3052. Mtime: 0,
  3053. Module: 7,
  3054. RecordDate: schedulestartTime,
  3055. Sourse: 1,
  3056. PatientId: patientID,
  3057. }
  3058. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3059. if dialysisFinish.ID == 0 {
  3060. service.CreateDialysisFinish(finish)
  3061. }
  3062. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3063. redis := service.RedisClient()
  3064. //清空key 值
  3065. redis.Set(key, "", time.Second)
  3066. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3067. redis.Set(keyOne, "", time.Second)
  3068. defer redis.Close()
  3069. if err != nil {
  3070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3071. return
  3072. }
  3073. }
  3074. go func() {
  3075. ssoDomain := beego.AppConfig.String("call_domain")
  3076. api := ssoDomain + "/index/uppatient"
  3077. values := make(url.Values)
  3078. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3079. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3080. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3081. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3082. http.PostForm(api, values)
  3083. }()
  3084. this.ServeSuccessJSON(map[string]interface{}{
  3085. "dialysis_order": newdialysisRecord,
  3086. "monitor": record,
  3087. })
  3088. return
  3089. }
  3090. func (c *DialysisAPIController) PostSolution() {
  3091. id, _ := c.GetInt64("patient", 0)
  3092. recordDateStr := c.GetString("record_date")
  3093. if id <= 0 {
  3094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3095. return
  3096. }
  3097. adminUserInfo := c.GetMobileAdminUserInfo()
  3098. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3099. if patient.ID == 0 {
  3100. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3101. return
  3102. }
  3103. if len(recordDateStr) == 0 {
  3104. recordDateStr = time.Now().Format("2006-01-02")
  3105. }
  3106. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3107. if parseDateErr != nil {
  3108. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3110. return
  3111. }
  3112. mode_id, _ := c.GetInt64("mode_id", 0)
  3113. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3114. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3115. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3116. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3117. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3118. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3119. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3120. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3121. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3122. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3123. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3124. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3125. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3126. kalium, _ := c.GetFloat("kalium", 0)
  3127. sodium, _ := c.GetFloat("sodium", 0)
  3128. calcium, _ := c.GetFloat("calcium", 0)
  3129. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3130. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3131. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3132. glucose, _ := c.GetFloat("glucose", 0)
  3133. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3134. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3135. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3136. conductivity, _ := c.GetFloat("conductivity", 0)
  3137. remark := c.GetString("remark")
  3138. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3139. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3140. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3141. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3142. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3143. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3144. special_medicine_other := c.GetString("special_medicine_other")
  3145. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3146. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3147. blood_access, _ := c.GetInt64("blood_access", 0)
  3148. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3149. body_fluid_other := c.GetString("body_fluid_other")
  3150. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3151. niprocart, _ := c.GetInt64("niprocart", 0)
  3152. jms, _ := c.GetInt64("jms", 0)
  3153. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3154. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3155. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3156. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3157. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3158. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3159. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3160. injector, _ := c.GetInt64("injector", 0)
  3161. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3162. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3163. safe_package, _ := c.GetInt64("package", 0)
  3164. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3165. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3166. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3167. blood := c.GetString("blood")
  3168. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3169. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3170. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3171. displace_speed := c.GetString("displace_speed")
  3172. illness, _ := c.GetInt64("illness")
  3173. amylaceum := c.GetString("amylaceum")
  3174. single_time := c.GetString("single_time")
  3175. single_water := c.GetString("single_water")
  3176. replacement_flow := c.GetString("replacement_flow")
  3177. plasma_separator := c.GetString("plasma_separator")
  3178. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3179. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3180. oxygen_flow := c.GetString("oxygen_flow")
  3181. oxygen_time := c.GetString("oxygen_time")
  3182. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3183. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3184. puncture_needle := c.GetString("puncture_needle")
  3185. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3186. epo := c.GetString("epo")
  3187. epo_count, _ := c.GetFloat("epo_count", 0)
  3188. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3189. pre_impulse := c.GetString("pre_impulse")
  3190. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3191. admin_user_id, _ := c.GetInt64("admin_user_id")
  3192. is_water := c.GetString("is_water")
  3193. add_amount, _ := c.GetFloat("add_amount")
  3194. reduce_amount, _ := c.GetFloat("reduce_amount")
  3195. prescribing_number, _ := c.GetFloat("prescribing_number")
  3196. treatment_remark := c.GetString("treatment_remark")
  3197. prescription_sodium := c.GetString("prescription_sodium")
  3198. start_sodium := c.GetString("start_sodium")
  3199. sodium_curve := c.GetString("sodium_curve")
  3200. var is_war int64
  3201. if is_water == "是" {
  3202. is_war = 1
  3203. }
  3204. if is_water == "否" {
  3205. is_war = 2
  3206. }
  3207. if is_water == "请选择" {
  3208. is_war = 0
  3209. }
  3210. drhy_water := c.GetString("drhy_water")
  3211. dry_water_hour := c.GetString("dry_water_hour")
  3212. water_machine := c.GetString("water_machine")
  3213. dialysis_remark := c.GetString("dialysis_remark")
  3214. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3215. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3216. prescription_water, _ := c.GetFloat("prescription_water")
  3217. dialysis_strainer := c.GetString("dialysis_strainer")
  3218. chaptalization := c.GetString("chaptalization")
  3219. washing_time := c.GetString("washing_time")
  3220. warsh_count := c.GetString("warsh_count")
  3221. blood_access_part_id := c.GetString("blood_access_part_id")
  3222. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3223. dialyzate := c.GetString("dialyzate")
  3224. if mode_id > 0 {
  3225. var str string
  3226. //查找该机构用的是什么透析器
  3227. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3228. if filedConfig.ID > 0 {
  3229. str = dialyzerPerfusionApparatus
  3230. } else {
  3231. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3232. }
  3233. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3234. }
  3235. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3236. //
  3237. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3238. // if appRole.UserType == 3 {
  3239. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3240. // if getPermissionErr != nil {
  3241. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3242. // return
  3243. // } else if headNursePermission == nil {
  3244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3245. // return
  3246. // }
  3247. // }
  3248. //}
  3249. // 查询信息规挡的设置天数
  3250. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3251. if infor.ID > 0 && infor.WeekDay > 0 {
  3252. var cha_time int64
  3253. timeNowStr := time.Now().Format("2006-01-02")
  3254. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3255. //今日的日期减去设置的日期
  3256. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3257. if cha_time >= recordDate.Unix() {
  3258. //查询审核是否允许
  3259. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3260. //申请状态不允许的情况 拒绝修改
  3261. if infor.ApplicationStatus != 1 {
  3262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3263. return
  3264. }
  3265. }
  3266. }
  3267. prescription := models.DialysisPrescription{
  3268. UserOrgId: adminUserInfo.Org.Id,
  3269. PatientId: id,
  3270. RecordDate: recordDate.Unix(),
  3271. ModeId: mode_id,
  3272. DialysisDuration: dialysis_duration,
  3273. Dialyzer: dialyzer,
  3274. PerfusionApparatus: perfusion_apparatus,
  3275. BloodFlowVolume: blood_flow_volume,
  3276. DewaterAmount: dewater_amount,
  3277. DisplaceLiqui: displace_liqui,
  3278. ReplacementWay: replacement_way,
  3279. Anticoagulant: anticoagulant,
  3280. AnticoagulantShouji: anticoagulant_shouji,
  3281. AnticoagulantWeichi: anticoagulant_weichi,
  3282. AnticoagulantZongliang: anticoagulant_zongliang,
  3283. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3284. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3285. Kalium: kalium,
  3286. Sodium: sodium,
  3287. Calcium: calcium,
  3288. Bicarbonate: bicarbonate,
  3289. Glucose: glucose,
  3290. // DryWeight: dry_weight,
  3291. DialysateFlow: dialysate_flow,
  3292. DialysateTemperature: dialysate_temperature,
  3293. Conductivity: conductivity,
  3294. Remark: remark,
  3295. Status: 1,
  3296. CreatedTime: time.Now().Unix(),
  3297. UpdatedTime: time.Now().Unix(),
  3298. DialysisDurationMinute: dialysisDurationMinute,
  3299. DialysisDurationHour: dialysisDurationHour,
  3300. TargetUltrafiltration: targetUltrafiltration,
  3301. DialysateFormulation: dialysateFormulation,
  3302. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3303. BodyFluid: body_fluid,
  3304. SpecialMedicine: special_medicine,
  3305. SpecialMedicineOther: special_medicine_other,
  3306. DisplaceLiquiPart: displace_liqui_part,
  3307. DisplaceLiquiValue: displace_liqui_value,
  3308. BloodAccess: blood_access,
  3309. Ultrafiltration: ultrafiltration,
  3310. BodyFluidOther: body_fluid_other,
  3311. ReplacementTotal: replacement_total,
  3312. Niprocart: niprocart,
  3313. Jms: jms,
  3314. FistulaNeedleSet: fistula_needle_set,
  3315. FistulaNeedleSet16: fistula_needle_set_16,
  3316. Hemoperfusion: hemoperfusion,
  3317. DialyserSterilised: dialyser_sterilised,
  3318. Filtryzer: filtryzer,
  3319. TargetKtv: target_ktv,
  3320. Dialyzers: dialyzers,
  3321. Injector: injector,
  3322. Bloodlines: bloodlines,
  3323. TubingHemodialysis: tubing_hemodialysis,
  3324. Package: safe_package,
  3325. ALiquid: a_liquid,
  3326. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3327. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3328. Blood: blood,
  3329. DialysisDialyszers: dialysis_dialyszers,
  3330. DialysisIrrigation: dialysis_irrigation,
  3331. AntioxidantCommodityName: antioxidant_commodity_name,
  3332. DisplaceSpeed: displace_speed,
  3333. Illness: illness,
  3334. Amylaceum: amylaceum,
  3335. SingleWater: single_water,
  3336. SingleTime: single_time,
  3337. ReplacementFlow: replacement_flow,
  3338. PlasmaSeparator: plasma_separator,
  3339. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3340. OxygenUptake: oxygen_uptake,
  3341. OxygenTime: oxygen_time,
  3342. OxygenFlow: oxygen_flow,
  3343. HemodialysisPipelines: hemodialysis_pipelines,
  3344. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3345. PunctureNeedle: puncture_needle,
  3346. PunctureNeedleCount: puncture_needle_count,
  3347. Epo: epo,
  3348. EpoCount: epo_count,
  3349. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3350. PreImpulse: impulse,
  3351. AdminUserId: admin_user_id,
  3352. IsWater: is_war,
  3353. DrhyWater: drhy_water,
  3354. DryWaterHour: dry_water_hour,
  3355. WaterMachine: water_machine,
  3356. AddAmount: add_amount,
  3357. ReduceAmount: reduce_amount,
  3358. DialysisRemark: dialysis_remark,
  3359. PrescribingNumber: prescribing_number,
  3360. PrescriptionSodium: prescription_sodium,
  3361. StartSodium: start_sodium,
  3362. SodiumCurve: sodium_curve,
  3363. TreatmentRemark: treatment_remark,
  3364. DialysisFluidFlow: dialysis_fluid_flow,
  3365. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3366. PrescriptionWater: prescription_water,
  3367. DialysisStrainer: dialysis_strainer,
  3368. Chaptalization: chaptalization,
  3369. WashingTime: washing_time,
  3370. WarshCount: warsh_count,
  3371. BloodAccessPartId: blood_access_part_id,
  3372. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3373. Dialyzate: dialyzate,
  3374. }
  3375. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3376. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3377. //
  3378. if appRole.UserType == 2 || appRole.UserType == 1 {
  3379. prescription_doctor = adminUserInfo.AdminUser.Id
  3380. prescription.PrescriptionDoctor = prescription_doctor
  3381. }
  3382. if dialysisPrescription.ID == 0 { //新增
  3383. prescription.Creater = adminUserInfo.AdminUser.Id
  3384. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3385. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3386. }
  3387. } else { //修改
  3388. if dialysisPrescription.Creater == 0 {
  3389. prescription.Creater = adminUserInfo.AdminUser.Id
  3390. } else {
  3391. prescription.Creater = dialysisPrescription.Creater
  3392. if adminUserInfo.Org.Id == 9882 {
  3393. if appRole.UserType == 2 || appRole.UserType == 1 {
  3394. prescription.Creater = adminUserInfo.AdminUser.Id
  3395. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3396. }
  3397. }
  3398. }
  3399. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3400. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3401. }
  3402. //if/**/
  3403. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3404. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3405. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3406. // if getPermissionErr != nil {
  3407. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3408. // return
  3409. // } else if headNursePermission == nil {
  3410. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3411. // return
  3412. // }
  3413. //}
  3414. //prescription.Creater = dialysisPrescription.Creater
  3415. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3416. prescription.Modifier = adminUserInfo.AdminUser.Id
  3417. prescription.ID = dialysisPrescription.ID
  3418. }
  3419. solution := models.DialysisSolution{
  3420. RegistrarsId: adminUserInfo.AdminUser.Id,
  3421. UserOrgId: adminUserInfo.Org.Id,
  3422. Doctor: prescription_doctor,
  3423. PatientId: id,
  3424. ModeId: mode_id,
  3425. DialysisDuration: dialysis_duration,
  3426. PerfusionApparatus: perfusion_apparatus,
  3427. BloodFlowVolume: blood_flow_volume,
  3428. Dewater: dewater_amount,
  3429. DisplaceLiqui: displace_liqui,
  3430. ReplacementWay: replacement_way,
  3431. Anticoagulant: anticoagulant,
  3432. AnticoagulantShouji: anticoagulant_shouji,
  3433. AnticoagulantWeichi: anticoagulant_weichi,
  3434. AnticoagulantZongliang: anticoagulant_zongliang,
  3435. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3436. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3437. Kalium: kalium,
  3438. Sodium: sodium,
  3439. Calcium: calcium,
  3440. Bicarbonate: bicarbonate,
  3441. Glucose: glucose,
  3442. // DryWeight: dry_weight,
  3443. DialysateFlow: dialysate_flow,
  3444. DialysateTemperature: dialysate_temperature,
  3445. Conductivity: conductivity,
  3446. Remark: remark,
  3447. Status: 1,
  3448. CreatedTime: time.Now().Unix(),
  3449. UpdatedTime: time.Now().Unix(),
  3450. DialysisDurationMinute: dialysisDurationMinute,
  3451. DialysisDurationHour: dialysisDurationHour,
  3452. TargetUltrafiltration: targetUltrafiltration,
  3453. DialysateFormulation: dialysateFormulation,
  3454. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3455. BodyFluid: body_fluid,
  3456. SpecialMedicine: special_medicine,
  3457. SpecialMedicineOther: special_medicine_other,
  3458. DisplaceLiquiPart: displace_liqui_part,
  3459. DisplaceLiquiValue: displace_liqui_value,
  3460. BloodAccess: blood_access,
  3461. Ultrafiltration: ultrafiltration,
  3462. BodyFluidOther: body_fluid_other,
  3463. ReplacementTotal: replacement_total,
  3464. TargetKtv: target_ktv,
  3465. DialysisDialyszers: dialysis_dialyszers,
  3466. DialysisIrrigation: dialysis_irrigation,
  3467. HemodialysisPipelines: hemodialysis_pipelines,
  3468. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3469. PunctureNeedle: puncture_needle,
  3470. PunctureNeedleCount: puncture_needle_count,
  3471. Epo: epo,
  3472. EpoCount: epo_count,
  3473. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3474. PreImpulse: impulse,
  3475. SolutionStatus: 1,
  3476. DialysisRemark: dialysis_remark,
  3477. PrescribingNumber: prescribing_number,
  3478. PrescriptionSodium: prescription_sodium,
  3479. StartSodium: start_sodium,
  3480. SodiumCurve: sodium_curve,
  3481. TreatmentRemark: treatment_remark,
  3482. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3483. DialysisFluidFlow: dialysis_fluid_flow,
  3484. PrescriptionWater: prescription_water,
  3485. DialysisStrainer: dialysis_strainer,
  3486. Chaptalization: chaptalization,
  3487. WashingTime: washing_time,
  3488. WarshCount: warsh_count,
  3489. BloodAccessPartId: blood_access_part_id,
  3490. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3491. Dialyzate: dialyzate,
  3492. }
  3493. //针对河间咸的
  3494. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3495. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3496. solution.DisplaceLiquiPart = 0
  3497. solution.DisplaceLiquiValue = 0
  3498. }
  3499. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3500. prescription.DisplaceLiquiPart = 0
  3501. prescription.DisplaceLiquiValue = 0
  3502. }
  3503. }
  3504. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3505. if solution.PrescribingNumber == 0 {
  3506. solution.PrescribingNumber = 1
  3507. }
  3508. if prescription.PrescribingNumber == 0 {
  3509. prescription.PrescribingNumber = 1
  3510. }
  3511. if solution.PrescribingNumber == 0 && id == 14682 {
  3512. solution.PrescribingNumber = 2
  3513. }
  3514. if solution.PrescribingNumber == 0 && id == 18560 {
  3515. solution.PrescribingNumber = 2
  3516. }
  3517. if prescription.PrescribingNumber == 0 && id == 14682 {
  3518. prescription.PrescribingNumber = 2
  3519. }
  3520. if prescription.PrescribingNumber == 0 && id == 18560 {
  3521. prescription.PrescribingNumber = 2
  3522. }
  3523. }
  3524. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3525. //记录日志
  3526. byterequest, _ := json.Marshal(prescription)
  3527. prescriptionLog := models.XtDialysisPrescriptionLog{
  3528. UserOrgId: prescription.UserOrgId,
  3529. Ctime: time.Now().Unix(),
  3530. Mtime: 0,
  3531. ErrLog: string(byterequest),
  3532. AdminUserId: adminUserInfo.AdminUser.Id,
  3533. RecordDate: prescription.RecordDate,
  3534. PatientId: prescription.PatientId,
  3535. Source: "手机端新增长期处方",
  3536. Status: 1,
  3537. }
  3538. service.CreatePrescriptionLog(prescriptionLog)
  3539. finish := models.XtDialysisFinish{
  3540. IsFinish: 1,
  3541. UserOrgId: adminUserInfo.Org.Id,
  3542. Status: 1,
  3543. Ctime: time.Now().Unix(),
  3544. Mtime: 0,
  3545. Module: 1,
  3546. RecordDate: recordDate.Unix(),
  3547. Sourse: 1,
  3548. PatientId: id,
  3549. }
  3550. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3551. if dialysisFinish.ID == 0 {
  3552. service.CreateDialysisFinish(finish)
  3553. }
  3554. //获取最新1条
  3555. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3556. //更新状态
  3557. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3558. //长沙南雅医院,自动生成抗凝剂的临时处方
  3559. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3560. if prescribing_number == 0 {
  3561. prescribing_number = 1
  3562. }
  3563. advice := models.DoctorAdvice{
  3564. UserOrgId: adminUserInfo.Org.Id,
  3565. PatientId: id,
  3566. GroupNo: 0,
  3567. AdviceType: 2,
  3568. RecordDate: recordDate.Unix(),
  3569. AdviceDate: recordDate.Unix(),
  3570. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3571. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3572. AdviceDesc: "",
  3573. ReminderDate: 0,
  3574. SingleDose: prescription.AnticoagulantZongliang,
  3575. SingleDoseUnit: "iu",
  3576. DrugSpec: 0,
  3577. DrugSpecUnit: "",
  3578. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3579. PrescribingNumberUnit: "支",
  3580. DeliveryWay: "静脉注射",
  3581. ExecutionFrequency: "上机前",
  3582. AdviceDoctor: 0,
  3583. Status: 1,
  3584. CreatedTime: time.Now().Unix(),
  3585. UpdatedTime: time.Now().Unix(),
  3586. IsPrescription: 1,
  3587. ExecutionState: 2,
  3588. StopState: 2,
  3589. IsSettle: 2,
  3590. }
  3591. // 查询排班信息
  3592. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3593. if schedulePatient.ID > 0 {
  3594. if schedulePatient.ScheduleType == 1 {
  3595. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3596. }
  3597. if schedulePatient.ScheduleType == 2 {
  3598. advice.StartTime = recordDate.Unix() + 10*60*60
  3599. }
  3600. }
  3601. // 抗凝剂名称
  3602. switch anticoagulant {
  3603. case 1:
  3604. advice.AdviceName = "无肝素"
  3605. break
  3606. case 2:
  3607. advice.AdviceName = "普通肝素"
  3608. break
  3609. case 3:
  3610. advice.AdviceName = "低分子肝素"
  3611. break
  3612. case 4:
  3613. advice.AdviceName = "阿加曲班"
  3614. break
  3615. case 5:
  3616. advice.AdviceName = "枸橼酸钠"
  3617. break
  3618. case 6:
  3619. advice.AdviceName = "低分子肝素钙"
  3620. break
  3621. case 7:
  3622. advice.AdviceName = "低分子肝素钠"
  3623. break
  3624. case 8:
  3625. advice.AdviceName = "依诺肝素"
  3626. break
  3627. case 9:
  3628. advice.AdviceName = "达肝素"
  3629. break
  3630. case 10:
  3631. advice.AdviceName = "体外抗凝"
  3632. break
  3633. case 11:
  3634. advice.AdviceName = "那曲肝素"
  3635. break
  3636. case 12:
  3637. advice.AdviceName = "无抗凝剂"
  3638. break
  3639. }
  3640. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3641. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3642. advice.AdviceDoctor = appRole.AdminUserId
  3643. }
  3644. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3645. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3646. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3647. advice.AdviceName = "低分子肝素钠注射液"
  3648. // 修改患者临时医嘱里的抗凝剂医嘱
  3649. advice.ID = advicePrescription.ID
  3650. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3651. } else {
  3652. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3653. advice.AdviceName = "低分子肝素钠注射液"
  3654. service.CreateDoctorAdvice(&advice)
  3655. }
  3656. }
  3657. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3658. redis := service.RedisClient()
  3659. defer redis.Close()
  3660. //清空key 值
  3661. redis.Set(key, "", time.Second)
  3662. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3663. redis.Set(keyOne, "", time.Second)
  3664. }
  3665. //获取key,清空redis
  3666. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3667. redis := service.RedisClient()
  3668. defer redis.Close()
  3669. //清空key 值
  3670. redis.Set(key, "", time.Second)
  3671. //清空长期医嘱的key
  3672. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3673. redis.Set(soulution_key, "", time.Second)
  3674. //查询最近透析准备表里是否存在 透析器 灌流器
  3675. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3676. redis.Set(keyOne, "", time.Second)
  3677. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3678. redis.Set(keyTwo, "", time.Second)
  3679. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3680. redis.Set(keyThree, "", time.Second)
  3681. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3682. redis.Set(keyFour, "", time.Second)
  3683. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3684. //
  3685. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3686. //
  3687. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3688. //if len(mation)>0{
  3689. // for _, item := range splitStr {
  3690. // for _,it := range mation{
  3691. // if(item == it.SpecificationName){
  3692. //
  3693. // //查询最近一次的透析器
  3694. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3695. //
  3696. // if errcode == gorm.ErrRecordNotFound{
  3697. // //插入数据
  3698. // prepare := models.DialysisBeforePrepare{
  3699. // UserOrgId: adminUserInfo.Org.Id,
  3700. // PatientId: id,
  3701. // RecordDate: recordDate.Unix(),
  3702. // GoodTypeId: it.GoodTypeId,
  3703. // GoodId: it.ID,
  3704. // Count: 1,
  3705. // Ctime: time.Now().Unix(),
  3706. // Creater: adminUserInfo.AdminUser.Id,
  3707. // Status:1,
  3708. //
  3709. // }
  3710. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3711. // fmt.Println("",errcode)
  3712. // }
  3713. // }
  3714. // }
  3715. //
  3716. // }
  3717. //
  3718. // for _, item := range splitIrrigation {
  3719. // for _,it := range mation{
  3720. // if(item == it.SpecificationName){
  3721. // //查询最近一次的透析器
  3722. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3723. // if errcode == gorm.ErrRecordNotFound{
  3724. // //插入数据
  3725. // prepare := models.DialysisBeforePrepare{
  3726. // UserOrgId: adminUserInfo.Org.Id,
  3727. // PatientId: id,
  3728. // RecordDate: recordDate.Unix(),
  3729. // GoodTypeId: it.GoodTypeId,
  3730. // GoodId: it.ID,
  3731. // Count: 1,
  3732. // Ctime: time.Now().Unix(),
  3733. // Creater: adminUserInfo.AdminUser.Id,
  3734. // Status:1,
  3735. //
  3736. // }
  3737. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3738. // fmt.Println(errcode)
  3739. // }
  3740. // }
  3741. // }
  3742. // }
  3743. //}
  3744. c.ServeSuccessJSON(map[string]interface{}{
  3745. "solution": &solution,
  3746. "prescription": &prescription,
  3747. })
  3748. }
  3749. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3750. patient, _ := c.GetInt64("patient", 0)
  3751. adminUserInfo := c.GetMobileAdminUserInfo()
  3752. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3753. c.ServeSuccessJSON(map[string]interface{}{
  3754. "receiveTreatmentAsses": receiveTreatmentAsses,
  3755. })
  3756. }
  3757. func (this *DialysisAPIController) PostSignInfo() {
  3758. patientID, _ := this.GetInt64("patient_id")
  3759. recordDateStr := this.GetString("date")
  3760. if patientID <= 0 {
  3761. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3762. return
  3763. }
  3764. if len(recordDateStr) == 0 {
  3765. recordDateStr = time.Now().Format("2006-01-02")
  3766. }
  3767. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3768. if parseDateErr != nil {
  3769. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3770. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3771. return
  3772. }
  3773. adminInfo := this.GetMobileAdminUserInfo()
  3774. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3775. if err != nil {
  3776. this.ErrorLog("签名失败:%v", err)
  3777. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3778. return
  3779. }
  3780. this.ServeSuccessJSON(map[string]interface{}{
  3781. "doctor_id": adminInfo.AdminUser.Id,
  3782. })
  3783. }
  3784. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3785. patientID, _ := this.GetInt64("patient_id")
  3786. adminInfo := this.GetMobileAdminUserInfo()
  3787. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3788. this.ServeSuccessJSON(map[string]interface{}{
  3789. "monitor": record,
  3790. })
  3791. }
  3792. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3793. thisTime := time.Now()
  3794. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3795. timeLayout := "2006-01-02 15:04:05"
  3796. loc, _ := time.LoadLocation("Local")
  3797. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3798. theAssessmentDateTime := theStartTime.Unix()
  3799. patientID, _ := this.GetInt64("patient_id")
  3800. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3801. adminInfo := this.GetMobileAdminUserInfo()
  3802. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3803. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3804. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3805. var ultrafiltration_rate float64
  3806. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3807. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3808. fmt.Println(evaluation)
  3809. fmt.Println("prescription.ID", prescription.ID)
  3810. if prescription.ID > 0 {
  3811. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3812. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3813. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3814. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3815. record.UltrafiltrationRate = ultrafiltration_rate
  3816. }
  3817. if adminInfo.Org.Id == 10597 {
  3818. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3819. record.UltrafiltrationRate = ultrafiltration_rate
  3820. }
  3821. if adminInfo.Org.Id == 10510 {
  3822. record.UltrafiltrationRate = 0
  3823. }
  3824. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3825. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3826. record.UltrafiltrationRate = ultrafiltration_rate
  3827. }
  3828. if template.TemplateId == 20 || template.TemplateId == 22 {
  3829. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3830. record.UltrafiltrationRate = ultrafiltration_rate
  3831. }
  3832. // 只针对方济医院
  3833. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3834. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3835. ultrafiltration_rate = value
  3836. record.UltrafiltrationRate = ultrafiltration_rate
  3837. }
  3838. if template.TemplateId == 41 || template.TemplateId == 47 {
  3839. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3840. record.UltrafiltrationRate = ultrafiltration_rate
  3841. }
  3842. if template.TemplateId == 43 {
  3843. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3844. record.UltrafiltrationRate = ultrafiltration_rate
  3845. }
  3846. if template.TemplateId == 46 || template.TemplateId == 54 {
  3847. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3848. record.UltrafiltrationRate = ultrafiltration_rate
  3849. }
  3850. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 {
  3851. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3852. record.UltrafiltrationRate = ultrafiltration_rate
  3853. }
  3854. if adminInfo.Org.Id == 10469 {
  3855. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3856. record.UltrafiltrationRate = ultrafiltration_rate
  3857. }
  3858. if adminInfo.Org.Id == 10471 {
  3859. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3860. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3861. }
  3862. if adminInfo.Org.Id == 10460 {
  3863. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3864. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3865. }
  3866. if adminInfo.Org.Id == 10551 {
  3867. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3868. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3869. }
  3870. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3871. record.UltrafiltrationRate = 0
  3872. }
  3873. //if template.TemplateId == 47 {
  3874. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3875. // record.UltrafiltrationRate = ultrafiltration_rate
  3876. //}
  3877. }
  3878. }
  3879. // record.UltrafiltrationRate = ultrafiltration_rate
  3880. record.UltrafiltrationVolume = 0
  3881. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 { //adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535adminInfo.Org.Id == 3907 || adminInfo.Org.Id == 4 || adminInfo.Org.Id == 12 || adminInfo.Org.Id == 13 || adminInfo.Org.Id == 9535
  3882. if ultrafiltration_rate > 0 {
  3883. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3884. record.UltrafiltrationVolume = value
  3885. }
  3886. }
  3887. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  3888. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3889. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3890. record.UltrafiltrationVolume = ultrafiltration_volume
  3891. }
  3892. }
  3893. if adminInfo.Org.Id == 10597 {
  3894. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3895. record.UltrafiltrationVolume = ultrafiltration_volume
  3896. }
  3897. //长沙南雅
  3898. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 {
  3899. if ultrafiltration_rate > 0 {
  3900. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3901. record.UltrafiltrationVolume = ultrafiltration_volume
  3902. }
  3903. }
  3904. if adminInfo.Org.Id == 10471 {
  3905. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3906. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3907. }
  3908. if adminInfo.Org.Id == 10460 {
  3909. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3910. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3911. }
  3912. if adminInfo.Org.Id == 10551 {
  3913. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3914. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3915. }
  3916. //长沙南雅累计血容量自动计算
  3917. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3918. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3919. //}
  3920. if template.TemplateId == 47 || template.TemplateId == 54 {
  3921. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3922. }
  3923. if adminInfo.Org.Id == 10510 {
  3924. record.UltrafiltrationVolume = 0
  3925. }
  3926. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3927. this.ServeSuccessJSON(map[string]interface{}{
  3928. "monitor": record,
  3929. "lastMonitorRecordList": lastMonitorRecordList,
  3930. })
  3931. }
  3932. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3933. record_id, _ := this.GetInt64("id")
  3934. nurseID, _ := this.GetInt64("start_nurse")
  3935. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3936. bedID, _ := this.GetInt64("bed")
  3937. start_time := this.GetString("start_time")
  3938. schedual_type, _ := this.GetInt64("schedual_type")
  3939. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3940. change_nurse, _ := this.GetInt64("change_nurse")
  3941. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3942. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3943. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3944. fmt.Println("quality_nurse_id", quality_nurse_id)
  3945. patient_id, _ := this.GetInt64("patient_id")
  3946. record_date, _ := this.GetInt64("record_date")
  3947. puncture_needle := this.GetString("puncture_needle")
  3948. puncture_way := this.GetString("puncture_way")
  3949. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3950. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3951. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3952. nuclein_date_str := this.GetString("nuclein_date_str")
  3953. order_remark := this.GetString("order_remark")
  3954. schedule_remark := this.GetString("schedule_remark")
  3955. catheter_operation := this.GetString("catheter_operation")
  3956. blood_flow_volume := this.GetString("blood_flow_volume")
  3957. if record_id == 0 {
  3958. this.ErrorLog("id:%v", record_id)
  3959. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3960. return
  3961. }
  3962. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3963. if parseStartDateErr != nil {
  3964. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3965. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3966. return
  3967. }
  3968. adminUserInfo := this.GetMobileAdminUserInfo()
  3969. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3970. if getNurseErr != nil {
  3971. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3972. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3973. return
  3974. } else if nurse == nil {
  3975. this.ErrorLog("护士不存在")
  3976. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3977. return
  3978. }
  3979. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3980. //if getNurseErr != nil {
  3981. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3982. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3983. // return
  3984. //} else if nurse == nil {
  3985. // this.ErrorLog("护士不存在")
  3986. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3987. // return
  3988. //}
  3989. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3990. if getDeviceNumberErr != nil {
  3991. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3992. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3993. return
  3994. } else if deviceNumber == nil {
  3995. this.ErrorLog("床位号不存在")
  3996. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3997. return
  3998. }
  3999. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4000. //
  4001. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4002. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4003. // if getPermissionErr != nil {
  4004. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4005. // return
  4006. // } else if headNursePermission == nil {
  4007. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4008. // return
  4009. // }
  4010. //}
  4011. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4012. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4013. timeLayout := "2006-01-02 15:04:05"
  4014. loc, _ := time.LoadLocation("Local")
  4015. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4016. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4017. schedulestartTime := theStartTime.Unix()
  4018. scheduleendTime := theEndTime.Unix()
  4019. var theNucleinDate int64
  4020. timeLayoutOne := "2006-01-02"
  4021. if len(nuclein_date_str) > 0 {
  4022. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4023. if err != nil {
  4024. utils.ErrorLog(err.Error())
  4025. }
  4026. theNucleinDate = theTime.Unix()
  4027. }
  4028. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4029. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4030. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4031. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4032. if err == gorm.ErrRecordNotFound { //空床位
  4033. // 修改了床位逻辑
  4034. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4035. if daySchedule.ID > 0 {
  4036. //daySchedule.BedId = bedID
  4037. //daySchedule.PartitionId = deviceNumber.ZoneID
  4038. //daySchedule.ScheduleType = schedual_type
  4039. //daySchedule.UpdatedTime = time.Now().Unix()
  4040. //err := service.UpdateSchedule(&daySchedule)
  4041. xtSchedule := models.Schedule{
  4042. PartitionId: deviceNumber.ZoneID,
  4043. BedId: bedID,
  4044. ScheduleType: schedual_type,
  4045. UpdatedTime: time.Now().Unix(),
  4046. }
  4047. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4048. if err != nil {
  4049. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4050. return
  4051. }
  4052. }
  4053. } else if err == nil {
  4054. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4055. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4056. if daySchedule.ID > 0 {
  4057. //daySchedule.BedId = bedID
  4058. //daySchedule.PartitionId = deviceNumber.ZoneID
  4059. //
  4060. //daySchedule.ScheduleType = schedual_type
  4061. //daySchedule.UpdatedTime = time.Now().Unix()
  4062. //err := service.UpdateSchedule(&daySchedule)
  4063. xtSchedule := models.Schedule{
  4064. PartitionId: deviceNumber.ZoneID,
  4065. BedId: bedID,
  4066. ScheduleType: schedual_type,
  4067. UpdatedTime: time.Now().Unix(),
  4068. }
  4069. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4070. if err != nil {
  4071. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4072. return
  4073. }
  4074. }
  4075. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4076. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4077. return
  4078. }
  4079. } else if err != nil {
  4080. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4081. return
  4082. }
  4083. }
  4084. dialysisRecord := &models.DialysisOrder{
  4085. ID: record_id,
  4086. UserOrgId: adminUserInfo.Org.Id,
  4087. BedID: bedID,
  4088. StartNurse: nurseID,
  4089. StartTime: startDate.Unix(),
  4090. PunctureNurse: puncture_nurse,
  4091. Creator: adminUserInfo.AdminUser.Id,
  4092. Modifier: adminUserInfo.AdminUser.Id,
  4093. WashpipeNurse: washpipe_nurse,
  4094. SchedualType: schedual_type,
  4095. ChangeNurse: change_nurse,
  4096. DifficultPunctureNurse: difficult_puncture_nurse,
  4097. NewFistulaNurse: new_fistula_nurse,
  4098. QualityNurseId: quality_nurse_id,
  4099. PunctureNeedle: puncture_needle,
  4100. PunctureWay: puncture_way,
  4101. DialysisDialyszers: dialysis_dialyszers,
  4102. DialysisIrrigation: dialysis_irrigation,
  4103. BloodAccessId: blood_access_id,
  4104. NucleinDate: theNucleinDate,
  4105. OrderRemark: order_remark,
  4106. ScheduleRemark: schedule_remark,
  4107. CatheterOperation: catheter_operation,
  4108. BloodFlowVolume: blood_flow_volume,
  4109. }
  4110. //修改床位号需要重新消毒
  4111. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4112. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4113. //查询第一条监测
  4114. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4115. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4116. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4117. redis := service.RedisClient()
  4118. //清空key 值
  4119. redis.Set(key, "", time.Second)
  4120. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4121. redis.Set(keyOne, "", time.Second)
  4122. defer redis.Close()
  4123. }
  4124. // 查询信息规挡的设置天数
  4125. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4126. if infor.ID > 0 && infor.WeekDay > 0 {
  4127. var cha_time int64
  4128. timeNowStr := time.Now().Format("2006-01-02")
  4129. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4130. //今日的日期减去设置的日期
  4131. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4132. if cha_time >= record_date {
  4133. //查询审核是否允许
  4134. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4135. //申请状态不允许的情况 拒绝修改
  4136. if infor.ApplicationStatus != 1 {
  4137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4138. return
  4139. }
  4140. }
  4141. }
  4142. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4143. order, _ := service.GetLastPatientOrder(record_id)
  4144. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4145. redis := service.RedisClient()
  4146. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4147. redis.Set(key, "", time.Second)
  4148. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4149. //清空key 值
  4150. redis.Set(keyOne, "", time.Second)
  4151. scheduleDateStartOne := startDate.Format("2006-01-02")
  4152. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4153. redis.Set(keyTwo, "", time.Second)
  4154. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4155. redis.Set(keyThree, "", time.Second)
  4156. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4157. redis.Set(keyFour, "", time.Second)
  4158. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4159. redis.Set(keyFive, "", time.Second)
  4160. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4161. redis.Set(keySix, "", time.Second)
  4162. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4163. redis.Set(keySeven, "", time.Second)
  4164. if updateErr != nil {
  4165. this.ErrorLog("修改上机失败:%v", updateErr)
  4166. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4167. return
  4168. }
  4169. if updateErr == nil {
  4170. if tempDialysisRecord.Stage == 2 {
  4171. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4172. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4173. fmt.Println(value)
  4174. a, b := math.Modf(value)
  4175. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4176. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4177. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4178. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4179. redis := service.RedisClient()
  4180. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4181. redis.Set(key, "", time.Second)
  4182. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4183. redis.Set(keyOne, "", time.Second)
  4184. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4185. //清空key 值
  4186. redis.Set(keySix, "", time.Second)
  4187. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4188. redis.Set(keySeven, "", time.Second)
  4189. redis.Close()
  4190. if updateAssessmentErr != nil {
  4191. utils.ErrorLog("%v", updateAssessmentErr)
  4192. }
  4193. }
  4194. }
  4195. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4196. this.ServeSuccessJSON(map[string]interface{}{
  4197. "dialysis_order": dialysisRecords,
  4198. })
  4199. }
  4200. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4201. record_id, _ := c.GetInt64("id")
  4202. nurseID, _ := c.GetInt64("nurse")
  4203. end_time := c.GetString("end_time")
  4204. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4205. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4206. catheter := c.GetString("catheter")
  4207. cruor := c.GetString("cruor")
  4208. mission := c.GetString("mission")
  4209. condenser := c.GetString("condenser")
  4210. if record_id <= 0 || nurseID <= 0 {
  4211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4212. return
  4213. }
  4214. adminUserInfo := c.GetMobileAdminUserInfo()
  4215. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4216. if getNurseErr != nil {
  4217. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4219. return
  4220. } else if nurse == nil {
  4221. c.ErrorLog("护士不存在")
  4222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4223. return
  4224. }
  4225. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4226. if parseEndDateErr != nil {
  4227. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4228. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4229. return
  4230. }
  4231. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4232. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4233. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4234. // if getPermissionErr != nil {
  4235. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4236. // return
  4237. // } else if headNursePermission == nil {
  4238. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4239. // return
  4240. // }
  4241. //}
  4242. // 查询信息规挡的设置天数
  4243. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4244. if infor.ID > 0 {
  4245. var cha_time int64
  4246. timeNowStr := time.Now().Format("2006-01-02")
  4247. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4248. //今日的日期减去设置的日期
  4249. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4250. if cha_time >= tempDialysisRecords.DialysisDate {
  4251. //查询审核是否允许
  4252. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4253. //申请状态不允许的情况 拒绝修改
  4254. if infor.ApplicationStatus != 1 {
  4255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4256. return
  4257. }
  4258. }
  4259. }
  4260. dialysisRecord := &models.DialysisOrder{
  4261. ID: record_id,
  4262. UserOrgId: adminUserInfo.Org.Id,
  4263. EndTime: endDate.Unix(),
  4264. FinishNurse: nurseID,
  4265. FinishModifier: adminUserInfo.AdminUser.Id,
  4266. PuncturePointHaematoma: puncture_point_haematoma,
  4267. BloodAccessInternalFistula: blood_access_internal_fistula,
  4268. Catheter: catheter,
  4269. Cruor: cruor,
  4270. Mission: mission,
  4271. Condenser: condenser,
  4272. }
  4273. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4274. redis := service.RedisClient()
  4275. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4276. //清空key 值
  4277. redis.Set(key, "", time.Second)
  4278. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4279. //清空key 值
  4280. redis.Set(keyOne, "", time.Second)
  4281. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4282. redis.Set(keySeven, "", time.Second)
  4283. redis.Close()
  4284. if updateErr != nil {
  4285. c.ErrorLog("修改下机失败:%v", updateErr)
  4286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4287. return
  4288. }
  4289. if updateErr == nil {
  4290. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4291. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4292. a, b := math.Modf(value)
  4293. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4294. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4295. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4296. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4297. redis := service.RedisClient()
  4298. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4299. redis.Set(keyTen, "", time.Second)
  4300. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4301. redis.Set(keyTwo, "", time.Second)
  4302. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4303. redis.Set(key, "", time.Second)
  4304. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4305. redis.Set(keyThree, "", time.Second)
  4306. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4307. redis.Set(keySeven, "", time.Second)
  4308. defer redis.Close()
  4309. if updateAssessmentErr != nil {
  4310. utils.ErrorLog("%v", updateAssessmentErr)
  4311. }
  4312. }
  4313. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4314. c.ServeSuccessJSON(map[string]interface{}{
  4315. "dialysis_order": dialysisRecords,
  4316. })
  4317. }
  4318. func (c *DialysisAPIController) GetLongAdvice() {
  4319. patient_id, _ := c.GetInt64("id")
  4320. adminUserInfo := c.GetMobileAdminUserInfo()
  4321. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4322. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4323. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4324. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4325. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4326. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4327. c.ServeSuccessJSON(map[string]interface{}{
  4328. "status": "1",
  4329. })
  4330. return
  4331. } else { //开启推送提醒
  4332. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4333. var advice_three []*models.DoctorAdvice
  4334. recordDateStr := time.Now().Format("2006-01-02")
  4335. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4336. nowtime := recordDate.Unix()
  4337. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4338. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4339. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4340. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4341. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4342. for _, advice := range advices {
  4343. if advice.FrequencyType == 3 {
  4344. t := time.Now()
  4345. week := int(t.Weekday())
  4346. fmt.Println(t.Weekday())
  4347. fmt.Println(week)
  4348. switch week {
  4349. case 1:
  4350. if strings.Index(advice.WeekDay, "周一") == -1 {
  4351. advice_three = append(advice_three, advice)
  4352. }
  4353. break
  4354. case 2:
  4355. if strings.Index(advice.WeekDay, "周二") == -1 {
  4356. advice_three = append(advice_three, advice)
  4357. }
  4358. break
  4359. case 3:
  4360. if strings.Index(advice.WeekDay, "周三") == -1 {
  4361. advice_three = append(advice_three, advice)
  4362. }
  4363. break
  4364. case 4:
  4365. if strings.Index(advice.WeekDay, "周四") == -1 {
  4366. advice_three = append(advice_three, advice)
  4367. }
  4368. break
  4369. case 5:
  4370. if strings.Index(advice.WeekDay, "周五") == -1 {
  4371. advice_three = append(advice_three, advice)
  4372. }
  4373. break
  4374. case 6:
  4375. if strings.Index(advice.WeekDay, "周六") == -1 {
  4376. advice_three = append(advice_three, advice)
  4377. }
  4378. break
  4379. case 0:
  4380. if strings.Index(advice.WeekDay, "周日") == -1 {
  4381. advice_three = append(advice_three, advice)
  4382. }
  4383. break
  4384. }
  4385. }
  4386. }
  4387. for _, advice := range advices_two {
  4388. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4389. now := p.Unix()
  4390. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4391. dayStr2 := "-" + dayStr
  4392. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4393. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4394. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4395. for _, ad := range advices {
  4396. advice_three = append(advice_three, ad)
  4397. }
  4398. }
  4399. if err == nil {
  4400. c.ServeSuccessJSON(map[string]interface{}{
  4401. "status": "2",
  4402. "advices": advices,
  4403. "advices_two": RemoveRepeatedElement(advice_three),
  4404. "is_open_remind": config.IsOpenRemind,
  4405. "his_config_open": hisConfig.IsOpen,
  4406. "is_advice_open": is_advice_open.IsAdviceOpen,
  4407. "prescription_open": prescription_open.IsOpen,
  4408. })
  4409. }
  4410. }
  4411. }
  4412. func (c *DialysisAPIController) GetLongAdviceOne() {
  4413. patient_id, _ := c.GetInt64("id")
  4414. startTime := c.GetString("schedule_date")
  4415. timeLayout := "2006-01-02"
  4416. loc, _ := time.LoadLocation("Local")
  4417. var theStartTime int64
  4418. if len(startTime) > 0 {
  4419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4420. if err != nil {
  4421. utils.ErrorLog(err.Error())
  4422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4423. return
  4424. }
  4425. theStartTime = theTime.Unix()
  4426. }
  4427. adminUserInfo := c.GetMobileAdminUserInfo()
  4428. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4429. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4430. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4431. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4432. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4433. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4434. c.ServeSuccessJSON(map[string]interface{}{
  4435. "status": "1",
  4436. })
  4437. return
  4438. } else { //开启推送提醒
  4439. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4440. var advice_three []*models.DoctorAdvice
  4441. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4442. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4443. for _, advice := range advices {
  4444. if advice.FrequencyType == 3 {
  4445. t := time.Now()
  4446. week := int(t.Weekday())
  4447. fmt.Println(t.Weekday())
  4448. fmt.Println(week)
  4449. switch week {
  4450. case 1:
  4451. if strings.Index(advice.WeekDay, "周一") == -1 {
  4452. advice_three = append(advice_three, advice)
  4453. }
  4454. break
  4455. case 2:
  4456. if strings.Index(advice.WeekDay, "周二") == -1 {
  4457. advice_three = append(advice_three, advice)
  4458. }
  4459. break
  4460. case 3:
  4461. if strings.Index(advice.WeekDay, "周三") == -1 {
  4462. advice_three = append(advice_three, advice)
  4463. }
  4464. break
  4465. case 4:
  4466. if strings.Index(advice.WeekDay, "周四") == -1 {
  4467. advice_three = append(advice_three, advice)
  4468. }
  4469. break
  4470. case 5:
  4471. if strings.Index(advice.WeekDay, "周五") == -1 {
  4472. advice_three = append(advice_three, advice)
  4473. }
  4474. break
  4475. case 6:
  4476. if strings.Index(advice.WeekDay, "周六") == -1 {
  4477. advice_three = append(advice_three, advice)
  4478. }
  4479. break
  4480. case 0:
  4481. if strings.Index(advice.WeekDay, "周日") == -1 {
  4482. advice_three = append(advice_three, advice)
  4483. }
  4484. break
  4485. }
  4486. }
  4487. }
  4488. for _, advice := range advices_two {
  4489. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4490. now := p.Unix()
  4491. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4492. dayStr2 := "-" + dayStr
  4493. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4494. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4495. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4496. for _, ad := range advices {
  4497. advice_three = append(advice_three, ad)
  4498. }
  4499. }
  4500. if err == nil {
  4501. c.ServeSuccessJSON(map[string]interface{}{
  4502. "status": "2",
  4503. "advices": advices,
  4504. "advices_two": RemoveRepeatedElement(advice_three),
  4505. "is_open_remind": config.IsOpenRemind,
  4506. "his_config_open": hisConfig.IsOpen,
  4507. "is_advice_open": is_advice_open.IsAdviceOpen,
  4508. "prescription_open": prescription_open.IsOpen,
  4509. })
  4510. }
  4511. }
  4512. }
  4513. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4514. newArr = make([]*models.DoctorAdvice, 0)
  4515. for i := 0; i < len(arr); i++ {
  4516. repeat := false
  4517. for j := i + 1; j < len(arr); j++ {
  4518. if arr[i].ID == arr[j].ID {
  4519. repeat = true
  4520. break
  4521. }
  4522. }
  4523. if !repeat {
  4524. newArr = append(newArr, arr[i])
  4525. }
  4526. }
  4527. return
  4528. }
  4529. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4530. patient, _ := c.GetInt64("id", 0)
  4531. groupNo, _ := c.GetInt64("groupno", 0)
  4532. if patient <= 0 {
  4533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4534. return
  4535. }
  4536. adminUserInfo := c.GetMobileAdminUserInfo()
  4537. dataBody := make(map[string]interface{}, 0)
  4538. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4539. if err != nil {
  4540. utils.ErrorLog(err.Error())
  4541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4542. return
  4543. }
  4544. utils.ErrorLog("%v", dataBody)
  4545. timeLayout := "2006-01-02 15:04"
  4546. loc, _ := time.LoadLocation("Local")
  4547. timeLayout2 := "2006-01-02"
  4548. loc2, _ := time.LoadLocation("Local")
  4549. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4550. utils.ErrorLog("advice_type")
  4551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4552. return
  4553. }
  4554. adviceType := int64(2)
  4555. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4556. utils.ErrorLog("advice_date")
  4557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4558. return
  4559. }
  4560. adviceDate, _ := dataBody["advice_date"].(string)
  4561. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4562. AdviceDate := theTime.Unix()
  4563. RecordDate := theTime.Unix()
  4564. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4565. utils.ErrorLog("start_time")
  4566. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4567. return
  4568. }
  4569. startTime, _ := dataBody["start_time"].(string)
  4570. if len(startTime) == 0 {
  4571. utils.ErrorLog("len(start_time) == 0")
  4572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4573. return
  4574. }
  4575. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4576. if err != nil {
  4577. utils.ErrorLog(err.Error())
  4578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4579. return
  4580. }
  4581. StartTime := theTime.Unix()
  4582. Remark := ""
  4583. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4584. remark, _ := dataBody["remark"].(string)
  4585. Remark = remark
  4586. }
  4587. var advices []*models.GroupAdvice
  4588. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4589. utils.ErrorLog("advices")
  4590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4591. return
  4592. }
  4593. adviceNames := dataBody["advices"].([]interface{})
  4594. for _, adviceNameMap := range adviceNames {
  4595. adviceNameM := adviceNameMap.(map[string]interface{})
  4596. var advice models.GroupAdvice
  4597. advice.Remark = Remark
  4598. advice.AdviceType = adviceType
  4599. advice.StartTime = StartTime
  4600. advice.AdviceDate = AdviceDate
  4601. advice.RecordDate = RecordDate
  4602. advice.Status = 1
  4603. advice.CreatedTime = time.Now().Unix()
  4604. advice.UpdatedTime = time.Now().Unix()
  4605. advice.StopState = 2
  4606. advice.ExecutionState = 2
  4607. advice.UserOrgId = adminUserInfo.Org.Id
  4608. advice.PatientId = patient
  4609. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4610. advice.IsSettle = 2
  4611. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4612. utils.ErrorLog("advice_name")
  4613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4614. return
  4615. }
  4616. adviceName, _ := adviceNameM["advice_name"].(string)
  4617. if len(adviceName) == 0 {
  4618. utils.ErrorLog("len(advice_name) == 0")
  4619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4620. return
  4621. }
  4622. advice.AdviceName = adviceName
  4623. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4624. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4625. advice.DrugSpec = drugSpec
  4626. }
  4627. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4628. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4629. advice.AdviceDesc = adviceDesc
  4630. }
  4631. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4632. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4633. advice.DrugSpecUnit = drugSpecUnit
  4634. }
  4635. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4636. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4637. // advice.SingleDose = singleDose
  4638. //}
  4639. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4640. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4641. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4642. }
  4643. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4644. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4645. advice.SingleDoseUnit = singleDoseUnit
  4646. }
  4647. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4648. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4649. // advice.PrescribingNumber = prescribingNumber
  4650. //}
  4651. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4652. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4653. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4654. }
  4655. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4656. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4657. advice.PrescribingNumberUnit = prescribingNumberUnit
  4658. }
  4659. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4660. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4661. advice.DeliveryWay = deliveryWay
  4662. }
  4663. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4664. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4665. advice.ExecutionFrequency = executionFrequency
  4666. }
  4667. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4668. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4669. advice.FrequencyType = frequency_type
  4670. }
  4671. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4672. day_count := int64(adviceNameM["day_count"].(float64))
  4673. advice.DayCount = day_count
  4674. }
  4675. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4676. week_day, _ := adviceNameM["week_day"].(string)
  4677. advice.WeekDay = week_day
  4678. }
  4679. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4680. way := int64(adviceNameM["way"].(float64))
  4681. advice.Way = way
  4682. }
  4683. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4684. drug_id := int64(adviceNameM["drug_id"].(float64))
  4685. advice.DrugId = drug_id
  4686. }
  4687. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4688. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4689. advice.DrugNameId = drug_name_id
  4690. }
  4691. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4692. remark, _ := adviceNameM["remark"].(string)
  4693. advice.Remark = remark
  4694. }
  4695. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4696. groupno := int64(adviceNameM["groupno"].(float64))
  4697. advice.GroupNo = groupno
  4698. }
  4699. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4700. template_id, _ := adviceNameM["template_id"].(string)
  4701. advice.TemplateId = template_id
  4702. }
  4703. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4704. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4705. advice.ExecutionFrequency = executionFrequency
  4706. }
  4707. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4708. children := adviceNameM["child"].([]interface{})
  4709. if len(children) > 0 {
  4710. for _, childrenMap := range children {
  4711. childMap := childrenMap.(map[string]interface{})
  4712. var child models.GroupAdvice
  4713. child.Remark = Remark
  4714. child.AdviceType = adviceType
  4715. child.StartTime = StartTime
  4716. child.AdviceDate = AdviceDate
  4717. child.RecordDate = RecordDate
  4718. child.Status = 1
  4719. child.CreatedTime = time.Now().Unix()
  4720. child.UpdatedTime = time.Now().Unix()
  4721. child.StopState = 2
  4722. child.ExecutionState = 2
  4723. child.UserOrgId = adminUserInfo.Org.Id
  4724. child.PatientId = patient
  4725. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4726. child.IsSettle = 1
  4727. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4728. utils.ErrorLog("child advice_name")
  4729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4730. return
  4731. }
  4732. childAdviceName, _ := childMap["advice_name"].(string)
  4733. if len(childAdviceName) == 0 {
  4734. utils.ErrorLog("len(child advice_name) == 0")
  4735. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4736. return
  4737. }
  4738. child.AdviceName = childAdviceName
  4739. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4740. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4741. child.AdviceDesc = childAdviceDesc
  4742. }
  4743. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4744. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4745. child.DrugSpec = childDrugSpec
  4746. }
  4747. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4748. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4749. child.DrugSpecUnit = childDrugSpecUnit
  4750. }
  4751. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4752. child.SingleDose = childMap["single_dose"].(float64)
  4753. }
  4754. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4755. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4756. child.SingleDoseUnit = childSingleDoseUnit
  4757. }
  4758. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4759. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4760. }
  4761. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4762. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4763. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4764. }
  4765. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4766. groupno := int64(childMap["groupno"].(float64))
  4767. advice.GroupNo = groupno
  4768. }
  4769. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4770. remark, _ := childMap["remark"].(string)
  4771. child.Remark = remark
  4772. }
  4773. child.DeliveryWay = advice.DeliveryWay
  4774. child.ExecutionFrequency = advice.ExecutionFrequency
  4775. advice.Children = append(advice.Children, &child)
  4776. }
  4777. }
  4778. }
  4779. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4780. if temp_advice.ID == 0 {
  4781. advices = append(advices, &advice)
  4782. }
  4783. }
  4784. if len(advices) > 0 {
  4785. finish := models.XtDialysisFinish{
  4786. IsFinish: 1,
  4787. UserOrgId: adminUserInfo.Org.Id,
  4788. Status: 1,
  4789. Ctime: time.Now().Unix(),
  4790. Mtime: 0,
  4791. Module: 4,
  4792. RecordDate: AdviceDate,
  4793. Sourse: 1,
  4794. PatientId: patient,
  4795. }
  4796. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4797. if dialysisFinish.ID == 0 {
  4798. service.CreateDialysisFinish(finish)
  4799. }
  4800. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4801. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4802. for _, item := range advices {
  4803. byterequest, _ := json.Marshal(item)
  4804. adviceLog := models.XtDoctorAdviceLog{
  4805. UserOrgId: adminUserInfo.Org.Id,
  4806. PatientId: patient,
  4807. AdminUserId: adminUserInfo.AdminUser.Id,
  4808. Module: 1,
  4809. ErrLog: string(byterequest),
  4810. Status: 1,
  4811. Ctime: time.Now().Unix(),
  4812. Mtime: 0,
  4813. Source: "手机端医嘱推送",
  4814. RecordDate: item.AdviceDate,
  4815. }
  4816. service.CreateDoctorAdviceLog(adviceLog)
  4817. }
  4818. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4819. redis := service.RedisClient()
  4820. //清空key 值
  4821. redis.Set(key, "", time.Second)
  4822. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4823. redis.Set(keyOne, "", time.Second)
  4824. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4825. defer redis.Close()
  4826. redis.Set(keyThree, "", time.Second)
  4827. if err != nil {
  4828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4829. return
  4830. }
  4831. c.ServeSuccessJSON(map[string]interface{}{
  4832. "msg": "ok",
  4833. "advices": list,
  4834. })
  4835. } else {
  4836. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4837. for _, item := range advices {
  4838. byterequest, _ := json.Marshal(item)
  4839. adviceLog := models.XtDoctorAdviceLog{
  4840. UserOrgId: adminUserInfo.Org.Id,
  4841. PatientId: patient,
  4842. AdminUserId: adminUserInfo.AdminUser.Id,
  4843. Module: 1,
  4844. ErrLog: string(byterequest),
  4845. Status: 1,
  4846. Ctime: time.Now().Unix(),
  4847. Mtime: 0,
  4848. Source: "手机端医嘱推送",
  4849. RecordDate: item.AdviceDate,
  4850. }
  4851. service.CreateDoctorAdviceLog(adviceLog)
  4852. }
  4853. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4854. redis := service.RedisClient()
  4855. //清空key 值
  4856. redis.Set(key, "", time.Second)
  4857. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4858. redis.Set(keyOne, "", time.Second)
  4859. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4860. defer redis.Close()
  4861. redis.Set(keyThree, "", time.Second)
  4862. if err != nil {
  4863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4864. return
  4865. }
  4866. c.ServeSuccessJSON(map[string]interface{}{
  4867. "msg": "ok",
  4868. "advices": list,
  4869. })
  4870. }
  4871. } else {
  4872. c.ServeSuccessJSON(map[string]interface{}{
  4873. "msg": "ok",
  4874. })
  4875. }
  4876. return
  4877. }
  4878. func (c *DialysisAPIController) UploadDryWeight() {
  4879. patient_id, _ := c.GetInt64("id")
  4880. dry_weight, _ := c.GetFloat("dry_weight")
  4881. doctor_id, _ := c.GetInt64("doctor_id")
  4882. remark := c.GetString("remark")
  4883. adminUserInfo := c.GetMobileAdminUserInfo()
  4884. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4885. if err == gorm.ErrRecordNotFound {
  4886. dryWeight := &models.SgjPatientDryweight{
  4887. PatientId: patient_id,
  4888. DryWeight: dry_weight,
  4889. Remakes: remark,
  4890. Ctime: time.Now().Unix(),
  4891. Mtime: time.Now().Unix(),
  4892. Creator: doctor_id,
  4893. Status: 1,
  4894. UserOrgId: adminUserInfo.Org.Id,
  4895. AdjustedValue: "/",
  4896. UserId: adminUserInfo.AdminUser.Id,
  4897. }
  4898. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4899. redis := service.RedisClient()
  4900. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4901. redis.Set(keyOne, "", time.Second)
  4902. loc, _ := time.LoadLocation("Local")
  4903. nowTime := time.Now()
  4904. nowDay := nowTime.Format("2006-01-02")
  4905. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4906. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4907. redis.Set(key, "", time.Second)
  4908. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4909. redis.Set(keyTwo, "", time.Second)
  4910. redis.Close()
  4911. if createErr == nil {
  4912. c.ServeSuccessJSON(map[string]interface{}{
  4913. "msg": "提交成功",
  4914. "weight": dryWeight,
  4915. })
  4916. }
  4917. } else {
  4918. dryWeight := &models.SgjPatientDryweight{
  4919. PatientId: patient_id,
  4920. DryWeight: dry_weight,
  4921. Remakes: remark,
  4922. Ctime: time.Now().Unix(),
  4923. Mtime: time.Now().Unix(),
  4924. Creator: doctor_id,
  4925. Status: 1,
  4926. UserOrgId: adminUserInfo.Org.Id,
  4927. AdjustedValue: "/",
  4928. UserId: adminUserInfo.AdminUser.Id,
  4929. }
  4930. var value float64
  4931. value = dry_weight - weightAdjust.DryWeight
  4932. if value < 0 {
  4933. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4934. } else if value == 0 {
  4935. dryWeight.AdjustedValue = "/"
  4936. } else if value > 0 {
  4937. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4938. }
  4939. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4940. redis := service.RedisClient()
  4941. loc, _ := time.LoadLocation("Local")
  4942. nowTime := time.Now()
  4943. nowDay := nowTime.Format("2006-01-02")
  4944. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4945. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4946. redis.Set(keyOne, "", time.Second)
  4947. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4948. redis.Set(key, "", time.Second)
  4949. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4950. redis.Set(keyTwo, "", time.Second)
  4951. redis.Close()
  4952. if createErr == nil {
  4953. c.ServeSuccessJSON(map[string]interface{}{
  4954. "msg": "提交成功",
  4955. "weight": dryWeight,
  4956. })
  4957. }
  4958. }
  4959. }
  4960. func (c *DialysisAPIController) GetSolution() {
  4961. patient_id, _ := c.GetInt64("patient_id")
  4962. mode_id, _ := c.GetInt64("mode_id")
  4963. adminUserInfo := c.GetMobileAdminUserInfo()
  4964. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4965. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4966. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4967. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4968. if err != nil {
  4969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4970. return
  4971. }
  4972. c.ServeSuccessJSON(map[string]interface{}{
  4973. "solution": solution,
  4974. "prescription": prescription,
  4975. "system_prescription": system_prescription,
  4976. "dialysisPrescription": dialysisPrescription,
  4977. })
  4978. }
  4979. func (c *DialysisAPIController) GetSchedule() {
  4980. schedual_type, _ := c.GetInt64("schedual_type")
  4981. adminUserInfo := c.GetMobileAdminUserInfo()
  4982. scheduleTime, _ := c.GetInt64("record_date")
  4983. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4984. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4985. c.ServeSuccessJSON(map[string]interface{}{
  4986. "number": deviceNumber,
  4987. "list": list,
  4988. })
  4989. }
  4990. func (c *DialysisAPIController) GetPatientId() {
  4991. id, _ := c.GetInt64("id")
  4992. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4993. patientId, _ := service.GetPatientId(id)
  4994. //获取该患者的所有传染病
  4995. list, _ := service.GetPatientInfectious(id)
  4996. c.ServeSuccessJSON(map[string]interface{}{
  4997. "patient": patientId,
  4998. "infectioulist": list,
  4999. })
  5000. }
  5001. func (this *DialysisAPIController) GetDialysisSchedule() {
  5002. schedualDate := this.GetString("date")
  5003. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5004. if parseDateErr != nil {
  5005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5006. return
  5007. }
  5008. adminInfo := this.GetMobileAdminUserInfo()
  5009. orgID := adminInfo.Org.Id
  5010. redis := service.RedisClient()
  5011. defer redis.Close()
  5012. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5013. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5014. if len(scheduals) > 0 {
  5015. //缓存数据
  5016. scheduals_json, err := json.Marshal(scheduals)
  5017. if err == nil {
  5018. redis.Set(key, scheduals_json, time.Second*30)
  5019. }
  5020. }
  5021. this.ServeSuccessJSON(map[string]interface{}{
  5022. "scheduals": scheduals,
  5023. })
  5024. }
  5025. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5026. change_type, _ := this.GetInt64("type", 0)
  5027. record_date := this.GetString("record_time")
  5028. patient_id, _ := this.GetInt64("patient_id", 0)
  5029. timeLayout := "2006-01-02"
  5030. loc, _ := time.LoadLocation("Local")
  5031. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5032. record_time := theAdviceRecordTime.Unix()
  5033. adminUserInfo := this.GetMobileAdminUserInfo()
  5034. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5035. if err == nil {
  5036. if len(advices) == 0 {
  5037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5038. return
  5039. } else {
  5040. this.ServeSuccessJSON(map[string]interface{}{
  5041. "advices": advices,
  5042. "schedule": sch,
  5043. })
  5044. return
  5045. }
  5046. } else {
  5047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5048. return
  5049. }
  5050. }
  5051. func (c *DialysisAPIController) CreateConsumables() {
  5052. record_date := c.GetString("record_time")
  5053. patient_id, _ := c.GetInt64("patient_id", 0)
  5054. active, _ := c.GetInt64("active")
  5055. adminUser := c.GetMobileAdminUserInfo()
  5056. timeLayout := "2006-01-02"
  5057. loc, _ := time.LoadLocation("Local")
  5058. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5059. record_time := theRecordTime.Unix()
  5060. // 查询信息规挡的设置天数
  5061. orgid := c.GetMobileAdminUserInfo().Org.Id
  5062. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5063. if infor.ID > 0 {
  5064. var cha_time int64
  5065. timeNowStr := time.Now().Format("2006-01-02")
  5066. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5067. //今日的日期减去设置的日期
  5068. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5069. if cha_time >= record_time {
  5070. //查询审核是否允许
  5071. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5072. //申请状态不允许的情况 拒绝修改
  5073. if infor.ApplicationStatus != 1 {
  5074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5075. return
  5076. }
  5077. }
  5078. }
  5079. dataBody := make(map[string]interface{}, 0)
  5080. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5081. if err != nil {
  5082. utils.ErrorLog(err.Error())
  5083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5084. return
  5085. }
  5086. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5087. var beforePrepares []*models.DialysisBeforePrepareGoods
  5088. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5089. var dialysisBefor []*models.DialysisBeforePrepare
  5090. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5091. goods, _ := dataBody["goods"].([]interface{})
  5092. if len(goods) > 0 {
  5093. for _, item := range goods {
  5094. items := item.(map[string]interface{})
  5095. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5096. utils.ErrorLog("good_id")
  5097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5098. return
  5099. }
  5100. good_id := int64(items["good_id"].(float64))
  5101. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5102. utils.ErrorLog("good_type_id")
  5103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5104. return
  5105. }
  5106. good_type_id := int64(items["good_type_id"].(float64))
  5107. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5108. utils.ErrorLog("count")
  5109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5110. return
  5111. }
  5112. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5113. commdity_code := items["commdity_code"].(string)
  5114. fmt.Println("commdity", commdity_code)
  5115. prepareGoods := &models.DialysisBeforePrepareGoods{
  5116. GoodTypeId: good_type_id,
  5117. GoodId: good_id,
  5118. Count: count,
  5119. StorehouseId: houseConfig.StorehouseOutInfo,
  5120. }
  5121. beforePrepares = append(beforePrepares, prepareGoods)
  5122. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5123. GoodTypeId: good_type_id,
  5124. GoodId: good_id,
  5125. Count: count,
  5126. StorehouseId: houseConfig.StorehouseOutInfo,
  5127. }
  5128. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5129. prepare := &models.DialysisBeforePrepare{
  5130. GoodTypeId: good_type_id,
  5131. GoodId: good_id,
  5132. Count: count,
  5133. PatientId: patient_id,
  5134. RecordDate: record_time,
  5135. UserOrgId: adminUser.Org.Id,
  5136. Status: 1,
  5137. Ctime: time.Now().Unix(),
  5138. Creater: adminUser.AdminUser.Id,
  5139. CommdityCode: commdity_code,
  5140. StorehouseId: houseConfig.StorehouseOutInfo,
  5141. }
  5142. dialysisBefor = append(dialysisBefor, prepare)
  5143. }
  5144. }
  5145. //查询是否有库存
  5146. for _, item := range dialysisBefor {
  5147. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5148. if err == gorm.ErrRecordNotFound {
  5149. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5150. c.ServeSuccessJSON(map[string]interface{}{
  5151. "message": "1",
  5152. "good_name": goodObj.GoodName,
  5153. "specification_name": goodObj.SpecificationName,
  5154. })
  5155. return
  5156. }
  5157. if err != nil {
  5158. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5159. c.ServeSuccessJSON(map[string]interface{}{
  5160. "message": "1",
  5161. "good_name": goodObj.GoodName,
  5162. "specification_name": goodObj.SpecificationName,
  5163. })
  5164. return
  5165. }
  5166. }
  5167. //新增
  5168. if active == 1 && len(goods) > 0 {
  5169. for _, item := range dialysisBefor {
  5170. dialyPrepareOne := models.DialysisBeforePrepare{
  5171. GoodTypeId: item.GoodTypeId,
  5172. GoodId: item.GoodId,
  5173. PatientId: item.PatientId,
  5174. RecordDate: item.RecordDate,
  5175. UserOrgId: item.UserOrgId,
  5176. Count: item.Count,
  5177. Ctime: time.Now().Unix(),
  5178. Creater: item.Creater,
  5179. CommdityCode: item.CommdityCode,
  5180. Status: 1,
  5181. StorehouseId: houseConfig.StorehouseOutInfo,
  5182. }
  5183. //先清除再插入
  5184. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5185. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5186. //查询默认仓库
  5187. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5188. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5189. var total_count int64
  5190. for _, it := range stockList {
  5191. total_count += it.StockCount
  5192. }
  5193. //基础库插入数据
  5194. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5195. //更新库存
  5196. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5197. var flush_count int64
  5198. for _, it := range goodList {
  5199. flush_count += it.StockCount
  5200. }
  5201. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5202. }
  5203. if err == nil {
  5204. c.ServeSuccessJSON(map[string]interface{}{
  5205. "msg": "保存成功",
  5206. "message": "2",
  5207. })
  5208. return
  5209. } else {
  5210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5211. return
  5212. }
  5213. }
  5214. if len(beforePrepares) > 0 && active == 2 {
  5215. for _, item := range beforePrepares {
  5216. //1.查看该患者该耗材型号最后一次出库数量
  5217. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5218. //判断当前出库数量和最后一次出库数量的大小
  5219. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5220. if item.Count <= goodInfo.Count {
  5221. //退库
  5222. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5223. //查询今日出库数据
  5224. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5225. for _, it := range list {
  5226. prepare := models.DialysisBeforePrepare{
  5227. UserOrgId: it.OrgId,
  5228. PatientId: patient_id,
  5229. RecordDate: it.RecordTime,
  5230. GoodId: it.GoodId,
  5231. GoodTypeId: it.GoodTypeId,
  5232. Count: it.Count,
  5233. Ctime: time.Now().Unix(),
  5234. Creater: adminUser.AdminUser.Id,
  5235. Status: 1,
  5236. StorehouseId: houseConfig.StorehouseOutInfo,
  5237. }
  5238. //删除准备表数据
  5239. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5240. service.CreateDialysisBeforePrepareOne(&prepare)
  5241. }
  5242. }
  5243. var last_total int64
  5244. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5245. if item.Count >= goodInfo.Count {
  5246. //查询当前批次当前耗材最后一条出库数据
  5247. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5248. //计算当前出库和最后一次出库数据相差数据
  5249. last_total = item.Count - lastOutInfo.Count
  5250. //查询该批次剩余库存
  5251. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5252. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5253. if lastInfo.StockCount >= last_total {
  5254. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5255. //查询今日出库数据
  5256. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5257. for _, it := range list {
  5258. prepare := models.DialysisBeforePrepare{
  5259. UserOrgId: it.OrgId,
  5260. PatientId: patient_id,
  5261. RecordDate: it.RecordTime,
  5262. GoodId: it.GoodId,
  5263. GoodTypeId: it.GoodTypeId,
  5264. Count: it.Count,
  5265. Ctime: time.Now().Unix(),
  5266. Creater: adminUser.AdminUser.Id,
  5267. Status: 1,
  5268. StorehouseId: houseConfig.StorehouseOutInfo,
  5269. }
  5270. //删除准备表数据
  5271. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5272. service.CreateDialysisBeforePrepareOne(&prepare)
  5273. //查询默认仓库
  5274. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5275. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5276. var total_count int64
  5277. for _, it := range stockList {
  5278. total_count += it.StockCount
  5279. }
  5280. //基础库插入数据
  5281. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5282. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5283. var flush_count int64
  5284. for _, it := range goodList {
  5285. flush_count += it.StockCount
  5286. }
  5287. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5288. }
  5289. }
  5290. //如果库存不够,则出库到下一个批次
  5291. if lastInfo.StockCount < last_total {
  5292. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5293. //查询今日出库数据
  5294. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5295. for _, it := range list {
  5296. prepare := models.DialysisBeforePrepare{
  5297. UserOrgId: it.OrgId,
  5298. PatientId: patient_id,
  5299. RecordDate: it.RecordTime,
  5300. GoodId: it.GoodId,
  5301. GoodTypeId: it.GoodTypeId,
  5302. Count: it.Count,
  5303. Ctime: time.Now().Unix(),
  5304. Creater: adminUser.AdminUser.Id,
  5305. Status: 1,
  5306. StorehouseId: houseConfig.StorehouseOutInfo,
  5307. }
  5308. //删除准备表数据
  5309. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5310. service.CreateDialysisBeforePrepareOne(&prepare)
  5311. //查询默认仓库
  5312. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5313. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5314. var total_count int64
  5315. for _, it := range stockList {
  5316. total_count += it.StockCount
  5317. }
  5318. //基础库插入数据
  5319. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5320. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5321. var flush_count int64
  5322. for _, it := range goodList {
  5323. flush_count += it.StockCount
  5324. }
  5325. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5326. }
  5327. if err != nil {
  5328. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5329. c.ServeSuccessJSON(map[string]interface{}{
  5330. "message": "1",
  5331. "good_name": goodObj.GoodName,
  5332. "specification_name": goodObj.SpecificationName,
  5333. })
  5334. return
  5335. }
  5336. }
  5337. }
  5338. if err != nil {
  5339. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5340. c.ServeSuccessJSON(map[string]interface{}{
  5341. "message": "1",
  5342. "good_name": goodObj.GoodName,
  5343. "specification_name": goodObj.SpecificationName,
  5344. })
  5345. return
  5346. }
  5347. }
  5348. }
  5349. }
  5350. var errs error
  5351. if errs == nil {
  5352. c.ServeSuccessJSON(map[string]interface{}{
  5353. "msg": "提交成功",
  5354. "message": "2",
  5355. "good_name": "",
  5356. "specification_name": "",
  5357. })
  5358. return
  5359. } else {
  5360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5361. return
  5362. }
  5363. }
  5364. func (c *DialysisAPIController) CreateStockOutInfo() {
  5365. patient_id, _ := c.GetInt64("patient_id", 0)
  5366. record_date := c.GetString("record_time")
  5367. if patient_id <= 0 {
  5368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5369. return
  5370. }
  5371. adminInfo := c.GetMobileAdminUserInfo()
  5372. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5373. timeLayout := "2006-01-02"
  5374. loc, _ := time.LoadLocation("Local")
  5375. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5376. record_time := theRecordTime.Unix()
  5377. // 查询信息规挡的设置天数
  5378. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5379. if infor.ID > 0 && infor.WeekDay > 0 {
  5380. var cha_time int64
  5381. timeNowStr := time.Now().Format("2006-01-02")
  5382. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5383. //今日的日期减去设置的日期
  5384. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5385. if cha_time >= record_time {
  5386. //查询审核是否允许
  5387. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5388. //申请状态不允许的情况 拒绝修改
  5389. if infor.ApplicationStatus != 1 {
  5390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5391. return
  5392. }
  5393. }
  5394. }
  5395. //创建步骤表
  5396. finish := models.XtDialysisFinish{
  5397. IsFinish: 1,
  5398. UserOrgId: adminInfo.Org.Id,
  5399. Status: 1,
  5400. Ctime: time.Now().Unix(),
  5401. Mtime: 0,
  5402. Module: 11,
  5403. RecordDate: record_time,
  5404. Sourse: 1,
  5405. PatientId: patient_id,
  5406. }
  5407. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5408. if dialysisFinish.ID == 0 {
  5409. service.CreateDialysisFinish(finish)
  5410. }
  5411. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5412. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5413. //去重
  5414. consumables = RemoveRepeatedGood(consumables)
  5415. if adminInfo.Org.Id == 9919 {
  5416. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5417. //查询是否有库存
  5418. for _, item := range consumables {
  5419. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5420. if item.Count > warehouse.Count {
  5421. goodErrcode := models.XtGoodErrcode{
  5422. UserOrgId: item.UserOrgId,
  5423. Errcode: "自动出库库存不足",
  5424. GoodId: item.GoodId,
  5425. Status: 1,
  5426. Ctime: time.Now().Unix(),
  5427. Mtime: 0,
  5428. Count: 0,
  5429. StockCount: 0,
  5430. Creater: creator,
  5431. BatchNumberId: warehouse.ID,
  5432. WarehouseOutId: 0,
  5433. }
  5434. service.CreateGoodErrcode(goodErrcode)
  5435. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5436. c.ServeSuccessJSON(map[string]interface{}{
  5437. "message": "1",
  5438. "good_name": goodObj.GoodName,
  5439. "specification_name": goodObj.SpecificationName,
  5440. })
  5441. return
  5442. }
  5443. }
  5444. //查询是否有出库单
  5445. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5446. if err == gorm.ErrRecordNotFound {
  5447. //没有记录,则创建出库单
  5448. timeStr := time.Now().Format("2006-01-02")
  5449. timeArr := strings.Split(timeStr, "-")
  5450. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5451. total = total + 1
  5452. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5453. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5454. number = number + total
  5455. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5456. creater := adminInfo.AdminUser.Id
  5457. warehouseOut := models.WarehouseOut{
  5458. WarehouseOutOrderNumber: warehousing_out_order,
  5459. OperationTime: time.Now().Unix(),
  5460. OrgId: adminInfo.Org.Id,
  5461. Creater: creater,
  5462. Ctime: time.Now().Unix(),
  5463. Status: 1,
  5464. WarehouseOutTime: record_time,
  5465. Dealer: 0,
  5466. Manufacturer: 0,
  5467. Type: 1,
  5468. IsSys: 1,
  5469. StorehouseId: houseConfig.StorehouseOutInfo,
  5470. IsCheck: 1,
  5471. }
  5472. err := service.AddSigleWarehouseOut(&warehouseOut)
  5473. if err != nil {
  5474. goodErrcode := models.XtGoodErrcode{
  5475. UserOrgId: adminInfo.Org.Id,
  5476. Errcode: "创建出库单失败",
  5477. GoodId: 0,
  5478. Status: 1,
  5479. Ctime: time.Now().Unix(),
  5480. Mtime: 0,
  5481. Count: 0,
  5482. StockCount: 0,
  5483. Creater: creator,
  5484. BatchNumberId: 0,
  5485. WarehouseOutId: 0,
  5486. }
  5487. service.CreateGoodErrcode(goodErrcode)
  5488. utils.TraceLog("创建出库单失败 err = %v", err)
  5489. } else {
  5490. for _, item := range consumables {
  5491. //出库
  5492. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5493. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5494. if err == nil {
  5495. goodErrcode := models.XtGoodErrcode{
  5496. UserOrgId: adminInfo.Org.Id,
  5497. Errcode: "自动出库接口报错",
  5498. GoodId: 0,
  5499. Status: 1,
  5500. Ctime: time.Now().Unix(),
  5501. Mtime: 0,
  5502. Count: 0,
  5503. StockCount: 0,
  5504. Creater: creator,
  5505. BatchNumberId: 0,
  5506. WarehouseOutId: 0,
  5507. }
  5508. service.CreateGoodErrcode(goodErrcode)
  5509. utils.TraceLog("创建出库单失败 err = %v", err)
  5510. }
  5511. //查询
  5512. //出库数量相加
  5513. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5514. if errs != nil {
  5515. goodErrcode := models.XtGoodErrcode{
  5516. UserOrgId: item.UserOrgId,
  5517. Errcode: "创建剩余库存字段报错",
  5518. GoodId: item.GoodId,
  5519. Status: 1,
  5520. Ctime: time.Now().Unix(),
  5521. Mtime: 0,
  5522. Count: 0,
  5523. StockCount: 0,
  5524. Creater: creater,
  5525. BatchNumberId: 0,
  5526. WarehouseOutId: 0,
  5527. }
  5528. service.CreateGoodErrcode(goodErrcode)
  5529. }
  5530. }
  5531. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5532. if len(list) == 0 {
  5533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5534. return
  5535. }
  5536. for _, item := range list {
  5537. prepare := models.DialysisBeforePrepare{
  5538. UserOrgId: adminInfo.Org.Id,
  5539. PatientId: patient_id,
  5540. RecordDate: record_time,
  5541. GoodId: item.GoodId,
  5542. GoodTypeId: item.GoodTypeId,
  5543. Count: item.Count,
  5544. Creater: adminInfo.AdminUser.Id,
  5545. Status: 1,
  5546. Ctime: time.Now().Unix(),
  5547. StorehouseId: houseConfig.StorehouseOutInfo,
  5548. }
  5549. //清空准备表数据
  5550. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5551. if err != nil {
  5552. goodErrcode := models.XtGoodErrcode{
  5553. UserOrgId: item.OrgId,
  5554. Errcode: "自动出库清空准备表数据报错",
  5555. GoodId: item.GoodId,
  5556. Status: 1,
  5557. Ctime: time.Now().Unix(),
  5558. Mtime: 0,
  5559. Count: 0,
  5560. StockCount: 0,
  5561. Creater: creater,
  5562. BatchNumberId: 0,
  5563. WarehouseOutId: 0,
  5564. }
  5565. service.CreateGoodErrcode(goodErrcode)
  5566. }
  5567. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5568. if errs != nil {
  5569. goodErrcode := models.XtGoodErrcode{
  5570. UserOrgId: item.OrgId,
  5571. Errcode: "自动出库创建准备表数据报错",
  5572. GoodId: item.GoodId,
  5573. Status: 1,
  5574. Ctime: time.Now().Unix(),
  5575. Mtime: 0,
  5576. Count: 0,
  5577. StockCount: 0,
  5578. Creater: creater,
  5579. BatchNumberId: 0,
  5580. WarehouseOutId: 0,
  5581. }
  5582. service.CreateGoodErrcode(goodErrcode)
  5583. }
  5584. //查询默认仓库
  5585. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5586. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5587. var total_count int64
  5588. for _, it := range stockList {
  5589. total_count += it.StockCount
  5590. }
  5591. //基础库插入数据
  5592. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5593. if errcodes != nil {
  5594. goodErrcode := models.XtGoodErrcode{
  5595. UserOrgId: item.OrgId,
  5596. Errcode: "自动出库基础库插入数据",
  5597. GoodId: item.GoodId,
  5598. Status: 1,
  5599. Ctime: time.Now().Unix(),
  5600. Mtime: 0,
  5601. Count: 0,
  5602. StockCount: 0,
  5603. Creater: creater,
  5604. BatchNumberId: 0,
  5605. WarehouseOutId: 0,
  5606. }
  5607. service.CreateGoodErrcode(goodErrcode)
  5608. }
  5609. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5610. var flush_count int64
  5611. for _, it := range goodList {
  5612. flush_count += it.StockCount
  5613. }
  5614. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5615. if errsss != nil {
  5616. goodErrcode := models.XtGoodErrcode{
  5617. UserOrgId: item.OrgId,
  5618. Errcode: "自动出库剩余库存更新数据",
  5619. GoodId: item.GoodId,
  5620. Status: 1,
  5621. Ctime: time.Now().Unix(),
  5622. Mtime: 0,
  5623. Count: 0,
  5624. StockCount: 0,
  5625. Creater: creater,
  5626. BatchNumberId: 0,
  5627. WarehouseOutId: 0,
  5628. }
  5629. service.CreateGoodErrcode(goodErrcode)
  5630. }
  5631. }
  5632. }
  5633. //
  5634. } else if err == nil {
  5635. for _, item := range consumables {
  5636. //出库
  5637. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5638. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5639. if err != nil {
  5640. goodErrcode := models.XtGoodErrcode{
  5641. UserOrgId: adminInfo.Org.Id,
  5642. Errcode: "自动出库接口报错",
  5643. GoodId: 0,
  5644. Status: 1,
  5645. Ctime: time.Now().Unix(),
  5646. Mtime: 0,
  5647. Count: 0,
  5648. StockCount: 0,
  5649. Creater: creator,
  5650. BatchNumberId: 0,
  5651. WarehouseOutId: 0,
  5652. }
  5653. service.CreateGoodErrcode(goodErrcode)
  5654. }
  5655. //出库数量相加
  5656. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5657. if errss != nil {
  5658. goodErrcode := models.XtGoodErrcode{
  5659. UserOrgId: item.UserOrgId,
  5660. Errcode: "创建剩余库存字段报错",
  5661. GoodId: item.GoodId,
  5662. Status: 1,
  5663. Ctime: time.Now().Unix(),
  5664. Mtime: time.Now().Unix(),
  5665. Count: 0,
  5666. StockCount: 0,
  5667. Creater: item.Creater,
  5668. BatchNumberId: 0,
  5669. WarehouseOutId: 0,
  5670. }
  5671. service.CreateGoodErrcode(goodErrcode)
  5672. }
  5673. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5674. if len(list) == 0 {
  5675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5676. return
  5677. }
  5678. for _, item := range list {
  5679. prepare := models.DialysisBeforePrepare{
  5680. UserOrgId: adminInfo.Org.Id,
  5681. PatientId: patient_id,
  5682. RecordDate: record_time,
  5683. GoodId: item.GoodId,
  5684. GoodTypeId: item.GoodTypeId,
  5685. Count: item.Count,
  5686. Creater: adminInfo.AdminUser.Id,
  5687. Status: 1,
  5688. Ctime: time.Now().Unix(),
  5689. StorehouseId: houseConfig.StorehouseOutInfo,
  5690. }
  5691. //清空准备表数据
  5692. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5693. if errs != nil {
  5694. goodErrcode := models.XtGoodErrcode{
  5695. UserOrgId: adminInfo.Org.Id,
  5696. Errcode: "自动出库清空准备表数据报错",
  5697. GoodId: 0,
  5698. Status: 1,
  5699. Ctime: time.Now().Unix(),
  5700. Mtime: 0,
  5701. Count: 0,
  5702. StockCount: 0,
  5703. Creater: creator,
  5704. BatchNumberId: 0,
  5705. WarehouseOutId: 0,
  5706. }
  5707. service.CreateGoodErrcode(goodErrcode)
  5708. }
  5709. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5710. if errcodes != nil {
  5711. goodErrcode := models.XtGoodErrcode{
  5712. UserOrgId: adminInfo.Org.Id,
  5713. Errcode: "自动出库创建准备表数据报错",
  5714. GoodId: 0,
  5715. Status: 1,
  5716. Ctime: time.Now().Unix(),
  5717. Mtime: 0,
  5718. Count: 0,
  5719. StockCount: 0,
  5720. Creater: creator,
  5721. BatchNumberId: 0,
  5722. WarehouseOutId: 0,
  5723. }
  5724. service.CreateGoodErrcode(goodErrcode)
  5725. }
  5726. //查询默认仓库
  5727. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5728. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5729. var total_count int64
  5730. for _, it := range stockList {
  5731. total_count += it.StockCount
  5732. }
  5733. //基础库插入数据
  5734. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5735. if errcodes != nil {
  5736. goodErrcode := models.XtGoodErrcode{
  5737. UserOrgId: adminInfo.Org.Id,
  5738. Errcode: "自动出库基础库插入数据报错",
  5739. GoodId: 0,
  5740. Status: 1,
  5741. Ctime: time.Now().Unix(),
  5742. Mtime: 0,
  5743. Count: 0,
  5744. StockCount: 0,
  5745. Creater: creator,
  5746. BatchNumberId: 0,
  5747. WarehouseOutId: 0,
  5748. }
  5749. service.CreateGoodErrcode(goodErrcode)
  5750. }
  5751. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5752. var flush_count int64
  5753. for _, it := range goodList {
  5754. flush_count += it.StockCount
  5755. }
  5756. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5757. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5758. if errss != nil {
  5759. goodErrcode := models.XtGoodErrcode{
  5760. UserOrgId: item.OrgId,
  5761. Errcode: "自动出库剩余库存更新数据",
  5762. GoodId: item.GoodId,
  5763. Status: 1,
  5764. Ctime: time.Now().Unix(),
  5765. Mtime: 0,
  5766. Count: 0,
  5767. StockCount: 0,
  5768. Creater: creater,
  5769. BatchNumberId: 0,
  5770. WarehouseOutId: 0,
  5771. }
  5772. service.CreateGoodErrcode(goodErrcode)
  5773. }
  5774. }
  5775. }
  5776. }
  5777. c.ServeSuccessJSON(map[string]interface{}{
  5778. "msg": "提交成功",
  5779. "message": "2",
  5780. "good_name": "",
  5781. "specification_name": "",
  5782. })
  5783. return
  5784. }
  5785. if record.IsOpen == 1 {
  5786. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5787. //查询是否有库存
  5788. for _, item := range consumables {
  5789. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5790. if item.Count > warehouse.Count {
  5791. goodErrcode := models.XtGoodErrcode{
  5792. UserOrgId: item.UserOrgId,
  5793. Errcode: "自动出库库存不足",
  5794. GoodId: item.GoodId,
  5795. Status: 1,
  5796. Ctime: time.Now().Unix(),
  5797. Mtime: 0,
  5798. Count: 0,
  5799. StockCount: 0,
  5800. Creater: creator,
  5801. BatchNumberId: warehouse.ID,
  5802. WarehouseOutId: 0,
  5803. }
  5804. service.CreateGoodErrcode(goodErrcode)
  5805. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5806. c.ServeSuccessJSON(map[string]interface{}{
  5807. "message": "1",
  5808. "good_name": goodObj.GoodName,
  5809. "specification_name": goodObj.SpecificationName,
  5810. })
  5811. return
  5812. }
  5813. }
  5814. //查询是否有出库单
  5815. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5816. if err == gorm.ErrRecordNotFound {
  5817. //没有记录,则创建出库单
  5818. timeStr := time.Now().Format("2006-01-02")
  5819. timeArr := strings.Split(timeStr, "-")
  5820. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5821. total = total + 1
  5822. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5823. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5824. number = number + total
  5825. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5826. creater := adminInfo.AdminUser.Id
  5827. warehouseOut := models.WarehouseOut{
  5828. WarehouseOutOrderNumber: warehousing_out_order,
  5829. OperationTime: time.Now().Unix(),
  5830. OrgId: adminInfo.Org.Id,
  5831. Creater: creater,
  5832. Ctime: time.Now().Unix(),
  5833. Status: 1,
  5834. WarehouseOutTime: record_time,
  5835. Dealer: 0,
  5836. Manufacturer: 0,
  5837. Type: 1,
  5838. IsSys: 1,
  5839. StorehouseId: houseConfig.StorehouseOutInfo,
  5840. IsCheck: 1,
  5841. }
  5842. err := service.AddSigleWarehouseOut(&warehouseOut)
  5843. if err != nil {
  5844. goodErrcode := models.XtGoodErrcode{
  5845. UserOrgId: adminInfo.Org.Id,
  5846. Errcode: "创建出库单失败",
  5847. GoodId: 0,
  5848. Status: 1,
  5849. Ctime: time.Now().Unix(),
  5850. Mtime: 0,
  5851. Count: 0,
  5852. StockCount: 0,
  5853. Creater: creator,
  5854. BatchNumberId: 0,
  5855. WarehouseOutId: 0,
  5856. }
  5857. service.CreateGoodErrcode(goodErrcode)
  5858. utils.TraceLog("创建出库单失败 err = %v", err)
  5859. } else {
  5860. for _, item := range consumables {
  5861. //出库
  5862. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5863. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5864. if err == nil {
  5865. goodErrcode := models.XtGoodErrcode{
  5866. UserOrgId: adminInfo.Org.Id,
  5867. Errcode: "自动出库接口报错",
  5868. GoodId: 0,
  5869. Status: 1,
  5870. Ctime: time.Now().Unix(),
  5871. Mtime: 0,
  5872. Count: 0,
  5873. StockCount: 0,
  5874. Creater: creator,
  5875. BatchNumberId: 0,
  5876. WarehouseOutId: 0,
  5877. }
  5878. service.CreateGoodErrcode(goodErrcode)
  5879. utils.TraceLog("创建出库单失败 err = %v", err)
  5880. }
  5881. //查询
  5882. //出库数量相加
  5883. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5884. if errs != nil {
  5885. goodErrcode := models.XtGoodErrcode{
  5886. UserOrgId: item.UserOrgId,
  5887. Errcode: "创建剩余库存字段报错",
  5888. GoodId: item.GoodId,
  5889. Status: 1,
  5890. Ctime: time.Now().Unix(),
  5891. Mtime: 0,
  5892. Count: 0,
  5893. StockCount: 0,
  5894. Creater: creater,
  5895. BatchNumberId: 0,
  5896. WarehouseOutId: 0,
  5897. }
  5898. service.CreateGoodErrcode(goodErrcode)
  5899. }
  5900. }
  5901. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5902. if len(list) == 0 {
  5903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5904. return
  5905. }
  5906. for _, item := range list {
  5907. prepare := models.DialysisBeforePrepare{
  5908. UserOrgId: adminInfo.Org.Id,
  5909. PatientId: patient_id,
  5910. RecordDate: record_time,
  5911. GoodId: item.GoodId,
  5912. GoodTypeId: item.GoodTypeId,
  5913. Count: item.Count,
  5914. Creater: adminInfo.AdminUser.Id,
  5915. Status: 1,
  5916. Ctime: time.Now().Unix(),
  5917. StorehouseId: houseConfig.StorehouseOutInfo,
  5918. }
  5919. //清空准备表数据
  5920. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5921. if err != nil {
  5922. goodErrcode := models.XtGoodErrcode{
  5923. UserOrgId: item.OrgId,
  5924. Errcode: "自动出库清空准备表数据报错",
  5925. GoodId: item.GoodId,
  5926. Status: 1,
  5927. Ctime: time.Now().Unix(),
  5928. Mtime: 0,
  5929. Count: 0,
  5930. StockCount: 0,
  5931. Creater: creater,
  5932. BatchNumberId: 0,
  5933. WarehouseOutId: 0,
  5934. }
  5935. service.CreateGoodErrcode(goodErrcode)
  5936. }
  5937. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5938. if errs != nil {
  5939. goodErrcode := models.XtGoodErrcode{
  5940. UserOrgId: item.OrgId,
  5941. Errcode: "自动出库创建准备表数据报错",
  5942. GoodId: item.GoodId,
  5943. Status: 1,
  5944. Ctime: time.Now().Unix(),
  5945. Mtime: 0,
  5946. Count: 0,
  5947. StockCount: 0,
  5948. Creater: creater,
  5949. BatchNumberId: 0,
  5950. WarehouseOutId: 0,
  5951. }
  5952. service.CreateGoodErrcode(goodErrcode)
  5953. }
  5954. //查询默认仓库
  5955. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5956. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5957. var total_count int64
  5958. for _, it := range stockList {
  5959. total_count += it.StockCount
  5960. }
  5961. //基础库插入数据
  5962. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5963. if errcodes != nil {
  5964. goodErrcode := models.XtGoodErrcode{
  5965. UserOrgId: item.OrgId,
  5966. Errcode: "自动出库基础库插入数据",
  5967. GoodId: item.GoodId,
  5968. Status: 1,
  5969. Ctime: time.Now().Unix(),
  5970. Mtime: 0,
  5971. Count: 0,
  5972. StockCount: 0,
  5973. Creater: creater,
  5974. BatchNumberId: 0,
  5975. WarehouseOutId: 0,
  5976. }
  5977. service.CreateGoodErrcode(goodErrcode)
  5978. }
  5979. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5980. var flush_count int64
  5981. for _, it := range goodList {
  5982. flush_count += it.StockCount
  5983. }
  5984. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5985. if errsss != nil {
  5986. goodErrcode := models.XtGoodErrcode{
  5987. UserOrgId: item.OrgId,
  5988. Errcode: "自动出库剩余库存更新数据",
  5989. GoodId: item.GoodId,
  5990. Status: 1,
  5991. Ctime: time.Now().Unix(),
  5992. Mtime: 0,
  5993. Count: 0,
  5994. StockCount: 0,
  5995. Creater: creater,
  5996. BatchNumberId: 0,
  5997. WarehouseOutId: 0,
  5998. }
  5999. service.CreateGoodErrcode(goodErrcode)
  6000. }
  6001. }
  6002. }
  6003. //
  6004. } else if err == nil {
  6005. for _, item := range consumables {
  6006. //出库
  6007. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6008. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6009. if err != nil {
  6010. goodErrcode := models.XtGoodErrcode{
  6011. UserOrgId: adminInfo.Org.Id,
  6012. Errcode: "自动出库接口报错",
  6013. GoodId: 0,
  6014. Status: 1,
  6015. Ctime: time.Now().Unix(),
  6016. Mtime: 0,
  6017. Count: 0,
  6018. StockCount: 0,
  6019. Creater: creator,
  6020. BatchNumberId: 0,
  6021. WarehouseOutId: 0,
  6022. }
  6023. service.CreateGoodErrcode(goodErrcode)
  6024. }
  6025. //出库数量相加
  6026. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6027. if errss != nil {
  6028. goodErrcode := models.XtGoodErrcode{
  6029. UserOrgId: item.UserOrgId,
  6030. Errcode: "创建剩余库存字段报错",
  6031. GoodId: item.GoodId,
  6032. Status: 1,
  6033. Ctime: time.Now().Unix(),
  6034. Mtime: time.Now().Unix(),
  6035. Count: 0,
  6036. StockCount: 0,
  6037. Creater: item.Creater,
  6038. BatchNumberId: 0,
  6039. WarehouseOutId: 0,
  6040. }
  6041. service.CreateGoodErrcode(goodErrcode)
  6042. }
  6043. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6044. if len(list) == 0 {
  6045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6046. return
  6047. }
  6048. for _, item := range list {
  6049. prepare := models.DialysisBeforePrepare{
  6050. UserOrgId: adminInfo.Org.Id,
  6051. PatientId: patient_id,
  6052. RecordDate: record_time,
  6053. GoodId: item.GoodId,
  6054. GoodTypeId: item.GoodTypeId,
  6055. Count: item.Count,
  6056. Creater: adminInfo.AdminUser.Id,
  6057. Status: 1,
  6058. Ctime: time.Now().Unix(),
  6059. StorehouseId: houseConfig.StorehouseOutInfo,
  6060. }
  6061. //清空准备表数据
  6062. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6063. if errs != nil {
  6064. goodErrcode := models.XtGoodErrcode{
  6065. UserOrgId: adminInfo.Org.Id,
  6066. Errcode: "自动出库清空准备表数据报错",
  6067. GoodId: 0,
  6068. Status: 1,
  6069. Ctime: time.Now().Unix(),
  6070. Mtime: 0,
  6071. Count: 0,
  6072. StockCount: 0,
  6073. Creater: creator,
  6074. BatchNumberId: 0,
  6075. WarehouseOutId: 0,
  6076. }
  6077. service.CreateGoodErrcode(goodErrcode)
  6078. }
  6079. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6080. if errcodes != nil {
  6081. goodErrcode := models.XtGoodErrcode{
  6082. UserOrgId: adminInfo.Org.Id,
  6083. Errcode: "自动出库创建准备表数据报错",
  6084. GoodId: 0,
  6085. Status: 1,
  6086. Ctime: time.Now().Unix(),
  6087. Mtime: 0,
  6088. Count: 0,
  6089. StockCount: 0,
  6090. Creater: creator,
  6091. BatchNumberId: 0,
  6092. WarehouseOutId: 0,
  6093. }
  6094. service.CreateGoodErrcode(goodErrcode)
  6095. }
  6096. //查询默认仓库
  6097. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6098. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6099. var total_count int64
  6100. for _, it := range stockList {
  6101. total_count += it.StockCount
  6102. }
  6103. //基础库插入数据
  6104. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6105. if errcodes != nil {
  6106. goodErrcode := models.XtGoodErrcode{
  6107. UserOrgId: adminInfo.Org.Id,
  6108. Errcode: "自动出库基础库插入数据报错",
  6109. GoodId: 0,
  6110. Status: 1,
  6111. Ctime: time.Now().Unix(),
  6112. Mtime: 0,
  6113. Count: 0,
  6114. StockCount: 0,
  6115. Creater: creator,
  6116. BatchNumberId: 0,
  6117. WarehouseOutId: 0,
  6118. }
  6119. service.CreateGoodErrcode(goodErrcode)
  6120. }
  6121. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6122. var flush_count int64
  6123. for _, it := range goodList {
  6124. flush_count += it.StockCount
  6125. }
  6126. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6127. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6128. if errss != nil {
  6129. goodErrcode := models.XtGoodErrcode{
  6130. UserOrgId: item.OrgId,
  6131. Errcode: "自动出库剩余库存更新数据",
  6132. GoodId: item.GoodId,
  6133. Status: 1,
  6134. Ctime: time.Now().Unix(),
  6135. Mtime: 0,
  6136. Count: 0,
  6137. StockCount: 0,
  6138. Creater: creater,
  6139. BatchNumberId: 0,
  6140. WarehouseOutId: 0,
  6141. }
  6142. service.CreateGoodErrcode(goodErrcode)
  6143. }
  6144. }
  6145. }
  6146. }
  6147. c.ServeSuccessJSON(map[string]interface{}{
  6148. "msg": "提交成功",
  6149. "message": "2",
  6150. "good_name": "",
  6151. "specification_name": "",
  6152. })
  6153. return
  6154. } else {
  6155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6156. return
  6157. }
  6158. }
  6159. func (c *DialysisAPIController) EditConsumables() {
  6160. patient_id, _ := c.GetInt64("patient_id", 0)
  6161. record_date := c.GetString("record_time")
  6162. if patient_id <= 0 {
  6163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6164. return
  6165. }
  6166. adminInfo := c.GetMobileAdminUserInfo()
  6167. timeLayout := "2006-01-02"
  6168. loc, _ := time.LoadLocation("Local")
  6169. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6170. record_time := theRecordTime.Unix()
  6171. // 查询信息规挡的设置天数
  6172. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6173. if infor.ID > 0 && infor.WeekDay > 0 {
  6174. var cha_time int64
  6175. timeNowStr := time.Now().Format("2006-01-02")
  6176. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6177. //今日的日期减去设置的日期
  6178. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6179. if cha_time >= record_time {
  6180. //查询审核是否允许
  6181. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6182. //申请状态不允许的情况 拒绝修改
  6183. if infor.ApplicationStatus != 1 {
  6184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6185. return
  6186. }
  6187. }
  6188. }
  6189. dataBody := make(map[string]interface{}, 0)
  6190. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6191. if err != nil {
  6192. utils.ErrorLog(err.Error())
  6193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6194. return
  6195. }
  6196. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6197. var beforePrepares []*models.DialysisBeforePrepareGoods
  6198. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6199. var cancelbefor []*models.DialysisBeforePrepareGoods
  6200. var outbefor []*models.DialysisBeforePrepareGoods
  6201. //判断是否开启自动出库
  6202. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6203. if record.IsOpen == 1 {
  6204. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6205. goods, _ := dataBody["goods"].([]interface{})
  6206. if len(goods) > 0 {
  6207. for _, item := range goods {
  6208. items := item.(map[string]interface{})
  6209. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6210. utils.ErrorLog("good_id")
  6211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6212. return
  6213. }
  6214. good_id := int64(items["good_id"].(float64))
  6215. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6216. utils.ErrorLog("good_type_id")
  6217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6218. return
  6219. }
  6220. good_type_id := int64(items["good_type_id"].(float64))
  6221. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6222. utils.ErrorLog("count")
  6223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6224. return
  6225. }
  6226. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6227. commdity_code := items["commdity_code"].(string)
  6228. fmt.Println(commdity_code)
  6229. prepareGoods := &models.DialysisBeforePrepareGoods{
  6230. GoodTypeId: good_type_id,
  6231. GoodId: good_id,
  6232. Count: count,
  6233. StorehouseId: houseConfig.StorehouseOutInfo,
  6234. }
  6235. beforePrepares = append(beforePrepares, prepareGoods)
  6236. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6237. GoodTypeId: good_type_id,
  6238. GoodId: good_id,
  6239. Count: count,
  6240. StorehouseId: houseConfig.StorehouseOutInfo,
  6241. }
  6242. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6243. }
  6244. for _, item := range beforePrepares {
  6245. //1.查看该患者该耗材型号最后一次出库数量
  6246. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6247. //判断当前出库数量和最后一次出库数量的大小
  6248. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6249. if item.Count < goodInfo.Count {
  6250. cancelbefor = append(cancelbefor, item)
  6251. }
  6252. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6253. if item.Count > goodInfo.Count {
  6254. outbefor = append(outbefor, item)
  6255. }
  6256. //处理编辑耗材新增不了的问题
  6257. if goodInfo.Count == item.Count {
  6258. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6259. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6260. }
  6261. }
  6262. if len(cancelbefor) > 0 {
  6263. //退库
  6264. for _, item := range cancelbefor {
  6265. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6266. creater := adminInfo.AdminUser.Id
  6267. //查询该患者当天已经出库的耗材信息
  6268. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6269. var delete_count int64 = 0
  6270. delete_count = warehouseOutInfos.Count - item.Count
  6271. //增加库存数量
  6272. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6273. //减少实际出库库存数量
  6274. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6275. // 删除出库完成后,要增加对应批次的库存数量
  6276. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6277. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6278. //更新剩余库存
  6279. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6280. var flush_count int64
  6281. for _, it := range goodListOne {
  6282. flush_count += it.StockCount
  6283. }
  6284. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6285. //查询剩余库存
  6286. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6287. var sum_count int64
  6288. for _, item := range goodList {
  6289. sum_count += item.StockCount
  6290. }
  6291. // 在出库记录表里记录退库详情
  6292. warehouseOutInfo := &models.WarehouseOutInfo{
  6293. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6294. WarehouseOutId: warehouseOut.ID,
  6295. Status: 1,
  6296. Ctime: time.Now().Unix(),
  6297. OrgId: adminInfo.Org.Id,
  6298. Type: 1,
  6299. IsSys: 1,
  6300. SysRecordTime: record_time,
  6301. GoodTypeId: item.GoodTypeId,
  6302. GoodId: item.GoodId,
  6303. PatientId: patient_id,
  6304. ConsumableType: 2,
  6305. StorehouseId: houseConfig.StorehouseOutInfo,
  6306. IsCheck: 1,
  6307. OverCount: sum_count,
  6308. }
  6309. warehouseOutInfo.Count = item.Count
  6310. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6311. warehouseOutInfo.Price = stockInInfo.Price
  6312. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6313. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6314. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6315. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6316. warehouseOutInfo.Number = warehouseOutInfos.Number
  6317. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6318. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6319. //查找当天是否存在出库记录
  6320. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6321. if errcod == gorm.ErrRecordNotFound {
  6322. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6323. //插入详情明细表
  6324. stockFlow := models.VmStockFlow{
  6325. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6326. WarehouseOutId: warehouseOut.ID,
  6327. GoodId: item.GoodId,
  6328. Number: warehouseOutInfos.Number,
  6329. ProductDate: stockInInfo.ProductDate,
  6330. ExpireDate: stockInInfo.ExpiryDate,
  6331. Count: item.Count,
  6332. Price: stockInInfo.Price,
  6333. Status: 1,
  6334. Ctime: time.Now().Unix(),
  6335. UserOrgId: adminInfo.Org.Id,
  6336. Manufacturer: stockInInfo.Manufacturer,
  6337. Dealer: stockInInfo.Dealer,
  6338. LicenseNumber: stockInInfo.LicenseNumber,
  6339. IsEdit: 2,
  6340. Creator: creater,
  6341. SystemTime: record_time,
  6342. ConsumableType: 3,
  6343. WarehousingDetailId: 0,
  6344. IsSys: 1,
  6345. UpdateCreator: creater,
  6346. PatientId: patient_id,
  6347. StorehouseId: houseConfig.StorehouseOutInfo,
  6348. }
  6349. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6350. if errflow == gorm.ErrRecordNotFound {
  6351. //创建流水表
  6352. err := service.CreateStockFlowOne(stockFlow)
  6353. fmt.Println("err", err)
  6354. } else if errflow == nil {
  6355. //插入详情明细表
  6356. stockFlow := models.VmStockFlow{
  6357. ID: exsit.ID,
  6358. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6359. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6360. WarehouseOutId: warehouseOut.ID,
  6361. GoodId: item.GoodId,
  6362. Number: warehouseOutInfos.Number,
  6363. ProductDate: stockInInfo.ProductDate,
  6364. ExpireDate: stockInInfo.ExpiryDate,
  6365. Count: exsit.Count - delete_count,
  6366. Price: stockInInfo.Price,
  6367. Status: 1,
  6368. Ctime: time.Now().Unix(),
  6369. UserOrgId: adminInfo.Org.Id,
  6370. Manufacturer: stockInInfo.Manufacturer,
  6371. Dealer: stockInInfo.Dealer,
  6372. LicenseNumber: stockInInfo.LicenseNumber,
  6373. IsEdit: 2,
  6374. Creator: creater,
  6375. SystemTime: record_time,
  6376. ConsumableType: 3,
  6377. WarehousingDetailId: 0,
  6378. IsSys: 1,
  6379. UpdateCreator: creater,
  6380. PatientId: patient_id,
  6381. StorehouseId: houseConfig.StorehouseOutInfo,
  6382. }
  6383. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6384. }
  6385. } else if errcod == nil {
  6386. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6387. //查询剩余库存
  6388. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6389. var sum_count int64
  6390. for _, item := range goodList {
  6391. sum_count += item.StockCount
  6392. }
  6393. //创建退库单,生成退库数据
  6394. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6395. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6396. operation_time := time.Now().Unix()
  6397. creater := adminInfo.AdminUser.Id
  6398. //创建退库单
  6399. timeStr := time.Now().Format("2006-01-02")
  6400. timeArr := strings.Split(timeStr, "-")
  6401. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6402. total = total + 1
  6403. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6404. cancelStock := models.CancelStock{
  6405. OrderNumber: orderNumber,
  6406. OperaTime: operation_time,
  6407. OrgId: adminInfo.Org.Id,
  6408. Creater: creater,
  6409. Ctime: time.Now().Unix(),
  6410. Status: 1,
  6411. ReturnTime: record_time,
  6412. Type: 1,
  6413. StorehouseId: houseConfig.StorehouseOutInfo,
  6414. IsCheck: 1,
  6415. }
  6416. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6417. if msgerrkonde == gorm.ErrRecordNotFound {
  6418. service.AddSigleCancelStock(&cancelStock)
  6419. }
  6420. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6421. //查询是否有出库
  6422. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6423. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6424. deaerler, _ := service.GetDealerById(info.Dealer)
  6425. if info.ID > 0 {
  6426. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6427. cancelStockInfo := models.CancelStockInfo{
  6428. GoodId: item.GoodId,
  6429. CancelStockId: cancel.ID,
  6430. GoodTypeId: good.GoodTypeId,
  6431. Count: delete_count,
  6432. Price: info.Price,
  6433. Total: 0,
  6434. ProductDate: info.ProductDate,
  6435. ExpiryDate: info.ExpiryDate,
  6436. Ctime: time.Now().Unix(),
  6437. Status: 1,
  6438. OrgId: adminInfo.Org.Id,
  6439. OrderNumber: cancel.OrderNumber,
  6440. Type: 0,
  6441. Dealer: deaerler.DealerName,
  6442. Manufacturer: manufacturer.ManufacturerName,
  6443. Number: info.Number,
  6444. RegisterAccount: "",
  6445. Remark: "",
  6446. WarehouseInfoId: info.WarehouseInfotId,
  6447. PatientId: info.PatientId,
  6448. RecordDate: info.SysRecordTime,
  6449. StorehouseId: houseConfig.StorehouseOutInfo,
  6450. IsCheck: 1,
  6451. }
  6452. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6453. //退库数量增加
  6454. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6455. //查询剩余库存
  6456. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6457. var over_count int64
  6458. for _, it := range goodList {
  6459. over_count += it.StockCount
  6460. }
  6461. flow := models.VmStockFlow{
  6462. WarehousingId: info.WarehouseInfotId,
  6463. GoodId: item.GoodId,
  6464. Number: info.Number,
  6465. LicenseNumber: info.LicenseNumber,
  6466. Count: delete_count,
  6467. UserOrgId: adminInfo.Org.Id,
  6468. PatientId: patient_id,
  6469. SystemTime: info.SysRecordTime,
  6470. ConsumableType: 7,
  6471. IsSys: 0,
  6472. WarehousingOrder: "",
  6473. WarehouseOutId: info.WarehouseOutId,
  6474. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6475. IsEdit: 0,
  6476. CancelStockId: cancel.ID,
  6477. CancelOrderNumber: cancel.OrderNumber,
  6478. Manufacturer: manufacturer.ID,
  6479. Dealer: 0,
  6480. Creator: adminInfo.AdminUser.Id,
  6481. UpdateCreator: 0,
  6482. Status: 1,
  6483. Ctime: time.Now().Unix(),
  6484. Mtime: 0,
  6485. Price: info.Price,
  6486. WarehousingDetailId: info.WarehouseInfotId,
  6487. WarehouseOutDetailId: info.ID,
  6488. CancelOutDetailId: cancelInfo.ID,
  6489. ProductDate: info.ProductDate,
  6490. ExpireDate: info.ExpiryDate,
  6491. StorehouseId: houseConfig.StorehouseOutInfo,
  6492. OverCount: over_count,
  6493. }
  6494. service.CreateStockFlowOne(flow)
  6495. }
  6496. }
  6497. //更改自动出库的表格
  6498. details := models.BloodAutomaticReduceDetail{
  6499. WarehouseOutId: warehouseOutInfo.ID,
  6500. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6501. PatientId: patient_id,
  6502. Ctime: time.Now().Unix(),
  6503. Mtime: time.Now().Unix(),
  6504. Status: 1,
  6505. RecordTime: record_time,
  6506. OrgId: adminInfo.Org.Id,
  6507. GoodId: item.GoodId,
  6508. GoodTypeId: item.GoodTypeId,
  6509. Count: item.Count,
  6510. StorehouseId: houseConfig.StorehouseOutInfo,
  6511. }
  6512. //查询当天耗材是否已经存在数据
  6513. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6514. if errcode == gorm.ErrRecordNotFound {
  6515. service.CreateAutoReduceRecord(&details)
  6516. } else if errcode == nil {
  6517. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6518. service.CreateAutoReduceRecord(&details)
  6519. }
  6520. //查询默认仓库
  6521. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6522. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6523. var total_count int64
  6524. for _, it := range stockList {
  6525. total_count += it.StockCount
  6526. }
  6527. //基础库插入数据
  6528. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6529. }
  6530. }
  6531. if len(outbefor) > 0 {
  6532. //出库
  6533. for _, item := range outbefor {
  6534. var last_total int64
  6535. //1.查看该患者该耗材型号最后一次出库数量
  6536. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6537. //计算当前出库和最后一次出库数据相差数据
  6538. last_total = item.Count - goodInfoOne.Count
  6539. //查询该耗材的总库存
  6540. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6541. // 如果库存差大于剩余库存则提示库存不足
  6542. if last_total > wareinfo.StockCount {
  6543. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6544. c.ServeSuccessJSON(map[string]interface{}{
  6545. "message": "1",
  6546. "good_name": goodObj.GoodName,
  6547. "specification_name": goodObj.SpecificationName,
  6548. })
  6549. return
  6550. } else {
  6551. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6552. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6553. if err == gorm.ErrRecordNotFound {
  6554. //没有记录,则创建出库单
  6555. timeStr := time.Now().Format("2006-01-02")
  6556. timeArr := strings.Split(timeStr, "-")
  6557. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6558. total = total + 1
  6559. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6560. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6561. number = number + total
  6562. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6563. warehouseOut := models.WarehouseOut{
  6564. WarehouseOutOrderNumber: warehousing_out_order,
  6565. OperationTime: time.Now().Unix(),
  6566. OrgId: adminInfo.Org.Id,
  6567. Creater: adminInfo.AdminUser.Id,
  6568. Ctime: time.Now().Unix(),
  6569. Status: 1,
  6570. WarehouseOutTime: record_time,
  6571. Dealer: 0,
  6572. Manufacturer: 0,
  6573. Type: 1,
  6574. IsSys: 1,
  6575. StorehouseId: houseConfig.StorehouseOutInfo,
  6576. IsCheck: 1,
  6577. }
  6578. service.AddSigleWarehouseOut(&warehouseOut)
  6579. }
  6580. //出库
  6581. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6582. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6583. //1.查看该患者该耗材型号最后一次出库数量
  6584. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6585. prepare := models.DialysisBeforePrepare{
  6586. UserOrgId: adminInfo.Org.Id,
  6587. PatientId: patient_id,
  6588. RecordDate: record_time,
  6589. GoodId: item.GoodId,
  6590. GoodTypeId: item.GoodTypeId,
  6591. Count: item.Count - goodInfoTwo.Count,
  6592. Ctime: time.Now().Unix(),
  6593. Mtime: 0,
  6594. Creater: adminInfo.AdminUser.Id,
  6595. Modifier: adminInfo.AdminUser.Id,
  6596. Status: 1,
  6597. CommdityCode: "",
  6598. NewCount: 0,
  6599. ProjectId: 0,
  6600. StorehouseId: houseConfig.StorehouseOutInfo,
  6601. }
  6602. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6603. //增加出库数量
  6604. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6605. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6606. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6607. var total_count int64
  6608. for _, it := range stockList {
  6609. total_count += it.StockCount
  6610. }
  6611. //基础库插入数据
  6612. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6613. //剩余库存
  6614. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6615. var flush_count int64
  6616. for _, it := range goodList {
  6617. flush_count += it.StockCount
  6618. }
  6619. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6620. }
  6621. }
  6622. }
  6623. //查询今日出库数据
  6624. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6625. for _, it := range list {
  6626. prepare := models.DialysisBeforePrepare{
  6627. UserOrgId: it.OrgId,
  6628. PatientId: patient_id,
  6629. RecordDate: it.RecordTime,
  6630. GoodId: it.GoodId,
  6631. GoodTypeId: it.GoodTypeId,
  6632. Count: it.Count,
  6633. Ctime: time.Now().Unix(),
  6634. Creater: adminInfo.AdminUser.Id,
  6635. Status: 1,
  6636. StorehouseId: houseConfig.StorehouseOutInfo,
  6637. ProjectId: it.ProjectId,
  6638. }
  6639. //删除准备表数据
  6640. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6641. service.CreateDialysisBeforePrepareOne(&prepare)
  6642. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6643. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6644. var total_count int64
  6645. for _, it := range stockList {
  6646. total_count += it.StockCount
  6647. }
  6648. //基础库插入数据
  6649. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6650. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6651. var flush_count int64
  6652. for _, it := range goodList {
  6653. flush_count += it.StockCount
  6654. }
  6655. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6656. }
  6657. }
  6658. }
  6659. //更新自动出库的地方
  6660. var errs error
  6661. if errs == nil {
  6662. c.ServeSuccessJSON(map[string]interface{}{
  6663. "msg": "修改成功",
  6664. "message": "2",
  6665. "good_name": "",
  6666. "specification_name": "",
  6667. })
  6668. return
  6669. } else {
  6670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6671. return
  6672. }
  6673. }
  6674. }
  6675. func (c *DialysisAPIController) GetDialysisGoods() {
  6676. schedualDate := c.GetString("schedule_date")
  6677. schedule_type, _ := c.GetInt64("schedule_type")
  6678. partition_id, _ := c.GetInt64("partition_id")
  6679. page, _ := c.GetInt("page")
  6680. patient_id, _ := c.GetInt64("patient_id")
  6681. schedualEndDate := int64(0)
  6682. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6683. if parseDateErr != nil && len(schedualDate) != 0 {
  6684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6685. return
  6686. }
  6687. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6688. if parseDateErr != nil && len(schedualDate) != 0 {
  6689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6690. return
  6691. }
  6692. schedualEndDate = endDate.Unix()
  6693. adminUser := c.GetMobileAdminUserInfo()
  6694. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6695. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6696. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6697. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6698. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6699. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6700. //获取当天该病人的透析处方
  6701. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6702. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6703. if err == gorm.ErrRecordNotFound {
  6704. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6705. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6706. if patient_id != 0 {
  6707. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6708. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6709. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6710. //获取患者总的出库数据
  6711. item.LastAutomaticReduceDetail = goodUser
  6712. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6713. item.Project = project
  6714. }
  6715. }
  6716. c.ServeSuccessJSON(map[string]interface{}{
  6717. "dialysis_goods": dialysisGoods,
  6718. "good_type": goodTypes,
  6719. "total": total,
  6720. "prescribe": prescribe,
  6721. "good_info": good_info,
  6722. "warehouseOutList": warehouseOutList,
  6723. "config": config,
  6724. "outConfig": outConfig,
  6725. "settleConfig": settleConfig,
  6726. })
  6727. return
  6728. } else if err == nil {
  6729. //获取当天排班的每个患者的库存使用情况
  6730. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6731. //获取患者总的出库数据
  6732. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6733. if patient_id != 0 {
  6734. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6735. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6736. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6737. item.Project = project
  6738. item.LastAutomaticReduceDetail = goodUser
  6739. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6740. }
  6741. }
  6742. if err == nil {
  6743. c.ServeSuccessJSON(map[string]interface{}{
  6744. "dialysis_goods": dialysisGoods,
  6745. "good_type": goodTypes,
  6746. "total": total,
  6747. "prescribe": prescribe,
  6748. "good_info": good_info,
  6749. "project": project,
  6750. "warehouseOutList": warehouseOutList,
  6751. "config": config,
  6752. "outConfig": outConfig,
  6753. "settleConfig": settleConfig,
  6754. })
  6755. return
  6756. } else {
  6757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6758. return
  6759. }
  6760. } else if err != nil {
  6761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6762. return
  6763. }
  6764. }
  6765. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6766. start_time := c.GetString("start_time")
  6767. end_time := c.GetString("end_time")
  6768. timeLayout := "2006-01-02"
  6769. loc, _ := time.LoadLocation("Local")
  6770. var theStartTime int64
  6771. if len(start_time) > 0 {
  6772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6773. if err != nil {
  6774. utils.ErrorLog(err.Error())
  6775. }
  6776. theStartTime = theTime.Unix()
  6777. }
  6778. var theEndtTime int64
  6779. if len(end_time) > 0 {
  6780. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6781. if err != nil {
  6782. utils.ErrorLog(err.Error())
  6783. }
  6784. theEndtTime = theTime.Unix()
  6785. }
  6786. adminUser := c.GetMobileAdminUserInfo()
  6787. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6788. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6789. if err == nil {
  6790. c.ServeSuccessJSON(map[string]interface{}{
  6791. "stock_out": outInfo,
  6792. "stockCount": stockCount,
  6793. })
  6794. return
  6795. } else {
  6796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6797. return
  6798. }
  6799. }
  6800. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6801. patient_id, _ := c.GetInt64("patient_id", 0)
  6802. record_time := c.GetString("record_time")
  6803. adminUser := c.GetMobileAdminUserInfo()
  6804. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6805. if parseDateErr != nil && len(record_time) != 0 {
  6806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6807. return
  6808. }
  6809. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6810. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6811. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6812. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6813. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6814. //获取今日患者的透析处方参数
  6815. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6816. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6817. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6818. c.ServeSuccessJSON(map[string]interface{}{
  6819. "good_type": goodTypes,
  6820. "good_user": goodUser,
  6821. "good_info": good_info,
  6822. "last_good_user": lastGoodUserDetial,
  6823. "project": project,
  6824. "prescription": prescribe,
  6825. "outInfo": outInfo,
  6826. "configs": configs,
  6827. })
  6828. return
  6829. }
  6830. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6831. patient_id, _ := c.GetInt64("patient_id", 0)
  6832. record_date := c.GetString("record_time")
  6833. timeLayout := "2006-01-02"
  6834. loc, _ := time.LoadLocation("Local")
  6835. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6836. record_time := theRecordTime.Unix()
  6837. adminInfo := c.GetMobileAdminUserInfo()
  6838. dataBody := make(map[string]interface{}, 0)
  6839. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6840. if err != nil {
  6841. utils.ErrorLog(err.Error())
  6842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6843. return
  6844. }
  6845. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6846. var beforePrepares []*models.DialysisBeforePrepareGoods
  6847. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6848. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6849. goods, _ := dataBody["goods"].([]interface{})
  6850. if len(goods) > 0 {
  6851. for _, item := range goods {
  6852. items := item.(map[string]interface{})
  6853. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6854. utils.ErrorLog("good_id")
  6855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6856. return
  6857. }
  6858. good_id := int64(items["good_id"].(float64))
  6859. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6860. utils.ErrorLog("good_type_id")
  6861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6862. return
  6863. }
  6864. good_type_id := int64(items["good_type_id"].(float64))
  6865. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6866. utils.ErrorLog("count")
  6867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6868. return
  6869. }
  6870. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6871. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6872. utils.ErrorLog("project_id")
  6873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6874. return
  6875. }
  6876. project_id := int64(items["project_id"].(float64))
  6877. new_count := int64(items["new_count"].(float64))
  6878. old_count := int64(items["old_count"].(float64))
  6879. prepare := &models.DialysisBeforePrepareGoods{
  6880. GoodId: good_id,
  6881. GoodTypeId: good_type_id,
  6882. Count: count,
  6883. ProjectId: project_id,
  6884. StorehouseId: houseConfig.StorehouseOutInfo,
  6885. NewCount: new_count,
  6886. OldCount: old_count,
  6887. }
  6888. beforePrepares = append(beforePrepares, prepare)
  6889. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6890. GoodId: good_id,
  6891. GoodTypeId: good_type_id,
  6892. Count: count,
  6893. ProjectId: project_id,
  6894. StorehouseId: houseConfig.StorehouseOutInfo,
  6895. NewCount: new_count,
  6896. OldCount: old_count,
  6897. }
  6898. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6899. }
  6900. }
  6901. }
  6902. //查询是否有库存
  6903. for _, item := range beforePrepares {
  6904. if item.NewCount > 0 {
  6905. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6906. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6907. if item.Count > warehouse.Count {
  6908. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6909. c.ServeSuccessJSON(map[string]interface{}{
  6910. "message": "1",
  6911. "good_name": goodObj.GoodName,
  6912. "specification_name": goodObj.SpecificationName,
  6913. })
  6914. return
  6915. }
  6916. }
  6917. }
  6918. // 查询信息规挡的设置天数
  6919. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6920. if infor.ID > 0 && infor.WeekDay > 0 {
  6921. var cha_time int64
  6922. timeNowStr := time.Now().Format("2006-01-02")
  6923. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6924. //今日的日期减去设置的日期
  6925. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6926. if cha_time >= record_time {
  6927. //查询审核是否允许
  6928. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6929. //申请状态不允许的情况 拒绝修改
  6930. if infor.ApplicationStatus != 1 {
  6931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6932. return
  6933. }
  6934. }
  6935. }
  6936. //出库逻辑
  6937. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6938. if err != nil {
  6939. utils.ErrorLog(err.Error())
  6940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6941. return
  6942. }
  6943. finish := models.XtDialysisFinish{
  6944. IsFinish: 1,
  6945. UserOrgId: adminInfo.Org.Id,
  6946. Status: 1,
  6947. Ctime: time.Now().Unix(),
  6948. Mtime: 0,
  6949. Module: 11,
  6950. RecordDate: record_time,
  6951. Sourse: 1,
  6952. PatientId: patient_id,
  6953. }
  6954. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6955. if dialysisFinish.ID == 0 {
  6956. service.CreateDialysisFinish(finish)
  6957. }
  6958. //查询当天出库的数据
  6959. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6960. for _, item := range list {
  6961. prepare := models.DialysisBeforePrepare{
  6962. UserOrgId: item.OrgId,
  6963. PatientId: item.PatientId,
  6964. RecordDate: item.RecordTime,
  6965. GoodId: item.GoodId,
  6966. GoodTypeId: item.GoodTypeId,
  6967. Count: item.Count,
  6968. Creater: adminInfo.AdminUser.Id,
  6969. Status: 1,
  6970. Ctime: time.Now().Unix(),
  6971. ProjectId: item.ProjectId,
  6972. StorehouseId: houseConfig.StorehouseOutInfo,
  6973. }
  6974. //清空准备表的数据
  6975. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6976. //插入准备表数据
  6977. service.CreateDialysisBeforePrepareOne(&prepare)
  6978. //查询默认仓库
  6979. //查询默认仓库
  6980. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6981. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6982. var total_count int64
  6983. for _, it := range stockList {
  6984. total_count += it.StockCount
  6985. }
  6986. //基础库插入数据
  6987. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6988. ////更新剩余库存
  6989. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6990. var flush_count int64
  6991. for _, it := range goodList {
  6992. flush_count += it.StockCount
  6993. }
  6994. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6995. if errs != nil {
  6996. goodErrcode := models.XtGoodErrcode{
  6997. UserOrgId: item.OrgId,
  6998. Errcode: "手动出库更新剩余出库失败",
  6999. GoodId: item.GoodId,
  7000. Status: 1,
  7001. Ctime: time.Now().Unix(),
  7002. Mtime: 0,
  7003. Count: 0,
  7004. StockCount: 0,
  7005. Creater: adminInfo.AdminUser.Id,
  7006. BatchNumberId: 0,
  7007. WarehouseOutId: 0,
  7008. }
  7009. service.CreateGoodErrcode(goodErrcode)
  7010. }
  7011. }
  7012. //更新自动出库的地方
  7013. var errs error
  7014. if errs == nil {
  7015. c.ServeSuccessJSON(map[string]interface{}{
  7016. "msg": "修改成功",
  7017. "message": "2",
  7018. "good_name": "",
  7019. "specification_name": "",
  7020. })
  7021. return
  7022. } else {
  7023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7024. return
  7025. }
  7026. }
  7027. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7028. newArr = make([]*models.DialysisBeforePrepare, 0)
  7029. for i := 0; i < len(arr); i++ {
  7030. repeat := false
  7031. for j := i + 1; j < len(arr); j++ {
  7032. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7033. repeat = true
  7034. break
  7035. }
  7036. }
  7037. if !repeat {
  7038. newArr = append(newArr, arr[i])
  7039. }
  7040. }
  7041. return
  7042. }
  7043. func (c *DialysisAPIController) GetAllDrug() {
  7044. patient_id, _ := c.GetInt64("patient_id", 0)
  7045. adminInfo := c.GetMobileAdminUserInfo()
  7046. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7047. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7048. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7049. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7050. c.ServeSuccessJSON(map[string]interface{}{
  7051. "base_drug_config": drugStockConfig,
  7052. "private_drug_config": privateDrugConfig,
  7053. "base_drug_list": drugList,
  7054. "private_drug_list": privateDrugList,
  7055. })
  7056. }
  7057. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7058. newArr = make([]*models.DialysisBeforePrepare, 0)
  7059. for i := 0; i < len(arr); i++ {
  7060. repeat := false
  7061. for j := i + 1; j < len(arr); j++ {
  7062. if arr[i].GoodId == arr[j].GoodId {
  7063. repeat = true
  7064. break
  7065. }
  7066. }
  7067. if !repeat {
  7068. newArr = append(newArr, arr[i])
  7069. }
  7070. }
  7071. return
  7072. }
  7073. func (c *DialysisAPIController) GetDepartment() {
  7074. adminInfo := c.GetMobileAdminUserInfo()
  7075. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7076. if err == nil {
  7077. c.ServeSuccessJSON(map[string]interface{}{
  7078. "departments": departments,
  7079. })
  7080. } else {
  7081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7082. return
  7083. }
  7084. }
  7085. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7086. types, _ := c.GetInt("type", 0)
  7087. start_time := c.GetString("start_time")
  7088. end_time := c.GetString("end_time")
  7089. orgId := c.GetMobileAdminUserInfo().Org.Id
  7090. timeLayout := "2006-01-02"
  7091. loc, _ := time.LoadLocation("Local")
  7092. var startTime int64
  7093. if len(start_time) > 0 {
  7094. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7095. if err != nil {
  7096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7097. return
  7098. }
  7099. startTime = theTime.Unix()
  7100. }
  7101. var endTime int64
  7102. if len(end_time) > 0 {
  7103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7104. if err != nil {
  7105. utils.ErrorLog(err.Error())
  7106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7107. return
  7108. }
  7109. endTime = theTime.Unix()
  7110. }
  7111. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7112. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7113. if err != nil {
  7114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7115. } else {
  7116. c.ServeSuccessJSON(map[string]interface{}{
  7117. "list": list,
  7118. "type": types,
  7119. "stockTotal": stockTotal,
  7120. })
  7121. }
  7122. }
  7123. func (c *DialysisAPIController) GetPrescriptionList() {
  7124. start_time := c.GetString("start_time")
  7125. end_time := c.GetString("end_time")
  7126. schedule_type, _ := c.GetInt64("schedule_type")
  7127. partion_id, _ := c.GetInt64("partion_id")
  7128. orgId := c.GetMobileAdminUserInfo().Org.Id
  7129. timeLayout := "2006-01-02"
  7130. loc, _ := time.LoadLocation("Local")
  7131. var startTime int64
  7132. if len(start_time) > 0 {
  7133. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7134. if err != nil {
  7135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7136. return
  7137. }
  7138. startTime = theTime.Unix()
  7139. }
  7140. var endTime int64
  7141. if len(end_time) > 0 {
  7142. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7143. if err != nil {
  7144. utils.ErrorLog(err.Error())
  7145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7146. return
  7147. }
  7148. endTime = theTime.Unix()
  7149. }
  7150. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7151. fmt.Println("schedulelist22222222", schedulelist)
  7152. c.ServeSuccessJSON(map[string]interface{}{
  7153. "list": schedulelist,
  7154. })
  7155. return
  7156. }
  7157. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7158. ids := c.GetString("ids")
  7159. //patient_id, _ := c.GetInt64("patient_id")
  7160. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7161. idArray := strings.Split(ids, ",")
  7162. err := service.BatchDeleteMonitor(idArray)
  7163. fmt.Print("err", err)
  7164. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7165. //redis := service.RedisClient()
  7166. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7167. //redis.Set(key, "", time.Second)
  7168. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7169. //redis.Set(keyOne, "", time.Second)
  7170. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7171. //redis.Close()
  7172. c.ServeSuccessJSON(map[string]interface{}{
  7173. "msg": "批量删除成功",
  7174. })
  7175. return
  7176. }
  7177. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7178. id, _ := c.GetInt64("id")
  7179. timeLayout := "2006-01-02"
  7180. loc, _ := time.LoadLocation("Local")
  7181. //start_time := time.Now().Format("2006-01-02")
  7182. start_time := c.GetString("start_time")
  7183. end_time := c.GetString("end_time")
  7184. var startdateunix int64
  7185. if len(start_time) > 0 {
  7186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7187. if err != nil {
  7188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7189. return
  7190. }
  7191. startdateunix = theTime.Unix()
  7192. }
  7193. var enddateunix int64
  7194. if len(end_time) > 0 {
  7195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7196. if err != nil {
  7197. utils.ErrorLog(err.Error())
  7198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7199. return
  7200. }
  7201. enddateunix = theTime.Unix()
  7202. }
  7203. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7204. //nowTime := time.Now()
  7205. //endTime := nowTime.AddDate(-30, 0, 0)
  7206. //endTimes := endTime.Format("2006-01-02")
  7207. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7208. org_id := c.GetMobileAdminUserInfo().Org.Id
  7209. //if org_id == 10579 {
  7210. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7211. // c.ServeSuccessJSON(map[string]interface{}{
  7212. // "list": list,
  7213. // })
  7214. // return
  7215. //} else {
  7216. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7217. // c.ServeSuccessJSON(map[string]interface{}{
  7218. // "list": list,
  7219. // })
  7220. // return
  7221. //}
  7222. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7223. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7224. c.ServeSuccessJSON(map[string]interface{}{
  7225. "list": list,
  7226. })
  7227. return
  7228. } else {
  7229. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7230. c.ServeSuccessJSON(map[string]interface{}{
  7231. "list": list,
  7232. })
  7233. }
  7234. return
  7235. }
  7236. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7237. dataBody := make(map[string]interface{}, 0)
  7238. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7239. ids := c.GetString("ids")
  7240. idArray := strings.Split(ids, ",")
  7241. origin, _ := c.GetInt64("origin")
  7242. if origin == 1 {
  7243. err = service.BatchDeleteAdvice(idArray)
  7244. fmt.Print("err", err)
  7245. c.ServeSuccessJSON(map[string]interface{}{
  7246. "msg": "批量删除成功",
  7247. })
  7248. return
  7249. }
  7250. if origin == 2 {
  7251. service.BatchDeleteHisAdvice(idArray)
  7252. }
  7253. }
  7254. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7255. good_id, _ := c.GetInt64("good_id")
  7256. count, _ := c.GetInt64("count")
  7257. record_time, _ := c.GetInt64("record_time")
  7258. patient_id, _ := c.GetInt64("patient_id")
  7259. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7260. c.ServeSuccessJSON(map[string]interface{}{
  7261. "detail": detail,
  7262. })
  7263. return
  7264. }
  7265. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7266. good_id, _ := c.GetInt64("good_id")
  7267. record_time, _ := c.GetInt64("record_time")
  7268. patient_id, _ := c.GetInt64("patient_id")
  7269. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7270. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7271. fmt.Print("err", err)
  7272. c.ServeSuccessJSON(map[string]interface{}{
  7273. "msg": "批量删除成功",
  7274. })
  7275. return
  7276. }
  7277. func (c *DialysisAPIController) BatchAdviceCheck() {
  7278. ids := c.GetString("ids")
  7279. idArray := strings.Split(ids, ",")
  7280. creator, _ := c.GetInt64("creator")
  7281. origin, _ := c.GetInt64("origin")
  7282. if origin == 1 {
  7283. err := service.BatchAdviceCheck(idArray, creator)
  7284. fmt.Println(err)
  7285. list, _ := service.GetAdviceExecutionById(idArray)
  7286. c.ServeSuccessJSON(map[string]interface{}{
  7287. "list": list,
  7288. })
  7289. return
  7290. }
  7291. if origin == 2 {
  7292. service.BatchHisAdviceCheck(idArray, creator)
  7293. list, _ := service.GetHisAdviceExecutionById(idArray)
  7294. c.ServeSuccessJSON(map[string]interface{}{
  7295. "list": list,
  7296. })
  7297. return
  7298. }
  7299. }
  7300. func (c *DialysisAPIController) BatchAdviceExecution() {
  7301. ids := c.GetString("ids")
  7302. idArray := strings.Split(ids, ",")
  7303. executionTime := c.GetString("execution_time")
  7304. creator, _ := c.GetInt64("creator")
  7305. timeLayout := "2006-01-02 15:04:05"
  7306. loc, _ := time.LoadLocation("Local")
  7307. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7308. orgin, _ := c.GetInt64("origin")
  7309. if orgin == 1 {
  7310. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7311. list, _ := service.GetAdviceExecutionById(idArray)
  7312. fmt.Println(err)
  7313. c.ServeSuccessJSON(map[string]interface{}{
  7314. "list": list,
  7315. })
  7316. return
  7317. }
  7318. if orgin == 2 {
  7319. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7320. list, _ := service.GetHisAdviceExecutionById(idArray)
  7321. fmt.Println(err)
  7322. c.ServeSuccessJSON(map[string]interface{}{
  7323. "list": list,
  7324. })
  7325. return
  7326. }
  7327. }
  7328. func (c *DialysisAPIController) UpdateStockGoods() {
  7329. good_id, _ := c.GetInt64("good_id")
  7330. record_time, _ := c.GetInt64("record_time")
  7331. patient_id, _ := c.GetInt64("patient_id")
  7332. count, _ := c.GetInt64("count")
  7333. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7334. fmt.Print("err", err)
  7335. c.ServeSuccessJSON(map[string]interface{}{
  7336. "msg": "更新成功",
  7337. })
  7338. return
  7339. }
  7340. // 当前数据比上一次出库数据少
  7341. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7342. //查询该患者当天已经出库的耗材信息
  7343. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7344. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7345. for i := len(goods_yc) - 1; i >= 0; i-- {
  7346. goods_yc_temp := goods_yc[i]
  7347. for j := len(goods) - 1; j >= 0; j-- {
  7348. goods_temp := goods[j]
  7349. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7350. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7351. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7352. if goods_yc_temp.Count == goods_temp.Count {
  7353. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7354. goods = append(goods[:j], goods[j+1:]...)
  7355. break
  7356. }
  7357. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7358. if goods_yc_temp.Count > goods_temp.Count {
  7359. temp_count := goods_yc_temp.Count - goods_temp.Count
  7360. goods_yc[i].Count = temp_count
  7361. goods = append(goods[:j], goods[j+1:]...)
  7362. break
  7363. }
  7364. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7365. if goods_yc_temp.Count < goods_temp.Count {
  7366. temp_count := goods_temp.Count - goods_yc_temp.Count
  7367. goods[j].Count = temp_count
  7368. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7369. break
  7370. }
  7371. }
  7372. }
  7373. }
  7374. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7375. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7376. //退库
  7377. if len(goods_yc) > 0 {
  7378. for _, good_yc := range goods_yc {
  7379. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7380. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7381. }
  7382. }
  7383. return nil
  7384. }
  7385. // 耗材出库删除
  7386. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7387. // 先根据相关信息查询当天该耗材的出库信息
  7388. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7389. if err != nil {
  7390. return err
  7391. }
  7392. var delete_count int64 = 0
  7393. delete_count = warehouseOutInfos.Count - count
  7394. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7395. // 在出库记录表里记录退库详情
  7396. warehouseOutInfo := &models.WarehouseOutInfo{
  7397. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7398. WarehouseOutId: warehouseOut.ID,
  7399. Status: 1,
  7400. Ctime: time.Now().Unix(),
  7401. OrgId: orgID,
  7402. Type: 1,
  7403. IsSys: 1,
  7404. SysRecordTime: record_time,
  7405. GoodTypeId: good_yc.GoodTypeId,
  7406. GoodId: good_yc.GoodId,
  7407. PatientId: good_yc.PatientId,
  7408. ConsumableType: 2,
  7409. StorehouseId: houseConfig.StorehouseOutInfo,
  7410. IsCheck: 1,
  7411. }
  7412. warehouseOutInfo.Count = count
  7413. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7414. warehouseOutInfo.Price = stockInInfo.Price
  7415. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7416. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7417. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7418. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7419. warehouseOutInfo.Number = warehouseOutInfos.Number
  7420. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7421. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7422. //查找当天是否存在出库记录
  7423. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7424. if errcod == gorm.ErrRecordNotFound {
  7425. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7426. //插入详情明细表
  7427. stockFlow := models.VmStockFlow{
  7428. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7429. WarehouseOutId: warehouseOut.ID,
  7430. GoodId: good_yc.GoodId,
  7431. Number: warehouseOutInfos.Number,
  7432. ProductDate: stockInInfo.ProductDate,
  7433. ExpireDate: stockInInfo.ExpiryDate,
  7434. Count: count,
  7435. Price: stockInInfo.Price,
  7436. Status: 1,
  7437. Ctime: time.Now().Unix(),
  7438. UserOrgId: good_yc.OrgId,
  7439. Manufacturer: stockInInfo.Manufacturer,
  7440. Dealer: stockInInfo.Dealer,
  7441. LicenseNumber: stockInInfo.LicenseNumber,
  7442. IsEdit: 2,
  7443. Creator: creater,
  7444. SystemTime: record_time,
  7445. ConsumableType: 3,
  7446. WarehousingDetailId: 0,
  7447. IsSys: 1,
  7448. UpdateCreator: creater,
  7449. PatientId: patient_id,
  7450. StorehouseId: houseConfig.StorehouseOutInfo,
  7451. }
  7452. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7453. if errflow == gorm.ErrRecordNotFound {
  7454. //创建流水表
  7455. err := service.CreateStockFlowOne(stockFlow)
  7456. fmt.Println("err", err)
  7457. } else if errflow == nil {
  7458. //插入详情明细表
  7459. stockFlow := models.VmStockFlow{
  7460. ID: exsit.ID,
  7461. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7462. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7463. WarehouseOutId: warehouseOut.ID,
  7464. GoodId: good_yc.GoodId,
  7465. Number: warehouseOutInfos.Number,
  7466. ProductDate: stockInInfo.ProductDate,
  7467. ExpireDate: stockInInfo.ExpiryDate,
  7468. Count: exsit.Count - delete_count,
  7469. Price: stockInInfo.Price,
  7470. Status: 1,
  7471. Ctime: time.Now().Unix(),
  7472. UserOrgId: good_yc.OrgId,
  7473. Manufacturer: stockInInfo.Manufacturer,
  7474. Dealer: stockInInfo.Dealer,
  7475. LicenseNumber: stockInInfo.LicenseNumber,
  7476. IsEdit: 2,
  7477. Creator: creater,
  7478. SystemTime: record_time,
  7479. ConsumableType: 3,
  7480. WarehousingDetailId: 0,
  7481. IsSys: 1,
  7482. UpdateCreator: creater,
  7483. PatientId: patient_id,
  7484. StorehouseId: houseConfig.StorehouseOutInfo,
  7485. }
  7486. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7487. }
  7488. if errOne != nil {
  7489. return errOne
  7490. }
  7491. } else if errcod == nil {
  7492. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7493. //插入详情明细表
  7494. stockFlow := models.VmStockFlow{
  7495. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7496. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7497. WarehouseOutId: warehouseOut.ID,
  7498. GoodId: good_yc.GoodId,
  7499. Number: warehouseOutInfos.Number,
  7500. ProductDate: stockInInfo.ProductDate,
  7501. ExpireDate: stockInInfo.ExpiryDate,
  7502. Count: count,
  7503. Price: stockInInfo.Price,
  7504. Status: 1,
  7505. Ctime: time.Now().Unix(),
  7506. UserOrgId: good_yc.OrgId,
  7507. Manufacturer: stockInInfo.Manufacturer,
  7508. Dealer: stockInInfo.Dealer,
  7509. LicenseNumber: stockInInfo.LicenseNumber,
  7510. IsEdit: 2,
  7511. Creator: creater,
  7512. SystemTime: record_time,
  7513. ConsumableType: 3,
  7514. WarehousingDetailId: 0,
  7515. IsSys: 1,
  7516. UpdateCreator: creater,
  7517. PatientId: patient_id,
  7518. ReturnCount: delete_count,
  7519. StorehouseId: houseConfig.StorehouseOutInfo,
  7520. }
  7521. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7522. if errflows == gorm.ErrRecordNotFound {
  7523. //创建流水表
  7524. service.CreateStockFlowOne(stockFlow)
  7525. } else if errflows == nil {
  7526. stockFlow := models.VmStockFlow{
  7527. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7528. ID: exsit.ID,
  7529. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7530. WarehouseOutId: warehouseOut.ID,
  7531. GoodId: good_yc.GoodId,
  7532. Number: warehouseOutInfos.Number,
  7533. ProductDate: stockInInfo.ProductDate,
  7534. ExpireDate: stockInInfo.ExpiryDate,
  7535. Count: exsit.Count - delete_count,
  7536. Price: stockInInfo.Price,
  7537. Status: 1,
  7538. Ctime: time.Now().Unix(),
  7539. UserOrgId: good_yc.OrgId,
  7540. Manufacturer: stockInInfo.Manufacturer,
  7541. Dealer: stockInInfo.Dealer,
  7542. LicenseNumber: stockInInfo.LicenseNumber,
  7543. IsEdit: 2,
  7544. Creator: creater,
  7545. SystemTime: record_time,
  7546. ConsumableType: 3,
  7547. WarehousingDetailId: 0,
  7548. IsSys: 1,
  7549. UpdateCreator: creater,
  7550. PatientId: patient_id,
  7551. ReturnCount: delete_count,
  7552. StorehouseId: houseConfig.StorehouseOutInfo,
  7553. }
  7554. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7555. }
  7556. }
  7557. //更改自动出库的表格
  7558. details := models.BloodAutomaticReduceDetail{
  7559. WarehouseOutId: warehouseOutInfo.ID,
  7560. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7561. PatientId: patient_id,
  7562. Ctime: time.Now().Unix(),
  7563. Mtime: time.Now().Unix(),
  7564. Status: 1,
  7565. RecordTime: record_time,
  7566. OrgId: orgID,
  7567. GoodId: good_yc.GoodId,
  7568. GoodTypeId: good_yc.GoodTypeId,
  7569. Count: count,
  7570. StorehouseId: houseConfig.StorehouseOutInfo,
  7571. }
  7572. //查询当天耗材是否已经存在数据
  7573. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7574. if errcode == gorm.ErrRecordNotFound {
  7575. errTwo := service.CreateAutoReduceRecord(&details)
  7576. if errTwo != nil {
  7577. return errTwo
  7578. }
  7579. } else if errcode == nil {
  7580. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7581. service.CreateAutoReduceRecord(&details)
  7582. }
  7583. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7584. //增加出库库存数量
  7585. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7586. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7587. fmt.Println("errOne", errOne)
  7588. // 删除出库完成后,要增加对应批次的库存数量
  7589. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7590. if errThree != nil {
  7591. return errThree
  7592. }
  7593. if good_yc.Count == 0 {
  7594. return nil
  7595. } else {
  7596. return errors.New("退库和出库数据不匹配")
  7597. }
  7598. }
  7599. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7600. //查询该患者当天已经出库的耗材信息
  7601. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7602. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7603. for i := len(goods_yc) - 1; i >= 0; i-- {
  7604. goods_yc_temp := goods_yc[i]
  7605. for j := len(goods) - 1; j >= 0; j-- {
  7606. goods_temp := goods[j]
  7607. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7608. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7609. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7610. if goods_yc_temp.Count == goods_temp.Count {
  7611. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7612. goods = append(goods[:j], goods[j+1:]...)
  7613. break
  7614. }
  7615. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7616. if goods_yc_temp.Count > goods_temp.Count {
  7617. temp_count := goods_yc_temp.Count - goods_temp.Count
  7618. goods_yc[i].Count = temp_count
  7619. goods = append(goods[:j], goods[j+1:]...)
  7620. break
  7621. }
  7622. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7623. if goods_yc_temp.Count < goods_temp.Count {
  7624. temp_count := goods_temp.Count - goods_yc_temp.Count
  7625. goods[j].Count = temp_count
  7626. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7627. break
  7628. }
  7629. }
  7630. }
  7631. }
  7632. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7633. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7634. fmt.Println("剩余需要出库的", len(goods))
  7635. if len(goods) > 0 {
  7636. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7637. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7638. if err == gorm.ErrRecordNotFound {
  7639. //没有记录,则创建出库单
  7640. timeStr := time.Now().Format("2006-01-02")
  7641. timeArr := strings.Split(timeStr, "-")
  7642. total, _ := service.FindAllWarehouseOut(orgID)
  7643. total = total + 1
  7644. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7645. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7646. number = number + total
  7647. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7648. warehouseOut := models.WarehouseOut{
  7649. WarehouseOutOrderNumber: warehousing_out_order,
  7650. OperationTime: time.Now().Unix(),
  7651. OrgId: orgID,
  7652. Creater: creater,
  7653. Ctime: time.Now().Unix(),
  7654. Status: 1,
  7655. WarehouseOutTime: record_time,
  7656. Dealer: 0,
  7657. Manufacturer: 0,
  7658. Type: 1,
  7659. IsSys: 1,
  7660. StorehouseId: houseConfig.StorehouseOutInfo,
  7661. IsCheck: 1,
  7662. }
  7663. err := service.AddSigleWarehouseOut(&warehouseOut)
  7664. if err != nil {
  7665. utils.TraceLog("创建出库单失败 err = %v", err)
  7666. return err
  7667. } else {
  7668. out = warehouseOut
  7669. }
  7670. }
  7671. for _, item := range goods {
  7672. var newCount int64 = 0
  7673. for _, it := range goodOne {
  7674. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7675. newCount = it.Count
  7676. }
  7677. }
  7678. prepare := models.DialysisBeforePrepare{
  7679. GoodTypeId: item.GoodTypeId,
  7680. GoodId: item.GoodId,
  7681. Count: item.Count,
  7682. StorehouseId: houseConfig.StorehouseOutInfo,
  7683. }
  7684. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7685. //增加出库数量
  7686. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7687. }
  7688. }
  7689. if len(goods_yc) > 0 {
  7690. for _, good_yc := range goods_yc {
  7691. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7692. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7693. }
  7694. }
  7695. return nil
  7696. }
  7697. // 耗材出库删除
  7698. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7699. // 先根据相关信息查询当天该耗材的出库信息
  7700. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7701. if err != nil {
  7702. return err
  7703. }
  7704. var delete_count int64 = 0
  7705. for _, ware := range warehouseOutInfos {
  7706. // 判断当前出库的数据和删除出库数量
  7707. if good_yc.Count <= ware.Count {
  7708. delete_count = good_yc.Count
  7709. } else {
  7710. delete_count = ware.Count
  7711. }
  7712. warehouseOutInfo := &models.WarehouseOutInfo{
  7713. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7714. WarehouseOutId: warehouseOut.ID,
  7715. Status: 1,
  7716. Ctime: time.Now().Unix(),
  7717. Remark: "",
  7718. OrgId: orgID,
  7719. Type: 1,
  7720. Manufacturer: 0,
  7721. Dealer: 0,
  7722. IsSys: 0,
  7723. SysRecordTime: record_time,
  7724. GoodTypeId: good_yc.GoodTypeId,
  7725. GoodId: good_yc.GoodId,
  7726. StorehouseId: warehouseOut.StorehouseId,
  7727. IsCheck: 1,
  7728. }
  7729. warehouseOutInfo.Count = delete_count
  7730. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7731. warehouseOutInfo.Price = stockInInfo.Price
  7732. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7733. if errOne != nil {
  7734. return errOne
  7735. }
  7736. // 删除出库完成后,要改变流水库存(有疑问)
  7737. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7738. fmt.Println("errOne", errOne)
  7739. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7740. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7741. //扣减出库数量
  7742. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7743. if errThree != nil {
  7744. return errThree
  7745. }
  7746. }
  7747. if good_yc.Count == 0 {
  7748. return nil
  7749. } else {
  7750. return errors.New("退库和出库数据不匹配")
  7751. }
  7752. }
  7753. func (this *DialysisAPIController) GetMobileScheduleList() {
  7754. limit, _ := this.GetInt64("limit")
  7755. page, _ := this.GetInt64("page")
  7756. type_options_visible, _ := this.GetInt64("type_options_visible")
  7757. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7758. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7759. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7760. }
  7761. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7762. newArr = make([]*models.HisPrescriptionProject, 0)
  7763. for i := 0; i < len(arr); i++ {
  7764. repeat := false
  7765. for j := i + 1; j < len(arr); j++ {
  7766. if arr[i].TeamId == arr[j].TeamId {
  7767. repeat = true
  7768. break
  7769. }
  7770. }
  7771. if !repeat {
  7772. newArr = append(newArr, arr[i])
  7773. }
  7774. }
  7775. return
  7776. }
  7777. func (this *DialysisAPIController) GetRoleList() {
  7778. admin_user_id, _ := this.GetInt64("admin_user_id")
  7779. orgid := this.GetMobileAdminUserInfo().Org.Id
  7780. list, err := service.GetRoleList(orgid, admin_user_id)
  7781. fmt.Println(err)
  7782. this.ServeSuccessJSON(map[string]interface{}{
  7783. "list": list,
  7784. })
  7785. return
  7786. }
  7787. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7788. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7789. // 先根据相关信息查询当天该耗材的出库信息
  7790. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7791. if err != nil {
  7792. return err
  7793. }
  7794. var delete_count int64 = 0
  7795. delete_count = warehouseOutInfos.Count - count
  7796. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7797. // 删除出库完成后,要增加对应批次的库存数量
  7798. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7799. if errThree != nil {
  7800. return errThree
  7801. }
  7802. //增加退库数量
  7803. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7804. //扣减出库数量
  7805. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7806. //查询剩余库存
  7807. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7808. var sum_count int64
  7809. for _, item := range goodList {
  7810. sum_count += item.StockCount
  7811. }
  7812. // 在出库记录表里记录退库详情
  7813. warehouseOutInfo := &models.WarehouseOutInfo{
  7814. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7815. WarehouseOutId: warehouseOut.ID,
  7816. Status: 1,
  7817. Ctime: time.Now().Unix(),
  7818. OrgId: orgID,
  7819. Type: 1,
  7820. IsSys: 1,
  7821. SysRecordTime: record_time,
  7822. GoodTypeId: good_yc.GoodTypeId,
  7823. GoodId: good_yc.GoodId,
  7824. PatientId: good_yc.PatientId,
  7825. ConsumableType: 2,
  7826. StorehouseId: houseConfig.StorehouseOutInfo,
  7827. IsCheck: 1,
  7828. OverCount: sum_count,
  7829. }
  7830. warehouseOutInfo.Count = count
  7831. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7832. warehouseOutInfo.Price = stockInInfo.Price
  7833. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7834. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7835. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7836. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7837. warehouseOutInfo.Number = warehouseOutInfos.Number
  7838. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7839. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7840. //查找当天是否存在出库记录
  7841. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7842. if errcod == gorm.ErrRecordNotFound {
  7843. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7844. //插入详情明细表
  7845. if errOne != nil {
  7846. return errOne
  7847. }
  7848. //插入详情明细表
  7849. stockFlow := models.VmStockFlow{
  7850. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7851. WarehouseOutId: warehouseOut.ID,
  7852. GoodId: good_yc.GoodId,
  7853. Number: warehouseOutInfos.Number,
  7854. ProductDate: stockInInfo.ProductDate,
  7855. ExpireDate: stockInInfo.ExpiryDate,
  7856. Count: count,
  7857. Price: stockInInfo.Price,
  7858. Status: 1,
  7859. Ctime: time.Now().Unix(),
  7860. UserOrgId: good_yc.OrgId,
  7861. Manufacturer: stockInInfo.Manufacturer,
  7862. Dealer: stockInInfo.Dealer,
  7863. LicenseNumber: stockInInfo.LicenseNumber,
  7864. IsEdit: 2,
  7865. Creator: creater,
  7866. SystemTime: record_time,
  7867. ConsumableType: 3,
  7868. WarehousingDetailId: 0,
  7869. IsSys: 1,
  7870. UpdateCreator: creater,
  7871. PatientId: patient_id,
  7872. StorehouseId: houseConfig.StorehouseOutInfo,
  7873. OverCount: sum_count,
  7874. ProjectId: good_yc.ProjectId,
  7875. }
  7876. err := service.CreateStockFlowOne(stockFlow)
  7877. fmt.Println("err", err)
  7878. } else if errcod == nil {
  7879. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7880. }
  7881. //创建退库单
  7882. operation_time := time.Now().Unix()
  7883. //创建退库单
  7884. timeStr := time.Now().Format("2006-01-02")
  7885. timeArr := strings.Split(timeStr, "-")
  7886. total, _ := service.FindAllCancelStockTotal(orgID)
  7887. total = total + 1
  7888. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7889. cancelStock := models.CancelStock{
  7890. OrderNumber: orderNumber,
  7891. OperaTime: operation_time,
  7892. OrgId: orgID,
  7893. Creater: warehouseOut.Creater,
  7894. Ctime: time.Now().Unix(),
  7895. Status: 1,
  7896. ReturnTime: record_time,
  7897. Type: 1,
  7898. StorehouseId: stockInInfo.StorehouseId,
  7899. IsCheck: 1,
  7900. }
  7901. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7902. if msgerrkonde == gorm.ErrRecordNotFound {
  7903. service.AddSigleCancelStock(&cancelStock)
  7904. }
  7905. cancel, _ := service.GetLastCancelStockById(orgID)
  7906. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7907. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7908. cancelStockInfo := models.CancelStockInfo{
  7909. GoodId: stockInInfo.GoodId,
  7910. CancelStockId: cancel.ID,
  7911. GoodTypeId: stockInInfo.GoodTypeId,
  7912. Count: delete_count,
  7913. Price: stockInInfo.PackingPrice,
  7914. Total: 0,
  7915. ProductDate: stockInInfo.ProductDate,
  7916. ExpiryDate: stockInInfo.ExpiryDate,
  7917. Ctime: time.Now().Unix(),
  7918. Status: 1,
  7919. OrgId: orgID,
  7920. OrderNumber: cancel.OrderNumber,
  7921. Type: 0,
  7922. Dealer: deaerler.DealerName,
  7923. Manufacturer: manufacturer.ManufacturerName,
  7924. Number: stockInInfo.Number,
  7925. RegisterAccount: "",
  7926. Remark: "",
  7927. WarehouseInfoId: stockInInfo.ID,
  7928. PatientId: patient_id,
  7929. RecordDate: record_time,
  7930. StorehouseId: stockInInfo.StorehouseId,
  7931. IsCheck: 1,
  7932. }
  7933. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7934. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7935. flow := models.VmStockFlow{
  7936. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7937. GoodId: good_yc.GoodId,
  7938. Number: warehouseOutInfos.Number,
  7939. LicenseNumber: stockInInfo.LicenseNumber,
  7940. Count: delete_count,
  7941. UserOrgId: orgID,
  7942. PatientId: patient_id,
  7943. SystemTime: record_time,
  7944. ConsumableType: 7,
  7945. IsSys: 0,
  7946. WarehousingOrder: "",
  7947. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7948. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7949. IsEdit: 0,
  7950. CancelStockId: cancel.ID,
  7951. CancelOrderNumber: cancel.OrderNumber,
  7952. Manufacturer: manufacturer.ID,
  7953. Dealer: 0,
  7954. Creator: warehouseOut.Creater,
  7955. UpdateCreator: 0,
  7956. Status: 1,
  7957. Ctime: time.Now().Unix(),
  7958. Mtime: 0,
  7959. Price: stockInInfo.Price,
  7960. WarehousingDetailId: stockInInfo.ID,
  7961. WarehouseOutDetailId: warehouseOutInfos.ID,
  7962. CancelOutDetailId: cancelInfo.ID,
  7963. ProductDate: stockInInfo.ProductDate,
  7964. ExpireDate: stockInInfo.ExpiryDate,
  7965. StorehouseId: houseConfig.StorehouseOutInfo,
  7966. OverCount: sum_count,
  7967. }
  7968. service.CreateStockFlowOne(flow)
  7969. //更改自动出库的表格
  7970. details := models.BloodAutomaticReduceDetail{
  7971. WarehouseOutId: warehouseOutInfo.ID,
  7972. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7973. PatientId: patient_id,
  7974. Ctime: time.Now().Unix(),
  7975. Mtime: time.Now().Unix(),
  7976. Status: 1,
  7977. RecordTime: record_time,
  7978. OrgId: orgID,
  7979. GoodId: good_yc.GoodId,
  7980. GoodTypeId: good_yc.GoodTypeId,
  7981. Count: count,
  7982. StorehouseId: houseConfig.StorehouseOutInfo,
  7983. }
  7984. //查询当天耗材是否已经存在数据
  7985. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7986. if errcode == gorm.ErrRecordNotFound {
  7987. errTwo := service.CreateAutoReduceRecord(&details)
  7988. if errTwo != nil {
  7989. return errTwo
  7990. }
  7991. } else if errcode == nil {
  7992. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7993. service.CreateAutoReduceRecord(&details)
  7994. }
  7995. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7996. //增加出库库存数量
  7997. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7998. if good_yc.Count == 0 {
  7999. return nil
  8000. } else {
  8001. return errors.New("退库和出库数据不匹配")
  8002. }
  8003. }
  8004. func (this *DialysisAPIController) SavePatientSign() {
  8005. adminUserInfo := this.GetMobileAdminUserInfo()
  8006. patient_id, _ := this.GetInt64("patient_id")
  8007. dialysis_date, _ := this.GetInt64("dialysis_date")
  8008. orgid := adminUserInfo.Org.Id
  8009. var esdata models.DialysisOrder
  8010. var err error
  8011. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8012. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8013. return
  8014. }
  8015. esdata.Hash = esdata.Hash
  8016. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8017. order := models.DialysisOrder{
  8018. Hash: esdata.Hash,
  8019. Url: esdata.Url,
  8020. }
  8021. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8022. redis := service.RedisClient()
  8023. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8024. redis.Set(key, "", time.Second)
  8025. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8026. //清空key 值
  8027. redis.Set(keyOne, "", time.Second)
  8028. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8029. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8030. //redis.Set(keyTwo, "", time.Second)
  8031. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8032. redis.Set(keyThree, "", time.Second)
  8033. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8034. redis.Set(keyFour, "", time.Second)
  8035. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8036. redis.Set(keyFive, "", time.Second)
  8037. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8038. redis.Set(keySix, "", time.Second)
  8039. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8040. redis.Set(keySeven, "", time.Second)
  8041. if err != nil {
  8042. fmt.Println(err)
  8043. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8044. return
  8045. }
  8046. this.ServeSuccessJSON(map[string]interface{}{
  8047. "electronic_signature": esdata,
  8048. })
  8049. }
  8050. func (this *DialysisAPIController) GetPatientSign() {
  8051. patient_id, _ := this.GetInt64("patient_id")
  8052. dialysis_date, _ := this.GetInt64("dialysis_date")
  8053. adminUserInfo := this.GetMobileAdminUserInfo()
  8054. orgId := adminUserInfo.Org.Id
  8055. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8056. if err != nil {
  8057. fmt.Println(err)
  8058. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8059. return
  8060. }
  8061. this.ServeSuccessJSON(map[string]interface{}{
  8062. "dialysisOrder": dialysisOrder,
  8063. })
  8064. }
  8065. func (this *DialysisAPIController) GetScheduleByPatient() {
  8066. patient_id, _ := this.GetInt64("patient_id")
  8067. schedule_date, _ := this.GetInt64("schedule_date")
  8068. orgid := this.GetMobileAdminUserInfo().Org.Id
  8069. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8070. this.ServeSuccessJSON(map[string]interface{}{
  8071. "schedule": schedule,
  8072. })
  8073. }
  8074. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8075. org_id := this.GetMobileAdminUserInfo().Org.Id
  8076. patient_id, _ := this.GetInt64("patient_id")
  8077. schedule_date, _ := this.GetInt64("schedule_date")
  8078. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8079. this.ServeSuccessJSON(map[string]interface{}{
  8080. "order": order,
  8081. })
  8082. }
  8083. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8084. org_id := this.GetMobileAdminUserInfo().Org.Id
  8085. schedule_date := this.GetString("schedule_date")
  8086. schedule_type, _ := this.GetInt64("schedule_type")
  8087. timeLayout := "2006-01-02"
  8088. loc, _ := time.LoadLocation("Local")
  8089. var startdateunix int64
  8090. if len(schedule_date) > 0 {
  8091. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8092. if err != nil {
  8093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8094. return
  8095. }
  8096. startdateunix = theTime.Unix()
  8097. }
  8098. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8099. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8100. devices, _ := service.GetAllDevicetByListSix(org_id)
  8101. for key, item := range scheduals {
  8102. // 床位信息
  8103. for _, device := range devices {
  8104. if item.BedId == device.ID {
  8105. scheduals[key].DeviceNumber = device
  8106. break
  8107. }
  8108. }
  8109. }
  8110. this.ServeSuccessJSON(map[string]interface{}{
  8111. "list": list,
  8112. "scheduals": scheduals,
  8113. })
  8114. }
  8115. func (this *DialysisAPIController) SavePatientPicture() {
  8116. patient_id, _ := this.GetInt64("patient_id")
  8117. dialysis_date, _ := this.GetInt64("schedule_date")
  8118. avatar := this.GetString("avatar")
  8119. fmt.Println("patient_id", patient_id)
  8120. orgId := this.GetMobileAdminUserInfo().Org.Id
  8121. order := models.DialysisOrder{
  8122. Url: avatar,
  8123. }
  8124. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8125. redis := service.RedisClient()
  8126. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8127. redis.Set(key, "", time.Second)
  8128. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8129. //清空key 值
  8130. redis.Set(keyOne, "", time.Second)
  8131. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8132. redis.Set(keyThree, "", time.Second)
  8133. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8134. redis.Set(keyFour, "", time.Second)
  8135. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8136. redis.Set(keyFive, "", time.Second)
  8137. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8138. redis.Set(keySix, "", time.Second)
  8139. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8140. redis.Set(keySeven, "", time.Second)
  8141. if err != nil {
  8142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8143. return
  8144. }
  8145. this.ServeSuccessJSON(map[string]interface{}{
  8146. "order": order,
  8147. })
  8148. }
  8149. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8150. ids := this.GetString("ids")
  8151. idSplit := strings.Split(ids, ",")
  8152. orgId := this.GetMobileAdminUserInfo().Org.Id
  8153. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8154. execution_time := this.GetString("exce_time")
  8155. timeLayout2 := "2006-01-02 15:04:05"
  8156. loc, _ := time.LoadLocation("Local")
  8157. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8158. if errs != nil {
  8159. utils.ErrorLog(errs.Error())
  8160. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8161. return
  8162. }
  8163. //his客户
  8164. if config.IsOpen == 1 {
  8165. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8166. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8167. for _, item := range list {
  8168. for _, it := range adviceList {
  8169. if item.DrugId == it.DrugId {
  8170. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8171. }
  8172. }
  8173. }
  8174. for _, item := range list {
  8175. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8176. var sum_out_count int64
  8177. for _, itemThree := range item.ChildDoctorAdvice {
  8178. var prescribing_number int64
  8179. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8180. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8181. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8182. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8183. }
  8184. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8185. prescribing_number = parseIntPrescribingNumber
  8186. }
  8187. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8188. prescribing_number = parseIntPrescribingNumber
  8189. }
  8190. sum_out_count += prescribing_number
  8191. }
  8192. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8193. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8194. //库存不足
  8195. if sum_out_count > drugStockOut.FlushCount {
  8196. this.ServeSuccessJSON(map[string]interface{}{
  8197. "msg": "2",
  8198. "drug": medical,
  8199. "ids": ids,
  8200. })
  8201. return
  8202. }
  8203. }
  8204. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8205. //执行医嘱
  8206. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8207. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8208. for _, item := range advices {
  8209. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8210. redis := service.RedisClient()
  8211. //清空key 值
  8212. redis.Set(key, "", time.Second)
  8213. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8214. redis.Set(keyTwo, "", time.Second)
  8215. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8216. redis.Set(keyThree, "", time.Second)
  8217. recordDate := theTime.Format("2006-01-02")
  8218. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8219. redis.Set(keyFour, "", time.Second)
  8220. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8221. redis.Set(keyFive, "", time.Second)
  8222. defer redis.Close()
  8223. }
  8224. if errs == nil {
  8225. //药品管理信息
  8226. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8227. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8228. if drugStockConfig.IsOpen == 1 {
  8229. for _, item := range advices {
  8230. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8231. config, _ := service.GetDrugOpenConfigOne(orgId)
  8232. if config.IsOpen != 1 {
  8233. //查询该药品是否有库存
  8234. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8235. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8236. if medical.IsUse == 2 {
  8237. if config.IsOpen != 1 {
  8238. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8239. service.HisDrugsDelivery(orgId, creater, &advice)
  8240. if orgId == 3877 || orgId == 10265 {
  8241. //查询该药品是否有出库记录
  8242. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8243. if len(flowMap) == 0 {
  8244. errs := service.UpdateHisAdviceById(advice.ID)
  8245. if errs != nil {
  8246. drugError := models.XtDrugError{
  8247. UserOrgId: orgId,
  8248. DrugId: item.DrugId,
  8249. RecordDate: item.AdviceDate,
  8250. PatientId: item.PatientId,
  8251. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8252. Status: 1,
  8253. Ctime: time.Now().Unix(),
  8254. Mtime: 0,
  8255. SumCount: 0,
  8256. Prescribingnumber: advice.PrescribingNumber,
  8257. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8258. }
  8259. service.CreateDrugError(drugError)
  8260. }
  8261. this.ServeSuccessJSON(map[string]interface{}{
  8262. "msg": "2",
  8263. "drug": medical,
  8264. "ids": ids,
  8265. })
  8266. return
  8267. }
  8268. }
  8269. }
  8270. if pharmacyConfig.IsOpen != 1 {
  8271. service.HisDrugsDelivery(orgId, creater, &advice)
  8272. if orgId == 3877 || orgId == 10265 {
  8273. //查询该药品是否有出库记录
  8274. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8275. if len(flowMap) == 0 {
  8276. errs := service.UpdateHisAdviceById(advice.ID)
  8277. if errs != nil {
  8278. drugError := models.XtDrugError{
  8279. UserOrgId: orgId,
  8280. DrugId: item.DrugId,
  8281. RecordDate: item.AdviceDate,
  8282. PatientId: item.PatientId,
  8283. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8284. Status: 1,
  8285. Ctime: time.Now().Unix(),
  8286. Mtime: 0,
  8287. SumCount: 0,
  8288. Prescribingnumber: advice.PrescribingNumber,
  8289. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8290. }
  8291. service.CreateDrugError(drugError)
  8292. }
  8293. this.ServeSuccessJSON(map[string]interface{}{
  8294. "msg": "2",
  8295. "drug": medical,
  8296. "ids": ids,
  8297. })
  8298. return
  8299. }
  8300. }
  8301. }
  8302. //更新字典里面的库存
  8303. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8304. var sum_count int64
  8305. for _, its := range stockInfo {
  8306. if its.MaxUnit == medical.MaxUnit {
  8307. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8308. }
  8309. sum_count += its.StockMaxNumber + its.StockMinNumber
  8310. }
  8311. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8312. //剩余库存
  8313. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8314. }
  8315. }
  8316. }
  8317. }
  8318. }
  8319. this.ServeSuccessJSON(map[string]interface{}{
  8320. "msg": "1",
  8321. "ids": ids,
  8322. })
  8323. return
  8324. } else {
  8325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8326. }
  8327. }
  8328. fmt.Println("config233322333223", config.IsOpen)
  8329. //血透客户
  8330. if config.IsOpen == 2 || config.IsOpen == 0 {
  8331. //药品管理信息
  8332. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8333. if drugStockConfig.IsOpen == 1 {
  8334. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8335. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8336. for _, item := range list {
  8337. for _, it := range adviceList {
  8338. if item.DrugId == it.DrugId {
  8339. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8340. }
  8341. }
  8342. }
  8343. for _, item := range list {
  8344. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8345. var sum_out_count int64
  8346. for _, itemThree := range item.ChildDoctorAdvice {
  8347. var prescribing_number int64
  8348. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8349. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8350. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8351. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8352. }
  8353. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8354. prescribing_number = parseIntPrescribingNumber
  8355. }
  8356. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8357. prescribing_number = parseIntPrescribingNumber
  8358. }
  8359. sum_out_count += prescribing_number
  8360. }
  8361. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8362. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8363. //库存不足
  8364. if sum_out_count > drugStockOut.FlushCount {
  8365. this.ServeSuccessJSON(map[string]interface{}{
  8366. "msg": "2",
  8367. "drug": medical,
  8368. "ids": ids,
  8369. })
  8370. return
  8371. }
  8372. }
  8373. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8374. fmt.Println("creater2332243244224242424", creater)
  8375. //执行医嘱
  8376. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8377. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8378. for _, item := range advices {
  8379. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8380. redis := service.RedisClient()
  8381. //清空key 值
  8382. redis.Set(key, "", time.Second)
  8383. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8384. redis.Set(keyTwo, "", time.Second)
  8385. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8386. redis.Set(keyThree, "", time.Second)
  8387. recordDate := theTime.Format("2006-01-02")
  8388. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8389. redis.Set(keyFour, "", time.Second)
  8390. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8391. redis.Set(keyFive, "", time.Second)
  8392. defer redis.Close()
  8393. }
  8394. if errs == nil {
  8395. for _, item := range advices {
  8396. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8397. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8398. //查询是否出库按钮开启
  8399. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8400. if adviceSetting.IsAdviceOpen == 1 {
  8401. //查询是否出库按钮开启
  8402. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8403. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8404. if prescriptionConfig.IsOpen == 1 {
  8405. if medical.IsUse == 2 {
  8406. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8407. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8408. }
  8409. if pharmacyConfig.IsOpen != 1 {
  8410. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8411. }
  8412. //更新字典里面的库存
  8413. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8414. var sum_count int64
  8415. for _, its := range stockInfo {
  8416. if its.MaxUnit == medical.MaxUnit {
  8417. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8418. }
  8419. sum_count += its.StockMaxNumber + its.StockMinNumber
  8420. }
  8421. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8422. //剩余库存
  8423. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8424. }
  8425. }
  8426. } else {
  8427. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8428. if medical.IsUse == 2 {
  8429. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8430. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8431. }
  8432. if pharmacyConfig.IsOpen != 1 {
  8433. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8434. }
  8435. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8436. var sum_count int64
  8437. for _, its := range stockInfo {
  8438. if its.MaxUnit == medical.MaxUnit {
  8439. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8440. }
  8441. sum_count += its.StockMaxNumber + its.StockMinNumber
  8442. }
  8443. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8444. //剩余库存
  8445. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8446. }
  8447. }
  8448. }
  8449. }
  8450. this.ServeSuccessJSON(map[string]interface{}{
  8451. "msg": "1",
  8452. "ids": ids,
  8453. })
  8454. return
  8455. } else {
  8456. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8457. //执行医嘱
  8458. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8459. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8460. for _, item := range advices {
  8461. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8462. redis := service.RedisClient()
  8463. //清空key 值
  8464. redis.Set(key, "", time.Second)
  8465. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8466. redis.Set(keyTwo, "", time.Second)
  8467. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8468. redis.Set(keyThree, "", time.Second)
  8469. recordDate := theTime.Format("2006-01-02")
  8470. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8471. redis.Set(keyFour, "", time.Second)
  8472. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8473. redis.Set(keyFive, "", time.Second)
  8474. defer redis.Close()
  8475. }
  8476. this.ServeSuccessJSON(map[string]interface{}{
  8477. "msg": "1",
  8478. "ids": ids,
  8479. })
  8480. return
  8481. }
  8482. }
  8483. }
  8484. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8485. ids := this.GetString("ids")
  8486. idSplit := strings.Split(ids, ",")
  8487. orgId := this.GetMobileAdminUserInfo().Org.Id
  8488. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8489. if config.IsOpen == 1 {
  8490. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8491. this.ServeSuccessJSON(map[string]interface{}{
  8492. "msg": "1",
  8493. "ids": ids,
  8494. })
  8495. return
  8496. }
  8497. if config.IsOpen == 0 || config.IsOpen == 2 {
  8498. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8499. this.ServeSuccessJSON(map[string]interface{}{
  8500. "msg": "1",
  8501. "ids": ids,
  8502. })
  8503. return
  8504. }
  8505. }
  8506. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8507. ids := this.GetString("ids")
  8508. idSplit := strings.Split(ids, ",")
  8509. orgId := this.GetMobileAdminUserInfo().Org.Id
  8510. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8511. //his
  8512. if config.IsOpen == 1 {
  8513. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8514. theTime := time.Now()
  8515. advices := models.HisDoctorAdviceThirty{
  8516. CheckTime: theTime.Unix(),
  8517. Checker: checker,
  8518. UpdatedTime: time.Now().Unix(),
  8519. }
  8520. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8521. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8522. for _, item := range list {
  8523. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8524. redis := service.RedisClient()
  8525. //清空key 值
  8526. redis.Set(key, "", time.Second)
  8527. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8528. redis.Set(keyTwo, "", time.Second)
  8529. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8530. redis.Set(keyThree, "", time.Second)
  8531. recordDate := theTime.Format("2006-01-02")
  8532. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8533. redis.Set(keyFour, "", time.Second)
  8534. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8535. redis.Set(keyFive, "", time.Second)
  8536. defer redis.Close()
  8537. }
  8538. this.ServeSuccessJSON(map[string]interface{}{
  8539. "msg": "1",
  8540. "ids": ids,
  8541. })
  8542. return
  8543. }
  8544. //血透
  8545. if config.IsOpen == 0 || config.IsOpen == 2 {
  8546. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8547. theTime := time.Now()
  8548. advices := models.DoctorAdvice{
  8549. CheckTime: theTime.Unix(),
  8550. Checker: checker,
  8551. UpdatedTime: time.Now().Unix(),
  8552. }
  8553. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8554. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8555. for _, item := range list {
  8556. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8557. redis := service.RedisClient()
  8558. //清空key 值
  8559. redis.Set(key, "", time.Second)
  8560. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8561. redis.Set(keyTwo, "", time.Second)
  8562. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8563. redis.Set(keyThree, "", time.Second)
  8564. recordDate := theTime.Format("2006-01-02")
  8565. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8566. redis.Set(keyFour, "", time.Second)
  8567. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8568. redis.Set(keyFive, "", time.Second)
  8569. defer redis.Close()
  8570. }
  8571. this.ServeSuccessJSON(map[string]interface{}{
  8572. "msg": "1",
  8573. "ids": ids,
  8574. })
  8575. return
  8576. }
  8577. }
  8578. func (this *DialysisAPIController) CheckSchedule() {
  8579. patientID, _ := this.GetInt64("patient_id")
  8580. recordDateStr := this.GetString("record_date")
  8581. nurseID, _ := this.GetInt64("start_nurse")
  8582. schedual_type, _ := this.GetInt64("schedual_type")
  8583. bedID, _ := this.GetInt64("bed")
  8584. start_time := this.GetString("start_time")
  8585. fmt.Println("patientID", patientID)
  8586. fmt.Println("recordDateStr", recordDateStr)
  8587. fmt.Println("nurseID", nurseID)
  8588. fmt.Println("schedual_type------", schedual_type)
  8589. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8591. return
  8592. }
  8593. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8594. if parseStartDateErr != nil {
  8595. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8597. return
  8598. }
  8599. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8600. if parseErr != nil {
  8601. this.ErrorLog("时间解析失败:%v", parseErr)
  8602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8603. return
  8604. }
  8605. adminUserInfo := this.GetMobileAdminUserInfo()
  8606. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8607. if getPatientErr != nil {
  8608. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8610. return
  8611. } else if patient == nil {
  8612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8613. return
  8614. }
  8615. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8616. if getNurseErr != nil {
  8617. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8619. return
  8620. } else if nurse == nil {
  8621. this.ErrorLog("护士不存在")
  8622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8623. return
  8624. }
  8625. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8626. if getDeviceNumberErr != nil {
  8627. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8629. return
  8630. } else if deviceNumber == nil {
  8631. this.ErrorLog("床位号不存在")
  8632. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8633. return
  8634. }
  8635. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8636. if getRecordErr != nil {
  8637. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8638. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8639. return
  8640. } else if dialysisRecord != nil {
  8641. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8642. return
  8643. }
  8644. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8645. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8646. timeLayout := "2006-01-02 15:04:05"
  8647. loc, _ := time.LoadLocation("Local")
  8648. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8649. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8650. schedulestartTime := theStartTime.Unix()
  8651. scheduleendTime := theEndTime.Unix()
  8652. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8653. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8654. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8655. //查询该床位是否有人用了
  8656. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8657. if err == nil {
  8658. if schedule.ID == 0 {
  8659. this.ServeSuccessJSON(map[string]interface{}{
  8660. "status": 0,
  8661. "msg": "请求失败",
  8662. })
  8663. } else {
  8664. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8665. if order.ID > 0 { //该机位被其他人占用了
  8666. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8667. return
  8668. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8669. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8670. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8671. this.ServeSuccessJSON(map[string]interface{}{
  8672. "status": 1,
  8673. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8674. })
  8675. return
  8676. } else {
  8677. this.ServeSuccessJSON(map[string]interface{}{
  8678. "status": 0,
  8679. "msg": "",
  8680. })
  8681. }
  8682. }
  8683. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8684. this.ServeSuccessJSON(map[string]interface{}{
  8685. "status": 2,
  8686. "msg": "当前机位已有患者在使用,请重新选择!",
  8687. })
  8688. }
  8689. }
  8690. } else {
  8691. this.ServeSuccessJSON(map[string]interface{}{
  8692. "status": 0,
  8693. "msg": "",
  8694. })
  8695. }
  8696. }
  8697. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8698. orgId := this.GetMobileAdminUserInfo().Org.Id
  8699. schedule_type, _ := this.GetInt64("schedule_type")
  8700. partion_type, _ := this.GetInt64("partion_type")
  8701. start_time := this.GetString("start_time")
  8702. timeLayout := "2006-01-02"
  8703. loc, _ := time.LoadLocation("Local")
  8704. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8705. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8706. _, config := service.FindXTHisRecordByOrgId(orgId)
  8707. appId := this.GetMobileAdminUserInfo().App.Id
  8708. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8709. if err == nil {
  8710. this.ServeSuccessJSON(map[string]interface{}{
  8711. "list": list,
  8712. "config": config,
  8713. "doctorList": doctorList,
  8714. })
  8715. return
  8716. } else {
  8717. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8718. return
  8719. }
  8720. }
  8721. func (this *DialysisAPIController) SaveMobileInformation() {
  8722. patient_id, _ := this.GetInt64("patient_id")
  8723. record_date, _ := this.GetInt64("record_date")
  8724. startTime := this.GetString("start_time")
  8725. module, _ := this.GetInt64("module")
  8726. remark := this.GetString("remark")
  8727. timeLayout := "2006-01-02 15:04"
  8728. loc, _ := time.LoadLocation("Local")
  8729. if len(startTime) == 0 {
  8730. utils.ErrorLog("len(start_time) == 0")
  8731. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8732. return
  8733. }
  8734. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8735. if err != nil {
  8736. utils.ErrorLog(err.Error())
  8737. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8738. return
  8739. }
  8740. StartTime := theTime.Unix()
  8741. fmt.Println("startime-------------", StartTime)
  8742. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8743. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8744. information := models.XtDialysisInformation{
  8745. Module: module,
  8746. PatientId: patient_id,
  8747. RecordDate: record_date,
  8748. ApplicationDate: StartTime,
  8749. Creater: creater,
  8750. ApplicationStatus: 2,
  8751. Checker: 0,
  8752. CheckTime: 0,
  8753. Remark: remark,
  8754. UserOrgId: user_org_id,
  8755. Ctime: time.Now().Unix(),
  8756. Status: 1,
  8757. Mtime: 0,
  8758. }
  8759. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8760. if infor.ID == 0 {
  8761. service.SaveDialysisInformation(information)
  8762. }
  8763. if infor.ID > 0 {
  8764. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8765. }
  8766. this.ServeSuccessJSON(map[string]interface{}{
  8767. "information": information,
  8768. })
  8769. return
  8770. }
  8771. func (this *DialysisAPIController) GetMobileInformation() {
  8772. limit, _ := this.GetInt64("limit")
  8773. page, _ := this.GetInt64("page")
  8774. orgid := this.GetMobileAdminUserInfo().Org.Id
  8775. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8776. appid := this.GetMobileAdminUserInfo().App.Id
  8777. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8778. patients, _ := service.GetAllpatientThirty(orgid)
  8779. this.ServeSuccessJSON(map[string]interface{}{
  8780. "information": information,
  8781. "total": total,
  8782. "doclist": doclist,
  8783. "patients": patients,
  8784. })
  8785. return
  8786. }
  8787. func (this *DialysisAPIController) GetMobileInformationOne() {
  8788. limit, _ := this.GetInt64("limit")
  8789. page, _ := this.GetInt64("page")
  8790. orgid := this.GetMobileAdminUserInfo().Org.Id
  8791. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8792. appid := this.GetMobileAdminUserInfo().App.Id
  8793. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8794. patients, _ := service.GetAllpatientThirty(orgid)
  8795. this.ServeSuccessJSON(map[string]interface{}{
  8796. "information": information,
  8797. "total": total,
  8798. "doclist": doclist,
  8799. "patients": patients,
  8800. })
  8801. return
  8802. }
  8803. func (this *DialysisAPIController) CheckMobileInformation() {
  8804. id, _ := this.GetInt64("id")
  8805. application_status, _ := this.GetInt64("application_status")
  8806. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8807. checktime := time.Now().Unix()
  8808. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8809. if err == nil {
  8810. this.ServeSuccessJSON(map[string]interface{}{
  8811. "msg": "ok",
  8812. })
  8813. return
  8814. }
  8815. }
  8816. func (c *DialysisAPIController) GetControlMonitorList() {
  8817. partition, _ := c.GetInt64("partition")
  8818. monitorDate := c.GetString("date")
  8819. patient_id, _ := c.GetInt64("patient_id")
  8820. pat_type, _ := c.GetInt64("pat_type")
  8821. timeLayout := "2006-01-02"
  8822. loc, _ := time.LoadLocation("Local")
  8823. var theStartTime int64
  8824. if len(monitorDate) > 0 {
  8825. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8826. if err != nil {
  8827. theStartTime = 0
  8828. }
  8829. theStartTime = theTime.Unix()
  8830. }
  8831. adminInfo := c.GetMobileAdminUserInfo()
  8832. orgID := adminInfo.Org.Id
  8833. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8834. if err != nil {
  8835. c.ErrorLog("获取排班信息失败:%v", err)
  8836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8837. } else {
  8838. if len(monitor) > 0 {
  8839. //获取所有床位
  8840. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8841. //获取所有分区
  8842. zoneList, _ := service.GetAllZoneByList(orgID)
  8843. //获取透析处方
  8844. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8845. //获取透前评估
  8846. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8847. //获取上机
  8848. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8849. //获取透后
  8850. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8851. //获取透后监测
  8852. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8853. //获取所有的患者
  8854. patients, _ := service.GetAllPatientListByListOne(orgID)
  8855. //获取所有透析模式
  8856. treatments, _ := service.GetAllTreatModeByList(orgID)
  8857. //获取所有医嘱
  8858. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8859. //获取双人核对
  8860. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8861. //治疗小结
  8862. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8863. //待消毒
  8864. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8865. for key, item := range monitor {
  8866. // 获取床位信息
  8867. for _, it := range numberList {
  8868. if item.BedId == it.ID {
  8869. monitor[key].DeviceNumber = it
  8870. break
  8871. }
  8872. }
  8873. //获取分区信息
  8874. for _, it := range zoneList {
  8875. if item.PartitionId == it.ID {
  8876. monitor[key].DeviceZone = it
  8877. }
  8878. }
  8879. for _, prescription := range prescriptions {
  8880. if item.PatientId == prescription.PatientId {
  8881. monitor[key].Prescription = prescription
  8882. break
  8883. }
  8884. }
  8885. for _, it := range checkList {
  8886. if item.PatientId == it.PatientId {
  8887. monitor[key].DoubleCheck = it
  8888. break
  8889. }
  8890. }
  8891. for _, it := range summaryList {
  8892. if item.PatientId == it.PatientId {
  8893. monitor[key].TreatmentSummaryForList = it
  8894. break
  8895. }
  8896. }
  8897. // 透前评估
  8898. for _, assessmentBefore := range assessmentBefores {
  8899. if item.PatientId == assessmentBefore.PatientId {
  8900. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8901. break
  8902. }
  8903. }
  8904. // 透析上下机
  8905. for _, dialysisOrder := range dialysisOrders {
  8906. if item.PatientId == dialysisOrder.PatientId {
  8907. monitor[key].DialysisOrder = dialysisOrder
  8908. break
  8909. }
  8910. }
  8911. // 治疗小节
  8912. for _, afterDislysis := range AssessmentAfterDislysis {
  8913. if item.PatientId == afterDislysis.PatientId {
  8914. monitor[key].AssessmentAfterDislysis = afterDislysis
  8915. break
  8916. }
  8917. }
  8918. for _, it := range monitorlist {
  8919. if item.PatientId == it.PatientId {
  8920. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8921. }
  8922. }
  8923. for _, it := range adviceList {
  8924. if item.PatientId == it.PatientId {
  8925. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8926. }
  8927. }
  8928. for _, patient := range patients {
  8929. if item.PatientId == patient.ID {
  8930. monitor[key].MonitorPatients = patient
  8931. break
  8932. }
  8933. }
  8934. for _, treatment := range treatments {
  8935. if item.ModeId == treatment.ID {
  8936. monitor[key].TreatmentMode = treatment
  8937. break
  8938. }
  8939. }
  8940. for _, infor := range informationList {
  8941. if item.PatientId == infor.PatientId {
  8942. monitor[key].NewDeviceInformation = infor
  8943. break
  8944. }
  8945. }
  8946. }
  8947. }
  8948. }
  8949. patients, err := service.GetAllpatientFourty(orgID)
  8950. var mds []*models.NewMonitorDialysisScheduleList
  8951. if pat_type == 0 {
  8952. for _, item := range monitor {
  8953. mds = append(mds, item)
  8954. }
  8955. }
  8956. //待医嘱核对
  8957. if pat_type == 1 {
  8958. for _, item := range monitor {
  8959. if len(item.AdviceList) > 0 {
  8960. mds = append(mds, item)
  8961. }
  8962. }
  8963. }
  8964. //待开小结
  8965. if pat_type == 2 {
  8966. for _, item := range monitor {
  8967. if item.TreatmentSummaryForList == nil {
  8968. mds = append(mds, item)
  8969. }
  8970. }
  8971. }
  8972. //待下机
  8973. if pat_type == 3 {
  8974. for _, item := range monitor {
  8975. if item.DialysisOrder != nil {
  8976. if item.DialysisOrder.ID > 0 {
  8977. mds = append(mds, item)
  8978. }
  8979. }
  8980. }
  8981. }
  8982. //待消毒
  8983. if pat_type == 4 {
  8984. for _, item := range monitor {
  8985. if item.NewDeviceInformation == nil {
  8986. mds = append(mds, item)
  8987. }
  8988. }
  8989. }
  8990. //待双人核对
  8991. if pat_type == 5 {
  8992. for _, item := range monitor {
  8993. if item.DoubleCheck == nil {
  8994. mds = append(mds, item)
  8995. }
  8996. }
  8997. }
  8998. //医嘱未执行
  8999. if pat_type == 6 {
  9000. for _, item := range monitor {
  9001. if len(item.AdviceList) > 0 {
  9002. mds = append(mds, item)
  9003. }
  9004. }
  9005. }
  9006. //患者未签名
  9007. if pat_type == 7 {
  9008. for _, item := range monitor {
  9009. if item.DialysisOrder != nil {
  9010. if item.DialysisOrder.ID > 0 {
  9011. mds = append(mds, item)
  9012. }
  9013. }
  9014. }
  9015. }
  9016. //目标超滤于实际超滤不同
  9017. if pat_type == 8 {
  9018. for _, item := range monitor {
  9019. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9020. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9021. mds = append(mds, item)
  9022. }
  9023. }
  9024. }
  9025. }
  9026. //血压少于5次
  9027. if pat_type == 9 {
  9028. for _, item := range monitor {
  9029. if len(item.MonitoringRecord) < 5 {
  9030. mds = append(mds, item)
  9031. }
  9032. }
  9033. }
  9034. if pat_type == 10 {
  9035. for _, item := range monitor {
  9036. if len(item.MonitoringRecord) == 0 {
  9037. mds = append(mds, item)
  9038. }
  9039. }
  9040. }
  9041. if pat_type == 11 {
  9042. for _, item := range monitor {
  9043. if len(item.MonitoringRecord) > 0 {
  9044. mds = append(mds, item)
  9045. }
  9046. }
  9047. }
  9048. if pat_type == 12 {
  9049. for _, item := range monitor {
  9050. if len(item.MonitoringRecord) > 0 {
  9051. mds = append(mds, item)
  9052. }
  9053. }
  9054. }
  9055. if err == nil {
  9056. c.ServeSuccessJSON(map[string]interface{}{
  9057. "monitor": mds,
  9058. "patients": patients,
  9059. })
  9060. } else {
  9061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9062. }
  9063. }
  9064. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9065. admin_user_id, _ := c.GetInt64("admin_user_id")
  9066. timeStr := time.Now().Format("2006-01-02")
  9067. timeLayout := "2006-01-02 15:04:05"
  9068. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9069. timenow := timeStringToTime.Unix()
  9070. orgId := c.GetMobileAdminUserInfo().Org.Id
  9071. //查询当前护士的患者
  9072. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9073. var patientIds []int64
  9074. for _, item := range orderList {
  9075. patientIds = append(patientIds, item.PatientId)
  9076. }
  9077. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9078. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9079. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9080. //药品管理信息
  9081. _, drugStockConfig := service.FindHisConfig(orgId)
  9082. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9083. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9084. c.ServeSuccessJSON(map[string]interface{}{
  9085. "adviceList": adviceList,
  9086. "hisAdviceList": hisAdviceList,
  9087. "projectList": projectList,
  9088. "drugStockConfig": drugStockConfig,
  9089. "patientList": patientList,
  9090. "projectConfig": projectConfig,
  9091. })
  9092. }
  9093. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  9094. patient_id, _ := c.GetInt64("patient_id")
  9095. recrods, _ := service.GetLastAcceptRecrods(patient_id)
  9096. c.ServeSuccessJSON(map[string]interface{}{
  9097. "recrods": recrods,
  9098. })
  9099. }
  9100. func (c *DialysisAPIController) ExMobileChangeSch() {
  9101. id_one, _ := c.GetInt64("id_one")
  9102. id_two, _ := c.GetInt64("id_two")
  9103. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9104. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9105. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  9106. //if order2.ID > 0 {
  9107. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9108. // return
  9109. //}
  9110. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9111. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9112. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9113. if count > 0 {
  9114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9115. return
  9116. }
  9117. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  9118. if count1 > 0 {
  9119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9120. return
  9121. }
  9122. }
  9123. err := service.UpdateScheduleThree(sch, sch_two)
  9124. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9125. if order.ID > 0 {
  9126. //查询该患者的排班机位
  9127. pSchedule, _ := service.GetPscheduleDate(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9128. service.UpdateDialysiOrderByPatientId(id_two, pSchedule.ScheduleType, pSchedule.PartitionId, pSchedule.BedId)
  9129. redis := service.RedisClient()
  9130. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9131. redis.Set(key, "", time.Second)
  9132. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9133. //清空key 值
  9134. redis.Set(keyOne, "", time.Second)
  9135. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderOne)
  9136. //return
  9137. }
  9138. if err == nil {
  9139. //去除当天患者排班中重复数据,保留最后一条数据
  9140. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9141. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9142. c.ServeSuccessJSON(map[string]interface{}{
  9143. "msg": "交换成功",
  9144. })
  9145. } else {
  9146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9147. return
  9148. }
  9149. }
  9150. func (c *DialysisAPIController) MobileCoverSch() {
  9151. id_one, _ := c.GetInt64("id_one")
  9152. id_two, _ := c.GetInt64("id_two")
  9153. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  9154. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  9155. order, _ := service.GetOneDialysisOrderOne(sch.ScheduleDate, sch.PatientId, sch.UserOrgId)
  9156. if order.ID > 0 {
  9157. service.UpdateDialysiOrderByPatientId(id_two, sch_two.ScheduleType, sch_two.PartitionId, sch_two.BedId)
  9158. redis := service.RedisClient()
  9159. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  9160. redis.Set(key, "", time.Second)
  9161. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  9162. //清空key 值
  9163. redis.Set(keyOne, "", time.Second)
  9164. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  9165. //return
  9166. }
  9167. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  9168. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  9169. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  9170. if count > 0 {
  9171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  9172. return
  9173. }
  9174. }
  9175. var new_sch models.Schedule
  9176. new_sch = sch
  9177. new_sch.BedId = sch_two.BedId
  9178. new_sch.ScheduleDate = sch_two.ScheduleDate
  9179. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  9180. new_sch.PartitionId = sch_two.PartitionId
  9181. new_sch.ScheduleType = sch_two.ScheduleType
  9182. new_sch.ID = 0
  9183. //删除原来的排班
  9184. err := service.SaveSchTwo(sch, sch_two)
  9185. //生成新的排班
  9186. if err == nil {
  9187. err2 := service.SaveSch(&new_sch)
  9188. if err2 == nil {
  9189. //去除当天患者排班中重复数据,保留最后一条数据
  9190. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  9191. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  9192. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  9193. c.ServeSuccessJSON(map[string]interface{}{
  9194. "msg": "覆盖成功",
  9195. "new_sch": new_sch,
  9196. })
  9197. } else {
  9198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9199. return
  9200. }
  9201. } else {
  9202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9203. return
  9204. }
  9205. }