dialysis_api_controller.go 282KB

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