dialysis_api_controller.go 279KB

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