dialysis_api_controller.go 306KB

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