dialysis_api_controller.go 353KB

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