dialysis_api_controller.go 318KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "XT_New/models"
  10. "XT_New/service"
  11. "XT_New/utils"
  12. "github.com/jinzhu/gorm"
  13. //"strings"
  14. "time"
  15. "XT_New/enums"
  16. "github.com/astaxie/beego"
  17. )
  18. type DialysisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func DialysisApiRegistRouters() {
  22. beego.Router("/api/dialysis/device", &DialysisApiController{}, "get:GetDeviceList")
  23. beego.Router("/api/dialysis/patients", &DialysisApiController{}, "get:GetDialysisWatch")
  24. beego.Router("/api/dialysis/zone", &DialysisApiController{}, "get:GetAllDeviceZone")
  25. beego.Router("/api/dialysis/info", &DialysisApiController{}, "get:GetSchedualPatientsInfo")
  26. beego.Router("/api/dialysis/advice/create", &DialysisApiController{}, "Post:CreateDoctorAdvice")
  27. beego.Router("/api/dialysis/advice/get", &DialysisApiController{}, "Get:GetDoctorAdvice")
  28. beego.Router("/api/dialysis/advice/edit", &DialysisApiController{}, "put:EditDoctorAdvice")
  29. beego.Router("/api/dialysis/monitor/create", &DialysisApiController{}, "Post:CreateMonitor")
  30. beego.Router("/api/dialysis/monitor/del", &DialysisApiController{}, "Post:DelMonitor")
  31. beego.Router("/api/dialysis/dialysisorder", &DialysisApiController{}, "Get:GetDialysisOrder")
  32. beego.Router("/api/dialysis/prescription", &DialysisApiController{}, "Post:PostPrescription")
  33. beego.Router("/api/dialysis/soulution", &DialysisApiController{}, "Post:PostSoulution")
  34. beego.Router("/api/dialysis/dobule", &DialysisApiController{}, "Post:PostDouleCheck")
  35. beego.Router("/api/dialysis/accepts", &DialysisApiController{}, "Post:PostReceiveTreatmentAsses")
  36. beego.Router("/api/dialysis/assessmentbeforedislysis", &DialysisApiController{}, "Post:PostAssessmentBeforeDislysis")
  37. beego.Router("/api/dialysis/assessmentafterdislysis", &DialysisApiController{}, "Post:PostAssessmentAfterDislysis")
  38. beego.Router("/api/dialysis/treatmentsummary", &DialysisApiController{}, "Post:PostTreatmentSummary")
  39. beego.Router("/api/dialysis/advice_remind", &DialysisApiController{}, "Get:GetLongAdvice")
  40. beego.Router("/api/dialysis/advice_remind/one", &DialysisApiController{}, "Get:GetLongAdviceOne")
  41. beego.Router("/api/dialysis/advice_remind/two", &DialysisApiController{}, "Get:GetLongAdviceTwo")
  42. beego.Router("/api/advice_remind/create", &DialysisApiController{}, "Post:CreateRemindDoctorAdvice")
  43. beego.Router("/api/solution/get", &DialysisApiController{}, "Get:GetSolution")
  44. beego.Router("/api/schedule/get", &DialysisApiController{}, "Get:GetSchedule")
  45. beego.Router("/api/today_monitor/get", &DialysisApiController{}, "Get:GetTodayMonitor")
  46. beego.Router("/api/dryweight/commit", &DialysisApiController{}, "Post:UploadDryWeight")
  47. beego.Router("/api/func_per/get", &DialysisApiController{}, "Get:GetFuncPurview")
  48. beego.Router("/api/doctoradvice/get", &DialysisApiController{}, "Get:GetLastOrNextDoctorAdvice")
  49. beego.Router("/api/dialysisgoods/get", &DialysisApiController{}, "Get:GetDialysisGoods")
  50. beego.Router("/api/goodstatistics/get", &DialysisApiController{}, "Get:GetDialysisGoodsStatistics")
  51. beego.Router("/api/queue/get", &DialysisApiController{}, "Get:GetQueueCall")
  52. beego.Router("/api/queue/update", &DialysisApiController{}, "Get:UpdateQueueCall")
  53. beego.Router("/api/get/getrolelist", &DialysisApiController{}, "Get:GetRoleList")
  54. beego.Router("/api/getinitprintdata", &DialysisApiController{}, "Get:GetInitPrintData")
  55. beego.Router("/api/schedule/getorderdoctoradvice", &DialysisApiController{}, "Get:GetOrderDoctorAdvice")
  56. beego.Router("/api/getinitprintdateone", &DialysisApiController{}, "Get:GetInitPrintDataOne")
  57. //新接口
  58. beego.Router("/api/patient/getpatientdialysissolutiongrouplist", &DialysisApiController{}, "Get:GetPatientDialysisSolutionGroupList")
  59. beego.Router("/api/patient/getdialysisadvicetemplatelist", &DialysisApiController{}, "Get:GetDialysisAdviceTemplateList")
  60. beego.Router("/api/patient/savedialysissetting", &DialysisApiController{}, "Get:SaveDialysisSetting")
  61. beego.Router("/api/patient/getdialysissetting", &DialysisApiController{}, "Get:GetDialysisSetting")
  62. beego.Router("/api/patient/getdialysisparameter", &DialysisApiController{}, "Get:GetDialysisParameterList")
  63. beego.Router("/api/patient/getdialysisgoodtotalcount", &DialysisApiController{}, "Get:GetDialysisGoodTotalCount")
  64. beego.Router("/api/patient/getdialysisadvicescheduelist", &DialysisApiController{}, "Get:GetDialysisAdviceSchedulist")
  65. beego.Router("/api/patient/getdialysisparametergoodlist", &DialysisApiController{}, "Get:GetDialysisParameterGoodList")
  66. beego.Router("/api/patient/savehisdialysis", &DialysisApiController{}, "Get:SaveHisDialysis")
  67. beego.Router("/api/patient/gethisdialysisgoodcount", &DialysisApiController{}, "Get:GetHisDialysisGoodCount")
  68. beego.Router("/api/schedule/getpatientshedule", &DialysisApiController{}, "Get:GetPatientSchedule")
  69. beego.Router("/api/patient/getscheduleprintlist", &DialysisApiController{}, "Get:GetSchedulePrintList")
  70. beego.Router("/api/patient/getsolutionlistbyorgid", &DialysisApiController{}, "Get:GetSolutionListByOrgId")
  71. beego.Router("/api/schedule/excutiondoctoradvice", &DialysisApiController{}, "Get:ExcutionDoctorAdvice")
  72. beego.Router("/api/schedule/checknewdoctoradvice", &DialysisApiController{}, "Get:CheckNewDoctorAdvice")
  73. beego.Router("/api/schedule/settlenewdoctoradvice", &DialysisApiController{}, "Get:SettleNewDoctorAdvice")
  74. beego.Router("/api/schedule/excutiondoctoradvicebyid", &DialysisApiController{}, "Get:ExcutionDoctorAdviceById")
  75. beego.Router("/api/patient/getdialysisadvicetoday", &DialysisApiController{}, "Get:GetDialysisAdviceToday")
  76. beego.Router("/api/schedule/getmobileschedulelist", &DialysisApiController{}, "Get:GetMobileScheduleList")
  77. beego.Router("/api/patient/saveinformation", &DialysisApiController{}, "Get:SaveInformation")
  78. beego.Router("/api/patient/savedialysisInformationsetting", &DialysisApiController{}, "Get:SaveDialysisInformationSetting")
  79. beego.Router("/api/patient/getdialyisinformationsetting", &DialysisApiController{}, "Get:GetDialysisInformationSetting")
  80. beego.Router("/api/patient/checkdialysisinformation", &DialysisApiController{}, "Get:CheckDialysisInformation")
  81. beego.Router("/api/dialysis/patientsflow", &DialysisApiController{}, "Get:GetDialysisPatientsFlow")
  82. beego.Router("/api/patient/getlongdialysisadvicetoday", &DialysisApiController{}, "Get:GetLongDialysisAdviceToday")
  83. beego.Router("/api/patient/getpatientlist", &DialysisApiController{}, "Get:GetPatientList")
  84. beego.Router("/api/patient/getprescriptionloglist", &DialysisApiController{}, "Get:GetPrescriptionLogList")
  85. beego.Router("/api/patient/getbeforloglist", &DialysisApiController{}, "Get:GetBeforLogList")
  86. beego.Router("/api/patient/getdocloglist", &DialysisApiController{}, "Get:GetDocLogList")
  87. beego.Router("/api/patient/getmonitorloglist", &DialysisApiController{}, "Get:GetMonitorLogList")
  88. beego.Router("/api/patient/getafterloglist", &DialysisApiController{}, "Get:GetAfterLogList")
  89. beego.Router("/api/patient/savegathersetting", &DialysisApiController{}, "Get:SaveGatherSetting")
  90. beego.Router("/api/patient/getgathersetting", &DialysisApiController{}, "Get:GetGatherSetting")
  91. beego.Router("/api/patient/getdialysisgatherlist", &DialysisApiController{}, "Get:GetDialysisGatherList")
  92. beego.Router("/api/getpatientdialysisrecordlist", &DialysisApiController{}, "Get:GetPatientDialysisRecordList")
  93. beego.Router("/api/patient/getpatientrecordlist", &DialysisApiController{}, "Get:GetPatientRecordList")
  94. beego.Router("/api/patient/getdialysistotalcount", &DialysisApiController{}, "Get:GetDialysisTotalCount")
  95. beego.Router("/api/schedule/getdialysisproject", &DialysisApiController{}, "Get:GetDialysisProject")
  96. beego.Router("/api/schedule/getpatientbefor", &DialysisApiController{}, "Get:GetPatientBefor")
  97. }
  98. func (c *DialysisApiController) GetQueueCall() {
  99. adminUserInfo := c.GetAdminUserInfo()
  100. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  101. if queueConfig.ID <= 0 {
  102. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  103. queueConfig.Qhsj = 10
  104. queueConfig.Jzdcbbcs = 3
  105. queueConfig.Jzbbsy = 1
  106. queueConfig.Jzjhyc = 0
  107. queueConfig.Sjdcbbcs = 3
  108. queueConfig.Sjbbsy = 0
  109. queueConfig.Sjjhyc = 0
  110. queueConfig.Txxqyxs = 0
  111. queueConfig.Txglsyxs = 0
  112. }
  113. c.ServeSuccessJSON(map[string]interface{}{
  114. "queue_config": queueConfig,
  115. })
  116. }
  117. func (c *DialysisApiController) UpdateQueueCall() {
  118. adminUserInfo := c.GetAdminUserInfo()
  119. queueConfig, _ := service.FindQueueCallInfo(adminUserInfo.CurrentOrgId)
  120. if queueConfig.ID <= 0 {
  121. queueConfig.OrgId = adminUserInfo.CurrentOrgId
  122. queueConfig.Qhsj = 10
  123. queueConfig.Jzdcbbcs = 3
  124. queueConfig.Jzbbsy = 1
  125. queueConfig.Jzjhyc = 0
  126. queueConfig.Sjdcbbcs = 3
  127. queueConfig.Sjbbsy = 0
  128. queueConfig.Sjjhyc = 0
  129. queueConfig.Txxqyxs = 0
  130. queueConfig.Txglsyxs = 0
  131. queueConfig.CreateTime = time.Now().Unix()
  132. queueConfig.UpdateTime = time.Now().Unix()
  133. }
  134. qhsj, _ := c.GetInt64("qhsj", 0)
  135. if qhsj > 0 {
  136. queueConfig.Qhsj = qhsj
  137. }
  138. jzdcbbcs, _ := c.GetInt64("jzdcbbcs", 0)
  139. if jzdcbbcs > 0 {
  140. queueConfig.Jzdcbbcs = jzdcbbcs
  141. }
  142. jzbbsy, _ := c.GetInt64("jzbbsy", 0)
  143. if jzbbsy > 0 {
  144. queueConfig.Jzbbsy = jzbbsy
  145. }
  146. jzjhyc, _ := c.GetInt64("jzjhyc", 0)
  147. queueConfig.Jzjhyc = jzjhyc
  148. sjdcbbcs, _ := c.GetInt64("sjdcbbcs", 0)
  149. if sjdcbbcs > 0 {
  150. queueConfig.Sjdcbbcs = sjdcbbcs
  151. }
  152. sjbbsy, _ := c.GetInt64("sjbbsy", 0)
  153. if sjbbsy > 0 {
  154. queueConfig.Sjbbsy = sjbbsy
  155. }
  156. sjjhyc, _ := c.GetInt64("sjjhyc", 0)
  157. queueConfig.Sjjhyc = sjjhyc
  158. txxqyxs, _ := c.GetInt64("txxqyxs", 0)
  159. queueConfig.Txxqyxs = txxqyxs
  160. txglsyxs, _ := c.GetInt64("txglsyxs", 0)
  161. queueConfig.Txglsyxs = txglsyxs
  162. queueConfig.UpdateTime = time.Now().Unix()
  163. service.UpDateQueueCallInfo(queueConfig)
  164. c.ServeSuccessJSON(map[string]interface{}{
  165. "queue_config": queueConfig,
  166. })
  167. }
  168. func (c *DialysisApiController) PostPrescription() {
  169. patient, _ := c.GetInt64("patient_id", 0)
  170. recordDateStr := c.GetString("record_date")
  171. if patient <= 0 {
  172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  173. return
  174. }
  175. adminUserInfo := c.GetAdminUserInfo()
  176. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  177. if patientInfo.ID == 0 {
  178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  179. return
  180. }
  181. if len(recordDateStr) == 0 {
  182. recordDateStr = time.Now().Format("2006-01-02")
  183. }
  184. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  185. if parseDateErr != nil {
  186. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  188. return
  189. }
  190. mode_id, _ := c.GetInt64("mode_id", 0)
  191. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  192. dialyzer, _ := c.GetInt64("dialyzer", 0)
  193. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  194. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  195. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  196. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  197. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  198. replacement_way, _ := c.GetInt64("replacement_way", 0)
  199. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  200. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  201. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  202. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  203. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  204. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  205. kalium, _ := c.GetFloat("kalium", 0)
  206. sodium, _ := c.GetFloat("sodium", 0)
  207. replacement_total, _ := c.GetFloat("replacement_total", 0)
  208. calcium, _ := c.GetFloat("calcium", 0)
  209. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  210. glucose, _ := c.GetFloat("glucose", 0)
  211. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  212. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  213. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  214. conductivity, _ := c.GetFloat("conductivity", 0)
  215. remark := c.GetString("remark")
  216. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  217. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  218. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  219. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  220. body_fluid, _ := c.GetInt64("body_fluid", 0)
  221. special_medicine, _ := c.GetInt64("special_medicine", 0)
  222. special_medicine_other := c.GetString("special_medicine_other")
  223. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  224. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  225. blood_access, _ := c.GetInt64("blood_access", 0)
  226. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  227. body_fluid_other := c.GetString("body_fluid_other")
  228. target_ktv, _ := c.GetFloat("target_ktv", 0)
  229. niprocart, _ := c.GetInt64("niprocart", 0)
  230. jms, _ := c.GetInt64("jms", 0)
  231. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  232. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  233. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  234. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  235. filtryzer, _ := c.GetInt64("filtryzer", 0)
  236. dialyzers, _ := c.GetInt64("dialyzers", 0)
  237. injector, _ := c.GetInt64("injector", 0)
  238. bloodlines, _ := c.GetInt64("bloodlines", 0)
  239. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  240. safe_package, _ := c.GetInt64("package", 0)
  241. a_liquid, _ := c.GetInt64("a_liquid", 0)
  242. preImpules, _ := c.GetFloat("pre_impulse", 0)
  243. fmt.Println("", preImpules)
  244. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  245. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  246. blood := c.GetString("blood")
  247. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  248. dialysis_irrigation := c.GetString("dialysis_irrigation")
  249. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  250. displace_speed := c.GetString("displace_speed")
  251. illness, _ := c.GetInt64("illness")
  252. amylaceum := c.GetString("amylaceum")
  253. single_time := c.GetString("single_time")
  254. single_water := c.GetString("single_water")
  255. replacement_flow := c.GetString("replacement_flow")
  256. plasma_separator := c.GetString("plasma_separator")
  257. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  258. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  259. oxygen_flow := c.GetString("oxygen_flow")
  260. oxygen_time := c.GetString("oxygen_time")
  261. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  262. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  263. puncture_needle := c.GetString("puncture_needle")
  264. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  265. epo := c.GetString("epo")
  266. epo_count, _ := c.GetFloat("epo_count", 0)
  267. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  268. admin_user_id, _ := c.GetInt64("admin_user_id")
  269. is_water, _ := c.GetInt64("is_water")
  270. drhy_water := c.GetString("drhy_water")
  271. dry_water_hour := c.GetString("dry_water_hour")
  272. water_machine := c.GetString("water_machine")
  273. add_amount, _ := c.GetFloat("add_amount")
  274. reduce_amount, _ := c.GetFloat("reduce_amount")
  275. dialysis_remark := c.GetString("dialysis_remark")
  276. prescribing_number, _ := c.GetFloat("prescribing_number")
  277. treatment_remark := c.GetString("treatment_remark")
  278. prescription_sodium := c.GetString("prescription_sodium")
  279. start_sodium := c.GetString("start_sodium")
  280. sodium_curve := c.GetString("sodium_curve")
  281. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  282. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  283. prescription_water, _ := c.GetFloat("prescription_water")
  284. dialysis_strainer := c.GetString("dialysis_strainer")
  285. chaptalization := c.GetString("chaptalization")
  286. washing_time := c.GetString("washing_time")
  287. warsh_count := c.GetString("warsh_count")
  288. blood_access_part_id := c.GetString("blood_access_part_id")
  289. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  290. dialyzate := c.GetString("dialyzate")
  291. first_super, _ := c.GetInt64("first_super")
  292. is_sequential, _ := c.GetInt64("is_sequential")
  293. conduct := c.GetString("conduct")
  294. sterilization_water := c.GetString("sterilization_water")
  295. five_glucose := c.GetString("five_glucose")
  296. fifty_glucose := c.GetString("fifty_glucose")
  297. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  298. calcium_gluconate := c.GetString("calcium_gluconate")
  299. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  300. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  301. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  302. new_sty := c.GetString("new_sty")
  303. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  304. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  305. //if template.TemplateId == 2 || template.TemplateId == 6 {
  306. // if appRole.UserType == 3 {
  307. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  308. // if getPermissionErr != nil {
  309. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  310. // return
  311. // } else if headNursePermission == nil {
  312. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  313. // return
  314. // }
  315. // }
  316. //}
  317. goodList, _ := service.GetMobileGoodList(adminUserInfo.CurrentOrgId)
  318. var dialysis_dialyszers_id int64
  319. var dialysis_strainer_id int64
  320. var dialysis_irrigation_id int64
  321. if len(goodList) > 0 {
  322. for _, item := range goodList {
  323. if item.SpecificationName == dialysis_dialyszers {
  324. dialysis_dialyszers_id = item.ID
  325. }
  326. if item.SpecificationName == dialysis_irrigation {
  327. dialysis_irrigation_id = item.ID
  328. }
  329. if item.SpecificationName == dialysis_strainer {
  330. dialysis_strainer_id = item.ID
  331. }
  332. }
  333. }
  334. prescription := models.DialysisPrescription{
  335. UserOrgId: adminUserInfo.CurrentOrgId,
  336. PatientId: patient,
  337. RecordDate: recordDate.Unix(),
  338. ModeId: mode_id,
  339. DialysisDuration: dialysis_duration,
  340. Dialyzer: dialyzer,
  341. ReplacementTotal: replacement_total,
  342. PerfusionApparatus: perfusion_apparatus,
  343. BloodFlowVolume: blood_flow_volume,
  344. DewaterAmount: dewater_amount,
  345. DisplaceLiqui: displace_liqui,
  346. ReplacementWay: replacement_way,
  347. Anticoagulant: anticoagulant,
  348. AnticoagulantShouji: anticoagulant_shouji,
  349. AnticoagulantWeichi: anticoagulant_weichi,
  350. AnticoagulantZongliang: anticoagulant_zongliang,
  351. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  352. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  353. Kalium: kalium,
  354. Sodium: sodium,
  355. Calcium: calcium,
  356. Bicarbonate: bicarbonate,
  357. Glucose: glucose,
  358. // DryWeight: dry_weight,
  359. DialysateFlow: dialysate_flow,
  360. DialysateTemperature: dialysate_temperature,
  361. Conductivity: conductivity,
  362. Remark: remark,
  363. Status: 1,
  364. CreatedTime: time.Now().Unix(),
  365. UpdatedTime: time.Now().Unix(),
  366. DialysisDurationMinute: dialysisDurationMinute,
  367. DialysisDurationHour: dialysisDurationHour,
  368. TargetUltrafiltration: targetUltrafiltration,
  369. DialysateFormulation: dialysateFormulation,
  370. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  371. BodyFluid: body_fluid,
  372. SpecialMedicine: special_medicine,
  373. SpecialMedicineOther: special_medicine_other,
  374. DisplaceLiquiPart: displace_liqui_part,
  375. DisplaceLiquiValue: displace_liqui_value,
  376. BloodAccess: blood_access,
  377. Ultrafiltration: ultrafiltration,
  378. BodyFluidOther: body_fluid_other,
  379. TargetKtv: target_ktv,
  380. Niprocart: niprocart,
  381. Jms: jms,
  382. FistulaNeedleSet: fistula_needle_set,
  383. FistulaNeedleSet16: fistula_needle_set_16,
  384. Hemoperfusion: hemoperfusion,
  385. DialyserSterilised: dialyser_sterilised,
  386. Filtryzer: filtryzer,
  387. Dialyzers: dialyzers,
  388. Injector: injector,
  389. Bloodlines: bloodlines,
  390. TubingHemodialysis: tubing_hemodialysis,
  391. Package: safe_package,
  392. ALiquid: a_liquid,
  393. PreImpulse: preImpules,
  394. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  395. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  396. Blood: blood,
  397. DialysisDialyszers: dialysis_dialyszers,
  398. DialysisIrrigation: dialysis_irrigation,
  399. AntioxidantCommodityName: antioxidant_commodity_name,
  400. DisplaceSpeed: displace_speed,
  401. Illness: illness,
  402. Amylaceum: amylaceum,
  403. SingleTime: single_time,
  404. SingleWater: single_water,
  405. ReplacementFlow: replacement_flow,
  406. PlasmaSeparator: plasma_separator,
  407. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  408. OxygenFlow: oxygen_flow,
  409. OxygenUptake: oxygen_uptake,
  410. OxygenTime: oxygen_time,
  411. HemodialysisPipelines: hemodialysis_pipelines,
  412. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  413. PunctureNeedle: puncture_needle,
  414. PunctureNeedleCount: puncture_needle_count,
  415. Epo: epo,
  416. EpoCount: epo_count,
  417. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  418. AdminUserId: admin_user_id,
  419. IsWater: is_water,
  420. DrhyWater: drhy_water,
  421. DryWaterHour: dry_water_hour,
  422. WaterMachine: water_machine,
  423. AddAmount: add_amount,
  424. ReduceAmount: reduce_amount,
  425. DialysisRemark: dialysis_remark,
  426. PrescribingNumber: prescribing_number,
  427. TreatmentRemark: treatment_remark,
  428. PrescriptionSodium: prescription_sodium,
  429. StartSodium: start_sodium,
  430. SodiumCurve: sodium_curve,
  431. DialysisFluidFlow: dialysis_fluid_flow,
  432. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  433. PrescriptionWater: prescription_water,
  434. DialysisStrainer: dialysis_strainer,
  435. Chaptalization: chaptalization,
  436. WarshCount: warsh_count,
  437. WashingTime: washing_time,
  438. BloodAccessPartId: blood_access_part_id,
  439. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  440. Dialyzate: dialyzate,
  441. DialysisStrainerId: dialysis_strainer_id,
  442. DialysisIrrigationId: dialysis_irrigation_id,
  443. DialysisDialyszersId: dialysis_dialyszers_id,
  444. FirstSuper: first_super,
  445. IsSequential: is_sequential,
  446. Conduct: conduct,
  447. SterilizationWater: sterilization_water,
  448. FiveGlucose: five_glucose,
  449. FiftyGlucose: fifty_glucose,
  450. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  451. CalciumGluconate: calcium_gluconate,
  452. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  453. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  454. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  455. NewSty: new_sty,
  456. }
  457. if prescription.ModeId != 13 {
  458. prescription.SterilizationWater = ""
  459. prescription.FiveGlucose = ""
  460. prescription.FiftyGlucose = ""
  461. prescription.MagnesiumSulfateInjection = ""
  462. prescription.CalciumGluconate = ""
  463. prescription.FivePotassiumChlorideInjection = ""
  464. prescription.TenPotassiumChlorideInjection = ""
  465. prescription.FiveSodiumBicarbonateInjection = ""
  466. prescription.NewSty = ""
  467. }
  468. if adminUserInfo.CurrentOrgId == 10721 {
  469. if prescription.ModeId == 2 {
  470. if prescription.ReplacementTotal == 0 {
  471. prescription.ReplacementTotal = 15
  472. }
  473. }
  474. }
  475. if adminUserInfo.CurrentOrgId == 10766 {
  476. if prescription.ModeId == 2 || prescription.ModeId == 13 {
  477. if prescription.ReplacementTotal == 0 {
  478. prescription.ReplacementTotal = 15
  479. }
  480. }
  481. }
  482. //长沙南雅医院,自动生成抗凝剂的临时处方
  483. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  484. if prescribing_number == 0 {
  485. prescribing_number = 1
  486. }
  487. advice := models.DoctorAdvice{
  488. UserOrgId: adminUserInfo.CurrentOrgId,
  489. PatientId: patient,
  490. GroupNo: 0,
  491. AdviceType: 2,
  492. RecordDate: recordDate.Unix(),
  493. AdviceDate: recordDate.Unix(),
  494. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  495. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  496. AdviceDesc: "",
  497. ReminderDate: 0,
  498. SingleDose: anticoagulant_zongliang,
  499. SingleDoseUnit: "iu",
  500. DrugSpec: 0,
  501. DrugSpecUnit: "",
  502. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  503. PrescribingNumberUnit: "支",
  504. DeliveryWay: "静脉注射",
  505. ExecutionFrequency: "上机前",
  506. AdviceDoctor: 0,
  507. Status: 1,
  508. CreatedTime: time.Now().Unix(),
  509. UpdatedTime: time.Now().Unix(),
  510. IsPrescription: 1,
  511. ExecutionState: 2,
  512. StopState: 2,
  513. IsSettle: 2,
  514. }
  515. // 查询排班信息
  516. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  517. if schedulePatient.ID > 0 {
  518. if schedulePatient.ScheduleType == 1 {
  519. advice.StartTime = recordDate.Unix() + 6.5*60*60
  520. }
  521. if schedulePatient.ScheduleType == 2 {
  522. advice.StartTime = recordDate.Unix() + 9*60*60
  523. }
  524. }
  525. // 抗凝剂名称
  526. switch anticoagulant {
  527. case 1:
  528. advice.AdviceName = "无肝素"
  529. break
  530. case 2:
  531. advice.AdviceName = "普通肝素"
  532. break
  533. case 3:
  534. advice.AdviceName = "低分子肝素"
  535. break
  536. case 4:
  537. advice.AdviceName = "阿加曲班"
  538. break
  539. case 5:
  540. advice.AdviceName = "枸橼酸钠"
  541. break
  542. case 6:
  543. advice.AdviceName = "低分子肝素钙"
  544. break
  545. case 7:
  546. advice.AdviceName = "低分子肝素钠"
  547. break
  548. case 8:
  549. advice.AdviceName = "依诺肝素"
  550. break
  551. case 9:
  552. advice.AdviceName = "达肝素"
  553. break
  554. case 10:
  555. advice.AdviceName = "体外抗凝"
  556. break
  557. case 11:
  558. advice.AdviceName = "那曲肝素"
  559. break
  560. case 12:
  561. advice.AdviceName = "无抗凝剂"
  562. break
  563. }
  564. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  565. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  566. advice.AdviceDoctor = appRole.AdminUserId
  567. }
  568. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  569. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  570. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  571. advice.AdviceName = "低分子肝素钠注射液"
  572. // 修改患者临时医嘱里的抗凝剂医嘱
  573. advice.ID = advicePrescription.ID
  574. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  575. //service.UpdateDoctorAdvice(&advice)
  576. } else {
  577. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  578. advice.AdviceName = "低分子肝素钠注射液"
  579. // 新增患者临时医嘱里的抗凝剂医嘱
  580. service.CreateDoctorAdvice(&advice)
  581. }
  582. }
  583. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  584. redis := service.RedisClient()
  585. //清空key 值
  586. redis.Set(key, "", time.Second)
  587. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  588. redis.Set(keyOne, "", time.Second)
  589. }
  590. if appRole.UserType == 2 || appRole.UserType == 1 {
  591. prescription.PrescriptionDoctor = appRole.AdminUserId
  592. }
  593. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  594. if dialysisPrescription.ID == 0 { //新增
  595. if mode_id > 0 {
  596. var str string
  597. //查找该机构用的是什么透析器
  598. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  599. if filedConfig.ID > 0 {
  600. str = dialyzerPerfusionApparatus
  601. } else {
  602. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  603. }
  604. if adminUserInfo.CurrentOrgId == 10346 {
  605. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  606. } else {
  607. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  608. }
  609. }
  610. prescription.Creater = adminUserInfo.AdminUser.Id
  611. //针对河间咸得
  612. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10766 {
  613. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 && prescription.ModeId != 13 {
  614. prescription.DisplaceLiquiPart = 0
  615. prescription.DisplaceLiquiValue = 0
  616. }
  617. }
  618. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  619. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  620. }
  621. // 查询信息规挡的设置天数
  622. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  623. if infor.ID > 0 && infor.WeekDay > 0 {
  624. var cha_time int64
  625. timeNowStr := time.Now().Format("2006-01-02")
  626. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  627. //今日的日期减去设置的日期
  628. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  629. if cha_time >= recordDate.Unix() {
  630. //查询审核是否允许
  631. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  632. //申请状态不允许的情况 拒绝修改
  633. if infor.ApplicationStatus != 1 {
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  635. return
  636. }
  637. }
  638. }
  639. err := service.AddSigleRecord(&prescription)
  640. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 9478 {
  641. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  642. if len(monitorList) > 0 {
  643. var ultrafiltration_rate float64
  644. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  645. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  646. var replacement_rate float64
  647. if adminUserInfo.CurrentOrgId == 10721 {
  648. //乘10 除10是为了保留一位小数
  649. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  650. }
  651. if adminUserInfo.CurrentOrgId == 9478 {
  652. //乘10 除10是为了保留一位小数
  653. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  654. }
  655. if adminUserInfo.CurrentOrgId == 10766 {
  656. //乘10 除10是为了保留一位小数
  657. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  658. }
  659. var firstOpeateTime = monitorList[0].OperateTime
  660. for _, item := range monitorList {
  661. //超滤率
  662. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  663. //置换率
  664. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  665. //超滤量
  666. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  667. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  668. //置换量
  669. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  670. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  671. }
  672. }
  673. }
  674. //记录日志
  675. byterequest, _ := json.Marshal(prescription)
  676. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  677. UserOrgId: adminUserInfo.CurrentOrgId,
  678. Ctime: time.Now().Unix(),
  679. Mtime: 0,
  680. ErrLog: string(byterequest),
  681. AdminUserId: adminUserInfo.AdminUser.Id,
  682. RecordDate: prescription.RecordDate,
  683. PatientId: prescription.PatientId,
  684. Source: "电脑端新建处方",
  685. Status: 1,
  686. }
  687. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  688. //创建步骤表
  689. finish := models.XtDialysisFinish{
  690. IsFinish: 1,
  691. UserOrgId: adminUserInfo.CurrentOrgId,
  692. Status: 1,
  693. Ctime: time.Now().Unix(),
  694. Mtime: 0,
  695. Module: 1,
  696. RecordDate: recordDate.Unix(),
  697. Sourse: 1,
  698. PatientId: patient,
  699. }
  700. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  701. if dialysisFinish.ID == 0 {
  702. service.CreateDialysisFinish(finish)
  703. }
  704. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  705. redis := service.RedisClient()
  706. //清空key 值
  707. redis.Set(key, "", time.Second)
  708. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  709. redis.Set(keyTwo, "", time.Second)
  710. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  711. redis.Set(keyThree, "", time.Second)
  712. defer redis.Close()
  713. if err == nil {
  714. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  715. if updateErr != nil {
  716. utils.ErrorLog("%v", updateErr)
  717. }
  718. c.ServeSuccessJSON(map[string]interface{}{
  719. "prescription": &prescription,
  720. })
  721. } else {
  722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  723. }
  724. } else { //修改
  725. if mode_id > 0 {
  726. var str string
  727. //查找该机构用的是什么透析器
  728. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  729. if filedConfig.ID > 0 {
  730. str = dialyzerPerfusionApparatus
  731. } else {
  732. str = dialysis_dialyszers + "/" + dialysis_irrigation
  733. }
  734. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  735. }
  736. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  737. //if template.TemplateId == 1 {
  738. // if dialysisPrescription.Creater > 0 && dialysisPrescription.Creater != adminUserInfo.AdminUser.Id {
  739. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  740. // if getPermissionErr != nil {
  741. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  742. // return
  743. // } else if headNursePermission == nil {
  744. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  745. // return
  746. // }
  747. // }
  748. //}
  749. if appRole.UserType == 2 || appRole.UserType == 1 {
  750. prescription_doctor := adminUserInfo.AdminUser.Id
  751. prescription.PrescriptionDoctor = prescription_doctor
  752. }
  753. if dialysisPrescription.Creater == 0 { //体重称
  754. prescription.Creater = adminUserInfo.AdminUser.Id
  755. } else {
  756. prescription.Creater = dialysisPrescription.Creater
  757. if adminUserInfo.CurrentOrgId == 9882 {
  758. if appRole.UserType == 2 || appRole.UserType == 1 {
  759. prescription_doctor := adminUserInfo.AdminUser.Id
  760. prescription.PrescriptionDoctor = prescription_doctor
  761. prescription.Creater = prescription_doctor
  762. }
  763. }
  764. }
  765. prescription.CreatedTime = dialysisPrescription.CreatedTime
  766. prescription.UpdatedTime = time.Now().Unix()
  767. prescription.Modifier = adminUserInfo.AdminUser.Id
  768. prescription.ID = dialysisPrescription.ID
  769. // 查询信息规挡的设置天数
  770. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  771. if infor.ID > 0 && infor.WeekDay > 0 {
  772. var cha_time int64
  773. timeNowStr := time.Now().Format("2006-01-02")
  774. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  775. //今日的日期减去设置的日期
  776. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  777. if cha_time >= recordDate.Unix() {
  778. //查询审核是否允许
  779. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  780. //申请状态不允许的情况 拒绝修改
  781. if infor.ApplicationStatus != 1 {
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  783. return
  784. }
  785. }
  786. }
  787. if adminUserInfo.CurrentOrgId == 10721 {
  788. if prescription.ModeId == 2 {
  789. if prescription.ReplacementTotal == 0 {
  790. prescription.ReplacementTotal = 15
  791. }
  792. }
  793. }
  794. updateErr := service.UpDateDialysisPrescription(&prescription)
  795. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 9478 {
  796. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  797. if len(monitorList) > 0 {
  798. var ultrafiltration_rate float64
  799. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  800. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  801. var replacement_rate float64
  802. if adminUserInfo.CurrentOrgId == 10721 {
  803. //乘10 除10是为了保留一位小数
  804. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  805. }
  806. if adminUserInfo.CurrentOrgId == 9478 {
  807. //乘10 除10是为了保留一位小数
  808. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  809. }
  810. if adminUserInfo.CurrentOrgId == 10766 {
  811. //乘10 除10是为了保留一位小数
  812. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  813. }
  814. var firstOpeateTime = monitorList[0].OperateTime
  815. for _, item := range monitorList {
  816. //超滤率
  817. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  818. //置换率
  819. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  820. //超滤量
  821. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  822. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  823. //置换量
  824. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  825. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  826. }
  827. }
  828. }
  829. //记录日志
  830. byterequest, _ := json.Marshal(prescription)
  831. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  832. UserOrgId: adminUserInfo.CurrentOrgId,
  833. Ctime: time.Now().Unix(),
  834. Mtime: 0,
  835. ErrLog: string(byterequest),
  836. AdminUserId: adminUserInfo.AdminUser.Id,
  837. RecordDate: prescription.RecordDate,
  838. PatientId: prescription.PatientId,
  839. Source: "电脑端修改处方",
  840. Status: 1,
  841. }
  842. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  843. //创建步骤表
  844. finish := models.XtDialysisFinish{
  845. IsFinish: 1,
  846. UserOrgId: adminUserInfo.CurrentOrgId,
  847. Status: 1,
  848. Ctime: time.Now().Unix(),
  849. Mtime: 0,
  850. Module: 1,
  851. RecordDate: recordDate.Unix(),
  852. Sourse: 1,
  853. PatientId: patient,
  854. }
  855. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  856. if dialysisFinish.ID == 0 {
  857. service.CreateDialysisFinish(finish)
  858. }
  859. //修改处方
  860. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  861. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  862. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  863. if advicePrescription.ID > 0 {
  864. service.UpdateDoctorAdvieByIdOne(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  865. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  866. redis := service.RedisClient()
  867. defer redis.Close()
  868. //清空key 值
  869. redis.Set(key, "", time.Second)
  870. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  871. redis.Set(keyOne, "", time.Second)
  872. }
  873. }
  874. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  875. redis := service.RedisClient()
  876. defer redis.Close()
  877. //清空key 值
  878. redis.Set(key, "", time.Second)
  879. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  880. redis.Set(keyOne, "", time.Second)
  881. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  882. redis.Set(keyThree, "", time.Second)
  883. if updateErr == nil {
  884. updateErr := service.UpdateScheduleModeId(patient, adminUserInfo.CurrentOrgId, recordDate.Unix(), mode_id)
  885. if updateErr != nil {
  886. utils.ErrorLog("%v", updateErr)
  887. }
  888. c.ServeSuccessJSON(map[string]interface{}{
  889. "prescription": &prescription,
  890. })
  891. } else {
  892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  893. }
  894. }
  895. }
  896. func (c *DialysisApiController) PostSoulution() {
  897. patient, _ := c.GetInt64("patient", 0)
  898. recordDateStr := c.GetString("record_date")
  899. if patient <= 0 {
  900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  901. return
  902. }
  903. adminUserInfo := c.GetAdminUserInfo()
  904. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  905. if patientInfo.ID == 0 {
  906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  907. return
  908. }
  909. if len(recordDateStr) == 0 {
  910. recordDateStr = time.Now().Format("2006-01-02")
  911. }
  912. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  913. if parseDateErr != nil {
  914. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  915. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  916. return
  917. }
  918. mode_id, _ := c.GetInt64("mode_id", 0)
  919. dialysis_duration, _ := c.GetFloat("dialysis_duration", 0)
  920. dialyzer, _ := c.GetInt64("dialyzer", 0)
  921. perfusion_apparatus, _ := c.GetInt64("perfusion_apparatus", 0)
  922. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  923. replacement_total, _ := c.GetFloat("replacement_total", 0)
  924. dialyzerPerfusionApparatus := c.GetString("dialyzer_perfusion_apparatus")
  925. dewater_amount, _ := c.GetFloat("dewater_amount", 0)
  926. displace_liqui, _ := c.GetFloat("displace_liqui", 0)
  927. replacement_way, _ := c.GetInt64("replacement_way", 0)
  928. anticoagulant, _ := c.GetInt64("anticoagulant", 0)
  929. anticoagulant_shouji, _ := c.GetFloat("anticoagulant_shouji", 0)
  930. anticoagulant_weichi, _ := c.GetFloat("anticoagulant_weichi", 0)
  931. anticoagulant_zongliang, _ := c.GetFloat("anticoagulant_zongliang", 0)
  932. anticoagulant_gaimingcheng := c.GetString("anticoagulant_gaimingcheng")
  933. anticoagulant_gaijiliang := c.GetString("anticoagulant_gaijiliang")
  934. kalium, _ := c.GetFloat("kalium", 0)
  935. sodium, _ := c.GetFloat("sodium", 0)
  936. calcium, _ := c.GetFloat("calcium", 0)
  937. bicarbonate, _ := c.GetFloat("bicarbonate", 0)
  938. glucose, _ := c.GetFloat("glucose", 0)
  939. // dry_weight, _ := c.GetFloat("dry_weight", 0)
  940. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  941. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  942. conductivity, _ := c.GetFloat("conductivity", 0)
  943. remark := c.GetString("remark")
  944. dialysisDurationHour, _ := c.GetInt64("dialysis_duration_hour", 0)
  945. dialysisDurationMinute, _ := c.GetInt64("dialysis_duration_minute", 0)
  946. targetUltrafiltration, _ := c.GetFloat("target_ultrafiltration", 0)
  947. dialysateFormulation, _ := c.GetInt64("dialysate_formulation", 0)
  948. body_fluid, _ := c.GetInt64("body_fluid", 0)
  949. special_medicine, _ := c.GetInt64("special_medicine", 0)
  950. special_medicine_other := c.GetString("special_medicine_other")
  951. displace_liqui_part, _ := c.GetInt64("displace_liqui_part", 0)
  952. displace_liqui_value, _ := c.GetFloat("displace_liqui_value", 0)
  953. blood_access, _ := c.GetInt64("blood_access", 0)
  954. ultrafiltration, _ := c.GetFloat("ultrafiltration", 0)
  955. body_fluid_other := c.GetString("body_fluid_other")
  956. target_ktv, _ := c.GetFloat("target_ktv", 0)
  957. niprocart, _ := c.GetInt64("niprocart", 0)
  958. jms, _ := c.GetInt64("jms", 0)
  959. fistula_needle_set, _ := c.GetInt64("fistula_needle_set", 0)
  960. fistula_needle_set_16, _ := c.GetInt64("fistula_needle_set_16", 0)
  961. hemoperfusion, _ := c.GetInt64("hemoperfusion", 0)
  962. dialyser_sterilised, _ := c.GetInt64("dialyser_sterilised", 0)
  963. filtryzer, _ := c.GetInt64("filtryzer", 0)
  964. dialyzers, _ := c.GetInt64("dialyzers", 0)
  965. injector, _ := c.GetInt64("injector", 0)
  966. bloodlines, _ := c.GetInt64("bloodlines", 0)
  967. tubing_hemodialysis, _ := c.GetInt64("tubing_hemodialysis", 0)
  968. safe_package, _ := c.GetInt64("package", 0)
  969. a_liquid, _ := c.GetInt64("a_liquid", 0)
  970. anticoagulant_stop_time_hour, _ := c.GetInt64("anticoagulant_stop_time_hour", 0)
  971. anticoagulant_stop_time_min, _ := c.GetInt64("anticoagulant_stop_time_min", 0)
  972. blood := c.GetString("blood")
  973. dialysis_dialyszers := c.GetString("dialysis_dialyszers")
  974. dialysis_irrigation := c.GetString("dialysis_irrigation")
  975. antioxidant_commodity_name := c.GetString("antioxidant_commodity_name")
  976. displace_speed := c.GetString("displace_speed")
  977. illness, _ := c.GetInt64("illness")
  978. amylaceum := c.GetString("amylaceum")
  979. single_time := c.GetString("single_time")
  980. single_water := c.GetString("single_water")
  981. replacement_flow := c.GetString("replacement_flow")
  982. plasma_separator := c.GetString("plasma_separator")
  983. bilirubin_adsorption_column := c.GetString("bilirubin_adsorption_column")
  984. oxygen_uptake, _ := c.GetInt64("oxygen_uptake")
  985. oxygen_flow := c.GetString("oxygen_flow")
  986. oxygen_time := c.GetString("oxygen_time")
  987. hemodialysis_pipelines := c.GetString("hemodialysis_pipelines")
  988. hemodialysis_pipelines_count, _ := c.GetFloat("hemodialysis_pipelines_count", 0)
  989. puncture_needle := c.GetString("puncture_needle")
  990. puncture_needle_count, _ := c.GetFloat("puncture_needle_count", 0)
  991. epo := c.GetString("epo")
  992. epo_count, _ := c.GetFloat("epo_count", 0)
  993. max_ultrafiltration_rate, _ := c.GetFloat("max_ultrafiltration_rate")
  994. impulse := c.GetString("impulse")
  995. preImpules, parseDateErr := strconv.ParseFloat(impulse, 64)
  996. admin_user_id, _ := c.GetInt64("admin_user_id")
  997. fmt.Println("", preImpules)
  998. is_water, _ := c.GetInt64("is_water")
  999. dry_water_hour := c.GetString("dry_water_hour")
  1000. drhy_water := c.GetString("drhy_water")
  1001. water_machine := c.GetString("water_machine")
  1002. add_amount, _ := c.GetFloat("add_amount")
  1003. reduce_amount, _ := c.GetFloat("reduce_amount")
  1004. dialysis_remark := c.GetString("dialysis_remark")
  1005. prescribing_number, _ := c.GetFloat("prescribing_number")
  1006. treatment_remark := c.GetString("treatment_remark")
  1007. prescription_sodium := c.GetString("prescription_sodium")
  1008. start_sodium := c.GetString("start_sodium")
  1009. sodium_curve := c.GetString("sodium_curve")
  1010. dialysis_fluid_flow := c.GetString("dialysis_fluid_flow")
  1011. sodium_bicarbonate_flow := c.GetString("sodium_bicarbonate_flow")
  1012. prescription_water, _ := c.GetFloat("prescription_water")
  1013. dialysis_strainer := c.GetString("dialysis_strainer")
  1014. chaptalization := c.GetString("chaptalization")
  1015. warsh_count := c.GetString("warsh_count")
  1016. washing_time := c.GetString("washing_time")
  1017. blood_access_part_id := c.GetString("blood_access_part_id")
  1018. anticoagulant_weichi_hour := c.GetString("anticoagulant_weichi_hour")
  1019. dialyzate := c.GetString("dialyzate")
  1020. first_super, _ := c.GetInt64("first_super")
  1021. is_sequential, _ := c.GetInt64("is_sequential")
  1022. conduct := c.GetString("conduct")
  1023. sterilization_water := c.GetString("sterilization_water")
  1024. five_glucose := c.GetString("five_glucose")
  1025. fifty_glucose := c.GetString("fifty_glucose")
  1026. magnesium_sulfate_injection := c.GetString("magnesium_sulfate_injection")
  1027. calcium_gluconate := c.GetString("calcium_gluconate")
  1028. five_potassium_chloride_injection := c.GetString("five_potassium_chloride_injection")
  1029. ten_potassium_chloride_injection := c.GetString("ten_potassium_chloride_injection")
  1030. five_sodium_bicarbonate_injection := c.GetString("five_sodium_bicarbonate_injection")
  1031. new_sty := c.GetString("new_sty")
  1032. var prescription_doctor int64
  1033. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1034. if appRole.UserType == 2 || appRole.UserType == 1 {
  1035. prescription_doctor = appRole.AdminUserId
  1036. }
  1037. if mode_id > 0 {
  1038. var str string
  1039. //查找该机构用的是什么透析器
  1040. filedConfig, _ := service.GetFiledConfig(adminUserInfo.CurrentOrgId)
  1041. if filedConfig.ID > 0 {
  1042. str = dialyzerPerfusionApparatus
  1043. } else {
  1044. str = dialysis_dialyszers + "/" + dialysis_irrigation + " " + dialysis_strainer
  1045. }
  1046. if adminUserInfo.CurrentOrgId == 10346 {
  1047. service.ModifyScheduleModeOne(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  1048. } else {
  1049. service.ModifyScheduleMode(mode_id, patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, str)
  1050. }
  1051. }
  1052. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1053. //
  1054. //if template.TemplateId == 2 || template.TemplateId == 6 {
  1055. // if appRole.UserType == 3 {
  1056. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1057. // if getPermissionErr != nil {
  1058. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1059. // return
  1060. // } else if headNursePermission == nil {
  1061. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1062. // return
  1063. // }
  1064. // }
  1065. //}
  1066. // 查询信息规挡的设置天数
  1067. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  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(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 1)
  1077. //申请状态不允许的情况 拒绝修改
  1078. if infor.ApplicationStatus != 1 {
  1079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1080. return
  1081. }
  1082. }
  1083. }
  1084. goodList, _ := service.GetMobileGoodList(adminUserInfo.CurrentOrgId)
  1085. var dialysis_dialyszers_id int64
  1086. var dialysis_strainer_id int64
  1087. var dialysis_irrigation_id int64
  1088. if len(goodList) > 0 {
  1089. for _, item := range goodList {
  1090. if item.SpecificationName == dialysis_dialyszers {
  1091. dialysis_dialyszers_id = item.ID
  1092. }
  1093. if item.SpecificationName == dialysis_irrigation {
  1094. dialysis_irrigation_id = item.ID
  1095. }
  1096. if item.SpecificationName == dialysis_strainer {
  1097. dialysis_strainer_id = item.ID
  1098. }
  1099. }
  1100. }
  1101. prescription := models.DialysisPrescription{
  1102. UserOrgId: adminUserInfo.CurrentOrgId,
  1103. PatientId: patient,
  1104. RecordDate: recordDate.Unix(),
  1105. ModeId: mode_id,
  1106. DialysisDuration: dialysis_duration,
  1107. Dialyzer: dialyzer,
  1108. PerfusionApparatus: perfusion_apparatus,
  1109. BloodFlowVolume: blood_flow_volume,
  1110. DewaterAmount: dewater_amount,
  1111. DisplaceLiqui: displace_liqui,
  1112. ReplacementWay: replacement_way,
  1113. Anticoagulant: anticoagulant,
  1114. AnticoagulantShouji: anticoagulant_shouji,
  1115. AnticoagulantWeichi: anticoagulant_weichi,
  1116. AnticoagulantZongliang: anticoagulant_zongliang,
  1117. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1118. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1119. Kalium: kalium,
  1120. Sodium: sodium,
  1121. Calcium: calcium,
  1122. Bicarbonate: bicarbonate,
  1123. Glucose: glucose,
  1124. // DryWeight: dry_weight,
  1125. DialysateFlow: dialysate_flow,
  1126. DialysateTemperature: dialysate_temperature,
  1127. Conductivity: conductivity,
  1128. Remark: remark,
  1129. PrescriptionDoctor: prescription_doctor,
  1130. Status: 1,
  1131. CreatedTime: time.Now().Unix(),
  1132. UpdatedTime: time.Now().Unix(),
  1133. DialysisDurationMinute: dialysisDurationMinute,
  1134. DialysisDurationHour: dialysisDurationHour,
  1135. TargetUltrafiltration: targetUltrafiltration,
  1136. DialysateFormulation: dialysateFormulation,
  1137. ReplacementTotal: replacement_total,
  1138. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1139. BodyFluid: body_fluid,
  1140. SpecialMedicine: special_medicine,
  1141. SpecialMedicineOther: special_medicine_other,
  1142. DisplaceLiquiPart: displace_liqui_part,
  1143. DisplaceLiquiValue: displace_liqui_value,
  1144. BloodAccess: blood_access,
  1145. Ultrafiltration: ultrafiltration,
  1146. BodyFluidOther: body_fluid_other,
  1147. TargetKtv: target_ktv,
  1148. Niprocart: niprocart,
  1149. Jms: jms,
  1150. FistulaNeedleSet: fistula_needle_set,
  1151. FistulaNeedleSet16: fistula_needle_set_16,
  1152. Hemoperfusion: hemoperfusion,
  1153. DialyserSterilised: dialyser_sterilised,
  1154. Filtryzer: filtryzer,
  1155. Dialyzers: dialyzers,
  1156. Injector: injector,
  1157. Bloodlines: bloodlines,
  1158. TubingHemodialysis: tubing_hemodialysis,
  1159. Package: safe_package,
  1160. ALiquid: a_liquid,
  1161. AnticoagulantStopTimeHour: anticoagulant_stop_time_hour,
  1162. AnticoagulantStopTimeMin: anticoagulant_stop_time_min,
  1163. Blood: blood,
  1164. DialysisIrrigation: dialysis_irrigation,
  1165. DialysisDialyszers: dialysis_dialyszers,
  1166. AntioxidantCommodityName: antioxidant_commodity_name,
  1167. DisplaceSpeed: displace_speed,
  1168. Illness: illness,
  1169. Amylaceum: amylaceum,
  1170. SingleTime: single_time,
  1171. SingleWater: single_water,
  1172. ReplacementFlow: replacement_flow,
  1173. PlasmaSeparator: plasma_separator,
  1174. BilirubinAdsorptionColumn: bilirubin_adsorption_column,
  1175. OxygenTime: oxygen_time,
  1176. OxygenUptake: oxygen_uptake,
  1177. OxygenFlow: oxygen_flow,
  1178. HemodialysisPipelines: hemodialysis_pipelines,
  1179. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1180. PunctureNeedle: puncture_needle,
  1181. PunctureNeedleCount: puncture_needle_count,
  1182. Epo: epo,
  1183. EpoCount: epo_count,
  1184. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1185. PreImpulse: preImpules,
  1186. AdminUserId: admin_user_id,
  1187. IsWater: is_water,
  1188. DryWaterHour: dry_water_hour,
  1189. DrhyWater: drhy_water,
  1190. WaterMachine: water_machine,
  1191. AddAmount: add_amount,
  1192. ReduceAmount: reduce_amount,
  1193. DialysisRemark: dialysis_remark,
  1194. PrescribingNumber: prescribing_number,
  1195. StartSodium: start_sodium,
  1196. PrescriptionSodium: prescription_sodium,
  1197. SodiumCurve: sodium_curve,
  1198. TreatmentRemark: treatment_remark,
  1199. DialysisFluidFlow: dialysis_fluid_flow,
  1200. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1201. PrescriptionWater: prescription_water,
  1202. DialysisStrainer: dialysis_strainer,
  1203. Chaptalization: chaptalization,
  1204. WarshCount: warsh_count,
  1205. WashingTime: washing_time,
  1206. BloodAccessPartId: blood_access_part_id,
  1207. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1208. Dialyzate: dialyzate,
  1209. DialysisDialyszersId: dialysis_dialyszers_id,
  1210. DialysisIrrigationId: dialysis_irrigation_id,
  1211. DialysisStrainerId: dialysis_strainer_id,
  1212. FirstSuper: first_super,
  1213. IsSequential: is_sequential,
  1214. Conduct: conduct,
  1215. SterilizationWater: sterilization_water,
  1216. FiveGlucose: five_glucose,
  1217. FiftyGlucose: fifty_glucose,
  1218. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  1219. CalciumGluconate: calcium_gluconate,
  1220. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  1221. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  1222. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  1223. NewSty: new_sty,
  1224. }
  1225. if prescription.ModeId != 13 {
  1226. prescription.SterilizationWater = ""
  1227. prescription.FiveGlucose = ""
  1228. prescription.FiftyGlucose = ""
  1229. prescription.MagnesiumSulfateInjection = ""
  1230. prescription.CalciumGluconate = ""
  1231. prescription.FivePotassiumChlorideInjection = ""
  1232. prescription.TenPotassiumChlorideInjection = ""
  1233. prescription.FiveSodiumBicarbonateInjection = ""
  1234. prescription.NewSty = ""
  1235. }
  1236. if prescription.Anticoagulant == 0 {
  1237. prescription.Anticoagulant = 3
  1238. }
  1239. //查询最近透析准备表里是否存在 透析器 灌流器
  1240. //splitStr := strings.Split(dialysis_dialyszers, ",")
  1241. //
  1242. //splitIrrigation := strings.Split(dialysis_irrigation, ",")
  1243. //
  1244. //mation, _ := service.GetGoodInfoMation(adminUserInfo.CurrentOrgId)
  1245. //if len(mation)>0{
  1246. // for _, item := range splitStr {
  1247. // for _,it := range mation{
  1248. // if(item == it.SpecificationName){
  1249. //
  1250. // //查询最近一次的透析器
  1251. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  1252. //
  1253. // if errcode == gorm.ErrRecordNotFound{
  1254. // //插入数据
  1255. // prepare := models.DialysisBeforePrepare{
  1256. // UserOrgId: adminUserInfo.CurrentOrgId,
  1257. // PatientId: patient,
  1258. // RecordDate: recordDate.Unix(),
  1259. // GoodTypeId: it.GoodTypeId,
  1260. // GoodId: it.ID,
  1261. // Count: 1,
  1262. // Ctime: time.Now().Unix(),
  1263. // Creater: adminUserInfo.AdminUser.Id,
  1264. // Status:1,
  1265. //
  1266. // }
  1267. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1268. // fmt.Println("",errcode)
  1269. // }
  1270. // }
  1271. // }
  1272. //
  1273. // }
  1274. //
  1275. // for _, item := range splitIrrigation {
  1276. // for _,it := range mation{
  1277. // if(item == it.SpecificationName){
  1278. // //查询最近一次的透析器
  1279. // _, errcode := service.GetDialysisBeforePrepare(it.GoodTypeId, it.ID, adminUserInfo.CurrentOrgId,patient)
  1280. // if errcode == gorm.ErrRecordNotFound{
  1281. // //插入数据
  1282. // prepare := models.DialysisBeforePrepare{
  1283. // UserOrgId: adminUserInfo.CurrentOrgId,
  1284. // PatientId: patient,
  1285. // RecordDate: recordDate.Unix(),
  1286. // GoodTypeId: it.GoodTypeId,
  1287. // GoodId: it.ID,
  1288. // Count: 1,
  1289. // Ctime: time.Now().Unix(),
  1290. // Creater: adminUserInfo.AdminUser.Id,
  1291. // Status:1,
  1292. //
  1293. // }
  1294. // errcode := service.CreateDialysisBeforePrepareOne(&prepare)
  1295. // fmt.Println(errcode)
  1296. // }
  1297. // }
  1298. // }
  1299. // }
  1300. //}
  1301. //创建步骤表
  1302. finish := models.XtDialysisFinish{
  1303. IsFinish: 1,
  1304. UserOrgId: adminUserInfo.CurrentOrgId,
  1305. Status: 1,
  1306. Ctime: time.Now().Unix(),
  1307. Mtime: 0,
  1308. Module: 1,
  1309. RecordDate: recordDate.Unix(),
  1310. Sourse: 1,
  1311. PatientId: patient,
  1312. }
  1313. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1314. if dialysisFinish.ID == 0 {
  1315. service.CreateDialysisFinish(finish)
  1316. }
  1317. _, dialysisPrescription := service.FindDialysisPrescriptionByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1318. if dialysisPrescription.ID == 0 { //新增
  1319. if appRole.UserType == 2 || appRole.UserType == 1 {
  1320. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1321. }
  1322. prescription.Creater = adminUserInfo.AdminUser.Id
  1323. } else { //修改
  1324. //template, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  1325. //if template.TemplateId == 1 {
  1326. // if dialysisPrescription.Creater != adminUserInfo.AdminUser.Id && dialysisPrescription.Creater != 0 {
  1327. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1328. // if getPermissionErr != nil {
  1329. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1330. // return
  1331. // } else if headNursePermission == nil {
  1332. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1333. // return
  1334. // }
  1335. // }
  1336. //}
  1337. if appRole.UserType == 2 || appRole.UserType == 1 {
  1338. prescription_doctor := adminUserInfo.AdminUser.Id
  1339. prescription.PrescriptionDoctor = prescription_doctor
  1340. } else {
  1341. prescription.PrescriptionDoctor = dialysisPrescription.PrescriptionDoctor
  1342. }
  1343. if dialysisPrescription.Creater == 0 {
  1344. prescription.Creater = adminUserInfo.AdminUser.Id
  1345. } else {
  1346. prescription.Creater = dialysisPrescription.Creater
  1347. if appRole.UserType == 2 || appRole.UserType == 1 {
  1348. prescription.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1349. prescription.Creater = adminUserInfo.AdminUser.Id
  1350. }
  1351. }
  1352. prescription.CreatedTime = dialysisPrescription.CreatedTime
  1353. prescription.UpdatedTime = time.Now().Unix()
  1354. prescription.Modifier = adminUserInfo.AdminUser.Id
  1355. prescription.ID = dialysisPrescription.ID
  1356. }
  1357. solution := models.DialysisSolution{
  1358. RegistrarsId: adminUserInfo.AdminUser.Id,
  1359. UserOrgId: adminUserInfo.CurrentOrgId,
  1360. Doctor: prescription_doctor,
  1361. PatientId: patient,
  1362. ModeId: mode_id,
  1363. DialysisDuration: dialysis_duration,
  1364. PerfusionApparatus: perfusion_apparatus,
  1365. BloodFlowVolume: blood_flow_volume,
  1366. Dewater: dewater_amount,
  1367. DisplaceLiqui: displace_liqui,
  1368. ReplacementWay: replacement_way,
  1369. Anticoagulant: anticoagulant,
  1370. AnticoagulantShouji: anticoagulant_shouji,
  1371. AnticoagulantWeichi: anticoagulant_weichi,
  1372. AnticoagulantZongliang: anticoagulant_zongliang,
  1373. AnticoagulantGaimingcheng: anticoagulant_gaimingcheng,
  1374. AnticoagulantGaijiliang: anticoagulant_gaijiliang,
  1375. Kalium: kalium,
  1376. Sodium: sodium,
  1377. Calcium: calcium,
  1378. Bicarbonate: bicarbonate,
  1379. Glucose: glucose,
  1380. // DryWeight: dry_weight,
  1381. DialysateFlow: dialysate_flow,
  1382. DialysateTemperature: dialysate_temperature,
  1383. Conductivity: conductivity,
  1384. Remark: remark,
  1385. Status: 1,
  1386. CreatedTime: time.Now().Unix(),
  1387. UpdatedTime: time.Now().Unix(),
  1388. DialysisDurationMinute: dialysisDurationMinute,
  1389. DialysisDurationHour: dialysisDurationHour,
  1390. TargetUltrafiltration: targetUltrafiltration,
  1391. DialysateFormulation: dialysateFormulation,
  1392. DialyzerPerfusionApparatus: dialyzerPerfusionApparatus,
  1393. BodyFluid: body_fluid,
  1394. SpecialMedicine: special_medicine,
  1395. SpecialMedicineOther: special_medicine_other,
  1396. DisplaceLiquiPart: displace_liqui_part,
  1397. DisplaceLiquiValue: displace_liqui_value,
  1398. BloodAccess: blood_access,
  1399. Ultrafiltration: ultrafiltration,
  1400. BodyFluidOther: body_fluid_other,
  1401. ReplacementTotal: replacement_total,
  1402. TargetKtv: target_ktv,
  1403. DialysisIrrigation: dialysis_irrigation,
  1404. DialysisDialyszers: dialysis_dialyszers,
  1405. HemodialysisPipelines: hemodialysis_pipelines,
  1406. HemodialysisPipelinesCount: hemodialysis_pipelines_count,
  1407. PunctureNeedle: puncture_needle,
  1408. PunctureNeedleCount: puncture_needle_count,
  1409. Epo: epo,
  1410. EpoCount: epo_count,
  1411. MaxUltrafiltrationRate: max_ultrafiltration_rate,
  1412. OxygenUptake: oxygen_uptake,
  1413. OxygenFlow: oxygen_flow,
  1414. OxygenTime: oxygen_time,
  1415. PreImpulse: preImpules,
  1416. SolutionStatus: 1,
  1417. DialysisRemark: dialysis_remark,
  1418. PrescribingNumber: prescribing_number,
  1419. StartSodium: start_sodium,
  1420. PrescriptionSodium: prescription_sodium,
  1421. SodiumCurve: sodium_curve,
  1422. TreatmentRemark: treatment_remark,
  1423. DialysisFluidFlow: dialysis_fluid_flow,
  1424. SodiumBicarbonateFlow: sodium_bicarbonate_flow,
  1425. PrescriptionWater: prescribing_number,
  1426. DialysisStrainer: dialysis_strainer,
  1427. Chaptalization: chaptalization,
  1428. WarshCount: warsh_count,
  1429. WashingTime: washing_time,
  1430. BloodAccessPartId: blood_access_part_id,
  1431. AnticoagulantWeichiHour: anticoagulant_weichi_hour,
  1432. Dialyzate: dialyzate,
  1433. DialysisDialyszersId: dialysis_dialyszers_id,
  1434. DialysisIrrigationId: dialysis_irrigation_id,
  1435. DialysisStrainerId: dialysis_strainer_id,
  1436. FirstSuper: first_super,
  1437. IsSequential: is_sequential,
  1438. Conduct: conduct,
  1439. SterilizationWater: sterilization_water,
  1440. FiveGlucose: five_glucose,
  1441. FiftyGlucose: fifty_glucose,
  1442. MagnesiumSulfateInjection: magnesium_sulfate_injection,
  1443. CalciumGluconate: calcium_gluconate,
  1444. FivePotassiumChlorideInjection: five_potassium_chloride_injection,
  1445. TenPotassiumChlorideInjection: ten_potassium_chloride_injection,
  1446. FiveSodiumBicarbonateInjection: five_sodium_bicarbonate_injection,
  1447. NewSty: new_sty,
  1448. }
  1449. if solution.ModeId != 13 {
  1450. solution.SterilizationWater = ""
  1451. solution.FiveGlucose = ""
  1452. solution.FiftyGlucose = ""
  1453. solution.MagnesiumSulfateInjection = ""
  1454. solution.CalciumGluconate = ""
  1455. solution.FivePotassiumChlorideInjection = ""
  1456. solution.TenPotassiumChlorideInjection = ""
  1457. solution.FiveSodiumBicarbonateInjection = ""
  1458. solution.NewSty = ""
  1459. }
  1460. if solution.Anticoagulant == 0 {
  1461. solution.Anticoagulant = 3
  1462. }
  1463. //针对河间咸得
  1464. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 {
  1465. if prescription.ModeId != 2 && prescription.ModeId != 5 && prescription.ModeId != 12 {
  1466. prescription.DisplaceLiquiPart = 0
  1467. prescription.DisplaceLiquiValue = 0
  1468. }
  1469. }
  1470. if adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10090 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10766 {
  1471. if solution.ModeId != 2 && solution.ModeId != 5 && solution.ModeId != 12 && solution.ModeId != 13 {
  1472. solution.DisplaceLiquiPart = 0
  1473. solution.DisplaceLiquiValue = 0
  1474. }
  1475. }
  1476. if adminUserInfo.CurrentOrgId == 10340 && prescription.AdminUserId == 0 {
  1477. prescription.AdminUserId = adminUserInfo.AdminUser.Id
  1478. }
  1479. if adminUserInfo.CurrentOrgId == 10721 {
  1480. if prescription.ModeId == 2 {
  1481. if prescription.ReplacementTotal == 0 {
  1482. prescription.ReplacementTotal = 15
  1483. }
  1484. }
  1485. }
  1486. err := service.SavePrescriptionAndCreateSolution(&solution, &prescription)
  1487. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 9478 {
  1488. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  1489. if len(monitorList) > 0 {
  1490. var ultrafiltration_rate float64
  1491. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  1492. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  1493. var replacement_rate float64
  1494. if adminUserInfo.CurrentOrgId == 10721 {
  1495. //乘10 除10是为了保留一位小数
  1496. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  1497. }
  1498. if adminUserInfo.CurrentOrgId == 9478 {
  1499. //乘10 除10是为了保留一位小数
  1500. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  1501. }
  1502. if adminUserInfo.CurrentOrgId == 10766 {
  1503. //乘10 除10是为了保留一位小数
  1504. replacement_rate = math.Floor(prescription.DisplaceLiquiValue*1000/float64(totalMin)*10) / 10
  1505. }
  1506. var firstOpeateTime = monitorList[0].OperateTime
  1507. for _, item := range monitorList {
  1508. //超滤率
  1509. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  1510. //置换率
  1511. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  1512. //超滤量
  1513. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  1514. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  1515. //置换量
  1516. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  1517. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  1518. }
  1519. }
  1520. }
  1521. //记录日志
  1522. byterequest, _ := json.Marshal(prescription)
  1523. dialysisPrescriptionLog := models.XtDialysisPrescriptionLog{
  1524. UserOrgId: adminUserInfo.CurrentOrgId,
  1525. Ctime: time.Now().Unix(),
  1526. Mtime: 0,
  1527. ErrLog: string(byterequest),
  1528. AdminUserId: adminUserInfo.AdminUser.Id,
  1529. RecordDate: prescription.RecordDate,
  1530. PatientId: prescription.PatientId,
  1531. Source: "电脑端新增长期处方",
  1532. Status: 1,
  1533. }
  1534. service.CreatePrescriptionLog(dialysisPrescriptionLog)
  1535. //创建步骤表
  1536. finishOne := models.XtDialysisFinish{
  1537. IsFinish: 1,
  1538. UserOrgId: adminUserInfo.CurrentOrgId,
  1539. Status: 1,
  1540. Ctime: time.Now().Unix(),
  1541. Mtime: 0,
  1542. Module: 1,
  1543. RecordDate: recordDate.Unix(),
  1544. Sourse: 1,
  1545. PatientId: patient,
  1546. }
  1547. dialysisFinishOne, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 1, patient)
  1548. if dialysisFinishOne.ID == 0 {
  1549. service.CreateDialysisFinish(finishOne)
  1550. }
  1551. //获取最新1条
  1552. dialysisSolution, _ := service.GetLastPatientDialysisSolution(patient, adminUserInfo.CurrentOrgId)
  1553. //更新状态
  1554. service.UpdateDialysisSolutionStatusTwo(dialysisSolution.ID, dialysisSolution.ModeId, dialysisSolution.UserOrgId, dialysisSolution.PatientId)
  1555. //长沙南雅医院,自动生成抗凝剂的临时处方
  1556. if adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 10340 {
  1557. if prescribing_number == 0 {
  1558. prescribing_number = 1
  1559. }
  1560. advice := models.DoctorAdvice{
  1561. UserOrgId: adminUserInfo.CurrentOrgId,
  1562. PatientId: patient,
  1563. GroupNo: 0,
  1564. AdviceType: 2,
  1565. RecordDate: recordDate.Unix(),
  1566. AdviceDate: recordDate.Unix(),
  1567. StartTime: recordDate.Unix() + 6.5*60*60, // 根据排班班次,给默认时间
  1568. AdviceName: "", // 根据抗凝剂转换为中文 + 首剂 + 维持 + 总量
  1569. AdviceDesc: "",
  1570. ReminderDate: 0,
  1571. SingleDose: anticoagulant_zongliang,
  1572. SingleDoseUnit: "iu",
  1573. DrugSpec: 0,
  1574. DrugSpecUnit: "",
  1575. PrescribingNumber: prescribing_number, // 前端传过来的开药数量
  1576. PrescribingNumberUnit: "支",
  1577. DeliveryWay: "静脉注射",
  1578. ExecutionFrequency: "上机前",
  1579. AdviceDoctor: 0,
  1580. Status: 1,
  1581. CreatedTime: time.Now().Unix(),
  1582. UpdatedTime: time.Now().Unix(),
  1583. IsPrescription: 1,
  1584. ExecutionState: 2,
  1585. StopState: 2,
  1586. IsSettle: 2,
  1587. }
  1588. // 查询排班信息
  1589. schedulePatient, _ := service.GetScheduleByPatient(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1590. if schedulePatient.ID > 0 {
  1591. if schedulePatient.ScheduleType == 1 {
  1592. advice.StartTime = recordDate.Unix() + 6.5*60*60
  1593. }
  1594. if schedulePatient.ScheduleType == 2 {
  1595. advice.StartTime = recordDate.Unix() + 9*60*60
  1596. }
  1597. }
  1598. // 抗凝剂名称
  1599. switch anticoagulant {
  1600. case 1:
  1601. advice.AdviceName = "无肝素"
  1602. break
  1603. case 2:
  1604. advice.AdviceName = "普通肝素"
  1605. break
  1606. case 3:
  1607. advice.AdviceName = "低分子肝素"
  1608. break
  1609. case 4:
  1610. advice.AdviceName = "阿加曲班"
  1611. break
  1612. case 5:
  1613. advice.AdviceName = "枸橼酸钠"
  1614. break
  1615. case 6:
  1616. advice.AdviceName = "低分子肝素钙"
  1617. break
  1618. case 7:
  1619. advice.AdviceName = "低分子肝素钠"
  1620. break
  1621. case 8:
  1622. advice.AdviceName = "依诺肝素"
  1623. break
  1624. case 9:
  1625. advice.AdviceName = "达肝素"
  1626. break
  1627. case 10:
  1628. advice.AdviceName = "体外抗凝"
  1629. break
  1630. case 11:
  1631. advice.AdviceName = "那曲肝素"
  1632. break
  1633. case 12:
  1634. advice.AdviceName = "无抗凝剂"
  1635. break
  1636. }
  1637. //advice.AdviceDesc = "首剂" + strconv.FormatFloat(anticoagulant_shouji, 'f', -1, 64) + "维持" + strconv.FormatFloat(anticoagulant_weichi, 'f', -1, 64) + "总量" + strconv.FormatFloat(anticoagulant_zongliang, 'f', -1, 64)
  1638. if appRole.UserType == 2 || appRole.UserType == 1 || appRole.UserType == 3 {
  1639. advice.AdviceDoctor = appRole.AdminUserId
  1640. }
  1641. // 患者的临时医嘱里查找是否有抗凝剂临时医嘱
  1642. advicePrescription, _ := service.GetAdvicesByPrescription(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1643. if advicePrescription.ID > 0 && (anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7) {
  1644. advice.AdviceName = "低分子肝素钠注射液"
  1645. // 修改患者临时医嘱里的抗凝剂医嘱
  1646. advice.ID = advicePrescription.ID
  1647. service.UpdateDoctorAdviceById(advicePrescription.ID, prescribing_number, anticoagulant_zongliang)
  1648. } else {
  1649. // 新增患者临时医嘱里的抗凝剂医嘱
  1650. if anticoagulant == 3 || anticoagulant == 6 || anticoagulant == 7 {
  1651. advice.AdviceName = "低分子肝素钠注射液"
  1652. service.CreateDoctorAdvice(&advice)
  1653. }
  1654. }
  1655. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":doctor_advices"
  1656. redis := service.RedisClient()
  1657. //清空key 值
  1658. redis.Set(key, "", time.Second)
  1659. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":advice_list_all"
  1660. redis.Set(keyOne, "", time.Second)
  1661. }
  1662. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_solution"
  1663. redis := service.RedisClient()
  1664. //清空key 值
  1665. redis.Set(key, "", time.Second)
  1666. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1667. //清空key 值
  1668. redis.Set(keyOne, "", time.Second)
  1669. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1670. redis.Set(keyTwo, "", time.Second)
  1671. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1672. redis.Set(keyThree, "", time.Second)
  1673. defer redis.Close()
  1674. if err == nil {
  1675. c.ServeSuccessJSON(map[string]interface{}{
  1676. "solution": &solution,
  1677. "prescription": &prescription,
  1678. })
  1679. } else {
  1680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1681. }
  1682. }
  1683. func (c *DialysisApiController) PostDouleCheck() {
  1684. id, _ := c.GetInt64("patient", 0)
  1685. recordDateStr := c.GetString("record_date")
  1686. checkTimeStr := c.GetString("check_time")
  1687. firstCheckTimeStr := c.GetString("first_check_time")
  1688. creater, _ := c.GetInt64("creater", 0)
  1689. modifier, _ := c.GetInt64("modifier", 0)
  1690. dialysis_item_check, _ := c.GetInt64("dialysis_item_check", 0)
  1691. dialysis_parameter_check, _ := c.GetInt64("dialysis_parameter_check", 0)
  1692. vascular_access_verification, _ := c.GetInt64("vascular_access_verification", 0)
  1693. pipeline_connection_check, _ := c.GetInt64("pipeline_connection_check", 0)
  1694. dialysis_item_desc := c.GetString("dialysis_item_desc")
  1695. dialysis_parameter_desc := c.GetString("dialysis_parameter_desc")
  1696. vascular_access_desc := c.GetString("vascular_access_desc")
  1697. pipeline_connection_desc := c.GetString("pipeline_connection_desc")
  1698. collator, _ := c.GetInt64("collator", 0)
  1699. employee_number := c.GetString("employee_number")
  1700. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1701. needle_batch_number := c.GetString("needle_batch_number")
  1702. if id <= 0 {
  1703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1704. return
  1705. }
  1706. adminUserInfo := c.GetAdminUserInfo()
  1707. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1708. if patient.ID == 0 {
  1709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1710. return
  1711. }
  1712. if len(recordDateStr) == 0 {
  1713. recordDateStr = time.Now().Format("2006-01-02")
  1714. }
  1715. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1716. if parseDateErr != nil {
  1717. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1719. return
  1720. }
  1721. var checkDate int64
  1722. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1723. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1724. if employee_number != list.JobNumber {
  1725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1726. return
  1727. }
  1728. }
  1729. if len(checkTimeStr) == 0 {
  1730. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1731. checkDate = 0
  1732. } else {
  1733. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1734. checkDate = checkDateUnix.Unix()
  1735. }
  1736. var firstCheckTimeDate int64
  1737. if len(firstCheckTimeStr) == 0 {
  1738. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1739. firstCheckTimeDate = 0
  1740. } else {
  1741. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1742. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1743. }
  1744. doubleCheck := models.DoubleCheck{
  1745. UserOrgId: adminUserInfo.CurrentOrgId,
  1746. PatientId: id,
  1747. DialysisItemCheck: dialysis_item_check,
  1748. DialysisParameterCheck: dialysis_parameter_check,
  1749. VascularAccessVerification: vascular_access_verification,
  1750. PipelineConnectionCheck: pipeline_connection_check,
  1751. DialysisItemDesc: dialysis_item_desc,
  1752. DialysisParameterDesc: dialysis_parameter_desc,
  1753. VascularAccessDesc: vascular_access_desc,
  1754. PipelineConnectionDesc: pipeline_connection_desc,
  1755. Collator: collator,
  1756. Status: 1,
  1757. CreatedTime: time.Now().Unix(),
  1758. UpdatedTime: time.Now().Unix(),
  1759. CheckDate: recordDate.Unix(),
  1760. EmployeeNumber: employee_number,
  1761. DialyzerBatchNumber: dialyzer_batch_number,
  1762. NeedleBatchNumber: needle_batch_number,
  1763. }
  1764. // 查询信息规挡的设置天数
  1765. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1766. if infor.ID > 0 && infor.WeekDay > 0 {
  1767. var cha_time int64
  1768. timeNowStr := time.Now().Format("2006-01-02")
  1769. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1770. //今日的日期减去设置的日期
  1771. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1772. if cha_time >= recordDate.Unix() {
  1773. //查询审核是否允许
  1774. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 5)
  1775. //申请状态不允许的情况 拒绝修改
  1776. if infor.ApplicationStatus != 1 {
  1777. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1778. return
  1779. }
  1780. }
  1781. }
  1782. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1783. if check.ID == 0 { //新增
  1784. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1785. doubleCheck.CheckTime = checkDate
  1786. doubleCheck.Creater = creater
  1787. doubleCheck.Modifier = modifier
  1788. err := service.AddSigleDoubleCheck(&doubleCheck)
  1789. //创建步骤表
  1790. finish := models.XtDialysisFinish{
  1791. IsFinish: 1,
  1792. UserOrgId: adminUserInfo.CurrentOrgId,
  1793. Status: 1,
  1794. Ctime: time.Now().Unix(),
  1795. Mtime: 0,
  1796. Module: 5,
  1797. RecordDate: recordDate.Unix(),
  1798. Sourse: 1,
  1799. PatientId: id,
  1800. }
  1801. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 5, id)
  1802. if dialysisFinish.ID == 0 {
  1803. service.CreateDialysisFinish(finish)
  1804. }
  1805. // 查询信息规挡的设置天数
  1806. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1807. if infor.ID > 0 {
  1808. var cha_time int64
  1809. timeNowStr := time.Now().Format("2006-01-02")
  1810. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1811. //今日的日期减去设置的日期
  1812. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1813. if cha_time >= recordDate.Unix() {
  1814. //查询审核是否允许
  1815. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 5)
  1816. //申请状态不允许的情况 拒绝修改
  1817. if infor.ApplicationStatus != 1 {
  1818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1819. return
  1820. }
  1821. }
  1822. }
  1823. //针对溪康
  1824. if adminUserInfo.CurrentOrgId == 10721 {
  1825. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1826. if len(adviceInfoList) > 0 {
  1827. for _, item := range adviceInfoList {
  1828. service.UpdateHisAdviceList(item.ID, creater)
  1829. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1830. redis := service.RedisClient()
  1831. //清空key 值
  1832. redis.Set(key, "", time.Second)
  1833. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1834. redis.Set(keyTwo, "", time.Second)
  1835. theTime := time.Now()
  1836. recordDate := theTime.Format("2006-01-02")
  1837. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1838. redis.Set(keyFour, "", time.Second)
  1839. defer redis.Close()
  1840. }
  1841. }
  1842. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1843. if len(adviceList) > 0 {
  1844. for _, item := range adviceList {
  1845. service.UpdateAdviceList(item.ID, creater)
  1846. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1847. redis := service.RedisClient()
  1848. //清空key 值
  1849. redis.Set(key, "", time.Second)
  1850. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1851. redis.Set(keyTwo, "", time.Second)
  1852. theTime := time.Now()
  1853. recordDate := theTime.Format("2006-01-02")
  1854. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1855. redis.Set(keyFour, "", time.Second)
  1856. defer redis.Close()
  1857. }
  1858. }
  1859. }
  1860. redis := service.RedisClient()
  1861. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1862. //清空key 值
  1863. redis.Set(key, "", time.Second)
  1864. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1865. redis.Set(keyTwo, "", time.Second)
  1866. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1867. redis.Set(keyThree, "", time.Second)
  1868. defer redis.Close()
  1869. if err == nil {
  1870. c.ServeSuccessJSON(map[string]interface{}{
  1871. "doubleCheck": doubleCheck,
  1872. })
  1873. } else {
  1874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1875. }
  1876. } else { //修改
  1877. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1878. doubleCheck.CheckTime = checkDate
  1879. doubleCheck.Creater = creater
  1880. doubleCheck.Modifier = modifier
  1881. doubleCheck.CreatedTime = check.CreatedTime
  1882. doubleCheck.UpdatedTime = time.Now().Unix()
  1883. doubleCheck.ID = check.ID
  1884. redis := service.RedisClient()
  1885. err := service.UpdateDoubleCheck(&doubleCheck)
  1886. //针对溪康
  1887. if adminUserInfo.CurrentOrgId == 10721 {
  1888. adviceInfoList, _ := service.GetHisDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1889. if len(adviceInfoList) > 0 {
  1890. for _, item := range adviceInfoList {
  1891. service.UpdateHisAdviceList(item.ID, creater)
  1892. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1893. redis := service.RedisClient()
  1894. //清空key 值
  1895. redis.Set(key, "", time.Second)
  1896. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1897. redis.Set(keyTwo, "", time.Second)
  1898. theTime := time.Now()
  1899. recordDate := theTime.Format("2006-01-02")
  1900. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1901. redis.Set(keyFour, "", time.Second)
  1902. defer redis.Close()
  1903. }
  1904. }
  1905. adviceList, _ := service.GetMobileDoctorAdviceList(adminUserInfo.CurrentOrgId, id, recordDate.Unix())
  1906. if len(adviceList) > 0 {
  1907. for _, item := range adviceList {
  1908. service.UpdateAdviceList(item.ID, creater)
  1909. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  1910. redis := service.RedisClient()
  1911. //清空key 值
  1912. redis.Set(key, "", time.Second)
  1913. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  1914. redis.Set(keyTwo, "", time.Second)
  1915. theTime := time.Now()
  1916. recordDate := theTime.Format("2006-01-02")
  1917. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1918. redis.Set(keyFour, "", time.Second)
  1919. defer redis.Close()
  1920. }
  1921. }
  1922. }
  1923. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1924. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1925. redis.Set(keyTwo, "", time.Second)
  1926. //清空key 值
  1927. redis.Set(key, "", time.Second)
  1928. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1929. redis.Set(keyThree, "", time.Second)
  1930. defer redis.Close()
  1931. if err == nil {
  1932. c.ServeSuccessJSON(map[string]interface{}{
  1933. "doubleCheck": doubleCheck,
  1934. })
  1935. } else {
  1936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1937. }
  1938. }
  1939. }
  1940. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1941. id, _ := c.GetInt64("patient", 0)
  1942. recordDateStr := c.GetString("record_date")
  1943. way, _ := c.GetInt64("way", 0)
  1944. consciousness, _ := c.GetInt64("consciousness", 0)
  1945. appetite, _ := c.GetInt64("appetite", 0)
  1946. condition, _ := c.GetInt64("condition", 0)
  1947. posture, _ := c.GetInt64("posture")
  1948. score := c.GetString("score")
  1949. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1950. danger_level, _ := c.GetInt64("danger_level", 0)
  1951. intake, _ := c.GetInt64("intake", 0)
  1952. nutrition, _ := c.GetInt64("nutrition", 0)
  1953. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1954. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1955. sick_condition_other := c.GetString("sick_condition_other")
  1956. //precaution, _ := c.GetInt64("precaution", 0)
  1957. precaution := c.GetString("precaution")
  1958. precaution_other := c.GetString("precaution_other")
  1959. psychological_other := c.GetString("psychological_other")
  1960. admission_number := c.GetString("admission_number")
  1961. tumble, _ := c.GetInt64("tumble")
  1962. his_department := c.GetString("his_department")
  1963. his_bed := c.GetString("his_bed")
  1964. diacrisis := c.GetString("diacrisis")
  1965. if id <= 0 {
  1966. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1967. return
  1968. }
  1969. adminUserInfo := c.GetAdminUserInfo()
  1970. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1971. if patient.ID == 0 {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1973. return
  1974. }
  1975. if len(recordDateStr) == 0 {
  1976. recordDateStr = time.Now().Format("2006-01-02")
  1977. }
  1978. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1979. if parseDateErr != nil {
  1980. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1981. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1982. return
  1983. }
  1984. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1985. if adminUserInfo.CurrentOrgId == 10340 {
  1986. if condition == 1 {
  1987. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.CurrentOrgId, id)
  1988. if admission_number == "" {
  1989. admission_number = lastAcceptTreatment.AdmissionNumber
  1990. his_bed = lastAcceptTreatment.HisBed
  1991. his_department = lastAcceptTreatment.HisDepartment
  1992. tumble = lastAcceptTreatment.Tumble
  1993. }
  1994. }
  1995. }
  1996. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1997. UserOrgId: adminUserInfo.CurrentOrgId,
  1998. PatientId: id,
  1999. RecordDate: recordDate.Unix(),
  2000. Way: way,
  2001. Consciousness: consciousness,
  2002. Appetite: appetite,
  2003. Condition: condition,
  2004. SickCondition: sick_condition,
  2005. DangerLevel: danger_level,
  2006. Intake: intake,
  2007. Nutrition: nutrition,
  2008. PsychologicalAssessment: psychological_assessment,
  2009. PsychologicalAssessmentOther: psychological_assessment_other,
  2010. SickConditionOther: sick_condition_other,
  2011. Posture: posture,
  2012. CreatedTime: time.Now().Unix(),
  2013. UpdateTime: time.Now().Unix(),
  2014. Status: 1,
  2015. Score: score,
  2016. Precaution: precaution,
  2017. PrecautionOther: precaution_other,
  2018. PsychologicalOther: psychological_other,
  2019. AdmissionNumber: admission_number,
  2020. Tumble: tumble,
  2021. HisDepartment: his_department,
  2022. HisBed: his_bed,
  2023. Diacrisis: diacrisis,
  2024. }
  2025. // 查询信息规挡的设置天数
  2026. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2027. if infor.ID > 0 && infor.WeekDay > 0 {
  2028. var cha_time int64
  2029. timeNowStr := time.Now().Format("2006-01-02")
  2030. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2031. //今日的日期减去设置的日期
  2032. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2033. if cha_time >= recordDate.Unix() {
  2034. //查询审核是否允许
  2035. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 2)
  2036. //申请状态不允许的情况 拒绝修改
  2037. if infor.ApplicationStatus != 1 {
  2038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2039. return
  2040. }
  2041. }
  2042. }
  2043. if receiveTreatment.ID == 0 { //新增
  2044. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  2045. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  2046. //创建步骤表
  2047. finish := models.XtDialysisFinish{
  2048. IsFinish: 1,
  2049. UserOrgId: adminUserInfo.CurrentOrgId,
  2050. Status: 1,
  2051. Ctime: time.Now().Unix(),
  2052. Mtime: 0,
  2053. Module: 2,
  2054. RecordDate: recordDate.Unix(),
  2055. Sourse: 1,
  2056. PatientId: id,
  2057. }
  2058. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 2, id)
  2059. if dialysisFinish.ID == 0 {
  2060. service.CreateDialysisFinish(finish)
  2061. }
  2062. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  2063. redis := service.RedisClient()
  2064. //清空key 值
  2065. redis.Set(key, "", time.Second)
  2066. defer redis.Close()
  2067. if err == nil {
  2068. c.ServeSuccessJSON(map[string]interface{}{
  2069. "receiveTreatmentAsses": receiveTreatmentAsses,
  2070. })
  2071. } else {
  2072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2073. }
  2074. } else { //修改
  2075. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  2076. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2077. // if getPermissionErr != nil {
  2078. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2079. // return
  2080. // } else if headNursePermission == nil {
  2081. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2082. // return
  2083. // }
  2084. //}
  2085. // 查询信息规挡的设置天数
  2086. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2087. if infor.ID > 0 && infor.WeekDay > 0 {
  2088. var cha_time int64
  2089. timeNowStr := time.Now().Format("2006-01-02")
  2090. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2091. //今日的日期减去设置的日期
  2092. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2093. if cha_time >= recordDate.Unix() {
  2094. //查询审核是否允许
  2095. infor, _ := service.GetDialysisInformationByRecordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId, 2)
  2096. //申请状态不允许的情况 拒绝修改
  2097. if infor.ApplicationStatus != 1 {
  2098. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2099. return
  2100. }
  2101. }
  2102. }
  2103. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  2104. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  2105. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  2106. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  2107. receiveTreatmentAsses.ID = receiveTreatment.ID
  2108. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  2109. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  2110. redis := service.RedisClient()
  2111. defer redis.Close()
  2112. redis.Set(keyOne, "", time.Second*60*60*18)
  2113. if err == nil {
  2114. c.ServeSuccessJSON(map[string]interface{}{
  2115. "receiveTreatmentAsses": receiveTreatmentAsses,
  2116. })
  2117. } else {
  2118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2119. }
  2120. }
  2121. }
  2122. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  2123. patient, _ := c.GetInt64("patient", 0)
  2124. recordDateStr := c.GetString("record_date")
  2125. record_time := c.GetString("record_time")
  2126. if patient <= 0 {
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. adminUserInfo := c.GetAdminUserInfo()
  2131. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2132. if patientInfo.ID == 0 {
  2133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2134. return
  2135. }
  2136. if len(recordDateStr) == 0 {
  2137. recordDateStr = time.Now().Format("2006-01-02")
  2138. }
  2139. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2140. if parseDateErr != nil {
  2141. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2143. return
  2144. }
  2145. startDate, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", record_time)
  2146. // data := make(map[string]interface{}, 0)
  2147. var data models.AssessmentAfterDislysis
  2148. var err error
  2149. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  2150. fmt.Println(err)
  2151. if err != nil {
  2152. c.ErrorLog("数据解析错误:%v", err)
  2153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2154. return
  2155. }
  2156. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2157. assessment.DialysisOrderId = data.DialysisOrderId
  2158. assessment.Evaluator = adminUserInfo.AdminUser.Id
  2159. assessment.Status = 1
  2160. assessment.WeightAfter = data.WeightAfter
  2161. assessment.WeightLoss = data.WeightLoss
  2162. assessment.Temperature = data.Temperature
  2163. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  2164. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  2165. assessment.PulseFrequency = data.PulseFrequency
  2166. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  2167. assessment.ActualDisplacement = data.ActualDisplacement
  2168. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  2169. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  2170. assessment.Cruor = data.Cruor
  2171. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  2172. assessment.DialysisIntakes = data.DialysisIntakes
  2173. assessment.InternalFistula = data.InternalFistula
  2174. assessment.BloodAccessPartId = data.BloodAccessPartId
  2175. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  2176. assessment.Catheter = data.Catheter
  2177. assessment.Complication = data.Complication
  2178. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  2179. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  2180. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  2181. assessment.PatientGose = data.PatientGose
  2182. assessment.InpatientDepartment = data.InpatientDepartment
  2183. assessment.ObservationContent = data.ObservationContent
  2184. assessment.ObservationContentOther = data.ObservationContentOther
  2185. assessment.Remark = data.Remark
  2186. assessment.BreathingRate = data.BreathingRate
  2187. assessment.DialysisProcess = data.DialysisProcess
  2188. assessment.InAdvanceMinute = data.InAdvanceMinute
  2189. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  2190. assessment.InAdvanceReason = data.InAdvanceReason
  2191. assessment.HemostasisOpera = data.HemostasisOpera
  2192. assessment.HemostasisMinute = data.HemostasisMinute
  2193. assessment.TremorNoise = data.TremorNoise
  2194. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  2195. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  2196. assessment.ArterialTube = data.ArterialTube
  2197. assessment.IntravenousTube = data.IntravenousTube
  2198. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  2199. assessment.Dialyzer = data.Dialyzer
  2200. assessment.IsEat = data.IsEat
  2201. assessment.CvcA = data.CvcA
  2202. assessment.CvcV = data.CvcV
  2203. assessment.Channel = data.Channel
  2204. assessment.ReturnBlood = data.ReturnBlood
  2205. assessment.RehydrationVolume = data.RehydrationVolume
  2206. assessment.DialysisDuring = data.DialysisDuring
  2207. assessment.StrokeVolume = data.StrokeVolume
  2208. assessment.BloodFlow = data.BloodFlow
  2209. assessment.SealingFluidDispose = data.SealingFluidDispose
  2210. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  2211. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  2212. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  2213. assessment.SettingPressure = data.SettingPressure
  2214. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  2215. assessment.DiastolicPressure = data.DiastolicPressure
  2216. assessment.AdditionalWeight = data.AdditionalWeight
  2217. assessment.OtherComplication = data.OtherComplication
  2218. assessment.Ktv = data.Ktv
  2219. assessment.Urr = data.Urr
  2220. assessment.Hypertenison = data.Hypertenison
  2221. assessment.Hypopiesia = data.Hypopiesia
  2222. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  2223. assessment.Lapse = data.Lapse
  2224. assessment.Consciousness = data.Consciousness
  2225. assessment.Fallrisk = data.Fallrisk
  2226. assessment.MachineRun = data.MachineRun
  2227. assessment.AfterUrea = data.AfterUrea
  2228. assessment.PipCoagulation = data.PipCoagulation
  2229. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  2230. assessment.TransfusionVolume = data.TransfusionVolume
  2231. assessment.Condenser = data.Condenser
  2232. assessment.LastAfterWeight = data.LastAfterWeight
  2233. assessment.DisplaceLiquiValue = data.DisplaceLiquiValue
  2234. assessment.RecordTime = startDate.Unix()
  2235. assessment.SymptomAfterDialysisRemark = data.SymptomAfterDialysisRemark
  2236. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2237. if assessment.ID > 0 {
  2238. if appRole.UserType == 2 || appRole.UserType == 1 {
  2239. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2240. assessment.AssessmentTime = time.Now().Unix()
  2241. } else {
  2242. if assessment.Creater == 0 {
  2243. assessment.Modifier = adminUserInfo.AdminUser.Id
  2244. assessment.Creater = adminUserInfo.AdminUser.Id
  2245. } else {
  2246. assessment.Modifier = adminUserInfo.AdminUser.Id
  2247. }
  2248. }
  2249. assessment.UpdatedTime = time.Now().Unix()
  2250. // 查询信息规挡的设置天数
  2251. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2252. if infor.ID > 0 {
  2253. var cha_time int64
  2254. timeNowStr := time.Now().Format("2006-01-02")
  2255. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2256. //今日的日期减去设置的日期
  2257. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2258. if cha_time >= recordDate.Unix() {
  2259. //查询审核是否允许
  2260. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 9)
  2261. //申请状态不允许的情况 拒绝修改
  2262. if infor.ApplicationStatus != 1 {
  2263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2264. return
  2265. }
  2266. }
  2267. }
  2268. if adminUserInfo.CurrentOrgId == 10744 {
  2269. evaluation, _ := service.GetAssessmentBeforThrity(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2270. if evaluation.WeightBefore > 0 {
  2271. assessment.WeightLoss = evaluation.WeightBefore - assessment.WeightAfter
  2272. }
  2273. }
  2274. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  2275. //记录日志
  2276. byterequest, _ := json.Marshal(assessment)
  2277. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  2278. UserOrgId: assessment.UserOrgId,
  2279. PatientId: assessment.PatientId,
  2280. RecordDate: assessment.AssessmentDate,
  2281. Status: 1,
  2282. ErrLog: string(byterequest),
  2283. AdminUserId: adminUserInfo.AdminUser.Id,
  2284. Ctime: time.Now().Unix(),
  2285. Mtime: 0,
  2286. Source: "电脑端保存透后评估",
  2287. }
  2288. service.CreateAfterDialysisLog(afterDialysisLog)
  2289. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2290. redis := service.RedisClient()
  2291. //清空key 值
  2292. redis.Set(key, "", time.Second)
  2293. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2294. redis.Set(keyThree, "", time.Second)
  2295. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2296. redis.Set(keyTwo, "", time.Second)
  2297. defer redis.Close()
  2298. } else {
  2299. if appRole.UserType == 2 || appRole.UserType == 1 {
  2300. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2301. assessment.AssessmentTime = time.Now().Unix()
  2302. } else {
  2303. assessment.Creater = adminUserInfo.AdminUser.Id
  2304. }
  2305. assessment.CreatedTime = time.Now().Unix()
  2306. assessment.UpdatedTime = time.Now().Unix()
  2307. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  2308. assessment.PatientId = patient
  2309. assessment.AssessmentDate = recordDate.Unix()
  2310. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  2311. //记录日志
  2312. byterequest, _ := json.Marshal(assessment)
  2313. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  2314. UserOrgId: assessment.UserOrgId,
  2315. PatientId: assessment.PatientId,
  2316. RecordDate: assessment.AssessmentDate,
  2317. Status: 1,
  2318. ErrLog: string(byterequest),
  2319. AdminUserId: adminUserInfo.AdminUser.Id,
  2320. Ctime: time.Now().Unix(),
  2321. Mtime: 0,
  2322. Source: "电脑端修改保存透后评估",
  2323. }
  2324. service.CreateAfterDialysisLog(afterDialysisLog)
  2325. finish := models.XtDialysisFinish{
  2326. IsFinish: 1,
  2327. UserOrgId: adminUserInfo.CurrentOrgId,
  2328. Status: 1,
  2329. Ctime: time.Now().Unix(),
  2330. Mtime: 0,
  2331. Module: 9,
  2332. RecordDate: recordDate.Unix(),
  2333. Sourse: 1,
  2334. PatientId: patient,
  2335. }
  2336. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patient)
  2337. if dialysisFinish.ID == 0 {
  2338. service.CreateDialysisFinish(finish)
  2339. }
  2340. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  2341. redis := service.RedisClient()
  2342. //清空key 值
  2343. redis.Set(key, "", time.Second)
  2344. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  2345. redis.Set(keyThree, "", time.Second)
  2346. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2347. redis.Set(keyTwo, "", time.Second)
  2348. defer redis.Close()
  2349. }
  2350. if err != nil {
  2351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2352. return
  2353. }
  2354. c.ServeSuccessJSON(map[string]interface{}{
  2355. "AssessmentAfterDislysis": &assessment,
  2356. })
  2357. }
  2358. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  2359. patient, _ := c.GetInt64("patient", 0)
  2360. recordDateStr := c.GetString("record_date")
  2361. if patient <= 0 {
  2362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2363. return
  2364. }
  2365. adminUserInfo := c.GetAdminUserInfo()
  2366. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2367. if patientInfo.ID == 0 {
  2368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2369. return
  2370. }
  2371. if len(recordDateStr) == 0 {
  2372. recordDateStr = time.Now().Format("2006-01-02")
  2373. }
  2374. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2375. if parseDateErr != nil {
  2376. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2378. return
  2379. }
  2380. weight_before, _ := c.GetFloat("weight_before", 0)
  2381. dry_weight, _ := c.GetFloat("dry_weight", 0)
  2382. additional_weight, _ := c.GetFloat("additional_weight", 0)
  2383. temperature, _ := c.GetFloat("temperature", 0)
  2384. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2385. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2386. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2387. last_post_dialysis := c.GetString("last_post_dialysis")
  2388. dialysis_interphase := c.GetString("dialysis_interphase")
  2389. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  2390. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  2391. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  2392. bloodAccessPartId := c.GetString("blood_access_part_id")
  2393. internalFistula := c.GetString("internal_fistula")
  2394. internal_fistula_skin := c.GetString("internal_fistula_skin")
  2395. catheter := c.GetString("catheter")
  2396. catheter_bend, _ := c.GetInt("catheter_bend")
  2397. complication := c.GetString("complication")
  2398. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2399. hemorrhage := c.GetString("hemorrhage")
  2400. hemorrhage_other := c.GetString("hemorrhage_other")
  2401. remark := c.GetString("remark")
  2402. puncture_method := c.GetString("puncture_method")
  2403. dialysis_count := c.GetString("dialysis_count")
  2404. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2405. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2406. ductus_arantii := c.GetString("ductus_arantii")
  2407. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2408. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2409. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2410. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  2411. puncture_way := c.GetString("puncture_way")
  2412. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2413. internal_fistula_other := c.GetString("internal_fistula_other")
  2414. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2415. breathing_rate := c.GetString("breathing_rate")
  2416. is_infect, _ := c.GetInt64("is_infect", 0)
  2417. exposed, _ := c.GetFloat("exposed", 0)
  2418. skin := c.GetString("skin")
  2419. skin_other := c.GetString("skin_other")
  2420. infect_other := c.GetString("infect_other")
  2421. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2422. machine_type := c.GetString("machine_type")
  2423. puncture_needle := c.GetString("puncture_needle")
  2424. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  2425. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  2426. phinholing := c.GetString("pinholing")
  2427. catheter_suture := c.GetString("catheter_suture")
  2428. catheter_suture_other := c.GetString("catheter_suture_other")
  2429. edema := c.GetString("edema")
  2430. urine_volume, _ := c.GetFloat("urine_volume", 0)
  2431. special_treatment := c.GetString("special_treatment")
  2432. catheter_maintenance := c.GetString("catheter_maintenance")
  2433. thrombusType := c.GetString("thromubus_type")
  2434. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  2435. thrombus_a := c.GetString("thromubus_a")
  2436. thrombus_av := c.GetString("thrombus_av")
  2437. thrombus_v := c.GetString("thromubus_v")
  2438. dehydration := c.GetString("dehydration")
  2439. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  2440. period, _ := c.GetInt64("period")
  2441. estimated_food_intake := c.GetString("estimated_food_intake")
  2442. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  2443. urea_befor := c.GetString("urea_befor")
  2444. suction := c.GetString("suction")
  2445. weight_befor_remake := c.GetString("weight_befor_remake")
  2446. height := c.GetString("height")
  2447. age := c.GetString("age")
  2448. his_department := c.GetString("his_department")
  2449. his_bed := c.GetString("his_bed")
  2450. point_puncture := c.GetString("point_puncture")
  2451. catheter_evaluation_program := c.GetString("catheter_evaluation_program")
  2452. skin_site_catheterization := c.GetString("skin_site_catheterization")
  2453. pathway_formation_time := c.GetString("pathway_formation_time")
  2454. timeLayout := "2006-01-02"
  2455. loc, _ := time.LoadLocation("Local")
  2456. var startTime int64
  2457. if len(pathway_formation_time) > 0 {
  2458. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  2459. startTime = theTime.Unix()
  2460. }
  2461. whether_unobstructed, _ := c.GetInt64("whether_unobstructed")
  2462. lien_necessary, _ := c.GetInt64("lien_necessary")
  2463. befor_symptoms := c.GetString("befor_symptoms")
  2464. warsh_count := c.GetString("warsh_count")
  2465. washing_time := c.GetString("washing_time")
  2466. puncture_needle_direction := c.GetString("puncture_needle_direction")
  2467. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2468. DialysisCount: dialysis_count,
  2469. EmergencyTreatment: emergency_treatment,
  2470. EmergencyTreatmentOther: emergency_treatment_other,
  2471. DuctusArantii: ductus_arantii,
  2472. VenousCatheterization: venous_catheterization,
  2473. VenousCatheterizationPart: venous_catheterization_part,
  2474. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2475. PunctureWay: puncture_way,
  2476. BloodAccessInternalFistula: blood_access_internal_fistula,
  2477. BloodAccessNoise: blood_access_noise,
  2478. InternalFistulaOther: internal_fistula_other,
  2479. Evaluator: adminUserInfo.AdminUser.Id,
  2480. UserOrgId: adminUserInfo.CurrentOrgId,
  2481. PatientId: patient,
  2482. AssessmentDate: recordDate.Unix(),
  2483. Temperature: temperature,
  2484. PulseFrequency: pulse_frequency,
  2485. SystolicBloodPressure: systolic_blood_pressure,
  2486. DiastolicBloodPressure: diastolic_blood_pressure,
  2487. WeightBefore: weight_before,
  2488. DryWeight: dry_weight,
  2489. AdditionalWeight: additional_weight,
  2490. DialysisInterphase: dialysis_interphase,
  2491. LastPostDialysis: last_post_dialysis,
  2492. SymptomBeforeDialysis: symptom_before_dialysis,
  2493. InternalFistula: internalFistula,
  2494. InternalFistulaSkin: internal_fistula_skin,
  2495. Catheter: catheter,
  2496. CatheterBend: catheter_bend,
  2497. Complication: complication,
  2498. CreatedTime: time.Now().Unix(),
  2499. Status: 1,
  2500. Remark: remark,
  2501. IsHemorrhage: is_hemorrhage,
  2502. Hemorrhage: hemorrhage,
  2503. HemorrhageOther: hemorrhage_other,
  2504. BloodAccessPartId: bloodAccessPartId,
  2505. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2506. PunctureMethod: puncture_method,
  2507. BreathingRate: breathing_rate,
  2508. IsInfect: is_infect,
  2509. Exposed: exposed,
  2510. Skin: skin,
  2511. SkinOther: skin_other,
  2512. InfectOther: infect_other,
  2513. DuctusArantiiOther: ductus_arantii_other,
  2514. MachineType: machine_type,
  2515. PunctureNeedle: puncture_needle,
  2516. HumorExcessiveSymptom: humor_excessive_symptom,
  2517. Phinholing: phinholing,
  2518. CatheterSuture: catheter_suture,
  2519. CatheterSutureOther: catheter_suture_other,
  2520. Edema: edema,
  2521. UrineVolume: urine_volume,
  2522. SpecialTreatment: special_treatment,
  2523. CatheterMaintenance: catheter_maintenance,
  2524. ThromubusType: thrombusInt,
  2525. ThrombusAv: thrombus_av,
  2526. ThromubusA: thrombus_a,
  2527. ThromubusV: thrombus_v,
  2528. Dehydration: dehydration,
  2529. PreDialysisDrugs: pre_dialysis_drugs,
  2530. Period: period,
  2531. EstimatedFoodIntake: estimated_food_intake,
  2532. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  2533. UreaBefor: urea_befor,
  2534. Suction: suction,
  2535. WeightBeforRemake: weight_befor_remake,
  2536. Height: height,
  2537. Age: age,
  2538. HisDepartment: his_department,
  2539. HisBed: his_bed,
  2540. PointPuncture: point_puncture,
  2541. CatheterEvaluationProgram: catheter_evaluation_program,
  2542. SkinSiteCatheterization: skin_site_catheterization,
  2543. PathwayFormationTime: startTime,
  2544. WhetherUnobstructed: whether_unobstructed,
  2545. LienNecessary: lien_necessary,
  2546. BeforSymptoms: befor_symptoms,
  2547. WarshCount: warsh_count,
  2548. WashingTime: washing_time,
  2549. PunctureNeedleDirection: puncture_needle_direction,
  2550. }
  2551. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2552. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2553. if evaluation.ID == 0 { //新增
  2554. if appRole.UserType == 2 || appRole.UserType == 1 {
  2555. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2556. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2557. } else {
  2558. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2559. }
  2560. // 查询信息规挡的设置天数
  2561. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2562. if infor.ID > 0 && infor.WeekDay > 0 {
  2563. var cha_time int64
  2564. timeNowStr := time.Now().Format("2006-01-02")
  2565. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2566. //今日的日期减去设置的日期
  2567. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2568. if cha_time >= recordDate.Unix() {
  2569. //查询审核是否允许
  2570. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2571. //申请状态不允许的情况 拒绝修改
  2572. if infor.ApplicationStatus != 1 {
  2573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2574. return
  2575. }
  2576. }
  2577. }
  2578. if adminUserInfo.CurrentOrgId == 10644 {
  2579. assessmentBeforeDislysis.PunctureNeedle = ""
  2580. }
  2581. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2582. //记录日志
  2583. byterequest, _ := json.Marshal(assessmentBeforeDislysis)
  2584. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2585. UserOrgId: assessmentBeforeDislysis.UserOrgId,
  2586. AdminUserId: adminUserInfo.AdminUser.Id,
  2587. ErrLog: string(byterequest),
  2588. PatientId: assessmentBeforeDislysis.PatientId,
  2589. RecordDate: assessmentBeforeDislysis.AssessmentDate,
  2590. Ctime: time.Now().Unix(),
  2591. Mtime: 0,
  2592. Status: 1,
  2593. Source: "电脑端保存透前评估",
  2594. }
  2595. service.CreateBeforLog(beforeDislysisLog)
  2596. //创建步骤表
  2597. finish := models.XtDialysisFinish{
  2598. IsFinish: 1,
  2599. UserOrgId: adminUserInfo.CurrentOrgId,
  2600. Status: 1,
  2601. Ctime: time.Now().Unix(),
  2602. Mtime: 0,
  2603. Module: 3,
  2604. RecordDate: recordDate.Unix(),
  2605. Sourse: 1,
  2606. PatientId: patient,
  2607. }
  2608. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2609. if dialysisFinish.ID == 0 {
  2610. service.CreateDialysisFinish(finish)
  2611. }
  2612. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 || adminUserInfo.CurrentOrgId == 10551 || adminUserInfo.CurrentOrgId == 10579 || adminUserInfo.CurrentOrgId == 10580 || adminUserInfo.CurrentOrgId == 10585 || adminUserInfo.CurrentOrgId == 10344 || adminUserInfo.CurrentOrgId == 10622 || adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10635 || adminUserInfo.CurrentOrgId == 10723 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10727 || adminUserInfo.CurrentOrgId == 10726 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10727 || adminUserInfo.CurrentOrgId == 10751 || adminUserInfo.CurrentOrgId == 10752 || adminUserInfo.CurrentOrgId == 10480 || adminUserInfo.CurrentOrgId == 10293 || adminUserInfo.CurrentOrgId == 9478 || adminUserInfo.CurrentOrgId == 10766 {
  2613. var dewater_amount float64
  2614. dewater_amount = 0
  2615. if dry_weight > 0 {
  2616. dewater_amount = weight_before - dry_weight - additional_weight
  2617. if adminUserInfo.CurrentOrgId != 10551 && adminUserInfo.CurrentOrgId != 10579 && adminUserInfo.CurrentOrgId != 10580 && adminUserInfo.CurrentOrgId != 10585 && adminUserInfo.CurrentOrgId != 10344 && adminUserInfo.CurrentOrgId != 10622 && adminUserInfo.CurrentOrgId != 10702 && adminUserInfo.CurrentOrgId != 10635 && adminUserInfo.CurrentOrgId != 10723 && adminUserInfo.CurrentOrgId != 10480 && adminUserInfo.CurrentOrgId != 10293 && adminUserInfo.CurrentOrgId != 9478 && adminUserInfo.CurrentOrgId != 10744 && adminUserInfo.CurrentOrgId != 10766 {
  2618. dewater_amount = dewater_amount * 1000
  2619. }
  2620. if dewater_amount <= 0 {
  2621. dewater_amount = 0
  2622. }
  2623. } else {
  2624. dewater_amount = 0
  2625. }
  2626. // 计算透析处方的相关超滤量
  2627. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2628. var lastDialysisPrescribe *models.DialysisPrescription
  2629. var dialysisSolution *models.DialysisSolution
  2630. var dialysisPrescribe *models.DialysisPrescription
  2631. var mode_id int64
  2632. if schedual != nil {
  2633. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2634. if dialysisPrescribe == nil {
  2635. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2636. }
  2637. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2638. // 获取透析模版
  2639. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2640. mode_id = schedual.ModeId
  2641. } else {
  2642. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2643. // 获取透析模版
  2644. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2645. // 获取透析模版
  2646. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2647. if dialysisPrescribe == nil && dialysisSolution != nil {
  2648. mode_id = dialysisSolution.ModeId
  2649. }
  2650. if dialysisPrescribe == nil && dialysisSolution == nil {
  2651. mode_id = 0
  2652. }
  2653. }
  2654. // 插入透析处方
  2655. if dialysisPrescribe == nil && dialysisSolution != nil {
  2656. var newprescribe models.DialysisPrescription
  2657. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2658. newprescribe.PatientId = patient
  2659. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2660. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2661. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2662. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2663. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2664. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2665. newprescribe.ModeId = dialysisSolution.ModeId
  2666. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2667. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2668. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2669. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2670. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2671. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2672. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2673. newprescribe.Glucose = dialysisSolution.Glucose
  2674. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2675. newprescribe.Kalium = dialysisSolution.Kalium
  2676. newprescribe.Sodium = dialysisSolution.Sodium
  2677. newprescribe.Calcium = dialysisSolution.Calcium
  2678. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2679. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2680. newprescribe.Conductivity = dialysisSolution.Conductivity
  2681. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2682. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2683. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2684. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2685. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2686. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2687. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2688. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2689. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2690. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2691. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2692. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2693. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2694. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2695. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2696. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2697. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  2698. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  2699. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  2700. newprescribe.CreatedTime = time.Now().Unix()
  2701. newprescribe.UpdatedTime = time.Now().Unix()
  2702. newprescribe.RecordDate = recordDate.Unix()
  2703. newprescribe.DewaterAmount = dewater_amount
  2704. newprescribe.TargetUltrafiltration = dewater_amount
  2705. newprescribe.PrescriptionWater = dewater_amount
  2706. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2707. newprescribe.Amylaceum = dialysisSolution.Amylaceum
  2708. newprescribe.Status = 1
  2709. if adminUserInfo.CurrentOrgId == 10579 {
  2710. newprescribe.Modifier = 0
  2711. newprescribe.PrescriptionDoctor = 0
  2712. newprescribe.Creater = 0
  2713. }
  2714. err := service.AddSigleRecord(&newprescribe)
  2715. //记录日志
  2716. byterequest, _ := json.Marshal(newprescribe)
  2717. prescriptionLog := models.XtDialysisPrescriptionLog{
  2718. UserOrgId: newprescribe.UserOrgId,
  2719. Ctime: time.Now().Unix(),
  2720. Mtime: 0,
  2721. ErrLog: string(byterequest),
  2722. AdminUserId: adminUserInfo.AdminUser.Id,
  2723. RecordDate: newprescribe.RecordDate,
  2724. PatientId: newprescribe.PatientId,
  2725. Source: "电脑端透前评估保存",
  2726. Status: 1,
  2727. }
  2728. service.CreatePrescriptionLog(prescriptionLog)
  2729. if err != nil {
  2730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2731. }
  2732. }
  2733. if dialysisPrescribe == nil && dialysisSolution == nil {
  2734. if lastDialysisPrescribe != nil {
  2735. var newprescribe models.DialysisPrescription
  2736. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2737. newprescribe.PatientId = patient
  2738. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2739. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2740. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2741. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2742. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2743. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2744. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2745. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2746. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2747. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2748. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2749. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2750. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2751. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2752. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2753. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2754. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2755. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2756. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2757. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2758. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2759. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2760. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2761. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2762. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2763. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2764. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2765. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2766. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2767. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2768. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2769. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2770. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2771. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2772. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2773. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2774. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2775. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  2776. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  2777. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  2778. newprescribe.Amylaceum = lastDialysisPrescribe.Amylaceum
  2779. newprescribe.CreatedTime = time.Now().Unix()
  2780. newprescribe.UpdatedTime = time.Now().Unix()
  2781. newprescribe.RecordDate = recordDate.Unix()
  2782. newprescribe.DewaterAmount = dewater_amount
  2783. newprescribe.PrescriptionWater = dewater_amount
  2784. newprescribe.TargetUltrafiltration = dewater_amount
  2785. newprescribe.Status = 1
  2786. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2787. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2788. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2789. if adminUserInfo.CurrentOrgId == 10579 {
  2790. newprescribe.Modifier = 0
  2791. newprescribe.PrescriptionDoctor = 0
  2792. newprescribe.Creater = 0
  2793. }
  2794. err := service.AddSigleRecord(&newprescribe)
  2795. //记录日志
  2796. byterequest, _ := json.Marshal(newprescribe)
  2797. prescriptionLog := models.XtDialysisPrescriptionLog{
  2798. UserOrgId: newprescribe.UserOrgId,
  2799. Ctime: time.Now().Unix(),
  2800. Mtime: 0,
  2801. ErrLog: string(byterequest),
  2802. AdminUserId: adminUserInfo.AdminUser.Id,
  2803. RecordDate: newprescribe.RecordDate,
  2804. PatientId: newprescribe.PatientId,
  2805. Source: "电脑端透前评估保存",
  2806. Status: 1,
  2807. }
  2808. service.CreatePrescriptionLog(prescriptionLog)
  2809. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2810. redis := service.RedisClient()
  2811. defer redis.Close()
  2812. //清空key 值
  2813. redis.Set(key, "", time.Second)
  2814. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2815. redis.Set(keyOne, "", time.Second)
  2816. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2817. redis.Set(keyThree, "", time.Second)
  2818. if err != nil {
  2819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2820. }
  2821. } else {
  2822. var newprescribe models.DialysisPrescription
  2823. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2824. newprescribe.PatientId = patient
  2825. newprescribe.ModeId = mode_id
  2826. newprescribe.CreatedTime = time.Now().Unix()
  2827. newprescribe.UpdatedTime = time.Now().Unix()
  2828. newprescribe.RecordDate = recordDate.Unix()
  2829. newprescribe.DewaterAmount = dewater_amount
  2830. newprescribe.TargetUltrafiltration = dewater_amount
  2831. newprescribe.Status = 1
  2832. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2833. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2834. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2835. if adminUserInfo.CurrentOrgId == 10579 {
  2836. newprescribe.Modifier = 0
  2837. newprescribe.PrescriptionDoctor = 0
  2838. newprescribe.Creater = 0
  2839. }
  2840. err := service.AddSigleRecord(&newprescribe)
  2841. //记录日志
  2842. byterequest, _ := json.Marshal(newprescribe)
  2843. prescriptionLog := models.XtDialysisPrescriptionLog{
  2844. UserOrgId: newprescribe.UserOrgId,
  2845. Ctime: time.Now().Unix(),
  2846. Mtime: 0,
  2847. ErrLog: string(byterequest),
  2848. AdminUserId: adminUserInfo.AdminUser.Id,
  2849. RecordDate: newprescribe.RecordDate,
  2850. PatientId: newprescribe.PatientId,
  2851. Source: "电脑端透前评估保存",
  2852. Status: 1,
  2853. }
  2854. service.CreatePrescriptionLog(prescriptionLog)
  2855. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2856. redis := service.RedisClient()
  2857. defer redis.Close()
  2858. //清空key 值
  2859. redis.Set(key, "", time.Second)
  2860. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2861. redis.Set(keyOne, "", time.Second)
  2862. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2863. redis.Set(keyThree, "", time.Second)
  2864. if err != nil {
  2865. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2866. }
  2867. }
  2868. }
  2869. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 {
  2870. prescription, _ := service.GetTodayPrescription(patient, adminUserInfo.CurrentOrgId, recordDate.Unix())
  2871. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  2872. if len(monitorList) > 0 {
  2873. var ultrafiltration_rate float64
  2874. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  2875. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  2876. var replacement_rate float64
  2877. //乘10 除10是为了保留一位小数
  2878. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  2879. var firstOpeateTime = monitorList[0].OperateTime
  2880. for _, item := range monitorList {
  2881. //超滤率
  2882. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  2883. //置换率
  2884. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  2885. //超滤量
  2886. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  2887. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  2888. //置换量
  2889. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  2890. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  2891. }
  2892. }
  2893. }
  2894. }
  2895. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2896. redis := service.RedisClient()
  2897. //清空key 值
  2898. redis.Set(key, "", time.Second)
  2899. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2900. redis.Set(keyOne, "", time.Second)
  2901. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2902. redis.Set(keyTwo, "", time.Second)
  2903. defer redis.Close()
  2904. if err == nil {
  2905. c.ServeSuccessJSON(map[string]interface{}{
  2906. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2907. })
  2908. } else {
  2909. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2911. }
  2912. } else { //修改
  2913. //if appRole.UserType == 3 {
  2914. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2915. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2916. // if getPermissionErr != nil {
  2917. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2918. // return
  2919. // } else if headNursePermission == nil {
  2920. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2921. // return
  2922. // }
  2923. // }
  2924. //}
  2925. if appRole.UserType == 2 || appRole.UserType == 1 {
  2926. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2927. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2928. } else {
  2929. if evaluation.Creater == 0 {
  2930. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2931. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2932. } else {
  2933. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2934. }
  2935. }
  2936. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2937. assessmentBeforeDislysis.ID = evaluation.ID
  2938. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2939. //
  2940. //新增逻辑
  2941. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2942. var dewater_amount float64
  2943. dewater_amount = 0
  2944. if evaluation.DryWeight > 0 {
  2945. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2946. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 || adminUserInfo.CurrentOrgId == 10551 || adminUserInfo.CurrentOrgId == 10751 || adminUserInfo.CurrentOrgId == 10757 || adminUserInfo.CurrentOrgId == 9478 {
  2947. if adminUserInfo.CurrentOrgId != 10551 && adminUserInfo.CurrentOrgId != 10751 && adminUserInfo.CurrentOrgId != 9478 {
  2948. dewater_amount = dewater_amount * 1000
  2949. }
  2950. }
  2951. if dewater_amount <= 0 {
  2952. dewater_amount = 0
  2953. }
  2954. } else {
  2955. dewater_amount = 0
  2956. }
  2957. // 计算透析处方的相关超滤量
  2958. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2959. var lastDialysisPrescribe *models.DialysisPrescription
  2960. var dialysisSolution *models.DialysisSolution
  2961. var dialysisPrescribe *models.DialysisPrescription
  2962. var mode_id int64
  2963. if schedual != nil {
  2964. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2965. if dialysisPrescribe == nil {
  2966. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2967. }
  2968. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2969. // 获取透析模版
  2970. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2971. mode_id = schedual.ModeId
  2972. } else {
  2973. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2974. // 获取透析模版
  2975. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2976. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2977. if dialysisPrescribe == nil && dialysisSolution != nil {
  2978. mode_id = dialysisSolution.ModeId
  2979. }
  2980. if dialysisPrescribe == nil && dialysisSolution == nil {
  2981. mode_id = 0
  2982. }
  2983. }
  2984. // 插入透析处方
  2985. if dialysisPrescribe == nil && dialysisSolution != nil {
  2986. var newprescribe models.DialysisPrescription
  2987. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2988. newprescribe.PatientId = patient
  2989. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2990. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2991. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2992. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2993. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2994. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2995. newprescribe.ModeId = dialysisSolution.ModeId
  2996. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2997. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2998. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2999. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  3000. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  3001. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  3002. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  3003. newprescribe.Glucose = dialysisSolution.Glucose
  3004. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  3005. newprescribe.Kalium = dialysisSolution.Kalium
  3006. newprescribe.Sodium = dialysisSolution.Sodium
  3007. newprescribe.Calcium = dialysisSolution.Calcium
  3008. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  3009. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  3010. newprescribe.Conductivity = dialysisSolution.Conductivity
  3011. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  3012. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  3013. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  3014. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  3015. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  3016. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  3017. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  3018. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  3019. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  3020. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  3021. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  3022. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  3023. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  3024. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  3025. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  3026. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  3027. newprescribe.DialysisStrainer = dialysisSolution.DialysisStrainer
  3028. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  3029. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  3030. newprescribe.CreatedTime = time.Now().Unix()
  3031. newprescribe.UpdatedTime = time.Now().Unix()
  3032. newprescribe.RecordDate = recordDate.Unix()
  3033. newprescribe.DewaterAmount = dewater_amount
  3034. newprescribe.TargetUltrafiltration = dewater_amount
  3035. newprescribe.PrescriptionWater = dewater_amount
  3036. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3037. newprescribe.Amylaceum = dialysisSolution.Amylaceum
  3038. newprescribe.Status = 1
  3039. if adminUserInfo.CurrentOrgId == 10579 {
  3040. newprescribe.Modifier = 0
  3041. newprescribe.PrescriptionDoctor = 0
  3042. newprescribe.Creater = 0
  3043. }
  3044. err := service.AddSigleRecord(&newprescribe)
  3045. //记录日志
  3046. byterequest, _ := json.Marshal(newprescribe)
  3047. prescriptionLog := models.XtDialysisPrescriptionLog{
  3048. UserOrgId: newprescribe.UserOrgId,
  3049. Ctime: time.Now().Unix(),
  3050. Mtime: 0,
  3051. ErrLog: string(byterequest),
  3052. AdminUserId: adminUserInfo.AdminUser.Id,
  3053. RecordDate: newprescribe.RecordDate,
  3054. PatientId: newprescribe.PatientId,
  3055. Source: "电脑端透前评估保存",
  3056. Status: 1,
  3057. }
  3058. service.CreatePrescriptionLog(prescriptionLog)
  3059. if err != nil {
  3060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3061. }
  3062. }
  3063. if dialysisPrescribe == nil && dialysisSolution == nil {
  3064. if lastDialysisPrescribe != nil {
  3065. var newprescribe models.DialysisPrescription
  3066. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  3067. newprescribe.PatientId = patient
  3068. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  3069. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  3070. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  3071. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  3072. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  3073. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  3074. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  3075. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  3076. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  3077. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  3078. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  3079. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  3080. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  3081. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  3082. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  3083. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  3084. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  3085. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  3086. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  3087. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  3088. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  3089. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  3090. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  3091. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  3092. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  3093. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  3094. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  3095. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  3096. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  3097. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  3098. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  3099. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  3100. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  3101. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  3102. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  3103. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  3104. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  3105. newprescribe.CreatedTime = time.Now().Unix()
  3106. newprescribe.UpdatedTime = time.Now().Unix()
  3107. newprescribe.RecordDate = recordDate.Unix()
  3108. newprescribe.DewaterAmount = dewater_amount
  3109. newprescribe.TargetUltrafiltration = dewater_amount
  3110. newprescribe.PrescriptionWater = dewater_amount
  3111. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  3112. newprescribe.DialysisStrainer = lastDialysisPrescribe.DialysisStrainer
  3113. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  3114. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  3115. newprescribe.Amylaceum = lastDialysisPrescribe.Amylaceum
  3116. newprescribe.Status = 1
  3117. if adminUserInfo.CurrentOrgId == 10579 {
  3118. newprescribe.Modifier = 0
  3119. newprescribe.PrescriptionDoctor = 0
  3120. newprescribe.Creater = 0
  3121. }
  3122. err := service.AddSigleRecord(&newprescribe)
  3123. //记录日志
  3124. byterequest, _ := json.Marshal(newprescribe)
  3125. prescriptionLog := models.XtDialysisPrescriptionLog{
  3126. UserOrgId: newprescribe.UserOrgId,
  3127. Ctime: time.Now().Unix(),
  3128. Mtime: 0,
  3129. ErrLog: string(byterequest),
  3130. AdminUserId: adminUserInfo.AdminUser.Id,
  3131. RecordDate: newprescribe.RecordDate,
  3132. PatientId: newprescribe.PatientId,
  3133. Source: "电脑端透前评估保存",
  3134. Status: 1,
  3135. }
  3136. service.CreatePrescriptionLog(prescriptionLog)
  3137. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3138. redis := service.RedisClient()
  3139. defer redis.Close()
  3140. //清空key 值
  3141. redis.Set(key, "", time.Second)
  3142. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3143. redis.Set(keyOne, "", time.Second)
  3144. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3145. redis.Set(keyThree, "", time.Second)
  3146. if err != nil {
  3147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3148. }
  3149. } else {
  3150. var newprescribe models.DialysisPrescription
  3151. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  3152. newprescribe.PatientId = patient
  3153. newprescribe.ModeId = mode_id
  3154. newprescribe.CreatedTime = time.Now().Unix()
  3155. newprescribe.UpdatedTime = time.Now().Unix()
  3156. newprescribe.RecordDate = recordDate.Unix()
  3157. newprescribe.DewaterAmount = dewater_amount
  3158. newprescribe.TargetUltrafiltration = dewater_amount
  3159. newprescribe.Status = 1
  3160. err := service.AddSigleRecord(&newprescribe)
  3161. //记录日志
  3162. byterequest, _ := json.Marshal(newprescribe)
  3163. prescriptionLog := models.XtDialysisPrescriptionLog{
  3164. UserOrgId: newprescribe.UserOrgId,
  3165. Ctime: time.Now().Unix(),
  3166. Mtime: 0,
  3167. ErrLog: string(byterequest),
  3168. AdminUserId: adminUserInfo.AdminUser.Id,
  3169. RecordDate: newprescribe.RecordDate,
  3170. PatientId: newprescribe.PatientId,
  3171. Source: "电脑端透前评估保存",
  3172. Status: 1,
  3173. }
  3174. service.CreatePrescriptionLog(prescriptionLog)
  3175. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  3176. redis := service.RedisClient()
  3177. defer redis.Close()
  3178. //清空key 值
  3179. redis.Set(key, "", time.Second)
  3180. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  3181. redis.Set(keyOne, "", time.Second)
  3182. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3183. redis.Set(keyThree, "", time.Second)
  3184. if err != nil {
  3185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3186. }
  3187. }
  3188. }
  3189. // 查询信息规挡的设置天数
  3190. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3191. if infor.ID > 0 {
  3192. var cha_time int64
  3193. timeNowStr := time.Now().Format("2006-01-02")
  3194. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3195. //今日的日期减去设置的日期
  3196. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3197. if cha_time >= recordDate.Unix() {
  3198. //查询审核是否允许
  3199. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  3200. //申请状态不允许的情况 拒绝修改
  3201. if infor.ApplicationStatus != 1 {
  3202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3203. return
  3204. }
  3205. }
  3206. }
  3207. //针对孝昌康桥超滤率计算问题
  3208. if adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10635 || adminUserInfo.CurrentOrgId == 10723 || adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10726 || adminUserInfo.CurrentOrgId == 10742 || adminUserInfo.CurrentOrgId == 10751 || adminUserInfo.CurrentOrgId == 10752 || adminUserInfo.CurrentOrgId == 10697 || adminUserInfo.CurrentOrgId == 9478 || adminUserInfo.CurrentOrgId == 10766 {
  3209. if assessmentBeforeDislysis.ID == 0 {
  3210. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3211. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  3212. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  3213. if adminUserInfo.CurrentOrgId == 10751 {
  3214. dewater_amount = dewater_amount * 1000
  3215. }
  3216. service.UpdateMobileGetDialysisPrescribe(dialysisPrescribeOne.ID, dewater_amount)
  3217. }
  3218. }
  3219. if adminUserInfo.CurrentOrgId != 10751 {
  3220. if assessmentBeforeDislysis.ID > 0 {
  3221. dialysisPrescribeOne, _ := service.MobileGetDialysisPrescribeOne(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  3222. if dialysisPrescribeOne.ID > 0 && assessmentBeforeDislysis.ID > 0 {
  3223. dewater_amount = assessmentBeforeDislysis.WeightBefore - assessmentBeforeDislysis.DryWeight - assessmentBeforeDislysis.AdditionalWeight
  3224. //if adminUserInfo.CurrentOrgId == 10751 {
  3225. // dewater_amount = dewater_amount * 1000
  3226. //}
  3227. service.UpdateMobileGetDialysisPrescribeOne(dialysisPrescribeOne.ID, dewater_amount)
  3228. }
  3229. }
  3230. }
  3231. }
  3232. if adminUserInfo.CurrentOrgId == 10721 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10766 || adminUserInfo.CurrentOrgId == 9478 {
  3233. prescription, _ := service.GetTodayPrescription(patient, adminUserInfo.CurrentOrgId, recordDate.Unix())
  3234. monitorList, _ := service.GetMobilePatientMonitor(prescription.PatientId, prescription.RecordDate, prescription.UserOrgId)
  3235. if len(monitorList) > 0 {
  3236. var ultrafiltration_rate float64
  3237. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3238. ultrafiltration_rate = (math.Floor(prescription.PrescriptionWater * 1000 / float64(totalMin) * 60 * 1000)) / 1000
  3239. var replacement_rate float64
  3240. //乘10 除10是为了保留一位小数
  3241. replacement_rate = math.Floor(prescription.ReplacementTotal*1000/float64(totalMin)*10) / 10
  3242. var firstOpeateTime = monitorList[0].OperateTime
  3243. for _, item := range monitorList {
  3244. //超滤率
  3245. service.ModifyDialysisPatientMonitor(item.ID, ultrafiltration_rate)
  3246. //置换率
  3247. service.ModifyDialysisPatientReplascementRate(item.ID, replacement_rate)
  3248. //超滤量
  3249. ultrafiltration_volume := math.Floor(float64(item.OperateTime-firstOpeateTime)/3600) * ultrafiltration_rate
  3250. service.ModifyPatientUltrafiltrationVolume(item.ID, ultrafiltration_volume)
  3251. //置换量
  3252. displacement_quantity := (math.Floor(float64(item.OperateTime+3600-firstOpeateTime)/3600) * replacement_rate) * 60 / 1000
  3253. service.ModifyPatientDisplacementQuantity(item.ID, displacement_quantity)
  3254. }
  3255. }
  3256. }
  3257. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  3258. //创建步骤表
  3259. finish := models.XtDialysisFinish{
  3260. IsFinish: 1,
  3261. UserOrgId: adminUserInfo.CurrentOrgId,
  3262. Status: 1,
  3263. Ctime: time.Now().Unix(),
  3264. Mtime: 0,
  3265. Module: 3,
  3266. RecordDate: recordDate.Unix(),
  3267. Sourse: 1,
  3268. PatientId: patient,
  3269. }
  3270. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  3271. if dialysisFinish.ID == 0 {
  3272. service.CreateDialysisFinish(finish)
  3273. }
  3274. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  3275. redis := service.RedisClient()
  3276. //清空key 值
  3277. redis.Set(key, "", time.Second)
  3278. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  3279. redis.Set(keyOne, "", time.Second)
  3280. defer redis.Close()
  3281. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3282. redis.Set(keyTwo, "", time.Second)
  3283. if err == nil {
  3284. c.ServeSuccessJSON(map[string]interface{}{
  3285. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  3286. })
  3287. } else {
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3289. }
  3290. }
  3291. }
  3292. func (c *DialysisApiController) PostTreatmentSummary() {
  3293. patient, _ := c.GetInt64("patient", 0)
  3294. recordDateStr := c.GetString("record_date")
  3295. if patient <= 0 {
  3296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3297. return
  3298. }
  3299. adminUserInfo := c.GetAdminUserInfo()
  3300. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3301. if patientInfo.ID == 0 {
  3302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3303. return
  3304. }
  3305. if len(recordDateStr) == 0 {
  3306. recordDateStr = time.Now().Format("2006-01-02")
  3307. }
  3308. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3309. if parseDateErr != nil {
  3310. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  3311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3312. return
  3313. }
  3314. mission := c.GetString("mission")
  3315. dialysis_summary := c.GetString("dialysis_summary")
  3316. nursingRecord := c.GetString("nursing_record")
  3317. specialRecord := c.GetString("special_record")
  3318. sj_nurse := adminUserInfo.AdminUser.Id
  3319. zl_nurse := adminUserInfo.AdminUser.Id
  3320. hd_nurse := adminUserInfo.AdminUser.Id
  3321. xj_nurse := adminUserInfo.AdminUser.Id
  3322. zl_doctor := adminUserInfo.AdminUser.Id
  3323. treatmentSummary := models.TreatmentSummary{
  3324. UserOrgId: adminUserInfo.CurrentOrgId,
  3325. PatientId: patient,
  3326. AssessmentDate: recordDate.Unix(),
  3327. Mission: mission,
  3328. DialysisSummary: dialysis_summary,
  3329. SjNurse: sj_nurse,
  3330. ZlNurse: zl_nurse,
  3331. HdNurse: hd_nurse,
  3332. XjNurse: xj_nurse,
  3333. ZlDoctor: zl_doctor,
  3334. Status: 1,
  3335. CreatedTime: time.Now().Unix(),
  3336. NursingRecord: nursingRecord,
  3337. SpecialRecord: specialRecord,
  3338. }
  3339. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  3340. if tempTreatmentSummary.ID == 0 { //新增
  3341. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  3342. // 查询信息规挡的设置天数
  3343. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3344. if infor.ID > 0 && infor.WeekDay > 0 {
  3345. var cha_time int64
  3346. timeNowStr := time.Now().Format("2006-01-02")
  3347. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3348. //今日的日期减去设置的日期
  3349. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3350. if cha_time >= recordDate.Unix() {
  3351. //查询审核是否允许
  3352. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  3353. //申请状态不允许的情况 拒绝修改
  3354. if infor.ApplicationStatus != 1 {
  3355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3356. return
  3357. }
  3358. }
  3359. }
  3360. err := service.AddSigleSummaryRecord(&treatmentSummary)
  3361. finish := models.XtDialysisFinish{
  3362. IsFinish: 1,
  3363. UserOrgId: adminUserInfo.CurrentOrgId,
  3364. Status: 1,
  3365. Ctime: time.Now().Unix(),
  3366. Mtime: 0,
  3367. Module: 10,
  3368. RecordDate: recordDate.Unix(),
  3369. Sourse: 1,
  3370. PatientId: patient,
  3371. }
  3372. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10, patient)
  3373. if dialysisFinish.ID == 0 {
  3374. service.CreateDialysisFinish(finish)
  3375. }
  3376. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  3377. redis := service.RedisClient()
  3378. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  3379. redis.Set(keyOne, "", time.Second)
  3380. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3381. redis.Set(keyThree, "", time.Second)
  3382. defer redis.Close()
  3383. //清空key 值
  3384. redis.Set(key, "", time.Second)
  3385. if err == nil {
  3386. c.ServeSuccessJSON(map[string]interface{}{
  3387. "summary": treatmentSummary,
  3388. })
  3389. } else {
  3390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3391. }
  3392. } else { //修改
  3393. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  3394. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3395. // if getPermissionErr != nil {
  3396. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3397. // return
  3398. // } else if headNursePermission == nil {
  3399. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3400. // return
  3401. // }
  3402. //}
  3403. // 查询信息规挡的设置天数
  3404. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3405. if infor.ID > 0 && infor.WeekDay > 0 {
  3406. var cha_time int64
  3407. timeNowStr := time.Now().Format("2006-01-02")
  3408. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3409. //今日的日期减去设置的日期
  3410. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3411. if cha_time >= recordDate.Unix() {
  3412. //查询审核是否允许
  3413. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  3414. //申请状态不允许的情况 拒绝修改
  3415. if infor.ApplicationStatus != 1 {
  3416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3417. return
  3418. }
  3419. }
  3420. }
  3421. treatmentSummary.Creater = tempTreatmentSummary.Creater
  3422. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  3423. treatmentSummary.UpdatedTime = time.Now().Unix()
  3424. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  3425. treatmentSummary.ID = tempTreatmentSummary.ID
  3426. err := service.UpdateSummeRecord(&treatmentSummary)
  3427. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  3428. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  3429. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3430. //清空key 值
  3431. redis := service.RedisClient()
  3432. redis.Set(key, "", time.Second)
  3433. redis.Set(keyOne, "", time.Second)
  3434. redis.Set(keyThree, "", time.Second)
  3435. defer redis.Close()
  3436. if err == nil {
  3437. c.ServeSuccessJSON(map[string]interface{}{
  3438. "summary": treatmentSummary,
  3439. })
  3440. } else {
  3441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  3442. }
  3443. }
  3444. }
  3445. func (c *DialysisApiController) GetDeviceList() {
  3446. adminUserInfo := c.GetAdminUserInfo()
  3447. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  3448. c.ServeSuccessJSON(map[string]interface{}{
  3449. "device": device,
  3450. })
  3451. }
  3452. func (c *DialysisApiController) GetAllDeviceZone() {
  3453. adminUserInfo := c.GetAdminUserInfo()
  3454. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  3455. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  3456. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  3457. if err == nil {
  3458. c.ServeSuccessJSON(map[string]interface{}{
  3459. "zone": zone,
  3460. "dics": dics,
  3461. "efs": efs,
  3462. })
  3463. }
  3464. }
  3465. func (c *DialysisApiController) GetDialysisWatch() {
  3466. page, _ := c.GetInt64("page", 1)
  3467. limit, _ := c.GetInt64("limit", 10)
  3468. schedulType, _ := c.GetInt64("schedul_type", 0)
  3469. startTime, _ := c.GetInt64("schedul_time", 0)
  3470. partitionType, _ := c.GetInt64("partition_type", 0)
  3471. keywords := c.GetString("keywords")
  3472. start_time, _ := c.GetInt64("start_time")
  3473. end_time, _ := c.GetInt64("end_time")
  3474. adminUserInfo := c.GetAdminUserInfo()
  3475. if len(keywords) > 0 {
  3476. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3477. if err == nil {
  3478. c.ServeSuccessJSON(map[string]interface{}{
  3479. "schedule": dialysisSchedule,
  3480. "total": total,
  3481. })
  3482. } else {
  3483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3484. }
  3485. } else {
  3486. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  3487. for _, item := range dialysisSchedule {
  3488. patients, _ := service.GetMonitorPatients(item.PatientId)
  3489. item.MonitorPatients = patients
  3490. orderObj, _ := service.GetMonitorDialysisOrderObj(item.PatientId, item.ScheduleDate)
  3491. item.DialysisOrder = orderObj
  3492. prescription, _ := service.GetMonitorDialysisPrescription(item.PatientId, item.ScheduleDate)
  3493. item.Prescription = prescription
  3494. evaluation, _ := service.GetMonitorPredialysisEvaluation(item.PatientId, item.ScheduleDate)
  3495. item.AssessmentBeforeDislysis = evaluation
  3496. afterdislysis, _ := service.GetMonitorAssessmentAfterDislysis(item.PatientId, item.ScheduleDate)
  3497. item.AssessmentAfterDislysis = afterdislysis
  3498. monitorRecord, _ := service.GetMonitoringRecordList(item.PatientId, item.ScheduleDate)
  3499. item.MonitoringRecord = monitorRecord
  3500. }
  3501. if err == nil {
  3502. c.ServeSuccessJSON(map[string]interface{}{
  3503. "schedule": dialysisSchedule,
  3504. "total": total,
  3505. })
  3506. } else {
  3507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3508. }
  3509. }
  3510. }
  3511. //func (c *DialysisApiController) GetDialysisWatch() {
  3512. // page, _ := c.GetInt64("page", 1)
  3513. // limit, _ := c.GetInt64("limit", 10)
  3514. // schedulType, _ := c.GetInt64("schedul_type", 0)
  3515. // startTime, _ := c.GetInt64("schedul_time", 0)
  3516. // partitionType, _ := c.GetInt64("partition_type", 0)
  3517. // keywords := c.GetString("keywords")
  3518. //
  3519. // adminUserInfo := c.GetAdminUserInfo()
  3520. // if len(keywords) > 0 {
  3521. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3522. //
  3523. // //获取所有床位号
  3524. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  3525. //
  3526. // //获取透析处方
  3527. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  3528. // //获取透前评估
  3529. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  3530. // //获取上机
  3531. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  3532. // //获取透后
  3533. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  3534. //
  3535. // //获取透后监测
  3536. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  3537. //
  3538. // //获取所有的患者
  3539. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  3540. //
  3541. // //获取所有透析模式
  3542. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  3543. //
  3544. // for key, scheduals := range dialysisSchedule {
  3545. // // 获取患者信息
  3546. // for _, patient := range patients {
  3547. // if scheduals.PatientId == patient.ID {
  3548. // dialysisSchedule[key].MonitorPatients = patient
  3549. // break
  3550. // }
  3551. // }
  3552. // // 床位信息
  3553. // for _, device := range numberList {
  3554. // if scheduals.BedId == device.ID {
  3555. // dialysisSchedule[key].DeviceNumber = device
  3556. // break
  3557. // }
  3558. // }
  3559. //
  3560. // // 医嘱信息
  3561. // for _, prescription := range prescriptions {
  3562. // if scheduals.PatientId == prescription.PatientId {
  3563. // dialysisSchedule[key].Prescription = prescription
  3564. // break
  3565. // }
  3566. // }
  3567. //
  3568. // // 透前评估
  3569. // for _, assessmentBefore := range assessmentBefores {
  3570. // if scheduals.PatientId == assessmentBefore.PatientId {
  3571. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  3572. // break
  3573. // }
  3574. // }
  3575. //
  3576. // // 透析上下机
  3577. // for _, dialysisOrder := range dialysisOrders {
  3578. // if scheduals.PatientId == dialysisOrder.PatientId {
  3579. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  3580. // break
  3581. // }
  3582. // }
  3583. //
  3584. // records := make([]*models.MonitoringRecord, 0)
  3585. // // 透析监测
  3586. // for _, it := range monitorlist {
  3587. // records := append(records, it)
  3588. // if scheduals.PatientId == it.PatientId {
  3589. // dialysisSchedule[key].MonitoringRecord = records
  3590. // }
  3591. // }
  3592. //
  3593. // // 透后评估
  3594. // for _, afterDislysis := range AssessmentAfterDislysis {
  3595. // if scheduals.PatientId == afterDislysis.PatientId {
  3596. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  3597. // break
  3598. // }
  3599. // }
  3600. //
  3601. // //透析模式
  3602. // for _, treatment := range treatments {
  3603. // if scheduals.ModeId == treatment.ID {
  3604. // dialysisSchedule[key].TreatmentMode = treatment
  3605. // break
  3606. // }
  3607. // }
  3608. // }
  3609. // //获取所有床位号
  3610. // if err == nil {
  3611. // c.ServeSuccessJSON(map[string]interface{}{
  3612. // "schedule": dialysisSchedule,
  3613. // "total": total,
  3614. // })
  3615. // } else {
  3616. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3617. // }
  3618. //
  3619. // } else {
  3620. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3621. // if err == nil {
  3622. // c.ServeSuccessJSON(map[string]interface{}{
  3623. // "schedule": dialysisSchedule,
  3624. // "total": total,
  3625. // })
  3626. // } else {
  3627. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3628. // }
  3629. // }
  3630. //}
  3631. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3632. patientId, _ := c.GetInt64("id", 0)
  3633. record_date, _ := c.GetInt64("record_date", 0)
  3634. adminUserInfo := c.GetAdminUserInfo()
  3635. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3636. var dialysisStatus int64
  3637. if dialysisOrder == nil { //没有透析记录
  3638. dialysisStatus = 0 //未透析
  3639. } else {
  3640. dialysisStatus = dialysisOrder.Stage
  3641. }
  3642. //用户基本信息
  3643. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3644. //接诊评估
  3645. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3646. //透前评估
  3647. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3648. //临时医嘱
  3649. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3650. //双人核对
  3651. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3652. //透析监测
  3653. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3654. //透后评估
  3655. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3656. //透析小结
  3657. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3658. //透析处方
  3659. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3660. if dialysisPrescription.ID == 0 {
  3661. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3662. c.ServeSuccessJSON(map[string]interface{}{
  3663. "patientInfo": schedualPatientInfo,
  3664. "dialysisPrescription": solution,
  3665. "receiverTreatmentAccess": receiverTreatmentAccess,
  3666. "predialysisEvaluation": PredialysisEvaluation,
  3667. "doctorAdvice": DoctorAdvice,
  3668. "doubleCheck": DoubleCheck,
  3669. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3670. "treatmentSummary": TreatmentSummary,
  3671. "monitorRecord": Record,
  3672. "dialysisStatus": dialysisStatus,
  3673. "dialysisOrder": dialysisOrder,
  3674. "isSolution": 1,
  3675. })
  3676. } else {
  3677. c.ServeSuccessJSON(map[string]interface{}{
  3678. "patientInfo": schedualPatientInfo,
  3679. "dialysisPrescription": dialysisPrescription,
  3680. "receiverTreatmentAccess": receiverTreatmentAccess,
  3681. "predialysisEvaluation": PredialysisEvaluation,
  3682. "doctorAdvice": DoctorAdvice,
  3683. "doubleCheck": DoubleCheck,
  3684. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3685. "treatmentSummary": TreatmentSummary,
  3686. "monitorRecord": Record,
  3687. "dialysisStatus": dialysisStatus,
  3688. "dialysisOrder": dialysisOrder,
  3689. "isSolution": 2,
  3690. })
  3691. }
  3692. }
  3693. func (c *DialysisApiController) CreateDoctorAdvice() {
  3694. patient, _ := c.GetInt64("id", 0)
  3695. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3696. record_date, _ := c.GetInt64("record_date", 0)
  3697. if patient <= 0 {
  3698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3699. return
  3700. }
  3701. adminUserInfo := c.GetAdminUserInfo()
  3702. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3703. if patientInfo.ID == 0 {
  3704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3705. return
  3706. }
  3707. var advice models.DoctorAdvice
  3708. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3709. if code > 0 {
  3710. c.ServeFailJSONWithSGJErrorCode(code)
  3711. return
  3712. }
  3713. if advice.ParentId > 0 {
  3714. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3715. if old.ID == 0 || old.PatientId != patient {
  3716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3717. return
  3718. }
  3719. if old.StopState == 1 || old.ExecutionState == 1 {
  3720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3721. return
  3722. }
  3723. if old.ParentId > 0 {
  3724. advice.ParentId = old.ParentId
  3725. }
  3726. advice.StartTime = old.StartTime
  3727. advice.AdviceDoctor = old.AdviceDoctor
  3728. advice.DeliveryWay = old.DeliveryWay
  3729. advice.ExecutionFrequency = old.ExecutionFrequency
  3730. }
  3731. advice.RecordDate = record_date
  3732. advice.DialysisOrderId = dialysis_id
  3733. advice.Status = 1
  3734. advice.CreatedTime = time.Now().Unix()
  3735. advice.UpdatedTime = time.Now().Unix()
  3736. advice.StopState = 2
  3737. advice.ExecutionState = 2
  3738. advice.AdviceType = 2
  3739. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3740. advice.PatientId = patient
  3741. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3742. err := service.CreateDoctorAdvice(&advice)
  3743. if err != nil {
  3744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3745. return
  3746. }
  3747. for _, subAdvice := range subAdivice {
  3748. subAdvice.ParentId = advice.ID
  3749. subAdvice.PatientId = patient
  3750. subAdvice.RecordDate = record_date
  3751. subAdvice.CreatedTime = time.Now().Unix()
  3752. subAdvice.UpdatedTime = time.Now().Unix()
  3753. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3754. }
  3755. service.CreateSubDoctorAdvice(subAdivice)
  3756. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3757. c.ServeSuccessJSON(map[string]interface{}{
  3758. "msg": "ok",
  3759. "advice": advice,
  3760. "subAdvice": subAdivices,
  3761. })
  3762. return
  3763. }
  3764. func (c *DialysisApiController) EditDoctorAdvice() {
  3765. patient, _ := c.GetInt64("patient", 0)
  3766. id, _ := c.GetInt64("id", 0)
  3767. parent_id, _ := c.GetInt64("parent_id", 0)
  3768. execution_time := c.GetString("execution_time")
  3769. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3770. // checker, _ := c.GetInt64("checker", 0)
  3771. if id <= 0 || patient <= 0 {
  3772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3773. return
  3774. }
  3775. adminUserInfo := c.GetAdminUserInfo()
  3776. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3777. if advice.ID == 0 || advice.PatientId != patient {
  3778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3779. return
  3780. }
  3781. if len(execution_time) <= 0 {
  3782. utils.ErrorLog("execution_time")
  3783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3784. return
  3785. }
  3786. execution_staff := adminUserInfo.AdminUser.Id
  3787. checker := adminUserInfo.AdminUser.Id
  3788. timeLayout2 := "2006-01-02 15:04"
  3789. loc, _ := time.LoadLocation("Local")
  3790. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3791. if errs != nil {
  3792. utils.ErrorLog(errs.Error())
  3793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3794. return
  3795. }
  3796. advices := models.DoctorAdvice{
  3797. ExecutionStaff: execution_staff,
  3798. ExecutionTime: theTime.Unix(),
  3799. Checker: checker,
  3800. UpdatedTime: time.Now().Unix(),
  3801. }
  3802. var err error
  3803. if parent_id > 0 {
  3804. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3805. } else {
  3806. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3807. }
  3808. if err != nil {
  3809. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3810. return
  3811. }
  3812. c.ServeSuccessJSON(map[string]interface{}{
  3813. "msg": "ok",
  3814. "advice": advice,
  3815. })
  3816. return
  3817. }
  3818. func (c *DialysisApiController) GetDoctorAdvice() {
  3819. patient, _ := c.GetInt64("patient_id", 0)
  3820. parent_id, _ := c.GetInt64("parent_id", 0)
  3821. adviceId, _ := c.GetInt64("id", 0)
  3822. if patient <= 0 {
  3823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3824. return
  3825. }
  3826. dminUserInfo := c.GetAdminUserInfo()
  3827. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3828. if patientInfo.ID == 0 {
  3829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3830. return
  3831. }
  3832. var subAdvice []*models.DoctorAdvice
  3833. var advice models.DoctorAdvice
  3834. if parent_id > 0 {
  3835. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3836. if advice.ID == 0 || advice.PatientId != patient {
  3837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3838. return
  3839. }
  3840. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3841. } else {
  3842. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3843. if advice.ID == 0 || advice.PatientId != patient {
  3844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3845. return
  3846. }
  3847. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3848. }
  3849. c.ServeSuccessJSON(map[string]interface{}{
  3850. "msg": "ok",
  3851. "advice": advice,
  3852. "subAdvice": subAdvice,
  3853. })
  3854. }
  3855. func (this *DialysisApiController) DelMonitor() {
  3856. recordID, _ := this.GetInt64("record_id")
  3857. patientID, _ := this.GetInt64("patient_id")
  3858. if recordID <= 0 || patientID <= 0 {
  3859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3860. return
  3861. }
  3862. adminInfo := this.GetAdminUserInfo()
  3863. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3864. if getPatientErr != nil {
  3865. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3867. return
  3868. } else if patient == nil {
  3869. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3870. return
  3871. }
  3872. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3873. if getMonitorErr != nil {
  3874. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3875. return
  3876. }
  3877. //if monitor != nil {
  3878. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3879. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3880. // if getPermissionErr != nil {
  3881. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3882. // return
  3883. // } else if headNursePermission == nil {
  3884. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3885. // return
  3886. // }
  3887. // }
  3888. //}
  3889. // 查询信息规挡的设置天数
  3890. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  3891. if infor.ID > 0 && infor.WeekDay > 0 {
  3892. var cha_time int64
  3893. timeNowStr := time.Now().Format("2006-01-02")
  3894. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3895. //今日的日期减去设置的日期
  3896. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3897. if cha_time >= monitor.MonitoringDate {
  3898. //查询审核是否允许
  3899. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId, 7)
  3900. //申请状态不允许的情况 拒绝修改
  3901. if infor.ApplicationStatus != 1 {
  3902. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3903. return
  3904. }
  3905. }
  3906. }
  3907. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3908. //记录日志
  3909. byterequest, _ := json.Marshal(monitor)
  3910. monitorRecordLog := models.XtMonitorRecordLog{
  3911. RecordDate: monitor.MonitoringDate,
  3912. PatientId: monitor.PatientId,
  3913. Module: 3,
  3914. AdminUserId: adminInfo.AdminUser.Id,
  3915. Ctime: time.Now().Unix(),
  3916. Mtime: 0,
  3917. Status: 1,
  3918. UserOrgId: monitor.UserOrgId,
  3919. ErrLog: string(byterequest),
  3920. Source: "电脑端删除监测",
  3921. }
  3922. service.CreateMonitorRecordLog(monitorRecordLog)
  3923. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  3924. redis := service.RedisClient()
  3925. //清空key 值
  3926. redis.Set(key, "", time.Second)
  3927. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  3928. redis.Set(keyOne, "", time.Second)
  3929. defer redis.Close()
  3930. if err != nil {
  3931. this.ErrorLog("删除透析监测记录失败:%v", err)
  3932. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3933. return
  3934. }
  3935. this.ServeSuccessJSON(map[string]interface{}{
  3936. "record_id": monitor.ID,
  3937. })
  3938. }
  3939. func (c *DialysisApiController) CreateMonitor() {
  3940. patient, _ := c.GetInt64("id", 0)
  3941. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3942. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3943. operate_time, _ := c.GetInt64("operate_time", 0)
  3944. // monitoring_time := c.GetString("monitoring_time")
  3945. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3946. breathing_rated := c.GetString("breathing_rated")
  3947. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3948. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3949. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3950. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3951. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3952. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3953. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3954. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3955. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3956. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3957. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3958. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3959. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3960. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3961. temperature, _ := c.GetFloat("temperature", 0)
  3962. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3963. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3964. conductivity, _ := c.GetFloat("conductivity", 0)
  3965. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3966. heparin, _ := c.GetFloat("heparin", 0)
  3967. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3968. ktv, _ := c.GetFloat("ktv", 0)
  3969. symptom := c.GetString("symptom")
  3970. dispose := c.GetString("dispose")
  3971. result := c.GetString("results")
  3972. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3973. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3974. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3975. replacement_speed, _ := c.GetFloat("replacement_speed")
  3976. dicarbonate, _ := c.GetFloat("dicarbonate")
  3977. monitoring_date = monitoring_date / 1000
  3978. // operate_time = operate_time / 1000
  3979. if patient <= 0 {
  3980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3981. return
  3982. }
  3983. adminUserInfo := c.GetAdminUserInfo()
  3984. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3985. if patientInfo.ID == 0 {
  3986. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3987. return
  3988. }
  3989. monitorRecord := models.MonitoringRecord{
  3990. PatientId: patient,
  3991. MonitoringDate: monitoring_date,
  3992. DialysisOrderId: dialysis_order_id,
  3993. OperateTime: operate_time,
  3994. // MonitoringTime: monitoring_time,
  3995. PulseFrequency: pulse_frequency,
  3996. BreathingRate: breathing_rated,
  3997. SystolicBloodPressure: systolic_blood_pressure,
  3998. DiastolicBloodPressure: diastolic_blood_pressure,
  3999. BloodPressureType: blood_pressure_type,
  4000. BloodFlowVolume: blood_flow_volume,
  4001. VenousPressure: venous_pressure,
  4002. VenousPressureType: venous_pressure_type,
  4003. TransmembranePressure: transmembrane_pressure,
  4004. TransmembranePressureType: transmembrane_pressure_type,
  4005. UltrafiltrationRate: ultrafiltration_rate,
  4006. UltrafiltrationVolume: ultrafiltration_volume,
  4007. SodiumConcentration: sodium_concentration,
  4008. ArterialPressure: arterial_pressure,
  4009. ArterialPressureType: arterial_pressure_type,
  4010. DialysateTemperature: dialysate_temperature,
  4011. Temperature: temperature,
  4012. ReplacementRate: replacement_rate,
  4013. DisplacementQuantity: displacement_quantity,
  4014. Ktv: ktv,
  4015. Symptom: symptom,
  4016. Dispose: dispose,
  4017. Result: result,
  4018. MonitoringNurse: monitoring_nurse,
  4019. Status: 1,
  4020. CreatedTime: time.Now().Unix(),
  4021. UpdatedTime: time.Now().Unix(),
  4022. UserOrgId: adminUserInfo.CurrentOrgId,
  4023. Conductivity: conductivity,
  4024. DisplacementFlowQuantity: displacement_flow_quantity,
  4025. Heparin: heparin,
  4026. DialysateFlow: dialysate_flow,
  4027. MonitorAnticoagulant: monitor_anticoagulant,
  4028. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  4029. ReplacementSpeed: replacement_speed,
  4030. Dicarbonate: dicarbonate,
  4031. }
  4032. // 查询信息规挡的设置天数
  4033. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  4034. if infor.ID > 0 && infor.WeekDay > 0 {
  4035. var cha_time int64
  4036. timeNowStr := time.Now().Format("2006-01-02")
  4037. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  4038. //今日的日期减去设置的日期
  4039. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  4040. if cha_time >= monitoring_date {
  4041. //查询审核是否允许
  4042. infor, _ := service.GetDialysisInformationByRecordDate(patient, monitoring_date, adminUserInfo.CurrentOrgId, 7)
  4043. //申请状态不允许的情况 拒绝修改
  4044. if infor.ApplicationStatus != 1 {
  4045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  4046. return
  4047. }
  4048. }
  4049. }
  4050. err := service.CreateMonitor(&monitorRecord)
  4051. finish := models.XtDialysisFinish{
  4052. IsFinish: 1,
  4053. UserOrgId: adminUserInfo.CurrentOrgId,
  4054. Status: 1,
  4055. Ctime: time.Now().Unix(),
  4056. Mtime: 0,
  4057. Module: 7,
  4058. RecordDate: monitoring_date,
  4059. Sourse: 1,
  4060. PatientId: patient,
  4061. }
  4062. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitoring_date, 7, patient)
  4063. if dialysisFinish.ID == 0 {
  4064. service.CreateDialysisFinish(finish)
  4065. }
  4066. redis := service.RedisClient()
  4067. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  4068. redis.Set(key, "", time.Second)
  4069. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  4070. redis.Set(keyOne, "", time.Second)
  4071. redis.Close()
  4072. if err != nil {
  4073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  4074. return
  4075. }
  4076. c.ServeSuccessJSON(map[string]interface{}{
  4077. "msg": "ok",
  4078. "monitor": monitorRecord,
  4079. })
  4080. return
  4081. }
  4082. // 已弃用
  4083. // func (c *DialysisApiController) CreateRecordData() {
  4084. // patient, _ := c.GetInt64("id", 0)
  4085. // status, _ := c.GetInt64("status", 0)
  4086. // now := time.Now()
  4087. // year, month, day := now.Date()
  4088. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  4089. // todayTimeStamp := today_time.Unix()
  4090. // if patient <= 0 {
  4091. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4092. // return
  4093. // }
  4094. // adminUserInfo := c.GetAdminUserInfo()
  4095. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  4096. // if patientInfo.ID == 0 {
  4097. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4098. // return
  4099. // }
  4100. // record := &models.DialysisOrder{
  4101. // DialysisDate: todayTimeStamp,
  4102. // UserOrgId: adminUserInfo.CurrentOrgId,
  4103. // PatientId: patient,
  4104. // Stage: status,
  4105. // Status: 1,
  4106. // CreatedTime: time.Now().Unix(),
  4107. // UpdatedTime: time.Now().Unix(),
  4108. // }
  4109. // if status == 1 {
  4110. // //创建透析记录
  4111. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  4112. // if err == nil {
  4113. // c.ServeSuccessJSON(map[string]interface{}{
  4114. // "dialysisOrder": record,
  4115. // })
  4116. // } else {
  4117. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4118. // }
  4119. // } else {
  4120. // record_id, _ := c.GetInt64("record_id", 0)
  4121. // //修改透析记录状态
  4122. // errs := service.ModifyDialysisRecord(record_id)
  4123. // //结束时候透析次数加1
  4124. // service.UpdateSolutionByPatientId(patient)
  4125. // if errs == nil {
  4126. // c.ServeSuccessJSON(map[string]interface{}{
  4127. // "dialysisOrder": record,
  4128. // })
  4129. // } else {
  4130. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4131. // }
  4132. // }
  4133. // }
  4134. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  4135. dataBody := make(map[string]interface{}, 0)
  4136. err := json.Unmarshal(data, &dataBody)
  4137. if err != nil {
  4138. utils.ErrorLog(err.Error())
  4139. code = enums.ErrorCodeParamWrong
  4140. return
  4141. }
  4142. timeLayout := "2006-01-02 "
  4143. timeLayout2 := "2006-01-02 15:04"
  4144. loc, _ := time.LoadLocation("Local")
  4145. if action == "create" {
  4146. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4147. utils.ErrorLog("advice_type")
  4148. code = enums.ErrorCodeParamWrong
  4149. return
  4150. }
  4151. adviceType := int64(dataBody["advice_type"].(float64))
  4152. if adviceType != 1 && adviceType != 2 {
  4153. utils.ErrorLog("advice_type != 1&&2")
  4154. code = enums.ErrorCodeParamWrong
  4155. return
  4156. }
  4157. advice.AdviceType = adviceType
  4158. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4159. utils.ErrorLog("advice_date")
  4160. code = enums.ErrorCodeParamWrong
  4161. return
  4162. }
  4163. adviceDate, _ := dataBody["advice_date"].(string)
  4164. if len(adviceDate) == 0 {
  4165. utils.ErrorLog("len(adviceDate) == 0")
  4166. code = enums.ErrorCodeParamWrong
  4167. return
  4168. }
  4169. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  4170. if err != nil {
  4171. utils.ErrorLog(err.Error())
  4172. code = enums.ErrorCodeParamWrong
  4173. return
  4174. }
  4175. advice.AdviceDate = theTime.Unix()
  4176. }
  4177. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4178. utils.ErrorLog("start_time")
  4179. code = enums.ErrorCodeParamWrong
  4180. return
  4181. }
  4182. startDate, _ := dataBody["start_time"].(string)
  4183. if len(startDate) == 0 {
  4184. utils.ErrorLog("len(startDate) == 0")
  4185. code = enums.ErrorCodeParamWrong
  4186. return
  4187. }
  4188. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  4189. if err != nil {
  4190. utils.ErrorLog(err.Error())
  4191. code = enums.ErrorCodeParamWrong
  4192. return
  4193. }
  4194. advice.StartTime = theTime.Unix()
  4195. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  4196. utils.ErrorLog("advice_name")
  4197. code = enums.ErrorCodeParamWrong
  4198. return
  4199. }
  4200. adviceName, _ := dataBody["advice_name"].(string)
  4201. if len(adviceName) == 0 {
  4202. utils.ErrorLog("len(advice_name) == 0")
  4203. code = enums.ErrorCodeParamWrong
  4204. return
  4205. }
  4206. advice.AdviceName = adviceName
  4207. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  4208. utils.ErrorLog("delivery_way")
  4209. code = enums.ErrorCodeParamWrong
  4210. return
  4211. }
  4212. deliveryWay, _ := dataBody["delivery_way"].(string)
  4213. if len(deliveryWay) == 0 {
  4214. utils.ErrorLog("len(deliveryWay) == 0")
  4215. code = enums.ErrorCodeParamWrong
  4216. return
  4217. }
  4218. advice.DeliveryWay = deliveryWay
  4219. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  4220. utils.ErrorLog("execution_frequency")
  4221. code = enums.ErrorCodeParamWrong
  4222. return
  4223. }
  4224. execution_frequency, _ := dataBody["execution_frequency"].(string)
  4225. if len(execution_frequency) == 0 {
  4226. utils.ErrorLog("len(execution_frequency) == 0")
  4227. code = enums.ErrorCodeParamWrong
  4228. return
  4229. }
  4230. advice.ExecutionFrequency = execution_frequency
  4231. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  4232. adviceDsc, _ := dataBody["advice_desc"].(string)
  4233. advice.AdviceDesc = adviceDsc
  4234. }
  4235. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  4236. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  4237. advice.DrugSpecUnit = drugSpecUnit
  4238. }
  4239. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  4240. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  4241. advice.SingleDose = singleDose
  4242. }
  4243. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  4244. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  4245. advice.SingleDoseUnit = singleDoseUnit
  4246. }
  4247. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  4248. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  4249. advice.PrescribingNumber = prescribingNumber
  4250. }
  4251. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  4252. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  4253. advice.PrescribingNumberUnit = prescribingNumberUnit
  4254. }
  4255. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  4256. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  4257. if len(thisContagions) > 0 {
  4258. for _, item := range thisContagions {
  4259. items := item.(map[string]interface{})
  4260. advice_name, _ := items["advice_name"].(string)
  4261. advice_desc, _ := items["advice_desc"].(string)
  4262. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  4263. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  4264. single_dose_unit, _ := items["single_dose_unit"].(string)
  4265. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  4266. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  4267. advice := &models.DoctorAdvice{
  4268. AdviceName: advice_name,
  4269. AdviceDesc: advice_desc,
  4270. SingleDose: single_dose,
  4271. SingleDoseUnit: single_dose_unit,
  4272. DrugSpecUnit: drug_spec_unit,
  4273. PrescribingNumber: prescribing_number,
  4274. PrescribingNumberUnit: prescribing_number_unit,
  4275. }
  4276. subAdvice = append(subAdvice, advice)
  4277. }
  4278. }
  4279. }
  4280. return
  4281. }
  4282. func (c *DialysisApiController) GetDialysisOrder() {
  4283. //xtno := c.GetString("xtno")
  4284. xtdate := c.GetString("xtdate")
  4285. patient_id, _ := c.GetInt64("patient_id")
  4286. timeLayout := "2006-01-02"
  4287. loc, _ := time.LoadLocation("Local")
  4288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  4289. if err != nil {
  4290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4291. return
  4292. }
  4293. xttime := theTime.Unix()
  4294. operatorIDs := make([]int64, 0)
  4295. adminUserInfo := c.GetAdminUserInfo()
  4296. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  4297. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  4298. //透析单
  4299. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4300. if dialysisOrder != nil {
  4301. if dialysisOrder.FinishNurse > 0 {
  4302. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  4303. }
  4304. if dialysisOrder.StartNurse > 0 {
  4305. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  4306. }
  4307. }
  4308. //透前评估
  4309. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4310. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  4311. //透后评估
  4312. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4313. if AssessmentAfterDislysis.Modifier > 0 {
  4314. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  4315. }
  4316. //上次透前评估
  4317. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4318. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4319. //透析处方
  4320. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4321. if dialysisPrescription.PrescriptionDoctor > 0 {
  4322. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  4323. }
  4324. //获取病人的透析模式
  4325. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4326. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4327. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4328. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4329. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4330. //获取透析处方
  4331. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4332. //获取临时医嘱
  4333. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4334. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  4335. //获取医嘱内容
  4336. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4337. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  4338. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4339. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4340. //获取上次的透后体重
  4341. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4342. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4343. //获取透析次数
  4344. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  4345. if len(DoctorAdvice) > 0 {
  4346. for _, item := range DoctorAdvice {
  4347. if item.AdviceDoctor > 0 {
  4348. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  4349. }
  4350. if item.ExecutionStaff > 0 {
  4351. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  4352. }
  4353. if item.Checker > 0 {
  4354. operatorIDs = append(operatorIDs, item.Checker)
  4355. }
  4356. }
  4357. }
  4358. //透析监测
  4359. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4360. //透析检测
  4361. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4362. //透析小结
  4363. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4364. //接诊评估
  4365. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4366. if receiverTreatmentAccess.Condition == 1 {
  4367. if len(receiverTreatmentAccess.AdmissionNumber) == 0 || receiverTreatmentAccess.AdmissionNumber == "" {
  4368. lastAcceptTreatment, _ := service.GetLastAcceptTreatment(adminUserInfo.CurrentOrgId, patientInfo.ID)
  4369. receiverTreatmentAccess.AdmissionNumber = lastAcceptTreatment.AdmissionNumber
  4370. receiverTreatmentAccess.HisDepartment = lastAcceptTreatment.HisDepartment
  4371. receiverTreatmentAccess.HisBed = lastAcceptTreatment.HisBed
  4372. }
  4373. }
  4374. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4375. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  4376. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4377. patientInfo.TotalDialysis = dialysis_count
  4378. }
  4379. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  4380. if xttime <= 1735574400 {
  4381. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4382. patientInfo.TotalDialysis = dialysis_count
  4383. }
  4384. if xttime >= 1735660800 {
  4385. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4386. patientInfo.TotalDialysis = dialysis_count
  4387. }
  4388. }
  4389. //相关操作对应的操作人
  4390. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  4391. operators, err := service.GetAdminUserEsTwo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  4392. //fmt.Println("operators------------------------------------", operators)
  4393. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  4394. //获取当前日期月份的第一天
  4395. firstmonth := service.GetFirstDateOfMonth(theTime)
  4396. firstMonthDate := firstmonth.Unix()
  4397. //获取当前月份的病人透析次数
  4398. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  4399. var hisAdvice []*models.HisDoctorAdviceInfo
  4400. var his_advices_one []*models.HisDoctorAdviceInfo
  4401. //获取his数据
  4402. hisAdvice, _ = service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4403. //针对茂名舒和
  4404. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  4405. if len(hisAdvice) > 0 {
  4406. for _, item := range hisAdvice {
  4407. drug, _ := service.GetDrugIsShow(item.DrugId, adminUserInfo.CurrentOrgId)
  4408. if drug.IsShow == 1 {
  4409. his_advices_one = append(his_advices_one, item)
  4410. }
  4411. }
  4412. }
  4413. } else {
  4414. if len(hisAdvice) > 0 {
  4415. for _, item := range hisAdvice {
  4416. his_advices_one = append(his_advices_one, item)
  4417. }
  4418. }
  4419. }
  4420. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  4421. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  4422. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  4423. var projects []*models.HisPrescriptionProject
  4424. projects, _ = service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4425. var projectsOne []*models.HisPrescriptionProject
  4426. //针对茂名舒和
  4427. if adminUserInfo.CurrentOrgId == 10666 || adminUserInfo.CurrentOrgId == 10644 {
  4428. if len(projects) > 0 {
  4429. for _, item := range projects {
  4430. if item.Type == 2 {
  4431. if item.HisProject.IsShow == 1 {
  4432. projectsOne = append(projectsOne, item)
  4433. }
  4434. }
  4435. if item.Type == 3 {
  4436. if item.GoodInfo.IsShow == 1 {
  4437. projectsOne = append(projectsOne, item)
  4438. }
  4439. }
  4440. }
  4441. }
  4442. } else {
  4443. for _, item := range projects {
  4444. projectsOne = append(projectsOne, item)
  4445. }
  4446. }
  4447. //获取诊断
  4448. prescriptionInfo, _ := service.GetPrescriptionInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4449. patientDiagnose, _ := service.FindPatientDianose(adminUserInfo.CurrentOrgId)
  4450. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  4451. numberList, _ := service.GetAllBedNumberList(adminUserInfo.CurrentOrgId)
  4452. now := time.Now()
  4453. // 计算当前是周几,周一为第1天,周日为第0天
  4454. weekday := now.Weekday()
  4455. // 计算当前日期是周几,并计算出周一的日期
  4456. // 通过减去当前是周几的偏移量再加1来实现(因为Weekday()返回的是从周日开始的索引,而我们想要从周一开始)
  4457. mondayone := now.AddDate(0, 0, -(int(weekday)+6)%7) // 或者使用 monday := now.Add(-time.Hour * 24 * (int(weekday)+6)%7)
  4458. // 设置开始时间为周一的00:00:00
  4459. startOfTheWeek := time.Date(mondayone.Year(), mondayone.Month(), mondayone.Day(), 0, 0, 0, 0, mondayone.Location())
  4460. // 设置结束时间为周日的23:59:59(周一的日期基础上加6天)
  4461. endOfTheWeek := startOfTheWeek.AddDate(0, 0, 6).Add(24*time.Hour - time.Second) // 或者使用 endOfTheWeek := monday.AddDate(0, 0, 7).Add(-time.Second)
  4462. var start_time = startOfTheWeek.Format("2006-01-02")
  4463. var end_time = endOfTheWeek.Format("2006-01-02")
  4464. var startTime int64
  4465. if len(start_time) > 0 {
  4466. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4467. if err != nil {
  4468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4469. return
  4470. }
  4471. startTime = theTime.Unix()
  4472. }
  4473. var endTime int64
  4474. if len(end_time) > 0 {
  4475. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4476. if err != nil {
  4477. utils.ErrorLog(err.Error())
  4478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4479. return
  4480. }
  4481. endTime = theTime.Unix()
  4482. }
  4483. if xttime < 1740931200 {
  4484. startTime = 1740326400
  4485. endTime = 1740844800
  4486. }
  4487. scheduleDialyCount, _ := service.GetPatientScheduleDialyCount(patientInfo.ID, startTime, endTime, adminUserInfo.CurrentOrgId)
  4488. dialysis_count := len(scheduleDialyCount)
  4489. var dialysis_count_str = "一周" + strconv.Itoa(dialysis_count) + "次"
  4490. if adminUserInfo.CurrentOrgId == 10742 {
  4491. PredialysisEvaluation.DialysisCount = dialysis_count_str
  4492. }
  4493. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  4494. // for _, item := range projects {
  4495. // var advice *models.HisDoctorAdviceInfo
  4496. // advice.ID = item.ID
  4497. // advice.Checker = item.Checker
  4498. // advice.CheckTime = item.CheckTime
  4499. // advice.CheckState = item.CheckState
  4500. // advice.ExecutionState = item.ExecutionState
  4501. // advice.ExecutionStaff = item.ExecutionStaff
  4502. // advice.PrescribingNumber = float64(item.Count)
  4503. // advice.PrescribingNumberUnit = item.Unit
  4504. // advice.AdviceDoctor = item.Doctor
  4505. // if item.Type == 3 {
  4506. // advice.AdviceName = item.GoodInfo.GoodName
  4507. // } else if item.Type == 2 {
  4508. // advice.AdviceName = item.HisProject.ProjectName
  4509. // }
  4510. // advice.StartTime = item.StartTime
  4511. // hisAdvice = append(hisAdvice, advice)
  4512. // }
  4513. //}
  4514. if config.IsOpen == 1 {
  4515. c.ServeSuccessJSON(map[string]interface{}{
  4516. "xtdate": xtdate,
  4517. "users": adminUser,
  4518. "patientInfo": patientInfo,
  4519. "PredialysisEvaluation": PredialysisEvaluation,
  4520. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4521. "dialysisPrescription": dialysisPrescription,
  4522. "advices": his_advices_one,
  4523. "monitors": Record,
  4524. "summary": TreatmentSummary,
  4525. "receiverTreatmentAccess": receiverTreatmentAccess,
  4526. "dialysisOrder": dialysisOrder,
  4527. "operators": operators,
  4528. "org_template_info": templateInfo,
  4529. "check": check,
  4530. "schedule": schedule,
  4531. "dialysisway": dialysisway,
  4532. "order": order,
  4533. "doctorAdvice": doctorAdvice,
  4534. "doctor": doctor,
  4535. "nurse": nurse,
  4536. "doctorAdevieInfo": doctorAdevieInfo,
  4537. "total": total,
  4538. "startNuse": startNuse,
  4539. "DoctorName": DoctorName,
  4540. "assessmentAfterDislysis": assessmentAfterDislysis,
  4541. "predialysName": predialysName,
  4542. "FinishNuse": FinishNuse,
  4543. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4544. "dialysiscount": dialysiscount,
  4545. "last_order": lastOrder,
  4546. "project_config": project_config,
  4547. "projects": projectsOne,
  4548. "prescriptionInfo": prescriptionInfo,
  4549. "patientDiagnose": patientDiagnose,
  4550. "lastSchedule": lastSchedule,
  4551. "numberList": numberList,
  4552. })
  4553. }
  4554. if config.IsOpen == 0 || config.IsOpen == 2 {
  4555. c.ServeSuccessJSON(map[string]interface{}{
  4556. "xtdate": xtdate,
  4557. "users": adminUser,
  4558. "patientInfo": patientInfo,
  4559. "PredialysisEvaluation": PredialysisEvaluation,
  4560. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  4561. "dialysisPrescription": dialysisPrescription,
  4562. "advices": DoctorAdvice,
  4563. "monitors": Record,
  4564. "summary": TreatmentSummary,
  4565. "receiverTreatmentAccess": receiverTreatmentAccess,
  4566. "dialysisOrder": dialysisOrder,
  4567. "operators": operators,
  4568. "org_template_info": templateInfo,
  4569. "check": check,
  4570. "schedule": schedule,
  4571. "dialysisway": dialysisway,
  4572. "order": order,
  4573. "doctorAdvice": doctorAdvice,
  4574. "doctor": doctor,
  4575. "nurse": nurse,
  4576. "doctorAdevieInfo": doctorAdevieInfo,
  4577. "total": total,
  4578. "startNuse": startNuse,
  4579. "DoctorName": DoctorName,
  4580. "assessmentAfterDislysis": assessmentAfterDislysis,
  4581. "predialysName": predialysName,
  4582. "FinishNuse": FinishNuse,
  4583. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  4584. "dialysiscount": dialysiscount,
  4585. "last_order": lastOrder,
  4586. "project_config": project_config,
  4587. "projects": projects,
  4588. "prescriptionInfo": prescriptionInfo,
  4589. "patientDiagnose": patientDiagnose,
  4590. "lastSchedule": lastSchedule,
  4591. "numberList": numberList,
  4592. })
  4593. }
  4594. }
  4595. func (c *DialysisApiController) GetLongAdvice() {
  4596. patient_id, _ := c.GetInt64("patient_id")
  4597. adminUserInfo := c.GetAdminUserInfo()
  4598. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4599. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4600. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4601. c.ServeSuccessJSON(map[string]interface{}{
  4602. "status": "1",
  4603. })
  4604. return
  4605. } else { //开启推送提醒
  4606. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4607. var advice_three []*models.DoctorAdvice
  4608. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4609. recordDateStr := time.Now().Format("2006-01-02")
  4610. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4611. nowtime := recordDate.Unix()
  4612. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4613. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4614. for _, advice := range advices {
  4615. if advice.FrequencyType == 3 {
  4616. t := time.Now()
  4617. week := int(t.Weekday())
  4618. switch week {
  4619. case 1:
  4620. if strings.Index(advice.WeekDay, "周一") == -1 {
  4621. advice_three = append(advice_three, advice)
  4622. }
  4623. break
  4624. case 2:
  4625. if strings.Index(advice.WeekDay, "周二") == -1 {
  4626. advice_three = append(advice_three, advice)
  4627. }
  4628. break
  4629. case 3:
  4630. if strings.Index(advice.WeekDay, "周三") == -1 {
  4631. advice_three = append(advice_three, advice)
  4632. }
  4633. break
  4634. case 4:
  4635. if strings.Index(advice.WeekDay, "周四") == -1 {
  4636. advice_three = append(advice_three, advice)
  4637. }
  4638. break
  4639. case 5:
  4640. if strings.Index(advice.WeekDay, "周五") == -1 {
  4641. advice_three = append(advice_three, advice)
  4642. }
  4643. break
  4644. case 6:
  4645. if strings.Index(advice.WeekDay, "周六") == -1 {
  4646. advice_three = append(advice_three, advice)
  4647. }
  4648. break
  4649. case 0:
  4650. if strings.Index(advice.WeekDay, "周日") == -1 {
  4651. advice_three = append(advice_three, advice)
  4652. }
  4653. break
  4654. }
  4655. }
  4656. }
  4657. for _, advice := range advices_two {
  4658. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4659. now := p.Unix()
  4660. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4661. dayStr2 := "-" + dayStr
  4662. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4663. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4664. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4665. for _, ad := range advices {
  4666. advice_three = append(advice_three, ad)
  4667. }
  4668. }
  4669. if err == nil {
  4670. c.ServeSuccessJSON(map[string]interface{}{
  4671. "status": "2",
  4672. "advices": advices,
  4673. "advices_two": RemoveRepeatedElement(advice_three),
  4674. "is_open_remind": config.IsOpenRemind,
  4675. })
  4676. }
  4677. }
  4678. }
  4679. func (c *DialysisApiController) GetLongAdviceOne() {
  4680. patient_id, _ := c.GetInt64("patient_id")
  4681. schedule_date := c.GetString("schedule_date")
  4682. adminUserInfo := c.GetAdminUserInfo()
  4683. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4684. timeLayout := "2006-01-02"
  4685. loc, _ := time.LoadLocation("Local")
  4686. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4687. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4688. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4689. c.ServeSuccessJSON(map[string]interface{}{
  4690. "status": "1",
  4691. })
  4692. return
  4693. } else { //开启推送提醒
  4694. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4695. var advice_three []*models.DoctorAdvice
  4696. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4697. //recordDateStr := time.Now().Format("2006-01-02")
  4698. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4699. //
  4700. //nowtime := recordDate.Unix()
  4701. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4702. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4703. for _, advice := range advices {
  4704. if advice.FrequencyType == 3 {
  4705. t := time.Now()
  4706. week := int(t.Weekday())
  4707. switch week {
  4708. case 1:
  4709. if strings.Index(advice.WeekDay, "周一") == -1 {
  4710. advice_three = append(advice_three, advice)
  4711. }
  4712. break
  4713. case 2:
  4714. if strings.Index(advice.WeekDay, "周二") == -1 {
  4715. advice_three = append(advice_three, advice)
  4716. }
  4717. break
  4718. case 3:
  4719. if strings.Index(advice.WeekDay, "周三") == -1 {
  4720. advice_three = append(advice_three, advice)
  4721. }
  4722. break
  4723. case 4:
  4724. if strings.Index(advice.WeekDay, "周四") == -1 {
  4725. advice_three = append(advice_three, advice)
  4726. }
  4727. break
  4728. case 5:
  4729. if strings.Index(advice.WeekDay, "周五") == -1 {
  4730. advice_three = append(advice_three, advice)
  4731. }
  4732. break
  4733. case 6:
  4734. if strings.Index(advice.WeekDay, "周六") == -1 {
  4735. advice_three = append(advice_three, advice)
  4736. }
  4737. break
  4738. case 0:
  4739. if strings.Index(advice.WeekDay, "周日") == -1 {
  4740. advice_three = append(advice_three, advice)
  4741. }
  4742. break
  4743. }
  4744. }
  4745. }
  4746. for _, advice := range advices_two {
  4747. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4748. now := p.Unix()
  4749. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4750. dayStr2 := "-" + dayStr
  4751. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4752. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4753. fmt.Println("oldTime--------------------------", oldTime)
  4754. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4755. fmt.Println("advices-------------------------", advices)
  4756. for _, ad := range advices {
  4757. advice_three = append(advice_three, ad)
  4758. }
  4759. }
  4760. if err == nil {
  4761. c.ServeSuccessJSON(map[string]interface{}{
  4762. "status": "2",
  4763. "advices": advices,
  4764. "advices_two": RemoveRepeatedElement(advice_three),
  4765. "is_open_remind": config.IsOpenRemind,
  4766. })
  4767. }
  4768. }
  4769. }
  4770. func (c *DialysisApiController) GetLongAdviceTwo() {
  4771. patient_id, _ := c.GetInt64("patient_id")
  4772. schedule_date, _ := c.GetInt64("schedule_date")
  4773. adminUserInfo := c.GetAdminUserInfo()
  4774. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4775. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4776. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4777. c.ServeSuccessJSON(map[string]interface{}{
  4778. "status": "1",
  4779. })
  4780. return
  4781. } else { //开启推送提醒
  4782. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4783. var advice_three []*models.DoctorAdvice
  4784. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4785. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4786. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4787. for _, advice := range advices {
  4788. if advice.FrequencyType == 3 {
  4789. t := time.Now()
  4790. week := int(t.Weekday())
  4791. switch week {
  4792. case 1:
  4793. if strings.Index(advice.WeekDay, "周一") == -1 {
  4794. advice_three = append(advice_three, advice)
  4795. }
  4796. break
  4797. case 2:
  4798. if strings.Index(advice.WeekDay, "周二") == -1 {
  4799. advice_three = append(advice_three, advice)
  4800. }
  4801. break
  4802. case 3:
  4803. if strings.Index(advice.WeekDay, "周三") == -1 {
  4804. advice_three = append(advice_three, advice)
  4805. }
  4806. break
  4807. case 4:
  4808. if strings.Index(advice.WeekDay, "周四") == -1 {
  4809. advice_three = append(advice_three, advice)
  4810. }
  4811. break
  4812. case 5:
  4813. if strings.Index(advice.WeekDay, "周五") == -1 {
  4814. advice_three = append(advice_three, advice)
  4815. }
  4816. break
  4817. case 6:
  4818. if strings.Index(advice.WeekDay, "周六") == -1 {
  4819. advice_three = append(advice_three, advice)
  4820. }
  4821. break
  4822. case 0:
  4823. if strings.Index(advice.WeekDay, "周日") == -1 {
  4824. advice_three = append(advice_three, advice)
  4825. }
  4826. break
  4827. }
  4828. }
  4829. }
  4830. for _, advice := range advices_two {
  4831. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4832. now := p.Unix()
  4833. fmt.Println("now-------------------------", now)
  4834. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4835. dayStr2 := "-" + dayStr
  4836. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4837. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4838. fmt.Println("oldTime--------------------------", oldTime)
  4839. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4840. for _, ad := range advices {
  4841. advice_three = append(advice_three, ad)
  4842. }
  4843. }
  4844. if err == nil {
  4845. c.ServeSuccessJSON(map[string]interface{}{
  4846. "status": "2",
  4847. "advices": advices,
  4848. "advices_two": RemoveRepeatedElement(advice_three),
  4849. "is_open_remind": config.IsOpenRemind,
  4850. })
  4851. }
  4852. }
  4853. }
  4854. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4855. newArr = make([]*models.DoctorAdvice, 0)
  4856. for i := 0; i < len(arr); i++ {
  4857. repeat := false
  4858. for j := i + 1; j < len(arr); j++ {
  4859. if arr[i].ID == arr[j].ID {
  4860. repeat = true
  4861. break
  4862. }
  4863. }
  4864. if !repeat {
  4865. newArr = append(newArr, arr[i])
  4866. }
  4867. }
  4868. return
  4869. }
  4870. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4871. patient, _ := c.GetInt64("id", 0)
  4872. groupNo, _ := c.GetInt64("groupno", 0)
  4873. if patient <= 0 {
  4874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4875. return
  4876. }
  4877. adminUserInfo := c.GetAdminUserInfo()
  4878. dataBody := make(map[string]interface{}, 0)
  4879. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4880. if err != nil {
  4881. utils.ErrorLog(err.Error())
  4882. return
  4883. }
  4884. utils.ErrorLog("%v", dataBody)
  4885. timeLayout := "2006-01-02 15:04"
  4886. loc, _ := time.LoadLocation("Local")
  4887. timeLayout2 := "2006-01-02"
  4888. loc2, _ := time.LoadLocation("Local")
  4889. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4890. utils.ErrorLog("advice_type")
  4891. return
  4892. }
  4893. adviceType := int64(2)
  4894. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4895. utils.ErrorLog("advice_date")
  4896. return
  4897. }
  4898. adviceDate, _ := dataBody["advice_date"].(string)
  4899. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4900. AdviceDate := theTime.Unix()
  4901. RecordDate := theTime.Unix()
  4902. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4903. utils.ErrorLog("start_time")
  4904. return
  4905. }
  4906. startTime, _ := dataBody["start_time"].(string)
  4907. if len(startTime) == 0 {
  4908. utils.ErrorLog("len(start_time) == 0")
  4909. return
  4910. }
  4911. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  4912. fmt.Println("theTimeUnix", theTimeUnix.Unix())
  4913. //if err != nil {
  4914. // utils.ErrorLog(err.Error())
  4915. // return
  4916. //}
  4917. StartTime := theTimeUnix.Unix()
  4918. fmt.Println("startTIME", StartTime)
  4919. Remark := ""
  4920. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4921. remark, _ := dataBody["remark"].(string)
  4922. Remark = remark
  4923. }
  4924. var advices []*models.GroupAdvice
  4925. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4926. utils.ErrorLog("advices")
  4927. return
  4928. }
  4929. adviceNames := dataBody["advices"].([]interface{})
  4930. for _, adviceNameMap := range adviceNames {
  4931. adviceNameM := adviceNameMap.(map[string]interface{})
  4932. var advice models.GroupAdvice
  4933. advice.Remark = Remark
  4934. advice.AdviceType = adviceType
  4935. advice.StartTime = StartTime
  4936. if advice.StartTime < 0 {
  4937. advice.StartTime = time.Now().Unix()
  4938. }
  4939. advice.AdviceDate = AdviceDate
  4940. advice.RecordDate = RecordDate
  4941. advice.Status = 1
  4942. advice.CreatedTime = time.Now().Unix()
  4943. advice.UpdatedTime = time.Now().Unix()
  4944. advice.StopState = 2
  4945. advice.ExecutionState = 2
  4946. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4947. advice.PatientId = patient
  4948. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4949. advice.IsSettle = 2
  4950. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4951. utils.ErrorLog("advice_name")
  4952. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4953. return
  4954. }
  4955. adviceName, _ := adviceNameM["advice_name"].(string)
  4956. if len(adviceName) == 0 {
  4957. utils.ErrorLog("len(advice_name) == 0")
  4958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4959. return
  4960. }
  4961. advice.AdviceName = adviceName
  4962. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4963. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4964. advice.DrugSpec = drugSpec
  4965. }
  4966. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4967. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4968. advice.AdviceDesc = adviceDesc
  4969. }
  4970. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4971. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4972. advice.DrugSpecUnit = drugSpecUnit
  4973. }
  4974. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4975. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4976. // advice.SingleDose = singleDose
  4977. //}
  4978. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4979. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4980. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4981. }
  4982. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4983. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4984. advice.SingleDoseUnit = singleDoseUnit
  4985. }
  4986. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4987. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4988. // advice.PrescribingNumber = prescribingNumber
  4989. //}
  4990. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4991. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4992. }
  4993. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4994. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4995. advice.PrescribingNumberUnit = prescribingNumberUnit
  4996. }
  4997. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4998. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4999. advice.DeliveryWay = deliveryWay
  5000. }
  5001. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5002. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5003. advice.ExecutionFrequency = executionFrequency
  5004. }
  5005. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  5006. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  5007. advice.FrequencyType = frequency_type
  5008. }
  5009. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  5010. day_count := int64(adviceNameM["day_count"].(float64))
  5011. advice.DayCount = day_count
  5012. }
  5013. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  5014. way := int64(adviceNameM["way"].(float64))
  5015. advice.Way = way
  5016. }
  5017. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  5018. drug_id := int64(adviceNameM["drug_id"].(float64))
  5019. advice.DrugId = drug_id
  5020. }
  5021. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  5022. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  5023. advice.DrugNameId = drug_name_id
  5024. }
  5025. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  5026. week_day, _ := adviceNameM["week_day"].(string)
  5027. advice.WeekDay = week_day
  5028. }
  5029. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  5030. template_id, _ := adviceNameM["template_id"].(string)
  5031. advice.TemplateId = template_id
  5032. }
  5033. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  5034. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  5035. advice.ExecutionFrequency = executionFrequency
  5036. }
  5037. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  5038. children := adviceNameM["child"].([]interface{})
  5039. if len(children) > 0 {
  5040. for _, childrenMap := range children {
  5041. childMap := childrenMap.(map[string]interface{})
  5042. var child models.GroupAdvice
  5043. child.Remark = Remark
  5044. child.AdviceType = adviceType
  5045. child.StartTime = StartTime
  5046. if child.StartTime < 0 {
  5047. child.StartTime = time.Now().Unix()
  5048. }
  5049. child.AdviceDate = AdviceDate
  5050. child.RecordDate = RecordDate
  5051. child.Status = 1
  5052. child.CreatedTime = time.Now().Unix()
  5053. child.UpdatedTime = time.Now().Unix()
  5054. child.StopState = 2
  5055. child.ExecutionState = 2
  5056. child.UserOrgId = adminUserInfo.CurrentOrgId
  5057. child.PatientId = patient
  5058. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  5059. child.IsSettle = 2
  5060. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  5061. utils.ErrorLog("child advice_name")
  5062. return
  5063. }
  5064. childAdviceName, _ := childMap["advice_name"].(string)
  5065. if len(childAdviceName) == 0 {
  5066. utils.ErrorLog("len(child advice_name) == 0")
  5067. return
  5068. }
  5069. child.AdviceName = childAdviceName
  5070. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  5071. childAdviceDesc, _ := childMap["advice_desc"].(string)
  5072. child.AdviceDesc = childAdviceDesc
  5073. }
  5074. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  5075. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  5076. child.DrugSpec = childDrugSpec
  5077. }
  5078. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  5079. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  5080. child.DrugSpecUnit = childDrugSpecUnit
  5081. }
  5082. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  5083. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  5084. child.SingleDose = childSingleDose
  5085. }
  5086. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  5087. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  5088. child.SingleDose = childMap["single_dose"].(float64)
  5089. }
  5090. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  5091. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  5092. child.Remark = childMap["remark"].(string)
  5093. }
  5094. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  5095. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  5096. child.DrugId = int64(childMap["drug_id"].(float64))
  5097. }
  5098. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  5099. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  5100. child.SingleDoseUnit = childSingleDoseUnit
  5101. }
  5102. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  5103. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  5104. child.PrescribingNumber = childPrescribingNumber
  5105. }
  5106. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  5107. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  5108. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  5109. }
  5110. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  5111. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  5112. child.PrescribingNumberUnit = childPrescribingNumberUnit
  5113. }
  5114. child.DeliveryWay = advice.DeliveryWay
  5115. child.ExecutionFrequency = advice.ExecutionFrequency
  5116. advice.Children = append(advice.Children, &child)
  5117. }
  5118. }
  5119. }
  5120. if advice.DrugId == 0 {
  5121. drug, _ := service.GetDoctorAdviceByAdviceName(advice.AdviceName, adminUserInfo.CurrentOrgId)
  5122. advice.DrugId = drug.ID
  5123. }
  5124. advices = append(advices, &advice)
  5125. }
  5126. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  5127. for _, item := range advices {
  5128. //记录日志
  5129. byterequest, _ := json.Marshal(item)
  5130. adviceLog := models.XtDoctorAdviceLog{
  5131. UserOrgId: item.UserOrgId,
  5132. PatientId: item.PatientId,
  5133. AdminUserId: adminUserInfo.AdminUser.Id,
  5134. Module: 1,
  5135. ErrLog: string(byterequest),
  5136. Status: 1,
  5137. Ctime: time.Now().Unix(),
  5138. Mtime: 0,
  5139. Source: "电脑端医嘱推送",
  5140. RecordDate: item.AdviceDate,
  5141. }
  5142. service.CreateDoctorAdviceLog(adviceLog)
  5143. }
  5144. //创建步骤表
  5145. finish := models.XtDialysisFinish{
  5146. IsFinish: 1,
  5147. UserOrgId: adminUserInfo.CurrentOrgId,
  5148. Status: 1,
  5149. Ctime: time.Now().Unix(),
  5150. Mtime: 0,
  5151. Module: 4,
  5152. RecordDate: AdviceDate,
  5153. Sourse: 1,
  5154. PatientId: patient,
  5155. }
  5156. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, AdviceDate, 4, patient)
  5157. if dialysisFinish.ID == 0 {
  5158. service.CreateDialysisFinish(finish)
  5159. }
  5160. redis := service.RedisClient()
  5161. formatAdviceDate := theTime.Format("2006-01-02")
  5162. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  5163. redis.Set(key, "", time.Second)
  5164. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  5165. redis.Set(keyOne, "", time.Second)
  5166. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  5167. redis.Set(keyFour, "", time.Second)
  5168. defer redis.Close()
  5169. if err != nil {
  5170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  5171. return
  5172. }
  5173. c.ServeSuccessJSON(map[string]interface{}{
  5174. "msg": "ok",
  5175. "advices": list,
  5176. })
  5177. return
  5178. }
  5179. func (c *DialysisApiController) GetSolution() {
  5180. patient_id, _ := c.GetInt64("patient_id")
  5181. mode_id, _ := c.GetInt64("mode_id")
  5182. adminUserInfo := c.GetAdminUserInfo()
  5183. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  5184. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdTen(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  5185. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  5186. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  5187. if err != nil {
  5188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5189. return
  5190. }
  5191. c.ServeSuccessJSON(map[string]interface{}{
  5192. "solution": solution,
  5193. "prescription": prescription,
  5194. "system_prescription": system_prescription,
  5195. "dialysisPrescription": dialysisPrescription,
  5196. })
  5197. }
  5198. func (c *DialysisApiController) GetSchedule() {
  5199. schedual_type, _ := c.GetInt64("schedual_type")
  5200. adminUserInfo := c.GetAdminUserInfo()
  5201. //timeLayout := "2006-01-02 15:04:05"
  5202. //
  5203. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  5204. //loc, _ := time.LoadLocation("Local")
  5205. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  5206. //scheduleTime := theStartTime.Unix()
  5207. scheduleTime, _ := c.GetInt64("record_date")
  5208. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  5209. c.ServeSuccessJSON(map[string]interface{}{
  5210. "number": deviceNumber,
  5211. })
  5212. }
  5213. func (this *DialysisApiController) GetTodayMonitor() {
  5214. thisTime := time.Now()
  5215. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  5216. timeLayout := "2006-01-02 15:04:05"
  5217. loc, _ := time.LoadLocation("Local")
  5218. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  5219. theAssessmentDateTime := theStartTime.Unix()
  5220. patientID, _ := this.GetInt64("patient_id")
  5221. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  5222. adminInfo := this.GetAdminUserInfo()
  5223. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  5224. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  5225. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  5226. var ultrafiltration_rate float64
  5227. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  5228. //针对福建医师汇 获取透前评估预增脱水量
  5229. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  5230. fmt.Println("透前评估数据", evaluation)
  5231. if prescription.ID > 0 {
  5232. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  5233. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  5234. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  5235. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5236. record.UltrafiltrationRate = ultrafiltration_rate
  5237. }
  5238. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  5239. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  5240. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  5241. record.UltrafiltrationRate = ultrafiltration_rate
  5242. }
  5243. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  5244. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  5245. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  5246. record.UltrafiltrationRate = ultrafiltration_rate
  5247. }
  5248. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  5249. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5250. record.UltrafiltrationRate = ultrafiltration_rate
  5251. }
  5252. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  5253. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5254. record.UltrafiltrationRate = ultrafiltration_rate
  5255. }
  5256. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  5257. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5258. record.UltrafiltrationRate = ultrafiltration_rate
  5259. }
  5260. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  5261. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  5262. record.UltrafiltrationRate = ultrafiltration_rate
  5263. }
  5264. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  5265. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5266. record.UltrafiltrationRate = ultrafiltration_rate
  5267. }
  5268. // 只针对方济医院
  5269. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  5270. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  5271. ultrafiltration_rate = value
  5272. record.UltrafiltrationRate = ultrafiltration_rate
  5273. }
  5274. //长沙南雅
  5275. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10340 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 9829 || adminInfo.CurrentOrgId == 10440 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  5276. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  5277. record.UltrafiltrationRate = ultrafiltration_rate
  5278. }
  5279. if adminInfo.CurrentOrgId == 10694 || adminInfo.CurrentOrgId == 10697 {
  5280. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  5281. ultrafiltration_rate = ultrafiltration_rate
  5282. }
  5283. }
  5284. }
  5285. // record.UltrafiltrationRate = ultrafiltration_rate
  5286. record.UltrafiltrationVolume = 0
  5287. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  5288. if ultrafiltration_rate > 0 {
  5289. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  5290. record.UltrafiltrationVolume = value
  5291. }
  5292. }
  5293. if template.TemplateId == 6 || template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 || template.TemplateId == 41 || template.TemplateId == 43 || template.TemplateId == 47 || template.TemplateId == 54 {
  5294. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  5295. if adminInfo.CurrentOrgId != 10735 {
  5296. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5297. record.UltrafiltrationVolume = ultrafiltration_volume
  5298. }
  5299. if adminInfo.CurrentOrgId == 10735 {
  5300. ultrafiltration_volume := math.Floor(float64(record.OperateTime+1800-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5301. record.UltrafiltrationVolume = ultrafiltration_volume
  5302. }
  5303. }
  5304. }
  5305. //长沙南雅
  5306. if adminInfo.CurrentOrgId == 10395 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10432 || adminInfo.CurrentOrgId == 10441 || adminInfo.CurrentOrgId == 10445 || adminInfo.CurrentOrgId == 10469 || adminInfo.CurrentOrgId == 10471 {
  5307. if ultrafiltration_rate > 0 {
  5308. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  5309. record.UltrafiltrationVolume = ultrafiltration_volume
  5310. }
  5311. }
  5312. if template.TemplateId == 47 || template.TemplateId == 54 {
  5313. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  5314. }
  5315. if adminInfo.CurrentOrgId == 10697 || adminInfo.CurrentOrgId == 10694 {
  5316. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate * 1000)
  5317. record.UltrafiltrationVolume = ultrafiltration_volume / 1000
  5318. }
  5319. this.ServeSuccessJSON(map[string]interface{}{
  5320. "monitor": record,
  5321. })
  5322. }
  5323. func (c *DialysisApiController) UploadDryWeight() {
  5324. patient_id, _ := c.GetInt64("id")
  5325. dry_weight, _ := c.GetFloat("dry_weight")
  5326. doctor_id, _ := c.GetInt64("doctor_id")
  5327. remark := c.GetString("remark")
  5328. adminUserInfo := c.GetAdminUserInfo()
  5329. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  5330. fmt.Println(err)
  5331. if err == gorm.ErrRecordNotFound {
  5332. dryWeight := &models.SgjPatientDryweight{
  5333. PatientId: patient_id,
  5334. DryWeight: dry_weight,
  5335. Remakes: remark,
  5336. Ctime: time.Now().Unix(),
  5337. Mtime: time.Now().Unix(),
  5338. Creator: doctor_id,
  5339. Status: 1,
  5340. UserOrgId: adminUserInfo.CurrentOrgId,
  5341. AdjustedValue: "/",
  5342. UserId: adminUserInfo.AdminUser.Id,
  5343. }
  5344. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5345. loc, _ := time.LoadLocation("Local")
  5346. nowTime := time.Now()
  5347. nowDay := nowTime.Format("2006-01-02")
  5348. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5349. redis := service.RedisClient()
  5350. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5351. redis.Set(keyOne, "", time.Second)
  5352. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5353. redis.Set(key, "", time.Second)
  5354. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5355. redis.Set(keyTwo, "", time.Second)
  5356. redis.Close()
  5357. if createErr == nil {
  5358. c.ServeSuccessJSON(map[string]interface{}{
  5359. "msg": "提交成功",
  5360. "weight": dryWeight,
  5361. })
  5362. }
  5363. } else {
  5364. dryWeight := &models.SgjPatientDryweight{
  5365. PatientId: patient_id,
  5366. DryWeight: dry_weight,
  5367. Remakes: remark,
  5368. Ctime: time.Now().Unix(),
  5369. Mtime: time.Now().Unix(),
  5370. Creator: doctor_id,
  5371. Status: 1,
  5372. UserOrgId: adminUserInfo.CurrentOrgId,
  5373. AdjustedValue: "/",
  5374. UserId: adminUserInfo.AdminUser.Id,
  5375. }
  5376. var value float64
  5377. value = dry_weight - weightAdjust.DryWeight
  5378. fmt.Println(value)
  5379. if value < 0 {
  5380. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  5381. } else if value == 0 {
  5382. dryWeight.AdjustedValue = "/"
  5383. } else if value > 0 {
  5384. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  5385. }
  5386. fmt.Println(value)
  5387. createErr := service.CreatePatientWeightAdjust(dryWeight)
  5388. //康桥
  5389. if adminUserInfo.CurrentOrgId == 10702 || adminUserInfo.CurrentOrgId == 10164 || adminUserInfo.CurrentOrgId == 10721 {
  5390. timeNowStr := time.Now().Format("2006-01-02")
  5391. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  5392. beforAssesment, _ := service.GetPatientAssesmentBefor(patient_id, timeNewDate.Unix(), adminUserInfo.CurrentOrgId)
  5393. dialysisPrescription, _ := service.GetPatientDialysisPrescription(patient_id, timeNewDate.Unix(), adminUserInfo.CurrentOrgId)
  5394. if beforAssesment.ID > 0 {
  5395. service.UpdatePatientAssesmentBefor(beforAssesment.ID, dry_weight)
  5396. var dewater_amount float64
  5397. dewater_amount = beforAssesment.WeightBefore - dry_weight - beforAssesment.AdditionalWeight
  5398. if adminUserInfo.CurrentOrgId != 10702 {
  5399. service.UpdatePatientDialysisPrscription(dialysisPrescription.ID, dewater_amount)
  5400. }
  5401. if adminUserInfo.CurrentOrgId == 10702 {
  5402. service.UpdatePatientDialysisPrscriptionOne(dialysisPrescription.ID, dewater_amount)
  5403. }
  5404. //获取key,清空redis
  5405. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_prescribe"
  5406. redis := service.RedisClient()
  5407. //清空key 值
  5408. redis.Set(key, "", time.Second)
  5409. keyOne := "scheduals_" + timeNowStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  5410. //清空key 值
  5411. redis.Set(keyOne, "", time.Second)
  5412. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dialysisPrescription.ModeId, 10) + ":dialysis_solution"
  5413. //清空key 值
  5414. redis.Set(keyTwo, "", time.Second)
  5415. keySix := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":prescriptions_list_all"
  5416. redis.Set(keySix, "", time.Second)
  5417. keySeven := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(timeNewDate.Unix(), 10) + ":dialysis_prescribe_by_mode"
  5418. redis.Set(keySeven, "", time.Second)
  5419. }
  5420. }
  5421. loc, _ := time.LoadLocation("Local")
  5422. nowTime := time.Now()
  5423. nowDay := nowTime.Format("2006-01-02")
  5424. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  5425. redis := service.RedisClient()
  5426. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  5427. redis.Set(keyOne, "", time.Second)
  5428. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  5429. redis.Set(key, "", time.Second)
  5430. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  5431. redis.Set(keyTwo, "", time.Second)
  5432. redis.Close()
  5433. if createErr == nil {
  5434. c.ServeSuccessJSON(map[string]interface{}{
  5435. "msg": "提交成功",
  5436. "weight": dryWeight,
  5437. })
  5438. }
  5439. }
  5440. }
  5441. func (this *DialysisApiController) GetFuncPurview() {
  5442. adminUserInfo := this.GetAdminUserInfo()
  5443. user_id := adminUserInfo.AdminUser.Id
  5444. app_id := adminUserInfo.CurrentAppId
  5445. org_id := adminUserInfo.CurrentOrgId
  5446. create_url := this.GetString("create_url")
  5447. modify_url := this.GetString("modify_url")
  5448. modify_other_url := this.GetString("modify_other_url")
  5449. del_url := this.GetString("del_url")
  5450. del_other_url := this.GetString("del_other_url")
  5451. exce_url := this.GetString("exce_url")
  5452. check_url := this.GetString("check_url")
  5453. modify_exce_url := this.GetString("modify_exce_url")
  5454. module, _ := this.GetInt64("module", 0)
  5455. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  5456. var is_has_create bool
  5457. var is_has_modify bool
  5458. var is_has_modify_other bool
  5459. var is_has_del bool
  5460. var is_has_del_other bool
  5461. var is_has_exce bool
  5462. var is_has_check bool
  5463. var is_has_modify_exce bool
  5464. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  5465. if adminUserInfo.AdminUser.Id != org.Creator {
  5466. if app_role != nil {
  5467. if len(app_role.RoleIds) > 0 {
  5468. roles := strings.Split(app_role.RoleIds, ",")
  5469. var userRolePurviews string
  5470. for _, item := range roles {
  5471. role_id, _ := strconv.ParseInt(item, 10, 64)
  5472. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  5473. if len(userRolePurviews) == 0 {
  5474. userRolePurviews = purviews
  5475. } else {
  5476. userRolePurviews = userRolePurviews + "," + purviews
  5477. }
  5478. }
  5479. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  5480. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  5481. for _, item := range funcPurviews {
  5482. //for _, url := range strings.Split(item.Urlfor,","){
  5483. if strings.Split(item.Urlfor, ",")[1] == create_url {
  5484. is_has_create = true
  5485. }
  5486. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  5487. is_has_modify = true
  5488. }
  5489. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  5490. is_has_modify_other = true
  5491. }
  5492. if strings.Split(item.Urlfor, ",")[1] == del_url {
  5493. is_has_del = true
  5494. }
  5495. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  5496. is_has_del_other = true
  5497. }
  5498. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  5499. is_has_exce = true
  5500. }
  5501. if strings.Split(item.Urlfor, ",")[1] == check_url {
  5502. is_has_check = true
  5503. }
  5504. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  5505. is_has_modify_exce = true
  5506. }
  5507. }
  5508. } else {
  5509. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  5510. return
  5511. }
  5512. this.ServeSuccessJSON(map[string]interface{}{
  5513. "is_has_create": is_has_create,
  5514. "is_has_modify": is_has_modify,
  5515. "is_has_modify_other": is_has_modify_other,
  5516. "is_has_del": is_has_del,
  5517. "is_has_del_other": is_has_del_other,
  5518. "is_has_exce": is_has_exce,
  5519. "is_has_check": is_has_check,
  5520. "is_has_modify_exce": is_has_modify_exce,
  5521. "module": module,
  5522. })
  5523. } else {
  5524. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  5525. return
  5526. }
  5527. } else {
  5528. this.ServeSuccessJSON(map[string]interface{}{
  5529. "is_has_create": true,
  5530. "is_has_modify": true,
  5531. "is_has_modify_other": true,
  5532. "is_has_del": true,
  5533. "is_has_del_other": true,
  5534. "is_has_exce": true,
  5535. "is_has_check": true,
  5536. "is_has_modify_exce": true,
  5537. "module": true,
  5538. })
  5539. }
  5540. }
  5541. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  5542. patient_id, _ := this.GetInt64("patient_id", 0)
  5543. advice_date, _ := this.GetInt64("advice_date")
  5544. adminUserInfo := this.GetAdminUserInfo()
  5545. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5546. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  5547. this.ServeSuccessJSON(map[string]interface{}{
  5548. "doctorAdvice": doctorAdvice,
  5549. "hisDoctorAdvice": hisDoctorAdvice,
  5550. })
  5551. }
  5552. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  5553. change_type, _ := this.GetInt64("type", 0)
  5554. record_date := this.GetString("record_time")
  5555. patient_id, _ := this.GetInt64("patient_id", 0)
  5556. timeLayout := "2006-01-02"
  5557. loc, _ := time.LoadLocation("Local")
  5558. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  5559. record_time := theAdviceRecordTime.Unix()
  5560. adminUserInfo := this.GetAdminUserInfo()
  5561. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  5562. if err == nil {
  5563. if len(advices) == 0 {
  5564. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  5565. return
  5566. } else {
  5567. this.ServeSuccessJSON(map[string]interface{}{
  5568. "advices": advices,
  5569. "schedule": sch,
  5570. })
  5571. return
  5572. }
  5573. } else {
  5574. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5575. return
  5576. }
  5577. }
  5578. func (c *DialysisApiController) GetDialysisGoods() {
  5579. schedualDate := c.GetString("schedule_date")
  5580. schedule_type, _ := c.GetInt64("schedule_type")
  5581. partition_id, _ := c.GetInt64("partition_id")
  5582. page, _ := c.GetInt("page")
  5583. limit, _ := c.GetInt("limit")
  5584. keywords := c.GetString("keywords")
  5585. patient_id, _ := c.GetInt64("patient_id")
  5586. good_type, _ := c.GetInt64("good_type")
  5587. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  5588. if parseDateErr != nil && len(schedualDate) != 0 {
  5589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5590. return
  5591. }
  5592. schedualEndDate := int64(0)
  5593. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  5594. if parseDateErr != nil && len(schedualDate) != 0 {
  5595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5596. return
  5597. }
  5598. schedualEndDate = endDate.Unix()
  5599. adminUser := c.GetAdminUserInfo()
  5600. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  5601. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  5602. if err == gorm.ErrRecordNotFound {
  5603. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5604. var ids []int64
  5605. for _, item := range list {
  5606. ids = append(ids, item.PatientId)
  5607. }
  5608. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5609. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5610. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5611. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5612. item.LastAutomaticReduceDetail = goodUser
  5613. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5614. }
  5615. c.ServeSuccessJSON(map[string]interface{}{
  5616. "dialysis_goods": dialysisGoods,
  5617. "good_type": goodTypes,
  5618. "total": total,
  5619. })
  5620. return
  5621. } else if err == nil {
  5622. //获取当天排班的每个患者的库存使用情况
  5623. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  5624. var ids []int64
  5625. for _, item := range list {
  5626. ids = append(ids, item.PatientId)
  5627. }
  5628. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  5629. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  5630. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5631. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  5632. fmt.Println(goodUser)
  5633. fmt.Println(lastGoodUserDetial)
  5634. item.LastAutomaticReduceDetail = goodUser
  5635. item.LastDialysisBeforePrepare = lastGoodUserDetial
  5636. }
  5637. if err == nil {
  5638. c.ServeSuccessJSON(map[string]interface{}{
  5639. "dialysis_goods": dialysisGoods,
  5640. "good_type": goodTypes,
  5641. "total": total,
  5642. })
  5643. return
  5644. } else {
  5645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5646. return
  5647. }
  5648. } else if err != nil {
  5649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5650. return
  5651. }
  5652. }
  5653. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  5654. start_time := c.GetString("start_time")
  5655. end_time := c.GetString("end_time")
  5656. timeLayout := "2006-01-02"
  5657. loc, _ := time.LoadLocation("Local")
  5658. var theStartTime int64
  5659. if len(start_time) > 0 {
  5660. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5661. if err != nil {
  5662. utils.ErrorLog(err.Error())
  5663. }
  5664. theStartTime = theTime.Unix()
  5665. }
  5666. var theEndtTime int64
  5667. if len(end_time) > 0 {
  5668. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5669. if err != nil {
  5670. utils.ErrorLog(err.Error())
  5671. }
  5672. theEndtTime = theTime.Unix()
  5673. }
  5674. adminUser := c.GetAdminUserInfo()
  5675. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  5676. if err == nil {
  5677. c.ServeSuccessJSON(map[string]interface{}{
  5678. "stock_out": outInfo,
  5679. })
  5680. return
  5681. } else {
  5682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5683. return
  5684. }
  5685. }
  5686. func (c *DialysisApiController) GetRoleList() {
  5687. orgId := c.GetAdminUserInfo().CurrentOrgId
  5688. admin_user_id, _ := c.GetInt64("admin_user_id")
  5689. list, err := service.GetRoleList(orgId, admin_user_id)
  5690. if err == nil {
  5691. c.ServeSuccessJSON(map[string]interface{}{
  5692. "adminRole": list,
  5693. })
  5694. return
  5695. } else {
  5696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5697. return
  5698. }
  5699. }
  5700. func (c *DialysisApiController) GetInitPrintData() {
  5701. patient_id, _ := c.GetInt64("patient_id")
  5702. record_date, _ := c.GetInt64("record_date")
  5703. orgId := c.GetAdminUserInfo().CurrentOrgId
  5704. schedule, _ := service.GetPatientBySchedule(patient_id, record_date, orgId)
  5705. list, err := service.GetInitPrintData(patient_id, record_date, orgId, schedule.ModeId)
  5706. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  5707. if err == nil {
  5708. c.ServeSuccessJSON(map[string]interface{}{
  5709. "list": list,
  5710. "assessmentAfterDislysis": assessmentAfterDislysis,
  5711. })
  5712. return
  5713. } else {
  5714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5715. return
  5716. }
  5717. }
  5718. func (c *DialysisApiController) GetInitPrintDataOne() {
  5719. patient_id, _ := c.GetInt64("patient_id")
  5720. start_time := c.GetString("record_date")
  5721. timeLayout := "2006-01-02"
  5722. loc, _ := time.LoadLocation("Local")
  5723. var theStartTime int64
  5724. if len(start_time) > 0 {
  5725. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5726. if err != nil {
  5727. utils.ErrorLog(err.Error())
  5728. }
  5729. theStartTime = theTime.Unix()
  5730. }
  5731. orgId := c.GetAdminUserInfo().CurrentOrgId
  5732. schedule, _ := service.GetPatientBySchedule(patient_id, theStartTime, orgId)
  5733. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId, schedule.ModeId)
  5734. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  5735. if err == nil {
  5736. c.ServeSuccessJSON(map[string]interface{}{
  5737. "list": list,
  5738. "assessmentAfterDislysis": assessmentAfterDislysis,
  5739. })
  5740. return
  5741. } else {
  5742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5743. return
  5744. }
  5745. }
  5746. // 新接口
  5747. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  5748. keyword := this.GetString("keywords")
  5749. limit, _ := this.GetInt64("limit")
  5750. page, _ := this.GetInt64("page")
  5751. partition_id, _ := this.GetInt64("partition_id")
  5752. schedule_type, _ := this.GetInt64("schedule_type")
  5753. start_time := this.GetString("schedule_date")
  5754. advice_ids := this.GetString("ids")
  5755. var ids []string
  5756. if advice_ids != "" {
  5757. ids = strings.Split(advice_ids, ",")
  5758. }
  5759. timeLayout := "2006-01-02"
  5760. loc, _ := time.LoadLocation("Local")
  5761. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5762. orgId := this.GetAdminUserInfo().CurrentOrgId
  5763. _, config := service.FindXTHisRecordByOrgId(orgId)
  5764. goodType, _ := service.GetAllGoodType(orgId)
  5765. if config.IsOpen != 1 {
  5766. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5767. if err == nil {
  5768. this.ServeSuccessJSON(map[string]interface{}{
  5769. "list": list,
  5770. "total": total,
  5771. "config": config,
  5772. "goodType": goodType,
  5773. })
  5774. return
  5775. } else {
  5776. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5777. return
  5778. }
  5779. }
  5780. if config.IsOpen == 1 {
  5781. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5782. if err == nil {
  5783. this.ServeSuccessJSON(map[string]interface{}{
  5784. "list": list,
  5785. "total": total,
  5786. "config": config,
  5787. "goodType": goodType,
  5788. })
  5789. return
  5790. }
  5791. }
  5792. }
  5793. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  5794. keyword := this.GetString("keywords")
  5795. limit, _ := this.GetInt64("limit")
  5796. page, _ := this.GetInt64("page")
  5797. partition_id, _ := this.GetInt64("partition_id")
  5798. schedule_type, _ := this.GetInt64("schedule_type")
  5799. start_time := this.GetString("schedule_date")
  5800. ids := this.GetString("ids")
  5801. var idArray []string
  5802. if ids != "" {
  5803. idArray = strings.Split(ids, ",")
  5804. }
  5805. timeLayout := "2006-01-02"
  5806. loc, _ := time.LoadLocation("Local")
  5807. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5808. orgId := this.GetAdminUserInfo().CurrentOrgId
  5809. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5810. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5811. //获取长期医嘱
  5812. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5813. _, config := service.FindXTHisRecordByOrgId(orgId)
  5814. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  5815. if err == nil {
  5816. this.ServeSuccessJSON(map[string]interface{}{
  5817. "list": list,
  5818. "total": total,
  5819. "adviceList": adviceList,
  5820. "config": config,
  5821. "drugList": drugList,
  5822. "tablelist": tablelist,
  5823. })
  5824. return
  5825. } else {
  5826. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5827. return
  5828. }
  5829. }
  5830. func (this *DialysisApiController) SaveDialysisSetting() {
  5831. orgId := this.GetAdminUserInfo().CurrentOrgId
  5832. device_number_set, _ := this.GetInt64("device_number_set")
  5833. device_type_set, _ := this.GetInt64("device_type_set")
  5834. name_set, _ := this.GetInt64("name_set")
  5835. admission_number_set, _ := this.GetInt64("admission_number_set")
  5836. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  5837. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  5838. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  5839. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  5840. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  5841. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  5842. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  5843. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  5844. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  5845. mode_id_set, _ := this.GetInt64("mode_id_set")
  5846. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  5847. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  5848. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  5849. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  5850. kalium_set, _ := this.GetInt64("kalium_set")
  5851. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  5852. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  5853. glucose_set, _ := this.GetInt64("glucose_set")
  5854. sodium_set, _ := this.GetInt64("sodium_set")
  5855. calcium_set, _ := this.GetInt64("calcium_set")
  5856. blood_access_set, _ := this.GetInt64("blood_access_set")
  5857. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  5858. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  5859. cuhong_set, _ := this.GetInt64("cuhong_set")
  5860. zuoka_set, _ := this.GetInt64("zuoka_set")
  5861. difenzi_set, _ := this.GetInt64("difenzi_set")
  5862. gansuna_set, _ := this.GetInt64("gansuna_set")
  5863. zhetangtie_set, _ := this.GetInt64("zhetangtie_set")
  5864. niaojimei_set, _ := this.GetInt64("niaojimei_set")
  5865. dialysis_strainer_set, _ := this.GetInt64("dialysis_strainer_set")
  5866. dialysisSetting := models.XtDialysisSetting{
  5867. Sodium: sodium_set,
  5868. Calcium: calcium_set,
  5869. BloodAccess: blood_access_set,
  5870. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  5871. DisplaceLiquiPart: displace_liqui_part_set,
  5872. UserOrgId: orgId,
  5873. Status: 1,
  5874. DeviceNumber: device_number_set,
  5875. DeviceType: device_type_set,
  5876. Name: name_set,
  5877. AdmissionNumber: admission_number_set,
  5878. DialysisNo: dialysis_no_set,
  5879. WeightBefor: weight_befor_set,
  5880. DryWeight: dry_weight_set,
  5881. BloodPressure: blood_pressure_set,
  5882. UltrafiltrationVolume: ultrafiltration_volume_set,
  5883. InternalFistula: internal_fistula_set,
  5884. BloodFlowVolume: blood_flow_volume_set,
  5885. Anticoagulant: anticoagulant_set,
  5886. SealingFluidDispose: sealing_fluid_dispose_set,
  5887. ModeId: mode_id_set,
  5888. DialysisTime: dialysis_time_set,
  5889. DialysisDialyszers: dialysis_dialyszers_set,
  5890. DialysisIrrigation: dialysis_irrigation_set,
  5891. Gaijiliang: gaijiliang_set,
  5892. Kalium: kalium_set,
  5893. DisplaceLiquiValue: displace_liqui_value_set,
  5894. Bicarbonate: bicarbonate_set,
  5895. Glucose: glucose_set,
  5896. Ctime: time.Now().Unix(),
  5897. Mtime: time.Now().Unix(),
  5898. CuhongSet: cuhong_set,
  5899. ZuokaSet: zuoka_set,
  5900. DifenziSet: difenzi_set,
  5901. GansunaSet: gansuna_set,
  5902. ZhetangtieSet: zhetangtie_set,
  5903. NiaojimeiSet: niaojimei_set,
  5904. DialysisStrainerSet: dialysis_strainer_set,
  5905. }
  5906. err := service.SaveDialysisSetting(dialysisSetting)
  5907. if err == nil {
  5908. this.ServeSuccessJSON(map[string]interface{}{
  5909. "dialysisSetting": dialysisSetting,
  5910. })
  5911. return
  5912. } else {
  5913. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5914. return
  5915. }
  5916. }
  5917. func (this *DialysisApiController) GetDialysisSetting() {
  5918. orgId := this.GetAdminUserInfo().CurrentOrgId
  5919. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5920. this.ServeSuccessJSON(map[string]interface{}{
  5921. "dialysisSett": dialysisSett,
  5922. })
  5923. return
  5924. }
  5925. func (this *DialysisApiController) GetDialysisParameterList() {
  5926. keyword := this.GetString("keywords")
  5927. limit, _ := this.GetInt64("limit")
  5928. page, _ := this.GetInt64("page")
  5929. //partition_id, _ := this.GetInt64("partition_id")
  5930. partion_type := this.GetString("partition_id")
  5931. idSplit := strings.Split(partion_type, ",")
  5932. schedule_type, _ := this.GetInt64("schedule_type")
  5933. start_time := this.GetString("schedule_date")
  5934. timeLayout := "2006-01-02"
  5935. loc, _ := time.LoadLocation("Local")
  5936. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5937. orgId := this.GetAdminUserInfo().CurrentOrgId
  5938. scheduids := this.GetString("ids")
  5939. var ids []string
  5940. if scheduids != "" {
  5941. ids = strings.Split(scheduids, ",")
  5942. }
  5943. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  5944. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5945. if err == nil {
  5946. this.ServeSuccessJSON(map[string]interface{}{
  5947. "list": list,
  5948. "total": total,
  5949. "dialysisSett": dialysisSett,
  5950. })
  5951. return
  5952. } else {
  5953. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5954. return
  5955. }
  5956. }
  5957. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  5958. orgId := this.GetAdminUserInfo().CurrentOrgId
  5959. schedule_type, _ := this.GetInt64("schedule_type")
  5960. //partion_type, _ := this.GetInt64("partion_type")
  5961. start_time := this.GetString("selected_date")
  5962. partion_type := this.GetString("partion_type")
  5963. var ids []string
  5964. ids = strings.Split(partion_type, ",")
  5965. timeLayout := "2006-01-02"
  5966. loc, _ := time.LoadLocation("Local")
  5967. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5968. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  5969. if err == nil {
  5970. this.ServeSuccessJSON(map[string]interface{}{
  5971. "list": list,
  5972. })
  5973. return
  5974. } else {
  5975. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5976. return
  5977. }
  5978. }
  5979. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  5980. orgId := this.GetAdminUserInfo().CurrentOrgId
  5981. schedule_type, _ := this.GetInt64("schedule_type")
  5982. //partion_type, _ := this.GetInt64("partion_type")
  5983. partion_type := this.GetString("partion_type")
  5984. var ids []string
  5985. ids = strings.Split(partion_type, ",")
  5986. start_time := this.GetString("selected_date")
  5987. timeLayout := "2006-01-02"
  5988. loc, _ := time.LoadLocation("Local")
  5989. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5990. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  5991. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  5992. //获取长期医嘱
  5993. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5994. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5995. _, config := service.FindXTHisRecordByOrgId(orgId)
  5996. if err == nil {
  5997. this.ServeSuccessJSON(map[string]interface{}{
  5998. "list": list,
  5999. "drug": drug,
  6000. "adviceList": adviceList,
  6001. "config": config,
  6002. "tablelist": tablelist,
  6003. })
  6004. return
  6005. } else {
  6006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6007. return
  6008. }
  6009. }
  6010. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  6011. orgId := this.GetAdminUserInfo().CurrentOrgId
  6012. schedule_type, _ := this.GetInt64("schedule_type")
  6013. partion_type, _ := this.GetInt64("partion_type")
  6014. start_time := this.GetString("selected_date")
  6015. timeLayout := "2006-01-02"
  6016. loc, _ := time.LoadLocation("Local")
  6017. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6018. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  6019. if err == nil {
  6020. this.ServeSuccessJSON(map[string]interface{}{
  6021. "list": list,
  6022. })
  6023. return
  6024. } else {
  6025. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6026. return
  6027. }
  6028. }
  6029. func (this *DialysisApiController) SaveHisDialysis() {
  6030. var ids []string
  6031. advice_ids := this.GetString("ids")
  6032. ids = strings.Split(advice_ids, ",")
  6033. orgId := this.GetAdminUserInfo().CurrentOrgId
  6034. service.SaveHisDialysis(orgId, ids)
  6035. returnData := make(map[string]interface{}, 0)
  6036. returnData["msg"] = "ok"
  6037. this.ServeSuccessJSON(returnData)
  6038. return
  6039. }
  6040. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  6041. orgId := this.GetAdminUserInfo().CurrentOrgId
  6042. schedule_type, _ := this.GetInt64("schedule_type")
  6043. //partion_type, _ := this.GetInt64("partion_type")
  6044. partion_type := this.GetString("partion_type")
  6045. var ids []string
  6046. ids = strings.Split(partion_type, ",")
  6047. start_time := this.GetString("selected_date")
  6048. timeLayout := "2006-01-02"
  6049. loc, _ := time.LoadLocation("Local")
  6050. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6051. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  6052. this.ServeSuccessJSON(map[string]interface{}{
  6053. "list": list,
  6054. })
  6055. return
  6056. }
  6057. func (this *DialysisApiController) GetPatientSchedule() {
  6058. orgId := this.GetAdminUserInfo().CurrentOrgId
  6059. patient_id, _ := this.GetInt64("patient_id")
  6060. schedule_date, _ := this.GetInt64("schedule_date")
  6061. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  6062. this.ServeSuccessJSON(map[string]interface{}{
  6063. "schedulePatient": schedulePatient,
  6064. })
  6065. }
  6066. func (c *DialysisApiController) GetSchedulePrintList() {
  6067. page, _ := c.GetInt64("page", 1)
  6068. limit, _ := c.GetInt64("limit", 10)
  6069. schedulType, _ := c.GetInt64("schedule_type", 0)
  6070. partitionType, _ := c.GetInt64("partition_type", 0)
  6071. keywords := c.GetString("keywords")
  6072. schedule_date := c.GetString("schedule_date")
  6073. timeLayout := "2006-01-02"
  6074. loc, _ := time.LoadLocation("Local")
  6075. var theStartTime int64
  6076. if len(schedule_date) > 0 {
  6077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  6078. if err != nil {
  6079. utils.ErrorLog(err.Error())
  6080. }
  6081. theStartTime = theTime.Unix()
  6082. }
  6083. adminUserInfo := c.GetAdminUserInfo()
  6084. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  6085. for _, item := range list {
  6086. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  6087. item.DialysisOrderTwenty = order
  6088. }
  6089. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  6090. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  6091. c.ServeSuccessJSON(map[string]interface{}{
  6092. "list": list,
  6093. "total": total,
  6094. "numberList": numberList,
  6095. "listOne": listOne,
  6096. })
  6097. }
  6098. func (this *DialysisApiController) GetSolutionListByOrgId() {
  6099. orgId := this.GetAdminUserInfo().CurrentOrgId
  6100. list, _ := service.GetSolutionListByOrgId(orgId)
  6101. for _, item := range list {
  6102. //获取该模式最新的1条数据
  6103. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  6104. //更新状态值
  6105. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  6106. }
  6107. this.ServeSuccessJSON(map[string]interface{}{
  6108. "list": list,
  6109. })
  6110. }
  6111. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  6112. orgId := this.GetAdminUserInfo().CurrentOrgId
  6113. is_open, _ := this.GetInt64("is_open")
  6114. idsStr := this.GetString("str")
  6115. recordIDStrs := strings.Split(idsStr, ",")
  6116. start_time := this.GetString("advice_date")
  6117. exec_time, _ := this.GetInt64("exec_time")
  6118. timeLayout := "2006-01-02"
  6119. loc, _ := time.LoadLocation("Local")
  6120. var startTime int64
  6121. if len(start_time) > 0 {
  6122. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6123. if err != nil {
  6124. //fmt.Println(err)
  6125. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6126. return
  6127. }
  6128. startTime = theTime.Unix()
  6129. }
  6130. config, _ := service.GetDrugOpenConfigOne(orgId)
  6131. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6132. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6133. //his医嘱
  6134. if is_open == 1 {
  6135. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  6136. //查找未执行医嘱
  6137. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  6138. for _, item := range list {
  6139. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  6140. this.ServeSuccessJSON(map[string]interface{}{
  6141. "msg": "3",
  6142. })
  6143. return
  6144. }
  6145. }
  6146. for _, item := range groupList {
  6147. for _, it := range list {
  6148. if item.DrugId == it.DrugId {
  6149. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6150. }
  6151. }
  6152. }
  6153. for _, item := range groupList {
  6154. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6155. var sum_out_count int64
  6156. for _, it := range item.ChildDoctorAdvice {
  6157. var prescribing_number int64
  6158. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  6159. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6160. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6161. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6162. }
  6163. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6164. prescribing_number = parseIntPrescribingNumber
  6165. }
  6166. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6167. prescribing_number = parseIntPrescribingNumber
  6168. }
  6169. sum_out_count += prescribing_number
  6170. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6171. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6172. //库存不足
  6173. if sum_out_count > drugStockOut.FlushCount {
  6174. this.ServeSuccessJSON(map[string]interface{}{
  6175. "msg": "2",
  6176. "drug": medical,
  6177. })
  6178. return
  6179. }
  6180. }
  6181. }
  6182. creater := this.GetAdminUserInfo().AdminUser.Id
  6183. //执行出库逻辑
  6184. for _, item := range list {
  6185. hisadvice := &models.HisDoctorAdviceInfo{
  6186. ID: item.ID,
  6187. UserOrgId: item.UserOrgId,
  6188. PatientId: item.PatientId,
  6189. AdviceType: item.AdviceType,
  6190. AdviceDate: item.AdviceDate,
  6191. StartTime: item.StartTime,
  6192. AdviceName: item.AdviceName,
  6193. AdviceDesc: item.AdviceDesc,
  6194. ReminderDate: item.ReminderDate,
  6195. SingleDose: item.SingleDose,
  6196. SingleDoseUnit: item.SingleDoseUnit,
  6197. DrugSpec: item.DrugSpec,
  6198. DrugSpecUnit: item.DrugSpecUnit,
  6199. PrescribingNumber: item.PrescribingNumber,
  6200. PrescribingNumberUnit: item.PrescribingNumberUnit,
  6201. DeliveryWay: item.DeliveryWay,
  6202. ExecutionFrequency: item.ExecutionFrequency,
  6203. AdviceDoctor: item.AdviceDoctor,
  6204. Status: 1,
  6205. CreatedTime: item.CreatedTime,
  6206. UpdatedTime: item.UpdatedTime,
  6207. AdviceAffirm: item.AdviceAffirm,
  6208. Remark: item.Remark,
  6209. StopTime: item.StopTime,
  6210. StopReason: item.StopReason,
  6211. StopDoctor: item.StopDoctor,
  6212. StopState: item.StopState,
  6213. ParentId: item.ParentId,
  6214. ExecutionTime: item.ExecutionTime,
  6215. ExecutionStaff: creater,
  6216. ExecutionState: item.ExecutionState,
  6217. Checker: item.Checker,
  6218. RecordDate: item.RecordDate,
  6219. DialysisOrderId: item.DialysisOrderId,
  6220. CheckTime: item.CheckTime,
  6221. CheckState: item.CheckState,
  6222. RemindType: item.RemindType,
  6223. FrequencyType: item.FrequencyType,
  6224. DayCount: item.DayCount,
  6225. WeekDay: item.WeekDay,
  6226. TemplateId: item.TemplateId,
  6227. Modifier: item.Modifier,
  6228. Way: item.Way,
  6229. DrugId: item.DrugId,
  6230. ExecutionFrequencyId: item.ExecutionFrequencyId,
  6231. }
  6232. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6233. if medical.IsUse == 2 {
  6234. if config.IsOpen != 1 {
  6235. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6236. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  6237. }
  6238. //不通过药房发药
  6239. if pharmacyConfig.IsOpen != 1 {
  6240. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  6241. }
  6242. //查询默认仓库
  6243. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6244. //查询默认仓库剩余多少库存
  6245. var sum_count int64
  6246. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6247. for _, its := range stockInfo {
  6248. if its.MaxUnit == medical.MaxUnit {
  6249. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6250. }
  6251. sum_count += its.StockMaxNumber + its.StockMinNumber
  6252. }
  6253. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6254. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6255. }
  6256. }
  6257. info := models.HisDoctorAdviceInfo{
  6258. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6259. ExecutionTime: exec_time,
  6260. ExecutionState: 1,
  6261. UpdatedTime: time.Now().Unix(),
  6262. }
  6263. //执行医嘱
  6264. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  6265. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6266. redis := service.RedisClient()
  6267. //清空key 值
  6268. redis.Set(key, "", time.Second)
  6269. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6270. redis.Set(keyTwo, "", time.Second)
  6271. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6272. redis.Set(keyThree, "", time.Second)
  6273. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6274. theTime := toTime.Format("2006-01-02")
  6275. fmt.Println("theTIME", theTime)
  6276. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  6277. redis.Set(keyFour, "", time.Second)
  6278. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6279. redis.Set(keyFive, "", time.Second)
  6280. }
  6281. } else {
  6282. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  6283. //查找未执行医嘱
  6284. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  6285. for _, item := range groupList {
  6286. for _, it := range list {
  6287. if item.DrugId == it.DrugId {
  6288. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  6289. }
  6290. }
  6291. }
  6292. for _, item := range groupList {
  6293. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6294. var sum_out_count int64
  6295. for _, it := range item.ChildDoctorAdvice {
  6296. var prescribing_number int64
  6297. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  6298. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6299. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6300. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6301. }
  6302. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6303. prescribing_number = parseIntPrescribingNumber
  6304. }
  6305. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6306. prescribing_number = parseIntPrescribingNumber
  6307. }
  6308. sum_out_count += prescribing_number
  6309. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6310. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6311. //库存不足
  6312. if sum_out_count > drugStockOut.FlushCount {
  6313. this.ServeSuccessJSON(map[string]interface{}{
  6314. "msg": "2",
  6315. "drug": medical,
  6316. })
  6317. return
  6318. }
  6319. }
  6320. }
  6321. for _, item := range list {
  6322. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6323. dadvice := &models.DoctorAdvice{
  6324. ID: item.ID,
  6325. UserOrgId: item.UserOrgId,
  6326. PatientId: item.PatientId,
  6327. AdviceType: item.AdviceType,
  6328. AdviceDate: item.AdviceDate,
  6329. StartTime: item.StartTime,
  6330. AdviceName: item.AdviceName,
  6331. AdviceDesc: item.AdviceDesc,
  6332. ReminderDate: item.ReminderDate,
  6333. SingleDose: item.SingleDose,
  6334. SingleDoseUnit: item.SingleDoseUnit,
  6335. DrugSpec: item.DrugSpec,
  6336. DrugSpecUnit: item.DrugSpecUnit,
  6337. PrescribingNumber: item.PrescribingNumber,
  6338. PrescribingNumberUnit: item.PrescribingNumberUnit,
  6339. DeliveryWay: item.DeliveryWay,
  6340. ExecutionFrequency: item.ExecutionFrequency,
  6341. AdviceDoctor: item.AdviceDoctor,
  6342. Status: 1,
  6343. CreatedTime: item.CreatedTime,
  6344. UpdatedTime: item.UpdatedTime,
  6345. AdviceAffirm: item.AdviceAffirm,
  6346. Remark: item.Remark,
  6347. StopTime: item.StopTime,
  6348. StopReason: item.StopReason,
  6349. StopDoctor: item.StopDoctor,
  6350. StopState: item.StopState,
  6351. ParentId: item.ParentId,
  6352. ExecutionTime: item.ExecutionTime,
  6353. ExecutionStaff: item.ExecutionStaff,
  6354. ExecutionState: item.ExecutionState,
  6355. Checker: item.Checker,
  6356. RecordDate: item.ReminderDate,
  6357. DialysisOrderId: item.DialysisOrderId,
  6358. CheckTime: item.CheckTime,
  6359. CheckState: item.CheckState,
  6360. RemindType: item.RemindType,
  6361. FrequencyType: item.FrequencyType,
  6362. DayCount: item.DayCount,
  6363. WeekDay: item.WeekDay,
  6364. TemplateId: item.TemplateId,
  6365. Modifier: item.Modifier,
  6366. Way: item.Way,
  6367. DrugId: item.DrugId,
  6368. }
  6369. if medical.IsUse == 2 {
  6370. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6371. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  6372. }
  6373. if pharmacyConfig.IsOpen != 1 {
  6374. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  6375. }
  6376. //更新字典里面的库存
  6377. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6378. var sum_count int64
  6379. for _, its := range stockInfo {
  6380. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6381. if its.MaxUnit == baseDrug.MaxUnit {
  6382. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6383. }
  6384. sum_count += its.StockMaxNumber + its.StockMinNumber
  6385. }
  6386. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6387. //剩余库存
  6388. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6389. }
  6390. info := models.DoctorAdvice{
  6391. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6392. ExecutionTime: exec_time,
  6393. ExecutionState: 1,
  6394. UpdatedTime: time.Now().Unix(),
  6395. }
  6396. //执行医嘱
  6397. service.UpdateDoctorAdviceExecution(info, item.ID)
  6398. }
  6399. }
  6400. this.ServeSuccessJSON(map[string]interface{}{
  6401. "msg": "1",
  6402. })
  6403. return
  6404. }
  6405. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  6406. orgId := this.GetAdminUserInfo().CurrentOrgId
  6407. idsStr := this.GetString("str")
  6408. recordIDStrs := strings.Split(idsStr, ",")
  6409. start_time := this.GetString("advice_date")
  6410. timeLayout := "2006-01-02"
  6411. loc, _ := time.LoadLocation("Local")
  6412. var startTime int64
  6413. if len(start_time) > 0 {
  6414. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6415. if err != nil {
  6416. //fmt.Println(err)
  6417. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6418. return
  6419. }
  6420. startTime = theTime.Unix()
  6421. }
  6422. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6423. if config.IsOpen == 1 {
  6424. creater := this.GetAdminUserInfo().AdminUser.Id
  6425. //查询未核对的医嘱
  6426. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  6427. for _, item := range advicelist {
  6428. if item.ExecutionStaff == creater {
  6429. this.ServeSuccessJSON(map[string]interface{}{
  6430. "msg": "2",
  6431. "advice": item,
  6432. })
  6433. return
  6434. }
  6435. service.CheckHisDoctorAdvice(item.ID, creater)
  6436. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6437. redis := service.RedisClient()
  6438. //清空key 值
  6439. redis.Set(key, "", time.Second)
  6440. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6441. redis.Set(keyTwo, "", time.Second)
  6442. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6443. redis.Set(keyThree, "", time.Second)
  6444. theTime := time.Now()
  6445. recordDate := theTime.Format("2006-01-02")
  6446. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6447. redis.Set(keyFour, "", time.Second)
  6448. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6449. redis.Set(keyFive, "", time.Second)
  6450. }
  6451. } else {
  6452. //查询未核对的医嘱
  6453. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  6454. creater := this.GetAdminUserInfo().AdminUser.Id
  6455. for _, item := range advicelist {
  6456. if item.ExecutionStaff == creater {
  6457. this.ServeSuccessJSON(map[string]interface{}{
  6458. "msg": "2",
  6459. "advice": item,
  6460. })
  6461. return
  6462. }
  6463. service.CheckDoctorAdvice(item.ID, creater)
  6464. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  6465. redis := service.RedisClient()
  6466. //清空key 值
  6467. redis.Set(key, "", time.Second)
  6468. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  6469. redis.Set(keyTwo, "", time.Second)
  6470. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  6471. redis.Set(keyThree, "", time.Second)
  6472. theTime := time.Now()
  6473. recordDate := theTime.Format("2006-01-02")
  6474. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  6475. redis.Set(keyFour, "", time.Second)
  6476. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  6477. redis.Set(keyFive, "", time.Second)
  6478. }
  6479. }
  6480. this.ServeSuccessJSON(map[string]interface{}{
  6481. "msg": "1",
  6482. })
  6483. return
  6484. }
  6485. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  6486. orgId := this.GetAdminUserInfo().CurrentOrgId
  6487. is_open, _ := this.GetInt64("is_open")
  6488. idsStr := this.GetString("str")
  6489. recordIDStrs := strings.Split(idsStr, ",")
  6490. start_time := this.GetString("advice_date")
  6491. timeLayout := "2006-01-02"
  6492. loc, _ := time.LoadLocation("Local")
  6493. var startTime int64
  6494. if len(start_time) > 0 {
  6495. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6496. if err != nil {
  6497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6498. return
  6499. }
  6500. startTime = theTime.Unix()
  6501. }
  6502. if is_open == 1 {
  6503. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  6504. } else {
  6505. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  6506. }
  6507. this.ServeSuccessJSON(map[string]interface{}{
  6508. "msg": "1",
  6509. })
  6510. return
  6511. }
  6512. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  6513. advice_id, _ := this.GetInt64("advice_id")
  6514. start_time := this.GetString("advice_date")
  6515. orgId := this.GetAdminUserInfo().CurrentOrgId
  6516. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  6517. exec_time, _ := this.GetInt64("exec_time")
  6518. //his医嘱
  6519. if config.IsOpen == 1 {
  6520. //查询医嘱
  6521. advice, _ := service.GetHisDocById(advice_id, orgId)
  6522. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  6523. this.ServeSuccessJSON(map[string]interface{}{
  6524. "msg": "3",
  6525. })
  6526. return
  6527. }
  6528. medical, _ := service.GetBaseDrugMedical(orgId)
  6529. var prescribing_number int64
  6530. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6531. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6532. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6533. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6534. }
  6535. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6536. prescribing_number = parseIntPrescribingNumber
  6537. }
  6538. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6539. prescribing_number = parseIntPrescribingNumber
  6540. }
  6541. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6542. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6543. //库存不足
  6544. if prescribing_number > drugStockOut.FlushCount {
  6545. this.ServeSuccessJSON(map[string]interface{}{
  6546. "msg": "2",
  6547. "drug": medical,
  6548. })
  6549. return
  6550. }
  6551. info := models.HisDoctorAdviceInfo{
  6552. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6553. ExecutionTime: exec_time,
  6554. ExecutionState: 1,
  6555. UpdatedTime: time.Now().Unix(),
  6556. }
  6557. //执行医嘱
  6558. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  6559. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  6560. redis := service.RedisClient()
  6561. //清空key 值
  6562. redis.Set(key, "", time.Second)
  6563. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  6564. redis.Set(keyTwo, "", time.Second)
  6565. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  6566. redis.Set(keyThree, "", time.Second)
  6567. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  6568. theTime := toTime.Format("2006-01-02")
  6569. fmt.Println("theTIME", theTime)
  6570. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  6571. redis.Set(keyFour, "", time.Second)
  6572. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  6573. redis.Set(keyFive, "", time.Second)
  6574. //出库
  6575. if prescribing_number <= drugStockOut.FlushCount {
  6576. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6577. //执行出库逻辑
  6578. hisadvice := &models.HisDoctorAdviceInfo{
  6579. ID: advice.ID,
  6580. UserOrgId: advice.UserOrgId,
  6581. PatientId: advice.PatientId,
  6582. AdviceType: advice.AdviceType,
  6583. AdviceDate: advice.AdviceDate,
  6584. StartTime: advice.StartTime,
  6585. AdviceName: advice.AdviceName,
  6586. AdviceDesc: advice.AdviceDesc,
  6587. ReminderDate: advice.ReminderDate,
  6588. SingleDose: advice.SingleDose,
  6589. SingleDoseUnit: advice.SingleDoseUnit,
  6590. DrugSpec: advice.DrugSpec,
  6591. DrugSpecUnit: advice.DrugSpecUnit,
  6592. PrescribingNumber: advice.PrescribingNumber,
  6593. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6594. DeliveryWay: advice.DeliveryWay,
  6595. ExecutionFrequency: advice.ExecutionFrequency,
  6596. AdviceDoctor: advice.AdviceDoctor,
  6597. Status: 1,
  6598. CreatedTime: advice.CreatedTime,
  6599. UpdatedTime: advice.UpdatedTime,
  6600. AdviceAffirm: advice.AdviceAffirm,
  6601. Remark: advice.Remark,
  6602. StopTime: advice.StopTime,
  6603. StopReason: advice.StopReason,
  6604. StopDoctor: advice.StopDoctor,
  6605. StopState: advice.StopState,
  6606. ParentId: advice.ParentId,
  6607. ExecutionTime: advice.ExecutionTime,
  6608. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6609. ExecutionState: advice.ExecutionState,
  6610. Checker: advice.Checker,
  6611. RecordDate: advice.RecordDate,
  6612. DialysisOrderId: advice.DialysisOrderId,
  6613. CheckTime: advice.CheckTime,
  6614. CheckState: advice.CheckState,
  6615. RemindType: advice.RemindType,
  6616. FrequencyType: advice.FrequencyType,
  6617. DayCount: advice.DayCount,
  6618. WeekDay: advice.WeekDay,
  6619. TemplateId: advice.TemplateId,
  6620. Modifier: advice.Modifier,
  6621. Way: advice.Way,
  6622. DrugId: advice.DrugId,
  6623. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  6624. }
  6625. if medical.IsUse == 2 {
  6626. if config.IsOpen != 1 {
  6627. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6628. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6629. }
  6630. //不通过药房发药
  6631. if pharmacyConfig.IsOpen != 1 {
  6632. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  6633. }
  6634. //查询默认仓库
  6635. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  6636. //查询默认仓库剩余多少库存
  6637. var sum_count int64
  6638. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6639. for _, its := range stockInfo {
  6640. if its.MaxUnit == medical.MaxUnit {
  6641. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6642. }
  6643. sum_count += its.StockMaxNumber + its.StockMinNumber
  6644. }
  6645. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6646. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6647. }
  6648. }
  6649. }
  6650. this.ServeSuccessJSON(map[string]interface{}{
  6651. "msg": "1",
  6652. })
  6653. return
  6654. }
  6655. if config.IsOpen == 2 || config.IsOpen == 0 {
  6656. advice, _ := service.GetBloodDocById(advice_id, orgId)
  6657. medical, _ := service.GetBaseDrugMedical(orgId)
  6658. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  6659. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6660. var prescribing_number int64
  6661. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  6662. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6663. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6664. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6665. }
  6666. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6667. prescribing_number = parseIntPrescribingNumber
  6668. }
  6669. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6670. prescribing_number = parseIntPrescribingNumber
  6671. }
  6672. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6673. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6674. //库存不足
  6675. if prescribing_number > drugStockOut.FlushCount {
  6676. this.ServeSuccessJSON(map[string]interface{}{
  6677. "msg": "2",
  6678. "drug": medical,
  6679. })
  6680. return
  6681. }
  6682. info := models.DoctorAdvice{
  6683. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6684. ExecutionTime: exec_time,
  6685. ExecutionState: 1,
  6686. UpdatedTime: time.Now().Unix(),
  6687. }
  6688. //执行医嘱
  6689. service.UpdateDoctorAdviceExecution(info, advice.ID)
  6690. dadvice := &models.DoctorAdvice{
  6691. ID: advice.ID,
  6692. UserOrgId: advice.UserOrgId,
  6693. PatientId: advice.PatientId,
  6694. AdviceType: advice.AdviceType,
  6695. AdviceDate: advice.AdviceDate,
  6696. StartTime: advice.StartTime,
  6697. AdviceName: advice.AdviceName,
  6698. AdviceDesc: advice.AdviceDesc,
  6699. ReminderDate: advice.ReminderDate,
  6700. SingleDose: advice.SingleDose,
  6701. SingleDoseUnit: advice.SingleDoseUnit,
  6702. DrugSpec: advice.DrugSpec,
  6703. DrugSpecUnit: advice.DrugSpecUnit,
  6704. PrescribingNumber: advice.PrescribingNumber,
  6705. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6706. DeliveryWay: advice.DeliveryWay,
  6707. ExecutionFrequency: advice.ExecutionFrequency,
  6708. AdviceDoctor: advice.AdviceDoctor,
  6709. Status: 1,
  6710. CreatedTime: advice.CreatedTime,
  6711. UpdatedTime: advice.UpdatedTime,
  6712. AdviceAffirm: advice.AdviceAffirm,
  6713. Remark: advice.Remark,
  6714. StopTime: advice.StopTime,
  6715. StopReason: advice.StopReason,
  6716. StopDoctor: advice.StopDoctor,
  6717. StopState: advice.StopState,
  6718. ParentId: advice.ParentId,
  6719. ExecutionTime: advice.ExecutionTime,
  6720. ExecutionStaff: advice.ExecutionStaff,
  6721. ExecutionState: advice.ExecutionState,
  6722. Checker: advice.Checker,
  6723. RecordDate: advice.ReminderDate,
  6724. DialysisOrderId: advice.DialysisOrderId,
  6725. CheckTime: advice.CheckTime,
  6726. CheckState: advice.CheckState,
  6727. RemindType: advice.RemindType,
  6728. FrequencyType: advice.FrequencyType,
  6729. DayCount: advice.DayCount,
  6730. WeekDay: advice.WeekDay,
  6731. TemplateId: advice.TemplateId,
  6732. Modifier: advice.Modifier,
  6733. Way: advice.Way,
  6734. DrugId: advice.DrugId,
  6735. }
  6736. if medical.IsUse == 2 {
  6737. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6738. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6739. }
  6740. if pharmacyConfig.IsOpen != 1 {
  6741. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6742. }
  6743. //更新字典里面的库存
  6744. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6745. var sum_count int64
  6746. for _, its := range stockInfo {
  6747. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6748. if its.MaxUnit == baseDrug.MaxUnit {
  6749. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6750. }
  6751. sum_count += its.StockMaxNumber + its.StockMinNumber
  6752. }
  6753. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6754. //剩余库存
  6755. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6756. }
  6757. }
  6758. this.ServeSuccessJSON(map[string]interface{}{
  6759. "msg": "1",
  6760. })
  6761. return
  6762. }
  6763. func (this *DialysisApiController) GetDialysisAdviceToday() {
  6764. orgId := this.GetAdminUserInfo().CurrentOrgId
  6765. schedule_type, _ := this.GetInt64("schedule_type")
  6766. //partion_type, _ := this.GetInt64("partion_type")
  6767. partion_type := this.GetString("partion_type")
  6768. var ids []string
  6769. ids = strings.Split(partion_type, ",")
  6770. start_time := this.GetString("selected_date")
  6771. timeLayout := "2006-01-02"
  6772. loc, _ := time.LoadLocation("Local")
  6773. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6774. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6775. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6776. _, config := service.FindXTHisRecordByOrgId(orgId)
  6777. appId := this.GetAdminUserInfo().CurrentAppId
  6778. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6779. manufacturerList, _ := service.GetAllManufacturerList(orgId)
  6780. if err == nil {
  6781. this.ServeSuccessJSON(map[string]interface{}{
  6782. "list": list,
  6783. "drug": drug,
  6784. "config": config,
  6785. "doctorList": doctorList,
  6786. "manufacturerList": manufacturerList,
  6787. })
  6788. return
  6789. } else {
  6790. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6791. return
  6792. }
  6793. }
  6794. func (this *DialysisApiController) GetDialysisProject() {
  6795. orgId := this.GetAdminUserInfo().CurrentOrgId
  6796. schedule_type, _ := this.GetInt64("schedule_type")
  6797. partion_type := this.GetString("partion_type")
  6798. var ids []string
  6799. ids = strings.Split(partion_type, ",")
  6800. start_time := this.GetString("selected_date")
  6801. timeLayout := "2006-01-02"
  6802. loc, _ := time.LoadLocation("Local")
  6803. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6804. list, err := service.GetDialysisProjectSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6805. if err == nil {
  6806. this.ServeSuccessJSON(map[string]interface{}{
  6807. "list": list,
  6808. })
  6809. return
  6810. } else {
  6811. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6812. return
  6813. }
  6814. }
  6815. func (this *DialysisApiController) GetMobileScheduleList() {
  6816. orgId := this.GetAdminUserInfo().CurrentOrgId
  6817. schedule, _ := service.GetMobileScheduleList(orgId)
  6818. if len(schedule) > 0 {
  6819. for _, its := range schedule {
  6820. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6821. //its.DialysisPrescription = prescription
  6822. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6823. //its.MonitoringRecord = monitor
  6824. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6825. //its.XtAssessmentAfterDislysis = after
  6826. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  6827. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  6828. }
  6829. }
  6830. this.ServeSuccessJSON(map[string]interface{}{
  6831. "schedule": schedule,
  6832. })
  6833. return
  6834. }
  6835. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  6836. week_day, _ := this.GetInt64("week_day")
  6837. orgId := this.GetAdminUserInfo().CurrentOrgId
  6838. informaitonSetting := models.XtDialysisInformaitonSetting{
  6839. WeekDay: week_day,
  6840. UserOrgId: orgId,
  6841. Status: 1,
  6842. Ctime: time.Now().Unix(),
  6843. Mtime: 0,
  6844. }
  6845. information, _ := service.GetInformationSettingByOrgId(orgId)
  6846. if information.ID == 0 {
  6847. service.CreateInformationSetting(informaitonSetting)
  6848. }
  6849. if information.ID > 0 {
  6850. service.UpdateInformationSettingById(orgId, week_day)
  6851. }
  6852. this.ServeSuccessJSON(map[string]interface{}{
  6853. "informaitonSetting": informaitonSetting,
  6854. })
  6855. return
  6856. }
  6857. func (this *DialysisApiController) GetDialysisInformationSetting() {
  6858. orgId := this.GetAdminUserInfo().CurrentOrgId
  6859. limit, _ := this.GetInt64("limit")
  6860. page, _ := this.GetInt64("page")
  6861. informationSetting, _ := service.GetDialysisInformationSettingList(orgId)
  6862. //未审核
  6863. infor, total, _ := service.GetDialysisInformationIsNoCheck(orgId, limit, page, 2)
  6864. //全部
  6865. inforList, totalOne, _ := service.GetDialysisInformationIsNoCheckOne(orgId, limit, page, 1)
  6866. patients, _ := service.GetAllpatientThirty(orgId)
  6867. appId := this.GetAdminUserInfo().CurrentAppId
  6868. role, _ := service.GetAllDoctorListSix(orgId, appId)
  6869. this.ServeSuccessJSON(map[string]interface{}{
  6870. "informaitonSetting": informationSetting,
  6871. "infor": infor,
  6872. "total": total,
  6873. "totalOne": totalOne,
  6874. "inforList": inforList,
  6875. "patients": patients,
  6876. "adminList": role,
  6877. })
  6878. return
  6879. }
  6880. func (this *DialysisApiController) CheckDialysisInformation() {
  6881. id, _ := this.GetInt64("id")
  6882. application_status, _ := this.GetInt64("application_status")
  6883. timeNow := time.Now().Unix()
  6884. checker := this.GetAdminUserInfo().AdminUser.Id
  6885. information, _ := service.CheckDialysisInformation(id, application_status, timeNow, checker)
  6886. this.ServeSuccessJSON(map[string]interface{}{
  6887. "information": information,
  6888. })
  6889. return
  6890. }
  6891. func (this *DialysisApiController) GetDialysisPatientsFlow() {
  6892. page, _ := this.GetInt64("page", 1)
  6893. limit, _ := this.GetInt64("limit", 10)
  6894. schedulType, _ := this.GetInt64("schedul_type", 0)
  6895. startTime, _ := this.GetInt64("schedul_time", 0)
  6896. partitionType, _ := this.GetInt64("partition_type", 0)
  6897. keywords := this.GetString("keywords")
  6898. start_time, _ := this.GetInt64("start_time")
  6899. end_time, _ := this.GetInt64("end_time")
  6900. adminUserInfo := this.GetAdminUserInfo()
  6901. if len(keywords) > 0 {
  6902. dialysisSchedule, err, total := service.GetDialysisWatchByKeywordFlow(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6903. if err == nil {
  6904. this.ServeSuccessJSON(map[string]interface{}{
  6905. "schedule": dialysisSchedule,
  6906. "total": total,
  6907. })
  6908. } else {
  6909. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6910. }
  6911. } else {
  6912. dialysisSchedule, err, total := service.GetDialysisWatchFlow(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6913. if err == nil {
  6914. this.ServeSuccessJSON(map[string]interface{}{
  6915. "schedule": dialysisSchedule,
  6916. "total": total,
  6917. })
  6918. } else {
  6919. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6920. }
  6921. }
  6922. }
  6923. func (this *DialysisApiController) SaveInformation() {
  6924. patient_id, _ := this.GetInt64("patient_id")
  6925. record_date, _ := this.GetInt64("record_date")
  6926. startTime := this.GetString("selected_date")
  6927. timeLayout := "2006-01-02 15:04"
  6928. loc, _ := time.LoadLocation("Local")
  6929. if len(startTime) == 0 {
  6930. utils.ErrorLog("len(start_time) == 0")
  6931. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6932. return
  6933. }
  6934. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  6935. if err != nil {
  6936. utils.ErrorLog(err.Error())
  6937. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6938. return
  6939. }
  6940. StartTime := theTime.Unix()
  6941. fmt.Println("startime-------------", StartTime)
  6942. module, _ := this.GetInt64("module")
  6943. remark := this.GetString("remark")
  6944. orgId := this.GetAdminUserInfo().CurrentOrgId
  6945. creater := this.GetAdminUserInfo().AdminUser.Id
  6946. information := models.XtDialysisInformation{
  6947. Module: module,
  6948. PatientId: patient_id,
  6949. RecordDate: record_date,
  6950. ApplicationDate: StartTime,
  6951. Creater: creater,
  6952. ApplicationStatus: 2,
  6953. Checker: 0,
  6954. CheckTime: 0,
  6955. Remark: remark,
  6956. UserOrgId: orgId,
  6957. Ctime: time.Now().Unix(),
  6958. Status: 1,
  6959. Mtime: 0,
  6960. }
  6961. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  6962. if infor.ID == 0 {
  6963. err := service.CreatedDialysisInformation(information)
  6964. if err == nil {
  6965. this.ServeSuccessJSON(map[string]interface{}{
  6966. "information": information,
  6967. })
  6968. return
  6969. }
  6970. }
  6971. if infor.ID > 0 {
  6972. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, StartTime, remark)
  6973. if err == nil {
  6974. this.ServeSuccessJSON(map[string]interface{}{
  6975. "information": information,
  6976. })
  6977. return
  6978. }
  6979. }
  6980. }
  6981. func (this *DialysisApiController) GetLongDialysisAdviceToday() {
  6982. orgId := this.GetAdminUserInfo().CurrentOrgId
  6983. schedule_type, _ := this.GetInt64("schedule_type")
  6984. partion_type := this.GetString("partion_type")
  6985. var ids []string
  6986. ids = strings.Split(partion_type, ",")
  6987. start_time := this.GetString("selected_date")
  6988. timeLayout := "2006-01-02"
  6989. loc, _ := time.LoadLocation("Local")
  6990. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6991. list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
  6992. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6993. _, config := service.FindXTHisRecordByOrgId(orgId)
  6994. appId := this.GetAdminUserInfo().CurrentAppId
  6995. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6996. if err == nil {
  6997. this.ServeSuccessJSON(map[string]interface{}{
  6998. "list": list,
  6999. "drug": drug,
  7000. "config": config,
  7001. "doctorList": doctorList,
  7002. })
  7003. return
  7004. } else {
  7005. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7006. return
  7007. }
  7008. }
  7009. func (this *DialysisApiController) GetPatientList() {
  7010. orgId := this.GetAdminUserInfo().CurrentOrgId
  7011. keyWord := this.GetString("keyword")
  7012. patientList, err := service.GetPrescriptionPatientList(orgId, keyWord)
  7013. if err == nil {
  7014. this.ServeSuccessJSON(map[string]interface{}{
  7015. "patientList": patientList,
  7016. })
  7017. return
  7018. } else {
  7019. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7020. return
  7021. }
  7022. }
  7023. func (this *DialysisApiController) GetPrescriptionLogList() {
  7024. patient_id, _ := this.GetInt64("patient_id")
  7025. record_date := this.GetString("record_date")
  7026. page, _ := this.GetInt64("page")
  7027. limit, _ := this.GetInt64("limit")
  7028. orgId := this.GetAdminUserInfo().CurrentOrgId
  7029. timeLayout := "2006-01-02"
  7030. loc, _ := time.LoadLocation("Local")
  7031. var recordDateTime int64
  7032. if len(record_date) > 0 {
  7033. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7034. if err != nil {
  7035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7036. return
  7037. }
  7038. recordDateTime = theTime.Unix()
  7039. }
  7040. prescriptionlogList, total, err := service.GetPrescriptionLogList(patient_id, page, limit, recordDateTime, orgId)
  7041. patients, _ := service.GetAllPatientLog(orgId)
  7042. role, _ := service.GetAllDoctorLog(orgId)
  7043. if err == nil {
  7044. this.ServeSuccessJSON(map[string]interface{}{
  7045. "prescriptionlogList": prescriptionlogList,
  7046. "total": total,
  7047. "patients": patients,
  7048. "role": role,
  7049. })
  7050. return
  7051. } else {
  7052. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7053. return
  7054. }
  7055. }
  7056. func (this *DialysisApiController) GetBeforLogList() {
  7057. patient_id, _ := this.GetInt64("patient_id")
  7058. record_date := this.GetString("record_date")
  7059. page, _ := this.GetInt64("page")
  7060. limit, _ := this.GetInt64("limit")
  7061. orgId := this.GetAdminUserInfo().CurrentOrgId
  7062. timeLayout := "2006-01-02"
  7063. loc, _ := time.LoadLocation("Local")
  7064. var recordDateTime int64
  7065. if len(record_date) > 0 {
  7066. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7067. if err != nil {
  7068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7069. return
  7070. }
  7071. recordDateTime = theTime.Unix()
  7072. }
  7073. beforLogList, total, err := service.GetBeforLogList(patient_id, page, limit, recordDateTime, orgId)
  7074. patients, _ := service.GetAllPatientLog(orgId)
  7075. role, _ := service.GetAllDoctorLog(orgId)
  7076. if err == nil {
  7077. this.ServeSuccessJSON(map[string]interface{}{
  7078. "beforLogList": beforLogList,
  7079. "total": total,
  7080. "patients": patients,
  7081. "role": role,
  7082. })
  7083. return
  7084. } else {
  7085. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7086. return
  7087. }
  7088. }
  7089. func (this *DialysisApiController) GetDocLogList() {
  7090. patient_id, _ := this.GetInt64("patient_id")
  7091. record_date := this.GetString("record_date")
  7092. page, _ := this.GetInt64("page")
  7093. limit, _ := this.GetInt64("limit")
  7094. orgId := this.GetAdminUserInfo().CurrentOrgId
  7095. timeLayout := "2006-01-02"
  7096. loc, _ := time.LoadLocation("Local")
  7097. var recordDateTime int64
  7098. if len(record_date) > 0 {
  7099. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7100. if err != nil {
  7101. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7102. return
  7103. }
  7104. recordDateTime = theTime.Unix()
  7105. }
  7106. adviceLogList, total, err := service.GetDocLogList(patient_id, page, limit, recordDateTime, orgId)
  7107. patients, _ := service.GetAllPatientLog(orgId)
  7108. role, _ := service.GetAllDoctorLog(orgId)
  7109. if err == nil {
  7110. this.ServeSuccessJSON(map[string]interface{}{
  7111. "adviceLogList": adviceLogList,
  7112. "total": total,
  7113. "patients": patients,
  7114. "role": role,
  7115. })
  7116. return
  7117. } else {
  7118. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7119. return
  7120. }
  7121. }
  7122. func (this *DialysisApiController) GetMonitorLogList() {
  7123. patient_id, _ := this.GetInt64("patient_id")
  7124. record_date := this.GetString("record_date")
  7125. page, _ := this.GetInt64("page")
  7126. limit, _ := this.GetInt64("limit")
  7127. orgId := this.GetAdminUserInfo().CurrentOrgId
  7128. timeLayout := "2006-01-02"
  7129. loc, _ := time.LoadLocation("Local")
  7130. var recordDateTime int64
  7131. if len(record_date) > 0 {
  7132. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7133. if err != nil {
  7134. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7135. return
  7136. }
  7137. recordDateTime = theTime.Unix()
  7138. }
  7139. monitorLogList, total, err := service.GetMonitorLogList(patient_id, page, limit, recordDateTime, orgId)
  7140. patients, _ := service.GetAllPatientLog(orgId)
  7141. role, _ := service.GetAllDoctorLog(orgId)
  7142. if err == nil {
  7143. this.ServeSuccessJSON(map[string]interface{}{
  7144. "monitorLogList": monitorLogList,
  7145. "total": total,
  7146. "patients": patients,
  7147. "role": role,
  7148. })
  7149. return
  7150. } else {
  7151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7152. return
  7153. }
  7154. }
  7155. func (this *DialysisApiController) GetAfterLogList() {
  7156. patient_id, _ := this.GetInt64("patient_id")
  7157. record_date := this.GetString("record_date")
  7158. page, _ := this.GetInt64("page")
  7159. limit, _ := this.GetInt64("limit")
  7160. orgId := this.GetAdminUserInfo().CurrentOrgId
  7161. timeLayout := "2006-01-02"
  7162. loc, _ := time.LoadLocation("Local")
  7163. var recordDateTime int64
  7164. if len(record_date) > 0 {
  7165. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7166. if err != nil {
  7167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7168. return
  7169. }
  7170. recordDateTime = theTime.Unix()
  7171. }
  7172. afterLogList, total, err := service.GetAfterLogList(patient_id, page, limit, recordDateTime, orgId)
  7173. patients, _ := service.GetAllPatientLog(orgId)
  7174. role, _ := service.GetAllDoctorLog(orgId)
  7175. if err == nil {
  7176. this.ServeSuccessJSON(map[string]interface{}{
  7177. "afterLogList": afterLogList,
  7178. "total": total,
  7179. "patients": patients,
  7180. "role": role,
  7181. })
  7182. return
  7183. } else {
  7184. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7185. return
  7186. }
  7187. }
  7188. func (this *DialysisApiController) SaveGatherSetting() {
  7189. orgId := this.GetAdminUserInfo().CurrentOrgId
  7190. is_index_number, _ := this.GetInt64("is_index_number")
  7191. fmt.Println("this,23o2332232323232332", is_index_number)
  7192. is_zone, _ := this.GetInt64("is_zone")
  7193. is_number, _ := this.GetInt64("is_number")
  7194. is_birth, _ := this.GetInt64("is_birth")
  7195. is_age, _ := this.GetInt64("is_age")
  7196. is_name, _ := this.GetInt64("is_name")
  7197. is_mode_type, _ := this.GetInt64("is_mode_type")
  7198. is_prescription_status, _ := this.GetInt64("is_prescription_status")
  7199. is_admission_number, _ := this.GetInt64("is_admission_number")
  7200. is_dialysis_no, _ := this.GetInt64("is_dialysis_no")
  7201. is_dry_weight, _ := this.GetInt64("is_dry_weight")
  7202. is_dialysis_dialyszers, _ := this.GetInt64("is_dialysis_dialyszers")
  7203. is_dialysis_strainer, _ := this.GetInt64("is_dialysis_strainer")
  7204. is_dialysis_irrigation, _ := this.GetInt64("is_dialysis_irrigation")
  7205. is_calcium, _ := this.GetInt64("is_calcium")
  7206. is_kalium, _ := this.GetInt64("is_kalium")
  7207. is_change_nurse, _ := this.GetInt64("is_change_nurse")
  7208. is_puncture_needle, _ := this.GetInt64("is_puncture_needle")
  7209. is_anticoagulant, _ := this.GetInt64("is_anticoagulant")
  7210. is_tube, _ := this.GetInt64("is_tube")
  7211. is_cuhong, _ := this.GetInt64("is_cuhong")
  7212. is_zuoka, _ := this.GetInt64("is_zuoka")
  7213. is_zhetangtie, _ := this.GetInt64("is_zhetangtie")
  7214. is_paligu, _ := this.GetInt64("is_paligu")
  7215. is_guhuachun, _ := this.GetInt64("is_guhuachun")
  7216. is_niaojimei, _ := this.GetInt64("is_niaojimei")
  7217. is_putaosuangai, _ := this.GetInt64("is_putaosuangai")
  7218. is_jiaguan, _ := this.GetInt64("is_jiaguan")
  7219. is_xiongxiewutai, _ := this.GetInt64("is_xiongxiewutai")
  7220. gatherSetting := models.XtDialysisGatherSetting{
  7221. UserOrgId: orgId,
  7222. IndexNumber: is_index_number,
  7223. Zone: is_zone,
  7224. Number: is_number,
  7225. Birth: is_birth,
  7226. Name: is_name,
  7227. Age: is_age,
  7228. ModeType: is_mode_type,
  7229. PrescriptionStatus: is_prescription_status,
  7230. AdmissionNumber: is_admission_number,
  7231. DialysisNo: is_dialysis_no,
  7232. DryWeight: is_dry_weight,
  7233. DialysisDialyszers: is_dialysis_dialyszers,
  7234. DialysisStrainer: is_dialysis_strainer,
  7235. DialysisIrrigation: is_dialysis_irrigation,
  7236. Calcium: is_calcium,
  7237. Kalium: is_kalium,
  7238. ChangeNurse: is_change_nurse,
  7239. PunctureNeedle: is_puncture_needle,
  7240. Anticoagulant: is_anticoagulant,
  7241. Tube: is_tube,
  7242. Cuhong: is_cuhong,
  7243. Zuoka: is_zuoka,
  7244. Zhetangtie: is_zhetangtie,
  7245. Paligu: is_paligu,
  7246. Guhuachun: is_guhuachun,
  7247. Niaojimei: is_niaojimei,
  7248. Putaosuangai: is_putaosuangai,
  7249. Jiaguan: is_jiaguan,
  7250. Xiongxiewutai: is_xiongxiewutai,
  7251. Ctime: time.Now().Unix(),
  7252. Mtime: time.Now().Unix(),
  7253. Status: 1,
  7254. }
  7255. //查询该机构有没有设置
  7256. gatherSettingOne, _ := service.GetGatherSettingByOrgId(orgId)
  7257. if gatherSettingOne.ID == 0 {
  7258. service.CreateGather(gatherSetting)
  7259. } else {
  7260. gatherSetting.ID = gatherSettingOne.ID
  7261. service.SaveGather(gatherSetting)
  7262. }
  7263. this.ServeSuccessJSON(map[string]interface{}{
  7264. "gatherSetting": gatherSetting,
  7265. })
  7266. return
  7267. }
  7268. func (this *DialysisApiController) GetGatherSetting() {
  7269. orgId := this.GetAdminUserInfo().CurrentOrgId
  7270. gatherSetting, _ := service.GetGatherSetting(orgId)
  7271. this.ServeSuccessJSON(map[string]interface{}{
  7272. "gatherSetting": gatherSetting,
  7273. })
  7274. return
  7275. }
  7276. func (this *DialysisApiController) GetDialysisGatherList() {
  7277. keyword := this.GetString("keywords")
  7278. limit, _ := this.GetInt64("limit")
  7279. page, _ := this.GetInt64("page")
  7280. partion_type := this.GetString("partition_id")
  7281. idSplit := strings.Split(partion_type, ",")
  7282. schedule_type, _ := this.GetInt64("schedule_type")
  7283. start_time := this.GetString("schedule_date")
  7284. timeLayout := "2006-01-02"
  7285. loc, _ := time.LoadLocation("Local")
  7286. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7287. orgId := this.GetAdminUserInfo().CurrentOrgId
  7288. scheduids := this.GetString("ids")
  7289. var ids []string
  7290. if scheduids != "" {
  7291. ids = strings.Split(scheduids, ",")
  7292. }
  7293. list, total, _ := service.GetDialysisGatherList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  7294. gatherSetting, _ := service.GetGatherSetting(orgId)
  7295. this.ServeSuccessJSON(map[string]interface{}{
  7296. "list": list,
  7297. "total": total,
  7298. "gatherSetting": gatherSetting,
  7299. })
  7300. return
  7301. }
  7302. func (this *DialysisApiController) GetPatientDialysisRecordList() {
  7303. patient_id, _ := this.GetInt64("patient_id")
  7304. timeLayout := "2006-01-02"
  7305. loc, _ := time.LoadLocation("Local")
  7306. start_time := this.GetString("start_time")
  7307. end_time := this.GetString("end_time")
  7308. var startdateunix int64
  7309. if len(start_time) > 0 {
  7310. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7311. if err != nil {
  7312. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7313. return
  7314. }
  7315. startdateunix = theTime.Unix()
  7316. }
  7317. var enddateunix int64
  7318. if len(end_time) > 0 {
  7319. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7320. if err != nil {
  7321. utils.ErrorLog(err.Error())
  7322. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7323. return
  7324. }
  7325. enddateunix = theTime.Unix()
  7326. }
  7327. org_id := this.GetAdminUserInfo().CurrentOrgId
  7328. if org_id == 9538 || org_id == 10101 || org_id == 10353 {
  7329. list, _ := service.GetPatientDialysisRecordList(patient_id, startdateunix, enddateunix)
  7330. this.ServeSuccessJSON(map[string]interface{}{
  7331. "list": list,
  7332. })
  7333. return
  7334. } else {
  7335. list, _ := service.GetPatientDialysisRecordListOne(patient_id, startdateunix, enddateunix)
  7336. this.ServeSuccessJSON(map[string]interface{}{
  7337. "list": list,
  7338. })
  7339. }
  7340. return
  7341. }
  7342. func (this *DialysisApiController) GetPatientRecordList() {
  7343. patient_id, _ := this.GetInt64("patient_id")
  7344. orgId := this.GetAdminUserInfo().CurrentOrgId
  7345. beforList, _ := service.GetPatientBeforRecordList(patient_id, orgId)
  7346. afterList, _ := service.GetPatientAfterRecordList(patient_id, orgId)
  7347. monitorList, _ := service.GetMonitorRecordByGroup(patient_id, orgId)
  7348. this.ServeSuccessJSON(map[string]interface{}{
  7349. "beforList": beforList,
  7350. "afterList": afterList,
  7351. "monitorList": monitorList,
  7352. })
  7353. }
  7354. func (this *DialysisApiController) GetDialysisTotalCount() {
  7355. timeLayout := "2006-01-02"
  7356. loc, _ := time.LoadLocation("Local")
  7357. start_time := this.GetString("start_time")
  7358. end_time := this.GetString("end_time")
  7359. patient_id, _ := this.GetInt64("patient_id")
  7360. var startdateunix int64
  7361. if len(start_time) > 0 {
  7362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7363. if err != nil {
  7364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7365. return
  7366. }
  7367. startdateunix = theTime.Unix()
  7368. }
  7369. var enddateunix int64
  7370. if len(end_time) > 0 {
  7371. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  7372. if err != nil {
  7373. utils.ErrorLog(err.Error())
  7374. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7375. return
  7376. }
  7377. enddateunix = theTime.Unix()
  7378. }
  7379. orgId := this.GetAdminUserInfo().CurrentOrgId
  7380. order, _ := service.GetDialysisTotalCountByTime(orgId, startdateunix, enddateunix, patient_id)
  7381. this.ServeSuccessJSON(map[string]interface{}{
  7382. "order": order,
  7383. })
  7384. }
  7385. func (this *DialysisApiController) GetPatientBefor() {
  7386. timeLayout := "2006-01-02"
  7387. loc, _ := time.LoadLocation("Local")
  7388. record_date := this.GetString("record_date")
  7389. patient_id, _ := this.GetInt64("patient_id")
  7390. user_org_id := this.GetAdminUserInfo().CurrentOrgId
  7391. var startdateunix int64
  7392. if len(record_date) > 0 {
  7393. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7394. if err != nil {
  7395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7396. return
  7397. }
  7398. startdateunix = theTime.Unix()
  7399. }
  7400. patientBefor, _ := service.GetPatientBefor(patient_id, startdateunix, user_org_id)
  7401. prescription, _ := service.GetDialysisPrescribeOneList(patient_id, startdateunix, user_org_id)
  7402. this.ServeSuccessJSON(map[string]interface{}{
  7403. "patientBefor": patientBefor,
  7404. "prescription": prescription,
  7405. })
  7406. }