dialysis_api_controller.go 259KB

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