dialysis_api_controller.go 348KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666
  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. returnData := map[string]interface{}{
  500. "patient": patient,
  501. "schedual": schedual,
  502. "prescription": dialysisPrescribe,
  503. "solution": dialysisSolution,
  504. "last_prescription": lastDialysisPrescribe,
  505. "receiver_treatment_access": receiverTreatmentAccess,
  506. "predialysis_evaluation": predialysisEvaluation,
  507. "doctor_advices": doctorAdvices,
  508. "double_check": doubleCheck,
  509. "assessment_after_dislysis": assessmentAfterDislysis,
  510. "treatment_summary": treatmentSummary,
  511. "monitor_records": monitorRecords,
  512. "dialysis_order": dialysisOrder,
  513. "operators": operators,
  514. "last_predialysis_evaluation": lastPredialysisEvaluation,
  515. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  516. "last_monitor_record": lastMonitorRecord,
  517. "config": gobalConfig,
  518. "dry_weight": lastDryWeightDislysis,
  519. "system_prescription": systemDialysisPrescribe,
  520. "his_advices": his_advices,
  521. "is_open_config": is_open_config,
  522. "stockType": stockType,
  523. "prepare": prepare,
  524. "lastAssessment": lastAssessment,
  525. "prescribeOne": prescribeOne,
  526. "is_project_open_config": is_project_open_config,
  527. "project": projects,
  528. "team_projects": team_projects,
  529. "is_advice_open": is_advice_open,
  530. "prescription_open": prescriptionConfig.IsOpen,
  531. "lastOrder": lastOrder,
  532. "remind_lists": remind_lists,
  533. }
  534. this.ServeSuccessJSON(returnData)
  535. }
  536. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  537. adminInfo := c.GetMobileAdminUserInfo()
  538. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  539. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  540. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  541. returnData := map[string]interface{}{
  542. "admin_users": adminUsers,
  543. "devices": devices,
  544. "device_numbers": device_numbers,
  545. }
  546. c.ServeSuccessJSON(returnData)
  547. }
  548. func (c *DialysisAPIController) PostAtreatmentInfo() {
  549. id, _ := c.GetInt64("patient", 0)
  550. recordDateStr := c.GetString("record_date")
  551. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  552. summaryContent := c.GetString("summaryContent")
  553. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  554. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  555. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  556. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  557. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  558. nursingRecord := c.GetString("nursing_record")
  559. fmt.Println("护理记录", nursingRecord)
  560. specialRecord := c.GetString("special_record")
  561. fmt.Println("特殊记录", specialRecord)
  562. adminUserInfo := c.GetMobileAdminUserInfo()
  563. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  564. checkStaffId = adminUserInfo.AdminUser.Id
  565. deboardNurseId = adminUserInfo.AdminUser.Id
  566. treatDoctor = adminUserInfo.AdminUser.Id
  567. if id <= 0 {
  568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  569. return
  570. }
  571. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  572. if patient.ID == 0 {
  573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  574. return
  575. }
  576. if len(recordDateStr) == 0 {
  577. recordDateStr = time.Now().Format("2006-01-02")
  578. }
  579. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  580. if parseDateErr != nil {
  581. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  583. return
  584. }
  585. summary := models.TreatmentSummary{
  586. UserOrgId: adminUserInfo.Org.Id,
  587. PatientId: id,
  588. AssessmentDate: recordDate.Unix(),
  589. Mission: propagandaAndEducationContent,
  590. DialysisSummary: summaryContent,
  591. SjNurse: changeMedicalNurseId,
  592. ZlNurse: treatNurseId,
  593. HdNurse: checkStaffId,
  594. XjNurse: deboardNurseId,
  595. ZlDoctor: treatDoctor,
  596. CreatedTime: time.Now().Unix(),
  597. Status: 1,
  598. NursingRecord: nursingRecord,
  599. SpecialRecord: specialRecord,
  600. }
  601. // 查询信息规挡的设置天数
  602. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  603. if infor.ID > 0 && infor.WeekDay > 0 {
  604. var cha_time int64
  605. timeNowStr := time.Now().Format("2006-01-02")
  606. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  607. //今日的日期减去设置的日期
  608. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  609. if cha_time >= recordDate.Unix() {
  610. //查询审核是否允许
  611. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  612. //申请状态不允许的情况 拒绝修改
  613. if infor.ApplicationStatus != 1 {
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  615. return
  616. }
  617. }
  618. }
  619. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  620. if treatmentSummary.ID == 0 { //新增
  621. summary.Creater = adminUserInfo.AdminUser.Id
  622. service.AddSigleSummaryRecord(&summary)
  623. finish := models.XtDialysisFinish{
  624. IsFinish: 1,
  625. UserOrgId: adminUserInfo.Org.Id,
  626. Status: 1,
  627. Ctime: time.Now().Unix(),
  628. Mtime: 0,
  629. Module: 10,
  630. RecordDate: recordDate.Unix(),
  631. Sourse: 1,
  632. PatientId: id,
  633. }
  634. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  635. if dialysisFinish.ID == 0 {
  636. service.CreateDialysisFinish(finish)
  637. }
  638. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  639. redis := service.RedisClient()
  640. //清空key 值
  641. redis.Set(key, "", time.Second)
  642. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  643. redis.Set(keyOne, "", time.Second)
  644. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  645. redis.Set(keyThree, "", time.Second)
  646. defer redis.Close()
  647. c.ServeSuccessJSON(map[string]interface{}{
  648. "summary": summary,
  649. })
  650. } else { //修改
  651. summary.Creater = treatmentSummary.Creater
  652. summary.CreatedTime = treatmentSummary.CreatedTime
  653. summary.Modifier = adminUserInfo.AdminUser.Id
  654. summary.ID = treatmentSummary.ID
  655. service.UpdateSummeRecord(&summary)
  656. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  657. redis := service.RedisClient()
  658. //清空key 值
  659. redis.Set(key, "", time.Second)
  660. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  661. redis.Set(keyOne, "", time.Second)
  662. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  663. redis.Set(keyThree, "", time.Second)
  664. defer redis.Close()
  665. c.ServeSuccessJSON(map[string]interface{}{
  666. "summary": summary,
  667. })
  668. }
  669. }
  670. func (c *DialysisAPIController) PostDoubleCheck() {
  671. id, _ := c.GetInt64("patient", 0)
  672. recordDateStr := c.GetString("record_date")
  673. checkTimeStr := c.GetString("check_time")
  674. firstCheckTimeStr := c.GetString("first_check_time")
  675. creater, _ := c.GetInt64("creater", 0)
  676. modifier, _ := c.GetInt64("modifier", 0)
  677. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  678. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  679. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  680. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  681. dialysis_item_desc := c.GetString("dialysis_item_desc")
  682. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  683. vascular_access_desc := c.GetString("vascular_access_desc")
  684. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  685. collator, _ := c.GetInt64("collator", 0)
  686. employee_number := c.GetString("employee_number")
  687. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  688. needle_batch_number := c.GetString("needle_batch_number")
  689. if id <= 0 {
  690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  691. return
  692. }
  693. adminUserInfo := c.GetMobileAdminUserInfo()
  694. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  695. if patient.ID == 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  697. return
  698. }
  699. if len(recordDateStr) == 0 {
  700. recordDateStr = time.Now().Format("2006-01-02")
  701. }
  702. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  703. if parseDateErr != nil {
  704. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  706. return
  707. }
  708. var checkDate int64
  709. if len(checkTimeStr) == 0 {
  710. checkDate = 0
  711. } else {
  712. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  713. checkDate = checkDateUnix.Unix()
  714. }
  715. var firstCheckDate int64
  716. if len(firstCheckTimeStr) == 0 {
  717. firstCheckDate = 0
  718. } else {
  719. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  720. firstCheckDate = firstCheckDateUnix.Unix()
  721. }
  722. //if adminUserInfo.Org.Id == 10340 {
  723. //
  724. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  725. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  726. // if check.ID == 0 {
  727. // if employee_number != list.JobNumber {
  728. // c.ServeSuccessJSON(map[string]interface{}{
  729. // "doubleCheck": check,
  730. // "msg": "2",
  731. // })
  732. // return
  733. // }
  734. // }
  735. // if check.ID > 0 {
  736. // if employee_number != list.JobNumber {
  737. // c.ServeSuccessJSON(map[string]interface{}{
  738. // "doubleCheck": check,
  739. // "msg": "2",
  740. // })
  741. // return
  742. // }
  743. // }
  744. //
  745. //}
  746. doubleCheck := models.DoubleCheck{
  747. UserOrgId: adminUserInfo.Org.Id,
  748. PatientId: id,
  749. DialysisItemCheck: dialysis_item_check,
  750. DialysisParameterCheck: dialysis_parameter_check,
  751. VascularAccessVerification: vascular_access_verification,
  752. PipelineConnectionCheck: pipeline_connection_check,
  753. DialysisItemDesc: dialysis_item_desc,
  754. DialysisParameterDesc: dialysis_parameter_desc,
  755. VascularAccessDesc: vascular_access_desc,
  756. PipelineConnectionDesc: pipeline_connection_desc,
  757. Collator: collator,
  758. Status: 1,
  759. CreatedTime: time.Now().Unix(),
  760. CheckDate: recordDate.Unix(),
  761. UpdatedTime: time.Now().Unix(),
  762. EmployeeNumber: employee_number,
  763. DialyzerBatchNumber: dialyzer_batch_number,
  764. NeedleBatchNumber: needle_batch_number,
  765. }
  766. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  767. if check.ID == 0 { //新增
  768. doubleCheck.FirstCheckTime = firstCheckDate
  769. doubleCheck.CheckTime = checkDate
  770. doubleCheck.Creater = creater
  771. doubleCheck.Modifier = modifier
  772. if adminUserInfo.Org.Id == 10340 {
  773. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  774. doubleCheck.Creater = order.StartNurse
  775. }
  776. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  777. //查询未核对的医嘱
  778. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  779. for _, advice := range doctorList {
  780. if advice.ExecutionStaff == modifier {
  781. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  782. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  783. return
  784. }
  785. }
  786. }
  787. // 查询信息规挡的设置天数
  788. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  789. if infor.ID > 0 && infor.WeekDay > 0 {
  790. var cha_time int64
  791. timeNowStr := time.Now().Format("2006-01-02")
  792. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  793. //今日的日期减去设置的日期
  794. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  795. if cha_time >= recordDate.Unix() {
  796. //查询审核是否允许
  797. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  798. //申请状态不允许的情况 拒绝修改
  799. if infor.ApplicationStatus != 1 {
  800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  801. return
  802. }
  803. }
  804. }
  805. err := service.AddSigleDoubleCheck(&doubleCheck)
  806. finish := models.XtDialysisFinish{
  807. IsFinish: 1,
  808. UserOrgId: adminUserInfo.Org.Id,
  809. Status: 1,
  810. Ctime: time.Now().Unix(),
  811. Mtime: 0,
  812. Module: 5,
  813. RecordDate: recordDate.Unix(),
  814. Sourse: 1,
  815. PatientId: id,
  816. }
  817. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  818. if dialysisFinish.ID == 0 {
  819. service.CreateDialysisFinish(finish)
  820. }
  821. //针对长沙南雅
  822. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  823. //查询未核对的医嘱
  824. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  825. if len(doctorList) > 0 && modifier > 0 {
  826. for _, advice := range doctorList {
  827. service.UpdateDoctorAdviceList(advice.ID, modifier)
  828. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  829. redis := service.RedisClient()
  830. //清空key 值
  831. redis.Set(key, "", time.Second)
  832. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  833. redis.Set(keyTwo, "", time.Second)
  834. theTime := time.Now()
  835. recordDate := theTime.Format("2006-01-02")
  836. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  837. redis.Set(keyFour, "", time.Second)
  838. defer redis.Close()
  839. }
  840. }
  841. }
  842. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  843. redis := service.RedisClient()
  844. //清空key 值
  845. redis.Set(key, "", time.Second)
  846. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  847. redis.Set(keyOne, "", time.Second)
  848. defer redis.Close()
  849. if err == nil {
  850. c.ServeSuccessJSON(map[string]interface{}{
  851. "doubleCheck": &doubleCheck,
  852. })
  853. }
  854. } else { //修改
  855. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  856. if infor.ID > 0 {
  857. var cha_time int64
  858. timeNowStr := time.Now().Format("2006-01-02")
  859. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  860. //今日的日期减去设置的日期
  861. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  862. if cha_time >= recordDate.Unix() {
  863. //查询审核是否允许
  864. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  865. //申请状态不允许的情况 拒绝修改
  866. if infor.ApplicationStatus != 1 {
  867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  868. return
  869. }
  870. }
  871. }
  872. doubleCheck.FirstCheckTime = firstCheckDate
  873. doubleCheck.CheckTime = checkDate
  874. doubleCheck.Creater = creater
  875. doubleCheck.Modifier = modifier
  876. doubleCheck.CreatedTime = check.CreatedTime
  877. doubleCheck.ID = check.ID
  878. doubleCheck.EmployeeNumber = employee_number
  879. doubleCheck.NeedleBatchNumber = needle_batch_number
  880. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  881. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  882. //查询未核对的医嘱
  883. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  884. for _, advice := range doctorList {
  885. if advice.ExecutionStaff == modifier {
  886. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  887. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  888. return
  889. }
  890. }
  891. }
  892. err := service.UpdateDoubleCheck(&doubleCheck)
  893. //针对长沙南雅
  894. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  895. //查询未核对的医嘱
  896. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  897. if len(doctorList) > 0 && modifier > 0 {
  898. for _, advice := range doctorList {
  899. service.UpdateDoctorAdviceList(advice.ID, modifier)
  900. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  901. redis := service.RedisClient()
  902. //清空key 值
  903. redis.Set(key, "", time.Second)
  904. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  905. redis.Set(keyTwo, "", time.Second)
  906. theTime := time.Now()
  907. recordDate := theTime.Format("2006-01-02")
  908. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  909. redis.Set(keyFour, "", time.Second)
  910. defer redis.Close()
  911. }
  912. }
  913. }
  914. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  915. redis := service.RedisClient()
  916. //清空key 值
  917. redis.Set(key, "", time.Second)
  918. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  919. redis.Set(keyOne, "", time.Second)
  920. defer redis.Close()
  921. if err == nil {
  922. c.ServeSuccessJSON(map[string]interface{}{
  923. "doubleCheck": &doubleCheck,
  924. "msg": "1",
  925. })
  926. }
  927. }
  928. }
  929. func (c *DialysisAPIController) PostAcceptsAssessment() {
  930. id, _ := c.GetInt64("patient", 0)
  931. recordDateStr := c.GetString("record_date")
  932. way, _ := c.GetInt64("way", 0)
  933. consciousness, _ := c.GetInt64("consciousness", 0)
  934. appetite, _ := c.GetInt64("appetite", 0)
  935. condition, _ := c.GetInt64("condition", 0)
  936. posture, _ := c.GetInt64("posture")
  937. sick_condition, _ := c.GetInt64("sick_condition", 0)
  938. danger_level, _ := c.GetInt64("danger_level", 0)
  939. intake, _ := c.GetInt64("intake", 0)
  940. nutrition, _ := c.GetInt64("nutrition", 0)
  941. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  942. psychological_assessment_other := c.GetString("psychological_assessment_other")
  943. score := c.GetString("score")
  944. sick_condition_other := c.GetString("sick_condition_other")
  945. //precaution, _ := c.GetInt64("precaution", 0)
  946. precaution := c.GetString("precaution")
  947. precaution_other := c.GetString("precaution_other")
  948. psychological_other := c.GetString("psychological_other")
  949. admission_number := c.GetString("admission_number")
  950. tumble, _ := c.GetInt64("tumble")
  951. diacrisis := c.GetString("diacrisis")
  952. his_department := c.GetString("his_department")
  953. his_bed := c.GetString("his_bed")
  954. if id <= 0 {
  955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  956. return
  957. }
  958. adminUserInfo := c.GetMobileAdminUserInfo()
  959. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  960. if patient.ID == 0 {
  961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  962. return
  963. }
  964. //now := time.Now()
  965. //year, month, day := now.Date()
  966. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  967. //todayTimeStamp := today_time.Unix()
  968. if len(recordDateStr) == 0 {
  969. recordDateStr = time.Now().Format("2006-01-02")
  970. }
  971. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  972. if parseDateErr != nil {
  973. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  975. return
  976. }
  977. // 查询信息规挡的设置天数
  978. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  979. if infor.ID > 0 && infor.WeekDay > 0 {
  980. var cha_time int64
  981. timeNowStr := time.Now().Format("2006-01-02")
  982. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  983. //今日的日期减去设置的日期
  984. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  985. if cha_time >= recordDate.Unix() {
  986. //查询审核是否允许
  987. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  988. //申请状态不允许的情况 拒绝修改
  989. if infor.ApplicationStatus != 1 {
  990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  991. return
  992. }
  993. }
  994. }
  995. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  996. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  997. UserOrgId: adminUserInfo.Org.Id,
  998. PatientId: id,
  999. RecordDate: recordDate.Unix(),
  1000. Way: way,
  1001. Consciousness: consciousness,
  1002. Appetite: appetite,
  1003. Condition: condition,
  1004. SickCondition: sick_condition,
  1005. DangerLevel: danger_level,
  1006. Intake: intake,
  1007. Nutrition: nutrition,
  1008. PsychologicalAssessment: psychological_assessment,
  1009. PsychologicalAssessmentOther: psychological_assessment_other,
  1010. SickConditionOther: sick_condition_other,
  1011. Posture: posture,
  1012. CreatedTime: time.Now().Unix(),
  1013. UpdateTime: time.Now().Unix(),
  1014. Status: 1,
  1015. Score: score,
  1016. Precaution: precaution,
  1017. PrecautionOther: precaution_other,
  1018. PsychologicalOther: psychological_other,
  1019. AdmissionNumber: admission_number,
  1020. Tumble: tumble,
  1021. Diacrisis: diacrisis,
  1022. HisBed: his_bed,
  1023. HisDepartment: his_department,
  1024. }
  1025. if receiveTreatment.ID == 0 { //新增
  1026. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1027. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1028. finish := models.XtDialysisFinish{
  1029. IsFinish: 1,
  1030. UserOrgId: adminUserInfo.Org.Id,
  1031. Status: 1,
  1032. Ctime: time.Now().Unix(),
  1033. Mtime: 0,
  1034. Module: 2,
  1035. RecordDate: recordDate.Unix(),
  1036. Sourse: 1,
  1037. PatientId: id,
  1038. }
  1039. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1040. if dialysisFinish.ID == 0 {
  1041. service.CreateDialysisFinish(finish)
  1042. }
  1043. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1044. redis := service.RedisClient()
  1045. defer redis.Close()
  1046. //清空key 值
  1047. redis.Set(key, "", time.Second)
  1048. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1049. redis.Set(keyOne, "", time.Second)
  1050. if err == nil {
  1051. c.ServeSuccessJSON(map[string]interface{}{
  1052. "receiveTreatmentAsses": receiveTreatmentAsses,
  1053. })
  1054. }
  1055. } else { //修改
  1056. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1057. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1058. // if getPermissionErr != nil {
  1059. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1060. // return
  1061. // } else if headNursePermission == nil {
  1062. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1063. // return
  1064. // }
  1065. //}
  1066. // 查询信息规挡的设置天数
  1067. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1068. if infor.ID > 0 && infor.WeekDay > 0 {
  1069. var cha_time int64
  1070. timeNowStr := time.Now().Format("2006-01-02")
  1071. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1072. //今日的日期减去设置的日期
  1073. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1074. if cha_time >= recordDate.Unix() {
  1075. //查询审核是否允许
  1076. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1077. //申请状态不允许的情况 拒绝修改
  1078. if infor.ApplicationStatus != 1 {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1080. return
  1081. }
  1082. }
  1083. }
  1084. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1085. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1086. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1087. receiveTreatmentAsses.ID = receiveTreatment.ID
  1088. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1089. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1090. redis := service.RedisClient()
  1091. defer redis.Close()
  1092. //清空key 值
  1093. redis.Set(key, "", time.Second)
  1094. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1095. redis.Set(keyOne, "", time.Second)
  1096. if err == nil {
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "receiveTreatmentAsses": receiveTreatmentAsses,
  1099. })
  1100. }
  1101. }
  1102. }
  1103. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1104. id, _ := c.GetInt64("patient", 0)
  1105. recordDateStr := c.GetString("record_date")
  1106. weightAfter, _ := c.GetFloat("weight_after", 0)
  1107. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1108. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1109. fmt.Println("weight_loss", weightReduce)
  1110. temperature, _ := c.GetFloat("temperature", 0)
  1111. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1112. breathing_rate := c.GetString("breathing_rate")
  1113. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1114. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1115. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1116. fmt.Println("actual_ultrafiltration233232322323", actual_ultrafiltration)
  1117. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1118. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1119. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1120. cruor := c.GetString("cruor")
  1121. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1122. internalFistula := c.GetString("internal_fistula")
  1123. catheter := c.GetString("catheter")
  1124. complications := c.GetString("complication")
  1125. remark := c.GetString("remark")
  1126. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1127. dialysis_intakes := c.GetString("dialysis_intakes")
  1128. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1129. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1130. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1131. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1132. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1133. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1134. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1135. patientGose, _ := c.GetInt64("patient_gose", 0)
  1136. inpatientDepartment := c.GetString("inpatient_department")
  1137. observationContent := c.GetString("observation_content")
  1138. observationContentOther := c.GetString("observation_content_other")
  1139. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1140. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1141. in_advance_reason := c.GetString("in_advance_reason")
  1142. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1143. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1144. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1145. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1146. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1147. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1148. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1149. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1150. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1151. is_eat, _ := c.GetInt64("is_eat", 0)
  1152. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1153. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1154. channels, _ := c.GetInt64("channel", 0)
  1155. return_blood, _ := c.GetInt64("return_blood", 0)
  1156. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1157. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1158. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1159. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1160. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1161. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1162. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1163. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1164. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1165. setting_pressure := c.GetString("setting_pressure")
  1166. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1167. diastolic_pressure := c.GetString("diastolic_pressure")
  1168. other_complication := c.GetString("other_complication")
  1169. ktv := c.GetString("ktv")
  1170. urr := c.GetString("urr")
  1171. hypertenison, _ := c.GetInt64("hypertenison")
  1172. hypopiesia, _ := c.GetInt64("hypopiesia")
  1173. leave_office_method, _ := c.GetInt64("leave_office_method")
  1174. lapse, _ := c.GetInt64("lapse")
  1175. consciousness, _ := c.GetInt64("consciousness")
  1176. fallrisk, _ := c.GetInt64("fallrisk")
  1177. machine_run := c.GetString("machine_run")
  1178. after_urea := c.GetString("after_urea")
  1179. pip_coagulation := c.GetString("pip_coagulation")
  1180. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1181. fmt.Println("accumulated_blood_volume", accumulated_blood_volume)
  1182. if id <= 0 {
  1183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1184. return
  1185. }
  1186. adminUserInfo := c.GetMobileAdminUserInfo()
  1187. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1188. if patient.ID == 0 {
  1189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1190. return
  1191. }
  1192. if len(recordDateStr) == 0 {
  1193. recordDateStr = time.Now().Format("2006-01-02")
  1194. }
  1195. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1196. fmt.Println("parseDateErr", parseDateErr)
  1197. if parseDateErr != nil {
  1198. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1200. return
  1201. }
  1202. //now := time.Now()
  1203. //year, month, day := now.Date()
  1204. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1205. //todayTimeStamp := today_time.Unix()
  1206. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1207. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1208. UserOrgId: adminUserInfo.Org.Id,
  1209. PatientId: id,
  1210. AssessmentDate: recordDate.Unix(),
  1211. Temperature: temperature,
  1212. PulseFrequency: pulse_frequency,
  1213. BreathingRate: breathing_rate,
  1214. SystolicBloodPressure: systolic_blood_pressure,
  1215. DiastolicBloodPressure: diastolic_blood_pressure,
  1216. ActualUltrafiltration: actual_ultrafiltration,
  1217. ActualDisplacement: actual_displacement,
  1218. ActualTreatmentHour: actualtreatHour,
  1219. ActualTreatmentMinute: actualtreatmin,
  1220. WeightAfter: weightAfter,
  1221. AdditionalWeight: additionalWeight,
  1222. WeightLoss: weightReduce,
  1223. Cruor: cruor,
  1224. SymptomAfterDialysis: symptomsAfterDialysi,
  1225. InternalFistula: internalFistula,
  1226. Catheter: catheter,
  1227. Complication: complications,
  1228. DialysisIntakes: dialysateVolume,
  1229. CreatedTime: time.Now().Unix(),
  1230. UpdatedTime: time.Now().Unix(),
  1231. Status: 1,
  1232. Remark: remark,
  1233. BloodAccessPartId: blood_access_part_id,
  1234. BloodAccessPartOperaId: blood_access_part_opera_id,
  1235. DialysisIntakesUnit: dialysis_intakes_unit,
  1236. PuncturePointOozingBlood: puncturePointOozingBlood,
  1237. PuncturePointHaematoma: puncturePointHaematoma,
  1238. InternalFistulaTremorAc: internalFistulaTremorAc,
  1239. PatientGose: patientGose,
  1240. InpatientDepartment: inpatientDepartment,
  1241. ObservationContent: observationContent,
  1242. ObservationContentOther: observationContentOther,
  1243. DialysisProcess: dialysis_process,
  1244. InAdvanceMinute: in_advance_minute,
  1245. InAdvanceReason: in_advance_reason,
  1246. HemostasisMinute: hemostasis_minute,
  1247. HemostasisOpera: hemostasis_opera,
  1248. TremorNoise: tremor_noise,
  1249. DisequilibriumSyndrome: disequilibrium_syndrome,
  1250. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1251. ArterialTube: arterial_tube,
  1252. IntravenousTube: intravenous_tube,
  1253. Dialyzer: dialyzer,
  1254. InAdvanceReasonOther: in_advance_reason_other,
  1255. IsEat: is_eat,
  1256. CvcA: cvc_a,
  1257. CvcV: cvc_v,
  1258. Channel: channels,
  1259. ReturnBlood: return_blood,
  1260. RehydrationVolume: rehydration_volume,
  1261. DialysisDuring: dialysis_during,
  1262. StrokeVolume: stroke_volume,
  1263. BloodFlow: blood_flow,
  1264. SealingFluidDispose: sealing_fluid_dispose,
  1265. SealingFluidSpecial: sealing_fluid_special,
  1266. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1267. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1268. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1269. SettingPressure: setting_pressure,
  1270. DiastolicPressure: diastolic_pressure,
  1271. OtherComplication: other_complication,
  1272. Ktv: ktv,
  1273. Urr: urr,
  1274. Hypopiesia: hypopiesia,
  1275. Hypertenison: hypertenison,
  1276. Lapse: lapse,
  1277. LeaveOfficeMethod: leave_office_method,
  1278. Consciousness: consciousness,
  1279. Fallrisk: fallrisk,
  1280. MachineRun: machine_run,
  1281. AfterUrea: after_urea,
  1282. PipCoagulation: pip_coagulation,
  1283. AccumulatedBloodVolume: accumulated_blood_volume,
  1284. }
  1285. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1286. // 查询信息规挡的设置天数
  1287. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1288. if infor.ID > 0 && infor.WeekDay > 0 {
  1289. var cha_time int64
  1290. timeNowStr := time.Now().Format("2006-01-02")
  1291. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1292. //今日的日期减去设置的日期
  1293. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1294. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1295. if cha_time >= recordDate.Unix() {
  1296. //查询审核是否允许
  1297. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1298. //申请状态不允许的情况 拒绝修改
  1299. if infor.ApplicationStatus != 1 {
  1300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1301. return
  1302. }
  1303. }
  1304. }
  1305. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1306. if assessmentAfter.ID == 0 { //新增
  1307. if appRole.UserType == 2 || appRole.UserType == 1 {
  1308. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1309. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1310. } else {
  1311. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1312. }
  1313. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1314. finish := models.XtDialysisFinish{
  1315. IsFinish: 1,
  1316. UserOrgId: adminUserInfo.Org.Id,
  1317. Status: 1,
  1318. Ctime: time.Now().Unix(),
  1319. Mtime: 0,
  1320. Module: 9,
  1321. RecordDate: recordDate.Unix(),
  1322. Sourse: 1,
  1323. PatientId: id,
  1324. }
  1325. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1326. if dialysisFinish.ID == 0 {
  1327. service.CreateDialysisFinish(finish)
  1328. }
  1329. redis := service.RedisClient()
  1330. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1331. redis.Set(keyTwo, "", time.Second)
  1332. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1333. //清空key 值
  1334. redis.Set(key, "", time.Second)
  1335. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1336. redis.Set(keyOne, "", time.Second)
  1337. defer redis.Close()
  1338. if err == nil {
  1339. c.ServeSuccessJSON(map[string]interface{}{
  1340. "assessmentAfterDislysis": assessmentAfterDislysis,
  1341. })
  1342. }
  1343. return
  1344. } else { //修改
  1345. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1346. if infor.ID > 0 && infor.WeekDay > 0 {
  1347. var cha_time int64
  1348. timeNowStr := time.Now().Format("2006-01-02")
  1349. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1350. //今日的日期减去设置的日期
  1351. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1352. if cha_time >= recordDate.Unix() {
  1353. //查询审核是否允许
  1354. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1355. //申请状态不允许的情况 拒绝修改
  1356. if infor.ApplicationStatus != 1 {
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1358. return
  1359. }
  1360. }
  1361. }
  1362. if appRole.UserType == 2 || appRole.UserType == 1 {
  1363. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1364. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1365. } else {
  1366. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1367. if assessmentAfterDislysis.Creater == 0 {
  1368. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1369. }
  1370. }
  1371. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1372. assessmentAfterDislysis.ID = assessmentAfter.ID
  1373. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1374. fmt.Println("werwewweoweoweoweoewoewoew", err)
  1375. redis := service.RedisClient()
  1376. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1377. redis.Set(keyTwo, "", time.Second)
  1378. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1379. //清空key 值
  1380. redis.Set(key, "", time.Second)
  1381. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1382. redis.Set(keyOne, "", time.Second)
  1383. if err == nil {
  1384. c.ServeSuccessJSON(map[string]interface{}{
  1385. "assessmentAfterDislysis": assessmentAfterDislysis,
  1386. })
  1387. return
  1388. }
  1389. }
  1390. return
  1391. }
  1392. func (c *DialysisAPIController) PostDialysisPrescription() {
  1393. id, _ := c.GetInt64("patient", 0)
  1394. recordDateStr := c.GetString("record_date")
  1395. if id <= 0 {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1397. return
  1398. }
  1399. adminUserInfo := c.GetMobileAdminUserInfo()
  1400. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1401. if patient.ID == 0 {
  1402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1403. return
  1404. }
  1405. if len(recordDateStr) == 0 {
  1406. recordDateStr = time.Now().Format("2006-01-02")
  1407. }
  1408. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1409. if parseDateErr != nil {
  1410. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1412. return
  1413. }
  1414. mode_id, _ := c.GetInt64("mode_id", 0)
  1415. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1416. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1417. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1418. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1419. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1420. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1421. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1422. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1423. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1424. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1425. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1426. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1427. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1428. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1429. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1430. kalium, _ := c.GetFloat("kalium", 0)
  1431. sodium, _ := c.GetFloat("sodium", 0)
  1432. calcium, _ := c.GetFloat("calcium", 0)
  1433. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1434. glucose, _ := c.GetFloat("glucose", 0)
  1435. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1436. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1437. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1438. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1439. conductivity, _ := c.GetFloat("conductivity", 0)
  1440. remark := c.GetString("remark")
  1441. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1442. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1443. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1444. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1445. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1446. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1447. special_medicine_other := c.GetString("special_medicine_other")
  1448. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1449. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1450. blood_access, _ := c.GetInt64("blood_access", 0)
  1451. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1452. body_fluid_other := c.GetString("body_fluid_other")
  1453. niprocart, _ := c.GetInt64("niprocart", 0)
  1454. jms, _ := c.GetInt64("jms", 0)
  1455. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1456. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1457. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1458. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1459. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1460. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1461. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1462. injector, _ := c.GetInt64("injector", 0)
  1463. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1464. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1465. safe_package, _ := c.GetInt64("package", 0)
  1466. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1467. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1468. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1469. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1470. blood := c.GetString("blood")
  1471. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1472. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1473. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1474. displace_speed := c.GetString("displace_speed")
  1475. illness, _ := c.GetInt64("illness")
  1476. amylaceum := c.GetString("amylaceum")
  1477. single_time := c.GetString("single_time")
  1478. single_water := c.GetString("single_water")
  1479. replacement_flow := c.GetString("replacement_flow")
  1480. plasma_separator := c.GetString("plasma_separator")
  1481. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1482. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1483. oxygen_flow := c.GetString("oxygen_flow")
  1484. oxygen_time := c.GetString("oxygen_time")
  1485. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1486. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1487. puncture_needle := c.GetString("puncture_needle")
  1488. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1489. epo := c.GetString("epo")
  1490. epo_count, _ := c.GetFloat("epo_count", 0)
  1491. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1492. admin_user_id, _ := c.GetInt64("admin_user_id")
  1493. is_water := c.GetString("is_water")
  1494. var is_war int64
  1495. if is_water == "是" {
  1496. is_war = 1
  1497. }
  1498. if is_water == "否" {
  1499. is_war = 2
  1500. }
  1501. if is_water == "请选择" {
  1502. is_war = 0
  1503. }
  1504. drhy_water := c.GetString("drhy_water")
  1505. dry_water_hour := c.GetString("dry_water_hour")
  1506. water_machine := c.GetString("water_machine")
  1507. add_amount, _ := c.GetFloat("add_amount")
  1508. reduce_amount, _ := c.GetFloat("reduce_amount")
  1509. dialysis_remark := c.GetString("dialysis_remark")
  1510. prescribing_number, _ := c.GetFloat("prescribing_number")
  1511. prescription_sodium := c.GetString("prescription_sodium")
  1512. start_sodium := c.GetString("start_sodium")
  1513. sodium_curve := c.GetString("sodium_curve")
  1514. treatment_remark := c.GetString("treatment_remark")
  1515. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1516. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1517. prescription_water, _ := c.GetFloat("prescription_water")
  1518. dialysis_strainer := c.GetString("dialysis_strainer")
  1519. chaptalization := c.GetString("chaptalization")
  1520. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1521. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1522. //
  1523. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1524. // if appRole.UserType == 3 {
  1525. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1526. // if getPermissionErr != nil {
  1527. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1528. // return
  1529. // } else if headNursePermission == nil {
  1530. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1531. // return
  1532. // }
  1533. // }
  1534. //}
  1535. // 查询信息规挡的设置天数
  1536. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1537. if infor.ID > 0 && infor.WeekDay > 0 {
  1538. var cha_time int64
  1539. timeNowStr := time.Now().Format("2006-01-02")
  1540. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1541. //今日的日期减去设置的日期
  1542. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1543. if cha_time >= recordDate.Unix() {
  1544. //查询审核是否允许
  1545. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1546. //申请状态不允许的情况 拒绝修改
  1547. if infor.ApplicationStatus != 1 {
  1548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1549. return
  1550. }
  1551. }
  1552. }
  1553. if mode_id > 0 {
  1554. var str string
  1555. //查找该机构用的是什么透析器
  1556. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1557. if filedConfig.ID > 0 {
  1558. str = dialyzerPerfusionApparatus
  1559. } else {
  1560. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1561. }
  1562. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1563. }
  1564. //TODO 需要根据角色去判断
  1565. prescription := models.DialysisPrescription{
  1566. UserOrgId: adminUserInfo.Org.Id,
  1567. PatientId: id,
  1568. RecordDate: recordDate.Unix(),
  1569. ModeId: mode_id,
  1570. DialysisDuration: dialysis_duration,
  1571. Dialyzer: dialyzer,
  1572. PerfusionApparatus: perfusion_apparatus,
  1573. BloodFlowVolume: blood_flow_volume,
  1574. DewaterAmount: dewater_amount,
  1575. DisplaceLiqui: displace_liqui,
  1576. ReplacementWay: replacement_way,
  1577. Anticoagulant: anticoagulant,
  1578. AnticoagulantShouji: anticoagulant_shouji,
  1579. AnticoagulantWeichi: anticoagulant_weichi,
  1580. AnticoagulantZongliang: anticoagulant_zongliang,
  1581. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1582. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1583. Kalium: kalium,
  1584. Sodium: sodium,
  1585. Calcium: calcium,
  1586. Bicarbonate: bicarbonate,
  1587. Glucose: glucose,
  1588. // DryWeight: dry_weight,
  1589. DialysateFlow: dialysate_flow,
  1590. DialysateTemperature: dialysate_temperature,
  1591. // PrescriptionDoctor: prescription_doctor,
  1592. ReplacementTotal: replacement_total,
  1593. Conductivity: conductivity,
  1594. Remark: remark,
  1595. Status: 1,
  1596. CreatedTime: time.Now().Unix(),
  1597. UpdatedTime: time.Now().Unix(),
  1598. DialysisDurationMinute: dialysisDurationMinute,
  1599. DialysisDurationHour: dialysisDurationHour,
  1600. TargetUltrafiltration: targetUltrafiltration,
  1601. DialysateFormulation: dialysateFormulation,
  1602. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1603. BodyFluid: body_fluid,
  1604. SpecialMedicine: special_medicine,
  1605. SpecialMedicineOther: special_medicine_other,
  1606. DisplaceLiquiPart: displace_liqui_part,
  1607. DisplaceLiquiValue: displace_liqui_value,
  1608. BloodAccess: blood_access,
  1609. Ultrafiltration: ultrafiltration,
  1610. BodyFluidOther: body_fluid_other,
  1611. Niprocart: niprocart,
  1612. Jms: jms,
  1613. FistulaNeedleSet: fistula_needle_set,
  1614. FistulaNeedleSet16: fistula_needle_set_16,
  1615. Hemoperfusion: hemoperfusion,
  1616. DialyserSterilised: dialyser_sterilised,
  1617. Filtryzer: filtryzer,
  1618. Dialyzers: dialyzers,
  1619. Injector: injector,
  1620. Bloodlines: bloodlines,
  1621. TubingHemodialysis: tubing_hemodialysis,
  1622. Package: safe_package,
  1623. ALiquid: a_liquid,
  1624. TargetKtv: target_ktv,
  1625. PreImpulse: pre_impulse,
  1626. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1627. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1628. Blood: blood,
  1629. DialysisDialyszers: dialysis_dialyszers,
  1630. DialysisIrrigation: dialysis_irrigation,
  1631. AntioxidantCommodityName: antioxidant_commodity_name,
  1632. DisplaceSpeed: displace_speed,
  1633. Illness: illness,
  1634. Amylaceum: amylaceum,
  1635. SingleTime: single_time,
  1636. SingleWater: single_water,
  1637. ReplacementFlow: replacement_flow,
  1638. PlasmaSeparator: plasma_separator,
  1639. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1640. OxygenUptake: oxygen_uptake,
  1641. OxygenFlow: oxygen_flow,
  1642. OxygenTime: oxygen_time,
  1643. HemodialysisPipelines: hemodialysis_pipelines,
  1644. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1645. PunctureNeedle: puncture_needle,
  1646. PunctureNeedleCount: puncture_needle_count,
  1647. Epo: epo,
  1648. EpoCount: epo_count,
  1649. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1650. AdminUserId: admin_user_id,
  1651. IsWater: is_war,
  1652. DrhyWater: drhy_water,
  1653. DryWaterHour: dry_water_hour,
  1654. WaterMachine: water_machine,
  1655. AddAmount: add_amount,
  1656. ReduceAmount: reduce_amount,
  1657. DialysisRemark: dialysis_remark,
  1658. PrescribingNumber: prescribing_number,
  1659. StartSodium: start_sodium,
  1660. SodiumCurve: sodium_curve,
  1661. TreatmentRemark: treatment_remark,
  1662. PrescriptionSodium: prescription_sodium,
  1663. DialysisFluidFlow: dialysis_fluid_flow,
  1664. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1665. PrescriptionWater: prescription_water,
  1666. DialysisStrainer: dialysis_strainer,
  1667. Chaptalization: chaptalization,
  1668. }
  1669. //查询最近透析准备表里是否存在 透析器 灌流器
  1670. //
  1671. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1672. //
  1673. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1674. //
  1675. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1676. //if len(mation)>0{
  1677. // for _, item := range splitStr {
  1678. // for _,it := range mation{
  1679. // if(item == it.SpecificationName){
  1680. //
  1681. // //查询最近一次的透析器
  1682. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1683. //
  1684. // if errcode == gorm.ErrRecordNotFound{
  1685. // //插入数据
  1686. // prepare := models.DialysisBeforePrepare{
  1687. // UserOrgId: adminUserInfo.Org.Id,
  1688. // PatientId: id,
  1689. // RecordDate: recordDate.Unix(),
  1690. // GoodTypeId: it.GoodTypeId,
  1691. // GoodId: it.ID,
  1692. // Count: 1,
  1693. // Ctime: time.Now().Unix(),
  1694. // Creater: adminUserInfo.AdminUser.Id,
  1695. // Status:1,
  1696. //
  1697. // }
  1698. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1699. // fmt.Println("",errcode)
  1700. // }
  1701. // }
  1702. // }
  1703. //
  1704. // }
  1705. //
  1706. // for _, item := range splitIrrigation {
  1707. // for _,it := range mation{
  1708. // if(item == it.SpecificationName){
  1709. // //查询最近一次的透析器
  1710. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1711. // if errcode == gorm.ErrRecordNotFound{
  1712. // //插入数据
  1713. // prepare := models.DialysisBeforePrepare{
  1714. // UserOrgId: adminUserInfo.Org.Id,
  1715. // PatientId: id,
  1716. // RecordDate: recordDate.Unix(),
  1717. // GoodTypeId: it.GoodTypeId,
  1718. // GoodId: it.ID,
  1719. // Count: 1,
  1720. // Ctime: time.Now().Unix(),
  1721. // Creater: adminUserInfo.AdminUser.Id,
  1722. // Status:1,
  1723. //
  1724. // }
  1725. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1726. // fmt.Println(errcode)
  1727. // }
  1728. // }
  1729. // }
  1730. // }
  1731. //}
  1732. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1733. if dialysisPrescription.ID == 0 { //新增
  1734. if appRole.UserType == 2 || appRole.UserType == 1 {
  1735. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1736. }
  1737. prescription.Creater = adminUserInfo.AdminUser.Id
  1738. //针对河间咸得
  1739. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1740. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1741. prescription.DisplaceLiquiPart = 0
  1742. prescription.DisplaceLiquiValue = 0
  1743. }
  1744. }
  1745. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1746. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1747. }
  1748. err := service.AddSigleRecord(&prescription)
  1749. finish := models.XtDialysisFinish{
  1750. IsFinish: 1,
  1751. UserOrgId: adminUserInfo.Org.Id,
  1752. Status: 1,
  1753. Ctime: time.Now().Unix(),
  1754. Mtime: 0,
  1755. Module: 1,
  1756. RecordDate: recordDate.Unix(),
  1757. Sourse: 1,
  1758. PatientId: id,
  1759. }
  1760. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1761. if dialysisFinish.ID == 0 {
  1762. service.CreateDialysisFinish(finish)
  1763. }
  1764. //长沙南雅医院,自动生成抗凝剂的临时处方
  1765. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1766. if prescribing_number == 0 {
  1767. prescribing_number = 1
  1768. }
  1769. if prescribing_number == 0 && id == 14682 {
  1770. prescribing_number = 2
  1771. }
  1772. if prescribing_number == 0 && id == 18560 {
  1773. prescribing_number = 2
  1774. }
  1775. advice := models.DoctorAdvice{
  1776. UserOrgId: adminUserInfo.Org.Id,
  1777. PatientId: id,
  1778. GroupNo: 0,
  1779. AdviceType: 2,
  1780. RecordDate: recordDate.Unix(),
  1781. AdviceDate: recordDate.Unix(),
  1782. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1783. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1784. AdviceDesc: "",
  1785. ReminderDate: 0,
  1786. SingleDose: anticoagulant_zongliang,
  1787. SingleDoseUnit: "iu",
  1788. DrugSpec: 0,
  1789. DrugSpecUnit: "",
  1790. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1791. PrescribingNumberUnit: "支",
  1792. DeliveryWay: "静脉注射",
  1793. ExecutionFrequency: "上机前",
  1794. AdviceDoctor: 0,
  1795. Status: 1,
  1796. CreatedTime: time.Now().Unix(),
  1797. UpdatedTime: time.Now().Unix(),
  1798. IsPrescription: 1,
  1799. ExecutionState: 2,
  1800. StopState: 2,
  1801. IsSettle: 2,
  1802. }
  1803. // 查询排班信息
  1804. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1805. if schedulePatient.ID > 0 {
  1806. if schedulePatient.ScheduleType == 1 {
  1807. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1808. }
  1809. if schedulePatient.ScheduleType == 2 {
  1810. advice.StartTime = recordDate.Unix() + 10*60*60
  1811. }
  1812. }
  1813. // 抗凝剂名称
  1814. switch anticoagulant {
  1815. case 1:
  1816. advice.AdviceName = "无肝素"
  1817. break
  1818. case 2:
  1819. advice.AdviceName = "普通肝素"
  1820. break
  1821. case 3:
  1822. advice.AdviceName = "低分子肝素"
  1823. break
  1824. case 4:
  1825. advice.AdviceName = "阿加曲班"
  1826. break
  1827. case 5:
  1828. advice.AdviceName = "枸橼酸钠"
  1829. break
  1830. case 6:
  1831. advice.AdviceName = "低分子肝素钙"
  1832. break
  1833. case 7:
  1834. advice.AdviceName = "低分子肝素钠"
  1835. break
  1836. case 8:
  1837. advice.AdviceName = "依诺肝素"
  1838. break
  1839. case 9:
  1840. advice.AdviceName = "达肝素"
  1841. break
  1842. case 10:
  1843. advice.AdviceName = "体外抗凝"
  1844. break
  1845. case 11:
  1846. advice.AdviceName = "那曲肝素"
  1847. break
  1848. case 12:
  1849. advice.AdviceName = "无抗凝剂"
  1850. break
  1851. }
  1852. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1853. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1854. advice.AdviceDoctor = appRole.AdminUserId
  1855. }
  1856. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1857. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1858. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1859. advice.AdviceName = "低分子肝素钠注射液"
  1860. // 修改患者临时医嘱里的抗凝剂医嘱
  1861. advice.ID = advicePrescription.ID
  1862. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1863. } else {
  1864. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1865. advice.AdviceName = "低分子肝素钠注射液"
  1866. // 新增患者临时医嘱里的抗凝剂医嘱
  1867. service.CreateDoctorAdvice(&advice)
  1868. }
  1869. }
  1870. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1871. redis := service.RedisClient()
  1872. defer redis.Close()
  1873. //清空key 值
  1874. redis.Set(key, "", time.Second)
  1875. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1876. redis.Set(keyOne, "", time.Second)
  1877. }
  1878. //获取key,清空redis
  1879. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1880. redis := service.RedisClient()
  1881. //清空key 值
  1882. redis.Set(key, "", time.Second)
  1883. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1884. //清空key 值
  1885. redis.Set(keyOne, "", time.Second)
  1886. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1887. //清空key 值
  1888. redis.Set(keyTwo, "", time.Second)
  1889. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1890. redis.Set(keySix, "", time.Second)
  1891. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1892. redis.Set(keySeven, "", time.Second)
  1893. if err == nil {
  1894. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1895. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1896. //清空key 值
  1897. redis.Set(keyThree, "", time.Second)
  1898. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1899. //清空key 值
  1900. redis.Set(keyFour, "", time.Second)
  1901. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1902. redis.Set(keyFive, "", time.Second)
  1903. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1904. redis.Set(keySix, "", time.Second)
  1905. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1906. redis.Set(keySeven, "", time.Second)
  1907. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1908. //清空key 值
  1909. redis.Set(keyOne, "", time.Second)
  1910. if updateErr != nil {
  1911. utils.ErrorLog("%v", updateErr)
  1912. }
  1913. defer redis.Close()
  1914. c.ServeSuccessJSON(map[string]interface{}{
  1915. "prescription": prescription,
  1916. })
  1917. }
  1918. } else { //修改
  1919. //if mode_id > 0 {
  1920. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1921. //}
  1922. //if template.TemplateId == 1 {
  1923. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1924. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1925. // if getPermissionErr != nil {
  1926. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1927. // return
  1928. // } else if headNursePermission == nil {
  1929. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1930. // return
  1931. // }
  1932. // }
  1933. //}
  1934. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1935. prescription.Modifier = adminUserInfo.AdminUser.Id
  1936. if appRole.UserType == 2 || appRole.UserType == 1 {
  1937. prescription_doctor := adminUserInfo.AdminUser.Id
  1938. prescription.PrescriptionDoctor = prescription_doctor
  1939. } else {
  1940. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1941. }
  1942. if dialysisPrescription.Creater == 0 { //体重称
  1943. prescription.Creater = adminUserInfo.AdminUser.Id
  1944. } else {
  1945. prescription.Creater = dialysisPrescription.Creater
  1946. if adminUserInfo.Org.Id == 9882 {
  1947. if appRole.UserType == 2 || appRole.UserType == 1 {
  1948. prescription_doctor := adminUserInfo.AdminUser.Id
  1949. prescription.PrescriptionDoctor = prescription_doctor
  1950. prescription.Creater = prescription_doctor
  1951. }
  1952. }
  1953. }
  1954. prescription.ID = dialysisPrescription.ID
  1955. err := service.UpDateDialysisPrescription(&prescription)
  1956. finish := models.XtDialysisFinish{
  1957. IsFinish: 1,
  1958. UserOrgId: adminUserInfo.Org.Id,
  1959. Status: 1,
  1960. Ctime: time.Now().Unix(),
  1961. Mtime: 0,
  1962. Module: 1,
  1963. RecordDate: recordDate.Unix(),
  1964. Sourse: 1,
  1965. PatientId: id,
  1966. }
  1967. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1968. if dialysisFinish.ID == 0 {
  1969. service.CreateDialysisFinish(finish)
  1970. }
  1971. //修改处方
  1972. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1973. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1974. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1975. if advicePrescription.ID > 0 {
  1976. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1977. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1978. redis := service.RedisClient()
  1979. defer redis.Close()
  1980. //清空key 值
  1981. redis.Set(key, "", time.Second)
  1982. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1983. redis.Set(keyOne, "", time.Second)
  1984. }
  1985. }
  1986. //获取key,清空redis
  1987. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1988. redis := service.RedisClient()
  1989. //清空key 值
  1990. redis.Set(key, "", time.Second)
  1991. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1992. //清空key 值
  1993. redis.Set(keyOne, "", time.Second)
  1994. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1995. redis.Set(keySix, "", time.Second)
  1996. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1997. redis.Set(keySeven, "", time.Second)
  1998. if err == nil {
  1999. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2000. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2001. //清空key 值
  2002. redis.Set(keyOne, "", time.Second)
  2003. defer redis.Close()
  2004. if updateErr != nil {
  2005. utils.ErrorLog("%v", updateErr)
  2006. }
  2007. c.ServeSuccessJSON(map[string]interface{}{
  2008. "prescription": prescription,
  2009. })
  2010. }
  2011. }
  2012. }
  2013. func (c *DialysisAPIController) Finish() {
  2014. id, _ := c.GetInt64("patient", 0)
  2015. recordDateStr := c.GetString("record_date")
  2016. nurseID, _ := c.GetInt64("nurse")
  2017. end_time := c.GetString("end_time")
  2018. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2019. internal_fistula := c.GetString("blood_access_internal_fistula")
  2020. catheter := c.GetString("catheter")
  2021. cruor := c.GetString("cruor")
  2022. mission := c.GetString("mission")
  2023. if id <= 0 || nurseID <= 0 {
  2024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2025. return
  2026. }
  2027. adminUserInfo := c.GetMobileAdminUserInfo()
  2028. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2029. if patient.ID == 0 {
  2030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2031. return
  2032. }
  2033. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2034. if getNurseErr != nil {
  2035. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2037. return
  2038. } else if nurse == nil {
  2039. c.ErrorLog("护士不存在")
  2040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2041. return
  2042. }
  2043. if len(recordDateStr) == 0 {
  2044. recordDateStr = time.Now().Format("2006-01-02")
  2045. }
  2046. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2047. if parseDateErr != nil {
  2048. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2050. return
  2051. }
  2052. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2053. if parseEndDateErr != nil {
  2054. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2056. return
  2057. }
  2058. // 查询信息规挡的设置天数
  2059. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2060. if infor.ID > 0 && infor.WeekDay > 0 {
  2061. var cha_time int64
  2062. timeNowStr := time.Now().Format("2006-01-02")
  2063. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2064. //今日的日期减去设置的日期
  2065. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2066. if cha_time >= recordDate.Unix() {
  2067. //查询审核是否允许
  2068. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2069. //申请状态不允许的情况 拒绝修改
  2070. if infor.ApplicationStatus != 1 {
  2071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2072. return
  2073. }
  2074. }
  2075. }
  2076. //now := time.Now()
  2077. //year, month, day := now.Date()
  2078. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2079. //todayTimeStamp := today_time.Unix()
  2080. // 获取当天的第一条透析纪录
  2081. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2082. if getMonitorRecordsErr != nil {
  2083. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2085. return
  2086. }
  2087. // 获取当前的最后一条透析纪录
  2088. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2089. if getMonitorRecordsErr != nil {
  2090. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2092. return
  2093. }
  2094. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2095. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2096. if getAADErr != nil {
  2097. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2099. return
  2100. }
  2101. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2102. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2103. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2104. if assessmentAfterDislysis != nil {
  2105. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2106. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2107. } else {
  2108. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2109. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2110. tempassessmentAfterDislysis.Status = 1
  2111. tempassessmentAfterDislysis.PatientId = id
  2112. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2113. }
  2114. //长沙南雅
  2115. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2116. //获取最后一条透析处方数据
  2117. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2118. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2119. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2120. }
  2121. if dialysisOrder.Stage == 1 {
  2122. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2123. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2124. fmt.Println(value)
  2125. a, b := math.Modf(value)
  2126. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2127. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2128. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2129. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2130. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2131. }
  2132. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2133. //var num1 int64
  2134. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2135. //fmt.Println(num1)
  2136. //sub := float64(num1 / 3600)
  2137. //fmt.Println(sub)
  2138. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2139. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2140. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2141. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2142. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2143. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2144. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2145. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2146. if adminUserInfo.Org.Id != 10445 {
  2147. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2148. }
  2149. //北方营口医院
  2150. if adminUserInfo.Org.Id == 10445 {
  2151. //获取最后一条透析处方数据
  2152. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2153. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2154. } else {
  2155. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2156. }
  2157. //新化博翔
  2158. if adminUserInfo.Org.Id == 10447 {
  2159. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2160. }
  2161. //阳春
  2162. if adminUserInfo.Org.Id == 10485 {
  2163. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2164. }
  2165. }
  2166. 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 {
  2167. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2168. if evaluation.SystolicBloodPressure == 0 {
  2169. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2170. pre := models.PredialysisEvaluation{
  2171. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2172. }
  2173. fmt.Println("prew", pre)
  2174. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2175. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2176. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2177. redis := service.RedisClient()
  2178. redis.Set(key, "", time.Second)
  2179. redis.Set(keyOne, "", time.Second)
  2180. defer redis.Close()
  2181. fmt.Println(getNurseErr)
  2182. }
  2183. if evaluation.DiastolicBloodPressure == 0 {
  2184. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2185. pres := models.PredialysisEvaluation{
  2186. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2187. }
  2188. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2189. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2190. redis := service.RedisClient()
  2191. redis.Set(key, "", time.Second)
  2192. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2193. redis.Set(keyOne, "", time.Second)
  2194. defer redis.Close()
  2195. fmt.Println(getNurseErr)
  2196. }
  2197. if evaluation.PulseFrequency == 0 {
  2198. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2199. press := models.PredialysisEvaluation{
  2200. PulseFrequency: evaluation.PulseFrequency,
  2201. }
  2202. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2203. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2204. redis := service.RedisClient()
  2205. redis.Set(key, "", time.Second)
  2206. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2207. redis.Set(keyOne, "", time.Second)
  2208. defer redis.Close()
  2209. fmt.Println(getNurseErr)
  2210. }
  2211. if evaluation.Temperature == 0 {
  2212. evaluation.Temperature = fmonitorRecords.Temperature
  2213. press := models.PredialysisEvaluation{
  2214. Temperature: evaluation.Temperature,
  2215. }
  2216. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2217. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2218. redis := service.RedisClient()
  2219. redis.Set(key, "", time.Second)
  2220. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2221. redis.Set(keyOne, "", time.Second)
  2222. defer redis.Close()
  2223. fmt.Println(getNurseErr)
  2224. }
  2225. }
  2226. if adminUserInfo.Org.Id == 9583 {
  2227. //获取透析处方的最后一条数据
  2228. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2229. if diaerr != nil {
  2230. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2232. return
  2233. }
  2234. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2235. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2236. }
  2237. }
  2238. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2239. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2240. }
  2241. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2242. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2243. }
  2244. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2245. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2246. }
  2247. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2248. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2249. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2250. }
  2251. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2252. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2253. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2254. }
  2255. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2256. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2257. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2258. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2259. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2260. }
  2261. if lastAssessmentAfterDislysis != nil {
  2262. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2263. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2264. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2265. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2266. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2267. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2268. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2269. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2270. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2271. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2272. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2273. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2274. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2275. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2276. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2277. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2278. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2279. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2280. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2281. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2282. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2283. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2284. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2285. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2286. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2287. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2288. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2289. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2290. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2291. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2292. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2293. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2294. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2295. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2296. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2297. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2298. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2299. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2300. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2301. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2302. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2303. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2304. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2305. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2306. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2307. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2308. if tempassessmentAfterDislysis.PatientId == 18695 {
  2309. tempassessmentAfterDislysis.ActualDisplacement = 0
  2310. }
  2311. }
  2312. finish := models.XtDialysisFinish{
  2313. IsFinish: 1,
  2314. UserOrgId: adminUserInfo.Org.Id,
  2315. Status: 1,
  2316. Ctime: time.Now().Unix(),
  2317. Mtime: 0,
  2318. Module: 9,
  2319. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2320. Sourse: 1,
  2321. PatientId: tempassessmentAfterDislysis.PatientId,
  2322. }
  2323. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2324. if dialysisFinish.ID == 0 {
  2325. service.CreateDialysisFinish(finish)
  2326. }
  2327. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2328. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2329. redis := service.RedisClient()
  2330. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2331. redis.Set(keyOne, "", time.Second)
  2332. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2333. redis.Set(keyTwo, "", time.Second)
  2334. defer redis.Close()
  2335. //清空key 值
  2336. redis.Set(key, "", time.Second)
  2337. if err != nil {
  2338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2339. return
  2340. }
  2341. if dialysisOrder == nil {
  2342. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2343. return
  2344. }
  2345. if dialysisOrder.Stage == 2 {
  2346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2347. return
  2348. }
  2349. if dialysisOrder.Stage == 1 {
  2350. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission)
  2351. finish := models.XtDialysisFinish{
  2352. IsFinish: 1,
  2353. UserOrgId: adminUserInfo.Org.Id,
  2354. Status: 1,
  2355. Ctime: time.Now().Unix(),
  2356. Mtime: 0,
  2357. Module: 8,
  2358. RecordDate: recordDate.Unix(),
  2359. Sourse: 1,
  2360. PatientId: id,
  2361. }
  2362. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2363. if dialysisFinish.ID == 0 {
  2364. service.CreateDialysisFinish(finish)
  2365. }
  2366. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2367. redis := service.RedisClient()
  2368. defer redis.Close()
  2369. //清空key 值
  2370. redis.Set(key, "", time.Second)
  2371. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2372. redis.Set(keyOne, "", time.Second)
  2373. //结束时候透析次数加1
  2374. service.UpdateSolutionByPatientId(id)
  2375. //下机完自动消毒,针对长沙南雅
  2376. if dialysisOrder.Stage == 1 {
  2377. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 {
  2378. //根据床位号获取设备型号
  2379. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2380. //查询使用消毒最后一条消毒记录
  2381. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2382. fmt.Println("err", err)
  2383. if err == gorm.ErrRecordNotFound {
  2384. //查找排班
  2385. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2386. //查询改设备是否有消毒计划
  2387. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2388. //根据床位号获取设备id
  2389. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2390. //查询病人信息
  2391. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2392. var con = ""
  2393. if patients.IsInfectious == 0 {
  2394. con = ""
  2395. }
  2396. if patients.IsInfectious == 1 {
  2397. con = "无"
  2398. }
  2399. if patients.IsInfectious == 2 {
  2400. con = "有"
  2401. }
  2402. if errcode == nil {
  2403. var end_time int64
  2404. end_time = endDate.Unix() + plan.DisinfecTime*60
  2405. //新增消毒
  2406. information := models.DeviceInformation{
  2407. Date: dialysisOrder.DialysisDate,
  2408. Zone: dialysisOrder.ZoneId,
  2409. Class: dialysisOrder.SchedualType,
  2410. BedNumber: dialysisOrder.BedID,
  2411. PatientId: dialysisOrder.PatientId,
  2412. DialysisMode: scheduleByPatient.ModeId,
  2413. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2414. Disinfection: 1,
  2415. DialysisConcentration: 1,
  2416. DisinfectionStatus: 1,
  2417. Move: 1,
  2418. UserOrgId: dialysisOrder.UserOrgId,
  2419. DisinfectType: plan.Way,
  2420. DisinfectantType: plan.MachineDisinfectant,
  2421. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2422. Disinfectant: plan.Disinfectant,
  2423. Ctime: time.Now().Unix(),
  2424. Status: 1,
  2425. SignName: nurseID,
  2426. EquimentId: addmacher.ID,
  2427. DisinfectionResidue: 2,
  2428. Bed: addmacher.BedNumber,
  2429. StartTime: dialysisOrder.StartTime,
  2430. EndTime: dialysisOrder.EndTime,
  2431. Contagion: con,
  2432. WeightLoss: 0,
  2433. Hyperfiltratio: 0,
  2434. DialysisHour: "",
  2435. MachineRun: 1,
  2436. DisinfecStartime: endDate.Unix(),
  2437. DisinfecEndtime: end_time,
  2438. }
  2439. err := service.CreateInformationTwo(&information)
  2440. fmt.Println("报错", err)
  2441. }
  2442. }
  2443. }
  2444. }
  2445. dialysisOrder.Stage = 2
  2446. dialysisOrder.FinishNurse = nurseID
  2447. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2448. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2449. dialysisOrder.EndTime = endDate.Unix()
  2450. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2451. // 长沙南雅需求
  2452. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2453. //获取最后1条监测的数据
  2454. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2455. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2456. var accumulatedBloodVolume float64
  2457. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2458. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2459. fmt.Println(err)
  2460. // 查询未执行的医嘱
  2461. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2462. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2463. for _, item := range doctorAdvice {
  2464. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2465. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2466. redis := service.RedisClient()
  2467. //清空key 值
  2468. redis.Set(key, "", time.Second)
  2469. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2470. redis.Set(keyTwo, "", time.Second)
  2471. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2472. redis.Set(keyThree, "", time.Second)
  2473. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2474. theTime := toTime.Format("2006-01-02")
  2475. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2476. redis.Set(keyFour, "", time.Second)
  2477. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2478. redis.Set(keyFive, "", time.Second)
  2479. defer redis.Close()
  2480. }
  2481. }
  2482. go func() {
  2483. ssoDomain := beego.AppConfig.String("call_domain")
  2484. api := ssoDomain + "/index/downpatient"
  2485. values := make(url.Values)
  2486. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2487. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2488. values.Set("patient_id", strconv.FormatInt(id, 10))
  2489. http.PostForm(api, values)
  2490. }()
  2491. if err == nil {
  2492. c.ServeSuccessJSON(map[string]interface{}{
  2493. "dialysisOrder": dialysisOrder,
  2494. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2495. })
  2496. } else {
  2497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2498. }
  2499. }
  2500. }
  2501. func (c *DialysisAPIController) GetAllZone() {
  2502. adminUserInfo := c.GetMobileAdminUserInfo()
  2503. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2504. if err == nil {
  2505. c.ServeSuccessJSON(map[string]interface{}{
  2506. "zone": zone,
  2507. })
  2508. }
  2509. }
  2510. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2511. adminUserInfo := c.GetMobileAdminUserInfo()
  2512. page, _ := c.GetInt64("page", 1)
  2513. limit, _ := c.GetInt64("limit", 10)
  2514. schedulType, _ := c.GetInt64("schedul_type", 0)
  2515. startTime, _ := c.GetInt64("schedul_time", 0)
  2516. partitionType, _ := c.GetInt64("partition_type", 0)
  2517. keywords := c.GetString("keywords")
  2518. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2519. if err == nil {
  2520. c.ServeSuccessJSON(map[string]interface{}{
  2521. "schedule": dialysisSchedule,
  2522. })
  2523. }
  2524. return
  2525. }
  2526. // /m/api/dialysis/start [post]
  2527. // @param patient_id:int
  2528. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2529. // @param nurse:int 上机护士
  2530. // @param bed:int 床位号
  2531. func (this *DialysisAPIController) StartDialysis() {
  2532. patientID, _ := this.GetInt64("patient_id")
  2533. recordDateStr := this.GetString("record_date")
  2534. nurseID, _ := this.GetInt64("start_nurse")
  2535. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2536. blood_drawing, _ := this.GetInt64("blood_drawing")
  2537. schedual_type, _ := this.GetInt64("schedual_type")
  2538. bedID, _ := this.GetInt64("bed")
  2539. start_time := this.GetString("start_time")
  2540. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2541. change_nurse, _ := this.GetInt64("change_nurse")
  2542. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2543. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2544. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2545. puncture_needle := this.GetString("puncture_needle")
  2546. puncture_way := this.GetString("puncture_way")
  2547. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2548. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2549. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2550. zone_id, _ := this.GetInt64("zone_id")
  2551. elecsign := this.GetString("url")
  2552. nuclein_date_str := this.GetString("nuclein_date_str")
  2553. schedule_remark := this.GetString("schedule_remark")
  2554. order_remark := this.GetString("order_remark")
  2555. catheter_operation := this.GetString("catheter_operation")
  2556. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2557. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2558. return
  2559. }
  2560. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2561. if parseStartDateErr != nil {
  2562. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2563. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2564. return
  2565. }
  2566. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2567. if parseErr != nil {
  2568. this.ErrorLog("时间解析失败:%v", parseErr)
  2569. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2570. return
  2571. }
  2572. adminUserInfo := this.GetMobileAdminUserInfo()
  2573. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2574. if getPatientErr != nil {
  2575. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2576. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2577. return
  2578. } else if patient == nil {
  2579. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2580. return
  2581. }
  2582. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2583. if getNurseErr != nil {
  2584. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2585. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2586. return
  2587. } else if nurse == nil {
  2588. this.ErrorLog("护士不存在")
  2589. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2590. return
  2591. }
  2592. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2593. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2594. if getDeviceNumberErr != nil {
  2595. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2597. return
  2598. } else if deviceNumber == nil {
  2599. this.ErrorLog("床位号不存在")
  2600. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2601. return
  2602. }
  2603. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2604. if getRecordErr != nil {
  2605. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2607. return
  2608. } else if dialysisRecord != nil {
  2609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2610. return
  2611. }
  2612. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2613. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2614. timeLayout := "2006-01-02 15:04:05"
  2615. loc, _ := time.LoadLocation("Local")
  2616. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2617. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2618. schedulestartTime := theStartTime.Unix()
  2619. scheduleendTime := theEndTime.Unix()
  2620. var theNucleinDate int64
  2621. timeLayoutOne := "2006-01-02"
  2622. if len(nuclein_date_str) > 0 {
  2623. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2624. if err != nil {
  2625. utils.ErrorLog(err.Error())
  2626. }
  2627. theNucleinDate = theTime.Unix()
  2628. }
  2629. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2630. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2631. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2632. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2633. //查询该床位是否有人用了
  2634. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2635. if err == gorm.ErrRecordNotFound { //空床位
  2636. // 修改了床位逻辑
  2637. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2638. if daySchedule.ID > 0 {
  2639. daySchedule.PartitionId = deviceNumber.ZoneID
  2640. daySchedule.BedId = bedID
  2641. daySchedule.ScheduleType = schedual_type
  2642. daySchedule.UpdatedTime = time.Now().Unix()
  2643. xtSchedule := models.Schedule{
  2644. PartitionId: deviceNumber.ZoneID,
  2645. BedId: bedID,
  2646. ScheduleType: schedual_type,
  2647. UpdatedTime: time.Now().Unix(),
  2648. }
  2649. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2650. if err != nil {
  2651. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2652. return
  2653. }
  2654. }
  2655. } else if err == nil {
  2656. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2657. if order.ID > 0 { //该机位被其他人占用了
  2658. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2659. return
  2660. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2661. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2662. if daySchedule.ID > 0 {
  2663. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2664. if err != nil {
  2665. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2666. return
  2667. }
  2668. }
  2669. }
  2670. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2672. return
  2673. }
  2674. //else if order.ID == 0 { //该床位没被占用
  2675. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2676. // if daySchedule.ID > 0 {
  2677. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2678. // //daySchedule.BedId = bedID
  2679. // //daySchedule.ScheduleType = schedual_type
  2680. // //daySchedule.UpdatedTime = time.Now().Unix()
  2681. // //err := service.UpdateSchedule(&daySchedule)
  2682. // xtSchedule := models.Schedule{
  2683. // PartitionId: deviceNumber.ZoneID,
  2684. // BedId: bedID,
  2685. // ScheduleType: schedual_type,
  2686. // UpdatedTime: time.Now().Unix(),
  2687. // }
  2688. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2689. // if err != nil {
  2690. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2691. // return
  2692. // }
  2693. // }
  2694. //}
  2695. //}
  2696. } else if err != nil {
  2697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2698. return
  2699. }
  2700. // 查询信息规挡的设置天数
  2701. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2702. if infor.ID > 0 && infor.WeekDay > 0 {
  2703. var cha_time int64
  2704. timeNowStr := time.Now().Format("2006-01-02")
  2705. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2706. //今日的日期减去设置的日期
  2707. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2708. if cha_time >= recordDate.Unix() {
  2709. //查询审核是否允许
  2710. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id)
  2711. //申请状态不允许的情况 拒绝修改
  2712. if infor.ApplicationStatus != 1 {
  2713. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2714. return
  2715. }
  2716. }
  2717. }
  2718. dialysisRecord = &models.DialysisOrder{
  2719. DialysisDate: recordDate.Unix(),
  2720. UserOrgId: adminUserInfo.Org.Id,
  2721. PatientId: patientID,
  2722. Stage: 1,
  2723. BedID: bedID,
  2724. StartNurse: nurseID,
  2725. Status: 1,
  2726. StartTime: startDate.Unix(),
  2727. CreatedTime: time.Now().Unix(),
  2728. UpdatedTime: time.Now().Unix(),
  2729. PunctureNurse: puncture_nurse,
  2730. Creator: adminUserInfo.AdminUser.Id,
  2731. Modifier: adminUserInfo.AdminUser.Id,
  2732. SchedualType: schedual_type,
  2733. WashpipeNurse: washpipe_nurse,
  2734. ChangeNurse: change_nurse,
  2735. DifficultPunctureNurse: difficult_puncture_nurse,
  2736. NewFistulaNurse: new_fistula_nurse,
  2737. ZoneId: zone_id,
  2738. QualityNurseId: quality_nurse_id,
  2739. PunctureNeedle: puncture_needle,
  2740. PunctureWay: puncture_way,
  2741. DialysisIrrigation: dialysis_irrigation,
  2742. DialysisDialyszers: dialysis_dialyszers,
  2743. BloodAccessId: blood_access_id,
  2744. Url: elecsign,
  2745. NucleinDate: theNucleinDate,
  2746. ScheduleRemark: schedule_remark,
  2747. OrderRemark: order_remark,
  2748. CatheterOperation: catheter_operation,
  2749. }
  2750. //查询该床位是否有人用了
  2751. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2752. if errorscode == gorm.ErrRecordNotFound {
  2753. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2754. finish := models.XtDialysisFinish{
  2755. IsFinish: 1,
  2756. UserOrgId: adminUserInfo.Org.Id,
  2757. Status: 1,
  2758. Ctime: time.Now().Unix(),
  2759. Mtime: 0,
  2760. Module: 6,
  2761. RecordDate: schedulestartTime,
  2762. Sourse: 1,
  2763. PatientId: patientID,
  2764. }
  2765. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2766. if dialysisFinish.ID == 0 {
  2767. service.CreateDialysisFinish(finish)
  2768. }
  2769. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2770. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2771. //统计该患者总次数
  2772. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2773. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2774. }
  2775. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2776. //统计该患者总次数
  2777. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2778. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2779. }
  2780. redis := service.RedisClient()
  2781. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2782. redis.Set(key, "", time.Second)
  2783. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2784. //清空key 值
  2785. redis.Set(keyOne, "", time.Second)
  2786. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2787. //清空key 值
  2788. redis.Set(keyTwo, "", time.Second)
  2789. if createErr != nil {
  2790. this.ErrorLog("上机失败:%v", createErr)
  2791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2792. return
  2793. }
  2794. }
  2795. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2796. var tempdispose string
  2797. // 只针对中能建
  2798. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2799. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2800. }
  2801. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2802. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2803. }
  2804. var ultrafiltration_rate float64
  2805. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2806. //后期预增脱水量
  2807. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2808. if prescription.ID > 0 {
  2809. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2810. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2811. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  2812. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2813. }
  2814. //针对医师汇
  2815. if adminUserInfo.Org.Id == 10121 {
  2816. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2817. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2818. }
  2819. //针对通道
  2820. if adminUserInfo.Org.Id == 10234 {
  2821. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2822. }
  2823. //针对监利大垸医院
  2824. if template.TemplateId == 41 {
  2825. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2826. }
  2827. //针对肇庆三鹤血液透析中心
  2828. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2829. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2830. }
  2831. if adminUserInfo.Org.Id == 10469 {
  2832. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2833. }
  2834. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2835. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2836. }
  2837. // 只针对方济医院
  2838. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2839. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2840. ultrafiltration_rate = value
  2841. }
  2842. //针对
  2843. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 {
  2844. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2845. ultrafiltration_rate = ultrafiltration_rate / 1000
  2846. }
  2847. }
  2848. }
  2849. record := models.MonitoringRecord{
  2850. UserOrgId: adminUserInfo.Org.Id,
  2851. PatientId: patientID,
  2852. DialysisOrderId: dialysisRecord.ID,
  2853. MonitoringDate: schedulestartTime,
  2854. OperateTime: startDate.Unix(),
  2855. // MonitoringTime: recordTime,
  2856. MonitoringNurse: nurseID,
  2857. Dispose: tempdispose,
  2858. UltrafiltrationRate: ultrafiltration_rate,
  2859. UltrafiltrationVolume: 0,
  2860. Status: 1,
  2861. CreatedTime: time.Now().Unix(),
  2862. UpdatedTime: time.Now().Unix(),
  2863. }
  2864. //只针对广慈医院
  2865. 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 {
  2866. // 查询病人是否有透前评估数据
  2867. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2868. //如果有数据就插入
  2869. if errcode == nil {
  2870. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2871. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2872. record.BreathingRate = befor.BreathingRate
  2873. record.PulseFrequency = befor.PulseFrequency
  2874. record.Temperature = befor.Temperature
  2875. }
  2876. }
  2877. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2878. if newdialysisRecord.ID > 0 {
  2879. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2880. record.Temperature = 36.5
  2881. record.ArterialPressure = -100
  2882. record.DialysateTemperature = 36.5
  2883. record.Conductivity = 14
  2884. record.BreathingRate = "20"
  2885. record.VenousPressure = 80
  2886. record.TransmembranePressure = 60
  2887. record.Dispose = catheter_operation
  2888. }
  2889. //针对新化博翔
  2890. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2891. record.BloodOxygenSaturation = "99"
  2892. record.Conductivity = 14
  2893. record.DialysateTemperature = 36.5
  2894. record.BreathingRate = "20"
  2895. }
  2896. //针对兰溪人民医院的需求
  2897. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2898. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2899. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2900. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2901. record.Temperature = befor.Temperature
  2902. record.PulseFrequency = befor.PulseFrequency
  2903. record.BreathingRate = befor.BreathingRate
  2904. }
  2905. //新化博翔
  2906. if adminUserInfo.Org.Id == 10447 {
  2907. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2908. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2909. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2910. record.BreathingRate = befor.BreathingRate
  2911. }
  2912. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  2913. record.PulseFrequency = 80
  2914. record.Temperature = 36.5
  2915. }
  2916. //诊断灵山圣康
  2917. if adminUserInfo.Org.Id == 10375 {
  2918. record.Conductivity = 13.8
  2919. record.DialysateTemperature = 37
  2920. record.DialysateFlow = 500
  2921. record.BloodFlowVolume = 200
  2922. record.BreathingRate = "18"
  2923. record.SodiumConcentration = 140
  2924. }
  2925. err := service.CreateMonitor(&record)
  2926. finish := models.XtDialysisFinish{
  2927. IsFinish: 1,
  2928. UserOrgId: adminUserInfo.Org.Id,
  2929. Status: 1,
  2930. Ctime: time.Now().Unix(),
  2931. Mtime: 0,
  2932. Module: 7,
  2933. RecordDate: schedulestartTime,
  2934. Sourse: 1,
  2935. PatientId: patientID,
  2936. }
  2937. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  2938. if dialysisFinish.ID == 0 {
  2939. service.CreateDialysisFinish(finish)
  2940. }
  2941. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  2942. redis := service.RedisClient()
  2943. //清空key 值
  2944. redis.Set(key, "", time.Second)
  2945. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  2946. redis.Set(keyOne, "", time.Second)
  2947. defer redis.Close()
  2948. if err != nil {
  2949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2950. return
  2951. }
  2952. }
  2953. go func() {
  2954. ssoDomain := beego.AppConfig.String("call_domain")
  2955. api := ssoDomain + "/index/uppatient"
  2956. values := make(url.Values)
  2957. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  2958. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2959. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  2960. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  2961. http.PostForm(api, values)
  2962. }()
  2963. this.ServeSuccessJSON(map[string]interface{}{
  2964. "dialysis_order": newdialysisRecord,
  2965. "monitor": record,
  2966. })
  2967. return
  2968. }
  2969. func (c *DialysisAPIController) PostSolution() {
  2970. id, _ := c.GetInt64("patient", 0)
  2971. recordDateStr := c.GetString("record_date")
  2972. if id <= 0 {
  2973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2974. return
  2975. }
  2976. adminUserInfo := c.GetMobileAdminUserInfo()
  2977. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2978. if patient.ID == 0 {
  2979. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2980. return
  2981. }
  2982. if len(recordDateStr) == 0 {
  2983. recordDateStr = time.Now().Format("2006-01-02")
  2984. }
  2985. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2986. if parseDateErr != nil {
  2987. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2989. return
  2990. }
  2991. mode_id, _ := c.GetInt64("mode_id", 0)
  2992. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  2993. dialyzer, _ := c.GetInt64("dialyzer", 0)
  2994. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  2995. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2996. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  2997. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  2998. replacement_way, _ := c.GetInt64("replacement_way", 0)
  2999. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3000. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3001. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3002. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3003. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3004. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3005. kalium, _ := c.GetFloat("kalium", 0)
  3006. sodium, _ := c.GetFloat("sodium", 0)
  3007. calcium, _ := c.GetFloat("calcium", 0)
  3008. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3009. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3010. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3011. glucose, _ := c.GetFloat("glucose", 0)
  3012. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3013. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3014. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3015. conductivity, _ := c.GetFloat("conductivity", 0)
  3016. remark := c.GetString("remark")
  3017. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3018. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3019. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3020. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3021. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3022. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3023. special_medicine_other := c.GetString("special_medicine_other")
  3024. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3025. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3026. blood_access, _ := c.GetInt64("blood_access", 0)
  3027. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3028. body_fluid_other := c.GetString("body_fluid_other")
  3029. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3030. niprocart, _ := c.GetInt64("niprocart", 0)
  3031. jms, _ := c.GetInt64("jms", 0)
  3032. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3033. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3034. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3035. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3036. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3037. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3038. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3039. injector, _ := c.GetInt64("injector", 0)
  3040. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3041. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3042. safe_package, _ := c.GetInt64("package", 0)
  3043. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3044. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3045. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3046. blood := c.GetString("blood")
  3047. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3048. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3049. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3050. displace_speed := c.GetString("displace_speed")
  3051. illness, _ := c.GetInt64("illness")
  3052. amylaceum := c.GetString("amylaceum")
  3053. single_time := c.GetString("single_time")
  3054. single_water := c.GetString("single_water")
  3055. replacement_flow := c.GetString("replacement_flow")
  3056. plasma_separator := c.GetString("plasma_separator")
  3057. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3058. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3059. oxygen_flow := c.GetString("oxygen_flow")
  3060. oxygen_time := c.GetString("oxygen_time")
  3061. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3062. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3063. puncture_needle := c.GetString("puncture_needle")
  3064. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3065. epo := c.GetString("epo")
  3066. epo_count, _ := c.GetFloat("epo_count", 0)
  3067. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3068. pre_impulse := c.GetString("pre_impulse")
  3069. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3070. admin_user_id, _ := c.GetInt64("admin_user_id")
  3071. is_water := c.GetString("is_water")
  3072. add_amount, _ := c.GetFloat("add_amount")
  3073. reduce_amount, _ := c.GetFloat("reduce_amount")
  3074. prescribing_number, _ := c.GetFloat("prescribing_number")
  3075. treatment_remark := c.GetString("treatment_remark")
  3076. prescription_sodium := c.GetString("prescription_sodium")
  3077. start_sodium := c.GetString("start_sodium")
  3078. sodium_curve := c.GetString("sodium_curve")
  3079. var is_war int64
  3080. if is_water == "是" {
  3081. is_war = 1
  3082. }
  3083. if is_water == "否" {
  3084. is_war = 2
  3085. }
  3086. if is_water == "请选择" {
  3087. is_war = 0
  3088. }
  3089. drhy_water := c.GetString("drhy_water")
  3090. dry_water_hour := c.GetString("dry_water_hour")
  3091. water_machine := c.GetString("water_machine")
  3092. dialysis_remark := c.GetString("dialysis_remark")
  3093. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3094. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3095. prescription_water, _ := c.GetFloat("prescription_water")
  3096. dialysis_strainer := c.GetString("dialysis_strainer")
  3097. chaptalization := c.GetString("chaptalization")
  3098. if mode_id > 0 {
  3099. var str string
  3100. //查找该机构用的是什么透析器
  3101. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3102. if filedConfig.ID > 0 {
  3103. str = dialyzerPerfusionApparatus
  3104. } else {
  3105. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3106. }
  3107. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3108. }
  3109. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3110. //
  3111. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3112. // if appRole.UserType == 3 {
  3113. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3114. // if getPermissionErr != nil {
  3115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3116. // return
  3117. // } else if headNursePermission == nil {
  3118. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3119. // return
  3120. // }
  3121. // }
  3122. //}
  3123. // 查询信息规挡的设置天数
  3124. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3125. if infor.ID > 0 && infor.WeekDay > 0 {
  3126. var cha_time int64
  3127. timeNowStr := time.Now().Format("2006-01-02")
  3128. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3129. //今日的日期减去设置的日期
  3130. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3131. if cha_time >= recordDate.Unix() {
  3132. //查询审核是否允许
  3133. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3134. //申请状态不允许的情况 拒绝修改
  3135. if infor.ApplicationStatus != 1 {
  3136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3137. return
  3138. }
  3139. }
  3140. }
  3141. prescription := models.DialysisPrescription{
  3142. UserOrgId: adminUserInfo.Org.Id,
  3143. PatientId: id,
  3144. RecordDate: recordDate.Unix(),
  3145. ModeId: mode_id,
  3146. DialysisDuration: dialysis_duration,
  3147. Dialyzer: dialyzer,
  3148. PerfusionApparatus: perfusion_apparatus,
  3149. BloodFlowVolume: blood_flow_volume,
  3150. DewaterAmount: dewater_amount,
  3151. DisplaceLiqui: displace_liqui,
  3152. ReplacementWay: replacement_way,
  3153. Anticoagulant: anticoagulant,
  3154. AnticoagulantShouji: anticoagulant_shouji,
  3155. AnticoagulantWeichi: anticoagulant_weichi,
  3156. AnticoagulantZongliang: anticoagulant_zongliang,
  3157. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3158. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3159. Kalium: kalium,
  3160. Sodium: sodium,
  3161. Calcium: calcium,
  3162. Bicarbonate: bicarbonate,
  3163. Glucose: glucose,
  3164. // DryWeight: dry_weight,
  3165. DialysateFlow: dialysate_flow,
  3166. DialysateTemperature: dialysate_temperature,
  3167. Conductivity: conductivity,
  3168. Remark: remark,
  3169. Status: 1,
  3170. CreatedTime: time.Now().Unix(),
  3171. UpdatedTime: time.Now().Unix(),
  3172. DialysisDurationMinute: dialysisDurationMinute,
  3173. DialysisDurationHour: dialysisDurationHour,
  3174. TargetUltrafiltration: targetUltrafiltration,
  3175. DialysateFormulation: dialysateFormulation,
  3176. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3177. BodyFluid: body_fluid,
  3178. SpecialMedicine: special_medicine,
  3179. SpecialMedicineOther: special_medicine_other,
  3180. DisplaceLiquiPart: displace_liqui_part,
  3181. DisplaceLiquiValue: displace_liqui_value,
  3182. BloodAccess: blood_access,
  3183. Ultrafiltration: ultrafiltration,
  3184. BodyFluidOther: body_fluid_other,
  3185. ReplacementTotal: replacement_total,
  3186. Niprocart: niprocart,
  3187. Jms: jms,
  3188. FistulaNeedleSet: fistula_needle_set,
  3189. FistulaNeedleSet16: fistula_needle_set_16,
  3190. Hemoperfusion: hemoperfusion,
  3191. DialyserSterilised: dialyser_sterilised,
  3192. Filtryzer: filtryzer,
  3193. TargetKtv: target_ktv,
  3194. Dialyzers: dialyzers,
  3195. Injector: injector,
  3196. Bloodlines: bloodlines,
  3197. TubingHemodialysis: tubing_hemodialysis,
  3198. Package: safe_package,
  3199. ALiquid: a_liquid,
  3200. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3201. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3202. Blood: blood,
  3203. DialysisDialyszers: dialysis_dialyszers,
  3204. DialysisIrrigation: dialysis_irrigation,
  3205. AntioxidantCommodityName: antioxidant_commodity_name,
  3206. DisplaceSpeed: displace_speed,
  3207. Illness: illness,
  3208. Amylaceum: amylaceum,
  3209. SingleWater: single_water,
  3210. SingleTime: single_time,
  3211. ReplacementFlow: replacement_flow,
  3212. PlasmaSeparator: plasma_separator,
  3213. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3214. OxygenUptake: oxygen_uptake,
  3215. OxygenTime: oxygen_time,
  3216. OxygenFlow: oxygen_flow,
  3217. HemodialysisPipelines: hemodialysis_pipelines,
  3218. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3219. PunctureNeedle: puncture_needle,
  3220. PunctureNeedleCount: puncture_needle_count,
  3221. Epo: epo,
  3222. EpoCount: epo_count,
  3223. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3224. PreImpulse: impulse,
  3225. AdminUserId: admin_user_id,
  3226. IsWater: is_war,
  3227. DrhyWater: drhy_water,
  3228. DryWaterHour: dry_water_hour,
  3229. WaterMachine: water_machine,
  3230. AddAmount: add_amount,
  3231. ReduceAmount: reduce_amount,
  3232. DialysisRemark: dialysis_remark,
  3233. PrescribingNumber: prescribing_number,
  3234. PrescriptionSodium: prescription_sodium,
  3235. StartSodium: start_sodium,
  3236. SodiumCurve: sodium_curve,
  3237. TreatmentRemark: treatment_remark,
  3238. DialysisFluidFlow: dialysis_fluid_flow,
  3239. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3240. PrescriptionWater: prescription_water,
  3241. DialysisStrainer: dialysis_strainer,
  3242. Chaptalization: chaptalization,
  3243. }
  3244. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3245. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3246. fmt.Println("appRole0000000000000", appRole.UserType)
  3247. //
  3248. if appRole.UserType == 2 || appRole.UserType == 1 {
  3249. prescription_doctor = adminUserInfo.AdminUser.Id
  3250. prescription.PrescriptionDoctor = prescription_doctor
  3251. }
  3252. if dialysisPrescription.ID == 0 { //新增
  3253. prescription.Creater = adminUserInfo.AdminUser.Id
  3254. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3255. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3256. }
  3257. } else { //修改
  3258. if dialysisPrescription.Creater == 0 {
  3259. prescription.Creater = adminUserInfo.AdminUser.Id
  3260. } else {
  3261. prescription.Creater = dialysisPrescription.Creater
  3262. if adminUserInfo.Org.Id == 9882 {
  3263. if appRole.UserType == 2 || appRole.UserType == 1 {
  3264. prescription.Creater = adminUserInfo.AdminUser.Id
  3265. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3266. }
  3267. }
  3268. }
  3269. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3270. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3271. }
  3272. //if/**/
  3273. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3274. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3275. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3276. // if getPermissionErr != nil {
  3277. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3278. // return
  3279. // } else if headNursePermission == nil {
  3280. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3281. // return
  3282. // }
  3283. //}
  3284. //prescription.Creater = dialysisPrescription.Creater
  3285. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3286. prescription.Modifier = adminUserInfo.AdminUser.Id
  3287. prescription.ID = dialysisPrescription.ID
  3288. }
  3289. solution := models.DialysisSolution{
  3290. RegistrarsId: adminUserInfo.AdminUser.Id,
  3291. UserOrgId: adminUserInfo.Org.Id,
  3292. Doctor: prescription_doctor,
  3293. PatientId: id,
  3294. ModeId: mode_id,
  3295. DialysisDuration: dialysis_duration,
  3296. PerfusionApparatus: perfusion_apparatus,
  3297. BloodFlowVolume: blood_flow_volume,
  3298. Dewater: dewater_amount,
  3299. DisplaceLiqui: displace_liqui,
  3300. ReplacementWay: replacement_way,
  3301. Anticoagulant: anticoagulant,
  3302. AnticoagulantShouji: anticoagulant_shouji,
  3303. AnticoagulantWeichi: anticoagulant_weichi,
  3304. AnticoagulantZongliang: anticoagulant_zongliang,
  3305. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3306. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3307. Kalium: kalium,
  3308. Sodium: sodium,
  3309. Calcium: calcium,
  3310. Bicarbonate: bicarbonate,
  3311. Glucose: glucose,
  3312. // DryWeight: dry_weight,
  3313. DialysateFlow: dialysate_flow,
  3314. DialysateTemperature: dialysate_temperature,
  3315. Conductivity: conductivity,
  3316. Remark: remark,
  3317. Status: 1,
  3318. CreatedTime: time.Now().Unix(),
  3319. UpdatedTime: time.Now().Unix(),
  3320. DialysisDurationMinute: dialysisDurationMinute,
  3321. DialysisDurationHour: dialysisDurationHour,
  3322. TargetUltrafiltration: targetUltrafiltration,
  3323. DialysateFormulation: dialysateFormulation,
  3324. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3325. BodyFluid: body_fluid,
  3326. SpecialMedicine: special_medicine,
  3327. SpecialMedicineOther: special_medicine_other,
  3328. DisplaceLiquiPart: displace_liqui_part,
  3329. DisplaceLiquiValue: displace_liqui_value,
  3330. BloodAccess: blood_access,
  3331. Ultrafiltration: ultrafiltration,
  3332. BodyFluidOther: body_fluid_other,
  3333. ReplacementTotal: replacement_total,
  3334. TargetKtv: target_ktv,
  3335. DialysisDialyszers: dialysis_dialyszers,
  3336. DialysisIrrigation: dialysis_irrigation,
  3337. HemodialysisPipelines: hemodialysis_pipelines,
  3338. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3339. PunctureNeedle: puncture_needle,
  3340. PunctureNeedleCount: puncture_needle_count,
  3341. Epo: epo,
  3342. EpoCount: epo_count,
  3343. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3344. PreImpulse: impulse,
  3345. SolutionStatus: 1,
  3346. DialysisRemark: dialysis_remark,
  3347. PrescribingNumber: prescribing_number,
  3348. PrescriptionSodium: prescription_sodium,
  3349. StartSodium: start_sodium,
  3350. SodiumCurve: sodium_curve,
  3351. TreatmentRemark: treatment_remark,
  3352. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3353. DialysisFluidFlow: dialysis_fluid_flow,
  3354. PrescriptionWater: prescription_water,
  3355. DialysisStrainer: dialysis_strainer,
  3356. Chaptalization: chaptalization,
  3357. }
  3358. //针对河间咸的
  3359. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3360. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3361. solution.DisplaceLiquiPart = 0
  3362. solution.DisplaceLiquiValue = 0
  3363. }
  3364. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3365. prescription.DisplaceLiquiPart = 0
  3366. prescription.DisplaceLiquiValue = 0
  3367. }
  3368. }
  3369. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3370. if solution.PrescribingNumber == 0 {
  3371. solution.PrescribingNumber = 1
  3372. }
  3373. if prescription.PrescribingNumber == 0 {
  3374. prescription.PrescribingNumber = 1
  3375. }
  3376. if solution.PrescribingNumber == 0 && id == 14682 {
  3377. solution.PrescribingNumber = 2
  3378. }
  3379. if solution.PrescribingNumber == 0 && id == 18560 {
  3380. solution.PrescribingNumber = 2
  3381. }
  3382. if prescription.PrescribingNumber == 0 && id == 14682 {
  3383. prescription.PrescribingNumber = 2
  3384. }
  3385. if prescription.PrescribingNumber == 0 && id == 18560 {
  3386. prescription.PrescribingNumber = 2
  3387. }
  3388. }
  3389. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3390. finish := models.XtDialysisFinish{
  3391. IsFinish: 1,
  3392. UserOrgId: adminUserInfo.Org.Id,
  3393. Status: 1,
  3394. Ctime: time.Now().Unix(),
  3395. Mtime: 0,
  3396. Module: 1,
  3397. RecordDate: recordDate.Unix(),
  3398. Sourse: 1,
  3399. PatientId: id,
  3400. }
  3401. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3402. if dialysisFinish.ID == 0 {
  3403. service.CreateDialysisFinish(finish)
  3404. }
  3405. //获取最新1条
  3406. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3407. //更新状态
  3408. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3409. //长沙南雅医院,自动生成抗凝剂的临时处方
  3410. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3411. if prescribing_number == 0 {
  3412. prescribing_number = 1
  3413. }
  3414. advice := models.DoctorAdvice{
  3415. UserOrgId: adminUserInfo.Org.Id,
  3416. PatientId: id,
  3417. GroupNo: 0,
  3418. AdviceType: 2,
  3419. RecordDate: recordDate.Unix(),
  3420. AdviceDate: recordDate.Unix(),
  3421. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3422. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3423. AdviceDesc: "",
  3424. ReminderDate: 0,
  3425. SingleDose: prescription.AnticoagulantZongliang,
  3426. SingleDoseUnit: "iu",
  3427. DrugSpec: 0,
  3428. DrugSpecUnit: "",
  3429. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3430. PrescribingNumberUnit: "支",
  3431. DeliveryWay: "静脉注射",
  3432. ExecutionFrequency: "上机前",
  3433. AdviceDoctor: 0,
  3434. Status: 1,
  3435. CreatedTime: time.Now().Unix(),
  3436. UpdatedTime: time.Now().Unix(),
  3437. IsPrescription: 1,
  3438. ExecutionState: 2,
  3439. StopState: 2,
  3440. IsSettle: 2,
  3441. }
  3442. // 查询排班信息
  3443. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3444. if schedulePatient.ID > 0 {
  3445. if schedulePatient.ScheduleType == 1 {
  3446. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3447. }
  3448. if schedulePatient.ScheduleType == 2 {
  3449. advice.StartTime = recordDate.Unix() + 10*60*60
  3450. }
  3451. }
  3452. // 抗凝剂名称
  3453. switch anticoagulant {
  3454. case 1:
  3455. advice.AdviceName = "无肝素"
  3456. break
  3457. case 2:
  3458. advice.AdviceName = "普通肝素"
  3459. break
  3460. case 3:
  3461. advice.AdviceName = "低分子肝素"
  3462. break
  3463. case 4:
  3464. advice.AdviceName = "阿加曲班"
  3465. break
  3466. case 5:
  3467. advice.AdviceName = "枸橼酸钠"
  3468. break
  3469. case 6:
  3470. advice.AdviceName = "低分子肝素钙"
  3471. break
  3472. case 7:
  3473. advice.AdviceName = "低分子肝素钠"
  3474. break
  3475. case 8:
  3476. advice.AdviceName = "依诺肝素"
  3477. break
  3478. case 9:
  3479. advice.AdviceName = "达肝素"
  3480. break
  3481. case 10:
  3482. advice.AdviceName = "体外抗凝"
  3483. break
  3484. case 11:
  3485. advice.AdviceName = "那曲肝素"
  3486. break
  3487. case 12:
  3488. advice.AdviceName = "无抗凝剂"
  3489. break
  3490. }
  3491. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3492. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3493. advice.AdviceDoctor = appRole.AdminUserId
  3494. }
  3495. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3496. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3497. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3498. advice.AdviceName = "低分子肝素钠注射液"
  3499. // 修改患者临时医嘱里的抗凝剂医嘱
  3500. advice.ID = advicePrescription.ID
  3501. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3502. } else {
  3503. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3504. advice.AdviceName = "低分子肝素钠注射液"
  3505. service.CreateDoctorAdvice(&advice)
  3506. }
  3507. }
  3508. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3509. redis := service.RedisClient()
  3510. defer redis.Close()
  3511. //清空key 值
  3512. redis.Set(key, "", time.Second)
  3513. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3514. redis.Set(keyOne, "", time.Second)
  3515. }
  3516. //获取key,清空redis
  3517. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3518. redis := service.RedisClient()
  3519. defer redis.Close()
  3520. //清空key 值
  3521. redis.Set(key, "", time.Second)
  3522. //清空长期医嘱的key
  3523. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3524. redis.Set(soulution_key, "", time.Second)
  3525. //查询最近透析准备表里是否存在 透析器 灌流器
  3526. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3527. redis.Set(keyOne, "", time.Second)
  3528. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3529. redis.Set(keyTwo, "", time.Second)
  3530. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3531. redis.Set(keyThree, "", time.Second)
  3532. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3533. redis.Set(keyFour, "", time.Second)
  3534. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3535. //
  3536. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3537. //
  3538. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3539. //if len(mation)>0{
  3540. // for _, item := range splitStr {
  3541. // for _,it := range mation{
  3542. // if(item == it.SpecificationName){
  3543. //
  3544. // //查询最近一次的透析器
  3545. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3546. //
  3547. // if errcode == gorm.ErrRecordNotFound{
  3548. // //插入数据
  3549. // prepare := models.DialysisBeforePrepare{
  3550. // UserOrgId: adminUserInfo.Org.Id,
  3551. // PatientId: id,
  3552. // RecordDate: recordDate.Unix(),
  3553. // GoodTypeId: it.GoodTypeId,
  3554. // GoodId: it.ID,
  3555. // Count: 1,
  3556. // Ctime: time.Now().Unix(),
  3557. // Creater: adminUserInfo.AdminUser.Id,
  3558. // Status:1,
  3559. //
  3560. // }
  3561. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3562. // fmt.Println("",errcode)
  3563. // }
  3564. // }
  3565. // }
  3566. //
  3567. // }
  3568. //
  3569. // for _, item := range splitIrrigation {
  3570. // for _,it := range mation{
  3571. // if(item == it.SpecificationName){
  3572. // //查询最近一次的透析器
  3573. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3574. // if errcode == gorm.ErrRecordNotFound{
  3575. // //插入数据
  3576. // prepare := models.DialysisBeforePrepare{
  3577. // UserOrgId: adminUserInfo.Org.Id,
  3578. // PatientId: id,
  3579. // RecordDate: recordDate.Unix(),
  3580. // GoodTypeId: it.GoodTypeId,
  3581. // GoodId: it.ID,
  3582. // Count: 1,
  3583. // Ctime: time.Now().Unix(),
  3584. // Creater: adminUserInfo.AdminUser.Id,
  3585. // Status:1,
  3586. //
  3587. // }
  3588. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3589. // fmt.Println(errcode)
  3590. // }
  3591. // }
  3592. // }
  3593. // }
  3594. //}
  3595. c.ServeSuccessJSON(map[string]interface{}{
  3596. "solution": &solution,
  3597. "prescription": &prescription,
  3598. })
  3599. }
  3600. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3601. patient, _ := c.GetInt64("patient", 0)
  3602. adminUserInfo := c.GetMobileAdminUserInfo()
  3603. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3604. c.ServeSuccessJSON(map[string]interface{}{
  3605. "receiveTreatmentAsses": receiveTreatmentAsses,
  3606. })
  3607. }
  3608. func (this *DialysisAPIController) PostSignInfo() {
  3609. patientID, _ := this.GetInt64("patient_id")
  3610. recordDateStr := this.GetString("date")
  3611. if patientID <= 0 {
  3612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3613. return
  3614. }
  3615. if len(recordDateStr) == 0 {
  3616. recordDateStr = time.Now().Format("2006-01-02")
  3617. }
  3618. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3619. if parseDateErr != nil {
  3620. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3621. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3622. return
  3623. }
  3624. adminInfo := this.GetMobileAdminUserInfo()
  3625. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3626. if err != nil {
  3627. this.ErrorLog("签名失败:%v", err)
  3628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3629. return
  3630. }
  3631. this.ServeSuccessJSON(map[string]interface{}{
  3632. "doctor_id": adminInfo.AdminUser.Id,
  3633. })
  3634. }
  3635. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3636. patientID, _ := this.GetInt64("patient_id")
  3637. adminInfo := this.GetMobileAdminUserInfo()
  3638. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3639. this.ServeSuccessJSON(map[string]interface{}{
  3640. "monitor": record,
  3641. })
  3642. }
  3643. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3644. thisTime := time.Now()
  3645. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3646. timeLayout := "2006-01-02 15:04:05"
  3647. loc, _ := time.LoadLocation("Local")
  3648. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3649. theAssessmentDateTime := theStartTime.Unix()
  3650. patientID, _ := this.GetInt64("patient_id")
  3651. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3652. adminInfo := this.GetMobileAdminUserInfo()
  3653. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3654. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3655. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3656. var ultrafiltration_rate float64
  3657. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3658. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3659. fmt.Println(evaluation)
  3660. fmt.Println("prescription.ID", prescription.ID)
  3661. if prescription.ID > 0 {
  3662. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3663. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3664. fmt.Println("hahhdahahah", template.TemplateId)
  3665. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375) && adminInfo.Org.Id != 9538 {
  3666. fmt.Println("hahhdahahah")
  3667. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3668. record.UltrafiltrationRate = ultrafiltration_rate
  3669. }
  3670. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3671. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3672. record.UltrafiltrationRate = ultrafiltration_rate
  3673. }
  3674. if template.TemplateId == 20 || template.TemplateId == 22 {
  3675. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3676. record.UltrafiltrationRate = ultrafiltration_rate
  3677. }
  3678. // 只针对方济医院
  3679. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3680. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3681. ultrafiltration_rate = value
  3682. record.UltrafiltrationRate = ultrafiltration_rate
  3683. }
  3684. if template.TemplateId == 41 || template.TemplateId == 47 {
  3685. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3686. record.UltrafiltrationRate = ultrafiltration_rate
  3687. }
  3688. if template.TemplateId == 43 {
  3689. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3690. record.UltrafiltrationRate = ultrafiltration_rate
  3691. }
  3692. if template.TemplateId == 46 || template.TemplateId == 54 {
  3693. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3694. record.UltrafiltrationRate = ultrafiltration_rate
  3695. }
  3696. 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 {
  3697. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3698. record.UltrafiltrationRate = ultrafiltration_rate
  3699. }
  3700. if adminInfo.Org.Id == 10469 {
  3701. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3702. record.UltrafiltrationRate = ultrafiltration_rate
  3703. }
  3704. if adminInfo.Org.Id == 10471 {
  3705. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3706. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3707. }
  3708. //if template.TemplateId == 47 {
  3709. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3710. // record.UltrafiltrationRate = ultrafiltration_rate
  3711. //}
  3712. }
  3713. }
  3714. // record.UltrafiltrationRate = ultrafiltration_rate
  3715. record.UltrafiltrationVolume = 0
  3716. 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
  3717. if ultrafiltration_rate > 0 {
  3718. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3719. record.UltrafiltrationVolume = value
  3720. }
  3721. }
  3722. 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 == 9538
  3723. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3724. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3725. record.UltrafiltrationVolume = ultrafiltration_volume
  3726. }
  3727. }
  3728. //长沙南雅
  3729. 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 {
  3730. if ultrafiltration_rate > 0 {
  3731. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3732. fmt.Println("ultrafiltration_volume", ultrafiltration_volume)
  3733. record.UltrafiltrationVolume = ultrafiltration_volume
  3734. }
  3735. }
  3736. if adminInfo.Org.Id == 10471 {
  3737. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3738. fmt.Println("ultrafiltration_volume", ultrafiltration_volume)
  3739. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3740. }
  3741. //长沙南雅累计血容量自动计算
  3742. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3743. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3744. //}
  3745. if template.TemplateId == 47 || template.TemplateId == 54 {
  3746. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3747. }
  3748. this.ServeSuccessJSON(map[string]interface{}{
  3749. "monitor": record,
  3750. })
  3751. }
  3752. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3753. record_id, _ := this.GetInt64("id")
  3754. nurseID, _ := this.GetInt64("start_nurse")
  3755. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3756. bedID, _ := this.GetInt64("bed")
  3757. start_time := this.GetString("start_time")
  3758. schedual_type, _ := this.GetInt64("schedual_type")
  3759. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3760. change_nurse, _ := this.GetInt64("change_nurse")
  3761. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3762. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3763. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3764. fmt.Println("quality_nurse_id", quality_nurse_id)
  3765. patient_id, _ := this.GetInt64("patient_id")
  3766. record_date, _ := this.GetInt64("record_date")
  3767. puncture_needle := this.GetString("puncture_needle")
  3768. puncture_way := this.GetString("puncture_way")
  3769. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3770. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3771. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3772. nuclein_date_str := this.GetString("nuclein_date_str")
  3773. order_remark := this.GetString("order_remark")
  3774. schedule_remark := this.GetString("schedule_remark")
  3775. catheter_operation := this.GetString("catheter_operation")
  3776. if record_id == 0 {
  3777. this.ErrorLog("id:%v", record_id)
  3778. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3779. return
  3780. }
  3781. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3782. if parseStartDateErr != nil {
  3783. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3785. return
  3786. }
  3787. adminUserInfo := this.GetMobileAdminUserInfo()
  3788. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3789. if getNurseErr != nil {
  3790. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3791. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3792. return
  3793. } else if nurse == nil {
  3794. this.ErrorLog("护士不存在")
  3795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3796. return
  3797. }
  3798. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3799. //if getNurseErr != nil {
  3800. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3801. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3802. // return
  3803. //} else if nurse == nil {
  3804. // this.ErrorLog("护士不存在")
  3805. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3806. // return
  3807. //}
  3808. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3809. if getDeviceNumberErr != nil {
  3810. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3812. return
  3813. } else if deviceNumber == nil {
  3814. this.ErrorLog("床位号不存在")
  3815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3816. return
  3817. }
  3818. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3819. //
  3820. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  3821. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3822. // if getPermissionErr != nil {
  3823. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3824. // return
  3825. // } else if headNursePermission == nil {
  3826. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3827. // return
  3828. // }
  3829. //}
  3830. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3831. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3832. timeLayout := "2006-01-02 15:04:05"
  3833. loc, _ := time.LoadLocation("Local")
  3834. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3835. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3836. schedulestartTime := theStartTime.Unix()
  3837. scheduleendTime := theEndTime.Unix()
  3838. var theNucleinDate int64
  3839. timeLayoutOne := "2006-01-02"
  3840. if len(nuclein_date_str) > 0 {
  3841. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3842. if err != nil {
  3843. utils.ErrorLog(err.Error())
  3844. }
  3845. theNucleinDate = theTime.Unix()
  3846. }
  3847. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3848. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3849. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3850. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  3851. if err == gorm.ErrRecordNotFound { //空床位
  3852. // 修改了床位逻辑
  3853. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3854. if daySchedule.ID > 0 {
  3855. //daySchedule.BedId = bedID
  3856. //daySchedule.PartitionId = deviceNumber.ZoneID
  3857. //daySchedule.ScheduleType = schedual_type
  3858. //daySchedule.UpdatedTime = time.Now().Unix()
  3859. //err := service.UpdateSchedule(&daySchedule)
  3860. xtSchedule := models.Schedule{
  3861. PartitionId: deviceNumber.ZoneID,
  3862. BedId: bedID,
  3863. ScheduleType: schedual_type,
  3864. UpdatedTime: time.Now().Unix(),
  3865. }
  3866. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3867. if err != nil {
  3868. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3869. return
  3870. }
  3871. }
  3872. } else if err == nil {
  3873. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3874. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  3875. if daySchedule.ID > 0 {
  3876. //daySchedule.BedId = bedID
  3877. //daySchedule.PartitionId = deviceNumber.ZoneID
  3878. //
  3879. //daySchedule.ScheduleType = schedual_type
  3880. //daySchedule.UpdatedTime = time.Now().Unix()
  3881. //err := service.UpdateSchedule(&daySchedule)
  3882. xtSchedule := models.Schedule{
  3883. PartitionId: deviceNumber.ZoneID,
  3884. BedId: bedID,
  3885. ScheduleType: schedual_type,
  3886. UpdatedTime: time.Now().Unix(),
  3887. }
  3888. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3889. if err != nil {
  3890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3891. return
  3892. }
  3893. }
  3894. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3895. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3896. return
  3897. }
  3898. } else if err != nil {
  3899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3900. return
  3901. }
  3902. }
  3903. dialysisRecord := &models.DialysisOrder{
  3904. ID: record_id,
  3905. UserOrgId: adminUserInfo.Org.Id,
  3906. BedID: bedID,
  3907. StartNurse: nurseID,
  3908. StartTime: startDate.Unix(),
  3909. PunctureNurse: puncture_nurse,
  3910. Creator: adminUserInfo.AdminUser.Id,
  3911. Modifier: adminUserInfo.AdminUser.Id,
  3912. WashpipeNurse: washpipe_nurse,
  3913. SchedualType: schedual_type,
  3914. ChangeNurse: change_nurse,
  3915. DifficultPunctureNurse: difficult_puncture_nurse,
  3916. NewFistulaNurse: new_fistula_nurse,
  3917. QualityNurseId: quality_nurse_id,
  3918. PunctureNeedle: puncture_needle,
  3919. PunctureWay: puncture_way,
  3920. DialysisDialyszers: dialysis_dialyszers,
  3921. DialysisIrrigation: dialysis_irrigation,
  3922. BloodAccessId: blood_access_id,
  3923. NucleinDate: theNucleinDate,
  3924. OrderRemark: order_remark,
  3925. ScheduleRemark: schedule_remark,
  3926. CatheterOperation: catheter_operation,
  3927. }
  3928. //修改床位号需要重新消毒
  3929. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  3930. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3931. //查询第一条监测
  3932. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  3933. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  3934. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  3935. redis := service.RedisClient()
  3936. //清空key 值
  3937. redis.Set(key, "", time.Second)
  3938. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  3939. redis.Set(keyOne, "", time.Second)
  3940. defer redis.Close()
  3941. }
  3942. // 查询信息规挡的设置天数
  3943. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3944. if infor.ID > 0 && infor.WeekDay > 0 {
  3945. var cha_time int64
  3946. timeNowStr := time.Now().Format("2006-01-02")
  3947. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3948. //今日的日期减去设置的日期
  3949. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3950. if cha_time >= record_date {
  3951. //查询审核是否允许
  3952. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id)
  3953. //申请状态不允许的情况 拒绝修改
  3954. if infor.ApplicationStatus != 1 {
  3955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3956. return
  3957. }
  3958. }
  3959. }
  3960. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  3961. order, _ := service.GetLastPatientOrder(record_id)
  3962. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  3963. redis := service.RedisClient()
  3964. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  3965. redis.Set(key, "", time.Second)
  3966. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  3967. //清空key 值
  3968. redis.Set(keyOne, "", time.Second)
  3969. scheduleDateStartOne := startDate.Format("2006-01-02")
  3970. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3971. redis.Set(keyTwo, "", time.Second)
  3972. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  3973. redis.Set(keyThree, "", time.Second)
  3974. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  3975. redis.Set(keyFour, "", time.Second)
  3976. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  3977. redis.Set(keyFive, "", time.Second)
  3978. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  3979. redis.Set(keySix, "", time.Second)
  3980. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  3981. redis.Set(keySeven, "", time.Second)
  3982. if updateErr != nil {
  3983. this.ErrorLog("修改上机失败:%v", updateErr)
  3984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3985. return
  3986. }
  3987. if updateErr == nil {
  3988. if tempDialysisRecord.Stage == 2 {
  3989. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  3990. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  3991. fmt.Println(value)
  3992. a, b := math.Modf(value)
  3993. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  3994. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  3995. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  3996. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  3997. redis := service.RedisClient()
  3998. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  3999. redis.Set(key, "", time.Second)
  4000. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4001. redis.Set(keyOne, "", time.Second)
  4002. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4003. //清空key 值
  4004. redis.Set(keySix, "", time.Second)
  4005. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4006. redis.Set(keySeven, "", time.Second)
  4007. redis.Close()
  4008. if updateAssessmentErr != nil {
  4009. utils.ErrorLog("%v", updateAssessmentErr)
  4010. }
  4011. }
  4012. }
  4013. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4014. this.ServeSuccessJSON(map[string]interface{}{
  4015. "dialysis_order": dialysisRecords,
  4016. })
  4017. }
  4018. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4019. record_id, _ := c.GetInt64("id")
  4020. nurseID, _ := c.GetInt64("nurse")
  4021. end_time := c.GetString("end_time")
  4022. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4023. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4024. catheter := c.GetString("catheter")
  4025. cruor := c.GetString("cruor")
  4026. mission := c.GetString("mission")
  4027. if record_id <= 0 || nurseID <= 0 {
  4028. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4029. return
  4030. }
  4031. adminUserInfo := c.GetMobileAdminUserInfo()
  4032. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4033. if getNurseErr != nil {
  4034. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4036. return
  4037. } else if nurse == nil {
  4038. c.ErrorLog("护士不存在")
  4039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4040. return
  4041. }
  4042. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4043. if parseEndDateErr != nil {
  4044. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4046. return
  4047. }
  4048. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4049. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4050. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4051. // if getPermissionErr != nil {
  4052. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4053. // return
  4054. // } else if headNursePermission == nil {
  4055. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4056. // return
  4057. // }
  4058. //}
  4059. // 查询信息规挡的设置天数
  4060. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4061. if infor.ID > 0 {
  4062. var cha_time int64
  4063. timeNowStr := time.Now().Format("2006-01-02")
  4064. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4065. //今日的日期减去设置的日期
  4066. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4067. if cha_time >= tempDialysisRecords.DialysisDate {
  4068. //查询审核是否允许
  4069. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id)
  4070. //申请状态不允许的情况 拒绝修改
  4071. if infor.ApplicationStatus != 1 {
  4072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4073. return
  4074. }
  4075. }
  4076. }
  4077. dialysisRecord := &models.DialysisOrder{
  4078. ID: record_id,
  4079. UserOrgId: adminUserInfo.Org.Id,
  4080. EndTime: endDate.Unix(),
  4081. FinishNurse: nurseID,
  4082. FinishModifier: adminUserInfo.AdminUser.Id,
  4083. PuncturePointHaematoma: puncture_point_haematoma,
  4084. BloodAccessInternalFistula: blood_access_internal_fistula,
  4085. Catheter: catheter,
  4086. Cruor: cruor,
  4087. Mission: mission,
  4088. }
  4089. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4090. redis := service.RedisClient()
  4091. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4092. //清空key 值
  4093. redis.Set(key, "", time.Second)
  4094. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4095. //清空key 值
  4096. redis.Set(keyOne, "", time.Second)
  4097. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4098. redis.Set(keySeven, "", time.Second)
  4099. redis.Close()
  4100. if updateErr != nil {
  4101. c.ErrorLog("修改下机失败:%v", updateErr)
  4102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4103. return
  4104. }
  4105. if updateErr == nil {
  4106. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4107. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4108. a, b := math.Modf(value)
  4109. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4110. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4111. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4112. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4113. redis := service.RedisClient()
  4114. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4115. redis.Set(keyTen, "", time.Second)
  4116. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4117. redis.Set(keyTwo, "", time.Second)
  4118. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4119. redis.Set(key, "", time.Second)
  4120. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4121. redis.Set(keyThree, "", time.Second)
  4122. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4123. redis.Set(keySeven, "", time.Second)
  4124. defer redis.Close()
  4125. if updateAssessmentErr != nil {
  4126. utils.ErrorLog("%v", updateAssessmentErr)
  4127. }
  4128. }
  4129. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4130. c.ServeSuccessJSON(map[string]interface{}{
  4131. "dialysis_order": dialysisRecords,
  4132. })
  4133. }
  4134. func (c *DialysisAPIController) GetLongAdvice() {
  4135. patient_id, _ := c.GetInt64("id")
  4136. adminUserInfo := c.GetMobileAdminUserInfo()
  4137. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4138. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4139. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4140. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4141. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4142. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4143. c.ServeSuccessJSON(map[string]interface{}{
  4144. "status": "1",
  4145. })
  4146. return
  4147. } else { //开启推送提醒
  4148. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4149. var advice_three []*models.DoctorAdvice
  4150. recordDateStr := time.Now().Format("2006-01-02")
  4151. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4152. nowtime := recordDate.Unix()
  4153. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4154. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4155. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4156. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4157. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4158. for _, advice := range advices {
  4159. if advice.FrequencyType == 3 {
  4160. t := time.Now()
  4161. week := int(t.Weekday())
  4162. fmt.Println(t.Weekday())
  4163. fmt.Println(week)
  4164. switch week {
  4165. case 1:
  4166. if strings.Index(advice.WeekDay, "周一") == -1 {
  4167. advice_three = append(advice_three, advice)
  4168. }
  4169. break
  4170. case 2:
  4171. if strings.Index(advice.WeekDay, "周二") == -1 {
  4172. advice_three = append(advice_three, advice)
  4173. }
  4174. break
  4175. case 3:
  4176. if strings.Index(advice.WeekDay, "周三") == -1 {
  4177. advice_three = append(advice_three, advice)
  4178. }
  4179. break
  4180. case 4:
  4181. if strings.Index(advice.WeekDay, "周四") == -1 {
  4182. advice_three = append(advice_three, advice)
  4183. }
  4184. break
  4185. case 5:
  4186. if strings.Index(advice.WeekDay, "周五") == -1 {
  4187. advice_three = append(advice_three, advice)
  4188. }
  4189. break
  4190. case 6:
  4191. if strings.Index(advice.WeekDay, "周六") == -1 {
  4192. advice_three = append(advice_three, advice)
  4193. }
  4194. break
  4195. case 0:
  4196. if strings.Index(advice.WeekDay, "周日") == -1 {
  4197. advice_three = append(advice_three, advice)
  4198. }
  4199. break
  4200. }
  4201. }
  4202. }
  4203. for _, advice := range advices_two {
  4204. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4205. now := p.Unix()
  4206. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4207. dayStr2 := "-" + dayStr
  4208. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4209. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4210. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4211. for _, ad := range advices {
  4212. advice_three = append(advice_three, ad)
  4213. }
  4214. }
  4215. if err == nil {
  4216. c.ServeSuccessJSON(map[string]interface{}{
  4217. "status": "2",
  4218. "advices": advices,
  4219. "advices_two": RemoveRepeatedElement(advice_three),
  4220. "is_open_remind": config.IsOpenRemind,
  4221. "his_config_open": hisConfig.IsOpen,
  4222. "is_advice_open": is_advice_open.IsAdviceOpen,
  4223. "prescription_open": prescription_open.IsOpen,
  4224. })
  4225. }
  4226. }
  4227. }
  4228. func (c *DialysisAPIController) GetLongAdviceOne() {
  4229. patient_id, _ := c.GetInt64("id")
  4230. startTime := c.GetString("schedule_date")
  4231. timeLayout := "2006-01-02"
  4232. loc, _ := time.LoadLocation("Local")
  4233. var theStartTime int64
  4234. if len(startTime) > 0 {
  4235. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4236. if err != nil {
  4237. utils.ErrorLog(err.Error())
  4238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4239. return
  4240. }
  4241. theStartTime = theTime.Unix()
  4242. }
  4243. adminUserInfo := c.GetMobileAdminUserInfo()
  4244. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4245. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4246. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4247. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4248. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4249. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4250. c.ServeSuccessJSON(map[string]interface{}{
  4251. "status": "1",
  4252. })
  4253. return
  4254. } else { //开启推送提醒
  4255. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4256. var advice_three []*models.DoctorAdvice
  4257. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4258. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4259. for _, advice := range advices {
  4260. if advice.FrequencyType == 3 {
  4261. t := time.Now()
  4262. week := int(t.Weekday())
  4263. fmt.Println(t.Weekday())
  4264. fmt.Println(week)
  4265. switch week {
  4266. case 1:
  4267. if strings.Index(advice.WeekDay, "周一") == -1 {
  4268. advice_three = append(advice_three, advice)
  4269. }
  4270. break
  4271. case 2:
  4272. if strings.Index(advice.WeekDay, "周二") == -1 {
  4273. advice_three = append(advice_three, advice)
  4274. }
  4275. break
  4276. case 3:
  4277. if strings.Index(advice.WeekDay, "周三") == -1 {
  4278. advice_three = append(advice_three, advice)
  4279. }
  4280. break
  4281. case 4:
  4282. if strings.Index(advice.WeekDay, "周四") == -1 {
  4283. advice_three = append(advice_three, advice)
  4284. }
  4285. break
  4286. case 5:
  4287. if strings.Index(advice.WeekDay, "周五") == -1 {
  4288. advice_three = append(advice_three, advice)
  4289. }
  4290. break
  4291. case 6:
  4292. if strings.Index(advice.WeekDay, "周六") == -1 {
  4293. advice_three = append(advice_three, advice)
  4294. }
  4295. break
  4296. case 0:
  4297. if strings.Index(advice.WeekDay, "周日") == -1 {
  4298. advice_three = append(advice_three, advice)
  4299. }
  4300. break
  4301. }
  4302. }
  4303. }
  4304. for _, advice := range advices_two {
  4305. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4306. now := p.Unix()
  4307. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4308. dayStr2 := "-" + dayStr
  4309. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4310. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4311. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4312. for _, ad := range advices {
  4313. advice_three = append(advice_three, ad)
  4314. }
  4315. }
  4316. if err == nil {
  4317. c.ServeSuccessJSON(map[string]interface{}{
  4318. "status": "2",
  4319. "advices": advices,
  4320. "advices_two": RemoveRepeatedElement(advice_three),
  4321. "is_open_remind": config.IsOpenRemind,
  4322. "his_config_open": hisConfig.IsOpen,
  4323. "is_advice_open": is_advice_open.IsAdviceOpen,
  4324. "prescription_open": prescription_open.IsOpen,
  4325. })
  4326. }
  4327. }
  4328. }
  4329. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4330. newArr = make([]*models.DoctorAdvice, 0)
  4331. for i := 0; i < len(arr); i++ {
  4332. repeat := false
  4333. for j := i + 1; j < len(arr); j++ {
  4334. if arr[i].ID == arr[j].ID {
  4335. repeat = true
  4336. break
  4337. }
  4338. }
  4339. if !repeat {
  4340. newArr = append(newArr, arr[i])
  4341. }
  4342. }
  4343. return
  4344. }
  4345. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4346. patient, _ := c.GetInt64("id", 0)
  4347. groupNo, _ := c.GetInt64("groupno", 0)
  4348. if patient <= 0 {
  4349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4350. return
  4351. }
  4352. adminUserInfo := c.GetMobileAdminUserInfo()
  4353. dataBody := make(map[string]interface{}, 0)
  4354. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4355. if err != nil {
  4356. utils.ErrorLog(err.Error())
  4357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4358. return
  4359. }
  4360. utils.ErrorLog("%v", dataBody)
  4361. timeLayout := "2006-01-02 15:04"
  4362. loc, _ := time.LoadLocation("Local")
  4363. timeLayout2 := "2006-01-02"
  4364. loc2, _ := time.LoadLocation("Local")
  4365. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4366. utils.ErrorLog("advice_type")
  4367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4368. return
  4369. }
  4370. adviceType := int64(2)
  4371. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4372. utils.ErrorLog("advice_date")
  4373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4374. return
  4375. }
  4376. adviceDate, _ := dataBody["advice_date"].(string)
  4377. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4378. AdviceDate := theTime.Unix()
  4379. RecordDate := theTime.Unix()
  4380. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4381. utils.ErrorLog("start_time")
  4382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4383. return
  4384. }
  4385. startTime, _ := dataBody["start_time"].(string)
  4386. if len(startTime) == 0 {
  4387. utils.ErrorLog("len(start_time) == 0")
  4388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4389. return
  4390. }
  4391. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4392. if err != nil {
  4393. utils.ErrorLog(err.Error())
  4394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4395. return
  4396. }
  4397. StartTime := theTime.Unix()
  4398. Remark := ""
  4399. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4400. remark, _ := dataBody["remark"].(string)
  4401. Remark = remark
  4402. }
  4403. var advices []*models.GroupAdvice
  4404. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4405. utils.ErrorLog("advices")
  4406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4407. return
  4408. }
  4409. adviceNames := dataBody["advices"].([]interface{})
  4410. for _, adviceNameMap := range adviceNames {
  4411. adviceNameM := adviceNameMap.(map[string]interface{})
  4412. var advice models.GroupAdvice
  4413. advice.Remark = Remark
  4414. advice.AdviceType = adviceType
  4415. advice.StartTime = StartTime
  4416. advice.AdviceDate = AdviceDate
  4417. advice.RecordDate = RecordDate
  4418. advice.Status = 1
  4419. advice.CreatedTime = time.Now().Unix()
  4420. advice.UpdatedTime = time.Now().Unix()
  4421. advice.StopState = 2
  4422. advice.ExecutionState = 2
  4423. advice.UserOrgId = adminUserInfo.Org.Id
  4424. advice.PatientId = patient
  4425. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4426. advice.IsSettle = 2
  4427. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4428. utils.ErrorLog("advice_name")
  4429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4430. return
  4431. }
  4432. adviceName, _ := adviceNameM["advice_name"].(string)
  4433. if len(adviceName) == 0 {
  4434. utils.ErrorLog("len(advice_name) == 0")
  4435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4436. return
  4437. }
  4438. advice.AdviceName = adviceName
  4439. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4440. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4441. advice.DrugSpec = drugSpec
  4442. }
  4443. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4444. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4445. advice.AdviceDesc = adviceDesc
  4446. }
  4447. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4448. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4449. advice.DrugSpecUnit = drugSpecUnit
  4450. }
  4451. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4452. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4453. // advice.SingleDose = singleDose
  4454. //}
  4455. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4456. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4457. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4458. }
  4459. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4460. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4461. advice.SingleDoseUnit = singleDoseUnit
  4462. }
  4463. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4464. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4465. // advice.PrescribingNumber = prescribingNumber
  4466. //}
  4467. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4468. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4469. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4470. }
  4471. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4472. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4473. advice.PrescribingNumberUnit = prescribingNumberUnit
  4474. }
  4475. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4476. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4477. advice.DeliveryWay = deliveryWay
  4478. }
  4479. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4480. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4481. advice.ExecutionFrequency = executionFrequency
  4482. }
  4483. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4484. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4485. advice.FrequencyType = frequency_type
  4486. }
  4487. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4488. day_count := int64(adviceNameM["day_count"].(float64))
  4489. advice.DayCount = day_count
  4490. }
  4491. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4492. week_day, _ := adviceNameM["week_day"].(string)
  4493. advice.WeekDay = week_day
  4494. }
  4495. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4496. way := int64(adviceNameM["way"].(float64))
  4497. advice.Way = way
  4498. }
  4499. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4500. drug_id := int64(adviceNameM["drug_id"].(float64))
  4501. advice.DrugId = drug_id
  4502. }
  4503. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4504. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4505. advice.DrugNameId = drug_name_id
  4506. }
  4507. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4508. template_id, _ := adviceNameM["template_id"].(string)
  4509. advice.TemplateId = template_id
  4510. }
  4511. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4512. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4513. advice.ExecutionFrequency = executionFrequency
  4514. }
  4515. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4516. children := adviceNameM["child"].([]interface{})
  4517. if len(children) > 0 {
  4518. for _, childrenMap := range children {
  4519. childMap := childrenMap.(map[string]interface{})
  4520. var child models.GroupAdvice
  4521. child.Remark = Remark
  4522. child.AdviceType = adviceType
  4523. child.StartTime = StartTime
  4524. child.AdviceDate = AdviceDate
  4525. child.RecordDate = RecordDate
  4526. child.Status = 1
  4527. child.CreatedTime = time.Now().Unix()
  4528. child.UpdatedTime = time.Now().Unix()
  4529. child.StopState = 2
  4530. child.ExecutionState = 2
  4531. child.UserOrgId = adminUserInfo.Org.Id
  4532. child.PatientId = patient
  4533. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4534. child.IsSettle = 1
  4535. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4536. utils.ErrorLog("child advice_name")
  4537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4538. return
  4539. }
  4540. childAdviceName, _ := childMap["advice_name"].(string)
  4541. if len(childAdviceName) == 0 {
  4542. utils.ErrorLog("len(child advice_name) == 0")
  4543. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4544. return
  4545. }
  4546. child.AdviceName = childAdviceName
  4547. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4548. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4549. child.AdviceDesc = childAdviceDesc
  4550. }
  4551. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4552. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4553. child.DrugSpec = childDrugSpec
  4554. }
  4555. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4556. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4557. child.DrugSpecUnit = childDrugSpecUnit
  4558. }
  4559. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4560. child.SingleDose = childMap["single_dose"].(float64)
  4561. }
  4562. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4563. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4564. child.SingleDoseUnit = childSingleDoseUnit
  4565. }
  4566. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4567. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4568. }
  4569. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4570. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4571. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4572. }
  4573. child.DeliveryWay = advice.DeliveryWay
  4574. child.ExecutionFrequency = advice.ExecutionFrequency
  4575. advice.Children = append(advice.Children, &child)
  4576. }
  4577. }
  4578. }
  4579. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4580. if temp_advice.ID == 0 {
  4581. advices = append(advices, &advice)
  4582. }
  4583. }
  4584. if len(advices) > 0 {
  4585. finish := models.XtDialysisFinish{
  4586. IsFinish: 1,
  4587. UserOrgId: adminUserInfo.Org.Id,
  4588. Status: 1,
  4589. Ctime: time.Now().Unix(),
  4590. Mtime: 0,
  4591. Module: 4,
  4592. RecordDate: AdviceDate,
  4593. Sourse: 1,
  4594. PatientId: patient,
  4595. }
  4596. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4597. if dialysisFinish.ID == 0 {
  4598. service.CreateDialysisFinish(finish)
  4599. }
  4600. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4601. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4602. redis := service.RedisClient()
  4603. //清空key 值
  4604. redis.Set(key, "", time.Second)
  4605. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4606. redis.Set(keyOne, "", time.Second)
  4607. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4608. defer redis.Close()
  4609. redis.Set(keyThree, "", time.Second)
  4610. if err != nil {
  4611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4612. return
  4613. }
  4614. c.ServeSuccessJSON(map[string]interface{}{
  4615. "msg": "ok",
  4616. "advices": list,
  4617. })
  4618. } else {
  4619. c.ServeSuccessJSON(map[string]interface{}{
  4620. "msg": "ok",
  4621. })
  4622. }
  4623. return
  4624. }
  4625. func (c *DialysisAPIController) UploadDryWeight() {
  4626. patient_id, _ := c.GetInt64("id")
  4627. dry_weight, _ := c.GetFloat("dry_weight")
  4628. doctor_id, _ := c.GetInt64("doctor_id")
  4629. remark := c.GetString("remark")
  4630. adminUserInfo := c.GetMobileAdminUserInfo()
  4631. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4632. if err == gorm.ErrRecordNotFound {
  4633. dryWeight := &models.SgjPatientDryweight{
  4634. PatientId: patient_id,
  4635. DryWeight: dry_weight,
  4636. Remakes: remark,
  4637. Ctime: time.Now().Unix(),
  4638. Mtime: time.Now().Unix(),
  4639. Creator: doctor_id,
  4640. Status: 1,
  4641. UserOrgId: adminUserInfo.Org.Id,
  4642. AdjustedValue: "/",
  4643. UserId: adminUserInfo.AdminUser.Id,
  4644. }
  4645. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4646. redis := service.RedisClient()
  4647. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4648. redis.Set(keyOne, "", time.Second)
  4649. loc, _ := time.LoadLocation("Local")
  4650. nowTime := time.Now()
  4651. nowDay := nowTime.Format("2006-01-02")
  4652. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4653. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4654. redis.Set(key, "", time.Second)
  4655. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4656. redis.Set(keyTwo, "", time.Second)
  4657. redis.Close()
  4658. if createErr == nil {
  4659. c.ServeSuccessJSON(map[string]interface{}{
  4660. "msg": "提交成功",
  4661. "weight": dryWeight,
  4662. })
  4663. }
  4664. } else {
  4665. dryWeight := &models.SgjPatientDryweight{
  4666. PatientId: patient_id,
  4667. DryWeight: dry_weight,
  4668. Remakes: remark,
  4669. Ctime: time.Now().Unix(),
  4670. Mtime: time.Now().Unix(),
  4671. Creator: doctor_id,
  4672. Status: 1,
  4673. UserOrgId: adminUserInfo.Org.Id,
  4674. AdjustedValue: "/",
  4675. UserId: adminUserInfo.AdminUser.Id,
  4676. }
  4677. var value float64
  4678. value = dry_weight - weightAdjust.DryWeight
  4679. if value < 0 {
  4680. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4681. } else if value == 0 {
  4682. dryWeight.AdjustedValue = "/"
  4683. } else if value > 0 {
  4684. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4685. }
  4686. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4687. redis := service.RedisClient()
  4688. loc, _ := time.LoadLocation("Local")
  4689. nowTime := time.Now()
  4690. nowDay := nowTime.Format("2006-01-02")
  4691. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4693. redis.Set(keyOne, "", time.Second)
  4694. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4695. redis.Set(key, "", time.Second)
  4696. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4697. redis.Set(keyTwo, "", time.Second)
  4698. redis.Close()
  4699. if createErr == nil {
  4700. c.ServeSuccessJSON(map[string]interface{}{
  4701. "msg": "提交成功",
  4702. "weight": dryWeight,
  4703. })
  4704. }
  4705. }
  4706. }
  4707. func (c *DialysisAPIController) GetSolution() {
  4708. patient_id, _ := c.GetInt64("patient_id")
  4709. mode_id, _ := c.GetInt64("mode_id")
  4710. adminUserInfo := c.GetMobileAdminUserInfo()
  4711. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4712. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4713. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4714. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4715. if err != nil {
  4716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4717. return
  4718. }
  4719. c.ServeSuccessJSON(map[string]interface{}{
  4720. "solution": solution,
  4721. "prescription": prescription,
  4722. "system_prescription": system_prescription,
  4723. "dialysisPrescription": dialysisPrescription,
  4724. })
  4725. }
  4726. func (c *DialysisAPIController) GetSchedule() {
  4727. schedual_type, _ := c.GetInt64("schedual_type")
  4728. adminUserInfo := c.GetMobileAdminUserInfo()
  4729. scheduleTime, _ := c.GetInt64("record_date")
  4730. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4731. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4732. c.ServeSuccessJSON(map[string]interface{}{
  4733. "number": deviceNumber,
  4734. "list": list,
  4735. })
  4736. }
  4737. func (c *DialysisAPIController) GetPatientId() {
  4738. id, _ := c.GetInt64("id")
  4739. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4740. patientId, _ := service.GetPatientId(id)
  4741. //获取该患者的所有传染病
  4742. list, _ := service.GetPatientInfectious(id)
  4743. c.ServeSuccessJSON(map[string]interface{}{
  4744. "patient": patientId,
  4745. "infectioulist": list,
  4746. })
  4747. }
  4748. func (this *DialysisAPIController) GetDialysisSchedule() {
  4749. schedualDate := this.GetString("date")
  4750. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4751. if parseDateErr != nil {
  4752. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4753. return
  4754. }
  4755. adminInfo := this.GetMobileAdminUserInfo()
  4756. orgID := adminInfo.Org.Id
  4757. redis := service.RedisClient()
  4758. defer redis.Close()
  4759. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  4760. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  4761. if len(scheduals) > 0 {
  4762. //缓存数据
  4763. scheduals_json, err := json.Marshal(scheduals)
  4764. if err == nil {
  4765. redis.Set(key, scheduals_json, time.Second*30)
  4766. }
  4767. }
  4768. this.ServeSuccessJSON(map[string]interface{}{
  4769. "scheduals": scheduals,
  4770. })
  4771. }
  4772. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  4773. change_type, _ := this.GetInt64("type", 0)
  4774. record_date := this.GetString("record_time")
  4775. patient_id, _ := this.GetInt64("patient_id", 0)
  4776. timeLayout := "2006-01-02"
  4777. loc, _ := time.LoadLocation("Local")
  4778. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4779. record_time := theAdviceRecordTime.Unix()
  4780. adminUserInfo := this.GetMobileAdminUserInfo()
  4781. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  4782. if err == nil {
  4783. if len(advices) == 0 {
  4784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4785. return
  4786. } else {
  4787. this.ServeSuccessJSON(map[string]interface{}{
  4788. "advices": advices,
  4789. "schedule": sch,
  4790. })
  4791. return
  4792. }
  4793. } else {
  4794. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4795. return
  4796. }
  4797. }
  4798. func (c *DialysisAPIController) CreateConsumables() {
  4799. record_date := c.GetString("record_time")
  4800. patient_id, _ := c.GetInt64("patient_id", 0)
  4801. active, _ := c.GetInt64("active")
  4802. adminUser := c.GetMobileAdminUserInfo()
  4803. timeLayout := "2006-01-02"
  4804. loc, _ := time.LoadLocation("Local")
  4805. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4806. record_time := theRecordTime.Unix()
  4807. // 查询信息规挡的设置天数
  4808. orgid := c.GetMobileAdminUserInfo().Org.Id
  4809. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  4810. if infor.ID > 0 {
  4811. var cha_time int64
  4812. timeNowStr := time.Now().Format("2006-01-02")
  4813. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4814. //今日的日期减去设置的日期
  4815. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4816. if cha_time >= record_time {
  4817. //查询审核是否允许
  4818. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid)
  4819. //申请状态不允许的情况 拒绝修改
  4820. if infor.ApplicationStatus != 1 {
  4821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4822. return
  4823. }
  4824. }
  4825. }
  4826. dataBody := make(map[string]interface{}, 0)
  4827. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4828. if err != nil {
  4829. utils.ErrorLog(err.Error())
  4830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4831. return
  4832. }
  4833. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4834. var beforePrepares []*models.DialysisBeforePrepareGoods
  4835. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  4836. var dialysisBefor []*models.DialysisBeforePrepare
  4837. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  4838. goods, _ := dataBody["goods"].([]interface{})
  4839. if len(goods) > 0 {
  4840. for _, item := range goods {
  4841. items := item.(map[string]interface{})
  4842. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  4843. utils.ErrorLog("good_id")
  4844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4845. return
  4846. }
  4847. good_id := int64(items["good_id"].(float64))
  4848. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  4849. utils.ErrorLog("good_type_id")
  4850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4851. return
  4852. }
  4853. good_type_id := int64(items["good_type_id"].(float64))
  4854. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  4855. utils.ErrorLog("count")
  4856. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4857. return
  4858. }
  4859. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  4860. commdity_code := items["commdity_code"].(string)
  4861. fmt.Println("commdity", commdity_code)
  4862. prepareGoods := &models.DialysisBeforePrepareGoods{
  4863. GoodTypeId: good_type_id,
  4864. GoodId: good_id,
  4865. Count: count,
  4866. StorehouseId: houseConfig.StorehouseOutInfo,
  4867. }
  4868. beforePrepares = append(beforePrepares, prepareGoods)
  4869. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  4870. GoodTypeId: good_type_id,
  4871. GoodId: good_id,
  4872. Count: count,
  4873. StorehouseId: houseConfig.StorehouseOutInfo,
  4874. }
  4875. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  4876. prepare := &models.DialysisBeforePrepare{
  4877. GoodTypeId: good_type_id,
  4878. GoodId: good_id,
  4879. Count: count,
  4880. PatientId: patient_id,
  4881. RecordDate: record_time,
  4882. UserOrgId: adminUser.Org.Id,
  4883. Status: 1,
  4884. Ctime: time.Now().Unix(),
  4885. Creater: adminUser.AdminUser.Id,
  4886. CommdityCode: commdity_code,
  4887. StorehouseId: houseConfig.StorehouseOutInfo,
  4888. }
  4889. dialysisBefor = append(dialysisBefor, prepare)
  4890. }
  4891. }
  4892. //查询是否有库存
  4893. for _, item := range dialysisBefor {
  4894. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  4895. if err == gorm.ErrRecordNotFound {
  4896. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4897. c.ServeSuccessJSON(map[string]interface{}{
  4898. "message": "1",
  4899. "good_name": goodObj.GoodName,
  4900. "specification_name": goodObj.SpecificationName,
  4901. })
  4902. return
  4903. }
  4904. if err != nil {
  4905. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  4906. c.ServeSuccessJSON(map[string]interface{}{
  4907. "message": "1",
  4908. "good_name": goodObj.GoodName,
  4909. "specification_name": goodObj.SpecificationName,
  4910. })
  4911. return
  4912. }
  4913. }
  4914. //新增
  4915. if active == 1 && len(goods) > 0 {
  4916. for _, item := range dialysisBefor {
  4917. dialyPrepareOne := models.DialysisBeforePrepare{
  4918. GoodTypeId: item.GoodTypeId,
  4919. GoodId: item.GoodId,
  4920. PatientId: item.PatientId,
  4921. RecordDate: item.RecordDate,
  4922. UserOrgId: item.UserOrgId,
  4923. Count: item.Count,
  4924. Ctime: time.Now().Unix(),
  4925. Creater: item.Creater,
  4926. CommdityCode: item.CommdityCode,
  4927. Status: 1,
  4928. StorehouseId: houseConfig.StorehouseOutInfo,
  4929. }
  4930. //先清除再插入
  4931. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4932. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  4933. //查询默认仓库
  4934. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  4935. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  4936. var total_count int64
  4937. for _, it := range stockList {
  4938. total_count += it.StockCount
  4939. }
  4940. //基础库插入数据
  4941. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  4942. //更新库存
  4943. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  4944. var flush_count int64
  4945. for _, it := range goodList {
  4946. flush_count += it.StockCount
  4947. }
  4948. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  4949. }
  4950. if err == nil {
  4951. c.ServeSuccessJSON(map[string]interface{}{
  4952. "msg": "保存成功",
  4953. "message": "2",
  4954. })
  4955. return
  4956. } else {
  4957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4958. return
  4959. }
  4960. }
  4961. if len(beforePrepares) > 0 && active == 2 {
  4962. for _, item := range beforePrepares {
  4963. //1.查看该患者该耗材型号最后一次出库数量
  4964. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  4965. //判断当前出库数量和最后一次出库数量的大小
  4966. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  4967. if item.Count <= goodInfo.Count {
  4968. //退库
  4969. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  4970. //查询今日出库数据
  4971. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  4972. for _, it := range list {
  4973. prepare := models.DialysisBeforePrepare{
  4974. UserOrgId: it.OrgId,
  4975. PatientId: patient_id,
  4976. RecordDate: it.RecordTime,
  4977. GoodId: it.GoodId,
  4978. GoodTypeId: it.GoodTypeId,
  4979. Count: it.Count,
  4980. Ctime: time.Now().Unix(),
  4981. Creater: adminUser.AdminUser.Id,
  4982. Status: 1,
  4983. StorehouseId: houseConfig.StorehouseOutInfo,
  4984. }
  4985. //删除准备表数据
  4986. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4987. service.CreateDialysisBeforePrepareOne(&prepare)
  4988. }
  4989. }
  4990. var last_total int64
  4991. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  4992. if item.Count >= goodInfo.Count {
  4993. //查询当前批次当前耗材最后一条出库数据
  4994. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  4995. //计算当前出库和最后一次出库数据相差数据
  4996. last_total = item.Count - lastOutInfo.Count
  4997. //查询该批次剩余库存
  4998. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  4999. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5000. if lastInfo.StockCount >= last_total {
  5001. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5002. //查询今日出库数据
  5003. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5004. for _, it := range list {
  5005. prepare := models.DialysisBeforePrepare{
  5006. UserOrgId: it.OrgId,
  5007. PatientId: patient_id,
  5008. RecordDate: it.RecordTime,
  5009. GoodId: it.GoodId,
  5010. GoodTypeId: it.GoodTypeId,
  5011. Count: it.Count,
  5012. Ctime: time.Now().Unix(),
  5013. Creater: adminUser.AdminUser.Id,
  5014. Status: 1,
  5015. StorehouseId: houseConfig.StorehouseOutInfo,
  5016. }
  5017. //删除准备表数据
  5018. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5019. service.CreateDialysisBeforePrepareOne(&prepare)
  5020. //查询默认仓库
  5021. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5022. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5023. var total_count int64
  5024. for _, it := range stockList {
  5025. total_count += it.StockCount
  5026. }
  5027. //基础库插入数据
  5028. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5029. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5030. var flush_count int64
  5031. for _, it := range goodList {
  5032. flush_count += it.StockCount
  5033. }
  5034. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5035. }
  5036. }
  5037. //如果库存不够,则出库到下一个批次
  5038. if lastInfo.StockCount < last_total {
  5039. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5040. //查询今日出库数据
  5041. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5042. for _, it := range list {
  5043. prepare := models.DialysisBeforePrepare{
  5044. UserOrgId: it.OrgId,
  5045. PatientId: patient_id,
  5046. RecordDate: it.RecordTime,
  5047. GoodId: it.GoodId,
  5048. GoodTypeId: it.GoodTypeId,
  5049. Count: it.Count,
  5050. Ctime: time.Now().Unix(),
  5051. Creater: adminUser.AdminUser.Id,
  5052. Status: 1,
  5053. StorehouseId: houseConfig.StorehouseOutInfo,
  5054. }
  5055. //删除准备表数据
  5056. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5057. service.CreateDialysisBeforePrepareOne(&prepare)
  5058. //查询默认仓库
  5059. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5060. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5061. var total_count int64
  5062. for _, it := range stockList {
  5063. total_count += it.StockCount
  5064. }
  5065. //基础库插入数据
  5066. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5067. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5068. var flush_count int64
  5069. for _, it := range goodList {
  5070. flush_count += it.StockCount
  5071. }
  5072. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5073. }
  5074. if err != nil {
  5075. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5076. c.ServeSuccessJSON(map[string]interface{}{
  5077. "message": "1",
  5078. "good_name": goodObj.GoodName,
  5079. "specification_name": goodObj.SpecificationName,
  5080. })
  5081. return
  5082. }
  5083. }
  5084. }
  5085. if err != nil {
  5086. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5087. c.ServeSuccessJSON(map[string]interface{}{
  5088. "message": "1",
  5089. "good_name": goodObj.GoodName,
  5090. "specification_name": goodObj.SpecificationName,
  5091. })
  5092. return
  5093. }
  5094. }
  5095. }
  5096. }
  5097. var errs error
  5098. if errs == nil {
  5099. c.ServeSuccessJSON(map[string]interface{}{
  5100. "msg": "提交成功",
  5101. "message": "2",
  5102. "good_name": "",
  5103. "specification_name": "",
  5104. })
  5105. return
  5106. } else {
  5107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5108. return
  5109. }
  5110. }
  5111. func (c *DialysisAPIController) CreateStockOutInfo() {
  5112. patient_id, _ := c.GetInt64("patient_id", 0)
  5113. record_date := c.GetString("record_time")
  5114. if patient_id <= 0 {
  5115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5116. return
  5117. }
  5118. adminInfo := c.GetMobileAdminUserInfo()
  5119. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5120. timeLayout := "2006-01-02"
  5121. loc, _ := time.LoadLocation("Local")
  5122. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5123. record_time := theRecordTime.Unix()
  5124. // 查询信息规挡的设置天数
  5125. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5126. if infor.ID > 0 && infor.WeekDay > 0 {
  5127. var cha_time int64
  5128. timeNowStr := time.Now().Format("2006-01-02")
  5129. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5130. //今日的日期减去设置的日期
  5131. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5132. if cha_time >= record_time {
  5133. //查询审核是否允许
  5134. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  5135. //申请状态不允许的情况 拒绝修改
  5136. if infor.ApplicationStatus != 1 {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5138. return
  5139. }
  5140. }
  5141. }
  5142. //创建步骤表
  5143. finish := models.XtDialysisFinish{
  5144. IsFinish: 1,
  5145. UserOrgId: adminInfo.Org.Id,
  5146. Status: 1,
  5147. Ctime: time.Now().Unix(),
  5148. Mtime: 0,
  5149. Module: 11,
  5150. RecordDate: record_time,
  5151. Sourse: 1,
  5152. PatientId: patient_id,
  5153. }
  5154. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5155. if dialysisFinish.ID == 0 {
  5156. service.CreateDialysisFinish(finish)
  5157. }
  5158. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5159. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5160. //去重
  5161. consumables = RemoveRepeatedGood(consumables)
  5162. if record.IsOpen == 1 {
  5163. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5164. //查询是否有库存
  5165. for _, item := range consumables {
  5166. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5167. if item.Count > warehouse.Count {
  5168. goodErrcode := models.XtGoodErrcode{
  5169. UserOrgId: item.UserOrgId,
  5170. Errcode: "自动出库库存不足",
  5171. GoodId: item.GoodId,
  5172. Status: 1,
  5173. Ctime: time.Now().Unix(),
  5174. Mtime: 0,
  5175. Count: 0,
  5176. StockCount: 0,
  5177. Creater: creator,
  5178. BatchNumberId: warehouse.ID,
  5179. WarehouseOutId: 0,
  5180. }
  5181. service.CreateGoodErrcode(goodErrcode)
  5182. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5183. c.ServeSuccessJSON(map[string]interface{}{
  5184. "message": "1",
  5185. "good_name": goodObj.GoodName,
  5186. "specification_name": goodObj.SpecificationName,
  5187. })
  5188. return
  5189. }
  5190. }
  5191. //查询是否有出库单
  5192. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5193. if err == gorm.ErrRecordNotFound {
  5194. //没有记录,则创建出库单
  5195. timeStr := time.Now().Format("2006-01-02")
  5196. timeArr := strings.Split(timeStr, "-")
  5197. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5198. total = total + 1
  5199. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5200. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5201. number = number + total
  5202. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5203. creater := adminInfo.AdminUser.Id
  5204. warehouseOut := models.WarehouseOut{
  5205. WarehouseOutOrderNumber: warehousing_out_order,
  5206. OperationTime: time.Now().Unix(),
  5207. OrgId: adminInfo.Org.Id,
  5208. Creater: creater,
  5209. Ctime: time.Now().Unix(),
  5210. Status: 1,
  5211. WarehouseOutTime: record_time,
  5212. Dealer: 0,
  5213. Manufacturer: 0,
  5214. Type: 1,
  5215. IsSys: 1,
  5216. StorehouseId: houseConfig.StorehouseOutInfo,
  5217. IsCheck: 1,
  5218. }
  5219. err := service.AddSigleWarehouseOut(&warehouseOut)
  5220. if err != nil {
  5221. goodErrcode := models.XtGoodErrcode{
  5222. UserOrgId: adminInfo.Org.Id,
  5223. Errcode: "创建出库单失败",
  5224. GoodId: 0,
  5225. Status: 1,
  5226. Ctime: time.Now().Unix(),
  5227. Mtime: 0,
  5228. Count: 0,
  5229. StockCount: 0,
  5230. Creater: creator,
  5231. BatchNumberId: 0,
  5232. WarehouseOutId: 0,
  5233. }
  5234. service.CreateGoodErrcode(goodErrcode)
  5235. utils.TraceLog("创建出库单失败 err = %v", err)
  5236. } else {
  5237. for _, item := range consumables {
  5238. //出库
  5239. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5240. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5241. if err == nil {
  5242. goodErrcode := models.XtGoodErrcode{
  5243. UserOrgId: adminInfo.Org.Id,
  5244. Errcode: "自动出库接口报错",
  5245. GoodId: 0,
  5246. Status: 1,
  5247. Ctime: time.Now().Unix(),
  5248. Mtime: 0,
  5249. Count: 0,
  5250. StockCount: 0,
  5251. Creater: creator,
  5252. BatchNumberId: 0,
  5253. WarehouseOutId: 0,
  5254. }
  5255. service.CreateGoodErrcode(goodErrcode)
  5256. utils.TraceLog("创建出库单失败 err = %v", err)
  5257. }
  5258. //查询
  5259. //出库数量相加
  5260. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5261. if errs != nil {
  5262. goodErrcode := models.XtGoodErrcode{
  5263. UserOrgId: item.UserOrgId,
  5264. Errcode: "创建剩余库存字段报错",
  5265. GoodId: item.GoodId,
  5266. Status: 1,
  5267. Ctime: time.Now().Unix(),
  5268. Mtime: 0,
  5269. Count: 0,
  5270. StockCount: 0,
  5271. Creater: creater,
  5272. BatchNumberId: 0,
  5273. WarehouseOutId: 0,
  5274. }
  5275. service.CreateGoodErrcode(goodErrcode)
  5276. }
  5277. }
  5278. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5279. if len(list) == 0 {
  5280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5281. return
  5282. }
  5283. for _, item := range list {
  5284. prepare := models.DialysisBeforePrepare{
  5285. UserOrgId: adminInfo.Org.Id,
  5286. PatientId: patient_id,
  5287. RecordDate: record_time,
  5288. GoodId: item.GoodId,
  5289. GoodTypeId: item.GoodTypeId,
  5290. Count: item.Count,
  5291. Creater: adminInfo.AdminUser.Id,
  5292. Status: 1,
  5293. Ctime: time.Now().Unix(),
  5294. StorehouseId: houseConfig.StorehouseOutInfo,
  5295. }
  5296. //清空准备表数据
  5297. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5298. if err != nil {
  5299. goodErrcode := models.XtGoodErrcode{
  5300. UserOrgId: item.OrgId,
  5301. Errcode: "自动出库清空准备表数据报错",
  5302. GoodId: item.GoodId,
  5303. Status: 1,
  5304. Ctime: time.Now().Unix(),
  5305. Mtime: 0,
  5306. Count: 0,
  5307. StockCount: 0,
  5308. Creater: creater,
  5309. BatchNumberId: 0,
  5310. WarehouseOutId: 0,
  5311. }
  5312. service.CreateGoodErrcode(goodErrcode)
  5313. }
  5314. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5315. if errs != nil {
  5316. goodErrcode := models.XtGoodErrcode{
  5317. UserOrgId: item.OrgId,
  5318. Errcode: "自动出库创建准备表数据报错",
  5319. GoodId: item.GoodId,
  5320. Status: 1,
  5321. Ctime: time.Now().Unix(),
  5322. Mtime: 0,
  5323. Count: 0,
  5324. StockCount: 0,
  5325. Creater: creater,
  5326. BatchNumberId: 0,
  5327. WarehouseOutId: 0,
  5328. }
  5329. service.CreateGoodErrcode(goodErrcode)
  5330. }
  5331. //查询默认仓库
  5332. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5333. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5334. var total_count int64
  5335. for _, it := range stockList {
  5336. total_count += it.StockCount
  5337. }
  5338. //基础库插入数据
  5339. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5340. if errcodes != nil {
  5341. goodErrcode := models.XtGoodErrcode{
  5342. UserOrgId: item.OrgId,
  5343. Errcode: "自动出库基础库插入数据",
  5344. GoodId: item.GoodId,
  5345. Status: 1,
  5346. Ctime: time.Now().Unix(),
  5347. Mtime: 0,
  5348. Count: 0,
  5349. StockCount: 0,
  5350. Creater: creater,
  5351. BatchNumberId: 0,
  5352. WarehouseOutId: 0,
  5353. }
  5354. service.CreateGoodErrcode(goodErrcode)
  5355. }
  5356. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5357. var flush_count int64
  5358. for _, it := range goodList {
  5359. flush_count += it.StockCount
  5360. }
  5361. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5362. if errsss != nil {
  5363. goodErrcode := models.XtGoodErrcode{
  5364. UserOrgId: item.OrgId,
  5365. Errcode: "自动出库剩余库存更新数据",
  5366. GoodId: item.GoodId,
  5367. Status: 1,
  5368. Ctime: time.Now().Unix(),
  5369. Mtime: 0,
  5370. Count: 0,
  5371. StockCount: 0,
  5372. Creater: creater,
  5373. BatchNumberId: 0,
  5374. WarehouseOutId: 0,
  5375. }
  5376. service.CreateGoodErrcode(goodErrcode)
  5377. }
  5378. }
  5379. }
  5380. //
  5381. } else if err == nil {
  5382. for _, item := range consumables {
  5383. //出库
  5384. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5385. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5386. if err != nil {
  5387. goodErrcode := models.XtGoodErrcode{
  5388. UserOrgId: adminInfo.Org.Id,
  5389. Errcode: "自动出库接口报错",
  5390. GoodId: 0,
  5391. Status: 1,
  5392. Ctime: time.Now().Unix(),
  5393. Mtime: 0,
  5394. Count: 0,
  5395. StockCount: 0,
  5396. Creater: creator,
  5397. BatchNumberId: 0,
  5398. WarehouseOutId: 0,
  5399. }
  5400. service.CreateGoodErrcode(goodErrcode)
  5401. }
  5402. //出库数量相加
  5403. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5404. if errss != nil {
  5405. goodErrcode := models.XtGoodErrcode{
  5406. UserOrgId: item.UserOrgId,
  5407. Errcode: "创建剩余库存字段报错",
  5408. GoodId: item.GoodId,
  5409. Status: 1,
  5410. Ctime: time.Now().Unix(),
  5411. Mtime: time.Now().Unix(),
  5412. Count: 0,
  5413. StockCount: 0,
  5414. Creater: item.Creater,
  5415. BatchNumberId: 0,
  5416. WarehouseOutId: 0,
  5417. }
  5418. service.CreateGoodErrcode(goodErrcode)
  5419. }
  5420. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5421. if len(list) == 0 {
  5422. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5423. return
  5424. }
  5425. for _, item := range list {
  5426. prepare := models.DialysisBeforePrepare{
  5427. UserOrgId: adminInfo.Org.Id,
  5428. PatientId: patient_id,
  5429. RecordDate: record_time,
  5430. GoodId: item.GoodId,
  5431. GoodTypeId: item.GoodTypeId,
  5432. Count: item.Count,
  5433. Creater: adminInfo.AdminUser.Id,
  5434. Status: 1,
  5435. Ctime: time.Now().Unix(),
  5436. StorehouseId: houseConfig.StorehouseOutInfo,
  5437. }
  5438. //清空准备表数据
  5439. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5440. if errs != nil {
  5441. goodErrcode := models.XtGoodErrcode{
  5442. UserOrgId: adminInfo.Org.Id,
  5443. Errcode: "自动出库清空准备表数据报错",
  5444. GoodId: 0,
  5445. Status: 1,
  5446. Ctime: time.Now().Unix(),
  5447. Mtime: 0,
  5448. Count: 0,
  5449. StockCount: 0,
  5450. Creater: creator,
  5451. BatchNumberId: 0,
  5452. WarehouseOutId: 0,
  5453. }
  5454. service.CreateGoodErrcode(goodErrcode)
  5455. }
  5456. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5457. if errcodes != nil {
  5458. goodErrcode := models.XtGoodErrcode{
  5459. UserOrgId: adminInfo.Org.Id,
  5460. Errcode: "自动出库创建准备表数据报错",
  5461. GoodId: 0,
  5462. Status: 1,
  5463. Ctime: time.Now().Unix(),
  5464. Mtime: 0,
  5465. Count: 0,
  5466. StockCount: 0,
  5467. Creater: creator,
  5468. BatchNumberId: 0,
  5469. WarehouseOutId: 0,
  5470. }
  5471. service.CreateGoodErrcode(goodErrcode)
  5472. }
  5473. //查询默认仓库
  5474. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5475. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5476. var total_count int64
  5477. for _, it := range stockList {
  5478. total_count += it.StockCount
  5479. }
  5480. //基础库插入数据
  5481. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5482. if errcodes != nil {
  5483. goodErrcode := models.XtGoodErrcode{
  5484. UserOrgId: adminInfo.Org.Id,
  5485. Errcode: "自动出库基础库插入数据报错",
  5486. GoodId: 0,
  5487. Status: 1,
  5488. Ctime: time.Now().Unix(),
  5489. Mtime: 0,
  5490. Count: 0,
  5491. StockCount: 0,
  5492. Creater: creator,
  5493. BatchNumberId: 0,
  5494. WarehouseOutId: 0,
  5495. }
  5496. service.CreateGoodErrcode(goodErrcode)
  5497. }
  5498. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5499. var flush_count int64
  5500. for _, it := range goodList {
  5501. flush_count += it.StockCount
  5502. }
  5503. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5504. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5505. if errss != nil {
  5506. goodErrcode := models.XtGoodErrcode{
  5507. UserOrgId: item.OrgId,
  5508. Errcode: "自动出库剩余库存更新数据",
  5509. GoodId: item.GoodId,
  5510. Status: 1,
  5511. Ctime: time.Now().Unix(),
  5512. Mtime: 0,
  5513. Count: 0,
  5514. StockCount: 0,
  5515. Creater: creater,
  5516. BatchNumberId: 0,
  5517. WarehouseOutId: 0,
  5518. }
  5519. service.CreateGoodErrcode(goodErrcode)
  5520. }
  5521. }
  5522. }
  5523. }
  5524. c.ServeSuccessJSON(map[string]interface{}{
  5525. "msg": "提交成功",
  5526. "message": "2",
  5527. "good_name": "",
  5528. "specification_name": "",
  5529. })
  5530. return
  5531. } else {
  5532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  5533. return
  5534. }
  5535. }
  5536. func (c *DialysisAPIController) EditConsumables() {
  5537. patient_id, _ := c.GetInt64("patient_id", 0)
  5538. record_date := c.GetString("record_time")
  5539. if patient_id <= 0 {
  5540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5541. return
  5542. }
  5543. adminInfo := c.GetMobileAdminUserInfo()
  5544. timeLayout := "2006-01-02"
  5545. loc, _ := time.LoadLocation("Local")
  5546. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5547. record_time := theRecordTime.Unix()
  5548. // 查询信息规挡的设置天数
  5549. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5550. if infor.ID > 0 && infor.WeekDay > 0 {
  5551. var cha_time int64
  5552. timeNowStr := time.Now().Format("2006-01-02")
  5553. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5554. //今日的日期减去设置的日期
  5555. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5556. if cha_time >= record_time {
  5557. //查询审核是否允许
  5558. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  5559. //申请状态不允许的情况 拒绝修改
  5560. if infor.ApplicationStatus != 1 {
  5561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5562. return
  5563. }
  5564. }
  5565. }
  5566. dataBody := make(map[string]interface{}, 0)
  5567. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5568. if err != nil {
  5569. utils.ErrorLog(err.Error())
  5570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5571. return
  5572. }
  5573. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5574. var beforePrepares []*models.DialysisBeforePrepareGoods
  5575. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5576. var cancelbefor []*models.DialysisBeforePrepareGoods
  5577. var outbefor []*models.DialysisBeforePrepareGoods
  5578. //判断是否开启自动出库
  5579. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5580. if record.IsOpen == 1 {
  5581. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5582. goods, _ := dataBody["goods"].([]interface{})
  5583. if len(goods) > 0 {
  5584. for _, item := range goods {
  5585. items := item.(map[string]interface{})
  5586. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5587. utils.ErrorLog("good_id")
  5588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5589. return
  5590. }
  5591. good_id := int64(items["good_id"].(float64))
  5592. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5593. utils.ErrorLog("good_type_id")
  5594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5595. return
  5596. }
  5597. good_type_id := int64(items["good_type_id"].(float64))
  5598. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5599. utils.ErrorLog("count")
  5600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5601. return
  5602. }
  5603. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5604. commdity_code := items["commdity_code"].(string)
  5605. fmt.Println(commdity_code)
  5606. prepareGoods := &models.DialysisBeforePrepareGoods{
  5607. GoodTypeId: good_type_id,
  5608. GoodId: good_id,
  5609. Count: count,
  5610. StorehouseId: houseConfig.StorehouseOutInfo,
  5611. }
  5612. beforePrepares = append(beforePrepares, prepareGoods)
  5613. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5614. GoodTypeId: good_type_id,
  5615. GoodId: good_id,
  5616. Count: count,
  5617. StorehouseId: houseConfig.StorehouseOutInfo,
  5618. }
  5619. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5620. }
  5621. for _, item := range beforePrepares {
  5622. //1.查看该患者该耗材型号最后一次出库数量
  5623. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5624. //判断当前出库数量和最后一次出库数量的大小
  5625. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  5626. if item.Count < goodInfo.Count {
  5627. cancelbefor = append(cancelbefor, item)
  5628. }
  5629. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5630. if item.Count > goodInfo.Count {
  5631. outbefor = append(outbefor, item)
  5632. }
  5633. //处理编辑耗材新增不了的问题
  5634. if goodInfo.Count == item.Count {
  5635. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  5636. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  5637. }
  5638. }
  5639. if len(cancelbefor) > 0 {
  5640. //退库
  5641. for _, item := range cancelbefor {
  5642. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5643. creater := adminInfo.AdminUser.Id
  5644. //查询该患者当天已经出库的耗材信息
  5645. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  5646. var delete_count int64 = 0
  5647. delete_count = warehouseOutInfos.Count - item.Count
  5648. //增加库存数量
  5649. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  5650. //减少实际出库库存数量
  5651. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  5652. // 删除出库完成后,要增加对应批次的库存数量
  5653. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  5654. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5655. //更新剩余库存
  5656. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  5657. var flush_count int64
  5658. for _, it := range goodListOne {
  5659. flush_count += it.StockCount
  5660. }
  5661. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5662. //查询剩余库存
  5663. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  5664. var sum_count int64
  5665. for _, item := range goodList {
  5666. sum_count += item.StockCount
  5667. }
  5668. // 在出库记录表里记录退库详情
  5669. warehouseOutInfo := &models.WarehouseOutInfo{
  5670. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5671. WarehouseOutId: warehouseOut.ID,
  5672. Status: 1,
  5673. Ctime: time.Now().Unix(),
  5674. OrgId: adminInfo.Org.Id,
  5675. Type: 1,
  5676. IsSys: 1,
  5677. SysRecordTime: record_time,
  5678. GoodTypeId: item.GoodTypeId,
  5679. GoodId: item.GoodId,
  5680. PatientId: patient_id,
  5681. ConsumableType: 2,
  5682. StorehouseId: houseConfig.StorehouseOutInfo,
  5683. IsCheck: 1,
  5684. OverCount: sum_count,
  5685. }
  5686. warehouseOutInfo.Count = item.Count
  5687. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  5688. warehouseOutInfo.Price = stockInInfo.Price
  5689. warehouseOutInfo.Dealer = stockInInfo.Dealer
  5690. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  5691. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  5692. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  5693. warehouseOutInfo.Number = warehouseOutInfos.Number
  5694. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  5695. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  5696. //查找当天是否存在出库记录
  5697. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  5698. if errcod == gorm.ErrRecordNotFound {
  5699. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  5700. //插入详情明细表
  5701. stockFlow := models.VmStockFlow{
  5702. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5703. WarehouseOutId: warehouseOut.ID,
  5704. GoodId: item.GoodId,
  5705. Number: warehouseOutInfos.Number,
  5706. ProductDate: stockInInfo.ProductDate,
  5707. ExpireDate: stockInInfo.ExpiryDate,
  5708. Count: item.Count,
  5709. Price: stockInInfo.Price,
  5710. Status: 1,
  5711. Ctime: time.Now().Unix(),
  5712. UserOrgId: adminInfo.Org.Id,
  5713. Manufacturer: stockInInfo.Manufacturer,
  5714. Dealer: stockInInfo.Dealer,
  5715. LicenseNumber: stockInInfo.LicenseNumber,
  5716. IsEdit: 2,
  5717. Creator: creater,
  5718. SystemTime: record_time,
  5719. ConsumableType: 3,
  5720. WarehousingDetailId: 0,
  5721. IsSys: 1,
  5722. UpdateCreator: creater,
  5723. PatientId: patient_id,
  5724. StorehouseId: houseConfig.StorehouseOutInfo,
  5725. }
  5726. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  5727. if errflow == gorm.ErrRecordNotFound {
  5728. //创建流水表
  5729. err := service.CreateStockFlowOne(stockFlow)
  5730. fmt.Println("err", err)
  5731. } else if errflow == nil {
  5732. //插入详情明细表
  5733. stockFlow := models.VmStockFlow{
  5734. ID: exsit.ID,
  5735. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  5736. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  5737. WarehouseOutId: warehouseOut.ID,
  5738. GoodId: item.GoodId,
  5739. Number: warehouseOutInfos.Number,
  5740. ProductDate: stockInInfo.ProductDate,
  5741. ExpireDate: stockInInfo.ExpiryDate,
  5742. Count: exsit.Count - delete_count,
  5743. Price: stockInInfo.Price,
  5744. Status: 1,
  5745. Ctime: time.Now().Unix(),
  5746. UserOrgId: adminInfo.Org.Id,
  5747. Manufacturer: stockInInfo.Manufacturer,
  5748. Dealer: stockInInfo.Dealer,
  5749. LicenseNumber: stockInInfo.LicenseNumber,
  5750. IsEdit: 2,
  5751. Creator: creater,
  5752. SystemTime: record_time,
  5753. ConsumableType: 3,
  5754. WarehousingDetailId: 0,
  5755. IsSys: 1,
  5756. UpdateCreator: creater,
  5757. PatientId: patient_id,
  5758. StorehouseId: houseConfig.StorehouseOutInfo,
  5759. }
  5760. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  5761. }
  5762. } else if errcod == nil {
  5763. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  5764. //查询剩余库存
  5765. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  5766. var sum_count int64
  5767. for _, item := range goodList {
  5768. sum_count += item.StockCount
  5769. }
  5770. //创建退库单,生成退库数据
  5771. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5772. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  5773. operation_time := time.Now().Unix()
  5774. creater := adminInfo.AdminUser.Id
  5775. //创建退库单
  5776. timeStr := time.Now().Format("2006-01-02")
  5777. timeArr := strings.Split(timeStr, "-")
  5778. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  5779. total = total + 1
  5780. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5781. cancelStock := models.CancelStock{
  5782. OrderNumber: orderNumber,
  5783. OperaTime: operation_time,
  5784. OrgId: adminInfo.Org.Id,
  5785. Creater: creater,
  5786. Ctime: time.Now().Unix(),
  5787. Status: 1,
  5788. ReturnTime: record_time,
  5789. Type: 1,
  5790. StorehouseId: houseConfig.StorehouseOutInfo,
  5791. IsCheck: 1,
  5792. }
  5793. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  5794. if msgerrkonde == gorm.ErrRecordNotFound {
  5795. service.AddSigleCancelStock(&cancelStock)
  5796. }
  5797. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  5798. //查询是否有出库
  5799. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  5800. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5801. deaerler, _ := service.GetDealerById(info.Dealer)
  5802. if info.ID > 0 {
  5803. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  5804. cancelStockInfo := models.CancelStockInfo{
  5805. GoodId: item.GoodId,
  5806. CancelStockId: cancel.ID,
  5807. GoodTypeId: good.GoodTypeId,
  5808. Count: delete_count,
  5809. Price: info.Price,
  5810. Total: 0,
  5811. ProductDate: info.ProductDate,
  5812. ExpiryDate: info.ExpiryDate,
  5813. Ctime: time.Now().Unix(),
  5814. Status: 1,
  5815. OrgId: adminInfo.Org.Id,
  5816. OrderNumber: cancel.OrderNumber,
  5817. Type: 0,
  5818. Dealer: deaerler.DealerName,
  5819. Manufacturer: manufacturer.ManufacturerName,
  5820. Number: info.Number,
  5821. RegisterAccount: "",
  5822. Remark: "",
  5823. WarehouseInfoId: info.WarehouseInfotId,
  5824. PatientId: info.PatientId,
  5825. RecordDate: info.SysRecordTime,
  5826. StorehouseId: houseConfig.StorehouseOutInfo,
  5827. IsCheck: 1,
  5828. }
  5829. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5830. //退库数量增加
  5831. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  5832. //查询剩余库存
  5833. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  5834. var over_count int64
  5835. for _, it := range goodList {
  5836. over_count += it.StockCount
  5837. }
  5838. flow := models.VmStockFlow{
  5839. WarehousingId: info.WarehouseInfotId,
  5840. GoodId: item.GoodId,
  5841. Number: info.Number,
  5842. LicenseNumber: info.LicenseNumber,
  5843. Count: delete_count,
  5844. UserOrgId: adminInfo.Org.Id,
  5845. PatientId: patient_id,
  5846. SystemTime: info.SysRecordTime,
  5847. ConsumableType: 7,
  5848. IsSys: 0,
  5849. WarehousingOrder: "",
  5850. WarehouseOutId: info.WarehouseOutId,
  5851. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5852. IsEdit: 0,
  5853. CancelStockId: cancel.ID,
  5854. CancelOrderNumber: cancel.OrderNumber,
  5855. Manufacturer: manufacturer.ID,
  5856. Dealer: 0,
  5857. Creator: adminInfo.AdminUser.Id,
  5858. UpdateCreator: 0,
  5859. Status: 1,
  5860. Ctime: time.Now().Unix(),
  5861. Mtime: 0,
  5862. Price: info.Price,
  5863. WarehousingDetailId: info.WarehouseInfotId,
  5864. WarehouseOutDetailId: info.ID,
  5865. CancelOutDetailId: cancelInfo.ID,
  5866. ProductDate: info.ProductDate,
  5867. ExpireDate: info.ExpiryDate,
  5868. StorehouseId: houseConfig.StorehouseOutInfo,
  5869. OverCount: over_count,
  5870. }
  5871. service.CreateStockFlowOne(flow)
  5872. }
  5873. }
  5874. //更改自动出库的表格
  5875. details := models.BloodAutomaticReduceDetail{
  5876. WarehouseOutId: warehouseOutInfo.ID,
  5877. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  5878. PatientId: patient_id,
  5879. Ctime: time.Now().Unix(),
  5880. Mtime: time.Now().Unix(),
  5881. Status: 1,
  5882. RecordTime: record_time,
  5883. OrgId: adminInfo.Org.Id,
  5884. GoodId: item.GoodId,
  5885. GoodTypeId: item.GoodTypeId,
  5886. Count: item.Count,
  5887. StorehouseId: houseConfig.StorehouseOutInfo,
  5888. }
  5889. //查询当天耗材是否已经存在数据
  5890. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5891. if errcode == gorm.ErrRecordNotFound {
  5892. service.CreateAutoReduceRecord(&details)
  5893. } else if errcode == nil {
  5894. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5895. service.CreateAutoReduceRecord(&details)
  5896. }
  5897. //查询默认仓库
  5898. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5899. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5900. var total_count int64
  5901. for _, it := range stockList {
  5902. total_count += it.StockCount
  5903. }
  5904. //基础库插入数据
  5905. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5906. }
  5907. }
  5908. if len(outbefor) > 0 {
  5909. //出库
  5910. for _, item := range outbefor {
  5911. var last_total int64
  5912. //1.查看该患者该耗材型号最后一次出库数量
  5913. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5914. //计算当前出库和最后一次出库数据相差数据
  5915. last_total = item.Count - goodInfoOne.Count
  5916. //查询该耗材的总库存
  5917. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  5918. // 如果库存差大于剩余库存则提示库存不足
  5919. if last_total > wareinfo.StockCount {
  5920. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5921. c.ServeSuccessJSON(map[string]interface{}{
  5922. "message": "1",
  5923. "good_name": goodObj.GoodName,
  5924. "specification_name": goodObj.SpecificationName,
  5925. })
  5926. return
  5927. } else {
  5928. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5929. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5930. if err == gorm.ErrRecordNotFound {
  5931. //没有记录,则创建出库单
  5932. timeStr := time.Now().Format("2006-01-02")
  5933. timeArr := strings.Split(timeStr, "-")
  5934. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5935. total = total + 1
  5936. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5937. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5938. number = number + total
  5939. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5940. warehouseOut := models.WarehouseOut{
  5941. WarehouseOutOrderNumber: warehousing_out_order,
  5942. OperationTime: time.Now().Unix(),
  5943. OrgId: adminInfo.Org.Id,
  5944. Creater: adminInfo.AdminUser.Id,
  5945. Ctime: time.Now().Unix(),
  5946. Status: 1,
  5947. WarehouseOutTime: record_time,
  5948. Dealer: 0,
  5949. Manufacturer: 0,
  5950. Type: 1,
  5951. IsSys: 1,
  5952. StorehouseId: houseConfig.StorehouseOutInfo,
  5953. IsCheck: 1,
  5954. }
  5955. service.AddSigleWarehouseOut(&warehouseOut)
  5956. }
  5957. //出库
  5958. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  5959. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5960. //1.查看该患者该耗材型号最后一次出库数量
  5961. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5962. prepare := models.DialysisBeforePrepare{
  5963. UserOrgId: adminInfo.Org.Id,
  5964. PatientId: patient_id,
  5965. RecordDate: record_time,
  5966. GoodId: item.GoodId,
  5967. GoodTypeId: item.GoodTypeId,
  5968. Count: item.Count - goodInfoTwo.Count,
  5969. Ctime: time.Now().Unix(),
  5970. Mtime: 0,
  5971. Creater: adminInfo.AdminUser.Id,
  5972. Modifier: adminInfo.AdminUser.Id,
  5973. Status: 1,
  5974. CommdityCode: "",
  5975. NewCount: 0,
  5976. ProjectId: 0,
  5977. StorehouseId: houseConfig.StorehouseOutInfo,
  5978. }
  5979. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  5980. //增加出库数量
  5981. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  5982. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5983. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5984. var total_count int64
  5985. for _, it := range stockList {
  5986. total_count += it.StockCount
  5987. }
  5988. //基础库插入数据
  5989. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5990. //剩余库存
  5991. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5992. var flush_count int64
  5993. for _, it := range goodList {
  5994. flush_count += it.StockCount
  5995. }
  5996. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5997. }
  5998. }
  5999. }
  6000. //查询今日出库数据
  6001. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6002. for _, it := range list {
  6003. prepare := models.DialysisBeforePrepare{
  6004. UserOrgId: it.OrgId,
  6005. PatientId: patient_id,
  6006. RecordDate: it.RecordTime,
  6007. GoodId: it.GoodId,
  6008. GoodTypeId: it.GoodTypeId,
  6009. Count: it.Count,
  6010. Ctime: time.Now().Unix(),
  6011. Creater: adminInfo.AdminUser.Id,
  6012. Status: 1,
  6013. StorehouseId: houseConfig.StorehouseOutInfo,
  6014. ProjectId: it.ProjectId,
  6015. }
  6016. //删除准备表数据
  6017. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6018. service.CreateDialysisBeforePrepareOne(&prepare)
  6019. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6020. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6021. var total_count int64
  6022. for _, it := range stockList {
  6023. total_count += it.StockCount
  6024. }
  6025. //基础库插入数据
  6026. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6027. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6028. var flush_count int64
  6029. for _, it := range goodList {
  6030. flush_count += it.StockCount
  6031. }
  6032. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6033. }
  6034. }
  6035. }
  6036. //更新自动出库的地方
  6037. var errs error
  6038. if errs == nil {
  6039. c.ServeSuccessJSON(map[string]interface{}{
  6040. "msg": "修改成功",
  6041. "message": "2",
  6042. "good_name": "",
  6043. "specification_name": "",
  6044. })
  6045. return
  6046. } else {
  6047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6048. return
  6049. }
  6050. }
  6051. }
  6052. func (c *DialysisAPIController) GetDialysisGoods() {
  6053. schedualDate := c.GetString("schedule_date")
  6054. schedule_type, _ := c.GetInt64("schedule_type")
  6055. partition_id, _ := c.GetInt64("partition_id")
  6056. page, _ := c.GetInt("page")
  6057. patient_id, _ := c.GetInt64("patient_id")
  6058. schedualEndDate := int64(0)
  6059. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6060. if parseDateErr != nil && len(schedualDate) != 0 {
  6061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6062. return
  6063. }
  6064. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6065. if parseDateErr != nil && len(schedualDate) != 0 {
  6066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6067. return
  6068. }
  6069. schedualEndDate = endDate.Unix()
  6070. adminUser := c.GetMobileAdminUserInfo()
  6071. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6072. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6073. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6074. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6075. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6076. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6077. //获取当天该病人的透析处方
  6078. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6079. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6080. if err == gorm.ErrRecordNotFound {
  6081. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6082. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6083. if patient_id != 0 {
  6084. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6085. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6086. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6087. //获取患者总的出库数据
  6088. item.LastAutomaticReduceDetail = goodUser
  6089. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6090. item.Project = project
  6091. }
  6092. }
  6093. c.ServeSuccessJSON(map[string]interface{}{
  6094. "dialysis_goods": dialysisGoods,
  6095. "good_type": goodTypes,
  6096. "total": total,
  6097. "prescribe": prescribe,
  6098. "good_info": good_info,
  6099. "warehouseOutList": warehouseOutList,
  6100. "config": config,
  6101. "outConfig": outConfig,
  6102. "settleConfig": settleConfig,
  6103. })
  6104. return
  6105. } else if err == nil {
  6106. //获取当天排班的每个患者的库存使用情况
  6107. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6108. //获取患者总的出库数据
  6109. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6110. if patient_id != 0 {
  6111. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6112. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6113. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6114. item.Project = project
  6115. item.LastAutomaticReduceDetail = goodUser
  6116. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6117. }
  6118. }
  6119. if err == nil {
  6120. c.ServeSuccessJSON(map[string]interface{}{
  6121. "dialysis_goods": dialysisGoods,
  6122. "good_type": goodTypes,
  6123. "total": total,
  6124. "prescribe": prescribe,
  6125. "good_info": good_info,
  6126. "project": project,
  6127. "warehouseOutList": warehouseOutList,
  6128. "config": config,
  6129. "outConfig": outConfig,
  6130. "settleConfig": settleConfig,
  6131. })
  6132. return
  6133. } else {
  6134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6135. return
  6136. }
  6137. } else if err != nil {
  6138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6139. return
  6140. }
  6141. }
  6142. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6143. start_time := c.GetString("start_time")
  6144. end_time := c.GetString("end_time")
  6145. timeLayout := "2006-01-02"
  6146. loc, _ := time.LoadLocation("Local")
  6147. var theStartTime int64
  6148. if len(start_time) > 0 {
  6149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6150. if err != nil {
  6151. utils.ErrorLog(err.Error())
  6152. }
  6153. theStartTime = theTime.Unix()
  6154. }
  6155. var theEndtTime int64
  6156. if len(end_time) > 0 {
  6157. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6158. if err != nil {
  6159. utils.ErrorLog(err.Error())
  6160. }
  6161. theEndtTime = theTime.Unix()
  6162. }
  6163. adminUser := c.GetMobileAdminUserInfo()
  6164. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6165. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6166. if err == nil {
  6167. c.ServeSuccessJSON(map[string]interface{}{
  6168. "stock_out": outInfo,
  6169. "stockCount": stockCount,
  6170. })
  6171. return
  6172. } else {
  6173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6174. return
  6175. }
  6176. }
  6177. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6178. patient_id, _ := c.GetInt64("patient_id", 0)
  6179. record_time := c.GetString("record_time")
  6180. adminUser := c.GetMobileAdminUserInfo()
  6181. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6182. if parseDateErr != nil && len(record_time) != 0 {
  6183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6184. return
  6185. }
  6186. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6187. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6188. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6189. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6190. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6191. //获取今日患者的透析处方参数
  6192. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6193. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6194. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6195. c.ServeSuccessJSON(map[string]interface{}{
  6196. "good_type": goodTypes,
  6197. "good_user": goodUser,
  6198. "good_info": good_info,
  6199. "last_good_user": lastGoodUserDetial,
  6200. "project": project,
  6201. "prescription": prescribe,
  6202. "outInfo": outInfo,
  6203. "configs": configs,
  6204. })
  6205. return
  6206. }
  6207. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6208. patient_id, _ := c.GetInt64("patient_id", 0)
  6209. record_date := c.GetString("record_time")
  6210. timeLayout := "2006-01-02"
  6211. loc, _ := time.LoadLocation("Local")
  6212. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6213. record_time := theRecordTime.Unix()
  6214. adminInfo := c.GetMobileAdminUserInfo()
  6215. dataBody := make(map[string]interface{}, 0)
  6216. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6217. if err != nil {
  6218. utils.ErrorLog(err.Error())
  6219. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6220. return
  6221. }
  6222. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6223. var beforePrepares []*models.DialysisBeforePrepareGoods
  6224. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6225. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6226. goods, _ := dataBody["goods"].([]interface{})
  6227. if len(goods) > 0 {
  6228. for _, item := range goods {
  6229. items := item.(map[string]interface{})
  6230. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6231. utils.ErrorLog("good_id")
  6232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6233. return
  6234. }
  6235. good_id := int64(items["good_id"].(float64))
  6236. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6237. utils.ErrorLog("good_type_id")
  6238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6239. return
  6240. }
  6241. good_type_id := int64(items["good_type_id"].(float64))
  6242. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6243. utils.ErrorLog("count")
  6244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6245. return
  6246. }
  6247. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6248. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6249. utils.ErrorLog("project_id")
  6250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6251. return
  6252. }
  6253. project_id := int64(items["project_id"].(float64))
  6254. new_count := int64(items["new_count"].(float64))
  6255. old_count := int64(items["old_count"].(float64))
  6256. prepare := &models.DialysisBeforePrepareGoods{
  6257. GoodId: good_id,
  6258. GoodTypeId: good_type_id,
  6259. Count: count,
  6260. ProjectId: project_id,
  6261. StorehouseId: houseConfig.StorehouseOutInfo,
  6262. NewCount: new_count,
  6263. OldCount: old_count,
  6264. }
  6265. beforePrepares = append(beforePrepares, prepare)
  6266. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6267. GoodId: good_id,
  6268. GoodTypeId: good_type_id,
  6269. Count: count,
  6270. ProjectId: project_id,
  6271. StorehouseId: houseConfig.StorehouseOutInfo,
  6272. NewCount: new_count,
  6273. OldCount: old_count,
  6274. }
  6275. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6276. }
  6277. }
  6278. }
  6279. //查询是否有库存
  6280. for _, item := range beforePrepares {
  6281. if item.NewCount > 0 {
  6282. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6283. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6284. if item.Count > warehouse.Count {
  6285. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6286. c.ServeSuccessJSON(map[string]interface{}{
  6287. "message": "1",
  6288. "good_name": goodObj.GoodName,
  6289. "specification_name": goodObj.SpecificationName,
  6290. })
  6291. return
  6292. }
  6293. }
  6294. }
  6295. // 查询信息规挡的设置天数
  6296. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6297. if infor.ID > 0 && infor.WeekDay > 0 {
  6298. var cha_time int64
  6299. timeNowStr := time.Now().Format("2006-01-02")
  6300. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6301. //今日的日期减去设置的日期
  6302. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6303. if cha_time >= record_time {
  6304. //查询审核是否允许
  6305. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id)
  6306. //申请状态不允许的情况 拒绝修改
  6307. if infor.ApplicationStatus != 1 {
  6308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6309. return
  6310. }
  6311. }
  6312. }
  6313. //出库逻辑
  6314. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6315. if err != nil {
  6316. utils.ErrorLog(err.Error())
  6317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6318. return
  6319. }
  6320. finish := models.XtDialysisFinish{
  6321. IsFinish: 1,
  6322. UserOrgId: adminInfo.Org.Id,
  6323. Status: 1,
  6324. Ctime: time.Now().Unix(),
  6325. Mtime: 0,
  6326. Module: 11,
  6327. RecordDate: record_time,
  6328. Sourse: 1,
  6329. PatientId: patient_id,
  6330. }
  6331. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6332. if dialysisFinish.ID == 0 {
  6333. service.CreateDialysisFinish(finish)
  6334. }
  6335. //查询当天出库的数据
  6336. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6337. for _, item := range list {
  6338. prepare := models.DialysisBeforePrepare{
  6339. UserOrgId: item.OrgId,
  6340. PatientId: item.PatientId,
  6341. RecordDate: item.RecordTime,
  6342. GoodId: item.GoodId,
  6343. GoodTypeId: item.GoodTypeId,
  6344. Count: item.Count,
  6345. Creater: adminInfo.AdminUser.Id,
  6346. Status: 1,
  6347. Ctime: time.Now().Unix(),
  6348. ProjectId: item.ProjectId,
  6349. StorehouseId: houseConfig.StorehouseOutInfo,
  6350. }
  6351. //清空准备表的数据
  6352. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6353. //插入准备表数据
  6354. service.CreateDialysisBeforePrepareOne(&prepare)
  6355. //查询默认仓库
  6356. //查询默认仓库
  6357. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6358. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6359. var total_count int64
  6360. for _, it := range stockList {
  6361. total_count += it.StockCount
  6362. }
  6363. //基础库插入数据
  6364. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6365. ////更新剩余库存
  6366. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6367. var flush_count int64
  6368. for _, it := range goodList {
  6369. flush_count += it.StockCount
  6370. }
  6371. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6372. if errs != nil {
  6373. goodErrcode := models.XtGoodErrcode{
  6374. UserOrgId: item.OrgId,
  6375. Errcode: "手动出库更新剩余出库失败",
  6376. GoodId: item.GoodId,
  6377. Status: 1,
  6378. Ctime: time.Now().Unix(),
  6379. Mtime: 0,
  6380. Count: 0,
  6381. StockCount: 0,
  6382. Creater: adminInfo.AdminUser.Id,
  6383. BatchNumberId: 0,
  6384. WarehouseOutId: 0,
  6385. }
  6386. service.CreateGoodErrcode(goodErrcode)
  6387. }
  6388. }
  6389. //更新自动出库的地方
  6390. var errs error
  6391. if errs == nil {
  6392. c.ServeSuccessJSON(map[string]interface{}{
  6393. "msg": "修改成功",
  6394. "message": "2",
  6395. "good_name": "",
  6396. "specification_name": "",
  6397. })
  6398. return
  6399. } else {
  6400. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6401. return
  6402. }
  6403. }
  6404. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6405. newArr = make([]*models.DialysisBeforePrepare, 0)
  6406. for i := 0; i < len(arr); i++ {
  6407. repeat := false
  6408. for j := i + 1; j < len(arr); j++ {
  6409. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  6410. repeat = true
  6411. break
  6412. }
  6413. }
  6414. if !repeat {
  6415. newArr = append(newArr, arr[i])
  6416. }
  6417. }
  6418. return
  6419. }
  6420. func (c *DialysisAPIController) GetAllDrug() {
  6421. patient_id, _ := c.GetInt64("patient_id", 0)
  6422. adminInfo := c.GetMobileAdminUserInfo()
  6423. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6424. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  6425. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  6426. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  6427. c.ServeSuccessJSON(map[string]interface{}{
  6428. "base_drug_config": drugStockConfig,
  6429. "private_drug_config": privateDrugConfig,
  6430. "base_drug_list": drugList,
  6431. "private_drug_list": privateDrugList,
  6432. })
  6433. }
  6434. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  6435. newArr = make([]*models.DialysisBeforePrepare, 0)
  6436. for i := 0; i < len(arr); i++ {
  6437. repeat := false
  6438. for j := i + 1; j < len(arr); j++ {
  6439. if arr[i].GoodId == arr[j].GoodId {
  6440. repeat = true
  6441. break
  6442. }
  6443. }
  6444. if !repeat {
  6445. newArr = append(newArr, arr[i])
  6446. }
  6447. }
  6448. return
  6449. }
  6450. func (c *DialysisAPIController) GetDepartment() {
  6451. adminInfo := c.GetMobileAdminUserInfo()
  6452. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  6453. if err == nil {
  6454. c.ServeSuccessJSON(map[string]interface{}{
  6455. "departments": departments,
  6456. })
  6457. } else {
  6458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6459. return
  6460. }
  6461. }
  6462. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  6463. types, _ := c.GetInt("type", 0)
  6464. start_time := c.GetString("start_time")
  6465. end_time := c.GetString("end_time")
  6466. orgId := c.GetMobileAdminUserInfo().Org.Id
  6467. timeLayout := "2006-01-02"
  6468. loc, _ := time.LoadLocation("Local")
  6469. var startTime int64
  6470. if len(start_time) > 0 {
  6471. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6472. if err != nil {
  6473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6474. return
  6475. }
  6476. startTime = theTime.Unix()
  6477. }
  6478. var endTime int64
  6479. if len(end_time) > 0 {
  6480. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6481. if err != nil {
  6482. utils.ErrorLog(err.Error())
  6483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6484. return
  6485. }
  6486. endTime = theTime.Unix()
  6487. }
  6488. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  6489. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  6490. if err != nil {
  6491. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6492. } else {
  6493. c.ServeSuccessJSON(map[string]interface{}{
  6494. "list": list,
  6495. "type": types,
  6496. "stockTotal": stockTotal,
  6497. })
  6498. }
  6499. }
  6500. func (c *DialysisAPIController) BatchDeleteMonitor() {
  6501. ids := c.GetString("ids")
  6502. //patient_id, _ := c.GetInt64("patient_id")
  6503. //monitoring_date, _ := c.GetInt64("monitoring_date")
  6504. idArray := strings.Split(ids, ",")
  6505. err := service.BatchDeleteMonitor(idArray)
  6506. fmt.Print("err", err)
  6507. //orgid := c.GetMobileAdminUserInfo().Org.Id
  6508. //redis := service.RedisClient()
  6509. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  6510. //redis.Set(key, "", time.Second)
  6511. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  6512. //redis.Set(keyOne, "", time.Second)
  6513. //fmt.Println("keyo呢32332322332332232332",keyOne)
  6514. //redis.Close()
  6515. c.ServeSuccessJSON(map[string]interface{}{
  6516. "msg": "批量删除成功",
  6517. })
  6518. return
  6519. }
  6520. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  6521. id, _ := c.GetInt64("id")
  6522. timeLayout := "2006-01-02"
  6523. loc, _ := time.LoadLocation("Local")
  6524. start_time := time.Now().Format("2006-01-02")
  6525. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6526. nowTime := time.Now()
  6527. endTime := nowTime.AddDate(-2, 0, 0)
  6528. endTimes := endTime.Format("2006-01-02")
  6529. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", endTimes+" 00:00:00", loc)
  6530. list, _ := service.GetPatientDialysisRecordList(id, endtime.Unix(), startime.Unix())
  6531. fmt.Println("endtime232332322332322323232332", endTime.Unix())
  6532. c.ServeSuccessJSON(map[string]interface{}{
  6533. "list": list,
  6534. })
  6535. return
  6536. }
  6537. func (c *DialysisAPIController) BathDeleteAdviceList() {
  6538. dataBody := make(map[string]interface{}, 0)
  6539. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6540. ids := c.GetString("ids")
  6541. idArray := strings.Split(ids, ",")
  6542. origin, _ := c.GetInt64("origin")
  6543. if origin == 1 {
  6544. err = service.BatchDeleteAdvice(idArray)
  6545. fmt.Print("err", err)
  6546. c.ServeSuccessJSON(map[string]interface{}{
  6547. "msg": "批量删除成功",
  6548. })
  6549. return
  6550. }
  6551. if origin == 2 {
  6552. service.BatchDeleteHisAdvice(idArray)
  6553. }
  6554. }
  6555. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  6556. good_id, _ := c.GetInt64("good_id")
  6557. count, _ := c.GetInt64("count")
  6558. record_time, _ := c.GetInt64("record_time")
  6559. patient_id, _ := c.GetInt64("patient_id")
  6560. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  6561. c.ServeSuccessJSON(map[string]interface{}{
  6562. "detail": detail,
  6563. })
  6564. return
  6565. }
  6566. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  6567. good_id, _ := c.GetInt64("good_id")
  6568. record_time, _ := c.GetInt64("record_time")
  6569. patient_id, _ := c.GetInt64("patient_id")
  6570. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  6571. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  6572. fmt.Print("err", err)
  6573. c.ServeSuccessJSON(map[string]interface{}{
  6574. "msg": "批量删除成功",
  6575. })
  6576. return
  6577. }
  6578. func (c *DialysisAPIController) BatchAdviceCheck() {
  6579. ids := c.GetString("ids")
  6580. idArray := strings.Split(ids, ",")
  6581. creator, _ := c.GetInt64("creator")
  6582. origin, _ := c.GetInt64("origin")
  6583. if origin == 1 {
  6584. err := service.BatchAdviceCheck(idArray, creator)
  6585. fmt.Println(err)
  6586. list, _ := service.GetAdviceExecutionById(idArray)
  6587. c.ServeSuccessJSON(map[string]interface{}{
  6588. "list": list,
  6589. })
  6590. return
  6591. }
  6592. if origin == 2 {
  6593. service.BatchHisAdviceCheck(idArray, creator)
  6594. list, _ := service.GetHisAdviceExecutionById(idArray)
  6595. c.ServeSuccessJSON(map[string]interface{}{
  6596. "list": list,
  6597. })
  6598. return
  6599. }
  6600. }
  6601. func (c *DialysisAPIController) BatchAdviceExecution() {
  6602. ids := c.GetString("ids")
  6603. idArray := strings.Split(ids, ",")
  6604. executionTime := c.GetString("execution_time")
  6605. creator, _ := c.GetInt64("creator")
  6606. timeLayout := "2006-01-02 15:04:05"
  6607. loc, _ := time.LoadLocation("Local")
  6608. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  6609. orgin, _ := c.GetInt64("origin")
  6610. if orgin == 1 {
  6611. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  6612. list, _ := service.GetAdviceExecutionById(idArray)
  6613. fmt.Println(err)
  6614. c.ServeSuccessJSON(map[string]interface{}{
  6615. "list": list,
  6616. })
  6617. return
  6618. }
  6619. if orgin == 2 {
  6620. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  6621. list, _ := service.GetHisAdviceExecutionById(idArray)
  6622. fmt.Println(err)
  6623. c.ServeSuccessJSON(map[string]interface{}{
  6624. "list": list,
  6625. })
  6626. return
  6627. }
  6628. }
  6629. func (c *DialysisAPIController) UpdateStockGoods() {
  6630. good_id, _ := c.GetInt64("good_id")
  6631. record_time, _ := c.GetInt64("record_time")
  6632. patient_id, _ := c.GetInt64("patient_id")
  6633. count, _ := c.GetInt64("count")
  6634. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  6635. fmt.Print("err", err)
  6636. c.ServeSuccessJSON(map[string]interface{}{
  6637. "msg": "更新成功",
  6638. })
  6639. return
  6640. }
  6641. // 当前数据比上一次出库数据少
  6642. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  6643. //查询该患者当天已经出库的耗材信息
  6644. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  6645. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  6646. for i := len(goods_yc) - 1; i >= 0; i-- {
  6647. goods_yc_temp := goods_yc[i]
  6648. for j := len(goods) - 1; j >= 0; j-- {
  6649. goods_temp := goods[j]
  6650. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  6651. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  6652. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  6653. if goods_yc_temp.Count == goods_temp.Count {
  6654. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6655. goods = append(goods[:j], goods[j+1:]...)
  6656. break
  6657. }
  6658. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  6659. if goods_yc_temp.Count > goods_temp.Count {
  6660. temp_count := goods_yc_temp.Count - goods_temp.Count
  6661. goods_yc[i].Count = temp_count
  6662. goods = append(goods[:j], goods[j+1:]...)
  6663. break
  6664. }
  6665. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  6666. if goods_yc_temp.Count < goods_temp.Count {
  6667. temp_count := goods_temp.Count - goods_yc_temp.Count
  6668. goods[j].Count = temp_count
  6669. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6670. break
  6671. }
  6672. }
  6673. }
  6674. }
  6675. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  6676. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  6677. //退库
  6678. if len(goods_yc) > 0 {
  6679. for _, good_yc := range goods_yc {
  6680. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  6681. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  6682. }
  6683. }
  6684. return nil
  6685. }
  6686. // 耗材出库删除
  6687. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  6688. // 先根据相关信息查询当天该耗材的出库信息
  6689. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  6690. if err != nil {
  6691. return err
  6692. }
  6693. var delete_count int64 = 0
  6694. delete_count = warehouseOutInfos.Count - count
  6695. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6696. // 在出库记录表里记录退库详情
  6697. warehouseOutInfo := &models.WarehouseOutInfo{
  6698. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6699. WarehouseOutId: warehouseOut.ID,
  6700. Status: 1,
  6701. Ctime: time.Now().Unix(),
  6702. OrgId: orgID,
  6703. Type: 1,
  6704. IsSys: 1,
  6705. SysRecordTime: record_time,
  6706. GoodTypeId: good_yc.GoodTypeId,
  6707. GoodId: good_yc.GoodId,
  6708. PatientId: good_yc.PatientId,
  6709. ConsumableType: 2,
  6710. StorehouseId: houseConfig.StorehouseOutInfo,
  6711. IsCheck: 1,
  6712. }
  6713. warehouseOutInfo.Count = count
  6714. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  6715. warehouseOutInfo.Price = stockInInfo.Price
  6716. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6717. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6718. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6719. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6720. warehouseOutInfo.Number = warehouseOutInfos.Number
  6721. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6722. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6723. //查找当天是否存在出库记录
  6724. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6725. if errcod == gorm.ErrRecordNotFound {
  6726. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6727. //插入详情明细表
  6728. stockFlow := models.VmStockFlow{
  6729. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6730. WarehouseOutId: warehouseOut.ID,
  6731. GoodId: good_yc.GoodId,
  6732. Number: warehouseOutInfos.Number,
  6733. ProductDate: stockInInfo.ProductDate,
  6734. ExpireDate: stockInInfo.ExpiryDate,
  6735. Count: count,
  6736. Price: stockInInfo.Price,
  6737. Status: 1,
  6738. Ctime: time.Now().Unix(),
  6739. UserOrgId: good_yc.OrgId,
  6740. Manufacturer: stockInInfo.Manufacturer,
  6741. Dealer: stockInInfo.Dealer,
  6742. LicenseNumber: stockInInfo.LicenseNumber,
  6743. IsEdit: 2,
  6744. Creator: creater,
  6745. SystemTime: record_time,
  6746. ConsumableType: 3,
  6747. WarehousingDetailId: 0,
  6748. IsSys: 1,
  6749. UpdateCreator: creater,
  6750. PatientId: patient_id,
  6751. StorehouseId: houseConfig.StorehouseOutInfo,
  6752. }
  6753. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  6754. if errflow == gorm.ErrRecordNotFound {
  6755. //创建流水表
  6756. err := service.CreateStockFlowOne(stockFlow)
  6757. fmt.Println("err", err)
  6758. } else if errflow == nil {
  6759. //插入详情明细表
  6760. stockFlow := models.VmStockFlow{
  6761. ID: exsit.ID,
  6762. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6763. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6764. WarehouseOutId: warehouseOut.ID,
  6765. GoodId: good_yc.GoodId,
  6766. Number: warehouseOutInfos.Number,
  6767. ProductDate: stockInInfo.ProductDate,
  6768. ExpireDate: stockInInfo.ExpiryDate,
  6769. Count: exsit.Count - delete_count,
  6770. Price: stockInInfo.Price,
  6771. Status: 1,
  6772. Ctime: time.Now().Unix(),
  6773. UserOrgId: good_yc.OrgId,
  6774. Manufacturer: stockInInfo.Manufacturer,
  6775. Dealer: stockInInfo.Dealer,
  6776. LicenseNumber: stockInInfo.LicenseNumber,
  6777. IsEdit: 2,
  6778. Creator: creater,
  6779. SystemTime: record_time,
  6780. ConsumableType: 3,
  6781. WarehousingDetailId: 0,
  6782. IsSys: 1,
  6783. UpdateCreator: creater,
  6784. PatientId: patient_id,
  6785. StorehouseId: houseConfig.StorehouseOutInfo,
  6786. }
  6787. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  6788. }
  6789. if errOne != nil {
  6790. return errOne
  6791. }
  6792. } else if errcod == nil {
  6793. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  6794. //插入详情明细表
  6795. stockFlow := models.VmStockFlow{
  6796. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6797. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6798. WarehouseOutId: warehouseOut.ID,
  6799. GoodId: good_yc.GoodId,
  6800. Number: warehouseOutInfos.Number,
  6801. ProductDate: stockInInfo.ProductDate,
  6802. ExpireDate: stockInInfo.ExpiryDate,
  6803. Count: count,
  6804. Price: stockInInfo.Price,
  6805. Status: 1,
  6806. Ctime: time.Now().Unix(),
  6807. UserOrgId: good_yc.OrgId,
  6808. Manufacturer: stockInInfo.Manufacturer,
  6809. Dealer: stockInInfo.Dealer,
  6810. LicenseNumber: stockInInfo.LicenseNumber,
  6811. IsEdit: 2,
  6812. Creator: creater,
  6813. SystemTime: record_time,
  6814. ConsumableType: 3,
  6815. WarehousingDetailId: 0,
  6816. IsSys: 1,
  6817. UpdateCreator: creater,
  6818. PatientId: patient_id,
  6819. ReturnCount: delete_count,
  6820. StorehouseId: houseConfig.StorehouseOutInfo,
  6821. }
  6822. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  6823. if errflows == gorm.ErrRecordNotFound {
  6824. //创建流水表
  6825. service.CreateStockFlowOne(stockFlow)
  6826. } else if errflows == nil {
  6827. stockFlow := models.VmStockFlow{
  6828. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6829. ID: exsit.ID,
  6830. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6831. WarehouseOutId: warehouseOut.ID,
  6832. GoodId: good_yc.GoodId,
  6833. Number: warehouseOutInfos.Number,
  6834. ProductDate: stockInInfo.ProductDate,
  6835. ExpireDate: stockInInfo.ExpiryDate,
  6836. Count: exsit.Count - delete_count,
  6837. Price: stockInInfo.Price,
  6838. Status: 1,
  6839. Ctime: time.Now().Unix(),
  6840. UserOrgId: good_yc.OrgId,
  6841. Manufacturer: stockInInfo.Manufacturer,
  6842. Dealer: stockInInfo.Dealer,
  6843. LicenseNumber: stockInInfo.LicenseNumber,
  6844. IsEdit: 2,
  6845. Creator: creater,
  6846. SystemTime: record_time,
  6847. ConsumableType: 3,
  6848. WarehousingDetailId: 0,
  6849. IsSys: 1,
  6850. UpdateCreator: creater,
  6851. PatientId: patient_id,
  6852. ReturnCount: delete_count,
  6853. StorehouseId: houseConfig.StorehouseOutInfo,
  6854. }
  6855. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  6856. }
  6857. }
  6858. //更改自动出库的表格
  6859. details := models.BloodAutomaticReduceDetail{
  6860. WarehouseOutId: warehouseOutInfo.ID,
  6861. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6862. PatientId: patient_id,
  6863. Ctime: time.Now().Unix(),
  6864. Mtime: time.Now().Unix(),
  6865. Status: 1,
  6866. RecordTime: record_time,
  6867. OrgId: orgID,
  6868. GoodId: good_yc.GoodId,
  6869. GoodTypeId: good_yc.GoodTypeId,
  6870. Count: count,
  6871. StorehouseId: houseConfig.StorehouseOutInfo,
  6872. }
  6873. //查询当天耗材是否已经存在数据
  6874. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6875. if errcode == gorm.ErrRecordNotFound {
  6876. errTwo := service.CreateAutoReduceRecord(&details)
  6877. if errTwo != nil {
  6878. return errTwo
  6879. }
  6880. } else if errcode == nil {
  6881. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  6882. service.CreateAutoReduceRecord(&details)
  6883. }
  6884. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  6885. //增加出库库存数量
  6886. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  6887. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  6888. fmt.Println("errOne", errOne)
  6889. // 删除出库完成后,要增加对应批次的库存数量
  6890. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  6891. if errThree != nil {
  6892. return errThree
  6893. }
  6894. if good_yc.Count == 0 {
  6895. return nil
  6896. } else {
  6897. return errors.New("退库和出库数据不匹配")
  6898. }
  6899. }
  6900. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  6901. //查询该患者当天已经出库的耗材信息
  6902. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  6903. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  6904. for i := len(goods_yc) - 1; i >= 0; i-- {
  6905. goods_yc_temp := goods_yc[i]
  6906. for j := len(goods) - 1; j >= 0; j-- {
  6907. goods_temp := goods[j]
  6908. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  6909. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  6910. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  6911. if goods_yc_temp.Count == goods_temp.Count {
  6912. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6913. goods = append(goods[:j], goods[j+1:]...)
  6914. break
  6915. }
  6916. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  6917. if goods_yc_temp.Count > goods_temp.Count {
  6918. temp_count := goods_yc_temp.Count - goods_temp.Count
  6919. goods_yc[i].Count = temp_count
  6920. goods = append(goods[:j], goods[j+1:]...)
  6921. break
  6922. }
  6923. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  6924. if goods_yc_temp.Count < goods_temp.Count {
  6925. temp_count := goods_temp.Count - goods_yc_temp.Count
  6926. goods[j].Count = temp_count
  6927. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  6928. break
  6929. }
  6930. }
  6931. }
  6932. }
  6933. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  6934. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  6935. fmt.Println("剩余需要出库的", len(goods))
  6936. if len(goods) > 0 {
  6937. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  6938. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  6939. if err == gorm.ErrRecordNotFound {
  6940. //没有记录,则创建出库单
  6941. timeStr := time.Now().Format("2006-01-02")
  6942. timeArr := strings.Split(timeStr, "-")
  6943. total, _ := service.FindAllWarehouseOut(orgID)
  6944. total = total + 1
  6945. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6946. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6947. number = number + total
  6948. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6949. warehouseOut := models.WarehouseOut{
  6950. WarehouseOutOrderNumber: warehousing_out_order,
  6951. OperationTime: time.Now().Unix(),
  6952. OrgId: orgID,
  6953. Creater: creater,
  6954. Ctime: time.Now().Unix(),
  6955. Status: 1,
  6956. WarehouseOutTime: record_time,
  6957. Dealer: 0,
  6958. Manufacturer: 0,
  6959. Type: 1,
  6960. IsSys: 1,
  6961. StorehouseId: houseConfig.StorehouseOutInfo,
  6962. IsCheck: 1,
  6963. }
  6964. err := service.AddSigleWarehouseOut(&warehouseOut)
  6965. if err != nil {
  6966. utils.TraceLog("创建出库单失败 err = %v", err)
  6967. return err
  6968. } else {
  6969. out = warehouseOut
  6970. }
  6971. }
  6972. for _, item := range goods {
  6973. var newCount int64 = 0
  6974. for _, it := range goodOne {
  6975. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  6976. newCount = it.Count
  6977. }
  6978. }
  6979. prepare := models.DialysisBeforePrepare{
  6980. GoodTypeId: item.GoodTypeId,
  6981. GoodId: item.GoodId,
  6982. Count: item.Count,
  6983. StorehouseId: houseConfig.StorehouseOutInfo,
  6984. }
  6985. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  6986. //增加出库数量
  6987. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  6988. }
  6989. }
  6990. if len(goods_yc) > 0 {
  6991. for _, good_yc := range goods_yc {
  6992. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  6993. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  6994. }
  6995. }
  6996. return nil
  6997. }
  6998. // 耗材出库删除
  6999. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7000. // 先根据相关信息查询当天该耗材的出库信息
  7001. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7002. if err != nil {
  7003. return err
  7004. }
  7005. var delete_count int64 = 0
  7006. for _, ware := range warehouseOutInfos {
  7007. // 判断当前出库的数据和删除出库数量
  7008. if good_yc.Count <= ware.Count {
  7009. delete_count = good_yc.Count
  7010. } else {
  7011. delete_count = ware.Count
  7012. }
  7013. warehouseOutInfo := &models.WarehouseOutInfo{
  7014. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7015. WarehouseOutId: warehouseOut.ID,
  7016. Status: 1,
  7017. Ctime: time.Now().Unix(),
  7018. Remark: "",
  7019. OrgId: orgID,
  7020. Type: 1,
  7021. Manufacturer: 0,
  7022. Dealer: 0,
  7023. IsSys: 0,
  7024. SysRecordTime: record_time,
  7025. GoodTypeId: good_yc.GoodTypeId,
  7026. GoodId: good_yc.GoodId,
  7027. StorehouseId: warehouseOut.StorehouseId,
  7028. IsCheck: 1,
  7029. }
  7030. warehouseOutInfo.Count = delete_count
  7031. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7032. warehouseOutInfo.Price = stockInInfo.Price
  7033. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7034. if errOne != nil {
  7035. return errOne
  7036. }
  7037. // 删除出库完成后,要改变流水库存(有疑问)
  7038. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7039. fmt.Println("errOne", errOne)
  7040. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7041. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7042. //扣减出库数量
  7043. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7044. if errThree != nil {
  7045. return errThree
  7046. }
  7047. }
  7048. if good_yc.Count == 0 {
  7049. return nil
  7050. } else {
  7051. return errors.New("退库和出库数据不匹配")
  7052. }
  7053. }
  7054. func (this *DialysisAPIController) GetMobileScheduleList() {
  7055. limit, _ := this.GetInt64("limit")
  7056. page, _ := this.GetInt64("page")
  7057. type_options_visible, _ := this.GetInt64("type_options_visible")
  7058. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7059. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7060. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7061. }
  7062. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7063. newArr = make([]*models.HisPrescriptionProject, 0)
  7064. for i := 0; i < len(arr); i++ {
  7065. repeat := false
  7066. for j := i + 1; j < len(arr); j++ {
  7067. if arr[i].TeamId == arr[j].TeamId {
  7068. repeat = true
  7069. break
  7070. }
  7071. }
  7072. if !repeat {
  7073. newArr = append(newArr, arr[i])
  7074. }
  7075. }
  7076. return
  7077. }
  7078. func (this *DialysisAPIController) GetRoleList() {
  7079. admin_user_id, _ := this.GetInt64("admin_user_id")
  7080. orgid := this.GetMobileAdminUserInfo().Org.Id
  7081. list, err := service.GetRoleList(orgid, admin_user_id)
  7082. fmt.Println(err)
  7083. this.ServeSuccessJSON(map[string]interface{}{
  7084. "list": list,
  7085. })
  7086. return
  7087. }
  7088. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7089. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7090. // 先根据相关信息查询当天该耗材的出库信息
  7091. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7092. if err != nil {
  7093. return err
  7094. }
  7095. var delete_count int64 = 0
  7096. delete_count = warehouseOutInfos.Count - count
  7097. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7098. // 删除出库完成后,要增加对应批次的库存数量
  7099. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7100. if errThree != nil {
  7101. return errThree
  7102. }
  7103. //增加退库数量
  7104. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7105. //扣减出库数量
  7106. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7107. //查询剩余库存
  7108. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7109. var sum_count int64
  7110. for _, item := range goodList {
  7111. sum_count += item.StockCount
  7112. }
  7113. // 在出库记录表里记录退库详情
  7114. warehouseOutInfo := &models.WarehouseOutInfo{
  7115. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7116. WarehouseOutId: warehouseOut.ID,
  7117. Status: 1,
  7118. Ctime: time.Now().Unix(),
  7119. OrgId: orgID,
  7120. Type: 1,
  7121. IsSys: 1,
  7122. SysRecordTime: record_time,
  7123. GoodTypeId: good_yc.GoodTypeId,
  7124. GoodId: good_yc.GoodId,
  7125. PatientId: good_yc.PatientId,
  7126. ConsumableType: 2,
  7127. StorehouseId: houseConfig.StorehouseOutInfo,
  7128. IsCheck: 1,
  7129. OverCount: sum_count,
  7130. }
  7131. warehouseOutInfo.Count = count
  7132. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7133. warehouseOutInfo.Price = stockInInfo.Price
  7134. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7135. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7136. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7137. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7138. warehouseOutInfo.Number = warehouseOutInfos.Number
  7139. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7140. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7141. //查找当天是否存在出库记录
  7142. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7143. if errcod == gorm.ErrRecordNotFound {
  7144. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7145. //插入详情明细表
  7146. if errOne != nil {
  7147. return errOne
  7148. }
  7149. //插入详情明细表
  7150. stockFlow := models.VmStockFlow{
  7151. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7152. WarehouseOutId: warehouseOut.ID,
  7153. GoodId: good_yc.GoodId,
  7154. Number: warehouseOutInfos.Number,
  7155. ProductDate: stockInInfo.ProductDate,
  7156. ExpireDate: stockInInfo.ExpiryDate,
  7157. Count: count,
  7158. Price: stockInInfo.Price,
  7159. Status: 1,
  7160. Ctime: time.Now().Unix(),
  7161. UserOrgId: good_yc.OrgId,
  7162. Manufacturer: stockInInfo.Manufacturer,
  7163. Dealer: stockInInfo.Dealer,
  7164. LicenseNumber: stockInInfo.LicenseNumber,
  7165. IsEdit: 2,
  7166. Creator: creater,
  7167. SystemTime: record_time,
  7168. ConsumableType: 3,
  7169. WarehousingDetailId: 0,
  7170. IsSys: 1,
  7171. UpdateCreator: creater,
  7172. PatientId: patient_id,
  7173. StorehouseId: houseConfig.StorehouseOutInfo,
  7174. OverCount: sum_count,
  7175. ProjectId: good_yc.ProjectId,
  7176. }
  7177. err := service.CreateStockFlowOne(stockFlow)
  7178. fmt.Println("err", err)
  7179. } else if errcod == nil {
  7180. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7181. }
  7182. //创建退库单
  7183. operation_time := time.Now().Unix()
  7184. //创建退库单
  7185. timeStr := time.Now().Format("2006-01-02")
  7186. timeArr := strings.Split(timeStr, "-")
  7187. total, _ := service.FindAllCancelStockTotal(orgID)
  7188. total = total + 1
  7189. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7190. cancelStock := models.CancelStock{
  7191. OrderNumber: orderNumber,
  7192. OperaTime: operation_time,
  7193. OrgId: orgID,
  7194. Creater: warehouseOut.Creater,
  7195. Ctime: time.Now().Unix(),
  7196. Status: 1,
  7197. ReturnTime: record_time,
  7198. Type: 1,
  7199. StorehouseId: stockInInfo.StorehouseId,
  7200. IsCheck: 1,
  7201. }
  7202. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7203. if msgerrkonde == gorm.ErrRecordNotFound {
  7204. service.AddSigleCancelStock(&cancelStock)
  7205. }
  7206. cancel, _ := service.GetLastCancelStockById(orgID)
  7207. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7208. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7209. cancelStockInfo := models.CancelStockInfo{
  7210. GoodId: stockInInfo.GoodId,
  7211. CancelStockId: cancel.ID,
  7212. GoodTypeId: stockInInfo.GoodTypeId,
  7213. Count: delete_count,
  7214. Price: stockInInfo.PackingPrice,
  7215. Total: 0,
  7216. ProductDate: stockInInfo.ProductDate,
  7217. ExpiryDate: stockInInfo.ExpiryDate,
  7218. Ctime: time.Now().Unix(),
  7219. Status: 1,
  7220. OrgId: orgID,
  7221. OrderNumber: cancel.OrderNumber,
  7222. Type: 0,
  7223. Dealer: deaerler.DealerName,
  7224. Manufacturer: manufacturer.ManufacturerName,
  7225. Number: stockInInfo.Number,
  7226. RegisterAccount: "",
  7227. Remark: "",
  7228. WarehouseInfoId: stockInInfo.ID,
  7229. PatientId: patient_id,
  7230. RecordDate: record_time,
  7231. StorehouseId: stockInInfo.StorehouseId,
  7232. IsCheck: 1,
  7233. }
  7234. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7235. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7236. flow := models.VmStockFlow{
  7237. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7238. GoodId: good_yc.GoodId,
  7239. Number: warehouseOutInfos.Number,
  7240. LicenseNumber: stockInInfo.LicenseNumber,
  7241. Count: delete_count,
  7242. UserOrgId: orgID,
  7243. PatientId: patient_id,
  7244. SystemTime: record_time,
  7245. ConsumableType: 7,
  7246. IsSys: 0,
  7247. WarehousingOrder: "",
  7248. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7249. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7250. IsEdit: 0,
  7251. CancelStockId: cancel.ID,
  7252. CancelOrderNumber: cancel.OrderNumber,
  7253. Manufacturer: manufacturer.ID,
  7254. Dealer: 0,
  7255. Creator: warehouseOut.Creater,
  7256. UpdateCreator: 0,
  7257. Status: 1,
  7258. Ctime: time.Now().Unix(),
  7259. Mtime: 0,
  7260. Price: stockInInfo.Price,
  7261. WarehousingDetailId: stockInInfo.ID,
  7262. WarehouseOutDetailId: warehouseOutInfos.ID,
  7263. CancelOutDetailId: cancelInfo.ID,
  7264. ProductDate: stockInInfo.ProductDate,
  7265. ExpireDate: stockInInfo.ExpiryDate,
  7266. StorehouseId: houseConfig.StorehouseOutInfo,
  7267. OverCount: sum_count,
  7268. }
  7269. service.CreateStockFlowOne(flow)
  7270. //更改自动出库的表格
  7271. details := models.BloodAutomaticReduceDetail{
  7272. WarehouseOutId: warehouseOutInfo.ID,
  7273. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7274. PatientId: patient_id,
  7275. Ctime: time.Now().Unix(),
  7276. Mtime: time.Now().Unix(),
  7277. Status: 1,
  7278. RecordTime: record_time,
  7279. OrgId: orgID,
  7280. GoodId: good_yc.GoodId,
  7281. GoodTypeId: good_yc.GoodTypeId,
  7282. Count: count,
  7283. StorehouseId: houseConfig.StorehouseOutInfo,
  7284. }
  7285. //查询当天耗材是否已经存在数据
  7286. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7287. if errcode == gorm.ErrRecordNotFound {
  7288. errTwo := service.CreateAutoReduceRecord(&details)
  7289. if errTwo != nil {
  7290. return errTwo
  7291. }
  7292. } else if errcode == nil {
  7293. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7294. service.CreateAutoReduceRecord(&details)
  7295. }
  7296. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7297. //增加出库库存数量
  7298. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7299. if good_yc.Count == 0 {
  7300. return nil
  7301. } else {
  7302. return errors.New("退库和出库数据不匹配")
  7303. }
  7304. }
  7305. func (this *DialysisAPIController) SavePatientSign() {
  7306. adminUserInfo := this.GetMobileAdminUserInfo()
  7307. patient_id, _ := this.GetInt64("patient_id")
  7308. dialysis_date, _ := this.GetInt64("dialysis_date")
  7309. orgid := adminUserInfo.Org.Id
  7310. var esdata models.DialysisOrder
  7311. var err error
  7312. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  7313. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7314. return
  7315. }
  7316. esdata.Hash = esdata.Hash
  7317. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  7318. order := models.DialysisOrder{
  7319. Hash: esdata.Hash,
  7320. Url: esdata.Url,
  7321. }
  7322. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  7323. redis := service.RedisClient()
  7324. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7325. redis.Set(key, "", time.Second)
  7326. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7327. //清空key 值
  7328. redis.Set(keyOne, "", time.Second)
  7329. //scheduleDateStartOne := startDate.Format("2006-01-02")
  7330. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  7331. //redis.Set(keyTwo, "", time.Second)
  7332. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7333. redis.Set(keyThree, "", time.Second)
  7334. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7335. redis.Set(keyFour, "", time.Second)
  7336. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7337. redis.Set(keyFive, "", time.Second)
  7338. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7339. redis.Set(keySix, "", time.Second)
  7340. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  7341. redis.Set(keySeven, "", time.Second)
  7342. if err != nil {
  7343. fmt.Println(err)
  7344. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7345. return
  7346. }
  7347. this.ServeSuccessJSON(map[string]interface{}{
  7348. "electronic_signature": esdata,
  7349. })
  7350. }
  7351. func (this *DialysisAPIController) GetPatientSign() {
  7352. patient_id, _ := this.GetInt64("patient_id")
  7353. dialysis_date, _ := this.GetInt64("dialysis_date")
  7354. adminUserInfo := this.GetMobileAdminUserInfo()
  7355. orgId := adminUserInfo.Org.Id
  7356. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  7357. if err != nil {
  7358. fmt.Println(err)
  7359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7360. return
  7361. }
  7362. this.ServeSuccessJSON(map[string]interface{}{
  7363. "dialysisOrder": dialysisOrder,
  7364. })
  7365. }
  7366. func (this *DialysisAPIController) GetScheduleByPatient() {
  7367. patient_id, _ := this.GetInt64("patient_id")
  7368. schedule_date, _ := this.GetInt64("schedule_date")
  7369. orgid := this.GetMobileAdminUserInfo().Org.Id
  7370. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  7371. this.ServeSuccessJSON(map[string]interface{}{
  7372. "schedule": schedule,
  7373. })
  7374. }
  7375. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  7376. org_id := this.GetMobileAdminUserInfo().Org.Id
  7377. patient_id, _ := this.GetInt64("patient_id")
  7378. schedule_date, _ := this.GetInt64("schedule_date")
  7379. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  7380. this.ServeSuccessJSON(map[string]interface{}{
  7381. "order": order,
  7382. })
  7383. }
  7384. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  7385. org_id := this.GetMobileAdminUserInfo().Org.Id
  7386. schedule_date := this.GetString("schedule_date")
  7387. schedule_type, _ := this.GetInt64("schedule_type")
  7388. timeLayout := "2006-01-02"
  7389. loc, _ := time.LoadLocation("Local")
  7390. var startdateunix int64
  7391. if len(schedule_date) > 0 {
  7392. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  7393. if err != nil {
  7394. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7395. return
  7396. }
  7397. startdateunix = theTime.Unix()
  7398. }
  7399. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  7400. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  7401. devices, _ := service.GetAllDevicetByListSix(org_id)
  7402. for key, item := range scheduals {
  7403. // 床位信息
  7404. for _, device := range devices {
  7405. if item.BedId == device.ID {
  7406. scheduals[key].DeviceNumber = device
  7407. break
  7408. }
  7409. }
  7410. }
  7411. this.ServeSuccessJSON(map[string]interface{}{
  7412. "list": list,
  7413. "scheduals": scheduals,
  7414. })
  7415. }
  7416. func (this *DialysisAPIController) SavePatientPicture() {
  7417. patient_id, _ := this.GetInt64("patient_id")
  7418. dialysis_date, _ := this.GetInt64("schedule_date")
  7419. avatar := this.GetString("avatar")
  7420. fmt.Println("patient_id", patient_id)
  7421. orgId := this.GetMobileAdminUserInfo().Org.Id
  7422. order := models.DialysisOrder{
  7423. Url: avatar,
  7424. }
  7425. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  7426. redis := service.RedisClient()
  7427. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  7428. redis.Set(key, "", time.Second)
  7429. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  7430. //清空key 值
  7431. redis.Set(keyOne, "", time.Second)
  7432. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  7433. redis.Set(keyThree, "", time.Second)
  7434. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  7435. redis.Set(keyFour, "", time.Second)
  7436. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  7437. redis.Set(keyFive, "", time.Second)
  7438. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  7439. redis.Set(keySix, "", time.Second)
  7440. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  7441. redis.Set(keySeven, "", time.Second)
  7442. if err != nil {
  7443. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  7444. return
  7445. }
  7446. this.ServeSuccessJSON(map[string]interface{}{
  7447. "order": order,
  7448. })
  7449. }
  7450. func (this *DialysisAPIController) ExectionMobileAdvice() {
  7451. ids := this.GetString("ids")
  7452. idSplit := strings.Split(ids, ",")
  7453. orgId := this.GetMobileAdminUserInfo().Org.Id
  7454. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7455. execution_time := this.GetString("exce_time")
  7456. timeLayout2 := "2006-01-02 15:04:05"
  7457. loc, _ := time.LoadLocation("Local")
  7458. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  7459. if errs != nil {
  7460. utils.ErrorLog(errs.Error())
  7461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7462. return
  7463. }
  7464. //his客户
  7465. if config.IsOpen == 1 {
  7466. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  7467. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  7468. for _, item := range list {
  7469. for _, it := range adviceList {
  7470. if item.DrugId == it.DrugId {
  7471. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  7472. }
  7473. }
  7474. }
  7475. for _, item := range list {
  7476. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7477. var sum_out_count int64
  7478. for _, itemThree := range item.ChildDoctorAdvice {
  7479. var prescribing_number int64
  7480. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7481. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7482. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7483. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7484. }
  7485. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7486. prescribing_number = parseIntPrescribingNumber
  7487. }
  7488. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7489. prescribing_number = parseIntPrescribingNumber
  7490. }
  7491. sum_out_count += prescribing_number
  7492. }
  7493. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7494. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  7495. //库存不足
  7496. if sum_out_count > drugStockOut.FlushCount {
  7497. this.ServeSuccessJSON(map[string]interface{}{
  7498. "msg": "2",
  7499. "drug": medical,
  7500. "ids": ids,
  7501. })
  7502. return
  7503. }
  7504. }
  7505. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7506. //执行医嘱
  7507. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7508. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  7509. for _, item := range advices {
  7510. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7511. redis := service.RedisClient()
  7512. //清空key 值
  7513. redis.Set(key, "", time.Second)
  7514. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7515. redis.Set(keyTwo, "", time.Second)
  7516. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7517. redis.Set(keyThree, "", time.Second)
  7518. recordDate := theTime.Format("2006-01-02")
  7519. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7520. redis.Set(keyFour, "", time.Second)
  7521. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7522. redis.Set(keyFive, "", time.Second)
  7523. defer redis.Close()
  7524. }
  7525. if errs == nil {
  7526. //药品管理信息
  7527. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  7528. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7529. if drugStockConfig.IsOpen == 1 {
  7530. for _, item := range advices {
  7531. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  7532. config, _ := service.GetDrugOpenConfigOne(orgId)
  7533. if config.IsOpen != 1 {
  7534. //查询该药品是否有库存
  7535. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7536. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  7537. if medical.IsUse == 2 {
  7538. if config.IsOpen != 1 {
  7539. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7540. service.HisDrugsDelivery(orgId, creater, &advice)
  7541. if orgId == 3877 || orgId == 10265 {
  7542. //查询该药品是否有出库记录
  7543. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  7544. if len(flowMap) == 0 {
  7545. errs := service.UpdateHisAdviceById(advice.ID)
  7546. if errs != nil {
  7547. drugError := models.XtDrugError{
  7548. UserOrgId: orgId,
  7549. DrugId: item.DrugId,
  7550. RecordDate: item.AdviceDate,
  7551. PatientId: item.PatientId,
  7552. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  7553. Status: 1,
  7554. Ctime: time.Now().Unix(),
  7555. Mtime: 0,
  7556. SumCount: 0,
  7557. Prescribingnumber: advice.PrescribingNumber,
  7558. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  7559. }
  7560. service.CreateDrugError(drugError)
  7561. }
  7562. this.ServeSuccessJSON(map[string]interface{}{
  7563. "msg": "2",
  7564. "drug": medical,
  7565. "ids": ids,
  7566. })
  7567. return
  7568. }
  7569. }
  7570. }
  7571. if pharmacyConfig.IsOpen != 1 {
  7572. service.HisDrugsDelivery(orgId, creater, &advice)
  7573. if orgId == 3877 || orgId == 10265 {
  7574. //查询该药品是否有出库记录
  7575. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  7576. if len(flowMap) == 0 {
  7577. errs := service.UpdateHisAdviceById(advice.ID)
  7578. if errs != nil {
  7579. drugError := models.XtDrugError{
  7580. UserOrgId: orgId,
  7581. DrugId: item.DrugId,
  7582. RecordDate: item.AdviceDate,
  7583. PatientId: item.PatientId,
  7584. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  7585. Status: 1,
  7586. Ctime: time.Now().Unix(),
  7587. Mtime: 0,
  7588. SumCount: 0,
  7589. Prescribingnumber: advice.PrescribingNumber,
  7590. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  7591. }
  7592. service.CreateDrugError(drugError)
  7593. }
  7594. this.ServeSuccessJSON(map[string]interface{}{
  7595. "msg": "2",
  7596. "drug": medical,
  7597. "ids": ids,
  7598. })
  7599. return
  7600. }
  7601. }
  7602. }
  7603. //更新字典里面的库存
  7604. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7605. var sum_count int64
  7606. for _, its := range stockInfo {
  7607. if its.MaxUnit == medical.MaxUnit {
  7608. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7609. }
  7610. sum_count += its.StockMaxNumber + its.StockMinNumber
  7611. }
  7612. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7613. //剩余库存
  7614. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7615. }
  7616. }
  7617. }
  7618. }
  7619. }
  7620. this.ServeSuccessJSON(map[string]interface{}{
  7621. "msg": "1",
  7622. "ids": ids,
  7623. })
  7624. return
  7625. } else {
  7626. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7627. }
  7628. }
  7629. fmt.Println("config233322333223", config.IsOpen)
  7630. //血透客户
  7631. if config.IsOpen == 2 || config.IsOpen == 0 {
  7632. //药品管理信息
  7633. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  7634. if drugStockConfig.IsOpen == 1 {
  7635. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  7636. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  7637. for _, item := range list {
  7638. for _, it := range adviceList {
  7639. if item.DrugId == it.DrugId {
  7640. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  7641. }
  7642. }
  7643. }
  7644. for _, item := range list {
  7645. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7646. var sum_out_count int64
  7647. for _, itemThree := range item.ChildDoctorAdvice {
  7648. var prescribing_number int64
  7649. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7650. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7651. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7652. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7653. }
  7654. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7655. prescribing_number = parseIntPrescribingNumber
  7656. }
  7657. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7658. prescribing_number = parseIntPrescribingNumber
  7659. }
  7660. sum_out_count += prescribing_number
  7661. }
  7662. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7663. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  7664. //库存不足
  7665. if sum_out_count > drugStockOut.FlushCount {
  7666. this.ServeSuccessJSON(map[string]interface{}{
  7667. "msg": "2",
  7668. "drug": medical,
  7669. "ids": ids,
  7670. })
  7671. return
  7672. }
  7673. }
  7674. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7675. fmt.Println("creater2332243244224242424", creater)
  7676. //执行医嘱
  7677. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7678. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  7679. for _, item := range advices {
  7680. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7681. redis := service.RedisClient()
  7682. //清空key 值
  7683. redis.Set(key, "", time.Second)
  7684. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7685. redis.Set(keyTwo, "", time.Second)
  7686. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7687. redis.Set(keyThree, "", time.Second)
  7688. recordDate := theTime.Format("2006-01-02")
  7689. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7690. redis.Set(keyFour, "", time.Second)
  7691. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7692. redis.Set(keyFive, "", time.Second)
  7693. defer redis.Close()
  7694. }
  7695. if errs == nil {
  7696. for _, item := range advices {
  7697. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7698. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7699. //查询是否出库按钮开启
  7700. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  7701. if adviceSetting.IsAdviceOpen == 1 {
  7702. //查询是否出库按钮开启
  7703. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  7704. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  7705. if prescriptionConfig.IsOpen == 1 {
  7706. if medical.IsUse == 2 {
  7707. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7708. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7709. }
  7710. if pharmacyConfig.IsOpen != 1 {
  7711. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7712. }
  7713. //更新字典里面的库存
  7714. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7715. var sum_count int64
  7716. for _, its := range stockInfo {
  7717. if its.MaxUnit == medical.MaxUnit {
  7718. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7719. }
  7720. sum_count += its.StockMaxNumber + its.StockMinNumber
  7721. }
  7722. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7723. //剩余库存
  7724. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7725. }
  7726. }
  7727. } else {
  7728. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  7729. if medical.IsUse == 2 {
  7730. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  7731. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7732. }
  7733. if pharmacyConfig.IsOpen != 1 {
  7734. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  7735. }
  7736. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7737. var sum_count int64
  7738. for _, its := range stockInfo {
  7739. if its.MaxUnit == medical.MaxUnit {
  7740. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7741. }
  7742. sum_count += its.StockMaxNumber + its.StockMinNumber
  7743. }
  7744. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7745. //剩余库存
  7746. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7747. }
  7748. }
  7749. }
  7750. }
  7751. this.ServeSuccessJSON(map[string]interface{}{
  7752. "msg": "1",
  7753. "ids": ids,
  7754. })
  7755. return
  7756. } else {
  7757. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  7758. //执行医嘱
  7759. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  7760. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  7761. for _, item := range advices {
  7762. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7763. redis := service.RedisClient()
  7764. //清空key 值
  7765. redis.Set(key, "", time.Second)
  7766. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7767. redis.Set(keyTwo, "", time.Second)
  7768. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7769. redis.Set(keyThree, "", time.Second)
  7770. recordDate := theTime.Format("2006-01-02")
  7771. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7772. redis.Set(keyFour, "", time.Second)
  7773. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7774. redis.Set(keyFive, "", time.Second)
  7775. defer redis.Close()
  7776. }
  7777. this.ServeSuccessJSON(map[string]interface{}{
  7778. "msg": "1",
  7779. "ids": ids,
  7780. })
  7781. return
  7782. }
  7783. }
  7784. }
  7785. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  7786. ids := this.GetString("ids")
  7787. idSplit := strings.Split(ids, ",")
  7788. orgId := this.GetMobileAdminUserInfo().Org.Id
  7789. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7790. if config.IsOpen == 1 {
  7791. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  7792. this.ServeSuccessJSON(map[string]interface{}{
  7793. "msg": "1",
  7794. "ids": ids,
  7795. })
  7796. return
  7797. }
  7798. if config.IsOpen == 0 || config.IsOpen == 2 {
  7799. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  7800. this.ServeSuccessJSON(map[string]interface{}{
  7801. "msg": "1",
  7802. "ids": ids,
  7803. })
  7804. return
  7805. }
  7806. }
  7807. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  7808. ids := this.GetString("ids")
  7809. idSplit := strings.Split(ids, ",")
  7810. orgId := this.GetMobileAdminUserInfo().Org.Id
  7811. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  7812. //his
  7813. if config.IsOpen == 1 {
  7814. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  7815. theTime := time.Now()
  7816. advices := models.HisDoctorAdviceThirty{
  7817. CheckTime: theTime.Unix(),
  7818. Checker: checker,
  7819. UpdatedTime: time.Now().Unix(),
  7820. }
  7821. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  7822. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  7823. for _, item := range list {
  7824. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7825. redis := service.RedisClient()
  7826. //清空key 值
  7827. redis.Set(key, "", time.Second)
  7828. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7829. redis.Set(keyTwo, "", time.Second)
  7830. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7831. redis.Set(keyThree, "", time.Second)
  7832. recordDate := theTime.Format("2006-01-02")
  7833. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7834. redis.Set(keyFour, "", time.Second)
  7835. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7836. redis.Set(keyFive, "", time.Second)
  7837. defer redis.Close()
  7838. }
  7839. this.ServeSuccessJSON(map[string]interface{}{
  7840. "msg": "1",
  7841. "ids": ids,
  7842. })
  7843. return
  7844. }
  7845. //血透
  7846. if config.IsOpen == 0 || config.IsOpen == 2 {
  7847. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  7848. theTime := time.Now()
  7849. advices := models.DoctorAdvice{
  7850. CheckTime: theTime.Unix(),
  7851. Checker: checker,
  7852. UpdatedTime: time.Now().Unix(),
  7853. }
  7854. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  7855. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  7856. for _, item := range list {
  7857. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  7858. redis := service.RedisClient()
  7859. //清空key 值
  7860. redis.Set(key, "", time.Second)
  7861. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  7862. redis.Set(keyTwo, "", time.Second)
  7863. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  7864. redis.Set(keyThree, "", time.Second)
  7865. recordDate := theTime.Format("2006-01-02")
  7866. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  7867. redis.Set(keyFour, "", time.Second)
  7868. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  7869. redis.Set(keyFive, "", time.Second)
  7870. defer redis.Close()
  7871. }
  7872. this.ServeSuccessJSON(map[string]interface{}{
  7873. "msg": "1",
  7874. "ids": ids,
  7875. })
  7876. return
  7877. }
  7878. }
  7879. func (this *DialysisAPIController) CheckSchedule() {
  7880. patientID, _ := this.GetInt64("patient_id")
  7881. recordDateStr := this.GetString("record_date")
  7882. nurseID, _ := this.GetInt64("start_nurse")
  7883. schedual_type, _ := this.GetInt64("schedual_type")
  7884. bedID, _ := this.GetInt64("bed")
  7885. start_time := this.GetString("start_time")
  7886. fmt.Println("patientID", patientID)
  7887. fmt.Println("recordDateStr", recordDateStr)
  7888. fmt.Println("nurseID", nurseID)
  7889. fmt.Println("schedual_type------", schedual_type)
  7890. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  7891. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7892. return
  7893. }
  7894. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  7895. if parseStartDateErr != nil {
  7896. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  7897. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7898. return
  7899. }
  7900. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7901. if parseErr != nil {
  7902. this.ErrorLog("时间解析失败:%v", parseErr)
  7903. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7904. return
  7905. }
  7906. adminUserInfo := this.GetMobileAdminUserInfo()
  7907. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  7908. if getPatientErr != nil {
  7909. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  7910. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7911. return
  7912. } else if patient == nil {
  7913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7914. return
  7915. }
  7916. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  7917. if getNurseErr != nil {
  7918. this.ErrorLog("获取护士失败:%v", getNurseErr)
  7919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7920. return
  7921. } else if nurse == nil {
  7922. this.ErrorLog("护士不存在")
  7923. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7924. return
  7925. }
  7926. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  7927. if getDeviceNumberErr != nil {
  7928. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  7929. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7930. return
  7931. } else if deviceNumber == nil {
  7932. this.ErrorLog("床位号不存在")
  7933. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7934. return
  7935. }
  7936. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  7937. if getRecordErr != nil {
  7938. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  7939. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7940. return
  7941. } else if dialysisRecord != nil {
  7942. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  7943. return
  7944. }
  7945. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  7946. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  7947. timeLayout := "2006-01-02 15:04:05"
  7948. loc, _ := time.LoadLocation("Local")
  7949. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  7950. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  7951. schedulestartTime := theStartTime.Unix()
  7952. scheduleendTime := theEndTime.Unix()
  7953. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  7954. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  7955. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7956. //查询该床位是否有人用了
  7957. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  7958. if err == nil {
  7959. if schedule.ID == 0 {
  7960. this.ServeSuccessJSON(map[string]interface{}{
  7961. "status": 0,
  7962. "msg": "请求失败",
  7963. })
  7964. } else {
  7965. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  7966. if order.ID > 0 { //该机位被其他人占用了
  7967. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  7968. return
  7969. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  7970. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  7971. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  7972. this.ServeSuccessJSON(map[string]interface{}{
  7973. "status": 1,
  7974. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  7975. })
  7976. return
  7977. } else {
  7978. this.ServeSuccessJSON(map[string]interface{}{
  7979. "status": 0,
  7980. "msg": "",
  7981. })
  7982. }
  7983. }
  7984. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  7985. this.ServeSuccessJSON(map[string]interface{}{
  7986. "status": 2,
  7987. "msg": "当前机位已有患者在使用,请重新选择!",
  7988. })
  7989. }
  7990. }
  7991. } else {
  7992. this.ServeSuccessJSON(map[string]interface{}{
  7993. "status": 0,
  7994. "msg": "",
  7995. })
  7996. }
  7997. }
  7998. func (this *DialysisAPIController) GetNewDoctorListToday() {
  7999. orgId := this.GetMobileAdminUserInfo().Org.Id
  8000. schedule_type, _ := this.GetInt64("schedule_type")
  8001. partion_type, _ := this.GetInt64("partion_type")
  8002. start_time := this.GetString("start_time")
  8003. timeLayout := "2006-01-02"
  8004. loc, _ := time.LoadLocation("Local")
  8005. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8006. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8007. _, config := service.FindXTHisRecordByOrgId(orgId)
  8008. appId := this.GetMobileAdminUserInfo().App.Id
  8009. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8010. if err == nil {
  8011. this.ServeSuccessJSON(map[string]interface{}{
  8012. "list": list,
  8013. "config": config,
  8014. "doctorList": doctorList,
  8015. })
  8016. return
  8017. } else {
  8018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8019. return
  8020. }
  8021. }
  8022. func (this *DialysisAPIController) SaveMobileInformation() {
  8023. patient_id, _ := this.GetInt64("patient_id")
  8024. record_date, _ := this.GetInt64("record_date")
  8025. startTime := this.GetString("start_time")
  8026. module, _ := this.GetInt64("module")
  8027. remark := this.GetString("remark")
  8028. timeLayout := "2006-01-02 15:04"
  8029. loc, _ := time.LoadLocation("Local")
  8030. if len(startTime) == 0 {
  8031. utils.ErrorLog("len(start_time) == 0")
  8032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8033. return
  8034. }
  8035. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8036. if err != nil {
  8037. utils.ErrorLog(err.Error())
  8038. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8039. return
  8040. }
  8041. StartTime := theTime.Unix()
  8042. fmt.Println("startime-------------", StartTime)
  8043. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8044. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8045. information := models.XtDialysisInformation{
  8046. Module: module,
  8047. PatientId: patient_id,
  8048. RecordDate: record_date,
  8049. ApplicationDate: StartTime,
  8050. Creater: creater,
  8051. ApplicationStatus: 2,
  8052. Checker: 0,
  8053. CheckTime: 0,
  8054. Remark: remark,
  8055. UserOrgId: user_org_id,
  8056. Ctime: time.Now().Unix(),
  8057. Status: 1,
  8058. Mtime: 0,
  8059. }
  8060. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_date, user_org_id)
  8061. if infor.ID == 0 {
  8062. service.SaveDialysisInformation(information)
  8063. }
  8064. if infor.ID > 0 {
  8065. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8066. }
  8067. this.ServeSuccessJSON(map[string]interface{}{
  8068. "information": information,
  8069. })
  8070. return
  8071. }
  8072. func (this *DialysisAPIController) GetMobileInformation() {
  8073. limit, _ := this.GetInt64("limit")
  8074. page, _ := this.GetInt64("page")
  8075. orgid := this.GetMobileAdminUserInfo().Org.Id
  8076. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8077. appid := this.GetMobileAdminUserInfo().App.Id
  8078. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8079. patients, _ := service.GetAllpatientThirty(orgid)
  8080. this.ServeSuccessJSON(map[string]interface{}{
  8081. "information": information,
  8082. "total": total,
  8083. "doclist": doclist,
  8084. "patients": patients,
  8085. })
  8086. return
  8087. }
  8088. func (this *DialysisAPIController) GetMobileInformationOne() {
  8089. limit, _ := this.GetInt64("limit")
  8090. page, _ := this.GetInt64("page")
  8091. orgid := this.GetMobileAdminUserInfo().Org.Id
  8092. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8093. appid := this.GetMobileAdminUserInfo().App.Id
  8094. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8095. patients, _ := service.GetAllpatientThirty(orgid)
  8096. this.ServeSuccessJSON(map[string]interface{}{
  8097. "information": information,
  8098. "total": total,
  8099. "doclist": doclist,
  8100. "patients": patients,
  8101. })
  8102. return
  8103. }
  8104. func (this *DialysisAPIController) CheckMobileInformation() {
  8105. id, _ := this.GetInt64("id")
  8106. application_status, _ := this.GetInt64("application_status")
  8107. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8108. checktime := time.Now().Unix()
  8109. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8110. if err == nil {
  8111. this.ServeSuccessJSON(map[string]interface{}{
  8112. "msg": "ok",
  8113. })
  8114. return
  8115. }
  8116. }
  8117. func (c *DialysisAPIController) GetControlMonitorList() {
  8118. partition, _ := c.GetInt64("partition")
  8119. monitorDate := c.GetString("date")
  8120. patient_id, _ := c.GetInt64("patient_id")
  8121. pat_type, _ := c.GetInt64("pat_type")
  8122. timeLayout := "2006-01-02"
  8123. loc, _ := time.LoadLocation("Local")
  8124. var theStartTime int64
  8125. if len(monitorDate) > 0 {
  8126. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8127. if err != nil {
  8128. theStartTime = 0
  8129. }
  8130. theStartTime = theTime.Unix()
  8131. }
  8132. adminInfo := c.GetMobileAdminUserInfo()
  8133. orgID := adminInfo.Org.Id
  8134. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8135. if err != nil {
  8136. c.ErrorLog("获取排班信息失败:%v", err)
  8137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8138. } else {
  8139. if len(monitor) > 0 {
  8140. //获取所有床位
  8141. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8142. //获取所有分区
  8143. zoneList, _ := service.GetAllZoneByList(orgID)
  8144. //获取透析处方
  8145. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8146. //获取透前评估
  8147. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8148. //获取上机
  8149. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8150. //获取透后
  8151. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8152. //获取透后监测
  8153. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8154. //获取所有的患者
  8155. patients, _ := service.GetAllPatientListByListOne(orgID)
  8156. //获取所有透析模式
  8157. treatments, _ := service.GetAllTreatModeByList(orgID)
  8158. //获取所有医嘱
  8159. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8160. //获取双人核对
  8161. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8162. //治疗小结
  8163. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8164. //待消毒
  8165. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8166. for key, item := range monitor {
  8167. // 获取床位信息
  8168. for _, it := range numberList {
  8169. if item.BedId == it.ID {
  8170. monitor[key].DeviceNumber = it
  8171. break
  8172. }
  8173. }
  8174. //获取分区信息
  8175. for _, it := range zoneList {
  8176. if item.PartitionId == it.ID {
  8177. monitor[key].DeviceZone = it
  8178. }
  8179. }
  8180. for _, prescription := range prescriptions {
  8181. if item.PatientId == prescription.PatientId {
  8182. monitor[key].Prescription = prescription
  8183. break
  8184. }
  8185. }
  8186. for _, it := range checkList {
  8187. if item.PatientId == it.PatientId {
  8188. monitor[key].DoubleCheck = it
  8189. break
  8190. }
  8191. }
  8192. for _, it := range summaryList {
  8193. if item.PatientId == it.PatientId {
  8194. monitor[key].TreatmentSummaryForList = it
  8195. break
  8196. }
  8197. }
  8198. // 透前评估
  8199. for _, assessmentBefore := range assessmentBefores {
  8200. if item.PatientId == assessmentBefore.PatientId {
  8201. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8202. break
  8203. }
  8204. }
  8205. // 透析上下机
  8206. for _, dialysisOrder := range dialysisOrders {
  8207. if item.PatientId == dialysisOrder.PatientId {
  8208. monitor[key].DialysisOrder = dialysisOrder
  8209. break
  8210. }
  8211. }
  8212. // 治疗小节
  8213. for _, afterDislysis := range AssessmentAfterDislysis {
  8214. if item.PatientId == afterDislysis.PatientId {
  8215. monitor[key].AssessmentAfterDislysis = afterDislysis
  8216. break
  8217. }
  8218. }
  8219. for _, it := range monitorlist {
  8220. if item.PatientId == it.PatientId {
  8221. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8222. }
  8223. }
  8224. for _, it := range adviceList {
  8225. if item.PatientId == it.PatientId {
  8226. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8227. }
  8228. }
  8229. for _, patient := range patients {
  8230. if item.PatientId == patient.ID {
  8231. monitor[key].MonitorPatients = patient
  8232. break
  8233. }
  8234. }
  8235. for _, treatment := range treatments {
  8236. if item.ModeId == treatment.ID {
  8237. monitor[key].TreatmentMode = treatment
  8238. break
  8239. }
  8240. }
  8241. for _, infor := range informationList {
  8242. if item.PatientId == infor.PatientId {
  8243. monitor[key].NewDeviceInformation = infor
  8244. break
  8245. }
  8246. }
  8247. }
  8248. }
  8249. }
  8250. patients, err := service.GetAllpatientFourty(orgID)
  8251. var mds []*models.NewMonitorDialysisScheduleList
  8252. if pat_type == 0 {
  8253. for _, item := range monitor {
  8254. mds = append(mds, item)
  8255. }
  8256. }
  8257. //待医嘱核对
  8258. if pat_type == 1 {
  8259. for _, item := range monitor {
  8260. if len(item.AdviceList) > 0 {
  8261. mds = append(mds, item)
  8262. }
  8263. }
  8264. }
  8265. //待开小结
  8266. if pat_type == 2 {
  8267. for _, item := range monitor {
  8268. if item.TreatmentSummaryForList == nil {
  8269. mds = append(mds, item)
  8270. }
  8271. }
  8272. }
  8273. //待下机
  8274. if pat_type == 3 {
  8275. for _, item := range monitor {
  8276. if item.DialysisOrder != nil {
  8277. if item.DialysisOrder.ID > 0 {
  8278. mds = append(mds, item)
  8279. }
  8280. }
  8281. }
  8282. }
  8283. //待消毒
  8284. if pat_type == 4 {
  8285. for _, item := range monitor {
  8286. if item.NewDeviceInformation == nil {
  8287. mds = append(mds, item)
  8288. }
  8289. }
  8290. }
  8291. //待双人核对
  8292. if pat_type == 5 {
  8293. for _, item := range monitor {
  8294. if item.DoubleCheck == nil {
  8295. mds = append(mds, item)
  8296. }
  8297. }
  8298. }
  8299. //医嘱未执行
  8300. if pat_type == 6 {
  8301. for _, item := range monitor {
  8302. if len(item.AdviceList) > 0 {
  8303. mds = append(mds, item)
  8304. }
  8305. }
  8306. }
  8307. //患者未签名
  8308. if pat_type == 7 {
  8309. for _, item := range monitor {
  8310. if item.DialysisOrder != nil {
  8311. if item.DialysisOrder.ID > 0 {
  8312. mds = append(mds, item)
  8313. }
  8314. }
  8315. }
  8316. }
  8317. //目标超滤于实际超滤不同
  8318. if pat_type == 8 {
  8319. for _, item := range monitor {
  8320. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  8321. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  8322. mds = append(mds, item)
  8323. }
  8324. }
  8325. }
  8326. }
  8327. //血压少于5次
  8328. if pat_type == 9 {
  8329. for _, item := range monitor {
  8330. if len(item.MonitoringRecord) < 5 {
  8331. mds = append(mds, item)
  8332. }
  8333. }
  8334. }
  8335. if pat_type == 10 {
  8336. for _, item := range monitor {
  8337. if len(item.MonitoringRecord) == 0 {
  8338. mds = append(mds, item)
  8339. }
  8340. }
  8341. }
  8342. if pat_type == 11 {
  8343. for _, item := range monitor {
  8344. if len(item.MonitoringRecord) > 0 {
  8345. mds = append(mds, item)
  8346. }
  8347. }
  8348. }
  8349. if pat_type == 12 {
  8350. for _, item := range monitor {
  8351. if len(item.MonitoringRecord) > 0 {
  8352. mds = append(mds, item)
  8353. }
  8354. }
  8355. }
  8356. if err == nil {
  8357. c.ServeSuccessJSON(map[string]interface{}{
  8358. "monitor": mds,
  8359. "patients": patients,
  8360. })
  8361. } else {
  8362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8363. }
  8364. }