dialysis_api_controller.go 310KB

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