dialysis_api_controller.go 338KB

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