dialysis_api_controller.go 287KB

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