dialysis_api_controller.go 280KB

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