dialysis_api_controller.go 282KB

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