dialysis_api_controller.go 375KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "errors"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "math"
  13. "net/http"
  14. "net/url"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // type DialysisTestAPIController struct {
  21. // MobileBaseAPIController
  22. // }
  23. // [get]/m/api/test
  24. // func (this *DialysisTestAPIController) Test() {
  25. // orgID := int64(3907)
  26. // now := time.Now()
  27. // nextWeek := now.AddDate(0, 0, 7)
  28. // nextWeekMon, nextWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextWeek)
  29. // nextTwoWeek := now.AddDate(0, 0, 14)
  30. // nextTwoWeekMon, nextTwoWeekSun := utils.GetMondayAndSundayOfWeekDate(&nextTwoWeek)
  31. // nextWeekSchs, getNextWeekSchErr := service.GetWeekSchedule(orgID, nextWeekMon.Unix(), nextWeekSun.Unix())
  32. // nextTwoWeekSchs, getNextTwoWeekSchErr := service.GetWeekSchedule(orgID, nextTwoWeekMon.Unix(), nextTwoWeekSun.Unix())
  33. // if getNextWeekSchErr != nil || getNextTwoWeekSchErr != nil {
  34. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  35. // return
  36. // }
  37. // exchangeErr := service.ExchangeScheduleTimeWithWeekSchedules(orgID, nextWeekSchs, nextTwoWeekSchs)
  38. // if exchangeErr != nil {
  39. // this.ErrorLog("%v", exchangeErr)
  40. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  41. // return
  42. // }
  43. // this.ServeSuccessJSON(map[string]interface{}{
  44. // // "now": now,
  45. // // "next_week": nextWeek,f
  46. // // "next_week_mon": nextWeekMon,
  47. // // "next_week_sun": nextWeekSun,
  48. // // "next_two_week_mon": nextTwoWeekMon,
  49. // // "next_two_week_sun": nextTwoWeekSun,
  50. // "next_week_schs": nextWeekSchs,
  51. // "next_two_week_schs": nextTwoWeekSchs,
  52. // })
  53. // }
  54. type DialysisAPIController struct {
  55. MobileBaseAPIAuthController
  56. }
  57. // /m/api/scheduals [get]
  58. // @param type:int
  59. // @param date:string
  60. func (this *DialysisAPIController) Scheduals() {
  61. schedualType, _ := this.GetInt64("type")
  62. schedualDate := this.GetString("date")
  63. if schedualType != 0 && schedualType != 1 && schedualType != 2 && schedualType != 3 {
  64. schedualType = 0
  65. }
  66. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  67. if parseDateErr != nil {
  68. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  69. return
  70. }
  71. adminInfo := this.GetMobileAdminUserInfo()
  72. orgID := adminInfo.Org.Id
  73. redis := service.RedisClient()
  74. defer redis.Close()
  75. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  76. //redis.Set(key, "", time.Second)
  77. scheduals_json_str, _ := redis.Get(key).Result()
  78. patients, _ := service.GetAllPatientListSix(orgID)
  79. if len(scheduals_json_str) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  80. scheduals, err := service.MobileGetDialysisScheduals(orgID, date.Unix(), schedualType)
  81. for _, item := range scheduals {
  82. order, _ := service.GetMonitDialysisOrder(item.UserOrgId, item.PatientId, date.Unix())
  83. item.DialysisLastOrder = order
  84. solution, _ := service.GetMonitDialysisSolution(item.UserOrgId, item.PatientId, item.ModeId)
  85. item.DialysisSolution = solution
  86. }
  87. if err != nil {
  88. this.ErrorLog("获取排班信息失败:%v", err)
  89. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  90. } else {
  91. if len(scheduals) > 0 {
  92. devices, _ := service.GetAllDevicetByListSix(orgID)
  93. advices, _ := service.GetAllAdvicestByList(orgID, date.Unix())
  94. prescriptions, _ := service.GetAllPrescriptionsByList(orgID, date.Unix())
  95. assessmentBefores, _ := service.GetAllAssessmentBeforesByList(orgID, date.Unix())
  96. dialysisOrders, _ := service.GetAllDialysisOrdersByList(orgID, date.Unix())
  97. treatmentSummarys, _ := service.GetAllTreatmentSummarysByList(orgID, date.Unix())
  98. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByList(orgID, date.Unix())
  99. dobulecheck, _ := service.GetAllDobuleCheckList(orgID, date.Unix())
  100. hisAdvices, _ := service.GetAllHisAdvicesByList(orgID, date.Unix())
  101. inforMation, _ := service.GetTodayInforMation(orgID, date.Unix())
  102. //monitor, _ := service.GetMonitorByListSix(orgID, date.Unix())
  103. for key, item := range scheduals {
  104. for _, infor := range inforMation {
  105. if item.PatientId == infor.PatientId && item.BedId == infor.BedNumber {
  106. scheduals[key].NewDeviceInformation = infor
  107. break
  108. }
  109. }
  110. // 获取患者信息
  111. for _, patient := range patients {
  112. if item.PatientId == patient.ID {
  113. scheduals[key].SchedualPatient = patient
  114. break
  115. }
  116. }
  117. // 床位信息
  118. for _, device := range devices {
  119. if item.BedId == device.ID {
  120. scheduals[key].DeviceNumber = device
  121. break
  122. }
  123. }
  124. // 医嘱信息
  125. scheduals[key].Advices = make([]models.VMDoctorAdviceForList, 0)
  126. for _, advice := range advices {
  127. if item.PatientId == advice.PatientId {
  128. scheduals[key].Advices = append(scheduals[key].Advices, advice)
  129. }
  130. }
  131. // 医嘱信息
  132. scheduals[key].HisAdvices = make([]service.VMHisDoctorAdviceInfo, 0)
  133. for _, hisAdvice := range hisAdvices {
  134. if item.PatientId == hisAdvice.PatientId {
  135. scheduals[key].HisAdvices = append(scheduals[key].HisAdvices, hisAdvice)
  136. }
  137. }
  138. // 医嘱信息
  139. for _, prescription := range prescriptions {
  140. if item.PatientId == prescription.PatientId {
  141. scheduals[key].Prescription = prescription
  142. break
  143. }
  144. }
  145. // 透前评估
  146. for _, assessmentBefore := range assessmentBefores {
  147. if item.PatientId == assessmentBefore.PatientId {
  148. scheduals[key].AssessmentBeforeDislysis = assessmentBefore
  149. break
  150. }
  151. }
  152. // 透析上下机
  153. for _, dialysisOrder := range dialysisOrders {
  154. if item.PatientId == dialysisOrder.PatientId {
  155. scheduals[key].DialysisOrder = dialysisOrder
  156. break
  157. }
  158. }
  159. // 治疗小节
  160. for _, afterDislysis := range AssessmentAfterDislysis {
  161. if item.PatientId == afterDislysis.PatientId {
  162. scheduals[key].AssessmentAfterDislysis = afterDislysis
  163. break
  164. }
  165. }
  166. // 透后评估
  167. for _, treatmentSummary := range treatmentSummarys {
  168. if item.PatientId == treatmentSummary.PatientId {
  169. scheduals[key].TreatmentSummary = treatmentSummary
  170. break
  171. }
  172. }
  173. for _, check := range dobulecheck {
  174. if item.PatientId == check.PatientId {
  175. scheduals[key].DoubleCheck = check
  176. break
  177. }
  178. }
  179. //// 监测
  180. //scheduals[key].VMMonitoringRecord = make([]models.VMMonitoringRecord, 0)
  181. //for _, moni := range monitor {
  182. // if item.PatientId == moni.PatientId {
  183. // scheduals[key].VMMonitoringRecord = append(scheduals[key].VMMonitoringRecord, moni)
  184. // }
  185. //}
  186. }
  187. //缓存数据
  188. scheduals_json, err := json.Marshal(&scheduals)
  189. if err == nil {
  190. redis.Set(key, scheduals_json, time.Second*60)
  191. }
  192. }
  193. //获取今日所有的处方开的耗材
  194. _, configs := service.FindXTHisProjectByOrgId(orgID)
  195. project := make([]*models.HisPrescriptionProjectTwo, 0)
  196. if configs.ID > 0 && configs.IsOpen == 1 {
  197. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  198. }
  199. //list, _ := service.GetZoneCountList(orgID, date.Unix())
  200. this.ServeSuccessJSON(map[string]interface{}{
  201. "scheduals": scheduals,
  202. "project": project,
  203. })
  204. }
  205. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  206. var dat []map[string]interface{}
  207. if err := json.Unmarshal([]byte(scheduals_json_str), &dat); err == nil {
  208. } else {
  209. }
  210. //获取今日所有的处方开的耗材
  211. _, configs := service.FindXTHisProjectByOrgId(orgID)
  212. project := make([]*models.HisPrescriptionProjectTwo, 0)
  213. if configs.ID > 0 && configs.IsOpen == 1 {
  214. project, _ = service.GetAllHisProjectPrescription(orgID, date.Unix())
  215. }
  216. this.ServeSuccessJSON(map[string]interface{}{
  217. "scheduals": dat,
  218. "redis": "true",
  219. "date": schedualDate,
  220. "project": project,
  221. })
  222. }
  223. }
  224. // /m/api/waiting_scheduals [get]
  225. // @param date:string
  226. func (this *DialysisAPIController) WaitingScheduals() {
  227. schedualDate := this.GetString("date")
  228. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  229. if parseDateErr != nil && len(schedualDate) != 0 {
  230. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  231. return
  232. }
  233. adminInfo := this.GetMobileAdminUserInfo()
  234. orgID := adminInfo.Org.Id
  235. redis := service.RedisClient()
  236. defer redis.Close()
  237. // cur_date := time.Now().Format("2006-01-02")
  238. key := "wait_scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  239. wait_scheduals, _ := redis.Get(key).Result()
  240. if len(wait_scheduals) == 0 { //没有到缓存数据,从数据库中获取数据,进行缓存到redis
  241. scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  242. if err != nil {
  243. this.ErrorLog("获取排班信息失败:%v", err)
  244. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. } else {
  246. returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  247. for _, s := range scheduals {
  248. returnScheduals = append(returnScheduals, s)
  249. }
  250. if len(returnScheduals) > 0 {
  251. //缓存数据
  252. wait_scheduals_json, err := json.Marshal(scheduals)
  253. if err == nil {
  254. redis.Set(key, wait_scheduals_json, time.Second*30)
  255. }
  256. }
  257. this.ServeSuccessJSON(map[string]interface{}{
  258. "scheduals": scheduals,
  259. })
  260. }
  261. } else { //缓存数据了数据,将redis缓存的json字符串转为map
  262. var dat []map[string]interface{}
  263. if err := json.Unmarshal([]byte(wait_scheduals), &dat); err == nil {
  264. } else {
  265. }
  266. this.ServeSuccessJSON(map[string]interface{}{
  267. "scheduals": dat,
  268. "redis": "true",
  269. "date": schedualDate,
  270. })
  271. }
  272. }
  273. //else{
  274. // fmt.Println("33333333")
  275. //
  276. // scheduals, err := service.MobileGetWaitingScheduals(orgID, date.Unix())
  277. // if err != nil {
  278. // this.ErrorLog("获取排班信息失败:%v", err)
  279. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  280. // } else {
  281. // returnScheduals := make([]*service.MDialysisScheduleVM, 0, len(scheduals))
  282. // for _, s := range scheduals {
  283. //
  284. // returnScheduals = append(returnScheduals, s)
  285. // }
  286. //
  287. // this.ServeSuccessJSON(map[string]interface{}{
  288. // "scheduals": returnScheduals,
  289. // })
  290. // }
  291. //
  292. // }
  293. //if err == nil{
  294. //
  295. //
  296. //
  297. //
  298. //
  299. //}else{
  300. //}
  301. // /m/api/dialysis/record [get]
  302. // @param patient_id:int
  303. // @param date:string (yyyy-MM-dd)
  304. func (this *DialysisAPIController) DialysisRecord() {
  305. patientID, _ := this.GetInt64("patient_id")
  306. recordDateStr := this.GetString("date")
  307. if patientID <= 0 {
  308. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  309. return
  310. }
  311. if len(recordDateStr) == 0 {
  312. recordDateStr = time.Now().Format("2006-01-02")
  313. }
  314. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  315. if parseDateErr != nil {
  316. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  317. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  318. return
  319. }
  320. adminInfo := this.GetMobileAdminUserInfo()
  321. ch := make(chan struct{})
  322. count := 24 // count 表示活动的协程个数
  323. var patient models.Patients
  324. var receiverTreatmentAccess *models.ReceiveTreatmentAsses
  325. var predialysisEvaluation *models.PredialysisEvaluation
  326. var lastPredialysisEvaluation *models.PredialysisEvaluation
  327. var doctorAdvices []*models.DoctorAdvice
  328. var dialysisOrder *models.DialysisOrder
  329. var doubleCheck *models.DoubleCheck
  330. var monitorRecords []*models.MonitoringRecord
  331. var lastMonitorRecord *models.MonitoringRecord
  332. var assessmentAfterDislysis *models.AssessmentAfterDislysis
  333. var lastAssessmentAfterDislysis *models.AssessmentAfterDislysis
  334. var treatmentSummary *models.TreatmentSummary
  335. var dialysisPrescribe *models.DialysisPrescription
  336. var dialysisSolution *models.DialysisSolution
  337. var lastDialysisPrescribe *models.DialysisPrescription
  338. var systemDialysisPrescribe *models.SystemPrescription
  339. var is_project_open_config models.XtHisProjectConfig
  340. var projects []*models.HisPrescriptionProject
  341. var stockType []*models.GoodsTypeOne
  342. var prepare []*models.XtDialysisBeforePrepare
  343. var lastAssessment models.XtPatientVascularAccess
  344. var lastDryWeightDislysis *models.SgjPatientDryweight
  345. var gobalConfig models.GobalConfig
  346. var operators []*models.SgjUserAdminRoles
  347. // 先走redis,没有走数据库
  348. schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
  349. go func() {
  350. patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
  351. ch <- struct{}{}
  352. }()
  353. go func() {
  354. receiverTreatmentAccess, _ = service.MobileGetReceiverTreatmentAccessRecord(adminInfo.Org.Id, patientID, date.Unix())
  355. ch <- struct{}{}
  356. }()
  357. go func() {
  358. predialysisEvaluation, _ = service.MobileGetPredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  359. ch <- struct{}{}
  360. }()
  361. go func() {
  362. lastPredialysisEvaluation, _ = service.MobileGetLastTimePredialysisEvaluation(adminInfo.Org.Id, patientID, date.Unix())
  363. ch <- struct{}{}
  364. }()
  365. go func() {
  366. doctorAdvices, _ = service.MobileGetDoctorAdvicesByGroups(adminInfo.Org.Id, patientID, date.Unix())
  367. ch <- struct{}{}
  368. }()
  369. go func() {
  370. dialysisOrder, _ = service.MobileGetSchedualDialysisRecord(adminInfo.Org.Id, patientID, date.Unix())
  371. ch <- struct{}{}
  372. }()
  373. go func() {
  374. doubleCheck, _ = service.MobileGetDoubleCheck(adminInfo.Org.Id, patientID, date.Unix())
  375. ch <- struct{}{}
  376. }()
  377. go func() {
  378. monitorRecords, _ = service.MobileGetMonitorRecords(adminInfo.Org.Id, patientID, date.Unix())
  379. ch <- struct{}{}
  380. }()
  381. go func() {
  382. lastMonitorRecord, _ = service.MobileGetLastMonitorRecord(adminInfo.Org.Id, patientID, date.Unix())
  383. ch <- struct{}{}
  384. }()
  385. go func() {
  386. assessmentAfterDislysis, _ = service.MobileGetAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  387. ch <- struct{}{}
  388. }()
  389. go func() {
  390. lastAssessmentAfterDislysis, _ = service.MobileGetLastTimeAssessmentAfterDislysis(adminInfo.Org.Id, patientID, date.Unix())
  391. ch <- struct{}{}
  392. }()
  393. go func() {
  394. treatmentSummary, _ = service.MobileGetTreatmentSummary(adminInfo.Org.Id, patientID, date.Unix())
  395. ch <- struct{}{}
  396. }()
  397. go func() {
  398. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeId(adminInfo.Org.Id, patientID, date.Unix(), schedual.ModeId)
  399. ch <- struct{}{}
  400. }()
  401. go func() {
  402. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminInfo.Org.Id, patientID, schedual.ModeId)
  403. ch <- struct{}{}
  404. }()
  405. go func() {
  406. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminInfo.Org.Id, patientID, schedual.ModeId)
  407. ch <- struct{}{}
  408. }()
  409. go func() {
  410. systemDialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminInfo.Org.Id, schedual.ModeId)
  411. ch <- struct{}{}
  412. }()
  413. go func() {
  414. // 先走redis,没有走数据库
  415. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  416. ch <- struct{}{}
  417. }()
  418. go func() {
  419. // 先走redis,没有走数据库
  420. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  421. ch <- struct{}{}
  422. }()
  423. go func() {
  424. // // 先走redis,没有走数据库
  425. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  426. ch <- struct{}{}
  427. }()
  428. go func() {
  429. // 先走redis,没有走数据库
  430. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  431. ch <- struct{}{}
  432. }()
  433. go func() {
  434. // //获取最后一次血管通路
  435. // 先走redis,没有走数据库
  436. lastAssessment, _ = service.GetLastPassWayAssessment(adminInfo.Org.Id, patientID)
  437. ch <- struct{}{}
  438. }()
  439. go func() {
  440. // 先走redis,没有走数据库
  441. lastDryWeightDislysis, _ = service.MobileGetLastDryWeight(adminInfo.Org.Id, patientID)
  442. ch <- struct{}{}
  443. }()
  444. go func() {
  445. // 先走redis,没有走数据库
  446. _, gobalConfig = service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  447. ch <- struct{}{}
  448. }()
  449. go func() {
  450. // 先走redis,没有走数据库
  451. operators, _ = service.GetAllStarfEs(adminInfo.Org.Id)
  452. ch <- struct{}{}
  453. }()
  454. for range ch {
  455. // 每次从ch中接收数据,表明一个活动的协程结束
  456. count--
  457. // 当所有活动的协程都结束时,关闭管道
  458. if count == 0 {
  459. close(ch)
  460. }
  461. }
  462. prescribeOne, _ := service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  463. _, is_open_config := service.FindXTHisRecordByOrgId(adminInfo.Org.Id)
  464. _, is_project_open_config = service.FindXTHisProjectByOrgId(adminInfo.Org.Id)
  465. projects, _ = service.GetHisPrescriptionProjects(adminInfo.Org.Id, patientID, date.Unix())
  466. temp_team_projects, _ := service.GetHisPrescriptionTeamProjects(adminInfo.Org.Id, patientID, date.Unix())
  467. prescriptionConfig, _ := service.FindPrescriptionConfigById(adminInfo.Org.Id)
  468. var team_projects []*models.HisPrescriptionProject
  469. //var index int64 = 0
  470. for _, item := range temp_team_projects {
  471. //组套里面非检验项目的
  472. if item.HisProject.CostClassify != 3 {
  473. projects = append(projects, item)
  474. }
  475. //组套里面检验项目的
  476. if item.HisProject.CostClassify == 3 {
  477. team_projects = append(team_projects, item)
  478. }
  479. }
  480. team_projects = RemoveRepeatedCheckRecod(team_projects)
  481. stockType, _ = service.GetStockType(adminInfo.Org.Id)
  482. prepare, _ = service.GetDialyStockOut(adminInfo.Org.Id, date.Unix(), patientID)
  483. prescribeOne, _ = service.MobileGetDialysisPrescribeByModeIdOne(adminInfo.Org.Id, patientID, date.Unix())
  484. var his_advices []*models.HisDoctorAdviceInfo
  485. if is_open_config.IsOpen == 1 {
  486. // 先走redis,没有走数据库
  487. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  488. }
  489. is_advice_open, _ := service.FindAdviceSettingById(adminInfo.Org.Id)
  490. if is_advice_open.IsAdviceOpen == 1 {
  491. his_advices, _ = service.GetAllHisDoctorAdvice(adminInfo.Org.Id, patientID, date.Unix())
  492. }
  493. lastOrder, _ := service.GetLastDilysisOrder(adminInfo.Org.Id, patientID, date.Unix())
  494. remind_config, _ := service.GetCheckRemindConfigById(adminInfo.Org.Id)
  495. var remind_lists []models.XtCheckRemind
  496. if remind_config.ID > 0 && remind_config.IsOpen == 1 {
  497. remind_lists, _ = service.GetAllInspectionRemind(adminInfo.Org.Id, patientID)
  498. }
  499. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(patientID, adminInfo.Org.Id)
  500. returnData := map[string]interface{}{
  501. "patient": patient,
  502. "schedual": schedual,
  503. "prescription": dialysisPrescribe,
  504. "solution": dialysisSolution,
  505. "last_prescription": lastDialysisPrescribe,
  506. "receiver_treatment_access": receiverTreatmentAccess,
  507. "predialysis_evaluation": predialysisEvaluation,
  508. "doctor_advices": doctorAdvices,
  509. "double_check": doubleCheck,
  510. "assessment_after_dislysis": assessmentAfterDislysis,
  511. "treatment_summary": treatmentSummary,
  512. "monitor_records": monitorRecords,
  513. "dialysis_order": dialysisOrder,
  514. "operators": operators,
  515. "last_predialysis_evaluation": lastPredialysisEvaluation,
  516. "last_assessment_after_dislysis": lastAssessmentAfterDislysis,
  517. "last_monitor_record": lastMonitorRecord,
  518. "config": gobalConfig,
  519. "dry_weight": lastDryWeightDislysis,
  520. "system_prescription": systemDialysisPrescribe,
  521. "his_advices": his_advices,
  522. "is_open_config": is_open_config,
  523. "stockType": stockType,
  524. "prepare": prepare,
  525. "lastAssessment": lastAssessment,
  526. "prescribeOne": prescribeOne,
  527. "is_project_open_config": is_project_open_config,
  528. "project": projects,
  529. "team_projects": team_projects,
  530. "is_advice_open": is_advice_open,
  531. "prescription_open": prescriptionConfig.IsOpen,
  532. "lastOrder": lastOrder,
  533. "remind_lists": remind_lists,
  534. "lastDialysisPrescription": lastDialysisPrescription,
  535. }
  536. this.ServeSuccessJSON(returnData)
  537. }
  538. func (c *DialysisAPIController) GetDialysisGlobalConfig() {
  539. adminInfo := c.GetMobileAdminUserInfo()
  540. adminUsers, _ := service.GetAllAdminUsers(adminInfo.Org.Id, adminInfo.App.Id)
  541. devices, _ := service.GetValidDevicesBy(adminInfo.Org.Id, 0, 0)
  542. device_numbers, _ := service.GetAllValidDeviceNumbers(adminInfo.Org.Id)
  543. returnData := map[string]interface{}{
  544. "admin_users": adminUsers,
  545. "devices": devices,
  546. "device_numbers": device_numbers,
  547. }
  548. c.ServeSuccessJSON(returnData)
  549. }
  550. func (c *DialysisAPIController) PostAtreatmentInfo() {
  551. id, _ := c.GetInt64("patient", 0)
  552. recordDateStr := c.GetString("record_date")
  553. propagandaAndEducationContent := c.GetString("propagandaAndEducationContent")
  554. summaryContent := c.GetString("summaryContent")
  555. changeMedicalNurseId, _ := c.GetInt64("changeMedicalNurse", 0)
  556. treatNurseId, _ := c.GetInt64("treatNurse", 0)
  557. checkStaffId, _ := c.GetInt64("checkStaff", 0)
  558. deboardNurseId, _ := c.GetInt64("deboardNurse", 0)
  559. treatDoctor, _ := c.GetInt64("treatDoctor", 0)
  560. nursingRecord := c.GetString("nursing_record")
  561. fmt.Println("护理记录", nursingRecord)
  562. specialRecord := c.GetString("special_record")
  563. fmt.Println("特殊记录", specialRecord)
  564. adminUserInfo := c.GetMobileAdminUserInfo()
  565. changeMedicalNurseId = adminUserInfo.AdminUser.Id
  566. checkStaffId = adminUserInfo.AdminUser.Id
  567. deboardNurseId = adminUserInfo.AdminUser.Id
  568. treatDoctor = adminUserInfo.AdminUser.Id
  569. if id <= 0 {
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  571. return
  572. }
  573. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  574. if patient.ID == 0 {
  575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  576. return
  577. }
  578. if len(recordDateStr) == 0 {
  579. recordDateStr = time.Now().Format("2006-01-02")
  580. }
  581. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  582. if parseDateErr != nil {
  583. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  585. return
  586. }
  587. summary := models.TreatmentSummary{
  588. UserOrgId: adminUserInfo.Org.Id,
  589. PatientId: id,
  590. AssessmentDate: recordDate.Unix(),
  591. Mission: propagandaAndEducationContent,
  592. DialysisSummary: summaryContent,
  593. SjNurse: changeMedicalNurseId,
  594. ZlNurse: treatNurseId,
  595. HdNurse: checkStaffId,
  596. XjNurse: deboardNurseId,
  597. ZlDoctor: treatDoctor,
  598. CreatedTime: time.Now().Unix(),
  599. Status: 1,
  600. NursingRecord: nursingRecord,
  601. SpecialRecord: specialRecord,
  602. }
  603. // 查询信息规挡的设置天数
  604. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  605. if infor.ID > 0 && infor.WeekDay > 0 {
  606. var cha_time int64
  607. timeNowStr := time.Now().Format("2006-01-02")
  608. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  609. //今日的日期减去设置的日期
  610. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  611. if cha_time >= recordDate.Unix() {
  612. //查询审核是否允许
  613. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 10)
  614. //申请状态不允许的情况 拒绝修改
  615. if infor.ApplicationStatus != 1 {
  616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  617. return
  618. }
  619. }
  620. }
  621. _, treatmentSummary := service.FindTreatmentSummaryByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  622. if treatmentSummary.ID == 0 { //新增
  623. summary.Creater = adminUserInfo.AdminUser.Id
  624. service.AddSigleSummaryRecord(&summary)
  625. finish := models.XtDialysisFinish{
  626. IsFinish: 1,
  627. UserOrgId: adminUserInfo.Org.Id,
  628. Status: 1,
  629. Ctime: time.Now().Unix(),
  630. Mtime: 0,
  631. Module: 10,
  632. RecordDate: recordDate.Unix(),
  633. Sourse: 1,
  634. PatientId: id,
  635. }
  636. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 10, id)
  637. if dialysisFinish.ID == 0 {
  638. service.CreateDialysisFinish(finish)
  639. }
  640. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  641. redis := service.RedisClient()
  642. //清空key 值
  643. redis.Set(key, "", time.Second)
  644. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  645. redis.Set(keyOne, "", time.Second)
  646. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  647. redis.Set(keyThree, "", time.Second)
  648. defer redis.Close()
  649. c.ServeSuccessJSON(map[string]interface{}{
  650. "summary": summary,
  651. })
  652. } else { //修改
  653. summary.Creater = treatmentSummary.Creater
  654. summary.CreatedTime = treatmentSummary.CreatedTime
  655. summary.Modifier = adminUserInfo.AdminUser.Id
  656. summary.ID = treatmentSummary.ID
  657. service.UpdateSummeRecord(&summary)
  658. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  659. redis := service.RedisClient()
  660. //清空key 值
  661. redis.Set(key, "", time.Second)
  662. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  663. redis.Set(keyOne, "", time.Second)
  664. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  665. redis.Set(keyThree, "", time.Second)
  666. defer redis.Close()
  667. c.ServeSuccessJSON(map[string]interface{}{
  668. "summary": summary,
  669. })
  670. }
  671. }
  672. func (c *DialysisAPIController) PostDoubleCheck() {
  673. id, _ := c.GetInt64("patient", 0)
  674. recordDateStr := c.GetString("record_date")
  675. checkTimeStr := c.GetString("check_time")
  676. firstCheckTimeStr := c.GetString("first_check_time")
  677. creater, _ := c.GetInt64("creater", 0)
  678. modifier, _ := c.GetInt64("modifier", 0)
  679. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  680. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  681. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  682. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  683. dialysis_item_desc := c.GetString("dialysis_item_desc")
  684. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  685. vascular_access_desc := c.GetString("vascular_access_desc")
  686. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  687. collator, _ := c.GetInt64("collator", 0)
  688. employee_number := c.GetString("employee_number")
  689. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  690. needle_batch_number := c.GetString("needle_batch_number")
  691. if id <= 0 {
  692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  693. return
  694. }
  695. adminUserInfo := c.GetMobileAdminUserInfo()
  696. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  697. if patient.ID == 0 {
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  699. return
  700. }
  701. if len(recordDateStr) == 0 {
  702. recordDateStr = time.Now().Format("2006-01-02")
  703. }
  704. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  705. if parseDateErr != nil {
  706. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  708. return
  709. }
  710. var checkDate int64
  711. if len(checkTimeStr) == 0 {
  712. checkDate = 0
  713. } else {
  714. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", checkTimeStr)
  715. checkDate = checkDateUnix.Unix()
  716. }
  717. var firstCheckDate int64
  718. if len(firstCheckTimeStr) == 0 {
  719. firstCheckDate = 0
  720. } else {
  721. firstCheckDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", firstCheckTimeStr)
  722. firstCheckDate = firstCheckDateUnix.Unix()
  723. }
  724. //if adminUserInfo.Org.Id == 10340 {
  725. //
  726. // list, _ := service.GetRoleList(adminUserInfo.Org.Id, modifier)
  727. // _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  728. // if check.ID == 0 {
  729. // if employee_number != list.JobNumber {
  730. // c.ServeSuccessJSON(map[string]interface{}{
  731. // "doubleCheck": check,
  732. // "msg": "2",
  733. // })
  734. // return
  735. // }
  736. // }
  737. // if check.ID > 0 {
  738. // if employee_number != list.JobNumber {
  739. // c.ServeSuccessJSON(map[string]interface{}{
  740. // "doubleCheck": check,
  741. // "msg": "2",
  742. // })
  743. // return
  744. // }
  745. // }
  746. //
  747. //}
  748. doubleCheck := models.DoubleCheck{
  749. UserOrgId: adminUserInfo.Org.Id,
  750. PatientId: id,
  751. DialysisItemCheck: dialysis_item_check,
  752. DialysisParameterCheck: dialysis_parameter_check,
  753. VascularAccessVerification: vascular_access_verification,
  754. PipelineConnectionCheck: pipeline_connection_check,
  755. DialysisItemDesc: dialysis_item_desc,
  756. DialysisParameterDesc: dialysis_parameter_desc,
  757. VascularAccessDesc: vascular_access_desc,
  758. PipelineConnectionDesc: pipeline_connection_desc,
  759. Collator: collator,
  760. Status: 1,
  761. CreatedTime: time.Now().Unix(),
  762. CheckDate: recordDate.Unix(),
  763. UpdatedTime: time.Now().Unix(),
  764. EmployeeNumber: employee_number,
  765. DialyzerBatchNumber: dialyzer_batch_number,
  766. NeedleBatchNumber: needle_batch_number,
  767. }
  768. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  769. if check.ID == 0 { //新增
  770. doubleCheck.FirstCheckTime = firstCheckDate
  771. doubleCheck.CheckTime = checkDate
  772. doubleCheck.Creater = creater
  773. doubleCheck.Modifier = modifier
  774. if adminUserInfo.Org.Id == 10340 {
  775. order, _ := service.GetDialysisOrder(recordDate.Unix(), id, adminUserInfo.Org.Id)
  776. doubleCheck.Creater = order.StartNurse
  777. }
  778. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  779. //查询未核对的医嘱
  780. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  781. for _, advice := range doctorList {
  782. if advice.ExecutionStaff == modifier {
  783. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  784. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  785. return
  786. }
  787. }
  788. }
  789. // 查询信息规挡的设置天数
  790. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  791. if infor.ID > 0 && infor.WeekDay > 0 {
  792. var cha_time int64
  793. timeNowStr := time.Now().Format("2006-01-02")
  794. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  795. //今日的日期减去设置的日期
  796. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  797. if cha_time >= recordDate.Unix() {
  798. //查询审核是否允许
  799. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  800. //申请状态不允许的情况 拒绝修改
  801. if infor.ApplicationStatus != 1 {
  802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  803. return
  804. }
  805. }
  806. }
  807. err := service.AddSigleDoubleCheck(&doubleCheck)
  808. finish := models.XtDialysisFinish{
  809. IsFinish: 1,
  810. UserOrgId: adminUserInfo.Org.Id,
  811. Status: 1,
  812. Ctime: time.Now().Unix(),
  813. Mtime: 0,
  814. Module: 5,
  815. RecordDate: recordDate.Unix(),
  816. Sourse: 1,
  817. PatientId: id,
  818. }
  819. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 5, id)
  820. if dialysisFinish.ID == 0 {
  821. service.CreateDialysisFinish(finish)
  822. }
  823. //针对长沙南雅
  824. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  825. //查询未核对的医嘱
  826. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  827. if len(doctorList) > 0 && modifier > 0 {
  828. for _, advice := range doctorList {
  829. service.UpdateDoctorAdviceList(advice.ID, modifier)
  830. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  831. redis := service.RedisClient()
  832. //清空key 值
  833. redis.Set(key, "", time.Second)
  834. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  835. redis.Set(keyTwo, "", time.Second)
  836. theTime := time.Now()
  837. recordDate := theTime.Format("2006-01-02")
  838. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  839. redis.Set(keyFour, "", time.Second)
  840. defer redis.Close()
  841. }
  842. }
  843. }
  844. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  845. redis := service.RedisClient()
  846. //清空key 值
  847. redis.Set(key, "", time.Second)
  848. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  849. redis.Set(keyOne, "", time.Second)
  850. defer redis.Close()
  851. if err == nil {
  852. c.ServeSuccessJSON(map[string]interface{}{
  853. "doubleCheck": &doubleCheck,
  854. })
  855. }
  856. } else { //修改
  857. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  858. if infor.ID > 0 {
  859. var cha_time int64
  860. timeNowStr := time.Now().Format("2006-01-02")
  861. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  862. //今日的日期减去设置的日期
  863. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  864. if cha_time >= recordDate.Unix() {
  865. //查询审核是否允许
  866. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 5)
  867. //申请状态不允许的情况 拒绝修改
  868. if infor.ApplicationStatus != 1 {
  869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  870. return
  871. }
  872. }
  873. }
  874. doubleCheck.FirstCheckTime = firstCheckDate
  875. doubleCheck.CheckTime = checkDate
  876. doubleCheck.Creater = creater
  877. doubleCheck.Modifier = modifier
  878. doubleCheck.CreatedTime = check.CreatedTime
  879. doubleCheck.ID = check.ID
  880. doubleCheck.EmployeeNumber = employee_number
  881. doubleCheck.NeedleBatchNumber = needle_batch_number
  882. doubleCheck.DialyzerBatchNumber = dialyzer_batch_number
  883. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  884. //查询未核对的医嘱
  885. doctorList, err := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  886. for _, advice := range doctorList {
  887. if advice.ExecutionStaff == modifier {
  888. c.ErrorLog("医嘱核对人不能和执行人为同一人!", err)
  889. c.ServeFailJSONWithSGJErrorCode(enums.AdviceCodeParamWrong)
  890. return
  891. }
  892. }
  893. }
  894. err := service.UpdateDoubleCheck(&doubleCheck)
  895. //针对长沙南雅
  896. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 {
  897. //查询未核对的医嘱
  898. doctorList, _ := service.GetDoctorAdviceCheckList(id, recordDate.Unix(), adminUserInfo.Org.Id)
  899. if len(doctorList) > 0 && modifier > 0 {
  900. for _, advice := range doctorList {
  901. service.UpdateDoctorAdviceList(advice.ID, modifier)
  902. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  903. redis := service.RedisClient()
  904. //清空key 值
  905. redis.Set(key, "", time.Second)
  906. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  907. redis.Set(keyTwo, "", time.Second)
  908. theTime := time.Now()
  909. recordDate := theTime.Format("2006-01-02")
  910. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  911. redis.Set(keyFour, "", time.Second)
  912. defer redis.Close()
  913. }
  914. }
  915. }
  916. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  917. redis := service.RedisClient()
  918. //清空key 值
  919. redis.Set(key, "", time.Second)
  920. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  921. redis.Set(keyOne, "", time.Second)
  922. defer redis.Close()
  923. if err == nil {
  924. c.ServeSuccessJSON(map[string]interface{}{
  925. "doubleCheck": &doubleCheck,
  926. "msg": "1",
  927. })
  928. }
  929. }
  930. }
  931. func (c *DialysisAPIController) PostAcceptsAssessment() {
  932. id, _ := c.GetInt64("patient", 0)
  933. recordDateStr := c.GetString("record_date")
  934. way, _ := c.GetInt64("way", 0)
  935. consciousness, _ := c.GetInt64("consciousness", 0)
  936. appetite, _ := c.GetInt64("appetite", 0)
  937. condition, _ := c.GetInt64("condition", 0)
  938. posture, _ := c.GetInt64("posture")
  939. sick_condition, _ := c.GetInt64("sick_condition", 0)
  940. danger_level, _ := c.GetInt64("danger_level", 0)
  941. intake, _ := c.GetInt64("intake", 0)
  942. nutrition, _ := c.GetInt64("nutrition", 0)
  943. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  944. psychological_assessment_other := c.GetString("psychological_assessment_other")
  945. score := c.GetString("score")
  946. sick_condition_other := c.GetString("sick_condition_other")
  947. //precaution, _ := c.GetInt64("precaution", 0)
  948. precaution := c.GetString("precaution")
  949. precaution_other := c.GetString("precaution_other")
  950. psychological_other := c.GetString("psychological_other")
  951. admission_number := c.GetString("admission_number")
  952. tumble, _ := c.GetInt64("tumble")
  953. diacrisis := c.GetString("diacrisis")
  954. his_department := c.GetString("his_department")
  955. his_bed := c.GetString("his_bed")
  956. if id <= 0 {
  957. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  958. return
  959. }
  960. adminUserInfo := c.GetMobileAdminUserInfo()
  961. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  962. if patient.ID == 0 {
  963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  964. return
  965. }
  966. //now := time.Now()
  967. //year, month, day := now.Date()
  968. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  969. //todayTimeStamp := today_time.Unix()
  970. if len(recordDateStr) == 0 {
  971. recordDateStr = time.Now().Format("2006-01-02")
  972. }
  973. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  974. if parseDateErr != nil {
  975. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  977. return
  978. }
  979. // 查询信息规挡的设置天数
  980. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  981. if infor.ID > 0 && infor.WeekDay > 0 {
  982. var cha_time int64
  983. timeNowStr := time.Now().Format("2006-01-02")
  984. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  985. //今日的日期减去设置的日期
  986. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  987. if cha_time >= recordDate.Unix() {
  988. //查询审核是否允许
  989. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  990. //申请状态不允许的情况 拒绝修改
  991. if infor.ApplicationStatus != 1 {
  992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  993. return
  994. }
  995. }
  996. }
  997. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  998. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  999. UserOrgId: adminUserInfo.Org.Id,
  1000. PatientId: id,
  1001. RecordDate: recordDate.Unix(),
  1002. Way: way,
  1003. Consciousness: consciousness,
  1004. Appetite: appetite,
  1005. Condition: condition,
  1006. SickCondition: sick_condition,
  1007. DangerLevel: danger_level,
  1008. Intake: intake,
  1009. Nutrition: nutrition,
  1010. PsychologicalAssessment: psychological_assessment,
  1011. PsychologicalAssessmentOther: psychological_assessment_other,
  1012. SickConditionOther: sick_condition_other,
  1013. Posture: posture,
  1014. CreatedTime: time.Now().Unix(),
  1015. UpdateTime: time.Now().Unix(),
  1016. Status: 1,
  1017. Score: score,
  1018. Precaution: precaution,
  1019. PrecautionOther: precaution_other,
  1020. PsychologicalOther: psychological_other,
  1021. AdmissionNumber: admission_number,
  1022. Tumble: tumble,
  1023. Diacrisis: diacrisis,
  1024. HisBed: his_bed,
  1025. HisDepartment: his_department,
  1026. }
  1027. if receiveTreatment.ID == 0 { //新增
  1028. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1029. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1030. finish := models.XtDialysisFinish{
  1031. IsFinish: 1,
  1032. UserOrgId: adminUserInfo.Org.Id,
  1033. Status: 1,
  1034. Ctime: time.Now().Unix(),
  1035. Mtime: 0,
  1036. Module: 2,
  1037. RecordDate: recordDate.Unix(),
  1038. Sourse: 1,
  1039. PatientId: id,
  1040. }
  1041. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 2, id)
  1042. if dialysisFinish.ID == 0 {
  1043. service.CreateDialysisFinish(finish)
  1044. }
  1045. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1046. redis := service.RedisClient()
  1047. defer redis.Close()
  1048. //清空key 值
  1049. redis.Set(key, "", time.Second)
  1050. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1051. redis.Set(keyOne, "", time.Second)
  1052. if err == nil {
  1053. c.ServeSuccessJSON(map[string]interface{}{
  1054. "receiveTreatmentAsses": receiveTreatmentAsses,
  1055. })
  1056. }
  1057. } else { //修改
  1058. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1059. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1060. // if getPermissionErr != nil {
  1061. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1062. // return
  1063. // } else if headNursePermission == nil {
  1064. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1065. // return
  1066. // }
  1067. //}
  1068. // 查询信息规挡的设置天数
  1069. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1070. if infor.ID > 0 && infor.WeekDay > 0 {
  1071. var cha_time int64
  1072. timeNowStr := time.Now().Format("2006-01-02")
  1073. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1074. //今日的日期减去设置的日期
  1075. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1076. if cha_time >= recordDate.Unix() {
  1077. //查询审核是否允许
  1078. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 2)
  1079. //申请状态不允许的情况 拒绝修改
  1080. if infor.ApplicationStatus != 1 {
  1081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1082. return
  1083. }
  1084. }
  1085. }
  1086. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1087. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1088. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1089. receiveTreatmentAsses.ID = receiveTreatment.ID
  1090. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1091. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1092. redis := service.RedisClient()
  1093. defer redis.Close()
  1094. //清空key 值
  1095. redis.Set(key, "", time.Second)
  1096. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1097. redis.Set(keyOne, "", time.Second)
  1098. if err == nil {
  1099. c.ServeSuccessJSON(map[string]interface{}{
  1100. "receiveTreatmentAsses": receiveTreatmentAsses,
  1101. })
  1102. }
  1103. }
  1104. }
  1105. func (c *DialysisAPIController) PostAssessmentAfterDislysis() {
  1106. id, _ := c.GetInt64("patient", 0)
  1107. recordDateStr := c.GetString("record_date")
  1108. weightAfter, _ := c.GetFloat("weight_after", 0)
  1109. additionalWeight, _ := c.GetFloat("additional_weight", 0)
  1110. weightReduce, _ := c.GetFloat("weight_loss", 0)
  1111. fmt.Println("weight_loss", weightReduce)
  1112. temperature, _ := c.GetFloat("temperature", 0)
  1113. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1114. breathing_rate := c.GetString("breathing_rate")
  1115. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1116. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1117. actual_ultrafiltration, _ := c.GetFloat("actual_ultrafiltration", 0)
  1118. actual_displacement, _ := c.GetFloat("actual_displacement", 0)
  1119. actualtreatHour, _ := c.GetInt64("actual_treatment_hour", 0)
  1120. actualtreatmin, _ := c.GetInt64("actual_treatment_minute", 0)
  1121. cruor := c.GetString("cruor")
  1122. symptomsAfterDialysi := c.GetString("symptom_after_dialysis")
  1123. internalFistula := c.GetString("internal_fistula")
  1124. catheter := c.GetString("catheter")
  1125. complications := c.GetString("complication")
  1126. remark := c.GetString("remark")
  1127. //dialysateVolume, _ := c.GetInt64("dialysis_intakes", 0)
  1128. dialysis_intakes := c.GetString("dialysis_intakes")
  1129. dialysateVolume, _ := strconv.ParseFloat(dialysis_intakes, 64)
  1130. dialysis_intakes_unit, _ := c.GetInt64("dialysis_intakes_unit", 0)
  1131. blood_access_part_id, _ := c.GetInt64("blood_access_part_id", 0)
  1132. blood_access_part_opera_id, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1133. puncturePointOozingBlood, _ := c.GetInt64("puncture_point_oozing_blood", 0)
  1134. puncturePointHaematoma, _ := c.GetInt64("puncture_point_haematoma", 0)
  1135. internalFistulaTremorAc, _ := c.GetInt64("internal_fistula_tremor_ac", 0)
  1136. patientGose, _ := c.GetInt64("patient_gose", 0)
  1137. inpatientDepartment := c.GetString("inpatient_department")
  1138. observationContent := c.GetString("observation_content")
  1139. observationContentOther := c.GetString("observation_content_other")
  1140. dialysis_process, _ := c.GetInt64("dialysis_process", 0)
  1141. in_advance_minute, _ := c.GetFloat("in_advance_minute", 0)
  1142. in_advance_reason := c.GetString("in_advance_reason")
  1143. hemostasis_minute, _ := c.GetInt64("hemostasis_minute", 0)
  1144. hemostasis_opera, _ := c.GetInt64("hemostasis_opera", 0)
  1145. tremor_noise, _ := c.GetInt64("tremor_noise", 0)
  1146. disequilibrium_syndrome, _ := c.GetInt64("disequilibrium_syndrome", 0)
  1147. disequilibrium_syndrome_option := c.GetString("disequilibrium_syndrome_option")
  1148. arterial_tube, _ := c.GetInt64("arterial_tube", 0)
  1149. intravenous_tube, _ := c.GetInt64("intravenous_tube", 0)
  1150. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1151. in_advance_reason_other := c.GetString("in_advance_reason_other")
  1152. is_eat, _ := c.GetInt64("is_eat", 0)
  1153. cvc_a, _ := c.GetFloat("cvc_a", 0)
  1154. cvc_v, _ := c.GetFloat("cvc_v", 0)
  1155. channels, _ := c.GetInt64("channel", 0)
  1156. return_blood, _ := c.GetInt64("return_blood", 0)
  1157. rehydration_volume, _ := c.GetInt64("rehydration_volume", 0)
  1158. dialysis_during, _ := c.GetInt64("dialysis_during", 0)
  1159. stroke_volume, _ := c.GetInt64("stroke_volume", 0)
  1160. blood_flow, _ := c.GetInt64("blood_flow", 0)
  1161. //sealing_fluid_dispose, _ := c.GetInt64("sealing_fluid_dispose", 0)
  1162. sealing_fluid_dispose := c.GetString("sealing_fluid_dispose")
  1163. sealing_fluid_special := c.GetString("sealing_fluid_special")
  1164. dosage_of_anticoagulants, _ := c.GetFloat("dosage_of_anticoagulants")
  1165. supine_systolic_blood_pressure := c.GetString("supine_systolic_blood_pressure")
  1166. setting_pressure := c.GetString("setting_pressure")
  1167. supine_diastolic_blood_pressure := c.GetString("supine_diastolic_blood_pressure")
  1168. diastolic_pressure := c.GetString("diastolic_pressure")
  1169. other_complication := c.GetString("other_complication")
  1170. ktv := c.GetString("ktv")
  1171. urr := c.GetString("urr")
  1172. hypertenison, _ := c.GetInt64("hypertenison")
  1173. hypopiesia, _ := c.GetInt64("hypopiesia")
  1174. leave_office_method, _ := c.GetInt64("leave_office_method")
  1175. lapse, _ := c.GetInt64("lapse")
  1176. consciousness, _ := c.GetInt64("consciousness")
  1177. fallrisk, _ := c.GetInt64("fallrisk")
  1178. machine_run := c.GetString("machine_run")
  1179. after_urea := c.GetString("after_urea")
  1180. pip_coagulation := c.GetString("pip_coagulation")
  1181. accumulated_blood_volume := c.GetString("accumulated_blood_volume")
  1182. transfusion_volume := c.GetString("transfusion_volume")
  1183. if id <= 0 {
  1184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1185. return
  1186. }
  1187. adminUserInfo := c.GetMobileAdminUserInfo()
  1188. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1189. if patient.ID == 0 {
  1190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1191. return
  1192. }
  1193. if len(recordDateStr) == 0 {
  1194. recordDateStr = time.Now().Format("2006-01-02")
  1195. }
  1196. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1197. fmt.Println("parseDateErr", parseDateErr)
  1198. if parseDateErr != nil {
  1199. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1201. return
  1202. }
  1203. //now := time.Now()
  1204. //year, month, day := now.Date()
  1205. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  1206. //todayTimeStamp := today_time.Unix()
  1207. //_, evaluation := service.FindPredialysisEvaluationByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1208. assessmentAfterDislysis := models.AssessmentAfterDislysis{
  1209. UserOrgId: adminUserInfo.Org.Id,
  1210. PatientId: id,
  1211. AssessmentDate: recordDate.Unix(),
  1212. Temperature: temperature,
  1213. PulseFrequency: pulse_frequency,
  1214. BreathingRate: breathing_rate,
  1215. SystolicBloodPressure: systolic_blood_pressure,
  1216. DiastolicBloodPressure: diastolic_blood_pressure,
  1217. ActualUltrafiltration: actual_ultrafiltration,
  1218. ActualDisplacement: actual_displacement,
  1219. ActualTreatmentHour: actualtreatHour,
  1220. ActualTreatmentMinute: actualtreatmin,
  1221. WeightAfter: weightAfter,
  1222. AdditionalWeight: additionalWeight,
  1223. WeightLoss: weightReduce,
  1224. Cruor: cruor,
  1225. SymptomAfterDialysis: symptomsAfterDialysi,
  1226. InternalFistula: internalFistula,
  1227. Catheter: catheter,
  1228. Complication: complications,
  1229. DialysisIntakes: dialysateVolume,
  1230. CreatedTime: time.Now().Unix(),
  1231. UpdatedTime: time.Now().Unix(),
  1232. Status: 1,
  1233. Remark: remark,
  1234. BloodAccessPartId: blood_access_part_id,
  1235. BloodAccessPartOperaId: blood_access_part_opera_id,
  1236. DialysisIntakesUnit: dialysis_intakes_unit,
  1237. PuncturePointOozingBlood: puncturePointOozingBlood,
  1238. PuncturePointHaematoma: puncturePointHaematoma,
  1239. InternalFistulaTremorAc: internalFistulaTremorAc,
  1240. PatientGose: patientGose,
  1241. InpatientDepartment: inpatientDepartment,
  1242. ObservationContent: observationContent,
  1243. ObservationContentOther: observationContentOther,
  1244. DialysisProcess: dialysis_process,
  1245. InAdvanceMinute: in_advance_minute,
  1246. InAdvanceReason: in_advance_reason,
  1247. HemostasisMinute: hemostasis_minute,
  1248. HemostasisOpera: hemostasis_opera,
  1249. TremorNoise: tremor_noise,
  1250. DisequilibriumSyndrome: disequilibrium_syndrome,
  1251. DisequilibriumSyndromeOption: disequilibrium_syndrome_option,
  1252. ArterialTube: arterial_tube,
  1253. IntravenousTube: intravenous_tube,
  1254. Dialyzer: dialyzer,
  1255. InAdvanceReasonOther: in_advance_reason_other,
  1256. IsEat: is_eat,
  1257. CvcA: cvc_a,
  1258. CvcV: cvc_v,
  1259. Channel: channels,
  1260. ReturnBlood: return_blood,
  1261. RehydrationVolume: rehydration_volume,
  1262. DialysisDuring: dialysis_during,
  1263. StrokeVolume: stroke_volume,
  1264. BloodFlow: blood_flow,
  1265. SealingFluidDispose: sealing_fluid_dispose,
  1266. SealingFluidSpecial: sealing_fluid_special,
  1267. DosageOfAnticoagulants: dosage_of_anticoagulants,
  1268. SupineDiastolicBloodPressure: supine_diastolic_blood_pressure,
  1269. SupineSystolicBloodPressure: supine_systolic_blood_pressure,
  1270. SettingPressure: setting_pressure,
  1271. DiastolicPressure: diastolic_pressure,
  1272. OtherComplication: other_complication,
  1273. Ktv: ktv,
  1274. Urr: urr,
  1275. Hypopiesia: hypopiesia,
  1276. Hypertenison: hypertenison,
  1277. Lapse: lapse,
  1278. LeaveOfficeMethod: leave_office_method,
  1279. Consciousness: consciousness,
  1280. Fallrisk: fallrisk,
  1281. MachineRun: machine_run,
  1282. AfterUrea: after_urea,
  1283. PipCoagulation: pip_coagulation,
  1284. AccumulatedBloodVolume: accumulated_blood_volume,
  1285. TransfusionVolume: transfusion_volume,
  1286. }
  1287. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1288. // 查询信息规挡的设置天数
  1289. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1290. if infor.ID > 0 && infor.WeekDay > 0 {
  1291. var cha_time int64
  1292. timeNowStr := time.Now().Format("2006-01-02")
  1293. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1294. //今日的日期减去设置的日期
  1295. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1296. fmt.Println("recordDate.Unix()", recordDate.Unix())
  1297. if cha_time >= recordDate.Unix() {
  1298. //查询审核是否允许
  1299. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1300. //申请状态不允许的情况 拒绝修改
  1301. if infor.ApplicationStatus != 1 {
  1302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1303. return
  1304. }
  1305. }
  1306. }
  1307. _, assessmentAfter := service.FindAssessmentAfterDislysisByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1308. if assessmentAfter.ID == 0 { //新增
  1309. if appRole.UserType == 2 || appRole.UserType == 1 {
  1310. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1311. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1312. } else {
  1313. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1314. }
  1315. err := service.AddSigleAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1316. //记录日志
  1317. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1318. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1319. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1320. PatientId: assessmentAfterDislysis.PatientId,
  1321. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1322. Status: 1,
  1323. ErrLog: string(byterequest),
  1324. AdminUserId: adminUserInfo.AdminUser.Id,
  1325. Ctime: 0,
  1326. Mtime: 0,
  1327. Source: "手机端保存透后评估",
  1328. }
  1329. service.CreateAfterDialysisLog(afterDialysisLog)
  1330. finish := models.XtDialysisFinish{
  1331. IsFinish: 1,
  1332. UserOrgId: adminUserInfo.Org.Id,
  1333. Status: 1,
  1334. Ctime: time.Now().Unix(),
  1335. Mtime: 0,
  1336. Module: 9,
  1337. RecordDate: recordDate.Unix(),
  1338. Sourse: 1,
  1339. PatientId: id,
  1340. }
  1341. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 9, id)
  1342. if dialysisFinish.ID == 0 {
  1343. service.CreateDialysisFinish(finish)
  1344. }
  1345. redis := service.RedisClient()
  1346. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1347. redis.Set(keyTwo, "", time.Second)
  1348. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1349. //清空key 值
  1350. redis.Set(key, "", time.Second)
  1351. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1352. redis.Set(keyOne, "", time.Second)
  1353. defer redis.Close()
  1354. if err == nil {
  1355. c.ServeSuccessJSON(map[string]interface{}{
  1356. "assessmentAfterDislysis": assessmentAfterDislysis,
  1357. })
  1358. }
  1359. return
  1360. } else { //修改
  1361. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1362. if infor.ID > 0 && infor.WeekDay > 0 {
  1363. var cha_time int64
  1364. timeNowStr := time.Now().Format("2006-01-02")
  1365. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1366. //今日的日期减去设置的日期
  1367. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1368. if cha_time >= recordDate.Unix() {
  1369. //查询审核是否允许
  1370. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 9)
  1371. //申请状态不允许的情况 拒绝修改
  1372. if infor.ApplicationStatus != 1 {
  1373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1374. return
  1375. }
  1376. }
  1377. }
  1378. if appRole.UserType == 2 || appRole.UserType == 1 {
  1379. assessmentAfterDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1380. assessmentAfterDislysis.AssessmentTime = time.Now().Unix()
  1381. } else {
  1382. assessmentAfterDislysis.Modifier = adminUserInfo.AdminUser.Id
  1383. if assessmentAfterDislysis.Creater == 0 {
  1384. assessmentAfterDislysis.Creater = adminUserInfo.AdminUser.Id
  1385. }
  1386. }
  1387. assessmentAfterDislysis.CreatedTime = assessmentAfter.CreatedTime
  1388. assessmentAfterDislysis.ID = assessmentAfter.ID
  1389. err := service.UpdateAssessmentAfterDislysisRecord(&assessmentAfterDislysis)
  1390. //记录日志
  1391. byterequest, _ := json.Marshal(assessmentAfterDislysis)
  1392. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1393. UserOrgId: assessmentAfterDislysis.UserOrgId,
  1394. PatientId: assessmentAfterDislysis.PatientId,
  1395. RecordDate: assessmentAfterDislysis.AssessmentDate,
  1396. Status: 1,
  1397. ErrLog: string(byterequest),
  1398. AdminUserId: adminUserInfo.AdminUser.Id,
  1399. Ctime: time.Now().Unix(),
  1400. Mtime: 0,
  1401. Source: "手机端修改保存透后评估",
  1402. }
  1403. service.CreateAfterDialysisLog(afterDialysisLog)
  1404. redis := service.RedisClient()
  1405. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1406. redis.Set(keyTwo, "", time.Second)
  1407. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1408. //清空key 值
  1409. redis.Set(key, "", time.Second)
  1410. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1411. redis.Set(keyOne, "", time.Second)
  1412. if err == nil {
  1413. c.ServeSuccessJSON(map[string]interface{}{
  1414. "assessmentAfterDislysis": assessmentAfterDislysis,
  1415. })
  1416. return
  1417. }
  1418. }
  1419. return
  1420. }
  1421. func (c *DialysisAPIController) PostDialysisPrescription() {
  1422. id, _ := c.GetInt64("patient", 0)
  1423. recordDateStr := c.GetString("record_date")
  1424. if id <= 0 {
  1425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1426. return
  1427. }
  1428. adminUserInfo := c.GetMobileAdminUserInfo()
  1429. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  1430. if patient.ID == 0 {
  1431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1432. return
  1433. }
  1434. if len(recordDateStr) == 0 {
  1435. recordDateStr = time.Now().Format("2006-01-02")
  1436. }
  1437. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1438. if parseDateErr != nil {
  1439. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1441. return
  1442. }
  1443. mode_id, _ := c.GetInt64("mode_id", 0)
  1444. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  1445. dialyzer, _ := c.GetInt64("dialyzer", 0)
  1446. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  1447. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  1448. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  1449. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  1450. replacement_total, _ := c.GetFloat("replacement_total", 0)
  1451. replacement_way, _ := c.GetInt64("replacement_way", 0)
  1452. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  1453. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  1454. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  1455. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  1456. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  1457. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  1458. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  1459. kalium, _ := c.GetFloat("kalium", 0)
  1460. sodium, _ := c.GetFloat("sodium", 0)
  1461. calcium, _ := c.GetFloat("calcium", 0)
  1462. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  1463. glucose, _ := c.GetFloat("glucose", 0)
  1464. // prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  1465. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  1466. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  1467. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  1468. conductivity, _ := c.GetFloat("conductivity", 0)
  1469. remark := c.GetString("remark")
  1470. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  1471. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  1472. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  1473. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  1474. body_fluid, _ := c.GetInt64("body_fluid", 0)
  1475. special_medicine, _ := c.GetInt64("special_medicine", 0)
  1476. special_medicine_other := c.GetString("special_medicine_other")
  1477. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  1478. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  1479. blood_access, _ := c.GetInt64("blood_access", 0)
  1480. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  1481. body_fluid_other := c.GetString("body_fluid_other")
  1482. niprocart, _ := c.GetInt64("niprocart", 0)
  1483. jms, _ := c.GetInt64("jms", 0)
  1484. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  1485. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  1486. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  1487. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  1488. filtryzer, _ := c.GetInt64("filtryzer", 0)
  1489. target_ktv, _ := c.GetFloat("target_ktv", 0)
  1490. dialyzers, _ := c.GetInt64("dialyzers", 0)
  1491. injector, _ := c.GetInt64("injector", 0)
  1492. bloodlines, _ := c.GetInt64("bloodlines", 0)
  1493. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  1494. safe_package, _ := c.GetInt64("package", 0)
  1495. a_liquid, _ := c.GetInt64("a_liquid", 0)
  1496. pre_impulse, parseDateErr := c.GetFloat("pre_impulse", 0)
  1497. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  1498. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  1499. blood := c.GetString("blood")
  1500. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  1501. dialysis_irrigation := c.GetString("dialysis_irrigation")
  1502. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  1503. displace_speed := c.GetString("displace_speed")
  1504. illness, _ := c.GetInt64("illness")
  1505. amylaceum := c.GetString("amylaceum")
  1506. single_time := c.GetString("single_time")
  1507. single_water := c.GetString("single_water")
  1508. replacement_flow := c.GetString("replacement_flow")
  1509. plasma_separator := c.GetString("plasma_separator")
  1510. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  1511. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  1512. oxygen_flow := c.GetString("oxygen_flow")
  1513. oxygen_time := c.GetString("oxygen_time")
  1514. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  1515. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  1516. puncture_needle := c.GetString("puncture_needle")
  1517. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  1518. epo := c.GetString("epo")
  1519. epo_count, _ := c.GetFloat("epo_count", 0)
  1520. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  1521. admin_user_id, _ := c.GetInt64("admin_user_id")
  1522. is_water := c.GetString("is_water")
  1523. var is_war int64
  1524. if is_water == "是" {
  1525. is_war = 1
  1526. }
  1527. if is_water == "否" {
  1528. is_war = 2
  1529. }
  1530. if is_water == "请选择" {
  1531. is_war = 0
  1532. }
  1533. drhy_water := c.GetString("drhy_water")
  1534. dry_water_hour := c.GetString("dry_water_hour")
  1535. water_machine := c.GetString("water_machine")
  1536. add_amount, _ := c.GetFloat("add_amount")
  1537. reduce_amount, _ := c.GetFloat("reduce_amount")
  1538. dialysis_remark := c.GetString("dialysis_remark")
  1539. prescribing_number, _ := c.GetFloat("prescribing_number")
  1540. prescription_sodium := c.GetString("prescription_sodium")
  1541. start_sodium := c.GetString("start_sodium")
  1542. sodium_curve := c.GetString("sodium_curve")
  1543. treatment_remark := c.GetString("treatment_remark")
  1544. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1545. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1546. prescription_water, _ := c.GetFloat("prescription_water")
  1547. dialysis_strainer := c.GetString("dialysis_strainer")
  1548. chaptalization := c.GetString("chaptalization")
  1549. washing_time := c.GetString("washing_time")
  1550. warsh_count := c.GetString("warsh_count")
  1551. blood_access_part_id := c.GetString("blood_access_part_id")
  1552. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1553. dialyzate := c.GetString("dialyzate")
  1554. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  1555. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  1556. //
  1557. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1558. // if appRole.UserType == 3 {
  1559. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1560. // if getPermissionErr != nil {
  1561. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1562. // return
  1563. // } else if headNursePermission == nil {
  1564. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1565. // return
  1566. // }
  1567. // }
  1568. //}
  1569. // 查询信息规挡的设置天数
  1570. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  1571. if infor.ID > 0 && infor.WeekDay > 0 {
  1572. var cha_time int64
  1573. timeNowStr := time.Now().Format("2006-01-02")
  1574. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1575. //今日的日期减去设置的日期
  1576. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1577. if cha_time >= recordDate.Unix() {
  1578. //查询审核是否允许
  1579. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  1580. //申请状态不允许的情况 拒绝修改
  1581. if infor.ApplicationStatus != 1 {
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1583. return
  1584. }
  1585. }
  1586. }
  1587. if mode_id > 0 {
  1588. var str string
  1589. //查找该机构用的是什么透析器
  1590. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  1591. if filedConfig.ID > 0 {
  1592. str = dialyzerPerfusionApparatus
  1593. } else {
  1594. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1595. }
  1596. service.ModifyScheduleMode(mode_id, id, recordDate.Unix(), adminUserInfo.Org.Id, str)
  1597. }
  1598. //TODO 需要根据角色去判断
  1599. prescription := models.DialysisPrescription{
  1600. UserOrgId: adminUserInfo.Org.Id,
  1601. PatientId: id,
  1602. RecordDate: recordDate.Unix(),
  1603. ModeId: mode_id,
  1604. DialysisDuration: dialysis_duration,
  1605. Dialyzer: dialyzer,
  1606. PerfusionApparatus: perfusion_apparatus,
  1607. BloodFlowVolume: blood_flow_volume,
  1608. DewaterAmount: dewater_amount,
  1609. DisplaceLiqui: displace_liqui,
  1610. ReplacementWay: replacement_way,
  1611. Anticoagulant: anticoagulant,
  1612. AnticoagulantShouji: anticoagulant_shouji,
  1613. AnticoagulantWeichi: anticoagulant_weichi,
  1614. AnticoagulantZongliang: anticoagulant_zongliang,
  1615. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1616. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1617. Kalium: kalium,
  1618. Sodium: sodium,
  1619. Calcium: calcium,
  1620. Bicarbonate: bicarbonate,
  1621. Glucose: glucose,
  1622. // DryWeight: dry_weight,
  1623. DialysateFlow: dialysate_flow,
  1624. DialysateTemperature: dialysate_temperature,
  1625. // PrescriptionDoctor: prescription_doctor,
  1626. ReplacementTotal: replacement_total,
  1627. Conductivity: conductivity,
  1628. Remark: remark,
  1629. Status: 1,
  1630. CreatedTime: time.Now().Unix(),
  1631. UpdatedTime: time.Now().Unix(),
  1632. DialysisDurationMinute: dialysisDurationMinute,
  1633. DialysisDurationHour: dialysisDurationHour,
  1634. TargetUltrafiltration: targetUltrafiltration,
  1635. DialysateFormulation: dialysateFormulation,
  1636. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1637. BodyFluid: body_fluid,
  1638. SpecialMedicine: special_medicine,
  1639. SpecialMedicineOther: special_medicine_other,
  1640. DisplaceLiquiPart: displace_liqui_part,
  1641. DisplaceLiquiValue: displace_liqui_value,
  1642. BloodAccess: blood_access,
  1643. Ultrafiltration: ultrafiltration,
  1644. BodyFluidOther: body_fluid_other,
  1645. Niprocart: niprocart,
  1646. Jms: jms,
  1647. FistulaNeedleSet: fistula_needle_set,
  1648. FistulaNeedleSet16: fistula_needle_set_16,
  1649. Hemoperfusion: hemoperfusion,
  1650. DialyserSterilised: dialyser_sterilised,
  1651. Filtryzer: filtryzer,
  1652. Dialyzers: dialyzers,
  1653. Injector: injector,
  1654. Bloodlines: bloodlines,
  1655. TubingHemodialysis: tubing_hemodialysis,
  1656. Package: safe_package,
  1657. ALiquid: a_liquid,
  1658. TargetKtv: target_ktv,
  1659. PreImpulse: pre_impulse,
  1660. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1661. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1662. Blood: blood,
  1663. DialysisDialyszers: dialysis_dialyszers,
  1664. DialysisIrrigation: dialysis_irrigation,
  1665. AntioxidantCommodityName: antioxidant_commodity_name,
  1666. DisplaceSpeed: displace_speed,
  1667. Illness: illness,
  1668. Amylaceum: amylaceum,
  1669. SingleTime: single_time,
  1670. SingleWater: single_water,
  1671. ReplacementFlow: replacement_flow,
  1672. PlasmaSeparator: plasma_separator,
  1673. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1674. OxygenUptake: oxygen_uptake,
  1675. OxygenFlow: oxygen_flow,
  1676. OxygenTime: oxygen_time,
  1677. HemodialysisPipelines: hemodialysis_pipelines,
  1678. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1679. PunctureNeedle: puncture_needle,
  1680. PunctureNeedleCount: puncture_needle_count,
  1681. Epo: epo,
  1682. EpoCount: epo_count,
  1683. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1684. AdminUserId: admin_user_id,
  1685. IsWater: is_war,
  1686. DrhyWater: drhy_water,
  1687. DryWaterHour: dry_water_hour,
  1688. WaterMachine: water_machine,
  1689. AddAmount: add_amount,
  1690. ReduceAmount: reduce_amount,
  1691. DialysisRemark: dialysis_remark,
  1692. PrescribingNumber: prescribing_number,
  1693. StartSodium: start_sodium,
  1694. SodiumCurve: sodium_curve,
  1695. TreatmentRemark: treatment_remark,
  1696. PrescriptionSodium: prescription_sodium,
  1697. DialysisFluidFlow: dialysis_fluid_flow,
  1698. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1699. PrescriptionWater: prescription_water,
  1700. DialysisStrainer: dialysis_strainer,
  1701. Chaptalization: chaptalization,
  1702. WashingTime: washing_time,
  1703. WarshCount: warsh_count,
  1704. BloodAccessPartId: blood_access_part_id,
  1705. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1706. Dialyzate: dialyzate,
  1707. }
  1708. //查询最近透析准备表里是否存在 透析器 灌流器
  1709. //
  1710. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1711. //
  1712. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1713. //
  1714. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  1715. //if len(mation)>0{
  1716. // for _, item := range splitStr {
  1717. // for _,it := range mation{
  1718. // if(item == it.SpecificationName){
  1719. //
  1720. // //查询最近一次的透析器
  1721. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1722. //
  1723. // if errcode == gorm.ErrRecordNotFound{
  1724. // //插入数据
  1725. // prepare := models.DialysisBeforePrepare{
  1726. // UserOrgId: adminUserInfo.Org.Id,
  1727. // PatientId: id,
  1728. // RecordDate: recordDate.Unix(),
  1729. // GoodTypeId: it.GoodTypeId,
  1730. // GoodId: it.ID,
  1731. // Count: 1,
  1732. // Ctime: time.Now().Unix(),
  1733. // Creater: adminUserInfo.AdminUser.Id,
  1734. // Status:1,
  1735. //
  1736. // }
  1737. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1738. // fmt.Println("",errcode)
  1739. // }
  1740. // }
  1741. // }
  1742. //
  1743. // }
  1744. //
  1745. // for _, item := range splitIrrigation {
  1746. // for _,it := range mation{
  1747. // if(item == it.SpecificationName){
  1748. // //查询最近一次的透析器
  1749. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  1750. // if errcode == gorm.ErrRecordNotFound{
  1751. // //插入数据
  1752. // prepare := models.DialysisBeforePrepare{
  1753. // UserOrgId: adminUserInfo.Org.Id,
  1754. // PatientId: id,
  1755. // RecordDate: recordDate.Unix(),
  1756. // GoodTypeId: it.GoodTypeId,
  1757. // GoodId: it.ID,
  1758. // Count: 1,
  1759. // Ctime: time.Now().Unix(),
  1760. // Creater: adminUserInfo.AdminUser.Id,
  1761. // Status:1,
  1762. //
  1763. // }
  1764. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1765. // fmt.Println(errcode)
  1766. // }
  1767. // }
  1768. // }
  1769. // }
  1770. //}
  1771. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1772. if dialysisPrescription.ID == 0 { //新增
  1773. if appRole.UserType == 2 || appRole.UserType == 1 {
  1774. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1775. }
  1776. prescription.Creater = adminUserInfo.AdminUser.Id
  1777. //针对河间咸得
  1778. if adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 3877 {
  1779. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1780. prescription.DisplaceLiquiPart = 0
  1781. prescription.DisplaceLiquiValue = 0
  1782. }
  1783. }
  1784. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  1785. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1786. }
  1787. err := service.AddSigleRecord(&prescription)
  1788. //记录日志
  1789. byterequest, _ := json.Marshal(prescription)
  1790. prescriptionLog := models.XtDialysisPrescriptionLog{
  1791. UserOrgId: prescription.UserOrgId,
  1792. Ctime: time.Now().Unix(),
  1793. Mtime: 0,
  1794. ErrLog: string(byterequest),
  1795. AdminUserId: adminUserInfo.AdminUser.Id,
  1796. RecordDate: prescription.RecordDate,
  1797. PatientId: prescription.PatientId,
  1798. Source: "手机端新增保存处方",
  1799. Status: 1,
  1800. }
  1801. service.CreatePrescriptionLog(prescriptionLog)
  1802. finish := models.XtDialysisFinish{
  1803. IsFinish: 1,
  1804. UserOrgId: adminUserInfo.Org.Id,
  1805. Status: 1,
  1806. Ctime: time.Now().Unix(),
  1807. Mtime: 0,
  1808. Module: 1,
  1809. RecordDate: recordDate.Unix(),
  1810. Sourse: 1,
  1811. PatientId: id,
  1812. }
  1813. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  1814. if dialysisFinish.ID == 0 {
  1815. service.CreateDialysisFinish(finish)
  1816. }
  1817. //长沙南雅医院,自动生成抗凝剂的临时处方
  1818. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  1819. if prescribing_number == 0 {
  1820. prescribing_number = 1
  1821. }
  1822. if prescribing_number == 0 && id == 14682 {
  1823. prescribing_number = 2
  1824. }
  1825. if prescribing_number == 0 && id == 18560 {
  1826. prescribing_number = 2
  1827. }
  1828. advice := models.DoctorAdvice{
  1829. UserOrgId: adminUserInfo.Org.Id,
  1830. PatientId: id,
  1831. GroupNo: 0,
  1832. AdviceType: 2,
  1833. RecordDate: recordDate.Unix(),
  1834. AdviceDate: recordDate.Unix(),
  1835. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1836. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1837. AdviceDesc: "",
  1838. ReminderDate: 0,
  1839. SingleDose: anticoagulant_zongliang,
  1840. SingleDoseUnit: "iu",
  1841. DrugSpec: 0,
  1842. DrugSpecUnit: "",
  1843. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1844. PrescribingNumberUnit: "支",
  1845. DeliveryWay: "静脉注射",
  1846. ExecutionFrequency: "上机前",
  1847. AdviceDoctor: 0,
  1848. Status: 1,
  1849. CreatedTime: time.Now().Unix(),
  1850. UpdatedTime: time.Now().Unix(),
  1851. IsPrescription: 1,
  1852. ExecutionState: 2,
  1853. StopState: 2,
  1854. IsSettle: 2,
  1855. }
  1856. // 查询排班信息
  1857. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  1858. if schedulePatient.ID > 0 {
  1859. if schedulePatient.ScheduleType == 1 {
  1860. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1861. }
  1862. if schedulePatient.ScheduleType == 2 {
  1863. advice.StartTime = recordDate.Unix() + 10*60*60
  1864. }
  1865. }
  1866. // 抗凝剂名称
  1867. switch anticoagulant {
  1868. case 1:
  1869. advice.AdviceName = "无肝素"
  1870. break
  1871. case 2:
  1872. advice.AdviceName = "普通肝素"
  1873. break
  1874. case 3:
  1875. advice.AdviceName = "低分子肝素"
  1876. break
  1877. case 4:
  1878. advice.AdviceName = "阿加曲班"
  1879. break
  1880. case 5:
  1881. advice.AdviceName = "枸橼酸钠"
  1882. break
  1883. case 6:
  1884. advice.AdviceName = "低分子肝素钙"
  1885. break
  1886. case 7:
  1887. advice.AdviceName = "低分子肝素钠"
  1888. break
  1889. case 8:
  1890. advice.AdviceName = "依诺肝素"
  1891. break
  1892. case 9:
  1893. advice.AdviceName = "达肝素"
  1894. break
  1895. case 10:
  1896. advice.AdviceName = "体外抗凝"
  1897. break
  1898. case 11:
  1899. advice.AdviceName = "那曲肝素"
  1900. break
  1901. case 12:
  1902. advice.AdviceName = "无抗凝剂"
  1903. break
  1904. }
  1905. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1906. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  1907. advice.AdviceDoctor = appRole.AdminUserId
  1908. }
  1909. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1910. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  1911. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1912. advice.AdviceName = "低分子肝素钠注射液"
  1913. // 修改患者临时医嘱里的抗凝剂医嘱
  1914. advice.ID = advicePrescription.ID
  1915. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1916. } else {
  1917. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1918. advice.AdviceName = "低分子肝素钠注射液"
  1919. // 新增患者临时医嘱里的抗凝剂医嘱
  1920. service.CreateDoctorAdvice(&advice)
  1921. }
  1922. }
  1923. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1924. redis := service.RedisClient()
  1925. defer redis.Close()
  1926. //清空key 值
  1927. redis.Set(key, "", time.Second)
  1928. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1929. redis.Set(keyOne, "", time.Second)
  1930. }
  1931. //获取key,清空redis
  1932. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1933. redis := service.RedisClient()
  1934. //清空key 值
  1935. redis.Set(key, "", time.Second)
  1936. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1937. //清空key 值
  1938. redis.Set(keyOne, "", time.Second)
  1939. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1940. //清空key 值
  1941. redis.Set(keyTwo, "", time.Second)
  1942. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1943. redis.Set(keySix, "", time.Second)
  1944. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1945. redis.Set(keySeven, "", time.Second)
  1946. if err == nil {
  1947. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  1948. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe_by_mode"
  1949. //清空key 值
  1950. redis.Set(keyThree, "", time.Second)
  1951. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":system_dialysis_prescribe"
  1952. //清空key 值
  1953. redis.Set(keyFour, "", time.Second)
  1954. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  1955. redis.Set(keyFive, "", time.Second)
  1956. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1957. redis.Set(keySix, "", time.Second)
  1958. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  1959. redis.Set(keySeven, "", time.Second)
  1960. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  1961. //清空key 值
  1962. redis.Set(keyOne, "", time.Second)
  1963. if updateErr != nil {
  1964. utils.ErrorLog("%v", updateErr)
  1965. }
  1966. defer redis.Close()
  1967. c.ServeSuccessJSON(map[string]interface{}{
  1968. "prescription": prescription,
  1969. })
  1970. }
  1971. } else { //修改
  1972. //if mode_id > 0 {
  1973. // service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id)
  1974. //}
  1975. //if template.TemplateId == 1 {
  1976. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1977. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1978. // if getPermissionErr != nil {
  1979. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1980. // return
  1981. // } else if headNursePermission == nil {
  1982. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePrescriptionPermissionDeniedModify)
  1983. // return
  1984. // }
  1985. // }
  1986. //}
  1987. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1988. prescription.Modifier = adminUserInfo.AdminUser.Id
  1989. if appRole.UserType == 2 || appRole.UserType == 1 {
  1990. prescription_doctor := adminUserInfo.AdminUser.Id
  1991. prescription.PrescriptionDoctor = prescription_doctor
  1992. } else {
  1993. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1994. }
  1995. if dialysisPrescription.Creater == 0 { //体重称
  1996. prescription.Creater = adminUserInfo.AdminUser.Id
  1997. } else {
  1998. prescription.Creater = dialysisPrescription.Creater
  1999. if adminUserInfo.Org.Id == 9882 {
  2000. if appRole.UserType == 2 || appRole.UserType == 1 {
  2001. prescription_doctor := adminUserInfo.AdminUser.Id
  2002. prescription.PrescriptionDoctor = prescription_doctor
  2003. prescription.Creater = prescription_doctor
  2004. }
  2005. }
  2006. }
  2007. prescription.ID = dialysisPrescription.ID
  2008. err := service.UpDateDialysisPrescription(&prescription)
  2009. //记录日志
  2010. byterequest, _ := json.Marshal(prescription)
  2011. prescriptionLog := models.XtDialysisPrescriptionLog{
  2012. UserOrgId: prescription.UserOrgId,
  2013. Ctime: time.Now().Unix(),
  2014. Mtime: 0,
  2015. ErrLog: string(byterequest),
  2016. AdminUserId: adminUserInfo.AdminUser.Id,
  2017. RecordDate: prescription.RecordDate,
  2018. PatientId: prescription.PatientId,
  2019. Source: "手机端修改处方",
  2020. Status: 1,
  2021. }
  2022. service.CreatePrescriptionLog(prescriptionLog)
  2023. finish := models.XtDialysisFinish{
  2024. IsFinish: 1,
  2025. UserOrgId: adminUserInfo.Org.Id,
  2026. Status: 1,
  2027. Ctime: time.Now().Unix(),
  2028. Mtime: 0,
  2029. Module: 1,
  2030. RecordDate: recordDate.Unix(),
  2031. Sourse: 1,
  2032. PatientId: id,
  2033. }
  2034. dialysisFinish, err := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  2035. if dialysisFinish.ID == 0 {
  2036. service.CreateDialysisFinish(finish)
  2037. }
  2038. //修改处方
  2039. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  2040. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  2041. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  2042. if advicePrescription.ID > 0 {
  2043. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  2044. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  2045. redis := service.RedisClient()
  2046. defer redis.Close()
  2047. //清空key 值
  2048. redis.Set(key, "", time.Second)
  2049. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  2050. redis.Set(keyOne, "", time.Second)
  2051. }
  2052. }
  2053. //获取key,清空redis
  2054. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2055. redis := service.RedisClient()
  2056. //清空key 值
  2057. redis.Set(key, "", time.Second)
  2058. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2059. //清空key 值
  2060. redis.Set(keyOne, "", time.Second)
  2061. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2062. redis.Set(keySix, "", time.Second)
  2063. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  2064. redis.Set(keySeven, "", time.Second)
  2065. if err == nil {
  2066. updateErr := service.UpdateScheduleModeId(patient.ID, adminUserInfo.Org.Id, recordDate.Unix(), mode_id)
  2067. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2068. //清空key 值
  2069. redis.Set(keyOne, "", time.Second)
  2070. defer redis.Close()
  2071. if updateErr != nil {
  2072. utils.ErrorLog("%v", updateErr)
  2073. }
  2074. c.ServeSuccessJSON(map[string]interface{}{
  2075. "prescription": prescription,
  2076. })
  2077. }
  2078. }
  2079. }
  2080. func (c *DialysisAPIController) Finish() {
  2081. id, _ := c.GetInt64("patient", 0)
  2082. recordDateStr := c.GetString("record_date")
  2083. nurseID, _ := c.GetInt64("nurse")
  2084. end_time := c.GetString("end_time")
  2085. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  2086. internal_fistula := c.GetString("blood_access_internal_fistula")
  2087. catheter := c.GetString("catheter")
  2088. cruor := c.GetString("cruor")
  2089. mission := c.GetString("mission")
  2090. condenser := c.GetString("condenser")
  2091. if id <= 0 || nurseID <= 0 {
  2092. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2093. return
  2094. }
  2095. adminUserInfo := c.GetMobileAdminUserInfo()
  2096. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  2097. if patient.ID == 0 {
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2099. return
  2100. }
  2101. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2102. if getNurseErr != nil {
  2103. c.ErrorLog("获取护士失败:%v", getNurseErr)
  2104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2105. return
  2106. } else if nurse == nil {
  2107. c.ErrorLog("护士不存在")
  2108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2109. return
  2110. }
  2111. if len(recordDateStr) == 0 {
  2112. recordDateStr = time.Now().Format("2006-01-02")
  2113. }
  2114. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2115. if parseDateErr != nil {
  2116. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2118. return
  2119. }
  2120. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  2121. if parseEndDateErr != nil {
  2122. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  2123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2124. return
  2125. }
  2126. // 查询信息规挡的设置天数
  2127. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2128. if infor.ID > 0 && infor.WeekDay > 0 {
  2129. var cha_time int64
  2130. timeNowStr := time.Now().Format("2006-01-02")
  2131. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2132. //今日的日期减去设置的日期
  2133. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2134. if cha_time >= recordDate.Unix() {
  2135. //查询审核是否允许
  2136. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 8)
  2137. //申请状态不允许的情况 拒绝修改
  2138. if infor.ApplicationStatus != 1 {
  2139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2140. return
  2141. }
  2142. }
  2143. }
  2144. //now := time.Now()
  2145. //year, month, day := now.Date()
  2146. //today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2147. //todayTimeStamp := today_time.Unix()
  2148. // 获取当天的第一条透析纪录
  2149. fmonitorRecords, getMonitorRecordsErr := service.MobileGetMonitorRecordFirst(adminUserInfo.Org.Id, id, recordDate.Unix())
  2150. if getMonitorRecordsErr != nil {
  2151. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2153. return
  2154. }
  2155. // 获取当前的最后一条透析纪录
  2156. endmonitorRecords, getMonitorRecordsErr := service.MobileGetLastMonitorRecordOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2157. if getMonitorRecordsErr != nil {
  2158. c.ErrorLog("获取透析监测记录失败:%v", getMonitorRecordsErr)
  2159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2160. return
  2161. }
  2162. fmt.Println(endmonitorRecords.UltrafiltrationVolume)
  2163. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2164. if getAADErr != nil {
  2165. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  2166. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2167. return
  2168. }
  2169. lastAssessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2170. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, recordDate.Unix())
  2171. var tempassessmentAfterDislysis models.AssessmentAfterDislysis
  2172. if assessmentAfterDislysis != nil {
  2173. tempassessmentAfterDislysis = *assessmentAfterDislysis
  2174. tempassessmentAfterDislysis.UpdatedTime = time.Now().Unix()
  2175. } else {
  2176. tempassessmentAfterDislysis.CreatedTime = time.Now().Unix()
  2177. tempassessmentAfterDislysis.AssessmentDate = recordDate.Unix()
  2178. tempassessmentAfterDislysis.Status = 1
  2179. tempassessmentAfterDislysis.PatientId = id
  2180. tempassessmentAfterDislysis.UserOrgId = adminUserInfo.Org.Id
  2181. }
  2182. //长沙南雅
  2183. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 9675 || adminUserInfo.Org.Id == 10340 {
  2184. //获取最后一条透析处方数据
  2185. prescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2186. evaluation, _ := service.MobileGetPredialysisEvaluationTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2187. tempassessmentAfterDislysis.WeightAfter = evaluation.WeightBefore - prescription.TargetUltrafiltration/1000
  2188. }
  2189. if dialysisOrder.Stage == 1 {
  2190. temp_time := (float64(endDate.Unix()) - float64(dialysisOrder.StartTime)) / 3600
  2191. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  2192. fmt.Println(value)
  2193. a, b := math.Modf(value)
  2194. c, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  2195. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  2196. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", c*60), 10, 64)
  2197. tempassessmentAfterDislysis.ActualTreatmentHour = hour
  2198. tempassessmentAfterDislysis.ActualTreatmentMinute = minute
  2199. }
  2200. if fmonitorRecords.ID > 0 && endmonitorRecords.ID > 0 {
  2201. //var num1 int64
  2202. //num1 = endmonitorRecords.OperateTime - fmonitorRecords.OperateTime
  2203. //fmt.Println(num1)
  2204. //sub := float64(num1 / 3600)
  2205. //fmt.Println(sub)
  2206. //tempassessmentAfterDislysis.ActualTreatmentHour = int64(math.Floor(sub))
  2207. //sub2 := float64(((endmonitorRecords.OperateTime - fmonitorRecords.OperateTime) % 3600) / 60)
  2208. //tempassessmentAfterDislysis.ActualTreatmentMinute = int64(math.Floor(sub2))
  2209. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2210. tempassessmentAfterDislysis.PulseFrequency = endmonitorRecords.PulseFrequency
  2211. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2212. if adminUserInfo.Org.Id != 10375 {
  2213. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2214. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2215. }
  2216. if adminUserInfo.Org.Id != 10445 {
  2217. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2218. }
  2219. //北方营口医院
  2220. if adminUserInfo.Org.Id == 10445 {
  2221. //获取最后一条透析处方数据
  2222. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2223. tempassessmentAfterDislysis.ActualDisplacement = lastprescription.DisplaceLiquiValue
  2224. } else {
  2225. tempassessmentAfterDislysis.ActualDisplacement = endmonitorRecords.DisplacementQuantity
  2226. }
  2227. //新化博翔
  2228. if adminUserInfo.Org.Id == 10447 {
  2229. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2230. }
  2231. //阳春
  2232. if adminUserInfo.Org.Id == 10485 {
  2233. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2234. }
  2235. if adminUserInfo.Org.Id == 10551 {
  2236. //获取最后一条透析处方数据
  2237. lastprescription, _ := service.GetLastDialysisPrescriptionByPatientIdTwo(adminUserInfo.Org.Id, id, recordDate.Unix())
  2238. tempassessmentAfterDislysis.ActualUltrafiltration = lastprescription.TargetUltrafiltration * 1000
  2239. }
  2240. if adminUserInfo.Org.Id == 10580 {
  2241. tempassessmentAfterDislysis.ActualUltrafiltration = 0
  2242. }
  2243. }
  2244. 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 {
  2245. evaluation, _ := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, recordDate.Unix())
  2246. if evaluation.SystolicBloodPressure == 0 {
  2247. evaluation.SystolicBloodPressure = fmonitorRecords.SystolicBloodPressure
  2248. pre := models.PredialysisEvaluation{
  2249. SystolicBloodPressure: evaluation.SystolicBloodPressure,
  2250. }
  2251. fmt.Println("prew", pre)
  2252. getNurseErr := service.UpdatePredialysisEvaluation(&pre, evaluation.ID)
  2253. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2254. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2255. redis := service.RedisClient()
  2256. redis.Set(key, "", time.Second)
  2257. redis.Set(keyOne, "", time.Second)
  2258. defer redis.Close()
  2259. fmt.Println(getNurseErr)
  2260. }
  2261. if evaluation.DiastolicBloodPressure == 0 {
  2262. evaluation.DiastolicBloodPressure = fmonitorRecords.DiastolicBloodPressure
  2263. pres := models.PredialysisEvaluation{
  2264. DiastolicBloodPressure: evaluation.DiastolicBloodPressure,
  2265. }
  2266. getNurseErr := service.UpdatePredialysisEvaluationTwo(&pres, evaluation.ID)
  2267. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2268. redis := service.RedisClient()
  2269. redis.Set(key, "", time.Second)
  2270. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2271. redis.Set(keyOne, "", time.Second)
  2272. defer redis.Close()
  2273. fmt.Println(getNurseErr)
  2274. }
  2275. if evaluation.PulseFrequency == 0 {
  2276. evaluation.PulseFrequency = fmonitorRecords.PulseFrequency
  2277. press := models.PredialysisEvaluation{
  2278. PulseFrequency: evaluation.PulseFrequency,
  2279. }
  2280. getNurseErr := service.UpdatePredialysisEvaluationThree(&press, evaluation.ID)
  2281. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2282. redis := service.RedisClient()
  2283. redis.Set(key, "", time.Second)
  2284. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2285. redis.Set(keyOne, "", time.Second)
  2286. defer redis.Close()
  2287. fmt.Println(getNurseErr)
  2288. }
  2289. if evaluation.Temperature == 0 {
  2290. evaluation.Temperature = fmonitorRecords.Temperature
  2291. press := models.PredialysisEvaluation{
  2292. Temperature: evaluation.Temperature,
  2293. }
  2294. getNurseErr := service.UpdatePredialysisEvaluationFour(&press, evaluation.ID)
  2295. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2296. redis := service.RedisClient()
  2297. redis.Set(key, "", time.Second)
  2298. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2299. redis.Set(keyOne, "", time.Second)
  2300. defer redis.Close()
  2301. fmt.Println(getNurseErr)
  2302. }
  2303. }
  2304. if adminUserInfo.Org.Id == 9583 {
  2305. //获取透析处方的最后一条数据
  2306. diaPrescription, diaerr := service.GetLastDialysisPrescriptionByPatientId(adminUserInfo.Org.Id, id, recordDate.Unix())
  2307. if diaerr != nil {
  2308. c.ErrorLog("获取透析处方失败:%v", diaerr)
  2309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2310. return
  2311. }
  2312. if diaPrescription.ID > 0 && adminUserInfo.Org.Id == 9583 {
  2313. tempassessmentAfterDislysis.ActualUltrafiltration = diaPrescription.TargetUltrafiltration
  2314. }
  2315. }
  2316. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10101 {
  2317. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2318. }
  2319. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10233 {
  2320. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume / 1000
  2321. }
  2322. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10060 {
  2323. tempassessmentAfterDislysis.ActualUltrafiltration = endmonitorRecords.UltrafiltrationVolume
  2324. }
  2325. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 9829 {
  2326. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2327. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2328. }
  2329. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10432 {
  2330. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2331. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2332. }
  2333. if endmonitorRecords.ID > 0 && adminUserInfo.Org.Id == 10495 {
  2334. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2335. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2336. tempassessmentAfterDislysis.Temperature = endmonitorRecords.Temperature
  2337. tempassessmentAfterDislysis.BreathingRate = endmonitorRecords.BreathingRate
  2338. }
  2339. if lastAssessmentAfterDislysis != nil {
  2340. tempassessmentAfterDislysis.BloodPressureType = lastAssessmentAfterDislysis.BloodPressureType
  2341. tempassessmentAfterDislysis.WeighingWay = lastAssessmentAfterDislysis.WeighingWay
  2342. tempassessmentAfterDislysis.Cruor = lastAssessmentAfterDislysis.Cruor
  2343. tempassessmentAfterDislysis.SymptomAfterDialysis = lastAssessmentAfterDislysis.SymptomAfterDialysis
  2344. tempassessmentAfterDislysis.InternalFistula = lastAssessmentAfterDislysis.InternalFistula
  2345. tempassessmentAfterDislysis.Catheter = lastAssessmentAfterDislysis.Catheter
  2346. tempassessmentAfterDislysis.Complication = lastAssessmentAfterDislysis.Complication
  2347. tempassessmentAfterDislysis.DialysisIntakes = lastAssessmentAfterDislysis.DialysisIntakes
  2348. tempassessmentAfterDislysis.DialysisIntakesFeed = lastAssessmentAfterDislysis.DialysisIntakesFeed
  2349. tempassessmentAfterDislysis.DialysisIntakesTransfusion = lastAssessmentAfterDislysis.DialysisIntakesTransfusion
  2350. tempassessmentAfterDislysis.DialysisIntakesBloodTransfusion = lastAssessmentAfterDislysis.DialysisIntakesBloodTransfusion
  2351. tempassessmentAfterDislysis.DialysisIntakesWashpipe = lastAssessmentAfterDislysis.DialysisIntakesWashpipe
  2352. tempassessmentAfterDislysis.BloodAccessPartId = lastAssessmentAfterDislysis.BloodAccessPartId
  2353. tempassessmentAfterDislysis.BloodAccessPartOperaId = lastAssessmentAfterDislysis.BloodAccessPartOperaId
  2354. tempassessmentAfterDislysis.PuncturePointOozingBlood = lastAssessmentAfterDislysis.PuncturePointOozingBlood
  2355. tempassessmentAfterDislysis.PuncturePointHaematoma = lastAssessmentAfterDislysis.PuncturePointHaematoma
  2356. tempassessmentAfterDislysis.InternalFistulaTremorAc = lastAssessmentAfterDislysis.InternalFistulaTremorAc
  2357. tempassessmentAfterDislysis.PatientGose = lastAssessmentAfterDislysis.PatientGose
  2358. tempassessmentAfterDislysis.InpatientDepartment = lastAssessmentAfterDislysis.InpatientDepartment
  2359. tempassessmentAfterDislysis.ObservationContent = lastAssessmentAfterDislysis.ObservationContent
  2360. tempassessmentAfterDislysis.ObservationContentOther = lastAssessmentAfterDislysis.ObservationContentOther
  2361. tempassessmentAfterDislysis.DryWeight = lastAssessmentAfterDislysis.DryWeight
  2362. tempassessmentAfterDislysis.DialysisProcess = lastAssessmentAfterDislysis.DialysisProcess
  2363. tempassessmentAfterDislysis.InAdvanceMinute = lastAssessmentAfterDislysis.InAdvanceMinute
  2364. tempassessmentAfterDislysis.InAdvanceReason = lastAssessmentAfterDislysis.InAdvanceReason
  2365. tempassessmentAfterDislysis.HemostasisMinute = lastAssessmentAfterDislysis.HemostasisMinute
  2366. tempassessmentAfterDislysis.HemostasisOpera = lastAssessmentAfterDislysis.HemostasisOpera
  2367. tempassessmentAfterDislysis.TremorNoise = lastAssessmentAfterDislysis.TremorNoise
  2368. tempassessmentAfterDislysis.DisequilibriumSyndrome = lastAssessmentAfterDislysis.DisequilibriumSyndrome
  2369. tempassessmentAfterDislysis.DisequilibriumSyndromeOption = lastAssessmentAfterDislysis.DisequilibriumSyndromeOption
  2370. tempassessmentAfterDislysis.ArterialTube = lastAssessmentAfterDislysis.ArterialTube
  2371. tempassessmentAfterDislysis.IntravenousTube = lastAssessmentAfterDislysis.IntravenousTube
  2372. tempassessmentAfterDislysis.Dialyzer = lastAssessmentAfterDislysis.Dialyzer
  2373. tempassessmentAfterDislysis.InAdvanceReasonOther = lastAssessmentAfterDislysis.InAdvanceReasonOther
  2374. tempassessmentAfterDislysis.IsEat = lastAssessmentAfterDislysis.IsEat
  2375. tempassessmentAfterDislysis.DialysisIntakesUnit = lastAssessmentAfterDislysis.DialysisIntakesUnit
  2376. tempassessmentAfterDislysis.CvcA = lastAssessmentAfterDislysis.CvcA
  2377. tempassessmentAfterDislysis.CvcV = lastAssessmentAfterDislysis.CvcV
  2378. tempassessmentAfterDislysis.Channel = lastAssessmentAfterDislysis.Channel
  2379. tempassessmentAfterDislysis.ReturnBlood = lastAssessmentAfterDislysis.ReturnBlood
  2380. tempassessmentAfterDislysis.RehydrationVolume = lastAssessmentAfterDislysis.RehydrationVolume
  2381. tempassessmentAfterDislysis.DialysisDuring = lastAssessmentAfterDislysis.DialysisDuring
  2382. tempassessmentAfterDislysis.StrokeVolume = lastAssessmentAfterDislysis.StrokeVolume
  2383. tempassessmentAfterDislysis.BloodFlow = lastAssessmentAfterDislysis.BloodFlow
  2384. tempassessmentAfterDislysis.SealingFluidDispose = lastAssessmentAfterDislysis.SealingFluidDispose
  2385. tempassessmentAfterDislysis.SealingFluidSpecial = lastAssessmentAfterDislysis.SealingFluidSpecial
  2386. if tempassessmentAfterDislysis.PatientId == 18695 {
  2387. tempassessmentAfterDislysis.ActualDisplacement = 0
  2388. }
  2389. if adminUserInfo.Org.Id != 10375 {
  2390. tempassessmentAfterDislysis.SystolicBloodPressure = endmonitorRecords.SystolicBloodPressure
  2391. tempassessmentAfterDislysis.DiastolicBloodPressure = endmonitorRecords.DiastolicBloodPressure
  2392. }
  2393. }
  2394. finish := models.XtDialysisFinish{
  2395. IsFinish: 1,
  2396. UserOrgId: adminUserInfo.Org.Id,
  2397. Status: 1,
  2398. Ctime: time.Now().Unix(),
  2399. Mtime: 0,
  2400. Module: 9,
  2401. RecordDate: tempassessmentAfterDislysis.AssessmentDate,
  2402. Sourse: 1,
  2403. PatientId: tempassessmentAfterDislysis.PatientId,
  2404. }
  2405. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, tempassessmentAfterDislysis.AssessmentDate, 9, tempassessmentAfterDislysis.PatientId)
  2406. if dialysisFinish.ID == 0 {
  2407. service.CreateDialysisFinish(finish)
  2408. }
  2409. err := service.UpdateAssessmentAfterDislysisRecord(&tempassessmentAfterDislysis)
  2410. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2411. redis := service.RedisClient()
  2412. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2413. redis.Set(keyOne, "", time.Second)
  2414. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_last"
  2415. redis.Set(keyTwo, "", time.Second)
  2416. defer redis.Close()
  2417. //清空key 值
  2418. redis.Set(key, "", time.Second)
  2419. if err != nil {
  2420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2421. return
  2422. }
  2423. if dialysisOrder == nil {
  2424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoStart)
  2425. return
  2426. }
  2427. if dialysisOrder.Stage == 2 {
  2428. c.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderNoEND)
  2429. return
  2430. }
  2431. if dialysisOrder.Stage == 1 {
  2432. err := service.ModifyDialysisRecord(dialysisOrder.ID, nurseID, endDate.Unix(), adminUserInfo.AdminUser.Id, puncture_point_haematoma, internal_fistula, catheter, cruor, mission, condenser)
  2433. finish := models.XtDialysisFinish{
  2434. IsFinish: 1,
  2435. UserOrgId: adminUserInfo.Org.Id,
  2436. Status: 1,
  2437. Ctime: time.Now().Unix(),
  2438. Mtime: 0,
  2439. Module: 8,
  2440. RecordDate: recordDate.Unix(),
  2441. Sourse: 1,
  2442. PatientId: id,
  2443. }
  2444. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 8, id)
  2445. if dialysisFinish.ID == 0 {
  2446. service.CreateDialysisFinish(finish)
  2447. }
  2448. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2449. redis := service.RedisClient()
  2450. defer redis.Close()
  2451. //清空key 值
  2452. redis.Set(key, "", time.Second)
  2453. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2454. redis.Set(keyOne, "", time.Second)
  2455. //结束时候透析次数加1
  2456. service.UpdateSolutionByPatientId(id)
  2457. //下机完自动消毒,针对长沙南雅
  2458. if dialysisOrder.Stage == 1 {
  2459. 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 {
  2460. //根据床位号获取设备型号
  2461. unitType, _ := service.GetUnitType(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2462. //查询使用消毒最后一条消毒记录
  2463. _, err := service.GetLaseDeviceInfomation(dialysisOrder.UserOrgId, dialysisOrder.BedID, dialysisOrder.DialysisDate, dialysisOrder.SchedualType)
  2464. fmt.Println("err", err)
  2465. if err == gorm.ErrRecordNotFound {
  2466. //查找排班
  2467. scheduleByPatient, _ := service.GetScheduleByPatient(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2468. //查询改设备是否有消毒计划
  2469. plan, errcode := service.GetDisInfectionTime(dialysisOrder.UserOrgId, unitType.UnitType, dialysisOrder.SchedualType, scheduleByPatient.ScheduleWeek)
  2470. //根据床位号获取设备id
  2471. addmacher, _ := service.GetEquimentIDTwo(dialysisOrder.BedID, dialysisOrder.UserOrgId)
  2472. //查询病人信息
  2473. patients, _ := service.GetPatientInfoMation(dialysisOrder.PatientId)
  2474. var con = ""
  2475. if patients.IsInfectious == 0 {
  2476. con = ""
  2477. }
  2478. if patients.IsInfectious == 1 {
  2479. con = "无"
  2480. }
  2481. if patients.IsInfectious == 2 {
  2482. con = "有"
  2483. }
  2484. if errcode == nil {
  2485. var end_time int64
  2486. end_time = endDate.Unix() + plan.DisinfecTime*60
  2487. //新增消毒
  2488. information := models.DeviceInformation{
  2489. Date: dialysisOrder.DialysisDate,
  2490. Zone: dialysisOrder.ZoneId,
  2491. Class: dialysisOrder.SchedualType,
  2492. BedNumber: dialysisOrder.BedID,
  2493. PatientId: dialysisOrder.PatientId,
  2494. DialysisMode: scheduleByPatient.ModeId,
  2495. LongTime: strconv.FormatInt(plan.DisinfecTime, 10),
  2496. Disinfection: 1,
  2497. DialysisConcentration: 1,
  2498. DisinfectionStatus: 1,
  2499. Move: 1,
  2500. UserOrgId: dialysisOrder.UserOrgId,
  2501. DisinfectType: plan.Way,
  2502. DisinfectantType: plan.MachineDisinfectant,
  2503. FluidPath: plan.DisinfectanWay, //液路消毒方式
  2504. Disinfectant: plan.Disinfectant,
  2505. Ctime: time.Now().Unix(),
  2506. Status: 1,
  2507. SignName: nurseID,
  2508. EquimentId: addmacher.ID,
  2509. DisinfectionResidue: 2,
  2510. Bed: addmacher.BedNumber,
  2511. StartTime: dialysisOrder.StartTime,
  2512. EndTime: dialysisOrder.EndTime,
  2513. Contagion: con,
  2514. WeightLoss: 0,
  2515. Hyperfiltratio: 0,
  2516. DialysisHour: "",
  2517. MachineRun: 1,
  2518. DisinfecStartime: endDate.Unix(),
  2519. DisinfecEndtime: end_time,
  2520. }
  2521. err := service.CreateInformationTwo(&information)
  2522. fmt.Println("报错", err)
  2523. }
  2524. }
  2525. }
  2526. }
  2527. dialysisOrder.Stage = 2
  2528. dialysisOrder.FinishNurse = nurseID
  2529. dialysisOrder.FinishCreator = adminUserInfo.AdminUser.Id
  2530. dialysisOrder.FinishModifier = adminUserInfo.AdminUser.Id
  2531. dialysisOrder.EndTime = endDate.Unix()
  2532. fmt.Println("ADMINWOOWOWOWOWO", adminUserInfo.Org.Id)
  2533. // 长沙南雅需求
  2534. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 9675 {
  2535. //获取最后1条监测的数据
  2536. fristrecordone, _ := service.FindFirstMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2537. lastrecord, _ := service.FindLastMonitorRecordToday(dialysisOrder.PatientId, dialysisOrder.UserOrgId, dialysisOrder.DialysisDate)
  2538. var accumulatedBloodVolume float64
  2539. accumulatedBloodVolume = (lastrecord.BloodFlowVolume - 25) * (math.Floor(float64(lastrecord.OperateTime-fristrecordone.OperateTime)/3600) * 60) / 1000
  2540. err := service.UpdateLastMonitorRecordToday(accumulatedBloodVolume, lastrecord.ID)
  2541. fmt.Println(err)
  2542. // 查询未执行的医嘱
  2543. doctorAdvice, _ := service.GetDoctorAdviceListNoExecution(dialysisOrder.PatientId, dialysisOrder.DialysisDate, dialysisOrder.UserOrgId)
  2544. fmt.Println("doctorAdviceWOWOOWOWOWOWOWOW", doctorAdvice)
  2545. for _, item := range doctorAdvice {
  2546. service.UpdateDoctorAdviceNoExecution(item.ID, dialysisOrder.FinishNurse, dialysisOrder.EndTime)
  2547. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  2548. redis := service.RedisClient()
  2549. //清空key 值
  2550. redis.Set(key, "", time.Second)
  2551. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  2552. redis.Set(keyTwo, "", time.Second)
  2553. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2554. redis.Set(keyThree, "", time.Second)
  2555. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", recordDateStr)
  2556. theTime := toTime.Format("2006-01-02")
  2557. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2558. redis.Set(keyFour, "", time.Second)
  2559. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2560. redis.Set(keyFive, "", time.Second)
  2561. defer redis.Close()
  2562. }
  2563. }
  2564. go func() {
  2565. ssoDomain := beego.AppConfig.String("call_domain")
  2566. api := ssoDomain + "/index/downpatient"
  2567. values := make(url.Values)
  2568. values.Set("org_id", strconv.FormatInt(adminUserInfo.AdminUser.Id, 10))
  2569. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  2570. values.Set("patient_id", strconv.FormatInt(id, 10))
  2571. http.PostForm(api, values)
  2572. }()
  2573. if err == nil {
  2574. c.ServeSuccessJSON(map[string]interface{}{
  2575. "dialysisOrder": dialysisOrder,
  2576. "assessmentAfterDislysis": tempassessmentAfterDislysis,
  2577. })
  2578. } else {
  2579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2580. }
  2581. }
  2582. }
  2583. func (c *DialysisAPIController) GetAllZone() {
  2584. adminUserInfo := c.GetMobileAdminUserInfo()
  2585. err, zone := service.GetAllDeviceZone(adminUserInfo.Org.Id)
  2586. if err == nil {
  2587. c.ServeSuccessJSON(map[string]interface{}{
  2588. "zone": zone,
  2589. })
  2590. }
  2591. }
  2592. func (c *DialysisAPIController) GetSchedualPatientsList() {
  2593. adminUserInfo := c.GetMobileAdminUserInfo()
  2594. page, _ := c.GetInt64("page", 1)
  2595. limit, _ := c.GetInt64("limit", 10)
  2596. schedulType, _ := c.GetInt64("schedul_type", 0)
  2597. startTime, _ := c.GetInt64("schedul_time", 0)
  2598. partitionType, _ := c.GetInt64("partition_type", 0)
  2599. keywords := c.GetString("keywords")
  2600. dialysisSchedule, err := service.GetSchedualPatientList(adminUserInfo.Org.Id, startTime/1000, schedulType, partitionType, keywords, page, limit)
  2601. if err == nil {
  2602. c.ServeSuccessJSON(map[string]interface{}{
  2603. "schedule": dialysisSchedule,
  2604. })
  2605. }
  2606. return
  2607. }
  2608. // /m/api/dialysis/start [post]
  2609. // @param patient_id:int
  2610. // @param record_date:string 排班时间 (yyyy-mm-dd)
  2611. // @param nurse:int 上机护士
  2612. // @param bed:int 床位号
  2613. func (this *DialysisAPIController) StartDialysis() {
  2614. patientID, _ := this.GetInt64("patient_id")
  2615. recordDateStr := this.GetString("record_date")
  2616. nurseID, _ := this.GetInt64("start_nurse")
  2617. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  2618. blood_drawing, _ := this.GetInt64("blood_drawing")
  2619. schedual_type, _ := this.GetInt64("schedual_type")
  2620. bedID, _ := this.GetInt64("bed")
  2621. start_time := this.GetString("start_time")
  2622. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  2623. change_nurse, _ := this.GetInt64("change_nurse")
  2624. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  2625. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  2626. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  2627. puncture_needle := this.GetString("puncture_needle")
  2628. puncture_way := this.GetString("puncture_way")
  2629. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  2630. dialysis_irrigation := this.GetString("dialysis_irrigation")
  2631. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  2632. zone_id, _ := this.GetInt64("zone_id")
  2633. elecsign := this.GetString("url")
  2634. nuclein_date_str := this.GetString("nuclein_date_str")
  2635. schedule_remark := this.GetString("schedule_remark")
  2636. order_remark := this.GetString("order_remark")
  2637. catheter_operation := this.GetString("catheter_operation")
  2638. blood_flow_volume := this.GetString("blood_flow_volume")
  2639. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  2640. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2641. return
  2642. }
  2643. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  2644. if parseStartDateErr != nil {
  2645. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  2646. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2647. return
  2648. }
  2649. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2650. if parseErr != nil {
  2651. this.ErrorLog("时间解析失败:%v", parseErr)
  2652. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2653. return
  2654. }
  2655. adminUserInfo := this.GetMobileAdminUserInfo()
  2656. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  2657. if getPatientErr != nil {
  2658. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2659. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2660. return
  2661. } else if patient == nil {
  2662. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2663. return
  2664. }
  2665. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  2666. if getNurseErr != nil {
  2667. this.ErrorLog("获取护士失败:%v", getNurseErr)
  2668. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2669. return
  2670. } else if nurse == nil {
  2671. this.ErrorLog("护士不存在")
  2672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2673. return
  2674. }
  2675. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  2676. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  2677. if getDeviceNumberErr != nil {
  2678. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  2679. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2680. return
  2681. } else if deviceNumber == nil {
  2682. this.ErrorLog("床位号不存在")
  2683. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2684. return
  2685. }
  2686. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2687. if getRecordErr != nil {
  2688. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  2689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2690. return
  2691. } else if dialysisRecord != nil {
  2692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  2693. return
  2694. }
  2695. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  2696. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  2697. timeLayout := "2006-01-02 15:04:05"
  2698. loc, _ := time.LoadLocation("Local")
  2699. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  2700. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  2701. schedulestartTime := theStartTime.Unix()
  2702. scheduleendTime := theEndTime.Unix()
  2703. var theNucleinDate int64
  2704. timeLayoutOne := "2006-01-02"
  2705. if len(nuclein_date_str) > 0 {
  2706. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  2707. if err != nil {
  2708. utils.ErrorLog(err.Error())
  2709. }
  2710. theNucleinDate = theTime.Unix()
  2711. }
  2712. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  2713. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  2714. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  2715. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2716. //查询该床位是否有人用了
  2717. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2718. if err == gorm.ErrRecordNotFound { //空床位
  2719. // 修改了床位逻辑
  2720. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2721. if daySchedule.ID > 0 {
  2722. daySchedule.PartitionId = deviceNumber.ZoneID
  2723. daySchedule.BedId = bedID
  2724. daySchedule.ScheduleType = schedual_type
  2725. daySchedule.UpdatedTime = time.Now().Unix()
  2726. xtSchedule := models.Schedule{
  2727. PartitionId: deviceNumber.ZoneID,
  2728. BedId: bedID,
  2729. ScheduleType: schedual_type,
  2730. UpdatedTime: time.Now().Unix(),
  2731. }
  2732. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2733. if err != nil {
  2734. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2735. return
  2736. }
  2737. }
  2738. } else if err == nil {
  2739. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  2740. if order.ID > 0 { //该机位被其他人占用了
  2741. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2742. return
  2743. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作
  2744. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2745. if daySchedule.ID > 0 {
  2746. err := service.UpdateScheduleTwo(daySchedule, schedule)
  2747. if err != nil {
  2748. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2749. return
  2750. }
  2751. }
  2752. }
  2753. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  2754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  2755. return
  2756. }
  2757. //else if order.ID == 0 { //该床位没被占用
  2758. // daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  2759. // if daySchedule.ID > 0 {
  2760. // //daySchedule.PartitionId = deviceNumber.ZoneID
  2761. // //daySchedule.BedId = bedID
  2762. // //daySchedule.ScheduleType = schedual_type
  2763. // //daySchedule.UpdatedTime = time.Now().Unix()
  2764. // //err := service.UpdateSchedule(&daySchedule)
  2765. // xtSchedule := models.Schedule{
  2766. // PartitionId: deviceNumber.ZoneID,
  2767. // BedId: bedID,
  2768. // ScheduleType: schedual_type,
  2769. // UpdatedTime: time.Now().Unix(),
  2770. // }
  2771. // err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  2772. // if err != nil {
  2773. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2774. // return
  2775. // }
  2776. // }
  2777. //}
  2778. //}
  2779. } else if err != nil {
  2780. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2781. return
  2782. }
  2783. // 查询信息规挡的设置天数
  2784. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  2785. if infor.ID > 0 && infor.WeekDay > 0 {
  2786. var cha_time int64
  2787. timeNowStr := time.Now().Format("2006-01-02")
  2788. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2789. //今日的日期减去设置的日期
  2790. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2791. if cha_time >= recordDate.Unix() {
  2792. //查询审核是否允许
  2793. infor, _ := service.GetDialysisInformationByRecordDate(patientID, recordDate.Unix(), adminUserInfo.Org.Id, 6)
  2794. //申请状态不允许的情况 拒绝修改
  2795. if infor.ApplicationStatus != 1 {
  2796. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2797. return
  2798. }
  2799. }
  2800. }
  2801. dialysisRecord = &models.DialysisOrder{
  2802. DialysisDate: recordDate.Unix(),
  2803. UserOrgId: adminUserInfo.Org.Id,
  2804. PatientId: patientID,
  2805. Stage: 1,
  2806. BedID: bedID,
  2807. StartNurse: nurseID,
  2808. Status: 1,
  2809. StartTime: startDate.Unix(),
  2810. CreatedTime: time.Now().Unix(),
  2811. UpdatedTime: time.Now().Unix(),
  2812. PunctureNurse: puncture_nurse,
  2813. Creator: adminUserInfo.AdminUser.Id,
  2814. Modifier: adminUserInfo.AdminUser.Id,
  2815. SchedualType: schedual_type,
  2816. WashpipeNurse: washpipe_nurse,
  2817. ChangeNurse: change_nurse,
  2818. DifficultPunctureNurse: difficult_puncture_nurse,
  2819. NewFistulaNurse: new_fistula_nurse,
  2820. ZoneId: zone_id,
  2821. QualityNurseId: quality_nurse_id,
  2822. PunctureNeedle: puncture_needle,
  2823. PunctureWay: puncture_way,
  2824. DialysisIrrigation: dialysis_irrigation,
  2825. DialysisDialyszers: dialysis_dialyszers,
  2826. BloodAccessId: blood_access_id,
  2827. Url: elecsign,
  2828. NucleinDate: theNucleinDate,
  2829. ScheduleRemark: schedule_remark,
  2830. OrderRemark: order_remark,
  2831. CatheterOperation: catheter_operation,
  2832. BloodFlowVolume: blood_flow_volume,
  2833. }
  2834. //查询该床位是否有人用了
  2835. _, errorscode := service.GetDialysisOrderByBedId(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  2836. if errorscode == gorm.ErrRecordNotFound {
  2837. createErr := service.MobileCreateDialysisOrder(adminUserInfo.Org.Id, patientID, dialysisRecord)
  2838. finish := models.XtDialysisFinish{
  2839. IsFinish: 1,
  2840. UserOrgId: adminUserInfo.Org.Id,
  2841. Status: 1,
  2842. Ctime: time.Now().Unix(),
  2843. Mtime: 0,
  2844. Module: 6,
  2845. RecordDate: schedulestartTime,
  2846. Sourse: 1,
  2847. PatientId: patientID,
  2848. }
  2849. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 6, patientID)
  2850. if dialysisFinish.ID == 0 {
  2851. service.CreateDialysisFinish(finish)
  2852. }
  2853. service.UpdateMobilePatient(adminUserInfo.Org.Id, patientID, schedule_remark)
  2854. if adminUserInfo.Org.Id != 10101 && adminUserInfo.Org.Id != 10445 && adminUserInfo.Org.Id != 3877 && adminUserInfo.Org.Id != 10345 {
  2855. //统计该患者总次数
  2856. dialysisCount, _ := service.GetDialysisTotalCount(adminUserInfo.Org.Id, patientID)
  2857. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2858. }
  2859. if adminUserInfo.Org.Id == 10101 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10345 {
  2860. //统计该患者总次数
  2861. dialysisCount, _ := service.GetDialysisTotalCountOne(adminUserInfo.Org.Id, patientID)
  2862. service.UpdateDialysisOrder(patientID, recordDate.Unix(), adminUserInfo.Org.Id, dialysisCount.Count)
  2863. }
  2864. redis := service.RedisClient()
  2865. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_order"
  2866. redis.Set(key, "", time.Second)
  2867. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_orders_list_all"
  2868. //清空key 值
  2869. redis.Set(keyOne, "", time.Second)
  2870. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  2871. //清空key 值
  2872. redis.Set(keyTwo, "", time.Second)
  2873. if createErr != nil {
  2874. this.ErrorLog("上机失败:%v", createErr)
  2875. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2876. return
  2877. }
  2878. }
  2879. newdialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2880. var tempdispose string
  2881. // 只针对中能建
  2882. if blood_drawing > 0 && adminUserInfo.Org.Id == 9538 {
  2883. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2884. }
  2885. if blood_drawing > 0 && adminUserInfo.Org.Id == 10318 {
  2886. tempdispose = "引血" + strconv.FormatInt(blood_drawing, 10) + "ml/min"
  2887. }
  2888. var ultrafiltration_rate float64
  2889. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2890. //后期预增脱水量
  2891. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, schedulestartTime, adminUserInfo.Org.Id)
  2892. if prescription.ID > 0 {
  2893. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  2894. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2895. 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
  2896. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2897. }
  2898. if adminUserInfo.Org.Id == 10597 { //adminUserInfo.Org.Id == 9538
  2899. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  2900. }
  2901. //针对医师汇
  2902. if adminUserInfo.Org.Id == 10121 {
  2903. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  2904. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  2905. }
  2906. //针对通道
  2907. if adminUserInfo.Org.Id == 10234 {
  2908. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration) / float64(totalMin) * 60 * 1000)
  2909. }
  2910. //针对监利大垸医院
  2911. if template.TemplateId == 41 {
  2912. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  2913. }
  2914. //针对肇庆三鹤血液透析中心
  2915. if template.TemplateId == 43 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10440 {
  2916. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  2917. }
  2918. if adminUserInfo.Org.Id == 10469 {
  2919. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / float64(totalMin))
  2920. }
  2921. if template.TemplateId == 20 || template.TemplateId == 22 { //adminUserInfo.Org.Id == 9538
  2922. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  2923. }
  2924. // 只针对方济医院
  2925. if template.TemplateId == 1 && adminUserInfo.Org.Id != 9849 {
  2926. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  2927. ultrafiltration_rate = value
  2928. }
  2929. //针对
  2930. if adminUserInfo.Org.Id == 10471 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10460 {
  2931. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  2932. ultrafiltration_rate = ultrafiltration_rate / 1000
  2933. }
  2934. if adminUserInfo.Org.Id == 10551 {
  2935. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  2936. ultrafiltration_rate = ultrafiltration_rate / 1000
  2937. }
  2938. }
  2939. }
  2940. record := models.MonitoringRecord{
  2941. UserOrgId: adminUserInfo.Org.Id,
  2942. PatientId: patientID,
  2943. DialysisOrderId: dialysisRecord.ID,
  2944. MonitoringDate: schedulestartTime,
  2945. OperateTime: startDate.Unix(),
  2946. // MonitoringTime: recordTime,
  2947. MonitoringNurse: nurseID,
  2948. Dispose: tempdispose,
  2949. UltrafiltrationRate: ultrafiltration_rate,
  2950. UltrafiltrationVolume: 0,
  2951. Status: 1,
  2952. CreatedTime: time.Now().Unix(),
  2953. UpdatedTime: time.Now().Unix(),
  2954. }
  2955. //只针对广慈医院
  2956. 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 {
  2957. // 查询病人是否有透前评估数据
  2958. befor, errcode := service.GetAssessmentBefor(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2959. //如果有数据就插入
  2960. if errcode == nil {
  2961. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2962. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2963. record.BreathingRate = befor.BreathingRate
  2964. record.PulseFrequency = befor.PulseFrequency
  2965. record.Temperature = befor.Temperature
  2966. }
  2967. }
  2968. // 如果当天有插入数据,则不再往透析纪录里插入数据
  2969. if newdialysisRecord.ID > 0 {
  2970. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 {
  2971. record.Temperature = 36.5
  2972. record.ArterialPressure = -100
  2973. record.DialysateTemperature = 36.5
  2974. record.Conductivity = 14
  2975. record.BreathingRate = "20"
  2976. record.VenousPressure = 80
  2977. record.TransmembranePressure = 60
  2978. record.Dispose = catheter_operation
  2979. }
  2980. //针对新化博翔
  2981. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10447 {
  2982. record.BloodOxygenSaturation = "99"
  2983. record.Conductivity = 14
  2984. record.DialysateTemperature = 36.5
  2985. record.BreathingRate = "20"
  2986. }
  2987. //针对兰溪人民医院的需求
  2988. if adminUserInfo.Org.Id == 10430 || adminUserInfo.Org.Id == 9671 {
  2989. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2990. record.SystolicBloodPressure = befor.SystolicBloodPressure
  2991. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  2992. record.Temperature = befor.Temperature
  2993. record.PulseFrequency = befor.PulseFrequency
  2994. record.BreathingRate = befor.BreathingRate
  2995. }
  2996. //新化博翔
  2997. if adminUserInfo.Org.Id == 10447 {
  2998. befor, _ := service.GetAssessmentBeforThrity(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  2999. record.SystolicBloodPressure = befor.SystolicBloodPressure
  3000. record.DiastolicBloodPressure = befor.DiastolicBloodPressure
  3001. record.BreathingRate = befor.BreathingRate
  3002. }
  3003. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  3004. record.PulseFrequency = 80
  3005. record.Temperature = 36.5
  3006. }
  3007. //诊断灵山圣康
  3008. if adminUserInfo.Org.Id == 10375 {
  3009. record.Conductivity = 13.8
  3010. record.DialysateTemperature = 37
  3011. record.DialysateFlow = 500
  3012. record.BloodFlowVolume = 200
  3013. record.BreathingRate = "18"
  3014. record.SodiumConcentration = 140
  3015. }
  3016. //江成肾病医院
  3017. if adminUserInfo.Org.Id == 10517 {
  3018. record.SodiumConcentration = 138
  3019. record.DialysateTemperature = 36.5
  3020. }
  3021. err := service.CreateMonitor(&record)
  3022. //记录日志
  3023. byterequest, _ := json.Marshal(record)
  3024. monitorRecordLog := models.XtMonitorRecordLog{
  3025. RecordDate: record.MonitoringDate,
  3026. PatientId: record.PatientId,
  3027. Module: 1,
  3028. AdminUserId: adminUserInfo.AdminUser.Id,
  3029. Ctime: time.Now().Unix(),
  3030. Mtime: 0,
  3031. Status: 1,
  3032. UserOrgId: record.UserOrgId,
  3033. ErrLog: string(byterequest),
  3034. Source: "执行上机时新增监测",
  3035. }
  3036. service.CreateMonitorRecordLog(monitorRecordLog)
  3037. finish := models.XtDialysisFinish{
  3038. IsFinish: 1,
  3039. UserOrgId: adminUserInfo.Org.Id,
  3040. Status: 1,
  3041. Ctime: time.Now().Unix(),
  3042. Mtime: 0,
  3043. Module: 7,
  3044. RecordDate: schedulestartTime,
  3045. Sourse: 1,
  3046. PatientId: patientID,
  3047. }
  3048. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 7, patientID)
  3049. if dialysisFinish.ID == 0 {
  3050. service.CreateDialysisFinish(finish)
  3051. }
  3052. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_records"
  3053. redis := service.RedisClient()
  3054. //清空key 值
  3055. redis.Set(key, "", time.Second)
  3056. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":monitor_record_list_all"
  3057. redis.Set(keyOne, "", time.Second)
  3058. defer redis.Close()
  3059. if err != nil {
  3060. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3061. return
  3062. }
  3063. }
  3064. go func() {
  3065. ssoDomain := beego.AppConfig.String("call_domain")
  3066. api := ssoDomain + "/index/uppatient"
  3067. values := make(url.Values)
  3068. values.Set("org_id", strconv.FormatInt(adminUserInfo.Org.Id, 10))
  3069. values.Set("admin_user_id", strconv.FormatInt(nurseID, 10))
  3070. values.Set("patient_id", strconv.FormatInt(patientID, 10))
  3071. values.Set("up_time", strconv.FormatInt(startDate.Unix(), 10))
  3072. http.PostForm(api, values)
  3073. }()
  3074. this.ServeSuccessJSON(map[string]interface{}{
  3075. "dialysis_order": newdialysisRecord,
  3076. "monitor": record,
  3077. })
  3078. return
  3079. }
  3080. func (c *DialysisAPIController) PostSolution() {
  3081. id, _ := c.GetInt64("patient", 0)
  3082. recordDateStr := c.GetString("record_date")
  3083. if id <= 0 {
  3084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3085. return
  3086. }
  3087. adminUserInfo := c.GetMobileAdminUserInfo()
  3088. patient, _ := service.FindPatientById(adminUserInfo.Org.Id, id)
  3089. if patient.ID == 0 {
  3090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3091. return
  3092. }
  3093. if len(recordDateStr) == 0 {
  3094. recordDateStr = time.Now().Format("2006-01-02")
  3095. }
  3096. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3097. if parseDateErr != nil {
  3098. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3100. return
  3101. }
  3102. mode_id, _ := c.GetInt64("mode_id", 0)
  3103. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  3104. dialyzer, _ := c.GetInt64("dialyzer", 0)
  3105. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  3106. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3107. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  3108. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  3109. replacement_way, _ := c.GetInt64("replacement_way", 0)
  3110. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  3111. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  3112. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  3113. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  3114. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  3115. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  3116. kalium, _ := c.GetFloat("kalium", 0)
  3117. sodium, _ := c.GetFloat("sodium", 0)
  3118. calcium, _ := c.GetFloat("calcium", 0)
  3119. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  3120. prescription_doctor, _ := c.GetInt64("prescription_doctor", 0)
  3121. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  3122. glucose, _ := c.GetFloat("glucose", 0)
  3123. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  3124. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3125. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3126. conductivity, _ := c.GetFloat("conductivity", 0)
  3127. remark := c.GetString("remark")
  3128. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  3129. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  3130. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  3131. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  3132. body_fluid, _ := c.GetInt64("body_fluid", 0)
  3133. special_medicine, _ := c.GetInt64("special_medicine", 0)
  3134. special_medicine_other := c.GetString("special_medicine_other")
  3135. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  3136. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  3137. blood_access, _ := c.GetInt64("blood_access", 0)
  3138. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  3139. body_fluid_other := c.GetString("body_fluid_other")
  3140. replacement_total, _ := c.GetFloat("replacement_total", 0)
  3141. niprocart, _ := c.GetInt64("niprocart", 0)
  3142. jms, _ := c.GetInt64("jms", 0)
  3143. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  3144. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  3145. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  3146. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  3147. filtryzer, _ := c.GetInt64("filtryzer", 0)
  3148. target_ktv, _ := c.GetFloat("target_ktv", 0)
  3149. dialyzers, _ := c.GetInt64("dialyzers", 0)
  3150. injector, _ := c.GetInt64("injector", 0)
  3151. bloodlines, _ := c.GetInt64("bloodlines", 0)
  3152. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  3153. safe_package, _ := c.GetInt64("package", 0)
  3154. a_liquid, _ := c.GetInt64("a_liquid", 0)
  3155. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  3156. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  3157. blood := c.GetString("blood")
  3158. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  3159. dialysis_irrigation := c.GetString("dialysis_irrigation")
  3160. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  3161. displace_speed := c.GetString("displace_speed")
  3162. illness, _ := c.GetInt64("illness")
  3163. amylaceum := c.GetString("amylaceum")
  3164. single_time := c.GetString("single_time")
  3165. single_water := c.GetString("single_water")
  3166. replacement_flow := c.GetString("replacement_flow")
  3167. plasma_separator := c.GetString("plasma_separator")
  3168. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  3169. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  3170. oxygen_flow := c.GetString("oxygen_flow")
  3171. oxygen_time := c.GetString("oxygen_time")
  3172. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  3173. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  3174. puncture_needle := c.GetString("puncture_needle")
  3175. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  3176. epo := c.GetString("epo")
  3177. epo_count, _ := c.GetFloat("epo_count", 0)
  3178. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  3179. pre_impulse := c.GetString("pre_impulse")
  3180. impulse, _ := strconv.ParseFloat(pre_impulse, 64)
  3181. admin_user_id, _ := c.GetInt64("admin_user_id")
  3182. is_water := c.GetString("is_water")
  3183. add_amount, _ := c.GetFloat("add_amount")
  3184. reduce_amount, _ := c.GetFloat("reduce_amount")
  3185. prescribing_number, _ := c.GetFloat("prescribing_number")
  3186. treatment_remark := c.GetString("treatment_remark")
  3187. prescription_sodium := c.GetString("prescription_sodium")
  3188. start_sodium := c.GetString("start_sodium")
  3189. sodium_curve := c.GetString("sodium_curve")
  3190. var is_war int64
  3191. if is_water == "是" {
  3192. is_war = 1
  3193. }
  3194. if is_water == "否" {
  3195. is_war = 2
  3196. }
  3197. if is_water == "请选择" {
  3198. is_war = 0
  3199. }
  3200. drhy_water := c.GetString("drhy_water")
  3201. dry_water_hour := c.GetString("dry_water_hour")
  3202. water_machine := c.GetString("water_machine")
  3203. dialysis_remark := c.GetString("dialysis_remark")
  3204. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  3205. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  3206. prescription_water, _ := c.GetFloat("prescription_water")
  3207. dialysis_strainer := c.GetString("dialysis_strainer")
  3208. chaptalization := c.GetString("chaptalization")
  3209. washing_time := c.GetString("washing_time")
  3210. warsh_count := c.GetString("warsh_count")
  3211. blood_access_part_id := c.GetString("blood_access_part_id")
  3212. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  3213. dialyzate := c.GetString("dialyzate")
  3214. if mode_id > 0 {
  3215. var str string
  3216. //查找该机构用的是什么透析器
  3217. filedConfig, _ := service.GetFiledConfig(adminUserInfo.Org.Id)
  3218. if filedConfig.ID > 0 {
  3219. str = dialyzerPerfusionApparatus
  3220. } else {
  3221. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  3222. }
  3223. service.ModifyScheduleMode(mode_id, patient.ID, recordDate.Unix(), adminUserInfo.Org.Id, str)
  3224. }
  3225. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3226. //
  3227. //if template.TemplateId == 2 || template.TemplateId == 6 {
  3228. // if appRole.UserType == 3 {
  3229. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3230. // if getPermissionErr != nil {
  3231. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3232. // return
  3233. // } else if headNursePermission == nil {
  3234. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3235. // return
  3236. // }
  3237. // }
  3238. //}
  3239. // 查询信息规挡的设置天数
  3240. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  3241. if infor.ID > 0 && infor.WeekDay > 0 {
  3242. var cha_time int64
  3243. timeNowStr := time.Now().Format("2006-01-02")
  3244. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3245. //今日的日期减去设置的日期
  3246. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3247. if cha_time >= recordDate.Unix() {
  3248. //查询审核是否允许
  3249. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.Org.Id, 1)
  3250. //申请状态不允许的情况 拒绝修改
  3251. if infor.ApplicationStatus != 1 {
  3252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3253. return
  3254. }
  3255. }
  3256. }
  3257. prescription := models.DialysisPrescription{
  3258. UserOrgId: adminUserInfo.Org.Id,
  3259. PatientId: id,
  3260. RecordDate: recordDate.Unix(),
  3261. ModeId: mode_id,
  3262. DialysisDuration: dialysis_duration,
  3263. Dialyzer: dialyzer,
  3264. PerfusionApparatus: perfusion_apparatus,
  3265. BloodFlowVolume: blood_flow_volume,
  3266. DewaterAmount: dewater_amount,
  3267. DisplaceLiqui: displace_liqui,
  3268. ReplacementWay: replacement_way,
  3269. Anticoagulant: anticoagulant,
  3270. AnticoagulantShouji: anticoagulant_shouji,
  3271. AnticoagulantWeichi: anticoagulant_weichi,
  3272. AnticoagulantZongliang: anticoagulant_zongliang,
  3273. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3274. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3275. Kalium: kalium,
  3276. Sodium: sodium,
  3277. Calcium: calcium,
  3278. Bicarbonate: bicarbonate,
  3279. Glucose: glucose,
  3280. // DryWeight: dry_weight,
  3281. DialysateFlow: dialysate_flow,
  3282. DialysateTemperature: dialysate_temperature,
  3283. Conductivity: conductivity,
  3284. Remark: remark,
  3285. Status: 1,
  3286. CreatedTime: time.Now().Unix(),
  3287. UpdatedTime: time.Now().Unix(),
  3288. DialysisDurationMinute: dialysisDurationMinute,
  3289. DialysisDurationHour: dialysisDurationHour,
  3290. TargetUltrafiltration: targetUltrafiltration,
  3291. DialysateFormulation: dialysateFormulation,
  3292. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3293. BodyFluid: body_fluid,
  3294. SpecialMedicine: special_medicine,
  3295. SpecialMedicineOther: special_medicine_other,
  3296. DisplaceLiquiPart: displace_liqui_part,
  3297. DisplaceLiquiValue: displace_liqui_value,
  3298. BloodAccess: blood_access,
  3299. Ultrafiltration: ultrafiltration,
  3300. BodyFluidOther: body_fluid_other,
  3301. ReplacementTotal: replacement_total,
  3302. Niprocart: niprocart,
  3303. Jms: jms,
  3304. FistulaNeedleSet: fistula_needle_set,
  3305. FistulaNeedleSet16: fistula_needle_set_16,
  3306. Hemoperfusion: hemoperfusion,
  3307. DialyserSterilised: dialyser_sterilised,
  3308. Filtryzer: filtryzer,
  3309. TargetKtv: target_ktv,
  3310. Dialyzers: dialyzers,
  3311. Injector: injector,
  3312. Bloodlines: bloodlines,
  3313. TubingHemodialysis: tubing_hemodialysis,
  3314. Package: safe_package,
  3315. ALiquid: a_liquid,
  3316. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  3317. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  3318. Blood: blood,
  3319. DialysisDialyszers: dialysis_dialyszers,
  3320. DialysisIrrigation: dialysis_irrigation,
  3321. AntioxidantCommodityName: antioxidant_commodity_name,
  3322. DisplaceSpeed: displace_speed,
  3323. Illness: illness,
  3324. Amylaceum: amylaceum,
  3325. SingleWater: single_water,
  3326. SingleTime: single_time,
  3327. ReplacementFlow: replacement_flow,
  3328. PlasmaSeparator: plasma_separator,
  3329. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  3330. OxygenUptake: oxygen_uptake,
  3331. OxygenTime: oxygen_time,
  3332. OxygenFlow: oxygen_flow,
  3333. HemodialysisPipelines: hemodialysis_pipelines,
  3334. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3335. PunctureNeedle: puncture_needle,
  3336. PunctureNeedleCount: puncture_needle_count,
  3337. Epo: epo,
  3338. EpoCount: epo_count,
  3339. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3340. PreImpulse: impulse,
  3341. AdminUserId: admin_user_id,
  3342. IsWater: is_war,
  3343. DrhyWater: drhy_water,
  3344. DryWaterHour: dry_water_hour,
  3345. WaterMachine: water_machine,
  3346. AddAmount: add_amount,
  3347. ReduceAmount: reduce_amount,
  3348. DialysisRemark: dialysis_remark,
  3349. PrescribingNumber: prescribing_number,
  3350. PrescriptionSodium: prescription_sodium,
  3351. StartSodium: start_sodium,
  3352. SodiumCurve: sodium_curve,
  3353. TreatmentRemark: treatment_remark,
  3354. DialysisFluidFlow: dialysis_fluid_flow,
  3355. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3356. PrescriptionWater: prescription_water,
  3357. DialysisStrainer: dialysis_strainer,
  3358. Chaptalization: chaptalization,
  3359. WashingTime: washing_time,
  3360. WarshCount: warsh_count,
  3361. BloodAccessPartId: blood_access_part_id,
  3362. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3363. Dialyzate: dialyzate,
  3364. }
  3365. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3366. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
  3367. //
  3368. if appRole.UserType == 2 || appRole.UserType == 1 {
  3369. prescription_doctor = adminUserInfo.AdminUser.Id
  3370. prescription.PrescriptionDoctor = prescription_doctor
  3371. }
  3372. if dialysisPrescription.ID == 0 { //新增
  3373. prescription.Creater = adminUserInfo.AdminUser.Id
  3374. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3375. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3376. }
  3377. } else { //修改
  3378. if dialysisPrescription.Creater == 0 {
  3379. prescription.Creater = adminUserInfo.AdminUser.Id
  3380. } else {
  3381. prescription.Creater = dialysisPrescription.Creater
  3382. if adminUserInfo.Org.Id == 9882 {
  3383. if appRole.UserType == 2 || appRole.UserType == 1 {
  3384. prescription.Creater = adminUserInfo.AdminUser.Id
  3385. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  3386. }
  3387. }
  3388. }
  3389. if adminUserInfo.Org.Id == 10340 && prescription.AdminUserId == 0 {
  3390. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  3391. }
  3392. //if/**/
  3393. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  3394. //if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater > 0 {
  3395. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3396. // if getPermissionErr != nil {
  3397. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3398. // return
  3399. // } else if headNursePermission == nil {
  3400. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3401. // return
  3402. // }
  3403. //}
  3404. //prescription.Creater = dialysisPrescription.Creater
  3405. prescription.CreatedTime = dialysisPrescription.CreatedTime
  3406. prescription.Modifier = adminUserInfo.AdminUser.Id
  3407. prescription.ID = dialysisPrescription.ID
  3408. }
  3409. solution := models.DialysisSolution{
  3410. RegistrarsId: adminUserInfo.AdminUser.Id,
  3411. UserOrgId: adminUserInfo.Org.Id,
  3412. Doctor: prescription_doctor,
  3413. PatientId: id,
  3414. ModeId: mode_id,
  3415. DialysisDuration: dialysis_duration,
  3416. PerfusionApparatus: perfusion_apparatus,
  3417. BloodFlowVolume: blood_flow_volume,
  3418. Dewater: dewater_amount,
  3419. DisplaceLiqui: displace_liqui,
  3420. ReplacementWay: replacement_way,
  3421. Anticoagulant: anticoagulant,
  3422. AnticoagulantShouji: anticoagulant_shouji,
  3423. AnticoagulantWeichi: anticoagulant_weichi,
  3424. AnticoagulantZongliang: anticoagulant_zongliang,
  3425. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  3426. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  3427. Kalium: kalium,
  3428. Sodium: sodium,
  3429. Calcium: calcium,
  3430. Bicarbonate: bicarbonate,
  3431. Glucose: glucose,
  3432. // DryWeight: dry_weight,
  3433. DialysateFlow: dialysate_flow,
  3434. DialysateTemperature: dialysate_temperature,
  3435. Conductivity: conductivity,
  3436. Remark: remark,
  3437. Status: 1,
  3438. CreatedTime: time.Now().Unix(),
  3439. UpdatedTime: time.Now().Unix(),
  3440. DialysisDurationMinute: dialysisDurationMinute,
  3441. DialysisDurationHour: dialysisDurationHour,
  3442. TargetUltrafiltration: targetUltrafiltration,
  3443. DialysateFormulation: dialysateFormulation,
  3444. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  3445. BodyFluid: body_fluid,
  3446. SpecialMedicine: special_medicine,
  3447. SpecialMedicineOther: special_medicine_other,
  3448. DisplaceLiquiPart: displace_liqui_part,
  3449. DisplaceLiquiValue: displace_liqui_value,
  3450. BloodAccess: blood_access,
  3451. Ultrafiltration: ultrafiltration,
  3452. BodyFluidOther: body_fluid_other,
  3453. ReplacementTotal: replacement_total,
  3454. TargetKtv: target_ktv,
  3455. DialysisDialyszers: dialysis_dialyszers,
  3456. DialysisIrrigation: dialysis_irrigation,
  3457. HemodialysisPipelines: hemodialysis_pipelines,
  3458. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  3459. PunctureNeedle: puncture_needle,
  3460. PunctureNeedleCount: puncture_needle_count,
  3461. Epo: epo,
  3462. EpoCount: epo_count,
  3463. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  3464. PreImpulse: impulse,
  3465. SolutionStatus: 1,
  3466. DialysisRemark: dialysis_remark,
  3467. PrescribingNumber: prescribing_number,
  3468. PrescriptionSodium: prescription_sodium,
  3469. StartSodium: start_sodium,
  3470. SodiumCurve: sodium_curve,
  3471. TreatmentRemark: treatment_remark,
  3472. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  3473. DialysisFluidFlow: dialysis_fluid_flow,
  3474. PrescriptionWater: prescription_water,
  3475. DialysisStrainer: dialysis_strainer,
  3476. Chaptalization: chaptalization,
  3477. WashingTime: washing_time,
  3478. WarshCount: warsh_count,
  3479. BloodAccessPartId: blood_access_part_id,
  3480. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  3481. Dialyzate: dialyzate,
  3482. }
  3483. //针对河间咸的
  3484. if adminUserInfo.Org.Id == 10090 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 3877 {
  3485. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 {
  3486. solution.DisplaceLiquiPart = 0
  3487. solution.DisplaceLiquiValue = 0
  3488. }
  3489. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  3490. prescription.DisplaceLiquiPart = 0
  3491. prescription.DisplaceLiquiValue = 0
  3492. }
  3493. }
  3494. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10340 {
  3495. if solution.PrescribingNumber == 0 {
  3496. solution.PrescribingNumber = 1
  3497. }
  3498. if prescription.PrescribingNumber == 0 {
  3499. prescription.PrescribingNumber = 1
  3500. }
  3501. if solution.PrescribingNumber == 0 && id == 14682 {
  3502. solution.PrescribingNumber = 2
  3503. }
  3504. if solution.PrescribingNumber == 0 && id == 18560 {
  3505. solution.PrescribingNumber = 2
  3506. }
  3507. if prescription.PrescribingNumber == 0 && id == 14682 {
  3508. prescription.PrescribingNumber = 2
  3509. }
  3510. if prescription.PrescribingNumber == 0 && id == 18560 {
  3511. prescription.PrescribingNumber = 2
  3512. }
  3513. }
  3514. service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  3515. //记录日志
  3516. byterequest, _ := json.Marshal(prescription)
  3517. prescriptionLog := models.XtDialysisPrescriptionLog{
  3518. UserOrgId: prescription.UserOrgId,
  3519. Ctime: time.Now().Unix(),
  3520. Mtime: 0,
  3521. ErrLog: string(byterequest),
  3522. AdminUserId: adminUserInfo.AdminUser.Id,
  3523. RecordDate: prescription.RecordDate,
  3524. PatientId: prescription.PatientId,
  3525. Source: "手机端新增处方",
  3526. Status: 1,
  3527. }
  3528. service.CreatePrescriptionLog(prescriptionLog)
  3529. finish := models.XtDialysisFinish{
  3530. IsFinish: 1,
  3531. UserOrgId: adminUserInfo.Org.Id,
  3532. Status: 1,
  3533. Ctime: time.Now().Unix(),
  3534. Mtime: 0,
  3535. Module: 1,
  3536. RecordDate: recordDate.Unix(),
  3537. Sourse: 1,
  3538. PatientId: id,
  3539. }
  3540. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, recordDate.Unix(), 1, id)
  3541. if dialysisFinish.ID == 0 {
  3542. service.CreateDialysisFinish(finish)
  3543. }
  3544. //获取最新1条
  3545. dialysisSolution, _ := service.GetLastPatientDialysisSolution(id, adminUserInfo.Org.Id)
  3546. //更新状态
  3547. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  3548. //长沙南雅医院,自动生成抗凝剂的临时处方
  3549. if adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 {
  3550. if prescribing_number == 0 {
  3551. prescribing_number = 1
  3552. }
  3553. advice := models.DoctorAdvice{
  3554. UserOrgId: adminUserInfo.Org.Id,
  3555. PatientId: id,
  3556. GroupNo: 0,
  3557. AdviceType: 2,
  3558. RecordDate: recordDate.Unix(),
  3559. AdviceDate: recordDate.Unix(),
  3560. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  3561. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  3562. AdviceDesc: "",
  3563. ReminderDate: 0,
  3564. SingleDose: prescription.AnticoagulantZongliang,
  3565. SingleDoseUnit: "iu",
  3566. DrugSpec: 0,
  3567. DrugSpecUnit: "",
  3568. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  3569. PrescribingNumberUnit: "支",
  3570. DeliveryWay: "静脉注射",
  3571. ExecutionFrequency: "上机前",
  3572. AdviceDoctor: 0,
  3573. Status: 1,
  3574. CreatedTime: time.Now().Unix(),
  3575. UpdatedTime: time.Now().Unix(),
  3576. IsPrescription: 1,
  3577. ExecutionState: 2,
  3578. StopState: 2,
  3579. IsSettle: 2,
  3580. }
  3581. // 查询排班信息
  3582. schedulePatient, _ := service.GetScheduleByPatient(id, recordDate.Unix(), adminUserInfo.Org.Id)
  3583. if schedulePatient.ID > 0 {
  3584. if schedulePatient.ScheduleType == 1 {
  3585. advice.StartTime = recordDate.Unix() + 6.5*60*60
  3586. }
  3587. if schedulePatient.ScheduleType == 2 {
  3588. advice.StartTime = recordDate.Unix() + 10*60*60
  3589. }
  3590. }
  3591. // 抗凝剂名称
  3592. switch anticoagulant {
  3593. case 1:
  3594. advice.AdviceName = "无肝素"
  3595. break
  3596. case 2:
  3597. advice.AdviceName = "普通肝素"
  3598. break
  3599. case 3:
  3600. advice.AdviceName = "低分子肝素"
  3601. break
  3602. case 4:
  3603. advice.AdviceName = "阿加曲班"
  3604. break
  3605. case 5:
  3606. advice.AdviceName = "枸橼酸钠"
  3607. break
  3608. case 6:
  3609. advice.AdviceName = "低分子肝素钙"
  3610. break
  3611. case 7:
  3612. advice.AdviceName = "低分子肝素钠"
  3613. break
  3614. case 8:
  3615. advice.AdviceName = "依诺肝素"
  3616. break
  3617. case 9:
  3618. advice.AdviceName = "达肝素"
  3619. break
  3620. case 10:
  3621. advice.AdviceName = "体外抗凝"
  3622. break
  3623. case 11:
  3624. advice.AdviceName = "那曲肝素"
  3625. break
  3626. case 12:
  3627. advice.AdviceName = "无抗凝剂"
  3628. break
  3629. }
  3630. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  3631. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 || appRole.UserType == 4 {
  3632. advice.AdviceDoctor = appRole.AdminUserId
  3633. }
  3634. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  3635. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.Org.Id, id, recordDate.Unix())
  3636. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  3637. advice.AdviceName = "低分子肝素钠注射液"
  3638. // 修改患者临时医嘱里的抗凝剂医嘱
  3639. advice.ID = advicePrescription.ID
  3640. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  3641. } else {
  3642. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  3643. advice.AdviceName = "低分子肝素钠注射液"
  3644. service.CreateDoctorAdvice(&advice)
  3645. }
  3646. }
  3647. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  3648. redis := service.RedisClient()
  3649. defer redis.Close()
  3650. //清空key 值
  3651. redis.Set(key, "", time.Second)
  3652. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  3653. redis.Set(keyOne, "", time.Second)
  3654. }
  3655. //获取key,清空redis
  3656. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3657. redis := service.RedisClient()
  3658. defer redis.Close()
  3659. //清空key 值
  3660. redis.Set(key, "", time.Second)
  3661. //清空长期医嘱的key
  3662. soulution_key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  3663. redis.Set(soulution_key, "", time.Second)
  3664. //查询最近透析准备表里是否存在 透析器 灌流器
  3665. keyOne := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  3666. redis.Set(keyOne, "", time.Second)
  3667. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":schedual_detail"
  3668. redis.Set(keyTwo, "", time.Second)
  3669. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3670. redis.Set(keyThree, "", time.Second)
  3671. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  3672. redis.Set(keyFour, "", time.Second)
  3673. //splitStr := strings.Split(dialysis_dialyszers, ",")
  3674. //
  3675. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  3676. //
  3677. //mation, _ := service.GetGoodInfoMation(adminUserInfo.Org.Id)
  3678. //if len(mation)>0{
  3679. // for _, item := range splitStr {
  3680. // for _,it := range mation{
  3681. // if(item == it.SpecificationName){
  3682. //
  3683. // //查询最近一次的透析器
  3684. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3685. //
  3686. // if errcode == gorm.ErrRecordNotFound{
  3687. // //插入数据
  3688. // prepare := models.DialysisBeforePrepare{
  3689. // UserOrgId: adminUserInfo.Org.Id,
  3690. // PatientId: id,
  3691. // RecordDate: recordDate.Unix(),
  3692. // GoodTypeId: it.GoodTypeId,
  3693. // GoodId: it.ID,
  3694. // Count: 1,
  3695. // Ctime: time.Now().Unix(),
  3696. // Creater: adminUserInfo.AdminUser.Id,
  3697. // Status:1,
  3698. //
  3699. // }
  3700. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3701. // fmt.Println("",errcode)
  3702. // }
  3703. // }
  3704. // }
  3705. //
  3706. // }
  3707. //
  3708. // for _, item := range splitIrrigation {
  3709. // for _,it := range mation{
  3710. // if(item == it.SpecificationName){
  3711. // //查询最近一次的透析器
  3712. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.Org.Id,id)
  3713. // if errcode == gorm.ErrRecordNotFound{
  3714. // //插入数据
  3715. // prepare := models.DialysisBeforePrepare{
  3716. // UserOrgId: adminUserInfo.Org.Id,
  3717. // PatientId: id,
  3718. // RecordDate: recordDate.Unix(),
  3719. // GoodTypeId: it.GoodTypeId,
  3720. // GoodId: it.ID,
  3721. // Count: 1,
  3722. // Ctime: time.Now().Unix(),
  3723. // Creater: adminUserInfo.AdminUser.Id,
  3724. // Status:1,
  3725. //
  3726. // }
  3727. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  3728. // fmt.Println(errcode)
  3729. // }
  3730. // }
  3731. // }
  3732. // }
  3733. //}
  3734. c.ServeSuccessJSON(map[string]interface{}{
  3735. "solution": &solution,
  3736. "prescription": &prescription,
  3737. })
  3738. }
  3739. func (c *DialysisAPIController) GetAcceptsAssessment() {
  3740. patient, _ := c.GetInt64("patient", 0)
  3741. adminUserInfo := c.GetMobileAdminUserInfo()
  3742. _, receiveTreatmentAsses := service.GetLastAcceptsAssessment(patient, adminUserInfo.Org.Id)
  3743. c.ServeSuccessJSON(map[string]interface{}{
  3744. "receiveTreatmentAsses": receiveTreatmentAsses,
  3745. })
  3746. }
  3747. func (this *DialysisAPIController) PostSignInfo() {
  3748. patientID, _ := this.GetInt64("patient_id")
  3749. recordDateStr := this.GetString("date")
  3750. if patientID <= 0 {
  3751. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3752. return
  3753. }
  3754. if len(recordDateStr) == 0 {
  3755. recordDateStr = time.Now().Format("2006-01-02")
  3756. }
  3757. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3758. if parseDateErr != nil {
  3759. this.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3760. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. adminInfo := this.GetMobileAdminUserInfo()
  3764. err := service.UpDateDialysisPrescriptionDoctorSign(patientID, date.Unix(), adminInfo.Org.Id, adminInfo.AdminUser.Id)
  3765. if err != nil {
  3766. this.ErrorLog("签名失败:%v", err)
  3767. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3768. return
  3769. }
  3770. this.ServeSuccessJSON(map[string]interface{}{
  3771. "doctor_id": adminInfo.AdminUser.Id,
  3772. })
  3773. }
  3774. func (this *DialysisAPIController) GetLastMonitorRecord() {
  3775. patientID, _ := this.GetInt64("patient_id")
  3776. adminInfo := this.GetMobileAdminUserInfo()
  3777. record, _ := service.FindLastMonitorRecord(patientID, adminInfo.Org.Id)
  3778. this.ServeSuccessJSON(map[string]interface{}{
  3779. "monitor": record,
  3780. })
  3781. }
  3782. func (this *DialysisAPIController) GetLastMonitorRecordTody() {
  3783. thisTime := time.Now()
  3784. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3785. timeLayout := "2006-01-02 15:04:05"
  3786. loc, _ := time.LoadLocation("Local")
  3787. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3788. theAssessmentDateTime := theStartTime.Unix()
  3789. patientID, _ := this.GetInt64("patient_id")
  3790. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3791. adminInfo := this.GetMobileAdminUserInfo()
  3792. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3793. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.Org.Id, monitorDate)
  3794. template, _ := service.GetOrgInfoTemplate(adminInfo.Org.Id)
  3795. var ultrafiltration_rate float64
  3796. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3797. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.Org.Id)
  3798. fmt.Println(evaluation)
  3799. fmt.Println("prescription.ID", prescription.ID)
  3800. if prescription.ID > 0 {
  3801. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3802. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3803. if (template.TemplateId == 6 || template.TemplateId == 65 || adminInfo.Org.Id == 10375 || adminInfo.Org.Id == 10599) && adminInfo.Org.Id != 9538 {
  3804. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3805. record.UltrafiltrationRate = ultrafiltration_rate
  3806. }
  3807. if adminInfo.Org.Id == 10597 {
  3808. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater / float64(totalMin) * 60 * 1000)
  3809. record.UltrafiltrationRate = ultrafiltration_rate
  3810. }
  3811. if adminInfo.Org.Id == 10510 {
  3812. record.UltrafiltrationRate = 0
  3813. }
  3814. if template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 36 {
  3815. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1)
  3816. record.UltrafiltrationRate = ultrafiltration_rate
  3817. }
  3818. if template.TemplateId == 20 || template.TemplateId == 22 {
  3819. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3820. record.UltrafiltrationRate = ultrafiltration_rate
  3821. }
  3822. // 只针对方济医院
  3823. if template.TemplateId == 1 && adminInfo.Org.Id != 9849 {
  3824. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3825. ultrafiltration_rate = value
  3826. record.UltrafiltrationRate = ultrafiltration_rate
  3827. }
  3828. if template.TemplateId == 41 || template.TemplateId == 47 {
  3829. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin) * 1000)
  3830. record.UltrafiltrationRate = ultrafiltration_rate
  3831. }
  3832. if template.TemplateId == 43 {
  3833. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3834. record.UltrafiltrationRate = ultrafiltration_rate
  3835. }
  3836. if template.TemplateId == 46 || template.TemplateId == 54 {
  3837. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3838. record.UltrafiltrationRate = ultrafiltration_rate
  3839. }
  3840. 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 {
  3841. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3842. record.UltrafiltrationRate = ultrafiltration_rate
  3843. }
  3844. if adminInfo.Org.Id == 10469 {
  3845. ultrafiltration_rate = math.Floor(prescription.PrescriptionWater * 60 / 1000 / float64(totalMin) * 1000)
  3846. record.UltrafiltrationRate = ultrafiltration_rate
  3847. }
  3848. if adminInfo.Org.Id == 10471 {
  3849. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3850. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3851. }
  3852. if adminInfo.Org.Id == 10460 {
  3853. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3854. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3855. }
  3856. if adminInfo.Org.Id == 10551 {
  3857. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 1000 / float64(totalMin) * 60 * 1000)
  3858. record.UltrafiltrationRate = ultrafiltration_rate / 1000
  3859. }
  3860. if adminInfo.Org.Id == 10597 || adminInfo.Org.Id == 10599 {
  3861. record.UltrafiltrationRate = 0
  3862. }
  3863. //if template.TemplateId == 47 {
  3864. // ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / float64(totalMin))
  3865. // record.UltrafiltrationRate = ultrafiltration_rate
  3866. //}
  3867. }
  3868. }
  3869. // record.UltrafiltrationRate = ultrafiltration_rate
  3870. record.UltrafiltrationVolume = 0
  3871. 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
  3872. if ultrafiltration_rate > 0 {
  3873. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3874. record.UltrafiltrationVolume = value
  3875. }
  3876. }
  3877. 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
  3878. if ultrafiltration_rate > 0 && adminInfo.Org.Id != 9538 {
  3879. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3880. record.UltrafiltrationVolume = ultrafiltration_volume
  3881. }
  3882. }
  3883. if adminInfo.Org.Id == 10597 {
  3884. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3885. record.UltrafiltrationVolume = ultrafiltration_volume
  3886. }
  3887. //长沙南雅
  3888. 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 {
  3889. if ultrafiltration_rate > 0 {
  3890. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3891. record.UltrafiltrationVolume = ultrafiltration_volume
  3892. }
  3893. }
  3894. if adminInfo.Org.Id == 10471 {
  3895. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3896. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3897. }
  3898. if adminInfo.Org.Id == 10460 {
  3899. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3900. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3901. }
  3902. if adminInfo.Org.Id == 10551 {
  3903. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3904. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  3905. }
  3906. //长沙南雅累计血容量自动计算
  3907. //if adminInfo.Org.Id == 10340 || adminInfo.Org.Id == 9671 || adminInfo.Org.Id == 3877{
  3908. // record.AccumulatedBloodVolume = (record.BloodFlowVolume - 25) * (math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime)/3600) * 60) / 1000
  3909. //}
  3910. if template.TemplateId == 47 || template.TemplateId == 54 {
  3911. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3912. }
  3913. if adminInfo.Org.Id == 10510 {
  3914. record.UltrafiltrationVolume = 0
  3915. }
  3916. lastMonitorRecordList, _ := service.GetLastMonitorRecordList(patientID, monitorDate, adminInfo.Org.Id)
  3917. this.ServeSuccessJSON(map[string]interface{}{
  3918. "monitor": record,
  3919. "lastMonitorRecordList": lastMonitorRecordList,
  3920. })
  3921. }
  3922. func (this *DialysisAPIController) ModifyStartDialysisOrder() {
  3923. record_id, _ := this.GetInt64("id")
  3924. nurseID, _ := this.GetInt64("start_nurse")
  3925. puncture_nurse, _ := this.GetInt64("puncture_nurse")
  3926. bedID, _ := this.GetInt64("bed")
  3927. start_time := this.GetString("start_time")
  3928. schedual_type, _ := this.GetInt64("schedual_type")
  3929. washpipe_nurse, _ := this.GetInt64("washpipe_nurse")
  3930. change_nurse, _ := this.GetInt64("change_nurse")
  3931. difficult_puncture_nurse, _ := this.GetInt64("difficult_puncture_nurse")
  3932. new_fistula_nurse, _ := this.GetInt64("new_fistula_nurse")
  3933. quality_nurse_id, _ := this.GetInt64("quality_nurse_id")
  3934. fmt.Println("quality_nurse_id", quality_nurse_id)
  3935. patient_id, _ := this.GetInt64("patient_id")
  3936. record_date, _ := this.GetInt64("record_date")
  3937. puncture_needle := this.GetString("puncture_needle")
  3938. puncture_way := this.GetString("puncture_way")
  3939. dialysis_dialyszers := this.GetString("dialysis_dialyszers")
  3940. dialysis_irrigation := this.GetString("dialysis_irrigation")
  3941. blood_access_id, _ := this.GetInt64("blood_access_part_opera_id")
  3942. nuclein_date_str := this.GetString("nuclein_date_str")
  3943. order_remark := this.GetString("order_remark")
  3944. schedule_remark := this.GetString("schedule_remark")
  3945. catheter_operation := this.GetString("catheter_operation")
  3946. blood_flow_volume := this.GetString("blood_flow_volume")
  3947. if record_id == 0 {
  3948. this.ErrorLog("id:%v", record_id)
  3949. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3950. return
  3951. }
  3952. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  3953. if parseStartDateErr != nil {
  3954. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  3955. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3956. return
  3957. }
  3958. adminUserInfo := this.GetMobileAdminUserInfo()
  3959. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  3960. if getNurseErr != nil {
  3961. this.ErrorLog("获取护士失败:%v", getNurseErr)
  3962. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3963. return
  3964. } else if nurse == nil {
  3965. this.ErrorLog("护士不存在")
  3966. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3967. return
  3968. }
  3969. nurse, getNurseErr = service.GetAdminUserByUserID(puncture_nurse)
  3970. //if getNurseErr != nil {
  3971. // this.ErrorLog("获取护士失败:%v", getNurseErr)
  3972. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3973. // return
  3974. //} else if nurse == nil {
  3975. // this.ErrorLog("护士不存在")
  3976. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3977. // return
  3978. //}
  3979. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  3980. if getDeviceNumberErr != nil {
  3981. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  3982. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3983. return
  3984. } else if deviceNumber == nil {
  3985. this.ErrorLog("床位号不存在")
  3986. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3987. return
  3988. }
  3989. _, tempDialysisRecord := service.FindDialysisOrderById(record_id)
  3990. //
  3991. //if tempDialysisRecord.Creator != adminUserInfo.AdminUser.Id {
  3992. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3993. // if getPermissionErr != nil {
  3994. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3995. // return
  3996. // } else if headNursePermission == nil {
  3997. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3998. // return
  3999. // }
  4000. //}
  4001. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  4002. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  4003. timeLayout := "2006-01-02 15:04:05"
  4004. loc, _ := time.LoadLocation("Local")
  4005. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4006. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  4007. schedulestartTime := theStartTime.Unix()
  4008. scheduleendTime := theEndTime.Unix()
  4009. var theNucleinDate int64
  4010. timeLayoutOne := "2006-01-02"
  4011. if len(nuclein_date_str) > 0 {
  4012. theTime, err := time.ParseInLocation(timeLayoutOne+" 15:04:05", nuclein_date_str+" 00:00:00", loc)
  4013. if err != nil {
  4014. utils.ErrorLog(err.Error())
  4015. }
  4016. theNucleinDate = theTime.Unix()
  4017. }
  4018. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  4019. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  4020. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4021. if daySchedule.BedId != bedID || daySchedule.ScheduleType != schedual_type {
  4022. if err == gorm.ErrRecordNotFound { //空床位
  4023. // 修改了床位逻辑
  4024. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4025. if daySchedule.ID > 0 {
  4026. //daySchedule.BedId = bedID
  4027. //daySchedule.PartitionId = deviceNumber.ZoneID
  4028. //daySchedule.ScheduleType = schedual_type
  4029. //daySchedule.UpdatedTime = time.Now().Unix()
  4030. //err := service.UpdateSchedule(&daySchedule)
  4031. xtSchedule := models.Schedule{
  4032. PartitionId: deviceNumber.ZoneID,
  4033. BedId: bedID,
  4034. ScheduleType: schedual_type,
  4035. UpdatedTime: time.Now().Unix(),
  4036. }
  4037. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4038. if err != nil {
  4039. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4040. return
  4041. }
  4042. }
  4043. } else if err == nil {
  4044. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  4045. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, tempDialysisRecord.PatientId)
  4046. if daySchedule.ID > 0 {
  4047. //daySchedule.BedId = bedID
  4048. //daySchedule.PartitionId = deviceNumber.ZoneID
  4049. //
  4050. //daySchedule.ScheduleType = schedual_type
  4051. //daySchedule.UpdatedTime = time.Now().Unix()
  4052. //err := service.UpdateSchedule(&daySchedule)
  4053. xtSchedule := models.Schedule{
  4054. PartitionId: deviceNumber.ZoneID,
  4055. BedId: bedID,
  4056. ScheduleType: schedual_type,
  4057. UpdatedTime: time.Now().Unix(),
  4058. }
  4059. err := service.UpdateScheduleOne(daySchedule.ID, xtSchedule)
  4060. if err != nil {
  4061. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4062. return
  4063. }
  4064. }
  4065. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 { //有排班且有上机记录
  4066. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  4067. return
  4068. }
  4069. } else if err != nil {
  4070. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4071. return
  4072. }
  4073. }
  4074. dialysisRecord := &models.DialysisOrder{
  4075. ID: record_id,
  4076. UserOrgId: adminUserInfo.Org.Id,
  4077. BedID: bedID,
  4078. StartNurse: nurseID,
  4079. StartTime: startDate.Unix(),
  4080. PunctureNurse: puncture_nurse,
  4081. Creator: adminUserInfo.AdminUser.Id,
  4082. Modifier: adminUserInfo.AdminUser.Id,
  4083. WashpipeNurse: washpipe_nurse,
  4084. SchedualType: schedual_type,
  4085. ChangeNurse: change_nurse,
  4086. DifficultPunctureNurse: difficult_puncture_nurse,
  4087. NewFistulaNurse: new_fistula_nurse,
  4088. QualityNurseId: quality_nurse_id,
  4089. PunctureNeedle: puncture_needle,
  4090. PunctureWay: puncture_way,
  4091. DialysisDialyszers: dialysis_dialyszers,
  4092. DialysisIrrigation: dialysis_irrigation,
  4093. BloodAccessId: blood_access_id,
  4094. NucleinDate: theNucleinDate,
  4095. OrderRemark: order_remark,
  4096. ScheduleRemark: schedule_remark,
  4097. CatheterOperation: catheter_operation,
  4098. BloodFlowVolume: blood_flow_volume,
  4099. }
  4100. //修改床位号需要重新消毒
  4101. if adminUserInfo.Org.Id == 9671 || adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 3877 {
  4102. service.UpdateDeviceInformation(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4103. //查询第一条监测
  4104. firstMonitor, _ := service.GetFirstMonitor(tempDialysisRecord.PatientId, tempDialysisRecord.DialysisDate)
  4105. service.UpdateFirstMonitor(firstMonitor.ID, catheter_operation)
  4106. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_records"
  4107. redis := service.RedisClient()
  4108. //清空key 值
  4109. redis.Set(key, "", time.Second)
  4110. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.DialysisDate, 10) + ":monitor_record_list_all"
  4111. redis.Set(keyOne, "", time.Second)
  4112. defer redis.Close()
  4113. }
  4114. // 查询信息规挡的设置天数
  4115. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4116. if infor.ID > 0 && infor.WeekDay > 0 {
  4117. var cha_time int64
  4118. timeNowStr := time.Now().Format("2006-01-02")
  4119. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4120. //今日的日期减去设置的日期
  4121. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4122. if cha_time >= record_date {
  4123. //查询审核是否允许
  4124. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecord.PatientId, record_date, adminUserInfo.Org.Id, 1)
  4125. //申请状态不允许的情况 拒绝修改
  4126. if infor.ApplicationStatus != 1 {
  4127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4128. return
  4129. }
  4130. }
  4131. }
  4132. updateErr := service.ModifyStartDialysisOrder(dialysisRecord)
  4133. order, _ := service.GetLastPatientOrder(record_id)
  4134. service.UpdateMobilePatient(adminUserInfo.Org.Id, order.PatientId, schedule_remark)
  4135. redis := service.RedisClient()
  4136. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_order"
  4137. redis.Set(key, "", time.Second)
  4138. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4139. //清空key 值
  4140. redis.Set(keyOne, "", time.Second)
  4141. scheduleDateStartOne := startDate.Format("2006-01-02")
  4142. keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4143. redis.Set(keyTwo, "", time.Second)
  4144. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":doctor_advices"
  4145. redis.Set(keyThree, "", time.Second)
  4146. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4147. redis.Set(keyFour, "", time.Second)
  4148. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  4149. redis.Set(keyFive, "", time.Second)
  4150. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":his_doctor_advice"
  4151. redis.Set(keySix, "", time.Second)
  4152. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  4153. redis.Set(keySeven, "", time.Second)
  4154. if updateErr != nil {
  4155. this.ErrorLog("修改上机失败:%v", updateErr)
  4156. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4157. return
  4158. }
  4159. if updateErr == nil {
  4160. if tempDialysisRecord.Stage == 2 {
  4161. temp_time := (float64(tempDialysisRecord.EndTime) - float64(startDate.Unix())) / 3600
  4162. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4163. fmt.Println(value)
  4164. a, b := math.Modf(value)
  4165. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4166. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4167. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4168. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecord.PatientId, tempDialysisRecord.UserOrgId, tempDialysisRecord.DialysisDate, hour, minute)
  4169. redis := service.RedisClient()
  4170. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis_list_all"
  4171. redis.Set(key, "", time.Second)
  4172. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecord.PatientId, 10) + ":" + strconv.FormatInt(record_date, 10) + ":assessment_after_dislysis"
  4173. redis.Set(keyOne, "", time.Second)
  4174. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":dialysis_orders_list_all"
  4175. //清空key 值
  4176. redis.Set(keySix, "", time.Second)
  4177. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(record_date, 10) + ":monitor_records"
  4178. redis.Set(keySeven, "", time.Second)
  4179. redis.Close()
  4180. if updateAssessmentErr != nil {
  4181. utils.ErrorLog("%v", updateAssessmentErr)
  4182. }
  4183. }
  4184. }
  4185. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4186. this.ServeSuccessJSON(map[string]interface{}{
  4187. "dialysis_order": dialysisRecords,
  4188. })
  4189. }
  4190. func (c *DialysisAPIController) ModifyFinishDialysisOrder() {
  4191. record_id, _ := c.GetInt64("id")
  4192. nurseID, _ := c.GetInt64("nurse")
  4193. end_time := c.GetString("end_time")
  4194. puncture_point_haematoma, _ := c.GetInt64("puncture_point_haematoma")
  4195. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  4196. catheter := c.GetString("catheter")
  4197. cruor := c.GetString("cruor")
  4198. mission := c.GetString("mission")
  4199. condenser := c.GetString("condenser")
  4200. if record_id <= 0 || nurseID <= 0 {
  4201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4202. return
  4203. }
  4204. adminUserInfo := c.GetMobileAdminUserInfo()
  4205. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  4206. if getNurseErr != nil {
  4207. c.ErrorLog("获取护士失败:%v", getNurseErr)
  4208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4209. return
  4210. } else if nurse == nil {
  4211. c.ErrorLog("护士不存在")
  4212. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4213. return
  4214. }
  4215. endDate, parseEndDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", end_time)
  4216. if parseEndDateErr != nil {
  4217. c.ErrorLog("日期(%v)解析错误:%v", end_time, parseEndDateErr)
  4218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4219. return
  4220. }
  4221. _, tempDialysisRecords := service.FindDialysisOrderById(record_id)
  4222. //if tempDialysisRecords.FinishCreator != adminUserInfo.AdminUser.Id {
  4223. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  4224. // if getPermissionErr != nil {
  4225. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4226. // return
  4227. // } else if headNursePermission == nil {
  4228. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  4229. // return
  4230. // }
  4231. //}
  4232. // 查询信息规挡的设置天数
  4233. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.Org.Id)
  4234. if infor.ID > 0 {
  4235. var cha_time int64
  4236. timeNowStr := time.Now().Format("2006-01-02")
  4237. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4238. //今日的日期减去设置的日期
  4239. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4240. if cha_time >= tempDialysisRecords.DialysisDate {
  4241. //查询审核是否允许
  4242. infor, _ := service.GetDialysisInformationByRecordDate(tempDialysisRecords.PatientId, tempDialysisRecords.DialysisDate, adminUserInfo.Org.Id, 6)
  4243. //申请状态不允许的情况 拒绝修改
  4244. if infor.ApplicationStatus != 1 {
  4245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4246. return
  4247. }
  4248. }
  4249. }
  4250. dialysisRecord := &models.DialysisOrder{
  4251. ID: record_id,
  4252. UserOrgId: adminUserInfo.Org.Id,
  4253. EndTime: endDate.Unix(),
  4254. FinishNurse: nurseID,
  4255. FinishModifier: adminUserInfo.AdminUser.Id,
  4256. PuncturePointHaematoma: puncture_point_haematoma,
  4257. BloodAccessInternalFistula: blood_access_internal_fistula,
  4258. Catheter: catheter,
  4259. Cruor: cruor,
  4260. Mission: mission,
  4261. Condenser: condenser,
  4262. }
  4263. updateErr := service.ModifyFinishDialysisOrder(dialysisRecord)
  4264. redis := service.RedisClient()
  4265. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_order"
  4266. //清空key 值
  4267. redis.Set(key, "", time.Second)
  4268. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4269. //清空key 值
  4270. redis.Set(keyOne, "", time.Second)
  4271. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4272. redis.Set(keySeven, "", time.Second)
  4273. redis.Close()
  4274. if updateErr != nil {
  4275. c.ErrorLog("修改下机失败:%v", updateErr)
  4276. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4277. return
  4278. }
  4279. if updateErr == nil {
  4280. temp_time := (float64(endDate.Unix()) - float64(tempDialysisRecords.StartTime)) / 3600
  4281. value, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", temp_time), 64)
  4282. a, b := math.Modf(value)
  4283. tempMinute, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", b), 64)
  4284. hour, _ := strconv.ParseInt(fmt.Sprintf("%.0f", a), 10, 64)
  4285. minute, _ := strconv.ParseInt(fmt.Sprintf("%.0f", tempMinute*60), 10, 64)
  4286. updateAssessmentErr := service.UpdateAssessmentAfterDate(tempDialysisRecords.PatientId, tempDialysisRecords.UserOrgId, tempDialysisRecords.DialysisDate, hour, minute)
  4287. redis := service.RedisClient()
  4288. keyTen := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis"
  4289. redis.Set(keyTen, "", time.Second)
  4290. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_last"
  4291. redis.Set(keyTwo, "", time.Second)
  4292. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":assessment_after_dislysis_list_all"
  4293. redis.Set(key, "", time.Second)
  4294. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":dialysis_orders_list_all"
  4295. redis.Set(keyThree, "", time.Second)
  4296. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(tempDialysisRecords.PatientId, 10) + ":" + strconv.FormatInt(tempDialysisRecords.DialysisDate, 10) + ":monitor_records"
  4297. redis.Set(keySeven, "", time.Second)
  4298. defer redis.Close()
  4299. if updateAssessmentErr != nil {
  4300. utils.ErrorLog("%v", updateAssessmentErr)
  4301. }
  4302. }
  4303. _, dialysisRecords := service.FindDialysisOrderById(record_id)
  4304. c.ServeSuccessJSON(map[string]interface{}{
  4305. "dialysis_order": dialysisRecords,
  4306. })
  4307. }
  4308. func (c *DialysisAPIController) GetLongAdvice() {
  4309. patient_id, _ := c.GetInt64("id")
  4310. adminUserInfo := c.GetMobileAdminUserInfo()
  4311. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4312. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4313. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4314. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4315. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4316. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4317. c.ServeSuccessJSON(map[string]interface{}{
  4318. "status": "1",
  4319. })
  4320. return
  4321. } else { //开启推送提醒
  4322. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4323. var advice_three []*models.DoctorAdvice
  4324. recordDateStr := time.Now().Format("2006-01-02")
  4325. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4326. nowtime := recordDate.Unix()
  4327. //advices, err := service.GetLastLongAdviceByGroupNoOne(adminUserInfo.Org.Id, patient_id,nowtime)
  4328. //fmt.Println("advices232333232323323233232333223233232322332",advices)
  4329. //advices_two, err := service.GetLastLongAdviceByGroupNoFour(adminUserInfo.Org.Id, patient_id,nowtime)
  4330. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, nowtime)
  4331. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, nowtime)
  4332. for _, advice := range advices {
  4333. if advice.FrequencyType == 3 {
  4334. t := time.Now()
  4335. week := int(t.Weekday())
  4336. fmt.Println(t.Weekday())
  4337. fmt.Println(week)
  4338. switch week {
  4339. case 1:
  4340. if strings.Index(advice.WeekDay, "周一") == -1 {
  4341. advice_three = append(advice_three, advice)
  4342. }
  4343. break
  4344. case 2:
  4345. if strings.Index(advice.WeekDay, "周二") == -1 {
  4346. advice_three = append(advice_three, advice)
  4347. }
  4348. break
  4349. case 3:
  4350. if strings.Index(advice.WeekDay, "周三") == -1 {
  4351. advice_three = append(advice_three, advice)
  4352. }
  4353. break
  4354. case 4:
  4355. if strings.Index(advice.WeekDay, "周四") == -1 {
  4356. advice_three = append(advice_three, advice)
  4357. }
  4358. break
  4359. case 5:
  4360. if strings.Index(advice.WeekDay, "周五") == -1 {
  4361. advice_three = append(advice_three, advice)
  4362. }
  4363. break
  4364. case 6:
  4365. if strings.Index(advice.WeekDay, "周六") == -1 {
  4366. advice_three = append(advice_three, advice)
  4367. }
  4368. break
  4369. case 0:
  4370. if strings.Index(advice.WeekDay, "周日") == -1 {
  4371. advice_three = append(advice_three, advice)
  4372. }
  4373. break
  4374. }
  4375. }
  4376. }
  4377. for _, advice := range advices_two {
  4378. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4379. now := p.Unix()
  4380. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4381. dayStr2 := "-" + dayStr
  4382. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4383. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4384. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4385. for _, ad := range advices {
  4386. advice_three = append(advice_three, ad)
  4387. }
  4388. }
  4389. if err == nil {
  4390. c.ServeSuccessJSON(map[string]interface{}{
  4391. "status": "2",
  4392. "advices": advices,
  4393. "advices_two": RemoveRepeatedElement(advice_three),
  4394. "is_open_remind": config.IsOpenRemind,
  4395. "his_config_open": hisConfig.IsOpen,
  4396. "is_advice_open": is_advice_open.IsAdviceOpen,
  4397. "prescription_open": prescription_open.IsOpen,
  4398. })
  4399. }
  4400. }
  4401. }
  4402. func (c *DialysisAPIController) GetLongAdviceOne() {
  4403. patient_id, _ := c.GetInt64("id")
  4404. startTime := c.GetString("schedule_date")
  4405. timeLayout := "2006-01-02"
  4406. loc, _ := time.LoadLocation("Local")
  4407. var theStartTime int64
  4408. if len(startTime) > 0 {
  4409. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", startTime+" 00:00:00", loc)
  4410. if err != nil {
  4411. utils.ErrorLog(err.Error())
  4412. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4413. return
  4414. }
  4415. theStartTime = theTime.Unix()
  4416. }
  4417. adminUserInfo := c.GetMobileAdminUserInfo()
  4418. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.Org.Id)
  4419. _, hisConfig := service.FindXTHisRecordByOrgId(adminUserInfo.Org.Id)
  4420. is_advice_open, _ := service.FindAdviceSettingById(adminUserInfo.Org.Id)
  4421. prescription_open, _ := service.FindPrescriptionConfigById(adminUserInfo.Org.Id)
  4422. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4423. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4424. c.ServeSuccessJSON(map[string]interface{}{
  4425. "status": "1",
  4426. })
  4427. return
  4428. } else { //开启推送提醒
  4429. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4430. var advice_three []*models.DoctorAdvice
  4431. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.Org.Id, patient_id, theStartTime)
  4432. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.Org.Id, patient_id, theStartTime)
  4433. for _, advice := range advices {
  4434. if advice.FrequencyType == 3 {
  4435. t := time.Now()
  4436. week := int(t.Weekday())
  4437. fmt.Println(t.Weekday())
  4438. fmt.Println(week)
  4439. switch week {
  4440. case 1:
  4441. if strings.Index(advice.WeekDay, "周一") == -1 {
  4442. advice_three = append(advice_three, advice)
  4443. }
  4444. break
  4445. case 2:
  4446. if strings.Index(advice.WeekDay, "周二") == -1 {
  4447. advice_three = append(advice_three, advice)
  4448. }
  4449. break
  4450. case 3:
  4451. if strings.Index(advice.WeekDay, "周三") == -1 {
  4452. advice_three = append(advice_three, advice)
  4453. }
  4454. break
  4455. case 4:
  4456. if strings.Index(advice.WeekDay, "周四") == -1 {
  4457. advice_three = append(advice_three, advice)
  4458. }
  4459. break
  4460. case 5:
  4461. if strings.Index(advice.WeekDay, "周五") == -1 {
  4462. advice_three = append(advice_three, advice)
  4463. }
  4464. break
  4465. case 6:
  4466. if strings.Index(advice.WeekDay, "周六") == -1 {
  4467. advice_three = append(advice_three, advice)
  4468. }
  4469. break
  4470. case 0:
  4471. if strings.Index(advice.WeekDay, "周日") == -1 {
  4472. advice_three = append(advice_three, advice)
  4473. }
  4474. break
  4475. }
  4476. }
  4477. }
  4478. for _, advice := range advices_two {
  4479. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4480. now := p.Unix()
  4481. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4482. dayStr2 := "-" + dayStr
  4483. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4484. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4485. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.Org.Id, advice.TemplateId)
  4486. for _, ad := range advices {
  4487. advice_three = append(advice_three, ad)
  4488. }
  4489. }
  4490. if err == nil {
  4491. c.ServeSuccessJSON(map[string]interface{}{
  4492. "status": "2",
  4493. "advices": advices,
  4494. "advices_two": RemoveRepeatedElement(advice_three),
  4495. "is_open_remind": config.IsOpenRemind,
  4496. "his_config_open": hisConfig.IsOpen,
  4497. "is_advice_open": is_advice_open.IsAdviceOpen,
  4498. "prescription_open": prescription_open.IsOpen,
  4499. })
  4500. }
  4501. }
  4502. }
  4503. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4504. newArr = make([]*models.DoctorAdvice, 0)
  4505. for i := 0; i < len(arr); i++ {
  4506. repeat := false
  4507. for j := i + 1; j < len(arr); j++ {
  4508. if arr[i].ID == arr[j].ID {
  4509. repeat = true
  4510. break
  4511. }
  4512. }
  4513. if !repeat {
  4514. newArr = append(newArr, arr[i])
  4515. }
  4516. }
  4517. return
  4518. }
  4519. func (c *DialysisAPIController) CreateRemindDoctorAdvice() {
  4520. patient, _ := c.GetInt64("id", 0)
  4521. groupNo, _ := c.GetInt64("groupno", 0)
  4522. if patient <= 0 {
  4523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4524. return
  4525. }
  4526. adminUserInfo := c.GetMobileAdminUserInfo()
  4527. dataBody := make(map[string]interface{}, 0)
  4528. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4529. if err != nil {
  4530. utils.ErrorLog(err.Error())
  4531. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4532. return
  4533. }
  4534. utils.ErrorLog("%v", dataBody)
  4535. timeLayout := "2006-01-02 15:04"
  4536. loc, _ := time.LoadLocation("Local")
  4537. timeLayout2 := "2006-01-02"
  4538. loc2, _ := time.LoadLocation("Local")
  4539. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4540. utils.ErrorLog("advice_type")
  4541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4542. return
  4543. }
  4544. adviceType := int64(2)
  4545. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4546. utils.ErrorLog("advice_date")
  4547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4548. return
  4549. }
  4550. adviceDate, _ := dataBody["advice_date"].(string)
  4551. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4552. AdviceDate := theTime.Unix()
  4553. RecordDate := theTime.Unix()
  4554. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4555. utils.ErrorLog("start_time")
  4556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4557. return
  4558. }
  4559. startTime, _ := dataBody["start_time"].(string)
  4560. if len(startTime) == 0 {
  4561. utils.ErrorLog("len(start_time) == 0")
  4562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4563. return
  4564. }
  4565. theTime, err = time.ParseInLocation(timeLayout, startTime, loc)
  4566. if err != nil {
  4567. utils.ErrorLog(err.Error())
  4568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4569. return
  4570. }
  4571. StartTime := theTime.Unix()
  4572. Remark := ""
  4573. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4574. remark, _ := dataBody["remark"].(string)
  4575. Remark = remark
  4576. }
  4577. var advices []*models.GroupAdvice
  4578. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4579. utils.ErrorLog("advices")
  4580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4581. return
  4582. }
  4583. adviceNames := dataBody["advices"].([]interface{})
  4584. for _, adviceNameMap := range adviceNames {
  4585. adviceNameM := adviceNameMap.(map[string]interface{})
  4586. var advice models.GroupAdvice
  4587. advice.Remark = Remark
  4588. advice.AdviceType = adviceType
  4589. advice.StartTime = StartTime
  4590. advice.AdviceDate = AdviceDate
  4591. advice.RecordDate = RecordDate
  4592. advice.Status = 1
  4593. advice.CreatedTime = time.Now().Unix()
  4594. advice.UpdatedTime = time.Now().Unix()
  4595. advice.StopState = 2
  4596. advice.ExecutionState = 2
  4597. advice.UserOrgId = adminUserInfo.Org.Id
  4598. advice.PatientId = patient
  4599. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4600. advice.IsSettle = 2
  4601. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4602. utils.ErrorLog("advice_name")
  4603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4604. return
  4605. }
  4606. adviceName, _ := adviceNameM["advice_name"].(string)
  4607. if len(adviceName) == 0 {
  4608. utils.ErrorLog("len(advice_name) == 0")
  4609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4610. return
  4611. }
  4612. advice.AdviceName = adviceName
  4613. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4614. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4615. advice.DrugSpec = drugSpec
  4616. }
  4617. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4618. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4619. advice.AdviceDesc = adviceDesc
  4620. }
  4621. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4622. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4623. advice.DrugSpecUnit = drugSpecUnit
  4624. }
  4625. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4626. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4627. // advice.SingleDose = singleDose
  4628. //}
  4629. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4630. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4631. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4632. }
  4633. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4634. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4635. advice.SingleDoseUnit = singleDoseUnit
  4636. }
  4637. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4638. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4639. // advice.PrescribingNumber = prescribingNumber
  4640. //}
  4641. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4642. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4643. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4644. }
  4645. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4646. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4647. advice.PrescribingNumberUnit = prescribingNumberUnit
  4648. }
  4649. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4650. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4651. advice.DeliveryWay = deliveryWay
  4652. }
  4653. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4654. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4655. advice.ExecutionFrequency = executionFrequency
  4656. }
  4657. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4658. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4659. advice.FrequencyType = frequency_type
  4660. }
  4661. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4662. day_count := int64(adviceNameM["day_count"].(float64))
  4663. advice.DayCount = day_count
  4664. }
  4665. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4666. week_day, _ := adviceNameM["week_day"].(string)
  4667. advice.WeekDay = week_day
  4668. }
  4669. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4670. way := int64(adviceNameM["way"].(float64))
  4671. advice.Way = way
  4672. }
  4673. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4674. drug_id := int64(adviceNameM["drug_id"].(float64))
  4675. advice.DrugId = drug_id
  4676. }
  4677. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4678. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4679. advice.DrugNameId = drug_name_id
  4680. }
  4681. if adviceNameM["remark"] != nil && reflect.TypeOf(adviceNameM["remark"]).String() == "string" {
  4682. remark, _ := adviceNameM["remark"].(string)
  4683. advice.Remark = remark
  4684. }
  4685. if adviceNameM["groupno"] != nil || reflect.TypeOf(adviceNameM["groupno"]).String() == "float64" {
  4686. groupno := int64(adviceNameM["groupno"].(float64))
  4687. advice.GroupNo = groupno
  4688. }
  4689. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4690. template_id, _ := adviceNameM["template_id"].(string)
  4691. advice.TemplateId = template_id
  4692. }
  4693. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "string" {
  4694. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4695. advice.ExecutionFrequency = executionFrequency
  4696. }
  4697. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4698. children := adviceNameM["child"].([]interface{})
  4699. if len(children) > 0 {
  4700. for _, childrenMap := range children {
  4701. childMap := childrenMap.(map[string]interface{})
  4702. var child models.GroupAdvice
  4703. child.Remark = Remark
  4704. child.AdviceType = adviceType
  4705. child.StartTime = StartTime
  4706. child.AdviceDate = AdviceDate
  4707. child.RecordDate = RecordDate
  4708. child.Status = 1
  4709. child.CreatedTime = time.Now().Unix()
  4710. child.UpdatedTime = time.Now().Unix()
  4711. child.StopState = 2
  4712. child.ExecutionState = 2
  4713. child.UserOrgId = adminUserInfo.Org.Id
  4714. child.PatientId = patient
  4715. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4716. child.IsSettle = 1
  4717. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4718. utils.ErrorLog("child advice_name")
  4719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4720. return
  4721. }
  4722. childAdviceName, _ := childMap["advice_name"].(string)
  4723. if len(childAdviceName) == 0 {
  4724. utils.ErrorLog("len(child advice_name) == 0")
  4725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4726. return
  4727. }
  4728. child.AdviceName = childAdviceName
  4729. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4730. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4731. child.AdviceDesc = childAdviceDesc
  4732. }
  4733. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4734. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4735. child.DrugSpec = childDrugSpec
  4736. }
  4737. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4738. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4739. child.DrugSpecUnit = childDrugSpecUnit
  4740. }
  4741. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4742. child.SingleDose = childMap["single_dose"].(float64)
  4743. }
  4744. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4745. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4746. child.SingleDoseUnit = childSingleDoseUnit
  4747. }
  4748. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4749. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4750. }
  4751. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4752. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4753. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4754. }
  4755. if childMap["groupno"] != nil || reflect.TypeOf(childMap["groupno"]).String() == "float64" {
  4756. groupno := int64(childMap["groupno"].(float64))
  4757. advice.GroupNo = groupno
  4758. }
  4759. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4760. remark, _ := childMap["remark"].(string)
  4761. child.Remark = remark
  4762. }
  4763. child.DeliveryWay = advice.DeliveryWay
  4764. child.ExecutionFrequency = advice.ExecutionFrequency
  4765. advice.Children = append(advice.Children, &child)
  4766. }
  4767. }
  4768. }
  4769. temp_advice, _ := service.FindRemindAdvice(advice.UserOrgId, advice.AdviceName, advice.AdviceDesc, advice.TemplateId, advice.FrequencyType, patient, advice.RecordDate)
  4770. if temp_advice.ID == 0 {
  4771. advices = append(advices, &advice)
  4772. }
  4773. }
  4774. if len(advices) > 0 {
  4775. finish := models.XtDialysisFinish{
  4776. IsFinish: 1,
  4777. UserOrgId: adminUserInfo.Org.Id,
  4778. Status: 1,
  4779. Ctime: time.Now().Unix(),
  4780. Mtime: 0,
  4781. Module: 4,
  4782. RecordDate: AdviceDate,
  4783. Sourse: 1,
  4784. PatientId: patient,
  4785. }
  4786. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.Org.Id, AdviceDate, 4, patient)
  4787. if dialysisFinish.ID == 0 {
  4788. service.CreateDialysisFinish(finish)
  4789. }
  4790. if adminUserInfo.Org.Id == 10597 || adminUserInfo.Org.Id == 3877 || adminUserInfo.Org.Id == 10164 || adminUserInfo.Org.Id == 9671 {
  4791. list, err := service.CreateMGroupAdviceOne(adminUserInfo.Org.Id, advices, groupNo)
  4792. for _, item := range advices {
  4793. byterequest, _ := json.Marshal(item)
  4794. adviceLog := models.XtDoctorAdviceLog{
  4795. UserOrgId: adminUserInfo.Org.Id,
  4796. PatientId: patient,
  4797. AdminUserId: adminUserInfo.AdminUser.Id,
  4798. Module: 1,
  4799. ErrLog: string(byterequest),
  4800. Status: 1,
  4801. Ctime: time.Now().Unix(),
  4802. Mtime: 0,
  4803. Source: "手机端医嘱推送",
  4804. RecordDate: item.AdviceDate,
  4805. }
  4806. service.CreateDoctorAdviceLog(adviceLog)
  4807. }
  4808. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4809. redis := service.RedisClient()
  4810. //清空key 值
  4811. redis.Set(key, "", time.Second)
  4812. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4813. redis.Set(keyOne, "", time.Second)
  4814. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4815. defer redis.Close()
  4816. redis.Set(keyThree, "", time.Second)
  4817. if err != nil {
  4818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4819. return
  4820. }
  4821. c.ServeSuccessJSON(map[string]interface{}{
  4822. "msg": "ok",
  4823. "advices": list,
  4824. })
  4825. } else {
  4826. list, err := service.CreateMGroupAdvice(adminUserInfo.Org.Id, advices, groupNo)
  4827. for _, item := range advices {
  4828. byterequest, _ := json.Marshal(item)
  4829. adviceLog := models.XtDoctorAdviceLog{
  4830. UserOrgId: adminUserInfo.Org.Id,
  4831. PatientId: patient,
  4832. AdminUserId: adminUserInfo.AdminUser.Id,
  4833. Module: 1,
  4834. ErrLog: string(byterequest),
  4835. Status: 1,
  4836. Ctime: time.Now().Unix(),
  4837. Mtime: 0,
  4838. Source: "手机端医嘱推送",
  4839. RecordDate: item.AdviceDate,
  4840. }
  4841. service.CreateDoctorAdviceLog(adviceLog)
  4842. }
  4843. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(RecordDate, 10) + ":doctor_advices"
  4844. redis := service.RedisClient()
  4845. //清空key 值
  4846. redis.Set(key, "", time.Second)
  4847. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4848. redis.Set(keyOne, "", time.Second)
  4849. keyThree := "scheduals_" + adviceDate + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  4850. defer redis.Close()
  4851. redis.Set(keyThree, "", time.Second)
  4852. if err != nil {
  4853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4854. return
  4855. }
  4856. c.ServeSuccessJSON(map[string]interface{}{
  4857. "msg": "ok",
  4858. "advices": list,
  4859. })
  4860. }
  4861. } else {
  4862. c.ServeSuccessJSON(map[string]interface{}{
  4863. "msg": "ok",
  4864. })
  4865. }
  4866. return
  4867. }
  4868. func (c *DialysisAPIController) UploadDryWeight() {
  4869. patient_id, _ := c.GetInt64("id")
  4870. dry_weight, _ := c.GetFloat("dry_weight")
  4871. doctor_id, _ := c.GetInt64("doctor_id")
  4872. remark := c.GetString("remark")
  4873. adminUserInfo := c.GetMobileAdminUserInfo()
  4874. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, patient_id)
  4875. if err == gorm.ErrRecordNotFound {
  4876. dryWeight := &models.SgjPatientDryweight{
  4877. PatientId: patient_id,
  4878. DryWeight: dry_weight,
  4879. Remakes: remark,
  4880. Ctime: time.Now().Unix(),
  4881. Mtime: time.Now().Unix(),
  4882. Creator: doctor_id,
  4883. Status: 1,
  4884. UserOrgId: adminUserInfo.Org.Id,
  4885. AdjustedValue: "/",
  4886. UserId: adminUserInfo.AdminUser.Id,
  4887. }
  4888. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4889. redis := service.RedisClient()
  4890. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":assessment_befores_list_all"
  4891. redis.Set(keyOne, "", time.Second)
  4892. loc, _ := time.LoadLocation("Local")
  4893. nowTime := time.Now()
  4894. nowDay := nowTime.Format("2006-01-02")
  4895. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4896. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4897. redis.Set(key, "", time.Second)
  4898. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4899. redis.Set(keyTwo, "", time.Second)
  4900. redis.Close()
  4901. if createErr == nil {
  4902. c.ServeSuccessJSON(map[string]interface{}{
  4903. "msg": "提交成功",
  4904. "weight": dryWeight,
  4905. })
  4906. }
  4907. } else {
  4908. dryWeight := &models.SgjPatientDryweight{
  4909. PatientId: patient_id,
  4910. DryWeight: dry_weight,
  4911. Remakes: remark,
  4912. Ctime: time.Now().Unix(),
  4913. Mtime: time.Now().Unix(),
  4914. Creator: doctor_id,
  4915. Status: 1,
  4916. UserOrgId: adminUserInfo.Org.Id,
  4917. AdjustedValue: "/",
  4918. UserId: adminUserInfo.AdminUser.Id,
  4919. }
  4920. var value float64
  4921. value = dry_weight - weightAdjust.DryWeight
  4922. if value < 0 {
  4923. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4924. } else if value == 0 {
  4925. dryWeight.AdjustedValue = "/"
  4926. } else if value > 0 {
  4927. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4928. }
  4929. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4930. redis := service.RedisClient()
  4931. loc, _ := time.LoadLocation("Local")
  4932. nowTime := time.Now()
  4933. nowDay := nowTime.Format("2006-01-02")
  4934. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4935. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4936. redis.Set(keyOne, "", time.Second)
  4937. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4938. redis.Set(key, "", time.Second)
  4939. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4940. redis.Set(keyTwo, "", time.Second)
  4941. redis.Close()
  4942. if createErr == nil {
  4943. c.ServeSuccessJSON(map[string]interface{}{
  4944. "msg": "提交成功",
  4945. "weight": dryWeight,
  4946. })
  4947. }
  4948. }
  4949. }
  4950. func (c *DialysisAPIController) GetSolution() {
  4951. patient_id, _ := c.GetInt64("patient_id")
  4952. mode_id, _ := c.GetInt64("mode_id")
  4953. adminUserInfo := c.GetMobileAdminUserInfo()
  4954. solution, err := service.MobileGetDialysisSolutionByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4955. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, patient_id, mode_id)
  4956. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSeven(adminUserInfo.Org.Id, mode_id)
  4957. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.Org.Id)
  4958. if err != nil {
  4959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4960. return
  4961. }
  4962. c.ServeSuccessJSON(map[string]interface{}{
  4963. "solution": solution,
  4964. "prescription": prescription,
  4965. "system_prescription": system_prescription,
  4966. "dialysisPrescription": dialysisPrescription,
  4967. })
  4968. }
  4969. func (c *DialysisAPIController) GetSchedule() {
  4970. schedual_type, _ := c.GetInt64("schedual_type")
  4971. adminUserInfo := c.GetMobileAdminUserInfo()
  4972. scheduleTime, _ := c.GetInt64("record_date")
  4973. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.Org.Id, scheduleTime, schedual_type)
  4974. list, _ := service.GetAllBedNumberSeven(adminUserInfo.Org.Id)
  4975. c.ServeSuccessJSON(map[string]interface{}{
  4976. "number": deviceNumber,
  4977. "list": list,
  4978. })
  4979. }
  4980. func (c *DialysisAPIController) GetPatientId() {
  4981. id, _ := c.GetInt64("id")
  4982. //orgid := c.GetMobileAdminUserInfo().Org.Id
  4983. patientId, _ := service.GetPatientId(id)
  4984. //获取该患者的所有传染病
  4985. list, _ := service.GetPatientInfectious(id)
  4986. c.ServeSuccessJSON(map[string]interface{}{
  4987. "patient": patientId,
  4988. "infectioulist": list,
  4989. })
  4990. }
  4991. func (this *DialysisAPIController) GetDialysisSchedule() {
  4992. schedualDate := this.GetString("date")
  4993. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4994. if parseDateErr != nil {
  4995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4996. return
  4997. }
  4998. adminInfo := this.GetMobileAdminUserInfo()
  4999. orgID := adminInfo.Org.Id
  5000. redis := service.RedisClient()
  5001. defer redis.Close()
  5002. key := "scheduals_" + schedualDate + "_" + strconv.FormatInt(orgID, 10)
  5003. scheduals, _ := service.MobileGetDialysisScheduals(orgID, date.Unix(), 0)
  5004. if len(scheduals) > 0 {
  5005. //缓存数据
  5006. scheduals_json, err := json.Marshal(scheduals)
  5007. if err == nil {
  5008. redis.Set(key, scheduals_json, time.Second*30)
  5009. }
  5010. }
  5011. this.ServeSuccessJSON(map[string]interface{}{
  5012. "scheduals": scheduals,
  5013. })
  5014. }
  5015. func (this *DialysisAPIController) GetLastOrNextDoctorAdvice() {
  5016. change_type, _ := this.GetInt64("type", 0)
  5017. record_date := this.GetString("record_time")
  5018. patient_id, _ := this.GetInt64("patient_id", 0)
  5019. timeLayout := "2006-01-02"
  5020. loc, _ := time.LoadLocation("Local")
  5021. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5022. record_time := theAdviceRecordTime.Unix()
  5023. adminUserInfo := this.GetMobileAdminUserInfo()
  5024. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.Org.Id, patient_id)
  5025. if err == nil {
  5026. if len(advices) == 0 {
  5027. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5028. return
  5029. } else {
  5030. this.ServeSuccessJSON(map[string]interface{}{
  5031. "advices": advices,
  5032. "schedule": sch,
  5033. })
  5034. return
  5035. }
  5036. } else {
  5037. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5038. return
  5039. }
  5040. }
  5041. func (c *DialysisAPIController) CreateConsumables() {
  5042. record_date := c.GetString("record_time")
  5043. patient_id, _ := c.GetInt64("patient_id", 0)
  5044. active, _ := c.GetInt64("active")
  5045. adminUser := c.GetMobileAdminUserInfo()
  5046. timeLayout := "2006-01-02"
  5047. loc, _ := time.LoadLocation("Local")
  5048. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5049. record_time := theRecordTime.Unix()
  5050. // 查询信息规挡的设置天数
  5051. orgid := c.GetMobileAdminUserInfo().Org.Id
  5052. infor, _ := service.GetDialysisInformationSetting(adminUser.Org.Id)
  5053. if infor.ID > 0 {
  5054. var cha_time int64
  5055. timeNowStr := time.Now().Format("2006-01-02")
  5056. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5057. //今日的日期减去设置的日期
  5058. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5059. if cha_time >= record_time {
  5060. //查询审核是否允许
  5061. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, orgid, 11)
  5062. //申请状态不允许的情况 拒绝修改
  5063. if infor.ApplicationStatus != 1 {
  5064. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5065. return
  5066. }
  5067. }
  5068. }
  5069. dataBody := make(map[string]interface{}, 0)
  5070. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5071. if err != nil {
  5072. utils.ErrorLog(err.Error())
  5073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5074. return
  5075. }
  5076. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5077. var beforePrepares []*models.DialysisBeforePrepareGoods
  5078. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  5079. var dialysisBefor []*models.DialysisBeforePrepare
  5080. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  5081. goods, _ := dataBody["goods"].([]interface{})
  5082. if len(goods) > 0 {
  5083. for _, item := range goods {
  5084. items := item.(map[string]interface{})
  5085. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  5086. utils.ErrorLog("good_id")
  5087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5088. return
  5089. }
  5090. good_id := int64(items["good_id"].(float64))
  5091. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  5092. utils.ErrorLog("good_type_id")
  5093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5094. return
  5095. }
  5096. good_type_id := int64(items["good_type_id"].(float64))
  5097. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  5098. utils.ErrorLog("count")
  5099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5100. return
  5101. }
  5102. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  5103. commdity_code := items["commdity_code"].(string)
  5104. fmt.Println("commdity", commdity_code)
  5105. prepareGoods := &models.DialysisBeforePrepareGoods{
  5106. GoodTypeId: good_type_id,
  5107. GoodId: good_id,
  5108. Count: count,
  5109. StorehouseId: houseConfig.StorehouseOutInfo,
  5110. }
  5111. beforePrepares = append(beforePrepares, prepareGoods)
  5112. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  5113. GoodTypeId: good_type_id,
  5114. GoodId: good_id,
  5115. Count: count,
  5116. StorehouseId: houseConfig.StorehouseOutInfo,
  5117. }
  5118. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  5119. prepare := &models.DialysisBeforePrepare{
  5120. GoodTypeId: good_type_id,
  5121. GoodId: good_id,
  5122. Count: count,
  5123. PatientId: patient_id,
  5124. RecordDate: record_time,
  5125. UserOrgId: adminUser.Org.Id,
  5126. Status: 1,
  5127. Ctime: time.Now().Unix(),
  5128. Creater: adminUser.AdminUser.Id,
  5129. CommdityCode: commdity_code,
  5130. StorehouseId: houseConfig.StorehouseOutInfo,
  5131. }
  5132. dialysisBefor = append(dialysisBefor, prepare)
  5133. }
  5134. }
  5135. //查询是否有库存
  5136. for _, item := range dialysisBefor {
  5137. _, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5138. if err == gorm.ErrRecordNotFound {
  5139. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5140. c.ServeSuccessJSON(map[string]interface{}{
  5141. "message": "1",
  5142. "good_name": goodObj.GoodName,
  5143. "specification_name": goodObj.SpecificationName,
  5144. })
  5145. return
  5146. }
  5147. if err != nil {
  5148. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5149. c.ServeSuccessJSON(map[string]interface{}{
  5150. "message": "1",
  5151. "good_name": goodObj.GoodName,
  5152. "specification_name": goodObj.SpecificationName,
  5153. })
  5154. return
  5155. }
  5156. }
  5157. //新增
  5158. if active == 1 && len(goods) > 0 {
  5159. for _, item := range dialysisBefor {
  5160. dialyPrepareOne := models.DialysisBeforePrepare{
  5161. GoodTypeId: item.GoodTypeId,
  5162. GoodId: item.GoodId,
  5163. PatientId: item.PatientId,
  5164. RecordDate: item.RecordDate,
  5165. UserOrgId: item.UserOrgId,
  5166. Count: item.Count,
  5167. Ctime: time.Now().Unix(),
  5168. Creater: item.Creater,
  5169. CommdityCode: item.CommdityCode,
  5170. Status: 1,
  5171. StorehouseId: houseConfig.StorehouseOutInfo,
  5172. }
  5173. //先清除再插入
  5174. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5175. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5176. //查询默认仓库
  5177. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5178. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5179. var total_count int64
  5180. for _, it := range stockList {
  5181. total_count += it.StockCount
  5182. }
  5183. //基础库插入数据
  5184. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5185. //更新库存
  5186. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5187. var flush_count int64
  5188. for _, it := range goodList {
  5189. flush_count += it.StockCount
  5190. }
  5191. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5192. }
  5193. if err == nil {
  5194. c.ServeSuccessJSON(map[string]interface{}{
  5195. "msg": "保存成功",
  5196. "message": "2",
  5197. })
  5198. return
  5199. } else {
  5200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5201. return
  5202. }
  5203. }
  5204. if len(beforePrepares) > 0 && active == 2 {
  5205. for _, item := range beforePrepares {
  5206. //1.查看该患者该耗材型号最后一次出库数量
  5207. goodInfo, _ := service.GetLastGoodListByPatientId(record_time, patient_id, item.GoodId, item.GoodTypeId)
  5208. //判断当前出库数量和最后一次出库数量的大小
  5209. //如果当前出库数量小于或等于最后一次出库数量 正常出库后 需要退库操作
  5210. if item.Count <= goodInfo.Count {
  5211. //退库
  5212. err = ConsumablesDeliveryTotalSeven(adminUser.Org.Id, patient_id, record_time, beforePrepares, adminUser.AdminUser.Id, item.Count)
  5213. //查询今日出库数据
  5214. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5215. for _, it := range list {
  5216. prepare := models.DialysisBeforePrepare{
  5217. UserOrgId: it.OrgId,
  5218. PatientId: patient_id,
  5219. RecordDate: it.RecordTime,
  5220. GoodId: it.GoodId,
  5221. GoodTypeId: it.GoodTypeId,
  5222. Count: it.Count,
  5223. Ctime: time.Now().Unix(),
  5224. Creater: adminUser.AdminUser.Id,
  5225. Status: 1,
  5226. StorehouseId: houseConfig.StorehouseOutInfo,
  5227. }
  5228. //删除准备表数据
  5229. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5230. service.CreateDialysisBeforePrepareOne(&prepare)
  5231. }
  5232. }
  5233. var last_total int64
  5234. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  5235. if item.Count >= goodInfo.Count {
  5236. //查询当前批次当前耗材最后一条出库数据
  5237. lastOutInfo, _ := service.GetLastWarehouOutInfoByPatientId(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5238. //计算当前出库和最后一次出库数据相差数据
  5239. last_total = item.Count - lastOutInfo.Count
  5240. //查询该批次剩余库存
  5241. lastInfo, _ := service.GetLastStockOut(lastOutInfo.WarehouseInfotId)
  5242. //比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
  5243. if lastInfo.StockCount >= last_total {
  5244. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5245. //查询今日出库数据
  5246. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5247. for _, it := range list {
  5248. prepare := models.DialysisBeforePrepare{
  5249. UserOrgId: it.OrgId,
  5250. PatientId: patient_id,
  5251. RecordDate: it.RecordTime,
  5252. GoodId: it.GoodId,
  5253. GoodTypeId: it.GoodTypeId,
  5254. Count: it.Count,
  5255. Ctime: time.Now().Unix(),
  5256. Creater: adminUser.AdminUser.Id,
  5257. Status: 1,
  5258. StorehouseId: houseConfig.StorehouseOutInfo,
  5259. }
  5260. //删除准备表数据
  5261. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5262. service.CreateDialysisBeforePrepareOne(&prepare)
  5263. //查询默认仓库
  5264. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5265. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5266. var total_count int64
  5267. for _, it := range stockList {
  5268. total_count += it.StockCount
  5269. }
  5270. //基础库插入数据
  5271. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5272. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5273. var flush_count int64
  5274. for _, it := range goodList {
  5275. flush_count += it.StockCount
  5276. }
  5277. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5278. }
  5279. }
  5280. //如果库存不够,则出库到下一个批次
  5281. if lastInfo.StockCount < last_total {
  5282. err = ConsumablesDeliveryTotalSix(adminUser.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminUser.AdminUser.Id)
  5283. //查询今日出库数据
  5284. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminUser.Org.Id, patient_id, record_time)
  5285. for _, it := range list {
  5286. prepare := models.DialysisBeforePrepare{
  5287. UserOrgId: it.OrgId,
  5288. PatientId: patient_id,
  5289. RecordDate: it.RecordTime,
  5290. GoodId: it.GoodId,
  5291. GoodTypeId: it.GoodTypeId,
  5292. Count: it.Count,
  5293. Ctime: time.Now().Unix(),
  5294. Creater: adminUser.AdminUser.Id,
  5295. Status: 1,
  5296. StorehouseId: houseConfig.StorehouseOutInfo,
  5297. }
  5298. //删除准备表数据
  5299. service.DeleteDialysisBefor(adminUser.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5300. service.CreateDialysisBeforePrepareOne(&prepare)
  5301. //查询默认仓库
  5302. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUser.Org.Id)
  5303. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminUser.Org.Id)
  5304. var total_count int64
  5305. for _, it := range stockList {
  5306. total_count += it.StockCount
  5307. }
  5308. //基础库插入数据
  5309. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminUser.Org.Id)
  5310. goodList, _ := service.GetSumGoodList(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5311. var flush_count int64
  5312. for _, it := range goodList {
  5313. flush_count += it.StockCount
  5314. }
  5315. service.UpdateSumGood(adminUser.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5316. }
  5317. if err != nil {
  5318. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5319. c.ServeSuccessJSON(map[string]interface{}{
  5320. "message": "1",
  5321. "good_name": goodObj.GoodName,
  5322. "specification_name": goodObj.SpecificationName,
  5323. })
  5324. return
  5325. }
  5326. }
  5327. }
  5328. if err != nil {
  5329. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5330. c.ServeSuccessJSON(map[string]interface{}{
  5331. "message": "1",
  5332. "good_name": goodObj.GoodName,
  5333. "specification_name": goodObj.SpecificationName,
  5334. })
  5335. return
  5336. }
  5337. }
  5338. }
  5339. }
  5340. var errs error
  5341. if errs == nil {
  5342. c.ServeSuccessJSON(map[string]interface{}{
  5343. "msg": "提交成功",
  5344. "message": "2",
  5345. "good_name": "",
  5346. "specification_name": "",
  5347. })
  5348. return
  5349. } else {
  5350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5351. return
  5352. }
  5353. }
  5354. func (c *DialysisAPIController) CreateStockOutInfo() {
  5355. patient_id, _ := c.GetInt64("patient_id", 0)
  5356. record_date := c.GetString("record_time")
  5357. if patient_id <= 0 {
  5358. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5359. return
  5360. }
  5361. adminInfo := c.GetMobileAdminUserInfo()
  5362. creator := c.GetMobileAdminUserInfo().AdminUser.Id
  5363. timeLayout := "2006-01-02"
  5364. loc, _ := time.LoadLocation("Local")
  5365. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5366. record_time := theRecordTime.Unix()
  5367. // 查询信息规挡的设置天数
  5368. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  5369. if infor.ID > 0 && infor.WeekDay > 0 {
  5370. var cha_time int64
  5371. timeNowStr := time.Now().Format("2006-01-02")
  5372. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5373. //今日的日期减去设置的日期
  5374. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  5375. if cha_time >= record_time {
  5376. //查询审核是否允许
  5377. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  5378. //申请状态不允许的情况 拒绝修改
  5379. if infor.ApplicationStatus != 1 {
  5380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  5381. return
  5382. }
  5383. }
  5384. }
  5385. //创建步骤表
  5386. finish := models.XtDialysisFinish{
  5387. IsFinish: 1,
  5388. UserOrgId: adminInfo.Org.Id,
  5389. Status: 1,
  5390. Ctime: time.Now().Unix(),
  5391. Mtime: 0,
  5392. Module: 11,
  5393. RecordDate: record_time,
  5394. Sourse: 1,
  5395. PatientId: patient_id,
  5396. }
  5397. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  5398. if dialysisFinish.ID == 0 {
  5399. service.CreateDialysisFinish(finish)
  5400. }
  5401. consumables, _ := service.FindConsumablesByDate(adminInfo.Org.Id, patient_id, record_time)
  5402. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  5403. //去重
  5404. consumables = RemoveRepeatedGood(consumables)
  5405. if adminInfo.Org.Id == 9919 {
  5406. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5407. //查询是否有库存
  5408. for _, item := range consumables {
  5409. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5410. if item.Count > warehouse.Count {
  5411. goodErrcode := models.XtGoodErrcode{
  5412. UserOrgId: item.UserOrgId,
  5413. Errcode: "自动出库库存不足",
  5414. GoodId: item.GoodId,
  5415. Status: 1,
  5416. Ctime: time.Now().Unix(),
  5417. Mtime: 0,
  5418. Count: 0,
  5419. StockCount: 0,
  5420. Creater: creator,
  5421. BatchNumberId: warehouse.ID,
  5422. WarehouseOutId: 0,
  5423. }
  5424. service.CreateGoodErrcode(goodErrcode)
  5425. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5426. c.ServeSuccessJSON(map[string]interface{}{
  5427. "message": "1",
  5428. "good_name": goodObj.GoodName,
  5429. "specification_name": goodObj.SpecificationName,
  5430. })
  5431. return
  5432. }
  5433. }
  5434. //查询是否有出库单
  5435. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5436. if err == gorm.ErrRecordNotFound {
  5437. //没有记录,则创建出库单
  5438. timeStr := time.Now().Format("2006-01-02")
  5439. timeArr := strings.Split(timeStr, "-")
  5440. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5441. total = total + 1
  5442. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5443. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5444. number = number + total
  5445. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5446. creater := adminInfo.AdminUser.Id
  5447. warehouseOut := models.WarehouseOut{
  5448. WarehouseOutOrderNumber: warehousing_out_order,
  5449. OperationTime: time.Now().Unix(),
  5450. OrgId: adminInfo.Org.Id,
  5451. Creater: creater,
  5452. Ctime: time.Now().Unix(),
  5453. Status: 1,
  5454. WarehouseOutTime: record_time,
  5455. Dealer: 0,
  5456. Manufacturer: 0,
  5457. Type: 1,
  5458. IsSys: 1,
  5459. StorehouseId: houseConfig.StorehouseOutInfo,
  5460. IsCheck: 1,
  5461. }
  5462. err := service.AddSigleWarehouseOut(&warehouseOut)
  5463. if err != nil {
  5464. goodErrcode := models.XtGoodErrcode{
  5465. UserOrgId: adminInfo.Org.Id,
  5466. Errcode: "创建出库单失败",
  5467. GoodId: 0,
  5468. Status: 1,
  5469. Ctime: time.Now().Unix(),
  5470. Mtime: 0,
  5471. Count: 0,
  5472. StockCount: 0,
  5473. Creater: creator,
  5474. BatchNumberId: 0,
  5475. WarehouseOutId: 0,
  5476. }
  5477. service.CreateGoodErrcode(goodErrcode)
  5478. utils.TraceLog("创建出库单失败 err = %v", err)
  5479. } else {
  5480. for _, item := range consumables {
  5481. //出库
  5482. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5483. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5484. if err == nil {
  5485. goodErrcode := models.XtGoodErrcode{
  5486. UserOrgId: adminInfo.Org.Id,
  5487. Errcode: "自动出库接口报错",
  5488. GoodId: 0,
  5489. Status: 1,
  5490. Ctime: time.Now().Unix(),
  5491. Mtime: 0,
  5492. Count: 0,
  5493. StockCount: 0,
  5494. Creater: creator,
  5495. BatchNumberId: 0,
  5496. WarehouseOutId: 0,
  5497. }
  5498. service.CreateGoodErrcode(goodErrcode)
  5499. utils.TraceLog("创建出库单失败 err = %v", err)
  5500. }
  5501. //查询
  5502. //出库数量相加
  5503. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5504. if errs != nil {
  5505. goodErrcode := models.XtGoodErrcode{
  5506. UserOrgId: item.UserOrgId,
  5507. Errcode: "创建剩余库存字段报错",
  5508. GoodId: item.GoodId,
  5509. Status: 1,
  5510. Ctime: time.Now().Unix(),
  5511. Mtime: 0,
  5512. Count: 0,
  5513. StockCount: 0,
  5514. Creater: creater,
  5515. BatchNumberId: 0,
  5516. WarehouseOutId: 0,
  5517. }
  5518. service.CreateGoodErrcode(goodErrcode)
  5519. }
  5520. }
  5521. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5522. if len(list) == 0 {
  5523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5524. return
  5525. }
  5526. for _, item := range list {
  5527. prepare := models.DialysisBeforePrepare{
  5528. UserOrgId: adminInfo.Org.Id,
  5529. PatientId: patient_id,
  5530. RecordDate: record_time,
  5531. GoodId: item.GoodId,
  5532. GoodTypeId: item.GoodTypeId,
  5533. Count: item.Count,
  5534. Creater: adminInfo.AdminUser.Id,
  5535. Status: 1,
  5536. Ctime: time.Now().Unix(),
  5537. StorehouseId: houseConfig.StorehouseOutInfo,
  5538. }
  5539. //清空准备表数据
  5540. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5541. if err != nil {
  5542. goodErrcode := models.XtGoodErrcode{
  5543. UserOrgId: item.OrgId,
  5544. Errcode: "自动出库清空准备表数据报错",
  5545. GoodId: item.GoodId,
  5546. Status: 1,
  5547. Ctime: time.Now().Unix(),
  5548. Mtime: 0,
  5549. Count: 0,
  5550. StockCount: 0,
  5551. Creater: creater,
  5552. BatchNumberId: 0,
  5553. WarehouseOutId: 0,
  5554. }
  5555. service.CreateGoodErrcode(goodErrcode)
  5556. }
  5557. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5558. if errs != nil {
  5559. goodErrcode := models.XtGoodErrcode{
  5560. UserOrgId: item.OrgId,
  5561. Errcode: "自动出库创建准备表数据报错",
  5562. GoodId: item.GoodId,
  5563. Status: 1,
  5564. Ctime: time.Now().Unix(),
  5565. Mtime: 0,
  5566. Count: 0,
  5567. StockCount: 0,
  5568. Creater: creater,
  5569. BatchNumberId: 0,
  5570. WarehouseOutId: 0,
  5571. }
  5572. service.CreateGoodErrcode(goodErrcode)
  5573. }
  5574. //查询默认仓库
  5575. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5576. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5577. var total_count int64
  5578. for _, it := range stockList {
  5579. total_count += it.StockCount
  5580. }
  5581. //基础库插入数据
  5582. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5583. if errcodes != nil {
  5584. goodErrcode := models.XtGoodErrcode{
  5585. UserOrgId: item.OrgId,
  5586. Errcode: "自动出库基础库插入数据",
  5587. GoodId: item.GoodId,
  5588. Status: 1,
  5589. Ctime: time.Now().Unix(),
  5590. Mtime: 0,
  5591. Count: 0,
  5592. StockCount: 0,
  5593. Creater: creater,
  5594. BatchNumberId: 0,
  5595. WarehouseOutId: 0,
  5596. }
  5597. service.CreateGoodErrcode(goodErrcode)
  5598. }
  5599. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5600. var flush_count int64
  5601. for _, it := range goodList {
  5602. flush_count += it.StockCount
  5603. }
  5604. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5605. if errsss != nil {
  5606. goodErrcode := models.XtGoodErrcode{
  5607. UserOrgId: item.OrgId,
  5608. Errcode: "自动出库剩余库存更新数据",
  5609. GoodId: item.GoodId,
  5610. Status: 1,
  5611. Ctime: time.Now().Unix(),
  5612. Mtime: 0,
  5613. Count: 0,
  5614. StockCount: 0,
  5615. Creater: creater,
  5616. BatchNumberId: 0,
  5617. WarehouseOutId: 0,
  5618. }
  5619. service.CreateGoodErrcode(goodErrcode)
  5620. }
  5621. }
  5622. }
  5623. //
  5624. } else if err == nil {
  5625. for _, item := range consumables {
  5626. //出库
  5627. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5628. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5629. if err != nil {
  5630. goodErrcode := models.XtGoodErrcode{
  5631. UserOrgId: adminInfo.Org.Id,
  5632. Errcode: "自动出库接口报错",
  5633. GoodId: 0,
  5634. Status: 1,
  5635. Ctime: time.Now().Unix(),
  5636. Mtime: 0,
  5637. Count: 0,
  5638. StockCount: 0,
  5639. Creater: creator,
  5640. BatchNumberId: 0,
  5641. WarehouseOutId: 0,
  5642. }
  5643. service.CreateGoodErrcode(goodErrcode)
  5644. }
  5645. //出库数量相加
  5646. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5647. if errss != nil {
  5648. goodErrcode := models.XtGoodErrcode{
  5649. UserOrgId: item.UserOrgId,
  5650. Errcode: "创建剩余库存字段报错",
  5651. GoodId: item.GoodId,
  5652. Status: 1,
  5653. Ctime: time.Now().Unix(),
  5654. Mtime: time.Now().Unix(),
  5655. Count: 0,
  5656. StockCount: 0,
  5657. Creater: item.Creater,
  5658. BatchNumberId: 0,
  5659. WarehouseOutId: 0,
  5660. }
  5661. service.CreateGoodErrcode(goodErrcode)
  5662. }
  5663. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5664. if len(list) == 0 {
  5665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5666. return
  5667. }
  5668. for _, item := range list {
  5669. prepare := models.DialysisBeforePrepare{
  5670. UserOrgId: adminInfo.Org.Id,
  5671. PatientId: patient_id,
  5672. RecordDate: record_time,
  5673. GoodId: item.GoodId,
  5674. GoodTypeId: item.GoodTypeId,
  5675. Count: item.Count,
  5676. Creater: adminInfo.AdminUser.Id,
  5677. Status: 1,
  5678. Ctime: time.Now().Unix(),
  5679. StorehouseId: houseConfig.StorehouseOutInfo,
  5680. }
  5681. //清空准备表数据
  5682. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5683. if errs != nil {
  5684. goodErrcode := models.XtGoodErrcode{
  5685. UserOrgId: adminInfo.Org.Id,
  5686. Errcode: "自动出库清空准备表数据报错",
  5687. GoodId: 0,
  5688. Status: 1,
  5689. Ctime: time.Now().Unix(),
  5690. Mtime: 0,
  5691. Count: 0,
  5692. StockCount: 0,
  5693. Creater: creator,
  5694. BatchNumberId: 0,
  5695. WarehouseOutId: 0,
  5696. }
  5697. service.CreateGoodErrcode(goodErrcode)
  5698. }
  5699. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  5700. if errcodes != nil {
  5701. goodErrcode := models.XtGoodErrcode{
  5702. UserOrgId: adminInfo.Org.Id,
  5703. Errcode: "自动出库创建准备表数据报错",
  5704. GoodId: 0,
  5705. Status: 1,
  5706. Ctime: time.Now().Unix(),
  5707. Mtime: 0,
  5708. Count: 0,
  5709. StockCount: 0,
  5710. Creater: creator,
  5711. BatchNumberId: 0,
  5712. WarehouseOutId: 0,
  5713. }
  5714. service.CreateGoodErrcode(goodErrcode)
  5715. }
  5716. //查询默认仓库
  5717. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5718. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5719. var total_count int64
  5720. for _, it := range stockList {
  5721. total_count += it.StockCount
  5722. }
  5723. //基础库插入数据
  5724. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5725. if errcodes != nil {
  5726. goodErrcode := models.XtGoodErrcode{
  5727. UserOrgId: adminInfo.Org.Id,
  5728. Errcode: "自动出库基础库插入数据报错",
  5729. GoodId: 0,
  5730. Status: 1,
  5731. Ctime: time.Now().Unix(),
  5732. Mtime: 0,
  5733. Count: 0,
  5734. StockCount: 0,
  5735. Creater: creator,
  5736. BatchNumberId: 0,
  5737. WarehouseOutId: 0,
  5738. }
  5739. service.CreateGoodErrcode(goodErrcode)
  5740. }
  5741. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5742. var flush_count int64
  5743. for _, it := range goodList {
  5744. flush_count += it.StockCount
  5745. }
  5746. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5747. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  5748. if errss != nil {
  5749. goodErrcode := models.XtGoodErrcode{
  5750. UserOrgId: item.OrgId,
  5751. Errcode: "自动出库剩余库存更新数据",
  5752. GoodId: item.GoodId,
  5753. Status: 1,
  5754. Ctime: time.Now().Unix(),
  5755. Mtime: 0,
  5756. Count: 0,
  5757. StockCount: 0,
  5758. Creater: creater,
  5759. BatchNumberId: 0,
  5760. WarehouseOutId: 0,
  5761. }
  5762. service.CreateGoodErrcode(goodErrcode)
  5763. }
  5764. }
  5765. }
  5766. }
  5767. c.ServeSuccessJSON(map[string]interface{}{
  5768. "msg": "提交成功",
  5769. "message": "2",
  5770. "good_name": "",
  5771. "specification_name": "",
  5772. })
  5773. return
  5774. }
  5775. if record.IsOpen == 1 {
  5776. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5777. //查询是否有库存
  5778. for _, item := range consumables {
  5779. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, houseConfig.StorehouseOutInfo)
  5780. if item.Count > warehouse.Count {
  5781. goodErrcode := models.XtGoodErrcode{
  5782. UserOrgId: item.UserOrgId,
  5783. Errcode: "自动出库库存不足",
  5784. GoodId: item.GoodId,
  5785. Status: 1,
  5786. Ctime: time.Now().Unix(),
  5787. Mtime: 0,
  5788. Count: 0,
  5789. StockCount: 0,
  5790. Creater: creator,
  5791. BatchNumberId: warehouse.ID,
  5792. WarehouseOutId: 0,
  5793. }
  5794. service.CreateGoodErrcode(goodErrcode)
  5795. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  5796. c.ServeSuccessJSON(map[string]interface{}{
  5797. "message": "1",
  5798. "good_name": goodObj.GoodName,
  5799. "specification_name": goodObj.SpecificationName,
  5800. })
  5801. return
  5802. }
  5803. }
  5804. //查询是否有出库单
  5805. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  5806. if err == gorm.ErrRecordNotFound {
  5807. //没有记录,则创建出库单
  5808. timeStr := time.Now().Format("2006-01-02")
  5809. timeArr := strings.Split(timeStr, "-")
  5810. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  5811. total = total + 1
  5812. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5813. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5814. number = number + total
  5815. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5816. creater := adminInfo.AdminUser.Id
  5817. warehouseOut := models.WarehouseOut{
  5818. WarehouseOutOrderNumber: warehousing_out_order,
  5819. OperationTime: time.Now().Unix(),
  5820. OrgId: adminInfo.Org.Id,
  5821. Creater: creater,
  5822. Ctime: time.Now().Unix(),
  5823. Status: 1,
  5824. WarehouseOutTime: record_time,
  5825. Dealer: 0,
  5826. Manufacturer: 0,
  5827. Type: 1,
  5828. IsSys: 1,
  5829. StorehouseId: houseConfig.StorehouseOutInfo,
  5830. IsCheck: 1,
  5831. }
  5832. err := service.AddSigleWarehouseOut(&warehouseOut)
  5833. if err != nil {
  5834. goodErrcode := models.XtGoodErrcode{
  5835. UserOrgId: adminInfo.Org.Id,
  5836. Errcode: "创建出库单失败",
  5837. GoodId: 0,
  5838. Status: 1,
  5839. Ctime: time.Now().Unix(),
  5840. Mtime: 0,
  5841. Count: 0,
  5842. StockCount: 0,
  5843. Creater: creator,
  5844. BatchNumberId: 0,
  5845. WarehouseOutId: 0,
  5846. }
  5847. service.CreateGoodErrcode(goodErrcode)
  5848. utils.TraceLog("创建出库单失败 err = %v", err)
  5849. } else {
  5850. for _, item := range consumables {
  5851. //出库
  5852. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, item.Count)
  5853. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &warehouseOut, adminInfo.AdminUser.Id, item.Count)
  5854. if err == nil {
  5855. goodErrcode := models.XtGoodErrcode{
  5856. UserOrgId: adminInfo.Org.Id,
  5857. Errcode: "自动出库接口报错",
  5858. GoodId: 0,
  5859. Status: 1,
  5860. Ctime: time.Now().Unix(),
  5861. Mtime: 0,
  5862. Count: 0,
  5863. StockCount: 0,
  5864. Creater: creator,
  5865. BatchNumberId: 0,
  5866. WarehouseOutId: 0,
  5867. }
  5868. service.CreateGoodErrcode(goodErrcode)
  5869. utils.TraceLog("创建出库单失败 err = %v", err)
  5870. }
  5871. //查询
  5872. //出库数量相加
  5873. errs := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  5874. if errs != nil {
  5875. goodErrcode := models.XtGoodErrcode{
  5876. UserOrgId: item.UserOrgId,
  5877. Errcode: "创建剩余库存字段报错",
  5878. GoodId: item.GoodId,
  5879. Status: 1,
  5880. Ctime: time.Now().Unix(),
  5881. Mtime: 0,
  5882. Count: 0,
  5883. StockCount: 0,
  5884. Creater: creater,
  5885. BatchNumberId: 0,
  5886. WarehouseOutId: 0,
  5887. }
  5888. service.CreateGoodErrcode(goodErrcode)
  5889. }
  5890. }
  5891. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  5892. if len(list) == 0 {
  5893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5894. return
  5895. }
  5896. for _, item := range list {
  5897. prepare := models.DialysisBeforePrepare{
  5898. UserOrgId: adminInfo.Org.Id,
  5899. PatientId: patient_id,
  5900. RecordDate: record_time,
  5901. GoodId: item.GoodId,
  5902. GoodTypeId: item.GoodTypeId,
  5903. Count: item.Count,
  5904. Creater: adminInfo.AdminUser.Id,
  5905. Status: 1,
  5906. Ctime: time.Now().Unix(),
  5907. StorehouseId: houseConfig.StorehouseOutInfo,
  5908. }
  5909. //清空准备表数据
  5910. err := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  5911. if err != nil {
  5912. goodErrcode := models.XtGoodErrcode{
  5913. UserOrgId: item.OrgId,
  5914. Errcode: "自动出库清空准备表数据报错",
  5915. GoodId: item.GoodId,
  5916. Status: 1,
  5917. Ctime: time.Now().Unix(),
  5918. Mtime: 0,
  5919. Count: 0,
  5920. StockCount: 0,
  5921. Creater: creater,
  5922. BatchNumberId: 0,
  5923. WarehouseOutId: 0,
  5924. }
  5925. service.CreateGoodErrcode(goodErrcode)
  5926. }
  5927. errs := service.CreateDialysisBeforePrepareOne(&prepare)
  5928. if errs != nil {
  5929. goodErrcode := models.XtGoodErrcode{
  5930. UserOrgId: item.OrgId,
  5931. Errcode: "自动出库创建准备表数据报错",
  5932. GoodId: item.GoodId,
  5933. Status: 1,
  5934. Ctime: time.Now().Unix(),
  5935. Mtime: 0,
  5936. Count: 0,
  5937. StockCount: 0,
  5938. Creater: creater,
  5939. BatchNumberId: 0,
  5940. WarehouseOutId: 0,
  5941. }
  5942. service.CreateGoodErrcode(goodErrcode)
  5943. }
  5944. //查询默认仓库
  5945. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  5946. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  5947. var total_count int64
  5948. for _, it := range stockList {
  5949. total_count += it.StockCount
  5950. }
  5951. //基础库插入数据
  5952. errcodes := service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  5953. if errcodes != nil {
  5954. goodErrcode := models.XtGoodErrcode{
  5955. UserOrgId: item.OrgId,
  5956. Errcode: "自动出库基础库插入数据",
  5957. GoodId: item.GoodId,
  5958. Status: 1,
  5959. Ctime: time.Now().Unix(),
  5960. Mtime: 0,
  5961. Count: 0,
  5962. StockCount: 0,
  5963. Creater: creater,
  5964. BatchNumberId: 0,
  5965. WarehouseOutId: 0,
  5966. }
  5967. service.CreateGoodErrcode(goodErrcode)
  5968. }
  5969. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  5970. var flush_count int64
  5971. for _, it := range goodList {
  5972. flush_count += it.StockCount
  5973. }
  5974. errsss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  5975. if errsss != nil {
  5976. goodErrcode := models.XtGoodErrcode{
  5977. UserOrgId: item.OrgId,
  5978. Errcode: "自动出库剩余库存更新数据",
  5979. GoodId: item.GoodId,
  5980. Status: 1,
  5981. Ctime: time.Now().Unix(),
  5982. Mtime: 0,
  5983. Count: 0,
  5984. StockCount: 0,
  5985. Creater: creater,
  5986. BatchNumberId: 0,
  5987. WarehouseOutId: 0,
  5988. }
  5989. service.CreateGoodErrcode(goodErrcode)
  5990. }
  5991. }
  5992. }
  5993. //
  5994. } else if err == nil {
  5995. for _, item := range consumables {
  5996. //出库
  5997. err := service.ConsumablesGoodDelivery(item.UserOrgId, patient_id, record_time, item, &out, item.Count)
  5998. //err := service.ConsumableMobileDelivery(item.UserOrgId, patient_id, record_time, item, &out, adminInfo.AdminUser.Id, item.Count)
  5999. if err != nil {
  6000. goodErrcode := models.XtGoodErrcode{
  6001. UserOrgId: adminInfo.Org.Id,
  6002. Errcode: "自动出库接口报错",
  6003. GoodId: 0,
  6004. Status: 1,
  6005. Ctime: time.Now().Unix(),
  6006. Mtime: 0,
  6007. Count: 0,
  6008. StockCount: 0,
  6009. Creater: creator,
  6010. BatchNumberId: 0,
  6011. WarehouseOutId: 0,
  6012. }
  6013. service.CreateGoodErrcode(goodErrcode)
  6014. }
  6015. //出库数量相加
  6016. errss := service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, item.UserOrgId, item.GoodId)
  6017. if errss != nil {
  6018. goodErrcode := models.XtGoodErrcode{
  6019. UserOrgId: item.UserOrgId,
  6020. Errcode: "创建剩余库存字段报错",
  6021. GoodId: item.GoodId,
  6022. Status: 1,
  6023. Ctime: time.Now().Unix(),
  6024. Mtime: time.Now().Unix(),
  6025. Count: 0,
  6026. StockCount: 0,
  6027. Creater: item.Creater,
  6028. BatchNumberId: 0,
  6029. WarehouseOutId: 0,
  6030. }
  6031. service.CreateGoodErrcode(goodErrcode)
  6032. }
  6033. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6034. if len(list) == 0 {
  6035. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6036. return
  6037. }
  6038. for _, item := range list {
  6039. prepare := models.DialysisBeforePrepare{
  6040. UserOrgId: adminInfo.Org.Id,
  6041. PatientId: patient_id,
  6042. RecordDate: record_time,
  6043. GoodId: item.GoodId,
  6044. GoodTypeId: item.GoodTypeId,
  6045. Count: item.Count,
  6046. Creater: adminInfo.AdminUser.Id,
  6047. Status: 1,
  6048. Ctime: time.Now().Unix(),
  6049. StorehouseId: houseConfig.StorehouseOutInfo,
  6050. }
  6051. //清空准备表数据
  6052. errs := service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6053. if errs != nil {
  6054. goodErrcode := models.XtGoodErrcode{
  6055. UserOrgId: adminInfo.Org.Id,
  6056. Errcode: "自动出库清空准备表数据报错",
  6057. GoodId: 0,
  6058. Status: 1,
  6059. Ctime: time.Now().Unix(),
  6060. Mtime: 0,
  6061. Count: 0,
  6062. StockCount: 0,
  6063. Creater: creator,
  6064. BatchNumberId: 0,
  6065. WarehouseOutId: 0,
  6066. }
  6067. service.CreateGoodErrcode(goodErrcode)
  6068. }
  6069. errcodes := service.CreateDialysisBeforePrepareOne(&prepare)
  6070. if errcodes != nil {
  6071. goodErrcode := models.XtGoodErrcode{
  6072. UserOrgId: adminInfo.Org.Id,
  6073. Errcode: "自动出库创建准备表数据报错",
  6074. GoodId: 0,
  6075. Status: 1,
  6076. Ctime: time.Now().Unix(),
  6077. Mtime: 0,
  6078. Count: 0,
  6079. StockCount: 0,
  6080. Creater: creator,
  6081. BatchNumberId: 0,
  6082. WarehouseOutId: 0,
  6083. }
  6084. service.CreateGoodErrcode(goodErrcode)
  6085. }
  6086. //查询默认仓库
  6087. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6088. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6089. var total_count int64
  6090. for _, it := range stockList {
  6091. total_count += it.StockCount
  6092. }
  6093. //基础库插入数据
  6094. errcodes = service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6095. if errcodes != nil {
  6096. goodErrcode := models.XtGoodErrcode{
  6097. UserOrgId: adminInfo.Org.Id,
  6098. Errcode: "自动出库基础库插入数据报错",
  6099. GoodId: 0,
  6100. Status: 1,
  6101. Ctime: time.Now().Unix(),
  6102. Mtime: 0,
  6103. Count: 0,
  6104. StockCount: 0,
  6105. Creater: creator,
  6106. BatchNumberId: 0,
  6107. WarehouseOutId: 0,
  6108. }
  6109. service.CreateGoodErrcode(goodErrcode)
  6110. }
  6111. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6112. var flush_count int64
  6113. for _, it := range goodList {
  6114. flush_count += it.StockCount
  6115. }
  6116. errss := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6117. creater := c.GetMobileAdminUserInfo().AdminUser.Id
  6118. if errss != nil {
  6119. goodErrcode := models.XtGoodErrcode{
  6120. UserOrgId: item.OrgId,
  6121. Errcode: "自动出库剩余库存更新数据",
  6122. GoodId: item.GoodId,
  6123. Status: 1,
  6124. Ctime: time.Now().Unix(),
  6125. Mtime: 0,
  6126. Count: 0,
  6127. StockCount: 0,
  6128. Creater: creater,
  6129. BatchNumberId: 0,
  6130. WarehouseOutId: 0,
  6131. }
  6132. service.CreateGoodErrcode(goodErrcode)
  6133. }
  6134. }
  6135. }
  6136. }
  6137. c.ServeSuccessJSON(map[string]interface{}{
  6138. "msg": "提交成功",
  6139. "message": "2",
  6140. "good_name": "",
  6141. "specification_name": "",
  6142. })
  6143. return
  6144. } else {
  6145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOpenStocktWrong)
  6146. return
  6147. }
  6148. }
  6149. func (c *DialysisAPIController) EditConsumables() {
  6150. patient_id, _ := c.GetInt64("patient_id", 0)
  6151. record_date := c.GetString("record_time")
  6152. if patient_id <= 0 {
  6153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6154. return
  6155. }
  6156. adminInfo := c.GetMobileAdminUserInfo()
  6157. timeLayout := "2006-01-02"
  6158. loc, _ := time.LoadLocation("Local")
  6159. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6160. record_time := theRecordTime.Unix()
  6161. // 查询信息规挡的设置天数
  6162. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6163. if infor.ID > 0 && infor.WeekDay > 0 {
  6164. var cha_time int64
  6165. timeNowStr := time.Now().Format("2006-01-02")
  6166. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6167. //今日的日期减去设置的日期
  6168. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6169. if cha_time >= record_time {
  6170. //查询审核是否允许
  6171. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6172. //申请状态不允许的情况 拒绝修改
  6173. if infor.ApplicationStatus != 1 {
  6174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6175. return
  6176. }
  6177. }
  6178. }
  6179. dataBody := make(map[string]interface{}, 0)
  6180. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6181. if err != nil {
  6182. utils.ErrorLog(err.Error())
  6183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6184. return
  6185. }
  6186. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6187. var beforePrepares []*models.DialysisBeforePrepareGoods
  6188. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6189. var cancelbefor []*models.DialysisBeforePrepareGoods
  6190. var outbefor []*models.DialysisBeforePrepareGoods
  6191. //判断是否开启自动出库
  6192. _, record := service.FindAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  6193. if record.IsOpen == 1 {
  6194. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6195. goods, _ := dataBody["goods"].([]interface{})
  6196. if len(goods) > 0 {
  6197. for _, item := range goods {
  6198. items := item.(map[string]interface{})
  6199. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6200. utils.ErrorLog("good_id")
  6201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6202. return
  6203. }
  6204. good_id := int64(items["good_id"].(float64))
  6205. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6206. utils.ErrorLog("good_type_id")
  6207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6208. return
  6209. }
  6210. good_type_id := int64(items["good_type_id"].(float64))
  6211. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6212. utils.ErrorLog("count")
  6213. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6214. return
  6215. }
  6216. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6217. commdity_code := items["commdity_code"].(string)
  6218. fmt.Println(commdity_code)
  6219. prepareGoods := &models.DialysisBeforePrepareGoods{
  6220. GoodTypeId: good_type_id,
  6221. GoodId: good_id,
  6222. Count: count,
  6223. StorehouseId: houseConfig.StorehouseOutInfo,
  6224. }
  6225. beforePrepares = append(beforePrepares, prepareGoods)
  6226. newPrepareGoods := &models.NewDialysisBeforePrepareGoods{
  6227. GoodTypeId: good_type_id,
  6228. GoodId: good_id,
  6229. Count: count,
  6230. StorehouseId: houseConfig.StorehouseOutInfo,
  6231. }
  6232. newBeforePrepares = append(newBeforePrepares, newPrepareGoods)
  6233. }
  6234. for _, item := range beforePrepares {
  6235. //1.查看该患者该耗材型号最后一次出库数量
  6236. goodInfo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6237. //判断当前出库数量和最后一次出库数量的大小
  6238. //如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
  6239. if item.Count < goodInfo.Count {
  6240. cancelbefor = append(cancelbefor, item)
  6241. }
  6242. //如果当前出库数量大于 最后一次出库数量,那么则需要去查询当前批次耗材的库存是否足够
  6243. if item.Count > goodInfo.Count {
  6244. outbefor = append(outbefor, item)
  6245. }
  6246. //处理编辑耗材新增不了的问题
  6247. if goodInfo.Count == item.Count {
  6248. lastCount, _ := service.GetAutoGoodLastCount(item.GoodId, item.Count, record_time, patient_id)
  6249. service.UpdateLastAutoCount(lastCount.ID, item.Count)
  6250. }
  6251. }
  6252. if len(cancelbefor) > 0 {
  6253. //退库
  6254. for _, item := range cancelbefor {
  6255. warehouseOut, _ := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6256. creater := adminInfo.AdminUser.Id
  6257. //查询该患者当天已经出库的耗材信息
  6258. warehouseOutInfos, _ := service.FindStockOutInfoByStockTwo(adminInfo.Org.Id, item.GoodTypeId, item.GoodId, record_time, patient_id)
  6259. var delete_count int64 = 0
  6260. delete_count = warehouseOutInfos.Count - item.Count
  6261. //增加库存数量
  6262. service.ModifyGoodAddInformation(item.GoodId, delete_count, adminInfo.Org.Id)
  6263. //减少实际出库库存数量
  6264. service.ModifyReduceGoodSumCountTwenty(houseConfig.StorehouseOutInfo, delete_count, adminInfo.Org.Id, item.GoodId)
  6265. // 删除出库完成后,要增加对应批次的库存数量
  6266. service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, item.GoodId)
  6267. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6268. //更新剩余库存
  6269. goodListOne, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6270. var flush_count int64
  6271. for _, it := range goodListOne {
  6272. flush_count += it.StockCount
  6273. }
  6274. service.UpdateSumGood(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6275. //查询剩余库存
  6276. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6277. var sum_count int64
  6278. for _, item := range goodList {
  6279. sum_count += item.StockCount
  6280. }
  6281. // 在出库记录表里记录退库详情
  6282. warehouseOutInfo := &models.WarehouseOutInfo{
  6283. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6284. WarehouseOutId: warehouseOut.ID,
  6285. Status: 1,
  6286. Ctime: time.Now().Unix(),
  6287. OrgId: adminInfo.Org.Id,
  6288. Type: 1,
  6289. IsSys: 1,
  6290. SysRecordTime: record_time,
  6291. GoodTypeId: item.GoodTypeId,
  6292. GoodId: item.GoodId,
  6293. PatientId: patient_id,
  6294. ConsumableType: 2,
  6295. StorehouseId: houseConfig.StorehouseOutInfo,
  6296. IsCheck: 1,
  6297. OverCount: sum_count,
  6298. }
  6299. warehouseOutInfo.Count = item.Count
  6300. stockInInfo, _ := service.FindLastStockInInfoRecord(item.GoodId, adminInfo.Org.Id)
  6301. warehouseOutInfo.Price = stockInInfo.Price
  6302. warehouseOutInfo.Dealer = stockInInfo.Dealer
  6303. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  6304. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  6305. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  6306. warehouseOutInfo.Number = warehouseOutInfos.Number
  6307. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  6308. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  6309. //查找当天是否存在出库记录
  6310. _, errcod := service.GetWarehouseOutInfoIsExistOne(item.GoodId, patient_id, record_time, 0)
  6311. if errcod == gorm.ErrRecordNotFound {
  6312. service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  6313. //插入详情明细表
  6314. stockFlow := models.VmStockFlow{
  6315. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6316. WarehouseOutId: warehouseOut.ID,
  6317. GoodId: item.GoodId,
  6318. Number: warehouseOutInfos.Number,
  6319. ProductDate: stockInInfo.ProductDate,
  6320. ExpireDate: stockInInfo.ExpiryDate,
  6321. Count: item.Count,
  6322. Price: stockInInfo.Price,
  6323. Status: 1,
  6324. Ctime: time.Now().Unix(),
  6325. UserOrgId: adminInfo.Org.Id,
  6326. Manufacturer: stockInInfo.Manufacturer,
  6327. Dealer: stockInInfo.Dealer,
  6328. LicenseNumber: stockInInfo.LicenseNumber,
  6329. IsEdit: 2,
  6330. Creator: creater,
  6331. SystemTime: record_time,
  6332. ConsumableType: 3,
  6333. WarehousingDetailId: 0,
  6334. IsSys: 1,
  6335. UpdateCreator: creater,
  6336. PatientId: patient_id,
  6337. StorehouseId: houseConfig.StorehouseOutInfo,
  6338. }
  6339. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, item.GoodId)
  6340. if errflow == gorm.ErrRecordNotFound {
  6341. //创建流水表
  6342. err := service.CreateStockFlowOne(stockFlow)
  6343. fmt.Println("err", err)
  6344. } else if errflow == nil {
  6345. //插入详情明细表
  6346. stockFlow := models.VmStockFlow{
  6347. ID: exsit.ID,
  6348. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  6349. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  6350. WarehouseOutId: warehouseOut.ID,
  6351. GoodId: item.GoodId,
  6352. Number: warehouseOutInfos.Number,
  6353. ProductDate: stockInInfo.ProductDate,
  6354. ExpireDate: stockInInfo.ExpiryDate,
  6355. Count: exsit.Count - delete_count,
  6356. Price: stockInInfo.Price,
  6357. Status: 1,
  6358. Ctime: time.Now().Unix(),
  6359. UserOrgId: adminInfo.Org.Id,
  6360. Manufacturer: stockInInfo.Manufacturer,
  6361. Dealer: stockInInfo.Dealer,
  6362. LicenseNumber: stockInInfo.LicenseNumber,
  6363. IsEdit: 2,
  6364. Creator: creater,
  6365. SystemTime: record_time,
  6366. ConsumableType: 3,
  6367. WarehousingDetailId: 0,
  6368. IsSys: 1,
  6369. UpdateCreator: creater,
  6370. PatientId: patient_id,
  6371. StorehouseId: houseConfig.StorehouseOutInfo,
  6372. }
  6373. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, item.GoodId)
  6374. }
  6375. } else if errcod == nil {
  6376. service.UpdatedWarehouseOutInfo(warehouseOutInfo, item.GoodId, patient_id, record_time, 0)
  6377. //查询剩余库存
  6378. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminInfo.Org.Id, houseConfig.StorehouseOutInfo)
  6379. var sum_count int64
  6380. for _, item := range goodList {
  6381. sum_count += item.StockCount
  6382. }
  6383. //创建退库单,生成退库数据
  6384. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6385. good, _ := service.FindGoodInfoByIdTwo(item.GoodId)
  6386. operation_time := time.Now().Unix()
  6387. creater := adminInfo.AdminUser.Id
  6388. //创建退库单
  6389. timeStr := time.Now().Format("2006-01-02")
  6390. timeArr := strings.Split(timeStr, "-")
  6391. total, _ := service.FindAllCancelStockTotal(adminInfo.Org.Id)
  6392. total = total + 1
  6393. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6394. cancelStock := models.CancelStock{
  6395. OrderNumber: orderNumber,
  6396. OperaTime: operation_time,
  6397. OrgId: adminInfo.Org.Id,
  6398. Creater: creater,
  6399. Ctime: time.Now().Unix(),
  6400. Status: 1,
  6401. ReturnTime: record_time,
  6402. Type: 1,
  6403. StorehouseId: houseConfig.StorehouseOutInfo,
  6404. IsCheck: 1,
  6405. }
  6406. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, adminInfo.Org.Id)
  6407. if msgerrkonde == gorm.ErrRecordNotFound {
  6408. service.AddSigleCancelStock(&cancelStock)
  6409. }
  6410. cancel, _ := service.GetLastCancelStockById(adminInfo.Org.Id)
  6411. //查询是否有出库
  6412. info, _ := service.GetLastWarehoseByGoodId(item.GoodId, patient_id, record_time)
  6413. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6414. deaerler, _ := service.GetDealerById(info.Dealer)
  6415. if info.ID > 0 {
  6416. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.GoodId)
  6417. cancelStockInfo := models.CancelStockInfo{
  6418. GoodId: item.GoodId,
  6419. CancelStockId: cancel.ID,
  6420. GoodTypeId: good.GoodTypeId,
  6421. Count: delete_count,
  6422. Price: info.Price,
  6423. Total: 0,
  6424. ProductDate: info.ProductDate,
  6425. ExpiryDate: info.ExpiryDate,
  6426. Ctime: time.Now().Unix(),
  6427. Status: 1,
  6428. OrgId: adminInfo.Org.Id,
  6429. OrderNumber: cancel.OrderNumber,
  6430. Type: 0,
  6431. Dealer: deaerler.DealerName,
  6432. Manufacturer: manufacturer.ManufacturerName,
  6433. Number: info.Number,
  6434. RegisterAccount: "",
  6435. Remark: "",
  6436. WarehouseInfoId: info.WarehouseInfotId,
  6437. PatientId: info.PatientId,
  6438. RecordDate: info.SysRecordTime,
  6439. StorehouseId: houseConfig.StorehouseOutInfo,
  6440. IsCheck: 1,
  6441. }
  6442. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6443. //退库数量增加
  6444. service.UpdateSumAddCancelCount(adminInfo.Org.Id, item.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  6445. //查询剩余库存
  6446. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, houseConfig.StorehouseOutInfo, item.GoodId)
  6447. var over_count int64
  6448. for _, it := range goodList {
  6449. over_count += it.StockCount
  6450. }
  6451. flow := models.VmStockFlow{
  6452. WarehousingId: info.WarehouseInfotId,
  6453. GoodId: item.GoodId,
  6454. Number: info.Number,
  6455. LicenseNumber: info.LicenseNumber,
  6456. Count: delete_count,
  6457. UserOrgId: adminInfo.Org.Id,
  6458. PatientId: patient_id,
  6459. SystemTime: info.SysRecordTime,
  6460. ConsumableType: 7,
  6461. IsSys: 0,
  6462. WarehousingOrder: "",
  6463. WarehouseOutId: info.WarehouseOutId,
  6464. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6465. IsEdit: 0,
  6466. CancelStockId: cancel.ID,
  6467. CancelOrderNumber: cancel.OrderNumber,
  6468. Manufacturer: manufacturer.ID,
  6469. Dealer: 0,
  6470. Creator: adminInfo.AdminUser.Id,
  6471. UpdateCreator: 0,
  6472. Status: 1,
  6473. Ctime: time.Now().Unix(),
  6474. Mtime: 0,
  6475. Price: info.Price,
  6476. WarehousingDetailId: info.WarehouseInfotId,
  6477. WarehouseOutDetailId: info.ID,
  6478. CancelOutDetailId: cancelInfo.ID,
  6479. ProductDate: info.ProductDate,
  6480. ExpireDate: info.ExpiryDate,
  6481. StorehouseId: houseConfig.StorehouseOutInfo,
  6482. OverCount: over_count,
  6483. }
  6484. service.CreateStockFlowOne(flow)
  6485. }
  6486. }
  6487. //更改自动出库的表格
  6488. details := models.BloodAutomaticReduceDetail{
  6489. WarehouseOutId: warehouseOutInfo.ID,
  6490. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  6491. PatientId: patient_id,
  6492. Ctime: time.Now().Unix(),
  6493. Mtime: time.Now().Unix(),
  6494. Status: 1,
  6495. RecordTime: record_time,
  6496. OrgId: adminInfo.Org.Id,
  6497. GoodId: item.GoodId,
  6498. GoodTypeId: item.GoodTypeId,
  6499. Count: item.Count,
  6500. StorehouseId: houseConfig.StorehouseOutInfo,
  6501. }
  6502. //查询当天耗材是否已经存在数据
  6503. _, errcode := service.GetAutoMaticReduceDetail(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6504. if errcode == gorm.ErrRecordNotFound {
  6505. service.CreateAutoReduceRecord(&details)
  6506. } else if errcode == nil {
  6507. service.DeleteAutoRedeceDetailTwo(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6508. service.CreateAutoReduceRecord(&details)
  6509. }
  6510. //查询默认仓库
  6511. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6512. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6513. var total_count int64
  6514. for _, it := range stockList {
  6515. total_count += it.StockCount
  6516. }
  6517. //基础库插入数据
  6518. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6519. }
  6520. }
  6521. if len(outbefor) > 0 {
  6522. //出库
  6523. for _, item := range outbefor {
  6524. var last_total int64
  6525. //1.查看该患者该耗材型号最后一次出库数量
  6526. goodInfoOne, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6527. //计算当前出库和最后一次出库数据相差数据
  6528. last_total = item.Count - goodInfoOne.Count
  6529. //查询该耗材的总库存
  6530. wareinfo, _ := service.GetStockGoodCount(item.GoodId)
  6531. // 如果库存差大于剩余库存则提示库存不足
  6532. if last_total > wareinfo.StockCount {
  6533. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6534. c.ServeSuccessJSON(map[string]interface{}{
  6535. "message": "1",
  6536. "good_name": goodObj.GoodName,
  6537. "specification_name": goodObj.SpecificationName,
  6538. })
  6539. return
  6540. } else {
  6541. out, err := service.FindStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
  6542. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6543. if err == gorm.ErrRecordNotFound {
  6544. //没有记录,则创建出库单
  6545. timeStr := time.Now().Format("2006-01-02")
  6546. timeArr := strings.Split(timeStr, "-")
  6547. total, _ := service.FindAllWarehouseOut(adminInfo.Org.Id)
  6548. total = total + 1
  6549. warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6550. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6551. number = number + total
  6552. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6553. warehouseOut := models.WarehouseOut{
  6554. WarehouseOutOrderNumber: warehousing_out_order,
  6555. OperationTime: time.Now().Unix(),
  6556. OrgId: adminInfo.Org.Id,
  6557. Creater: adminInfo.AdminUser.Id,
  6558. Ctime: time.Now().Unix(),
  6559. Status: 1,
  6560. WarehouseOutTime: record_time,
  6561. Dealer: 0,
  6562. Manufacturer: 0,
  6563. Type: 1,
  6564. IsSys: 1,
  6565. StorehouseId: houseConfig.StorehouseOutInfo,
  6566. IsCheck: 1,
  6567. }
  6568. service.AddSigleWarehouseOut(&warehouseOut)
  6569. }
  6570. //出库
  6571. //err = ConsumablesDeliveryTotalSix(adminInfo.Org.Id, patient_id, record_time, outbefor, newBeforePrepares, adminInfo.AdminUser.Id)
  6572. //houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6573. //1.查看该患者该耗材型号最后一次出库数量
  6574. goodInfoTwo, _ := service.GetLastGoodListByPatientIdOne(record_time, patient_id, item.GoodId, item.GoodTypeId)
  6575. prepare := models.DialysisBeforePrepare{
  6576. UserOrgId: adminInfo.Org.Id,
  6577. PatientId: patient_id,
  6578. RecordDate: record_time,
  6579. GoodId: item.GoodId,
  6580. GoodTypeId: item.GoodTypeId,
  6581. Count: item.Count - goodInfoTwo.Count,
  6582. Ctime: time.Now().Unix(),
  6583. Mtime: 0,
  6584. Creater: adminInfo.AdminUser.Id,
  6585. Modifier: adminInfo.AdminUser.Id,
  6586. Status: 1,
  6587. CommdityCode: "",
  6588. NewCount: 0,
  6589. ProjectId: 0,
  6590. StorehouseId: houseConfig.StorehouseOutInfo,
  6591. }
  6592. service.ConsumablesGoodDelivery(adminInfo.Org.Id, patient_id, record_time, &prepare, &out, item.Count)
  6593. //增加出库数量
  6594. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, prepare.Count, adminInfo.Org.Id, item.GoodId)
  6595. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6596. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6597. var total_count int64
  6598. for _, it := range stockList {
  6599. total_count += it.StockCount
  6600. }
  6601. //基础库插入数据
  6602. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6603. //剩余库存
  6604. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6605. var flush_count int64
  6606. for _, it := range goodList {
  6607. flush_count += it.StockCount
  6608. }
  6609. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6610. }
  6611. }
  6612. }
  6613. //查询今日出库数据
  6614. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6615. for _, it := range list {
  6616. prepare := models.DialysisBeforePrepare{
  6617. UserOrgId: it.OrgId,
  6618. PatientId: patient_id,
  6619. RecordDate: it.RecordTime,
  6620. GoodId: it.GoodId,
  6621. GoodTypeId: it.GoodTypeId,
  6622. Count: it.Count,
  6623. Ctime: time.Now().Unix(),
  6624. Creater: adminInfo.AdminUser.Id,
  6625. Status: 1,
  6626. StorehouseId: houseConfig.StorehouseOutInfo,
  6627. ProjectId: it.ProjectId,
  6628. }
  6629. //删除准备表数据
  6630. service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, it.GoodId, it.GoodTypeId)
  6631. service.CreateDialysisBeforePrepareOne(&prepare)
  6632. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6633. stockList, _ := service.GetStockCountByGoodId(it.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6634. var total_count int64
  6635. for _, it := range stockList {
  6636. total_count += it.StockCount
  6637. }
  6638. //基础库插入数据
  6639. service.UpdateGoodInfoReduceSumCount(it.GoodId, total_count, adminInfo.Org.Id)
  6640. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId)
  6641. var flush_count int64
  6642. for _, it := range goodList {
  6643. flush_count += it.StockCount
  6644. }
  6645. service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, it.GoodId, flush_count)
  6646. }
  6647. }
  6648. }
  6649. //更新自动出库的地方
  6650. var errs error
  6651. if errs == nil {
  6652. c.ServeSuccessJSON(map[string]interface{}{
  6653. "msg": "修改成功",
  6654. "message": "2",
  6655. "good_name": "",
  6656. "specification_name": "",
  6657. })
  6658. return
  6659. } else {
  6660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6661. return
  6662. }
  6663. }
  6664. }
  6665. func (c *DialysisAPIController) GetDialysisGoods() {
  6666. schedualDate := c.GetString("schedule_date")
  6667. schedule_type, _ := c.GetInt64("schedule_type")
  6668. partition_id, _ := c.GetInt64("partition_id")
  6669. page, _ := c.GetInt("page")
  6670. patient_id, _ := c.GetInt64("patient_id")
  6671. schedualEndDate := int64(0)
  6672. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  6673. if parseDateErr != nil && len(schedualDate) != 0 {
  6674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6675. return
  6676. }
  6677. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  6678. if parseDateErr != nil && len(schedualDate) != 0 {
  6679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6680. return
  6681. }
  6682. schedualEndDate = endDate.Unix()
  6683. adminUser := c.GetMobileAdminUserInfo()
  6684. _, err := service.FindStockOutByIsSys(adminUser.Org.Id, 1, date.Unix())
  6685. goodTypes, _ := service.FindAllGoodType(adminUser.Org.Id)
  6686. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6687. _, config := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6688. outConfig, _ := service.FindGoodOutConfigById(adminUser.Org.Id)
  6689. settleConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.Org.Id)
  6690. //获取当天该病人的透析处方
  6691. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6692. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6693. if err == gorm.ErrRecordNotFound {
  6694. dialysisGoods, _, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6695. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6696. if patient_id != 0 {
  6697. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6698. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6699. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6700. //获取患者总的出库数据
  6701. item.LastAutomaticReduceDetail = goodUser
  6702. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6703. item.Project = project
  6704. }
  6705. }
  6706. c.ServeSuccessJSON(map[string]interface{}{
  6707. "dialysis_goods": dialysisGoods,
  6708. "good_type": goodTypes,
  6709. "total": total,
  6710. "prescribe": prescribe,
  6711. "good_info": good_info,
  6712. "warehouseOutList": warehouseOutList,
  6713. "config": config,
  6714. "outConfig": outConfig,
  6715. "settleConfig": settleConfig,
  6716. })
  6717. return
  6718. } else if err == nil {
  6719. //获取当天排班的每个患者的库存使用情况
  6720. dialysisGoods, err, total := service.MobileGetDialysisGoods(adminUser.Org.Id, date.Unix(), schedule_type, partition_id, page, 0, patient_id, "", schedualEndDate)
  6721. //获取患者总的出库数据
  6722. warehouseOutList, _ := service.GetAllWarehouseOutSumList(patient_id, adminUser.Org.Id, date.Unix())
  6723. if patient_id != 0 {
  6724. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  6725. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.Org.Id, date.Unix())
  6726. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
  6727. item.Project = project
  6728. item.LastAutomaticReduceDetail = goodUser
  6729. item.LastDialysisBeforePrepare = lastGoodUserDetial
  6730. }
  6731. }
  6732. if err == nil {
  6733. c.ServeSuccessJSON(map[string]interface{}{
  6734. "dialysis_goods": dialysisGoods,
  6735. "good_type": goodTypes,
  6736. "total": total,
  6737. "prescribe": prescribe,
  6738. "good_info": good_info,
  6739. "project": project,
  6740. "warehouseOutList": warehouseOutList,
  6741. "config": config,
  6742. "outConfig": outConfig,
  6743. "settleConfig": settleConfig,
  6744. })
  6745. return
  6746. } else {
  6747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6748. return
  6749. }
  6750. } else if err != nil {
  6751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6752. return
  6753. }
  6754. }
  6755. func (c *DialysisAPIController) GetDialysisGoodsStatistics() {
  6756. start_time := c.GetString("start_time")
  6757. end_time := c.GetString("end_time")
  6758. timeLayout := "2006-01-02"
  6759. loc, _ := time.LoadLocation("Local")
  6760. var theStartTime int64
  6761. if len(start_time) > 0 {
  6762. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6763. if err != nil {
  6764. utils.ErrorLog(err.Error())
  6765. }
  6766. theStartTime = theTime.Unix()
  6767. }
  6768. var theEndtTime int64
  6769. if len(end_time) > 0 {
  6770. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6771. if err != nil {
  6772. utils.ErrorLog(err.Error())
  6773. }
  6774. theEndtTime = theTime.Unix()
  6775. }
  6776. adminUser := c.GetMobileAdminUserInfo()
  6777. outInfo, err := service.MobileGetGoodsStatistics(adminUser.Org.Id, theStartTime, theEndtTime)
  6778. stockCount, err := service.GetOutStockTotalCountOne(theStartTime, theEndtTime, adminUser.Org.Id)
  6779. if err == nil {
  6780. c.ServeSuccessJSON(map[string]interface{}{
  6781. "stock_out": outInfo,
  6782. "stockCount": stockCount,
  6783. })
  6784. return
  6785. } else {
  6786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6787. return
  6788. }
  6789. }
  6790. func (c *DialysisAPIController) GetStockInGoodInfo() {
  6791. patient_id, _ := c.GetInt64("patient_id", 0)
  6792. record_time := c.GetString("record_time")
  6793. adminUser := c.GetMobileAdminUserInfo()
  6794. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", record_time)
  6795. if parseDateErr != nil && len(record_time) != 0 {
  6796. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6797. return
  6798. }
  6799. goodTypes, _ := service.FindAllGoodTypeOne(adminUser.Org.Id)
  6800. good_info, _ := service.FindAllGoodInfo(adminUser.Org.Id)
  6801. goodUser, _ := service.GetAllStockOutUserDetail(patient_id, adminUser.Org.Id, date.Unix())
  6802. lastGoodUserDetial, _ := service.GetLastDialysisGoods(patient_id, adminUser.Org.Id, date.Unix())
  6803. project, _ := service.GetHisPrescriptionProject(adminUser.Org.Id, patient_id, date.Unix())
  6804. //获取今日患者的透析处方参数
  6805. prescribe, parseDateErr := service.GetDialysisPrescribe(adminUser.Org.Id, patient_id, date.Unix())
  6806. outInfo, _ := service.GetGoodWarehouseOutInfo(adminUser.Org.Id, patient_id, date.Unix())
  6807. _, configs := service.FindXTHisRecordByOrgId(adminUser.Org.Id)
  6808. c.ServeSuccessJSON(map[string]interface{}{
  6809. "good_type": goodTypes,
  6810. "good_user": goodUser,
  6811. "good_info": good_info,
  6812. "last_good_user": lastGoodUserDetial,
  6813. "project": project,
  6814. "prescription": prescribe,
  6815. "outInfo": outInfo,
  6816. "configs": configs,
  6817. })
  6818. return
  6819. }
  6820. func (c *DialysisAPIController) CreateOtherStockOutInfo() {
  6821. patient_id, _ := c.GetInt64("patient_id", 0)
  6822. record_date := c.GetString("record_time")
  6823. timeLayout := "2006-01-02"
  6824. loc, _ := time.LoadLocation("Local")
  6825. theRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6826. record_time := theRecordTime.Unix()
  6827. adminInfo := c.GetMobileAdminUserInfo()
  6828. dataBody := make(map[string]interface{}, 0)
  6829. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6830. if err != nil {
  6831. utils.ErrorLog(err.Error())
  6832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6833. return
  6834. }
  6835. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6836. var beforePrepares []*models.DialysisBeforePrepareGoods
  6837. var newBeforePrepares []*models.NewDialysisBeforePrepareGoods
  6838. if dataBody["goods"] != nil && reflect.TypeOf(dataBody["goods"]).String() == "[]interface {}" {
  6839. goods, _ := dataBody["goods"].([]interface{})
  6840. if len(goods) > 0 {
  6841. for _, item := range goods {
  6842. items := item.(map[string]interface{})
  6843. if items["good_id"] == nil || reflect.TypeOf(items["good_id"]).String() != "float64" {
  6844. utils.ErrorLog("good_id")
  6845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6846. return
  6847. }
  6848. good_id := int64(items["good_id"].(float64))
  6849. if items["good_type_id"] == nil || reflect.TypeOf(items["good_type_id"]).String() != "float64" {
  6850. utils.ErrorLog("good_type_id")
  6851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6852. return
  6853. }
  6854. good_type_id := int64(items["good_type_id"].(float64))
  6855. if items["count"] == nil || reflect.TypeOf(items["count"]).String() != "string" {
  6856. utils.ErrorLog("count")
  6857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6858. return
  6859. }
  6860. count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
  6861. if items["project_id"] == nil || reflect.TypeOf(items["project_id"]).String() != "float64" {
  6862. utils.ErrorLog("project_id")
  6863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6864. return
  6865. }
  6866. project_id := int64(items["project_id"].(float64))
  6867. new_count := int64(items["new_count"].(float64))
  6868. old_count := int64(items["old_count"].(float64))
  6869. prepare := &models.DialysisBeforePrepareGoods{
  6870. GoodId: good_id,
  6871. GoodTypeId: good_type_id,
  6872. Count: count,
  6873. ProjectId: project_id,
  6874. StorehouseId: houseConfig.StorehouseOutInfo,
  6875. NewCount: new_count,
  6876. OldCount: old_count,
  6877. }
  6878. beforePrepares = append(beforePrepares, prepare)
  6879. newPrepare := &models.NewDialysisBeforePrepareGoods{
  6880. GoodId: good_id,
  6881. GoodTypeId: good_type_id,
  6882. Count: count,
  6883. ProjectId: project_id,
  6884. StorehouseId: houseConfig.StorehouseOutInfo,
  6885. NewCount: new_count,
  6886. OldCount: old_count,
  6887. }
  6888. newBeforePrepares = append(newBeforePrepares, newPrepare)
  6889. }
  6890. }
  6891. }
  6892. //查询是否有库存
  6893. for _, item := range beforePrepares {
  6894. if item.NewCount > 0 {
  6895. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6896. warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId, storeConfig.StorehouseOutInfo)
  6897. if item.Count > warehouse.Count {
  6898. goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
  6899. c.ServeSuccessJSON(map[string]interface{}{
  6900. "message": "1",
  6901. "good_name": goodObj.GoodName,
  6902. "specification_name": goodObj.SpecificationName,
  6903. })
  6904. return
  6905. }
  6906. }
  6907. }
  6908. // 查询信息规挡的设置天数
  6909. infor, _ := service.GetDialysisInformationSetting(adminInfo.Org.Id)
  6910. if infor.ID > 0 && infor.WeekDay > 0 {
  6911. var cha_time int64
  6912. timeNowStr := time.Now().Format("2006-01-02")
  6913. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  6914. //今日的日期减去设置的日期
  6915. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  6916. if cha_time >= record_time {
  6917. //查询审核是否允许
  6918. infor, _ := service.GetDialysisInformationByRecordDate(patient_id, record_time, adminInfo.Org.Id, 11)
  6919. //申请状态不允许的情况 拒绝修改
  6920. if infor.ApplicationStatus != 1 {
  6921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  6922. return
  6923. }
  6924. }
  6925. }
  6926. //出库逻辑
  6927. err = service.ConsumablesDeliveryTotal(adminInfo.Org.Id, patient_id, record_time, beforePrepares, newBeforePrepares, adminInfo.AdminUser.Id)
  6928. if err != nil {
  6929. utils.ErrorLog(err.Error())
  6930. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6931. return
  6932. }
  6933. finish := models.XtDialysisFinish{
  6934. IsFinish: 1,
  6935. UserOrgId: adminInfo.Org.Id,
  6936. Status: 1,
  6937. Ctime: time.Now().Unix(),
  6938. Mtime: 0,
  6939. Module: 11,
  6940. RecordDate: record_time,
  6941. Sourse: 1,
  6942. PatientId: patient_id,
  6943. }
  6944. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.Org.Id, record_time, 11, patient_id)
  6945. if dialysisFinish.ID == 0 {
  6946. service.CreateDialysisFinish(finish)
  6947. }
  6948. //查询当天出库的数据
  6949. list, _ := service.GetAutoReduceRecordInfoByPatientId(adminInfo.Org.Id, patient_id, record_time)
  6950. for _, item := range list {
  6951. prepare := models.DialysisBeforePrepare{
  6952. UserOrgId: item.OrgId,
  6953. PatientId: item.PatientId,
  6954. RecordDate: item.RecordTime,
  6955. GoodId: item.GoodId,
  6956. GoodTypeId: item.GoodTypeId,
  6957. Count: item.Count,
  6958. Creater: adminInfo.AdminUser.Id,
  6959. Status: 1,
  6960. Ctime: time.Now().Unix(),
  6961. ProjectId: item.ProjectId,
  6962. StorehouseId: houseConfig.StorehouseOutInfo,
  6963. }
  6964. //清空准备表的数据
  6965. err = service.DeleteDialysisBefor(adminInfo.Org.Id, patient_id, record_time, item.GoodId, item.GoodTypeId)
  6966. //插入准备表数据
  6967. service.CreateDialysisBeforePrepareOne(&prepare)
  6968. //查询默认仓库
  6969. //查询默认仓库
  6970. storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
  6971. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeHouseConfig.StorehouseOutInfo, adminInfo.Org.Id)
  6972. var total_count int64
  6973. for _, it := range stockList {
  6974. total_count += it.StockCount
  6975. }
  6976. //基础库插入数据
  6977. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, adminInfo.Org.Id)
  6978. ////更新剩余库存
  6979. goodList, _ := service.GetSumGoodList(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId)
  6980. var flush_count int64
  6981. for _, it := range goodList {
  6982. flush_count += it.StockCount
  6983. }
  6984. errs := service.UpdateSumGood(adminInfo.Org.Id, storeHouseConfig.StorehouseOutInfo, item.GoodId, flush_count)
  6985. if errs != nil {
  6986. goodErrcode := models.XtGoodErrcode{
  6987. UserOrgId: item.OrgId,
  6988. Errcode: "手动出库更新剩余出库失败",
  6989. GoodId: item.GoodId,
  6990. Status: 1,
  6991. Ctime: time.Now().Unix(),
  6992. Mtime: 0,
  6993. Count: 0,
  6994. StockCount: 0,
  6995. Creater: adminInfo.AdminUser.Id,
  6996. BatchNumberId: 0,
  6997. WarehouseOutId: 0,
  6998. }
  6999. service.CreateGoodErrcode(goodErrcode)
  7000. }
  7001. }
  7002. //更新自动出库的地方
  7003. var errs error
  7004. if errs == nil {
  7005. c.ServeSuccessJSON(map[string]interface{}{
  7006. "msg": "修改成功",
  7007. "message": "2",
  7008. "good_name": "",
  7009. "specification_name": "",
  7010. })
  7011. return
  7012. } else {
  7013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7014. return
  7015. }
  7016. }
  7017. func RemoveRepeatedGood(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7018. newArr = make([]*models.DialysisBeforePrepare, 0)
  7019. for i := 0; i < len(arr); i++ {
  7020. repeat := false
  7021. for j := i + 1; j < len(arr); j++ {
  7022. if arr[i].GoodId == arr[j].GoodId && arr[i].GoodTypeId == arr[j].GoodTypeId {
  7023. repeat = true
  7024. break
  7025. }
  7026. }
  7027. if !repeat {
  7028. newArr = append(newArr, arr[i])
  7029. }
  7030. }
  7031. return
  7032. }
  7033. func (c *DialysisAPIController) GetAllDrug() {
  7034. patient_id, _ := c.GetInt64("patient_id", 0)
  7035. adminInfo := c.GetMobileAdminUserInfo()
  7036. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
  7037. privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminInfo.Org.Id)
  7038. drugList, _ := service.GetAllBaseDrugLibList(adminInfo.Org.Id)
  7039. privateDrugList, _ := service.GetPrivateDrugList(patient_id, adminInfo.Org.Id)
  7040. c.ServeSuccessJSON(map[string]interface{}{
  7041. "base_drug_config": drugStockConfig,
  7042. "private_drug_config": privateDrugConfig,
  7043. "base_drug_list": drugList,
  7044. "private_drug_list": privateDrugList,
  7045. })
  7046. }
  7047. func RemoveRepeatedGoodTwo(arr []*models.DialysisBeforePrepare) (newArr []*models.DialysisBeforePrepare) {
  7048. newArr = make([]*models.DialysisBeforePrepare, 0)
  7049. for i := 0; i < len(arr); i++ {
  7050. repeat := false
  7051. for j := i + 1; j < len(arr); j++ {
  7052. if arr[i].GoodId == arr[j].GoodId {
  7053. repeat = true
  7054. break
  7055. }
  7056. }
  7057. if !repeat {
  7058. newArr = append(newArr, arr[i])
  7059. }
  7060. }
  7061. return
  7062. }
  7063. func (c *DialysisAPIController) GetDepartment() {
  7064. adminInfo := c.GetMobileAdminUserInfo()
  7065. departments, err := service.GetAllDepartMent(adminInfo.Org.Id)
  7066. if err == nil {
  7067. c.ServeSuccessJSON(map[string]interface{}{
  7068. "departments": departments,
  7069. })
  7070. } else {
  7071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7072. return
  7073. }
  7074. }
  7075. func (c *DialysisAPIController) GetMobilePrintStockGood() {
  7076. types, _ := c.GetInt("type", 0)
  7077. start_time := c.GetString("start_time")
  7078. end_time := c.GetString("end_time")
  7079. orgId := c.GetMobileAdminUserInfo().Org.Id
  7080. timeLayout := "2006-01-02"
  7081. loc, _ := time.LoadLocation("Local")
  7082. var startTime int64
  7083. if len(start_time) > 0 {
  7084. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7085. if err != nil {
  7086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7087. return
  7088. }
  7089. startTime = theTime.Unix()
  7090. }
  7091. var endTime int64
  7092. if len(end_time) > 0 {
  7093. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7094. if err != nil {
  7095. utils.ErrorLog(err.Error())
  7096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7097. return
  7098. }
  7099. endTime = theTime.Unix()
  7100. }
  7101. list, err := service.FindPrintStockGoodInfoByType(types, startTime, endTime, orgId)
  7102. stockTotal, err := service.GetOutStockTotalCountTwo(startTime, endTime, orgId)
  7103. if err != nil {
  7104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7105. } else {
  7106. c.ServeSuccessJSON(map[string]interface{}{
  7107. "list": list,
  7108. "type": types,
  7109. "stockTotal": stockTotal,
  7110. })
  7111. }
  7112. }
  7113. func (c *DialysisAPIController) GetPrescriptionList() {
  7114. start_time := c.GetString("start_time")
  7115. end_time := c.GetString("end_time")
  7116. schedule_type, _ := c.GetInt64("schedule_type")
  7117. partion_id, _ := c.GetInt64("partion_id")
  7118. orgId := c.GetMobileAdminUserInfo().Org.Id
  7119. timeLayout := "2006-01-02"
  7120. loc, _ := time.LoadLocation("Local")
  7121. var startTime int64
  7122. if len(start_time) > 0 {
  7123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7124. if err != nil {
  7125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7126. return
  7127. }
  7128. startTime = theTime.Unix()
  7129. }
  7130. var endTime int64
  7131. if len(end_time) > 0 {
  7132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7133. if err != nil {
  7134. utils.ErrorLog(err.Error())
  7135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7136. return
  7137. }
  7138. endTime = theTime.Unix()
  7139. }
  7140. schedulelist, _ := service.GetMobileScheduleListOne(startTime, endTime, orgId, schedule_type, partion_id)
  7141. fmt.Println("schedulelist22222222", schedulelist)
  7142. c.ServeSuccessJSON(map[string]interface{}{
  7143. "list": schedulelist,
  7144. })
  7145. return
  7146. }
  7147. func (c *DialysisAPIController) BatchDeleteMonitor() {
  7148. ids := c.GetString("ids")
  7149. //patient_id, _ := c.GetInt64("patient_id")
  7150. //monitoring_date, _ := c.GetInt64("monitoring_date")
  7151. idArray := strings.Split(ids, ",")
  7152. err := service.BatchDeleteMonitor(idArray)
  7153. fmt.Print("err", err)
  7154. //orgid := c.GetMobileAdminUserInfo().Org.Id
  7155. //redis := service.RedisClient()
  7156. //key := strconv.FormatInt(orgid, 10) + ":" + ":monitor_record_list_all"
  7157. //redis.Set(key, "", time.Second)
  7158. //keyOne := strconv.FormatInt(orgid, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  7159. //redis.Set(keyOne, "", time.Second)
  7160. //fmt.Println("keyo呢32332322332332232332",keyOne)
  7161. //redis.Close()
  7162. c.ServeSuccessJSON(map[string]interface{}{
  7163. "msg": "批量删除成功",
  7164. })
  7165. return
  7166. }
  7167. func (c *DialysisAPIController) GetPatientDialysisRecordList() {
  7168. id, _ := c.GetInt64("id")
  7169. timeLayout := "2006-01-02"
  7170. loc, _ := time.LoadLocation("Local")
  7171. //start_time := time.Now().Format("2006-01-02")
  7172. start_time := c.GetString("start_time")
  7173. end_time := c.GetString("end_time")
  7174. var startdateunix int64
  7175. if len(start_time) > 0 {
  7176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7177. if err != nil {
  7178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7179. return
  7180. }
  7181. startdateunix = theTime.Unix()
  7182. }
  7183. var enddateunix int64
  7184. if len(end_time) > 0 {
  7185. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7186. if err != nil {
  7187. utils.ErrorLog(err.Error())
  7188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7189. return
  7190. }
  7191. enddateunix = theTime.Unix()
  7192. }
  7193. //startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7194. //nowTime := time.Now()
  7195. //endTime := nowTime.AddDate(-30, 0, 0)
  7196. //endTimes := endTime.Format("2006-01-02")
  7197. //endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7198. org_id := c.GetMobileAdminUserInfo().Org.Id
  7199. //if org_id == 10579 {
  7200. // list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7201. // c.ServeSuccessJSON(map[string]interface{}{
  7202. // "list": list,
  7203. // })
  7204. // return
  7205. //} else {
  7206. // list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7207. // c.ServeSuccessJSON(map[string]interface{}{
  7208. // "list": list,
  7209. // })
  7210. // return
  7211. //}
  7212. if org_id == 9538 || org_id == 10101 {
  7213. list, _ := service.GetPatientDialysisRecordList(id, startdateunix, enddateunix)
  7214. c.ServeSuccessJSON(map[string]interface{}{
  7215. "list": list,
  7216. })
  7217. return
  7218. } else {
  7219. list, _ := service.GetPatientDialysisRecordListOne(id, startdateunix, enddateunix)
  7220. c.ServeSuccessJSON(map[string]interface{}{
  7221. "list": list,
  7222. })
  7223. }
  7224. return
  7225. }
  7226. func (c *DialysisAPIController) BathDeleteAdviceList() {
  7227. dataBody := make(map[string]interface{}, 0)
  7228. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7229. ids := c.GetString("ids")
  7230. idArray := strings.Split(ids, ",")
  7231. origin, _ := c.GetInt64("origin")
  7232. if origin == 1 {
  7233. err = service.BatchDeleteAdvice(idArray)
  7234. fmt.Print("err", err)
  7235. c.ServeSuccessJSON(map[string]interface{}{
  7236. "msg": "批量删除成功",
  7237. })
  7238. return
  7239. }
  7240. if origin == 2 {
  7241. service.BatchDeleteHisAdvice(idArray)
  7242. }
  7243. }
  7244. func (c *DialysisAPIController) UpdateAutoReduceDetail() {
  7245. good_id, _ := c.GetInt64("good_id")
  7246. count, _ := c.GetInt64("count")
  7247. record_time, _ := c.GetInt64("record_time")
  7248. patient_id, _ := c.GetInt64("patient_id")
  7249. detail, _ := service.UpdateAutoReduceDetail(good_id, count, record_time, patient_id)
  7250. c.ServeSuccessJSON(map[string]interface{}{
  7251. "detail": detail,
  7252. })
  7253. return
  7254. }
  7255. func (c *DialysisAPIController) DeleteAutoReduceDetail() {
  7256. good_id, _ := c.GetInt64("good_id")
  7257. record_time, _ := c.GetInt64("record_time")
  7258. patient_id, _ := c.GetInt64("patient_id")
  7259. service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
  7260. err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
  7261. fmt.Print("err", err)
  7262. c.ServeSuccessJSON(map[string]interface{}{
  7263. "msg": "批量删除成功",
  7264. })
  7265. return
  7266. }
  7267. func (c *DialysisAPIController) BatchAdviceCheck() {
  7268. ids := c.GetString("ids")
  7269. idArray := strings.Split(ids, ",")
  7270. creator, _ := c.GetInt64("creator")
  7271. origin, _ := c.GetInt64("origin")
  7272. if origin == 1 {
  7273. err := service.BatchAdviceCheck(idArray, creator)
  7274. fmt.Println(err)
  7275. list, _ := service.GetAdviceExecutionById(idArray)
  7276. c.ServeSuccessJSON(map[string]interface{}{
  7277. "list": list,
  7278. })
  7279. return
  7280. }
  7281. if origin == 2 {
  7282. service.BatchHisAdviceCheck(idArray, creator)
  7283. list, _ := service.GetHisAdviceExecutionById(idArray)
  7284. c.ServeSuccessJSON(map[string]interface{}{
  7285. "list": list,
  7286. })
  7287. return
  7288. }
  7289. }
  7290. func (c *DialysisAPIController) BatchAdviceExecution() {
  7291. ids := c.GetString("ids")
  7292. idArray := strings.Split(ids, ",")
  7293. executionTime := c.GetString("execution_time")
  7294. creator, _ := c.GetInt64("creator")
  7295. timeLayout := "2006-01-02 15:04:05"
  7296. loc, _ := time.LoadLocation("Local")
  7297. theTime, _ := time.ParseInLocation(timeLayout, executionTime, loc)
  7298. orgin, _ := c.GetInt64("origin")
  7299. if orgin == 1 {
  7300. err := service.BatchAdviceExecution(idArray, creator, theTime.Unix())
  7301. list, _ := service.GetAdviceExecutionById(idArray)
  7302. fmt.Println(err)
  7303. c.ServeSuccessJSON(map[string]interface{}{
  7304. "list": list,
  7305. })
  7306. return
  7307. }
  7308. if orgin == 2 {
  7309. err := service.BatchHisAdviceExecution(idArray, creator, theTime.Unix())
  7310. list, _ := service.GetHisAdviceExecutionById(idArray)
  7311. fmt.Println(err)
  7312. c.ServeSuccessJSON(map[string]interface{}{
  7313. "list": list,
  7314. })
  7315. return
  7316. }
  7317. }
  7318. func (c *DialysisAPIController) UpdateStockGoods() {
  7319. good_id, _ := c.GetInt64("good_id")
  7320. record_time, _ := c.GetInt64("record_time")
  7321. patient_id, _ := c.GetInt64("patient_id")
  7322. count, _ := c.GetInt64("count")
  7323. err := service.UpdateStockGoods(good_id, record_time, patient_id, count)
  7324. fmt.Print("err", err)
  7325. c.ServeSuccessJSON(map[string]interface{}{
  7326. "msg": "更新成功",
  7327. })
  7328. return
  7329. }
  7330. // 当前数据比上一次出库数据少
  7331. func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, creater int64, count int64) (err error) {
  7332. //查询该患者当天已经出库的耗材信息
  7333. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7334. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7335. for i := len(goods_yc) - 1; i >= 0; i-- {
  7336. goods_yc_temp := goods_yc[i]
  7337. for j := len(goods) - 1; j >= 0; j-- {
  7338. goods_temp := goods[j]
  7339. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7340. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7341. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7342. if goods_yc_temp.Count == goods_temp.Count {
  7343. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7344. goods = append(goods[:j], goods[j+1:]...)
  7345. break
  7346. }
  7347. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7348. if goods_yc_temp.Count > goods_temp.Count {
  7349. temp_count := goods_yc_temp.Count - goods_temp.Count
  7350. goods_yc[i].Count = temp_count
  7351. goods = append(goods[:j], goods[j+1:]...)
  7352. break
  7353. }
  7354. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7355. if goods_yc_temp.Count < goods_temp.Count {
  7356. temp_count := goods_temp.Count - goods_yc_temp.Count
  7357. goods[j].Count = temp_count
  7358. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7359. break
  7360. }
  7361. }
  7362. }
  7363. }
  7364. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7365. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7366. //退库
  7367. if len(goods_yc) > 0 {
  7368. for _, good_yc := range goods_yc {
  7369. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7370. ConsumablesDeliveryDeleteNew(orgID, record_time, good_yc, &out, patient_id, creater, count)
  7371. }
  7372. }
  7373. return nil
  7374. }
  7375. // 耗材出库删除
  7376. func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7377. // 先根据相关信息查询当天该耗材的出库信息
  7378. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7379. if err != nil {
  7380. return err
  7381. }
  7382. var delete_count int64 = 0
  7383. delete_count = warehouseOutInfos.Count - count
  7384. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7385. // 在出库记录表里记录退库详情
  7386. warehouseOutInfo := &models.WarehouseOutInfo{
  7387. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7388. WarehouseOutId: warehouseOut.ID,
  7389. Status: 1,
  7390. Ctime: time.Now().Unix(),
  7391. OrgId: orgID,
  7392. Type: 1,
  7393. IsSys: 1,
  7394. SysRecordTime: record_time,
  7395. GoodTypeId: good_yc.GoodTypeId,
  7396. GoodId: good_yc.GoodId,
  7397. PatientId: good_yc.PatientId,
  7398. ConsumableType: 2,
  7399. StorehouseId: houseConfig.StorehouseOutInfo,
  7400. IsCheck: 1,
  7401. }
  7402. warehouseOutInfo.Count = count
  7403. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7404. warehouseOutInfo.Price = stockInInfo.Price
  7405. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7406. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7407. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7408. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7409. warehouseOutInfo.Number = warehouseOutInfos.Number
  7410. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7411. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7412. //查找当天是否存在出库记录
  7413. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7414. if errcod == gorm.ErrRecordNotFound {
  7415. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7416. //插入详情明细表
  7417. stockFlow := models.VmStockFlow{
  7418. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7419. WarehouseOutId: warehouseOut.ID,
  7420. GoodId: good_yc.GoodId,
  7421. Number: warehouseOutInfos.Number,
  7422. ProductDate: stockInInfo.ProductDate,
  7423. ExpireDate: stockInInfo.ExpiryDate,
  7424. Count: count,
  7425. Price: stockInInfo.Price,
  7426. Status: 1,
  7427. Ctime: time.Now().Unix(),
  7428. UserOrgId: good_yc.OrgId,
  7429. Manufacturer: stockInInfo.Manufacturer,
  7430. Dealer: stockInInfo.Dealer,
  7431. LicenseNumber: stockInInfo.LicenseNumber,
  7432. IsEdit: 2,
  7433. Creator: creater,
  7434. SystemTime: record_time,
  7435. ConsumableType: 3,
  7436. WarehousingDetailId: 0,
  7437. IsSys: 1,
  7438. UpdateCreator: creater,
  7439. PatientId: patient_id,
  7440. StorehouseId: houseConfig.StorehouseOutInfo,
  7441. }
  7442. exsit, errflow := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7443. if errflow == gorm.ErrRecordNotFound {
  7444. //创建流水表
  7445. err := service.CreateStockFlowOne(stockFlow)
  7446. fmt.Println("err", err)
  7447. } else if errflow == nil {
  7448. //插入详情明细表
  7449. stockFlow := models.VmStockFlow{
  7450. ID: exsit.ID,
  7451. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7452. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7453. WarehouseOutId: warehouseOut.ID,
  7454. GoodId: good_yc.GoodId,
  7455. Number: warehouseOutInfos.Number,
  7456. ProductDate: stockInInfo.ProductDate,
  7457. ExpireDate: stockInInfo.ExpiryDate,
  7458. Count: exsit.Count - delete_count,
  7459. Price: stockInInfo.Price,
  7460. Status: 1,
  7461. Ctime: time.Now().Unix(),
  7462. UserOrgId: good_yc.OrgId,
  7463. Manufacturer: stockInInfo.Manufacturer,
  7464. Dealer: stockInInfo.Dealer,
  7465. LicenseNumber: stockInInfo.LicenseNumber,
  7466. IsEdit: 2,
  7467. Creator: creater,
  7468. SystemTime: record_time,
  7469. ConsumableType: 3,
  7470. WarehousingDetailId: 0,
  7471. IsSys: 1,
  7472. UpdateCreator: creater,
  7473. PatientId: patient_id,
  7474. StorehouseId: houseConfig.StorehouseOutInfo,
  7475. }
  7476. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7477. }
  7478. if errOne != nil {
  7479. return errOne
  7480. }
  7481. } else if errcod == nil {
  7482. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7483. //插入详情明细表
  7484. stockFlow := models.VmStockFlow{
  7485. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7486. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7487. WarehouseOutId: warehouseOut.ID,
  7488. GoodId: good_yc.GoodId,
  7489. Number: warehouseOutInfos.Number,
  7490. ProductDate: stockInInfo.ProductDate,
  7491. ExpireDate: stockInInfo.ExpiryDate,
  7492. Count: count,
  7493. Price: stockInInfo.Price,
  7494. Status: 1,
  7495. Ctime: time.Now().Unix(),
  7496. UserOrgId: good_yc.OrgId,
  7497. Manufacturer: stockInInfo.Manufacturer,
  7498. Dealer: stockInInfo.Dealer,
  7499. LicenseNumber: stockInInfo.LicenseNumber,
  7500. IsEdit: 2,
  7501. Creator: creater,
  7502. SystemTime: record_time,
  7503. ConsumableType: 3,
  7504. WarehousingDetailId: 0,
  7505. IsSys: 1,
  7506. UpdateCreator: creater,
  7507. PatientId: patient_id,
  7508. ReturnCount: delete_count,
  7509. StorehouseId: houseConfig.StorehouseOutInfo,
  7510. }
  7511. exsit, errflows := service.GetStockFlowIsExsit(warehouseOutInfos.WarehouseInfotId, patient_id, record_time, good_yc.GoodId)
  7512. if errflows == gorm.ErrRecordNotFound {
  7513. //创建流水表
  7514. service.CreateStockFlowOne(stockFlow)
  7515. } else if errflows == nil {
  7516. stockFlow := models.VmStockFlow{
  7517. WarehousingId: warehouseOutInfos.WarehouseInfotId,
  7518. ID: exsit.ID,
  7519. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7520. WarehouseOutId: warehouseOut.ID,
  7521. GoodId: good_yc.GoodId,
  7522. Number: warehouseOutInfos.Number,
  7523. ProductDate: stockInInfo.ProductDate,
  7524. ExpireDate: stockInInfo.ExpiryDate,
  7525. Count: exsit.Count - delete_count,
  7526. Price: stockInInfo.Price,
  7527. Status: 1,
  7528. Ctime: time.Now().Unix(),
  7529. UserOrgId: good_yc.OrgId,
  7530. Manufacturer: stockInInfo.Manufacturer,
  7531. Dealer: stockInInfo.Dealer,
  7532. LicenseNumber: stockInInfo.LicenseNumber,
  7533. IsEdit: 2,
  7534. Creator: creater,
  7535. SystemTime: record_time,
  7536. ConsumableType: 3,
  7537. WarehousingDetailId: 0,
  7538. IsSys: 1,
  7539. UpdateCreator: creater,
  7540. PatientId: patient_id,
  7541. ReturnCount: delete_count,
  7542. StorehouseId: houseConfig.StorehouseOutInfo,
  7543. }
  7544. service.UpdatedStockFlowOne(stockFlow, warehouseOut.ID, patient_id, record_time, good_yc.GoodId)
  7545. }
  7546. }
  7547. //更改自动出库的表格
  7548. details := models.BloodAutomaticReduceDetail{
  7549. WarehouseOutId: warehouseOutInfo.ID,
  7550. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7551. PatientId: patient_id,
  7552. Ctime: time.Now().Unix(),
  7553. Mtime: time.Now().Unix(),
  7554. Status: 1,
  7555. RecordTime: record_time,
  7556. OrgId: orgID,
  7557. GoodId: good_yc.GoodId,
  7558. GoodTypeId: good_yc.GoodTypeId,
  7559. Count: count,
  7560. StorehouseId: houseConfig.StorehouseOutInfo,
  7561. }
  7562. //查询当天耗材是否已经存在数据
  7563. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7564. if errcode == gorm.ErrRecordNotFound {
  7565. errTwo := service.CreateAutoReduceRecord(&details)
  7566. if errTwo != nil {
  7567. return errTwo
  7568. }
  7569. } else if errcode == nil {
  7570. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7571. service.CreateAutoReduceRecord(&details)
  7572. }
  7573. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7574. //增加出库库存数量
  7575. service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, good_yc.OrgId, good_yc.GoodId)
  7576. errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7577. fmt.Println("errOne", errOne)
  7578. // 删除出库完成后,要增加对应批次的库存数量
  7579. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7580. if errThree != nil {
  7581. return errThree
  7582. }
  7583. if good_yc.Count == 0 {
  7584. return nil
  7585. } else {
  7586. return errors.New("退库和出库数据不匹配")
  7587. }
  7588. }
  7589. func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int64, goods []*models.DialysisBeforePrepareGoods, goodOne []*models.NewDialysisBeforePrepareGoods, creater int64) (err error) {
  7590. //查询该患者当天已经出库的耗材信息
  7591. goods_yc, _ := service.FindConsumablesByDateThree(orgID, patient_id, record_time)
  7592. // 和新请求的出库数据进行对比,分出那些是继续出库的,那些是需要删除出库的
  7593. for i := len(goods_yc) - 1; i >= 0; i-- {
  7594. goods_yc_temp := goods_yc[i]
  7595. for j := len(goods) - 1; j >= 0; j-- {
  7596. goods_temp := goods[j]
  7597. // 已经出库和新请求出库都存在该耗材,则判断出库数量,分成是继续出库,还是删除出库
  7598. if goods_yc_temp.GoodTypeId == goods_temp.GoodTypeId && goods_yc_temp.GoodId == goods_temp.GoodId {
  7599. // 已经出库和新请求出库的出库数量一致,则清除两个结构体里的数据(既不出库,也不删除出库)
  7600. if goods_yc_temp.Count == goods_temp.Count {
  7601. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7602. goods = append(goods[:j], goods[j+1:]...)
  7603. break
  7604. }
  7605. // 如果已经出库的数量 大于 新请求出库的数量,则代表需要删除出库
  7606. if goods_yc_temp.Count > goods_temp.Count {
  7607. temp_count := goods_yc_temp.Count - goods_temp.Count
  7608. goods_yc[i].Count = temp_count
  7609. goods = append(goods[:j], goods[j+1:]...)
  7610. break
  7611. }
  7612. // 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
  7613. if goods_yc_temp.Count < goods_temp.Count {
  7614. temp_count := goods_temp.Count - goods_yc_temp.Count
  7615. goods[j].Count = temp_count
  7616. goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
  7617. break
  7618. }
  7619. }
  7620. }
  7621. }
  7622. // goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
  7623. // goods 这个数据就是需要出库的耗材的数据(新增的数据)
  7624. fmt.Println("剩余需要出库的", len(goods))
  7625. if len(goods) > 0 {
  7626. out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
  7627. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7628. if err == gorm.ErrRecordNotFound {
  7629. //没有记录,则创建出库单
  7630. timeStr := time.Now().Format("2006-01-02")
  7631. timeArr := strings.Split(timeStr, "-")
  7632. total, _ := service.FindAllWarehouseOut(orgID)
  7633. total = total + 1
  7634. warehousing_out_order := strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7635. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7636. number = number + total
  7637. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7638. warehouseOut := models.WarehouseOut{
  7639. WarehouseOutOrderNumber: warehousing_out_order,
  7640. OperationTime: time.Now().Unix(),
  7641. OrgId: orgID,
  7642. Creater: creater,
  7643. Ctime: time.Now().Unix(),
  7644. Status: 1,
  7645. WarehouseOutTime: record_time,
  7646. Dealer: 0,
  7647. Manufacturer: 0,
  7648. Type: 1,
  7649. IsSys: 1,
  7650. StorehouseId: houseConfig.StorehouseOutInfo,
  7651. IsCheck: 1,
  7652. }
  7653. err := service.AddSigleWarehouseOut(&warehouseOut)
  7654. if err != nil {
  7655. utils.TraceLog("创建出库单失败 err = %v", err)
  7656. return err
  7657. } else {
  7658. out = warehouseOut
  7659. }
  7660. }
  7661. for _, item := range goods {
  7662. var newCount int64 = 0
  7663. for _, it := range goodOne {
  7664. if item.GoodTypeId == it.GoodTypeId && item.GoodId == it.GoodId {
  7665. newCount = it.Count
  7666. }
  7667. }
  7668. prepare := models.DialysisBeforePrepare{
  7669. GoodTypeId: item.GoodTypeId,
  7670. GoodId: item.GoodId,
  7671. Count: item.Count,
  7672. StorehouseId: houseConfig.StorehouseOutInfo,
  7673. }
  7674. service.ConsumablesGoodDelivery(orgID, patient_id, record_time, &prepare, &out, newCount)
  7675. //增加出库数量
  7676. service.ModifyGoodSumCount(houseConfig.StorehouseOutInfo, item.Count, orgID, item.GoodId)
  7677. }
  7678. }
  7679. if len(goods_yc) > 0 {
  7680. for _, good_yc := range goods_yc {
  7681. out, _ := service.FindStockOutByIsSys(orgID, 1, record_time)
  7682. ConsumablesDeliveryDeleteThree(orgID, record_time, good_yc, &out)
  7683. }
  7684. }
  7685. return nil
  7686. }
  7687. // 耗材出库删除
  7688. func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut) (err error) {
  7689. // 先根据相关信息查询当天该耗材的出库信息
  7690. warehouseOutInfos, err := service.FindStockOutInfoByStockOne(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time)
  7691. if err != nil {
  7692. return err
  7693. }
  7694. var delete_count int64 = 0
  7695. for _, ware := range warehouseOutInfos {
  7696. // 判断当前出库的数据和删除出库数量
  7697. if good_yc.Count <= ware.Count {
  7698. delete_count = good_yc.Count
  7699. } else {
  7700. delete_count = ware.Count
  7701. }
  7702. warehouseOutInfo := &models.WarehouseOutInfo{
  7703. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7704. WarehouseOutId: warehouseOut.ID,
  7705. Status: 1,
  7706. Ctime: time.Now().Unix(),
  7707. Remark: "",
  7708. OrgId: orgID,
  7709. Type: 1,
  7710. Manufacturer: 0,
  7711. Dealer: 0,
  7712. IsSys: 0,
  7713. SysRecordTime: record_time,
  7714. GoodTypeId: good_yc.GoodTypeId,
  7715. GoodId: good_yc.GoodId,
  7716. StorehouseId: warehouseOut.StorehouseId,
  7717. IsCheck: 1,
  7718. }
  7719. warehouseOutInfo.Count = delete_count
  7720. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7721. warehouseOutInfo.Price = stockInInfo.Price
  7722. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7723. if errOne != nil {
  7724. return errOne
  7725. }
  7726. // 删除出库完成后,要改变流水库存(有疑问)
  7727. errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
  7728. fmt.Println("errOne", errOne)
  7729. errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count, good_yc.PatientId, record_time, good_yc.GoodId)
  7730. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7731. //扣减出库数量
  7732. service.ModifyReduceGoodSumCount(warehouseOut.StorehouseId, good_yc.Count, good_yc.OrgId, good_yc.GoodId)
  7733. if errThree != nil {
  7734. return errThree
  7735. }
  7736. }
  7737. if good_yc.Count == 0 {
  7738. return nil
  7739. } else {
  7740. return errors.New("退库和出库数据不匹配")
  7741. }
  7742. }
  7743. func (this *DialysisAPIController) GetMobileScheduleList() {
  7744. limit, _ := this.GetInt64("limit")
  7745. page, _ := this.GetInt64("page")
  7746. type_options_visible, _ := this.GetInt64("type_options_visible")
  7747. sch_type_options_visible, _ := this.GetInt64("sch_type_options_visible")
  7748. zone_options_visible, _ := this.GetInt64("zone_options_visible")
  7749. fmt.Println(limit, page, type_options_visible, sch_type_options_visible, zone_options_visible)
  7750. }
  7751. func RemoveRepeatedCheckRecod(arr []*models.HisPrescriptionProject) (newArr []*models.HisPrescriptionProject) {
  7752. newArr = make([]*models.HisPrescriptionProject, 0)
  7753. for i := 0; i < len(arr); i++ {
  7754. repeat := false
  7755. for j := i + 1; j < len(arr); j++ {
  7756. if arr[i].TeamId == arr[j].TeamId {
  7757. repeat = true
  7758. break
  7759. }
  7760. }
  7761. if !repeat {
  7762. newArr = append(newArr, arr[i])
  7763. }
  7764. }
  7765. return
  7766. }
  7767. func (this *DialysisAPIController) GetRoleList() {
  7768. admin_user_id, _ := this.GetInt64("admin_user_id")
  7769. orgid := this.GetMobileAdminUserInfo().Org.Id
  7770. list, err := service.GetRoleList(orgid, admin_user_id)
  7771. fmt.Println(err)
  7772. this.ServeSuccessJSON(map[string]interface{}{
  7773. "list": list,
  7774. })
  7775. return
  7776. }
  7777. func ConsumablesDeliveryDeleteNew(orgID int64, record_time int64, good_yc *models.BloodAutomaticReduceDetail, warehouseOut *models.WarehouseOut, patient_id int64, creater int64, count int64) (err error) {
  7778. fmt.Println("退库222322232322332232332322332232332233wo", good_yc.GoodId)
  7779. // 先根据相关信息查询当天该耗材的出库信息
  7780. warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
  7781. if err != nil {
  7782. return err
  7783. }
  7784. var delete_count int64 = 0
  7785. delete_count = warehouseOutInfos.Count - count
  7786. houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
  7787. // 删除出库完成后,要增加对应批次的库存数量
  7788. errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count, patient_id, record_time, good_yc.GoodId)
  7789. if errThree != nil {
  7790. return errThree
  7791. }
  7792. //增加退库数量
  7793. service.UpdateSumAddCancelCount(orgID, good_yc.GoodId, houseConfig.StorehouseOutInfo, delete_count)
  7794. //扣减出库数量
  7795. service.ModifyAddGoodSumCount(houseConfig.StorehouseOutInfo, delete_count, orgID, good_yc.GoodId)
  7796. //查询剩余库存
  7797. goodList, _ := service.GetAllGoodSumCount(good_yc.GoodId, orgID, houseConfig.StorehouseOutInfo)
  7798. var sum_count int64
  7799. for _, item := range goodList {
  7800. sum_count += item.StockCount
  7801. }
  7802. // 在出库记录表里记录退库详情
  7803. warehouseOutInfo := &models.WarehouseOutInfo{
  7804. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7805. WarehouseOutId: warehouseOut.ID,
  7806. Status: 1,
  7807. Ctime: time.Now().Unix(),
  7808. OrgId: orgID,
  7809. Type: 1,
  7810. IsSys: 1,
  7811. SysRecordTime: record_time,
  7812. GoodTypeId: good_yc.GoodTypeId,
  7813. GoodId: good_yc.GoodId,
  7814. PatientId: good_yc.PatientId,
  7815. ConsumableType: 2,
  7816. StorehouseId: houseConfig.StorehouseOutInfo,
  7817. IsCheck: 1,
  7818. OverCount: sum_count,
  7819. }
  7820. warehouseOutInfo.Count = count
  7821. stockInInfo, _ := service.FindLastStockInInfoRecord(good_yc.GoodId, orgID)
  7822. warehouseOutInfo.Price = stockInInfo.Price
  7823. warehouseOutInfo.Dealer = stockInInfo.Dealer
  7824. warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
  7825. warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
  7826. warehouseOutInfo.ProductDate = stockInInfo.ProductDate
  7827. warehouseOutInfo.Number = warehouseOutInfos.Number
  7828. warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
  7829. warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
  7830. //查找当天是否存在出库记录
  7831. _, errcod := service.GetWarehouseOutInfoIsExistOne(good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7832. if errcod == gorm.ErrRecordNotFound {
  7833. errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
  7834. //插入详情明细表
  7835. if errOne != nil {
  7836. return errOne
  7837. }
  7838. //插入详情明细表
  7839. stockFlow := models.VmStockFlow{
  7840. WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
  7841. WarehouseOutId: warehouseOut.ID,
  7842. GoodId: good_yc.GoodId,
  7843. Number: warehouseOutInfos.Number,
  7844. ProductDate: stockInInfo.ProductDate,
  7845. ExpireDate: stockInInfo.ExpiryDate,
  7846. Count: count,
  7847. Price: stockInInfo.Price,
  7848. Status: 1,
  7849. Ctime: time.Now().Unix(),
  7850. UserOrgId: good_yc.OrgId,
  7851. Manufacturer: stockInInfo.Manufacturer,
  7852. Dealer: stockInInfo.Dealer,
  7853. LicenseNumber: stockInInfo.LicenseNumber,
  7854. IsEdit: 2,
  7855. Creator: creater,
  7856. SystemTime: record_time,
  7857. ConsumableType: 3,
  7858. WarehousingDetailId: 0,
  7859. IsSys: 1,
  7860. UpdateCreator: creater,
  7861. PatientId: patient_id,
  7862. StorehouseId: houseConfig.StorehouseOutInfo,
  7863. OverCount: sum_count,
  7864. ProjectId: good_yc.ProjectId,
  7865. }
  7866. err := service.CreateStockFlowOne(stockFlow)
  7867. fmt.Println("err", err)
  7868. } else if errcod == nil {
  7869. service.UpdatedWarehouseOutInfo(warehouseOutInfo, good_yc.GoodId, good_yc.PatientId, record_time, good_yc.ProjectId)
  7870. }
  7871. //创建退库单
  7872. operation_time := time.Now().Unix()
  7873. //创建退库单
  7874. timeStr := time.Now().Format("2006-01-02")
  7875. timeArr := strings.Split(timeStr, "-")
  7876. total, _ := service.FindAllCancelStockTotal(orgID)
  7877. total = total + 1
  7878. orderNumber := "CKTKD" + strconv.FormatInt(orgID, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7879. cancelStock := models.CancelStock{
  7880. OrderNumber: orderNumber,
  7881. OperaTime: operation_time,
  7882. OrgId: orgID,
  7883. Creater: warehouseOut.Creater,
  7884. Ctime: time.Now().Unix(),
  7885. Status: 1,
  7886. ReturnTime: record_time,
  7887. Type: 1,
  7888. StorehouseId: stockInInfo.StorehouseId,
  7889. IsCheck: 1,
  7890. }
  7891. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(record_time, orgID)
  7892. if msgerrkonde == gorm.ErrRecordNotFound {
  7893. service.AddSigleCancelStock(&cancelStock)
  7894. }
  7895. cancel, _ := service.GetLastCancelStockById(orgID)
  7896. manufacturer, _ := service.GetManufactureById(stockInInfo.Manufacturer)
  7897. deaerler, _ := service.GetDealerById(stockInInfo.Dealer)
  7898. cancelStockInfo := models.CancelStockInfo{
  7899. GoodId: stockInInfo.GoodId,
  7900. CancelStockId: cancel.ID,
  7901. GoodTypeId: stockInInfo.GoodTypeId,
  7902. Count: delete_count,
  7903. Price: stockInInfo.PackingPrice,
  7904. Total: 0,
  7905. ProductDate: stockInInfo.ProductDate,
  7906. ExpiryDate: stockInInfo.ExpiryDate,
  7907. Ctime: time.Now().Unix(),
  7908. Status: 1,
  7909. OrgId: orgID,
  7910. OrderNumber: cancel.OrderNumber,
  7911. Type: 0,
  7912. Dealer: deaerler.DealerName,
  7913. Manufacturer: manufacturer.ManufacturerName,
  7914. Number: stockInInfo.Number,
  7915. RegisterAccount: "",
  7916. Remark: "",
  7917. WarehouseInfoId: stockInInfo.ID,
  7918. PatientId: patient_id,
  7919. RecordDate: record_time,
  7920. StorehouseId: stockInInfo.StorehouseId,
  7921. IsCheck: 1,
  7922. }
  7923. service.CreateCancelStockInfoOne(&cancelStockInfo)
  7924. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(stockInInfo.GoodId)
  7925. flow := models.VmStockFlow{
  7926. WarehousingId: warehouseOutInfo.WarehouseInfotId,
  7927. GoodId: good_yc.GoodId,
  7928. Number: warehouseOutInfos.Number,
  7929. LicenseNumber: stockInInfo.LicenseNumber,
  7930. Count: delete_count,
  7931. UserOrgId: orgID,
  7932. PatientId: patient_id,
  7933. SystemTime: record_time,
  7934. ConsumableType: 7,
  7935. IsSys: 0,
  7936. WarehousingOrder: "",
  7937. WarehouseOutId: warehouseOutInfos.WarehouseOutId,
  7938. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7939. IsEdit: 0,
  7940. CancelStockId: cancel.ID,
  7941. CancelOrderNumber: cancel.OrderNumber,
  7942. Manufacturer: manufacturer.ID,
  7943. Dealer: 0,
  7944. Creator: warehouseOut.Creater,
  7945. UpdateCreator: 0,
  7946. Status: 1,
  7947. Ctime: time.Now().Unix(),
  7948. Mtime: 0,
  7949. Price: stockInInfo.Price,
  7950. WarehousingDetailId: stockInInfo.ID,
  7951. WarehouseOutDetailId: warehouseOutInfos.ID,
  7952. CancelOutDetailId: cancelInfo.ID,
  7953. ProductDate: stockInInfo.ProductDate,
  7954. ExpireDate: stockInInfo.ExpiryDate,
  7955. StorehouseId: houseConfig.StorehouseOutInfo,
  7956. OverCount: sum_count,
  7957. }
  7958. service.CreateStockFlowOne(flow)
  7959. //更改自动出库的表格
  7960. details := models.BloodAutomaticReduceDetail{
  7961. WarehouseOutId: warehouseOutInfo.ID,
  7962. WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
  7963. PatientId: patient_id,
  7964. Ctime: time.Now().Unix(),
  7965. Mtime: time.Now().Unix(),
  7966. Status: 1,
  7967. RecordTime: record_time,
  7968. OrgId: orgID,
  7969. GoodId: good_yc.GoodId,
  7970. GoodTypeId: good_yc.GoodTypeId,
  7971. Count: count,
  7972. StorehouseId: houseConfig.StorehouseOutInfo,
  7973. }
  7974. //查询当天耗材是否已经存在数据
  7975. _, errcode := service.GetAutoMaticReduceDetail(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7976. if errcode == gorm.ErrRecordNotFound {
  7977. errTwo := service.CreateAutoReduceRecord(&details)
  7978. if errTwo != nil {
  7979. return errTwo
  7980. }
  7981. } else if errcode == nil {
  7982. service.DeleteAutoRedeceDetailTwo(orgID, patient_id, record_time, good_yc.GoodId, good_yc.GoodTypeId)
  7983. service.CreateAutoReduceRecord(&details)
  7984. }
  7985. service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
  7986. //增加出库库存数量
  7987. //service.ModifyReduceGoodSumCount(houseConfig.StorehouseOutInfo,delete_count,good_yc.OrgId,good_yc.GoodId)
  7988. if good_yc.Count == 0 {
  7989. return nil
  7990. } else {
  7991. return errors.New("退库和出库数据不匹配")
  7992. }
  7993. }
  7994. func (this *DialysisAPIController) SavePatientSign() {
  7995. adminUserInfo := this.GetMobileAdminUserInfo()
  7996. patient_id, _ := this.GetInt64("patient_id")
  7997. dialysis_date, _ := this.GetInt64("dialysis_date")
  7998. orgid := adminUserInfo.Org.Id
  7999. var esdata models.DialysisOrder
  8000. var err error
  8001. if err = json.Unmarshal(this.Ctx.Input.RequestBody, &esdata); err != nil {
  8002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8003. return
  8004. }
  8005. esdata.Hash = esdata.Hash
  8006. esdata.Url = beego.AppConfig.String("qiniu_domain") + esdata.Hash
  8007. order := models.DialysisOrder{
  8008. Hash: esdata.Hash,
  8009. Url: esdata.Url,
  8010. }
  8011. err = service.UpdatePatientSign(patient_id, dialysis_date, order, orgid)
  8012. redis := service.RedisClient()
  8013. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8014. redis.Set(key, "", time.Second)
  8015. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8016. //清空key 值
  8017. redis.Set(keyOne, "", time.Second)
  8018. //scheduleDateStartOne := startDate.Format("2006-01-02")
  8019. //keyTwo := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  8020. //redis.Set(keyTwo, "", time.Second)
  8021. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8022. redis.Set(keyThree, "", time.Second)
  8023. keyFour := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8024. redis.Set(keyFour, "", time.Second)
  8025. keyFive := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8026. redis.Set(keyFive, "", time.Second)
  8027. keySix := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8028. redis.Set(keySix, "", time.Second)
  8029. keySeven := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + ":device_list_all"
  8030. redis.Set(keySeven, "", time.Second)
  8031. if err != nil {
  8032. fmt.Println(err)
  8033. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8034. return
  8035. }
  8036. this.ServeSuccessJSON(map[string]interface{}{
  8037. "electronic_signature": esdata,
  8038. })
  8039. }
  8040. func (this *DialysisAPIController) GetPatientSign() {
  8041. patient_id, _ := this.GetInt64("patient_id")
  8042. dialysis_date, _ := this.GetInt64("dialysis_date")
  8043. adminUserInfo := this.GetMobileAdminUserInfo()
  8044. orgId := adminUserInfo.Org.Id
  8045. dialysisOrder, err := service.GetPatientSign(patient_id, dialysis_date, orgId)
  8046. if err != nil {
  8047. fmt.Println(err)
  8048. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8049. return
  8050. }
  8051. this.ServeSuccessJSON(map[string]interface{}{
  8052. "dialysisOrder": dialysisOrder,
  8053. })
  8054. }
  8055. func (this *DialysisAPIController) GetScheduleByPatient() {
  8056. patient_id, _ := this.GetInt64("patient_id")
  8057. schedule_date, _ := this.GetInt64("schedule_date")
  8058. orgid := this.GetMobileAdminUserInfo().Org.Id
  8059. schedule, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgid)
  8060. this.ServeSuccessJSON(map[string]interface{}{
  8061. "schedule": schedule,
  8062. })
  8063. }
  8064. func (this *DialysisAPIController) GetDialysisRecordOrder() {
  8065. org_id := this.GetMobileAdminUserInfo().Org.Id
  8066. patient_id, _ := this.GetInt64("patient_id")
  8067. schedule_date, _ := this.GetInt64("schedule_date")
  8068. order, _ := service.GetDialysisRecordOrder(org_id, patient_id, schedule_date)
  8069. this.ServeSuccessJSON(map[string]interface{}{
  8070. "order": order,
  8071. })
  8072. }
  8073. func (this *DialysisAPIController) GetScheduleTypeByIdList() {
  8074. org_id := this.GetMobileAdminUserInfo().Org.Id
  8075. schedule_date := this.GetString("schedule_date")
  8076. schedule_type, _ := this.GetInt64("schedule_type")
  8077. timeLayout := "2006-01-02"
  8078. loc, _ := time.LoadLocation("Local")
  8079. var startdateunix int64
  8080. if len(schedule_date) > 0 {
  8081. theTime, err := time.ParseInLocation(timeLayout+"15:04:05", schedule_date+"00:00:00", loc)
  8082. if err != nil {
  8083. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8084. return
  8085. }
  8086. startdateunix = theTime.Unix()
  8087. }
  8088. list, _ := service.GetScheduleTypeById(org_id, startdateunix, schedule_type)
  8089. scheduals, _ := service.MobileGetDialysisScheduals(org_id, startdateunix, schedule_type)
  8090. devices, _ := service.GetAllDevicetByListSix(org_id)
  8091. for key, item := range scheduals {
  8092. // 床位信息
  8093. for _, device := range devices {
  8094. if item.BedId == device.ID {
  8095. scheduals[key].DeviceNumber = device
  8096. break
  8097. }
  8098. }
  8099. }
  8100. this.ServeSuccessJSON(map[string]interface{}{
  8101. "list": list,
  8102. "scheduals": scheduals,
  8103. })
  8104. }
  8105. func (this *DialysisAPIController) SavePatientPicture() {
  8106. patient_id, _ := this.GetInt64("patient_id")
  8107. dialysis_date, _ := this.GetInt64("schedule_date")
  8108. avatar := this.GetString("avatar")
  8109. fmt.Println("patient_id", patient_id)
  8110. orgId := this.GetMobileAdminUserInfo().Org.Id
  8111. order := models.DialysisOrder{
  8112. Url: avatar,
  8113. }
  8114. err := service.UpdatePatientSign(patient_id, dialysis_date, order, orgId)
  8115. redis := service.RedisClient()
  8116. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_order"
  8117. redis.Set(key, "", time.Second)
  8118. keyOne := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":dialysis_orders_list_all"
  8119. //清空key 值
  8120. redis.Set(keyOne, "", time.Second)
  8121. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":doctor_advices"
  8122. redis.Set(keyThree, "", time.Second)
  8123. keyFour := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":monitor_records"
  8124. redis.Set(keyFour, "", time.Second)
  8125. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":patient_info"
  8126. redis.Set(keyFive, "", time.Second)
  8127. keySix := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysis_date, 10) + ":his_doctor_advice"
  8128. redis.Set(keySix, "", time.Second)
  8129. keySeven := strconv.FormatInt(orgId, 10) + ":" + ":device_list_all"
  8130. redis.Set(keySeven, "", time.Second)
  8131. if err != nil {
  8132. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  8133. return
  8134. }
  8135. this.ServeSuccessJSON(map[string]interface{}{
  8136. "order": order,
  8137. })
  8138. }
  8139. func (this *DialysisAPIController) ExectionMobileAdvice() {
  8140. ids := this.GetString("ids")
  8141. idSplit := strings.Split(ids, ",")
  8142. orgId := this.GetMobileAdminUserInfo().Org.Id
  8143. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8144. execution_time := this.GetString("exce_time")
  8145. timeLayout2 := "2006-01-02 15:04:05"
  8146. loc, _ := time.LoadLocation("Local")
  8147. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  8148. if errs != nil {
  8149. utils.ErrorLog(errs.Error())
  8150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8151. return
  8152. }
  8153. //his客户
  8154. if config.IsOpen == 1 {
  8155. list, _ := service.GetHisMobileAdviceGroupList(orgId, idSplit)
  8156. adviceList, _ := service.GetHisMobileAdviceList(orgId, idSplit)
  8157. for _, item := range list {
  8158. for _, it := range adviceList {
  8159. if item.DrugId == it.DrugId {
  8160. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8161. }
  8162. }
  8163. }
  8164. for _, item := range list {
  8165. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8166. var sum_out_count int64
  8167. for _, itemThree := range item.ChildDoctorAdvice {
  8168. var prescribing_number int64
  8169. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8170. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8171. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8172. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8173. }
  8174. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8175. prescribing_number = parseIntPrescribingNumber
  8176. }
  8177. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8178. prescribing_number = parseIntPrescribingNumber
  8179. }
  8180. sum_out_count += prescribing_number
  8181. }
  8182. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8183. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8184. //库存不足
  8185. if sum_out_count > drugStockOut.FlushCount {
  8186. this.ServeSuccessJSON(map[string]interface{}{
  8187. "msg": "2",
  8188. "drug": medical,
  8189. "ids": ids,
  8190. })
  8191. return
  8192. }
  8193. }
  8194. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8195. //执行医嘱
  8196. errs := service.ExectionMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8197. advices, _ := service.FindHisDoctorAdviceByIds(orgId, idSplit)
  8198. for _, item := range advices {
  8199. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8200. redis := service.RedisClient()
  8201. //清空key 值
  8202. redis.Set(key, "", time.Second)
  8203. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8204. redis.Set(keyTwo, "", time.Second)
  8205. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8206. redis.Set(keyThree, "", time.Second)
  8207. recordDate := theTime.Format("2006-01-02")
  8208. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8209. redis.Set(keyFour, "", time.Second)
  8210. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8211. redis.Set(keyFive, "", time.Second)
  8212. defer redis.Close()
  8213. }
  8214. if errs == nil {
  8215. //药品管理信息
  8216. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8217. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8218. if drugStockConfig.IsOpen == 1 {
  8219. for _, item := range advices {
  8220. advice, _ := service.FindHisDoctorAdviceById(orgId, item.ID)
  8221. config, _ := service.GetDrugOpenConfigOne(orgId)
  8222. if config.IsOpen != 1 {
  8223. //查询该药品是否有库存
  8224. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8225. pharmacyConfig, _ := service.FindPharmacyConfig(advice.UserOrgId)
  8226. if medical.IsUse == 2 {
  8227. if config.IsOpen != 1 {
  8228. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8229. service.HisDrugsDelivery(orgId, creater, &advice)
  8230. if orgId == 3877 || orgId == 10265 {
  8231. //查询该药品是否有出库记录
  8232. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8233. if len(flowMap) == 0 {
  8234. errs := service.UpdateHisAdviceById(advice.ID)
  8235. if errs != nil {
  8236. drugError := models.XtDrugError{
  8237. UserOrgId: orgId,
  8238. DrugId: item.DrugId,
  8239. RecordDate: item.AdviceDate,
  8240. PatientId: item.PatientId,
  8241. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8242. Status: 1,
  8243. Ctime: time.Now().Unix(),
  8244. Mtime: 0,
  8245. SumCount: 0,
  8246. Prescribingnumber: advice.PrescribingNumber,
  8247. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8248. }
  8249. service.CreateDrugError(drugError)
  8250. }
  8251. this.ServeSuccessJSON(map[string]interface{}{
  8252. "msg": "2",
  8253. "drug": medical,
  8254. "ids": ids,
  8255. })
  8256. return
  8257. }
  8258. }
  8259. }
  8260. if pharmacyConfig.IsOpen != 1 {
  8261. service.HisDrugsDelivery(orgId, creater, &advice)
  8262. if orgId == 3877 || orgId == 10265 {
  8263. //查询该药品是否有出库记录
  8264. flowMap, _ := service.GetDrugFLowByAdviceById(advice.DrugId, advice.PatientId, advice.UserOrgId, advice.AdviceDate)
  8265. if len(flowMap) == 0 {
  8266. errs := service.UpdateHisAdviceById(advice.ID)
  8267. if errs != nil {
  8268. drugError := models.XtDrugError{
  8269. UserOrgId: orgId,
  8270. DrugId: item.DrugId,
  8271. RecordDate: item.AdviceDate,
  8272. PatientId: item.PatientId,
  8273. Remark: "透析医嘱页面出库记录为空,更新执行人失败",
  8274. Status: 1,
  8275. Ctime: time.Now().Unix(),
  8276. Mtime: 0,
  8277. SumCount: 0,
  8278. Prescribingnumber: advice.PrescribingNumber,
  8279. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  8280. }
  8281. service.CreateDrugError(drugError)
  8282. }
  8283. this.ServeSuccessJSON(map[string]interface{}{
  8284. "msg": "2",
  8285. "drug": medical,
  8286. "ids": ids,
  8287. })
  8288. return
  8289. }
  8290. }
  8291. }
  8292. //更新字典里面的库存
  8293. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8294. var sum_count int64
  8295. for _, its := range stockInfo {
  8296. if its.MaxUnit == medical.MaxUnit {
  8297. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8298. }
  8299. sum_count += its.StockMaxNumber + its.StockMinNumber
  8300. }
  8301. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8302. //剩余库存
  8303. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8304. }
  8305. }
  8306. }
  8307. }
  8308. }
  8309. this.ServeSuccessJSON(map[string]interface{}{
  8310. "msg": "1",
  8311. "ids": ids,
  8312. })
  8313. return
  8314. } else {
  8315. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8316. }
  8317. }
  8318. fmt.Println("config233322333223", config.IsOpen)
  8319. //血透客户
  8320. if config.IsOpen == 2 || config.IsOpen == 0 {
  8321. //药品管理信息
  8322. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(orgId)
  8323. if drugStockConfig.IsOpen == 1 {
  8324. list, _ := service.GetBloodMobileAdviceGroupList(orgId, idSplit)
  8325. adviceList, _ := service.GetBloodMobileAdviceList(orgId, idSplit)
  8326. for _, item := range list {
  8327. for _, it := range adviceList {
  8328. if item.DrugId == it.DrugId {
  8329. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  8330. }
  8331. }
  8332. }
  8333. for _, item := range list {
  8334. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8335. var sum_out_count int64
  8336. for _, itemThree := range item.ChildDoctorAdvice {
  8337. var prescribing_number int64
  8338. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8339. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8340. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8341. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8342. }
  8343. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8344. prescribing_number = parseIntPrescribingNumber
  8345. }
  8346. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8347. prescribing_number = parseIntPrescribingNumber
  8348. }
  8349. sum_out_count += prescribing_number
  8350. }
  8351. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8352. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(item.DrugId, orgId, houseConfig.DrugStorehouseOut)
  8353. //库存不足
  8354. if sum_out_count > drugStockOut.FlushCount {
  8355. this.ServeSuccessJSON(map[string]interface{}{
  8356. "msg": "2",
  8357. "drug": medical,
  8358. "ids": ids,
  8359. })
  8360. return
  8361. }
  8362. }
  8363. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8364. fmt.Println("creater2332243244224242424", creater)
  8365. //执行医嘱
  8366. errs := service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8367. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8368. for _, item := range advices {
  8369. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8370. redis := service.RedisClient()
  8371. //清空key 值
  8372. redis.Set(key, "", time.Second)
  8373. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8374. redis.Set(keyTwo, "", time.Second)
  8375. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8376. redis.Set(keyThree, "", time.Second)
  8377. recordDate := theTime.Format("2006-01-02")
  8378. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8379. redis.Set(keyFour, "", time.Second)
  8380. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8381. redis.Set(keyFive, "", time.Second)
  8382. defer redis.Close()
  8383. }
  8384. if errs == nil {
  8385. for _, item := range advices {
  8386. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8387. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8388. //查询是否出库按钮开启
  8389. adviceSetting, _ := service.FindAdviceSettingById(item.UserOrgId)
  8390. if adviceSetting.IsAdviceOpen == 1 {
  8391. //查询是否出库按钮开启
  8392. prescriptionConfig, _ := service.FindPrescriptionConfigById(item.UserOrgId)
  8393. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8394. if prescriptionConfig.IsOpen == 1 {
  8395. if medical.IsUse == 2 {
  8396. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8397. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8398. }
  8399. if pharmacyConfig.IsOpen != 1 {
  8400. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8401. }
  8402. //更新字典里面的库存
  8403. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8404. var sum_count int64
  8405. for _, its := range stockInfo {
  8406. if its.MaxUnit == medical.MaxUnit {
  8407. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8408. }
  8409. sum_count += its.StockMaxNumber + its.StockMinNumber
  8410. }
  8411. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8412. //剩余库存
  8413. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8414. }
  8415. }
  8416. } else {
  8417. pharmacyConfig, _ := service.FindPharmacyConfig(item.UserOrgId)
  8418. if medical.IsUse == 2 {
  8419. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  8420. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8421. }
  8422. if pharmacyConfig.IsOpen != 1 {
  8423. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
  8424. }
  8425. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8426. var sum_count int64
  8427. for _, its := range stockInfo {
  8428. if its.MaxUnit == medical.MaxUnit {
  8429. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8430. }
  8431. sum_count += its.StockMaxNumber + its.StockMinNumber
  8432. }
  8433. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8434. //剩余库存
  8435. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8436. }
  8437. }
  8438. }
  8439. }
  8440. this.ServeSuccessJSON(map[string]interface{}{
  8441. "msg": "1",
  8442. "ids": ids,
  8443. })
  8444. return
  8445. } else {
  8446. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8447. //执行医嘱
  8448. service.ExectionBloodMobileAdvice(orgId, idSplit, theTime.Unix(), creater)
  8449. advices, _ := service.FindAllDoctorAdviceByIds(orgId, idSplit)
  8450. for _, item := range advices {
  8451. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8452. redis := service.RedisClient()
  8453. //清空key 值
  8454. redis.Set(key, "", time.Second)
  8455. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8456. redis.Set(keyTwo, "", time.Second)
  8457. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8458. redis.Set(keyThree, "", time.Second)
  8459. recordDate := theTime.Format("2006-01-02")
  8460. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8461. redis.Set(keyFour, "", time.Second)
  8462. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8463. redis.Set(keyFive, "", time.Second)
  8464. defer redis.Close()
  8465. }
  8466. this.ServeSuccessJSON(map[string]interface{}{
  8467. "msg": "1",
  8468. "ids": ids,
  8469. })
  8470. return
  8471. }
  8472. }
  8473. }
  8474. func (this *DialysisAPIController) GetSettleMobileAdvice() {
  8475. ids := this.GetString("ids")
  8476. idSplit := strings.Split(ids, ",")
  8477. orgId := this.GetMobileAdminUserInfo().Org.Id
  8478. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8479. if config.IsOpen == 1 {
  8480. service.UpdateSettleMobileHisAdvice(orgId, idSplit)
  8481. this.ServeSuccessJSON(map[string]interface{}{
  8482. "msg": "1",
  8483. "ids": ids,
  8484. })
  8485. return
  8486. }
  8487. if config.IsOpen == 0 || config.IsOpen == 2 {
  8488. service.UpdateSettleMobileBloodAdvice(orgId, idSplit)
  8489. this.ServeSuccessJSON(map[string]interface{}{
  8490. "msg": "1",
  8491. "ids": ids,
  8492. })
  8493. return
  8494. }
  8495. }
  8496. func (this *DialysisAPIController) GetCheckMobileAdvice() {
  8497. ids := this.GetString("ids")
  8498. idSplit := strings.Split(ids, ",")
  8499. orgId := this.GetMobileAdminUserInfo().Org.Id
  8500. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  8501. //his
  8502. if config.IsOpen == 1 {
  8503. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8504. theTime := time.Now()
  8505. advices := models.HisDoctorAdviceThirty{
  8506. CheckTime: theTime.Unix(),
  8507. Checker: checker,
  8508. UpdatedTime: time.Now().Unix(),
  8509. }
  8510. service.CheckHisMobileDoctorAdvice(orgId, idSplit, advices)
  8511. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8512. for _, item := range list {
  8513. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8514. redis := service.RedisClient()
  8515. //清空key 值
  8516. redis.Set(key, "", time.Second)
  8517. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8518. redis.Set(keyTwo, "", time.Second)
  8519. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8520. redis.Set(keyThree, "", time.Second)
  8521. recordDate := theTime.Format("2006-01-02")
  8522. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8523. redis.Set(keyFour, "", time.Second)
  8524. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8525. redis.Set(keyFive, "", time.Second)
  8526. defer redis.Close()
  8527. }
  8528. this.ServeSuccessJSON(map[string]interface{}{
  8529. "msg": "1",
  8530. "ids": ids,
  8531. })
  8532. return
  8533. }
  8534. //血透
  8535. if config.IsOpen == 0 || config.IsOpen == 2 {
  8536. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8537. theTime := time.Now()
  8538. advices := models.DoctorAdvice{
  8539. CheckTime: theTime.Unix(),
  8540. Checker: checker,
  8541. UpdatedTime: time.Now().Unix(),
  8542. }
  8543. service.CheckBloodDoctorAdvice(orgId, idSplit, advices)
  8544. list, _ := service.FindDoctorAdviceByIds(orgId, idSplit)
  8545. for _, item := range list {
  8546. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  8547. redis := service.RedisClient()
  8548. //清空key 值
  8549. redis.Set(key, "", time.Second)
  8550. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  8551. redis.Set(keyTwo, "", time.Second)
  8552. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  8553. redis.Set(keyThree, "", time.Second)
  8554. recordDate := theTime.Format("2006-01-02")
  8555. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  8556. redis.Set(keyFour, "", time.Second)
  8557. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  8558. redis.Set(keyFive, "", time.Second)
  8559. defer redis.Close()
  8560. }
  8561. this.ServeSuccessJSON(map[string]interface{}{
  8562. "msg": "1",
  8563. "ids": ids,
  8564. })
  8565. return
  8566. }
  8567. }
  8568. func (this *DialysisAPIController) CheckSchedule() {
  8569. patientID, _ := this.GetInt64("patient_id")
  8570. recordDateStr := this.GetString("record_date")
  8571. nurseID, _ := this.GetInt64("start_nurse")
  8572. schedual_type, _ := this.GetInt64("schedual_type")
  8573. bedID, _ := this.GetInt64("bed")
  8574. start_time := this.GetString("start_time")
  8575. fmt.Println("patientID", patientID)
  8576. fmt.Println("recordDateStr", recordDateStr)
  8577. fmt.Println("nurseID", nurseID)
  8578. fmt.Println("schedual_type------", schedual_type)
  8579. if patientID <= 0 || len(recordDateStr) == 0 || nurseID <= 0 || bedID <= 0 {
  8580. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8581. return
  8582. }
  8583. startDate, parseStartDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  8584. if parseStartDateErr != nil {
  8585. this.ErrorLog("时间解析失败:%v", parseStartDateErr)
  8586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8587. return
  8588. }
  8589. recordDate, parseErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8590. if parseErr != nil {
  8591. this.ErrorLog("时间解析失败:%v", parseErr)
  8592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8593. return
  8594. }
  8595. adminUserInfo := this.GetMobileAdminUserInfo()
  8596. patient, getPatientErr := service.MobileGetPatientById(adminUserInfo.Org.Id, patientID)
  8597. if getPatientErr != nil {
  8598. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  8599. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8600. return
  8601. } else if patient == nil {
  8602. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8603. return
  8604. }
  8605. nurse, getNurseErr := service.GetAdminUserByUserID(nurseID)
  8606. if getNurseErr != nil {
  8607. this.ErrorLog("获取护士失败:%v", getNurseErr)
  8608. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8609. return
  8610. } else if nurse == nil {
  8611. this.ErrorLog("护士不存在")
  8612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8613. return
  8614. }
  8615. deviceNumber, getDeviceNumberErr := service.GetDeviceNumberByID(adminUserInfo.Org.Id, bedID)
  8616. if getDeviceNumberErr != nil {
  8617. this.ErrorLog("获取床位号失败:%v", getDeviceNumberErr)
  8618. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8619. return
  8620. } else if deviceNumber == nil {
  8621. this.ErrorLog("床位号不存在")
  8622. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8623. return
  8624. }
  8625. dialysisRecord, getRecordErr := service.MobileGetDialysisRecord(adminUserInfo.Org.Id, patientID, recordDate.Unix())
  8626. if getRecordErr != nil {
  8627. this.ErrorLog("获取透析记录失败:%v", getRecordErr)
  8628. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8629. return
  8630. } else if dialysisRecord != nil {
  8631. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatStart)
  8632. return
  8633. }
  8634. scheduleDateStart := startDate.Format("2006-01-02") + " 00:00:00"
  8635. scheduleDateEnd := startDate.Format("2006-01-02") + " 23:59:59"
  8636. timeLayout := "2006-01-02 15:04:05"
  8637. loc, _ := time.LoadLocation("Local")
  8638. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  8639. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  8640. schedulestartTime := theStartTime.Unix()
  8641. scheduleendTime := theEndTime.Unix()
  8642. //查询更改的机号,是否有人用了,如果只是排班了,但是没上机,直接替换,如果排班且上机了,就提示他无法上机
  8643. //sch, _ := service.GetSourceSch(adminUserInfo.Org.Id, patientID, scheduleendTime)
  8644. schedule, err := service.GetDayScheduleByBedid(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8645. //查询该床位是否有人用了
  8646. order, _ := service.GetDialysisOrderByBedIdTwo(adminUserInfo.Org.Id, schedulestartTime, bedID, schedual_type)
  8647. if err == nil {
  8648. if schedule.ID == 0 {
  8649. this.ServeSuccessJSON(map[string]interface{}{
  8650. "status": 0,
  8651. "msg": "请求失败",
  8652. })
  8653. } else {
  8654. if schedule.ID > 0 && schedule.DialysisOrder.ID == 0 { //有排班没上机记录
  8655. if order.ID > 0 { //该机位被其他人占用了
  8656. this.ServeFailJSONWithSGJErrorCode(enums.ErrorDialysisOrderRepeatBed)
  8657. return
  8658. } else { //2022-11-04 更变需求,如果改床位有排班,但是没上机,则进行互换床位操作,如果改床位是本人的话,不做处理
  8659. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, schedulestartTime, scheduleendTime, patientID)
  8660. if daySchedule.ID > 0 && schedule.PatientId != daySchedule.PatientId {
  8661. this.ServeSuccessJSON(map[string]interface{}{
  8662. "status": 1,
  8663. "msg": "该机位已有排班,继续操作将会与原来的排班信息进行互调,请问是否继续?",
  8664. })
  8665. return
  8666. } else {
  8667. this.ServeSuccessJSON(map[string]interface{}{
  8668. "status": 0,
  8669. "msg": "",
  8670. })
  8671. }
  8672. }
  8673. } else if schedule.ID > 0 && schedule.DialysisOrder.ID > 0 {
  8674. this.ServeSuccessJSON(map[string]interface{}{
  8675. "status": 2,
  8676. "msg": "当前机位已有患者在使用,请重新选择!",
  8677. })
  8678. }
  8679. }
  8680. } else {
  8681. this.ServeSuccessJSON(map[string]interface{}{
  8682. "status": 0,
  8683. "msg": "",
  8684. })
  8685. }
  8686. }
  8687. func (this *DialysisAPIController) GetNewDoctorListToday() {
  8688. orgId := this.GetMobileAdminUserInfo().Org.Id
  8689. schedule_type, _ := this.GetInt64("schedule_type")
  8690. partion_type, _ := this.GetInt64("partion_type")
  8691. start_time := this.GetString("start_time")
  8692. timeLayout := "2006-01-02"
  8693. loc, _ := time.LoadLocation("Local")
  8694. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8695. list, err := service.GetDialysisAdviceSchedulistSeven(orgId, schedule_type, partion_type, startTime.Unix())
  8696. _, config := service.FindXTHisRecordByOrgId(orgId)
  8697. appId := this.GetMobileAdminUserInfo().App.Id
  8698. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  8699. if err == nil {
  8700. this.ServeSuccessJSON(map[string]interface{}{
  8701. "list": list,
  8702. "config": config,
  8703. "doctorList": doctorList,
  8704. })
  8705. return
  8706. } else {
  8707. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8708. return
  8709. }
  8710. }
  8711. func (this *DialysisAPIController) SaveMobileInformation() {
  8712. patient_id, _ := this.GetInt64("patient_id")
  8713. record_date, _ := this.GetInt64("record_date")
  8714. startTime := this.GetString("start_time")
  8715. module, _ := this.GetInt64("module")
  8716. remark := this.GetString("remark")
  8717. timeLayout := "2006-01-02 15:04"
  8718. loc, _ := time.LoadLocation("Local")
  8719. if len(startTime) == 0 {
  8720. utils.ErrorLog("len(start_time) == 0")
  8721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8722. return
  8723. }
  8724. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  8725. if err != nil {
  8726. utils.ErrorLog(err.Error())
  8727. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8728. return
  8729. }
  8730. StartTime := theTime.Unix()
  8731. fmt.Println("startime-------------", StartTime)
  8732. creater := this.GetMobileAdminUserInfo().AdminUser.Id
  8733. user_org_id := this.GetMobileAdminUserInfo().Org.Id
  8734. information := models.XtDialysisInformation{
  8735. Module: module,
  8736. PatientId: patient_id,
  8737. RecordDate: record_date,
  8738. ApplicationDate: StartTime,
  8739. Creater: creater,
  8740. ApplicationStatus: 2,
  8741. Checker: 0,
  8742. CheckTime: 0,
  8743. Remark: remark,
  8744. UserOrgId: user_org_id,
  8745. Ctime: time.Now().Unix(),
  8746. Status: 1,
  8747. Mtime: 0,
  8748. }
  8749. infor, _ := service.GetDialysisInformationByRecordDateOne(patient_id, record_date, user_org_id)
  8750. if infor.ID == 0 {
  8751. service.SaveDialysisInformation(information)
  8752. }
  8753. if infor.ID > 0 {
  8754. service.UpdateInformationByRecordDate(patient_id, record_date, user_org_id, StartTime, remark)
  8755. }
  8756. this.ServeSuccessJSON(map[string]interface{}{
  8757. "information": information,
  8758. })
  8759. return
  8760. }
  8761. func (this *DialysisAPIController) GetMobileInformation() {
  8762. limit, _ := this.GetInt64("limit")
  8763. page, _ := this.GetInt64("page")
  8764. orgid := this.GetMobileAdminUserInfo().Org.Id
  8765. information, total, _ := service.GetMobileInformation(limit, page, 2, orgid)
  8766. appid := this.GetMobileAdminUserInfo().App.Id
  8767. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8768. patients, _ := service.GetAllpatientThirty(orgid)
  8769. this.ServeSuccessJSON(map[string]interface{}{
  8770. "information": information,
  8771. "total": total,
  8772. "doclist": doclist,
  8773. "patients": patients,
  8774. })
  8775. return
  8776. }
  8777. func (this *DialysisAPIController) GetMobileInformationOne() {
  8778. limit, _ := this.GetInt64("limit")
  8779. page, _ := this.GetInt64("page")
  8780. orgid := this.GetMobileAdminUserInfo().Org.Id
  8781. information, total, _ := service.GetMobileInformationOne(limit, page, orgid)
  8782. appid := this.GetMobileAdminUserInfo().App.Id
  8783. doclist, _ := service.GetAllDoctorSix(orgid, appid)
  8784. patients, _ := service.GetAllpatientThirty(orgid)
  8785. this.ServeSuccessJSON(map[string]interface{}{
  8786. "information": information,
  8787. "total": total,
  8788. "doclist": doclist,
  8789. "patients": patients,
  8790. })
  8791. return
  8792. }
  8793. func (this *DialysisAPIController) CheckMobileInformation() {
  8794. id, _ := this.GetInt64("id")
  8795. application_status, _ := this.GetInt64("application_status")
  8796. checker := this.GetMobileAdminUserInfo().AdminUser.Id
  8797. checktime := time.Now().Unix()
  8798. err := service.CheckMobileInformation(id, application_status, checker, checktime)
  8799. if err == nil {
  8800. this.ServeSuccessJSON(map[string]interface{}{
  8801. "msg": "ok",
  8802. })
  8803. return
  8804. }
  8805. }
  8806. func (c *DialysisAPIController) GetControlMonitorList() {
  8807. partition, _ := c.GetInt64("partition")
  8808. monitorDate := c.GetString("date")
  8809. patient_id, _ := c.GetInt64("patient_id")
  8810. pat_type, _ := c.GetInt64("pat_type")
  8811. timeLayout := "2006-01-02"
  8812. loc, _ := time.LoadLocation("Local")
  8813. var theStartTime int64
  8814. if len(monitorDate) > 0 {
  8815. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", monitorDate+" 00:00:00", loc)
  8816. if err != nil {
  8817. theStartTime = 0
  8818. }
  8819. theStartTime = theTime.Unix()
  8820. }
  8821. adminInfo := c.GetMobileAdminUserInfo()
  8822. orgID := adminInfo.Org.Id
  8823. monitor, err := service.GetNewMonitorRecord(orgID, theStartTime, partition, patient_id)
  8824. if err != nil {
  8825. c.ErrorLog("获取排班信息失败:%v", err)
  8826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8827. } else {
  8828. if len(monitor) > 0 {
  8829. //获取所有床位
  8830. numberList, _ := service.GetAllDeviceNumberByList(orgID)
  8831. //获取所有分区
  8832. zoneList, _ := service.GetAllZoneByList(orgID)
  8833. //获取透析处方
  8834. prescriptions, _ := service.GetAllPrescriptionByListSix(orgID, theStartTime)
  8835. //获取透前评估
  8836. assessmentBefores, _ := service.GetAllAssessmentBeforesByListOne(orgID, theStartTime)
  8837. //获取上机
  8838. dialysisOrders, _ := service.GetAllDialysisOrdersByListNight(orgID, theStartTime, pat_type)
  8839. //获取透后
  8840. AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListSix(orgID, theStartTime)
  8841. //获取透后监测
  8842. monitorlist, _ := service.GetNewAllMonitorList(orgID, theStartTime, pat_type)
  8843. //获取所有的患者
  8844. patients, _ := service.GetAllPatientListByListOne(orgID)
  8845. //获取所有透析模式
  8846. treatments, _ := service.GetAllTreatModeByList(orgID)
  8847. //获取所有医嘱
  8848. adviceList, _ := service.GetAdviceList(orgID, theStartTime, pat_type)
  8849. //获取双人核对
  8850. checkList, _ := service.GetDobuleCheck(orgID, theStartTime)
  8851. //治疗小结
  8852. summaryList, _ := service.GetTreatmentSummaryForList(orgID, theStartTime)
  8853. //待消毒
  8854. informationList, _ := service.GetDialysisInformationList(orgID, theStartTime)
  8855. for key, item := range monitor {
  8856. // 获取床位信息
  8857. for _, it := range numberList {
  8858. if item.BedId == it.ID {
  8859. monitor[key].DeviceNumber = it
  8860. break
  8861. }
  8862. }
  8863. //获取分区信息
  8864. for _, it := range zoneList {
  8865. if item.PartitionId == it.ID {
  8866. monitor[key].DeviceZone = it
  8867. }
  8868. }
  8869. for _, prescription := range prescriptions {
  8870. if item.PatientId == prescription.PatientId {
  8871. monitor[key].Prescription = prescription
  8872. break
  8873. }
  8874. }
  8875. for _, it := range checkList {
  8876. if item.PatientId == it.PatientId {
  8877. monitor[key].DoubleCheck = it
  8878. break
  8879. }
  8880. }
  8881. for _, it := range summaryList {
  8882. if item.PatientId == it.PatientId {
  8883. monitor[key].TreatmentSummaryForList = it
  8884. break
  8885. }
  8886. }
  8887. // 透前评估
  8888. for _, assessmentBefore := range assessmentBefores {
  8889. if item.PatientId == assessmentBefore.PatientId {
  8890. monitor[key].AssessmentBeforeDislysis = assessmentBefore
  8891. break
  8892. }
  8893. }
  8894. // 透析上下机
  8895. for _, dialysisOrder := range dialysisOrders {
  8896. if item.PatientId == dialysisOrder.PatientId {
  8897. monitor[key].DialysisOrder = dialysisOrder
  8898. break
  8899. }
  8900. }
  8901. // 治疗小节
  8902. for _, afterDislysis := range AssessmentAfterDislysis {
  8903. if item.PatientId == afterDislysis.PatientId {
  8904. monitor[key].AssessmentAfterDislysis = afterDislysis
  8905. break
  8906. }
  8907. }
  8908. for _, it := range monitorlist {
  8909. if item.PatientId == it.PatientId {
  8910. monitor[key].MonitoringRecord = append(monitor[key].MonitoringRecord, it)
  8911. }
  8912. }
  8913. for _, it := range adviceList {
  8914. if item.PatientId == it.PatientId {
  8915. monitor[key].AdviceList = append(monitor[key].AdviceList, it)
  8916. }
  8917. }
  8918. for _, patient := range patients {
  8919. if item.PatientId == patient.ID {
  8920. monitor[key].MonitorPatients = patient
  8921. break
  8922. }
  8923. }
  8924. for _, treatment := range treatments {
  8925. if item.ModeId == treatment.ID {
  8926. monitor[key].TreatmentMode = treatment
  8927. break
  8928. }
  8929. }
  8930. for _, infor := range informationList {
  8931. if item.PatientId == infor.PatientId {
  8932. monitor[key].NewDeviceInformation = infor
  8933. break
  8934. }
  8935. }
  8936. }
  8937. }
  8938. }
  8939. patients, err := service.GetAllpatientFourty(orgID)
  8940. var mds []*models.NewMonitorDialysisScheduleList
  8941. if pat_type == 0 {
  8942. for _, item := range monitor {
  8943. mds = append(mds, item)
  8944. }
  8945. }
  8946. //待医嘱核对
  8947. if pat_type == 1 {
  8948. for _, item := range monitor {
  8949. if len(item.AdviceList) > 0 {
  8950. mds = append(mds, item)
  8951. }
  8952. }
  8953. }
  8954. //待开小结
  8955. if pat_type == 2 {
  8956. for _, item := range monitor {
  8957. if item.TreatmentSummaryForList == nil {
  8958. mds = append(mds, item)
  8959. }
  8960. }
  8961. }
  8962. //待下机
  8963. if pat_type == 3 {
  8964. for _, item := range monitor {
  8965. if item.DialysisOrder != nil {
  8966. if item.DialysisOrder.ID > 0 {
  8967. mds = append(mds, item)
  8968. }
  8969. }
  8970. }
  8971. }
  8972. //待消毒
  8973. if pat_type == 4 {
  8974. for _, item := range monitor {
  8975. if item.NewDeviceInformation == nil {
  8976. mds = append(mds, item)
  8977. }
  8978. }
  8979. }
  8980. //待双人核对
  8981. if pat_type == 5 {
  8982. for _, item := range monitor {
  8983. if item.DoubleCheck == nil {
  8984. mds = append(mds, item)
  8985. }
  8986. }
  8987. }
  8988. //医嘱未执行
  8989. if pat_type == 6 {
  8990. for _, item := range monitor {
  8991. if len(item.AdviceList) > 0 {
  8992. mds = append(mds, item)
  8993. }
  8994. }
  8995. }
  8996. //患者未签名
  8997. if pat_type == 7 {
  8998. for _, item := range monitor {
  8999. if item.DialysisOrder != nil {
  9000. if item.DialysisOrder.ID > 0 {
  9001. mds = append(mds, item)
  9002. }
  9003. }
  9004. }
  9005. }
  9006. //目标超滤于实际超滤不同
  9007. if pat_type == 8 {
  9008. for _, item := range monitor {
  9009. if item.Prescription != nil && item.AssessmentAfterDislysis != nil {
  9010. if item.Prescription.TargetUltrafiltration != item.AssessmentAfterDislysis.ActualUltrafiltration {
  9011. mds = append(mds, item)
  9012. }
  9013. }
  9014. }
  9015. }
  9016. //血压少于5次
  9017. if pat_type == 9 {
  9018. for _, item := range monitor {
  9019. if len(item.MonitoringRecord) < 5 {
  9020. mds = append(mds, item)
  9021. }
  9022. }
  9023. }
  9024. if pat_type == 10 {
  9025. for _, item := range monitor {
  9026. if len(item.MonitoringRecord) == 0 {
  9027. mds = append(mds, item)
  9028. }
  9029. }
  9030. }
  9031. if pat_type == 11 {
  9032. for _, item := range monitor {
  9033. if len(item.MonitoringRecord) > 0 {
  9034. mds = append(mds, item)
  9035. }
  9036. }
  9037. }
  9038. if pat_type == 12 {
  9039. for _, item := range monitor {
  9040. if len(item.MonitoringRecord) > 0 {
  9041. mds = append(mds, item)
  9042. }
  9043. }
  9044. }
  9045. if err == nil {
  9046. c.ServeSuccessJSON(map[string]interface{}{
  9047. "monitor": mds,
  9048. "patients": patients,
  9049. })
  9050. } else {
  9051. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9052. }
  9053. }
  9054. func (c *DialysisAPIController) GetAdviceListNoExecution() {
  9055. admin_user_id, _ := c.GetInt64("admin_user_id")
  9056. timeStr := time.Now().Format("2006-01-02")
  9057. timeLayout := "2006-01-02 15:04:05"
  9058. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9059. timenow := timeStringToTime.Unix()
  9060. orgId := c.GetMobileAdminUserInfo().Org.Id
  9061. //查询当前护士的患者
  9062. orderList, _ := service.GetDialysisOrderNoExecution(admin_user_id, orgId, timenow)
  9063. var patientIds []int64
  9064. for _, item := range orderList {
  9065. patientIds = append(patientIds, item.PatientId)
  9066. }
  9067. adviceList, _ := service.GetAdviceListNoExecution(timenow, orgId, patientIds)
  9068. hisAdviceList, _ := service.GetHisAdviceListNoExecution(timenow, orgId, patientIds)
  9069. projectList, _ := service.GetProjectListNoExecution(timenow, orgId, patientIds)
  9070. //药品管理信息
  9071. _, drugStockConfig := service.FindHisConfig(orgId)
  9072. _, projectConfig := service.FindXTHisProjectByOrgId(orgId)
  9073. patientList, _ := service.GetPatientNoExecutionList(orgId, patientIds)
  9074. c.ServeSuccessJSON(map[string]interface{}{
  9075. "adviceList": adviceList,
  9076. "hisAdviceList": hisAdviceList,
  9077. "projectList": projectList,
  9078. "drugStockConfig": drugStockConfig,
  9079. "patientList": patientList,
  9080. "projectConfig": projectConfig,
  9081. })
  9082. }