dialysis_api_controller.go 232KB

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