dialysis_api_controller.go 338KB

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