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. assessment.Urr = data.Urr
  1852. assessment.Hypertenison = data.Hypertenison
  1853. assessment.Hypopiesia = data.Hypopiesia
  1854. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1855. assessment.Lapse = data.Lapse
  1856. assessment.Consciousness = data.Consciousness
  1857. assessment.Fallrisk = data.Fallrisk
  1858. assessment.MachineRun = data.MachineRun
  1859. assessment.AfterUrea = data.AfterUrea
  1860. assessment.PipCoagulation = data.PipCoagulation
  1861. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1862. assessment.TransfusionVolume = data.TransfusionVolume
  1863. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1864. if assessment.ID > 0 {
  1865. if appRole.UserType == 2 || appRole.UserType == 1 {
  1866. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1867. assessment.AssessmentTime = time.Now().Unix()
  1868. } else {
  1869. if assessment.Creater == 0 {
  1870. assessment.Modifier = adminUserInfo.AdminUser.Id
  1871. assessment.Creater = adminUserInfo.AdminUser.Id
  1872. } else {
  1873. assessment.Modifier = adminUserInfo.AdminUser.Id
  1874. }
  1875. }
  1876. assessment.UpdatedTime = time.Now().Unix()
  1877. // 查询信息规挡的设置天数
  1878. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  1879. if infor.ID > 0 {
  1880. var cha_time int64
  1881. timeNowStr := time.Now().Format("2006-01-02")
  1882. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  1883. //今日的日期减去设置的日期
  1884. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  1885. if cha_time >= recordDate.Unix() {
  1886. //查询审核是否允许
  1887. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 9)
  1888. //申请状态不允许的情况 拒绝修改
  1889. if infor.ApplicationStatus != 1 {
  1890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  1891. return
  1892. }
  1893. }
  1894. }
  1895. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1896. //记录日志
  1897. byterequest, _ := json.Marshal(assessment)
  1898. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1899. UserOrgId: assessment.UserOrgId,
  1900. PatientId: assessment.PatientId,
  1901. RecordDate: assessment.AssessmentDate,
  1902. Status: 1,
  1903. ErrLog: string(byterequest),
  1904. AdminUserId: adminUserInfo.AdminUser.Id,
  1905. Ctime: time.Now().Unix(),
  1906. Mtime: 0,
  1907. Source: "电脑端保存透后评估",
  1908. }
  1909. service.CreateAfterDialysisLog(afterDialysisLog)
  1910. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1911. redis := service.RedisClient()
  1912. //清空key 值
  1913. redis.Set(key, "", time.Second)
  1914. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1915. redis.Set(keyThree, "", time.Second)
  1916. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1917. redis.Set(keyTwo, "", time.Second)
  1918. defer redis.Close()
  1919. } else {
  1920. if appRole.UserType == 2 || appRole.UserType == 1 {
  1921. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1922. assessment.AssessmentTime = time.Now().Unix()
  1923. } else {
  1924. assessment.Creater = adminUserInfo.AdminUser.Id
  1925. }
  1926. assessment.CreatedTime = time.Now().Unix()
  1927. assessment.UpdatedTime = time.Now().Unix()
  1928. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1929. assessment.PatientId = patient
  1930. assessment.AssessmentDate = recordDate.Unix()
  1931. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1932. //记录日志
  1933. byterequest, _ := json.Marshal(assessment)
  1934. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  1935. UserOrgId: assessment.UserOrgId,
  1936. PatientId: assessment.PatientId,
  1937. RecordDate: assessment.AssessmentDate,
  1938. Status: 1,
  1939. ErrLog: string(byterequest),
  1940. AdminUserId: adminUserInfo.AdminUser.Id,
  1941. Ctime: time.Now().Unix(),
  1942. Mtime: 0,
  1943. Source: "电脑端修改保存透后评估",
  1944. }
  1945. service.CreateAfterDialysisLog(afterDialysisLog)
  1946. finish := models.XtDialysisFinish{
  1947. IsFinish: 1,
  1948. UserOrgId: adminUserInfo.CurrentOrgId,
  1949. Status: 1,
  1950. Ctime: time.Now().Unix(),
  1951. Mtime: 0,
  1952. Module: 9,
  1953. RecordDate: recordDate.Unix(),
  1954. Sourse: 1,
  1955. PatientId: patient,
  1956. }
  1957. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 9, patient)
  1958. if dialysisFinish.ID == 0 {
  1959. service.CreateDialysisFinish(finish)
  1960. }
  1961. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1962. redis := service.RedisClient()
  1963. //清空key 值
  1964. redis.Set(key, "", time.Second)
  1965. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1966. redis.Set(keyThree, "", time.Second)
  1967. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1968. redis.Set(keyTwo, "", time.Second)
  1969. defer redis.Close()
  1970. }
  1971. if err != nil {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1973. return
  1974. }
  1975. c.ServeSuccessJSON(map[string]interface{}{
  1976. "AssessmentAfterDislysis": &assessment,
  1977. })
  1978. }
  1979. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1980. patient, _ := c.GetInt64("patient", 0)
  1981. recordDateStr := c.GetString("record_date")
  1982. if patient <= 0 {
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1984. return
  1985. }
  1986. adminUserInfo := c.GetAdminUserInfo()
  1987. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1988. if patientInfo.ID == 0 {
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1990. return
  1991. }
  1992. if len(recordDateStr) == 0 {
  1993. recordDateStr = time.Now().Format("2006-01-02")
  1994. }
  1995. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1996. if parseDateErr != nil {
  1997. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1999. return
  2000. }
  2001. weight_before, _ := c.GetFloat("weight_before", 0)
  2002. dry_weight, _ := c.GetFloat("dry_weight", 0)
  2003. additional_weight, _ := c.GetFloat("additional_weight", 0)
  2004. temperature, _ := c.GetFloat("temperature", 0)
  2005. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2006. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2007. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2008. last_post_dialysis := c.GetString("last_post_dialysis")
  2009. dialysis_interphase := c.GetString("dialysis_interphase")
  2010. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  2011. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  2012. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  2013. bloodAccessPartId := c.GetString("blood_access_part_id")
  2014. internalFistula := c.GetString("internal_fistula")
  2015. internal_fistula_skin := c.GetString("internal_fistula_skin")
  2016. catheter := c.GetString("catheter")
  2017. catheter_bend, _ := c.GetInt("catheter_bend")
  2018. complication := c.GetString("complication")
  2019. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  2020. hemorrhage := c.GetString("hemorrhage")
  2021. hemorrhage_other := c.GetString("hemorrhage_other")
  2022. remark := c.GetString("remark")
  2023. puncture_method := c.GetString("puncture_method")
  2024. dialysis_count := c.GetString("dialysis_count")
  2025. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  2026. emergency_treatment_other := c.GetString("emergency_treatment_other")
  2027. ductus_arantii := c.GetString("ductus_arantii")
  2028. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  2029. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  2030. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  2031. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  2032. puncture_way := c.GetString("puncture_way")
  2033. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  2034. internal_fistula_other := c.GetString("internal_fistula_other")
  2035. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  2036. breathing_rate := c.GetString("breathing_rate")
  2037. is_infect, _ := c.GetInt64("is_infect", 0)
  2038. exposed, _ := c.GetFloat("exposed", 0)
  2039. skin := c.GetString("skin")
  2040. skin_other := c.GetString("skin_other")
  2041. infect_other := c.GetString("infect_other")
  2042. ductus_arantii_other := c.GetString("ductus_arantii_other")
  2043. machine_type := c.GetString("machine_type")
  2044. puncture_needle := c.GetString("puncture_needle")
  2045. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  2046. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  2047. phinholing := c.GetString("pinholing")
  2048. catheter_suture := c.GetString("catheter_suture")
  2049. catheter_suture_other := c.GetString("catheter_suture_other")
  2050. edema := c.GetString("edema")
  2051. urine_volume, _ := c.GetFloat("urine_volume", 0)
  2052. special_treatment := c.GetString("special_treatment")
  2053. catheter_maintenance := c.GetString("catheter_maintenance")
  2054. thrombusType := c.GetString("thromubus_type")
  2055. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  2056. thrombus_a := c.GetString("thromubus_a")
  2057. thrombus_av := c.GetString("thrombus_av")
  2058. thrombus_v := c.GetString("thromubus_v")
  2059. dehydration := c.GetString("dehydration")
  2060. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  2061. period, _ := c.GetInt64("period")
  2062. estimated_food_intake := c.GetString("estimated_food_intake")
  2063. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  2064. urea_befor := c.GetString("urea_befor")
  2065. suction := c.GetString("suction")
  2066. weight_befor_remake := c.GetString("weight_befor_remake")
  2067. height := c.GetString("height")
  2068. age := c.GetString("age")
  2069. his_department := c.GetString("his_department")
  2070. his_bed := c.GetString("his_bed")
  2071. point_puncture := c.GetString("point_puncture")
  2072. catheter_evaluation_program := c.GetString("catheter_evaluation_program")
  2073. skin_site_catheterization := c.GetString("skin_site_catheterization")
  2074. pathway_formation_time := c.GetString("pathway_formation_time")
  2075. timeLayout := "2006-01-02"
  2076. loc, _ := time.LoadLocation("Local")
  2077. var startTime int64
  2078. if len(pathway_formation_time) > 0 {
  2079. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", pathway_formation_time+" 00:00:00", loc)
  2080. startTime = theTime.Unix()
  2081. }
  2082. whether_unobstructed, _ := c.GetInt64("whether_unobstructed")
  2083. lien_necessary, _ := c.GetInt64("lien_necessary")
  2084. befor_symptoms := c.GetString("befor_symptoms")
  2085. warsh_count := c.GetString("warsh_count")
  2086. washing_time := c.GetString("washing_time")
  2087. assessmentBeforeDislysis := models.PredialysisEvaluation{
  2088. DialysisCount: dialysis_count,
  2089. EmergencyTreatment: emergency_treatment,
  2090. EmergencyTreatmentOther: emergency_treatment_other,
  2091. DuctusArantii: ductus_arantii,
  2092. VenousCatheterization: venous_catheterization,
  2093. VenousCatheterizationPart: venous_catheterization_part,
  2094. VenousCatheterizationPartOther: venous_catheterization_part_other,
  2095. PunctureWay: puncture_way,
  2096. BloodAccessInternalFistula: blood_access_internal_fistula,
  2097. BloodAccessNoise: blood_access_noise,
  2098. InternalFistulaOther: internal_fistula_other,
  2099. Evaluator: adminUserInfo.AdminUser.Id,
  2100. UserOrgId: adminUserInfo.CurrentOrgId,
  2101. PatientId: patient,
  2102. AssessmentDate: recordDate.Unix(),
  2103. Temperature: temperature,
  2104. PulseFrequency: pulse_frequency,
  2105. SystolicBloodPressure: systolic_blood_pressure,
  2106. DiastolicBloodPressure: diastolic_blood_pressure,
  2107. WeightBefore: weight_before,
  2108. DryWeight: dry_weight,
  2109. AdditionalWeight: additional_weight,
  2110. DialysisInterphase: dialysis_interphase,
  2111. LastPostDialysis: last_post_dialysis,
  2112. SymptomBeforeDialysis: symptom_before_dialysis,
  2113. InternalFistula: internalFistula,
  2114. InternalFistulaSkin: internal_fistula_skin,
  2115. Catheter: catheter,
  2116. CatheterBend: catheter_bend,
  2117. Complication: complication,
  2118. CreatedTime: time.Now().Unix(),
  2119. Status: 1,
  2120. Remark: remark,
  2121. IsHemorrhage: is_hemorrhage,
  2122. Hemorrhage: hemorrhage,
  2123. HemorrhageOther: hemorrhage_other,
  2124. BloodAccessPartId: bloodAccessPartId,
  2125. BloodAccessPartOperaId: bloodAccessPartOperaId,
  2126. PunctureMethod: puncture_method,
  2127. BreathingRate: breathing_rate,
  2128. IsInfect: is_infect,
  2129. Exposed: exposed,
  2130. Skin: skin,
  2131. SkinOther: skin_other,
  2132. InfectOther: infect_other,
  2133. DuctusArantiiOther: ductus_arantii_other,
  2134. MachineType: machine_type,
  2135. PunctureNeedle: puncture_needle,
  2136. HumorExcessiveSymptom: humor_excessive_symptom,
  2137. Phinholing: phinholing,
  2138. CatheterSuture: catheter_suture,
  2139. CatheterSutureOther: catheter_suture_other,
  2140. Edema: edema,
  2141. UrineVolume: urine_volume,
  2142. SpecialTreatment: special_treatment,
  2143. CatheterMaintenance: catheter_maintenance,
  2144. ThromubusType: thrombusInt,
  2145. ThrombusAv: thrombus_av,
  2146. ThromubusA: thrombus_a,
  2147. ThromubusV: thrombus_v,
  2148. Dehydration: dehydration,
  2149. PreDialysisDrugs: pre_dialysis_drugs,
  2150. Period: period,
  2151. EstimatedFoodIntake: estimated_food_intake,
  2152. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  2153. UreaBefor: urea_befor,
  2154. Suction: suction,
  2155. WeightBeforRemake: weight_befor_remake,
  2156. Height: height,
  2157. Age: age,
  2158. HisDepartment: his_department,
  2159. HisBed: his_bed,
  2160. PointPuncture: point_puncture,
  2161. CatheterEvaluationProgram: catheter_evaluation_program,
  2162. SkinSiteCatheterization: skin_site_catheterization,
  2163. PathwayFormationTime: startTime,
  2164. WhetherUnobstructed: whether_unobstructed,
  2165. LienNecessary: lien_necessary,
  2166. BeforSymptoms: befor_symptoms,
  2167. WarshCount: warsh_count,
  2168. WashingTime: washing_time,
  2169. }
  2170. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  2171. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2172. if evaluation.ID == 0 { //新增
  2173. if appRole.UserType == 2 || appRole.UserType == 1 {
  2174. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2175. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2176. } else {
  2177. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2178. }
  2179. // 查询信息规挡的设置天数
  2180. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2181. if infor.ID > 0 && infor.WeekDay > 0 {
  2182. var cha_time int64
  2183. timeNowStr := time.Now().Format("2006-01-02")
  2184. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2185. //今日的日期减去设置的日期
  2186. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2187. if cha_time >= recordDate.Unix() {
  2188. //查询审核是否允许
  2189. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2190. //申请状态不允许的情况 拒绝修改
  2191. if infor.ApplicationStatus != 1 {
  2192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2193. return
  2194. }
  2195. }
  2196. }
  2197. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  2198. //记录日志
  2199. byterequest, _ := json.Marshal(assessmentBeforeDislysis)
  2200. beforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  2201. UserOrgId: assessmentBeforeDislysis.UserOrgId,
  2202. AdminUserId: adminUserInfo.AdminUser.Id,
  2203. ErrLog: string(byterequest),
  2204. PatientId: assessmentBeforeDislysis.PatientId,
  2205. RecordDate: assessmentBeforeDislysis.AssessmentDate,
  2206. Ctime: time.Now().Unix(),
  2207. Mtime: 0,
  2208. Status: 1,
  2209. Source: "电脑端保存透前评估",
  2210. }
  2211. service.CreateBeforLog(beforeDislysisLog)
  2212. //创建步骤表
  2213. finish := models.XtDialysisFinish{
  2214. IsFinish: 1,
  2215. UserOrgId: adminUserInfo.CurrentOrgId,
  2216. Status: 1,
  2217. Ctime: time.Now().Unix(),
  2218. Mtime: 0,
  2219. Module: 3,
  2220. RecordDate: recordDate.Unix(),
  2221. Sourse: 1,
  2222. PatientId: patient,
  2223. }
  2224. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2225. if dialysisFinish.ID == 0 {
  2226. service.CreateDialysisFinish(finish)
  2227. }
  2228. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 || adminUserInfo.CurrentOrgId == 10551 {
  2229. var dewater_amount float64
  2230. dewater_amount = 0
  2231. if dry_weight > 0 {
  2232. dewater_amount = weight_before - dry_weight - additional_weight
  2233. if adminUserInfo.CurrentOrgId != 10551 {
  2234. dewater_amount = dewater_amount * 1000
  2235. }
  2236. if dewater_amount <= 0 {
  2237. dewater_amount = 0
  2238. }
  2239. } else {
  2240. dewater_amount = 0
  2241. }
  2242. // 计算透析处方的相关超滤量
  2243. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2244. var lastDialysisPrescribe *models.DialysisPrescription
  2245. var dialysisSolution *models.DialysisSolution
  2246. var dialysisPrescribe *models.DialysisPrescription
  2247. var mode_id int64
  2248. if schedual != nil {
  2249. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2250. if dialysisPrescribe == nil {
  2251. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2252. }
  2253. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2254. // 获取透析模版
  2255. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2256. mode_id = schedual.ModeId
  2257. } else {
  2258. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2259. // 获取透析模版
  2260. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2261. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2262. if dialysisPrescribe == nil && dialysisSolution != nil {
  2263. mode_id = dialysisSolution.ModeId
  2264. }
  2265. if dialysisPrescribe == nil && dialysisSolution == nil {
  2266. mode_id = 0
  2267. }
  2268. }
  2269. // 插入透析处方
  2270. if dialysisPrescribe == nil && dialysisSolution != nil {
  2271. var newprescribe models.DialysisPrescription
  2272. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2273. newprescribe.PatientId = dialysisSolution.PatientId
  2274. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2275. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2276. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2277. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2278. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2279. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2280. newprescribe.ModeId = dialysisSolution.ModeId
  2281. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2282. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2283. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2284. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2285. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2286. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2287. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2288. newprescribe.Glucose = dialysisSolution.Glucose
  2289. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2290. newprescribe.Kalium = dialysisSolution.Kalium
  2291. newprescribe.Sodium = dialysisSolution.Sodium
  2292. newprescribe.Calcium = dialysisSolution.Calcium
  2293. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2294. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2295. newprescribe.Conductivity = dialysisSolution.Conductivity
  2296. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2297. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2298. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2299. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2300. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2301. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2302. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2303. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2304. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2305. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2306. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2307. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2308. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2309. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2310. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2311. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2312. newprescribe.CreatedTime = time.Now().Unix()
  2313. newprescribe.UpdatedTime = time.Now().Unix()
  2314. newprescribe.RecordDate = recordDate.Unix()
  2315. newprescribe.DewaterAmount = dewater_amount
  2316. newprescribe.TargetUltrafiltration = dewater_amount
  2317. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2318. newprescribe.Status = 1
  2319. err := service.AddSigleRecord(&newprescribe)
  2320. //记录日志
  2321. byterequest, _ := json.Marshal(newprescribe)
  2322. prescriptionLog := models.XtDialysisPrescriptionLog{
  2323. UserOrgId: newprescribe.UserOrgId,
  2324. Ctime: time.Now().Unix(),
  2325. Mtime: 0,
  2326. ErrLog: string(byterequest),
  2327. AdminUserId: adminUserInfo.AdminUser.Id,
  2328. RecordDate: newprescribe.RecordDate,
  2329. PatientId: newprescribe.PatientId,
  2330. Source: "电脑端透前评估保存",
  2331. Status: 1,
  2332. }
  2333. service.CreatePrescriptionLog(prescriptionLog)
  2334. if err != nil {
  2335. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2336. }
  2337. }
  2338. if dialysisPrescribe == nil && dialysisSolution == nil {
  2339. if lastDialysisPrescribe != nil {
  2340. var newprescribe models.DialysisPrescription
  2341. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2342. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2343. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2344. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2345. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2346. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2347. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2348. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2349. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2350. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2351. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2352. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2353. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2354. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2355. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2356. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2357. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2358. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2359. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2360. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2361. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2362. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2363. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2364. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2365. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2366. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2367. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2368. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2369. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2370. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2371. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2372. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2373. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2374. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2375. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2376. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2377. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2378. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2379. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2380. newprescribe.CreatedTime = time.Now().Unix()
  2381. newprescribe.UpdatedTime = time.Now().Unix()
  2382. newprescribe.RecordDate = recordDate.Unix()
  2383. newprescribe.DewaterAmount = dewater_amount
  2384. newprescribe.TargetUltrafiltration = dewater_amount
  2385. newprescribe.Status = 1
  2386. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2387. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2388. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2389. err := service.AddSigleRecord(&newprescribe)
  2390. //记录日志
  2391. byterequest, _ := json.Marshal(newprescribe)
  2392. prescriptionLog := models.XtDialysisPrescriptionLog{
  2393. UserOrgId: newprescribe.UserOrgId,
  2394. Ctime: time.Now().Unix(),
  2395. Mtime: 0,
  2396. ErrLog: string(byterequest),
  2397. AdminUserId: adminUserInfo.AdminUser.Id,
  2398. RecordDate: newprescribe.RecordDate,
  2399. PatientId: newprescribe.PatientId,
  2400. Source: "电脑端透前评估保存",
  2401. Status: 1,
  2402. }
  2403. service.CreatePrescriptionLog(prescriptionLog)
  2404. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2405. redis := service.RedisClient()
  2406. defer redis.Close()
  2407. //清空key 值
  2408. redis.Set(key, "", time.Second)
  2409. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2410. redis.Set(keyOne, "", time.Second)
  2411. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2412. redis.Set(keyThree, "", time.Second)
  2413. if err != nil {
  2414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2415. }
  2416. } else {
  2417. var newprescribe models.DialysisPrescription
  2418. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2419. newprescribe.PatientId = patient
  2420. newprescribe.ModeId = mode_id
  2421. newprescribe.CreatedTime = time.Now().Unix()
  2422. newprescribe.UpdatedTime = time.Now().Unix()
  2423. newprescribe.RecordDate = recordDate.Unix()
  2424. newprescribe.DewaterAmount = dewater_amount
  2425. newprescribe.TargetUltrafiltration = dewater_amount
  2426. newprescribe.Status = 1
  2427. newprescribe.Creater = adminUserInfo.AdminUser.Id
  2428. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  2429. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  2430. err := service.AddSigleRecord(&newprescribe)
  2431. //记录日志
  2432. byterequest, _ := json.Marshal(newprescribe)
  2433. prescriptionLog := models.XtDialysisPrescriptionLog{
  2434. UserOrgId: newprescribe.UserOrgId,
  2435. Ctime: time.Now().Unix(),
  2436. Mtime: 0,
  2437. ErrLog: string(byterequest),
  2438. AdminUserId: adminUserInfo.AdminUser.Id,
  2439. RecordDate: newprescribe.RecordDate,
  2440. PatientId: newprescribe.PatientId,
  2441. Source: "电脑端透前评估保存",
  2442. Status: 1,
  2443. }
  2444. service.CreatePrescriptionLog(prescriptionLog)
  2445. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2446. redis := service.RedisClient()
  2447. defer redis.Close()
  2448. //清空key 值
  2449. redis.Set(key, "", time.Second)
  2450. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2451. redis.Set(keyOne, "", time.Second)
  2452. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2453. redis.Set(keyThree, "", time.Second)
  2454. if err != nil {
  2455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2456. }
  2457. }
  2458. }
  2459. }
  2460. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2461. redis := service.RedisClient()
  2462. //清空key 值
  2463. redis.Set(key, "", time.Second)
  2464. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2465. redis.Set(keyOne, "", time.Second)
  2466. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2467. redis.Set(keyTwo, "", time.Second)
  2468. defer redis.Close()
  2469. if err == nil {
  2470. c.ServeSuccessJSON(map[string]interface{}{
  2471. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2472. })
  2473. } else {
  2474. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2476. }
  2477. } else { //修改
  2478. //if appRole.UserType == 3 {
  2479. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  2480. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2481. // if getPermissionErr != nil {
  2482. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. // return
  2484. // } else if headNursePermission == nil {
  2485. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2486. // return
  2487. // }
  2488. // }
  2489. //}
  2490. if appRole.UserType == 2 || appRole.UserType == 1 {
  2491. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  2492. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  2493. } else {
  2494. if evaluation.Creater == 0 {
  2495. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2496. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2497. } else {
  2498. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2499. }
  2500. }
  2501. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2502. assessmentBeforeDislysis.ID = evaluation.ID
  2503. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2504. //
  2505. //新增逻辑
  2506. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2507. var dewater_amount float64
  2508. dewater_amount = 0
  2509. if evaluation.DryWeight > 0 {
  2510. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2511. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 || adminUserInfo.CurrentOrgId == 10551 {
  2512. if adminUserInfo.CurrentOrgId != 10551 {
  2513. dewater_amount = dewater_amount * 1000
  2514. }
  2515. }
  2516. if dewater_amount <= 0 {
  2517. dewater_amount = 0
  2518. }
  2519. } else {
  2520. dewater_amount = 0
  2521. }
  2522. // 计算透析处方的相关超滤量
  2523. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2524. var lastDialysisPrescribe *models.DialysisPrescription
  2525. var dialysisSolution *models.DialysisSolution
  2526. var dialysisPrescribe *models.DialysisPrescription
  2527. var mode_id int64
  2528. if schedual != nil {
  2529. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2530. if dialysisPrescribe == nil {
  2531. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2532. }
  2533. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2534. // 获取透析模版
  2535. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2536. mode_id = schedual.ModeId
  2537. } else {
  2538. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2539. // 获取透析模版
  2540. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2541. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2542. if dialysisPrescribe == nil && dialysisSolution != nil {
  2543. mode_id = dialysisSolution.ModeId
  2544. }
  2545. if dialysisPrescribe == nil && dialysisSolution == nil {
  2546. mode_id = 0
  2547. }
  2548. }
  2549. // 插入透析处方
  2550. if dialysisPrescribe == nil && dialysisSolution != nil {
  2551. var newprescribe models.DialysisPrescription
  2552. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2553. newprescribe.PatientId = dialysisSolution.PatientId
  2554. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2555. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2556. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2557. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2558. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2559. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2560. newprescribe.ModeId = dialysisSolution.ModeId
  2561. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2562. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2563. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2564. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2565. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2566. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2567. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2568. newprescribe.Glucose = dialysisSolution.Glucose
  2569. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2570. newprescribe.Kalium = dialysisSolution.Kalium
  2571. newprescribe.Sodium = dialysisSolution.Sodium
  2572. newprescribe.Calcium = dialysisSolution.Calcium
  2573. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2574. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2575. newprescribe.Conductivity = dialysisSolution.Conductivity
  2576. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2577. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2578. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2579. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2580. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2581. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2582. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2583. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2584. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2585. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2586. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2587. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2588. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2589. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2590. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2591. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2592. newprescribe.CreatedTime = time.Now().Unix()
  2593. newprescribe.UpdatedTime = time.Now().Unix()
  2594. newprescribe.RecordDate = recordDate.Unix()
  2595. newprescribe.DewaterAmount = dewater_amount
  2596. newprescribe.TargetUltrafiltration = dewater_amount
  2597. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2598. newprescribe.Status = 1
  2599. err := service.AddSigleRecord(&newprescribe)
  2600. //记录日志
  2601. byterequest, _ := json.Marshal(newprescribe)
  2602. prescriptionLog := models.XtDialysisPrescriptionLog{
  2603. UserOrgId: newprescribe.UserOrgId,
  2604. Ctime: time.Now().Unix(),
  2605. Mtime: 0,
  2606. ErrLog: string(byterequest),
  2607. AdminUserId: adminUserInfo.AdminUser.Id,
  2608. RecordDate: newprescribe.RecordDate,
  2609. PatientId: newprescribe.PatientId,
  2610. Source: "电脑端透前评估保存",
  2611. Status: 1,
  2612. }
  2613. service.CreatePrescriptionLog(prescriptionLog)
  2614. if err != nil {
  2615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2616. }
  2617. }
  2618. if dialysisPrescribe == nil && dialysisSolution == nil {
  2619. if lastDialysisPrescribe != nil {
  2620. var newprescribe models.DialysisPrescription
  2621. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2622. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2623. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2624. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2625. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2626. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2627. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2628. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2629. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2630. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2631. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2632. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2633. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2634. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2635. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2636. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2637. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2638. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2639. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2640. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2641. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2642. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2643. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2644. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2645. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2646. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2647. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2648. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2649. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2650. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2651. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2652. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2653. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2654. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2655. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2656. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2657. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2658. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2659. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2660. newprescribe.CreatedTime = time.Now().Unix()
  2661. newprescribe.UpdatedTime = time.Now().Unix()
  2662. newprescribe.RecordDate = recordDate.Unix()
  2663. newprescribe.DewaterAmount = dewater_amount
  2664. newprescribe.TargetUltrafiltration = dewater_amount
  2665. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  2666. newprescribe.Status = 1
  2667. err := service.AddSigleRecord(&newprescribe)
  2668. //记录日志
  2669. byterequest, _ := json.Marshal(newprescribe)
  2670. prescriptionLog := models.XtDialysisPrescriptionLog{
  2671. UserOrgId: newprescribe.UserOrgId,
  2672. Ctime: time.Now().Unix(),
  2673. Mtime: 0,
  2674. ErrLog: string(byterequest),
  2675. AdminUserId: adminUserInfo.AdminUser.Id,
  2676. RecordDate: newprescribe.RecordDate,
  2677. PatientId: newprescribe.PatientId,
  2678. Source: "电脑端透前评估保存",
  2679. Status: 1,
  2680. }
  2681. service.CreatePrescriptionLog(prescriptionLog)
  2682. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2683. redis := service.RedisClient()
  2684. defer redis.Close()
  2685. //清空key 值
  2686. redis.Set(key, "", time.Second)
  2687. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2688. redis.Set(keyOne, "", time.Second)
  2689. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2690. redis.Set(keyThree, "", time.Second)
  2691. if err != nil {
  2692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2693. }
  2694. } else {
  2695. var newprescribe models.DialysisPrescription
  2696. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2697. newprescribe.PatientId = patient
  2698. newprescribe.ModeId = mode_id
  2699. newprescribe.CreatedTime = time.Now().Unix()
  2700. newprescribe.UpdatedTime = time.Now().Unix()
  2701. newprescribe.RecordDate = recordDate.Unix()
  2702. newprescribe.DewaterAmount = dewater_amount
  2703. newprescribe.TargetUltrafiltration = dewater_amount
  2704. newprescribe.Status = 1
  2705. err := service.AddSigleRecord(&newprescribe)
  2706. //记录日志
  2707. byterequest, _ := json.Marshal(newprescribe)
  2708. prescriptionLog := models.XtDialysisPrescriptionLog{
  2709. UserOrgId: newprescribe.UserOrgId,
  2710. Ctime: time.Now().Unix(),
  2711. Mtime: 0,
  2712. ErrLog: string(byterequest),
  2713. AdminUserId: adminUserInfo.AdminUser.Id,
  2714. RecordDate: newprescribe.RecordDate,
  2715. PatientId: newprescribe.PatientId,
  2716. Source: "电脑端透前评估保存",
  2717. Status: 1,
  2718. }
  2719. service.CreatePrescriptionLog(prescriptionLog)
  2720. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2721. redis := service.RedisClient()
  2722. defer redis.Close()
  2723. //清空key 值
  2724. redis.Set(key, "", time.Second)
  2725. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2726. redis.Set(keyOne, "", time.Second)
  2727. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2728. redis.Set(keyThree, "", time.Second)
  2729. if err != nil {
  2730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2731. }
  2732. }
  2733. }
  2734. // 查询信息规挡的设置天数
  2735. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2736. if infor.ID > 0 {
  2737. var cha_time int64
  2738. timeNowStr := time.Now().Format("2006-01-02")
  2739. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2740. //今日的日期减去设置的日期
  2741. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2742. if cha_time >= recordDate.Unix() {
  2743. //查询审核是否允许
  2744. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 3)
  2745. //申请状态不允许的情况 拒绝修改
  2746. if infor.ApplicationStatus != 1 {
  2747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2748. return
  2749. }
  2750. }
  2751. }
  2752. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2753. //创建步骤表
  2754. finish := models.XtDialysisFinish{
  2755. IsFinish: 1,
  2756. UserOrgId: adminUserInfo.CurrentOrgId,
  2757. Status: 1,
  2758. Ctime: time.Now().Unix(),
  2759. Mtime: 0,
  2760. Module: 3,
  2761. RecordDate: recordDate.Unix(),
  2762. Sourse: 1,
  2763. PatientId: patient,
  2764. }
  2765. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 3, patient)
  2766. if dialysisFinish.ID == 0 {
  2767. service.CreateDialysisFinish(finish)
  2768. }
  2769. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2770. redis := service.RedisClient()
  2771. //清空key 值
  2772. redis.Set(key, "", time.Second)
  2773. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2774. redis.Set(keyOne, "", time.Second)
  2775. defer redis.Close()
  2776. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2777. redis.Set(keyTwo, "", time.Second)
  2778. if err == nil {
  2779. c.ServeSuccessJSON(map[string]interface{}{
  2780. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2781. })
  2782. } else {
  2783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2784. }
  2785. }
  2786. }
  2787. func (c *DialysisApiController) PostTreatmentSummary() {
  2788. patient, _ := c.GetInt64("patient", 0)
  2789. recordDateStr := c.GetString("record_date")
  2790. if patient <= 0 {
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2792. return
  2793. }
  2794. adminUserInfo := c.GetAdminUserInfo()
  2795. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2796. if patientInfo.ID == 0 {
  2797. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2798. return
  2799. }
  2800. if len(recordDateStr) == 0 {
  2801. recordDateStr = time.Now().Format("2006-01-02")
  2802. }
  2803. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2804. if parseDateErr != nil {
  2805. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2807. return
  2808. }
  2809. mission := c.GetString("mission")
  2810. dialysis_summary := c.GetString("dialysis_summary")
  2811. nursingRecord := c.GetString("nursing_record")
  2812. specialRecord := c.GetString("special_record")
  2813. sj_nurse := adminUserInfo.AdminUser.Id
  2814. zl_nurse := adminUserInfo.AdminUser.Id
  2815. hd_nurse := adminUserInfo.AdminUser.Id
  2816. xj_nurse := adminUserInfo.AdminUser.Id
  2817. zl_doctor := adminUserInfo.AdminUser.Id
  2818. treatmentSummary := models.TreatmentSummary{
  2819. UserOrgId: adminUserInfo.CurrentOrgId,
  2820. PatientId: patient,
  2821. AssessmentDate: recordDate.Unix(),
  2822. Mission: mission,
  2823. DialysisSummary: dialysis_summary,
  2824. SjNurse: sj_nurse,
  2825. ZlNurse: zl_nurse,
  2826. HdNurse: hd_nurse,
  2827. XjNurse: xj_nurse,
  2828. ZlDoctor: zl_doctor,
  2829. Status: 1,
  2830. CreatedTime: time.Now().Unix(),
  2831. NursingRecord: nursingRecord,
  2832. SpecialRecord: specialRecord,
  2833. }
  2834. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2835. if tempTreatmentSummary.ID == 0 { //新增
  2836. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2837. // 查询信息规挡的设置天数
  2838. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2839. if infor.ID > 0 && infor.WeekDay > 0 {
  2840. var cha_time int64
  2841. timeNowStr := time.Now().Format("2006-01-02")
  2842. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2843. //今日的日期减去设置的日期
  2844. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2845. if cha_time >= recordDate.Unix() {
  2846. //查询审核是否允许
  2847. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  2848. //申请状态不允许的情况 拒绝修改
  2849. if infor.ApplicationStatus != 1 {
  2850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2851. return
  2852. }
  2853. }
  2854. }
  2855. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2856. finish := models.XtDialysisFinish{
  2857. IsFinish: 1,
  2858. UserOrgId: adminUserInfo.CurrentOrgId,
  2859. Status: 1,
  2860. Ctime: time.Now().Unix(),
  2861. Mtime: 0,
  2862. Module: 10,
  2863. RecordDate: recordDate.Unix(),
  2864. Sourse: 1,
  2865. PatientId: patient,
  2866. }
  2867. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, recordDate.Unix(), 10, patient)
  2868. if dialysisFinish.ID == 0 {
  2869. service.CreateDialysisFinish(finish)
  2870. }
  2871. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2872. redis := service.RedisClient()
  2873. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2874. redis.Set(keyOne, "", time.Second)
  2875. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2876. redis.Set(keyThree, "", time.Second)
  2877. defer redis.Close()
  2878. //清空key 值
  2879. redis.Set(key, "", time.Second)
  2880. if err == nil {
  2881. c.ServeSuccessJSON(map[string]interface{}{
  2882. "summary": treatmentSummary,
  2883. })
  2884. } else {
  2885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2886. }
  2887. } else { //修改
  2888. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2889. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2890. // if getPermissionErr != nil {
  2891. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2892. // return
  2893. // } else if headNursePermission == nil {
  2894. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2895. // return
  2896. // }
  2897. //}
  2898. // 查询信息规挡的设置天数
  2899. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  2900. if infor.ID > 0 && infor.WeekDay > 0 {
  2901. var cha_time int64
  2902. timeNowStr := time.Now().Format("2006-01-02")
  2903. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  2904. //今日的日期减去设置的日期
  2905. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  2906. if cha_time >= recordDate.Unix() {
  2907. //查询审核是否允许
  2908. infor, _ := service.GetDialysisInformationByRecordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId, 10)
  2909. //申请状态不允许的情况 拒绝修改
  2910. if infor.ApplicationStatus != 1 {
  2911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  2912. return
  2913. }
  2914. }
  2915. }
  2916. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2917. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2918. treatmentSummary.UpdatedTime = time.Now().Unix()
  2919. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2920. treatmentSummary.ID = tempTreatmentSummary.ID
  2921. err := service.UpdateSummeRecord(&treatmentSummary)
  2922. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2923. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2924. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2925. //清空key 值
  2926. redis := service.RedisClient()
  2927. redis.Set(key, "", time.Second)
  2928. redis.Set(keyOne, "", time.Second)
  2929. redis.Set(keyThree, "", time.Second)
  2930. defer redis.Close()
  2931. if err == nil {
  2932. c.ServeSuccessJSON(map[string]interface{}{
  2933. "summary": treatmentSummary,
  2934. })
  2935. } else {
  2936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2937. }
  2938. }
  2939. }
  2940. func (c *DialysisApiController) GetDeviceList() {
  2941. adminUserInfo := c.GetAdminUserInfo()
  2942. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2943. c.ServeSuccessJSON(map[string]interface{}{
  2944. "device": device,
  2945. })
  2946. }
  2947. func (c *DialysisApiController) GetAllDeviceZone() {
  2948. adminUserInfo := c.GetAdminUserInfo()
  2949. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2950. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2951. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2952. if err == nil {
  2953. c.ServeSuccessJSON(map[string]interface{}{
  2954. "zone": zone,
  2955. "dics": dics,
  2956. "efs": efs,
  2957. })
  2958. }
  2959. }
  2960. func (c *DialysisApiController) GetDialysisWatch() {
  2961. page, _ := c.GetInt64("page", 1)
  2962. limit, _ := c.GetInt64("limit", 10)
  2963. schedulType, _ := c.GetInt64("schedul_type", 0)
  2964. startTime, _ := c.GetInt64("schedul_time", 0)
  2965. partitionType, _ := c.GetInt64("partition_type", 0)
  2966. keywords := c.GetString("keywords")
  2967. start_time, _ := c.GetInt64("start_time")
  2968. end_time, _ := c.GetInt64("end_time")
  2969. adminUserInfo := c.GetAdminUserInfo()
  2970. if len(keywords) > 0 {
  2971. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2972. if err == nil {
  2973. c.ServeSuccessJSON(map[string]interface{}{
  2974. "schedule": dialysisSchedule,
  2975. "total": total,
  2976. })
  2977. } else {
  2978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2979. }
  2980. } else {
  2981. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2982. for _, item := range dialysisSchedule {
  2983. patients, _ := service.GetMonitorPatients(item.PatientId)
  2984. item.MonitorPatients = patients
  2985. orderObj, _ := service.GetMonitorDialysisOrderObj(item.PatientId, item.ScheduleDate)
  2986. item.DialysisOrder = orderObj
  2987. prescription, _ := service.GetMonitorDialysisPrescription(item.PatientId, item.ScheduleDate)
  2988. item.Prescription = prescription
  2989. evaluation, _ := service.GetMonitorPredialysisEvaluation(item.PatientId, item.ScheduleDate)
  2990. item.AssessmentBeforeDislysis = evaluation
  2991. afterdislysis, _ := service.GetMonitorAssessmentAfterDislysis(item.PatientId, item.ScheduleDate)
  2992. item.AssessmentAfterDislysis = afterdislysis
  2993. monitorRecord, _ := service.GetMonitoringRecordList(item.PatientId, item.ScheduleDate)
  2994. item.MonitoringRecord = monitorRecord
  2995. }
  2996. if err == nil {
  2997. c.ServeSuccessJSON(map[string]interface{}{
  2998. "schedule": dialysisSchedule,
  2999. "total": total,
  3000. })
  3001. } else {
  3002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3003. }
  3004. }
  3005. }
  3006. //func (c *DialysisApiController) GetDialysisWatch() {
  3007. // page, _ := c.GetInt64("page", 1)
  3008. // limit, _ := c.GetInt64("limit", 10)
  3009. // schedulType, _ := c.GetInt64("schedul_type", 0)
  3010. // startTime, _ := c.GetInt64("schedul_time", 0)
  3011. // partitionType, _ := c.GetInt64("partition_type", 0)
  3012. // keywords := c.GetString("keywords")
  3013. //
  3014. // adminUserInfo := c.GetAdminUserInfo()
  3015. // if len(keywords) > 0 {
  3016. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  3017. //
  3018. // //获取所有床位号
  3019. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  3020. //
  3021. // //获取透析处方
  3022. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  3023. // //获取透前评估
  3024. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  3025. // //获取上机
  3026. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  3027. // //获取透后
  3028. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  3029. //
  3030. // //获取透后监测
  3031. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  3032. //
  3033. // //获取所有的患者
  3034. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  3035. //
  3036. // //获取所有透析模式
  3037. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  3038. //
  3039. // for key, scheduals := range dialysisSchedule {
  3040. // // 获取患者信息
  3041. // for _, patient := range patients {
  3042. // if scheduals.PatientId == patient.ID {
  3043. // dialysisSchedule[key].MonitorPatients = patient
  3044. // break
  3045. // }
  3046. // }
  3047. // // 床位信息
  3048. // for _, device := range numberList {
  3049. // if scheduals.BedId == device.ID {
  3050. // dialysisSchedule[key].DeviceNumber = device
  3051. // break
  3052. // }
  3053. // }
  3054. //
  3055. // // 医嘱信息
  3056. // for _, prescription := range prescriptions {
  3057. // if scheduals.PatientId == prescription.PatientId {
  3058. // dialysisSchedule[key].Prescription = prescription
  3059. // break
  3060. // }
  3061. // }
  3062. //
  3063. // // 透前评估
  3064. // for _, assessmentBefore := range assessmentBefores {
  3065. // if scheduals.PatientId == assessmentBefore.PatientId {
  3066. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  3067. // break
  3068. // }
  3069. // }
  3070. //
  3071. // // 透析上下机
  3072. // for _, dialysisOrder := range dialysisOrders {
  3073. // if scheduals.PatientId == dialysisOrder.PatientId {
  3074. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  3075. // break
  3076. // }
  3077. // }
  3078. //
  3079. // records := make([]*models.MonitoringRecord, 0)
  3080. // // 透析监测
  3081. // for _, it := range monitorlist {
  3082. // records := append(records, it)
  3083. // if scheduals.PatientId == it.PatientId {
  3084. // dialysisSchedule[key].MonitoringRecord = records
  3085. // }
  3086. // }
  3087. //
  3088. // // 透后评估
  3089. // for _, afterDislysis := range AssessmentAfterDislysis {
  3090. // if scheduals.PatientId == afterDislysis.PatientId {
  3091. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  3092. // break
  3093. // }
  3094. // }
  3095. //
  3096. // //透析模式
  3097. // for _, treatment := range treatments {
  3098. // if scheduals.ModeId == treatment.ID {
  3099. // dialysisSchedule[key].TreatmentMode = treatment
  3100. // break
  3101. // }
  3102. // }
  3103. // }
  3104. // //获取所有床位号
  3105. // if err == nil {
  3106. // c.ServeSuccessJSON(map[string]interface{}{
  3107. // "schedule": dialysisSchedule,
  3108. // "total": total,
  3109. // })
  3110. // } else {
  3111. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3112. // }
  3113. //
  3114. // } else {
  3115. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  3116. // if err == nil {
  3117. // c.ServeSuccessJSON(map[string]interface{}{
  3118. // "schedule": dialysisSchedule,
  3119. // "total": total,
  3120. // })
  3121. // } else {
  3122. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3123. // }
  3124. // }
  3125. //}
  3126. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  3127. patientId, _ := c.GetInt64("id", 0)
  3128. record_date, _ := c.GetInt64("record_date", 0)
  3129. adminUserInfo := c.GetAdminUserInfo()
  3130. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3131. var dialysisStatus int64
  3132. if dialysisOrder == nil { //没有透析记录
  3133. dialysisStatus = 0 //未透析
  3134. } else {
  3135. dialysisStatus = dialysisOrder.Stage
  3136. }
  3137. //用户基本信息
  3138. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3139. //接诊评估
  3140. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3141. //透前评估
  3142. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3143. //临时医嘱
  3144. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3145. //双人核对
  3146. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3147. //透析监测
  3148. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  3149. //透后评估
  3150. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3151. //透析小结
  3152. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3153. //透析处方
  3154. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  3155. if dialysisPrescription.ID == 0 {
  3156. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  3157. c.ServeSuccessJSON(map[string]interface{}{
  3158. "patientInfo": schedualPatientInfo,
  3159. "dialysisPrescription": solution,
  3160. "receiverTreatmentAccess": receiverTreatmentAccess,
  3161. "predialysisEvaluation": PredialysisEvaluation,
  3162. "doctorAdvice": DoctorAdvice,
  3163. "doubleCheck": DoubleCheck,
  3164. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3165. "treatmentSummary": TreatmentSummary,
  3166. "monitorRecord": Record,
  3167. "dialysisStatus": dialysisStatus,
  3168. "dialysisOrder": dialysisOrder,
  3169. "isSolution": 1,
  3170. })
  3171. } else {
  3172. c.ServeSuccessJSON(map[string]interface{}{
  3173. "patientInfo": schedualPatientInfo,
  3174. "dialysisPrescription": dialysisPrescription,
  3175. "receiverTreatmentAccess": receiverTreatmentAccess,
  3176. "predialysisEvaluation": PredialysisEvaluation,
  3177. "doctorAdvice": DoctorAdvice,
  3178. "doubleCheck": DoubleCheck,
  3179. "assessmentAfterDislysis": AssessmentAfterDislysis,
  3180. "treatmentSummary": TreatmentSummary,
  3181. "monitorRecord": Record,
  3182. "dialysisStatus": dialysisStatus,
  3183. "dialysisOrder": dialysisOrder,
  3184. "isSolution": 2,
  3185. })
  3186. }
  3187. }
  3188. func (c *DialysisApiController) CreateDoctorAdvice() {
  3189. patient, _ := c.GetInt64("id", 0)
  3190. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  3191. record_date, _ := c.GetInt64("record_date", 0)
  3192. if patient <= 0 {
  3193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3194. return
  3195. }
  3196. adminUserInfo := c.GetAdminUserInfo()
  3197. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3198. if patientInfo.ID == 0 {
  3199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3200. return
  3201. }
  3202. var advice models.DoctorAdvice
  3203. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  3204. if code > 0 {
  3205. c.ServeFailJSONWithSGJErrorCode(code)
  3206. return
  3207. }
  3208. if advice.ParentId > 0 {
  3209. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  3210. if old.ID == 0 || old.PatientId != patient {
  3211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3212. return
  3213. }
  3214. if old.StopState == 1 || old.ExecutionState == 1 {
  3215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  3216. return
  3217. }
  3218. if old.ParentId > 0 {
  3219. advice.ParentId = old.ParentId
  3220. }
  3221. advice.StartTime = old.StartTime
  3222. advice.AdviceDoctor = old.AdviceDoctor
  3223. advice.DeliveryWay = old.DeliveryWay
  3224. advice.ExecutionFrequency = old.ExecutionFrequency
  3225. }
  3226. advice.RecordDate = record_date
  3227. advice.DialysisOrderId = dialysis_id
  3228. advice.Status = 1
  3229. advice.CreatedTime = time.Now().Unix()
  3230. advice.UpdatedTime = time.Now().Unix()
  3231. advice.StopState = 2
  3232. advice.ExecutionState = 2
  3233. advice.AdviceType = 2
  3234. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3235. advice.PatientId = patient
  3236. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3237. err := service.CreateDoctorAdvice(&advice)
  3238. if err != nil {
  3239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3240. return
  3241. }
  3242. for _, subAdvice := range subAdivice {
  3243. subAdvice.ParentId = advice.ID
  3244. subAdvice.PatientId = patient
  3245. subAdvice.RecordDate = record_date
  3246. subAdvice.CreatedTime = time.Now().Unix()
  3247. subAdvice.UpdatedTime = time.Now().Unix()
  3248. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  3249. }
  3250. service.CreateSubDoctorAdvice(subAdivice)
  3251. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  3252. c.ServeSuccessJSON(map[string]interface{}{
  3253. "msg": "ok",
  3254. "advice": advice,
  3255. "subAdvice": subAdivices,
  3256. })
  3257. return
  3258. }
  3259. func (c *DialysisApiController) EditDoctorAdvice() {
  3260. patient, _ := c.GetInt64("patient", 0)
  3261. id, _ := c.GetInt64("id", 0)
  3262. parent_id, _ := c.GetInt64("parent_id", 0)
  3263. execution_time := c.GetString("execution_time")
  3264. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  3265. // checker, _ := c.GetInt64("checker", 0)
  3266. if id <= 0 || patient <= 0 {
  3267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3268. return
  3269. }
  3270. adminUserInfo := c.GetAdminUserInfo()
  3271. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  3272. if advice.ID == 0 || advice.PatientId != patient {
  3273. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  3274. return
  3275. }
  3276. if len(execution_time) <= 0 {
  3277. utils.ErrorLog("execution_time")
  3278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3279. return
  3280. }
  3281. execution_staff := adminUserInfo.AdminUser.Id
  3282. checker := adminUserInfo.AdminUser.Id
  3283. timeLayout2 := "2006-01-02 15:04"
  3284. loc, _ := time.LoadLocation("Local")
  3285. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  3286. if errs != nil {
  3287. utils.ErrorLog(errs.Error())
  3288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3289. return
  3290. }
  3291. advices := models.DoctorAdvice{
  3292. ExecutionStaff: execution_staff,
  3293. ExecutionTime: theTime.Unix(),
  3294. Checker: checker,
  3295. UpdatedTime: time.Now().Unix(),
  3296. }
  3297. var err error
  3298. if parent_id > 0 {
  3299. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  3300. } else {
  3301. err = service.ExceDoctorAdviceById(&advices, id, patient)
  3302. }
  3303. if err != nil {
  3304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  3305. return
  3306. }
  3307. c.ServeSuccessJSON(map[string]interface{}{
  3308. "msg": "ok",
  3309. "advice": advice,
  3310. })
  3311. return
  3312. }
  3313. func (c *DialysisApiController) GetDoctorAdvice() {
  3314. patient, _ := c.GetInt64("patient_id", 0)
  3315. parent_id, _ := c.GetInt64("parent_id", 0)
  3316. adviceId, _ := c.GetInt64("id", 0)
  3317. if patient <= 0 {
  3318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3319. return
  3320. }
  3321. dminUserInfo := c.GetAdminUserInfo()
  3322. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  3323. if patientInfo.ID == 0 {
  3324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3325. return
  3326. }
  3327. var subAdvice []*models.DoctorAdvice
  3328. var advice models.DoctorAdvice
  3329. if parent_id > 0 {
  3330. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  3331. if advice.ID == 0 || advice.PatientId != patient {
  3332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3333. return
  3334. }
  3335. subAdvice = service.FindSubAdivceById(patient, parent_id)
  3336. } else {
  3337. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  3338. if advice.ID == 0 || advice.PatientId != patient {
  3339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  3340. return
  3341. }
  3342. subAdvice = service.FindSubAdivceById(patient, adviceId)
  3343. }
  3344. c.ServeSuccessJSON(map[string]interface{}{
  3345. "msg": "ok",
  3346. "advice": advice,
  3347. "subAdvice": subAdvice,
  3348. })
  3349. }
  3350. func (this *DialysisApiController) DelMonitor() {
  3351. recordID, _ := this.GetInt64("record_id")
  3352. patientID, _ := this.GetInt64("patient_id")
  3353. if recordID <= 0 || patientID <= 0 {
  3354. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3355. return
  3356. }
  3357. adminInfo := this.GetAdminUserInfo()
  3358. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  3359. if getPatientErr != nil {
  3360. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  3361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3362. return
  3363. } else if patient == nil {
  3364. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3365. return
  3366. }
  3367. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  3368. if getMonitorErr != nil {
  3369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3370. return
  3371. }
  3372. //if monitor != nil {
  3373. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  3374. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  3375. // if getPermissionErr != nil {
  3376. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3377. // return
  3378. // } else if headNursePermission == nil {
  3379. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  3380. // return
  3381. // }
  3382. // }
  3383. //}
  3384. // 查询信息规挡的设置天数
  3385. infor, _ := service.GetDialysisInformationSetting(adminInfo.CurrentOrgId)
  3386. if infor.ID > 0 && infor.WeekDay > 0 {
  3387. var cha_time int64
  3388. timeNowStr := time.Now().Format("2006-01-02")
  3389. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3390. //今日的日期减去设置的日期
  3391. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3392. if cha_time >= monitor.MonitoringDate {
  3393. //查询审核是否允许
  3394. infor, _ := service.GetDialysisInformationByRecordDate(patientID, monitor.MonitoringDate, adminInfo.CurrentOrgId, 7)
  3395. //申请状态不允许的情况 拒绝修改
  3396. if infor.ApplicationStatus != 1 {
  3397. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3398. return
  3399. }
  3400. }
  3401. }
  3402. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  3403. //记录日志
  3404. byterequest, _ := json.Marshal(monitor)
  3405. monitorRecordLog := models.XtMonitorRecordLog{
  3406. RecordDate: monitor.MonitoringDate,
  3407. PatientId: monitor.PatientId,
  3408. Module: 3,
  3409. AdminUserId: adminInfo.AdminUser.Id,
  3410. Ctime: time.Now().Unix(),
  3411. Mtime: 0,
  3412. Status: 1,
  3413. UserOrgId: monitor.UserOrgId,
  3414. ErrLog: string(byterequest),
  3415. Source: "电脑端删除监测",
  3416. }
  3417. service.CreateMonitorRecordLog(monitorRecordLog)
  3418. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  3419. redis := service.RedisClient()
  3420. //清空key 值
  3421. redis.Set(key, "", time.Second)
  3422. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  3423. redis.Set(keyOne, "", time.Second)
  3424. defer redis.Close()
  3425. if err != nil {
  3426. this.ErrorLog("删除透析监测记录失败:%v", err)
  3427. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  3428. return
  3429. }
  3430. this.ServeSuccessJSON(map[string]interface{}{
  3431. "record_id": monitor.ID,
  3432. })
  3433. }
  3434. func (c *DialysisApiController) CreateMonitor() {
  3435. patient, _ := c.GetInt64("id", 0)
  3436. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  3437. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  3438. operate_time, _ := c.GetInt64("operate_time", 0)
  3439. // monitoring_time := c.GetString("monitoring_time")
  3440. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  3441. breathing_rated := c.GetString("breathing_rated")
  3442. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  3443. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  3444. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  3445. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  3446. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  3447. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  3448. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  3449. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  3450. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  3451. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  3452. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  3453. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  3454. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  3455. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  3456. temperature, _ := c.GetFloat("temperature", 0)
  3457. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  3458. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  3459. conductivity, _ := c.GetFloat("conductivity", 0)
  3460. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  3461. heparin, _ := c.GetFloat("heparin", 0)
  3462. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  3463. ktv, _ := c.GetFloat("ktv", 0)
  3464. symptom := c.GetString("symptom")
  3465. dispose := c.GetString("dispose")
  3466. result := c.GetString("results")
  3467. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  3468. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  3469. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  3470. replacement_speed, _ := c.GetFloat("replacement_speed")
  3471. dicarbonate, _ := c.GetFloat("dicarbonate")
  3472. monitoring_date = monitoring_date / 1000
  3473. // operate_time = operate_time / 1000
  3474. if patient <= 0 {
  3475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3476. return
  3477. }
  3478. adminUserInfo := c.GetAdminUserInfo()
  3479. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3480. if patientInfo.ID == 0 {
  3481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3482. return
  3483. }
  3484. monitorRecord := models.MonitoringRecord{
  3485. PatientId: patient,
  3486. MonitoringDate: monitoring_date,
  3487. DialysisOrderId: dialysis_order_id,
  3488. OperateTime: operate_time,
  3489. // MonitoringTime: monitoring_time,
  3490. PulseFrequency: pulse_frequency,
  3491. BreathingRate: breathing_rated,
  3492. SystolicBloodPressure: systolic_blood_pressure,
  3493. DiastolicBloodPressure: diastolic_blood_pressure,
  3494. BloodPressureType: blood_pressure_type,
  3495. BloodFlowVolume: blood_flow_volume,
  3496. VenousPressure: venous_pressure,
  3497. VenousPressureType: venous_pressure_type,
  3498. TransmembranePressure: transmembrane_pressure,
  3499. TransmembranePressureType: transmembrane_pressure_type,
  3500. UltrafiltrationRate: ultrafiltration_rate,
  3501. UltrafiltrationVolume: ultrafiltration_volume,
  3502. SodiumConcentration: sodium_concentration,
  3503. ArterialPressure: arterial_pressure,
  3504. ArterialPressureType: arterial_pressure_type,
  3505. DialysateTemperature: dialysate_temperature,
  3506. Temperature: temperature,
  3507. ReplacementRate: replacement_rate,
  3508. DisplacementQuantity: displacement_quantity,
  3509. Ktv: ktv,
  3510. Symptom: symptom,
  3511. Dispose: dispose,
  3512. Result: result,
  3513. MonitoringNurse: monitoring_nurse,
  3514. Status: 1,
  3515. CreatedTime: time.Now().Unix(),
  3516. UpdatedTime: time.Now().Unix(),
  3517. UserOrgId: adminUserInfo.CurrentOrgId,
  3518. Conductivity: conductivity,
  3519. DisplacementFlowQuantity: displacement_flow_quantity,
  3520. Heparin: heparin,
  3521. DialysateFlow: dialysate_flow,
  3522. MonitorAnticoagulant: monitor_anticoagulant,
  3523. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  3524. ReplacementSpeed: replacement_speed,
  3525. Dicarbonate: dicarbonate,
  3526. }
  3527. // 查询信息规挡的设置天数
  3528. infor, _ := service.GetDialysisInformationSetting(adminUserInfo.CurrentOrgId)
  3529. if infor.ID > 0 && infor.WeekDay > 0 {
  3530. var cha_time int64
  3531. timeNowStr := time.Now().Format("2006-01-02")
  3532. timeNewDate, _ := utils.ParseTimeStringToTime("2006-01-02", timeNowStr)
  3533. //今日的日期减去设置的日期
  3534. cha_time = timeNewDate.Unix() - infor.WeekDay*86400
  3535. if cha_time >= monitoring_date {
  3536. //查询审核是否允许
  3537. infor, _ := service.GetDialysisInformationByRecordDate(patient, monitoring_date, adminUserInfo.CurrentOrgId, 7)
  3538. //申请状态不允许的情况 拒绝修改
  3539. if infor.ApplicationStatus != 1 {
  3540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInformationExist)
  3541. return
  3542. }
  3543. }
  3544. }
  3545. err := service.CreateMonitor(&monitorRecord)
  3546. finish := models.XtDialysisFinish{
  3547. IsFinish: 1,
  3548. UserOrgId: adminUserInfo.CurrentOrgId,
  3549. Status: 1,
  3550. Ctime: time.Now().Unix(),
  3551. Mtime: 0,
  3552. Module: 7,
  3553. RecordDate: monitoring_date,
  3554. Sourse: 1,
  3555. PatientId: patient,
  3556. }
  3557. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, monitoring_date, 7, patient)
  3558. if dialysisFinish.ID == 0 {
  3559. service.CreateDialysisFinish(finish)
  3560. }
  3561. redis := service.RedisClient()
  3562. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  3563. redis.Set(key, "", time.Second)
  3564. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  3565. redis.Set(keyOne, "", time.Second)
  3566. redis.Close()
  3567. if err != nil {
  3568. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  3569. return
  3570. }
  3571. c.ServeSuccessJSON(map[string]interface{}{
  3572. "msg": "ok",
  3573. "monitor": monitorRecord,
  3574. })
  3575. return
  3576. }
  3577. // 已弃用
  3578. // func (c *DialysisApiController) CreateRecordData() {
  3579. // patient, _ := c.GetInt64("id", 0)
  3580. // status, _ := c.GetInt64("status", 0)
  3581. // now := time.Now()
  3582. // year, month, day := now.Date()
  3583. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  3584. // todayTimeStamp := today_time.Unix()
  3585. // if patient <= 0 {
  3586. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3587. // return
  3588. // }
  3589. // adminUserInfo := c.GetAdminUserInfo()
  3590. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  3591. // if patientInfo.ID == 0 {
  3592. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3593. // return
  3594. // }
  3595. // record := &models.DialysisOrder{
  3596. // DialysisDate: todayTimeStamp,
  3597. // UserOrgId: adminUserInfo.CurrentOrgId,
  3598. // PatientId: patient,
  3599. // Stage: status,
  3600. // Status: 1,
  3601. // CreatedTime: time.Now().Unix(),
  3602. // UpdatedTime: time.Now().Unix(),
  3603. // }
  3604. // if status == 1 {
  3605. // //创建透析记录
  3606. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  3607. // if err == nil {
  3608. // c.ServeSuccessJSON(map[string]interface{}{
  3609. // "dialysisOrder": record,
  3610. // })
  3611. // } else {
  3612. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3613. // }
  3614. // } else {
  3615. // record_id, _ := c.GetInt64("record_id", 0)
  3616. // //修改透析记录状态
  3617. // errs := service.ModifyDialysisRecord(record_id)
  3618. // //结束时候透析次数加1
  3619. // service.UpdateSolutionByPatientId(patient)
  3620. // if errs == nil {
  3621. // c.ServeSuccessJSON(map[string]interface{}{
  3622. // "dialysisOrder": record,
  3623. // })
  3624. // } else {
  3625. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3626. // }
  3627. // }
  3628. // }
  3629. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  3630. dataBody := make(map[string]interface{}, 0)
  3631. err := json.Unmarshal(data, &dataBody)
  3632. if err != nil {
  3633. utils.ErrorLog(err.Error())
  3634. code = enums.ErrorCodeParamWrong
  3635. return
  3636. }
  3637. timeLayout := "2006-01-02 "
  3638. timeLayout2 := "2006-01-02 15:04"
  3639. loc, _ := time.LoadLocation("Local")
  3640. if action == "create" {
  3641. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3642. utils.ErrorLog("advice_type")
  3643. code = enums.ErrorCodeParamWrong
  3644. return
  3645. }
  3646. adviceType := int64(dataBody["advice_type"].(float64))
  3647. if adviceType != 1 && adviceType != 2 {
  3648. utils.ErrorLog("advice_type != 1&&2")
  3649. code = enums.ErrorCodeParamWrong
  3650. return
  3651. }
  3652. advice.AdviceType = adviceType
  3653. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3654. utils.ErrorLog("advice_date")
  3655. code = enums.ErrorCodeParamWrong
  3656. return
  3657. }
  3658. adviceDate, _ := dataBody["advice_date"].(string)
  3659. if len(adviceDate) == 0 {
  3660. utils.ErrorLog("len(adviceDate) == 0")
  3661. code = enums.ErrorCodeParamWrong
  3662. return
  3663. }
  3664. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  3665. if err != nil {
  3666. utils.ErrorLog(err.Error())
  3667. code = enums.ErrorCodeParamWrong
  3668. return
  3669. }
  3670. advice.AdviceDate = theTime.Unix()
  3671. }
  3672. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3673. utils.ErrorLog("start_time")
  3674. code = enums.ErrorCodeParamWrong
  3675. return
  3676. }
  3677. startDate, _ := dataBody["start_time"].(string)
  3678. if len(startDate) == 0 {
  3679. utils.ErrorLog("len(startDate) == 0")
  3680. code = enums.ErrorCodeParamWrong
  3681. return
  3682. }
  3683. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  3684. if err != nil {
  3685. utils.ErrorLog(err.Error())
  3686. code = enums.ErrorCodeParamWrong
  3687. return
  3688. }
  3689. advice.StartTime = theTime.Unix()
  3690. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  3691. utils.ErrorLog("advice_name")
  3692. code = enums.ErrorCodeParamWrong
  3693. return
  3694. }
  3695. adviceName, _ := dataBody["advice_name"].(string)
  3696. if len(adviceName) == 0 {
  3697. utils.ErrorLog("len(advice_name) == 0")
  3698. code = enums.ErrorCodeParamWrong
  3699. return
  3700. }
  3701. advice.AdviceName = adviceName
  3702. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  3703. utils.ErrorLog("delivery_way")
  3704. code = enums.ErrorCodeParamWrong
  3705. return
  3706. }
  3707. deliveryWay, _ := dataBody["delivery_way"].(string)
  3708. if len(deliveryWay) == 0 {
  3709. utils.ErrorLog("len(deliveryWay) == 0")
  3710. code = enums.ErrorCodeParamWrong
  3711. return
  3712. }
  3713. advice.DeliveryWay = deliveryWay
  3714. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3715. utils.ErrorLog("execution_frequency")
  3716. code = enums.ErrorCodeParamWrong
  3717. return
  3718. }
  3719. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3720. if len(execution_frequency) == 0 {
  3721. utils.ErrorLog("len(execution_frequency) == 0")
  3722. code = enums.ErrorCodeParamWrong
  3723. return
  3724. }
  3725. advice.ExecutionFrequency = execution_frequency
  3726. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3727. adviceDsc, _ := dataBody["advice_desc"].(string)
  3728. advice.AdviceDesc = adviceDsc
  3729. }
  3730. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3731. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3732. advice.DrugSpecUnit = drugSpecUnit
  3733. }
  3734. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3735. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3736. advice.SingleDose = singleDose
  3737. }
  3738. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3739. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3740. advice.SingleDoseUnit = singleDoseUnit
  3741. }
  3742. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3743. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3744. advice.PrescribingNumber = prescribingNumber
  3745. }
  3746. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3747. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3748. advice.PrescribingNumberUnit = prescribingNumberUnit
  3749. }
  3750. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3751. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3752. if len(thisContagions) > 0 {
  3753. for _, item := range thisContagions {
  3754. items := item.(map[string]interface{})
  3755. advice_name, _ := items["advice_name"].(string)
  3756. advice_desc, _ := items["advice_desc"].(string)
  3757. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3758. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3759. single_dose_unit, _ := items["single_dose_unit"].(string)
  3760. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3761. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3762. advice := &models.DoctorAdvice{
  3763. AdviceName: advice_name,
  3764. AdviceDesc: advice_desc,
  3765. SingleDose: single_dose,
  3766. SingleDoseUnit: single_dose_unit,
  3767. DrugSpecUnit: drug_spec_unit,
  3768. PrescribingNumber: prescribing_number,
  3769. PrescribingNumberUnit: prescribing_number_unit,
  3770. }
  3771. subAdvice = append(subAdvice, advice)
  3772. }
  3773. }
  3774. }
  3775. return
  3776. }
  3777. func (c *DialysisApiController) GetDialysisOrder() {
  3778. //xtno := c.GetString("xtno")
  3779. xtdate := c.GetString("xtdate")
  3780. patient_id, _ := c.GetInt64("patient_id")
  3781. timeLayout := "2006-01-02"
  3782. loc, _ := time.LoadLocation("Local")
  3783. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3784. if err != nil {
  3785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3786. return
  3787. }
  3788. xttime := theTime.Unix()
  3789. operatorIDs := make([]int64, 0)
  3790. adminUserInfo := c.GetAdminUserInfo()
  3791. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3792. patientInfo, _ := service.FindPatientWithDeviceByPatientId(adminUserInfo.CurrentOrgId, patient_id, xttime)
  3793. //透析单
  3794. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3795. if dialysisOrder != nil {
  3796. if dialysisOrder.FinishNurse > 0 {
  3797. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3798. }
  3799. if dialysisOrder.StartNurse > 0 {
  3800. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3801. }
  3802. }
  3803. //透前评估
  3804. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3805. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3806. //透后评估
  3807. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3808. if AssessmentAfterDislysis.Modifier > 0 {
  3809. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3810. }
  3811. //上次透前评估
  3812. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3813. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3814. //透析处方
  3815. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3816. if dialysisPrescription.PrescriptionDoctor > 0 {
  3817. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3818. }
  3819. //获取病人的透析模式
  3820. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3821. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3822. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3823. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3824. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3825. //获取透析处方
  3826. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3827. //获取临时医嘱
  3828. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3829. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3830. //获取医嘱内容
  3831. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3832. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3833. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3834. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3835. //获取上次的透后体重
  3836. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3837. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3838. //获取透析次数
  3839. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3840. if len(DoctorAdvice) > 0 {
  3841. for _, item := range DoctorAdvice {
  3842. if item.AdviceDoctor > 0 {
  3843. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3844. }
  3845. if item.ExecutionStaff > 0 {
  3846. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3847. }
  3848. if item.Checker > 0 {
  3849. operatorIDs = append(operatorIDs, item.Checker)
  3850. }
  3851. }
  3852. }
  3853. //透析监测
  3854. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3855. //透析检测
  3856. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3857. //透析小结
  3858. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3859. //接诊评估
  3860. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3861. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3862. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3863. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3864. patientInfo.TotalDialysis = dialysis_count
  3865. }
  3866. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3867. if xttime <= 1672416000 {
  3868. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3869. patientInfo.TotalDialysis = dialysis_count
  3870. }
  3871. if xttime >= 1672502400 {
  3872. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3873. patientInfo.TotalDialysis = dialysis_count
  3874. }
  3875. }
  3876. //相关操作对应的操作人
  3877. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3878. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3879. fmt.Println("operators", operators)
  3880. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3881. //获取当前日期月份的第一天
  3882. firstmonth := service.GetFirstDateOfMonth(theTime)
  3883. firstMonthDate := firstmonth.Unix()
  3884. //获取当前月份的病人透析次数
  3885. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3886. //获取his数据
  3887. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3888. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3889. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3890. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3891. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3892. //获取诊断
  3893. prescriptionInfo, _ := service.GetPrescriptionInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3894. patientDiagnose, _ := service.FindPatientDianose(adminUserInfo.CurrentOrgId)
  3895. lastSchedule, _ := service.FindLastSchedule(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3896. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3897. // for _, item := range projects {
  3898. // var advice *models.HisDoctorAdviceInfo
  3899. // advice.ID = item.ID
  3900. // advice.Checker = item.Checker
  3901. // advice.CheckTime = item.CheckTime
  3902. // advice.CheckState = item.CheckState
  3903. // advice.ExecutionState = item.ExecutionState
  3904. // advice.ExecutionStaff = item.ExecutionStaff
  3905. // advice.PrescribingNumber = float64(item.Count)
  3906. // advice.PrescribingNumberUnit = item.Unit
  3907. // advice.AdviceDoctor = item.Doctor
  3908. // if item.Type == 3 {
  3909. // advice.AdviceName = item.GoodInfo.GoodName
  3910. // } else if item.Type == 2 {
  3911. // advice.AdviceName = item.HisProject.ProjectName
  3912. // }
  3913. // advice.StartTime = item.StartTime
  3914. // hisAdvice = append(hisAdvice, advice)
  3915. // }
  3916. //}
  3917. if config.IsOpen == 1 {
  3918. c.ServeSuccessJSON(map[string]interface{}{
  3919. "xtdate": xtdate,
  3920. "users": adminUser,
  3921. "patientInfo": patientInfo,
  3922. "PredialysisEvaluation": PredialysisEvaluation,
  3923. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3924. "dialysisPrescription": dialysisPrescription,
  3925. "advices": hisAdvice,
  3926. "monitors": Record,
  3927. "summary": TreatmentSummary,
  3928. "receiverTreatmentAccess": receiverTreatmentAccess,
  3929. "dialysisOrder": dialysisOrder,
  3930. "operators": operators,
  3931. "org_template_info": templateInfo,
  3932. "check": check,
  3933. "schedule": schedule,
  3934. "dialysisway": dialysisway,
  3935. "order": order,
  3936. "doctorAdvice": doctorAdvice,
  3937. "doctor": doctor,
  3938. "nurse": nurse,
  3939. "doctorAdevieInfo": doctorAdevieInfo,
  3940. "total": total,
  3941. "startNuse": startNuse,
  3942. "DoctorName": DoctorName,
  3943. "assessmentAfterDislysis": assessmentAfterDislysis,
  3944. "predialysName": predialysName,
  3945. "FinishNuse": FinishNuse,
  3946. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3947. "dialysiscount": dialysiscount,
  3948. "last_order": lastOrder,
  3949. "project_config": project_config,
  3950. "projects": projects,
  3951. "prescriptionInfo": prescriptionInfo,
  3952. "patientDiagnose": patientDiagnose,
  3953. "lastSchedule": lastSchedule,
  3954. })
  3955. }
  3956. if config.IsOpen == 0 || config.IsOpen == 2 {
  3957. c.ServeSuccessJSON(map[string]interface{}{
  3958. "xtdate": xtdate,
  3959. "users": adminUser,
  3960. "patientInfo": patientInfo,
  3961. "PredialysisEvaluation": PredialysisEvaluation,
  3962. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3963. "dialysisPrescription": dialysisPrescription,
  3964. "advices": DoctorAdvice,
  3965. "monitors": Record,
  3966. "summary": TreatmentSummary,
  3967. "receiverTreatmentAccess": receiverTreatmentAccess,
  3968. "dialysisOrder": dialysisOrder,
  3969. "operators": operators,
  3970. "org_template_info": templateInfo,
  3971. "check": check,
  3972. "schedule": schedule,
  3973. "dialysisway": dialysisway,
  3974. "order": order,
  3975. "doctorAdvice": doctorAdvice,
  3976. "doctor": doctor,
  3977. "nurse": nurse,
  3978. "doctorAdevieInfo": doctorAdevieInfo,
  3979. "total": total,
  3980. "startNuse": startNuse,
  3981. "DoctorName": DoctorName,
  3982. "assessmentAfterDislysis": assessmentAfterDislysis,
  3983. "predialysName": predialysName,
  3984. "FinishNuse": FinishNuse,
  3985. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3986. "dialysiscount": dialysiscount,
  3987. "last_order": lastOrder,
  3988. "project_config": project_config,
  3989. "projects": projects,
  3990. "prescriptionInfo": prescriptionInfo,
  3991. "patientDiagnose": patientDiagnose,
  3992. "lastSchedule": lastSchedule,
  3993. })
  3994. }
  3995. }
  3996. func (c *DialysisApiController) GetLongAdvice() {
  3997. patient_id, _ := c.GetInt64("patient_id")
  3998. adminUserInfo := c.GetAdminUserInfo()
  3999. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4000. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4001. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4002. c.ServeSuccessJSON(map[string]interface{}{
  4003. "status": "1",
  4004. })
  4005. return
  4006. } else { //开启推送提醒
  4007. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4008. var advice_three []*models.DoctorAdvice
  4009. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4010. recordDateStr := time.Now().Format("2006-01-02")
  4011. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4012. nowtime := recordDate.Unix()
  4013. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4014. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  4015. for _, advice := range advices {
  4016. if advice.FrequencyType == 3 {
  4017. t := time.Now()
  4018. week := int(t.Weekday())
  4019. switch week {
  4020. case 1:
  4021. if strings.Index(advice.WeekDay, "周一") == -1 {
  4022. advice_three = append(advice_three, advice)
  4023. }
  4024. break
  4025. case 2:
  4026. if strings.Index(advice.WeekDay, "周二") == -1 {
  4027. advice_three = append(advice_three, advice)
  4028. }
  4029. break
  4030. case 3:
  4031. if strings.Index(advice.WeekDay, "周三") == -1 {
  4032. advice_three = append(advice_three, advice)
  4033. }
  4034. break
  4035. case 4:
  4036. if strings.Index(advice.WeekDay, "周四") == -1 {
  4037. advice_three = append(advice_three, advice)
  4038. }
  4039. break
  4040. case 5:
  4041. if strings.Index(advice.WeekDay, "周五") == -1 {
  4042. advice_three = append(advice_three, advice)
  4043. }
  4044. break
  4045. case 6:
  4046. if strings.Index(advice.WeekDay, "周六") == -1 {
  4047. advice_three = append(advice_three, advice)
  4048. }
  4049. break
  4050. case 0:
  4051. if strings.Index(advice.WeekDay, "周日") == -1 {
  4052. advice_three = append(advice_three, advice)
  4053. }
  4054. break
  4055. }
  4056. }
  4057. }
  4058. for _, advice := range advices_two {
  4059. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4060. now := p.Unix()
  4061. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4062. dayStr2 := "-" + dayStr
  4063. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4064. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4065. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4066. for _, ad := range advices {
  4067. advice_three = append(advice_three, ad)
  4068. }
  4069. }
  4070. if err == nil {
  4071. c.ServeSuccessJSON(map[string]interface{}{
  4072. "status": "2",
  4073. "advices": advices,
  4074. "advices_two": RemoveRepeatedElement(advice_three),
  4075. "is_open_remind": config.IsOpenRemind,
  4076. })
  4077. }
  4078. }
  4079. }
  4080. func (c *DialysisApiController) GetLongAdviceOne() {
  4081. patient_id, _ := c.GetInt64("patient_id")
  4082. schedule_date := c.GetString("schedule_date")
  4083. adminUserInfo := c.GetAdminUserInfo()
  4084. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4085. timeLayout := "2006-01-02"
  4086. loc, _ := time.LoadLocation("Local")
  4087. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4088. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4089. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4090. c.ServeSuccessJSON(map[string]interface{}{
  4091. "status": "1",
  4092. })
  4093. return
  4094. } else { //开启推送提醒
  4095. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4096. var advice_three []*models.DoctorAdvice
  4097. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4098. //recordDateStr := time.Now().Format("2006-01-02")
  4099. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4100. //
  4101. //nowtime := recordDate.Unix()
  4102. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4103. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  4104. for _, advice := range advices {
  4105. if advice.FrequencyType == 3 {
  4106. t := time.Now()
  4107. week := int(t.Weekday())
  4108. switch week {
  4109. case 1:
  4110. if strings.Index(advice.WeekDay, "周一") == -1 {
  4111. advice_three = append(advice_three, advice)
  4112. }
  4113. break
  4114. case 2:
  4115. if strings.Index(advice.WeekDay, "周二") == -1 {
  4116. advice_three = append(advice_three, advice)
  4117. }
  4118. break
  4119. case 3:
  4120. if strings.Index(advice.WeekDay, "周三") == -1 {
  4121. advice_three = append(advice_three, advice)
  4122. }
  4123. break
  4124. case 4:
  4125. if strings.Index(advice.WeekDay, "周四") == -1 {
  4126. advice_three = append(advice_three, advice)
  4127. }
  4128. break
  4129. case 5:
  4130. if strings.Index(advice.WeekDay, "周五") == -1 {
  4131. advice_three = append(advice_three, advice)
  4132. }
  4133. break
  4134. case 6:
  4135. if strings.Index(advice.WeekDay, "周六") == -1 {
  4136. advice_three = append(advice_three, advice)
  4137. }
  4138. break
  4139. case 0:
  4140. if strings.Index(advice.WeekDay, "周日") == -1 {
  4141. advice_three = append(advice_three, advice)
  4142. }
  4143. break
  4144. }
  4145. }
  4146. }
  4147. for _, advice := range advices_two {
  4148. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4149. now := p.Unix()
  4150. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4151. dayStr2 := "-" + dayStr
  4152. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4153. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4154. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4155. for _, ad := range advices {
  4156. advice_three = append(advice_three, ad)
  4157. }
  4158. }
  4159. if err == nil {
  4160. c.ServeSuccessJSON(map[string]interface{}{
  4161. "status": "2",
  4162. "advices": advices,
  4163. "advices_two": RemoveRepeatedElement(advice_three),
  4164. "is_open_remind": config.IsOpenRemind,
  4165. })
  4166. }
  4167. }
  4168. }
  4169. func (c *DialysisApiController) GetLongAdviceTwo() {
  4170. patient_id, _ := c.GetInt64("patient_id")
  4171. schedule_date, _ := c.GetInt64("schedule_date")
  4172. adminUserInfo := c.GetAdminUserInfo()
  4173. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  4174. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  4175. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  4176. c.ServeSuccessJSON(map[string]interface{}{
  4177. "status": "1",
  4178. })
  4179. return
  4180. } else { //开启推送提醒
  4181. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  4182. var advice_three []*models.DoctorAdvice
  4183. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  4184. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4185. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  4186. for _, advice := range advices {
  4187. if advice.FrequencyType == 3 {
  4188. t := time.Now()
  4189. week := int(t.Weekday())
  4190. switch week {
  4191. case 1:
  4192. if strings.Index(advice.WeekDay, "周一") == -1 {
  4193. advice_three = append(advice_three, advice)
  4194. }
  4195. break
  4196. case 2:
  4197. if strings.Index(advice.WeekDay, "周二") == -1 {
  4198. advice_three = append(advice_three, advice)
  4199. }
  4200. break
  4201. case 3:
  4202. if strings.Index(advice.WeekDay, "周三") == -1 {
  4203. advice_three = append(advice_three, advice)
  4204. }
  4205. break
  4206. case 4:
  4207. if strings.Index(advice.WeekDay, "周四") == -1 {
  4208. advice_three = append(advice_three, advice)
  4209. }
  4210. break
  4211. case 5:
  4212. if strings.Index(advice.WeekDay, "周五") == -1 {
  4213. advice_three = append(advice_three, advice)
  4214. }
  4215. break
  4216. case 6:
  4217. if strings.Index(advice.WeekDay, "周六") == -1 {
  4218. advice_three = append(advice_three, advice)
  4219. }
  4220. break
  4221. case 0:
  4222. if strings.Index(advice.WeekDay, "周日") == -1 {
  4223. advice_three = append(advice_three, advice)
  4224. }
  4225. break
  4226. }
  4227. }
  4228. }
  4229. for _, advice := range advices_two {
  4230. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  4231. now := p.Unix()
  4232. dayStr := strconv.FormatInt(advice.DayCount, 10)
  4233. dayStr2 := "-" + dayStr
  4234. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  4235. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  4236. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  4237. for _, ad := range advices {
  4238. advice_three = append(advice_three, ad)
  4239. }
  4240. }
  4241. if err == nil {
  4242. c.ServeSuccessJSON(map[string]interface{}{
  4243. "status": "2",
  4244. "advices": advices,
  4245. "advices_two": RemoveRepeatedElement(advice_three),
  4246. "is_open_remind": config.IsOpenRemind,
  4247. })
  4248. }
  4249. }
  4250. }
  4251. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  4252. newArr = make([]*models.DoctorAdvice, 0)
  4253. for i := 0; i < len(arr); i++ {
  4254. repeat := false
  4255. for j := i + 1; j < len(arr); j++ {
  4256. if arr[i].ID == arr[j].ID {
  4257. repeat = true
  4258. break
  4259. }
  4260. }
  4261. if !repeat {
  4262. newArr = append(newArr, arr[i])
  4263. }
  4264. }
  4265. return
  4266. }
  4267. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  4268. patient, _ := c.GetInt64("id", 0)
  4269. groupNo, _ := c.GetInt64("groupno", 0)
  4270. if patient <= 0 {
  4271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4272. return
  4273. }
  4274. adminUserInfo := c.GetAdminUserInfo()
  4275. dataBody := make(map[string]interface{}, 0)
  4276. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4277. if err != nil {
  4278. utils.ErrorLog(err.Error())
  4279. return
  4280. }
  4281. utils.ErrorLog("%v", dataBody)
  4282. timeLayout := "2006-01-02 15:04"
  4283. loc, _ := time.LoadLocation("Local")
  4284. timeLayout2 := "2006-01-02"
  4285. loc2, _ := time.LoadLocation("Local")
  4286. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  4287. utils.ErrorLog("advice_type")
  4288. return
  4289. }
  4290. adviceType := int64(2)
  4291. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  4292. utils.ErrorLog("advice_date")
  4293. return
  4294. }
  4295. adviceDate, _ := dataBody["advice_date"].(string)
  4296. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  4297. AdviceDate := theTime.Unix()
  4298. RecordDate := theTime.Unix()
  4299. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  4300. utils.ErrorLog("start_time")
  4301. return
  4302. }
  4303. startTime, _ := dataBody["start_time"].(string)
  4304. if len(startTime) == 0 {
  4305. utils.ErrorLog("len(start_time) == 0")
  4306. return
  4307. }
  4308. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  4309. fmt.Println("theTimeUnix", theTimeUnix.Unix())
  4310. //if err != nil {
  4311. // utils.ErrorLog(err.Error())
  4312. // return
  4313. //}
  4314. StartTime := theTimeUnix.Unix()
  4315. fmt.Println("startTIME", StartTime)
  4316. Remark := ""
  4317. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  4318. remark, _ := dataBody["remark"].(string)
  4319. Remark = remark
  4320. }
  4321. var advices []*models.GroupAdvice
  4322. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  4323. utils.ErrorLog("advices")
  4324. return
  4325. }
  4326. adviceNames := dataBody["advices"].([]interface{})
  4327. for _, adviceNameMap := range adviceNames {
  4328. adviceNameM := adviceNameMap.(map[string]interface{})
  4329. var advice models.GroupAdvice
  4330. advice.Remark = Remark
  4331. advice.AdviceType = adviceType
  4332. advice.StartTime = StartTime
  4333. if StartTime < 0 {
  4334. advice.StartTime = time.Now().Unix()
  4335. }
  4336. advice.AdviceDate = AdviceDate
  4337. advice.RecordDate = RecordDate
  4338. advice.Status = 1
  4339. advice.CreatedTime = time.Now().Unix()
  4340. advice.UpdatedTime = time.Now().Unix()
  4341. advice.StopState = 2
  4342. advice.ExecutionState = 2
  4343. advice.UserOrgId = adminUserInfo.CurrentOrgId
  4344. advice.PatientId = patient
  4345. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  4346. advice.IsSettle = 2
  4347. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  4348. utils.ErrorLog("advice_name")
  4349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4350. return
  4351. }
  4352. adviceName, _ := adviceNameM["advice_name"].(string)
  4353. if len(adviceName) == 0 {
  4354. utils.ErrorLog("len(advice_name) == 0")
  4355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4356. return
  4357. }
  4358. advice.AdviceName = adviceName
  4359. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  4360. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  4361. advice.DrugSpec = drugSpec
  4362. }
  4363. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  4364. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  4365. advice.AdviceDesc = adviceDesc
  4366. }
  4367. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  4368. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  4369. advice.DrugSpecUnit = drugSpecUnit
  4370. }
  4371. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  4372. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  4373. // advice.SingleDose = singleDose
  4374. //}
  4375. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  4376. //single_dose := int64(adviceNameM["single_dose"].(float64))
  4377. advice.SingleDose = adviceNameM["single_dose"].(float64)
  4378. }
  4379. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  4380. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  4381. advice.SingleDoseUnit = singleDoseUnit
  4382. }
  4383. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  4384. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  4385. // advice.PrescribingNumber = prescribingNumber
  4386. //}
  4387. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  4388. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  4389. }
  4390. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  4391. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  4392. advice.PrescribingNumberUnit = prescribingNumberUnit
  4393. }
  4394. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  4395. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  4396. advice.DeliveryWay = deliveryWay
  4397. }
  4398. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4399. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4400. advice.ExecutionFrequency = executionFrequency
  4401. }
  4402. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  4403. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  4404. advice.FrequencyType = frequency_type
  4405. }
  4406. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  4407. day_count := int64(adviceNameM["day_count"].(float64))
  4408. advice.DayCount = day_count
  4409. }
  4410. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  4411. way := int64(adviceNameM["way"].(float64))
  4412. advice.Way = way
  4413. }
  4414. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  4415. drug_id := int64(adviceNameM["drug_id"].(float64))
  4416. advice.DrugId = drug_id
  4417. }
  4418. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  4419. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  4420. advice.DrugNameId = drug_name_id
  4421. }
  4422. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  4423. week_day, _ := adviceNameM["week_day"].(string)
  4424. advice.WeekDay = week_day
  4425. }
  4426. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  4427. template_id, _ := adviceNameM["template_id"].(string)
  4428. advice.TemplateId = template_id
  4429. }
  4430. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  4431. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  4432. advice.ExecutionFrequency = executionFrequency
  4433. }
  4434. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  4435. children := adviceNameM["child"].([]interface{})
  4436. if len(children) > 0 {
  4437. for _, childrenMap := range children {
  4438. childMap := childrenMap.(map[string]interface{})
  4439. var child models.GroupAdvice
  4440. child.Remark = Remark
  4441. child.AdviceType = adviceType
  4442. child.StartTime = StartTime
  4443. child.AdviceDate = AdviceDate
  4444. child.RecordDate = RecordDate
  4445. child.Status = 1
  4446. child.CreatedTime = time.Now().Unix()
  4447. child.UpdatedTime = time.Now().Unix()
  4448. child.StopState = 2
  4449. child.ExecutionState = 2
  4450. child.UserOrgId = adminUserInfo.CurrentOrgId
  4451. child.PatientId = patient
  4452. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  4453. child.IsSettle = 2
  4454. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  4455. utils.ErrorLog("child advice_name")
  4456. return
  4457. }
  4458. childAdviceName, _ := childMap["advice_name"].(string)
  4459. if len(childAdviceName) == 0 {
  4460. utils.ErrorLog("len(child advice_name) == 0")
  4461. return
  4462. }
  4463. child.AdviceName = childAdviceName
  4464. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  4465. childAdviceDesc, _ := childMap["advice_desc"].(string)
  4466. child.AdviceDesc = childAdviceDesc
  4467. }
  4468. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  4469. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  4470. child.DrugSpec = childDrugSpec
  4471. }
  4472. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  4473. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  4474. child.DrugSpecUnit = childDrugSpecUnit
  4475. }
  4476. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  4477. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4478. child.SingleDose = childSingleDose
  4479. }
  4480. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  4481. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4482. child.SingleDose = childMap["single_dose"].(float64)
  4483. }
  4484. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  4485. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4486. child.Remark = childMap["remark"].(string)
  4487. }
  4488. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  4489. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  4490. child.DrugId = int64(childMap["drug_id"].(float64))
  4491. }
  4492. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  4493. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  4494. child.SingleDoseUnit = childSingleDoseUnit
  4495. }
  4496. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  4497. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4498. child.PrescribingNumber = childPrescribingNumber
  4499. }
  4500. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  4501. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  4502. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  4503. }
  4504. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  4505. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  4506. child.PrescribingNumberUnit = childPrescribingNumberUnit
  4507. }
  4508. child.DeliveryWay = advice.DeliveryWay
  4509. child.ExecutionFrequency = advice.ExecutionFrequency
  4510. advice.Children = append(advice.Children, &child)
  4511. }
  4512. }
  4513. }
  4514. advices = append(advices, &advice)
  4515. }
  4516. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  4517. for _, item := range advices {
  4518. //记录日志
  4519. byterequest, _ := json.Marshal(item)
  4520. adviceLog := models.XtDoctorAdviceLog{
  4521. UserOrgId: item.UserOrgId,
  4522. PatientId: item.PatientId,
  4523. AdminUserId: adminUserInfo.AdminUser.Id,
  4524. Module: 1,
  4525. ErrLog: string(byterequest),
  4526. Status: 1,
  4527. Ctime: time.Now().Unix(),
  4528. Mtime: 0,
  4529. Source: "电脑端医嘱推送",
  4530. RecordDate: item.AdviceDate,
  4531. }
  4532. service.CreateDoctorAdviceLog(adviceLog)
  4533. }
  4534. //创建步骤表
  4535. finish := models.XtDialysisFinish{
  4536. IsFinish: 1,
  4537. UserOrgId: adminUserInfo.CurrentOrgId,
  4538. Status: 1,
  4539. Ctime: time.Now().Unix(),
  4540. Mtime: 0,
  4541. Module: 4,
  4542. RecordDate: AdviceDate,
  4543. Sourse: 1,
  4544. PatientId: patient,
  4545. }
  4546. dialysisFinish, _ := service.GetDialysisFinish(adminUserInfo.CurrentOrgId, AdviceDate, 4, patient)
  4547. if dialysisFinish.ID == 0 {
  4548. service.CreateDialysisFinish(finish)
  4549. }
  4550. redis := service.RedisClient()
  4551. formatAdviceDate := theTime.Format("2006-01-02")
  4552. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  4553. redis.Set(key, "", time.Second)
  4554. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  4555. redis.Set(keyOne, "", time.Second)
  4556. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  4557. redis.Set(keyFour, "", time.Second)
  4558. defer redis.Close()
  4559. if err != nil {
  4560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  4561. return
  4562. }
  4563. c.ServeSuccessJSON(map[string]interface{}{
  4564. "msg": "ok",
  4565. "advices": list,
  4566. })
  4567. return
  4568. }
  4569. func (c *DialysisApiController) GetSolution() {
  4570. patient_id, _ := c.GetInt64("patient_id")
  4571. mode_id, _ := c.GetInt64("mode_id")
  4572. adminUserInfo := c.GetAdminUserInfo()
  4573. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4574. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdTen(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  4575. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  4576. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  4577. if err != nil {
  4578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4579. return
  4580. }
  4581. c.ServeSuccessJSON(map[string]interface{}{
  4582. "solution": solution,
  4583. "prescription": prescription,
  4584. "system_prescription": system_prescription,
  4585. "dialysisPrescription": dialysisPrescription,
  4586. })
  4587. }
  4588. func (c *DialysisApiController) GetSchedule() {
  4589. schedual_type, _ := c.GetInt64("schedual_type")
  4590. adminUserInfo := c.GetAdminUserInfo()
  4591. //timeLayout := "2006-01-02 15:04:05"
  4592. //
  4593. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  4594. //loc, _ := time.LoadLocation("Local")
  4595. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  4596. //scheduleTime := theStartTime.Unix()
  4597. scheduleTime, _ := c.GetInt64("record_date")
  4598. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  4599. c.ServeSuccessJSON(map[string]interface{}{
  4600. "number": deviceNumber,
  4601. })
  4602. }
  4603. func (this *DialysisApiController) GetTodayMonitor() {
  4604. thisTime := time.Now()
  4605. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  4606. timeLayout := "2006-01-02 15:04:05"
  4607. loc, _ := time.LoadLocation("Local")
  4608. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  4609. theAssessmentDateTime := theStartTime.Unix()
  4610. patientID, _ := this.GetInt64("patient_id")
  4611. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  4612. adminInfo := this.GetAdminUserInfo()
  4613. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4614. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  4615. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  4616. var ultrafiltration_rate float64
  4617. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4618. //针对福建医师汇 获取透前评估预增脱水量
  4619. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  4620. fmt.Println("透前评估数据", evaluation)
  4621. if prescription.ID > 0 {
  4622. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  4623. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  4624. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  4625. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4626. record.UltrafiltrationRate = ultrafiltration_rate
  4627. }
  4628. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  4629. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4630. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4631. record.UltrafiltrationRate = ultrafiltration_rate
  4632. }
  4633. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  4634. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  4635. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  4636. record.UltrafiltrationRate = ultrafiltration_rate
  4637. }
  4638. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  4639. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4640. record.UltrafiltrationRate = ultrafiltration_rate
  4641. }
  4642. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  4643. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4644. record.UltrafiltrationRate = ultrafiltration_rate
  4645. }
  4646. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  4647. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4648. record.UltrafiltrationRate = ultrafiltration_rate
  4649. }
  4650. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  4651. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  4652. record.UltrafiltrationRate = ultrafiltration_rate
  4653. }
  4654. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  4655. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  4656. record.UltrafiltrationRate = ultrafiltration_rate
  4657. }
  4658. // 只针对方济医院
  4659. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4660. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  4661. ultrafiltration_rate = value
  4662. record.UltrafiltrationRate = ultrafiltration_rate
  4663. }
  4664. //长沙南雅
  4665. 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 {
  4666. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  4667. record.UltrafiltrationRate = ultrafiltration_rate
  4668. }
  4669. }
  4670. }
  4671. // record.UltrafiltrationRate = ultrafiltration_rate
  4672. record.UltrafiltrationVolume = 0
  4673. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  4674. if ultrafiltration_rate > 0 {
  4675. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  4676. record.UltrafiltrationVolume = value
  4677. }
  4678. }
  4679. 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 {
  4680. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  4681. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4682. record.UltrafiltrationVolume = ultrafiltration_volume
  4683. }
  4684. }
  4685. //长沙南雅
  4686. 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 {
  4687. if ultrafiltration_rate > 0 {
  4688. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  4689. record.UltrafiltrationVolume = ultrafiltration_volume
  4690. }
  4691. }
  4692. if template.TemplateId == 47 || template.TemplateId == 54 {
  4693. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  4694. }
  4695. this.ServeSuccessJSON(map[string]interface{}{
  4696. "monitor": record,
  4697. })
  4698. }
  4699. func (c *DialysisApiController) UploadDryWeight() {
  4700. patient_id, _ := c.GetInt64("id")
  4701. dry_weight, _ := c.GetFloat("dry_weight")
  4702. doctor_id, _ := c.GetInt64("doctor_id")
  4703. remark := c.GetString("remark")
  4704. adminUserInfo := c.GetAdminUserInfo()
  4705. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  4706. fmt.Println(err)
  4707. if err == gorm.ErrRecordNotFound {
  4708. dryWeight := &models.SgjPatientDryweight{
  4709. PatientId: patient_id,
  4710. DryWeight: dry_weight,
  4711. Remakes: remark,
  4712. Ctime: time.Now().Unix(),
  4713. Mtime: time.Now().Unix(),
  4714. Creator: doctor_id,
  4715. Status: 1,
  4716. UserOrgId: adminUserInfo.CurrentOrgId,
  4717. AdjustedValue: "/",
  4718. UserId: adminUserInfo.AdminUser.Id,
  4719. }
  4720. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4721. loc, _ := time.LoadLocation("Local")
  4722. nowTime := time.Now()
  4723. nowDay := nowTime.Format("2006-01-02")
  4724. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4725. redis := service.RedisClient()
  4726. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4727. redis.Set(keyOne, "", time.Second)
  4728. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4729. redis.Set(key, "", time.Second)
  4730. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4731. redis.Set(keyTwo, "", time.Second)
  4732. redis.Close()
  4733. if createErr == nil {
  4734. c.ServeSuccessJSON(map[string]interface{}{
  4735. "msg": "提交成功",
  4736. "weight": dryWeight,
  4737. })
  4738. }
  4739. } else {
  4740. dryWeight := &models.SgjPatientDryweight{
  4741. PatientId: patient_id,
  4742. DryWeight: dry_weight,
  4743. Remakes: remark,
  4744. Ctime: time.Now().Unix(),
  4745. Mtime: time.Now().Unix(),
  4746. Creator: doctor_id,
  4747. Status: 1,
  4748. UserOrgId: adminUserInfo.CurrentOrgId,
  4749. AdjustedValue: "/",
  4750. UserId: adminUserInfo.AdminUser.Id,
  4751. }
  4752. var value float64
  4753. value = dry_weight - weightAdjust.DryWeight
  4754. fmt.Println(value)
  4755. if value < 0 {
  4756. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  4757. } else if value == 0 {
  4758. dryWeight.AdjustedValue = "/"
  4759. } else if value > 0 {
  4760. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4761. }
  4762. fmt.Println(value)
  4763. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4764. loc, _ := time.LoadLocation("Local")
  4765. nowTime := time.Now()
  4766. nowDay := nowTime.Format("2006-01-02")
  4767. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4768. redis := service.RedisClient()
  4769. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4770. redis.Set(keyOne, "", time.Second)
  4771. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4772. redis.Set(key, "", time.Second)
  4773. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4774. redis.Set(keyTwo, "", time.Second)
  4775. redis.Close()
  4776. if createErr == nil {
  4777. c.ServeSuccessJSON(map[string]interface{}{
  4778. "msg": "提交成功",
  4779. "weight": dryWeight,
  4780. })
  4781. }
  4782. }
  4783. }
  4784. func (this *DialysisApiController) GetFuncPurview() {
  4785. adminUserInfo := this.GetAdminUserInfo()
  4786. user_id := adminUserInfo.AdminUser.Id
  4787. app_id := adminUserInfo.CurrentAppId
  4788. org_id := adminUserInfo.CurrentOrgId
  4789. create_url := this.GetString("create_url")
  4790. modify_url := this.GetString("modify_url")
  4791. modify_other_url := this.GetString("modify_other_url")
  4792. del_url := this.GetString("del_url")
  4793. del_other_url := this.GetString("del_other_url")
  4794. exce_url := this.GetString("exce_url")
  4795. check_url := this.GetString("check_url")
  4796. modify_exce_url := this.GetString("modify_exce_url")
  4797. module, _ := this.GetInt64("module", 0)
  4798. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4799. var is_has_create bool
  4800. var is_has_modify bool
  4801. var is_has_modify_other bool
  4802. var is_has_del bool
  4803. var is_has_del_other bool
  4804. var is_has_exce bool
  4805. var is_has_check bool
  4806. var is_has_modify_exce bool
  4807. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4808. if adminUserInfo.AdminUser.Id != org.Creator {
  4809. if app_role != nil {
  4810. if len(app_role.RoleIds) > 0 {
  4811. roles := strings.Split(app_role.RoleIds, ",")
  4812. var userRolePurviews string
  4813. for _, item := range roles {
  4814. role_id, _ := strconv.ParseInt(item, 10, 64)
  4815. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4816. if len(userRolePurviews) == 0 {
  4817. userRolePurviews = purviews
  4818. } else {
  4819. userRolePurviews = userRolePurviews + "," + purviews
  4820. }
  4821. }
  4822. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4823. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4824. for _, item := range funcPurviews {
  4825. //for _, url := range strings.Split(item.Urlfor,","){
  4826. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4827. is_has_create = true
  4828. }
  4829. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4830. is_has_modify = true
  4831. }
  4832. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4833. is_has_modify_other = true
  4834. }
  4835. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4836. is_has_del = true
  4837. }
  4838. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4839. is_has_del_other = true
  4840. }
  4841. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4842. is_has_exce = true
  4843. }
  4844. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4845. is_has_check = true
  4846. }
  4847. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4848. is_has_modify_exce = true
  4849. }
  4850. }
  4851. } else {
  4852. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4853. return
  4854. }
  4855. this.ServeSuccessJSON(map[string]interface{}{
  4856. "is_has_create": is_has_create,
  4857. "is_has_modify": is_has_modify,
  4858. "is_has_modify_other": is_has_modify_other,
  4859. "is_has_del": is_has_del,
  4860. "is_has_del_other": is_has_del_other,
  4861. "is_has_exce": is_has_exce,
  4862. "is_has_check": is_has_check,
  4863. "is_has_modify_exce": is_has_modify_exce,
  4864. "module": module,
  4865. })
  4866. } else {
  4867. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4868. return
  4869. }
  4870. } else {
  4871. this.ServeSuccessJSON(map[string]interface{}{
  4872. "is_has_create": true,
  4873. "is_has_modify": true,
  4874. "is_has_modify_other": true,
  4875. "is_has_del": true,
  4876. "is_has_del_other": true,
  4877. "is_has_exce": true,
  4878. "is_has_check": true,
  4879. "is_has_modify_exce": true,
  4880. "module": true,
  4881. })
  4882. }
  4883. }
  4884. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4885. patient_id, _ := this.GetInt64("patient_id", 0)
  4886. advice_date, _ := this.GetInt64("advice_date")
  4887. adminUserInfo := this.GetAdminUserInfo()
  4888. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4889. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4890. this.ServeSuccessJSON(map[string]interface{}{
  4891. "doctorAdvice": doctorAdvice,
  4892. "hisDoctorAdvice": hisDoctorAdvice,
  4893. })
  4894. }
  4895. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4896. change_type, _ := this.GetInt64("type", 0)
  4897. record_date := this.GetString("record_time")
  4898. patient_id, _ := this.GetInt64("patient_id", 0)
  4899. timeLayout := "2006-01-02"
  4900. loc, _ := time.LoadLocation("Local")
  4901. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4902. record_time := theAdviceRecordTime.Unix()
  4903. adminUserInfo := this.GetAdminUserInfo()
  4904. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4905. if err == nil {
  4906. if len(advices) == 0 {
  4907. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4908. return
  4909. } else {
  4910. this.ServeSuccessJSON(map[string]interface{}{
  4911. "advices": advices,
  4912. "schedule": sch,
  4913. })
  4914. return
  4915. }
  4916. } else {
  4917. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4918. return
  4919. }
  4920. }
  4921. func (c *DialysisApiController) GetDialysisGoods() {
  4922. schedualDate := c.GetString("schedule_date")
  4923. schedule_type, _ := c.GetInt64("schedule_type")
  4924. partition_id, _ := c.GetInt64("partition_id")
  4925. page, _ := c.GetInt("page")
  4926. limit, _ := c.GetInt("limit")
  4927. keywords := c.GetString("keywords")
  4928. patient_id, _ := c.GetInt64("patient_id")
  4929. good_type, _ := c.GetInt64("good_type")
  4930. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4931. if parseDateErr != nil && len(schedualDate) != 0 {
  4932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4933. return
  4934. }
  4935. schedualEndDate := int64(0)
  4936. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4937. if parseDateErr != nil && len(schedualDate) != 0 {
  4938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4939. return
  4940. }
  4941. schedualEndDate = endDate.Unix()
  4942. adminUser := c.GetAdminUserInfo()
  4943. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4944. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4945. if err == gorm.ErrRecordNotFound {
  4946. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4947. var ids []int64
  4948. for _, item := range list {
  4949. ids = append(ids, item.PatientId)
  4950. }
  4951. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4952. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4953. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4954. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4955. item.LastAutomaticReduceDetail = goodUser
  4956. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4957. }
  4958. c.ServeSuccessJSON(map[string]interface{}{
  4959. "dialysis_goods": dialysisGoods,
  4960. "good_type": goodTypes,
  4961. "total": total,
  4962. })
  4963. return
  4964. } else if err == nil {
  4965. //获取当天排班的每个患者的库存使用情况
  4966. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4967. var ids []int64
  4968. for _, item := range list {
  4969. ids = append(ids, item.PatientId)
  4970. }
  4971. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4972. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4973. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4974. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4975. fmt.Println(goodUser)
  4976. fmt.Println(lastGoodUserDetial)
  4977. item.LastAutomaticReduceDetail = goodUser
  4978. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4979. }
  4980. if err == nil {
  4981. c.ServeSuccessJSON(map[string]interface{}{
  4982. "dialysis_goods": dialysisGoods,
  4983. "good_type": goodTypes,
  4984. "total": total,
  4985. })
  4986. return
  4987. } else {
  4988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4989. return
  4990. }
  4991. } else if err != nil {
  4992. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4993. return
  4994. }
  4995. }
  4996. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4997. start_time := c.GetString("start_time")
  4998. end_time := c.GetString("end_time")
  4999. timeLayout := "2006-01-02"
  5000. loc, _ := time.LoadLocation("Local")
  5001. var theStartTime int64
  5002. if len(start_time) > 0 {
  5003. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5004. if err != nil {
  5005. utils.ErrorLog(err.Error())
  5006. }
  5007. theStartTime = theTime.Unix()
  5008. }
  5009. var theEndtTime int64
  5010. if len(end_time) > 0 {
  5011. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5012. if err != nil {
  5013. utils.ErrorLog(err.Error())
  5014. }
  5015. theEndtTime = theTime.Unix()
  5016. }
  5017. adminUser := c.GetAdminUserInfo()
  5018. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  5019. if err == nil {
  5020. c.ServeSuccessJSON(map[string]interface{}{
  5021. "stock_out": outInfo,
  5022. })
  5023. return
  5024. } else {
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5026. return
  5027. }
  5028. }
  5029. func (c *DialysisApiController) GetRoleList() {
  5030. orgId := c.GetAdminUserInfo().CurrentOrgId
  5031. admin_user_id, _ := c.GetInt64("admin_user_id")
  5032. list, err := service.GetRoleList(orgId, admin_user_id)
  5033. if err == nil {
  5034. c.ServeSuccessJSON(map[string]interface{}{
  5035. "adminRole": list,
  5036. })
  5037. return
  5038. } else {
  5039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5040. return
  5041. }
  5042. }
  5043. func (c *DialysisApiController) GetInitPrintData() {
  5044. patient_id, _ := c.GetInt64("patient_id")
  5045. record_date, _ := c.GetInt64("record_date")
  5046. orgId := c.GetAdminUserInfo().CurrentOrgId
  5047. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  5048. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  5049. if err == nil {
  5050. c.ServeSuccessJSON(map[string]interface{}{
  5051. "list": list,
  5052. "assessmentAfterDislysis": assessmentAfterDislysis,
  5053. })
  5054. return
  5055. } else {
  5056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5057. return
  5058. }
  5059. }
  5060. func (c *DialysisApiController) GetInitPrintDataOne() {
  5061. patient_id, _ := c.GetInt64("patient_id")
  5062. start_time := c.GetString("record_date")
  5063. timeLayout := "2006-01-02"
  5064. loc, _ := time.LoadLocation("Local")
  5065. var theStartTime int64
  5066. if len(start_time) > 0 {
  5067. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5068. if err != nil {
  5069. utils.ErrorLog(err.Error())
  5070. }
  5071. theStartTime = theTime.Unix()
  5072. }
  5073. orgId := c.GetAdminUserInfo().CurrentOrgId
  5074. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  5075. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  5076. if err == nil {
  5077. c.ServeSuccessJSON(map[string]interface{}{
  5078. "list": list,
  5079. "assessmentAfterDislysis": assessmentAfterDislysis,
  5080. })
  5081. return
  5082. } else {
  5083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5084. return
  5085. }
  5086. }
  5087. // 新接口
  5088. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  5089. keyword := this.GetString("keywords")
  5090. limit, _ := this.GetInt64("limit")
  5091. page, _ := this.GetInt64("page")
  5092. partition_id, _ := this.GetInt64("partition_id")
  5093. schedule_type, _ := this.GetInt64("schedule_type")
  5094. start_time := this.GetString("schedule_date")
  5095. advice_ids := this.GetString("ids")
  5096. var ids []string
  5097. if advice_ids != "" {
  5098. ids = strings.Split(advice_ids, ",")
  5099. }
  5100. timeLayout := "2006-01-02"
  5101. loc, _ := time.LoadLocation("Local")
  5102. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5103. orgId := this.GetAdminUserInfo().CurrentOrgId
  5104. _, config := service.FindXTHisRecordByOrgId(orgId)
  5105. goodType, _ := service.GetAllGoodType(orgId)
  5106. if config.IsOpen != 1 {
  5107. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5108. if err == nil {
  5109. this.ServeSuccessJSON(map[string]interface{}{
  5110. "list": list,
  5111. "total": total,
  5112. "config": config,
  5113. "goodType": goodType,
  5114. })
  5115. return
  5116. } else {
  5117. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5118. return
  5119. }
  5120. }
  5121. if config.IsOpen == 1 {
  5122. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  5123. if err == nil {
  5124. this.ServeSuccessJSON(map[string]interface{}{
  5125. "list": list,
  5126. "total": total,
  5127. "config": config,
  5128. "goodType": goodType,
  5129. })
  5130. return
  5131. }
  5132. }
  5133. }
  5134. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  5135. keyword := this.GetString("keywords")
  5136. limit, _ := this.GetInt64("limit")
  5137. page, _ := this.GetInt64("page")
  5138. partition_id, _ := this.GetInt64("partition_id")
  5139. schedule_type, _ := this.GetInt64("schedule_type")
  5140. start_time := this.GetString("schedule_date")
  5141. ids := this.GetString("ids")
  5142. var idArray []string
  5143. if ids != "" {
  5144. idArray = strings.Split(ids, ",")
  5145. }
  5146. timeLayout := "2006-01-02"
  5147. loc, _ := time.LoadLocation("Local")
  5148. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5149. orgId := this.GetAdminUserInfo().CurrentOrgId
  5150. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5151. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  5152. //获取长期医嘱
  5153. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5154. _, config := service.FindXTHisRecordByOrgId(orgId)
  5155. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  5156. if err == nil {
  5157. this.ServeSuccessJSON(map[string]interface{}{
  5158. "list": list,
  5159. "total": total,
  5160. "adviceList": adviceList,
  5161. "config": config,
  5162. "drugList": drugList,
  5163. "tablelist": tablelist,
  5164. })
  5165. return
  5166. } else {
  5167. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5168. return
  5169. }
  5170. }
  5171. func (this *DialysisApiController) SaveDialysisSetting() {
  5172. orgId := this.GetAdminUserInfo().CurrentOrgId
  5173. device_number_set, _ := this.GetInt64("device_number_set")
  5174. device_type_set, _ := this.GetInt64("device_type_set")
  5175. name_set, _ := this.GetInt64("name_set")
  5176. admission_number_set, _ := this.GetInt64("admission_number_set")
  5177. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  5178. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  5179. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  5180. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  5181. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  5182. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  5183. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  5184. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  5185. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  5186. mode_id_set, _ := this.GetInt64("mode_id_set")
  5187. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  5188. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  5189. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  5190. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  5191. kalium_set, _ := this.GetInt64("kalium_set")
  5192. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  5193. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  5194. glucose_set, _ := this.GetInt64("glucose_set")
  5195. sodium_set, _ := this.GetInt64("sodium_set")
  5196. calcium_set, _ := this.GetInt64("calcium_set")
  5197. blood_access_set, _ := this.GetInt64("blood_access_set")
  5198. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  5199. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  5200. dialysisSetting := models.XtDialysisSetting{
  5201. Sodium: sodium_set,
  5202. Calcium: calcium_set,
  5203. BloodAccess: blood_access_set,
  5204. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  5205. DisplaceLiquiPart: displace_liqui_part_set,
  5206. UserOrgId: orgId,
  5207. Status: 1,
  5208. DeviceNumber: device_number_set,
  5209. DeviceType: device_type_set,
  5210. Name: name_set,
  5211. AdmissionNumber: admission_number_set,
  5212. DialysisNo: dialysis_no_set,
  5213. WeightBefor: weight_befor_set,
  5214. DryWeight: dry_weight_set,
  5215. BloodPressure: blood_pressure_set,
  5216. UltrafiltrationVolume: ultrafiltration_volume_set,
  5217. InternalFistula: internal_fistula_set,
  5218. BloodFlowVolume: blood_flow_volume_set,
  5219. Anticoagulant: anticoagulant_set,
  5220. SealingFluidDispose: sealing_fluid_dispose_set,
  5221. ModeId: mode_id_set,
  5222. DialysisTime: dialysis_time_set,
  5223. DialysisDialyszers: dialysis_dialyszers_set,
  5224. DialysisIrrigation: dialysis_irrigation_set,
  5225. Gaijiliang: gaijiliang_set,
  5226. Kalium: kalium_set,
  5227. DisplaceLiquiValue: displace_liqui_value_set,
  5228. Bicarbonate: bicarbonate_set,
  5229. Glucose: glucose_set,
  5230. Ctime: time.Now().Unix(),
  5231. Mtime: time.Now().Unix(),
  5232. }
  5233. err := service.SaveDialysisSetting(dialysisSetting)
  5234. if err == nil {
  5235. this.ServeSuccessJSON(map[string]interface{}{
  5236. "dialysisSetting": dialysisSetting,
  5237. })
  5238. return
  5239. } else {
  5240. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5241. return
  5242. }
  5243. }
  5244. func (this *DialysisApiController) GetDialysisSetting() {
  5245. orgId := this.GetAdminUserInfo().CurrentOrgId
  5246. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5247. this.ServeSuccessJSON(map[string]interface{}{
  5248. "dialysisSett": dialysisSett,
  5249. })
  5250. return
  5251. }
  5252. func (this *DialysisApiController) GetDialysisParameterList() {
  5253. keyword := this.GetString("keywords")
  5254. limit, _ := this.GetInt64("limit")
  5255. page, _ := this.GetInt64("page")
  5256. //partition_id, _ := this.GetInt64("partition_id")
  5257. partion_type := this.GetString("partition_id")
  5258. idSplit := strings.Split(partion_type, ",")
  5259. schedule_type, _ := this.GetInt64("schedule_type")
  5260. start_time := this.GetString("schedule_date")
  5261. timeLayout := "2006-01-02"
  5262. loc, _ := time.LoadLocation("Local")
  5263. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5264. orgId := this.GetAdminUserInfo().CurrentOrgId
  5265. scheduids := this.GetString("ids")
  5266. var ids []string
  5267. if scheduids != "" {
  5268. ids = strings.Split(scheduids, ",")
  5269. }
  5270. list, total, err := service.GetDialysisParameterList(keyword, limit, page, idSplit, schedule_type, startTime.Unix(), orgId, ids)
  5271. dialysisSett, _ := service.GetDialysisSetting(orgId)
  5272. if err == nil {
  5273. this.ServeSuccessJSON(map[string]interface{}{
  5274. "list": list,
  5275. "total": total,
  5276. "dialysisSett": dialysisSett,
  5277. })
  5278. return
  5279. } else {
  5280. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5281. return
  5282. }
  5283. }
  5284. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  5285. orgId := this.GetAdminUserInfo().CurrentOrgId
  5286. schedule_type, _ := this.GetInt64("schedule_type")
  5287. //partion_type, _ := this.GetInt64("partion_type")
  5288. start_time := this.GetString("selected_date")
  5289. partion_type := this.GetString("partion_type")
  5290. var ids []string
  5291. ids = strings.Split(partion_type, ",")
  5292. timeLayout := "2006-01-02"
  5293. loc, _ := time.LoadLocation("Local")
  5294. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5295. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  5296. if err == nil {
  5297. this.ServeSuccessJSON(map[string]interface{}{
  5298. "list": list,
  5299. })
  5300. return
  5301. } else {
  5302. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5303. return
  5304. }
  5305. }
  5306. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  5307. orgId := this.GetAdminUserInfo().CurrentOrgId
  5308. schedule_type, _ := this.GetInt64("schedule_type")
  5309. //partion_type, _ := this.GetInt64("partion_type")
  5310. partion_type := this.GetString("partion_type")
  5311. var ids []string
  5312. ids = strings.Split(partion_type, ",")
  5313. start_time := this.GetString("selected_date")
  5314. timeLayout := "2006-01-02"
  5315. loc, _ := time.LoadLocation("Local")
  5316. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5317. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  5318. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  5319. //获取长期医嘱
  5320. adviceList, _ := service.GetAllLongAdviceList(orgId)
  5321. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5322. _, config := service.FindXTHisRecordByOrgId(orgId)
  5323. if err == nil {
  5324. this.ServeSuccessJSON(map[string]interface{}{
  5325. "list": list,
  5326. "drug": drug,
  5327. "adviceList": adviceList,
  5328. "config": config,
  5329. "tablelist": tablelist,
  5330. })
  5331. return
  5332. } else {
  5333. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5334. return
  5335. }
  5336. }
  5337. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  5338. orgId := this.GetAdminUserInfo().CurrentOrgId
  5339. schedule_type, _ := this.GetInt64("schedule_type")
  5340. partion_type, _ := this.GetInt64("partion_type")
  5341. start_time := this.GetString("selected_date")
  5342. timeLayout := "2006-01-02"
  5343. loc, _ := time.LoadLocation("Local")
  5344. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5345. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  5346. if err == nil {
  5347. this.ServeSuccessJSON(map[string]interface{}{
  5348. "list": list,
  5349. })
  5350. return
  5351. } else {
  5352. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5353. return
  5354. }
  5355. }
  5356. func (this *DialysisApiController) SaveHisDialysis() {
  5357. var ids []string
  5358. advice_ids := this.GetString("ids")
  5359. ids = strings.Split(advice_ids, ",")
  5360. orgId := this.GetAdminUserInfo().CurrentOrgId
  5361. service.SaveHisDialysis(orgId, ids)
  5362. returnData := make(map[string]interface{}, 0)
  5363. returnData["msg"] = "ok"
  5364. this.ServeSuccessJSON(returnData)
  5365. return
  5366. }
  5367. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  5368. orgId := this.GetAdminUserInfo().CurrentOrgId
  5369. schedule_type, _ := this.GetInt64("schedule_type")
  5370. //partion_type, _ := this.GetInt64("partion_type")
  5371. partion_type := this.GetString("partion_type")
  5372. var ids []string
  5373. ids = strings.Split(partion_type, ",")
  5374. start_time := this.GetString("selected_date")
  5375. timeLayout := "2006-01-02"
  5376. loc, _ := time.LoadLocation("Local")
  5377. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5378. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  5379. this.ServeSuccessJSON(map[string]interface{}{
  5380. "list": list,
  5381. })
  5382. return
  5383. }
  5384. func (this *DialysisApiController) GetPatientSchedule() {
  5385. orgId := this.GetAdminUserInfo().CurrentOrgId
  5386. patient_id, _ := this.GetInt64("patient_id")
  5387. schedule_date, _ := this.GetInt64("schedule_date")
  5388. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  5389. this.ServeSuccessJSON(map[string]interface{}{
  5390. "schedulePatient": schedulePatient,
  5391. })
  5392. }
  5393. func (c *DialysisApiController) GetSchedulePrintList() {
  5394. page, _ := c.GetInt64("page", 1)
  5395. limit, _ := c.GetInt64("limit", 10)
  5396. schedulType, _ := c.GetInt64("schedule_type", 0)
  5397. partitionType, _ := c.GetInt64("partition_type", 0)
  5398. keywords := c.GetString("keywords")
  5399. schedule_date := c.GetString("schedule_date")
  5400. timeLayout := "2006-01-02"
  5401. loc, _ := time.LoadLocation("Local")
  5402. var theStartTime int64
  5403. if len(schedule_date) > 0 {
  5404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  5405. if err != nil {
  5406. utils.ErrorLog(err.Error())
  5407. }
  5408. theStartTime = theTime.Unix()
  5409. }
  5410. adminUserInfo := c.GetAdminUserInfo()
  5411. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5412. for _, item := range list {
  5413. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  5414. item.DialysisOrderTwenty = order
  5415. }
  5416. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  5417. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  5418. c.ServeSuccessJSON(map[string]interface{}{
  5419. "list": list,
  5420. "total": total,
  5421. "numberList": numberList,
  5422. "listOne": listOne,
  5423. })
  5424. }
  5425. func (this *DialysisApiController) GetSolutionListByOrgId() {
  5426. orgId := this.GetAdminUserInfo().CurrentOrgId
  5427. list, _ := service.GetSolutionListByOrgId(orgId)
  5428. for _, item := range list {
  5429. //获取该模式最新的1条数据
  5430. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  5431. //更新状态值
  5432. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  5433. }
  5434. this.ServeSuccessJSON(map[string]interface{}{
  5435. "list": list,
  5436. })
  5437. }
  5438. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  5439. orgId := this.GetAdminUserInfo().CurrentOrgId
  5440. is_open, _ := this.GetInt64("is_open")
  5441. idsStr := this.GetString("str")
  5442. recordIDStrs := strings.Split(idsStr, ",")
  5443. start_time := this.GetString("advice_date")
  5444. exec_time, _ := this.GetInt64("exec_time")
  5445. timeLayout := "2006-01-02"
  5446. loc, _ := time.LoadLocation("Local")
  5447. var startTime int64
  5448. if len(start_time) > 0 {
  5449. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5450. if err != nil {
  5451. //fmt.Println(err)
  5452. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5453. return
  5454. }
  5455. startTime = theTime.Unix()
  5456. }
  5457. config, _ := service.GetDrugOpenConfigOne(orgId)
  5458. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5459. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5460. //his医嘱
  5461. if is_open == 1 {
  5462. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  5463. //查找未执行医嘱
  5464. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5465. for _, item := range list {
  5466. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5467. this.ServeSuccessJSON(map[string]interface{}{
  5468. "msg": "3",
  5469. })
  5470. return
  5471. }
  5472. }
  5473. for _, item := range groupList {
  5474. for _, it := range list {
  5475. if item.DrugId == it.DrugId {
  5476. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5477. }
  5478. }
  5479. }
  5480. for _, item := range groupList {
  5481. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5482. var sum_out_count int64
  5483. for _, it := range item.ChildDoctorAdvice {
  5484. var prescribing_number int64
  5485. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5486. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5487. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5488. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5489. }
  5490. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5491. prescribing_number = parseIntPrescribingNumber
  5492. }
  5493. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5494. prescribing_number = parseIntPrescribingNumber
  5495. }
  5496. sum_out_count += prescribing_number
  5497. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5498. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5499. //库存不足
  5500. if sum_out_count > drugStockOut.FlushCount {
  5501. this.ServeSuccessJSON(map[string]interface{}{
  5502. "msg": "2",
  5503. "drug": medical,
  5504. })
  5505. return
  5506. }
  5507. }
  5508. }
  5509. creater := this.GetAdminUserInfo().AdminUser.Id
  5510. //执行出库逻辑
  5511. for _, item := range list {
  5512. hisadvice := &models.HisDoctorAdviceInfo{
  5513. ID: item.ID,
  5514. UserOrgId: item.UserOrgId,
  5515. PatientId: item.PatientId,
  5516. AdviceType: item.AdviceType,
  5517. AdviceDate: item.AdviceDate,
  5518. StartTime: item.StartTime,
  5519. AdviceName: item.AdviceName,
  5520. AdviceDesc: item.AdviceDesc,
  5521. ReminderDate: item.ReminderDate,
  5522. SingleDose: item.SingleDose,
  5523. SingleDoseUnit: item.SingleDoseUnit,
  5524. DrugSpec: item.DrugSpec,
  5525. DrugSpecUnit: item.DrugSpecUnit,
  5526. PrescribingNumber: item.PrescribingNumber,
  5527. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5528. DeliveryWay: item.DeliveryWay,
  5529. ExecutionFrequency: item.ExecutionFrequency,
  5530. AdviceDoctor: item.AdviceDoctor,
  5531. Status: 1,
  5532. CreatedTime: item.CreatedTime,
  5533. UpdatedTime: item.UpdatedTime,
  5534. AdviceAffirm: item.AdviceAffirm,
  5535. Remark: item.Remark,
  5536. StopTime: item.StopTime,
  5537. StopReason: item.StopReason,
  5538. StopDoctor: item.StopDoctor,
  5539. StopState: item.StopState,
  5540. ParentId: item.ParentId,
  5541. ExecutionTime: item.ExecutionTime,
  5542. ExecutionStaff: creater,
  5543. ExecutionState: item.ExecutionState,
  5544. Checker: item.Checker,
  5545. RecordDate: item.RecordDate,
  5546. DialysisOrderId: item.DialysisOrderId,
  5547. CheckTime: item.CheckTime,
  5548. CheckState: item.CheckState,
  5549. RemindType: item.RemindType,
  5550. FrequencyType: item.FrequencyType,
  5551. DayCount: item.DayCount,
  5552. WeekDay: item.WeekDay,
  5553. TemplateId: item.TemplateId,
  5554. Modifier: item.Modifier,
  5555. Way: item.Way,
  5556. DrugId: item.DrugId,
  5557. ExecutionFrequencyId: item.ExecutionFrequencyId,
  5558. }
  5559. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5560. if medical.IsUse == 2 {
  5561. if config.IsOpen != 1 {
  5562. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5563. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5564. }
  5565. //不通过药房发药
  5566. if pharmacyConfig.IsOpen != 1 {
  5567. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  5568. }
  5569. //查询默认仓库
  5570. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5571. //查询默认仓库剩余多少库存
  5572. var sum_count int64
  5573. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5574. for _, its := range stockInfo {
  5575. if its.MaxUnit == medical.MaxUnit {
  5576. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5577. }
  5578. sum_count += its.StockMaxNumber + its.StockMinNumber
  5579. }
  5580. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5581. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5582. }
  5583. }
  5584. info := models.HisDoctorAdviceInfo{
  5585. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5586. ExecutionTime: exec_time,
  5587. ExecutionState: 1,
  5588. UpdatedTime: time.Now().Unix(),
  5589. }
  5590. //执行医嘱
  5591. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  5592. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5593. redis := service.RedisClient()
  5594. //清空key 值
  5595. redis.Set(key, "", time.Second)
  5596. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5597. redis.Set(keyTwo, "", time.Second)
  5598. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5599. redis.Set(keyThree, "", time.Second)
  5600. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5601. theTime := toTime.Format("2006-01-02")
  5602. fmt.Println("theTIME", theTime)
  5603. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5604. redis.Set(keyFour, "", time.Second)
  5605. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5606. redis.Set(keyFive, "", time.Second)
  5607. }
  5608. } else {
  5609. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  5610. //查找未执行医嘱
  5611. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  5612. for _, item := range groupList {
  5613. for _, it := range list {
  5614. if item.DrugId == it.DrugId {
  5615. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  5616. }
  5617. }
  5618. }
  5619. for _, item := range groupList {
  5620. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5621. var sum_out_count int64
  5622. for _, it := range item.ChildDoctorAdvice {
  5623. var prescribing_number int64
  5624. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  5625. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5626. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5627. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5628. }
  5629. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5630. prescribing_number = parseIntPrescribingNumber
  5631. }
  5632. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5633. prescribing_number = parseIntPrescribingNumber
  5634. }
  5635. sum_out_count += prescribing_number
  5636. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5637. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5638. //库存不足
  5639. if sum_out_count > drugStockOut.FlushCount {
  5640. this.ServeSuccessJSON(map[string]interface{}{
  5641. "msg": "2",
  5642. "drug": medical,
  5643. })
  5644. return
  5645. }
  5646. }
  5647. }
  5648. for _, item := range list {
  5649. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5650. dadvice := &models.DoctorAdvice{
  5651. ID: item.ID,
  5652. UserOrgId: item.UserOrgId,
  5653. PatientId: item.PatientId,
  5654. AdviceType: item.AdviceType,
  5655. AdviceDate: item.AdviceDate,
  5656. StartTime: item.StartTime,
  5657. AdviceName: item.AdviceName,
  5658. AdviceDesc: item.AdviceDesc,
  5659. ReminderDate: item.ReminderDate,
  5660. SingleDose: item.SingleDose,
  5661. SingleDoseUnit: item.SingleDoseUnit,
  5662. DrugSpec: item.DrugSpec,
  5663. DrugSpecUnit: item.DrugSpecUnit,
  5664. PrescribingNumber: item.PrescribingNumber,
  5665. PrescribingNumberUnit: item.PrescribingNumberUnit,
  5666. DeliveryWay: item.DeliveryWay,
  5667. ExecutionFrequency: item.ExecutionFrequency,
  5668. AdviceDoctor: item.AdviceDoctor,
  5669. Status: 1,
  5670. CreatedTime: item.CreatedTime,
  5671. UpdatedTime: item.UpdatedTime,
  5672. AdviceAffirm: item.AdviceAffirm,
  5673. Remark: item.Remark,
  5674. StopTime: item.StopTime,
  5675. StopReason: item.StopReason,
  5676. StopDoctor: item.StopDoctor,
  5677. StopState: item.StopState,
  5678. ParentId: item.ParentId,
  5679. ExecutionTime: item.ExecutionTime,
  5680. ExecutionStaff: item.ExecutionStaff,
  5681. ExecutionState: item.ExecutionState,
  5682. Checker: item.Checker,
  5683. RecordDate: item.ReminderDate,
  5684. DialysisOrderId: item.DialysisOrderId,
  5685. CheckTime: item.CheckTime,
  5686. CheckState: item.CheckState,
  5687. RemindType: item.RemindType,
  5688. FrequencyType: item.FrequencyType,
  5689. DayCount: item.DayCount,
  5690. WeekDay: item.WeekDay,
  5691. TemplateId: item.TemplateId,
  5692. Modifier: item.Modifier,
  5693. Way: item.Way,
  5694. DrugId: item.DrugId,
  5695. }
  5696. if medical.IsUse == 2 {
  5697. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5698. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5699. }
  5700. if pharmacyConfig.IsOpen != 1 {
  5701. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  5702. }
  5703. //更新字典里面的库存
  5704. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5705. var sum_count int64
  5706. for _, its := range stockInfo {
  5707. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5708. if its.MaxUnit == baseDrug.MaxUnit {
  5709. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5710. }
  5711. sum_count += its.StockMaxNumber + its.StockMinNumber
  5712. }
  5713. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5714. //剩余库存
  5715. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5716. }
  5717. info := models.DoctorAdvice{
  5718. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5719. ExecutionTime: exec_time,
  5720. ExecutionState: 1,
  5721. UpdatedTime: time.Now().Unix(),
  5722. }
  5723. //执行医嘱
  5724. service.UpdateDoctorAdviceExecution(info, item.ID)
  5725. }
  5726. }
  5727. this.ServeSuccessJSON(map[string]interface{}{
  5728. "msg": "1",
  5729. })
  5730. return
  5731. }
  5732. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  5733. orgId := this.GetAdminUserInfo().CurrentOrgId
  5734. idsStr := this.GetString("str")
  5735. recordIDStrs := strings.Split(idsStr, ",")
  5736. start_time := this.GetString("advice_date")
  5737. timeLayout := "2006-01-02"
  5738. loc, _ := time.LoadLocation("Local")
  5739. var startTime int64
  5740. if len(start_time) > 0 {
  5741. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5742. if err != nil {
  5743. //fmt.Println(err)
  5744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5745. return
  5746. }
  5747. startTime = theTime.Unix()
  5748. }
  5749. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5750. if config.IsOpen == 1 {
  5751. creater := this.GetAdminUserInfo().AdminUser.Id
  5752. //查询未核对的医嘱
  5753. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5754. for _, item := range advicelist {
  5755. if item.ExecutionStaff == creater {
  5756. this.ServeSuccessJSON(map[string]interface{}{
  5757. "msg": "2",
  5758. "advice": item,
  5759. })
  5760. return
  5761. }
  5762. service.CheckHisDoctorAdvice(item.ID, creater)
  5763. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5764. redis := service.RedisClient()
  5765. //清空key 值
  5766. redis.Set(key, "", time.Second)
  5767. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5768. redis.Set(keyTwo, "", time.Second)
  5769. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5770. redis.Set(keyThree, "", time.Second)
  5771. theTime := time.Now()
  5772. recordDate := theTime.Format("2006-01-02")
  5773. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5774. redis.Set(keyFour, "", time.Second)
  5775. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5776. redis.Set(keyFive, "", time.Second)
  5777. }
  5778. } else {
  5779. //查询未核对的医嘱
  5780. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5781. creater := this.GetAdminUserInfo().AdminUser.Id
  5782. for _, item := range advicelist {
  5783. if item.ExecutionStaff == creater {
  5784. this.ServeSuccessJSON(map[string]interface{}{
  5785. "msg": "2",
  5786. "advice": item,
  5787. })
  5788. return
  5789. }
  5790. service.CheckDoctorAdvice(item.ID, creater)
  5791. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5792. redis := service.RedisClient()
  5793. //清空key 值
  5794. redis.Set(key, "", time.Second)
  5795. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5796. redis.Set(keyTwo, "", time.Second)
  5797. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5798. redis.Set(keyThree, "", time.Second)
  5799. theTime := time.Now()
  5800. recordDate := theTime.Format("2006-01-02")
  5801. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5802. redis.Set(keyFour, "", time.Second)
  5803. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5804. redis.Set(keyFive, "", time.Second)
  5805. }
  5806. }
  5807. this.ServeSuccessJSON(map[string]interface{}{
  5808. "msg": "1",
  5809. })
  5810. return
  5811. }
  5812. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5813. orgId := this.GetAdminUserInfo().CurrentOrgId
  5814. is_open, _ := this.GetInt64("is_open")
  5815. idsStr := this.GetString("str")
  5816. recordIDStrs := strings.Split(idsStr, ",")
  5817. start_time := this.GetString("advice_date")
  5818. timeLayout := "2006-01-02"
  5819. loc, _ := time.LoadLocation("Local")
  5820. var startTime int64
  5821. if len(start_time) > 0 {
  5822. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5823. if err != nil {
  5824. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5825. return
  5826. }
  5827. startTime = theTime.Unix()
  5828. }
  5829. if is_open == 1 {
  5830. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5831. } else {
  5832. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5833. }
  5834. this.ServeSuccessJSON(map[string]interface{}{
  5835. "msg": "1",
  5836. })
  5837. return
  5838. }
  5839. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5840. advice_id, _ := this.GetInt64("advice_id")
  5841. start_time := this.GetString("advice_date")
  5842. orgId := this.GetAdminUserInfo().CurrentOrgId
  5843. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5844. exec_time, _ := this.GetInt64("exec_time")
  5845. //his医嘱
  5846. if config.IsOpen == 1 {
  5847. //查询医嘱
  5848. advice, _ := service.GetHisDocById(advice_id, orgId)
  5849. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5850. this.ServeSuccessJSON(map[string]interface{}{
  5851. "msg": "3",
  5852. })
  5853. return
  5854. }
  5855. medical, _ := service.GetBaseDrugMedical(orgId)
  5856. var prescribing_number int64
  5857. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5858. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5859. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5860. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5861. }
  5862. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5863. prescribing_number = parseIntPrescribingNumber
  5864. }
  5865. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5866. prescribing_number = parseIntPrescribingNumber
  5867. }
  5868. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5869. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5870. //库存不足
  5871. if prescribing_number > drugStockOut.FlushCount {
  5872. this.ServeSuccessJSON(map[string]interface{}{
  5873. "msg": "2",
  5874. "drug": medical,
  5875. })
  5876. return
  5877. }
  5878. info := models.HisDoctorAdviceInfo{
  5879. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5880. ExecutionTime: exec_time,
  5881. ExecutionState: 1,
  5882. UpdatedTime: time.Now().Unix(),
  5883. }
  5884. //执行医嘱
  5885. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5886. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5887. redis := service.RedisClient()
  5888. //清空key 值
  5889. redis.Set(key, "", time.Second)
  5890. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5891. redis.Set(keyTwo, "", time.Second)
  5892. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5893. redis.Set(keyThree, "", time.Second)
  5894. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5895. theTime := toTime.Format("2006-01-02")
  5896. fmt.Println("theTIME", theTime)
  5897. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5898. redis.Set(keyFour, "", time.Second)
  5899. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5900. redis.Set(keyFive, "", time.Second)
  5901. //出库
  5902. if prescribing_number <= drugStockOut.FlushCount {
  5903. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5904. //执行出库逻辑
  5905. hisadvice := &models.HisDoctorAdviceInfo{
  5906. ID: advice.ID,
  5907. UserOrgId: advice.UserOrgId,
  5908. PatientId: advice.PatientId,
  5909. AdviceType: advice.AdviceType,
  5910. AdviceDate: advice.AdviceDate,
  5911. StartTime: advice.StartTime,
  5912. AdviceName: advice.AdviceName,
  5913. AdviceDesc: advice.AdviceDesc,
  5914. ReminderDate: advice.ReminderDate,
  5915. SingleDose: advice.SingleDose,
  5916. SingleDoseUnit: advice.SingleDoseUnit,
  5917. DrugSpec: advice.DrugSpec,
  5918. DrugSpecUnit: advice.DrugSpecUnit,
  5919. PrescribingNumber: advice.PrescribingNumber,
  5920. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5921. DeliveryWay: advice.DeliveryWay,
  5922. ExecutionFrequency: advice.ExecutionFrequency,
  5923. AdviceDoctor: advice.AdviceDoctor,
  5924. Status: 1,
  5925. CreatedTime: advice.CreatedTime,
  5926. UpdatedTime: advice.UpdatedTime,
  5927. AdviceAffirm: advice.AdviceAffirm,
  5928. Remark: advice.Remark,
  5929. StopTime: advice.StopTime,
  5930. StopReason: advice.StopReason,
  5931. StopDoctor: advice.StopDoctor,
  5932. StopState: advice.StopState,
  5933. ParentId: advice.ParentId,
  5934. ExecutionTime: advice.ExecutionTime,
  5935. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5936. ExecutionState: advice.ExecutionState,
  5937. Checker: advice.Checker,
  5938. RecordDate: advice.RecordDate,
  5939. DialysisOrderId: advice.DialysisOrderId,
  5940. CheckTime: advice.CheckTime,
  5941. CheckState: advice.CheckState,
  5942. RemindType: advice.RemindType,
  5943. FrequencyType: advice.FrequencyType,
  5944. DayCount: advice.DayCount,
  5945. WeekDay: advice.WeekDay,
  5946. TemplateId: advice.TemplateId,
  5947. Modifier: advice.Modifier,
  5948. Way: advice.Way,
  5949. DrugId: advice.DrugId,
  5950. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5951. }
  5952. if medical.IsUse == 2 {
  5953. if config.IsOpen != 1 {
  5954. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5955. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5956. }
  5957. //不通过药房发药
  5958. if pharmacyConfig.IsOpen != 1 {
  5959. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5960. }
  5961. //查询默认仓库
  5962. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5963. //查询默认仓库剩余多少库存
  5964. var sum_count int64
  5965. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5966. for _, its := range stockInfo {
  5967. if its.MaxUnit == medical.MaxUnit {
  5968. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5969. }
  5970. sum_count += its.StockMaxNumber + its.StockMinNumber
  5971. }
  5972. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5973. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5974. }
  5975. }
  5976. }
  5977. this.ServeSuccessJSON(map[string]interface{}{
  5978. "msg": "1",
  5979. })
  5980. return
  5981. }
  5982. if config.IsOpen == 2 || config.IsOpen == 0 {
  5983. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5984. medical, _ := service.GetBaseDrugMedical(orgId)
  5985. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5986. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5987. var prescribing_number int64
  5988. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5989. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5990. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5991. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5992. }
  5993. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5994. prescribing_number = parseIntPrescribingNumber
  5995. }
  5996. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5997. prescribing_number = parseIntPrescribingNumber
  5998. }
  5999. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6000. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  6001. //库存不足
  6002. if prescribing_number > drugStockOut.FlushCount {
  6003. this.ServeSuccessJSON(map[string]interface{}{
  6004. "msg": "2",
  6005. "drug": medical,
  6006. })
  6007. return
  6008. }
  6009. info := models.DoctorAdvice{
  6010. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  6011. ExecutionTime: exec_time,
  6012. ExecutionState: 1,
  6013. UpdatedTime: time.Now().Unix(),
  6014. }
  6015. //执行医嘱
  6016. service.UpdateDoctorAdviceExecution(info, advice.ID)
  6017. dadvice := &models.DoctorAdvice{
  6018. ID: advice.ID,
  6019. UserOrgId: advice.UserOrgId,
  6020. PatientId: advice.PatientId,
  6021. AdviceType: advice.AdviceType,
  6022. AdviceDate: advice.AdviceDate,
  6023. StartTime: advice.StartTime,
  6024. AdviceName: advice.AdviceName,
  6025. AdviceDesc: advice.AdviceDesc,
  6026. ReminderDate: advice.ReminderDate,
  6027. SingleDose: advice.SingleDose,
  6028. SingleDoseUnit: advice.SingleDoseUnit,
  6029. DrugSpec: advice.DrugSpec,
  6030. DrugSpecUnit: advice.DrugSpecUnit,
  6031. PrescribingNumber: advice.PrescribingNumber,
  6032. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  6033. DeliveryWay: advice.DeliveryWay,
  6034. ExecutionFrequency: advice.ExecutionFrequency,
  6035. AdviceDoctor: advice.AdviceDoctor,
  6036. Status: 1,
  6037. CreatedTime: advice.CreatedTime,
  6038. UpdatedTime: advice.UpdatedTime,
  6039. AdviceAffirm: advice.AdviceAffirm,
  6040. Remark: advice.Remark,
  6041. StopTime: advice.StopTime,
  6042. StopReason: advice.StopReason,
  6043. StopDoctor: advice.StopDoctor,
  6044. StopState: advice.StopState,
  6045. ParentId: advice.ParentId,
  6046. ExecutionTime: advice.ExecutionTime,
  6047. ExecutionStaff: advice.ExecutionStaff,
  6048. ExecutionState: advice.ExecutionState,
  6049. Checker: advice.Checker,
  6050. RecordDate: advice.ReminderDate,
  6051. DialysisOrderId: advice.DialysisOrderId,
  6052. CheckTime: advice.CheckTime,
  6053. CheckState: advice.CheckState,
  6054. RemindType: advice.RemindType,
  6055. FrequencyType: advice.FrequencyType,
  6056. DayCount: advice.DayCount,
  6057. WeekDay: advice.WeekDay,
  6058. TemplateId: advice.TemplateId,
  6059. Modifier: advice.Modifier,
  6060. Way: advice.Way,
  6061. DrugId: advice.DrugId,
  6062. }
  6063. if medical.IsUse == 2 {
  6064. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  6065. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6066. }
  6067. if pharmacyConfig.IsOpen != 1 {
  6068. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  6069. }
  6070. //更新字典里面的库存
  6071. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  6072. var sum_count int64
  6073. for _, its := range stockInfo {
  6074. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  6075. if its.MaxUnit == baseDrug.MaxUnit {
  6076. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  6077. }
  6078. sum_count += its.StockMaxNumber + its.StockMinNumber
  6079. }
  6080. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  6081. //剩余库存
  6082. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6083. }
  6084. }
  6085. this.ServeSuccessJSON(map[string]interface{}{
  6086. "msg": "1",
  6087. })
  6088. return
  6089. }
  6090. func (this *DialysisApiController) GetDialysisAdviceToday() {
  6091. orgId := this.GetAdminUserInfo().CurrentOrgId
  6092. schedule_type, _ := this.GetInt64("schedule_type")
  6093. //partion_type, _ := this.GetInt64("partion_type")
  6094. partion_type := this.GetString("partion_type")
  6095. var ids []string
  6096. ids = strings.Split(partion_type, ",")
  6097. start_time := this.GetString("selected_date")
  6098. timeLayout := "2006-01-02"
  6099. loc, _ := time.LoadLocation("Local")
  6100. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6101. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  6102. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6103. _, config := service.FindXTHisRecordByOrgId(orgId)
  6104. appId := this.GetAdminUserInfo().CurrentAppId
  6105. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6106. if err == nil {
  6107. this.ServeSuccessJSON(map[string]interface{}{
  6108. "list": list,
  6109. "drug": drug,
  6110. "config": config,
  6111. "doctorList": doctorList,
  6112. })
  6113. return
  6114. } else {
  6115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6116. return
  6117. }
  6118. }
  6119. func (this *DialysisApiController) GetMobileScheduleList() {
  6120. orgId := this.GetAdminUserInfo().CurrentOrgId
  6121. schedule, _ := service.GetMobileScheduleList(orgId)
  6122. if len(schedule) > 0 {
  6123. for _, its := range schedule {
  6124. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6125. //its.DialysisPrescription = prescription
  6126. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6127. //its.MonitoringRecord = monitor
  6128. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  6129. //its.XtAssessmentAfterDislysis = after
  6130. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  6131. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  6132. }
  6133. }
  6134. this.ServeSuccessJSON(map[string]interface{}{
  6135. "schedule": schedule,
  6136. })
  6137. return
  6138. }
  6139. func (this *DialysisApiController) SaveDialysisInformationSetting() {
  6140. week_day, _ := this.GetInt64("week_day")
  6141. orgId := this.GetAdminUserInfo().CurrentOrgId
  6142. informaitonSetting := models.XtDialysisInformaitonSetting{
  6143. WeekDay: week_day,
  6144. UserOrgId: orgId,
  6145. Status: 1,
  6146. Ctime: time.Now().Unix(),
  6147. Mtime: 0,
  6148. }
  6149. information, _ := service.GetInformationSettingByOrgId(orgId)
  6150. if information.ID == 0 {
  6151. service.CreateInformationSetting(informaitonSetting)
  6152. }
  6153. if information.ID > 0 {
  6154. service.UpdateInformationSettingById(orgId, week_day)
  6155. }
  6156. this.ServeSuccessJSON(map[string]interface{}{
  6157. "informaitonSetting": informaitonSetting,
  6158. })
  6159. return
  6160. }
  6161. func (this *DialysisApiController) GetDialysisInformationSetting() {
  6162. orgId := this.GetAdminUserInfo().CurrentOrgId
  6163. limit, _ := this.GetInt64("limit")
  6164. page, _ := this.GetInt64("page")
  6165. informationSetting, _ := service.GetDialysisInformationSettingList(orgId)
  6166. //未审核
  6167. infor, total, _ := service.GetDialysisInformationIsNoCheck(orgId, limit, page, 2)
  6168. //全部
  6169. inforList, totalOne, _ := service.GetDialysisInformationIsNoCheckOne(orgId, limit, page, 1)
  6170. patients, _ := service.GetAllpatientThirty(orgId)
  6171. appId := this.GetAdminUserInfo().CurrentAppId
  6172. role, _ := service.GetAllDoctorListSix(orgId, appId)
  6173. this.ServeSuccessJSON(map[string]interface{}{
  6174. "informaitonSetting": informationSetting,
  6175. "infor": infor,
  6176. "total": total,
  6177. "totalOne": totalOne,
  6178. "inforList": inforList,
  6179. "patients": patients,
  6180. "adminList": role,
  6181. })
  6182. return
  6183. }
  6184. func (this *DialysisApiController) CheckDialysisInformation() {
  6185. id, _ := this.GetInt64("id")
  6186. application_status, _ := this.GetInt64("application_status")
  6187. timeNow := time.Now().Unix()
  6188. checker := this.GetAdminUserInfo().AdminUser.Id
  6189. information, _ := service.CheckDialysisInformation(id, application_status, timeNow, checker)
  6190. this.ServeSuccessJSON(map[string]interface{}{
  6191. "information": information,
  6192. })
  6193. return
  6194. }
  6195. func (this *DialysisApiController) GetDialysisPatientsFlow() {
  6196. page, _ := this.GetInt64("page", 1)
  6197. limit, _ := this.GetInt64("limit", 10)
  6198. schedulType, _ := this.GetInt64("schedul_type", 0)
  6199. startTime, _ := this.GetInt64("schedul_time", 0)
  6200. partitionType, _ := this.GetInt64("partition_type", 0)
  6201. keywords := this.GetString("keywords")
  6202. start_time, _ := this.GetInt64("start_time")
  6203. end_time, _ := this.GetInt64("end_time")
  6204. adminUserInfo := this.GetAdminUserInfo()
  6205. if len(keywords) > 0 {
  6206. dialysisSchedule, err, total := service.GetDialysisWatchByKeywordFlow(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6207. if err == nil {
  6208. this.ServeSuccessJSON(map[string]interface{}{
  6209. "schedule": dialysisSchedule,
  6210. "total": total,
  6211. })
  6212. } else {
  6213. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6214. }
  6215. } else {
  6216. dialysisSchedule, err, total := service.GetDialysisWatchFlow(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  6217. fmt.Println("dialysisSchedule-----------------------", dialysisSchedule)
  6218. if err == nil {
  6219. this.ServeSuccessJSON(map[string]interface{}{
  6220. "schedule": dialysisSchedule,
  6221. "total": total,
  6222. })
  6223. } else {
  6224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6225. }
  6226. }
  6227. }
  6228. func (this *DialysisApiController) SaveInformation() {
  6229. patient_id, _ := this.GetInt64("patient_id")
  6230. record_date, _ := this.GetInt64("record_date")
  6231. startTime := this.GetString("selected_date")
  6232. timeLayout := "2006-01-02 15:04"
  6233. loc, _ := time.LoadLocation("Local")
  6234. if len(startTime) == 0 {
  6235. utils.ErrorLog("len(start_time) == 0")
  6236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6237. return
  6238. }
  6239. theTime, err := time.ParseInLocation(timeLayout, startTime, loc)
  6240. if err != nil {
  6241. utils.ErrorLog(err.Error())
  6242. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6243. return
  6244. }
  6245. StartTime := theTime.Unix()
  6246. fmt.Println("startime-------------", StartTime)
  6247. module, _ := this.GetInt64("module")
  6248. remark := this.GetString("remark")
  6249. orgId := this.GetAdminUserInfo().CurrentOrgId
  6250. creater := this.GetAdminUserInfo().AdminUser.Id
  6251. information := models.XtDialysisInformation{
  6252. Module: module,
  6253. PatientId: patient_id,
  6254. RecordDate: record_date,
  6255. ApplicationDate: StartTime,
  6256. Creater: creater,
  6257. ApplicationStatus: 2,
  6258. Checker: 0,
  6259. CheckTime: 0,
  6260. Remark: remark,
  6261. UserOrgId: orgId,
  6262. Ctime: time.Now().Unix(),
  6263. Status: 1,
  6264. Mtime: 0,
  6265. }
  6266. infor, _ := service.GetDialysisInoformationById(patient_id, record_date, orgId, module)
  6267. if infor.ID == 0 {
  6268. err := service.CreatedDialysisInformation(information)
  6269. if err == nil {
  6270. this.ServeSuccessJSON(map[string]interface{}{
  6271. "information": information,
  6272. })
  6273. return
  6274. }
  6275. }
  6276. if infor.ID > 0 {
  6277. err := service.UpdateDialysisInformationById(patient_id, record_date, orgId, module, StartTime, remark)
  6278. if err == nil {
  6279. this.ServeSuccessJSON(map[string]interface{}{
  6280. "information": information,
  6281. })
  6282. return
  6283. }
  6284. }
  6285. }
  6286. func (this *DialysisApiController) GetLongDialysisAdviceToday() {
  6287. orgId := this.GetAdminUserInfo().CurrentOrgId
  6288. schedule_type, _ := this.GetInt64("schedule_type")
  6289. partion_type := this.GetString("partion_type")
  6290. var ids []string
  6291. ids = strings.Split(partion_type, ",")
  6292. start_time := this.GetString("selected_date")
  6293. timeLayout := "2006-01-02"
  6294. loc, _ := time.LoadLocation("Local")
  6295. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6296. list, err := service.GetLongDialysisAdviceToday(orgId, schedule_type, ids, startTime.Unix())
  6297. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  6298. _, config := service.FindXTHisRecordByOrgId(orgId)
  6299. appId := this.GetAdminUserInfo().CurrentAppId
  6300. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  6301. if err == nil {
  6302. this.ServeSuccessJSON(map[string]interface{}{
  6303. "list": list,
  6304. "drug": drug,
  6305. "config": config,
  6306. "doctorList": doctorList,
  6307. })
  6308. return
  6309. } else {
  6310. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6311. return
  6312. }
  6313. }
  6314. func (this *DialysisApiController) GetPatientList() {
  6315. orgId := this.GetAdminUserInfo().CurrentOrgId
  6316. keyWord := this.GetString("keyword")
  6317. patientList, err := service.GetPrescriptionPatientList(orgId, keyWord)
  6318. if err == nil {
  6319. this.ServeSuccessJSON(map[string]interface{}{
  6320. "patientList": patientList,
  6321. })
  6322. return
  6323. } else {
  6324. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6325. return
  6326. }
  6327. }
  6328. func (this *DialysisApiController) GetPrescriptionLogList() {
  6329. patient_id, _ := this.GetInt64("patient_id")
  6330. record_date := this.GetString("record_date")
  6331. page, _ := this.GetInt64("page")
  6332. limit, _ := this.GetInt64("limit")
  6333. orgId := this.GetAdminUserInfo().CurrentOrgId
  6334. timeLayout := "2006-01-02"
  6335. loc, _ := time.LoadLocation("Local")
  6336. var recordDateTime int64
  6337. if len(record_date) > 0 {
  6338. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6339. if err != nil {
  6340. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6341. return
  6342. }
  6343. recordDateTime = theTime.Unix()
  6344. }
  6345. prescriptionlogList, total, err := service.GetPrescriptionLogList(patient_id, page, limit, recordDateTime, orgId)
  6346. patients, _ := service.GetAllPatientLog(orgId)
  6347. role, _ := service.GetAllDoctorLog(orgId)
  6348. if err == nil {
  6349. this.ServeSuccessJSON(map[string]interface{}{
  6350. "prescriptionlogList": prescriptionlogList,
  6351. "total": total,
  6352. "patients": patients,
  6353. "role": role,
  6354. })
  6355. return
  6356. } else {
  6357. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6358. return
  6359. }
  6360. }
  6361. func (this *DialysisApiController) GetBeforLogList() {
  6362. patient_id, _ := this.GetInt64("patient_id")
  6363. record_date := this.GetString("record_date")
  6364. page, _ := this.GetInt64("page")
  6365. limit, _ := this.GetInt64("limit")
  6366. orgId := this.GetAdminUserInfo().CurrentOrgId
  6367. timeLayout := "2006-01-02"
  6368. loc, _ := time.LoadLocation("Local")
  6369. var recordDateTime int64
  6370. if len(record_date) > 0 {
  6371. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6372. if err != nil {
  6373. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6374. return
  6375. }
  6376. recordDateTime = theTime.Unix()
  6377. }
  6378. beforLogList, total, err := service.GetBeforLogList(patient_id, page, limit, recordDateTime, orgId)
  6379. patients, _ := service.GetAllPatientLog(orgId)
  6380. role, _ := service.GetAllDoctorLog(orgId)
  6381. if err == nil {
  6382. this.ServeSuccessJSON(map[string]interface{}{
  6383. "beforLogList": beforLogList,
  6384. "total": total,
  6385. "patients": patients,
  6386. "role": role,
  6387. })
  6388. return
  6389. } else {
  6390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6391. return
  6392. }
  6393. }
  6394. func (this *DialysisApiController) GetDocLogList() {
  6395. patient_id, _ := this.GetInt64("patient_id")
  6396. record_date := this.GetString("record_date")
  6397. page, _ := this.GetInt64("page")
  6398. limit, _ := this.GetInt64("limit")
  6399. orgId := this.GetAdminUserInfo().CurrentOrgId
  6400. timeLayout := "2006-01-02"
  6401. loc, _ := time.LoadLocation("Local")
  6402. var recordDateTime int64
  6403. if len(record_date) > 0 {
  6404. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6405. if err != nil {
  6406. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6407. return
  6408. }
  6409. recordDateTime = theTime.Unix()
  6410. }
  6411. adviceLogList, total, err := service.GetDocLogList(patient_id, page, limit, recordDateTime, orgId)
  6412. patients, _ := service.GetAllPatientLog(orgId)
  6413. role, _ := service.GetAllDoctorLog(orgId)
  6414. if err == nil {
  6415. this.ServeSuccessJSON(map[string]interface{}{
  6416. "adviceLogList": adviceLogList,
  6417. "total": total,
  6418. "patients": patients,
  6419. "role": role,
  6420. })
  6421. return
  6422. } else {
  6423. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6424. return
  6425. }
  6426. }
  6427. func (this *DialysisApiController) GetMonitorLogList() {
  6428. patient_id, _ := this.GetInt64("patient_id")
  6429. record_date := this.GetString("record_date")
  6430. page, _ := this.GetInt64("page")
  6431. limit, _ := this.GetInt64("limit")
  6432. orgId := this.GetAdminUserInfo().CurrentOrgId
  6433. timeLayout := "2006-01-02"
  6434. loc, _ := time.LoadLocation("Local")
  6435. var recordDateTime int64
  6436. if len(record_date) > 0 {
  6437. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6438. if err != nil {
  6439. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6440. return
  6441. }
  6442. recordDateTime = theTime.Unix()
  6443. }
  6444. monitorLogList, total, err := service.GetMonitorLogList(patient_id, page, limit, recordDateTime, orgId)
  6445. patients, _ := service.GetAllPatientLog(orgId)
  6446. role, _ := service.GetAllDoctorLog(orgId)
  6447. if err == nil {
  6448. this.ServeSuccessJSON(map[string]interface{}{
  6449. "monitorLogList": monitorLogList,
  6450. "total": total,
  6451. "patients": patients,
  6452. "role": role,
  6453. })
  6454. return
  6455. } else {
  6456. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6457. return
  6458. }
  6459. }
  6460. func (this *DialysisApiController) GetAfterLogList() {
  6461. patient_id, _ := this.GetInt64("patient_id")
  6462. record_date := this.GetString("record_date")
  6463. page, _ := this.GetInt64("page")
  6464. limit, _ := this.GetInt64("limit")
  6465. orgId := this.GetAdminUserInfo().CurrentOrgId
  6466. timeLayout := "2006-01-02"
  6467. loc, _ := time.LoadLocation("Local")
  6468. var recordDateTime int64
  6469. if len(record_date) > 0 {
  6470. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6471. if err != nil {
  6472. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6473. return
  6474. }
  6475. recordDateTime = theTime.Unix()
  6476. }
  6477. afterLogList, total, err := service.GetAfterLogList(patient_id, page, limit, recordDateTime, orgId)
  6478. patients, _ := service.GetAllPatientLog(orgId)
  6479. role, _ := service.GetAllDoctorLog(orgId)
  6480. if err == nil {
  6481. this.ServeSuccessJSON(map[string]interface{}{
  6482. "afterLogList": afterLogList,
  6483. "total": total,
  6484. "patients": patients,
  6485. "role": role,
  6486. })
  6487. return
  6488. } else {
  6489. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6490. return
  6491. }
  6492. }