dialysis_api_controller.go 266KB

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