dialysis_api_controller.go 455KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768
  1. package mobile_api_controllers
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "math"
  7. "net/http"
  8. "net/url"
  9. "reflect"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "XT_New/enums"
  14. "XT_New/models"
  15. "XT_New/service"
  16. "XT_New/utils"
  17. "github.com/astaxie/beego"
  18. "github.com/jinzhu/gorm"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var projectsOne []*models.HisPrescriptionProject
  342. var stockType []*models.GoodsTypeOne
  343. var prepare []*models.XtDialysisBeforePrepare
  344. var lastAssessment models.XtPatientVascularAccess
  345. var lastDryWeightDislysis *models.SgjPatientDryweight
  346. var gobalConfig models.GobalConfig
  347. var operators []*models.SgjUserAdminRoles
  348. // 先走redis,没有走数据库
  349. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  350. go func() {
  351. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  352. ch <- struct{}{}
  353. }()
  354. go func() {
  355. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  356. ch <- struct{}{}
  357. }()
  358. go func() {
  359. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  360. ch <- struct{}{}
  361. }()
  362. go func() {
  363. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  364. ch <- struct{}{}
  365. }()
  366. go func() {
  367. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  368. ch <- struct{}{}
  369. }()
  370. go func() {
  371. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  372. ch <- struct{}{}
  373. }()
  374. go func() {
  375. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  376. ch <- struct{}{}
  377. }()
  378. go func() {
  379. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  380. ch <- struct{}{}
  381. }()
  382. go func() {
  383. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  384. ch <- struct{}{}
  385. }()
  386. go func() {
  387. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  388. ch <- struct{}{}
  389. }()
  390. go func() {
  391. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  392. ch <- struct{}{}
  393. }()
  394. go func() {
  395. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  396. ch <- struct{}{}
  397. }()
  398. go func() {
  399. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  400. ch <- struct{}{}
  401. }()
  402. go func() {
  403. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  404. ch <- struct{}{}
  405. }()
  406. go func() {
  407. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  408. ch <- struct{}{}
  409. }()
  410. go func() {
  411. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  412. ch <- struct{}{}
  413. }()
  414. go func() {
  415. // 先走redis,没有走数据库
  416. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  417. ch <- struct{}{}
  418. }()
  419. go func() {
  420. // 先走redis,没有走数据库
  421. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  422. ch <- struct{}{}
  423. }()
  424. go func() {
  425. // // 先走redis,没有走数据库
  426. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  427. ch <- struct{}{}
  428. }()
  429. go func() {
  430. // 先走redis,没有走数据库
  431. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  432. ch <- struct{}{}
  433. }()
  434. go func() {
  435. // //获取最后一次血管通路
  436. // 先走redis,没有走数据库
  437. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  438. ch <- struct{}{}
  439. }()
  440. go func() {
  441. // 先走redis,没有走数据库
  442. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  443. ch <- struct{}{}
  444. }()
  445. go func() {
  446. // 先走redis,没有走数据库
  447. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  448. ch <- struct{}{}
  449. }()
  450. go func() {
  451. // 先走redis,没有走数据库
  452. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  453. ch <- struct{}{}
  454. }()
  455. for range ch {
  456. // 每次从ch中接收数据,表明一个活动的协程结束
  457. count--
  458. // 当所有活动的协程都结束时,关闭管道
  459. if count == 0 {
  460. close(ch)
  461. }
  462. }
  463. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  464. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  465. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  466. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  468. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  469. var team_projects []*models.HisPrescriptionProject
  470. //var index int64 = 0
  471. for _, item := range temp_team_projects {
  472. //组套里面非检验项目的
  473. if item.HisProject.CostClassify != 3 && item.HisProject.CostClassify != 104 {
  474. projects = append(projects, item)
  475. }
  476. //组套里面检验项目的
  477. if item.HisProject.CostClassify == 3 || item.HisProject.CostClassify == 104 {
  478. team_projects = append(team_projects, item)
  479. }
  480. }
  481. //针对茂名舒和
  482. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  483. if len(projects) > 0 {
  484. for _, item := range projects {
  485. if item.Type == 2 {
  486. if item.HisProject.IsShow == 1 {
  487. projectsOne = append(projectsOne, item)
  488. }
  489. }
  490. if item.Type == 3 {
  491. if item.GoodInfo.IsShow == 1 {
  492. projectsOne = append(projectsOne, item)
  493. }
  494. }
  495. }
  496. }
  497. } else {
  498. for _, item := range projects {
  499. projectsOne = append(projectsOne, item)
  500. }
  501. }
  502. team_projects = RemoveRepeatedCheckRecod(team_projects)
  503. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  504. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  505. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  506. var his_advices []*models.HisDoctorAdviceInfo
  507. var his_advices_one []*models.HisDoctorAdviceInfo
  508. if is_open_config.IsOpen == 1 {
  509. // 先走redis,没有走数据库
  510. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  511. }
  512. //针对茂名舒和
  513. if adminInfo.Org.Id == 10666 || adminInfo.Org.Id == 10644 {
  514. if len(his_advices) > 0 {
  515. for _, item := range his_advices {
  516. drug, _ := service.GetDrugIsShow(item.DrugId, adminInfo.Org.Id)
  517. if drug.IsShow == 1 {
  518. his_advices_one = append(his_advices_one, item)
  519. }
  520. }
  521. }
  522. } else {
  523. if len(his_advices) > 0 {
  524. for _, item := range his_advices {
  525. his_advices_one = append(his_advices_one, item)
  526. }
  527. }
  528. }
  529. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  530. if is_advice_open.IsAdviceOpen == 1 {
  531. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  532. }
  533. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  534. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  535. var remind_lists []models.XtCheckRemind
  536. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  537. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  538. }
  539. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  540. lastAssesmentBeforDialysis, _ := service.GetLastAssessmentBeforDialysis(patientID, adminInfo.Org.Id)
  541. dryWeightList, _ := service.GetPatientDryList(patientID, adminInfo.Org.Id)
  542. lastMonitor, _ := service.GetLastMonitor(patientID, date.Unix(), adminInfo.Org.Id)
  543. firstMonitor, _ := service.GetFirstMonitorOne(patientID, date.Unix(), adminInfo.Org.Id)
  544. returnData := map[string]interface{}{
  545. "patient": patient,
  546. "schedual": schedual,
  547. "prescription": dialysisPrescribe,
  548. "solution": dialysisSolution,
  549. "last_prescription": lastDialysisPrescribe,
  550. "receiver_treatment_access": receiverTreatmentAccess,
  551. "predialysis_evaluation": predialysisEvaluation,
  552. "doctor_advices": doctorAdvices,
  553. "double_check": doubleCheck,
  554. "assessment_after_dislysis": assessmentAfterDislysis,
  555. "treatment_summary": treatmentSummary,
  556. "monitor_records": monitorRecords,
  557. "dialysis_order": dialysisOrder,
  558. "operators": operators,
  559. "last_predialysis_evaluation": lastPredialysisEvaluation,
  560. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  561. "last_monitor_record": lastMonitorRecord,
  562. "config": gobalConfig,
  563. "dry_weight": lastDryWeightDislysis,
  564. "system_prescription": systemDialysisPrescribe,
  565. "his_advices": his_advices_one,
  566. "is_open_config": is_open_config,
  567. "stockType": stockType,
  568. "prepare": prepare,
  569. "lastAssessment": lastAssessment,
  570. "prescribeOne": prescribeOne,
  571. "is_project_open_config": is_project_open_config,
  572. "project": projectsOne,
  573. "team_projects": team_projects,
  574. "is_advice_open": is_advice_open,
  575. "prescription_open": prescriptionConfig.IsOpen,
  576. "lastOrder": lastOrder,
  577. "remind_lists": remind_lists,
  578. "lastDialysisPrescription": lastDialysisPrescription,
  579. "lastAssesmentBeforDialysis": lastAssesmentBeforDialysis,
  580. "dryWeightList": dryWeightList,
  581. "firstMonitor": firstMonitor,
  582. "lastMonitor": lastMonitor,
  583. }
  584. this.ServeSuccessJSON(returnData)
  585. }
  586. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  587. adminInfo := c.GetMobileAdminUserInfo()
  588. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  589. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  590. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  591. returnData := map[string]interface{}{
  592. "admin_users": adminUsers,
  593. "devices": devices,
  594. "device_numbers": device_numbers,
  595. }
  596. c.ServeSuccessJSON(returnData)
  597. }
  598. func (c *DialysisAPIController) PostAtreatmentInfo() {
  599. id, _ := c.GetInt64("patient", 0)
  600. recordDateStr := c.GetString("record_date")
  601. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  602. summaryContent := c.GetString("summaryContent")
  603. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  604. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  605. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  606. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  607. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  608. nursingRecord := c.GetString("nursing_record")
  609. fmt.Println("护理记录", nursingRecord)
  610. specialRecord := c.GetString("special_record")
  611. fmt.Println("特殊记录", specialRecord)
  612. adminUserInfo := c.GetMobileAdminUserInfo()
  613. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  614. checkStaffId = adminUserInfo.AdminUser.Id
  615. deboardNurseId = adminUserInfo.AdminUser.Id
  616. treatDoctor = adminUserInfo.AdminUser.Id
  617. if id <= 0 {
  618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  619. return
  620. }
  621. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  622. if patient.ID == 0 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  624. return
  625. }
  626. if len(recordDateStr) == 0 {
  627. recordDateStr = time.Now().Format("2006-01-02")
  628. }
  629. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  630. if parseDateErr != nil {
  631. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  632. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. return
  634. }
  635. summary := models.TreatmentSummary{
  636. UserOrgId: adminUserInfo.Org.Id,
  637. PatientId: id,
  638. AssessmentDate: recordDate.Unix(),
  639. Mission: propagandaAndEducationContent,
  640. DialysisSummary: summaryContent,
  641. SjNurse: changeMedicalNurseId,
  642. ZlNurse: treatNurseId,
  643. HdNurse: checkStaffId,
  644. XjNurse: deboardNurseId,
  645. ZlDoctor: treatDoctor,
  646. CreatedTime: time.Now().Unix(),
  647. Status: 1,
  648. NursingRecord: nursingRecord,
  649. SpecialRecord: specialRecord,
  650. }
  651. // 查询信息规挡的设置天数
  652. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  653. if infor.ID > 0 && infor.WeekDay > 0 {
  654. var cha_time int64
  655. timeNowStr := time.Now().Format("2006-01-02")
  656. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  657. //今日的日期减去设置的日期
  658. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  659. if cha_time >= recordDate.Unix() {
  660. //查询审核是否允许
  661. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  662. //申请状态不允许的情况 拒绝修改
  663. if infor.ApplicationStatus != 1 {
  664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  665. return
  666. }
  667. }
  668. }
  669. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  670. if treatmentSummary.ID == 0 { //新增
  671. summary.Creater = adminUserInfo.AdminUser.Id
  672. service.AddSigleSummaryRecord(&summary)
  673. finish := models.XtDialysisFinish{
  674. IsFinish: 1,
  675. UserOrgId: adminUserInfo.Org.Id,
  676. Status: 1,
  677. Ctime: time.Now().Unix(),
  678. Mtime: 0,
  679. Module: 10,
  680. RecordDate: recordDate.Unix(),
  681. Sourse: 1,
  682. PatientId: id,
  683. }
  684. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  685. if dialysisFinish.ID == 0 {
  686. service.CreateDialysisFinish(finish)
  687. }
  688. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  689. redis := service.RedisClient()
  690. //清空key 值
  691. redis.Set(key, "", time.Second)
  692. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  693. redis.Set(keyOne, "", time.Second)
  694. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  695. redis.Set(keyThree, "", time.Second)
  696. defer redis.Close()
  697. c.ServeSuccessJSON(map[string]interface{}{
  698. "summary": summary,
  699. })
  700. } else { //修改
  701. summary.Creater = treatmentSummary.Creater
  702. summary.CreatedTime = treatmentSummary.CreatedTime
  703. summary.Modifier = adminUserInfo.AdminUser.Id
  704. summary.ID = treatmentSummary.ID
  705. service.UpdateSummeRecord(&summary)
  706. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  707. redis := service.RedisClient()
  708. //清空key 值
  709. redis.Set(key, "", time.Second)
  710. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  711. redis.Set(keyOne, "", time.Second)
  712. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  713. redis.Set(keyThree, "", time.Second)
  714. defer redis.Close()
  715. c.ServeSuccessJSON(map[string]interface{}{
  716. "summary": summary,
  717. })
  718. }
  719. }
  720. func (c *DialysisAPIController) PostDoubleCheck() {
  721. id, _ := c.GetInt64("patient", 0)
  722. recordDateStr := c.GetString("record_date")
  723. checkTimeStr := c.GetString("check_time")
  724. firstCheckTimeStr := c.GetString("first_check_time")
  725. creater, _ := c.GetInt64("creater", 0)
  726. modifier, _ := c.GetInt64("modifier", 0)
  727. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  728. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  729. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  730. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  731. dialysis_item_desc := c.GetString("dialysis_item_desc")
  732. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  733. vascular_access_desc := c.GetString("vascular_access_desc")
  734. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  735. collator, _ := c.GetInt64("collator", 0)
  736. employee_number := c.GetString("employee_number")
  737. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  738. needle_batch_number := c.GetString("needle_batch_number")
  739. if id <= 0 {
  740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  741. return
  742. }
  743. adminUserInfo := c.GetMobileAdminUserInfo()
  744. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  745. if patient.ID == 0 {
  746. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  747. return
  748. }
  749. if len(recordDateStr) == 0 {
  750. recordDateStr = time.Now().Format("2006-01-02")
  751. }
  752. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  753. if parseDateErr != nil {
  754. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  756. return
  757. }
  758. var checkDate int64
  759. if len(checkTimeStr) == 0 {
  760. checkDate = 0
  761. } else {
  762. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  763. checkDate = checkDateUnix.Unix()
  764. }
  765. var firstCheckDate int64
  766. if len(firstCheckTimeStr) == 0 {
  767. firstCheckDate = 0
  768. } else {
  769. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  770. firstCheckDate = firstCheckDateUnix.Unix()
  771. }
  772. if adminUserInfo.Org.Id == 10644 {
  773. list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  774. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  775. if check.ID == 0 {
  776. if employee_number != list.JobNumber {
  777. c.ServeSuccessJSON(map[string]interface{}{
  778. "doubleCheck": check,
  779. "msg": "2",
  780. })
  781. return
  782. }
  783. }
  784. if check.ID > 0 {
  785. if employee_number != list.JobNumber {
  786. c.ServeSuccessJSON(map[string]interface{}{
  787. "doubleCheck": check,
  788. "msg": "2",
  789. })
  790. return
  791. }
  792. }
  793. }
  794. doubleCheck := models.DoubleCheck{
  795. UserOrgId: adminUserInfo.Org.Id,
  796. PatientId: id,
  797. DialysisItemCheck: dialysis_item_check,
  798. DialysisParameterCheck: dialysis_parameter_check,
  799. VascularAccessVerification: vascular_access_verification,
  800. PipelineConnectionCheck: pipeline_connection_check,
  801. DialysisItemDesc: dialysis_item_desc,
  802. DialysisParameterDesc: dialysis_parameter_desc,
  803. VascularAccessDesc: vascular_access_desc,
  804. PipelineConnectionDesc: pipeline_connection_desc,
  805. Collator: collator,
  806. Status: 1,
  807. CreatedTime: time.Now().Unix(),
  808. CheckDate: recordDate.Unix(),
  809. UpdatedTime: time.Now().Unix(),
  810. EmployeeNumber: employee_number,
  811. DialyzerBatchNumber: dialyzer_batch_number,
  812. NeedleBatchNumber: needle_batch_number,
  813. }
  814. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  815. if check.ID == 0 { //新增
  816. doubleCheck.FirstCheckTime = firstCheckDate
  817. doubleCheck.CheckTime = checkDate
  818. doubleCheck.Creater = creater
  819. doubleCheck.Modifier = modifier
  820. if adminUserInfo.Org.Id == 10340 {
  821. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  822. doubleCheck.Creater = order.StartNurse
  823. }
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. for _, advice := range doctorList {
  828. if advice.ExecutionStaff == modifier {
  829. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  830. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  831. return
  832. }
  833. }
  834. }
  835. // 查询信息规挡的设置天数
  836. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  837. if infor.ID > 0 && infor.WeekDay > 0 {
  838. var cha_time int64
  839. timeNowStr := time.Now().Format("2006-01-02")
  840. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  841. //今日的日期减去设置的日期
  842. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  843. if cha_time >= recordDate.Unix() {
  844. //查询审核是否允许
  845. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  846. //申请状态不允许的情况 拒绝修改
  847. if infor.ApplicationStatus != 1 {
  848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  849. return
  850. }
  851. }
  852. }
  853. err := service.AddSigleDoubleCheck(&doubleCheck)
  854. finish := models.XtDialysisFinish{
  855. IsFinish: 1,
  856. UserOrgId: adminUserInfo.Org.Id,
  857. Status: 1,
  858. Ctime: time.Now().Unix(),
  859. Mtime: 0,
  860. Module: 5,
  861. RecordDate: recordDate.Unix(),
  862. Sourse: 1,
  863. PatientId: id,
  864. }
  865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  866. if dialysisFinish.ID == 0 {
  867. service.CreateDialysisFinish(finish)
  868. }
  869. //针对长沙南雅
  870. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  871. //查询未核对的医嘱
  872. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  873. if len(doctorList) > 0 && modifier > 0 {
  874. for _, advice := range doctorList {
  875. service.UpdateDoctorAdviceList(advice.ID, modifier)
  876. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  877. redis := service.RedisClient()
  878. //清空key 值
  879. redis.Set(key, "", time.Second)
  880. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  881. redis.Set(keyTwo, "", time.Second)
  882. theTime := time.Now()
  883. recordDate := theTime.Format("2006-01-02")
  884. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  885. redis.Set(keyFour, "", time.Second)
  886. defer redis.Close()
  887. }
  888. }
  889. }
  890. //针对溪康
  891. if adminUserInfo.Org.Id == 10721 {
  892. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  893. if len(adviceInfoList) > 0 {
  894. for _, item := range adviceInfoList {
  895. service.UpdateHisAdviceList(item.ID, creater)
  896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  897. redis := service.RedisClient()
  898. //清空key 值
  899. redis.Set(key, "", time.Second)
  900. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  901. redis.Set(keyTwo, "", time.Second)
  902. theTime := time.Now()
  903. recordDate := theTime.Format("2006-01-02")
  904. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  905. redis.Set(keyFour, "", time.Second)
  906. defer redis.Close()
  907. }
  908. }
  909. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  910. if len(adviceList) > 0 {
  911. for _, item := range adviceList {
  912. service.UpdateAdviceList(item.ID, creater)
  913. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  914. redis := service.RedisClient()
  915. //清空key 值
  916. redis.Set(key, "", time.Second)
  917. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  918. redis.Set(keyTwo, "", time.Second)
  919. theTime := time.Now()
  920. recordDate := theTime.Format("2006-01-02")
  921. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  922. redis.Set(keyFour, "", time.Second)
  923. defer redis.Close()
  924. }
  925. }
  926. }
  927. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  928. redis := service.RedisClient()
  929. //清空key 值
  930. redis.Set(key, "", time.Second)
  931. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  932. redis.Set(keyOne, "", time.Second)
  933. defer redis.Close()
  934. if err == nil {
  935. c.ServeSuccessJSON(map[string]interface{}{
  936. "doubleCheck": &doubleCheck,
  937. })
  938. }
  939. } else { //修改
  940. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  941. if infor.ID > 0 {
  942. var cha_time int64
  943. timeNowStr := time.Now().Format("2006-01-02")
  944. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  945. //今日的日期减去设置的日期
  946. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  947. if cha_time >= recordDate.Unix() {
  948. //查询审核是否允许
  949. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  950. //申请状态不允许的情况 拒绝修改
  951. if infor.ApplicationStatus != 1 {
  952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  953. return
  954. }
  955. }
  956. }
  957. doubleCheck.FirstCheckTime = firstCheckDate
  958. doubleCheck.CheckTime = checkDate
  959. doubleCheck.Creater = creater
  960. doubleCheck.Modifier = modifier
  961. doubleCheck.CreatedTime = check.CreatedTime
  962. doubleCheck.ID = check.ID
  963. doubleCheck.EmployeeNumber = employee_number
  964. doubleCheck.NeedleBatchNumber = needle_batch_number
  965. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  966. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  967. //查询未核对的医嘱
  968. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  969. for _, advice := range doctorList {
  970. if advice.ExecutionStaff == modifier {
  971. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  972. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  973. return
  974. }
  975. }
  976. }
  977. //针对溪康
  978. if adminUserInfo.Org.Id == 10721 {
  979. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  980. if len(adviceInfoList) > 0 {
  981. for _, item := range adviceInfoList {
  982. service.UpdateHisAdviceList(item.ID, creater)
  983. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  984. redis := service.RedisClient()
  985. //清空key 值
  986. redis.Set(key, "", time.Second)
  987. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  988. redis.Set(keyTwo, "", time.Second)
  989. theTime := time.Now()
  990. recordDate := theTime.Format("2006-01-02")
  991. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  992. redis.Set(keyFour, "", time.Second)
  993. defer redis.Close()
  994. }
  995. }
  996. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.Org.Id, id, recordDate.Unix())
  997. if len(adviceList) > 0 {
  998. for _, item := range adviceList {
  999. service.UpdateAdviceList(item.ID, creater)
  1000. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1001. redis := service.RedisClient()
  1002. //清空key 值
  1003. redis.Set(key, "", time.Second)
  1004. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1005. redis.Set(keyTwo, "", time.Second)
  1006. theTime := time.Now()
  1007. recordDate := theTime.Format("2006-01-02")
  1008. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1009. redis.Set(keyFour, "", time.Second)
  1010. defer redis.Close()
  1011. }
  1012. }
  1013. }
  1014. err := service.UpdateDoubleCheck(&doubleCheck)
  1015. //针对长沙南雅
  1016. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  1017. //查询未核对的医嘱
  1018. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1019. if len(doctorList) > 0 && modifier > 0 {
  1020. for _, advice := range doctorList {
  1021. service.UpdateDoctorAdviceList(advice.ID, modifier)
  1022. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  1023. redis := service.RedisClient()
  1024. //清空key 值
  1025. redis.Set(key, "", time.Second)
  1026. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  1027. redis.Set(keyTwo, "", time.Second)
  1028. theTime := time.Now()
  1029. recordDate := theTime.Format("2006-01-02")
  1030. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1031. redis.Set(keyFour, "", time.Second)
  1032. defer redis.Close()
  1033. }
  1034. }
  1035. }
  1036. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1037. redis := service.RedisClient()
  1038. //清空key 值
  1039. redis.Set(key, "", time.Second)
  1040. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1041. redis.Set(keyOne, "", time.Second)
  1042. defer redis.Close()
  1043. if err == nil {
  1044. c.ServeSuccessJSON(map[string]interface{}{
  1045. "doubleCheck": &doubleCheck,
  1046. "msg": "1",
  1047. })
  1048. }
  1049. }
  1050. }
  1051. func (c *DialysisAPIController) PostAcceptsAssessment() {
  1052. id, _ := c.GetInt64("patient", 0)
  1053. recordDateStr := c.GetString("record_date")
  1054. way, _ := c.GetInt64("way", 0)
  1055. consciousness, _ := c.GetInt64("consciousness", 0)
  1056. appetite, _ := c.GetInt64("appetite", 0)
  1057. condition, _ := c.GetInt64("condition", 0)
  1058. posture, _ := c.GetInt64("posture")
  1059. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1060. danger_level, _ := c.GetInt64("danger_level", 0)
  1061. intake, _ := c.GetInt64("intake", 0)
  1062. nutrition, _ := c.GetInt64("nutrition", 0)
  1063. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1064. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1065. score := c.GetString("score")
  1066. sick_condition_other := c.GetString("sick_condition_other")
  1067. //precaution, _ := c.GetInt64("precaution", 0)
  1068. precaution := c.GetString("precaution")
  1069. precaution_other := c.GetString("precaution_other")
  1070. psychological_other := c.GetString("psychological_other")
  1071. admission_number := c.GetString("admission_number")
  1072. tumble, _ := c.GetInt64("tumble")
  1073. diacrisis := c.GetString("diacrisis")
  1074. his_department := c.GetString("his_department")
  1075. his_bed := c.GetString("his_bed")
  1076. if id <= 0 {
  1077. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1078. return
  1079. }
  1080. adminUserInfo := c.GetMobileAdminUserInfo()
  1081. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1082. if patient.ID == 0 {
  1083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1084. return
  1085. }
  1086. //now := time.Now()
  1087. //year, month, day := now.Date()
  1088. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1089. //todayTimeStamp := today_time.Unix()
  1090. if len(recordDateStr) == 0 {
  1091. recordDateStr = time.Now().Format("2006-01-02")
  1092. }
  1093. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1094. if parseDateErr != nil {
  1095. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. // 查询信息规挡的设置天数
  1100. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1101. if infor.ID > 0 && infor.WeekDay > 0 {
  1102. var cha_time int64
  1103. timeNowStr := time.Now().Format("2006-01-02")
  1104. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1105. //今日的日期减去设置的日期
  1106. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1107. if cha_time >= recordDate.Unix() {
  1108. //查询审核是否允许
  1109. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1110. //申请状态不允许的情况 拒绝修改
  1111. if infor.ApplicationStatus != 1 {
  1112. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1113. return
  1114. }
  1115. }
  1116. }
  1117. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1118. if adminUserInfo.Org.Id == 10340 {
  1119. if condition == 1 {
  1120. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1121. if admission_number == "" {
  1122. admission_number = lastAcceptTreatment.AdmissionNumber
  1123. his_bed = lastAcceptTreatment.HisBed
  1124. his_department = lastAcceptTreatment.HisDepartment
  1125. tumble = lastAcceptTreatment.Tumble
  1126. }
  1127. }
  1128. }
  1129. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1130. UserOrgId: adminUserInfo.Org.Id,
  1131. PatientId: id,
  1132. RecordDate: recordDate.Unix(),
  1133. Way: way,
  1134. Consciousness: consciousness,
  1135. Appetite: appetite,
  1136. Condition: condition,
  1137. SickCondition: sick_condition,
  1138. DangerLevel: danger_level,
  1139. Intake: intake,
  1140. Nutrition: nutrition,
  1141. PsychologicalAssessment: psychological_assessment,
  1142. PsychologicalAssessmentOther: psychological_assessment_other,
  1143. SickConditionOther: sick_condition_other,
  1144. Posture: posture,
  1145. CreatedTime: time.Now().Unix(),
  1146. UpdateTime: time.Now().Unix(),
  1147. Status: 1,
  1148. Score: score,
  1149. Precaution: precaution,
  1150. PrecautionOther: precaution_other,
  1151. PsychologicalOther: psychological_other,
  1152. AdmissionNumber: admission_number,
  1153. Tumble: tumble,
  1154. Diacrisis: diacrisis,
  1155. HisBed: his_bed,
  1156. HisDepartment: his_department,
  1157. }
  1158. if receiveTreatment.ID == 0 { //新增
  1159. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1160. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1161. finish := models.XtDialysisFinish{
  1162. IsFinish: 1,
  1163. UserOrgId: adminUserInfo.Org.Id,
  1164. Status: 1,
  1165. Ctime: time.Now().Unix(),
  1166. Mtime: 0,
  1167. Module: 2,
  1168. RecordDate: recordDate.Unix(),
  1169. Sourse: 1,
  1170. PatientId: id,
  1171. }
  1172. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1173. if dialysisFinish.ID == 0 {
  1174. service.CreateDialysisFinish(finish)
  1175. }
  1176. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1177. redis := service.RedisClient()
  1178. defer redis.Close()
  1179. //清空key 值
  1180. redis.Set(key, "", time.Second)
  1181. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1182. redis.Set(keyOne, "", time.Second)
  1183. if err == nil {
  1184. c.ServeSuccessJSON(map[string]interface{}{
  1185. "receiveTreatmentAsses": receiveTreatmentAsses,
  1186. })
  1187. }
  1188. } else { //修改
  1189. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1190. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1191. // if getPermissionErr != nil {
  1192. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1193. // return
  1194. // } else if headNursePermission == nil {
  1195. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1196. // return
  1197. // }
  1198. //}
  1199. // 查询信息规挡的设置天数
  1200. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1201. if infor.ID > 0 && infor.WeekDay > 0 {
  1202. var cha_time int64
  1203. timeNowStr := time.Now().Format("2006-01-02")
  1204. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1205. //今日的日期减去设置的日期
  1206. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1207. if cha_time >= recordDate.Unix() {
  1208. //查询审核是否允许
  1209. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1210. //申请状态不允许的情况 拒绝修改
  1211. if infor.ApplicationStatus != 1 {
  1212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1213. return
  1214. }
  1215. }
  1216. }
  1217. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1218. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1219. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1220. receiveTreatmentAsses.ID = receiveTreatment.ID
  1221. if adminUserInfo.Org.Id == 10340 {
  1222. if condition == 1 {
  1223. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.Org.Id, id)
  1224. if receiveTreatmentAsses.AdmissionNumber == "" {
  1225. receiveTreatmentAsses.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  1226. }
  1227. }
  1228. }
  1229. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1230. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1231. redis := service.RedisClient()
  1232. defer redis.Close()
  1233. //清空key 值
  1234. redis.Set(key, "", time.Second)
  1235. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1236. redis.Set(keyOne, "", time.Second)
  1237. if err == nil {
  1238. c.ServeSuccessJSON(map[string]interface{}{
  1239. "receiveTreatmentAsses": receiveTreatmentAsses,
  1240. })
  1241. }
  1242. }
  1243. }
  1244. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1245. id, _ := c.GetInt64("patient", 0)
  1246. recordDateStr := c.GetString("record_date")
  1247. weightAfter, _ := c.GetFloat("weight_after", 0)
  1248. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1249. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1250. fmt.Println("weight_loss", weightReduce)
  1251. temperature, _ := c.GetFloat("temperature", 0)
  1252. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1253. breathing_rate := c.GetString("breathing_rate")
  1254. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1255. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1256. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1257. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1258. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1259. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1260. cruor := c.GetString("cruor")
  1261. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1262. internalFistula := c.GetString("internal_fistula")
  1263. catheter := c.GetString("catheter")
  1264. complications := c.GetString("complication")
  1265. remark := c.GetString("remark")
  1266. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1267. dialysis_intakes := c.GetString("dialysis_intakes")
  1268. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1269. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1270. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1271. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1272. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1273. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1274. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1275. patientGose, _ := c.GetInt64("patient_gose", 0)
  1276. inpatientDepartment := c.GetString("inpatient_department")
  1277. observationContent := c.GetString("observation_content")
  1278. observationContentOther := c.GetString("observation_content_other")
  1279. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1280. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1281. in_advance_reason := c.GetString("in_advance_reason")
  1282. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1283. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1284. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1285. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1286. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1287. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1288. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1289. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1290. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1291. is_eat, _ := c.GetInt64("is_eat", 0)
  1292. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1293. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1294. channels, _ := c.GetInt64("channel", 0)
  1295. return_blood, _ := c.GetInt64("return_blood", 0)
  1296. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1297. //dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1298. dialysis_during, _ := c.GetFloat("dialysis_during")
  1299. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1300. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1301. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1302. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1303. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1304. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1305. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1306. setting_pressure := c.GetString("setting_pressure")
  1307. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1308. diastolic_pressure := c.GetString("diastolic_pressure")
  1309. other_complication := c.GetString("other_complication")
  1310. ktv := c.GetString("ktv")
  1311. urr := c.GetString("urr")
  1312. hypertenison, _ := c.GetInt64("hypertenison")
  1313. hypopiesia, _ := c.GetInt64("hypopiesia")
  1314. leave_office_method, _ := c.GetInt64("leave_office_method")
  1315. lapse, _ := c.GetInt64("lapse")
  1316. consciousness, _ := c.GetInt64("consciousness")
  1317. fallrisk, _ := c.GetInt64("fallrisk")
  1318. machine_run := c.GetString("machine_run")
  1319. after_urea := c.GetString("after_urea")
  1320. pip_coagulation := c.GetString("pip_coagulation")
  1321. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1322. transfusion_volume := c.GetString("transfusion_volume")
  1323. last_after_weight := c.GetString("last_after_weight")
  1324. displace_liqui_value := c.GetString("displace_liqui_value")
  1325. start_time := c.GetString("start_time")
  1326. symptom_after_dialysis_remark := c.GetString("symptom_after_dialysis_remark")
  1327. if id <= 0 {
  1328. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1329. return
  1330. }
  1331. adminUserInfo := c.GetMobileAdminUserInfo()
  1332. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1333. if patient.ID == 0 {
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1335. return
  1336. }
  1337. if len(recordDateStr) == 0 {
  1338. recordDateStr = time.Now().Format("2006-01-02")
  1339. }
  1340. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1341. fmt.Println("parseDateErr", parseDateErr)
  1342. if parseDateErr != nil {
  1343. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1345. return
  1346. }
  1347. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  1348. //now := time.Now()
  1349. //year, month, day := now.Date()
  1350. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1351. //todayTimeStamp := today_time.Unix()
  1352. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1353. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1354. UserOrgId: adminUserInfo.Org.Id,
  1355. PatientId: id,
  1356. AssessmentDate: recordDate.Unix(),
  1357. Temperature: temperature,
  1358. PulseFrequency: pulse_frequency,
  1359. BreathingRate: breathing_rate,
  1360. SystolicBloodPressure: systolic_blood_pressure,
  1361. DiastolicBloodPressure: diastolic_blood_pressure,
  1362. ActualUltrafiltration: actual_ultrafiltration,
  1363. ActualDisplacement: actual_displacement,
  1364. ActualTreatmentHour: actualtreatHour,
  1365. ActualTreatmentMinute: actualtreatmin,
  1366. WeightAfter: weightAfter,
  1367. AdditionalWeight: additionalWeight,
  1368. WeightLoss: weightReduce,
  1369. Cruor: cruor,
  1370. SymptomAfterDialysis: symptomsAfterDialysi,
  1371. InternalFistula: internalFistula,
  1372. Catheter: catheter,
  1373. Complication: complications,
  1374. DialysisIntakes: dialysateVolume,
  1375. CreatedTime: time.Now().Unix(),
  1376. UpdatedTime: time.Now().Unix(),
  1377. Status: 1,
  1378. Remark: remark,
  1379. BloodAccessPartId: blood_access_part_id,
  1380. BloodAccessPartOperaId: blood_access_part_opera_id,
  1381. DialysisIntakesUnit: dialysis_intakes_unit,
  1382. PuncturePointOozingBlood: puncturePointOozingBlood,
  1383. PuncturePointHaematoma: puncturePointHaematoma,
  1384. InternalFistulaTremorAc: internalFistulaTremorAc,
  1385. PatientGose: patientGose,
  1386. InpatientDepartment: inpatientDepartment,
  1387. ObservationContent: observationContent,
  1388. ObservationContentOther: observationContentOther,
  1389. DialysisProcess: dialysis_process,
  1390. InAdvanceMinute: in_advance_minute,
  1391. InAdvanceReason: in_advance_reason,
  1392. HemostasisMinute: hemostasis_minute,
  1393. HemostasisOpera: hemostasis_opera,
  1394. TremorNoise: tremor_noise,
  1395. DisequilibriumSyndrome: disequilibrium_syndrome,
  1396. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1397. ArterialTube: arterial_tube,
  1398. IntravenousTube: intravenous_tube,
  1399. Dialyzer: dialyzer,
  1400. InAdvanceReasonOther: in_advance_reason_other,
  1401. IsEat: is_eat,
  1402. CvcA: cvc_a,
  1403. CvcV: cvc_v,
  1404. Channel: channels,
  1405. ReturnBlood: return_blood,
  1406. RehydrationVolume: rehydration_volume,
  1407. DialysisDuring: dialysis_during,
  1408. StrokeVolume: stroke_volume,
  1409. BloodFlow: blood_flow,
  1410. SealingFluidDispose: sealing_fluid_dispose,
  1411. SealingFluidSpecial: sealing_fluid_special,
  1412. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1413. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1414. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1415. SettingPressure: setting_pressure,
  1416. DiastolicPressure: diastolic_pressure,
  1417. OtherComplication: other_complication,
  1418. Ktv: ktv,
  1419. Urr: urr,
  1420. Hypopiesia: hypopiesia,
  1421. Hypertenison: hypertenison,
  1422. Lapse: lapse,
  1423. LeaveOfficeMethod: leave_office_method,
  1424. Consciousness: consciousness,
  1425. Fallrisk: fallrisk,
  1426. MachineRun: machine_run,
  1427. AfterUrea: after_urea,
  1428. PipCoagulation: pip_coagulation,
  1429. AccumulatedBloodVolume: accumulated_blood_volume,
  1430. TransfusionVolume: transfusion_volume,
  1431. LastAfterWeight: last_after_weight,
  1432. DisplaceLiquiValue: displace_liqui_value,
  1433. RecordTime: startDate.Unix(),
  1434. SymptomAfterDialysisRemark: symptom_after_dialysis_remark,
  1435. }
  1436. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1437. // 查询信息规挡的设置天数
  1438. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1439. if infor.ID > 0 && infor.WeekDay > 0 {
  1440. var cha_time int64
  1441. timeNowStr := time.Now().Format("2006-01-02")
  1442. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1443. //今日的日期减去设置的日期
  1444. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1445. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1446. if cha_time >= recordDate.Unix() {
  1447. //查询审核是否允许
  1448. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1449. //申请状态不允许的情况 拒绝修改
  1450. if infor.ApplicationStatus != 1 {
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1452. return
  1453. }
  1454. }
  1455. }
  1456. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1457. if assessmentAfter.ID == 0 { //新增
  1458. if appRole.UserType == 2 || appRole.UserType == 1 {
  1459. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1460. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1461. } else {
  1462. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1463. }
  1464. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1465. if assessmentAfterDislysis.UserOrgId != 10340 {
  1466. if assessmentAfterDislysis.WeightAfter == 0 {
  1467. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1468. }
  1469. }
  1470. if adminUserInfo.Org.Id == 10693 {
  1471. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1472. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1473. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1474. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1475. }
  1476. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1477. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1478. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1479. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1480. }
  1481. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1482. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1483. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1484. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1485. }
  1486. if assessmentAfterDislysis.PulseFrequency == 0 {
  1487. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1488. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1489. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1490. }
  1491. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1492. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1493. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1494. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1495. }
  1496. }
  1497. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1498. //记录日志
  1499. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1500. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1501. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1502. PatientId: assessmentAfterDislysis.PatientId,
  1503. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1504. Status: 1,
  1505. ErrLog: string(byterequest),
  1506. AdminUserId: adminUserInfo.AdminUser.Id,
  1507. Ctime: 0,
  1508. Mtime: 0,
  1509. Source: "手机端保存透后评估",
  1510. }
  1511. service.CreateAfterDialysisLog(afterDialysisLog)
  1512. finish := models.XtDialysisFinish{
  1513. IsFinish: 1,
  1514. UserOrgId: adminUserInfo.Org.Id,
  1515. Status: 1,
  1516. Ctime: time.Now().Unix(),
  1517. Mtime: 0,
  1518. Module: 9,
  1519. RecordDate: recordDate.Unix(),
  1520. Sourse: 1,
  1521. PatientId: id,
  1522. }
  1523. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1524. if dialysisFinish.ID == 0 {
  1525. service.CreateDialysisFinish(finish)
  1526. }
  1527. redis := service.RedisClient()
  1528. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1529. redis.Set(keyTwo, "", time.Second)
  1530. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1531. //清空key 值
  1532. redis.Set(key, "", time.Second)
  1533. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1534. redis.Set(keyOne, "", time.Second)
  1535. defer redis.Close()
  1536. if err == nil {
  1537. c.ServeSuccessJSON(map[string]interface{}{
  1538. "assessmentAfterDislysis": assessmentAfterDislysis,
  1539. })
  1540. }
  1541. return
  1542. } else { //修改
  1543. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1544. if infor.ID > 0 && infor.WeekDay > 0 {
  1545. var cha_time int64
  1546. timeNowStr := time.Now().Format("2006-01-02")
  1547. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1548. //今日的日期减去设置的日期
  1549. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1550. if cha_time >= recordDate.Unix() {
  1551. //查询审核是否允许
  1552. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1553. //申请状态不允许的情况 拒绝修改
  1554. if infor.ApplicationStatus != 1 {
  1555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1556. return
  1557. }
  1558. }
  1559. }
  1560. if appRole.UserType == 2 || appRole.UserType == 1 {
  1561. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1562. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1563. } else {
  1564. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1565. if assessmentAfterDislysis.Creater == 0 {
  1566. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1567. }
  1568. }
  1569. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1570. assessmentAfterDislysis.ID = assessmentAfter.ID
  1571. recordDialysis, _ := service.GetSigleAssessmentAfterDislysisRecord(assessmentAfterDislysis.PatientId, assessmentAfter.AssessmentDate, assessmentAfter.UserOrgId)
  1572. if assessmentAfterDislysis.UserOrgId != 10340 {
  1573. if assessmentAfterDislysis.WeightAfter == 0 {
  1574. assessmentAfterDislysis.WeightAfter = recordDialysis.WeightAfter
  1575. }
  1576. }
  1577. if adminUserInfo.Org.Id == 10693 {
  1578. if assessmentAfterDislysis.ActualUltrafiltration == 0 {
  1579. lastRecord, _ := service.GetLastMonitorRecordTwenty(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1580. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(lastRecord.UltrafiltrationVolumeOne, 64)
  1581. assessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  1582. }
  1583. if assessmentAfterDislysis.SystolicBloodPressure == 0 {
  1584. lastRecord, _ := service.GetLastMonitorRecordTwentyOne(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1585. systolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorSystolicBloodPressureOne, 64)
  1586. assessmentAfterDislysis.SystolicBloodPressure = systolicBloodPressureOne
  1587. }
  1588. if assessmentAfterDislysis.DiastolicBloodPressure == 0 {
  1589. lastRecord, _ := service.GetLastMonitorRecordTwentyTwo(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1590. MonitorDiastolicBloodPressureOne, _ := strconv.ParseFloat(lastRecord.MonitorDiastolicBloodPressureOne, 64)
  1591. assessmentAfterDislysis.DiastolicBloodPressure = MonitorDiastolicBloodPressureOne
  1592. }
  1593. if assessmentAfterDislysis.PulseFrequency == 0 {
  1594. lastRecord, _ := service.GetLastMonitorRecordTwentyThree(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1595. PulseFrequencyOne, _ := strconv.ParseFloat(lastRecord.PulseFrequencyOne, 64)
  1596. assessmentAfterDislysis.PulseFrequency = PulseFrequencyOne
  1597. }
  1598. if assessmentAfterDislysis.ActualDisplacement == 0 {
  1599. lastRecord, _ := service.GetLastMonitorRecordTwentyFour(adminUserInfo.Org.Id, id, assessmentAfter.AssessmentDate)
  1600. DisplacementQuantityOne, _ := strconv.ParseFloat(lastRecord.DisplacementQuantityOne, 64)
  1601. assessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  1602. }
  1603. }
  1604. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1605. //记录日志
  1606. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1607. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1608. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1609. PatientId: assessmentAfterDislysis.PatientId,
  1610. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1611. Status: 1,
  1612. ErrLog: string(byterequest),
  1613. AdminUserId: adminUserInfo.AdminUser.Id,
  1614. Ctime: time.Now().Unix(),
  1615. Mtime: 0,
  1616. Source: "手机端修改保存透后评估",
  1617. }
  1618. service.CreateAfterDialysisLog(afterDialysisLog)
  1619. redis := service.RedisClient()
  1620. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1621. redis.Set(keyTwo, "", time.Second)
  1622. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1623. //清空key 值
  1624. redis.Set(key, "", time.Second)
  1625. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1626. redis.Set(keyOne, "", time.Second)
  1627. if err == nil {
  1628. c.ServeSuccessJSON(map[string]interface{}{
  1629. "assessmentAfterDislysis": assessmentAfterDislysis,
  1630. })
  1631. return
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func (c *DialysisAPIController) PostDialysisPrescription() {
  1637. id, _ := c.GetInt64("patient", 0)
  1638. recordDateStr := c.GetString("record_date")
  1639. if id <= 0 {
  1640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1641. return
  1642. }
  1643. adminUserInfo := c.GetMobileAdminUserInfo()
  1644. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1645. if patient.ID == 0 {
  1646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1647. return
  1648. }
  1649. if len(recordDateStr) == 0 {
  1650. recordDateStr = time.Now().Format("2006-01-02")
  1651. }
  1652. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1653. if parseDateErr != nil {
  1654. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1655. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1656. return
  1657. }
  1658. mode_id, _ := c.GetInt64("mode_id", 0)
  1659. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1660. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1661. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1662. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1663. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1664. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1665. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1666. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1667. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1668. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1669. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1670. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1671. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1672. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1673. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1674. kalium, _ := c.GetFloat("kalium", 0)
  1675. sodium, _ := c.GetFloat("sodium", 0)
  1676. calcium, _ := c.GetFloat("calcium", 0)
  1677. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1678. glucose, _ := c.GetFloat("glucose", 0)
  1679. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1680. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1681. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1682. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1683. conductivity, _ := c.GetFloat("conductivity", 0)
  1684. remark := c.GetString("remark")
  1685. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1686. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1687. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1688. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1689. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1690. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1691. special_medicine_other := c.GetString("special_medicine_other")
  1692. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1693. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1694. blood_access, _ := c.GetInt64("blood_access", 0)
  1695. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1696. body_fluid_other := c.GetString("body_fluid_other")
  1697. niprocart, _ := c.GetInt64("niprocart", 0)
  1698. jms, _ := c.GetInt64("jms", 0)
  1699. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1700. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1701. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1702. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1703. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1704. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1705. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1706. injector, _ := c.GetInt64("injector", 0)
  1707. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1708. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1709. safe_package, _ := c.GetInt64("package", 0)
  1710. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1711. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1712. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1713. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1714. blood := c.GetString("blood")
  1715. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1716. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1717. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1718. displace_speed := c.GetString("displace_speed")
  1719. illness, _ := c.GetInt64("illness")
  1720. amylaceum := c.GetString("amylaceum")
  1721. single_time := c.GetString("single_time")
  1722. single_water := c.GetString("single_water")
  1723. replacement_flow := c.GetString("replacement_flow")
  1724. plasma_separator := c.GetString("plasma_separator")
  1725. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1726. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1727. oxygen_flow := c.GetString("oxygen_flow")
  1728. oxygen_time := c.GetString("oxygen_time")
  1729. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1730. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1731. puncture_needle := c.GetString("puncture_needle")
  1732. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1733. epo := c.GetString("epo")
  1734. epo_count, _ := c.GetFloat("epo_count", 0)
  1735. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1736. admin_user_id, _ := c.GetInt64("admin_user_id")
  1737. is_water := c.GetString("is_water")
  1738. var is_war int64
  1739. if is_water == "是" {
  1740. is_war = 1
  1741. }
  1742. if is_water == "否" {
  1743. is_war = 2
  1744. }
  1745. if is_water == "请选择" {
  1746. is_war = 0
  1747. }
  1748. drhy_water := c.GetString("drhy_water")
  1749. dry_water_hour := c.GetString("dry_water_hour")
  1750. water_machine := c.GetString("water_machine")
  1751. add_amount, _ := c.GetFloat("add_amount")
  1752. reduce_amount, _ := c.GetFloat("reduce_amount")
  1753. dialysis_remark := c.GetString("dialysis_remark")
  1754. prescribing_number, _ := c.GetFloat("prescribing_number")
  1755. prescription_sodium := c.GetString("prescription_sodium")
  1756. start_sodium := c.GetString("start_sodium")
  1757. sodium_curve := c.GetString("sodium_curve")
  1758. treatment_remark := c.GetString("treatment_remark")
  1759. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1760. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1761. prescription_water, _ := c.GetFloat("prescription_water")
  1762. dialysis_strainer := c.GetString("dialysis_strainer")
  1763. chaptalization := c.GetString("chaptalization")
  1764. washing_time := c.GetString("washing_time")
  1765. warsh_count := c.GetString("warsh_count")
  1766. blood_access_part_id := c.GetString("blood_access_part_id")
  1767. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1768. dialyzate := c.GetString("dialyzate")
  1769. first_super := c.GetString("first_super")
  1770. var first_sup int64
  1771. if first_super == "是" {
  1772. first_sup = 1
  1773. }
  1774. if first_super == "否" {
  1775. first_sup = 2
  1776. }
  1777. if first_super == "请选择" {
  1778. first_sup = 0
  1779. }
  1780. is_sequential := c.GetString("is_sequential")
  1781. var is_sequent int64
  1782. if is_sequential == "是" {
  1783. is_sequent = 1
  1784. }
  1785. if is_sequential == "否" {
  1786. is_sequent = 2
  1787. }
  1788. if is_sequential == "请选择" {
  1789. is_sequent = 0
  1790. }
  1791. conduct := c.GetString("conduct")
  1792. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1793. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1794. //
  1795. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1796. // if appRole.UserType == 3 {
  1797. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1798. // if getPermissionErr != nil {
  1799. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1800. // return
  1801. // } else if headNursePermission == nil {
  1802. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1803. // return
  1804. // }
  1805. // }
  1806. //}
  1807. // 查询信息规挡的设置天数
  1808. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1809. if infor.ID > 0 && infor.WeekDay > 0 {
  1810. var cha_time int64
  1811. timeNowStr := time.Now().Format("2006-01-02")
  1812. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1813. //今日的日期减去设置的日期
  1814. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1815. if cha_time >= recordDate.Unix() {
  1816. //查询审核是否允许
  1817. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1818. //申请状态不允许的情况 拒绝修改
  1819. if infor.ApplicationStatus != 1 {
  1820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1821. return
  1822. }
  1823. }
  1824. }
  1825. if mode_id > 0 {
  1826. var str string
  1827. //查找该机构用的是什么透析器
  1828. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1829. if filedConfig.ID > 0 {
  1830. str = dialyzerPerfusionApparatus
  1831. } else {
  1832. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1833. }
  1834. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1835. }
  1836. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  1837. var dialysis_dialyszers_id int64
  1838. var dialysis_strainer_id int64
  1839. var dialysis_irrigation_id int64
  1840. if len(goodList) > 0 {
  1841. for _, item := range goodList {
  1842. if item.SpecificationName == dialysis_dialyszers {
  1843. dialysis_dialyszers_id = item.ID
  1844. }
  1845. if item.SpecificationName == dialysis_irrigation {
  1846. dialysis_irrigation_id = item.ID
  1847. }
  1848. if item.SpecificationName == dialysis_strainer {
  1849. dialysis_strainer_id = item.ID
  1850. }
  1851. }
  1852. }
  1853. //TODO 需要根据角色去判断
  1854. prescription := models.DialysisPrescription{
  1855. UserOrgId: adminUserInfo.Org.Id,
  1856. PatientId: id,
  1857. RecordDate: recordDate.Unix(),
  1858. ModeId: mode_id,
  1859. DialysisDuration: dialysis_duration,
  1860. Dialyzer: dialyzer,
  1861. PerfusionApparatus: perfusion_apparatus,
  1862. BloodFlowVolume: blood_flow_volume,
  1863. DewaterAmount: dewater_amount,
  1864. DisplaceLiqui: displace_liqui,
  1865. ReplacementWay: replacement_way,
  1866. Anticoagulant: anticoagulant,
  1867. AnticoagulantShouji: anticoagulant_shouji,
  1868. AnticoagulantWeichi: anticoagulant_weichi,
  1869. AnticoagulantZongliang: anticoagulant_zongliang,
  1870. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1871. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1872. Kalium: kalium,
  1873. Sodium: sodium,
  1874. Calcium: calcium,
  1875. Bicarbonate: bicarbonate,
  1876. Glucose: glucose,
  1877. // DryWeight: dry_weight,
  1878. DialysateFlow: dialysate_flow,
  1879. DialysateTemperature: dialysate_temperature,
  1880. // PrescriptionDoctor: prescription_doctor,
  1881. ReplacementTotal: replacement_total,
  1882. Conductivity: conductivity,
  1883. Remark: remark,
  1884. Status: 1,
  1885. CreatedTime: time.Now().Unix(),
  1886. UpdatedTime: time.Now().Unix(),
  1887. DialysisDurationMinute: dialysisDurationMinute,
  1888. DialysisDurationHour: dialysisDurationHour,
  1889. TargetUltrafiltration: targetUltrafiltration,
  1890. DialysateFormulation: dialysateFormulation,
  1891. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1892. BodyFluid: body_fluid,
  1893. SpecialMedicine: special_medicine,
  1894. SpecialMedicineOther: special_medicine_other,
  1895. DisplaceLiquiPart: displace_liqui_part,
  1896. DisplaceLiquiValue: displace_liqui_value,
  1897. BloodAccess: blood_access,
  1898. Ultrafiltration: ultrafiltration,
  1899. BodyFluidOther: body_fluid_other,
  1900. Niprocart: niprocart,
  1901. Jms: jms,
  1902. FistulaNeedleSet: fistula_needle_set,
  1903. FistulaNeedleSet16: fistula_needle_set_16,
  1904. Hemoperfusion: hemoperfusion,
  1905. DialyserSterilised: dialyser_sterilised,
  1906. Filtryzer: filtryzer,
  1907. Dialyzers: dialyzers,
  1908. Injector: injector,
  1909. Bloodlines: bloodlines,
  1910. TubingHemodialysis: tubing_hemodialysis,
  1911. Package: safe_package,
  1912. ALiquid: a_liquid,
  1913. TargetKtv: target_ktv,
  1914. PreImpulse: pre_impulse,
  1915. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1916. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1917. Blood: blood,
  1918. DialysisDialyszers: dialysis_dialyszers,
  1919. DialysisIrrigation: dialysis_irrigation,
  1920. AntioxidantCommodityName: antioxidant_commodity_name,
  1921. DisplaceSpeed: displace_speed,
  1922. Illness: illness,
  1923. Amylaceum: amylaceum,
  1924. SingleTime: single_time,
  1925. SingleWater: single_water,
  1926. ReplacementFlow: replacement_flow,
  1927. PlasmaSeparator: plasma_separator,
  1928. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1929. OxygenUptake: oxygen_uptake,
  1930. OxygenFlow: oxygen_flow,
  1931. OxygenTime: oxygen_time,
  1932. HemodialysisPipelines: hemodialysis_pipelines,
  1933. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1934. PunctureNeedle: puncture_needle,
  1935. PunctureNeedleCount: puncture_needle_count,
  1936. Epo: epo,
  1937. EpoCount: epo_count,
  1938. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1939. AdminUserId: admin_user_id,
  1940. IsWater: is_war,
  1941. DrhyWater: drhy_water,
  1942. DryWaterHour: dry_water_hour,
  1943. WaterMachine: water_machine,
  1944. AddAmount: add_amount,
  1945. ReduceAmount: reduce_amount,
  1946. DialysisRemark: dialysis_remark,
  1947. PrescribingNumber: prescribing_number,
  1948. StartSodium: start_sodium,
  1949. SodiumCurve: sodium_curve,
  1950. TreatmentRemark: treatment_remark,
  1951. PrescriptionSodium: prescription_sodium,
  1952. DialysisFluidFlow: dialysis_fluid_flow,
  1953. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1954. PrescriptionWater: prescription_water,
  1955. DialysisStrainer: dialysis_strainer,
  1956. Chaptalization: chaptalization,
  1957. WashingTime: washing_time,
  1958. WarshCount: warsh_count,
  1959. BloodAccessPartId: blood_access_part_id,
  1960. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1961. Dialyzate: dialyzate,
  1962. DialysisDialyszersId: dialysis_dialyszers_id,
  1963. DialysisIrrigationId: dialysis_irrigation_id,
  1964. DialysisStrainerId: dialysis_strainer_id,
  1965. FirstSuper: first_sup,
  1966. IsSequential: is_sequent,
  1967. Conduct: conduct,
  1968. }
  1969. if adminUserInfo.Org.Id == 10721 {
  1970. if prescription.ModeId == 2 {
  1971. if prescription.ReplacementTotal == 0 {
  1972. prescription.ReplacementTotal = 15
  1973. }
  1974. }
  1975. }
  1976. //查询最近透析准备表里是否存在 透析器 灌流器
  1977. //
  1978. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1979. //
  1980. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1981. //
  1982. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1983. //if len(mation)>0{
  1984. // for _, item := range splitStr {
  1985. // for _,it := range mation{
  1986. // if(item == it.SpecificationName){
  1987. //
  1988. // //查询最近一次的透析器
  1989. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1990. //
  1991. // if errcode == gorm.ErrRecordNotFound{
  1992. // //插入数据
  1993. // prepare := models.DialysisBeforePrepare{
  1994. // UserOrgId: adminUserInfo.Org.Id,
  1995. // PatientId: id,
  1996. // RecordDate: recordDate.Unix(),
  1997. // GoodTypeId: it.GoodTypeId,
  1998. // GoodId: it.ID,
  1999. // Count: 1,
  2000. // Ctime: time.Now().Unix(),
  2001. // Creater: adminUserInfo.AdminUser.Id,
  2002. // Status:1,
  2003. //
  2004. // }
  2005. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2006. // fmt.Println("",errcode)
  2007. // }
  2008. // }
  2009. // }
  2010. //
  2011. // }
  2012. //
  2013. // for _, item := range splitIrrigation {
  2014. // for _,it := range mation{
  2015. // if(item == it.SpecificationName){
  2016. // //查询最近一次的透析器
  2017. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  2018. // if errcode == gorm.ErrRecordNotFound{
  2019. // //插入数据
  2020. // prepare := models.DialysisBeforePrepare{
  2021. // UserOrgId: adminUserInfo.Org.Id,
  2022. // PatientId: id,
  2023. // RecordDate: recordDate.Unix(),
  2024. // GoodTypeId: it.GoodTypeId,
  2025. // GoodId: it.ID,
  2026. // Count: 1,
  2027. // Ctime: time.Now().Unix(),
  2028. // Creater: adminUserInfo.AdminUser.Id,
  2029. // Status:1,
  2030. //
  2031. // }
  2032. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  2033. // fmt.Println(errcode)
  2034. // }
  2035. // }
  2036. // }
  2037. // }
  2038. //}
  2039. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2040. if dialysisPrescription.ID == 0 { //新增
  2041. if appRole.UserType == 2 || appRole.UserType == 1 {
  2042. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2043. }
  2044. prescription.Creater = adminUserInfo.AdminUser.Id
  2045. //针对河间咸得
  2046. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  2047. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  2048. prescription.DisplaceLiquiPart = 0
  2049. prescription.DisplaceLiquiValue = 0
  2050. }
  2051. }
  2052. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  2053. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  2054. }
  2055. err := service.AddSigleRecord(&prescription)
  2056. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2057. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2058. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2059. if len(monitorList) > 0 {
  2060. var ultrafiltration_rate float64
  2061. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2062. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2063. var replacement_rate float64
  2064. //乘10 除10是为了保留一位小数
  2065. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2066. var firstOpeateTime = monitorList[0].OperateTime
  2067. for _, item := range monitorList {
  2068. //超滤率
  2069. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2070. //置换率
  2071. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2072. //超滤量
  2073. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2074. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2075. //置换量
  2076. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2077. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2078. }
  2079. }
  2080. }
  2081. //记录日志
  2082. byterequest, _ := json.Marshal(prescription)
  2083. prescriptionLog := models.XtDialysisPrescriptionLog{
  2084. UserOrgId: prescription.UserOrgId,
  2085. Ctime: time.Now().Unix(),
  2086. Mtime: 0,
  2087. ErrLog: string(byterequest),
  2088. AdminUserId: adminUserInfo.AdminUser.Id,
  2089. RecordDate: prescription.RecordDate,
  2090. PatientId: prescription.PatientId,
  2091. Source: "手机端新增保存处方",
  2092. Status: 1,
  2093. }
  2094. service.CreatePrescriptionLog(prescriptionLog)
  2095. finish := models.XtDialysisFinish{
  2096. IsFinish: 1,
  2097. UserOrgId: adminUserInfo.Org.Id,
  2098. Status: 1,
  2099. Ctime: time.Now().Unix(),
  2100. Mtime: 0,
  2101. Module: 1,
  2102. RecordDate: recordDate.Unix(),
  2103. Sourse: 1,
  2104. PatientId: id,
  2105. }
  2106. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2107. if dialysisFinish.ID == 0 {
  2108. service.CreateDialysisFinish(finish)
  2109. }
  2110. //长沙南雅医院,自动生成抗凝剂的临时处方
  2111. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2112. if prescribing_number == 0 {
  2113. prescribing_number = 1
  2114. }
  2115. if prescribing_number == 0 && id == 14682 {
  2116. prescribing_number = 2
  2117. }
  2118. if prescribing_number == 0 && id == 18560 {
  2119. prescribing_number = 2
  2120. }
  2121. advice := models.DoctorAdvice{
  2122. UserOrgId: adminUserInfo.Org.Id,
  2123. PatientId: id,
  2124. GroupNo: 0,
  2125. AdviceType: 2,
  2126. RecordDate: recordDate.Unix(),
  2127. AdviceDate: recordDate.Unix(),
  2128. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  2129. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  2130. AdviceDesc: "",
  2131. ReminderDate: 0,
  2132. SingleDose: anticoagulant_zongliang,
  2133. SingleDoseUnit: "iu",
  2134. DrugSpec: 0,
  2135. DrugSpecUnit: "",
  2136. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  2137. PrescribingNumberUnit: "支",
  2138. DeliveryWay: "静脉注射",
  2139. ExecutionFrequency: "上机前",
  2140. AdviceDoctor: 0,
  2141. Status: 1,
  2142. CreatedTime: time.Now().Unix(),
  2143. UpdatedTime: time.Now().Unix(),
  2144. IsPrescription: 1,
  2145. ExecutionState: 2,
  2146. StopState: 2,
  2147. IsSettle: 2,
  2148. }
  2149. // 查询排班信息
  2150. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  2151. if schedulePatient.ID > 0 {
  2152. if schedulePatient.ScheduleType == 1 {
  2153. advice.StartTime = recordDate.Unix() + 6.5*60*60
  2154. }
  2155. if schedulePatient.ScheduleType == 2 {
  2156. advice.StartTime = recordDate.Unix() + 9*60*60
  2157. }
  2158. }
  2159. // 抗凝剂名称
  2160. switch anticoagulant {
  2161. case 1:
  2162. advice.AdviceName = "无肝素"
  2163. break
  2164. case 2:
  2165. advice.AdviceName = "普通肝素"
  2166. break
  2167. case 3:
  2168. advice.AdviceName = "低分子肝素"
  2169. break
  2170. case 4:
  2171. advice.AdviceName = "阿加曲班"
  2172. break
  2173. case 5:
  2174. advice.AdviceName = "枸橼酸钠"
  2175. break
  2176. case 6:
  2177. advice.AdviceName = "低分子肝素钙"
  2178. break
  2179. case 7:
  2180. advice.AdviceName = "低分子肝素钠"
  2181. break
  2182. case 8:
  2183. advice.AdviceName = "依诺肝素"
  2184. break
  2185. case 9:
  2186. advice.AdviceName = "达肝素"
  2187. break
  2188. case 10:
  2189. advice.AdviceName = "体外抗凝"
  2190. break
  2191. case 11:
  2192. advice.AdviceName = "那曲肝素"
  2193. break
  2194. case 12:
  2195. advice.AdviceName = "无抗凝剂"
  2196. break
  2197. }
  2198. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  2199. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  2200. advice.AdviceDoctor = appRole.AdminUserId
  2201. }
  2202. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2203. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2204. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  2205. advice.AdviceName = "低分子肝素钠注射液"
  2206. // 修改患者临时医嘱里的抗凝剂医嘱
  2207. advice.ID = advicePrescription.ID
  2208. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2209. } else {
  2210. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  2211. advice.AdviceName = "低分子肝素钠注射液"
  2212. // 新增患者临时医嘱里的抗凝剂医嘱
  2213. service.CreateDoctorAdvice(&advice)
  2214. }
  2215. }
  2216. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2217. redis := service.RedisClient()
  2218. defer redis.Close()
  2219. //清空key 值
  2220. redis.Set(key, "", time.Second)
  2221. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2222. redis.Set(keyOne, "", time.Second)
  2223. }
  2224. //获取key,清空redis
  2225. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2226. redis := service.RedisClient()
  2227. //清空key 值
  2228. redis.Set(key, "", time.Second)
  2229. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2230. //清空key 值
  2231. redis.Set(keyOne, "", time.Second)
  2232. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  2233. //清空key 值
  2234. redis.Set(keyTwo, "", time.Second)
  2235. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2236. redis.Set(keySix, "", time.Second)
  2237. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2238. redis.Set(keySeven, "", time.Second)
  2239. if err == nil {
  2240. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2241. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  2242. //清空key 值
  2243. redis.Set(keyThree, "", time.Second)
  2244. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  2245. //清空key 值
  2246. redis.Set(keyFour, "", time.Second)
  2247. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  2248. redis.Set(keyFive, "", time.Second)
  2249. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2250. redis.Set(keySix, "", time.Second)
  2251. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2252. redis.Set(keySeven, "", time.Second)
  2253. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2254. //清空key 值
  2255. redis.Set(keyOne, "", time.Second)
  2256. if updateErr != nil {
  2257. utils.ErrorLog("%v", updateErr)
  2258. }
  2259. defer redis.Close()
  2260. c.ServeSuccessJSON(map[string]interface{}{
  2261. "prescription": prescription,
  2262. })
  2263. }
  2264. } else { //修改
  2265. //if mode_id > 0 {
  2266. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  2267. //}
  2268. //if template.TemplateId == 1 {
  2269. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  2270. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2271. // if getPermissionErr != nil {
  2272. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2273. // return
  2274. // } else if headNursePermission == nil {
  2275. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  2276. // return
  2277. // }
  2278. // }
  2279. //}
  2280. prescription.CreatedTime = dialysisPrescription.CreatedTime
  2281. prescription.Modifier = adminUserInfo.AdminUser.Id
  2282. if appRole.UserType == 2 || appRole.UserType == 1 {
  2283. prescription_doctor := adminUserInfo.AdminUser.Id
  2284. prescription.PrescriptionDoctor = prescription_doctor
  2285. } else {
  2286. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  2287. }
  2288. if dialysisPrescription.Creater == 0 { //体重称
  2289. prescription.Creater = adminUserInfo.AdminUser.Id
  2290. } else {
  2291. prescription.Creater = dialysisPrescription.Creater
  2292. if adminUserInfo.Org.Id == 9882 {
  2293. if appRole.UserType == 2 || appRole.UserType == 1 {
  2294. prescription_doctor := adminUserInfo.AdminUser.Id
  2295. prescription.PrescriptionDoctor = prescription_doctor
  2296. prescription.Creater = prescription_doctor
  2297. }
  2298. }
  2299. }
  2300. prescription.ID = dialysisPrescription.ID
  2301. if adminUserInfo.Org.Id == 10721 {
  2302. if prescription.ModeId == 2 {
  2303. if prescription.ReplacementTotal == 0 {
  2304. prescription.ReplacementTotal = 15
  2305. }
  2306. }
  2307. }
  2308. service.UpDateDialysisPrescription(&prescription)
  2309. //溪康 更改目标超滤量 同步监测里面的超滤量 超滤率 置换量 置换率
  2310. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  2311. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2312. if len(monitorList) > 0 {
  2313. var ultrafiltration_rate float64
  2314. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2315. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2316. var replacement_rate float64
  2317. //乘10 除10是为了保留一位小数
  2318. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2319. var firstOpeateTime = monitorList[0].OperateTime
  2320. for _, item := range monitorList {
  2321. //超滤率
  2322. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2323. //置换率
  2324. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2325. //超滤量
  2326. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2327. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2328. //置换量
  2329. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2330. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2331. }
  2332. }
  2333. }
  2334. //记录日志
  2335. byterequest, _ := json.Marshal(prescription)
  2336. prescriptionLog := models.XtDialysisPrescriptionLog{
  2337. UserOrgId: prescription.UserOrgId,
  2338. Ctime: time.Now().Unix(),
  2339. Mtime: 0,
  2340. ErrLog: string(byterequest),
  2341. AdminUserId: adminUserInfo.AdminUser.Id,
  2342. RecordDate: prescription.RecordDate,
  2343. PatientId: prescription.PatientId,
  2344. Source: "手机端修改处方",
  2345. Status: 1,
  2346. }
  2347. service.CreatePrescriptionLog(prescriptionLog)
  2348. finish := models.XtDialysisFinish{
  2349. IsFinish: 1,
  2350. UserOrgId: adminUserInfo.Org.Id,
  2351. Status: 1,
  2352. Ctime: time.Now().Unix(),
  2353. Mtime: 0,
  2354. Module: 1,
  2355. RecordDate: recordDate.Unix(),
  2356. Sourse: 1,
  2357. PatientId: id,
  2358. }
  2359. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2360. if dialysisFinish.ID == 0 {
  2361. service.CreateDialysisFinish(finish)
  2362. }
  2363. //修改处方
  2364. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2365. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2366. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2367. if advicePrescription.ID > 0 {
  2368. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2369. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2370. redis := service.RedisClient()
  2371. defer redis.Close()
  2372. //清空key 值
  2373. redis.Set(key, "", time.Second)
  2374. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2375. redis.Set(keyOne, "", time.Second)
  2376. }
  2377. }
  2378. //获取key,清空redis
  2379. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2380. redis := service.RedisClient()
  2381. //清空key 值
  2382. redis.Set(key, "", time.Second)
  2383. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2384. //清空key 值
  2385. redis.Set(keyOne, "", time.Second)
  2386. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2387. redis.Set(keySix, "", time.Second)
  2388. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2389. redis.Set(keySeven, "", time.Second)
  2390. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2391. keyTwoOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2392. //清空key 值
  2393. redis.Set(keyTwoOne, "", time.Second)
  2394. defer redis.Close()
  2395. if updateErr != nil {
  2396. utils.ErrorLog("%v", updateErr)
  2397. }
  2398. c.ServeSuccessJSON(map[string]interface{}{
  2399. "prescription": prescription,
  2400. })
  2401. }
  2402. }
  2403. func (c *DialysisAPIController) Finish() {
  2404. id, _ := c.GetInt64("patient", 0)
  2405. recordDateStr := c.GetString("record_date")
  2406. nurseID, _ := c.GetInt64("nurse")
  2407. end_time := c.GetString("end_time")
  2408. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2409. internal_fistula := c.GetString("blood_access_internal_fistula")
  2410. catheter := c.GetString("catheter")
  2411. cruor := c.GetString("cruor")
  2412. mission := c.GetString("mission")
  2413. condenser := c.GetString("condenser")
  2414. if id <= 0 || nurseID <= 0 {
  2415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2416. return
  2417. }
  2418. adminUserInfo := c.GetMobileAdminUserInfo()
  2419. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2420. if patient.ID == 0 {
  2421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2422. return
  2423. }
  2424. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2425. if getNurseErr != nil {
  2426. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2428. return
  2429. } else if nurse == nil {
  2430. c.ErrorLog("护士不存在")
  2431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2432. return
  2433. }
  2434. if len(recordDateStr) == 0 {
  2435. recordDateStr = time.Now().Format("2006-01-02")
  2436. }
  2437. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2438. if parseDateErr != nil {
  2439. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2441. return
  2442. }
  2443. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2444. if parseEndDateErr != nil {
  2445. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2446. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2447. return
  2448. }
  2449. // 查询信息规挡的设置天数
  2450. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2451. if infor.ID > 0 && infor.WeekDay > 0 {
  2452. var cha_time int64
  2453. timeNowStr := time.Now().Format("2006-01-02")
  2454. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2455. //今日的日期减去设置的日期
  2456. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2457. if cha_time >= recordDate.Unix() {
  2458. //查询审核是否允许
  2459. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2460. //申请状态不允许的情况 拒绝修改
  2461. if infor.ApplicationStatus != 1 {
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2463. return
  2464. }
  2465. }
  2466. }
  2467. //now := time.Now()
  2468. //year, month, day := now.Date()
  2469. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2470. //todayTimeStamp := today_time.Unix()
  2471. // 获取当天的第一条透析纪录
  2472. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2473. if getMonitorRecordsErr != nil {
  2474. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2476. return
  2477. }
  2478. // 获取当前的最后一条透析纪录
  2479. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2480. if getMonitorRecordsErr != nil {
  2481. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. return
  2484. }
  2485. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2486. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2487. if getAADErr != nil {
  2488. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2490. return
  2491. }
  2492. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2493. lastAssessmentAfterDislysisTwo, _ := service.MobileGetLastTimeAssessmentAfterDislysisTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2494. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2495. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2496. if assessmentAfterDislysis != nil {
  2497. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2498. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2499. } else {
  2500. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2501. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2502. tempassessmentAfterDislysis.Status = 1
  2503. tempassessmentAfterDislysis.PatientId = id
  2504. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2505. }
  2506. //长沙南雅
  2507. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2508. //获取最后一条透析处方数据
  2509. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2510. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2511. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2512. }
  2513. if dialysisOrder.Stage == 1 {
  2514. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2515. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2516. fmt.Println(value)
  2517. a, b := math.Modf(value)
  2518. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2519. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2520. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2521. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2522. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2523. }
  2524. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2525. //var num1 int64
  2526. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2527. //fmt.Println(num1)
  2528. //sub := float64(num1 / 3600)
  2529. //fmt.Println(sub)
  2530. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2531. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2532. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2533. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2534. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2535. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2536. if adminUserInfo.Org.Id != 10375 {
  2537. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2538. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2539. }
  2540. if adminUserInfo.Org.Id != 10445 {
  2541. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2542. }
  2543. //北方营口医院
  2544. if adminUserInfo.Org.Id == 10445 {
  2545. //获取最后一条透析处方数据
  2546. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2547. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2548. } else {
  2549. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2550. }
  2551. //新化博翔
  2552. if adminUserInfo.Org.Id == 10447 {
  2553. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2554. }
  2555. //阳春
  2556. if adminUserInfo.Org.Id == 10485 {
  2557. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2558. }
  2559. if adminUserInfo.Org.Id == 10551 {
  2560. //获取最后一条透析处方数据
  2561. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2562. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2563. }
  2564. if adminUserInfo.Org.Id == 10580 {
  2565. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2566. }
  2567. if adminUserInfo.Org.Id == 10612 {
  2568. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2569. }
  2570. //孝康
  2571. if adminUserInfo.Org.Id == 10693 {
  2572. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2573. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2574. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2575. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2576. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2577. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2578. tempassessmentAfterDislysis.PulseFrequency = pulseFrequency
  2579. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2580. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2581. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2582. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2583. }
  2584. if adminUserInfo.Org.Id == 10721 {
  2585. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2586. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2587. }
  2588. if adminUserInfo.Org.Id == 10697 {
  2589. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2590. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2591. lastWeightAfter.LastAfterWeight = floatAfeter
  2592. }
  2593. if adminUserInfo.Org.Id == 10624 {
  2594. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2595. }
  2596. }
  2597. 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 || adminUserInfo.Org.Id == 10693 || adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10735 || adminUserInfo.Org.Id == 10742 {
  2598. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2599. if adminUserInfo.Org.Id != 10702 {
  2600. if evaluation.SystolicBloodPressure == 0 {
  2601. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2602. if adminUserInfo.Org.Id == 10693 {
  2603. SystolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2604. evaluation.SystolicBloodPressure = SystolicBloodPressureOne
  2605. }
  2606. pre := models.PredialysisEvaluation{
  2607. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2608. }
  2609. fmt.Println("prew", pre)
  2610. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2611. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2612. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2613. redis := service.RedisClient()
  2614. redis.Set(key, "", time.Second)
  2615. redis.Set(keyOne, "", time.Second)
  2616. defer redis.Close()
  2617. fmt.Println(getNurseErr)
  2618. }
  2619. }
  2620. if adminUserInfo.Org.Id != 10702 {
  2621. if evaluation.DiastolicBloodPressure == 0 {
  2622. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2623. if adminUserInfo.Org.Id == 10693 {
  2624. DiastolicBloodPressureOne, _ := strconv.ParseFloat(fmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2625. evaluation.DiastolicBloodPressure = DiastolicBloodPressureOne
  2626. }
  2627. pres := models.PredialysisEvaluation{
  2628. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2629. }
  2630. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2631. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2632. redis := service.RedisClient()
  2633. redis.Set(key, "", time.Second)
  2634. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2635. redis.Set(keyOne, "", time.Second)
  2636. defer redis.Close()
  2637. fmt.Println(getNurseErr)
  2638. }
  2639. }
  2640. if adminUserInfo.Org.Id != 10702 {
  2641. if evaluation.PulseFrequency == 0 {
  2642. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2643. if adminUserInfo.Org.Id == 10693 {
  2644. pulseFrequency, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2645. evaluation.PulseFrequency = pulseFrequency
  2646. }
  2647. press := models.PredialysisEvaluation{
  2648. PulseFrequency: evaluation.PulseFrequency,
  2649. }
  2650. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2651. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2652. redis := service.RedisClient()
  2653. redis.Set(key, "", time.Second)
  2654. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2655. redis.Set(keyOne, "", time.Second)
  2656. defer redis.Close()
  2657. fmt.Println(getNurseErr)
  2658. }
  2659. }
  2660. if evaluation.Temperature == 0 {
  2661. evaluation.Temperature = fmonitorRecords.Temperature
  2662. press := models.PredialysisEvaluation{
  2663. Temperature: evaluation.Temperature,
  2664. }
  2665. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2666. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2667. redis := service.RedisClient()
  2668. redis.Set(key, "", time.Second)
  2669. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2670. redis.Set(keyOne, "", time.Second)
  2671. defer redis.Close()
  2672. fmt.Println(getNurseErr)
  2673. }
  2674. }
  2675. if adminUserInfo.Org.Id == 9583 {
  2676. //获取透析处方的最后一条数据
  2677. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2678. if diaerr != nil {
  2679. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2681. return
  2682. }
  2683. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2684. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2685. }
  2686. }
  2687. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2688. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2689. }
  2690. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2691. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2692. }
  2693. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2694. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2695. }
  2696. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10617 {
  2697. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2698. }
  2699. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2700. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2701. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2702. }
  2703. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2704. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2705. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2706. }
  2707. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2708. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2709. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2710. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2711. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2712. }
  2713. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10735 {
  2714. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2715. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2716. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2717. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2718. }
  2719. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2720. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2721. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2722. }
  2723. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2724. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2725. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2726. }
  2727. if lastAssessmentAfterDislysis != nil {
  2728. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2729. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2730. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2731. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2732. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2733. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2734. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2735. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2736. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2737. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2738. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2739. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2740. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2741. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2742. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2743. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2744. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2745. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2746. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2747. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2748. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2749. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2750. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2751. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2752. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2753. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2754. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2755. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2756. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2757. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2758. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2759. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2760. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2761. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2762. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2763. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2764. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2765. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2766. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2767. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2768. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2769. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2770. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2771. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2772. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2773. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2774. tempassessmentAfterDislysis.Ktv = lastAssessmentAfterDislysisTwo.Ktv
  2775. tempassessmentAfterDislysis.Urr = lastAssessmentAfterDislysisTwo.Urr
  2776. if tempassessmentAfterDislysis.PatientId == 18695 {
  2777. tempassessmentAfterDislysis.ActualDisplacement = 0
  2778. }
  2779. if adminUserInfo.Org.Id != 10375 {
  2780. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2781. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2782. }
  2783. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10598 {
  2784. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2785. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2786. }
  2787. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10683 {
  2788. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2789. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2790. }
  2791. }
  2792. finish := models.XtDialysisFinish{
  2793. IsFinish: 1,
  2794. UserOrgId: adminUserInfo.Org.Id,
  2795. Status: 1,
  2796. Ctime: time.Now().Unix(),
  2797. Mtime: 0,
  2798. Module: 9,
  2799. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2800. Sourse: 1,
  2801. PatientId: tempassessmentAfterDislysis.PatientId,
  2802. }
  2803. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2804. if dialysisFinish.ID == 0 {
  2805. service.CreateDialysisFinish(finish)
  2806. }
  2807. //孝康
  2808. if adminUserInfo.Org.Id == 10693 {
  2809. MonitorSystolicBloodPressureOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorSystolicBloodPressureOne, 64)
  2810. tempassessmentAfterDislysis.SystolicBloodPressure = MonitorSystolicBloodPressureOne
  2811. DiastolicBloodPressure, _ := strconv.ParseFloat(endmonitorRecords.MonitorDiastolicBloodPressureOne, 64)
  2812. tempassessmentAfterDislysis.DiastolicBloodPressure = DiastolicBloodPressure
  2813. MonitorPulseFrequencyOne, _ := strconv.ParseFloat(endmonitorRecords.MonitorPulseFrequencyOne, 64)
  2814. tempassessmentAfterDislysis.PulseFrequency = MonitorPulseFrequencyOne
  2815. DisplacementQuantityOne, _ := strconv.ParseFloat(endmonitorRecords.DisplacementQuantityOne, 64)
  2816. tempassessmentAfterDislysis.ActualDisplacement = DisplacementQuantityOne
  2817. UltrafiltrationVolumeOne, _ := strconv.ParseFloat(endmonitorRecords.UltrafiltrationVolumeOne, 64)
  2818. tempassessmentAfterDislysis.ActualUltrafiltration = UltrafiltrationVolumeOne
  2819. }
  2820. if adminUserInfo.Org.Id == 10697 {
  2821. lastWeightAfter, _ := service.GetLastWeightAfter(tempassessmentAfterDislysis.PatientId, tempassessmentAfterDislysis.AssessmentDate, adminUserInfo.Org.Id)
  2822. floatAfeter := strconv.FormatFloat(lastWeightAfter.WeightAfter, 'f', -1, 64)
  2823. lastWeightAfter.LastAfterWeight = floatAfeter
  2824. }
  2825. if adminUserInfo.Org.Id == 10721 {
  2826. tempassessmentAfterDislysis.DiastolicBloodPressure = 0
  2827. tempassessmentAfterDislysis.SystolicBloodPressure = 0
  2828. }
  2829. tempassessmentAfterDislysis.RecordTime = dialysisOrder.EndTime
  2830. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2831. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2832. redis := service.RedisClient()
  2833. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2834. redis.Set(keyOne, "", time.Second)
  2835. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2836. redis.Set(keyTwo, "", time.Second)
  2837. defer redis.Close()
  2838. //清空key 值
  2839. redis.Set(key, "", time.Second)
  2840. if err != nil {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2842. return
  2843. }
  2844. if dialysisOrder == nil {
  2845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2846. return
  2847. }
  2848. if dialysisOrder.Stage == 2 {
  2849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2850. return
  2851. }
  2852. if dialysisOrder.Stage == 1 {
  2853. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2854. finish := models.XtDialysisFinish{
  2855. IsFinish: 1,
  2856. UserOrgId: adminUserInfo.Org.Id,
  2857. Status: 1,
  2858. Ctime: time.Now().Unix(),
  2859. Mtime: 0,
  2860. Module: 8,
  2861. RecordDate: recordDate.Unix(),
  2862. Sourse: 1,
  2863. PatientId: id,
  2864. }
  2865. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2866. if dialysisFinish.ID == 0 {
  2867. service.CreateDialysisFinish(finish)
  2868. }
  2869. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2870. redis := service.RedisClient()
  2871. defer redis.Close()
  2872. //清空key 值
  2873. redis.Set(key, "", time.Second)
  2874. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2875. redis.Set(keyOne, "", time.Second)
  2876. //结束时候透析次数加1
  2877. service.UpdateSolutionByPatientId(id)
  2878. //下机完自动消毒,针对长沙南雅
  2879. if dialysisOrder.Stage == 1 {
  2880. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9538 || adminUserInfo.Org.Id == 10121 || adminUserInfo.Org.Id == 10612 {
  2881. //根据床位号获取设备型号
  2882. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2883. //查询使用消毒最后一条消毒记录
  2884. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2885. fmt.Println("err", err)
  2886. if err == gorm.ErrRecordNotFound {
  2887. //查找排班
  2888. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2889. //查询改设备是否有消毒计划
  2890. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2891. //根据床位号获取设备id
  2892. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2893. //查询病人信息
  2894. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2895. var con = ""
  2896. if patients.IsInfectious == 0 {
  2897. con = ""
  2898. }
  2899. if patients.IsInfectious == 1 {
  2900. con = "无"
  2901. }
  2902. if patients.IsInfectious == 2 {
  2903. con = "有"
  2904. }
  2905. if errcode == nil {
  2906. var end_time int64
  2907. end_time = endDate.Unix() + plan.DisinfecTime*60
  2908. //新增消毒
  2909. information := models.DeviceInformation{
  2910. Date: dialysisOrder.DialysisDate,
  2911. Zone: dialysisOrder.ZoneId,
  2912. Class: dialysisOrder.SchedualType,
  2913. BedNumber: dialysisOrder.BedID,
  2914. PatientId: dialysisOrder.PatientId,
  2915. DialysisMode: scheduleByPatient.ModeId,
  2916. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2917. Disinfection: 1,
  2918. DialysisConcentration: 1,
  2919. DisinfectionStatus: 1,
  2920. Move: 1,
  2921. UserOrgId: dialysisOrder.UserOrgId,
  2922. DisinfectType: plan.Way,
  2923. DisinfectantType: plan.MachineDisinfectant,
  2924. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2925. Disinfectant: plan.Disinfectant,
  2926. Ctime: time.Now().Unix(),
  2927. Status: 1,
  2928. SignName: nurseID,
  2929. EquimentId: addmacher.ID,
  2930. DisinfectionResidue: 2,
  2931. Bed: addmacher.BedNumber,
  2932. StartTime: dialysisOrder.StartTime,
  2933. EndTime: dialysisOrder.EndTime,
  2934. Contagion: con,
  2935. WeightLoss: 0,
  2936. Hyperfiltratio: 0,
  2937. DialysisHour: "",
  2938. MachineRun: 1,
  2939. DisinfecStartime: endDate.Unix(),
  2940. DisinfecEndtime: end_time,
  2941. }
  2942. err := service.CreateInformationTwo(&information)
  2943. fmt.Println("报错", err)
  2944. }
  2945. }
  2946. }
  2947. }
  2948. dialysisOrder.Stage = 2
  2949. dialysisOrder.FinishNurse = nurseID
  2950. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2951. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2952. dialysisOrder.EndTime = endDate.Unix()
  2953. // 长沙南雅需求
  2954. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2955. //获取最后1条监测的数据
  2956. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2957. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2958. var accumulatedBloodVolume float64
  2959. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2960. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2961. fmt.Println(err)
  2962. // 查询未执行的医嘱
  2963. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2964. for _, item := range doctorAdvice {
  2965. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2966. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2967. redis := service.RedisClient()
  2968. //清空key 值
  2969. redis.Set(key, "", time.Second)
  2970. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2971. redis.Set(keyTwo, "", time.Second)
  2972. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2973. redis.Set(keyThree, "", time.Second)
  2974. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2975. theTime := toTime.Format("2006-01-02")
  2976. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2977. redis.Set(keyFour, "", time.Second)
  2978. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2979. redis.Set(keyFive, "", time.Second)
  2980. defer redis.Close()
  2981. }
  2982. }
  2983. go func() {
  2984. ssoDomain := beego.AppConfig.String("call_domain")
  2985. api := ssoDomain + "/index/downpatient"
  2986. values := make(url.Values)
  2987. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2988. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2989. values.Set("patient_id", strconv.FormatInt(id, 10))
  2990. http.PostForm(api, values)
  2991. }()
  2992. if err == nil {
  2993. c.ServeSuccessJSON(map[string]interface{}{
  2994. "dialysisOrder": dialysisOrder,
  2995. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2996. })
  2997. } else {
  2998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2999. }
  3000. }
  3001. }
  3002. func (c *DialysisAPIController) GetAllZone() {
  3003. adminUserInfo := c.GetMobileAdminUserInfo()
  3004. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  3005. if err == nil {
  3006. c.ServeSuccessJSON(map[string]interface{}{
  3007. "zone": zone,
  3008. })
  3009. }
  3010. }
  3011. func (c *DialysisAPIController) GetSchedualPatientsList() {
  3012. adminUserInfo := c.GetMobileAdminUserInfo()
  3013. page, _ := c.GetInt64("page", 1)
  3014. limit, _ := c.GetInt64("limit", 10)
  3015. schedulType, _ := c.GetInt64("schedul_type", 0)
  3016. startTime, _ := c.GetInt64("schedul_time", 0)
  3017. partitionType, _ := c.GetInt64("partition_type", 0)
  3018. keywords := c.GetString("keywords")
  3019. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  3020. if err == nil {
  3021. c.ServeSuccessJSON(map[string]interface{}{
  3022. "schedule": dialysisSchedule,
  3023. })
  3024. }
  3025. return
  3026. }
  3027. // /m/api/dialysis/start [post]
  3028. // @param patient_id:int
  3029. // @param record_date:string 排班时间 (yyyy-mm-dd)
  3030. // @param nurse:int 上机护士
  3031. // @param bed:int 床位号
  3032. func (this *DialysisAPIController) StartDialysis() {
  3033. patientID, _ := this.GetInt64("patient_id")
  3034. recordDateStr := this.GetString("record_date")
  3035. nurseID, _ := this.GetInt64("start_nurse")
  3036. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3037. blood_drawing, _ := this.GetInt64("blood_drawing")
  3038. schedual_type, _ := this.GetInt64("schedual_type")
  3039. bedID, _ := this.GetInt64("bed")
  3040. start_time := this.GetString("start_time")
  3041. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3042. change_nurse, _ := this.GetInt64("change_nurse")
  3043. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3044. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3045. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3046. puncture_needle := this.GetString("puncture_needle")
  3047. puncture_way := this.GetString("puncture_way")
  3048. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3049. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3050. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3051. zone_id, _ := this.GetInt64("zone_id")
  3052. elecsign := this.GetString("url")
  3053. nuclein_date_str := this.GetString("nuclein_date_str")
  3054. schedule_remark := this.GetString("schedule_remark")
  3055. order_remark := this.GetString("order_remark")
  3056. catheter_operation := this.GetString("catheter_operation")
  3057. blood_flow_volume := this.GetString("blood_flow_volume")
  3058. dialysis_strainer := this.GetString("dialysis_strainer")
  3059. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  3060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3061. return
  3062. }
  3063. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3064. if parseStartDateErr != nil {
  3065. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3067. return
  3068. }
  3069. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3070. if parseErr != nil {
  3071. this.ErrorLog("时间解析失败:%v", parseErr)
  3072. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3073. return
  3074. }
  3075. adminUserInfo := this.GetMobileAdminUserInfo()
  3076. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  3077. if getPatientErr != nil {
  3078. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3079. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3080. return
  3081. } else if patient == nil {
  3082. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3083. return
  3084. }
  3085. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3086. if getNurseErr != nil {
  3087. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3089. return
  3090. } else if nurse == nil {
  3091. this.ErrorLog("护士不存在")
  3092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3093. return
  3094. }
  3095. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3096. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3097. if getDeviceNumberErr != nil {
  3098. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3100. return
  3101. } else if deviceNumber == nil {
  3102. this.ErrorLog("床位号不存在")
  3103. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3104. return
  3105. }
  3106. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3107. if getRecordErr != nil {
  3108. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  3109. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3110. return
  3111. } else if dialysisRecord != nil {
  3112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  3113. return
  3114. }
  3115. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  3116. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  3117. timeLayout := "2006-01-02 15:04:05"
  3118. loc, _ := time.LoadLocation("Local")
  3119. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3120. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  3121. schedulestartTime := theStartTime.Unix()
  3122. scheduleendTime := theEndTime.Unix()
  3123. var theNucleinDate int64
  3124. timeLayoutOne := "2006-01-02"
  3125. if len(nuclein_date_str) > 0 {
  3126. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  3127. if err != nil {
  3128. utils.ErrorLog(err.Error())
  3129. }
  3130. theNucleinDate = theTime.Unix()
  3131. }
  3132. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3133. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  3134. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  3135. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3136. if adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10164 {
  3137. record, _ := service.GetDialysisPrescriptionByRecord(adminUserInfo.Org.Id, patientID, schedulestartTime)
  3138. if record.ID == 0 {
  3139. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescription)
  3140. return
  3141. }
  3142. }
  3143. //查询该床位是否有人用了
  3144. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3145. if err == gorm.ErrRecordNotFound { //空床位
  3146. // 修改了床位逻辑
  3147. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3148. if daySchedule.ID > 0 {
  3149. daySchedule.PartitionId = deviceNumber.ZoneID
  3150. daySchedule.BedId = bedID
  3151. daySchedule.ScheduleType = schedual_type
  3152. daySchedule.UpdatedTime = time.Now().Unix()
  3153. xtSchedule := models.Schedule{
  3154. PartitionId: deviceNumber.ZoneID,
  3155. BedId: bedID,
  3156. ScheduleType: schedual_type,
  3157. UpdatedTime: time.Now().Unix(),
  3158. }
  3159. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3160. if err != nil {
  3161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3162. return
  3163. }
  3164. }
  3165. } else if err == nil {
  3166. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  3167. if order.ID > 0 { //该机位被其他人占用了
  3168. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3169. return
  3170. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  3171. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3172. if daySchedule.ID > 0 {
  3173. err := service.UpdateScheduleTwo(daySchedule, schedule)
  3174. if err != nil {
  3175. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3176. return
  3177. }
  3178. }
  3179. }
  3180. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  3181. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  3182. return
  3183. }
  3184. //else if order.ID == 0 { //该床位没被占用
  3185. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  3186. // if daySchedule.ID > 0 {
  3187. // //daySchedule.PartitionId = deviceNumber.ZoneID
  3188. // //daySchedule.BedId = bedID
  3189. // //daySchedule.ScheduleType = schedual_type
  3190. // //daySchedule.UpdatedTime = time.Now().Unix()
  3191. // //err := service.UpdateSchedule(&daySchedule)
  3192. // xtSchedule := models.Schedule{
  3193. // PartitionId: deviceNumber.ZoneID,
  3194. // BedId: bedID,
  3195. // ScheduleType: schedual_type,
  3196. // UpdatedTime: time.Now().Unix(),
  3197. // }
  3198. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  3199. // if err != nil {
  3200. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3201. // return
  3202. // }
  3203. // }
  3204. //}
  3205. //}
  3206. } else if err != nil {
  3207. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3208. return
  3209. }
  3210. // 查询信息规挡的设置天数
  3211. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3212. if infor.ID > 0 && infor.WeekDay > 0 {
  3213. var cha_time int64
  3214. timeNowStr := time.Now().Format("2006-01-02")
  3215. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3216. //今日的日期减去设置的日期
  3217. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3218. if cha_time >= recordDate.Unix() {
  3219. //查询审核是否允许
  3220. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  3221. //申请状态不允许的情况 拒绝修改
  3222. if infor.ApplicationStatus != 1 {
  3223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3224. return
  3225. }
  3226. }
  3227. }
  3228. dialysisRecord = &models.DialysisOrder{
  3229. DialysisDate: recordDate.Unix(),
  3230. UserOrgId: adminUserInfo.Org.Id,
  3231. PatientId: patientID,
  3232. Stage: 1,
  3233. BedID: bedID,
  3234. StartNurse: nurseID,
  3235. Status: 1,
  3236. StartTime: startDate.Unix(),
  3237. CreatedTime: time.Now().Unix(),
  3238. UpdatedTime: time.Now().Unix(),
  3239. PunctureNurse: puncture_nurse,
  3240. Creator: adminUserInfo.AdminUser.Id,
  3241. Modifier: adminUserInfo.AdminUser.Id,
  3242. SchedualType: schedual_type,
  3243. WashpipeNurse: washpipe_nurse,
  3244. ChangeNurse: change_nurse,
  3245. DifficultPunctureNurse: difficult_puncture_nurse,
  3246. NewFistulaNurse: new_fistula_nurse,
  3247. ZoneId: zone_id,
  3248. QualityNurseId: quality_nurse_id,
  3249. PunctureNeedle: puncture_needle,
  3250. PunctureWay: puncture_way,
  3251. DialysisIrrigation: dialysis_irrigation,
  3252. DialysisDialyszers: dialysis_dialyszers,
  3253. BloodAccessId: blood_access_id,
  3254. Url: elecsign,
  3255. NucleinDate: theNucleinDate,
  3256. ScheduleRemark: schedule_remark,
  3257. OrderRemark: order_remark,
  3258. CatheterOperation: catheter_operation,
  3259. BloodFlowVolume: blood_flow_volume,
  3260. BloodDrawing: blood_drawing,
  3261. DialysisStrainer: dialysis_strainer,
  3262. }
  3263. //查询该床位是否有人用了
  3264. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  3265. if errorscode == gorm.ErrRecordNotFound {
  3266. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  3267. finish := models.XtDialysisFinish{
  3268. IsFinish: 1,
  3269. UserOrgId: adminUserInfo.Org.Id,
  3270. Status: 1,
  3271. Ctime: time.Now().Unix(),
  3272. Mtime: 0,
  3273. Module: 6,
  3274. RecordDate: schedulestartTime,
  3275. Sourse: 1,
  3276. PatientId: patientID,
  3277. }
  3278. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  3279. if dialysisFinish.ID == 0 {
  3280. service.CreateDialysisFinish(finish)
  3281. }
  3282. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  3283. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  3284. //统计该患者总次数
  3285. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  3286. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3287. }
  3288. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  3289. //统计该患者总次数
  3290. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  3291. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  3292. }
  3293. redis := service.RedisClient()
  3294. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  3295. redis.Set(key, "", time.Second)
  3296. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  3297. //清空key 值
  3298. redis.Set(keyOne, "", time.Second)
  3299. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3300. //清空key 值
  3301. redis.Set(keyTwo, "", time.Second)
  3302. if createErr != nil {
  3303. this.ErrorLog("上机失败:%v", createErr)
  3304. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3305. return
  3306. }
  3307. }
  3308. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3309. var tempdispose string
  3310. // 只针对中能建
  3311. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  3312. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3313. }
  3314. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  3315. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3316. }
  3317. //if blood_drawing > 0 && adminUserInfo.Org.Id == 10629 {
  3318. // tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  3319. //}
  3320. var ultrafiltration_rate float64
  3321. var ultrafiltration_rate_one string
  3322. var replacement_rate float64
  3323. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3324. //后期预增脱水量
  3325. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  3326. if prescription.ID > 0 {
  3327. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3328. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3329. if (template.TemplateId == 6 || template.TemplateId == 32 || template.TemplateId == 65 || adminUserInfo.Org.Id == 10375 || adminUserInfo.Org.Id == 10599) && adminUserInfo.Org.Id != 9671 { //adminUserInfo.Org.Id == 9538
  3330. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3331. }
  3332. if adminUserInfo.Org.Id == 10742 || adminUserInfo.Org.Id == 10740 || adminUserInfo.Org.Id == 10745 {
  3333. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3334. }
  3335. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 10679 { //adminUserInfo.Org.Id == 9538
  3336. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3337. }
  3338. //针对医师汇
  3339. if adminUserInfo.Org.Id == 10121 {
  3340. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3341. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3342. }
  3343. //针对通道
  3344. if adminUserInfo.Org.Id == 10234 {
  3345. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  3346. }
  3347. //针对监利大垸医院
  3348. if template.TemplateId == 41 {
  3349. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3350. }
  3351. //针对肇庆三鹤血液透析中心
  3352. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  3353. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3354. }
  3355. if adminUserInfo.Org.Id == 10469 {
  3356. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3357. }
  3358. if adminUserInfo.Org.Id == 10667 {
  3359. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  3360. }
  3361. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  3362. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3363. }
  3364. // 只针对方济医院
  3365. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  3366. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3367. ultrafiltration_rate = value
  3368. }
  3369. //针对
  3370. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  3371. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3372. ultrafiltration_rate = ultrafiltration_rate / 1000
  3373. }
  3374. if adminUserInfo.Org.Id == 10551 {
  3375. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3376. ultrafiltration_rate = ultrafiltration_rate / 1000
  3377. }
  3378. if adminUserInfo.Org.Id == 10612 || adminUserInfo.Org.Id == 10617 {
  3379. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3380. ultrafiltration_rate = ultrafiltration_rate / 1000
  3381. }
  3382. if adminUserInfo.Org.Id == 10580 {
  3383. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3384. ultrafiltration_rate = ultrafiltration_rate / 1000
  3385. }
  3386. if adminUserInfo.Org.Id == 10629 {
  3387. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3388. ultrafiltration_rate = ultrafiltration_rate / 1000
  3389. }
  3390. if adminUserInfo.Org.Id == 10644 || adminUserInfo.Org.Id == 10751 {
  3391. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3392. ultrafiltration_rate = ultrafiltration_rate / 1000
  3393. }
  3394. if adminUserInfo.Org.Id == 10751 {
  3395. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3396. ultrafiltration_rate = ultrafiltration_rate / 1000
  3397. }
  3398. if adminUserInfo.Org.Id == 10667 {
  3399. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3400. ultrafiltration_rate = ultrafiltration_rate / 1000
  3401. }
  3402. if adminUserInfo.Org.Id == 10693 {
  3403. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3404. ultrafiltration_rate = ultrafiltration_rate
  3405. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3406. }
  3407. if adminUserInfo.Org.Id == 10727 || adminUserInfo.Org.Id == 10731 {
  3408. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3409. ultrafiltration_rate = ultrafiltration_rate
  3410. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3411. }
  3412. if adminUserInfo.Org.Id == 10206 {
  3413. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60)
  3414. ultrafiltration_rate = ultrafiltration_rate
  3415. ultrafiltration_rate_one = strconv.FormatFloat(ultrafiltration_rate, 'f', -1, 64)
  3416. }
  3417. if adminUserInfo.Org.Id == 10694 || adminUserInfo.Org.Id == 10697 {
  3418. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3419. ultrafiltration_rate = ultrafiltration_rate
  3420. }
  3421. if adminUserInfo.Org.Id == 10702 {
  3422. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3423. ultrafiltration_rate = ultrafiltration_rate / 1000
  3424. }
  3425. if adminUserInfo.Org.Id == 10752 {
  3426. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3427. ultrafiltration_rate = ultrafiltration_rate / 1000
  3428. }
  3429. if adminUserInfo.Org.Id == 10723 {
  3430. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3431. ultrafiltration_rate = ultrafiltration_rate / 1000
  3432. }
  3433. if adminUserInfo.Org.Id == 10721 {
  3434. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3435. ultrafiltration_rate = ultrafiltration_rate / 1000
  3436. }
  3437. if adminUserInfo.Org.Id == 10757 {
  3438. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  3439. ultrafiltration_rate = ultrafiltration_rate / 1000
  3440. }
  3441. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10757 {
  3442. if prescription.ModeId == 2 {
  3443. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3444. if totalMin == 0 {
  3445. totalMin = 240
  3446. }
  3447. if prescription.ReplacementTotal == 0 {
  3448. prescription.ReplacementTotal = 15
  3449. }
  3450. //乘10 除10是为了保留一位小数
  3451. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3452. }
  3453. }
  3454. if adminUserInfo.Org.Id == 10752 {
  3455. if prescription.ModeId == 2 {
  3456. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3457. if totalMin == 0 {
  3458. totalMin = 240
  3459. }
  3460. if prescription.ReplacementTotal == 0 {
  3461. prescription.ReplacementTotal = 15
  3462. }
  3463. //乘10 除10是为了保留一位小数
  3464. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3465. }
  3466. }
  3467. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10731 || adminUserInfo.Org.Id == 10727 {
  3468. if prescription.ModeId == 2 {
  3469. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3470. if totalMin == 0 {
  3471. totalMin = 240
  3472. }
  3473. if prescription.DisplaceLiquiValue == 0 {
  3474. prescription.ReplacementTotal = 32
  3475. }
  3476. //乘10 除10是为了保留一位小数
  3477. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  3478. }
  3479. }
  3480. }
  3481. }
  3482. if adminUserInfo.Org.Id == 10172 {
  3483. if prescription.ID == 0 {
  3484. if prescription.ModeId == 2 {
  3485. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3486. if totalMin == 0 {
  3487. totalMin = 240
  3488. }
  3489. if prescription.ReplacementTotal == 0 {
  3490. prescription.ReplacementTotal = 15
  3491. }
  3492. //乘10 除10是为了保留一位小数
  3493. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3494. }
  3495. }
  3496. }
  3497. record := models.MonitoringRecord{
  3498. UserOrgId: adminUserInfo.Org.Id,
  3499. PatientId: patientID,
  3500. DialysisOrderId: dialysisRecord.ID,
  3501. MonitoringDate: schedulestartTime,
  3502. OperateTime: startDate.Unix(),
  3503. // MonitoringTime: recordTime,
  3504. MonitoringNurse: nurseID,
  3505. Dispose: tempdispose,
  3506. UltrafiltrationRate: ultrafiltration_rate,
  3507. UltrafiltrationVolume: 0,
  3508. Status: 1,
  3509. CreatedTime: time.Now().Unix(),
  3510. UpdatedTime: time.Now().Unix(),
  3511. UltrafiltrationRateOne: ultrafiltration_rate_one,
  3512. ReplacementRate: replacement_rate,
  3513. }
  3514. //只针对广慈医院
  3515. 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 || adminUserInfo.Org.Id == 10679 || adminUserInfo.Org.Id == 10742 {
  3516. // 查询病人是否有透前评估数据
  3517. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3518. //如果有数据就插入
  3519. if errcode == nil {
  3520. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3521. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3522. record.BreathingRate = befor.BreathingRate
  3523. record.PulseFrequency = befor.PulseFrequency
  3524. record.Temperature = befor.Temperature
  3525. }
  3526. }
  3527. //孝昌
  3528. if adminUserInfo.Org.Id == 10693 {
  3529. // 查询病人是否有透前评估数据
  3530. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3531. //如果有数据就插入
  3532. if errcode == nil {
  3533. record.MonitorSystolicBloodPressureOne = strconv.FormatFloat(befor.SystolicBloodPressure, 'f', -1, 64)
  3534. record.MonitorDiastolicBloodPressureOne = strconv.FormatFloat(befor.DiastolicBloodPressure, 'f', -1, 64)
  3535. record.MonitorTemperatureOne = strconv.FormatFloat(befor.Temperature, 'f', -1, 64)
  3536. record.BreathingRate = befor.BreathingRate
  3537. }
  3538. }
  3539. // 如果当天有插入数据,则不再往透析纪录里插入数据
  3540. if newdialysisRecord.ID > 0 {
  3541. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  3542. record.Temperature = 36.5
  3543. record.ArterialPressure = -100
  3544. record.DialysateTemperature = 36.5
  3545. record.Conductivity = 14
  3546. record.BreathingRate = "20"
  3547. record.VenousPressure = 80
  3548. record.TransmembranePressure = 60
  3549. record.Dispose = catheter_operation
  3550. }
  3551. //针对新化博翔
  3552. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  3553. record.BloodOxygenSaturation = "99"
  3554. record.Conductivity = 14
  3555. record.DialysateTemperature = 36.5
  3556. record.BreathingRate = "20"
  3557. }
  3558. //针对兰溪人民医院的需求
  3559. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10683 {
  3560. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3561. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3562. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3563. record.Temperature = befor.Temperature
  3564. record.PulseFrequency = befor.PulseFrequency
  3565. record.BreathingRate = befor.BreathingRate
  3566. }
  3567. //针对乐山友谊医院的需求
  3568. if adminUserInfo.Org.Id == 10677 {
  3569. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3570. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3571. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3572. record.Temperature = befor.Temperature
  3573. record.PulseFrequency = befor.PulseFrequency
  3574. record.BreathingRate = befor.BreathingRate
  3575. }
  3576. //新化博翔
  3577. if adminUserInfo.Org.Id == 10447 {
  3578. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3579. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3580. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3581. record.BreathingRate = befor.BreathingRate
  3582. }
  3583. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3584. record.PulseFrequency = 80
  3585. record.Temperature = 36.5
  3586. }
  3587. //诊断灵山圣康
  3588. if adminUserInfo.Org.Id == 10375 {
  3589. record.Conductivity = 13.8
  3590. record.DialysateTemperature = 37
  3591. record.DialysateFlow = 500
  3592. record.BloodFlowVolume = 200
  3593. record.BreathingRate = "18"
  3594. record.SodiumConcentration = 140
  3595. }
  3596. //江成肾病医院
  3597. if adminUserInfo.Org.Id == 10517 {
  3598. record.SodiumConcentration = 138
  3599. record.DialysateTemperature = 36.5
  3600. }
  3601. //濉溪杏康血液透析中心
  3602. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  3603. record.BloodFlowVolume = prescription.BloodFlowVolume
  3604. }
  3605. //胶州少海医院
  3606. if adminUserInfo.Org.Id == 10735 {
  3607. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  3608. dialysisPrescription, _ := service.GetDialysisPrescription(patientID, adminUserInfo.Org.Id, recordDate.Unix())
  3609. record.BreathingRate = befor.BreathingRate
  3610. record.BloodFlowVolume = dialysisPrescription.BloodFlowVolume
  3611. record.Temperature = befor.Temperature
  3612. record.PulseFrequency = befor.PulseFrequency
  3613. }
  3614. if adminUserInfo.Org.Id != 10683 {
  3615. err = service.CreateMonitor(&record)
  3616. }
  3617. //记录日志
  3618. byterequest, _ := json.Marshal(record)
  3619. monitorRecordLog := models.XtMonitorRecordLog{
  3620. RecordDate: record.MonitoringDate,
  3621. PatientId: record.PatientId,
  3622. Module: 1,
  3623. AdminUserId: adminUserInfo.AdminUser.Id,
  3624. Ctime: time.Now().Unix(),
  3625. Mtime: 0,
  3626. Status: 1,
  3627. UserOrgId: record.UserOrgId,
  3628. ErrLog: string(byterequest),
  3629. Source: "执行上机时新增监测",
  3630. }
  3631. service.CreateMonitorRecordLog(monitorRecordLog)
  3632. finish := models.XtDialysisFinish{
  3633. IsFinish: 1,
  3634. UserOrgId: adminUserInfo.Org.Id,
  3635. Status: 1,
  3636. Ctime: time.Now().Unix(),
  3637. Mtime: 0,
  3638. Module: 7,
  3639. RecordDate: schedulestartTime,
  3640. Sourse: 1,
  3641. PatientId: patientID,
  3642. }
  3643. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3644. if dialysisFinish.ID == 0 {
  3645. service.CreateDialysisFinish(finish)
  3646. }
  3647. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3648. redis := service.RedisClient()
  3649. //清空key 值
  3650. redis.Set(key, "", time.Second)
  3651. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3652. redis.Set(keyOne, "", time.Second)
  3653. defer redis.Close()
  3654. if err != nil {
  3655. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3656. return
  3657. }
  3658. }
  3659. go func() {
  3660. ssoDomain := beego.AppConfig.String("call_domain")
  3661. api := ssoDomain + "/index/uppatient"
  3662. values := make(url.Values)
  3663. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3664. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3665. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3666. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3667. http.PostForm(api, values)
  3668. }()
  3669. this.ServeSuccessJSON(map[string]interface{}{
  3670. "dialysis_order": newdialysisRecord,
  3671. "monitor": record,
  3672. })
  3673. return
  3674. }
  3675. func (c *DialysisAPIController) PostSolution() {
  3676. id, _ := c.GetInt64("patient", 0)
  3677. recordDateStr := c.GetString("record_date")
  3678. if id <= 0 {
  3679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3680. return
  3681. }
  3682. adminUserInfo := c.GetMobileAdminUserInfo()
  3683. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3684. if patient.ID == 0 {
  3685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3686. return
  3687. }
  3688. if len(recordDateStr) == 0 {
  3689. recordDateStr = time.Now().Format("2006-01-02")
  3690. }
  3691. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3692. if parseDateErr != nil {
  3693. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3695. return
  3696. }
  3697. mode_id, _ := c.GetInt64("mode_id", 0)
  3698. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3699. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3700. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3701. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3702. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3703. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3704. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3705. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3706. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3707. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3708. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3709. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3710. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3711. kalium, _ := c.GetFloat("kalium", 0)
  3712. sodium, _ := c.GetFloat("sodium", 0)
  3713. calcium, _ := c.GetFloat("calcium", 0)
  3714. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3715. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3716. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3717. glucose, _ := c.GetFloat("glucose", 0)
  3718. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3719. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3720. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3721. conductivity, _ := c.GetFloat("conductivity", 0)
  3722. remark := c.GetString("remark")
  3723. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3724. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3725. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3726. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3727. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3728. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3729. special_medicine_other := c.GetString("special_medicine_other")
  3730. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3731. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3732. blood_access, _ := c.GetInt64("blood_access", 0)
  3733. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3734. body_fluid_other := c.GetString("body_fluid_other")
  3735. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3736. niprocart, _ := c.GetInt64("niprocart", 0)
  3737. jms, _ := c.GetInt64("jms", 0)
  3738. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3739. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3740. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3741. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3742. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3743. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3744. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3745. injector, _ := c.GetInt64("injector", 0)
  3746. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3747. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3748. safe_package, _ := c.GetInt64("package", 0)
  3749. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3750. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3751. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3752. blood := c.GetString("blood")
  3753. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3754. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3755. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3756. displace_speed := c.GetString("displace_speed")
  3757. illness, _ := c.GetInt64("illness")
  3758. amylaceum := c.GetString("amylaceum")
  3759. single_time := c.GetString("single_time")
  3760. single_water := c.GetString("single_water")
  3761. replacement_flow := c.GetString("replacement_flow")
  3762. plasma_separator := c.GetString("plasma_separator")
  3763. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3764. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3765. oxygen_flow := c.GetString("oxygen_flow")
  3766. oxygen_time := c.GetString("oxygen_time")
  3767. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3768. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3769. puncture_needle := c.GetString("puncture_needle")
  3770. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3771. epo := c.GetString("epo")
  3772. epo_count, _ := c.GetFloat("epo_count", 0)
  3773. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3774. pre_impulse := c.GetString("pre_impulse")
  3775. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3776. admin_user_id, _ := c.GetInt64("admin_user_id")
  3777. is_water := c.GetString("is_water")
  3778. add_amount, _ := c.GetFloat("add_amount")
  3779. reduce_amount, _ := c.GetFloat("reduce_amount")
  3780. prescribing_number, _ := c.GetFloat("prescribing_number")
  3781. treatment_remark := c.GetString("treatment_remark")
  3782. prescription_sodium := c.GetString("prescription_sodium")
  3783. start_sodium := c.GetString("start_sodium")
  3784. sodium_curve := c.GetString("sodium_curve")
  3785. var is_war int64
  3786. if is_water == "是" {
  3787. is_war = 1
  3788. }
  3789. if is_water == "否" {
  3790. is_war = 2
  3791. }
  3792. if is_water == "请选择" {
  3793. is_war = 0
  3794. }
  3795. drhy_water := c.GetString("drhy_water")
  3796. dry_water_hour := c.GetString("dry_water_hour")
  3797. water_machine := c.GetString("water_machine")
  3798. dialysis_remark := c.GetString("dialysis_remark")
  3799. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3800. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3801. prescription_water, _ := c.GetFloat("prescription_water")
  3802. dialysis_strainer := c.GetString("dialysis_strainer")
  3803. chaptalization := c.GetString("chaptalization")
  3804. washing_time := c.GetString("washing_time")
  3805. warsh_count := c.GetString("warsh_count")
  3806. blood_access_part_id := c.GetString("blood_access_part_id")
  3807. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3808. dialyzate := c.GetString("dialyzate")
  3809. first_super := c.GetString("first_super")
  3810. is_sequential := c.GetString("is_sequential")
  3811. var fisrt_sup int64
  3812. if first_super == "是" {
  3813. fisrt_sup = 1
  3814. }
  3815. if first_super == "否" {
  3816. fisrt_sup = 2
  3817. }
  3818. if first_super == "请选择" {
  3819. fisrt_sup = 0
  3820. }
  3821. var is_sequen int64
  3822. if is_sequential == "是" {
  3823. is_sequen = 1
  3824. }
  3825. if is_sequential == "否" {
  3826. is_sequen = 2
  3827. }
  3828. if is_sequential == "请选择" {
  3829. is_sequen = 0
  3830. }
  3831. conduct := c.GetString("conduct")
  3832. if mode_id > 0 {
  3833. var str string
  3834. //查找该机构用的是什么透析器
  3835. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3836. if filedConfig.ID > 0 {
  3837. str = dialyzerPerfusionApparatus
  3838. } else {
  3839. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3840. }
  3841. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3842. }
  3843. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3844. //
  3845. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3846. // if appRole.UserType == 3 {
  3847. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3848. // if getPermissionErr != nil {
  3849. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3850. // return
  3851. // } else if headNursePermission == nil {
  3852. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3853. // return
  3854. // }
  3855. // }
  3856. //}
  3857. // 查询信息规挡的设置天数
  3858. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3859. if infor.ID > 0 && infor.WeekDay > 0 {
  3860. var cha_time int64
  3861. timeNowStr := time.Now().Format("2006-01-02")
  3862. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3863. //今日的日期减去设置的日期
  3864. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3865. if cha_time >= recordDate.Unix() {
  3866. //查询审核是否允许
  3867. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3868. //申请状态不允许的情况 拒绝修改
  3869. if infor.ApplicationStatus != 1 {
  3870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3871. return
  3872. }
  3873. }
  3874. }
  3875. goodList, _ := service.GetMobileGoodList(adminUserInfo.Org.Id)
  3876. var dialysis_dialyszers_id int64
  3877. var dialysis_strainer_id int64
  3878. var dialysis_irrigation_id int64
  3879. if len(goodList) > 0 {
  3880. for _, item := range goodList {
  3881. if item.SpecificationName == dialysis_dialyszers {
  3882. dialysis_dialyszers_id = item.ID
  3883. }
  3884. if item.SpecificationName == dialysis_irrigation {
  3885. dialysis_irrigation_id = item.ID
  3886. }
  3887. if item.SpecificationName == dialysis_strainer {
  3888. dialysis_strainer_id = item.ID
  3889. }
  3890. }
  3891. }
  3892. prescription := models.DialysisPrescription{
  3893. UserOrgId: adminUserInfo.Org.Id,
  3894. PatientId: id,
  3895. RecordDate: recordDate.Unix(),
  3896. ModeId: mode_id,
  3897. DialysisDuration: dialysis_duration,
  3898. Dialyzer: dialyzer,
  3899. PerfusionApparatus: perfusion_apparatus,
  3900. BloodFlowVolume: blood_flow_volume,
  3901. DewaterAmount: dewater_amount,
  3902. DisplaceLiqui: displace_liqui,
  3903. ReplacementWay: replacement_way,
  3904. Anticoagulant: anticoagulant,
  3905. AnticoagulantShouji: anticoagulant_shouji,
  3906. AnticoagulantWeichi: anticoagulant_weichi,
  3907. AnticoagulantZongliang: anticoagulant_zongliang,
  3908. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3909. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3910. Kalium: kalium,
  3911. Sodium: sodium,
  3912. Calcium: calcium,
  3913. Bicarbonate: bicarbonate,
  3914. Glucose: glucose,
  3915. // DryWeight: dry_weight,
  3916. DialysateFlow: dialysate_flow,
  3917. DialysateTemperature: dialysate_temperature,
  3918. Conductivity: conductivity,
  3919. Remark: remark,
  3920. Status: 1,
  3921. CreatedTime: time.Now().Unix(),
  3922. UpdatedTime: time.Now().Unix(),
  3923. DialysisDurationMinute: dialysisDurationMinute,
  3924. DialysisDurationHour: dialysisDurationHour,
  3925. TargetUltrafiltration: targetUltrafiltration,
  3926. DialysateFormulation: dialysateFormulation,
  3927. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3928. BodyFluid: body_fluid,
  3929. SpecialMedicine: special_medicine,
  3930. SpecialMedicineOther: special_medicine_other,
  3931. DisplaceLiquiPart: displace_liqui_part,
  3932. DisplaceLiquiValue: displace_liqui_value,
  3933. BloodAccess: blood_access,
  3934. Ultrafiltration: ultrafiltration,
  3935. BodyFluidOther: body_fluid_other,
  3936. ReplacementTotal: replacement_total,
  3937. Niprocart: niprocart,
  3938. Jms: jms,
  3939. FistulaNeedleSet: fistula_needle_set,
  3940. FistulaNeedleSet16: fistula_needle_set_16,
  3941. Hemoperfusion: hemoperfusion,
  3942. DialyserSterilised: dialyser_sterilised,
  3943. Filtryzer: filtryzer,
  3944. TargetKtv: target_ktv,
  3945. Dialyzers: dialyzers,
  3946. Injector: injector,
  3947. Bloodlines: bloodlines,
  3948. TubingHemodialysis: tubing_hemodialysis,
  3949. Package: safe_package,
  3950. ALiquid: a_liquid,
  3951. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3952. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3953. Blood: blood,
  3954. DialysisDialyszers: dialysis_dialyszers,
  3955. DialysisIrrigation: dialysis_irrigation,
  3956. AntioxidantCommodityName: antioxidant_commodity_name,
  3957. DisplaceSpeed: displace_speed,
  3958. Illness: illness,
  3959. Amylaceum: amylaceum,
  3960. SingleWater: single_water,
  3961. SingleTime: single_time,
  3962. ReplacementFlow: replacement_flow,
  3963. PlasmaSeparator: plasma_separator,
  3964. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3965. OxygenUptake: oxygen_uptake,
  3966. OxygenTime: oxygen_time,
  3967. OxygenFlow: oxygen_flow,
  3968. HemodialysisPipelines: hemodialysis_pipelines,
  3969. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3970. PunctureNeedle: puncture_needle,
  3971. PunctureNeedleCount: puncture_needle_count,
  3972. Epo: epo,
  3973. EpoCount: epo_count,
  3974. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3975. PreImpulse: impulse,
  3976. AdminUserId: admin_user_id,
  3977. IsWater: is_war,
  3978. DrhyWater: drhy_water,
  3979. DryWaterHour: dry_water_hour,
  3980. WaterMachine: water_machine,
  3981. AddAmount: add_amount,
  3982. ReduceAmount: reduce_amount,
  3983. DialysisRemark: dialysis_remark,
  3984. PrescribingNumber: prescribing_number,
  3985. PrescriptionSodium: prescription_sodium,
  3986. StartSodium: start_sodium,
  3987. SodiumCurve: sodium_curve,
  3988. TreatmentRemark: treatment_remark,
  3989. DialysisFluidFlow: dialysis_fluid_flow,
  3990. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3991. PrescriptionWater: prescription_water,
  3992. DialysisStrainer: dialysis_strainer,
  3993. Chaptalization: chaptalization,
  3994. WashingTime: washing_time,
  3995. WarshCount: warsh_count,
  3996. BloodAccessPartId: blood_access_part_id,
  3997. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3998. Dialyzate: dialyzate,
  3999. DialysisDialyszersId: dialysis_dialyszers_id,
  4000. DialysisIrrigationId: dialysis_irrigation_id,
  4001. DialysisStrainerId: dialysis_strainer_id,
  4002. FirstSuper: fisrt_sup,
  4003. IsSequential: is_sequen,
  4004. Conduct: conduct,
  4005. }
  4006. if adminUserInfo.Org.Id == 10721 {
  4007. if prescription.ModeId == 2 {
  4008. if prescription.ReplacementTotal == 0 {
  4009. prescription.ReplacementTotal = 15
  4010. }
  4011. }
  4012. }
  4013. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4014. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  4015. //
  4016. if appRole.UserType == 2 || appRole.UserType == 1 {
  4017. prescription_doctor = adminUserInfo.AdminUser.Id
  4018. prescription.PrescriptionDoctor = prescription_doctor
  4019. }
  4020. if dialysisPrescription.ID == 0 { //新增
  4021. prescription.Creater = adminUserInfo.AdminUser.Id
  4022. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4023. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4024. }
  4025. } else { //修改
  4026. if dialysisPrescription.Creater == 0 {
  4027. prescription.Creater = adminUserInfo.AdminUser.Id
  4028. } else {
  4029. prescription.Creater = dialysisPrescription.Creater
  4030. if adminUserInfo.Org.Id == 9882 {
  4031. if appRole.UserType == 2 || appRole.UserType == 1 {
  4032. prescription.Creater = adminUserInfo.AdminUser.Id
  4033. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  4034. }
  4035. }
  4036. }
  4037. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  4038. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  4039. }
  4040. //if/**/
  4041. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  4042. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  4043. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4044. // if getPermissionErr != nil {
  4045. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4046. // return
  4047. // } else if headNursePermission == nil {
  4048. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4049. // return
  4050. // }
  4051. //}
  4052. //prescription.Creater = dialysisPrescription.Creater
  4053. prescription.CreatedTime = dialysisPrescription.CreatedTime
  4054. prescription.Modifier = adminUserInfo.AdminUser.Id
  4055. prescription.ID = dialysisPrescription.ID
  4056. }
  4057. solution := models.DialysisSolution{
  4058. RegistrarsId: adminUserInfo.AdminUser.Id,
  4059. UserOrgId: adminUserInfo.Org.Id,
  4060. Doctor: prescription_doctor,
  4061. PatientId: id,
  4062. ModeId: mode_id,
  4063. DialysisDuration: dialysis_duration,
  4064. PerfusionApparatus: perfusion_apparatus,
  4065. BloodFlowVolume: blood_flow_volume,
  4066. Dewater: dewater_amount,
  4067. DisplaceLiqui: displace_liqui,
  4068. ReplacementWay: replacement_way,
  4069. Anticoagulant: anticoagulant,
  4070. AnticoagulantShouji: anticoagulant_shouji,
  4071. AnticoagulantWeichi: anticoagulant_weichi,
  4072. AnticoagulantZongliang: anticoagulant_zongliang,
  4073. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  4074. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  4075. Kalium: kalium,
  4076. Sodium: sodium,
  4077. Calcium: calcium,
  4078. Bicarbonate: bicarbonate,
  4079. Glucose: glucose,
  4080. // DryWeight: dry_weight,
  4081. DialysateFlow: dialysate_flow,
  4082. DialysateTemperature: dialysate_temperature,
  4083. Conductivity: conductivity,
  4084. Remark: remark,
  4085. Status: 1,
  4086. CreatedTime: time.Now().Unix(),
  4087. UpdatedTime: time.Now().Unix(),
  4088. DialysisDurationMinute: dialysisDurationMinute,
  4089. DialysisDurationHour: dialysisDurationHour,
  4090. TargetUltrafiltration: targetUltrafiltration,
  4091. DialysateFormulation: dialysateFormulation,
  4092. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  4093. BodyFluid: body_fluid,
  4094. SpecialMedicine: special_medicine,
  4095. SpecialMedicineOther: special_medicine_other,
  4096. DisplaceLiquiPart: displace_liqui_part,
  4097. DisplaceLiquiValue: displace_liqui_value,
  4098. BloodAccess: blood_access,
  4099. Ultrafiltration: ultrafiltration,
  4100. BodyFluidOther: body_fluid_other,
  4101. ReplacementTotal: replacement_total,
  4102. TargetKtv: target_ktv,
  4103. DialysisDialyszers: dialysis_dialyszers,
  4104. DialysisIrrigation: dialysis_irrigation,
  4105. HemodialysisPipelines: hemodialysis_pipelines,
  4106. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  4107. PunctureNeedle: puncture_needle,
  4108. PunctureNeedleCount: puncture_needle_count,
  4109. Epo: epo,
  4110. EpoCount: epo_count,
  4111. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  4112. PreImpulse: impulse,
  4113. SolutionStatus: 1,
  4114. DialysisRemark: dialysis_remark,
  4115. PrescribingNumber: prescribing_number,
  4116. PrescriptionSodium: prescription_sodium,
  4117. StartSodium: start_sodium,
  4118. SodiumCurve: sodium_curve,
  4119. TreatmentRemark: treatment_remark,
  4120. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  4121. DialysisFluidFlow: dialysis_fluid_flow,
  4122. PrescriptionWater: prescription_water,
  4123. DialysisStrainer: dialysis_strainer,
  4124. Chaptalization: chaptalization,
  4125. WashingTime: washing_time,
  4126. WarshCount: warsh_count,
  4127. BloodAccessPartId: blood_access_part_id,
  4128. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  4129. Dialyzate: dialyzate,
  4130. DialysisDialyszersId: dialysis_dialyszers_id,
  4131. DialysisIrrigationId: dialysis_irrigation_id,
  4132. DialysisStrainerId: dialysis_strainer_id,
  4133. FirstSuper: fisrt_sup,
  4134. IsSequential: is_sequen,
  4135. Conduct: conduct,
  4136. }
  4137. //针对河间咸的
  4138. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  4139. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  4140. solution.DisplaceLiquiPart = 0
  4141. solution.DisplaceLiquiValue = 0
  4142. }
  4143. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  4144. prescription.DisplaceLiquiPart = 0
  4145. prescription.DisplaceLiquiValue = 0
  4146. }
  4147. }
  4148. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  4149. if solution.PrescribingNumber == 0 {
  4150. solution.PrescribingNumber = 1
  4151. }
  4152. if prescription.PrescribingNumber == 0 {
  4153. prescription.PrescribingNumber = 1
  4154. }
  4155. if solution.PrescribingNumber == 0 && id == 14682 {
  4156. solution.PrescribingNumber = 2
  4157. }
  4158. if solution.PrescribingNumber == 0 && id == 18560 {
  4159. solution.PrescribingNumber = 2
  4160. }
  4161. if prescription.PrescribingNumber == 0 && id == 14682 {
  4162. prescription.PrescribingNumber = 2
  4163. }
  4164. if prescription.PrescribingNumber == 0 && id == 18560 {
  4165. prescription.PrescribingNumber = 2
  4166. }
  4167. }
  4168. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  4169. if adminUserInfo.Org.Id == 10721 || adminUserInfo.Org.Id == 10164 {
  4170. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  4171. if len(monitorList) > 0 {
  4172. var ultrafiltration_rate float64
  4173. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4174. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  4175. var replacement_rate float64
  4176. //乘10 除10是为了保留一位小数
  4177. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  4178. var firstOpeateTime = monitorList[0].OperateTime
  4179. for _, item := range monitorList {
  4180. //超滤率
  4181. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  4182. //置换率
  4183. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  4184. //超滤量
  4185. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  4186. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  4187. //置换量
  4188. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  4189. fmt.Println("displacement_quantity----------------------", displacement_quantity)
  4190. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  4191. }
  4192. }
  4193. }
  4194. //记录日志
  4195. byterequest, _ := json.Marshal(prescription)
  4196. prescriptionLog := models.XtDialysisPrescriptionLog{
  4197. UserOrgId: prescription.UserOrgId,
  4198. Ctime: time.Now().Unix(),
  4199. Mtime: 0,
  4200. ErrLog: string(byterequest),
  4201. AdminUserId: adminUserInfo.AdminUser.Id,
  4202. RecordDate: prescription.RecordDate,
  4203. PatientId: prescription.PatientId,
  4204. Source: "手机端新增长期处方",
  4205. Status: 1,
  4206. }
  4207. service.CreatePrescriptionLog(prescriptionLog)
  4208. finish := models.XtDialysisFinish{
  4209. IsFinish: 1,
  4210. UserOrgId: adminUserInfo.Org.Id,
  4211. Status: 1,
  4212. Ctime: time.Now().Unix(),
  4213. Mtime: 0,
  4214. Module: 1,
  4215. RecordDate: recordDate.Unix(),
  4216. Sourse: 1,
  4217. PatientId: id,
  4218. }
  4219. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  4220. if dialysisFinish.ID == 0 {
  4221. service.CreateDialysisFinish(finish)
  4222. }
  4223. //获取最新1条
  4224. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  4225. //更新状态
  4226. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  4227. //长沙南雅医院,自动生成抗凝剂的临时处方
  4228. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  4229. if prescribing_number == 0 {
  4230. prescribing_number = 1
  4231. }
  4232. advice := models.DoctorAdvice{
  4233. UserOrgId: adminUserInfo.Org.Id,
  4234. PatientId: id,
  4235. GroupNo: 0,
  4236. AdviceType: 2,
  4237. RecordDate: recordDate.Unix(),
  4238. AdviceDate: recordDate.Unix(),
  4239. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  4240. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  4241. AdviceDesc: "",
  4242. ReminderDate: 0,
  4243. SingleDose: prescription.AnticoagulantZongliang,
  4244. SingleDoseUnit: "iu",
  4245. DrugSpec: 0,
  4246. DrugSpecUnit: "",
  4247. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  4248. PrescribingNumberUnit: "支",
  4249. DeliveryWay: "静脉注射",
  4250. ExecutionFrequency: "上机前",
  4251. AdviceDoctor: 0,
  4252. Status: 1,
  4253. CreatedTime: time.Now().Unix(),
  4254. UpdatedTime: time.Now().Unix(),
  4255. IsPrescription: 1,
  4256. ExecutionState: 2,
  4257. StopState: 2,
  4258. IsSettle: 2,
  4259. }
  4260. // 查询排班信息
  4261. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  4262. if schedulePatient.ID > 0 {
  4263. if schedulePatient.ScheduleType == 1 {
  4264. advice.StartTime = recordDate.Unix() + 6.5*60*60
  4265. }
  4266. if schedulePatient.ScheduleType == 2 {
  4267. advice.StartTime = recordDate.Unix() + 9*60*60
  4268. }
  4269. }
  4270. // 抗凝剂名称
  4271. switch anticoagulant {
  4272. case 1:
  4273. advice.AdviceName = "无肝素"
  4274. break
  4275. case 2:
  4276. advice.AdviceName = "普通肝素"
  4277. break
  4278. case 3:
  4279. advice.AdviceName = "低分子肝素"
  4280. break
  4281. case 4:
  4282. advice.AdviceName = "阿加曲班"
  4283. break
  4284. case 5:
  4285. advice.AdviceName = "枸橼酸钠"
  4286. break
  4287. case 6:
  4288. advice.AdviceName = "低分子肝素钙"
  4289. break
  4290. case 7:
  4291. advice.AdviceName = "低分子肝素钠"
  4292. break
  4293. case 8:
  4294. advice.AdviceName = "依诺肝素"
  4295. break
  4296. case 9:
  4297. advice.AdviceName = "达肝素"
  4298. break
  4299. case 10:
  4300. advice.AdviceName = "体外抗凝"
  4301. break
  4302. case 11:
  4303. advice.AdviceName = "那曲肝素"
  4304. break
  4305. case 12:
  4306. advice.AdviceName = "无抗凝剂"
  4307. break
  4308. }
  4309. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  4310. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  4311. advice.AdviceDoctor = appRole.AdminUserId
  4312. }
  4313. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  4314. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  4315. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  4316. advice.AdviceName = "低分子肝素钠注射液"
  4317. // 修改患者临时医嘱里的抗凝剂医嘱
  4318. advice.ID = advicePrescription.ID
  4319. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  4320. } else {
  4321. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  4322. advice.AdviceName = "低分子肝素钠注射液"
  4323. service.CreateDoctorAdvice(&advice)
  4324. }
  4325. }
  4326. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  4327. redis := service.RedisClient()
  4328. defer redis.Close()
  4329. //清空key 值
  4330. redis.Set(key, "", time.Second)
  4331. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  4332. redis.Set(keyOne, "", time.Second)
  4333. }
  4334. //获取key,清空redis
  4335. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  4336. redis := service.RedisClient()
  4337. defer redis.Close()
  4338. //清空key 值
  4339. redis.Set(key, "", time.Second)
  4340. //清空长期医嘱的key
  4341. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  4342. redis.Set(soulution_key, "", time.Second)
  4343. //查询最近透析准备表里是否存在 透析器 灌流器
  4344. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4345. redis.Set(keyOne, "", time.Second)
  4346. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  4347. redis.Set(keyTwo, "", time.Second)
  4348. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  4349. redis.Set(keyThree, "", time.Second)
  4350. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  4351. redis.Set(keyFour, "", time.Second)
  4352. //splitStr := strings.Split(dialysis_dialyszers, ",")
  4353. //
  4354. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  4355. //
  4356. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  4357. //if len(mation)>0{
  4358. // for _, item := range splitStr {
  4359. // for _,it := range mation{
  4360. // if(item == it.SpecificationName){
  4361. //
  4362. // //查询最近一次的透析器
  4363. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4364. //
  4365. // if errcode == gorm.ErrRecordNotFound{
  4366. // //插入数据
  4367. // prepare := models.DialysisBeforePrepare{
  4368. // UserOrgId: adminUserInfo.Org.Id,
  4369. // PatientId: id,
  4370. // RecordDate: recordDate.Unix(),
  4371. // GoodTypeId: it.GoodTypeId,
  4372. // GoodId: it.ID,
  4373. // Count: 1,
  4374. // Ctime: time.Now().Unix(),
  4375. // Creater: adminUserInfo.AdminUser.Id,
  4376. // Status:1,
  4377. //
  4378. // }
  4379. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4380. // fmt.Println("",errcode)
  4381. // }
  4382. // }
  4383. // }
  4384. //
  4385. // }
  4386. //
  4387. // for _, item := range splitIrrigation {
  4388. // for _,it := range mation{
  4389. // if(item == it.SpecificationName){
  4390. // //查询最近一次的透析器
  4391. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  4392. // if errcode == gorm.ErrRecordNotFound{
  4393. // //插入数据
  4394. // prepare := models.DialysisBeforePrepare{
  4395. // UserOrgId: adminUserInfo.Org.Id,
  4396. // PatientId: id,
  4397. // RecordDate: recordDate.Unix(),
  4398. // GoodTypeId: it.GoodTypeId,
  4399. // GoodId: it.ID,
  4400. // Count: 1,
  4401. // Ctime: time.Now().Unix(),
  4402. // Creater: adminUserInfo.AdminUser.Id,
  4403. // Status:1,
  4404. //
  4405. // }
  4406. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  4407. // fmt.Println(errcode)
  4408. // }
  4409. // }
  4410. // }
  4411. // }
  4412. //}
  4413. c.ServeSuccessJSON(map[string]interface{}{
  4414. "solution": &solution,
  4415. "prescription": &prescription,
  4416. })
  4417. }
  4418. func (c *DialysisAPIController) GetAcceptsAssessment() {
  4419. patient, _ := c.GetInt64("patient", 0)
  4420. adminUserInfo := c.GetMobileAdminUserInfo()
  4421. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  4422. c.ServeSuccessJSON(map[string]interface{}{
  4423. "receiveTreatmentAsses": receiveTreatmentAsses,
  4424. })
  4425. }
  4426. func (this *DialysisAPIController) PostSignInfo() {
  4427. patientID, _ := this.GetInt64("patient_id")
  4428. recordDateStr := this.GetString("date")
  4429. if patientID <= 0 {
  4430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4431. return
  4432. }
  4433. if len(recordDateStr) == 0 {
  4434. recordDateStr = time.Now().Format("2006-01-02")
  4435. }
  4436. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4437. if parseDateErr != nil {
  4438. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  4439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4440. return
  4441. }
  4442. adminInfo := this.GetMobileAdminUserInfo()
  4443. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  4444. if err != nil {
  4445. this.ErrorLog("签名失败:%v", err)
  4446. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4447. return
  4448. }
  4449. this.ServeSuccessJSON(map[string]interface{}{
  4450. "doctor_id": adminInfo.AdminUser.Id,
  4451. })
  4452. }
  4453. func (this *DialysisAPIController) GetLastMonitorRecord() {
  4454. patientID, _ := this.GetInt64("patient_id")
  4455. adminInfo := this.GetMobileAdminUserInfo()
  4456. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  4457. this.ServeSuccessJSON(map[string]interface{}{
  4458. "monitor": record,
  4459. })
  4460. }
  4461. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  4462. thisTime := time.Now()
  4463. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4464. timeLayout := "2006-01-02 15:04:05"
  4465. loc, _ := time.LoadLocation("Local")
  4466. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4467. theAssessmentDateTime := theStartTime.Unix()
  4468. patientID, _ := this.GetInt64("patient_id")
  4469. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4470. adminInfo := this.GetMobileAdminUserInfo()
  4471. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4472. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  4473. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  4474. var ultrafiltration_rate float64
  4475. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4476. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  4477. fmt.Println(evaluation)
  4478. fmt.Println("prescription.ID", prescription.ID)
  4479. if prescription.ID > 0 {
  4480. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4481. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4482. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  4483. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4484. record.UltrafiltrationRate = ultrafiltration_rate
  4485. }
  4486. //重庆塘坝卫生院
  4487. if adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10745 {
  4488. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4489. record.UltrafiltrationRate = ultrafiltration_rate
  4490. }
  4491. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4492. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4493. record.UltrafiltrationRate = ultrafiltration_rate
  4494. }
  4495. if adminInfo.Org.Id == 10510 {
  4496. record.UltrafiltrationRate = 0
  4497. }
  4498. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  4499. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  4500. record.UltrafiltrationRate = ultrafiltration_rate
  4501. }
  4502. if template.TemplateId == 20 || template.TemplateId == 22 || adminInfo.Org.Id == 10731 {
  4503. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4504. record.UltrafiltrationRate = ultrafiltration_rate
  4505. }
  4506. // 只针对方济医院
  4507. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  4508. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4509. ultrafiltration_rate = value
  4510. record.UltrafiltrationRate = ultrafiltration_rate
  4511. }
  4512. if template.TemplateId == 41 || template.TemplateId == 47 {
  4513. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  4514. record.UltrafiltrationRate = ultrafiltration_rate
  4515. }
  4516. if template.TemplateId == 43 {
  4517. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4518. record.UltrafiltrationRate = ultrafiltration_rate
  4519. }
  4520. if template.TemplateId == 46 || template.TemplateId == 54 {
  4521. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4522. record.UltrafiltrationRate = ultrafiltration_rate
  4523. }
  4524. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 9829 || adminInfo.Org.Id == 10440 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 {
  4525. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4526. record.UltrafiltrationRate = ultrafiltration_rate
  4527. }
  4528. if adminInfo.Org.Id == 10469 {
  4529. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4530. record.UltrafiltrationRate = ultrafiltration_rate
  4531. }
  4532. if adminInfo.Org.Id == 10667 {
  4533. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  4534. record.UltrafiltrationRate = ultrafiltration_rate
  4535. }
  4536. if adminInfo.Org.Id == 10471 {
  4537. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4538. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4539. }
  4540. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4541. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4542. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4543. }
  4544. if adminInfo.Org.Id == 10751 {
  4545. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  4546. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4547. }
  4548. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 || adminInfo.Org.Id == 10629 {
  4549. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4550. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4551. }
  4552. if adminInfo.Org.Id == 10721 {
  4553. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4554. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4555. }
  4556. if adminInfo.Org.Id == 10757 {
  4557. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4558. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4559. }
  4560. if adminInfo.Org.Id == 10752 {
  4561. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)
  4562. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4563. }
  4564. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 || adminInfo.Org.Id == 10679 {
  4565. record.UltrafiltrationRate = 0
  4566. }
  4567. if adminInfo.Org.Id == 10727 || adminInfo.Org.Id == 10731 {
  4568. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4569. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4570. }
  4571. if adminInfo.Org.Id == 10206 {
  4572. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4573. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4574. }
  4575. //湘潭爱心美白石
  4576. if adminInfo.Org.Id == 9850 {
  4577. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4578. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  4579. }
  4580. if adminInfo.Org.Id == 9919 {
  4581. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  4582. record.UltrafiltrationRate = math.Floor(ultrafiltration_rate / 1000)
  4583. }
  4584. //if template.TemplateId == 47 {
  4585. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  4586. // record.UltrafiltrationRate = ultrafiltration_rate
  4587. //}
  4588. }
  4589. }
  4590. // record.UltrafiltrationRate = ultrafiltration_rate
  4591. record.UltrafiltrationVolume = 0
  4592. 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
  4593. if ultrafiltration_rate > 0 {
  4594. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4595. record.UltrafiltrationVolume = value
  4596. }
  4597. }
  4598. if template.TemplateId == 6 || template.TemplateId == 65 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 || adminInfo.Org.Id == 10599 { //adminInfo.Org.Id == 9538
  4599. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  4600. if adminInfo.Org.Id != 10735 {
  4601. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4602. record.UltrafiltrationVolume = ultrafiltration_volume
  4603. }
  4604. //胶州少海医院
  4605. if adminInfo.Org.Id == 10735 {
  4606. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4607. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4608. var ultrafiltration_rate_one = math.Floor(prescription.TargetUltrafiltration*1000/float64(totalMin)*60*1000) / 1000
  4609. if lastMonitorRecordList.ID > 0 {
  4610. record.UltrafiltrationRate = ultrafiltration_rate_one
  4611. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4612. record.UltrafiltrationVolume = ultrafiltration_volume
  4613. } else {
  4614. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate_one)
  4615. record.UltrafiltrationVolume = ultrafiltration_volume
  4616. }
  4617. }
  4618. }
  4619. }
  4620. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10679 {
  4621. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4622. record.UltrafiltrationVolume = ultrafiltration_volume
  4623. }
  4624. //长沙南雅
  4625. if adminInfo.Org.Id == 10395 || adminInfo.Org.Id == 10138 || adminInfo.Org.Id == 10278 || adminInfo.Org.Id == 10432 || adminInfo.Org.Id == 10441 || adminInfo.Org.Id == 10445 || adminInfo.Org.Id == 10469 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10610 || adminInfo.Org.Id == 10537 || adminInfo.Org.Id == 10667 {
  4626. if ultrafiltration_rate > 0 {
  4627. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4628. record.UltrafiltrationVolume = ultrafiltration_volume
  4629. }
  4630. }
  4631. if adminInfo.Org.Id == 10471 {
  4632. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4633. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4634. }
  4635. if adminInfo.Org.Id == 10460 || adminInfo.Org.Id == 10644 || adminInfo.Org.Id == 10667 {
  4636. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4637. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4638. }
  4639. if adminInfo.Org.Id == 10751 {
  4640. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4641. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4642. }
  4643. if adminInfo.Org.Id == 10551 || adminInfo.Org.Id == 10617 || adminInfo.Org.Id == 10580 {
  4644. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4645. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4646. }
  4647. //长沙南雅累计血容量自动计算
  4648. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  4649. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  4650. //}
  4651. if template.TemplateId == 47 || template.TemplateId == 54 {
  4652. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4653. }
  4654. if adminInfo.Org.Id == 10510 {
  4655. record.UltrafiltrationVolume = 0
  4656. }
  4657. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10164 || adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10752 || adminInfo.Org.Id == 10757 {
  4658. if ultrafiltration_rate > 0 {
  4659. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4660. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4661. }
  4662. }
  4663. //古镇乐生
  4664. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4665. if ultrafiltration_rate > 0 {
  4666. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4667. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4668. }
  4669. }
  4670. if adminInfo.Org.Id == 9919 {
  4671. if ultrafiltration_rate > 0 {
  4672. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4673. record.UltrafiltrationVolume = math.Floor(ultrafiltration_volume / 1000)
  4674. }
  4675. }
  4676. if adminInfo.Org.Id == 10206 {
  4677. if ultrafiltration_rate > 0 {
  4678. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4679. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4680. }
  4681. }
  4682. if adminInfo.Org.Id == 10721 || adminInfo.Org.Id == 10757 {
  4683. var replacement_rate float64
  4684. var displacement_quantity float64
  4685. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4686. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*60) / 1000
  4687. record.ReplacementRate = replacement_rate
  4688. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4689. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4690. record.DisplacementQuantity = displacement_quantity
  4691. }
  4692. if adminInfo.Org.Id == 10752 {
  4693. var replacement_rate float64
  4694. var displacement_quantity float64
  4695. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4696. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4697. record.ReplacementRate = replacement_rate
  4698. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4699. record.DisplacementQuantity = displacement_quantity
  4700. }
  4701. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4702. var replacement_rate float64
  4703. var displacement_quantity float64
  4704. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4705. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*60) / 1000
  4706. record.ReplacementRate = replacement_rate
  4707. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4708. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4709. record.DisplacementQuantity = displacement_quantity
  4710. }
  4711. if adminInfo.Org.Id == 10740 || adminInfo.Org.Id == 10742 || adminInfo.Org.Id == 10745 {
  4712. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4713. record.UltrafiltrationVolume = ultrafiltration_volume
  4714. }
  4715. if adminInfo.Org.Id == 10731 || adminInfo.Org.Id == 10727 {
  4716. var replacement_rate float64
  4717. var displacement_quantity float64
  4718. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4719. if totalMin == 0 {
  4720. totalMin = 240
  4721. }
  4722. if prescription.DisplaceLiquiValue == 0 {
  4723. prescription.ReplacementTotal = 32
  4724. }
  4725. //乘10 除10是为了保留一位小数
  4726. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  4727. fmt.Println(math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600))
  4728. displacement_quantity = math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * replacement_rate
  4729. record.DisplacementQuantity = displacement_quantity
  4730. }
  4731. if adminInfo.Org.Id == 9850 {
  4732. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4733. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  4734. }
  4735. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  4736. this.ServeSuccessJSON(map[string]interface{}{
  4737. "monitor": record,
  4738. "lastMonitorRecordList": lastMonitorRecordList,
  4739. })
  4740. }
  4741. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  4742. record_id, _ := this.GetInt64("id")
  4743. nurseID, _ := this.GetInt64("start_nurse")
  4744. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  4745. bedID, _ := this.GetInt64("bed")
  4746. start_time := this.GetString("start_time")
  4747. schedual_type, _ := this.GetInt64("schedual_type")
  4748. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  4749. change_nurse, _ := this.GetInt64("change_nurse")
  4750. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  4751. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  4752. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  4753. patient_id, _ := this.GetInt64("patient_id")
  4754. record_date, _ := this.GetInt64("record_date")
  4755. puncture_needle := this.GetString("puncture_needle")
  4756. puncture_way := this.GetString("puncture_way")
  4757. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  4758. dialysis_irrigation := this.GetString("dialysis_irrigation")
  4759. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  4760. nuclein_date_str := this.GetString("nuclein_date_str")
  4761. order_remark := this.GetString("order_remark")
  4762. schedule_remark := this.GetString("schedule_remark")
  4763. catheter_operation := this.GetString("catheter_operation")
  4764. blood_flow_volume := this.GetString("blood_flow_volume")
  4765. blood_drawing, _ := this.GetInt64("blood_drawing")
  4766. dialysis_strainer := this.GetString("dialysis_strainer")
  4767. if record_id == 0 {
  4768. this.ErrorLog("id:%v", record_id)
  4769. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4770. return
  4771. }
  4772. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4773. if parseStartDateErr != nil {
  4774. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  4775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4776. return
  4777. }
  4778. adminUserInfo := this.GetMobileAdminUserInfo()
  4779. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4780. if getNurseErr != nil {
  4781. this.ErrorLog("获取护士失败:%v", getNurseErr)
  4782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4783. return
  4784. } else if nurse == nil {
  4785. this.ErrorLog("护士不存在")
  4786. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4787. return
  4788. }
  4789. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  4790. //if getNurseErr != nil {
  4791. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  4792. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4793. // return
  4794. //} else if nurse == nil {
  4795. // this.ErrorLog("护士不存在")
  4796. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4797. // return
  4798. //}
  4799. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  4800. if getDeviceNumberErr != nil {
  4801. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  4802. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4803. return
  4804. } else if deviceNumber == nil {
  4805. this.ErrorLog("床位号不存在")
  4806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4807. return
  4808. }
  4809. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  4810. //
  4811. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  4812. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4813. // if getPermissionErr != nil {
  4814. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4815. // return
  4816. // } else if headNursePermission == nil {
  4817. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4818. // return
  4819. // }
  4820. //}
  4821. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4822. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4823. timeLayout := "2006-01-02 15:04:05"
  4824. loc, _ := time.LoadLocation("Local")
  4825. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4826. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4827. schedulestartTime := theStartTime.Unix()
  4828. scheduleendTime := theEndTime.Unix()
  4829. var theNucleinDate int64
  4830. timeLayoutOne := "2006-01-02"
  4831. if len(nuclein_date_str) > 0 {
  4832. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4833. if err != nil {
  4834. utils.ErrorLog(err.Error())
  4835. }
  4836. theNucleinDate = theTime.Unix()
  4837. }
  4838. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4839. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4840. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4841. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4842. if err == gorm.ErrRecordNotFound { //空床位
  4843. // 修改了床位逻辑
  4844. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4845. if daySchedule.ID > 0 {
  4846. //daySchedule.BedId = bedID
  4847. //daySchedule.PartitionId = deviceNumber.ZoneID
  4848. //daySchedule.ScheduleType = schedual_type
  4849. //daySchedule.UpdatedTime = time.Now().Unix()
  4850. //err := service.UpdateSchedule(&daySchedule)
  4851. xtSchedule := models.Schedule{
  4852. PartitionId: deviceNumber.ZoneID,
  4853. BedId: bedID,
  4854. ScheduleType: schedual_type,
  4855. UpdatedTime: time.Now().Unix(),
  4856. }
  4857. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4858. if err != nil {
  4859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4860. return
  4861. }
  4862. }
  4863. } else if err == nil {
  4864. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4865. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4866. if daySchedule.ID > 0 {
  4867. //daySchedule.BedId = bedID
  4868. //daySchedule.PartitionId = deviceNumber.ZoneID
  4869. //
  4870. //daySchedule.ScheduleType = schedual_type
  4871. //daySchedule.UpdatedTime = time.Now().Unix()
  4872. //err := service.UpdateSchedule(&daySchedule)
  4873. xtSchedule := models.Schedule{
  4874. PartitionId: deviceNumber.ZoneID,
  4875. BedId: bedID,
  4876. ScheduleType: schedual_type,
  4877. UpdatedTime: time.Now().Unix(),
  4878. }
  4879. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4880. if err != nil {
  4881. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4882. return
  4883. }
  4884. }
  4885. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4887. return
  4888. }
  4889. } else if err != nil {
  4890. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4891. return
  4892. }
  4893. }
  4894. dialysisRecord := &models.DialysisOrder{
  4895. ID: record_id,
  4896. UserOrgId: adminUserInfo.Org.Id,
  4897. BedID: bedID,
  4898. StartNurse: nurseID,
  4899. StartTime: startDate.Unix(),
  4900. PunctureNurse: puncture_nurse,
  4901. Creator: adminUserInfo.AdminUser.Id,
  4902. Modifier: adminUserInfo.AdminUser.Id,
  4903. WashpipeNurse: washpipe_nurse,
  4904. SchedualType: schedual_type,
  4905. ChangeNurse: change_nurse,
  4906. DifficultPunctureNurse: difficult_puncture_nurse,
  4907. NewFistulaNurse: new_fistula_nurse,
  4908. QualityNurseId: quality_nurse_id,
  4909. PunctureNeedle: puncture_needle,
  4910. PunctureWay: puncture_way,
  4911. DialysisDialyszers: dialysis_dialyszers,
  4912. DialysisIrrigation: dialysis_irrigation,
  4913. BloodAccessId: blood_access_id,
  4914. NucleinDate: theNucleinDate,
  4915. OrderRemark: order_remark,
  4916. ScheduleRemark: schedule_remark,
  4917. CatheterOperation: catheter_operation,
  4918. BloodFlowVolume: blood_flow_volume,
  4919. BloodDrawing: blood_drawing,
  4920. DialysisStrainer: dialysis_strainer,
  4921. }
  4922. //修改床位号需要重新消毒
  4923. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4924. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4925. //查询第一条监测
  4926. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4927. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4928. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4929. redis := service.RedisClient()
  4930. //清空key 值
  4931. redis.Set(key, "", time.Second)
  4932. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4933. redis.Set(keyOne, "", time.Second)
  4934. defer redis.Close()
  4935. }
  4936. // 查询信息规挡的设置天数
  4937. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4938. if infor.ID > 0 && infor.WeekDay > 0 {
  4939. var cha_time int64
  4940. timeNowStr := time.Now().Format("2006-01-02")
  4941. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4942. //今日的日期减去设置的日期
  4943. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4944. if cha_time >= record_date {
  4945. //查询审核是否允许
  4946. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4947. //申请状态不允许的情况 拒绝修改
  4948. if infor.ApplicationStatus != 1 {
  4949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4950. return
  4951. }
  4952. }
  4953. }
  4954. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4955. //修改床位后重新生成消毒计划
  4956. if adminUserInfo.Org.Id == 10340 {
  4957. //根据床位号获取设备型号
  4958. unitType, _ := service.GetUnitType(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4959. //查询使用消毒最后一条消毒记录
  4960. _, err := service.GetLaseDeviceInfomation(dialysisRecord.UserOrgId, dialysisRecord.BedID, dialysisRecord.DialysisDate, dialysisRecord.SchedualType)
  4961. fmt.Println("err", err)
  4962. if err == gorm.ErrRecordNotFound {
  4963. //查找排班
  4964. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisRecord.PatientId, dialysisRecord.DialysisDate, dialysisRecord.UserOrgId)
  4965. //查询改设备是否有消毒计划
  4966. plan, errcode := service.GetDisInfectionTime(dialysisRecord.UserOrgId, unitType.UnitType, dialysisRecord.SchedualType, scheduleByPatient.ScheduleWeek)
  4967. //根据床位号获取设备id
  4968. addmacher, _ := service.GetEquimentIDTwo(dialysisRecord.BedID, dialysisRecord.UserOrgId)
  4969. //查询病人信息
  4970. patients, _ := service.GetPatientInfoMation(dialysisRecord.PatientId)
  4971. var con = ""
  4972. if patients.IsInfectious == 0 {
  4973. con = ""
  4974. }
  4975. if patients.IsInfectious == 1 {
  4976. con = "无"
  4977. }
  4978. if patients.IsInfectious == 2 {
  4979. con = "有"
  4980. }
  4981. if errcode == nil {
  4982. var end_time int64
  4983. end_time = dialysisRecord.EndTime + plan.DisinfecTime*60
  4984. //新增消毒
  4985. information := models.DeviceInformation{
  4986. Date: dialysisRecord.DialysisDate,
  4987. Zone: dialysisRecord.ZoneId,
  4988. Class: dialysisRecord.SchedualType,
  4989. BedNumber: dialysisRecord.BedID,
  4990. PatientId: dialysisRecord.PatientId,
  4991. DialysisMode: scheduleByPatient.ModeId,
  4992. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  4993. Disinfection: 1,
  4994. DialysisConcentration: 1,
  4995. DisinfectionStatus: 1,
  4996. Move: 1,
  4997. UserOrgId: dialysisRecord.UserOrgId,
  4998. DisinfectType: plan.Way,
  4999. DisinfectantType: plan.MachineDisinfectant,
  5000. FluidPath: plan.DisinfectanWay, //液路消毒方式
  5001. Disinfectant: plan.Disinfectant,
  5002. Ctime: time.Now().Unix(),
  5003. Status: 1,
  5004. SignName: nurseID,
  5005. EquimentId: addmacher.ID,
  5006. DisinfectionResidue: 2,
  5007. Bed: addmacher.BedNumber,
  5008. StartTime: dialysisRecord.StartTime,
  5009. EndTime: dialysisRecord.EndTime,
  5010. Contagion: con,
  5011. WeightLoss: 0,
  5012. Hyperfiltratio: 0,
  5013. DialysisHour: "",
  5014. MachineRun: 1,
  5015. DisinfecStartime: dialysisRecord.EndTime,
  5016. DisinfecEndtime: end_time,
  5017. }
  5018. err := service.CreateInformationTwo(&information)
  5019. fmt.Println("报错", err)
  5020. }
  5021. }
  5022. }
  5023. order, _ := service.GetLastPatientOrder(record_id)
  5024. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  5025. redis := service.RedisClient()
  5026. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  5027. redis.Set(key, "", time.Second)
  5028. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5029. //清空key 值
  5030. redis.Set(keyOne, "", time.Second)
  5031. scheduleDateStartOne := startDate.Format("2006-01-02")
  5032. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5033. redis.Set(keyTwo, "", time.Second)
  5034. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  5035. redis.Set(keyThree, "", time.Second)
  5036. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5037. redis.Set(keyFour, "", time.Second)
  5038. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  5039. redis.Set(keyFive, "", time.Second)
  5040. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  5041. redis.Set(keySix, "", time.Second)
  5042. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  5043. redis.Set(keySeven, "", time.Second)
  5044. if updateErr != nil {
  5045. this.ErrorLog("修改上机失败:%v", updateErr)
  5046. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5047. return
  5048. }
  5049. if updateErr == nil {
  5050. if tempDialysisRecord.Stage == 2 {
  5051. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  5052. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5053. fmt.Println(value)
  5054. a, b := math.Modf(value)
  5055. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5056. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5057. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5058. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  5059. redis := service.RedisClient()
  5060. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  5061. redis.Set(key, "", time.Second)
  5062. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  5063. redis.Set(keyOne, "", time.Second)
  5064. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  5065. //清空key 值
  5066. redis.Set(keySix, "", time.Second)
  5067. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  5068. redis.Set(keySeven, "", time.Second)
  5069. redis.Close()
  5070. if updateAssessmentErr != nil {
  5071. utils.ErrorLog("%v", updateAssessmentErr)
  5072. }
  5073. }
  5074. }
  5075. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5076. this.ServeSuccessJSON(map[string]interface{}{
  5077. "dialysis_order": dialysisRecords,
  5078. })
  5079. }
  5080. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  5081. record_id, _ := c.GetInt64("id")
  5082. nurseID, _ := c.GetInt64("nurse")
  5083. end_time := c.GetString("end_time")
  5084. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  5085. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  5086. catheter := c.GetString("catheter")
  5087. cruor := c.GetString("cruor")
  5088. mission := c.GetString("mission")
  5089. condenser := c.GetString("condenser")
  5090. if record_id <= 0 || nurseID <= 0 {
  5091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5092. return
  5093. }
  5094. adminUserInfo := c.GetMobileAdminUserInfo()
  5095. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  5096. if getNurseErr != nil {
  5097. c.ErrorLog("获取护士失败:%v", getNurseErr)
  5098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5099. return
  5100. } else if nurse == nil {
  5101. c.ErrorLog("护士不存在")
  5102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5103. return
  5104. }
  5105. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  5106. if parseEndDateErr != nil {
  5107. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  5108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5109. return
  5110. }
  5111. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  5112. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  5113. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  5114. // if getPermissionErr != nil {
  5115. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5116. // return
  5117. // } else if headNursePermission == nil {
  5118. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  5119. // return
  5120. // }
  5121. //}
  5122. // 查询信息规挡的设置天数
  5123. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  5124. if infor.ID > 0 {
  5125. var cha_time int64
  5126. timeNowStr := time.Now().Format("2006-01-02")
  5127. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5128. //今日的日期减去设置的日期
  5129. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5130. if cha_time >= tempDialysisRecords.DialysisDate {
  5131. //查询审核是否允许
  5132. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  5133. //申请状态不允许的情况 拒绝修改
  5134. if infor.ApplicationStatus != 1 {
  5135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5136. return
  5137. }
  5138. }
  5139. }
  5140. dialysisRecord := &models.DialysisOrder{
  5141. ID: record_id,
  5142. UserOrgId: adminUserInfo.Org.Id,
  5143. EndTime: endDate.Unix(),
  5144. FinishNurse: nurseID,
  5145. FinishModifier: adminUserInfo.AdminUser.Id,
  5146. PuncturePointHaematoma: puncture_point_haematoma,
  5147. BloodAccessInternalFistula: blood_access_internal_fistula,
  5148. Catheter: catheter,
  5149. Cruor: cruor,
  5150. Mission: mission,
  5151. Condenser: condenser,
  5152. }
  5153. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  5154. redis := service.RedisClient()
  5155. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  5156. //清空key 值
  5157. redis.Set(key, "", time.Second)
  5158. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5159. //清空key 值
  5160. redis.Set(keyOne, "", time.Second)
  5161. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5162. redis.Set(keySeven, "", time.Second)
  5163. redis.Close()
  5164. if updateErr != nil {
  5165. c.ErrorLog("修改下机失败:%v", updateErr)
  5166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5167. return
  5168. }
  5169. if updateErr == nil {
  5170. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  5171. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  5172. a, b := math.Modf(value)
  5173. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  5174. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  5175. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  5176. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  5177. redis := service.RedisClient()
  5178. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  5179. redis.Set(keyTen, "", time.Second)
  5180. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  5181. redis.Set(keyTwo, "", time.Second)
  5182. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  5183. redis.Set(key, "", time.Second)
  5184. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  5185. redis.Set(keyThree, "", time.Second)
  5186. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  5187. redis.Set(keySeven, "", time.Second)
  5188. defer redis.Close()
  5189. if updateAssessmentErr != nil {
  5190. utils.ErrorLog("%v", updateAssessmentErr)
  5191. }
  5192. }
  5193. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  5194. c.ServeSuccessJSON(map[string]interface{}{
  5195. "dialysis_order": dialysisRecords,
  5196. })
  5197. }
  5198. func (c *DialysisAPIController) GetLongAdvice() {
  5199. patient_id, _ := c.GetInt64("id")
  5200. adminUserInfo := c.GetMobileAdminUserInfo()
  5201. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5202. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5203. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5204. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5205. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5206. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5207. c.ServeSuccessJSON(map[string]interface{}{
  5208. "status": "1",
  5209. })
  5210. return
  5211. } else { //开启推送提醒
  5212. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5213. var advice_three []*models.DoctorAdvice
  5214. recordDateStr := time.Now().Format("2006-01-02")
  5215. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5216. nowtime := recordDate.Unix()
  5217. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  5218. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  5219. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  5220. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  5221. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  5222. for _, advice := range advices {
  5223. if advice.FrequencyType == 3 {
  5224. t := time.Now()
  5225. week := int(t.Weekday())
  5226. fmt.Println(t.Weekday())
  5227. fmt.Println(week)
  5228. switch week {
  5229. case 1:
  5230. if strings.Index(advice.WeekDay, "周一") == -1 {
  5231. advice_three = append(advice_three, advice)
  5232. }
  5233. break
  5234. case 2:
  5235. if strings.Index(advice.WeekDay, "周二") == -1 {
  5236. advice_three = append(advice_three, advice)
  5237. }
  5238. break
  5239. case 3:
  5240. if strings.Index(advice.WeekDay, "周三") == -1 {
  5241. advice_three = append(advice_three, advice)
  5242. }
  5243. break
  5244. case 4:
  5245. if strings.Index(advice.WeekDay, "周四") == -1 {
  5246. advice_three = append(advice_three, advice)
  5247. }
  5248. break
  5249. case 5:
  5250. if strings.Index(advice.WeekDay, "周五") == -1 {
  5251. advice_three = append(advice_three, advice)
  5252. }
  5253. break
  5254. case 6:
  5255. if strings.Index(advice.WeekDay, "周六") == -1 {
  5256. advice_three = append(advice_three, advice)
  5257. }
  5258. break
  5259. case 0:
  5260. if strings.Index(advice.WeekDay, "周日") == -1 {
  5261. advice_three = append(advice_three, advice)
  5262. }
  5263. break
  5264. }
  5265. }
  5266. }
  5267. for _, advice := range advices_two {
  5268. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5269. now := p.Unix()
  5270. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5271. dayStr2 := "-" + dayStr
  5272. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5273. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5274. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5275. for _, ad := range advices {
  5276. advice_three = append(advice_three, ad)
  5277. }
  5278. }
  5279. if err == nil {
  5280. c.ServeSuccessJSON(map[string]interface{}{
  5281. "status": "2",
  5282. "advices": advices,
  5283. "advices_two": RemoveRepeatedElement(advice_three),
  5284. "is_open_remind": config.IsOpenRemind,
  5285. "his_config_open": hisConfig.IsOpen,
  5286. "is_advice_open": is_advice_open.IsAdviceOpen,
  5287. "prescription_open": prescription_open.IsOpen,
  5288. })
  5289. }
  5290. }
  5291. }
  5292. func (c *DialysisAPIController) GetLongAdviceOne() {
  5293. patient_id, _ := c.GetInt64("id")
  5294. startTime := c.GetString("schedule_date")
  5295. timeLayout := "2006-01-02"
  5296. loc, _ := time.LoadLocation("Local")
  5297. var theStartTime int64
  5298. if len(startTime) > 0 {
  5299. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  5300. if err != nil {
  5301. utils.ErrorLog(err.Error())
  5302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5303. return
  5304. }
  5305. theStartTime = theTime.Unix()
  5306. }
  5307. adminUserInfo := c.GetMobileAdminUserInfo()
  5308. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  5309. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  5310. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  5311. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  5312. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  5313. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  5314. c.ServeSuccessJSON(map[string]interface{}{
  5315. "status": "1",
  5316. })
  5317. return
  5318. } else { //开启推送提醒
  5319. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  5320. var advice_three []*models.DoctorAdvice
  5321. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  5322. fmt.Println("theStartTime-----------------------", theStartTime)
  5323. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  5324. for _, advice := range advices {
  5325. if advice.FrequencyType == 3 {
  5326. t := time.Now()
  5327. week := int(t.Weekday())
  5328. fmt.Println(t.Weekday())
  5329. fmt.Println(week)
  5330. switch week {
  5331. case 1:
  5332. if strings.Index(advice.WeekDay, "周一") == -1 {
  5333. advice_three = append(advice_three, advice)
  5334. }
  5335. break
  5336. case 2:
  5337. if strings.Index(advice.WeekDay, "周二") == -1 {
  5338. advice_three = append(advice_three, advice)
  5339. }
  5340. break
  5341. case 3:
  5342. if strings.Index(advice.WeekDay, "周三") == -1 {
  5343. advice_three = append(advice_three, advice)
  5344. }
  5345. break
  5346. case 4:
  5347. if strings.Index(advice.WeekDay, "周四") == -1 {
  5348. advice_three = append(advice_three, advice)
  5349. }
  5350. break
  5351. case 5:
  5352. if strings.Index(advice.WeekDay, "周五") == -1 {
  5353. advice_three = append(advice_three, advice)
  5354. }
  5355. break
  5356. case 6:
  5357. if strings.Index(advice.WeekDay, "周六") == -1 {
  5358. advice_three = append(advice_three, advice)
  5359. }
  5360. break
  5361. case 0:
  5362. if strings.Index(advice.WeekDay, "周日") == -1 {
  5363. advice_three = append(advice_three, advice)
  5364. }
  5365. break
  5366. }
  5367. }
  5368. }
  5369. for _, advice := range advices_two {
  5370. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  5371. now := p.Unix()
  5372. dayStr := strconv.FormatInt(advice.DayCount, 10)
  5373. dayStr2 := "-" + dayStr
  5374. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  5375. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  5376. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  5377. fmt.Println("advices-==---------------", advices)
  5378. for _, ad := range advices {
  5379. advice_three = append(advice_three, ad)
  5380. }
  5381. }
  5382. if err == nil {
  5383. c.ServeSuccessJSON(map[string]interface{}{
  5384. "status": "2",
  5385. "advices": advices,
  5386. "advices_two": RemoveRepeatedElement(advice_three),
  5387. "is_open_remind": config.IsOpenRemind,
  5388. "his_config_open": hisConfig.IsOpen,
  5389. "is_advice_open": is_advice_open.IsAdviceOpen,
  5390. "prescription_open": prescription_open.IsOpen,
  5391. })
  5392. }
  5393. }
  5394. }
  5395. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  5396. newArr = make([]*models.DoctorAdvice, 0)
  5397. for i := 0; i < len(arr); i++ {
  5398. repeat := false
  5399. for j := i + 1; j < len(arr); j++ {
  5400. if arr[i].ID == arr[j].ID {
  5401. repeat = true
  5402. break
  5403. }
  5404. }
  5405. if !repeat {
  5406. newArr = append(newArr, arr[i])
  5407. }
  5408. }
  5409. return
  5410. }
  5411. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  5412. patient, _ := c.GetInt64("id", 0)
  5413. groupNo, _ := c.GetInt64("groupno", 0)
  5414. if patient <= 0 {
  5415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5416. return
  5417. }
  5418. adminUserInfo := c.GetMobileAdminUserInfo()
  5419. dataBody := make(map[string]interface{}, 0)
  5420. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5421. if err != nil {
  5422. utils.ErrorLog(err.Error())
  5423. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5424. return
  5425. }
  5426. utils.ErrorLog("%v", dataBody)
  5427. timeLayout := "2006-01-02 15:04"
  5428. loc, _ := time.LoadLocation("Local")
  5429. timeLayout2 := "2006-01-02"
  5430. loc2, _ := time.LoadLocation("Local")
  5431. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  5432. utils.ErrorLog("advice_type")
  5433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5434. return
  5435. }
  5436. adviceType := int64(2)
  5437. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  5438. utils.ErrorLog("advice_date")
  5439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5440. return
  5441. }
  5442. adviceDate, _ := dataBody["advice_date"].(string)
  5443. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  5444. AdviceDate := theTime.Unix()
  5445. RecordDate := theTime.Unix()
  5446. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  5447. utils.ErrorLog("start_time")
  5448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5449. return
  5450. }
  5451. startTime, _ := dataBody["start_time"].(string)
  5452. if len(startTime) == 0 {
  5453. utils.ErrorLog("len(start_time) == 0")
  5454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5455. return
  5456. }
  5457. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  5458. if err != nil {
  5459. utils.ErrorLog(err.Error())
  5460. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5461. return
  5462. }
  5463. StartTime := theTime.Unix()
  5464. Remark := ""
  5465. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  5466. remark, _ := dataBody["remark"].(string)
  5467. Remark = remark
  5468. }
  5469. var advices []*models.GroupAdvice
  5470. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  5471. utils.ErrorLog("advices")
  5472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5473. return
  5474. }
  5475. adviceNames := dataBody["advices"].([]interface{})
  5476. for _, adviceNameMap := range adviceNames {
  5477. adviceNameM := adviceNameMap.(map[string]interface{})
  5478. var advice models.GroupAdvice
  5479. advice.Remark = Remark
  5480. advice.AdviceType = adviceType
  5481. advice.StartTime = StartTime
  5482. advice.AdviceDate = AdviceDate
  5483. advice.RecordDate = RecordDate
  5484. advice.Status = 1
  5485. advice.CreatedTime = time.Now().Unix()
  5486. advice.UpdatedTime = time.Now().Unix()
  5487. advice.StopState = 2
  5488. advice.ExecutionState = 2
  5489. advice.UserOrgId = adminUserInfo.Org.Id
  5490. advice.PatientId = patient
  5491. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  5492. advice.IsSettle = 2
  5493. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  5494. utils.ErrorLog("advice_name")
  5495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5496. return
  5497. }
  5498. adviceName, _ := adviceNameM["advice_name"].(string)
  5499. if len(adviceName) == 0 {
  5500. utils.ErrorLog("len(advice_name) == 0")
  5501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5502. return
  5503. }
  5504. advice.AdviceName = adviceName
  5505. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  5506. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  5507. advice.DrugSpec = drugSpec
  5508. }
  5509. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  5510. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  5511. advice.AdviceDesc = adviceDesc
  5512. }
  5513. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  5514. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  5515. advice.DrugSpecUnit = drugSpecUnit
  5516. }
  5517. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  5518. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  5519. // advice.SingleDose = singleDose
  5520. //}
  5521. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  5522. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5523. advice.SingleDose = adviceNameM["single_dose"].(float64)
  5524. }
  5525. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  5526. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  5527. advice.SingleDoseUnit = singleDoseUnit
  5528. }
  5529. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  5530. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  5531. // advice.PrescribingNumber = prescribingNumber
  5532. //}
  5533. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  5534. //single_dose := int64(adviceNameM["single_dose"].(float64))
  5535. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  5536. }
  5537. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  5538. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  5539. advice.PrescribingNumberUnit = prescribingNumberUnit
  5540. }
  5541. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  5542. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  5543. advice.DeliveryWay = deliveryWay
  5544. }
  5545. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5546. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5547. advice.ExecutionFrequency = executionFrequency
  5548. }
  5549. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5550. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5551. advice.FrequencyType = frequency_type
  5552. }
  5553. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5554. day_count := int64(adviceNameM["day_count"].(float64))
  5555. advice.DayCount = day_count
  5556. }
  5557. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5558. week_day, _ := adviceNameM["week_day"].(string)
  5559. advice.WeekDay = week_day
  5560. }
  5561. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5562. way := int64(adviceNameM["way"].(float64))
  5563. advice.Way = way
  5564. }
  5565. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5566. drug_id := int64(adviceNameM["drug_id"].(float64))
  5567. advice.DrugId = drug_id
  5568. }
  5569. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5570. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5571. advice.DrugNameId = drug_name_id
  5572. }
  5573. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  5574. remark, _ := adviceNameM["remark"].(string)
  5575. advice.Remark = remark
  5576. }
  5577. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  5578. groupno := int64(adviceNameM["groupno"].(float64))
  5579. advice.GroupNo = groupno
  5580. }
  5581. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5582. template_id, _ := adviceNameM["template_id"].(string)
  5583. advice.TemplateId = template_id
  5584. }
  5585. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  5586. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5587. advice.ExecutionFrequency = executionFrequency
  5588. }
  5589. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5590. children := adviceNameM["child"].([]interface{})
  5591. if len(children) > 0 {
  5592. for _, childrenMap := range children {
  5593. childMap := childrenMap.(map[string]interface{})
  5594. var child models.GroupAdvice
  5595. child.Remark = Remark
  5596. child.AdviceType = adviceType
  5597. child.StartTime = StartTime
  5598. child.AdviceDate = AdviceDate
  5599. child.RecordDate = RecordDate
  5600. child.Status = 1
  5601. child.CreatedTime = time.Now().Unix()
  5602. child.UpdatedTime = time.Now().Unix()
  5603. child.StopState = 2
  5604. child.ExecutionState = 2
  5605. child.UserOrgId = adminUserInfo.Org.Id
  5606. child.PatientId = patient
  5607. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5608. child.IsSettle = 1
  5609. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5610. utils.ErrorLog("child advice_name")
  5611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5612. return
  5613. }
  5614. childAdviceName, _ := childMap["advice_name"].(string)
  5615. if len(childAdviceName) == 0 {
  5616. utils.ErrorLog("len(child advice_name) == 0")
  5617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5618. return
  5619. }
  5620. child.AdviceName = childAdviceName
  5621. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5622. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5623. child.AdviceDesc = childAdviceDesc
  5624. }
  5625. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5626. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5627. child.DrugSpec = childDrugSpec
  5628. }
  5629. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5630. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5631. child.DrugSpecUnit = childDrugSpecUnit
  5632. }
  5633. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5634. child.SingleDose = childMap["single_dose"].(float64)
  5635. }
  5636. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5637. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5638. child.SingleDoseUnit = childSingleDoseUnit
  5639. }
  5640. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5641. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5642. }
  5643. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5644. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5645. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5646. }
  5647. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  5648. groupno := int64(childMap["groupno"].(float64))
  5649. advice.GroupNo = groupno
  5650. }
  5651. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5652. remark, _ := childMap["remark"].(string)
  5653. child.Remark = remark
  5654. }
  5655. child.DeliveryWay = advice.DeliveryWay
  5656. child.ExecutionFrequency = advice.ExecutionFrequency
  5657. advice.Children = append(advice.Children, &child)
  5658. }
  5659. }
  5660. }
  5661. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  5662. if temp_advice.ID == 0 {
  5663. advices = append(advices, &advice)
  5664. }
  5665. }
  5666. if len(advices) > 0 {
  5667. finish := models.XtDialysisFinish{
  5668. IsFinish: 1,
  5669. UserOrgId: adminUserInfo.Org.Id,
  5670. Status: 1,
  5671. Ctime: time.Now().Unix(),
  5672. Mtime: 0,
  5673. Module: 4,
  5674. RecordDate: AdviceDate,
  5675. Sourse: 1,
  5676. PatientId: patient,
  5677. }
  5678. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  5679. if dialysisFinish.ID == 0 {
  5680. service.CreateDialysisFinish(finish)
  5681. }
  5682. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 {
  5683. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  5684. for _, item := range advices {
  5685. byterequest, _ := json.Marshal(item)
  5686. adviceLog := models.XtDoctorAdviceLog{
  5687. UserOrgId: adminUserInfo.Org.Id,
  5688. PatientId: patient,
  5689. AdminUserId: adminUserInfo.AdminUser.Id,
  5690. Module: 1,
  5691. ErrLog: string(byterequest),
  5692. Status: 1,
  5693. Ctime: time.Now().Unix(),
  5694. Mtime: 0,
  5695. Source: "手机端医嘱推送",
  5696. RecordDate: item.AdviceDate,
  5697. }
  5698. service.CreateDoctorAdviceLog(adviceLog)
  5699. }
  5700. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5701. redis := service.RedisClient()
  5702. //清空key 值
  5703. redis.Set(key, "", time.Second)
  5704. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5705. redis.Set(keyOne, "", time.Second)
  5706. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5707. defer redis.Close()
  5708. redis.Set(keyThree, "", time.Second)
  5709. if err != nil {
  5710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5711. return
  5712. }
  5713. c.ServeSuccessJSON(map[string]interface{}{
  5714. "msg": "ok",
  5715. "advices": list,
  5716. })
  5717. } else {
  5718. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  5719. for _, item := range advices {
  5720. byterequest, _ := json.Marshal(item)
  5721. adviceLog := models.XtDoctorAdviceLog{
  5722. UserOrgId: adminUserInfo.Org.Id,
  5723. PatientId: patient,
  5724. AdminUserId: adminUserInfo.AdminUser.Id,
  5725. Module: 1,
  5726. ErrLog: string(byterequest),
  5727. Status: 1,
  5728. Ctime: time.Now().Unix(),
  5729. Mtime: 0,
  5730. Source: "手机端医嘱推送",
  5731. RecordDate: item.AdviceDate,
  5732. }
  5733. service.CreateDoctorAdviceLog(adviceLog)
  5734. }
  5735. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  5736. redis := service.RedisClient()
  5737. //清空key 值
  5738. redis.Set(key, "", time.Second)
  5739. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5740. redis.Set(keyOne, "", time.Second)
  5741. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5742. defer redis.Close()
  5743. redis.Set(keyThree, "", time.Second)
  5744. if err != nil {
  5745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5746. return
  5747. }
  5748. c.ServeSuccessJSON(map[string]interface{}{
  5749. "msg": "ok",
  5750. "advices": list,
  5751. })
  5752. }
  5753. } else {
  5754. c.ServeSuccessJSON(map[string]interface{}{
  5755. "msg": "ok",
  5756. })
  5757. }
  5758. return
  5759. }
  5760. func (c *DialysisAPIController) UploadDryWeight() {
  5761. patient_id, _ := c.GetInt64("id")
  5762. dry_weight, _ := c.GetFloat("dry_weight")
  5763. doctor_id, _ := c.GetInt64("doctor_id")
  5764. remark := c.GetString("remark")
  5765. adminUserInfo := c.GetMobileAdminUserInfo()
  5766. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  5767. if err == gorm.ErrRecordNotFound {
  5768. dryWeight := &models.SgjPatientDryweight{
  5769. PatientId: patient_id,
  5770. DryWeight: dry_weight,
  5771. Remakes: remark,
  5772. Ctime: time.Now().Unix(),
  5773. Mtime: time.Now().Unix(),
  5774. Creator: doctor_id,
  5775. Status: 1,
  5776. UserOrgId: adminUserInfo.Org.Id,
  5777. AdjustedValue: "/",
  5778. UserId: adminUserInfo.AdminUser.Id,
  5779. }
  5780. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5781. redis := service.RedisClient()
  5782. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  5783. redis.Set(keyOne, "", time.Second)
  5784. loc, _ := time.LoadLocation("Local")
  5785. nowTime := time.Now()
  5786. nowDay := nowTime.Format("2006-01-02")
  5787. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5788. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5789. redis.Set(key, "", time.Second)
  5790. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5791. redis.Set(keyTwo, "", time.Second)
  5792. redis.Close()
  5793. if createErr == nil {
  5794. c.ServeSuccessJSON(map[string]interface{}{
  5795. "msg": "提交成功",
  5796. "weight": dryWeight,
  5797. })
  5798. }
  5799. } else {
  5800. dryWeight := &models.SgjPatientDryweight{
  5801. PatientId: patient_id,
  5802. DryWeight: dry_weight,
  5803. Remakes: remark,
  5804. Ctime: time.Now().Unix(),
  5805. Mtime: time.Now().Unix(),
  5806. Creator: doctor_id,
  5807. Status: 1,
  5808. UserOrgId: adminUserInfo.Org.Id,
  5809. AdjustedValue: "/",
  5810. UserId: adminUserInfo.AdminUser.Id,
  5811. }
  5812. var value float64
  5813. value = dry_weight - weightAdjust.DryWeight
  5814. if value < 0 {
  5815. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5816. } else if value == 0 {
  5817. dryWeight.AdjustedValue = "/"
  5818. } else if value > 0 {
  5819. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5820. }
  5821. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5822. //康桥
  5823. if adminUserInfo.Org.Id == 10702 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10721 {
  5824. timeNowStr := time.Now().Format("2006-01-02")
  5825. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5826. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5827. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.Org.Id)
  5828. if beforAssesment.ID > 0 {
  5829. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5830. var dewater_amount float64
  5831. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5832. if adminUserInfo.Org.Id != 10702 {
  5833. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5834. }
  5835. if adminUserInfo.Org.Id == 10702 {
  5836. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  5837. }
  5838. //获取key,清空redis
  5839. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5840. redis := service.RedisClient()
  5841. //清空key 值
  5842. redis.Set(key, "", time.Second)
  5843. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  5844. //清空key 值
  5845. redis.Set(keyOne, "", time.Second)
  5846. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5847. //清空key 值
  5848. redis.Set(keyTwo, "", time.Second)
  5849. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5850. redis.Set(keySix, "", time.Second)
  5851. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5852. redis.Set(keySeven, "", time.Second)
  5853. }
  5854. }
  5855. redis := service.RedisClient()
  5856. loc, _ := time.LoadLocation("Local")
  5857. nowTime := time.Now()
  5858. nowDay := nowTime.Format("2006-01-02")
  5859. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5860. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5861. redis.Set(keyOne, "", time.Second)
  5862. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5863. redis.Set(key, "", time.Second)
  5864. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5865. redis.Set(keyTwo, "", time.Second)
  5866. redis.Close()
  5867. if createErr == nil {
  5868. c.ServeSuccessJSON(map[string]interface{}{
  5869. "msg": "提交成功",
  5870. "weight": dryWeight,
  5871. })
  5872. }
  5873. }
  5874. }
  5875. func (c *DialysisAPIController) GetSolution() {
  5876. patient_id, _ := c.GetInt64("patient_id")
  5877. mode_id, _ := c.GetInt64("mode_id")
  5878. adminUserInfo := c.GetMobileAdminUserInfo()
  5879. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5880. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  5881. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  5882. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  5883. if err != nil {
  5884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5885. return
  5886. }
  5887. c.ServeSuccessJSON(map[string]interface{}{
  5888. "solution": solution,
  5889. "prescription": prescription,
  5890. "system_prescription": system_prescription,
  5891. "dialysisPrescription": dialysisPrescription,
  5892. })
  5893. }
  5894. func (c *DialysisAPIController) GetSchedule() {
  5895. schedual_type, _ := c.GetInt64("schedual_type")
  5896. adminUserInfo := c.GetMobileAdminUserInfo()
  5897. scheduleTime, _ := c.GetInt64("record_date")
  5898. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  5899. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  5900. c.ServeSuccessJSON(map[string]interface{}{
  5901. "number": deviceNumber,
  5902. "list": list,
  5903. })
  5904. }
  5905. func (c *DialysisAPIController) GetPatientId() {
  5906. id, _ := c.GetInt64("id")
  5907. //orgid := c.GetMobileAdminUserInfo().Org.Id
  5908. patientId, _ := service.GetPatientId(id)
  5909. //获取该患者的所有传染病
  5910. list, _ := service.GetPatientInfectious(id)
  5911. c.ServeSuccessJSON(map[string]interface{}{
  5912. "patient": patientId,
  5913. "infectioulist": list,
  5914. })
  5915. }
  5916. func (this *DialysisAPIController) GetDialysisSchedule() {
  5917. schedualDate := this.GetString("date")
  5918. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5919. if parseDateErr != nil {
  5920. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5921. return
  5922. }
  5923. adminInfo := this.GetMobileAdminUserInfo()
  5924. orgID := adminInfo.Org.Id
  5925. redis := service.RedisClient()
  5926. defer redis.Close()
  5927. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5928. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5929. if len(scheduals) > 0 {
  5930. //缓存数据
  5931. scheduals_json, err := json.Marshal(scheduals)
  5932. if err == nil {
  5933. redis.Set(key, scheduals_json, time.Second*30)
  5934. }
  5935. }
  5936. this.ServeSuccessJSON(map[string]interface{}{
  5937. "scheduals": scheduals,
  5938. })
  5939. }
  5940. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5941. change_type, _ := this.GetInt64("type", 0)
  5942. record_date := this.GetString("record_time")
  5943. patient_id, _ := this.GetInt64("patient_id", 0)
  5944. timeLayout := "2006-01-02"
  5945. loc, _ := time.LoadLocation("Local")
  5946. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5947. record_time := theAdviceRecordTime.Unix()
  5948. adminUserInfo := this.GetMobileAdminUserInfo()
  5949. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5950. if err == nil {
  5951. if len(advices) == 0 {
  5952. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5953. return
  5954. } else {
  5955. this.ServeSuccessJSON(map[string]interface{}{
  5956. "advices": advices,
  5957. "schedule": sch,
  5958. })
  5959. return
  5960. }
  5961. } else {
  5962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5963. return
  5964. }
  5965. }
  5966. func (c *DialysisAPIController) CreateConsumables() {
  5967. record_date := c.GetString("record_time")
  5968. patient_id, _ := c.GetInt64("patient_id", 0)
  5969. active, _ := c.GetInt64("active")
  5970. adminUser := c.GetMobileAdminUserInfo()
  5971. timeLayout := "2006-01-02"
  5972. loc, _ := time.LoadLocation("Local")
  5973. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5974. record_time := theRecordTime.Unix()
  5975. // 查询信息规挡的设置天数
  5976. orgid := c.GetMobileAdminUserInfo().Org.Id
  5977. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5978. if infor.ID > 0 {
  5979. var cha_time int64
  5980. timeNowStr := time.Now().Format("2006-01-02")
  5981. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5982. //今日的日期减去设置的日期
  5983. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5984. if cha_time >= record_time {
  5985. //查询审核是否允许
  5986. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5987. //申请状态不允许的情况 拒绝修改
  5988. if infor.ApplicationStatus != 1 {
  5989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5990. return
  5991. }
  5992. }
  5993. }
  5994. dataBody := make(map[string]interface{}, 0)
  5995. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5996. if err != nil {
  5997. utils.ErrorLog(err.Error())
  5998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5999. return
  6000. }
  6001. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6002. var beforePrepares []*models.DialysisBeforePrepareGoods
  6003. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6004. var dialysisBefor []*models.DialysisBeforePrepare
  6005. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6006. goods, _ := dataBody["goods"].([]interface{})
  6007. if len(goods) > 0 {
  6008. for _, item := range goods {
  6009. items := item.(map[string]interface{})
  6010. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6011. utils.ErrorLog("good_id")
  6012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6013. return
  6014. }
  6015. good_id := int64(items["good_id"].(float64))
  6016. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6017. utils.ErrorLog("good_type_id")
  6018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6019. return
  6020. }
  6021. good_type_id := int64(items["good_type_id"].(float64))
  6022. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6023. utils.ErrorLog("count")
  6024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6025. return
  6026. }
  6027. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6028. commdity_code := items["commdity_code"].(string)
  6029. fmt.Println("commdity", commdity_code)
  6030. prepareGoods := &models.DialysisBeforePrepareGoods{
  6031. GoodTypeId: good_type_id,
  6032. GoodId: good_id,
  6033. Count: count,
  6034. StorehouseId: houseConfig.StorehouseOutInfo,
  6035. }
  6036. beforePrepares = append(beforePrepares, prepareGoods)
  6037. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6038. GoodTypeId: good_type_id,
  6039. GoodId: good_id,
  6040. Count: count,
  6041. StorehouseId: houseConfig.StorehouseOutInfo,
  6042. }
  6043. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6044. prepare := &models.DialysisBeforePrepare{
  6045. GoodTypeId: good_type_id,
  6046. GoodId: good_id,
  6047. Count: count,
  6048. PatientId: patient_id,
  6049. RecordDate: record_time,
  6050. UserOrgId: adminUser.Org.Id,
  6051. Status: 1,
  6052. Ctime: time.Now().Unix(),
  6053. Creater: adminUser.AdminUser.Id,
  6054. CommdityCode: commdity_code,
  6055. StorehouseId: houseConfig.StorehouseOutInfo,
  6056. }
  6057. dialysisBefor = append(dialysisBefor, prepare)
  6058. }
  6059. }
  6060. //查询是否有库存
  6061. for _, item := range dialysisBefor {
  6062. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6063. if err == gorm.ErrRecordNotFound {
  6064. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6065. c.ServeSuccessJSON(map[string]interface{}{
  6066. "message": "1",
  6067. "good_name": goodObj.GoodName,
  6068. "specification_name": goodObj.SpecificationName,
  6069. })
  6070. return
  6071. }
  6072. if err != nil {
  6073. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6074. c.ServeSuccessJSON(map[string]interface{}{
  6075. "message": "1",
  6076. "good_name": goodObj.GoodName,
  6077. "specification_name": goodObj.SpecificationName,
  6078. })
  6079. return
  6080. }
  6081. }
  6082. fmt.Println("active-----------------------", active)
  6083. fmt.Println("len(goods)-----------------------", len(goods))
  6084. //新增
  6085. if active == 1 && len(goods) > 0 {
  6086. for _, item := range dialysisBefor {
  6087. dialyPrepareOne := models.DialysisBeforePrepare{
  6088. GoodTypeId: item.GoodTypeId,
  6089. GoodId: item.GoodId,
  6090. PatientId: item.PatientId,
  6091. RecordDate: item.RecordDate,
  6092. UserOrgId: item.UserOrgId,
  6093. Count: item.Count,
  6094. Ctime: time.Now().Unix(),
  6095. Creater: item.Creater,
  6096. CommdityCode: item.CommdityCode,
  6097. Status: 1,
  6098. StorehouseId: houseConfig.StorehouseOutInfo,
  6099. }
  6100. //先清除再插入
  6101. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6102. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  6103. //查询默认仓库
  6104. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6105. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6106. var total_count int64
  6107. for _, it := range stockList {
  6108. total_count += it.StockCount
  6109. }
  6110. //基础库插入数据
  6111. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6112. //更新库存
  6113. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6114. var flush_count int64
  6115. for _, it := range goodList {
  6116. flush_count += it.StockCount
  6117. }
  6118. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6119. }
  6120. if err == nil {
  6121. c.ServeSuccessJSON(map[string]interface{}{
  6122. "msg": "保存成功",
  6123. "message": "2",
  6124. })
  6125. return
  6126. } else {
  6127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6128. return
  6129. }
  6130. }
  6131. if len(beforePrepares) > 0 && active == 2 {
  6132. for _, item := range beforePrepares {
  6133. //1.查看该患者该耗材型号最后一次出库数量
  6134. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6135. //判断当前出库数量和最后一次出库数量的大小
  6136. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  6137. if item.Count <= goodInfo.Count {
  6138. //退库
  6139. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  6140. //查询今日出库数据
  6141. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6142. for _, it := range list {
  6143. prepare := models.DialysisBeforePrepare{
  6144. UserOrgId: it.OrgId,
  6145. PatientId: patient_id,
  6146. RecordDate: it.RecordTime,
  6147. GoodId: it.GoodId,
  6148. GoodTypeId: it.GoodTypeId,
  6149. Count: it.Count,
  6150. Ctime: time.Now().Unix(),
  6151. Creater: adminUser.AdminUser.Id,
  6152. Status: 1,
  6153. StorehouseId: houseConfig.StorehouseOutInfo,
  6154. }
  6155. //删除准备表数据
  6156. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6157. service.CreateDialysisBeforePrepareOne(&prepare)
  6158. }
  6159. }
  6160. var last_total int64
  6161. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6162. if item.Count >= goodInfo.Count {
  6163. //查询当前批次当前耗材最后一条出库数据
  6164. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6165. //计算当前出库和最后一次出库数据相差数据
  6166. last_total = item.Count - lastOutInfo.Count
  6167. //查询该批次剩余库存
  6168. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  6169. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  6170. if lastInfo.StockCount >= last_total {
  6171. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6172. //查询今日出库数据
  6173. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6174. for _, it := range list {
  6175. prepare := models.DialysisBeforePrepare{
  6176. UserOrgId: it.OrgId,
  6177. PatientId: patient_id,
  6178. RecordDate: it.RecordTime,
  6179. GoodId: it.GoodId,
  6180. GoodTypeId: it.GoodTypeId,
  6181. Count: it.Count,
  6182. Ctime: time.Now().Unix(),
  6183. Creater: adminUser.AdminUser.Id,
  6184. Status: 1,
  6185. StorehouseId: houseConfig.StorehouseOutInfo,
  6186. }
  6187. //删除准备表数据
  6188. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6189. service.CreateDialysisBeforePrepareOne(&prepare)
  6190. //查询默认仓库
  6191. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6192. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6193. var total_count int64
  6194. for _, it := range stockList {
  6195. total_count += it.StockCount
  6196. }
  6197. //基础库插入数据
  6198. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6199. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6200. var flush_count int64
  6201. for _, it := range goodList {
  6202. flush_count += it.StockCount
  6203. }
  6204. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6205. }
  6206. }
  6207. //如果库存不够,则出库到下一个批次
  6208. if lastInfo.StockCount < last_total {
  6209. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  6210. //查询今日出库数据
  6211. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  6212. for _, it := range list {
  6213. prepare := models.DialysisBeforePrepare{
  6214. UserOrgId: it.OrgId,
  6215. PatientId: patient_id,
  6216. RecordDate: it.RecordTime,
  6217. GoodId: it.GoodId,
  6218. GoodTypeId: it.GoodTypeId,
  6219. Count: it.Count,
  6220. Ctime: time.Now().Unix(),
  6221. Creater: adminUser.AdminUser.Id,
  6222. Status: 1,
  6223. StorehouseId: houseConfig.StorehouseOutInfo,
  6224. }
  6225. //删除准备表数据
  6226. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6227. service.CreateDialysisBeforePrepareOne(&prepare)
  6228. //查询默认仓库
  6229. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  6230. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  6231. var total_count int64
  6232. for _, it := range stockList {
  6233. total_count += it.StockCount
  6234. }
  6235. //基础库插入数据
  6236. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  6237. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6238. var flush_count int64
  6239. for _, it := range goodList {
  6240. flush_count += it.StockCount
  6241. }
  6242. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6243. }
  6244. if err != nil {
  6245. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6246. c.ServeSuccessJSON(map[string]interface{}{
  6247. "message": "1",
  6248. "good_name": goodObj.GoodName,
  6249. "specification_name": goodObj.SpecificationName,
  6250. })
  6251. return
  6252. }
  6253. }
  6254. }
  6255. if err != nil {
  6256. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6257. c.ServeSuccessJSON(map[string]interface{}{
  6258. "message": "1",
  6259. "good_name": goodObj.GoodName,
  6260. "specification_name": goodObj.SpecificationName,
  6261. })
  6262. return
  6263. }
  6264. }
  6265. }
  6266. }
  6267. var errs error
  6268. if errs == nil {
  6269. c.ServeSuccessJSON(map[string]interface{}{
  6270. "msg": "提交成功",
  6271. "message": "2",
  6272. "good_name": "",
  6273. "specification_name": "",
  6274. })
  6275. return
  6276. } else {
  6277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6278. return
  6279. }
  6280. }
  6281. func (c *DialysisAPIController) CreateStockOutInfo() {
  6282. patient_id, _ := c.GetInt64("patient_id", 0)
  6283. record_date := c.GetString("record_time")
  6284. if patient_id <= 0 {
  6285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6286. return
  6287. }
  6288. adminInfo := c.GetMobileAdminUserInfo()
  6289. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  6290. timeLayout := "2006-01-02"
  6291. loc, _ := time.LoadLocation("Local")
  6292. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6293. record_time := theRecordTime.Unix()
  6294. // 查询信息规挡的设置天数
  6295. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6296. if infor.ID > 0 && infor.WeekDay > 0 {
  6297. var cha_time int64
  6298. timeNowStr := time.Now().Format("2006-01-02")
  6299. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6300. //今日的日期减去设置的日期
  6301. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6302. if cha_time >= record_time {
  6303. //查询审核是否允许
  6304. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6305. //申请状态不允许的情况 拒绝修改
  6306. if infor.ApplicationStatus != 1 {
  6307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6308. return
  6309. }
  6310. }
  6311. }
  6312. //创建步骤表
  6313. finish := models.XtDialysisFinish{
  6314. IsFinish: 1,
  6315. UserOrgId: adminInfo.Org.Id,
  6316. Status: 1,
  6317. Ctime: time.Now().Unix(),
  6318. Mtime: 0,
  6319. Module: 11,
  6320. RecordDate: record_time,
  6321. Sourse: 1,
  6322. PatientId: patient_id,
  6323. }
  6324. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6325. if dialysisFinish.ID == 0 {
  6326. service.CreateDialysisFinish(finish)
  6327. }
  6328. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  6329. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6330. //去重
  6331. consumables = RemoveRepeatedGood(consumables)
  6332. if adminInfo.Org.Id == 9919 {
  6333. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6334. //查询是否有库存
  6335. for _, item := range consumables {
  6336. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6337. if item.Count > warehouse.Count {
  6338. goodErrcode := models.XtGoodErrcode{
  6339. UserOrgId: item.UserOrgId,
  6340. Errcode: "自动出库库存不足",
  6341. GoodId: item.GoodId,
  6342. Status: 1,
  6343. Ctime: time.Now().Unix(),
  6344. Mtime: 0,
  6345. Count: 0,
  6346. StockCount: 0,
  6347. Creater: creator,
  6348. BatchNumberId: warehouse.ID,
  6349. WarehouseOutId: 0,
  6350. }
  6351. service.CreateGoodErrcode(goodErrcode)
  6352. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6353. c.ServeSuccessJSON(map[string]interface{}{
  6354. "message": "1",
  6355. "good_name": goodObj.GoodName,
  6356. "specification_name": goodObj.SpecificationName,
  6357. })
  6358. return
  6359. }
  6360. }
  6361. //查询是否有出库单
  6362. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6363. if err == gorm.ErrRecordNotFound {
  6364. //没有记录,则创建出库单
  6365. timeStr := time.Now().Format("2006-01-02")
  6366. timeArr := strings.Split(timeStr, "-")
  6367. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6368. total = total + 1
  6369. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6370. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6371. number = number + total
  6372. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6373. creater := adminInfo.AdminUser.Id
  6374. warehouseOut := models.WarehouseOut{
  6375. WarehouseOutOrderNumber: warehousing_out_order,
  6376. OperationTime: time.Now().Unix(),
  6377. OrgId: adminInfo.Org.Id,
  6378. Creater: creater,
  6379. Ctime: time.Now().Unix(),
  6380. Status: 1,
  6381. WarehouseOutTime: record_time,
  6382. Dealer: 0,
  6383. Manufacturer: 0,
  6384. Type: 1,
  6385. IsSys: 1,
  6386. StorehouseId: houseConfig.StorehouseOutInfo,
  6387. IsCheck: 1,
  6388. }
  6389. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6390. if err != nil {
  6391. goodErrcode := models.XtGoodErrcode{
  6392. UserOrgId: adminInfo.Org.Id,
  6393. Errcode: "创建出库单失败",
  6394. GoodId: 0,
  6395. Status: 1,
  6396. Ctime: time.Now().Unix(),
  6397. Mtime: 0,
  6398. Count: 0,
  6399. StockCount: 0,
  6400. Creater: creator,
  6401. BatchNumberId: 0,
  6402. WarehouseOutId: 0,
  6403. }
  6404. service.CreateGoodErrcode(goodErrcode)
  6405. utils.TraceLog("创建出库单失败 err = %v", err)
  6406. } else {
  6407. for _, item := range consumables {
  6408. //出库
  6409. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6410. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6411. if err == nil {
  6412. goodErrcode := models.XtGoodErrcode{
  6413. UserOrgId: adminInfo.Org.Id,
  6414. Errcode: "自动出库接口报错",
  6415. GoodId: 0,
  6416. Status: 1,
  6417. Ctime: time.Now().Unix(),
  6418. Mtime: 0,
  6419. Count: 0,
  6420. StockCount: 0,
  6421. Creater: creator,
  6422. BatchNumberId: 0,
  6423. WarehouseOutId: 0,
  6424. }
  6425. service.CreateGoodErrcode(goodErrcode)
  6426. utils.TraceLog("创建出库单失败 err = %v", err)
  6427. }
  6428. //查询
  6429. //出库数量相加
  6430. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6431. if errs != nil {
  6432. goodErrcode := models.XtGoodErrcode{
  6433. UserOrgId: item.UserOrgId,
  6434. Errcode: "创建剩余库存字段报错",
  6435. GoodId: item.GoodId,
  6436. Status: 1,
  6437. Ctime: time.Now().Unix(),
  6438. Mtime: 0,
  6439. Count: 0,
  6440. StockCount: 0,
  6441. Creater: creater,
  6442. BatchNumberId: 0,
  6443. WarehouseOutId: 0,
  6444. }
  6445. service.CreateGoodErrcode(goodErrcode)
  6446. }
  6447. }
  6448. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6449. if len(list) == 0 {
  6450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6451. return
  6452. }
  6453. for _, item := range list {
  6454. prepare := models.DialysisBeforePrepare{
  6455. UserOrgId: adminInfo.Org.Id,
  6456. PatientId: patient_id,
  6457. RecordDate: record_time,
  6458. GoodId: item.GoodId,
  6459. GoodTypeId: item.GoodTypeId,
  6460. Count: item.Count,
  6461. Creater: adminInfo.AdminUser.Id,
  6462. Status: 1,
  6463. Ctime: time.Now().Unix(),
  6464. StorehouseId: houseConfig.StorehouseOutInfo,
  6465. }
  6466. //清空准备表数据
  6467. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6468. if err != nil {
  6469. goodErrcode := models.XtGoodErrcode{
  6470. UserOrgId: item.OrgId,
  6471. Errcode: "自动出库清空准备表数据报错",
  6472. GoodId: item.GoodId,
  6473. Status: 1,
  6474. Ctime: time.Now().Unix(),
  6475. Mtime: 0,
  6476. Count: 0,
  6477. StockCount: 0,
  6478. Creater: creater,
  6479. BatchNumberId: 0,
  6480. WarehouseOutId: 0,
  6481. }
  6482. service.CreateGoodErrcode(goodErrcode)
  6483. }
  6484. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6485. if errs != nil {
  6486. goodErrcode := models.XtGoodErrcode{
  6487. UserOrgId: item.OrgId,
  6488. Errcode: "自动出库创建准备表数据报错",
  6489. GoodId: item.GoodId,
  6490. Status: 1,
  6491. Ctime: time.Now().Unix(),
  6492. Mtime: 0,
  6493. Count: 0,
  6494. StockCount: 0,
  6495. Creater: creater,
  6496. BatchNumberId: 0,
  6497. WarehouseOutId: 0,
  6498. }
  6499. service.CreateGoodErrcode(goodErrcode)
  6500. }
  6501. //查询默认仓库
  6502. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6503. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6504. var total_count int64
  6505. for _, it := range stockList {
  6506. total_count += it.StockCount
  6507. }
  6508. //基础库插入数据
  6509. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6510. if errcodes != nil {
  6511. goodErrcode := models.XtGoodErrcode{
  6512. UserOrgId: item.OrgId,
  6513. Errcode: "自动出库基础库插入数据",
  6514. GoodId: item.GoodId,
  6515. Status: 1,
  6516. Ctime: time.Now().Unix(),
  6517. Mtime: 0,
  6518. Count: 0,
  6519. StockCount: 0,
  6520. Creater: creater,
  6521. BatchNumberId: 0,
  6522. WarehouseOutId: 0,
  6523. }
  6524. service.CreateGoodErrcode(goodErrcode)
  6525. }
  6526. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6527. var flush_count int64
  6528. for _, it := range goodList {
  6529. flush_count += it.StockCount
  6530. }
  6531. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6532. if errsss != nil {
  6533. goodErrcode := models.XtGoodErrcode{
  6534. UserOrgId: item.OrgId,
  6535. Errcode: "自动出库剩余库存更新数据",
  6536. GoodId: item.GoodId,
  6537. Status: 1,
  6538. Ctime: time.Now().Unix(),
  6539. Mtime: 0,
  6540. Count: 0,
  6541. StockCount: 0,
  6542. Creater: creater,
  6543. BatchNumberId: 0,
  6544. WarehouseOutId: 0,
  6545. }
  6546. service.CreateGoodErrcode(goodErrcode)
  6547. }
  6548. }
  6549. }
  6550. //
  6551. } else if err == nil {
  6552. for _, item := range consumables {
  6553. //出库
  6554. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6555. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6556. if err != nil {
  6557. goodErrcode := models.XtGoodErrcode{
  6558. UserOrgId: adminInfo.Org.Id,
  6559. Errcode: "自动出库接口报错",
  6560. GoodId: 0,
  6561. Status: 1,
  6562. Ctime: time.Now().Unix(),
  6563. Mtime: 0,
  6564. Count: 0,
  6565. StockCount: 0,
  6566. Creater: creator,
  6567. BatchNumberId: 0,
  6568. WarehouseOutId: 0,
  6569. }
  6570. service.CreateGoodErrcode(goodErrcode)
  6571. }
  6572. //出库数量相加
  6573. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6574. if errss != nil {
  6575. goodErrcode := models.XtGoodErrcode{
  6576. UserOrgId: item.UserOrgId,
  6577. Errcode: "创建剩余库存字段报错",
  6578. GoodId: item.GoodId,
  6579. Status: 1,
  6580. Ctime: time.Now().Unix(),
  6581. Mtime: time.Now().Unix(),
  6582. Count: 0,
  6583. StockCount: 0,
  6584. Creater: item.Creater,
  6585. BatchNumberId: 0,
  6586. WarehouseOutId: 0,
  6587. }
  6588. service.CreateGoodErrcode(goodErrcode)
  6589. }
  6590. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6591. if len(list) == 0 {
  6592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6593. return
  6594. }
  6595. for _, item := range list {
  6596. prepare := models.DialysisBeforePrepare{
  6597. UserOrgId: adminInfo.Org.Id,
  6598. PatientId: patient_id,
  6599. RecordDate: record_time,
  6600. GoodId: item.GoodId,
  6601. GoodTypeId: item.GoodTypeId,
  6602. Count: item.Count,
  6603. Creater: adminInfo.AdminUser.Id,
  6604. Status: 1,
  6605. Ctime: time.Now().Unix(),
  6606. StorehouseId: houseConfig.StorehouseOutInfo,
  6607. }
  6608. //清空准备表数据
  6609. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6610. if errs != nil {
  6611. goodErrcode := models.XtGoodErrcode{
  6612. UserOrgId: adminInfo.Org.Id,
  6613. Errcode: "自动出库清空准备表数据报错",
  6614. GoodId: 0,
  6615. Status: 1,
  6616. Ctime: time.Now().Unix(),
  6617. Mtime: 0,
  6618. Count: 0,
  6619. StockCount: 0,
  6620. Creater: creator,
  6621. BatchNumberId: 0,
  6622. WarehouseOutId: 0,
  6623. }
  6624. service.CreateGoodErrcode(goodErrcode)
  6625. }
  6626. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6627. if errcodes != nil {
  6628. goodErrcode := models.XtGoodErrcode{
  6629. UserOrgId: adminInfo.Org.Id,
  6630. Errcode: "自动出库创建准备表数据报错",
  6631. GoodId: 0,
  6632. Status: 1,
  6633. Ctime: time.Now().Unix(),
  6634. Mtime: 0,
  6635. Count: 0,
  6636. StockCount: 0,
  6637. Creater: creator,
  6638. BatchNumberId: 0,
  6639. WarehouseOutId: 0,
  6640. }
  6641. service.CreateGoodErrcode(goodErrcode)
  6642. }
  6643. //查询默认仓库
  6644. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6645. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6646. var total_count int64
  6647. for _, it := range stockList {
  6648. total_count += it.StockCount
  6649. }
  6650. //基础库插入数据
  6651. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6652. if errcodes != nil {
  6653. goodErrcode := models.XtGoodErrcode{
  6654. UserOrgId: adminInfo.Org.Id,
  6655. Errcode: "自动出库基础库插入数据报错",
  6656. GoodId: 0,
  6657. Status: 1,
  6658. Ctime: time.Now().Unix(),
  6659. Mtime: 0,
  6660. Count: 0,
  6661. StockCount: 0,
  6662. Creater: creator,
  6663. BatchNumberId: 0,
  6664. WarehouseOutId: 0,
  6665. }
  6666. service.CreateGoodErrcode(goodErrcode)
  6667. }
  6668. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6669. var flush_count int64
  6670. for _, it := range goodList {
  6671. flush_count += it.StockCount
  6672. }
  6673. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6674. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6675. if errss != nil {
  6676. goodErrcode := models.XtGoodErrcode{
  6677. UserOrgId: item.OrgId,
  6678. Errcode: "自动出库剩余库存更新数据",
  6679. GoodId: item.GoodId,
  6680. Status: 1,
  6681. Ctime: time.Now().Unix(),
  6682. Mtime: 0,
  6683. Count: 0,
  6684. StockCount: 0,
  6685. Creater: creater,
  6686. BatchNumberId: 0,
  6687. WarehouseOutId: 0,
  6688. }
  6689. service.CreateGoodErrcode(goodErrcode)
  6690. }
  6691. }
  6692. }
  6693. }
  6694. c.ServeSuccessJSON(map[string]interface{}{
  6695. "msg": "提交成功",
  6696. "message": "2",
  6697. "good_name": "",
  6698. "specification_name": "",
  6699. })
  6700. return
  6701. }
  6702. if record.IsOpen == 1 {
  6703. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6704. //查询是否有库存
  6705. for _, item := range consumables {
  6706. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  6707. if item.Count > warehouse.Count {
  6708. goodErrcode := models.XtGoodErrcode{
  6709. UserOrgId: item.UserOrgId,
  6710. Errcode: "自动出库库存不足",
  6711. GoodId: item.GoodId,
  6712. Status: 1,
  6713. Ctime: time.Now().Unix(),
  6714. Mtime: 0,
  6715. Count: 0,
  6716. StockCount: 0,
  6717. Creater: creator,
  6718. BatchNumberId: warehouse.ID,
  6719. WarehouseOutId: 0,
  6720. }
  6721. service.CreateGoodErrcode(goodErrcode)
  6722. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6723. c.ServeSuccessJSON(map[string]interface{}{
  6724. "message": "1",
  6725. "good_name": goodObj.GoodName,
  6726. "specification_name": goodObj.SpecificationName,
  6727. })
  6728. return
  6729. }
  6730. }
  6731. //查询是否有出库单
  6732. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6733. if err == gorm.ErrRecordNotFound {
  6734. //没有记录,则创建出库单
  6735. timeStr := time.Now().Format("2006-01-02")
  6736. timeArr := strings.Split(timeStr, "-")
  6737. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6738. total = total + 1
  6739. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6740. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6741. number = number + total
  6742. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6743. creater := adminInfo.AdminUser.Id
  6744. warehouseOut := models.WarehouseOut{
  6745. WarehouseOutOrderNumber: warehousing_out_order,
  6746. OperationTime: time.Now().Unix(),
  6747. OrgId: adminInfo.Org.Id,
  6748. Creater: creater,
  6749. Ctime: time.Now().Unix(),
  6750. Status: 1,
  6751. WarehouseOutTime: record_time,
  6752. Dealer: 0,
  6753. Manufacturer: 0,
  6754. Type: 1,
  6755. IsSys: 1,
  6756. StorehouseId: houseConfig.StorehouseOutInfo,
  6757. IsCheck: 1,
  6758. }
  6759. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  6760. if err != nil {
  6761. goodErrcode := models.XtGoodErrcode{
  6762. UserOrgId: adminInfo.Org.Id,
  6763. Errcode: "创建出库单失败",
  6764. GoodId: 0,
  6765. Status: 1,
  6766. Ctime: time.Now().Unix(),
  6767. Mtime: 0,
  6768. Count: 0,
  6769. StockCount: 0,
  6770. Creater: creator,
  6771. BatchNumberId: 0,
  6772. WarehouseOutId: 0,
  6773. }
  6774. service.CreateGoodErrcode(goodErrcode)
  6775. utils.TraceLog("创建出库单失败 err = %v", err)
  6776. } else {
  6777. for _, item := range consumables {
  6778. //出库
  6779. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  6780. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  6781. if err == nil {
  6782. goodErrcode := models.XtGoodErrcode{
  6783. UserOrgId: adminInfo.Org.Id,
  6784. Errcode: "自动出库接口报错",
  6785. GoodId: 0,
  6786. Status: 1,
  6787. Ctime: time.Now().Unix(),
  6788. Mtime: 0,
  6789. Count: 0,
  6790. StockCount: 0,
  6791. Creater: creator,
  6792. BatchNumberId: 0,
  6793. WarehouseOutId: 0,
  6794. }
  6795. service.CreateGoodErrcode(goodErrcode)
  6796. utils.TraceLog("创建出库单失败 err = %v", err)
  6797. }
  6798. //查询
  6799. //出库数量相加
  6800. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6801. if errs != nil {
  6802. goodErrcode := models.XtGoodErrcode{
  6803. UserOrgId: item.UserOrgId,
  6804. Errcode: "创建剩余库存字段报错",
  6805. GoodId: item.GoodId,
  6806. Status: 1,
  6807. Ctime: time.Now().Unix(),
  6808. Mtime: 0,
  6809. Count: 0,
  6810. StockCount: 0,
  6811. Creater: creater,
  6812. BatchNumberId: 0,
  6813. WarehouseOutId: 0,
  6814. }
  6815. service.CreateGoodErrcode(goodErrcode)
  6816. }
  6817. }
  6818. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6819. if len(list) == 0 {
  6820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6821. return
  6822. }
  6823. for _, item := range list {
  6824. prepare := models.DialysisBeforePrepare{
  6825. UserOrgId: adminInfo.Org.Id,
  6826. PatientId: patient_id,
  6827. RecordDate: record_time,
  6828. GoodId: item.GoodId,
  6829. GoodTypeId: item.GoodTypeId,
  6830. Count: item.Count,
  6831. Creater: adminInfo.AdminUser.Id,
  6832. Status: 1,
  6833. Ctime: time.Now().Unix(),
  6834. StorehouseId: houseConfig.StorehouseOutInfo,
  6835. }
  6836. //清空准备表数据
  6837. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6838. if err != nil {
  6839. goodErrcode := models.XtGoodErrcode{
  6840. UserOrgId: item.OrgId,
  6841. Errcode: "自动出库清空准备表数据报错",
  6842. GoodId: item.GoodId,
  6843. Status: 1,
  6844. Ctime: time.Now().Unix(),
  6845. Mtime: 0,
  6846. Count: 0,
  6847. StockCount: 0,
  6848. Creater: creater,
  6849. BatchNumberId: 0,
  6850. WarehouseOutId: 0,
  6851. }
  6852. service.CreateGoodErrcode(goodErrcode)
  6853. }
  6854. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  6855. if errs != nil {
  6856. goodErrcode := models.XtGoodErrcode{
  6857. UserOrgId: item.OrgId,
  6858. Errcode: "自动出库创建准备表数据报错",
  6859. GoodId: item.GoodId,
  6860. Status: 1,
  6861. Ctime: time.Now().Unix(),
  6862. Mtime: 0,
  6863. Count: 0,
  6864. StockCount: 0,
  6865. Creater: creater,
  6866. BatchNumberId: 0,
  6867. WarehouseOutId: 0,
  6868. }
  6869. service.CreateGoodErrcode(goodErrcode)
  6870. }
  6871. //查询默认仓库
  6872. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6873. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6874. var total_count int64
  6875. for _, it := range stockList {
  6876. total_count += it.StockCount
  6877. }
  6878. //基础库插入数据
  6879. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6880. if errcodes != nil {
  6881. goodErrcode := models.XtGoodErrcode{
  6882. UserOrgId: item.OrgId,
  6883. Errcode: "自动出库基础库插入数据",
  6884. GoodId: item.GoodId,
  6885. Status: 1,
  6886. Ctime: time.Now().Unix(),
  6887. Mtime: 0,
  6888. Count: 0,
  6889. StockCount: 0,
  6890. Creater: creater,
  6891. BatchNumberId: 0,
  6892. WarehouseOutId: 0,
  6893. }
  6894. service.CreateGoodErrcode(goodErrcode)
  6895. }
  6896. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6897. var flush_count int64
  6898. for _, it := range goodList {
  6899. flush_count += it.StockCount
  6900. }
  6901. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6902. if errsss != nil {
  6903. goodErrcode := models.XtGoodErrcode{
  6904. UserOrgId: item.OrgId,
  6905. Errcode: "自动出库剩余库存更新数据",
  6906. GoodId: item.GoodId,
  6907. Status: 1,
  6908. Ctime: time.Now().Unix(),
  6909. Mtime: 0,
  6910. Count: 0,
  6911. StockCount: 0,
  6912. Creater: creater,
  6913. BatchNumberId: 0,
  6914. WarehouseOutId: 0,
  6915. }
  6916. service.CreateGoodErrcode(goodErrcode)
  6917. }
  6918. }
  6919. }
  6920. //
  6921. } else if err == nil {
  6922. for _, item := range consumables {
  6923. //出库
  6924. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  6925. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  6926. if err != nil {
  6927. goodErrcode := models.XtGoodErrcode{
  6928. UserOrgId: adminInfo.Org.Id,
  6929. Errcode: "自动出库接口报错",
  6930. GoodId: 0,
  6931. Status: 1,
  6932. Ctime: time.Now().Unix(),
  6933. Mtime: 0,
  6934. Count: 0,
  6935. StockCount: 0,
  6936. Creater: creator,
  6937. BatchNumberId: 0,
  6938. WarehouseOutId: 0,
  6939. }
  6940. service.CreateGoodErrcode(goodErrcode)
  6941. }
  6942. //出库数量相加
  6943. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6944. if errss != nil {
  6945. goodErrcode := models.XtGoodErrcode{
  6946. UserOrgId: item.UserOrgId,
  6947. Errcode: "创建剩余库存字段报错",
  6948. GoodId: item.GoodId,
  6949. Status: 1,
  6950. Ctime: time.Now().Unix(),
  6951. Mtime: time.Now().Unix(),
  6952. Count: 0,
  6953. StockCount: 0,
  6954. Creater: item.Creater,
  6955. BatchNumberId: 0,
  6956. WarehouseOutId: 0,
  6957. }
  6958. service.CreateGoodErrcode(goodErrcode)
  6959. }
  6960. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6961. if len(list) == 0 {
  6962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6963. return
  6964. }
  6965. for _, item := range list {
  6966. prepare := models.DialysisBeforePrepare{
  6967. UserOrgId: adminInfo.Org.Id,
  6968. PatientId: patient_id,
  6969. RecordDate: record_time,
  6970. GoodId: item.GoodId,
  6971. GoodTypeId: item.GoodTypeId,
  6972. Count: item.Count,
  6973. Creater: adminInfo.AdminUser.Id,
  6974. Status: 1,
  6975. Ctime: time.Now().Unix(),
  6976. StorehouseId: houseConfig.StorehouseOutInfo,
  6977. }
  6978. //清空准备表数据
  6979. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6980. if errs != nil {
  6981. goodErrcode := models.XtGoodErrcode{
  6982. UserOrgId: adminInfo.Org.Id,
  6983. Errcode: "自动出库清空准备表数据报错",
  6984. GoodId: 0,
  6985. Status: 1,
  6986. Ctime: time.Now().Unix(),
  6987. Mtime: 0,
  6988. Count: 0,
  6989. StockCount: 0,
  6990. Creater: creator,
  6991. BatchNumberId: 0,
  6992. WarehouseOutId: 0,
  6993. }
  6994. service.CreateGoodErrcode(goodErrcode)
  6995. }
  6996. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6997. if errcodes != nil {
  6998. goodErrcode := models.XtGoodErrcode{
  6999. UserOrgId: adminInfo.Org.Id,
  7000. Errcode: "自动出库创建准备表数据报错",
  7001. GoodId: 0,
  7002. Status: 1,
  7003. Ctime: time.Now().Unix(),
  7004. Mtime: 0,
  7005. Count: 0,
  7006. StockCount: 0,
  7007. Creater: creator,
  7008. BatchNumberId: 0,
  7009. WarehouseOutId: 0,
  7010. }
  7011. service.CreateGoodErrcode(goodErrcode)
  7012. }
  7013. //查询默认仓库
  7014. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7015. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7016. var total_count int64
  7017. for _, it := range stockList {
  7018. total_count += it.StockCount
  7019. }
  7020. //基础库插入数据
  7021. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7022. if errcodes != nil {
  7023. goodErrcode := models.XtGoodErrcode{
  7024. UserOrgId: adminInfo.Org.Id,
  7025. Errcode: "自动出库基础库插入数据报错",
  7026. GoodId: 0,
  7027. Status: 1,
  7028. Ctime: time.Now().Unix(),
  7029. Mtime: 0,
  7030. Count: 0,
  7031. StockCount: 0,
  7032. Creater: creator,
  7033. BatchNumberId: 0,
  7034. WarehouseOutId: 0,
  7035. }
  7036. service.CreateGoodErrcode(goodErrcode)
  7037. }
  7038. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7039. var flush_count int64
  7040. for _, it := range goodList {
  7041. flush_count += it.StockCount
  7042. }
  7043. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7044. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  7045. if errss != nil {
  7046. goodErrcode := models.XtGoodErrcode{
  7047. UserOrgId: item.OrgId,
  7048. Errcode: "自动出库剩余库存更新数据",
  7049. GoodId: item.GoodId,
  7050. Status: 1,
  7051. Ctime: time.Now().Unix(),
  7052. Mtime: 0,
  7053. Count: 0,
  7054. StockCount: 0,
  7055. Creater: creater,
  7056. BatchNumberId: 0,
  7057. WarehouseOutId: 0,
  7058. }
  7059. service.CreateGoodErrcode(goodErrcode)
  7060. }
  7061. }
  7062. }
  7063. }
  7064. c.ServeSuccessJSON(map[string]interface{}{
  7065. "msg": "提交成功",
  7066. "message": "2",
  7067. "good_name": "",
  7068. "specification_name": "",
  7069. })
  7070. return
  7071. } else {
  7072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  7073. return
  7074. }
  7075. }
  7076. func (c *DialysisAPIController) EditConsumables() {
  7077. patient_id, _ := c.GetInt64("patient_id", 0)
  7078. record_date := c.GetString("record_time")
  7079. if patient_id <= 0 {
  7080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7081. return
  7082. }
  7083. adminInfo := c.GetMobileAdminUserInfo()
  7084. timeLayout := "2006-01-02"
  7085. loc, _ := time.LoadLocation("Local")
  7086. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7087. record_time := theRecordTime.Unix()
  7088. // 查询信息规挡的设置天数
  7089. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7090. if infor.ID > 0 && infor.WeekDay > 0 {
  7091. var cha_time int64
  7092. timeNowStr := time.Now().Format("2006-01-02")
  7093. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7094. //今日的日期减去设置的日期
  7095. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7096. if cha_time >= record_time {
  7097. //查询审核是否允许
  7098. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7099. //申请状态不允许的情况 拒绝修改
  7100. if infor.ApplicationStatus != 1 {
  7101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7102. return
  7103. }
  7104. }
  7105. }
  7106. dataBody := make(map[string]interface{}, 0)
  7107. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7108. if err != nil {
  7109. utils.ErrorLog(err.Error())
  7110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7111. return
  7112. }
  7113. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7114. var beforePrepares []*models.DialysisBeforePrepareGoods
  7115. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7116. var cancelbefor []*models.DialysisBeforePrepareGoods
  7117. var outbefor []*models.DialysisBeforePrepareGoods
  7118. //判断是否开启自动出库
  7119. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7120. if record.IsOpen == 1 {
  7121. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7122. goods, _ := dataBody["goods"].([]interface{})
  7123. if len(goods) > 0 {
  7124. for _, item := range goods {
  7125. items := item.(map[string]interface{})
  7126. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7127. utils.ErrorLog("good_id")
  7128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7129. return
  7130. }
  7131. good_id := int64(items["good_id"].(float64))
  7132. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7133. utils.ErrorLog("good_type_id")
  7134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7135. return
  7136. }
  7137. good_type_id := int64(items["good_type_id"].(float64))
  7138. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7139. utils.ErrorLog("count")
  7140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7141. return
  7142. }
  7143. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7144. commdity_code := items["commdity_code"].(string)
  7145. fmt.Println(commdity_code)
  7146. prepareGoods := &models.DialysisBeforePrepareGoods{
  7147. GoodTypeId: good_type_id,
  7148. GoodId: good_id,
  7149. Count: count,
  7150. StorehouseId: houseConfig.StorehouseOutInfo,
  7151. }
  7152. beforePrepares = append(beforePrepares, prepareGoods)
  7153. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  7154. GoodTypeId: good_type_id,
  7155. GoodId: good_id,
  7156. Count: count,
  7157. StorehouseId: houseConfig.StorehouseOutInfo,
  7158. }
  7159. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  7160. }
  7161. for _, item := range beforePrepares {
  7162. //1.查看该患者该耗材型号最后一次出库数量
  7163. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7164. //判断当前出库数量和最后一次出库数量的大小
  7165. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  7166. if item.Count < goodInfo.Count {
  7167. cancelbefor = append(cancelbefor, item)
  7168. }
  7169. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  7170. if item.Count > goodInfo.Count {
  7171. outbefor = append(outbefor, item)
  7172. }
  7173. //处理编辑耗材新增不了的问题
  7174. if goodInfo.Count == item.Count {
  7175. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  7176. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  7177. }
  7178. }
  7179. if len(cancelbefor) > 0 {
  7180. //退库
  7181. for _, item := range cancelbefor {
  7182. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7183. creater := adminInfo.AdminUser.Id
  7184. //查询该患者当天已经出库的耗材信息
  7185. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  7186. var delete_count int64 = 0
  7187. delete_count = warehouseOutInfos.Count - item.Count
  7188. //增加库存数量
  7189. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  7190. //减少实际出库库存数量
  7191. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  7192. // 删除出库完成后,要增加对应批次的库存数量
  7193. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  7194. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7195. //更新剩余库存
  7196. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7197. var flush_count int64
  7198. for _, it := range goodListOne {
  7199. flush_count += it.StockCount
  7200. }
  7201. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7202. //查询剩余库存
  7203. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7204. var sum_count int64
  7205. for _, item := range goodList {
  7206. sum_count += item.StockCount
  7207. }
  7208. // 在出库记录表里记录退库详情
  7209. warehouseOutInfo := &models.WarehouseOutInfo{
  7210. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7211. WarehouseOutId: warehouseOut.ID,
  7212. Status: 1,
  7213. Ctime: time.Now().Unix(),
  7214. OrgId: adminInfo.Org.Id,
  7215. Type: 1,
  7216. IsSys: 1,
  7217. SysRecordTime: record_time,
  7218. GoodTypeId: item.GoodTypeId,
  7219. GoodId: item.GoodId,
  7220. PatientId: patient_id,
  7221. ConsumableType: 2,
  7222. StorehouseId: houseConfig.StorehouseOutInfo,
  7223. IsCheck: 1,
  7224. OverCount: sum_count,
  7225. }
  7226. warehouseOutInfo.Count = item.Count
  7227. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  7228. warehouseOutInfo.Price = stockInInfo.Price
  7229. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7230. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7231. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7232. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7233. warehouseOutInfo.Number = warehouseOutInfos.Number
  7234. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7235. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7236. //查找当天是否存在出库记录
  7237. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  7238. if errcod == gorm.ErrRecordNotFound {
  7239. service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  7240. //插入详情明细表
  7241. stockFlow := models.VmStockFlow{
  7242. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7243. WarehouseOutId: warehouseOut.ID,
  7244. GoodId: item.GoodId,
  7245. Number: warehouseOutInfos.Number,
  7246. ProductDate: stockInInfo.ProductDate,
  7247. ExpireDate: stockInInfo.ExpiryDate,
  7248. Count: item.Count,
  7249. Price: stockInInfo.Price,
  7250. Status: 1,
  7251. Ctime: record_time,
  7252. UserOrgId: adminInfo.Org.Id,
  7253. Manufacturer: stockInInfo.Manufacturer,
  7254. Dealer: stockInInfo.Dealer,
  7255. LicenseNumber: stockInInfo.LicenseNumber,
  7256. IsEdit: 2,
  7257. Creator: creater,
  7258. SystemTime: record_time,
  7259. ConsumableType: 3,
  7260. WarehousingDetailId: 0,
  7261. IsSys: 1,
  7262. UpdateCreator: creater,
  7263. PatientId: patient_id,
  7264. StorehouseId: houseConfig.StorehouseOutInfo,
  7265. }
  7266. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  7267. if errflow == gorm.ErrRecordNotFound {
  7268. //创建流水表
  7269. err := service.CreateStockFlowOne(stockFlow)
  7270. fmt.Println("err", err)
  7271. } else if errflow == nil {
  7272. //插入详情明细表
  7273. stockFlow := models.VmStockFlow{
  7274. ID: exsit.ID,
  7275. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7276. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7277. WarehouseOutId: warehouseOut.ID,
  7278. GoodId: item.GoodId,
  7279. Number: warehouseOutInfos.Number,
  7280. ProductDate: stockInInfo.ProductDate,
  7281. ExpireDate: stockInInfo.ExpiryDate,
  7282. Count: exsit.Count - delete_count,
  7283. Price: stockInInfo.Price,
  7284. Status: 1,
  7285. Ctime: record_time,
  7286. UserOrgId: adminInfo.Org.Id,
  7287. Manufacturer: stockInInfo.Manufacturer,
  7288. Dealer: stockInInfo.Dealer,
  7289. LicenseNumber: stockInInfo.LicenseNumber,
  7290. IsEdit: 2,
  7291. Creator: creater,
  7292. SystemTime: record_time,
  7293. ConsumableType: 3,
  7294. WarehousingDetailId: 0,
  7295. IsSys: 1,
  7296. UpdateCreator: creater,
  7297. PatientId: patient_id,
  7298. StorehouseId: houseConfig.StorehouseOutInfo,
  7299. }
  7300. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  7301. }
  7302. } else if errcod == nil {
  7303. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  7304. //查询剩余库存
  7305. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  7306. var sum_count int64
  7307. for _, item := range goodList {
  7308. sum_count += item.StockCount
  7309. }
  7310. //创建退库单,生成退库数据
  7311. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7312. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  7313. operation_time := time.Now().Unix()
  7314. creater := adminInfo.AdminUser.Id
  7315. //创建退库单
  7316. timeStr := time.Now().Format("2006-01-02")
  7317. timeArr := strings.Split(timeStr, "-")
  7318. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  7319. total = total + 1
  7320. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7321. cancelStock := models.CancelStock{
  7322. OrderNumber: orderNumber,
  7323. OperaTime: operation_time,
  7324. OrgId: adminInfo.Org.Id,
  7325. Creater: creater,
  7326. Ctime: time.Now().Unix(),
  7327. Status: 1,
  7328. ReturnTime: record_time,
  7329. Type: 1,
  7330. StorehouseId: houseConfig.StorehouseOutInfo,
  7331. IsCheck: 1,
  7332. }
  7333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  7334. if msgerrkonde == gorm.ErrRecordNotFound {
  7335. service.AddSigleCancelStock(&cancelStock)
  7336. }
  7337. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  7338. //查询是否有出库
  7339. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  7340. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  7341. deaerler, _ := service.GetDealerById(info.Dealer)
  7342. if info.ID > 0 {
  7343. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  7344. cancelStockInfo := models.CancelStockInfo{
  7345. GoodId: item.GoodId,
  7346. CancelStockId: cancel.ID,
  7347. GoodTypeId: good.GoodTypeId,
  7348. Count: delete_count,
  7349. Price: info.Price,
  7350. Total: 0,
  7351. ProductDate: info.ProductDate,
  7352. ExpiryDate: info.ExpiryDate,
  7353. Ctime: time.Now().Unix(),
  7354. Status: 1,
  7355. OrgId: adminInfo.Org.Id,
  7356. OrderNumber: cancel.OrderNumber,
  7357. Type: 0,
  7358. Dealer: deaerler.DealerName,
  7359. Manufacturer: manufacturer.ManufacturerName,
  7360. Number: info.Number,
  7361. RegisterAccount: "",
  7362. Remark: "",
  7363. WarehouseInfoId: info.WarehouseInfotId,
  7364. PatientId: info.PatientId,
  7365. RecordDate: info.SysRecordTime,
  7366. StorehouseId: houseConfig.StorehouseOutInfo,
  7367. IsCheck: 1,
  7368. }
  7369. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7370. //退库数量增加
  7371. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7372. //查询剩余库存
  7373. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  7374. var over_count int64
  7375. for _, it := range goodList {
  7376. over_count += it.StockCount
  7377. }
  7378. flow := models.VmStockFlow{
  7379. WarehousingId: info.WarehouseInfotId,
  7380. GoodId: item.GoodId,
  7381. Number: info.Number,
  7382. LicenseNumber: info.LicenseNumber,
  7383. Count: delete_count,
  7384. UserOrgId: adminInfo.Org.Id,
  7385. PatientId: patient_id,
  7386. SystemTime: info.SysRecordTime,
  7387. ConsumableType: 7,
  7388. IsSys: 0,
  7389. WarehousingOrder: "",
  7390. WarehouseOutId: info.WarehouseOutId,
  7391. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  7392. IsEdit: 0,
  7393. CancelStockId: cancel.ID,
  7394. CancelOrderNumber: cancel.OrderNumber,
  7395. Manufacturer: manufacturer.ID,
  7396. Dealer: 0,
  7397. Creator: adminInfo.AdminUser.Id,
  7398. UpdateCreator: 0,
  7399. Status: 1,
  7400. Ctime: record_time,
  7401. Mtime: 0,
  7402. Price: info.Price,
  7403. WarehousingDetailId: info.WarehouseInfotId,
  7404. WarehouseOutDetailId: info.ID,
  7405. CancelOutDetailId: cancelInfo.ID,
  7406. ProductDate: info.ProductDate,
  7407. ExpireDate: info.ExpiryDate,
  7408. StorehouseId: houseConfig.StorehouseOutInfo,
  7409. OverCount: over_count,
  7410. }
  7411. service.CreateStockFlowOne(flow)
  7412. }
  7413. }
  7414. //更改自动出库的表格
  7415. details := models.BloodAutomaticReduceDetail{
  7416. WarehouseOutId: warehouseOutInfo.ID,
  7417. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7418. PatientId: patient_id,
  7419. Ctime: time.Now().Unix(),
  7420. Mtime: time.Now().Unix(),
  7421. Status: 1,
  7422. RecordTime: record_time,
  7423. OrgId: adminInfo.Org.Id,
  7424. GoodId: item.GoodId,
  7425. GoodTypeId: item.GoodTypeId,
  7426. Count: item.Count,
  7427. StorehouseId: houseConfig.StorehouseOutInfo,
  7428. }
  7429. //查询当天耗材是否已经存在数据
  7430. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7431. if errcode == gorm.ErrRecordNotFound {
  7432. service.CreateAutoReduceRecord(&details)
  7433. } else if errcode == nil {
  7434. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7435. service.CreateAutoReduceRecord(&details)
  7436. }
  7437. //查询默认仓库
  7438. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7439. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7440. var total_count int64
  7441. for _, it := range stockList {
  7442. total_count += it.StockCount
  7443. }
  7444. //基础库插入数据
  7445. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7446. }
  7447. }
  7448. if len(outbefor) > 0 {
  7449. //出库
  7450. for _, item := range outbefor {
  7451. var last_total int64
  7452. //1.查看该患者该耗材型号最后一次出库数量
  7453. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7454. //计算当前出库和最后一次出库数据相差数据
  7455. last_total = item.Count - goodInfoOne.Count
  7456. //查询该耗材的总库存
  7457. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  7458. // 如果库存差大于剩余库存则提示库存不足
  7459. if last_total > wareinfo.StockCount {
  7460. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7461. c.ServeSuccessJSON(map[string]interface{}{
  7462. "message": "1",
  7463. "good_name": goodObj.GoodName,
  7464. "specification_name": goodObj.SpecificationName,
  7465. })
  7466. return
  7467. } else {
  7468. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  7469. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7470. if err == gorm.ErrRecordNotFound {
  7471. //没有记录,则创建出库单
  7472. timeStr := time.Now().Format("2006-01-02")
  7473. timeArr := strings.Split(timeStr, "-")
  7474. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  7475. total = total + 1
  7476. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7477. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7478. number = number + total
  7479. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7480. warehouseOut := models.WarehouseOut{
  7481. WarehouseOutOrderNumber: warehousing_out_order,
  7482. OperationTime: time.Now().Unix(),
  7483. OrgId: adminInfo.Org.Id,
  7484. Creater: adminInfo.AdminUser.Id,
  7485. Ctime: time.Now().Unix(),
  7486. Status: 1,
  7487. WarehouseOutTime: record_time,
  7488. Dealer: 0,
  7489. Manufacturer: 0,
  7490. Type: 1,
  7491. IsSys: 1,
  7492. StorehouseId: houseConfig.StorehouseOutInfo,
  7493. IsCheck: 1,
  7494. }
  7495. service.AddSigleWarehouseOutOne(&warehouseOut)
  7496. }
  7497. //出库
  7498. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  7499. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7500. //1.查看该患者该耗材型号最后一次出库数量
  7501. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  7502. prepare := models.DialysisBeforePrepare{
  7503. UserOrgId: adminInfo.Org.Id,
  7504. PatientId: patient_id,
  7505. RecordDate: record_time,
  7506. GoodId: item.GoodId,
  7507. GoodTypeId: item.GoodTypeId,
  7508. Count: item.Count - goodInfoTwo.Count,
  7509. Ctime: time.Now().Unix(),
  7510. Mtime: 0,
  7511. Creater: adminInfo.AdminUser.Id,
  7512. Modifier: adminInfo.AdminUser.Id,
  7513. Status: 1,
  7514. CommdityCode: "",
  7515. NewCount: 0,
  7516. ProjectId: 0,
  7517. StorehouseId: houseConfig.StorehouseOutInfo,
  7518. }
  7519. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  7520. //增加出库数量
  7521. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  7522. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7523. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7524. var total_count int64
  7525. for _, it := range stockList {
  7526. total_count += it.StockCount
  7527. }
  7528. //基础库插入数据
  7529. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7530. //剩余库存
  7531. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7532. var flush_count int64
  7533. for _, it := range goodList {
  7534. flush_count += it.StockCount
  7535. }
  7536. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7537. }
  7538. }
  7539. }
  7540. //查询今日出库数据
  7541. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7542. for _, it := range list {
  7543. prepare := models.DialysisBeforePrepare{
  7544. UserOrgId: it.OrgId,
  7545. PatientId: patient_id,
  7546. RecordDate: it.RecordTime,
  7547. GoodId: it.GoodId,
  7548. GoodTypeId: it.GoodTypeId,
  7549. Count: it.Count,
  7550. Ctime: time.Now().Unix(),
  7551. Creater: adminInfo.AdminUser.Id,
  7552. Status: 1,
  7553. StorehouseId: houseConfig.StorehouseOutInfo,
  7554. ProjectId: it.ProjectId,
  7555. }
  7556. //删除准备表数据
  7557. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  7558. service.CreateDialysisBeforePrepareOne(&prepare)
  7559. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7560. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7561. var total_count int64
  7562. for _, it := range stockList {
  7563. total_count += it.StockCount
  7564. }
  7565. //基础库插入数据
  7566. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  7567. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  7568. var flush_count int64
  7569. for _, it := range goodList {
  7570. flush_count += it.StockCount
  7571. }
  7572. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  7573. }
  7574. }
  7575. }
  7576. //更新自动出库的地方
  7577. var errs error
  7578. if errs == nil {
  7579. c.ServeSuccessJSON(map[string]interface{}{
  7580. "msg": "修改成功",
  7581. "message": "2",
  7582. "good_name": "",
  7583. "specification_name": "",
  7584. })
  7585. return
  7586. } else {
  7587. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7588. return
  7589. }
  7590. }
  7591. }
  7592. func (c *DialysisAPIController) GetDialysisGoods() {
  7593. schedualDate := c.GetString("schedule_date")
  7594. schedule_type, _ := c.GetInt64("schedule_type")
  7595. partition_id, _ := c.GetInt64("partition_id")
  7596. page, _ := c.GetInt("page")
  7597. patient_id, _ := c.GetInt64("patient_id")
  7598. schedualEndDate := int64(0)
  7599. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  7600. if parseDateErr != nil && len(schedualDate) != 0 {
  7601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7602. return
  7603. }
  7604. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  7605. if parseDateErr != nil && len(schedualDate) != 0 {
  7606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7607. return
  7608. }
  7609. schedualEndDate = endDate.Unix()
  7610. adminUser := c.GetMobileAdminUserInfo()
  7611. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  7612. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  7613. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7614. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7615. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  7616. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  7617. //获取当天该病人的透析处方
  7618. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7619. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7620. if err == gorm.ErrRecordNotFound {
  7621. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7622. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7623. if patient_id != 0 {
  7624. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7625. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7626. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7627. //获取患者总的出库数据
  7628. item.LastAutomaticReduceDetail = goodUser
  7629. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7630. item.Project = project
  7631. for _, it := range item.AutomaticReduceDetail {
  7632. var total int64
  7633. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7634. for _, its := range auto {
  7635. total += its.Count
  7636. }
  7637. it.Count = total
  7638. }
  7639. }
  7640. }
  7641. c.ServeSuccessJSON(map[string]interface{}{
  7642. "dialysis_goods": dialysisGoods,
  7643. "good_type": goodTypes,
  7644. "total": total,
  7645. "prescribe": prescribe,
  7646. "good_info": good_info,
  7647. "warehouseOutList": warehouseOutList,
  7648. "config": config,
  7649. "outConfig": outConfig,
  7650. "settleConfig": settleConfig,
  7651. })
  7652. return
  7653. } else if err == nil {
  7654. //获取当天排班的每个患者的库存使用情况
  7655. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  7656. //获取患者总的出库数据
  7657. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  7658. if patient_id != 0 {
  7659. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  7660. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  7661. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  7662. item.Project = project
  7663. item.LastAutomaticReduceDetail = goodUser
  7664. item.LastDialysisBeforePrepare = lastGoodUserDetial
  7665. for _, it := range item.AutomaticReduceDetail {
  7666. var total int64
  7667. auto, _ := service.GetPatientAutoMatic(it.PatientId, adminUser.Org.Id, date.Unix(), it.GoodId)
  7668. for _, its := range auto {
  7669. total += its.Count
  7670. }
  7671. it.Count = total
  7672. }
  7673. }
  7674. }
  7675. if err == nil {
  7676. c.ServeSuccessJSON(map[string]interface{}{
  7677. "dialysis_goods": dialysisGoods,
  7678. "good_type": goodTypes,
  7679. "total": total,
  7680. "prescribe": prescribe,
  7681. "good_info": good_info,
  7682. "project": project,
  7683. "warehouseOutList": warehouseOutList,
  7684. "config": config,
  7685. "outConfig": outConfig,
  7686. "settleConfig": settleConfig,
  7687. })
  7688. return
  7689. } else {
  7690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7691. return
  7692. }
  7693. } else if err != nil {
  7694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7695. return
  7696. }
  7697. }
  7698. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  7699. start_time := c.GetString("start_time")
  7700. end_time := c.GetString("end_time")
  7701. timeLayout := "2006-01-02"
  7702. loc, _ := time.LoadLocation("Local")
  7703. var theStartTime int64
  7704. if len(start_time) > 0 {
  7705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7706. if err != nil {
  7707. utils.ErrorLog(err.Error())
  7708. }
  7709. theStartTime = theTime.Unix()
  7710. }
  7711. var theEndtTime int64
  7712. if len(end_time) > 0 {
  7713. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7714. if err != nil {
  7715. utils.ErrorLog(err.Error())
  7716. }
  7717. theEndtTime = theTime.Unix()
  7718. }
  7719. adminUser := c.GetMobileAdminUserInfo()
  7720. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  7721. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  7722. if err == nil {
  7723. c.ServeSuccessJSON(map[string]interface{}{
  7724. "stock_out": outInfo,
  7725. "stockCount": stockCount,
  7726. })
  7727. return
  7728. } else {
  7729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7730. return
  7731. }
  7732. }
  7733. func (c *DialysisAPIController) GetStockInGoodInfo() {
  7734. patient_id, _ := c.GetInt64("patient_id", 0)
  7735. record_time := c.GetString("record_time")
  7736. adminUser := c.GetMobileAdminUserInfo()
  7737. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  7738. if parseDateErr != nil && len(record_time) != 0 {
  7739. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7740. return
  7741. }
  7742. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  7743. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  7744. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  7745. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  7746. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  7747. //获取今日患者的透析处方参数
  7748. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  7749. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  7750. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  7751. c.ServeSuccessJSON(map[string]interface{}{
  7752. "good_type": goodTypes,
  7753. "good_user": goodUser,
  7754. "good_info": good_info,
  7755. "last_good_user": lastGoodUserDetial,
  7756. "project": project,
  7757. "prescription": prescribe,
  7758. "outInfo": outInfo,
  7759. "configs": configs,
  7760. })
  7761. return
  7762. }
  7763. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  7764. patient_id, _ := c.GetInt64("patient_id", 0)
  7765. record_date := c.GetString("record_time")
  7766. timeLayout := "2006-01-02"
  7767. loc, _ := time.LoadLocation("Local")
  7768. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7769. record_time := theRecordTime.Unix()
  7770. adminInfo := c.GetMobileAdminUserInfo()
  7771. dataBody := make(map[string]interface{}, 0)
  7772. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7773. if err != nil {
  7774. utils.ErrorLog(err.Error())
  7775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7776. return
  7777. }
  7778. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7779. var beforePrepares []*models.DialysisBeforePrepareGoods
  7780. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  7781. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  7782. goods, _ := dataBody["goods"].([]interface{})
  7783. if len(goods) > 0 {
  7784. for _, item := range goods {
  7785. items := item.(map[string]interface{})
  7786. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  7787. utils.ErrorLog("good_id")
  7788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7789. return
  7790. }
  7791. good_id := int64(items["good_id"].(float64))
  7792. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  7793. utils.ErrorLog("good_type_id")
  7794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7795. return
  7796. }
  7797. good_type_id := int64(items["good_type_id"].(float64))
  7798. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  7799. utils.ErrorLog("count")
  7800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7801. return
  7802. }
  7803. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  7804. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  7805. utils.ErrorLog("project_id")
  7806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7807. return
  7808. }
  7809. project_id := int64(items["project_id"].(float64))
  7810. new_count := int64(items["new_count"].(float64))
  7811. old_count := int64(items["old_count"].(float64))
  7812. prepare := &models.DialysisBeforePrepareGoods{
  7813. GoodId: good_id,
  7814. GoodTypeId: good_type_id,
  7815. Count: count,
  7816. ProjectId: project_id,
  7817. StorehouseId: houseConfig.StorehouseOutInfo,
  7818. NewCount: new_count,
  7819. OldCount: old_count,
  7820. }
  7821. beforePrepares = append(beforePrepares, prepare)
  7822. newPrepare := &models.NewDialysisBeforePrepareGoods{
  7823. GoodId: good_id,
  7824. GoodTypeId: good_type_id,
  7825. Count: count,
  7826. ProjectId: project_id,
  7827. StorehouseId: houseConfig.StorehouseOutInfo,
  7828. NewCount: new_count,
  7829. OldCount: old_count,
  7830. }
  7831. newBeforePrepares = append(newBeforePrepares, newPrepare)
  7832. }
  7833. }
  7834. }
  7835. //查询是否有库存
  7836. for _, item := range beforePrepares {
  7837. if item.NewCount > 0 {
  7838. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7839. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  7840. if item.Count > warehouse.Count {
  7841. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  7842. c.ServeSuccessJSON(map[string]interface{}{
  7843. "message": "1",
  7844. "good_name": goodObj.GoodName,
  7845. "specification_name": goodObj.SpecificationName,
  7846. })
  7847. return
  7848. }
  7849. }
  7850. }
  7851. // 查询信息规挡的设置天数
  7852. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  7853. if infor.ID > 0 && infor.WeekDay > 0 {
  7854. var cha_time int64
  7855. timeNowStr := time.Now().Format("2006-01-02")
  7856. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  7857. //今日的日期减去设置的日期
  7858. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  7859. if cha_time >= record_time {
  7860. //查询审核是否允许
  7861. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  7862. //申请状态不允许的情况 拒绝修改
  7863. if infor.ApplicationStatus != 1 {
  7864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  7865. return
  7866. }
  7867. }
  7868. }
  7869. //出库逻辑
  7870. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  7871. if err != nil {
  7872. utils.ErrorLog(err.Error())
  7873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7874. return
  7875. }
  7876. finish := models.XtDialysisFinish{
  7877. IsFinish: 1,
  7878. UserOrgId: adminInfo.Org.Id,
  7879. Status: 1,
  7880. Ctime: time.Now().Unix(),
  7881. Mtime: 0,
  7882. Module: 11,
  7883. RecordDate: record_time,
  7884. Sourse: 1,
  7885. PatientId: patient_id,
  7886. }
  7887. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  7888. if dialysisFinish.ID == 0 {
  7889. service.CreateDialysisFinish(finish)
  7890. }
  7891. //查询当天出库的数据
  7892. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  7893. for _, item := range list {
  7894. prepare := models.DialysisBeforePrepare{
  7895. UserOrgId: item.OrgId,
  7896. PatientId: item.PatientId,
  7897. RecordDate: item.RecordTime,
  7898. GoodId: item.GoodId,
  7899. GoodTypeId: item.GoodTypeId,
  7900. Count: item.Count,
  7901. Creater: adminInfo.AdminUser.Id,
  7902. Status: 1,
  7903. Ctime: time.Now().Unix(),
  7904. ProjectId: item.ProjectId,
  7905. StorehouseId: houseConfig.StorehouseOutInfo,
  7906. }
  7907. //清空准备表的数据
  7908. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  7909. //插入准备表数据
  7910. service.CreateDialysisBeforePrepareOne(&prepare)
  7911. //查询默认仓库
  7912. //查询默认仓库
  7913. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  7914. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  7915. var total_count int64
  7916. for _, it := range stockList {
  7917. total_count += it.StockCount
  7918. }
  7919. //基础库插入数据
  7920. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  7921. ////更新剩余库存
  7922. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  7923. var flush_count int64
  7924. for _, it := range goodList {
  7925. flush_count += it.StockCount
  7926. }
  7927. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  7928. if errs != nil {
  7929. goodErrcode := models.XtGoodErrcode{
  7930. UserOrgId: item.OrgId,
  7931. Errcode: "手动出库更新剩余出库失败",
  7932. GoodId: item.GoodId,
  7933. Status: 1,
  7934. Ctime: time.Now().Unix(),
  7935. Mtime: 0,
  7936. Count: 0,
  7937. StockCount: 0,
  7938. Creater: adminInfo.AdminUser.Id,
  7939. BatchNumberId: 0,
  7940. WarehouseOutId: 0,
  7941. }
  7942. service.CreateGoodErrcode(goodErrcode)
  7943. }
  7944. }
  7945. //更新自动出库的地方
  7946. var errs error
  7947. if errs == nil {
  7948. c.ServeSuccessJSON(map[string]interface{}{
  7949. "msg": "修改成功",
  7950. "message": "2",
  7951. "good_name": "",
  7952. "specification_name": "",
  7953. })
  7954. return
  7955. } else {
  7956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7957. return
  7958. }
  7959. }
  7960. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7961. newArr = make([]*models.DialysisBeforePrepare, 0)
  7962. for i := 0; i < len(arr); i++ {
  7963. repeat := false
  7964. for j := i + 1; j < len(arr); j++ {
  7965. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7966. repeat = true
  7967. break
  7968. }
  7969. }
  7970. if !repeat {
  7971. newArr = append(newArr, arr[i])
  7972. }
  7973. }
  7974. return
  7975. }
  7976. func (c *DialysisAPIController) GetAllDrug() {
  7977. patient_id, _ := c.GetInt64("patient_id", 0)
  7978. adminInfo := c.GetMobileAdminUserInfo()
  7979. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7980. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7981. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7982. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7983. c.ServeSuccessJSON(map[string]interface{}{
  7984. "base_drug_config": drugStockConfig,
  7985. "private_drug_config": privateDrugConfig,
  7986. "base_drug_list": drugList,
  7987. "private_drug_list": privateDrugList,
  7988. })
  7989. }
  7990. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7991. newArr = make([]*models.DialysisBeforePrepare, 0)
  7992. for i := 0; i < len(arr); i++ {
  7993. repeat := false
  7994. for j := i + 1; j < len(arr); j++ {
  7995. if arr[i].GoodId == arr[j].GoodId {
  7996. repeat = true
  7997. break
  7998. }
  7999. }
  8000. if !repeat {
  8001. newArr = append(newArr, arr[i])
  8002. }
  8003. }
  8004. return
  8005. }
  8006. func (c *DialysisAPIController) GetDepartment() {
  8007. adminInfo := c.GetMobileAdminUserInfo()
  8008. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  8009. if err == nil {
  8010. c.ServeSuccessJSON(map[string]interface{}{
  8011. "departments": departments,
  8012. })
  8013. } else {
  8014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8015. return
  8016. }
  8017. }
  8018. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  8019. types, _ := c.GetInt("type", 0)
  8020. start_time := c.GetString("start_time")
  8021. end_time := c.GetString("end_time")
  8022. orgId := c.GetMobileAdminUserInfo().Org.Id
  8023. timeLayout := "2006-01-02"
  8024. loc, _ := time.LoadLocation("Local")
  8025. var startTime int64
  8026. if len(start_time) > 0 {
  8027. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8028. if err != nil {
  8029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8030. return
  8031. }
  8032. startTime = theTime.Unix()
  8033. }
  8034. var endTime int64
  8035. if len(end_time) > 0 {
  8036. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8037. if err != nil {
  8038. utils.ErrorLog(err.Error())
  8039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8040. return
  8041. }
  8042. endTime = theTime.Unix()
  8043. }
  8044. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  8045. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  8046. if err != nil {
  8047. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8048. } else {
  8049. c.ServeSuccessJSON(map[string]interface{}{
  8050. "list": list,
  8051. "type": types,
  8052. "stockTotal": stockTotal,
  8053. })
  8054. }
  8055. }
  8056. func (c *DialysisAPIController) GetPrescriptionList() {
  8057. start_time := c.GetString("start_time")
  8058. end_time := c.GetString("end_time")
  8059. schedule_type, _ := c.GetInt64("schedule_type")
  8060. partion_id, _ := c.GetInt64("partion_id")
  8061. orgId := c.GetMobileAdminUserInfo().Org.Id
  8062. timeLayout := "2006-01-02"
  8063. loc, _ := time.LoadLocation("Local")
  8064. var startTime int64
  8065. if len(start_time) > 0 {
  8066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8067. if err != nil {
  8068. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8069. return
  8070. }
  8071. startTime = theTime.Unix()
  8072. }
  8073. var endTime int64
  8074. if len(end_time) > 0 {
  8075. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8076. if err != nil {
  8077. utils.ErrorLog(err.Error())
  8078. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8079. return
  8080. }
  8081. endTime = theTime.Unix()
  8082. }
  8083. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  8084. fmt.Println("schedulelist22222222", schedulelist)
  8085. c.ServeSuccessJSON(map[string]interface{}{
  8086. "list": schedulelist,
  8087. })
  8088. return
  8089. }
  8090. func (c *DialysisAPIController) BatchDeleteMonitor() {
  8091. ids := c.GetString("ids")
  8092. //patient_id, _ := c.GetInt64("patient_id")
  8093. //monitoring_date, _ := c.GetInt64("monitoring_date")
  8094. idArray := strings.Split(ids, ",")
  8095. err := service.BatchDeleteMonitor(idArray)
  8096. fmt.Print("err", err)
  8097. //orgid := c.GetMobileAdminUserInfo().Org.Id
  8098. //redis := service.RedisClient()
  8099. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  8100. //redis.Set(key, "", time.Second)
  8101. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  8102. //redis.Set(keyOne, "", time.Second)
  8103. //fmt.Println("keyo呢32332322332332232332",keyOne)
  8104. //redis.Close()
  8105. c.ServeSuccessJSON(map[string]interface{}{
  8106. "msg": "批量删除成功",
  8107. })
  8108. return
  8109. }
  8110. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  8111. id, _ := c.GetInt64("id")
  8112. timeLayout := "2006-01-02"
  8113. loc, _ := time.LoadLocation("Local")
  8114. //start_time := time.Now().Format("2006-01-02")
  8115. start_time := c.GetString("start_time")
  8116. end_time := c.GetString("end_time")
  8117. var startdateunix int64
  8118. if len(start_time) > 0 {
  8119. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8120. if err != nil {
  8121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8122. return
  8123. }
  8124. startdateunix = theTime.Unix()
  8125. }
  8126. var enddateunix int64
  8127. if len(end_time) > 0 {
  8128. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8129. if err != nil {
  8130. utils.ErrorLog(err.Error())
  8131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8132. return
  8133. }
  8134. enddateunix = theTime.Unix()
  8135. }
  8136. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8137. //nowTime := time.Now()
  8138. //endTime := nowTime.AddDate(-30, 0, 0)
  8139. //endTimes := endTime.Format("2006-01-02")
  8140. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8141. org_id := c.GetMobileAdminUserInfo().Org.Id
  8142. //if org_id == 10579 {
  8143. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8144. // c.ServeSuccessJSON(map[string]interface{}{
  8145. // "list": list,
  8146. // })
  8147. // return
  8148. //} else {
  8149. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8150. // c.ServeSuccessJSON(map[string]interface{}{
  8151. // "list": list,
  8152. // })
  8153. // return
  8154. //}
  8155. if org_id == 9538 || org_id == 10101 || org_id == 10353 || org_id == 9946 {
  8156. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  8157. c.ServeSuccessJSON(map[string]interface{}{
  8158. "list": list,
  8159. })
  8160. return
  8161. } else {
  8162. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  8163. c.ServeSuccessJSON(map[string]interface{}{
  8164. "list": list,
  8165. })
  8166. }
  8167. return
  8168. }
  8169. func (c *DialysisAPIController) BathDeleteAdviceList() {
  8170. dataBody := make(map[string]interface{}, 0)
  8171. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8172. ids := c.GetString("ids")
  8173. idArray := strings.Split(ids, ",")
  8174. origin, _ := c.GetInt64("origin")
  8175. if origin == 1 {
  8176. err = service.BatchDeleteAdvice(idArray)
  8177. fmt.Print("err", err)
  8178. c.ServeSuccessJSON(map[string]interface{}{
  8179. "msg": "批量删除成功",
  8180. })
  8181. return
  8182. }
  8183. if origin == 2 {
  8184. service.BatchDeleteHisAdvice(idArray)
  8185. }
  8186. }
  8187. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  8188. good_id, _ := c.GetInt64("good_id")
  8189. count, _ := c.GetInt64("count")
  8190. record_time, _ := c.GetInt64("record_time")
  8191. patient_id, _ := c.GetInt64("patient_id")
  8192. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  8193. c.ServeSuccessJSON(map[string]interface{}{
  8194. "detail": detail,
  8195. })
  8196. return
  8197. }
  8198. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  8199. good_id, _ := c.GetInt64("good_id")
  8200. record_time, _ := c.GetInt64("record_time")
  8201. patient_id, _ := c.GetInt64("patient_id")
  8202. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  8203. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  8204. fmt.Print("err", err)
  8205. c.ServeSuccessJSON(map[string]interface{}{
  8206. "msg": "批量删除成功",
  8207. })
  8208. return
  8209. }
  8210. func (c *DialysisAPIController) BatchAdviceCheck() {
  8211. ids := c.GetString("ids")
  8212. idArray := strings.Split(ids, ",")
  8213. creator, _ := c.GetInt64("creator")
  8214. origin, _ := c.GetInt64("origin")
  8215. if origin == 1 {
  8216. err := service.BatchAdviceCheck(idArray, creator)
  8217. fmt.Println(err)
  8218. list, _ := service.GetAdviceExecutionById(idArray)
  8219. c.ServeSuccessJSON(map[string]interface{}{
  8220. "list": list,
  8221. })
  8222. return
  8223. }
  8224. if origin == 2 {
  8225. service.BatchHisAdviceCheck(idArray, creator)
  8226. list, _ := service.GetHisAdviceExecutionById(idArray)
  8227. c.ServeSuccessJSON(map[string]interface{}{
  8228. "list": list,
  8229. })
  8230. return
  8231. }
  8232. }
  8233. func (c *DialysisAPIController) BatchAdviceExecution() {
  8234. ids := c.GetString("ids")
  8235. idArray := strings.Split(ids, ",")
  8236. executionTime := c.GetString("execution_time")
  8237. creator, _ := c.GetInt64("creator")
  8238. timeLayout := "2006-01-02 15:04:05"
  8239. loc, _ := time.LoadLocation("Local")
  8240. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  8241. orgin, _ := c.GetInt64("origin")
  8242. if orgin == 1 {
  8243. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  8244. list, _ := service.GetAdviceExecutionById(idArray)
  8245. fmt.Println(err)
  8246. c.ServeSuccessJSON(map[string]interface{}{
  8247. "list": list,
  8248. })
  8249. return
  8250. }
  8251. if orgin == 2 {
  8252. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  8253. list, _ := service.GetHisAdviceExecutionById(idArray)
  8254. fmt.Println(err)
  8255. c.ServeSuccessJSON(map[string]interface{}{
  8256. "list": list,
  8257. })
  8258. return
  8259. }
  8260. }
  8261. func (c *DialysisAPIController) UpdateStockGoods() {
  8262. good_id, _ := c.GetInt64("good_id")
  8263. record_time, _ := c.GetInt64("record_time")
  8264. patient_id, _ := c.GetInt64("patient_id")
  8265. count, _ := c.GetInt64("count")
  8266. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  8267. fmt.Print("err", err)
  8268. c.ServeSuccessJSON(map[string]interface{}{
  8269. "msg": "更新成功",
  8270. })
  8271. return
  8272. }
  8273. // 当前数据比上一次出库数据少
  8274. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  8275. //查询该患者当天已经出库的耗材信息
  8276. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8277. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8278. for i := len(goods_yc) - 1; i >= 0; i-- {
  8279. goods_yc_temp := goods_yc[i]
  8280. for j := len(goods) - 1; j >= 0; j-- {
  8281. goods_temp := goods[j]
  8282. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8283. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8284. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8285. if goods_yc_temp.Count == goods_temp.Count {
  8286. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8287. goods = append(goods[:j], goods[j+1:]...)
  8288. break
  8289. }
  8290. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8291. if goods_yc_temp.Count > goods_temp.Count {
  8292. temp_count := goods_yc_temp.Count - goods_temp.Count
  8293. goods_yc[i].Count = temp_count
  8294. goods = append(goods[:j], goods[j+1:]...)
  8295. break
  8296. }
  8297. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8298. if goods_yc_temp.Count < goods_temp.Count {
  8299. temp_count := goods_temp.Count - goods_yc_temp.Count
  8300. goods[j].Count = temp_count
  8301. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8302. break
  8303. }
  8304. }
  8305. }
  8306. }
  8307. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8308. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8309. //退库
  8310. if len(goods_yc) > 0 {
  8311. for _, good_yc := range goods_yc {
  8312. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8313. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  8314. }
  8315. }
  8316. return nil
  8317. }
  8318. // 耗材出库删除
  8319. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8320. // 先根据相关信息查询当天该耗材的出库信息
  8321. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8322. if err != nil {
  8323. return err
  8324. }
  8325. var delete_count int64 = 0
  8326. delete_count = warehouseOutInfos.Count - count
  8327. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8328. // 在出库记录表里记录退库详情
  8329. warehouseOutInfo := &models.WarehouseOutInfo{
  8330. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8331. WarehouseOutId: warehouseOut.ID,
  8332. Status: 1,
  8333. Ctime: time.Now().Unix(),
  8334. OrgId: orgID,
  8335. Type: 1,
  8336. IsSys: 1,
  8337. SysRecordTime: record_time,
  8338. GoodTypeId: good_yc.GoodTypeId,
  8339. GoodId: good_yc.GoodId,
  8340. PatientId: good_yc.PatientId,
  8341. ConsumableType: 2,
  8342. StorehouseId: houseConfig.StorehouseOutInfo,
  8343. IsCheck: 1,
  8344. }
  8345. warehouseOutInfo.Count = count
  8346. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8347. warehouseOutInfo.Price = stockInInfo.Price
  8348. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8349. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8350. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8351. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8352. warehouseOutInfo.Number = warehouseOutInfos.Number
  8353. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8354. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8355. //查找当天是否存在出库记录
  8356. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8357. if errcod == gorm.ErrRecordNotFound {
  8358. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8359. //插入详情明细表
  8360. stockFlow := models.VmStockFlow{
  8361. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8362. WarehouseOutId: warehouseOut.ID,
  8363. GoodId: good_yc.GoodId,
  8364. Number: warehouseOutInfos.Number,
  8365. ProductDate: stockInInfo.ProductDate,
  8366. ExpireDate: stockInInfo.ExpiryDate,
  8367. Count: count,
  8368. Price: stockInInfo.Price,
  8369. Status: 1,
  8370. Ctime: time.Now().Unix(),
  8371. UserOrgId: good_yc.OrgId,
  8372. Manufacturer: stockInInfo.Manufacturer,
  8373. Dealer: stockInInfo.Dealer,
  8374. LicenseNumber: stockInInfo.LicenseNumber,
  8375. IsEdit: 2,
  8376. Creator: creater,
  8377. SystemTime: record_time,
  8378. ConsumableType: 3,
  8379. WarehousingDetailId: 0,
  8380. IsSys: 1,
  8381. UpdateCreator: creater,
  8382. PatientId: patient_id,
  8383. StorehouseId: houseConfig.StorehouseOutInfo,
  8384. }
  8385. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8386. if errflow == gorm.ErrRecordNotFound {
  8387. //创建流水表
  8388. err := service.CreateStockFlowOne(stockFlow)
  8389. fmt.Println("err", err)
  8390. } else if errflow == nil {
  8391. //插入详情明细表
  8392. stockFlow := models.VmStockFlow{
  8393. ID: exsit.ID,
  8394. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8395. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8396. WarehouseOutId: warehouseOut.ID,
  8397. GoodId: good_yc.GoodId,
  8398. Number: warehouseOutInfos.Number,
  8399. ProductDate: stockInInfo.ProductDate,
  8400. ExpireDate: stockInInfo.ExpiryDate,
  8401. Count: exsit.Count - delete_count,
  8402. Price: stockInInfo.Price,
  8403. Status: 1,
  8404. Ctime: time.Now().Unix(),
  8405. UserOrgId: good_yc.OrgId,
  8406. Manufacturer: stockInInfo.Manufacturer,
  8407. Dealer: stockInInfo.Dealer,
  8408. LicenseNumber: stockInInfo.LicenseNumber,
  8409. IsEdit: 2,
  8410. Creator: creater,
  8411. SystemTime: record_time,
  8412. ConsumableType: 3,
  8413. WarehousingDetailId: 0,
  8414. IsSys: 1,
  8415. UpdateCreator: creater,
  8416. PatientId: patient_id,
  8417. StorehouseId: houseConfig.StorehouseOutInfo,
  8418. }
  8419. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8420. }
  8421. if errOne != nil {
  8422. return errOne
  8423. }
  8424. } else if errcod == nil {
  8425. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8426. //插入详情明细表
  8427. stockFlow := models.VmStockFlow{
  8428. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8429. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8430. WarehouseOutId: warehouseOut.ID,
  8431. GoodId: good_yc.GoodId,
  8432. Number: warehouseOutInfos.Number,
  8433. ProductDate: stockInInfo.ProductDate,
  8434. ExpireDate: stockInInfo.ExpiryDate,
  8435. Count: count,
  8436. Price: stockInInfo.Price,
  8437. Status: 1,
  8438. Ctime: time.Now().Unix(),
  8439. UserOrgId: good_yc.OrgId,
  8440. Manufacturer: stockInInfo.Manufacturer,
  8441. Dealer: stockInInfo.Dealer,
  8442. LicenseNumber: stockInInfo.LicenseNumber,
  8443. IsEdit: 2,
  8444. Creator: creater,
  8445. SystemTime: record_time,
  8446. ConsumableType: 3,
  8447. WarehousingDetailId: 0,
  8448. IsSys: 1,
  8449. UpdateCreator: creater,
  8450. PatientId: patient_id,
  8451. ReturnCount: delete_count,
  8452. StorehouseId: houseConfig.StorehouseOutInfo,
  8453. }
  8454. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  8455. if errflows == gorm.ErrRecordNotFound {
  8456. //创建流水表
  8457. service.CreateStockFlowOne(stockFlow)
  8458. } else if errflows == nil {
  8459. stockFlow := models.VmStockFlow{
  8460. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  8461. ID: exsit.ID,
  8462. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8463. WarehouseOutId: warehouseOut.ID,
  8464. GoodId: good_yc.GoodId,
  8465. Number: warehouseOutInfos.Number,
  8466. ProductDate: stockInInfo.ProductDate,
  8467. ExpireDate: stockInInfo.ExpiryDate,
  8468. Count: exsit.Count - delete_count,
  8469. Price: stockInInfo.Price,
  8470. Status: 1,
  8471. Ctime: time.Now().Unix(),
  8472. UserOrgId: good_yc.OrgId,
  8473. Manufacturer: stockInInfo.Manufacturer,
  8474. Dealer: stockInInfo.Dealer,
  8475. LicenseNumber: stockInInfo.LicenseNumber,
  8476. IsEdit: 2,
  8477. Creator: creater,
  8478. SystemTime: record_time,
  8479. ConsumableType: 3,
  8480. WarehousingDetailId: 0,
  8481. IsSys: 1,
  8482. UpdateCreator: creater,
  8483. PatientId: patient_id,
  8484. ReturnCount: delete_count,
  8485. StorehouseId: houseConfig.StorehouseOutInfo,
  8486. }
  8487. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  8488. }
  8489. }
  8490. //更改自动出库的表格
  8491. details := models.BloodAutomaticReduceDetail{
  8492. WarehouseOutId: warehouseOutInfo.ID,
  8493. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8494. PatientId: patient_id,
  8495. Ctime: time.Now().Unix(),
  8496. Mtime: time.Now().Unix(),
  8497. Status: 1,
  8498. RecordTime: record_time,
  8499. OrgId: orgID,
  8500. GoodId: good_yc.GoodId,
  8501. GoodTypeId: good_yc.GoodTypeId,
  8502. Count: count,
  8503. StorehouseId: houseConfig.StorehouseOutInfo,
  8504. }
  8505. //查询当天耗材是否已经存在数据
  8506. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8507. if errcode == gorm.ErrRecordNotFound {
  8508. errTwo := service.CreateAutoReduceRecord(&details)
  8509. if errTwo != nil {
  8510. return errTwo
  8511. }
  8512. } else if errcode == nil {
  8513. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8514. service.CreateAutoReduceRecord(&details)
  8515. }
  8516. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8517. //增加出库库存数量
  8518. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  8519. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8520. fmt.Println("errOne", errOne)
  8521. // 删除出库完成后,要增加对应批次的库存数量
  8522. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8523. if errThree != nil {
  8524. return errThree
  8525. }
  8526. if good_yc.Count == 0 {
  8527. return nil
  8528. } else {
  8529. return errors.New("退库和出库数据不匹配")
  8530. }
  8531. }
  8532. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  8533. //查询该患者当天已经出库的耗材信息
  8534. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  8535. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  8536. for i := len(goods_yc) - 1; i >= 0; i-- {
  8537. goods_yc_temp := goods_yc[i]
  8538. for j := len(goods) - 1; j >= 0; j-- {
  8539. goods_temp := goods[j]
  8540. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  8541. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  8542. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  8543. if goods_yc_temp.Count == goods_temp.Count {
  8544. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8545. goods = append(goods[:j], goods[j+1:]...)
  8546. break
  8547. }
  8548. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  8549. if goods_yc_temp.Count > goods_temp.Count {
  8550. temp_count := goods_yc_temp.Count - goods_temp.Count
  8551. goods_yc[i].Count = temp_count
  8552. goods = append(goods[:j], goods[j+1:]...)
  8553. break
  8554. }
  8555. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  8556. if goods_yc_temp.Count < goods_temp.Count {
  8557. temp_count := goods_temp.Count - goods_yc_temp.Count
  8558. goods[j].Count = temp_count
  8559. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  8560. break
  8561. }
  8562. }
  8563. }
  8564. }
  8565. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  8566. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  8567. fmt.Println("剩余需要出库的", len(goods))
  8568. if len(goods) > 0 {
  8569. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  8570. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8571. if err == gorm.ErrRecordNotFound {
  8572. //没有记录,则创建出库单
  8573. timeStr := time.Now().Format("2006-01-02")
  8574. timeArr := strings.Split(timeStr, "-")
  8575. total, _ := service.FindAllWarehouseOut(orgID)
  8576. total = total + 1
  8577. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8578. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8579. number = number + total
  8580. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8581. warehouseOut := models.WarehouseOut{
  8582. WarehouseOutOrderNumber: warehousing_out_order,
  8583. OperationTime: time.Now().Unix(),
  8584. OrgId: orgID,
  8585. Creater: creater,
  8586. Ctime: time.Now().Unix(),
  8587. Status: 1,
  8588. WarehouseOutTime: record_time,
  8589. Dealer: 0,
  8590. Manufacturer: 0,
  8591. Type: 1,
  8592. IsSys: 1,
  8593. StorehouseId: houseConfig.StorehouseOutInfo,
  8594. IsCheck: 1,
  8595. }
  8596. err := service.AddSigleWarehouseOutOne(&warehouseOut)
  8597. if err != nil {
  8598. utils.TraceLog("创建出库单失败 err = %v", err)
  8599. return err
  8600. } else {
  8601. out = warehouseOut
  8602. }
  8603. }
  8604. for _, item := range goods {
  8605. var newCount int64 = 0
  8606. for _, it := range goodOne {
  8607. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  8608. newCount = it.Count
  8609. }
  8610. }
  8611. prepare := models.DialysisBeforePrepare{
  8612. GoodTypeId: item.GoodTypeId,
  8613. GoodId: item.GoodId,
  8614. Count: item.Count,
  8615. StorehouseId: houseConfig.StorehouseOutInfo,
  8616. }
  8617. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  8618. //增加出库数量
  8619. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  8620. }
  8621. }
  8622. if len(goods_yc) > 0 {
  8623. for _, good_yc := range goods_yc {
  8624. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  8625. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  8626. }
  8627. }
  8628. return nil
  8629. }
  8630. // 耗材出库删除
  8631. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  8632. // 先根据相关信息查询当天该耗材的出库信息
  8633. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  8634. if err != nil {
  8635. return err
  8636. }
  8637. var delete_count int64 = 0
  8638. for _, ware := range warehouseOutInfos {
  8639. // 判断当前出库的数据和删除出库数量
  8640. if good_yc.Count <= ware.Count {
  8641. delete_count = good_yc.Count
  8642. } else {
  8643. delete_count = ware.Count
  8644. }
  8645. warehouseOutInfo := &models.WarehouseOutInfo{
  8646. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8647. WarehouseOutId: warehouseOut.ID,
  8648. Status: 1,
  8649. Ctime: time.Now().Unix(),
  8650. Remark: "",
  8651. OrgId: orgID,
  8652. Type: 1,
  8653. Manufacturer: 0,
  8654. Dealer: 0,
  8655. IsSys: 0,
  8656. SysRecordTime: record_time,
  8657. GoodTypeId: good_yc.GoodTypeId,
  8658. GoodId: good_yc.GoodId,
  8659. StorehouseId: warehouseOut.StorehouseId,
  8660. IsCheck: 1,
  8661. }
  8662. warehouseOutInfo.Count = delete_count
  8663. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8664. warehouseOutInfo.Price = stockInInfo.Price
  8665. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8666. if errOne != nil {
  8667. return errOne
  8668. }
  8669. // 删除出库完成后,要改变流水库存(有疑问)
  8670. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  8671. fmt.Println("errOne", errOne)
  8672. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  8673. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8674. //扣减出库数量
  8675. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  8676. if errThree != nil {
  8677. return errThree
  8678. }
  8679. }
  8680. if good_yc.Count == 0 {
  8681. return nil
  8682. } else {
  8683. return errors.New("退库和出库数据不匹配")
  8684. }
  8685. }
  8686. func (this *DialysisAPIController) GetMobileScheduleList() {
  8687. limit, _ := this.GetInt64("limit")
  8688. page, _ := this.GetInt64("page")
  8689. type_options_visible, _ := this.GetInt64("type_options_visible")
  8690. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  8691. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  8692. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  8693. }
  8694. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  8695. newArr = make([]*models.HisPrescriptionProject, 0)
  8696. for i := 0; i < len(arr); i++ {
  8697. repeat := false
  8698. for j := i + 1; j < len(arr); j++ {
  8699. if arr[i].TeamId == arr[j].TeamId && arr[i].PrescriptionId == arr[j].PrescriptionId {
  8700. repeat = true
  8701. break
  8702. }
  8703. }
  8704. if !repeat {
  8705. newArr = append(newArr, arr[i])
  8706. }
  8707. }
  8708. return
  8709. }
  8710. func (this *DialysisAPIController) GetRoleList() {
  8711. admin_user_id, _ := this.GetInt64("admin_user_id")
  8712. orgid := this.GetMobileAdminUserInfo().Org.Id
  8713. list, err := service.GetRoleList(orgid, admin_user_id)
  8714. fmt.Println(err)
  8715. this.ServeSuccessJSON(map[string]interface{}{
  8716. "list": list,
  8717. })
  8718. return
  8719. }
  8720. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  8721. // 先根据相关信息查询当天该耗材的出库信息
  8722. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  8723. if err != nil {
  8724. return err
  8725. }
  8726. var delete_count int64 = 0
  8727. delete_count = warehouseOutInfos.Count - count
  8728. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  8729. // 删除出库完成后,要增加对应批次的库存数量
  8730. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  8731. if errThree != nil {
  8732. return errThree
  8733. }
  8734. //增加退库数量
  8735. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  8736. //扣减出库数量
  8737. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  8738. //查询剩余库存
  8739. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  8740. var sum_count int64
  8741. for _, item := range goodList {
  8742. sum_count += item.StockCount
  8743. }
  8744. // 在出库记录表里记录退库详情
  8745. warehouseOutInfo := &models.WarehouseOutInfo{
  8746. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8747. WarehouseOutId: warehouseOut.ID,
  8748. Status: 1,
  8749. Ctime: time.Now().Unix(),
  8750. OrgId: orgID,
  8751. Type: 1,
  8752. IsSys: 1,
  8753. SysRecordTime: record_time,
  8754. GoodTypeId: good_yc.GoodTypeId,
  8755. GoodId: good_yc.GoodId,
  8756. PatientId: good_yc.PatientId,
  8757. ConsumableType: 2,
  8758. StorehouseId: houseConfig.StorehouseOutInfo,
  8759. IsCheck: 1,
  8760. OverCount: sum_count,
  8761. }
  8762. warehouseOutInfo.Count = count
  8763. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  8764. warehouseOutInfo.Price = stockInInfo.Price
  8765. warehouseOutInfo.Dealer = stockInInfo.Dealer
  8766. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  8767. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  8768. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  8769. warehouseOutInfo.Number = warehouseOutInfos.Number
  8770. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  8771. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  8772. //查找当天是否存在出库记录
  8773. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8774. if errcod == gorm.ErrRecordNotFound {
  8775. errOne := service.AddSigleWarehouseOutInfoOne(warehouseOutInfo)
  8776. //插入详情明细表
  8777. if errOne != nil {
  8778. return errOne
  8779. }
  8780. //插入详情明细表
  8781. stockFlow := models.VmStockFlow{
  8782. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  8783. WarehouseOutId: warehouseOut.ID,
  8784. GoodId: good_yc.GoodId,
  8785. Number: warehouseOutInfos.Number,
  8786. ProductDate: stockInInfo.ProductDate,
  8787. ExpireDate: stockInInfo.ExpiryDate,
  8788. Count: count,
  8789. Price: stockInInfo.Price,
  8790. Status: 1,
  8791. Ctime: record_time,
  8792. UserOrgId: good_yc.OrgId,
  8793. Manufacturer: stockInInfo.Manufacturer,
  8794. Dealer: stockInInfo.Dealer,
  8795. LicenseNumber: stockInInfo.LicenseNumber,
  8796. IsEdit: 2,
  8797. Creator: creater,
  8798. SystemTime: record_time,
  8799. ConsumableType: 3,
  8800. WarehousingDetailId: 0,
  8801. IsSys: 1,
  8802. UpdateCreator: creater,
  8803. PatientId: patient_id,
  8804. StorehouseId: houseConfig.StorehouseOutInfo,
  8805. OverCount: sum_count,
  8806. ProjectId: good_yc.ProjectId,
  8807. }
  8808. err := service.CreateStockFlowOne(stockFlow)
  8809. fmt.Println("err", err)
  8810. } else if errcod == nil {
  8811. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  8812. }
  8813. //创建退库单
  8814. operation_time := time.Now().Unix()
  8815. //创建退库单
  8816. timeStr := time.Now().Format("2006-01-02")
  8817. timeArr := strings.Split(timeStr, "-")
  8818. total, _ := service.FindAllCancelStockTotal(orgID)
  8819. total = total + 1
  8820. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8821. cancelStock := models.CancelStock{
  8822. OrderNumber: orderNumber,
  8823. OperaTime: operation_time,
  8824. OrgId: orgID,
  8825. Creater: warehouseOut.Creater,
  8826. Ctime: time.Now().Unix(),
  8827. Status: 1,
  8828. ReturnTime: record_time,
  8829. Type: 1,
  8830. StorehouseId: stockInInfo.StorehouseId,
  8831. IsCheck: 1,
  8832. }
  8833. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  8834. if msgerrkonde == gorm.ErrRecordNotFound {
  8835. service.AddSigleCancelStock(&cancelStock)
  8836. }
  8837. cancel, _ := service.GetLastCancelStockById(orgID)
  8838. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  8839. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  8840. cancelStockInfo := models.CancelStockInfo{
  8841. GoodId: stockInInfo.GoodId,
  8842. CancelStockId: cancel.ID,
  8843. GoodTypeId: stockInInfo.GoodTypeId,
  8844. Count: delete_count,
  8845. Price: stockInInfo.PackingPrice,
  8846. Total: 0,
  8847. ProductDate: stockInInfo.ProductDate,
  8848. ExpiryDate: stockInInfo.ExpiryDate,
  8849. Ctime: record_time,
  8850. Status: 1,
  8851. OrgId: orgID,
  8852. OrderNumber: cancel.OrderNumber,
  8853. Type: 0,
  8854. Dealer: deaerler.DealerName,
  8855. Manufacturer: manufacturer.ManufacturerName,
  8856. Number: stockInInfo.Number,
  8857. RegisterAccount: "",
  8858. Remark: "",
  8859. WarehouseInfoId: stockInInfo.ID,
  8860. PatientId: patient_id,
  8861. RecordDate: record_time,
  8862. StorehouseId: stockInInfo.StorehouseId,
  8863. IsCheck: 1,
  8864. }
  8865. service.CreateCancelStockInfoOne(&cancelStockInfo)
  8866. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  8867. flow := models.VmStockFlow{
  8868. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  8869. GoodId: good_yc.GoodId,
  8870. Number: warehouseOutInfos.Number,
  8871. LicenseNumber: stockInInfo.LicenseNumber,
  8872. Count: delete_count,
  8873. UserOrgId: orgID,
  8874. PatientId: patient_id,
  8875. SystemTime: record_time,
  8876. ConsumableType: 7,
  8877. IsSys: 0,
  8878. WarehousingOrder: "",
  8879. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  8880. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8881. IsEdit: 0,
  8882. CancelStockId: cancel.ID,
  8883. CancelOrderNumber: cancel.OrderNumber,
  8884. Manufacturer: manufacturer.ID,
  8885. Dealer: 0,
  8886. Creator: warehouseOut.Creater,
  8887. UpdateCreator: 0,
  8888. Status: 1,
  8889. Ctime: record_time,
  8890. Mtime: 0,
  8891. Price: stockInInfo.Price,
  8892. WarehousingDetailId: stockInInfo.ID,
  8893. WarehouseOutDetailId: warehouseOutInfos.ID,
  8894. CancelOutDetailId: cancelInfo.ID,
  8895. ProductDate: stockInInfo.ProductDate,
  8896. ExpireDate: stockInInfo.ExpiryDate,
  8897. StorehouseId: houseConfig.StorehouseOutInfo,
  8898. OverCount: sum_count,
  8899. }
  8900. service.CreateStockFlowOne(flow)
  8901. //更改自动出库的表格
  8902. details := models.BloodAutomaticReduceDetail{
  8903. WarehouseOutId: warehouseOutInfo.ID,
  8904. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  8905. PatientId: patient_id,
  8906. Ctime: time.Now().Unix(),
  8907. Mtime: time.Now().Unix(),
  8908. Status: 1,
  8909. RecordTime: record_time,
  8910. OrgId: orgID,
  8911. GoodId: good_yc.GoodId,
  8912. GoodTypeId: good_yc.GoodTypeId,
  8913. Count: count,
  8914. StorehouseId: houseConfig.StorehouseOutInfo,
  8915. }
  8916. //查询当天耗材是否已经存在数据
  8917. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8918. if errcode == gorm.ErrRecordNotFound {
  8919. errTwo := service.CreateAutoReduceRecord(&details)
  8920. if errTwo != nil {
  8921. return errTwo
  8922. }
  8923. } else if errcode == nil {
  8924. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  8925. service.CreateAutoReduceRecord(&details)
  8926. }
  8927. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  8928. //增加出库库存数量
  8929. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  8930. if good_yc.Count == 0 {
  8931. return nil
  8932. } else {
  8933. return errors.New("退库和出库数据不匹配")
  8934. }
  8935. }
  8936. func (this *DialysisAPIController) SavePatientSign() {
  8937. adminUserInfo := this.GetMobileAdminUserInfo()
  8938. patient_id, _ := this.GetInt64("patient_id")
  8939. dialysis_date, _ := this.GetInt64("dialysis_date")
  8940. orgid := adminUserInfo.Org.Id
  8941. var esdata models.DialysisOrder
  8942. var err error
  8943. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8944. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8945. return
  8946. }
  8947. esdata.Hash = esdata.Hash
  8948. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8949. order := models.DialysisOrder{
  8950. Hash: esdata.Hash,
  8951. Url: esdata.Url,
  8952. }
  8953. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8954. redis := service.RedisClient()
  8955. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8956. redis.Set(key, "", time.Second)
  8957. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8958. //清空key 值
  8959. redis.Set(keyOne, "", time.Second)
  8960. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8961. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8962. //redis.Set(keyTwo, "", time.Second)
  8963. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8964. redis.Set(keyThree, "", time.Second)
  8965. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8966. redis.Set(keyFour, "", time.Second)
  8967. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8968. redis.Set(keyFive, "", time.Second)
  8969. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8970. redis.Set(keySix, "", time.Second)
  8971. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8972. redis.Set(keySeven, "", time.Second)
  8973. if err != nil {
  8974. fmt.Println(err)
  8975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8976. return
  8977. }
  8978. this.ServeSuccessJSON(map[string]interface{}{
  8979. "electronic_signature": esdata,
  8980. })
  8981. }
  8982. func (this *DialysisAPIController) GetPatientSign() {
  8983. patient_id, _ := this.GetInt64("patient_id")
  8984. dialysis_date, _ := this.GetInt64("dialysis_date")
  8985. adminUserInfo := this.GetMobileAdminUserInfo()
  8986. orgId := adminUserInfo.Org.Id
  8987. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8988. if err != nil {
  8989. fmt.Println(err)
  8990. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8991. return
  8992. }
  8993. this.ServeSuccessJSON(map[string]interface{}{
  8994. "dialysisOrder": dialysisOrder,
  8995. })
  8996. }
  8997. func (this *DialysisAPIController) GetScheduleByPatient() {
  8998. patient_id, _ := this.GetInt64("patient_id")
  8999. schedule_date, _ := this.GetInt64("schedule_date")
  9000. orgid := this.GetMobileAdminUserInfo().Org.Id
  9001. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  9002. this.ServeSuccessJSON(map[string]interface{}{
  9003. "schedule": schedule,
  9004. })
  9005. }
  9006. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  9007. org_id := this.GetMobileAdminUserInfo().Org.Id
  9008. patient_id, _ := this.GetInt64("patient_id")
  9009. schedule_date, _ := this.GetInt64("schedule_date")
  9010. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  9011. this.ServeSuccessJSON(map[string]interface{}{
  9012. "order": order,
  9013. })
  9014. }
  9015. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  9016. org_id := this.GetMobileAdminUserInfo().Org.Id
  9017. schedule_date := this.GetString("schedule_date")
  9018. schedule_type, _ := this.GetInt64("schedule_type")
  9019. timeLayout := "2006-01-02"
  9020. loc, _ := time.LoadLocation("Local")
  9021. var startdateunix int64
  9022. if len(schedule_date) > 0 {
  9023. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  9024. if err != nil {
  9025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9026. return
  9027. }
  9028. startdateunix = theTime.Unix()
  9029. }
  9030. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  9031. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  9032. devices, _ := service.GetAllDevicetByListSix(org_id)
  9033. for key, item := range scheduals {
  9034. // 床位信息
  9035. for _, device := range devices {
  9036. if item.BedId == device.ID {
  9037. scheduals[key].DeviceNumber = device
  9038. break
  9039. }
  9040. }
  9041. }
  9042. this.ServeSuccessJSON(map[string]interface{}{
  9043. "list": list,
  9044. "scheduals": scheduals,
  9045. })
  9046. }
  9047. func (this *DialysisAPIController) SavePatientPicture() {
  9048. patient_id, _ := this.GetInt64("patient_id")
  9049. dialysis_date, _ := this.GetInt64("schedule_date")
  9050. avatar := this.GetString("avatar")
  9051. fmt.Println("patient_id", patient_id)
  9052. orgId := this.GetMobileAdminUserInfo().Org.Id
  9053. order := models.DialysisOrder{
  9054. Url: avatar,
  9055. }
  9056. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  9057. redis := service.RedisClient()
  9058. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  9059. redis.Set(key, "", time.Second)
  9060. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  9061. //清空key 值
  9062. redis.Set(keyOne, "", time.Second)
  9063. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  9064. redis.Set(keyThree, "", time.Second)
  9065. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  9066. redis.Set(keyFour, "", time.Second)
  9067. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  9068. redis.Set(keyFive, "", time.Second)
  9069. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  9070. redis.Set(keySix, "", time.Second)
  9071. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  9072. redis.Set(keySeven, "", time.Second)
  9073. if err != nil {
  9074. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  9075. return
  9076. }
  9077. this.ServeSuccessJSON(map[string]interface{}{
  9078. "order": order,
  9079. })
  9080. }
  9081. func (this *DialysisAPIController) ExectionMobileAdvice() {
  9082. ids := this.GetString("ids")
  9083. idSplit := strings.Split(ids, ",")
  9084. orgId := this.GetMobileAdminUserInfo().Org.Id
  9085. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9086. execution_time := this.GetString("exce_time")
  9087. timeLayout2 := "2006-01-02 15:04:05"
  9088. loc, _ := time.LoadLocation("Local")
  9089. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  9090. if errs != nil {
  9091. utils.ErrorLog(errs.Error())
  9092. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9093. return
  9094. }
  9095. //his客户
  9096. if config.IsOpen == 1 {
  9097. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  9098. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  9099. for _, item := range list {
  9100. for _, it := range adviceList {
  9101. if item.DrugId == it.DrugId {
  9102. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9103. }
  9104. }
  9105. }
  9106. for _, item := range list {
  9107. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9108. var sum_out_count int64
  9109. for _, itemThree := range item.ChildDoctorAdvice {
  9110. var prescribing_number int64
  9111. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9112. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9113. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9114. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9115. }
  9116. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9117. prescribing_number = parseIntPrescribingNumber
  9118. }
  9119. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9120. prescribing_number = parseIntPrescribingNumber
  9121. }
  9122. sum_out_count += prescribing_number
  9123. }
  9124. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9125. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9126. //库存不足
  9127. if sum_out_count > drugStockOut.FlushCount {
  9128. this.ServeSuccessJSON(map[string]interface{}{
  9129. "msg": "2",
  9130. "drug": medical,
  9131. "ids": ids,
  9132. })
  9133. return
  9134. }
  9135. }
  9136. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9137. //执行医嘱
  9138. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9139. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  9140. for _, item := range advices {
  9141. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9142. redis := service.RedisClient()
  9143. //清空key 值
  9144. redis.Set(key, "", time.Second)
  9145. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9146. redis.Set(keyTwo, "", time.Second)
  9147. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9148. redis.Set(keyThree, "", time.Second)
  9149. recordDate := theTime.Format("2006-01-02")
  9150. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9151. redis.Set(keyFour, "", time.Second)
  9152. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9153. redis.Set(keyFive, "", time.Second)
  9154. defer redis.Close()
  9155. }
  9156. if errs == nil {
  9157. //药品管理信息
  9158. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9159. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9160. if drugStockConfig.IsOpen == 1 {
  9161. for _, item := range advices {
  9162. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  9163. config, _ := service.GetDrugOpenConfigOne(orgId)
  9164. if config.IsOpen != 1 {
  9165. //查询该药品是否有库存
  9166. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9167. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  9168. if medical.IsUse == 2 {
  9169. if config.IsOpen != 1 {
  9170. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9171. service.HisDrugsDelivery(orgId, creater, &advice)
  9172. if orgId == 3877 || orgId == 10265 {
  9173. //查询该药品是否有出库记录
  9174. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9175. if len(flowMap) == 0 {
  9176. errs := service.UpdateHisAdviceById(advice.ID)
  9177. if errs != nil {
  9178. drugError := models.XtDrugError{
  9179. UserOrgId: orgId,
  9180. DrugId: item.DrugId,
  9181. RecordDate: item.AdviceDate,
  9182. PatientId: item.PatientId,
  9183. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9184. Status: 1,
  9185. Ctime: time.Now().Unix(),
  9186. Mtime: 0,
  9187. SumCount: 0,
  9188. Prescribingnumber: advice.PrescribingNumber,
  9189. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9190. }
  9191. service.CreateDrugError(drugError)
  9192. }
  9193. this.ServeSuccessJSON(map[string]interface{}{
  9194. "msg": "2",
  9195. "drug": medical,
  9196. "ids": ids,
  9197. })
  9198. return
  9199. }
  9200. }
  9201. }
  9202. if pharmacyConfig.IsOpen != 1 {
  9203. service.HisDrugsDelivery(orgId, creater, &advice)
  9204. if orgId == 3877 || orgId == 10265 {
  9205. //查询该药品是否有出库记录
  9206. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  9207. if len(flowMap) == 0 {
  9208. errs := service.UpdateHisAdviceById(advice.ID)
  9209. if errs != nil {
  9210. drugError := models.XtDrugError{
  9211. UserOrgId: orgId,
  9212. DrugId: item.DrugId,
  9213. RecordDate: item.AdviceDate,
  9214. PatientId: item.PatientId,
  9215. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  9216. Status: 1,
  9217. Ctime: time.Now().Unix(),
  9218. Mtime: 0,
  9219. SumCount: 0,
  9220. Prescribingnumber: advice.PrescribingNumber,
  9221. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  9222. }
  9223. service.CreateDrugError(drugError)
  9224. }
  9225. this.ServeSuccessJSON(map[string]interface{}{
  9226. "msg": "2",
  9227. "drug": medical,
  9228. "ids": ids,
  9229. })
  9230. return
  9231. }
  9232. }
  9233. }
  9234. //更新字典里面的库存
  9235. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9236. var sum_count int64
  9237. for _, its := range stockInfo {
  9238. if its.MaxUnit == medical.MaxUnit {
  9239. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9240. }
  9241. sum_count += its.StockMaxNumber + its.StockMinNumber
  9242. }
  9243. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9244. //剩余库存
  9245. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9246. }
  9247. }
  9248. }
  9249. }
  9250. }
  9251. this.ServeSuccessJSON(map[string]interface{}{
  9252. "msg": "1",
  9253. "ids": ids,
  9254. })
  9255. return
  9256. } else {
  9257. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9258. }
  9259. }
  9260. //血透客户
  9261. if config.IsOpen == 2 || config.IsOpen == 0 {
  9262. //药品管理信息
  9263. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  9264. if drugStockConfig.IsOpen == 1 {
  9265. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  9266. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  9267. for _, item := range list {
  9268. for _, it := range adviceList {
  9269. if item.DrugId == it.DrugId {
  9270. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  9271. }
  9272. }
  9273. }
  9274. for _, item := range list {
  9275. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9276. var sum_out_count int64
  9277. for _, itemThree := range item.ChildDoctorAdvice {
  9278. var prescribing_number int64
  9279. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  9280. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  9281. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  9282. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  9283. }
  9284. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  9285. prescribing_number = parseIntPrescribingNumber
  9286. }
  9287. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  9288. prescribing_number = parseIntPrescribingNumber
  9289. }
  9290. sum_out_count += prescribing_number
  9291. }
  9292. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9293. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  9294. //库存不足
  9295. if sum_out_count > drugStockOut.FlushCount {
  9296. this.ServeSuccessJSON(map[string]interface{}{
  9297. "msg": "2",
  9298. "drug": medical,
  9299. "ids": ids,
  9300. })
  9301. return
  9302. }
  9303. }
  9304. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9305. //执行医嘱
  9306. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9307. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9308. for _, item := range advices {
  9309. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9310. redis := service.RedisClient()
  9311. //清空key 值
  9312. redis.Set(key, "", time.Second)
  9313. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9314. redis.Set(keyTwo, "", time.Second)
  9315. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9316. redis.Set(keyThree, "", time.Second)
  9317. recordDate := theTime.Format("2006-01-02")
  9318. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9319. redis.Set(keyFour, "", time.Second)
  9320. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9321. redis.Set(keyFive, "", time.Second)
  9322. defer redis.Close()
  9323. }
  9324. if errs == nil {
  9325. for _, item := range advices {
  9326. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  9327. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  9328. //查询是否出库按钮开启
  9329. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  9330. if adviceSetting.IsAdviceOpen == 1 {
  9331. //查询是否出库按钮开启
  9332. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  9333. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9334. if prescriptionConfig.IsOpen == 1 {
  9335. if medical.IsUse == 2 {
  9336. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9337. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9338. }
  9339. if pharmacyConfig.IsOpen != 1 {
  9340. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9341. }
  9342. //更新字典里面的库存
  9343. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9344. var sum_count int64
  9345. for _, its := range stockInfo {
  9346. if its.MaxUnit == medical.MaxUnit {
  9347. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9348. }
  9349. sum_count += its.StockMaxNumber + its.StockMinNumber
  9350. }
  9351. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9352. //剩余库存
  9353. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9354. }
  9355. }
  9356. } else {
  9357. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  9358. if medical.IsUse == 2 {
  9359. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  9360. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9361. }
  9362. if pharmacyConfig.IsOpen != 1 {
  9363. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  9364. }
  9365. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  9366. var sum_count int64
  9367. for _, its := range stockInfo {
  9368. if its.MaxUnit == medical.MaxUnit {
  9369. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  9370. }
  9371. sum_count += its.StockMaxNumber + its.StockMinNumber
  9372. }
  9373. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  9374. //剩余库存
  9375. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  9376. }
  9377. }
  9378. }
  9379. }
  9380. this.ServeSuccessJSON(map[string]interface{}{
  9381. "msg": "1",
  9382. "ids": ids,
  9383. })
  9384. return
  9385. } else {
  9386. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9387. //执行医嘱
  9388. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  9389. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  9390. for _, item := range advices {
  9391. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9392. redis := service.RedisClient()
  9393. //清空key 值
  9394. redis.Set(key, "", time.Second)
  9395. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9396. redis.Set(keyTwo, "", time.Second)
  9397. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9398. redis.Set(keyThree, "", time.Second)
  9399. recordDate := theTime.Format("2006-01-02")
  9400. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9401. redis.Set(keyFour, "", time.Second)
  9402. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9403. redis.Set(keyFive, "", time.Second)
  9404. defer redis.Close()
  9405. }
  9406. this.ServeSuccessJSON(map[string]interface{}{
  9407. "msg": "1",
  9408. "ids": ids,
  9409. })
  9410. return
  9411. }
  9412. }
  9413. }
  9414. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  9415. ids := this.GetString("ids")
  9416. idSplit := strings.Split(ids, ",")
  9417. orgId := this.GetMobileAdminUserInfo().Org.Id
  9418. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9419. if config.IsOpen == 1 {
  9420. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  9421. this.ServeSuccessJSON(map[string]interface{}{
  9422. "msg": "1",
  9423. "ids": ids,
  9424. })
  9425. return
  9426. }
  9427. if config.IsOpen == 0 || config.IsOpen == 2 {
  9428. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  9429. this.ServeSuccessJSON(map[string]interface{}{
  9430. "msg": "1",
  9431. "ids": ids,
  9432. })
  9433. return
  9434. }
  9435. }
  9436. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  9437. ids := this.GetString("ids")
  9438. idSplit := strings.Split(ids, ",")
  9439. orgId := this.GetMobileAdminUserInfo().Org.Id
  9440. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  9441. //his
  9442. if config.IsOpen == 1 {
  9443. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9444. theTime := time.Now()
  9445. advices := models.HisDoctorAdviceThirty{
  9446. CheckTime: theTime.Unix(),
  9447. Checker: checker,
  9448. UpdatedTime: time.Now().Unix(),
  9449. }
  9450. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  9451. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9452. for _, item := range list {
  9453. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9454. redis := service.RedisClient()
  9455. //清空key 值
  9456. redis.Set(key, "", time.Second)
  9457. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9458. redis.Set(keyTwo, "", time.Second)
  9459. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9460. redis.Set(keyThree, "", time.Second)
  9461. recordDate := theTime.Format("2006-01-02")
  9462. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9463. redis.Set(keyFour, "", time.Second)
  9464. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9465. redis.Set(keyFive, "", time.Second)
  9466. defer redis.Close()
  9467. }
  9468. this.ServeSuccessJSON(map[string]interface{}{
  9469. "msg": "1",
  9470. "ids": ids,
  9471. })
  9472. return
  9473. }
  9474. //血透
  9475. if config.IsOpen == 0 || config.IsOpen == 2 {
  9476. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9477. theTime := time.Now()
  9478. advices := models.DoctorAdvice{
  9479. CheckTime: theTime.Unix(),
  9480. Checker: checker,
  9481. UpdatedTime: time.Now().Unix(),
  9482. }
  9483. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  9484. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  9485. for _, item := range list {
  9486. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  9487. redis := service.RedisClient()
  9488. //清空key 值
  9489. redis.Set(key, "", time.Second)
  9490. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  9491. redis.Set(keyTwo, "", time.Second)
  9492. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  9493. redis.Set(keyThree, "", time.Second)
  9494. recordDate := theTime.Format("2006-01-02")
  9495. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  9496. redis.Set(keyFour, "", time.Second)
  9497. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  9498. redis.Set(keyFive, "", time.Second)
  9499. defer redis.Close()
  9500. }
  9501. this.ServeSuccessJSON(map[string]interface{}{
  9502. "msg": "1",
  9503. "ids": ids,
  9504. })
  9505. return
  9506. }
  9507. }
  9508. func (this *DialysisAPIController) CheckSchedule() {
  9509. patientID, _ := this.GetInt64("patient_id")
  9510. recordDateStr := this.GetString("record_date")
  9511. nurseID, _ := this.GetInt64("start_nurse")
  9512. schedual_type, _ := this.GetInt64("schedual_type")
  9513. bedID, _ := this.GetInt64("bed")
  9514. start_time := this.GetString("start_time")
  9515. fmt.Println("patientID", patientID)
  9516. fmt.Println("recordDateStr", recordDateStr)
  9517. fmt.Println("nurseID", nurseID)
  9518. fmt.Println("schedual_type------", schedual_type)
  9519. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  9520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9521. return
  9522. }
  9523. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  9524. if parseStartDateErr != nil {
  9525. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  9526. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9527. return
  9528. }
  9529. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  9530. if parseErr != nil {
  9531. this.ErrorLog("时间解析失败:%v", parseErr)
  9532. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9533. return
  9534. }
  9535. adminUserInfo := this.GetMobileAdminUserInfo()
  9536. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  9537. if getPatientErr != nil {
  9538. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  9539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9540. return
  9541. } else if patient == nil {
  9542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  9543. return
  9544. }
  9545. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  9546. if getNurseErr != nil {
  9547. this.ErrorLog("获取护士失败:%v", getNurseErr)
  9548. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9549. return
  9550. } else if nurse == nil {
  9551. this.ErrorLog("护士不存在")
  9552. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9553. return
  9554. }
  9555. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  9556. if getDeviceNumberErr != nil {
  9557. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  9558. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9559. return
  9560. } else if deviceNumber == nil {
  9561. this.ErrorLog("床位号不存在")
  9562. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9563. return
  9564. }
  9565. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  9566. if getRecordErr != nil {
  9567. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  9568. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9569. return
  9570. } else if dialysisRecord != nil {
  9571. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  9572. return
  9573. }
  9574. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  9575. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  9576. timeLayout := "2006-01-02 15:04:05"
  9577. loc, _ := time.LoadLocation("Local")
  9578. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  9579. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  9580. schedulestartTime := theStartTime.Unix()
  9581. scheduleendTime := theEndTime.Unix()
  9582. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  9583. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  9584. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9585. //查询该床位是否有人用了
  9586. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  9587. if err == nil {
  9588. if schedule.ID == 0 {
  9589. this.ServeSuccessJSON(map[string]interface{}{
  9590. "status": 0,
  9591. "msg": "请求失败",
  9592. })
  9593. } else {
  9594. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  9595. if order.ID > 0 { //该机位被其他人占用了
  9596. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  9597. return
  9598. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  9599. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  9600. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  9601. this.ServeSuccessJSON(map[string]interface{}{
  9602. "status": 1,
  9603. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  9604. })
  9605. return
  9606. } else {
  9607. this.ServeSuccessJSON(map[string]interface{}{
  9608. "status": 0,
  9609. "msg": "",
  9610. })
  9611. }
  9612. }
  9613. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  9614. this.ServeSuccessJSON(map[string]interface{}{
  9615. "status": 2,
  9616. "msg": "当前机位已有患者在使用,请重新选择!",
  9617. })
  9618. }
  9619. }
  9620. } else {
  9621. this.ServeSuccessJSON(map[string]interface{}{
  9622. "status": 0,
  9623. "msg": "",
  9624. })
  9625. }
  9626. }
  9627. func (this *DialysisAPIController) GetNewDoctorListToday() {
  9628. orgId := this.GetMobileAdminUserInfo().Org.Id
  9629. schedule_type, _ := this.GetInt64("schedule_type")
  9630. partion_type, _ := this.GetInt64("partion_type")
  9631. start_time := this.GetString("start_time")
  9632. timeLayout := "2006-01-02"
  9633. loc, _ := time.LoadLocation("Local")
  9634. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9635. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  9636. _, config := service.FindXTHisRecordByOrgId(orgId)
  9637. appId := this.GetMobileAdminUserInfo().App.Id
  9638. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  9639. if err == nil {
  9640. this.ServeSuccessJSON(map[string]interface{}{
  9641. "list": list,
  9642. "config": config,
  9643. "doctorList": doctorList,
  9644. })
  9645. return
  9646. } else {
  9647. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9648. return
  9649. }
  9650. }
  9651. func (this *DialysisAPIController) SaveMobileInformation() {
  9652. patient_id, _ := this.GetInt64("patient_id")
  9653. record_date, _ := this.GetInt64("record_date")
  9654. startTime := this.GetString("start_time")
  9655. module, _ := this.GetInt64("module")
  9656. remark := this.GetString("remark")
  9657. timeLayout := "2006-01-02 15:04"
  9658. loc, _ := time.LoadLocation("Local")
  9659. if len(startTime) == 0 {
  9660. utils.ErrorLog("len(start_time) == 0")
  9661. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9662. return
  9663. }
  9664. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  9665. if err != nil {
  9666. utils.ErrorLog(err.Error())
  9667. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9668. return
  9669. }
  9670. StartTime := theTime.Unix()
  9671. fmt.Println("startime-------------", StartTime)
  9672. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  9673. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  9674. information := models.XtDialysisInformation{
  9675. Module: module,
  9676. PatientId: patient_id,
  9677. RecordDate: record_date,
  9678. ApplicationDate: StartTime,
  9679. Creater: creater,
  9680. ApplicationStatus: 2,
  9681. Checker: 0,
  9682. CheckTime: 0,
  9683. Remark: remark,
  9684. UserOrgId: user_org_id,
  9685. Ctime: time.Now().Unix(),
  9686. Status: 1,
  9687. Mtime: 0,
  9688. }
  9689. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  9690. if infor.ID == 0 {
  9691. service.SaveDialysisInformation(information)
  9692. }
  9693. if infor.ID > 0 {
  9694. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  9695. }
  9696. this.ServeSuccessJSON(map[string]interface{}{
  9697. "information": information,
  9698. })
  9699. return
  9700. }
  9701. func (this *DialysisAPIController) GetMobileInformation() {
  9702. limit, _ := this.GetInt64("limit")
  9703. page, _ := this.GetInt64("page")
  9704. orgid := this.GetMobileAdminUserInfo().Org.Id
  9705. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  9706. appid := this.GetMobileAdminUserInfo().App.Id
  9707. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9708. patients, _ := service.GetAllpatientThirty(orgid)
  9709. this.ServeSuccessJSON(map[string]interface{}{
  9710. "information": information,
  9711. "total": total,
  9712. "doclist": doclist,
  9713. "patients": patients,
  9714. })
  9715. return
  9716. }
  9717. func (this *DialysisAPIController) GetMobileInformationOne() {
  9718. limit, _ := this.GetInt64("limit")
  9719. page, _ := this.GetInt64("page")
  9720. orgid := this.GetMobileAdminUserInfo().Org.Id
  9721. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  9722. appid := this.GetMobileAdminUserInfo().App.Id
  9723. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  9724. patients, _ := service.GetAllpatientThirty(orgid)
  9725. this.ServeSuccessJSON(map[string]interface{}{
  9726. "information": information,
  9727. "total": total,
  9728. "doclist": doclist,
  9729. "patients": patients,
  9730. })
  9731. return
  9732. }
  9733. func (this *DialysisAPIController) CheckMobileInformation() {
  9734. id, _ := this.GetInt64("id")
  9735. application_status, _ := this.GetInt64("application_status")
  9736. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  9737. checktime := time.Now().Unix()
  9738. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  9739. if err == nil {
  9740. this.ServeSuccessJSON(map[string]interface{}{
  9741. "msg": "ok",
  9742. })
  9743. return
  9744. }
  9745. }
  9746. func (c *DialysisAPIController) GetControlMonitorList() {
  9747. partition, _ := c.GetInt64("partition")
  9748. monitorDate := c.GetString("date")
  9749. patient_id, _ := c.GetInt64("patient_id")
  9750. pat_type, _ := c.GetInt64("pat_type")
  9751. timeLayout := "2006-01-02"
  9752. loc, _ := time.LoadLocation("Local")
  9753. var theStartTime int64
  9754. if len(monitorDate) > 0 {
  9755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  9756. if err != nil {
  9757. theStartTime = 0
  9758. }
  9759. theStartTime = theTime.Unix()
  9760. }
  9761. adminInfo := c.GetMobileAdminUserInfo()
  9762. orgID := adminInfo.Org.Id
  9763. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  9764. if err != nil {
  9765. c.ErrorLog("获取排班信息失败:%v", err)
  9766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9767. } else {
  9768. if len(monitor) > 0 {
  9769. //获取所有床位
  9770. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  9771. //获取所有分区
  9772. zoneList, _ := service.GetAllZoneByList(orgID)
  9773. //获取透析处方
  9774. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  9775. //获取透前评估
  9776. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  9777. //获取上机
  9778. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  9779. //获取透后
  9780. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  9781. //获取透后监测
  9782. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  9783. //获取所有的患者
  9784. patients, _ := service.GetAllPatientListByListOne(orgID)
  9785. //获取所有透析模式
  9786. treatments, _ := service.GetAllTreatModeByList(orgID)
  9787. //获取所有医嘱
  9788. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  9789. //获取双人核对
  9790. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  9791. //治疗小结
  9792. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  9793. //待消毒
  9794. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  9795. for key, item := range monitor {
  9796. // 获取床位信息
  9797. for _, it := range numberList {
  9798. if item.BedId == it.ID {
  9799. monitor[key].DeviceNumber = it
  9800. break
  9801. }
  9802. }
  9803. //获取分区信息
  9804. for _, it := range zoneList {
  9805. if item.PartitionId == it.ID {
  9806. monitor[key].DeviceZone = it
  9807. }
  9808. }
  9809. for _, prescription := range prescriptions {
  9810. if item.PatientId == prescription.PatientId {
  9811. monitor[key].Prescription = prescription
  9812. break
  9813. }
  9814. }
  9815. for _, it := range checkList {
  9816. if item.PatientId == it.PatientId {
  9817. monitor[key].DoubleCheck = it
  9818. break
  9819. }
  9820. }
  9821. for _, it := range summaryList {
  9822. if item.PatientId == it.PatientId {
  9823. monitor[key].TreatmentSummaryForList = it
  9824. break
  9825. }
  9826. }
  9827. // 透前评估
  9828. for _, assessmentBefore := range assessmentBefores {
  9829. if item.PatientId == assessmentBefore.PatientId {
  9830. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  9831. break
  9832. }
  9833. }
  9834. // 透析上下机
  9835. for _, dialysisOrder := range dialysisOrders {
  9836. if item.PatientId == dialysisOrder.PatientId {
  9837. monitor[key].DialysisOrder = dialysisOrder
  9838. break
  9839. }
  9840. }
  9841. // 治疗小节
  9842. for _, afterDislysis := range AssessmentAfterDislysis {
  9843. if item.PatientId == afterDislysis.PatientId {
  9844. monitor[key].AssessmentAfterDislysis = afterDislysis
  9845. break
  9846. }
  9847. }
  9848. for _, it := range monitorlist {
  9849. if item.PatientId == it.PatientId {
  9850. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  9851. }
  9852. }
  9853. for _, it := range adviceList {
  9854. if item.PatientId == it.PatientId {
  9855. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  9856. }
  9857. }
  9858. for _, patient := range patients {
  9859. if item.PatientId == patient.ID {
  9860. monitor[key].MonitorPatients = patient
  9861. break
  9862. }
  9863. }
  9864. for _, treatment := range treatments {
  9865. if item.ModeId == treatment.ID {
  9866. monitor[key].TreatmentMode = treatment
  9867. break
  9868. }
  9869. }
  9870. for _, infor := range informationList {
  9871. if item.PatientId == infor.PatientId {
  9872. monitor[key].NewDeviceInformation = infor
  9873. break
  9874. }
  9875. }
  9876. }
  9877. }
  9878. }
  9879. patients, err := service.GetAllpatientFourty(orgID)
  9880. var mds []*models.NewMonitorDialysisScheduleList
  9881. if pat_type == 0 {
  9882. for _, item := range monitor {
  9883. mds = append(mds, item)
  9884. }
  9885. }
  9886. //待医嘱核对
  9887. if pat_type == 1 {
  9888. for _, item := range monitor {
  9889. if len(item.AdviceList) > 0 {
  9890. mds = append(mds, item)
  9891. }
  9892. }
  9893. }
  9894. //待开小结
  9895. if pat_type == 2 {
  9896. for _, item := range monitor {
  9897. if item.TreatmentSummaryForList == nil {
  9898. mds = append(mds, item)
  9899. }
  9900. }
  9901. }
  9902. //待下机
  9903. if pat_type == 3 {
  9904. for _, item := range monitor {
  9905. if item.DialysisOrder != nil {
  9906. if item.DialysisOrder.ID > 0 {
  9907. mds = append(mds, item)
  9908. }
  9909. }
  9910. }
  9911. }
  9912. //待消毒
  9913. if pat_type == 4 {
  9914. for _, item := range monitor {
  9915. if item.NewDeviceInformation == nil {
  9916. mds = append(mds, item)
  9917. }
  9918. }
  9919. }
  9920. //待双人核对
  9921. if pat_type == 5 {
  9922. for _, item := range monitor {
  9923. if item.DoubleCheck == nil {
  9924. mds = append(mds, item)
  9925. }
  9926. }
  9927. }
  9928. //医嘱未执行
  9929. if pat_type == 6 {
  9930. for _, item := range monitor {
  9931. if len(item.AdviceList) > 0 {
  9932. mds = append(mds, item)
  9933. }
  9934. }
  9935. }
  9936. //患者未签名
  9937. if pat_type == 7 {
  9938. for _, item := range monitor {
  9939. if item.DialysisOrder != nil {
  9940. if item.DialysisOrder.ID > 0 {
  9941. mds = append(mds, item)
  9942. }
  9943. }
  9944. }
  9945. }
  9946. //目标超滤于实际超滤不同
  9947. if pat_type == 8 {
  9948. for _, item := range monitor {
  9949. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9950. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9951. mds = append(mds, item)
  9952. }
  9953. }
  9954. }
  9955. }
  9956. //血压少于5次
  9957. if pat_type == 9 {
  9958. for _, item := range monitor {
  9959. if len(item.MonitoringRecord) < 5 {
  9960. mds = append(mds, item)
  9961. }
  9962. }
  9963. }
  9964. if pat_type == 13 {
  9965. for _, item := range monitor {
  9966. if len(item.MonitoringRecord) < 3 {
  9967. mds = append(mds, item)
  9968. }
  9969. }
  9970. }
  9971. if pat_type == 10 {
  9972. for _, item := range monitor {
  9973. if len(item.MonitoringRecord) == 0 {
  9974. mds = append(mds, item)
  9975. }
  9976. }
  9977. }
  9978. if pat_type == 11 {
  9979. for _, item := range monitor {
  9980. if len(item.MonitoringRecord) > 0 {
  9981. mds = append(mds, item)
  9982. }
  9983. }
  9984. }
  9985. if pat_type == 12 {
  9986. for _, item := range monitor {
  9987. if len(item.MonitoringRecord) > 0 {
  9988. mds = append(mds, item)
  9989. }
  9990. }
  9991. }
  9992. if err == nil {
  9993. c.ServeSuccessJSON(map[string]interface{}{
  9994. "monitor": mds,
  9995. "patients": patients,
  9996. })
  9997. } else {
  9998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9999. }
  10000. }
  10001. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  10002. admin_user_id, _ := c.GetInt64("admin_user_id")
  10003. timeStr := time.Now().Format("2006-01-02")
  10004. timeLayout := "2006-01-02 15:04:05"
  10005. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  10006. timenow := timeStringToTime.Unix()
  10007. orgId := c.GetMobileAdminUserInfo().Org.Id
  10008. //查询当前护士的患者
  10009. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  10010. var patientIds []int64
  10011. for _, item := range orderList {
  10012. patientIds = append(patientIds, item.PatientId)
  10013. }
  10014. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  10015. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  10016. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  10017. //药品管理信息
  10018. _, drugStockConfig := service.FindHisConfig(orgId)
  10019. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  10020. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  10021. c.ServeSuccessJSON(map[string]interface{}{
  10022. "adviceList": adviceList,
  10023. "hisAdviceList": hisAdviceList,
  10024. "projectList": projectList,
  10025. "drugStockConfig": drugStockConfig,
  10026. "patientList": patientList,
  10027. "projectConfig": projectConfig,
  10028. })
  10029. }
  10030. func (c *DialysisAPIController) GetLastAcceptRecrods() {
  10031. patient_id, _ := c.GetInt64("patient_id")
  10032. org_id := c.GetMobileAdminUserInfo().Org.Id
  10033. recrods, _ := service.GetLastAcceptRecrods(patient_id, org_id)
  10034. c.ServeSuccessJSON(map[string]interface{}{
  10035. "recrods": recrods,
  10036. })
  10037. }
  10038. func (c *DialysisAPIController) ExMobileChangeSch() {
  10039. id_one, _ := c.GetInt64("id_one")
  10040. id_two, _ := c.GetInt64("id_two")
  10041. sch, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10042. sch_two, _ := service.GetSchedule(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10043. //order2, _ := service.GetDialysisOrder(sch_two.ScheduleDate, sch_two.PatientId, sch_two.UserOrgId)
  10044. //if order2.ID > 0 {
  10045. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientDialysisOrderTwo)
  10046. // return
  10047. //}
  10048. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10049. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10050. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10051. if count > 0 {
  10052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10053. return
  10054. }
  10055. count1, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch.ScheduleDate, sch_two.PatientId)
  10056. if count1 > 0 {
  10057. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10058. return
  10059. }
  10060. }
  10061. err := service.UpdateScheduleThree(sch, sch_two)
  10062. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10063. if order.ID > 0 {
  10064. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10065. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10066. redis := service.RedisClient()
  10067. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10068. redis.Set(key, "", time.Second)
  10069. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10070. //清空key 值
  10071. redis.Set(keyOne, "", time.Second)
  10072. }
  10073. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10074. if orderOne.ID > 0 {
  10075. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10076. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10077. redis := service.RedisClient()
  10078. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10079. redis.Set(key, "", time.Second)
  10080. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10081. //清空key 值
  10082. redis.Set(keyOne, "", time.Second)
  10083. }
  10084. if err == nil {
  10085. //去除当天患者排班中重复数据,保留最后一条数据
  10086. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10087. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10088. c.ServeSuccessJSON(map[string]interface{}{
  10089. "msg": "交换成功",
  10090. })
  10091. } else {
  10092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10093. return
  10094. }
  10095. }
  10096. func (c *DialysisAPIController) MobileCoverSch() {
  10097. id_one, _ := c.GetInt64("id_one")
  10098. id_two, _ := c.GetInt64("id_two")
  10099. sch, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_one)
  10100. //针对凤凰医院
  10101. if c.GetMobileAdminUserInfo().Org.Id == 10579 || c.GetMobileAdminUserInfo().Org.Id == 10344 || c.GetMobileAdminUserInfo().Org.Id == 10206 {
  10102. advice, _ := service.GetDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10103. if len(advice) > 0 {
  10104. service.UpdateAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10105. }
  10106. }
  10107. if c.GetMobileAdminUserInfo().Org.Id == 10206 || c.GetMobileAdminUserInfo().Org.Id == 10344 {
  10108. hisAdvice, _ := service.GetHisDoctorAdviceListTwenty(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10109. project, _ := service.GetHisPrescriptionProjectList(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10110. if len(hisAdvice) > 0 {
  10111. service.UpdateHisAdviceObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10112. }
  10113. if len(project) > 0 {
  10114. service.UpdateProjectObj(sch.PatientId, sch.ScheduleDate, c.GetMobileAdminUserInfo().Org.Id)
  10115. }
  10116. }
  10117. sch_two, _ := service.GetScheduleTen(c.GetMobileAdminUserInfo().Org.Id, id_two)
  10118. //替换者和被替换的排班日期不是同一天,则进行一个患者一天不能有多个排班提醒
  10119. if sch.ScheduleDate != sch_two.ScheduleDate && sch.PatientId != sch_two.PatientId {
  10120. count, _ := service.GetScheduleCountByDate(c.GetMobileAdminUserInfo().Org.Id, sch_two.ScheduleDate, sch.PatientId)
  10121. if count > 0 {
  10122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientScheduleRepeat)
  10123. return
  10124. }
  10125. }
  10126. var new_sch models.Schedule
  10127. new_sch = sch
  10128. new_sch.BedId = sch_two.BedId
  10129. new_sch.ScheduleDate = sch_two.ScheduleDate
  10130. new_sch.ScheduleWeek = sch_two.ScheduleWeek
  10131. new_sch.PartitionId = sch_two.PartitionId
  10132. new_sch.ScheduleType = sch_two.ScheduleType
  10133. new_sch.ID = 0
  10134. //删除原来的排班
  10135. err := service.SaveSchTwo(sch, sch_two)
  10136. //生成新的排班
  10137. if err == nil {
  10138. err2 := service.SaveSch(&new_sch)
  10139. order, _ := service.GetOneDialysisOrderOne(sch.UserOrgId, sch.ScheduleDate, sch.PatientId)
  10140. if order.ID > 0 {
  10141. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch.PatientId, sch.UserOrgId, sch.ScheduleDate)
  10142. service.UpdateDialysiOrderByPatientId(order.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10143. redis := service.RedisClient()
  10144. key := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.PatientId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_order"
  10145. redis.Set(key, "", time.Second)
  10146. keyOne := strconv.FormatInt(sch.UserOrgId, 10) + ":" + strconv.FormatInt(sch.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10147. //清空key 值
  10148. redis.Set(keyOne, "", time.Second)
  10149. }
  10150. orderOne, _ := service.GetOneDialysisOrderOne(sch_two.UserOrgId, sch_two.ScheduleDate, sch_two.PatientId)
  10151. if orderOne.ID > 0 {
  10152. scheduleObj, _ := service.GetPatientScheduleByPatientId(sch_two.PatientId, sch_two.UserOrgId, sch_two.ScheduleDate)
  10153. service.UpdateDialysiOrderByPatientId(orderOne.ID, scheduleObj.ScheduleType, scheduleObj.PartitionId, scheduleObj.BedId)
  10154. redis := service.RedisClient()
  10155. key := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.PatientId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_order"
  10156. redis.Set(key, "", time.Second)
  10157. keyOne := strconv.FormatInt(sch_two.UserOrgId, 10) + ":" + strconv.FormatInt(sch_two.ScheduleDate, 10) + ":dialysis_orders_list_all"
  10158. //清空key 值
  10159. redis.Set(keyOne, "", time.Second)
  10160. }
  10161. if err2 == nil {
  10162. //去除当天患者排班中重复数据,保留最后一条数据
  10163. service.UpdateRepeatSchStatus(sch.UserOrgId, sch.ScheduleDate)
  10164. service.UpdateRepeatSchStatus(sch_two.UserOrgId, sch_two.ScheduleDate)
  10165. service.UpdateRepeatSchStatus(new_sch.UserOrgId, new_sch.ScheduleDate)
  10166. c.ServeSuccessJSON(map[string]interface{}{
  10167. "msg": "覆盖成功",
  10168. "new_sch": new_sch,
  10169. })
  10170. } else {
  10171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10172. return
  10173. }
  10174. } else {
  10175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10176. return
  10177. }
  10178. }
  10179. func (c *DialysisAPIController) BatchCheckAdvice() {
  10180. patient_id, _ := c.GetInt64("patient_id")
  10181. advice_date, _ := c.GetInt64("advice_date")
  10182. org_id := c.GetMobileAdminUserInfo().Org.Id
  10183. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  10184. //查询是his系统还是血透系统
  10185. _, configs := service.FindXTHisRecordByOrgId(org_id)
  10186. //his客户
  10187. if configs.IsOpen == 1 {
  10188. adviceList, _ := service.GetAllHisAdviceList(patient_id, advice_date, org_id)
  10189. for _, item := range adviceList {
  10190. service.BatchCheckHisAdvice(item.ID, creater)
  10191. }
  10192. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10193. for _, item := range projectList {
  10194. service.BatchCheckProject(item.ID, creater)
  10195. }
  10196. c.ServeSuccessJSON(map[string]interface{}{
  10197. "adviceList": adviceList,
  10198. "projectList": projectList,
  10199. })
  10200. }
  10201. if configs.IsOpen != 1 {
  10202. adviceList, _ := service.GetAllAdviceList(patient_id, advice_date, org_id)
  10203. for _, item := range adviceList {
  10204. service.BatchAdviceList(item.ID, creater)
  10205. }
  10206. projectList, _ := service.GetMobileProjectList(patient_id, advice_date, org_id)
  10207. for _, item := range projectList {
  10208. service.BatchCheckProject(item.ID, creater)
  10209. }
  10210. c.ServeSuccessJSON(map[string]interface{}{
  10211. "adviceList": adviceList,
  10212. "projectList": projectList,
  10213. })
  10214. }
  10215. return
  10216. }
  10217. func (c *DialysisAPIController) GetAllMobileDrugList() {
  10218. org_id := c.GetMobileAdminUserInfo().Org.Id
  10219. drugList, _ := service.GetAllDrugList(org_id)
  10220. c.ServeSuccessJSON(map[string]interface{}{
  10221. "drugList": drugList,
  10222. })
  10223. }
  10224. func (c *DialysisAPIController) SaveLongMobileAdvice() {
  10225. org_id := c.GetMobileAdminUserInfo().Org.Id
  10226. dataBody := make(map[string]interface{}, 0)
  10227. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10228. if err != nil {
  10229. utils.ErrorLog(err.Error())
  10230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10231. return
  10232. }
  10233. timeLayout := "2006-01-02"
  10234. loc, _ := time.LoadLocation("Local")
  10235. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  10236. utils.ErrorLog("advice_type")
  10237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10238. return
  10239. }
  10240. adviceType := int64(dataBody["advice_type"].(float64))
  10241. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10242. utils.ErrorLog("start_time")
  10243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10244. return
  10245. }
  10246. startTime2, _ := dataBody["start_time"].(string)
  10247. time_arr := strings.Split(startTime2, " ")
  10248. if len(time_arr) > 0 {
  10249. startTime2 = time_arr[0]
  10250. }
  10251. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10252. utils.ErrorLog("advice_date")
  10253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10254. return
  10255. }
  10256. advice_date, _ := dataBody["advice_date"].(string)
  10257. var advicedateunix int64
  10258. if len(advice_date) > 0 {
  10259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10260. if err != nil {
  10261. fmt.Println(err)
  10262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10263. return
  10264. }
  10265. advicedateunix = theTime.Unix()
  10266. }
  10267. adviceDate := startTime2
  10268. if len(adviceDate) == 0 {
  10269. utils.ErrorLog("len(adviceDate) == 0")
  10270. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10271. return
  10272. }
  10273. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10274. if err != nil {
  10275. utils.ErrorLog(err.Error())
  10276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10277. return
  10278. }
  10279. AdviceDate := advicedateunix
  10280. RecordDate := advicedateunix
  10281. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10282. utils.ErrorLog("start_time")
  10283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10284. return
  10285. }
  10286. startTime, _ := dataBody["start_time"].(string)
  10287. if len(startTime) == 0 {
  10288. utils.ErrorLog("len(start_time) == 0")
  10289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10290. return
  10291. }
  10292. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10293. if err != nil {
  10294. utils.ErrorLog(err.Error())
  10295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10296. return
  10297. }
  10298. StartTime := theTime.Unix()
  10299. advice_name, _ := dataBody["advice_name"].(string)
  10300. advice_desc, _ := dataBody["advice_desc"].(string)
  10301. delivery_way, _ := dataBody["delivery_way"].(string)
  10302. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10303. frequency_type := int64(dataBody["frequency_type"].(float64))
  10304. frequency_week, _ := dataBody["frequency_week"].(string)
  10305. prescribing_number := dataBody["prescribing_number"].(float64)
  10306. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10307. remark := dataBody["remark"].(string)
  10308. single_dose := dataBody["single_dose"].(float64)
  10309. single_dose_unit := dataBody["single_dose_unit"].(string)
  10310. patient_id := int64(dataBody["patient_id"].(float64))
  10311. day_count := int64(dataBody["day_count"].(float64))
  10312. groupNo := int64(dataBody["group_no"].(float64))
  10313. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10314. adviceLast, _ := service.GetLastLongAdviceList(org_id)
  10315. if groupNo <= 0 {
  10316. group := service.GetMaxAdviceGroupID(org_id)
  10317. groupNo = group + 1
  10318. }
  10319. var template_id = ""
  10320. adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
  10321. template_id = "M" + adviceLastId
  10322. advice := models.DoctorAdvice{
  10323. UserOrgId: org_id,
  10324. PatientId: patient_id,
  10325. AdviceType: adviceType,
  10326. AdviceDate: AdviceDate,
  10327. StartTime: StartTime,
  10328. AdviceName: advice_name,
  10329. AdviceDesc: advice_desc,
  10330. ReminderDate: 0,
  10331. SingleDose: single_dose,
  10332. SingleDoseUnit: single_dose_unit,
  10333. DrugSpec: 0,
  10334. DrugSpecUnit: "",
  10335. PrescribingNumber: prescribing_number,
  10336. PrescribingNumberUnit: prescribing_number_unit,
  10337. DeliveryWay: delivery_way,
  10338. ExecutionFrequency: execution_frequency,
  10339. AdviceDoctor: advice_doctor,
  10340. Status: 1,
  10341. CreatedTime: time.Now().Unix(),
  10342. UpdatedTime: 0,
  10343. AdviceAffirm: "",
  10344. Remark: remark,
  10345. StopTime: 0,
  10346. StopReason: "",
  10347. StopDoctor: 0,
  10348. StopState: 0,
  10349. ParentId: 0,
  10350. ExecutionTime: 0,
  10351. ExecutionStaff: 0,
  10352. ExecutionState: 0,
  10353. Checker: 0,
  10354. RecordDate: RecordDate,
  10355. DialysisOrderId: 0,
  10356. CheckTime: 0,
  10357. CheckState: 0,
  10358. AdviceId: 0,
  10359. RemindType: 0,
  10360. FrequencyType: frequency_type,
  10361. DayCount: day_count,
  10362. WeekDay: frequency_week,
  10363. ChildDoctorAdvice: nil,
  10364. TemplateId: template_id,
  10365. Modifier: 0,
  10366. IsCheck: 0,
  10367. Way: 0,
  10368. DrugId: 0,
  10369. DrugNameId: 0,
  10370. IsMedicine: 0,
  10371. PushStartTime: 0,
  10372. IsSettle: 0,
  10373. IsPrescription: 0,
  10374. GroupNo: groupNo,
  10375. }
  10376. service.CreateMobileAdivce(advice)
  10377. c.ServeSuccessJSON(map[string]interface{}{
  10378. "msg": "保存成功!",
  10379. })
  10380. }
  10381. func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
  10382. patient_id, _ := c.GetInt64("patient_id")
  10383. org_id := c.GetMobileAdminUserInfo().Org.Id
  10384. app_id := c.GetMobileAdminUserInfo().App.Id
  10385. adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
  10386. adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
  10387. c.ServeSuccessJSON(map[string]interface{}{
  10388. "adviceList": adviceList,
  10389. "adminRoles": adminRoles,
  10390. })
  10391. }
  10392. func (c *DialysisAPIController) SaveSelfChildDrugLongAdivce() {
  10393. org_id := c.GetMobileAdminUserInfo().Org.Id
  10394. dataBody := make(map[string]interface{}, 0)
  10395. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10396. if err != nil {
  10397. utils.ErrorLog(err.Error())
  10398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10399. return
  10400. }
  10401. timeLayout := "2006-01-02"
  10402. loc, _ := time.LoadLocation("Local")
  10403. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10404. utils.ErrorLog("start_time")
  10405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10406. return
  10407. }
  10408. startTime2, _ := dataBody["start_time"].(string)
  10409. time_arr := strings.Split(startTime2, " ")
  10410. if len(time_arr) > 0 {
  10411. startTime2 = time_arr[0]
  10412. }
  10413. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10414. utils.ErrorLog("advice_date")
  10415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10416. return
  10417. }
  10418. advice_date, _ := dataBody["advice_date"].(string)
  10419. var advicedateunix int64
  10420. if len(advice_date) > 0 {
  10421. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10422. if err != nil {
  10423. fmt.Println(err)
  10424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10425. return
  10426. }
  10427. advicedateunix = theTime.Unix()
  10428. }
  10429. adviceDate := startTime2
  10430. if len(adviceDate) == 0 {
  10431. utils.ErrorLog("len(adviceDate) == 0")
  10432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10433. return
  10434. }
  10435. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10436. if err != nil {
  10437. utils.ErrorLog(err.Error())
  10438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10439. return
  10440. }
  10441. AdviceDate := advicedateunix
  10442. RecordDate := advicedateunix
  10443. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10444. utils.ErrorLog("start_time")
  10445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10446. return
  10447. }
  10448. startTime, _ := dataBody["start_time"].(string)
  10449. if len(startTime) == 0 {
  10450. utils.ErrorLog("len(start_time) == 0")
  10451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10452. return
  10453. }
  10454. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10455. if err != nil {
  10456. utils.ErrorLog(err.Error())
  10457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10458. return
  10459. }
  10460. StartTime := theTime.Unix()
  10461. advice_name, _ := dataBody["advice_name"].(string)
  10462. advice_desc, _ := dataBody["advice_desc"].(string)
  10463. delivery_way, _ := dataBody["delivery_way"].(string)
  10464. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10465. prescribing_number := dataBody["prescribing_number"].(float64)
  10466. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10467. remark := dataBody["remark"].(string)
  10468. single_dose := dataBody["single_dose"].(float64)
  10469. single_dose_unit := dataBody["single_dose_unit"].(string)
  10470. patient_id := int64(dataBody["patient_id"].(float64))
  10471. groupNo := int64(dataBody["group_no"].(float64))
  10472. parent_id := int64(dataBody["parent_id"].(float64))
  10473. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10474. advice := models.XtDoctorAdviceOne{
  10475. UserOrgId: org_id,
  10476. PatientId: patient_id,
  10477. AdviceType: 1,
  10478. AdviceDate: AdviceDate,
  10479. StartTime: StartTime,
  10480. AdviceName: advice_name,
  10481. AdviceDesc: advice_desc,
  10482. ReminderDate: 0,
  10483. SingleDose: single_dose,
  10484. SingleDoseUnit: single_dose_unit,
  10485. PrescribingNumber: prescribing_number,
  10486. PrescribingNumberUnit: prescribing_number_unit,
  10487. DeliveryWay: delivery_way,
  10488. ExecutionFrequency: execution_frequency,
  10489. AdviceDoctor: advice_doctor,
  10490. Status: 1,
  10491. CreatedTime: time.Now().Unix(),
  10492. UpdatedTime: time.Now().Unix(),
  10493. AdviceAffirm: "",
  10494. Remark: remark,
  10495. StopTime: 0,
  10496. StopReason: "",
  10497. StopDoctor: 0,
  10498. StopState: 2,
  10499. ParentId: parent_id,
  10500. ExecutionTime: 0,
  10501. ExecutionStaff: 0,
  10502. ExecutionState: 0,
  10503. Checker: 0,
  10504. RecordDate: RecordDate,
  10505. DialysisOrderId: 0,
  10506. CheckTime: 0,
  10507. CheckState: 0,
  10508. DrugSpec: 0,
  10509. DrugSpecUnit: "",
  10510. Groupno: groupNo,
  10511. RemindType: 0,
  10512. FrequencyType: 0,
  10513. DayCount: 0,
  10514. WeekDay: "",
  10515. TemplateId: "",
  10516. Modifier: 0,
  10517. }
  10518. service.CreateMobileAdivceOne(advice)
  10519. c.ServeSuccessJSON(map[string]interface{}{
  10520. "msg": "保存成功!",
  10521. })
  10522. }
  10523. func (c *DialysisAPIController) DeleteSelfAdviceSubAdvice() {
  10524. id, _ := c.GetInt64("id")
  10525. service.DeleteSelfAdviceSubAdvice(id)
  10526. c.ServeSuccessJSON(map[string]interface{}{
  10527. "msg": "保存成功!",
  10528. })
  10529. }
  10530. func (c *DialysisAPIController) GetEditAdviceAction() {
  10531. id, _ := c.GetInt64("id")
  10532. org_id := c.GetMobileAdminUserInfo().Org.Id
  10533. advice, _ := service.GetEditAdviceActionList(id, org_id)
  10534. drugList, _ := service.GetAllDrugList(org_id)
  10535. c.ServeSuccessJSON(map[string]interface{}{
  10536. "advice": advice,
  10537. "drugList": drugList,
  10538. })
  10539. }
  10540. func (c *DialysisAPIController) UpdateLongMobileAdvice() {
  10541. dataBody := make(map[string]interface{}, 0)
  10542. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10543. if err != nil {
  10544. utils.ErrorLog(err.Error())
  10545. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10546. return
  10547. }
  10548. timeLayout := "2006-01-02"
  10549. loc, _ := time.LoadLocation("Local")
  10550. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10551. utils.ErrorLog("start_time")
  10552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10553. return
  10554. }
  10555. startTime2, _ := dataBody["start_time"].(string)
  10556. time_arr := strings.Split(startTime2, " ")
  10557. if len(time_arr) > 0 {
  10558. startTime2 = time_arr[0]
  10559. }
  10560. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10561. utils.ErrorLog("advice_date")
  10562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10563. return
  10564. }
  10565. advice_date, _ := dataBody["advice_date"].(string)
  10566. var advicedateunix int64
  10567. if len(advice_date) > 0 {
  10568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10569. if err != nil {
  10570. fmt.Println(err)
  10571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10572. return
  10573. }
  10574. advicedateunix = theTime.Unix()
  10575. }
  10576. adviceDate := startTime2
  10577. if len(adviceDate) == 0 {
  10578. utils.ErrorLog("len(adviceDate) == 0")
  10579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10580. return
  10581. }
  10582. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10583. if err != nil {
  10584. utils.ErrorLog(err.Error())
  10585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10586. return
  10587. }
  10588. AdviceDate := advicedateunix
  10589. RecordDate := advicedateunix
  10590. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10591. utils.ErrorLog("start_time")
  10592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10593. return
  10594. }
  10595. startTime, _ := dataBody["start_time"].(string)
  10596. if len(startTime) == 0 {
  10597. utils.ErrorLog("len(start_time) == 0")
  10598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10599. return
  10600. }
  10601. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10602. if err != nil {
  10603. utils.ErrorLog(err.Error())
  10604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10605. return
  10606. }
  10607. StartTime := theTime.Unix()
  10608. advice_name, _ := dataBody["advice_name"].(string)
  10609. advice_desc, _ := dataBody["advice_desc"].(string)
  10610. delivery_way, _ := dataBody["delivery_way"].(string)
  10611. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10612. prescribing_number := dataBody["prescribing_number"].(float64)
  10613. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10614. remark := dataBody["remark"].(string)
  10615. single_dose := dataBody["single_dose"].(float64)
  10616. single_dose_unit := dataBody["single_dose_unit"].(string)
  10617. id := int64(dataBody["id"].(float64))
  10618. frequency_type := int64(dataBody["frequency_type"].(float64))
  10619. frequency_week, _ := dataBody["frequency_week"].(string)
  10620. day_count := int64(dataBody["day_count"].(float64))
  10621. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10622. advice := models.XtDoctorAdviceOne{
  10623. AdviceDate: AdviceDate,
  10624. StartTime: StartTime,
  10625. AdviceName: advice_name,
  10626. AdviceDesc: advice_desc,
  10627. SingleDose: single_dose,
  10628. SingleDoseUnit: single_dose_unit,
  10629. PrescribingNumber: prescribing_number,
  10630. PrescribingNumberUnit: prescribing_number_unit,
  10631. DeliveryWay: delivery_way,
  10632. ExecutionFrequency: execution_frequency,
  10633. AdviceDoctor: advice_doctor,
  10634. Remark: remark,
  10635. RecordDate: RecordDate,
  10636. FrequencyType: frequency_type,
  10637. DayCount: day_count,
  10638. WeekDay: frequency_week,
  10639. }
  10640. service.UpdateMobileDoctorAdviceByIdOne(id, advice)
  10641. c.ServeSuccessJSON(map[string]interface{}{
  10642. "advice": advice,
  10643. })
  10644. }
  10645. func (c *DialysisAPIController) UpdateEditDrugOrder() {
  10646. dataBody := make(map[string]interface{}, 0)
  10647. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10648. if err != nil {
  10649. utils.ErrorLog(err.Error())
  10650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10651. return
  10652. }
  10653. timeLayout := "2006-01-02"
  10654. loc, _ := time.LoadLocation("Local")
  10655. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10656. utils.ErrorLog("start_time")
  10657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10658. return
  10659. }
  10660. startTime2, _ := dataBody["start_time"].(string)
  10661. time_arr := strings.Split(startTime2, " ")
  10662. if len(time_arr) > 0 {
  10663. startTime2 = time_arr[0]
  10664. }
  10665. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10666. utils.ErrorLog("advice_date")
  10667. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10668. return
  10669. }
  10670. advice_date, _ := dataBody["advice_date"].(string)
  10671. var advicedateunix int64
  10672. if len(advice_date) > 0 {
  10673. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10674. if err != nil {
  10675. fmt.Println(err)
  10676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10677. return
  10678. }
  10679. advicedateunix = theTime.Unix()
  10680. }
  10681. adviceDate := startTime2
  10682. if len(adviceDate) == 0 {
  10683. utils.ErrorLog("len(adviceDate) == 0")
  10684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10685. return
  10686. }
  10687. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10688. if err != nil {
  10689. utils.ErrorLog(err.Error())
  10690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10691. return
  10692. }
  10693. AdviceDate := advicedateunix
  10694. RecordDate := advicedateunix
  10695. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10696. utils.ErrorLog("start_time")
  10697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10698. return
  10699. }
  10700. startTime, _ := dataBody["start_time"].(string)
  10701. if len(startTime) == 0 {
  10702. utils.ErrorLog("len(start_time) == 0")
  10703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10704. return
  10705. }
  10706. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10707. if err != nil {
  10708. utils.ErrorLog(err.Error())
  10709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10710. return
  10711. }
  10712. StartTime := theTime.Unix()
  10713. advice_name, _ := dataBody["advice_name"].(string)
  10714. advice_desc, _ := dataBody["advice_desc"].(string)
  10715. delivery_way, _ := dataBody["delivery_way"].(string)
  10716. execution_frequency, _ := dataBody["execution_frequency"].(string)
  10717. prescribing_number := dataBody["prescribing_number"].(float64)
  10718. prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
  10719. remark := dataBody["remark"].(string)
  10720. single_dose := dataBody["single_dose"].(float64)
  10721. single_dose_unit := dataBody["single_dose_unit"].(string)
  10722. id := int64(dataBody["id"].(float64))
  10723. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10724. advice := models.XtDoctorAdviceOne{
  10725. AdviceDate: AdviceDate,
  10726. StartTime: StartTime,
  10727. AdviceName: advice_name,
  10728. AdviceDesc: advice_desc,
  10729. SingleDose: single_dose,
  10730. SingleDoseUnit: single_dose_unit,
  10731. PrescribingNumber: prescribing_number,
  10732. PrescribingNumberUnit: prescribing_number_unit,
  10733. DeliveryWay: delivery_way,
  10734. ExecutionFrequency: execution_frequency,
  10735. AdviceDoctor: advice_doctor,
  10736. Remark: remark,
  10737. RecordDate: RecordDate,
  10738. }
  10739. service.UpdateMobileDoctorAdviceById(id, advice)
  10740. c.ServeSuccessJSON(map[string]interface{}{
  10741. "advice": advice,
  10742. })
  10743. }
  10744. func (c *DialysisAPIController) SaveLongAdviceTemplate() {
  10745. dataBody := make(map[string]interface{}, 0)
  10746. timeLayout := "2006-01-02"
  10747. loc, _ := time.LoadLocation("Local")
  10748. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10749. if err != nil {
  10750. utils.ErrorLog(err.Error())
  10751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10752. return
  10753. }
  10754. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10755. utils.ErrorLog("start_time")
  10756. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10757. return
  10758. }
  10759. startTime2, _ := dataBody["start_time"].(string)
  10760. time_arr := strings.Split(startTime2, " ")
  10761. if len(time_arr) > 0 {
  10762. startTime2 = time_arr[0]
  10763. }
  10764. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  10765. utils.ErrorLog("advice_date")
  10766. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10767. return
  10768. }
  10769. advice_date, _ := dataBody["advice_date"].(string)
  10770. var advicedateunix int64
  10771. if len(advice_date) > 0 {
  10772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
  10773. if err != nil {
  10774. fmt.Println(err)
  10775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10776. return
  10777. }
  10778. advicedateunix = theTime.Unix()
  10779. }
  10780. adviceDate := startTime2
  10781. if len(adviceDate) == 0 {
  10782. utils.ErrorLog("len(adviceDate) == 0")
  10783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10784. return
  10785. }
  10786. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  10787. if err != nil {
  10788. utils.ErrorLog(err.Error())
  10789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10790. return
  10791. }
  10792. RecordDate := advicedateunix
  10793. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  10794. utils.ErrorLog("start_time")
  10795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10796. return
  10797. }
  10798. startTime, _ := dataBody["start_time"].(string)
  10799. if len(startTime) == 0 {
  10800. utils.ErrorLog("len(start_time) == 0")
  10801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10802. return
  10803. }
  10804. theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
  10805. if err != nil {
  10806. utils.ErrorLog(err.Error())
  10807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10808. return
  10809. }
  10810. StartTime := theTime.Unix()
  10811. patient_id := int64(dataBody["patient_id"].(float64))
  10812. group_no := int64(dataBody["group_no"].(float64))
  10813. org_id := c.GetMobileAdminUserInfo().Org.Id
  10814. advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
  10815. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  10816. utils.ErrorLog("advices")
  10817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10818. return
  10819. }
  10820. adviceNames := dataBody["advices"].([]interface{})
  10821. var advices []*models.GroupAdvice
  10822. for _, adviceNameMap := range adviceNames {
  10823. var advice models.GroupAdvice
  10824. adviceNameM := adviceNameMap.(map[string]interface{})
  10825. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  10826. utils.ErrorLog("advice_name")
  10827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10828. return
  10829. }
  10830. adviceName, _ := adviceNameM["advice_name"].(string)
  10831. if len(adviceName) == 0 {
  10832. utils.ErrorLog("len(advice_name) == 0")
  10833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10834. return
  10835. }
  10836. advice.AdviceName = adviceName
  10837. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  10838. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  10839. advice.DrugSpec = drugSpec
  10840. }
  10841. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  10842. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  10843. advice.AdviceDesc = adviceDesc
  10844. }
  10845. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  10846. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  10847. advice.DrugSpecUnit = drugSpecUnit
  10848. }
  10849. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  10850. singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  10851. advice.SingleDose = singleDose
  10852. }
  10853. if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  10854. singleDose := adviceNameM["single_dose"].(float64)
  10855. advice.SingleDose = singleDose
  10856. }
  10857. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  10858. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  10859. advice.SingleDoseUnit = singleDoseUnit
  10860. }
  10861. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "float64" {
  10862. tmp := adviceNameM["single_dose_unit"].(float64)
  10863. singleDoseUnit := service.TypeConversion(tmp)
  10864. advice.SingleDoseUnit = singleDoseUnit
  10865. }
  10866. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  10867. prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  10868. advice.PrescribingNumber = prescribingNumber
  10869. }
  10870. if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  10871. prescribingNumber := adviceNameM["prescribing_number"].(float64)
  10872. advice.PrescribingNumber = prescribingNumber
  10873. }
  10874. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  10875. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  10876. advice.PrescribingNumberUnit = prescribingNumberUnit
  10877. }
  10878. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  10879. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  10880. advice.DeliveryWay = deliveryWay
  10881. }
  10882. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  10883. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  10884. advice.ExecutionFrequency = executionFrequency
  10885. }
  10886. remark, _ := adviceNameM["remark"].(string)
  10887. advice.Remark = remark
  10888. advice.AdviceType = 1
  10889. advice.StartTime = StartTime
  10890. advice.RecordDate = RecordDate
  10891. advice.PatientId = patient_id
  10892. advice.UserOrgId = org_id
  10893. advice.AdviceDoctor = advice_doctor
  10894. advice.StopState = 2
  10895. advices = append(advices, &advice)
  10896. }
  10897. newAdvices, _ := service.CreateMobileMGroupAdvice(org_id, advices, group_no)
  10898. c.ServeSuccessJSON(map[string]interface{}{
  10899. "advice": newAdvices,
  10900. })
  10901. }
  10902. func (c *DialysisAPIController) StopLongAdvice() {
  10903. stop_time := c.GetString("execution_time")
  10904. id, _ := c.GetInt64("id")
  10905. if len(stop_time) <= 0 {
  10906. utils.ErrorLog("stop_time")
  10907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10908. return
  10909. }
  10910. timeLayout2 := "2006-01-02 15:04:05"
  10911. loc, _ := time.LoadLocation("Local")
  10912. theTime, errs := time.ParseInLocation(timeLayout2, stop_time, loc)
  10913. if errs != nil {
  10914. utils.ErrorLog(errs.Error())
  10915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10916. return
  10917. }
  10918. advice, _ := service.StopLongAdvice(id, theTime.Unix())
  10919. c.ServeSuccessJSON(map[string]interface{}{
  10920. "advice": advice,
  10921. })
  10922. }