dialysis_api_controller.go 310KB

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