dialysis_api_controller.go 274KB

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