dialysis_api_controller.go 383KB

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