dialysis_api_controller.go 307KB

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