dialysis_api_controller.go 233KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099
  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. dialyzer_batch_number := c.GetString("dialyzer_batch_number")
  1207. needle_batch_number := c.GetString("needle_batch_number")
  1208. if id <= 0 {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1210. return
  1211. }
  1212. adminUserInfo := c.GetAdminUserInfo()
  1213. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1214. if patient.ID == 0 {
  1215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1216. return
  1217. }
  1218. if len(recordDateStr) == 0 {
  1219. recordDateStr = time.Now().Format("2006-01-02")
  1220. }
  1221. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1222. if parseDateErr != nil {
  1223. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1225. return
  1226. }
  1227. var checkDate int64
  1228. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 9675 || adminUserInfo.CurrentOrgId == 10340 {
  1229. list, _ := service.GetRoleList(adminUserInfo.CurrentOrgId, modifier)
  1230. if employee_number != list.JobNumber {
  1231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorEmployeeNumber)
  1232. return
  1233. }
  1234. }
  1235. if len(checkTimeStr) == 0 {
  1236. //checkTimeStr = time.Now().Format("2006-01-02 15:04")
  1237. checkDate = 0
  1238. } else {
  1239. checkDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", checkTimeStr)
  1240. checkDate = checkDateUnix.Unix()
  1241. }
  1242. var firstCheckTimeDate int64
  1243. if len(firstCheckTimeStr) == 0 {
  1244. //firstCheckTimeStr = time.Now().Format("2006-01-02 15:04")
  1245. firstCheckTimeDate = 0
  1246. } else {
  1247. firstCheckTimeDateUnix, _ := utils.ParseTimeStringToTime("2006-01-02 15:04", firstCheckTimeStr)
  1248. firstCheckTimeDate = firstCheckTimeDateUnix.Unix()
  1249. }
  1250. doubleCheck := models.DoubleCheck{
  1251. UserOrgId: adminUserInfo.CurrentOrgId,
  1252. PatientId: id,
  1253. DialysisItemCheck: dialysis_item_check,
  1254. DialysisParameterCheck: dialysis_parameter_check,
  1255. VascularAccessVerification: vascular_access_verification,
  1256. PipelineConnectionCheck: pipeline_connection_check,
  1257. DialysisItemDesc: dialysis_item_desc,
  1258. DialysisParameterDesc: dialysis_parameter_desc,
  1259. VascularAccessDesc: vascular_access_desc,
  1260. PipelineConnectionDesc: pipeline_connection_desc,
  1261. Collator: collator,
  1262. Status: 1,
  1263. CreatedTime: time.Now().Unix(),
  1264. UpdatedTime: time.Now().Unix(),
  1265. CheckDate: recordDate.Unix(),
  1266. EmployeeNumber: employee_number,
  1267. DialyzerBatchNumber: dialyzer_batch_number,
  1268. NeedleBatchNumber: needle_batch_number,
  1269. }
  1270. _, check := service.FindDoubleCheckByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1271. if check.ID == 0 { //新增
  1272. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1273. doubleCheck.CheckTime = checkDate
  1274. doubleCheck.Creater = creater
  1275. doubleCheck.Modifier = modifier
  1276. err := service.AddSigleDoubleCheck(&doubleCheck)
  1277. redis := service.RedisClient()
  1278. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1279. //清空key 值
  1280. redis.Set(key, "", time.Second)
  1281. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1282. redis.Set(keyTwo, "", time.Second)
  1283. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1284. redis.Set(keyThree, "", time.Second)
  1285. defer redis.Close()
  1286. if err == nil {
  1287. c.ServeSuccessJSON(map[string]interface{}{
  1288. "doubleCheck": doubleCheck,
  1289. })
  1290. } else {
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1292. }
  1293. } else { //修改
  1294. doubleCheck.FirstCheckTime = firstCheckTimeDate
  1295. doubleCheck.CheckTime = checkDate
  1296. doubleCheck.Creater = creater
  1297. doubleCheck.Modifier = modifier
  1298. doubleCheck.CreatedTime = check.CreatedTime
  1299. doubleCheck.UpdatedTime = time.Now().Unix()
  1300. doubleCheck.ID = check.ID
  1301. redis := service.RedisClient()
  1302. err := service.UpdateDoubleCheck(&doubleCheck)
  1303. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":double_check"
  1304. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1305. redis.Set(keyTwo, "", time.Second)
  1306. //清空key 值
  1307. redis.Set(key, "", time.Second)
  1308. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + ":prescriptions_list_all"
  1309. redis.Set(keyThree, "", time.Second)
  1310. defer redis.Close()
  1311. if err == nil {
  1312. c.ServeSuccessJSON(map[string]interface{}{
  1313. "doubleCheck": doubleCheck,
  1314. })
  1315. } else {
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1317. }
  1318. }
  1319. }
  1320. func (c *DialysisApiController) PostReceiveTreatmentAsses() {
  1321. id, _ := c.GetInt64("patient", 0)
  1322. recordDateStr := c.GetString("record_date")
  1323. way, _ := c.GetInt64("way", 0)
  1324. consciousness, _ := c.GetInt64("consciousness", 0)
  1325. appetite, _ := c.GetInt64("appetite", 0)
  1326. condition, _ := c.GetInt64("condition", 0)
  1327. posture, _ := c.GetInt64("posture")
  1328. score := c.GetString("score")
  1329. sick_condition, _ := c.GetInt64("sick_condition", 0)
  1330. danger_level, _ := c.GetInt64("danger_level", 0)
  1331. intake, _ := c.GetInt64("intake", 0)
  1332. nutrition, _ := c.GetInt64("nutrition", 0)
  1333. psychological_assessment, _ := c.GetInt64("psychological_assessment", 0)
  1334. psychological_assessment_other := c.GetString("psychological_assessment_other")
  1335. sick_condition_other := c.GetString("sick_condition_other")
  1336. //precaution, _ := c.GetInt64("precaution", 0)
  1337. precaution := c.GetString("precaution")
  1338. precaution_other := c.GetString("precaution_other")
  1339. psychological_other := c.GetString("psychological_other")
  1340. admission_number := c.GetString("admission_number")
  1341. tumble, _ := c.GetInt64("tumble")
  1342. his_department := c.GetString("his_department")
  1343. his_bed := c.GetString("his_bed")
  1344. diacrisis := c.GetString("diacrisis")
  1345. if id <= 0 {
  1346. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1347. return
  1348. }
  1349. adminUserInfo := c.GetAdminUserInfo()
  1350. patient, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, id)
  1351. if patient.ID == 0 {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1353. return
  1354. }
  1355. if len(recordDateStr) == 0 {
  1356. recordDateStr = time.Now().Format("2006-01-02")
  1357. }
  1358. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1359. if parseDateErr != nil {
  1360. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1362. return
  1363. }
  1364. _, receiveTreatment := service.FindReceiveTreatmentAssesByReordDate(id, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1365. receiveTreatmentAsses := models.ReceiveTreatmentAsses{
  1366. UserOrgId: adminUserInfo.CurrentOrgId,
  1367. PatientId: id,
  1368. RecordDate: recordDate.Unix(),
  1369. Way: way,
  1370. Consciousness: consciousness,
  1371. Appetite: appetite,
  1372. Condition: condition,
  1373. SickCondition: sick_condition,
  1374. DangerLevel: danger_level,
  1375. Intake: intake,
  1376. Nutrition: nutrition,
  1377. PsychologicalAssessment: psychological_assessment,
  1378. PsychologicalAssessmentOther: psychological_assessment_other,
  1379. SickConditionOther: sick_condition_other,
  1380. Posture: posture,
  1381. CreatedTime: time.Now().Unix(),
  1382. UpdateTime: time.Now().Unix(),
  1383. Status: 1,
  1384. Score: score,
  1385. Precaution: precaution,
  1386. PrecautionOther: precaution_other,
  1387. PsychologicalOther: psychological_other,
  1388. AdmissionNumber: admission_number,
  1389. Tumble: tumble,
  1390. HisDepartment: his_department,
  1391. HisBed: his_bed,
  1392. Diacrisis: diacrisis,
  1393. }
  1394. if receiveTreatment.ID == 0 { //新增
  1395. receiveTreatmentAsses.Creater = adminUserInfo.AdminUser.Id
  1396. err := service.AddSigleReceiveTreatmentAssesRecord(&receiveTreatmentAsses)
  1397. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1398. redis := service.RedisClient()
  1399. //清空key 值
  1400. redis.Set(key, "", time.Second)
  1401. defer redis.Close()
  1402. if err == nil {
  1403. c.ServeSuccessJSON(map[string]interface{}{
  1404. "receiveTreatmentAsses": receiveTreatmentAsses,
  1405. })
  1406. } else {
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1408. }
  1409. } else { //修改
  1410. //if receiveTreatment.Creater != adminUserInfo.AdminUser.Id {
  1411. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1412. // if getPermissionErr != nil {
  1413. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1414. // return
  1415. // } else if headNursePermission == nil {
  1416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1417. // return
  1418. // }
  1419. //}
  1420. receiveTreatmentAsses.Creater = receiveTreatment.Creater
  1421. receiveTreatmentAsses.CreatedTime = receiveTreatment.CreatedTime
  1422. receiveTreatmentAsses.UpdateTime = time.Now().Unix()
  1423. receiveTreatmentAsses.Modifier = adminUserInfo.AdminUser.Id
  1424. receiveTreatmentAsses.ID = receiveTreatment.ID
  1425. err := service.UpadateReceiveTreatmentAsses(&receiveTreatmentAsses)
  1426. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":receive_treatment_asses"
  1427. redis := service.RedisClient()
  1428. defer redis.Close()
  1429. redis.Set(keyOne, "", time.Second*60*60*18)
  1430. if err == nil {
  1431. c.ServeSuccessJSON(map[string]interface{}{
  1432. "receiveTreatmentAsses": receiveTreatmentAsses,
  1433. })
  1434. } else {
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1436. }
  1437. }
  1438. }
  1439. func (c *DialysisApiController) PostAssessmentAfterDislysis() {
  1440. patient, _ := c.GetInt64("patient", 0)
  1441. recordDateStr := c.GetString("record_date")
  1442. fmt.Println(recordDateStr)
  1443. if patient <= 0 {
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1445. return
  1446. }
  1447. adminUserInfo := c.GetAdminUserInfo()
  1448. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1449. if patientInfo.ID == 0 {
  1450. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1451. return
  1452. }
  1453. if len(recordDateStr) == 0 {
  1454. recordDateStr = time.Now().Format("2006-01-02")
  1455. }
  1456. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1457. if parseDateErr != nil {
  1458. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1459. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1460. return
  1461. }
  1462. // data := make(map[string]interface{}, 0)
  1463. var data models.AssessmentAfterDislysis
  1464. var err error
  1465. err = json.Unmarshal(c.Ctx.Input.RequestBody, &data)
  1466. fmt.Println(err)
  1467. if err != nil {
  1468. c.ErrorLog("数据解析错误:%v", err)
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1470. return
  1471. }
  1472. assessment, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1473. assessment.DialysisOrderId = data.DialysisOrderId
  1474. assessment.Evaluator = adminUserInfo.AdminUser.Id
  1475. assessment.Status = 1
  1476. assessment.WeightAfter = data.WeightAfter
  1477. assessment.WeightLoss = data.WeightLoss
  1478. assessment.Temperature = data.Temperature
  1479. assessment.SystolicBloodPressure = data.SystolicBloodPressure
  1480. assessment.DiastolicBloodPressure = data.DiastolicBloodPressure
  1481. assessment.PulseFrequency = data.PulseFrequency
  1482. assessment.ActualUltrafiltration = data.ActualUltrafiltration
  1483. assessment.ActualDisplacement = data.ActualDisplacement
  1484. assessment.ActualTreatmentHour = data.ActualTreatmentHour
  1485. assessment.ActualTreatmentMinute = data.ActualTreatmentMinute
  1486. assessment.Cruor = data.Cruor
  1487. assessment.SymptomAfterDialysis = data.SymptomAfterDialysis
  1488. assessment.DialysisIntakes = data.DialysisIntakes
  1489. assessment.InternalFistula = data.InternalFistula
  1490. assessment.BloodAccessPartId = data.BloodAccessPartId
  1491. assessment.BloodAccessPartOperaId = data.BloodAccessPartOperaId
  1492. assessment.Catheter = data.Catheter
  1493. assessment.Complication = data.Complication
  1494. assessment.PuncturePointOozingBlood = data.PuncturePointOozingBlood
  1495. assessment.PuncturePointHaematoma = data.PuncturePointHaematoma
  1496. assessment.InternalFistulaTremorAc = data.InternalFistulaTremorAc
  1497. assessment.PatientGose = data.PatientGose
  1498. assessment.InpatientDepartment = data.InpatientDepartment
  1499. assessment.ObservationContent = data.ObservationContent
  1500. assessment.ObservationContentOther = data.ObservationContentOther
  1501. assessment.Remark = data.Remark
  1502. assessment.BreathingRate = data.BreathingRate
  1503. assessment.DialysisProcess = data.DialysisProcess
  1504. assessment.InAdvanceMinute = data.InAdvanceMinute
  1505. assessment.InAdvanceReasonOther = data.InAdvanceReasonOther
  1506. assessment.InAdvanceReason = data.InAdvanceReason
  1507. assessment.HemostasisOpera = data.HemostasisOpera
  1508. assessment.HemostasisMinute = data.HemostasisMinute
  1509. assessment.TremorNoise = data.TremorNoise
  1510. assessment.DisequilibriumSyndrome = data.DisequilibriumSyndrome
  1511. assessment.DisequilibriumSyndromeOption = data.DisequilibriumSyndromeOption
  1512. assessment.ArterialTube = data.ArterialTube
  1513. assessment.IntravenousTube = data.IntravenousTube
  1514. assessment.DialysisIntakesUnit = data.DialysisIntakesUnit
  1515. assessment.Dialyzer = data.Dialyzer
  1516. assessment.IsEat = data.IsEat
  1517. assessment.CvcA = data.CvcA
  1518. assessment.CvcV = data.CvcV
  1519. assessment.Channel = data.Channel
  1520. assessment.ReturnBlood = data.ReturnBlood
  1521. assessment.RehydrationVolume = data.RehydrationVolume
  1522. assessment.DialysisDuring = data.DialysisDuring
  1523. assessment.StrokeVolume = data.StrokeVolume
  1524. assessment.BloodFlow = data.BloodFlow
  1525. assessment.SealingFluidDispose = data.SealingFluidDispose
  1526. assessment.SealingFluidSpecial = data.SealingFluidSpecial
  1527. assessment.DosageOfAnticoagulants = data.DosageOfAnticoagulants
  1528. assessment.SupineSystolicBloodPressure = data.SupineSystolicBloodPressure
  1529. assessment.SettingPressure = data.SettingPressure
  1530. assessment.SupineDiastolicBloodPressure = data.SupineDiastolicBloodPressure
  1531. assessment.DiastolicPressure = data.DiastolicPressure
  1532. assessment.AdditionalWeight = data.AdditionalWeight
  1533. assessment.OtherComplication = data.OtherComplication
  1534. assessment.Ktv = data.Ktv
  1535. assessment.Urr = data.Urr
  1536. assessment.Hypertenison = data.Hypertenison
  1537. assessment.Hypopiesia = data.Hypopiesia
  1538. assessment.LeaveOfficeMethod = data.LeaveOfficeMethod
  1539. assessment.Lapse = data.Lapse
  1540. assessment.Consciousness = data.Consciousness
  1541. assessment.Fallrisk = data.Fallrisk
  1542. assessment.MachineRun = data.MachineRun
  1543. assessment.AfterUrea = data.AfterUrea
  1544. assessment.PipCoagulation = data.PipCoagulation
  1545. assessment.AccumulatedBloodVolume = data.AccumulatedBloodVolume
  1546. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1547. if assessment.ID > 0 {
  1548. if appRole.UserType == 2 || appRole.UserType == 1 {
  1549. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1550. assessment.AssessmentTime = time.Now().Unix()
  1551. } else {
  1552. if assessment.Creater == 0 {
  1553. assessment.Modifier = adminUserInfo.AdminUser.Id
  1554. assessment.Creater = adminUserInfo.AdminUser.Id
  1555. } else {
  1556. assessment.Modifier = adminUserInfo.AdminUser.Id
  1557. }
  1558. }
  1559. assessment.UpdatedTime = time.Now().Unix()
  1560. err = service.UpdateAssessmentAfterDislysisRecord(&assessment)
  1561. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1562. redis := service.RedisClient()
  1563. //清空key 值
  1564. redis.Set(key, "", time.Second)
  1565. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1566. redis.Set(keyThree, "", time.Second)
  1567. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1568. redis.Set(keyTwo, "", time.Second)
  1569. defer redis.Close()
  1570. } else {
  1571. if appRole.UserType == 2 || appRole.UserType == 1 {
  1572. assessment.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1573. assessment.AssessmentTime = time.Now().Unix()
  1574. } else {
  1575. assessment.Creater = adminUserInfo.AdminUser.Id
  1576. }
  1577. assessment.CreatedTime = time.Now().Unix()
  1578. assessment.UpdatedTime = time.Now().Unix()
  1579. assessment.UserOrgId = adminUserInfo.CurrentOrgId
  1580. assessment.PatientId = patient
  1581. assessment.AssessmentDate = recordDate.Unix()
  1582. err = service.AddSigleAssessmentAfterDislysisRecord(&assessment)
  1583. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis"
  1584. redis := service.RedisClient()
  1585. //清空key 值
  1586. redis.Set(key, "", time.Second)
  1587. keyThree := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_after_dislysis_list_all"
  1588. redis.Set(keyThree, "", time.Second)
  1589. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1590. redis.Set(keyTwo, "", time.Second)
  1591. defer redis.Close()
  1592. }
  1593. if err != nil {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1595. return
  1596. }
  1597. c.ServeSuccessJSON(map[string]interface{}{
  1598. "AssessmentAfterDislysis": &assessment,
  1599. })
  1600. }
  1601. func (c *DialysisApiController) PostAssessmentBeforeDislysis() {
  1602. patient, _ := c.GetInt64("patient", 0)
  1603. recordDateStr := c.GetString("record_date")
  1604. if patient <= 0 {
  1605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1606. return
  1607. }
  1608. adminUserInfo := c.GetAdminUserInfo()
  1609. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  1610. if patientInfo.ID == 0 {
  1611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1612. return
  1613. }
  1614. if len(recordDateStr) == 0 {
  1615. recordDateStr = time.Now().Format("2006-01-02")
  1616. }
  1617. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1618. if parseDateErr != nil {
  1619. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1621. return
  1622. }
  1623. weight_before, _ := c.GetFloat("weight_before", 0)
  1624. dry_weight, _ := c.GetFloat("dry_weight", 0)
  1625. additional_weight, _ := c.GetFloat("additional_weight", 0)
  1626. temperature, _ := c.GetFloat("temperature", 0)
  1627. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  1628. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  1629. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  1630. last_post_dialysis := c.GetString("last_post_dialysis")
  1631. dialysis_interphase := c.GetString("dialysis_interphase")
  1632. symptom_before_dialysis := c.GetString("symptom_before_dialysis")
  1633. bloodAccessPartOperaId, _ := c.GetInt64("blood_access_part_opera_id", 0)
  1634. //bloodAccessPartId, _ := c.GetInt64("blood_access_part_id", 0)
  1635. bloodAccessPartId := c.GetString("blood_access_part_id")
  1636. internalFistula := c.GetString("internal_fistula")
  1637. internal_fistula_skin := c.GetString("internal_fistula_skin")
  1638. catheter := c.GetString("catheter")
  1639. catheter_bend, _ := c.GetInt("catheter_bend")
  1640. complication := c.GetString("complication")
  1641. is_hemorrhage, _ := c.GetInt64("is_hemorrhage", 0)
  1642. hemorrhage := c.GetString("hemorrhage")
  1643. hemorrhage_other := c.GetString("hemorrhage_other")
  1644. remark := c.GetString("remark")
  1645. puncture_method := c.GetString("puncture_method")
  1646. dialysis_count := c.GetString("dialysis_count")
  1647. emergency_treatment, _ := c.GetInt64("emergency_treatment", 0)
  1648. emergency_treatment_other := c.GetString("emergency_treatment_other")
  1649. ductus_arantii := c.GetString("ductus_arantii")
  1650. venous_catheterization_part_other := c.GetString("venous_catheterization_part_other")
  1651. venous_catheterization_part, _ := c.GetInt64("venous_catheterization_part", 0)
  1652. venous_catheterization, _ := c.GetInt64("venous_catheterization", 0)
  1653. //puncture_way, _ := c.GetInt64("puncture_way", 0)
  1654. puncture_way := c.GetString("puncture_way")
  1655. blood_access_noise, _ := c.GetInt64("blood_access_noise", 0)
  1656. internal_fistula_other := c.GetString("internal_fistula_other")
  1657. blood_access_internal_fistula := c.GetString("blood_access_internal_fistula")
  1658. breathing_rate := c.GetString("breathing_rate")
  1659. is_infect, _ := c.GetInt64("is_infect", 0)
  1660. exposed, _ := c.GetFloat("exposed", 0)
  1661. skin := c.GetString("skin")
  1662. skin_other := c.GetString("skin_other")
  1663. infect_other := c.GetString("infect_other")
  1664. ductus_arantii_other := c.GetString("ductus_arantii_other")
  1665. machine_type := c.GetString("machine_type")
  1666. puncture_needle := c.GetString("puncture_needle")
  1667. //humor_excessive_symptom, _ := c.GetInt64("humor_excessive_symptom", 0)
  1668. humor_excessive_symptom := c.GetString("humor_excessive_symptom")
  1669. phinholing := c.GetString("pinholing")
  1670. catheter_suture := c.GetString("catheter_suture")
  1671. catheter_suture_other := c.GetString("catheter_suture_other")
  1672. edema := c.GetString("edema")
  1673. urine_volume, _ := c.GetFloat("urine_volume", 0)
  1674. special_treatment := c.GetString("special_treatment")
  1675. catheter_maintenance := c.GetString("catheter_maintenance")
  1676. thrombusType := c.GetString("thromubus_type")
  1677. thrombusInt, _ := strconv.ParseInt(thrombusType, 10, 64)
  1678. thrombus_a := c.GetString("thromubus_a")
  1679. thrombus_av := c.GetString("thrombus_av")
  1680. thrombus_v := c.GetString("thromubus_v")
  1681. dehydration := c.GetString("dehydration")
  1682. pre_dialysis_drugs := c.GetString("pre_dialysis_drugs")
  1683. period, _ := c.GetInt64("period")
  1684. estimated_food_intake := c.GetString("estimated_food_intake")
  1685. blood_pressure_during_dialysis := c.GetString("blood_pressure_during_dialysis")
  1686. urea_befor := c.GetString("urea_befor")
  1687. suction := c.GetString("suction")
  1688. weight_befor_remake := c.GetString("weight_befor_remake")
  1689. height := c.GetString("height")
  1690. age := c.GetString("age")
  1691. his_department := c.GetString("his_department")
  1692. his_bed := c.GetString("his_bed")
  1693. point_puncture := c.GetString("point_puncture")
  1694. assessmentBeforeDislysis := models.PredialysisEvaluation{
  1695. DialysisCount: dialysis_count,
  1696. EmergencyTreatment: emergency_treatment,
  1697. EmergencyTreatmentOther: emergency_treatment_other,
  1698. DuctusArantii: ductus_arantii,
  1699. VenousCatheterization: venous_catheterization,
  1700. VenousCatheterizationPart: venous_catheterization_part,
  1701. VenousCatheterizationPartOther: venous_catheterization_part_other,
  1702. PunctureWay: puncture_way,
  1703. BloodAccessInternalFistula: blood_access_internal_fistula,
  1704. BloodAccessNoise: blood_access_noise,
  1705. InternalFistulaOther: internal_fistula_other,
  1706. Evaluator: adminUserInfo.AdminUser.Id,
  1707. UserOrgId: adminUserInfo.CurrentOrgId,
  1708. PatientId: patient,
  1709. AssessmentDate: recordDate.Unix(),
  1710. Temperature: temperature,
  1711. PulseFrequency: pulse_frequency,
  1712. SystolicBloodPressure: systolic_blood_pressure,
  1713. DiastolicBloodPressure: diastolic_blood_pressure,
  1714. WeightBefore: weight_before,
  1715. DryWeight: dry_weight,
  1716. AdditionalWeight: additional_weight,
  1717. DialysisInterphase: dialysis_interphase,
  1718. LastPostDialysis: last_post_dialysis,
  1719. SymptomBeforeDialysis: symptom_before_dialysis,
  1720. InternalFistula: internalFistula,
  1721. InternalFistulaSkin: internal_fistula_skin,
  1722. Catheter: catheter,
  1723. CatheterBend: catheter_bend,
  1724. Complication: complication,
  1725. CreatedTime: time.Now().Unix(),
  1726. Status: 1,
  1727. Remark: remark,
  1728. IsHemorrhage: is_hemorrhage,
  1729. Hemorrhage: hemorrhage,
  1730. HemorrhageOther: hemorrhage_other,
  1731. BloodAccessPartId: bloodAccessPartId,
  1732. BloodAccessPartOperaId: bloodAccessPartOperaId,
  1733. PunctureMethod: puncture_method,
  1734. BreathingRate: breathing_rate,
  1735. IsInfect: is_infect,
  1736. Exposed: exposed,
  1737. Skin: skin,
  1738. SkinOther: skin_other,
  1739. InfectOther: infect_other,
  1740. DuctusArantiiOther: ductus_arantii_other,
  1741. MachineType: machine_type,
  1742. PunctureNeedle: puncture_needle,
  1743. HumorExcessiveSymptom: humor_excessive_symptom,
  1744. Phinholing: phinholing,
  1745. CatheterSuture: catheter_suture,
  1746. CatheterSutureOther: catheter_suture_other,
  1747. Edema: edema,
  1748. UrineVolume: urine_volume,
  1749. SpecialTreatment: special_treatment,
  1750. CatheterMaintenance: catheter_maintenance,
  1751. ThromubusType: thrombusInt,
  1752. ThrombusAv: thrombus_av,
  1753. ThromubusA: thrombus_a,
  1754. ThromubusV: thrombus_v,
  1755. Dehydration: dehydration,
  1756. PreDialysisDrugs: pre_dialysis_drugs,
  1757. Period: period,
  1758. EstimatedFoodIntake: estimated_food_intake,
  1759. BloodPressureDuringDialysis: blood_pressure_during_dialysis,
  1760. UreaBefor: urea_befor,
  1761. Suction: suction,
  1762. WeightBeforRemake: weight_befor_remake,
  1763. Height: height,
  1764. Age: age,
  1765. HisDepartment: his_department,
  1766. HisBed: his_bed,
  1767. PointPuncture: point_puncture,
  1768. }
  1769. appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
  1770. _, evaluation := service.FindPredialysisEvaluationByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  1771. if evaluation.ID == 0 { //新增
  1772. if appRole.UserType == 2 || appRole.UserType == 1 {
  1773. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1774. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1775. } else {
  1776. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  1777. }
  1778. err := service.AddSigleAssessmentBeforeDislysisRecord(&assessmentBeforeDislysis)
  1779. if adminUserInfo.CurrentOrgId == 9671 || adminUserInfo.CurrentOrgId == 3877 || adminUserInfo.CurrentOrgId == 10469 {
  1780. var dewater_amount float64
  1781. dewater_amount = 0
  1782. if dry_weight > 0 {
  1783. dewater_amount = weight_before - dry_weight - additional_weight
  1784. dewater_amount = dewater_amount * 1000
  1785. if dewater_amount <= 0 {
  1786. dewater_amount = 0
  1787. }
  1788. } else {
  1789. dewater_amount = 0
  1790. }
  1791. // 计算透析处方的相关超滤量
  1792. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1793. var lastDialysisPrescribe *models.DialysisPrescription
  1794. var dialysisSolution *models.DialysisSolution
  1795. var dialysisPrescribe *models.DialysisPrescription
  1796. var mode_id int64
  1797. if schedual != nil {
  1798. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  1799. if dialysisPrescribe == nil {
  1800. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1801. }
  1802. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1803. // 获取透析模版
  1804. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  1805. mode_id = schedual.ModeId
  1806. } else {
  1807. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  1808. // 获取透析模版
  1809. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  1810. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  1811. if dialysisPrescribe == nil && dialysisSolution != nil {
  1812. mode_id = dialysisSolution.ModeId
  1813. }
  1814. if dialysisPrescribe == nil && dialysisSolution == nil {
  1815. mode_id = 0
  1816. }
  1817. }
  1818. // 插入透析处方
  1819. if dialysisPrescribe == nil && dialysisSolution != nil {
  1820. var newprescribe models.DialysisPrescription
  1821. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  1822. newprescribe.PatientId = dialysisSolution.PatientId
  1823. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  1824. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  1825. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  1826. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  1827. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  1828. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  1829. newprescribe.ModeId = dialysisSolution.ModeId
  1830. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  1831. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  1832. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  1833. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  1834. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  1835. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  1836. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  1837. newprescribe.Glucose = dialysisSolution.Glucose
  1838. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  1839. newprescribe.Kalium = dialysisSolution.Kalium
  1840. newprescribe.Sodium = dialysisSolution.Sodium
  1841. newprescribe.Calcium = dialysisSolution.Calcium
  1842. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  1843. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  1844. newprescribe.Conductivity = dialysisSolution.Conductivity
  1845. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  1846. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  1847. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  1848. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  1849. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  1850. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  1851. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  1852. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  1853. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  1854. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  1855. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  1856. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  1857. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  1858. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  1859. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  1860. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  1861. newprescribe.CreatedTime = time.Now().Unix()
  1862. newprescribe.UpdatedTime = time.Now().Unix()
  1863. newprescribe.RecordDate = recordDate.Unix()
  1864. newprescribe.DewaterAmount = dewater_amount
  1865. newprescribe.TargetUltrafiltration = dewater_amount
  1866. newprescribe.Status = 1
  1867. err := service.AddSigleRecord(&newprescribe)
  1868. if err != nil {
  1869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1870. }
  1871. }
  1872. if dialysisPrescribe == nil && dialysisSolution == nil {
  1873. if lastDialysisPrescribe != nil {
  1874. var newprescribe models.DialysisPrescription
  1875. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  1876. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  1877. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  1878. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  1879. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  1880. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  1881. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  1882. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  1883. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  1884. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  1885. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  1886. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  1887. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  1888. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  1889. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  1890. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  1891. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  1892. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  1893. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  1894. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  1895. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  1896. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  1897. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  1898. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  1899. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  1900. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  1901. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  1902. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  1903. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  1904. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  1905. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  1906. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  1907. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  1908. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  1909. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  1910. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  1911. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  1912. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  1913. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  1914. newprescribe.CreatedTime = time.Now().Unix()
  1915. newprescribe.UpdatedTime = time.Now().Unix()
  1916. newprescribe.RecordDate = recordDate.Unix()
  1917. newprescribe.DewaterAmount = dewater_amount
  1918. newprescribe.TargetUltrafiltration = dewater_amount
  1919. newprescribe.Status = 1
  1920. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1921. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1922. err := service.AddSigleRecord(&newprescribe)
  1923. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1924. redis := service.RedisClient()
  1925. defer redis.Close()
  1926. //清空key 值
  1927. redis.Set(key, "", time.Second)
  1928. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1929. redis.Set(keyOne, "", time.Second)
  1930. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1931. redis.Set(keyThree, "", time.Second)
  1932. if err != nil {
  1933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1934. }
  1935. } else {
  1936. var newprescribe models.DialysisPrescription
  1937. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  1938. newprescribe.PatientId = patient
  1939. newprescribe.ModeId = mode_id
  1940. newprescribe.CreatedTime = time.Now().Unix()
  1941. newprescribe.UpdatedTime = time.Now().Unix()
  1942. newprescribe.RecordDate = recordDate.Unix()
  1943. newprescribe.DewaterAmount = dewater_amount
  1944. newprescribe.TargetUltrafiltration = dewater_amount
  1945. newprescribe.Status = 1
  1946. newprescribe.Creater = adminUserInfo.AdminUser.Id
  1947. newprescribe.PrescriptionDoctor = adminUserInfo.AdminUser.Id
  1948. newprescribe.Modifier = adminUserInfo.AdminUser.Id
  1949. err := service.AddSigleRecord(&newprescribe)
  1950. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  1951. redis := service.RedisClient()
  1952. defer redis.Close()
  1953. //清空key 值
  1954. redis.Set(key, "", time.Second)
  1955. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  1956. redis.Set(keyOne, "", time.Second)
  1957. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1958. redis.Set(keyThree, "", time.Second)
  1959. if err != nil {
  1960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1961. }
  1962. }
  1963. }
  1964. }
  1965. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  1966. redis := service.RedisClient()
  1967. //清空key 值
  1968. redis.Set(key, "", time.Second)
  1969. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  1970. redis.Set(keyOne, "", time.Second)
  1971. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  1972. redis.Set(keyTwo, "", time.Second)
  1973. defer redis.Close()
  1974. if err == nil {
  1975. c.ServeSuccessJSON(map[string]interface{}{
  1976. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  1977. })
  1978. } else {
  1979. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  1981. }
  1982. } else { //修改
  1983. //if appRole.UserType == 3 {
  1984. // if evaluation.Creater != adminUserInfo.AdminUser.Id && evaluation.Creater != 0 {
  1985. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  1986. // if getPermissionErr != nil {
  1987. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1988. // return
  1989. // } else if headNursePermission == nil {
  1990. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  1991. // return
  1992. // }
  1993. // }
  1994. //}
  1995. if appRole.UserType == 2 || appRole.UserType == 1 {
  1996. assessmentBeforeDislysis.AssessmentDoctor = adminUserInfo.AdminUser.Id
  1997. assessmentBeforeDislysis.AssessmentTime = time.Now().Unix()
  1998. } else {
  1999. if evaluation.Creater == 0 {
  2000. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2001. assessmentBeforeDislysis.Creater = adminUserInfo.AdminUser.Id
  2002. } else {
  2003. assessmentBeforeDislysis.Modifier = adminUserInfo.AdminUser.Id
  2004. }
  2005. }
  2006. assessmentBeforeDislysis.UpdatedTime = time.Now().Unix()
  2007. assessmentBeforeDislysis.ID = evaluation.ID
  2008. assessmentBeforeDislysis.CreatedTime = evaluation.CreatedTime
  2009. //
  2010. //新增逻辑
  2011. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  2012. var dewater_amount float64
  2013. dewater_amount = 0
  2014. if evaluation.DryWeight > 0 {
  2015. dewater_amount = evaluation.WeightBefore - evaluation.DryWeight - evaluation.AdditionalWeight
  2016. if templateInfo.TemplateId == 17 || templateInfo.TemplateId == 22 || templateInfo.TemplateId == 21 || templateInfo.TemplateId == 34 {
  2017. dewater_amount = dewater_amount * 1000
  2018. }
  2019. if dewater_amount <= 0 {
  2020. dewater_amount = 0
  2021. }
  2022. } else {
  2023. dewater_amount = 0
  2024. }
  2025. // 计算透析处方的相关超滤量
  2026. schedual, _ := service.MobileGetSchedualDetailSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2027. var lastDialysisPrescribe *models.DialysisPrescription
  2028. var dialysisSolution *models.DialysisSolution
  2029. var dialysisPrescribe *models.DialysisPrescription
  2030. var mode_id int64
  2031. if schedual != nil {
  2032. dialysisPrescribe, _ = service.MobileGetDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, recordDate.Unix(), schedual.ModeId)
  2033. if dialysisPrescribe == nil {
  2034. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2035. }
  2036. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2037. // 获取透析模版
  2038. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient, schedual.ModeId)
  2039. mode_id = schedual.ModeId
  2040. } else {
  2041. //lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribe(adminUserInfo.Org.Id, id,schedual.ModeId)
  2042. // 获取透析模版
  2043. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.CurrentOrgId, patient, recordDate.Unix())
  2044. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.CurrentOrgId, patient)
  2045. if dialysisPrescribe == nil && dialysisSolution != nil {
  2046. mode_id = dialysisSolution.ModeId
  2047. }
  2048. if dialysisPrescribe == nil && dialysisSolution == nil {
  2049. mode_id = 0
  2050. }
  2051. }
  2052. // 插入透析处方
  2053. if dialysisPrescribe == nil && dialysisSolution != nil {
  2054. var newprescribe models.DialysisPrescription
  2055. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  2056. newprescribe.PatientId = dialysisSolution.PatientId
  2057. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  2058. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  2059. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  2060. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  2061. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  2062. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  2063. newprescribe.ModeId = dialysisSolution.ModeId
  2064. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  2065. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  2066. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  2067. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  2068. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  2069. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  2070. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  2071. newprescribe.Glucose = dialysisSolution.Glucose
  2072. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  2073. newprescribe.Kalium = dialysisSolution.Kalium
  2074. newprescribe.Sodium = dialysisSolution.Sodium
  2075. newprescribe.Calcium = dialysisSolution.Calcium
  2076. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  2077. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  2078. newprescribe.Conductivity = dialysisSolution.Conductivity
  2079. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  2080. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  2081. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  2082. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  2083. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  2084. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  2085. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  2086. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  2087. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  2088. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  2089. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  2090. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  2091. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  2092. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  2093. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  2094. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  2095. newprescribe.CreatedTime = time.Now().Unix()
  2096. newprescribe.UpdatedTime = time.Now().Unix()
  2097. newprescribe.RecordDate = recordDate.Unix()
  2098. newprescribe.DewaterAmount = dewater_amount
  2099. newprescribe.TargetUltrafiltration = dewater_amount
  2100. newprescribe.Status = 1
  2101. err := service.AddSigleRecord(&newprescribe)
  2102. if err != nil {
  2103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2104. }
  2105. }
  2106. if dialysisPrescribe == nil && dialysisSolution == nil {
  2107. if lastDialysisPrescribe != nil {
  2108. var newprescribe models.DialysisPrescription
  2109. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  2110. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  2111. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  2112. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  2113. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  2114. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  2115. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  2116. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  2117. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  2118. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  2119. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  2120. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  2121. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  2122. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  2123. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  2124. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  2125. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  2126. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  2127. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  2128. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  2129. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  2130. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  2131. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  2132. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  2133. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  2134. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  2135. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  2136. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  2137. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  2138. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  2139. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  2140. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  2141. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  2142. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  2143. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  2144. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  2145. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  2146. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  2147. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  2148. newprescribe.CreatedTime = time.Now().Unix()
  2149. newprescribe.UpdatedTime = time.Now().Unix()
  2150. newprescribe.RecordDate = recordDate.Unix()
  2151. newprescribe.DewaterAmount = dewater_amount
  2152. newprescribe.TargetUltrafiltration = dewater_amount
  2153. newprescribe.Status = 1
  2154. err := service.AddSigleRecord(&newprescribe)
  2155. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2156. redis := service.RedisClient()
  2157. defer redis.Close()
  2158. //清空key 值
  2159. redis.Set(key, "", time.Second)
  2160. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2161. redis.Set(keyOne, "", time.Second)
  2162. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2163. redis.Set(keyThree, "", time.Second)
  2164. if err != nil {
  2165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2166. }
  2167. } else {
  2168. var newprescribe models.DialysisPrescription
  2169. newprescribe.UserOrgId = adminUserInfo.CurrentOrgId
  2170. newprescribe.PatientId = patient
  2171. newprescribe.ModeId = mode_id
  2172. newprescribe.CreatedTime = time.Now().Unix()
  2173. newprescribe.UpdatedTime = time.Now().Unix()
  2174. newprescribe.RecordDate = recordDate.Unix()
  2175. newprescribe.DewaterAmount = dewater_amount
  2176. newprescribe.TargetUltrafiltration = dewater_amount
  2177. newprescribe.Status = 1
  2178. err := service.AddSigleRecord(&newprescribe)
  2179. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  2180. redis := service.RedisClient()
  2181. defer redis.Close()
  2182. //清空key 值
  2183. redis.Set(key, "", time.Second)
  2184. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":prescriptions_list_all"
  2185. redis.Set(keyOne, "", time.Second)
  2186. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2187. redis.Set(keyThree, "", time.Second)
  2188. if err != nil {
  2189. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2190. }
  2191. }
  2192. }
  2193. err := service.UpadatePredialysisEvaluation(&assessmentBeforeDislysis)
  2194. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_before_dislysis"
  2195. redis := service.RedisClient()
  2196. //清空key 值
  2197. redis.Set(key, "", time.Second)
  2198. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":assessment_befores_list_all"
  2199. redis.Set(keyOne, "", time.Second)
  2200. defer redis.Close()
  2201. keyTwo := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2202. redis.Set(keyTwo, "", time.Second)
  2203. if err == nil {
  2204. c.ServeSuccessJSON(map[string]interface{}{
  2205. "assessmentBeforeDislysis": &assessmentBeforeDislysis,
  2206. })
  2207. } else {
  2208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2209. }
  2210. }
  2211. }
  2212. func (c *DialysisApiController) PostTreatmentSummary() {
  2213. patient, _ := c.GetInt64("patient", 0)
  2214. recordDateStr := c.GetString("record_date")
  2215. if patient <= 0 {
  2216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2217. return
  2218. }
  2219. adminUserInfo := c.GetAdminUserInfo()
  2220. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2221. if patientInfo.ID == 0 {
  2222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2223. return
  2224. }
  2225. if len(recordDateStr) == 0 {
  2226. recordDateStr = time.Now().Format("2006-01-02")
  2227. }
  2228. recordDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2229. if parseDateErr != nil {
  2230. c.ErrorLog("日期(%v)解析错误:%v", recordDateStr, parseDateErr)
  2231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2232. return
  2233. }
  2234. mission := c.GetString("mission")
  2235. dialysis_summary := c.GetString("dialysis_summary")
  2236. nursingRecord := c.GetString("nursing_record")
  2237. specialRecord := c.GetString("special_record")
  2238. sj_nurse := adminUserInfo.AdminUser.Id
  2239. zl_nurse := adminUserInfo.AdminUser.Id
  2240. hd_nurse := adminUserInfo.AdminUser.Id
  2241. xj_nurse := adminUserInfo.AdminUser.Id
  2242. zl_doctor := adminUserInfo.AdminUser.Id
  2243. treatmentSummary := models.TreatmentSummary{
  2244. UserOrgId: adminUserInfo.CurrentOrgId,
  2245. PatientId: patient,
  2246. AssessmentDate: recordDate.Unix(),
  2247. Mission: mission,
  2248. DialysisSummary: dialysis_summary,
  2249. SjNurse: sj_nurse,
  2250. ZlNurse: zl_nurse,
  2251. HdNurse: hd_nurse,
  2252. XjNurse: xj_nurse,
  2253. ZlDoctor: zl_doctor,
  2254. Status: 1,
  2255. CreatedTime: time.Now().Unix(),
  2256. NursingRecord: nursingRecord,
  2257. SpecialRecord: specialRecord,
  2258. }
  2259. _, tempTreatmentSummary := service.FindTreatmentSummaryByReordDate(patient, recordDate.Unix(), adminUserInfo.CurrentOrgId)
  2260. if tempTreatmentSummary.ID == 0 { //新增
  2261. treatmentSummary.Creater = adminUserInfo.AdminUser.Id
  2262. err := service.AddSigleSummaryRecord(&treatmentSummary)
  2263. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2264. redis := service.RedisClient()
  2265. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2266. redis.Set(keyOne, "", time.Second)
  2267. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2268. redis.Set(keyThree, "", time.Second)
  2269. defer redis.Close()
  2270. //清空key 值
  2271. redis.Set(key, "", time.Second)
  2272. if err == nil {
  2273. c.ServeSuccessJSON(map[string]interface{}{
  2274. "summary": treatmentSummary,
  2275. })
  2276. } else {
  2277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2278. }
  2279. } else { //修改
  2280. //if tempTreatmentSummary.Creater != adminUserInfo.AdminUser.Id {
  2281. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2282. // if getPermissionErr != nil {
  2283. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2284. // return
  2285. // } else if headNursePermission == nil {
  2286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2287. // return
  2288. // }
  2289. //}
  2290. treatmentSummary.Creater = tempTreatmentSummary.Creater
  2291. treatmentSummary.CreatedTime = tempTreatmentSummary.CreatedTime
  2292. treatmentSummary.UpdatedTime = time.Now().Unix()
  2293. treatmentSummary.Modifier = adminUserInfo.AdminUser.Id
  2294. treatmentSummary.ID = tempTreatmentSummary.ID
  2295. err := service.UpdateSummeRecord(&treatmentSummary)
  2296. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summary"
  2297. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(recordDate.Unix(), 10) + ":treatment_summarys_list_all"
  2298. keyThree := "scheduals_" + recordDateStr + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  2299. //清空key 值
  2300. redis := service.RedisClient()
  2301. redis.Set(key, "", time.Second)
  2302. redis.Set(keyOne, "", time.Second)
  2303. redis.Set(keyThree, "", time.Second)
  2304. defer redis.Close()
  2305. if err == nil {
  2306. c.ServeSuccessJSON(map[string]interface{}{
  2307. "summary": treatmentSummary,
  2308. })
  2309. } else {
  2310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  2311. }
  2312. }
  2313. }
  2314. func (c *DialysisApiController) GetDeviceList() {
  2315. adminUserInfo := c.GetAdminUserInfo()
  2316. device, _ := service.FindAllDeviceInfo(adminUserInfo.CurrentOrgId)
  2317. c.ServeSuccessJSON(map[string]interface{}{
  2318. "device": device,
  2319. })
  2320. }
  2321. func (c *DialysisApiController) GetAllDeviceZone() {
  2322. adminUserInfo := c.GetAdminUserInfo()
  2323. err, zone := service.GetAllDeviceZone(adminUserInfo.CurrentOrgId)
  2324. dics, _, err := service.GetDrugWayDics(adminUserInfo.CurrentOrgId)
  2325. efs, _, _ := service.GetExecutionFrequencyDics(adminUserInfo.CurrentOrgId)
  2326. if err == nil {
  2327. c.ServeSuccessJSON(map[string]interface{}{
  2328. "zone": zone,
  2329. "dics": dics,
  2330. "efs": efs,
  2331. })
  2332. }
  2333. }
  2334. func (c *DialysisApiController) GetDialysisWatch() {
  2335. page, _ := c.GetInt64("page", 1)
  2336. limit, _ := c.GetInt64("limit", 10)
  2337. schedulType, _ := c.GetInt64("schedul_type", 0)
  2338. startTime, _ := c.GetInt64("schedul_time", 0)
  2339. partitionType, _ := c.GetInt64("partition_type", 0)
  2340. keywords := c.GetString("keywords")
  2341. start_time, _ := c.GetInt64("start_time")
  2342. end_time, _ := c.GetInt64("end_time")
  2343. adminUserInfo := c.GetAdminUserInfo()
  2344. if len(keywords) > 0 {
  2345. dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2346. if err == nil {
  2347. c.ServeSuccessJSON(map[string]interface{}{
  2348. "schedule": dialysisSchedule,
  2349. "total": total,
  2350. })
  2351. } else {
  2352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2353. }
  2354. } else {
  2355. dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit, start_time/1000, end_time/1000)
  2356. if err == nil {
  2357. c.ServeSuccessJSON(map[string]interface{}{
  2358. "schedule": dialysisSchedule,
  2359. "total": total,
  2360. })
  2361. } else {
  2362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2363. }
  2364. }
  2365. }
  2366. //func (c *DialysisApiController) GetDialysisWatch() {
  2367. // page, _ := c.GetInt64("page", 1)
  2368. // limit, _ := c.GetInt64("limit", 10)
  2369. // schedulType, _ := c.GetInt64("schedul_type", 0)
  2370. // startTime, _ := c.GetInt64("schedul_time", 0)
  2371. // partitionType, _ := c.GetInt64("partition_type", 0)
  2372. // keywords := c.GetString("keywords")
  2373. //
  2374. // adminUserInfo := c.GetAdminUserInfo()
  2375. // if len(keywords) > 0 {
  2376. // dialysisSchedule, err, total := service.GetDialysisWatchByKeyword(adminUserInfo.CurrentOrgId, keywords, schedulType, partitionType, page, limit)
  2377. //
  2378. // //获取所有床位号
  2379. // numberList, _ := service.GetAllDeviceNumberByListSix(adminUserInfo.CurrentOrgId)
  2380. //
  2381. // //获取透析处方
  2382. // prescriptions, _ := service.GetAllPrescriptionByListTwo(adminUserInfo.CurrentOrgId, startTime)
  2383. // //获取透前评估
  2384. // assessmentBefores, _ := service.GetAllAssessmentBeforesByListThree(adminUserInfo.CurrentOrgId, startTime)
  2385. // //获取上机
  2386. // dialysisOrders, _ := service.GetAllDialysisOrdersByListThree(adminUserInfo.CurrentOrgId, startTime)
  2387. // //获取透后
  2388. // AssessmentAfterDislysis, _ := service.GetAllAssessmentAfterDislysisByListThree(adminUserInfo.CurrentOrgId, startTime)
  2389. //
  2390. // //获取透后监测
  2391. // monitorlist, _ := service.GetAllMonitorListThree(adminUserInfo.CurrentOrgId, startTime)
  2392. //
  2393. // //获取所有的患者
  2394. // patients, _ := service.GetAllPatientListByListSix(adminUserInfo.CurrentOrgId,keywords)
  2395. //
  2396. // //获取所有透析模式
  2397. // treatments, _ := service.GetAllTreatModeByList(adminUserInfo.CurrentOrgId)
  2398. //
  2399. // for key, scheduals := range dialysisSchedule {
  2400. // // 获取患者信息
  2401. // for _, patient := range patients {
  2402. // if scheduals.PatientId == patient.ID {
  2403. // dialysisSchedule[key].MonitorPatients = patient
  2404. // break
  2405. // }
  2406. // }
  2407. // // 床位信息
  2408. // for _, device := range numberList {
  2409. // if scheduals.BedId == device.ID {
  2410. // dialysisSchedule[key].DeviceNumber = device
  2411. // break
  2412. // }
  2413. // }
  2414. //
  2415. // // 医嘱信息
  2416. // for _, prescription := range prescriptions {
  2417. // if scheduals.PatientId == prescription.PatientId {
  2418. // dialysisSchedule[key].Prescription = prescription
  2419. // break
  2420. // }
  2421. // }
  2422. //
  2423. // // 透前评估
  2424. // for _, assessmentBefore := range assessmentBefores {
  2425. // if scheduals.PatientId == assessmentBefore.PatientId {
  2426. // dialysisSchedule[key].AssessmentBeforeDislysis = assessmentBefore
  2427. // break
  2428. // }
  2429. // }
  2430. //
  2431. // // 透析上下机
  2432. // for _, dialysisOrder := range dialysisOrders {
  2433. // if scheduals.PatientId == dialysisOrder.PatientId {
  2434. // dialysisSchedule[key].DialysisOrder = dialysisOrder
  2435. // break
  2436. // }
  2437. // }
  2438. //
  2439. // records := make([]*models.MonitoringRecord, 0)
  2440. // // 透析监测
  2441. // for _, it := range monitorlist {
  2442. // records := append(records, it)
  2443. // if scheduals.PatientId == it.PatientId {
  2444. // dialysisSchedule[key].MonitoringRecord = records
  2445. // }
  2446. // }
  2447. //
  2448. // // 透后评估
  2449. // for _, afterDislysis := range AssessmentAfterDislysis {
  2450. // if scheduals.PatientId == afterDislysis.PatientId {
  2451. // dialysisSchedule[key].AssessmentAfterDislysis = afterDislysis
  2452. // break
  2453. // }
  2454. // }
  2455. //
  2456. // //透析模式
  2457. // for _, treatment := range treatments {
  2458. // if scheduals.ModeId == treatment.ID {
  2459. // dialysisSchedule[key].TreatmentMode = treatment
  2460. // break
  2461. // }
  2462. // }
  2463. // }
  2464. // //获取所有床位号
  2465. // if err == nil {
  2466. // c.ServeSuccessJSON(map[string]interface{}{
  2467. // "schedule": dialysisSchedule,
  2468. // "total": total,
  2469. // })
  2470. // } else {
  2471. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2472. // }
  2473. //
  2474. // } else {
  2475. // dialysisSchedule, err, total := service.GetDialysisWatch(adminUserInfo.CurrentOrgId, startTime/1000, schedulType, partitionType, page, limit)
  2476. // if err == nil {
  2477. // c.ServeSuccessJSON(map[string]interface{}{
  2478. // "schedule": dialysisSchedule,
  2479. // "total": total,
  2480. // })
  2481. // } else {
  2482. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2483. // }
  2484. // }
  2485. //}
  2486. func (c *DialysisApiController) GetSchedualPatientsInfo() {
  2487. patientId, _ := c.GetInt64("id", 0)
  2488. record_date, _ := c.GetInt64("record_date", 0)
  2489. adminUserInfo := c.GetAdminUserInfo()
  2490. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2491. var dialysisStatus int64
  2492. if dialysisOrder == nil { //没有透析记录
  2493. dialysisStatus = 0 //未透析
  2494. } else {
  2495. dialysisStatus = dialysisOrder.Stage
  2496. }
  2497. //用户基本信息
  2498. schedualPatientInfo, _ := service.FindPatientInfoById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2499. //接诊评估
  2500. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2501. //透前评估
  2502. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2503. //临时医嘱
  2504. DoctorAdvice, _ := service.FindDoctorAdviceById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2505. //双人核对
  2506. DoubleCheck, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2507. //透析监测
  2508. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientId, record_date)
  2509. //透后评估
  2510. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2511. //透析小结
  2512. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2513. //透析处方
  2514. dialysisPrescription, _ := service.FindPatientPrescribeById(adminUserInfo.CurrentOrgId, patientId, record_date)
  2515. if dialysisPrescription.ID == 0 {
  2516. solution, _ := service.FindDialysisSolution(adminUserInfo.CurrentOrgId, patientId)
  2517. c.ServeSuccessJSON(map[string]interface{}{
  2518. "patientInfo": schedualPatientInfo,
  2519. "dialysisPrescription": solution,
  2520. "receiverTreatmentAccess": receiverTreatmentAccess,
  2521. "predialysisEvaluation": PredialysisEvaluation,
  2522. "doctorAdvice": DoctorAdvice,
  2523. "doubleCheck": DoubleCheck,
  2524. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2525. "treatmentSummary": TreatmentSummary,
  2526. "monitorRecord": Record,
  2527. "dialysisStatus": dialysisStatus,
  2528. "dialysisOrder": dialysisOrder,
  2529. "isSolution": 1,
  2530. })
  2531. } else {
  2532. c.ServeSuccessJSON(map[string]interface{}{
  2533. "patientInfo": schedualPatientInfo,
  2534. "dialysisPrescription": dialysisPrescription,
  2535. "receiverTreatmentAccess": receiverTreatmentAccess,
  2536. "predialysisEvaluation": PredialysisEvaluation,
  2537. "doctorAdvice": DoctorAdvice,
  2538. "doubleCheck": DoubleCheck,
  2539. "assessmentAfterDislysis": AssessmentAfterDislysis,
  2540. "treatmentSummary": TreatmentSummary,
  2541. "monitorRecord": Record,
  2542. "dialysisStatus": dialysisStatus,
  2543. "dialysisOrder": dialysisOrder,
  2544. "isSolution": 2,
  2545. })
  2546. }
  2547. }
  2548. func (c *DialysisApiController) CreateDoctorAdvice() {
  2549. patient, _ := c.GetInt64("id", 0)
  2550. dialysis_id, _ := c.GetInt64("dialysis_id", 0)
  2551. record_date, _ := c.GetInt64("record_date", 0)
  2552. if patient <= 0 {
  2553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2554. return
  2555. }
  2556. adminUserInfo := c.GetAdminUserInfo()
  2557. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2558. if patientInfo.ID == 0 {
  2559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2560. return
  2561. }
  2562. var advice models.DoctorAdvice
  2563. code, subAdivice := adviceFormDatas(&advice, c.Ctx.Input.RequestBody, "create")
  2564. if code > 0 {
  2565. c.ServeFailJSONWithSGJErrorCode(code)
  2566. return
  2567. }
  2568. if advice.ParentId > 0 {
  2569. old, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, advice.ParentId)
  2570. if old.ID == 0 || old.PatientId != patient {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2572. return
  2573. }
  2574. if old.StopState == 1 || old.ExecutionState == 1 {
  2575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdviceStoped)
  2576. return
  2577. }
  2578. if old.ParentId > 0 {
  2579. advice.ParentId = old.ParentId
  2580. }
  2581. advice.StartTime = old.StartTime
  2582. advice.AdviceDoctor = old.AdviceDoctor
  2583. advice.DeliveryWay = old.DeliveryWay
  2584. advice.ExecutionFrequency = old.ExecutionFrequency
  2585. }
  2586. advice.RecordDate = record_date
  2587. advice.DialysisOrderId = dialysis_id
  2588. advice.Status = 1
  2589. advice.CreatedTime = time.Now().Unix()
  2590. advice.UpdatedTime = time.Now().Unix()
  2591. advice.StopState = 2
  2592. advice.ExecutionState = 2
  2593. advice.AdviceType = 2
  2594. advice.UserOrgId = adminUserInfo.CurrentOrgId
  2595. advice.PatientId = patient
  2596. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  2597. err := service.CreateDoctorAdvice(&advice)
  2598. if err != nil {
  2599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  2600. return
  2601. }
  2602. for _, subAdvice := range subAdivice {
  2603. subAdvice.ParentId = advice.ID
  2604. subAdvice.PatientId = patient
  2605. subAdvice.RecordDate = record_date
  2606. subAdvice.CreatedTime = time.Now().Unix()
  2607. subAdvice.UpdatedTime = time.Now().Unix()
  2608. subAdvice.UserOrgId = adminUserInfo.CurrentOrgId
  2609. }
  2610. service.CreateSubDoctorAdvice(subAdivice)
  2611. _, subAdivices := service.FindAllSubDoctorAdvice(patient, advice.ID)
  2612. c.ServeSuccessJSON(map[string]interface{}{
  2613. "msg": "ok",
  2614. "advice": advice,
  2615. "subAdvice": subAdivices,
  2616. })
  2617. return
  2618. }
  2619. func (c *DialysisApiController) EditDoctorAdvice() {
  2620. patient, _ := c.GetInt64("patient", 0)
  2621. id, _ := c.GetInt64("id", 0)
  2622. parent_id, _ := c.GetInt64("parent_id", 0)
  2623. execution_time := c.GetString("execution_time")
  2624. // execution_staff, _ := c.GetInt64("execution_staff", 0)
  2625. // checker, _ := c.GetInt64("checker", 0)
  2626. if id <= 0 || patient <= 0 {
  2627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2628. return
  2629. }
  2630. adminUserInfo := c.GetAdminUserInfo()
  2631. advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
  2632. if advice.ID == 0 || advice.PatientId != patient {
  2633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
  2634. return
  2635. }
  2636. if len(execution_time) <= 0 {
  2637. utils.ErrorLog("execution_time")
  2638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2639. return
  2640. }
  2641. execution_staff := adminUserInfo.AdminUser.Id
  2642. checker := adminUserInfo.AdminUser.Id
  2643. timeLayout2 := "2006-01-02 15:04"
  2644. loc, _ := time.LoadLocation("Local")
  2645. theTime, errs := time.ParseInLocation(timeLayout2, execution_time, loc)
  2646. if errs != nil {
  2647. utils.ErrorLog(errs.Error())
  2648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2649. return
  2650. }
  2651. advices := models.DoctorAdvice{
  2652. ExecutionStaff: execution_staff,
  2653. ExecutionTime: theTime.Unix(),
  2654. Checker: checker,
  2655. UpdatedTime: time.Now().Unix(),
  2656. }
  2657. var err error
  2658. if parent_id > 0 {
  2659. err = service.ExceDoctorAdviceById(&advices, parent_id, patient)
  2660. } else {
  2661. err = service.ExceDoctorAdviceById(&advices, id, patient)
  2662. }
  2663. if err != nil {
  2664. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateDoctorAdviceFail)
  2665. return
  2666. }
  2667. c.ServeSuccessJSON(map[string]interface{}{
  2668. "msg": "ok",
  2669. "advice": advice,
  2670. })
  2671. return
  2672. }
  2673. func (c *DialysisApiController) GetDoctorAdvice() {
  2674. patient, _ := c.GetInt64("patient_id", 0)
  2675. parent_id, _ := c.GetInt64("parent_id", 0)
  2676. adviceId, _ := c.GetInt64("id", 0)
  2677. if patient <= 0 {
  2678. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2679. return
  2680. }
  2681. dminUserInfo := c.GetAdminUserInfo()
  2682. patientInfo, _ := service.FindPatientById(dminUserInfo.CurrentOrgId, patient)
  2683. if patientInfo.ID == 0 {
  2684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2685. return
  2686. }
  2687. var subAdvice []*models.DoctorAdvice
  2688. var advice models.DoctorAdvice
  2689. if parent_id > 0 {
  2690. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, parent_id)
  2691. if advice.ID == 0 || advice.PatientId != patient {
  2692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2693. return
  2694. }
  2695. subAdvice = service.FindSubAdivceById(patient, parent_id)
  2696. } else {
  2697. _, advice = service.FindAdivceById(dminUserInfo.CurrentOrgId, patient, adviceId)
  2698. if advice.ID == 0 || advice.PatientId != patient {
  2699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParentAdviceNotExist)
  2700. return
  2701. }
  2702. subAdvice = service.FindSubAdivceById(patient, adviceId)
  2703. }
  2704. c.ServeSuccessJSON(map[string]interface{}{
  2705. "msg": "ok",
  2706. "advice": advice,
  2707. "subAdvice": subAdvice,
  2708. })
  2709. }
  2710. func (this *DialysisApiController) DelMonitor() {
  2711. recordID, _ := this.GetInt64("record_id")
  2712. patientID, _ := this.GetInt64("patient_id")
  2713. if recordID <= 0 || patientID <= 0 {
  2714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2715. return
  2716. }
  2717. adminInfo := this.GetAdminUserInfo()
  2718. patient, getPatientErr := service.MobileGetPatientById(adminInfo.CurrentOrgId, patientID)
  2719. if getPatientErr != nil {
  2720. this.ErrorLog("获取患者信息失败:%v", getPatientErr)
  2721. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2722. return
  2723. } else if patient == nil {
  2724. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2725. return
  2726. }
  2727. monitor, getMonitorErr := service.GetMonitor(adminInfo.CurrentOrgId, patientID, recordID)
  2728. if getMonitorErr != nil {
  2729. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2730. return
  2731. }
  2732. //if monitor != nil {
  2733. // if monitor.MonitoringNurse != adminInfo.AdminUser.Id {
  2734. // headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminInfo.CurrentOrgId, adminInfo.CurrentAppId, adminInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
  2735. // if getPermissionErr != nil {
  2736. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2737. // return
  2738. // } else if headNursePermission == nil {
  2739. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
  2740. // return
  2741. // }
  2742. // }
  2743. //}
  2744. err := service.DisableMonitor(adminInfo.CurrentOrgId, patientID, recordID, adminInfo.AdminUser.Id)
  2745. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patientID, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_records"
  2746. redis := service.RedisClient()
  2747. //清空key 值
  2748. redis.Set(key, "", time.Second)
  2749. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitor.MonitoringDate, 10) + ":monitor_record_list_all"
  2750. redis.Set(keyOne, "", time.Second)
  2751. defer redis.Close()
  2752. if err != nil {
  2753. this.ErrorLog("删除透析监测记录失败:%v", err)
  2754. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBDelete)
  2755. return
  2756. }
  2757. this.ServeSuccessJSON(map[string]interface{}{
  2758. "record_id": monitor.ID,
  2759. })
  2760. }
  2761. func (c *DialysisApiController) CreateMonitor() {
  2762. patient, _ := c.GetInt64("id", 0)
  2763. dialysis_order_id, _ := c.GetInt64("dialysis_order_id", 0)
  2764. monitoring_date, _ := c.GetInt64("monitoring_date", 0)
  2765. operate_time, _ := c.GetInt64("operate_time", 0)
  2766. // monitoring_time := c.GetString("monitoring_time")
  2767. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0)
  2768. breathing_rated := c.GetString("breathing_rated")
  2769. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0)
  2770. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0)
  2771. blood_pressure_type, _ := c.GetInt64("blood_pressure_type", 0)
  2772. blood_flow_volume, _ := c.GetFloat("blood_flow_volume", 0)
  2773. venous_pressure, _ := c.GetFloat("venous_pressure", 0)
  2774. venous_pressure_type, _ := c.GetInt64("venous_pressure_type", 1)
  2775. transmembrane_pressure, _ := c.GetFloat("transmembrane_pressure", 0)
  2776. transmembrane_pressure_type, _ := c.GetInt64("transmembrane_pressure_type", 1)
  2777. ultrafiltration_rate, _ := c.GetFloat("ultrafiltration_rate", 0)
  2778. ultrafiltration_volume, _ := c.GetFloat("ultrafiltration_volume", 0)
  2779. sodium_concentration, _ := c.GetFloat("sodium_concentration", 0)
  2780. arterial_pressure, _ := c.GetFloat("arterial_pressure", 0)
  2781. arterial_pressure_type, _ := c.GetInt64("arterial_pressure_type", 1)
  2782. dialysate_temperature, _ := c.GetFloat("dialysate_temperature", 0)
  2783. temperature, _ := c.GetFloat("temperature", 0)
  2784. replacement_rate, _ := c.GetFloat("replacement_rate", 0)
  2785. displacement_quantity, _ := c.GetFloat("displacement_quantity", 0)
  2786. conductivity, _ := c.GetFloat("conductivity", 0)
  2787. displacement_flow_quantity, _ := c.GetFloat("displacement_flow_quantity", 0)
  2788. heparin, _ := c.GetFloat("heparin", 0)
  2789. dialysate_flow, _ := c.GetFloat("dialysate_flow", 0)
  2790. ktv, _ := c.GetFloat("ktv", 0)
  2791. symptom := c.GetString("symptom")
  2792. dispose := c.GetString("dispose")
  2793. result := c.GetString("results")
  2794. monitoring_nurse, _ := c.GetInt64("monitoring_nurse", 0)
  2795. monitor_anticoagulant, _ := c.GetInt64("monitor_anticoagulant")
  2796. monitor_anticoagulant_value := c.GetString("monitor_anticoagulant_value")
  2797. monitoring_date = monitoring_date / 1000
  2798. // operate_time = operate_time / 1000
  2799. if patient <= 0 {
  2800. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2801. return
  2802. }
  2803. adminUserInfo := c.GetAdminUserInfo()
  2804. patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2805. if patientInfo.ID == 0 {
  2806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2807. return
  2808. }
  2809. monitorRecord := models.MonitoringRecord{
  2810. PatientId: patient,
  2811. MonitoringDate: monitoring_date,
  2812. DialysisOrderId: dialysis_order_id,
  2813. OperateTime: operate_time,
  2814. // MonitoringTime: monitoring_time,
  2815. PulseFrequency: pulse_frequency,
  2816. BreathingRate: breathing_rated,
  2817. SystolicBloodPressure: systolic_blood_pressure,
  2818. DiastolicBloodPressure: diastolic_blood_pressure,
  2819. BloodPressureType: blood_pressure_type,
  2820. BloodFlowVolume: blood_flow_volume,
  2821. VenousPressure: venous_pressure,
  2822. VenousPressureType: venous_pressure_type,
  2823. TransmembranePressure: transmembrane_pressure,
  2824. TransmembranePressureType: transmembrane_pressure_type,
  2825. UltrafiltrationRate: ultrafiltration_rate,
  2826. UltrafiltrationVolume: ultrafiltration_volume,
  2827. SodiumConcentration: sodium_concentration,
  2828. ArterialPressure: arterial_pressure,
  2829. ArterialPressureType: arterial_pressure_type,
  2830. DialysateTemperature: dialysate_temperature,
  2831. Temperature: temperature,
  2832. ReplacementRate: replacement_rate,
  2833. DisplacementQuantity: displacement_quantity,
  2834. Ktv: ktv,
  2835. Symptom: symptom,
  2836. Dispose: dispose,
  2837. Result: result,
  2838. MonitoringNurse: monitoring_nurse,
  2839. Status: 1,
  2840. CreatedTime: time.Now().Unix(),
  2841. UpdatedTime: time.Now().Unix(),
  2842. UserOrgId: adminUserInfo.CurrentOrgId,
  2843. Conductivity: conductivity,
  2844. DisplacementFlowQuantity: displacement_flow_quantity,
  2845. Heparin: heparin,
  2846. DialysateFlow: dialysate_flow,
  2847. MonitorAnticoagulant: monitor_anticoagulant,
  2848. MonitorAnticoagulantValue: monitor_anticoagulant_value,
  2849. }
  2850. err := service.CreateMonitor(&monitorRecord)
  2851. redis := service.RedisClient()
  2852. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_record_list_all"
  2853. redis.Set(key, "", time.Second)
  2854. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(monitoring_date, 10) + ":monitor_records"
  2855. redis.Set(keyOne, "", time.Second)
  2856. redis.Close()
  2857. if err != nil {
  2858. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMonitorCreate)
  2859. return
  2860. }
  2861. c.ServeSuccessJSON(map[string]interface{}{
  2862. "msg": "ok",
  2863. "monitor": monitorRecord,
  2864. })
  2865. return
  2866. }
  2867. // 已弃用
  2868. // func (c *DialysisApiController) CreateRecordData() {
  2869. // patient, _ := c.GetInt64("id", 0)
  2870. // status, _ := c.GetInt64("status", 0)
  2871. // now := time.Now()
  2872. // year, month, day := now.Date()
  2873. // today_time := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
  2874. // todayTimeStamp := today_time.Unix()
  2875. // if patient <= 0 {
  2876. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2877. // return
  2878. // }
  2879. // adminUserInfo := c.GetAdminUserInfo()
  2880. // patientInfo, _ := service.FindPatientById(adminUserInfo.CurrentOrgId, patient)
  2881. // if patientInfo.ID == 0 {
  2882. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2883. // return
  2884. // }
  2885. // record := &models.DialysisOrder{
  2886. // DialysisDate: todayTimeStamp,
  2887. // UserOrgId: adminUserInfo.CurrentOrgId,
  2888. // PatientId: patient,
  2889. // Stage: status,
  2890. // Status: 1,
  2891. // CreatedTime: time.Now().Unix(),
  2892. // UpdatedTime: time.Now().Unix(),
  2893. // }
  2894. // if status == 1 {
  2895. // //创建透析记录
  2896. // err := service.CreateDialysisRecord(patient, adminUserInfo.CurrentOrgId, record)
  2897. // if err == nil {
  2898. // c.ServeSuccessJSON(map[string]interface{}{
  2899. // "dialysisOrder": record,
  2900. // })
  2901. // } else {
  2902. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2903. // }
  2904. // } else {
  2905. // record_id, _ := c.GetInt64("record_id", 0)
  2906. // //修改透析记录状态
  2907. // errs := service.ModifyDialysisRecord(record_id)
  2908. // //结束时候透析次数加1
  2909. // service.UpdateSolutionByPatientId(patient)
  2910. // if errs == nil {
  2911. // c.ServeSuccessJSON(map[string]interface{}{
  2912. // "dialysisOrder": record,
  2913. // })
  2914. // } else {
  2915. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2916. // }
  2917. // }
  2918. // }
  2919. func adviceFormDatas(advice *models.DoctorAdvice, data []byte, action string) (code int, subAdvice []*models.DoctorAdvice) {
  2920. dataBody := make(map[string]interface{}, 0)
  2921. err := json.Unmarshal(data, &dataBody)
  2922. if err != nil {
  2923. utils.ErrorLog(err.Error())
  2924. code = enums.ErrorCodeParamWrong
  2925. return
  2926. }
  2927. timeLayout := "2006-01-02 "
  2928. timeLayout2 := "2006-01-02 15:04"
  2929. loc, _ := time.LoadLocation("Local")
  2930. if action == "create" {
  2931. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  2932. utils.ErrorLog("advice_type")
  2933. code = enums.ErrorCodeParamWrong
  2934. return
  2935. }
  2936. adviceType := int64(dataBody["advice_type"].(float64))
  2937. if adviceType != 1 && adviceType != 2 {
  2938. utils.ErrorLog("advice_type != 1&&2")
  2939. code = enums.ErrorCodeParamWrong
  2940. return
  2941. }
  2942. advice.AdviceType = adviceType
  2943. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  2944. utils.ErrorLog("advice_date")
  2945. code = enums.ErrorCodeParamWrong
  2946. return
  2947. }
  2948. adviceDate, _ := dataBody["advice_date"].(string)
  2949. if len(adviceDate) == 0 {
  2950. utils.ErrorLog("len(adviceDate) == 0")
  2951. code = enums.ErrorCodeParamWrong
  2952. return
  2953. }
  2954. theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
  2955. if err != nil {
  2956. utils.ErrorLog(err.Error())
  2957. code = enums.ErrorCodeParamWrong
  2958. return
  2959. }
  2960. advice.AdviceDate = theTime.Unix()
  2961. }
  2962. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  2963. utils.ErrorLog("start_time")
  2964. code = enums.ErrorCodeParamWrong
  2965. return
  2966. }
  2967. startDate, _ := dataBody["start_time"].(string)
  2968. if len(startDate) == 0 {
  2969. utils.ErrorLog("len(startDate) == 0")
  2970. code = enums.ErrorCodeParamWrong
  2971. return
  2972. }
  2973. theTime, err := time.ParseInLocation(timeLayout2, startDate, loc)
  2974. if err != nil {
  2975. utils.ErrorLog(err.Error())
  2976. code = enums.ErrorCodeParamWrong
  2977. return
  2978. }
  2979. advice.StartTime = theTime.Unix()
  2980. if dataBody["advice_name"] == nil || reflect.TypeOf(dataBody["advice_name"]).String() != "string" {
  2981. utils.ErrorLog("advice_name")
  2982. code = enums.ErrorCodeParamWrong
  2983. return
  2984. }
  2985. adviceName, _ := dataBody["advice_name"].(string)
  2986. if len(adviceName) == 0 {
  2987. utils.ErrorLog("len(advice_name) == 0")
  2988. code = enums.ErrorCodeParamWrong
  2989. return
  2990. }
  2991. advice.AdviceName = adviceName
  2992. if dataBody["delivery_way"] == nil || reflect.TypeOf(dataBody["delivery_way"]).String() != "string" {
  2993. utils.ErrorLog("delivery_way")
  2994. code = enums.ErrorCodeParamWrong
  2995. return
  2996. }
  2997. deliveryWay, _ := dataBody["delivery_way"].(string)
  2998. if len(deliveryWay) == 0 {
  2999. utils.ErrorLog("len(deliveryWay) == 0")
  3000. code = enums.ErrorCodeParamWrong
  3001. return
  3002. }
  3003. advice.DeliveryWay = deliveryWay
  3004. if dataBody["execution_frequency"] == nil || reflect.TypeOf(dataBody["execution_frequency"]).String() != "string" {
  3005. utils.ErrorLog("execution_frequency")
  3006. code = enums.ErrorCodeParamWrong
  3007. return
  3008. }
  3009. execution_frequency, _ := dataBody["execution_frequency"].(string)
  3010. if len(execution_frequency) == 0 {
  3011. utils.ErrorLog("len(execution_frequency) == 0")
  3012. code = enums.ErrorCodeParamWrong
  3013. return
  3014. }
  3015. advice.ExecutionFrequency = execution_frequency
  3016. if dataBody["advice_desc"] != nil && reflect.TypeOf(dataBody["advice_desc"]).String() == "string" {
  3017. adviceDsc, _ := dataBody["advice_desc"].(string)
  3018. advice.AdviceDesc = adviceDsc
  3019. }
  3020. if dataBody["drug_spec_unit"] != nil && reflect.TypeOf(dataBody["drug_spec_unit"]).String() == "string" {
  3021. drugSpecUnit, _ := dataBody["drug_spec_unit"].(string)
  3022. advice.DrugSpecUnit = drugSpecUnit
  3023. }
  3024. if dataBody["single_dose"] != nil && reflect.TypeOf(dataBody["single_dose"]).String() == "string" {
  3025. singleDose, _ := strconv.ParseFloat(dataBody["single_dose"].(string), 64)
  3026. advice.SingleDose = singleDose
  3027. }
  3028. if dataBody["single_dose_unit"] != nil && reflect.TypeOf(dataBody["single_dose_unit"]).String() == "string" {
  3029. singleDoseUnit, _ := dataBody["single_dose_unit"].(string)
  3030. advice.SingleDoseUnit = singleDoseUnit
  3031. }
  3032. if dataBody["prescribing_number"] != nil && reflect.TypeOf(dataBody["prescribing_number"]).String() == "string" {
  3033. prescribingNumber, _ := strconv.ParseFloat(dataBody["prescribing_number"].(string), 64)
  3034. advice.PrescribingNumber = prescribingNumber
  3035. }
  3036. if dataBody["prescribing_number_unit"] != nil && reflect.TypeOf(dataBody["prescribing_number_unit"]).String() == "string" {
  3037. prescribingNumberUnit, _ := dataBody["prescribing_number_unit"].(string)
  3038. advice.PrescribingNumberUnit = prescribingNumberUnit
  3039. }
  3040. if dataBody["subAdviceForm"] != nil && reflect.TypeOf(dataBody["subAdviceForm"]).String() == "[]interface {}" {
  3041. thisContagions, _ := dataBody["subAdviceForm"].([]interface{})
  3042. if len(thisContagions) > 0 {
  3043. for _, item := range thisContagions {
  3044. items := item.(map[string]interface{})
  3045. advice_name, _ := items["advice_name"].(string)
  3046. advice_desc, _ := items["advice_desc"].(string)
  3047. drug_spec_unit, _ := items["drug_spec_unit"].(string)
  3048. prescribing_number_unit, _ := items["prescribing_number_unit"].(string)
  3049. single_dose_unit, _ := items["single_dose_unit"].(string)
  3050. prescribing_number, _ := strconv.ParseFloat(items["prescribing_number"].(string), 64)
  3051. single_dose, _ := strconv.ParseFloat(items["single_dose"].(string), 64)
  3052. advice := &models.DoctorAdvice{
  3053. AdviceName: advice_name,
  3054. AdviceDesc: advice_desc,
  3055. SingleDose: single_dose,
  3056. SingleDoseUnit: single_dose_unit,
  3057. DrugSpecUnit: drug_spec_unit,
  3058. PrescribingNumber: prescribing_number,
  3059. PrescribingNumberUnit: prescribing_number_unit,
  3060. }
  3061. subAdvice = append(subAdvice, advice)
  3062. }
  3063. }
  3064. }
  3065. return
  3066. }
  3067. func (c *DialysisApiController) GetDialysisOrder() {
  3068. xtno := c.GetString("xtno")
  3069. xtdate := c.GetString("xtdate")
  3070. timeLayout := "2006-01-02"
  3071. loc, _ := time.LoadLocation("Local")
  3072. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", xtdate+" 00:00:00", loc)
  3073. if err != nil {
  3074. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3075. return
  3076. }
  3077. xttime := theTime.Unix()
  3078. operatorIDs := make([]int64, 0)
  3079. adminUserInfo := c.GetAdminUserInfo()
  3080. adminUser, _ := service.GetAllAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
  3081. patientInfo, _ := service.FindPatientWithDeviceByNo(adminUserInfo.CurrentOrgId, xtno, xttime)
  3082. //透析单
  3083. dialysisOrder, _ := service.MobileGetSchedualDialysisRecordTen(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3084. if dialysisOrder != nil {
  3085. if dialysisOrder.FinishNurse > 0 {
  3086. operatorIDs = append(operatorIDs, dialysisOrder.FinishNurse)
  3087. }
  3088. if dialysisOrder.StartNurse > 0 {
  3089. operatorIDs = append(operatorIDs, dialysisOrder.StartNurse)
  3090. }
  3091. }
  3092. //透前评估
  3093. PredialysisEvaluation, _ := service.FindPredialysisEvaluationById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3094. predialysName, err := service.FindPredialysisName(PredialysisEvaluation.BloodAccessPartOperaId, adminUserInfo.CurrentOrgId)
  3095. //透后评估
  3096. AssessmentAfterDislysis, _ := service.FindAssessmentAfterDislysisById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3097. if AssessmentAfterDislysis.Modifier > 0 {
  3098. operatorIDs = append(operatorIDs, AssessmentAfterDislysis.Modifier)
  3099. }
  3100. //上次透前评估
  3101. lastPredialysisEvaluation, _ := service.GetLastTimePredialysisEvaluation(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3102. lastOrder, _ := service.GetLastTimeOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3103. //透析处方
  3104. dialysisPrescription, _ := service.FindPatientPrescribeWidyDevideById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3105. if dialysisPrescription.PrescriptionDoctor > 0 {
  3106. operatorIDs = append(operatorIDs, dialysisPrescription.PrescriptionDoctor)
  3107. }
  3108. //获取病人的透析模式
  3109. schedule, err := service.FindDialysisMode(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3110. order, err := service.FindDialysisMacher(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3111. nurse, err := service.FindPunctureNurse(order.PunctureNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3112. startNuse, err := service.FindeStartNuse(order.StartNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3113. FinishNuse, err := service.FindeStartNuse(order.FinishNurse, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3114. //获取透析处方
  3115. dialysisway, err := service.FindDialysisWay(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3116. //获取临时医嘱
  3117. doctorAdvice, _ := service.FindDoctorOrder(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3118. //config, err := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3119. //获取医嘱内容
  3120. doctor, err := service.FindDoctor(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3121. DoctorName, err := service.FindDoctorName(doctorAdvice.AdviceDoctor, adminUserInfo.CurrentAppId, adminUserInfo.CurrentOrgId)
  3122. DoctorAdvice, _ := service.FindDoctorAdviceOrderById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3123. doctorAdevieInfo, err := service.FindDoctorAdviceByInfo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3124. //获取上次的透后体重
  3125. // assessmentAfterDislysis, _ := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3126. assessmentAfterDislysis, _ := service.MobileGetLast(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3127. //获取透析次数
  3128. _, total, err := service.GetTotalDialysisCout(adminUserInfo.CurrentOrgId, patientInfo.ID)
  3129. if len(DoctorAdvice) > 0 {
  3130. for _, item := range DoctorAdvice {
  3131. if item.AdviceDoctor > 0 {
  3132. operatorIDs = append(operatorIDs, item.AdviceDoctor)
  3133. }
  3134. if item.ExecutionStaff > 0 {
  3135. operatorIDs = append(operatorIDs, item.ExecutionStaff)
  3136. }
  3137. if item.Checker > 0 {
  3138. operatorIDs = append(operatorIDs, item.Checker)
  3139. }
  3140. }
  3141. }
  3142. //透析监测
  3143. Record, _ := service.FindAllMonitorRecord(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3144. //透析检测
  3145. //monitor, err := service.FindAllMonitor(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3146. //透析小结
  3147. TreatmentSummary, _ := service.FindTreatmentSummaryById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3148. //接诊评估
  3149. receiverTreatmentAccess, _ := service.FindReceiverTreatmentAccessRecordById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3150. check, _ := service.FindDoubleCheckById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3151. if adminUserInfo.CurrentOrgId != 10101 && adminUserInfo.CurrentOrgId != 10445 && adminUserInfo.CurrentOrgId != 10345 {
  3152. dialysis_count, _ := service.GetDialysisOrderCount(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3153. patientInfo.TotalDialysis = dialysis_count
  3154. }
  3155. if adminUserInfo.CurrentOrgId == 10101 || adminUserInfo.CurrentOrgId == 10445 || adminUserInfo.CurrentOrgId == 10345 {
  3156. if xttime <= 1672416000 {
  3157. dialysis_count, _ := service.GetDialysisOrderCountOne(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3158. patientInfo.TotalDialysis = dialysis_count
  3159. }
  3160. if xttime >= 1672502400 {
  3161. dialysis_count, _ := service.GetDialysisOrderCountTwo(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3162. patientInfo.TotalDialysis = dialysis_count
  3163. }
  3164. }
  3165. //相关操作对应的操作人
  3166. //operators, _ := service.GetAdminUserES(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, operatorIDs)
  3167. operators, err := service.GetAdminUserEsOne(adminUserInfo.CurrentOrgId)
  3168. templateInfo, _ := service.GetOrgInfoTemplate(adminUserInfo.CurrentOrgId)
  3169. //获取当前日期月份的第一天
  3170. firstmonth := service.GetFirstDateOfMonth(theTime)
  3171. firstMonthDate := firstmonth.Unix()
  3172. //获取当前月份的病人透析次数
  3173. dialysiscount, err := service.GetDialysisCountByPatientId(firstMonthDate, xttime, patientInfo.ID, adminUserInfo.CurrentOrgId)
  3174. //获取his数据
  3175. hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3176. //hisAdvice, err := service.GetHisDoctorPatientById(adminUserInfo.Org.Id, patientInfo.ID, xttime)
  3177. config, _ := service.GetHisDoctorConfig(adminUserInfo.CurrentOrgId)
  3178. project_config, _ := service.GetHisProjectConfig(adminUserInfo.CurrentOrgId)
  3179. projects, _ := service.FindAllHisProjectById(adminUserInfo.CurrentOrgId, patientInfo.ID, xttime)
  3180. //if config.IsOpen == 1 && project_config.IsOpen == 1 && len(projects) > 0 {
  3181. // for _, item := range projects {
  3182. // var advice *models.HisDoctorAdviceInfo
  3183. // advice.ID = item.ID
  3184. // advice.Checker = item.Checker
  3185. // advice.CheckTime = item.CheckTime
  3186. // advice.CheckState = item.CheckState
  3187. // advice.ExecutionState = item.ExecutionState
  3188. // advice.ExecutionStaff = item.ExecutionStaff
  3189. // advice.PrescribingNumber = float64(item.Count)
  3190. // advice.PrescribingNumberUnit = item.Unit
  3191. // advice.AdviceDoctor = item.Doctor
  3192. // if item.Type == 3 {
  3193. // advice.AdviceName = item.GoodInfo.GoodName
  3194. // } else if item.Type == 2 {
  3195. // advice.AdviceName = item.HisProject.ProjectName
  3196. // }
  3197. // advice.StartTime = item.StartTime
  3198. // hisAdvice = append(hisAdvice, advice)
  3199. // }
  3200. //}
  3201. if config.IsOpen == 1 {
  3202. c.ServeSuccessJSON(map[string]interface{}{
  3203. "xtdate": xtdate,
  3204. "users": adminUser,
  3205. "patientInfo": patientInfo,
  3206. "PredialysisEvaluation": PredialysisEvaluation,
  3207. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3208. "dialysisPrescription": dialysisPrescription,
  3209. "advices": hisAdvice,
  3210. "monitors": Record,
  3211. "summary": TreatmentSummary,
  3212. "receiverTreatmentAccess": receiverTreatmentAccess,
  3213. "dialysisOrder": dialysisOrder,
  3214. "operators": operators,
  3215. "org_template_info": templateInfo,
  3216. "check": check,
  3217. "schedule": schedule,
  3218. "dialysisway": dialysisway,
  3219. "order": order,
  3220. "doctorAdvice": doctorAdvice,
  3221. "doctor": doctor,
  3222. "nurse": nurse,
  3223. "doctorAdevieInfo": doctorAdevieInfo,
  3224. "total": total,
  3225. "startNuse": startNuse,
  3226. "DoctorName": DoctorName,
  3227. "assessmentAfterDislysis": assessmentAfterDislysis,
  3228. "predialysName": predialysName,
  3229. "FinishNuse": FinishNuse,
  3230. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3231. "dialysiscount": dialysiscount,
  3232. "last_order": lastOrder,
  3233. "project_config": project_config,
  3234. "projects": projects,
  3235. })
  3236. }
  3237. if config.IsOpen == 0 || config.IsOpen == 2 {
  3238. c.ServeSuccessJSON(map[string]interface{}{
  3239. "xtdate": xtdate,
  3240. "users": adminUser,
  3241. "patientInfo": patientInfo,
  3242. "PredialysisEvaluation": PredialysisEvaluation,
  3243. "AssessmentAfterDislysis": AssessmentAfterDislysis,
  3244. "dialysisPrescription": dialysisPrescription,
  3245. "advices": DoctorAdvice,
  3246. "monitors": Record,
  3247. "summary": TreatmentSummary,
  3248. "receiverTreatmentAccess": receiverTreatmentAccess,
  3249. "dialysisOrder": dialysisOrder,
  3250. "operators": operators,
  3251. "org_template_info": templateInfo,
  3252. "check": check,
  3253. "schedule": schedule,
  3254. "dialysisway": dialysisway,
  3255. "order": order,
  3256. "doctorAdvice": doctorAdvice,
  3257. "doctor": doctor,
  3258. "nurse": nurse,
  3259. "doctorAdevieInfo": doctorAdevieInfo,
  3260. "total": total,
  3261. "startNuse": startNuse,
  3262. "DoctorName": DoctorName,
  3263. "assessmentAfterDislysis": assessmentAfterDislysis,
  3264. "predialysName": predialysName,
  3265. "FinishNuse": FinishNuse,
  3266. "lastPredialysisEvaluation": lastPredialysisEvaluation,
  3267. "dialysiscount": dialysiscount,
  3268. "last_order": lastOrder,
  3269. "project_config": project_config,
  3270. "projects": projects,
  3271. })
  3272. }
  3273. }
  3274. func (c *DialysisApiController) GetLongAdvice() {
  3275. patient_id, _ := c.GetInt64("patient_id")
  3276. adminUserInfo := c.GetAdminUserInfo()
  3277. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3278. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3279. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3280. c.ServeSuccessJSON(map[string]interface{}{
  3281. "status": "1",
  3282. })
  3283. return
  3284. } else { //开启推送提醒
  3285. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3286. var advice_three []*models.DoctorAdvice
  3287. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3288. recordDateStr := time.Now().Format("2006-01-02")
  3289. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3290. nowtime := recordDate.Unix()
  3291. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3292. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, nowtime)
  3293. for _, advice := range advices {
  3294. if advice.FrequencyType == 3 {
  3295. t := time.Now()
  3296. week := int(t.Weekday())
  3297. switch week {
  3298. case 1:
  3299. if strings.Index(advice.WeekDay, "周一") == -1 {
  3300. advice_three = append(advice_three, advice)
  3301. }
  3302. break
  3303. case 2:
  3304. if strings.Index(advice.WeekDay, "周二") == -1 {
  3305. advice_three = append(advice_three, advice)
  3306. }
  3307. break
  3308. case 3:
  3309. if strings.Index(advice.WeekDay, "周三") == -1 {
  3310. advice_three = append(advice_three, advice)
  3311. }
  3312. break
  3313. case 4:
  3314. if strings.Index(advice.WeekDay, "周四") == -1 {
  3315. advice_three = append(advice_three, advice)
  3316. }
  3317. break
  3318. case 5:
  3319. if strings.Index(advice.WeekDay, "周五") == -1 {
  3320. advice_three = append(advice_three, advice)
  3321. }
  3322. break
  3323. case 6:
  3324. if strings.Index(advice.WeekDay, "周六") == -1 {
  3325. advice_three = append(advice_three, advice)
  3326. }
  3327. break
  3328. case 0:
  3329. if strings.Index(advice.WeekDay, "周日") == -1 {
  3330. advice_three = append(advice_three, advice)
  3331. }
  3332. break
  3333. }
  3334. }
  3335. }
  3336. for _, advice := range advices_two {
  3337. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3338. now := p.Unix()
  3339. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3340. dayStr2 := "-" + dayStr
  3341. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3342. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3343. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3344. for _, ad := range advices {
  3345. advice_three = append(advice_three, ad)
  3346. }
  3347. }
  3348. if err == nil {
  3349. c.ServeSuccessJSON(map[string]interface{}{
  3350. "status": "2",
  3351. "advices": advices,
  3352. "advices_two": RemoveRepeatedElement(advice_three),
  3353. "is_open_remind": config.IsOpenRemind,
  3354. })
  3355. }
  3356. }
  3357. }
  3358. func (c *DialysisApiController) GetLongAdviceOne() {
  3359. patient_id, _ := c.GetInt64("patient_id")
  3360. schedule_date := c.GetString("schedule_date")
  3361. adminUserInfo := c.GetAdminUserInfo()
  3362. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3363. timeLayout := "2006-01-02"
  3364. loc, _ := time.LoadLocation("Local")
  3365. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  3366. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3367. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3368. c.ServeSuccessJSON(map[string]interface{}{
  3369. "status": "1",
  3370. })
  3371. return
  3372. } else { //开启推送提醒
  3373. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3374. var advice_three []*models.DoctorAdvice
  3375. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3376. //recordDateStr := time.Now().Format("2006-01-02")
  3377. //recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3378. //
  3379. //nowtime := recordDate.Unix()
  3380. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3381. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, theTime.Unix())
  3382. for _, advice := range advices {
  3383. if advice.FrequencyType == 3 {
  3384. t := time.Now()
  3385. week := int(t.Weekday())
  3386. switch week {
  3387. case 1:
  3388. if strings.Index(advice.WeekDay, "周一") == -1 {
  3389. advice_three = append(advice_three, advice)
  3390. }
  3391. break
  3392. case 2:
  3393. if strings.Index(advice.WeekDay, "周二") == -1 {
  3394. advice_three = append(advice_three, advice)
  3395. }
  3396. break
  3397. case 3:
  3398. if strings.Index(advice.WeekDay, "周三") == -1 {
  3399. advice_three = append(advice_three, advice)
  3400. }
  3401. break
  3402. case 4:
  3403. if strings.Index(advice.WeekDay, "周四") == -1 {
  3404. advice_three = append(advice_three, advice)
  3405. }
  3406. break
  3407. case 5:
  3408. if strings.Index(advice.WeekDay, "周五") == -1 {
  3409. advice_three = append(advice_three, advice)
  3410. }
  3411. break
  3412. case 6:
  3413. if strings.Index(advice.WeekDay, "周六") == -1 {
  3414. advice_three = append(advice_three, advice)
  3415. }
  3416. break
  3417. case 0:
  3418. if strings.Index(advice.WeekDay, "周日") == -1 {
  3419. advice_three = append(advice_three, advice)
  3420. }
  3421. break
  3422. }
  3423. }
  3424. }
  3425. for _, advice := range advices_two {
  3426. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3427. now := p.Unix()
  3428. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3429. dayStr2 := "-" + dayStr
  3430. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3431. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3432. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3433. for _, ad := range advices {
  3434. advice_three = append(advice_three, ad)
  3435. }
  3436. }
  3437. if err == nil {
  3438. c.ServeSuccessJSON(map[string]interface{}{
  3439. "status": "2",
  3440. "advices": advices,
  3441. "advices_two": RemoveRepeatedElement(advice_three),
  3442. "is_open_remind": config.IsOpenRemind,
  3443. })
  3444. }
  3445. }
  3446. }
  3447. func (c *DialysisApiController) GetLongAdviceTwo() {
  3448. patient_id, _ := c.GetInt64("patient_id")
  3449. schedule_date, _ := c.GetInt64("schedule_date")
  3450. adminUserInfo := c.GetAdminUserInfo()
  3451. _, config := service.FindDoctorAdviceRecordByOrgId(adminUserInfo.CurrentOrgId)
  3452. //patient, _ := service.FindPatientIsOpenRemindById(patient_id, adminUserInfo.Org.Id)
  3453. if config.IsOpenRemind == 0 { //针对老用户,即没开启推送功能,也没有 不开启推送功能,不做任何处理
  3454. c.ServeSuccessJSON(map[string]interface{}{
  3455. "status": "1",
  3456. })
  3457. return
  3458. } else { //开启推送提醒
  3459. //开启推送提醒逻辑 提交长期处方的时候,弹起长期医嘱推送
  3460. var advice_three []*models.DoctorAdvice
  3461. //groupNo := service.GetMaxLongAdviceGroupID(adminUserInfo.Org.Id, patient_id)
  3462. advices, err := service.GetLastLongAdviceByGroupNo(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3463. advices_two, err := service.GetLastLongAdviceByGroupNoThree(adminUserInfo.CurrentOrgId, patient_id, schedule_date)
  3464. for _, advice := range advices {
  3465. if advice.FrequencyType == 3 {
  3466. t := time.Now()
  3467. week := int(t.Weekday())
  3468. switch week {
  3469. case 1:
  3470. if strings.Index(advice.WeekDay, "周一") == -1 {
  3471. advice_three = append(advice_three, advice)
  3472. }
  3473. break
  3474. case 2:
  3475. if strings.Index(advice.WeekDay, "周二") == -1 {
  3476. advice_three = append(advice_three, advice)
  3477. }
  3478. break
  3479. case 3:
  3480. if strings.Index(advice.WeekDay, "周三") == -1 {
  3481. advice_three = append(advice_three, advice)
  3482. }
  3483. break
  3484. case 4:
  3485. if strings.Index(advice.WeekDay, "周四") == -1 {
  3486. advice_three = append(advice_three, advice)
  3487. }
  3488. break
  3489. case 5:
  3490. if strings.Index(advice.WeekDay, "周五") == -1 {
  3491. advice_three = append(advice_three, advice)
  3492. }
  3493. break
  3494. case 6:
  3495. if strings.Index(advice.WeekDay, "周六") == -1 {
  3496. advice_three = append(advice_three, advice)
  3497. }
  3498. break
  3499. case 0:
  3500. if strings.Index(advice.WeekDay, "周日") == -1 {
  3501. advice_three = append(advice_three, advice)
  3502. }
  3503. break
  3504. }
  3505. }
  3506. }
  3507. for _, advice := range advices_two {
  3508. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  3509. now := p.Unix()
  3510. dayStr := strconv.FormatInt(advice.DayCount, 10)
  3511. dayStr2 := "-" + dayStr
  3512. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  3513. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  3514. advices, _ := service.FindAllDoctorAdviceByTime(now, oldTime, patient_id, adminUserInfo.CurrentOrgId, advice.TemplateId)
  3515. for _, ad := range advices {
  3516. advice_three = append(advice_three, ad)
  3517. }
  3518. }
  3519. if err == nil {
  3520. c.ServeSuccessJSON(map[string]interface{}{
  3521. "status": "2",
  3522. "advices": advices,
  3523. "advices_two": RemoveRepeatedElement(advice_three),
  3524. "is_open_remind": config.IsOpenRemind,
  3525. })
  3526. }
  3527. }
  3528. }
  3529. func RemoveRepeatedElement(arr []*models.DoctorAdvice) (newArr []*models.DoctorAdvice) {
  3530. newArr = make([]*models.DoctorAdvice, 0)
  3531. for i := 0; i < len(arr); i++ {
  3532. repeat := false
  3533. for j := i + 1; j < len(arr); j++ {
  3534. if arr[i].ID == arr[j].ID {
  3535. repeat = true
  3536. break
  3537. }
  3538. }
  3539. if !repeat {
  3540. newArr = append(newArr, arr[i])
  3541. }
  3542. }
  3543. return
  3544. }
  3545. func (c *DialysisApiController) CreateRemindDoctorAdvice() {
  3546. patient, _ := c.GetInt64("id", 0)
  3547. groupNo, _ := c.GetInt64("groupno", 0)
  3548. if patient <= 0 {
  3549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3550. return
  3551. }
  3552. adminUserInfo := c.GetAdminUserInfo()
  3553. dataBody := make(map[string]interface{}, 0)
  3554. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3555. if err != nil {
  3556. utils.ErrorLog(err.Error())
  3557. return
  3558. }
  3559. utils.ErrorLog("%v", dataBody)
  3560. timeLayout := "2006-01-02 15:04"
  3561. loc, _ := time.LoadLocation("Local")
  3562. timeLayout2 := "2006-01-02"
  3563. loc2, _ := time.LoadLocation("Local")
  3564. if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
  3565. utils.ErrorLog("advice_type")
  3566. return
  3567. }
  3568. adviceType := int64(2)
  3569. if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
  3570. utils.ErrorLog("advice_date")
  3571. return
  3572. }
  3573. adviceDate, _ := dataBody["advice_date"].(string)
  3574. theTime, err := time.ParseInLocation(timeLayout2, adviceDate, loc2)
  3575. AdviceDate := theTime.Unix()
  3576. RecordDate := theTime.Unix()
  3577. if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
  3578. utils.ErrorLog("start_time")
  3579. return
  3580. }
  3581. startTime, _ := dataBody["start_time"].(string)
  3582. if len(startTime) == 0 {
  3583. utils.ErrorLog("len(start_time) == 0")
  3584. return
  3585. }
  3586. theTimeUnix, err := time.ParseInLocation(timeLayout, startTime, loc)
  3587. if err != nil {
  3588. utils.ErrorLog(err.Error())
  3589. return
  3590. }
  3591. StartTime := theTimeUnix.Unix()
  3592. fmt.Println("startTIME", StartTime)
  3593. Remark := ""
  3594. if dataBody["remark"] != nil && reflect.TypeOf(dataBody["remark"]).String() == "string" {
  3595. remark, _ := dataBody["remark"].(string)
  3596. Remark = remark
  3597. }
  3598. var advices []*models.GroupAdvice
  3599. if dataBody["advices"] == nil || reflect.TypeOf(dataBody["advices"]).String() != "[]interface {}" {
  3600. utils.ErrorLog("advices")
  3601. return
  3602. }
  3603. adviceNames := dataBody["advices"].([]interface{})
  3604. for _, adviceNameMap := range adviceNames {
  3605. adviceNameM := adviceNameMap.(map[string]interface{})
  3606. var advice models.GroupAdvice
  3607. advice.Remark = Remark
  3608. advice.AdviceType = adviceType
  3609. advice.StartTime = StartTime
  3610. advice.AdviceDate = AdviceDate
  3611. advice.RecordDate = RecordDate
  3612. advice.Status = 1
  3613. advice.CreatedTime = time.Now().Unix()
  3614. advice.UpdatedTime = time.Now().Unix()
  3615. advice.StopState = 2
  3616. advice.ExecutionState = 2
  3617. advice.UserOrgId = adminUserInfo.CurrentOrgId
  3618. advice.PatientId = patient
  3619. advice.AdviceDoctor = adminUserInfo.AdminUser.Id
  3620. advice.IsSettle = 2
  3621. if adviceNameM["advice_name"] == nil || reflect.TypeOf(adviceNameM["advice_name"]).String() != "string" {
  3622. utils.ErrorLog("advice_name")
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3624. return
  3625. }
  3626. adviceName, _ := adviceNameM["advice_name"].(string)
  3627. if len(adviceName) == 0 {
  3628. utils.ErrorLog("len(advice_name) == 0")
  3629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3630. return
  3631. }
  3632. advice.AdviceName = adviceName
  3633. if adviceNameM["drug_spec"] != nil && reflect.TypeOf(adviceNameM["drug_spec"]).String() == "string" {
  3634. drugSpec, _ := strconv.ParseFloat(adviceNameM["drug_spec"].(string), 64)
  3635. advice.DrugSpec = drugSpec
  3636. }
  3637. if adviceNameM["advice_desc"] != nil && reflect.TypeOf(adviceNameM["advice_desc"]).String() == "string" {
  3638. adviceDesc, _ := adviceNameM["advice_desc"].(string)
  3639. advice.AdviceDesc = adviceDesc
  3640. }
  3641. if adviceNameM["drug_spec_unit"] != nil && reflect.TypeOf(adviceNameM["drug_spec_unit"]).String() == "string" {
  3642. drugSpecUnit, _ := adviceNameM["drug_spec_unit"].(string)
  3643. advice.DrugSpecUnit = drugSpecUnit
  3644. }
  3645. //if adviceNameM["single_dose"] != nil && reflect.TypeOf(adviceNameM["single_dose"]).String() == "string" {
  3646. // singleDose, _ := strconv.ParseFloat(adviceNameM["single_dose"].(string), 64)
  3647. // advice.SingleDose = singleDose
  3648. //}
  3649. if adviceNameM["single_dose"] != nil || reflect.TypeOf(adviceNameM["single_dose"]).String() == "float64" {
  3650. //single_dose := int64(adviceNameM["single_dose"].(float64))
  3651. advice.SingleDose = adviceNameM["single_dose"].(float64)
  3652. }
  3653. if adviceNameM["single_dose_unit"] != nil && reflect.TypeOf(adviceNameM["single_dose_unit"]).String() == "string" {
  3654. singleDoseUnit, _ := adviceNameM["single_dose_unit"].(string)
  3655. advice.SingleDoseUnit = singleDoseUnit
  3656. }
  3657. //if adviceNameM["prescribing_number"] != nil && reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "string" {
  3658. // prescribingNumber, _ := strconv.ParseFloat(adviceNameM["prescribing_number"].(string), 64)
  3659. // advice.PrescribingNumber = prescribingNumber
  3660. //}
  3661. if adviceNameM["prescribing_number"] != nil || reflect.TypeOf(adviceNameM["prescribing_number"]).String() == "float64" {
  3662. advice.PrescribingNumber = adviceNameM["prescribing_number"].(float64)
  3663. }
  3664. if adviceNameM["prescribing_number_unit"] != nil && reflect.TypeOf(adviceNameM["prescribing_number_unit"]).String() == "string" {
  3665. prescribingNumberUnit, _ := adviceNameM["prescribing_number_unit"].(string)
  3666. advice.PrescribingNumberUnit = prescribingNumberUnit
  3667. }
  3668. if adviceNameM["delivery_way"] != nil && reflect.TypeOf(adviceNameM["delivery_way"]).String() == "string" {
  3669. deliveryWay, _ := adviceNameM["delivery_way"].(string)
  3670. advice.DeliveryWay = deliveryWay
  3671. }
  3672. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3673. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3674. advice.ExecutionFrequency = executionFrequency
  3675. }
  3676. if adviceNameM["frequency_type"] != nil || reflect.TypeOf(adviceNameM["frequency_type"]).String() == "float64" {
  3677. frequency_type := int64(adviceNameM["frequency_type"].(float64))
  3678. advice.FrequencyType = frequency_type
  3679. }
  3680. if adviceNameM["day_count"] != nil || reflect.TypeOf(adviceNameM["day_count"]).String() == "float64" {
  3681. day_count := int64(adviceNameM["day_count"].(float64))
  3682. advice.DayCount = day_count
  3683. }
  3684. if adviceNameM["way"] != nil || reflect.TypeOf(adviceNameM["way"]).String() == "float64" {
  3685. way := int64(adviceNameM["way"].(float64))
  3686. advice.Way = way
  3687. }
  3688. if adviceNameM["drug_id"] != nil || reflect.TypeOf(adviceNameM["drug_id"]).String() == "float64" {
  3689. drug_id := int64(adviceNameM["drug_id"].(float64))
  3690. advice.DrugId = drug_id
  3691. }
  3692. if adviceNameM["drug_name_id"] != nil || reflect.TypeOf(adviceNameM["drug_name_id"]).String() == "float64" {
  3693. drug_name_id := int64(adviceNameM["drug_name_id"].(float64))
  3694. advice.DrugNameId = drug_name_id
  3695. }
  3696. if adviceNameM["week_day"] != nil && reflect.TypeOf(adviceNameM["week_day"]).String() == "string" {
  3697. week_day, _ := adviceNameM["week_day"].(string)
  3698. advice.WeekDay = week_day
  3699. }
  3700. if adviceNameM["template_id"] != nil && reflect.TypeOf(adviceNameM["template_id"]).String() == "string" {
  3701. template_id, _ := adviceNameM["template_id"].(string)
  3702. advice.TemplateId = template_id
  3703. }
  3704. if adviceNameM["execution_frequency"] != nil && reflect.TypeOf(adviceNameM["execution_frequency"]).String() == "string" {
  3705. executionFrequency, _ := adviceNameM["execution_frequency"].(string)
  3706. advice.ExecutionFrequency = executionFrequency
  3707. }
  3708. if adviceNameM["child"] != nil && reflect.TypeOf(adviceNameM["child"]).String() == "[]interface {}" {
  3709. children := adviceNameM["child"].([]interface{})
  3710. if len(children) > 0 {
  3711. for _, childrenMap := range children {
  3712. childMap := childrenMap.(map[string]interface{})
  3713. var child models.GroupAdvice
  3714. child.Remark = Remark
  3715. child.AdviceType = adviceType
  3716. child.StartTime = StartTime
  3717. child.AdviceDate = AdviceDate
  3718. child.RecordDate = RecordDate
  3719. child.Status = 1
  3720. child.CreatedTime = time.Now().Unix()
  3721. child.UpdatedTime = time.Now().Unix()
  3722. child.StopState = 2
  3723. child.ExecutionState = 2
  3724. child.UserOrgId = adminUserInfo.CurrentOrgId
  3725. child.PatientId = patient
  3726. child.AdviceDoctor = adminUserInfo.AdminUser.Id
  3727. child.IsSettle = 2
  3728. if childMap["advice_name"] == nil || reflect.TypeOf(childMap["advice_name"]).String() != "string" {
  3729. utils.ErrorLog("child advice_name")
  3730. return
  3731. }
  3732. childAdviceName, _ := childMap["advice_name"].(string)
  3733. if len(childAdviceName) == 0 {
  3734. utils.ErrorLog("len(child advice_name) == 0")
  3735. return
  3736. }
  3737. child.AdviceName = childAdviceName
  3738. if childMap["advice_desc"] != nil && reflect.TypeOf(childMap["advice_desc"]).String() == "string" {
  3739. childAdviceDesc, _ := childMap["advice_desc"].(string)
  3740. child.AdviceDesc = childAdviceDesc
  3741. }
  3742. if childMap["drug_spec"] != nil && reflect.TypeOf(childMap["drug_spec"]).String() == "string" {
  3743. childDrugSpec, _ := strconv.ParseFloat(childMap["drug_spec"].(string), 64)
  3744. child.DrugSpec = childDrugSpec
  3745. }
  3746. if childMap["drug_spec_unit"] != nil && reflect.TypeOf(childMap["drug_spec_unit"]).String() == "string" {
  3747. childDrugSpecUnit, _ := childMap["drug_spec_unit"].(string)
  3748. child.DrugSpecUnit = childDrugSpecUnit
  3749. }
  3750. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "string" {
  3751. childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3752. child.SingleDose = childSingleDose
  3753. }
  3754. if childMap["single_dose"] != nil && reflect.TypeOf(childMap["single_dose"]).String() == "float64" {
  3755. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3756. child.SingleDose = childMap["single_dose"].(float64)
  3757. }
  3758. if childMap["remark"] != nil && reflect.TypeOf(childMap["remark"]).String() == "string" {
  3759. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3760. child.Remark = childMap["remark"].(string)
  3761. }
  3762. if childMap["drug_id"] != nil && reflect.TypeOf(childMap["drug_id"]).String() == "float64" {
  3763. //childSingleDose, _ := strconv.ParseFloat(childMap["single_dose"].(string), 64)
  3764. child.DrugId = int64(childMap["drug_id"].(float64))
  3765. }
  3766. if childMap["single_dose_unit"] != nil && reflect.TypeOf(childMap["single_dose_unit"]).String() == "string" {
  3767. childSingleDoseUnit, _ := childMap["single_dose_unit"].(string)
  3768. child.SingleDoseUnit = childSingleDoseUnit
  3769. }
  3770. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "string" {
  3771. childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3772. child.PrescribingNumber = childPrescribingNumber
  3773. }
  3774. if childMap["prescribing_number"] != nil && reflect.TypeOf(childMap["prescribing_number"]).String() == "float64" {
  3775. //childPrescribingNumber, _ := strconv.ParseFloat(childMap["prescribing_number"].(string), 64)
  3776. child.PrescribingNumber = childMap["prescribing_number"].(float64)
  3777. }
  3778. if childMap["prescribing_number_unit"] != nil && reflect.TypeOf(childMap["prescribing_number_unit"]).String() == "string" {
  3779. childPrescribingNumberUnit, _ := childMap["prescribing_number_unit"].(string)
  3780. child.PrescribingNumberUnit = childPrescribingNumberUnit
  3781. }
  3782. child.DeliveryWay = advice.DeliveryWay
  3783. child.ExecutionFrequency = advice.ExecutionFrequency
  3784. advice.Children = append(advice.Children, &child)
  3785. }
  3786. }
  3787. }
  3788. advices = append(advices, &advice)
  3789. }
  3790. list, err := service.CreateMGroupAdvice(adminUserInfo.CurrentOrgId, advices, groupNo)
  3791. redis := service.RedisClient()
  3792. formatAdviceDate := theTime.Format("2006-01-02")
  3793. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":advice_list_all"
  3794. redis.Set(key, "", time.Second)
  3795. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient, 10) + ":" + strconv.FormatInt(AdviceDate, 10) + ":doctor_advices"
  3796. redis.Set(keyOne, "", time.Second)
  3797. keyFour := "scheduals_" + formatAdviceDate + "_" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10)
  3798. redis.Set(keyFour, "", time.Second)
  3799. defer redis.Close()
  3800. if err != nil {
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateDoctorAdviceFail)
  3802. return
  3803. }
  3804. c.ServeSuccessJSON(map[string]interface{}{
  3805. "msg": "ok",
  3806. "advices": list,
  3807. })
  3808. return
  3809. }
  3810. func (c *DialysisApiController) GetSolution() {
  3811. patient_id, _ := c.GetInt64("patient_id")
  3812. mode_id, _ := c.GetInt64("mode_id")
  3813. adminUserInfo := c.GetAdminUserInfo()
  3814. solution, err := service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3815. prescription, err := service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, patient_id, mode_id)
  3816. system_prescription, err := service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.CurrentOrgId, mode_id)
  3817. dialysisPrescription, _ := service.MobileGetLastDialysisPrescription(patient_id, adminUserInfo.CurrentOrgId)
  3818. if err != nil {
  3819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3820. return
  3821. }
  3822. c.ServeSuccessJSON(map[string]interface{}{
  3823. "solution": solution,
  3824. "prescription": prescription,
  3825. "system_prescription": system_prescription,
  3826. "dialysisPrescription": dialysisPrescription,
  3827. })
  3828. }
  3829. func (c *DialysisApiController) GetSchedule() {
  3830. schedual_type, _ := c.GetInt64("schedual_type")
  3831. adminUserInfo := c.GetAdminUserInfo()
  3832. //timeLayout := "2006-01-02 15:04:05"
  3833. //
  3834. //date := time.Now().Format("2006-01-02") + " 00:00:00"
  3835. //loc, _ := time.LoadLocation("Local")
  3836. //theStartTime, _ := time.ParseInLocation(timeLayout, date, loc)
  3837. //scheduleTime := theStartTime.Unix()
  3838. scheduleTime, _ := c.GetInt64("record_date")
  3839. deviceNumber, _ := service.GetAllDeviceNumbers(adminUserInfo.CurrentOrgId, scheduleTime, schedual_type)
  3840. c.ServeSuccessJSON(map[string]interface{}{
  3841. "number": deviceNumber,
  3842. })
  3843. }
  3844. func (this *DialysisApiController) GetTodayMonitor() {
  3845. thisTime := time.Now()
  3846. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  3847. timeLayout := "2006-01-02 15:04:05"
  3848. loc, _ := time.LoadLocation("Local")
  3849. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  3850. theAssessmentDateTime := theStartTime.Unix()
  3851. patientID, _ := this.GetInt64("patient_id")
  3852. monitorDate, _ := this.GetInt64("monitoring_date", theAssessmentDateTime)
  3853. adminInfo := this.GetAdminUserInfo()
  3854. record, _ := service.FindLastMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3855. fristrecord, _ := service.FindFirstMonitorRecordToday(patientID, adminInfo.CurrentOrgId, monitorDate)
  3856. template, _ := service.GetOrgInfoTemplate(adminInfo.CurrentOrgId)
  3857. var ultrafiltration_rate float64
  3858. _, prescription := service.FindDialysisPrescriptionByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3859. //针对福建医师汇 获取透前评估预增脱水量
  3860. _, evaluation := service.FindPredialysisEvaluationByReordDate(patientID, theAssessmentDateTime, adminInfo.CurrentOrgId)
  3861. fmt.Println("透前评估数据", evaluation)
  3862. if prescription.ID > 0 {
  3863. if prescription.TargetUltrafiltration > 0 && prescription.DialysisDurationHour > 0 {
  3864. totalMin := prescription.DialysisDurationHour*60 + prescription.DialysisDurationMinute
  3865. if template.TemplateId == 6 { //adminInfo.CurrentOrgId == 9538
  3866. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3867. record.UltrafiltrationRate = ultrafiltration_rate
  3868. }
  3869. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10121 {
  3870. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3871. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3872. record.UltrafiltrationRate = ultrafiltration_rate
  3873. }
  3874. if template.TemplateId == 6 && adminInfo.CurrentOrgId == 10234 {
  3875. dehydration, _ := strconv.ParseFloat(evaluation.Dehydration, 64)
  3876. ultrafiltration_rate = math.Floor((prescription.TargetUltrafiltration + dehydration) / float64(totalMin) * 60 * 1000)
  3877. record.UltrafiltrationRate = ultrafiltration_rate
  3878. }
  3879. if template.TemplateId == 20 || template.TemplateId == 22 || template.TemplateId == 32 || template.TemplateId == 34 { //adminInfo.CurrentOrgId == 9538
  3880. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3881. record.UltrafiltrationRate = ultrafiltration_rate
  3882. }
  3883. if template.TemplateId == 41 { //adminInfo.CurrentOrgId == 9538
  3884. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3885. record.UltrafiltrationRate = ultrafiltration_rate
  3886. }
  3887. if template.TemplateId == 43 { //adminInfo.CurrentOrgId == 9538
  3888. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3889. record.UltrafiltrationRate = ultrafiltration_rate
  3890. }
  3891. if template.TemplateId == 46 || template.TemplateId == 54 { //adminInfo.CurrentOrgId == 9538
  3892. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60)
  3893. record.UltrafiltrationRate = ultrafiltration_rate
  3894. }
  3895. if template.TemplateId == 47 { //adminInfo.CurrentOrgId == 9538
  3896. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration / float64(totalMin) * 60 * 1000)
  3897. record.UltrafiltrationRate = ultrafiltration_rate
  3898. }
  3899. // 只针对方济医院
  3900. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3901. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", prescription.TargetUltrafiltration/float64(totalMin)*60), 6)
  3902. ultrafiltration_rate = value
  3903. record.UltrafiltrationRate = ultrafiltration_rate
  3904. }
  3905. //长沙南雅
  3906. 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 {
  3907. ultrafiltration_rate = math.Floor(prescription.TargetUltrafiltration * 60 / 1000 / float64(totalMin) * 1000)
  3908. record.UltrafiltrationRate = ultrafiltration_rate
  3909. }
  3910. }
  3911. }
  3912. // record.UltrafiltrationRate = ultrafiltration_rate
  3913. record.UltrafiltrationVolume = 0
  3914. if template.TemplateId == 1 && adminInfo.CurrentOrgId != 9849 {
  3915. if ultrafiltration_rate > 0 {
  3916. value, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", float64(record.OperateTime+3600-fristrecord.OperateTime)/3600*ultrafiltration_rate), 6)
  3917. record.UltrafiltrationVolume = value
  3918. }
  3919. }
  3920. 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 {
  3921. if ultrafiltration_rate > 0 && adminInfo.CurrentOrgId != 9538 {
  3922. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3923. record.UltrafiltrationVolume = ultrafiltration_volume
  3924. }
  3925. }
  3926. //长沙南雅
  3927. 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 {
  3928. if ultrafiltration_rate > 0 {
  3929. ultrafiltration_volume := math.Floor(float64(record.OperateTime+3600-fristrecord.OperateTime) / 3600 * ultrafiltration_rate)
  3930. record.UltrafiltrationVolume = ultrafiltration_volume
  3931. }
  3932. }
  3933. if template.TemplateId == 47 || template.TemplateId == 54 {
  3934. record.DisplacementQuantity = record.DisplacementQuantity + record.DisplacementQuantity
  3935. }
  3936. this.ServeSuccessJSON(map[string]interface{}{
  3937. "monitor": record,
  3938. })
  3939. }
  3940. func (c *DialysisApiController) UploadDryWeight() {
  3941. patient_id, _ := c.GetInt64("id")
  3942. dry_weight, _ := c.GetFloat("dry_weight")
  3943. doctor_id, _ := c.GetInt64("doctor_id")
  3944. remark := c.GetString("remark")
  3945. adminUserInfo := c.GetAdminUserInfo()
  3946. weightAdjust, err := service.FindLastDryWeightAdjust(adminUserInfo.CurrentOrgId, patient_id)
  3947. fmt.Println(err)
  3948. if err == gorm.ErrRecordNotFound {
  3949. dryWeight := &models.SgjPatientDryweight{
  3950. PatientId: patient_id,
  3951. DryWeight: dry_weight,
  3952. Remakes: remark,
  3953. Ctime: time.Now().Unix(),
  3954. Mtime: time.Now().Unix(),
  3955. Creator: doctor_id,
  3956. Status: 1,
  3957. UserOrgId: adminUserInfo.CurrentOrgId,
  3958. AdjustedValue: "/",
  3959. UserId: adminUserInfo.AdminUser.Id,
  3960. }
  3961. createErr := service.CreatePatientWeightAdjust(dryWeight)
  3962. loc, _ := time.LoadLocation("Local")
  3963. nowTime := time.Now()
  3964. nowDay := nowTime.Format("2006-01-02")
  3965. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  3966. redis := service.RedisClient()
  3967. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  3968. redis.Set(keyOne, "", time.Second)
  3969. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  3970. redis.Set(key, "", time.Second)
  3971. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  3972. redis.Set(keyTwo, "", time.Second)
  3973. redis.Close()
  3974. if createErr == nil {
  3975. c.ServeSuccessJSON(map[string]interface{}{
  3976. "msg": "提交成功",
  3977. "weight": dryWeight,
  3978. })
  3979. }
  3980. } else {
  3981. dryWeight := &models.SgjPatientDryweight{
  3982. PatientId: patient_id,
  3983. DryWeight: dry_weight,
  3984. Remakes: remark,
  3985. Ctime: time.Now().Unix(),
  3986. Mtime: time.Now().Unix(),
  3987. Creator: doctor_id,
  3988. Status: 1,
  3989. UserOrgId: adminUserInfo.CurrentOrgId,
  3990. AdjustedValue: "/",
  3991. UserId: adminUserInfo.AdminUser.Id,
  3992. }
  3993. var value float64
  3994. value = dry_weight - weightAdjust.DryWeight
  3995. fmt.Println(value)
  3996. if value < 0 {
  3997. dryWeight.AdjustedValue = strconv.FormatFloat(math.Abs(value), 'f', 1, 64) + "(下调)"
  3998. } else if value == 0 {
  3999. dryWeight.AdjustedValue = "/"
  4000. } else if value > 0 {
  4001. dryWeight.AdjustedValue = strconv.FormatFloat(value, 'f', 1, 64) + "(上调)"
  4002. }
  4003. fmt.Println(value)
  4004. createErr := service.CreatePatientWeightAdjust(dryWeight)
  4005. loc, _ := time.LoadLocation("Local")
  4006. nowTime := time.Now()
  4007. nowDay := nowTime.Format("2006-01-02")
  4008. dayTime, _ := time.ParseInLocation("2006-01-02 15:04:05", nowDay+" 00:00:00", loc)
  4009. redis := service.RedisClient()
  4010. keyOne := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_befores_list_all"
  4011. redis.Set(keyOne, "", time.Second)
  4012. key := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(dayTime.Unix(), 10) + ":assessment_before_dislysis"
  4013. redis.Set(key, "", time.Second)
  4014. keyTwo := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":last_dry_weight"
  4015. redis.Set(keyTwo, "", time.Second)
  4016. redis.Close()
  4017. if createErr == nil {
  4018. c.ServeSuccessJSON(map[string]interface{}{
  4019. "msg": "提交成功",
  4020. "weight": dryWeight,
  4021. })
  4022. }
  4023. }
  4024. }
  4025. func (this *DialysisApiController) GetFuncPurview() {
  4026. adminUserInfo := this.GetAdminUserInfo()
  4027. user_id := adminUserInfo.AdminUser.Id
  4028. app_id := adminUserInfo.CurrentAppId
  4029. org_id := adminUserInfo.CurrentOrgId
  4030. create_url := this.GetString("create_url")
  4031. modify_url := this.GetString("modify_url")
  4032. modify_other_url := this.GetString("modify_other_url")
  4033. del_url := this.GetString("del_url")
  4034. del_other_url := this.GetString("del_other_url")
  4035. exce_url := this.GetString("exce_url")
  4036. check_url := this.GetString("check_url")
  4037. modify_exce_url := this.GetString("modify_exce_url")
  4038. module, _ := this.GetInt64("module", 0)
  4039. app_role, _ := service.GetAppRole(org_id, app_id, user_id)
  4040. var is_has_create bool
  4041. var is_has_modify bool
  4042. var is_has_modify_other bool
  4043. var is_has_del bool
  4044. var is_has_del_other bool
  4045. var is_has_exce bool
  4046. var is_has_check bool
  4047. var is_has_modify_exce bool
  4048. org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
  4049. if adminUserInfo.AdminUser.Id != org.Creator {
  4050. if app_role != nil {
  4051. if len(app_role.RoleIds) > 0 {
  4052. roles := strings.Split(app_role.RoleIds, ",")
  4053. var userRolePurviews string
  4054. for _, item := range roles {
  4055. role_id, _ := strconv.ParseInt(item, 10, 64)
  4056. purviews, _ := service.GetRoleFuncPurviewIds(role_id)
  4057. if len(userRolePurviews) == 0 {
  4058. userRolePurviews = purviews
  4059. } else {
  4060. userRolePurviews = userRolePurviews + "," + purviews
  4061. }
  4062. }
  4063. userRolePurviewsArr := RemoveRepeatedPurviewElement2(strings.Split(userRolePurviews, ","))
  4064. funcPurviews, _ := service.FindAllFuncPurview(userRolePurviewsArr)
  4065. for _, item := range funcPurviews {
  4066. //for _, url := range strings.Split(item.Urlfor,","){
  4067. if strings.Split(item.Urlfor, ",")[1] == create_url {
  4068. is_has_create = true
  4069. }
  4070. if strings.Split(item.Urlfor, ",")[1] == modify_url {
  4071. is_has_modify = true
  4072. }
  4073. if strings.Split(item.Urlfor, ",")[1] == modify_other_url {
  4074. is_has_modify_other = true
  4075. }
  4076. if strings.Split(item.Urlfor, ",")[1] == del_url {
  4077. is_has_del = true
  4078. }
  4079. if strings.Split(item.Urlfor, ",")[1] == del_other_url {
  4080. is_has_del_other = true
  4081. }
  4082. if strings.Split(item.Urlfor, ",")[1] == exce_url {
  4083. is_has_exce = true
  4084. }
  4085. if strings.Split(item.Urlfor, ",")[1] == check_url {
  4086. is_has_check = true
  4087. }
  4088. if strings.Split(item.Urlfor, ",")[1] == modify_exce_url {
  4089. is_has_modify_exce = true
  4090. }
  4091. }
  4092. } else {
  4093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRole)
  4094. return
  4095. }
  4096. this.ServeSuccessJSON(map[string]interface{}{
  4097. "is_has_create": is_has_create,
  4098. "is_has_modify": is_has_modify,
  4099. "is_has_modify_other": is_has_modify_other,
  4100. "is_has_del": is_has_del,
  4101. "is_has_del_other": is_has_del_other,
  4102. "is_has_exce": is_has_exce,
  4103. "is_has_check": is_has_check,
  4104. "is_has_modify_exce": is_has_modify_exce,
  4105. "module": module,
  4106. })
  4107. } else {
  4108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserIsExit)
  4109. return
  4110. }
  4111. } else {
  4112. this.ServeSuccessJSON(map[string]interface{}{
  4113. "is_has_create": true,
  4114. "is_has_modify": true,
  4115. "is_has_modify_other": true,
  4116. "is_has_del": true,
  4117. "is_has_del_other": true,
  4118. "is_has_exce": true,
  4119. "is_has_check": true,
  4120. "is_has_modify_exce": true,
  4121. "module": true,
  4122. })
  4123. }
  4124. }
  4125. func (this *DialysisApiController) GetOrderDoctorAdvice() {
  4126. patient_id, _ := this.GetInt64("patient_id", 0)
  4127. advice_date, _ := this.GetInt64("advice_date")
  4128. adminUserInfo := this.GetAdminUserInfo()
  4129. doctorAdvice, _ := service.GetBloodDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4130. hisDoctorAdvice, _ := service.GetHisDoctorAdvice(advice_date, adminUserInfo.CurrentOrgId, patient_id)
  4131. this.ServeSuccessJSON(map[string]interface{}{
  4132. "doctorAdvice": doctorAdvice,
  4133. "hisDoctorAdvice": hisDoctorAdvice,
  4134. })
  4135. }
  4136. func (this *DialysisApiController) GetLastOrNextDoctorAdvice() {
  4137. change_type, _ := this.GetInt64("type", 0)
  4138. record_date := this.GetString("record_time")
  4139. patient_id, _ := this.GetInt64("patient_id", 0)
  4140. timeLayout := "2006-01-02"
  4141. loc, _ := time.LoadLocation("Local")
  4142. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4143. record_time := theAdviceRecordTime.Unix()
  4144. adminUserInfo := this.GetAdminUserInfo()
  4145. advices, sch, err := service.GetDoctorAdviceByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  4146. if err == nil {
  4147. if len(advices) == 0 {
  4148. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4149. return
  4150. } else {
  4151. this.ServeSuccessJSON(map[string]interface{}{
  4152. "advices": advices,
  4153. "schedule": sch,
  4154. })
  4155. return
  4156. }
  4157. } else {
  4158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4159. return
  4160. }
  4161. }
  4162. func (c *DialysisApiController) GetDialysisGoods() {
  4163. schedualDate := c.GetString("schedule_date")
  4164. schedule_type, _ := c.GetInt64("schedule_type")
  4165. partition_id, _ := c.GetInt64("partition_id")
  4166. page, _ := c.GetInt("page")
  4167. limit, _ := c.GetInt("limit")
  4168. keywords := c.GetString("keywords")
  4169. patient_id, _ := c.GetInt64("patient_id")
  4170. good_type, _ := c.GetInt64("good_type")
  4171. date, parseDateErr := utils.ParseTimeStringToTime("2006-01-02", schedualDate)
  4172. if parseDateErr != nil && len(schedualDate) != 0 {
  4173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4174. return
  4175. }
  4176. schedualEndDate := int64(0)
  4177. endDate, parseDateErr := utils.ParseTimeStringToTime("2006-01-02 15:04:05", schedualDate+" 23:59:59")
  4178. if parseDateErr != nil && len(schedualDate) != 0 {
  4179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4180. return
  4181. }
  4182. schedualEndDate = endDate.Unix()
  4183. adminUser := c.GetAdminUserInfo()
  4184. _, err := service.FindStockOutByIsSys(adminUser.CurrentOrgId, 1, date.Unix())
  4185. goodTypes, _ := service.FindAllGoodType(adminUser.CurrentOrgId)
  4186. if err == gorm.ErrRecordNotFound {
  4187. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4188. var ids []int64
  4189. for _, item := range list {
  4190. ids = append(ids, item.PatientId)
  4191. }
  4192. dialysisGoods, _, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4193. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4194. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4195. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4196. item.LastAutomaticReduceDetail = goodUser
  4197. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4198. }
  4199. c.ServeSuccessJSON(map[string]interface{}{
  4200. "dialysis_goods": dialysisGoods,
  4201. "good_type": goodTypes,
  4202. "total": total,
  4203. })
  4204. return
  4205. } else if err == nil {
  4206. //获取当天排班的每个患者的库存使用情况
  4207. list, _ := service.GetDialysisGood(adminUser.CurrentOrgId, date.Unix())
  4208. var ids []int64
  4209. for _, item := range list {
  4210. ids = append(ids, item.PatientId)
  4211. }
  4212. dialysisGoods, err, total := service.PCGetDialysisGoods(adminUser.CurrentOrgId, date.Unix(), schedule_type, partition_id, page, limit, patient_id, keywords, schedualEndDate, good_type, ids)
  4213. for _, item := range dialysisGoods { //获取当天排班的每个患者的最后日期的库存使用情况
  4214. goodUser, _ := service.GetLastDialysisGoods(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4215. lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.CurrentOrgId, date.Unix())
  4216. fmt.Println(goodUser)
  4217. fmt.Println(lastGoodUserDetial)
  4218. item.LastAutomaticReduceDetail = goodUser
  4219. item.LastDialysisBeforePrepare = lastGoodUserDetial
  4220. }
  4221. if err == nil {
  4222. c.ServeSuccessJSON(map[string]interface{}{
  4223. "dialysis_goods": dialysisGoods,
  4224. "good_type": goodTypes,
  4225. "total": total,
  4226. })
  4227. return
  4228. } else {
  4229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4230. return
  4231. }
  4232. } else if err != nil {
  4233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4234. return
  4235. }
  4236. }
  4237. func (c *DialysisApiController) GetDialysisGoodsStatistics() {
  4238. start_time := c.GetString("start_time")
  4239. end_time := c.GetString("end_time")
  4240. timeLayout := "2006-01-02"
  4241. loc, _ := time.LoadLocation("Local")
  4242. var theStartTime int64
  4243. if len(start_time) > 0 {
  4244. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4245. if err != nil {
  4246. utils.ErrorLog(err.Error())
  4247. }
  4248. theStartTime = theTime.Unix()
  4249. }
  4250. var theEndtTime int64
  4251. if len(end_time) > 0 {
  4252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4253. if err != nil {
  4254. utils.ErrorLog(err.Error())
  4255. }
  4256. theEndtTime = theTime.Unix()
  4257. }
  4258. adminUser := c.GetAdminUserInfo()
  4259. outInfo, err := service.MobileGetGoodsStatistics(adminUser.CurrentOrgId, theStartTime, theEndtTime)
  4260. if err == nil {
  4261. c.ServeSuccessJSON(map[string]interface{}{
  4262. "stock_out": outInfo,
  4263. })
  4264. return
  4265. } else {
  4266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4267. return
  4268. }
  4269. }
  4270. func (c *DialysisApiController) GetRoleList() {
  4271. orgId := c.GetAdminUserInfo().CurrentOrgId
  4272. admin_user_id, _ := c.GetInt64("admin_user_id")
  4273. list, err := service.GetRoleList(orgId, admin_user_id)
  4274. if err == nil {
  4275. c.ServeSuccessJSON(map[string]interface{}{
  4276. "adminRole": list,
  4277. })
  4278. return
  4279. } else {
  4280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4281. return
  4282. }
  4283. }
  4284. func (c *DialysisApiController) GetInitPrintData() {
  4285. patient_id, _ := c.GetInt64("patient_id")
  4286. record_date, _ := c.GetInt64("record_date")
  4287. orgId := c.GetAdminUserInfo().CurrentOrgId
  4288. list, err := service.GetInitPrintData(patient_id, record_date, orgId)
  4289. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, record_date, orgId)
  4290. if err == nil {
  4291. c.ServeSuccessJSON(map[string]interface{}{
  4292. "list": list,
  4293. "assessmentAfterDislysis": assessmentAfterDislysis,
  4294. })
  4295. return
  4296. } else {
  4297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4298. return
  4299. }
  4300. }
  4301. func (c *DialysisApiController) GetInitPrintDataOne() {
  4302. patient_id, _ := c.GetInt64("patient_id")
  4303. start_time := c.GetString("record_date")
  4304. timeLayout := "2006-01-02"
  4305. loc, _ := time.LoadLocation("Local")
  4306. var theStartTime int64
  4307. if len(start_time) > 0 {
  4308. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4309. if err != nil {
  4310. utils.ErrorLog(err.Error())
  4311. }
  4312. theStartTime = theTime.Unix()
  4313. }
  4314. orgId := c.GetAdminUserInfo().CurrentOrgId
  4315. list, err := service.GetInitPrintData(patient_id, theStartTime, orgId)
  4316. assessmentAfterDislysis, _ := service.GetLastWeightAfter(patient_id, theStartTime, orgId)
  4317. if err == nil {
  4318. c.ServeSuccessJSON(map[string]interface{}{
  4319. "list": list,
  4320. "assessmentAfterDislysis": assessmentAfterDislysis,
  4321. })
  4322. return
  4323. } else {
  4324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4325. return
  4326. }
  4327. }
  4328. // 新接口
  4329. func (this *DialysisApiController) GetPatientDialysisSolutionGroupList() {
  4330. keyword := this.GetString("keywords")
  4331. limit, _ := this.GetInt64("limit")
  4332. page, _ := this.GetInt64("page")
  4333. partition_id, _ := this.GetInt64("partition_id")
  4334. schedule_type, _ := this.GetInt64("schedule_type")
  4335. start_time := this.GetString("schedule_date")
  4336. advice_ids := this.GetString("ids")
  4337. var ids []string
  4338. if advice_ids != "" {
  4339. ids = strings.Split(advice_ids, ",")
  4340. }
  4341. timeLayout := "2006-01-02"
  4342. loc, _ := time.LoadLocation("Local")
  4343. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4344. orgId := this.GetAdminUserInfo().CurrentOrgId
  4345. _, config := service.FindXTHisRecordByOrgId(orgId)
  4346. goodType, _ := service.GetAllGoodType(orgId)
  4347. if config.IsOpen != 1 {
  4348. list, total, err := service.GetPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4349. fmt.Println("list2232323223332323232", list)
  4350. if err == nil {
  4351. this.ServeSuccessJSON(map[string]interface{}{
  4352. "list": list,
  4353. "total": total,
  4354. "config": config,
  4355. "goodType": goodType,
  4356. })
  4357. return
  4358. } else {
  4359. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4360. return
  4361. }
  4362. }
  4363. if config.IsOpen == 1 {
  4364. list, total, err := service.GetHisPatientDialysisSolutionGroupList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4365. if err == nil {
  4366. this.ServeSuccessJSON(map[string]interface{}{
  4367. "list": list,
  4368. "total": total,
  4369. "config": config,
  4370. "goodType": goodType,
  4371. })
  4372. return
  4373. }
  4374. }
  4375. }
  4376. func (this *DialysisApiController) GetDialysisAdviceTemplateList() {
  4377. keyword := this.GetString("keywords")
  4378. limit, _ := this.GetInt64("limit")
  4379. page, _ := this.GetInt64("page")
  4380. partition_id, _ := this.GetInt64("partition_id")
  4381. schedule_type, _ := this.GetInt64("schedule_type")
  4382. start_time := this.GetString("schedule_date")
  4383. ids := this.GetString("ids")
  4384. var idArray []string
  4385. if ids != "" {
  4386. idArray = strings.Split(ids, ",")
  4387. }
  4388. timeLayout := "2006-01-02"
  4389. loc, _ := time.LoadLocation("Local")
  4390. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4391. orgId := this.GetAdminUserInfo().CurrentOrgId
  4392. list, total, err := service.GetDialysisAdviceTemplateList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4393. tablelist, _, err := service.GetDialysisAdviceSchedulistSix(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, idArray)
  4394. //获取长期医嘱
  4395. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4396. _, config := service.FindXTHisRecordByOrgId(orgId)
  4397. drugList, _ := service.GetAllBaseDrugListTwenty(orgId)
  4398. if err == nil {
  4399. this.ServeSuccessJSON(map[string]interface{}{
  4400. "list": list,
  4401. "total": total,
  4402. "adviceList": adviceList,
  4403. "config": config,
  4404. "drugList": drugList,
  4405. "tablelist": tablelist,
  4406. })
  4407. return
  4408. } else {
  4409. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4410. return
  4411. }
  4412. }
  4413. func (this *DialysisApiController) SaveDialysisSetting() {
  4414. orgId := this.GetAdminUserInfo().CurrentOrgId
  4415. device_number_set, _ := this.GetInt64("device_number_set")
  4416. device_type_set, _ := this.GetInt64("device_type_set")
  4417. name_set, _ := this.GetInt64("name_set")
  4418. admission_number_set, _ := this.GetInt64("admission_number_set")
  4419. dialysis_no_set, _ := this.GetInt64("dialysis_no_set")
  4420. weight_befor_set, _ := this.GetInt64("weight_befor_set")
  4421. dry_weight_set, _ := this.GetInt64("dry_weight_set")
  4422. blood_pressure_set, _ := this.GetInt64("blood_pressure_set")
  4423. ultrafiltration_volume_set, _ := this.GetInt64("ultrafiltration_volume_set")
  4424. internal_fistula_set, _ := this.GetInt64("internal_fistula_set")
  4425. blood_flow_volume_set, _ := this.GetInt64("blood_flow_volume_set")
  4426. anticoagulant_set, _ := this.GetInt64("anticoagulant_set")
  4427. sealing_fluid_dispose_set, _ := this.GetInt64("sealing_fluid_dispose_set")
  4428. mode_id_set, _ := this.GetInt64("mode_id_set")
  4429. dialysis_time_set, _ := this.GetInt64("dialysis_time_set")
  4430. dialysis_dialyszers_set, _ := this.GetInt64("dialysis_dialyszers_set")
  4431. dialysis_irrigation_set, _ := this.GetInt64("dialysis_irrigation_set")
  4432. gaijiliang_set, _ := this.GetInt64("gaijiliang_set")
  4433. kalium_set, _ := this.GetInt64("kalium_set")
  4434. displace_liqui_value_set, _ := this.GetInt64("displace_liqui_value_set")
  4435. bicarbonate_set, _ := this.GetInt64("bicarbonate_set")
  4436. glucose_set, _ := this.GetInt64("glucose_set")
  4437. sodium_set, _ := this.GetInt64("sodium_set")
  4438. calcium_set, _ := this.GetInt64("calcium_set")
  4439. blood_access_set, _ := this.GetInt64("blood_access_set")
  4440. dialyzer_perfusion_apparatus_set, _ := this.GetInt64("dialyzer_perfusion_apparatus_set")
  4441. displace_liqui_part_set, _ := this.GetInt64("displace_liqui_part_set")
  4442. dialysisSetting := models.XtDialysisSetting{
  4443. Sodium: sodium_set,
  4444. Calcium: calcium_set,
  4445. BloodAccess: blood_access_set,
  4446. DialyzerPerfusionApparatus: dialyzer_perfusion_apparatus_set,
  4447. DisplaceLiquiPart: displace_liqui_part_set,
  4448. UserOrgId: orgId,
  4449. Status: 1,
  4450. DeviceNumber: device_number_set,
  4451. DeviceType: device_type_set,
  4452. Name: name_set,
  4453. AdmissionNumber: admission_number_set,
  4454. DialysisNo: dialysis_no_set,
  4455. WeightBefor: weight_befor_set,
  4456. DryWeight: dry_weight_set,
  4457. BloodPressure: blood_pressure_set,
  4458. UltrafiltrationVolume: ultrafiltration_volume_set,
  4459. InternalFistula: internal_fistula_set,
  4460. BloodFlowVolume: blood_flow_volume_set,
  4461. Anticoagulant: anticoagulant_set,
  4462. SealingFluidDispose: sealing_fluid_dispose_set,
  4463. ModeId: mode_id_set,
  4464. DialysisTime: dialysis_time_set,
  4465. DialysisDialyszers: dialysis_dialyszers_set,
  4466. DialysisIrrigation: dialysis_irrigation_set,
  4467. Gaijiliang: gaijiliang_set,
  4468. Kalium: kalium_set,
  4469. DisplaceLiquiValue: displace_liqui_value_set,
  4470. Bicarbonate: bicarbonate_set,
  4471. Glucose: glucose_set,
  4472. Ctime: time.Now().Unix(),
  4473. Mtime: time.Now().Unix(),
  4474. }
  4475. err := service.SaveDialysisSetting(dialysisSetting)
  4476. if err == nil {
  4477. this.ServeSuccessJSON(map[string]interface{}{
  4478. "dialysisSetting": dialysisSetting,
  4479. })
  4480. return
  4481. } else {
  4482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4483. return
  4484. }
  4485. }
  4486. func (this *DialysisApiController) GetDialysisSetting() {
  4487. orgId := this.GetAdminUserInfo().CurrentOrgId
  4488. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4489. this.ServeSuccessJSON(map[string]interface{}{
  4490. "dialysisSett": dialysisSett,
  4491. })
  4492. return
  4493. }
  4494. func (this *DialysisApiController) GetDialysisParameterList() {
  4495. keyword := this.GetString("keywords")
  4496. limit, _ := this.GetInt64("limit")
  4497. page, _ := this.GetInt64("page")
  4498. partition_id, _ := this.GetInt64("partition_id")
  4499. schedule_type, _ := this.GetInt64("schedule_type")
  4500. start_time := this.GetString("schedule_date")
  4501. timeLayout := "2006-01-02"
  4502. loc, _ := time.LoadLocation("Local")
  4503. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4504. orgId := this.GetAdminUserInfo().CurrentOrgId
  4505. scheduids := this.GetString("ids")
  4506. var ids []string
  4507. if scheduids != "" {
  4508. ids = strings.Split(scheduids, ",")
  4509. }
  4510. list, total, err := service.GetDialysisParameterList(keyword, limit, page, partition_id, schedule_type, startTime.Unix(), orgId, ids)
  4511. dialysisSett, _ := service.GetDialysisSetting(orgId)
  4512. if err == nil {
  4513. this.ServeSuccessJSON(map[string]interface{}{
  4514. "list": list,
  4515. "total": total,
  4516. "dialysisSett": dialysisSett,
  4517. })
  4518. return
  4519. } else {
  4520. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4521. return
  4522. }
  4523. }
  4524. func (this *DialysisApiController) GetDialysisGoodTotalCount() {
  4525. orgId := this.GetAdminUserInfo().CurrentOrgId
  4526. schedule_type, _ := this.GetInt64("schedule_type")
  4527. //partion_type, _ := this.GetInt64("partion_type")
  4528. start_time := this.GetString("selected_date")
  4529. partion_type := this.GetString("partion_type")
  4530. var ids []string
  4531. ids = strings.Split(partion_type, ",")
  4532. timeLayout := "2006-01-02"
  4533. loc, _ := time.LoadLocation("Local")
  4534. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4535. list, err := service.GetDialysisGoodTotalCount(orgId, schedule_type, ids, startTime.Unix())
  4536. if err == nil {
  4537. this.ServeSuccessJSON(map[string]interface{}{
  4538. "list": list,
  4539. })
  4540. return
  4541. } else {
  4542. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4543. return
  4544. }
  4545. }
  4546. func (this *DialysisApiController) GetDialysisAdviceSchedulist() {
  4547. orgId := this.GetAdminUserInfo().CurrentOrgId
  4548. schedule_type, _ := this.GetInt64("schedule_type")
  4549. //partion_type, _ := this.GetInt64("partion_type")
  4550. partion_type := this.GetString("partion_type")
  4551. var ids []string
  4552. ids = strings.Split(partion_type, ",")
  4553. start_time := this.GetString("selected_date")
  4554. timeLayout := "2006-01-02"
  4555. loc, _ := time.LoadLocation("Local")
  4556. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4557. list, err := service.GetDialysisAdviceSchedulist(orgId, schedule_type, ids, startTime.Unix())
  4558. tablelist, _ := service.GetDialysisAdviceSchedulistTwo(orgId, schedule_type, ids, startTime.Unix())
  4559. //获取长期医嘱
  4560. adviceList, _ := service.GetAllLongAdviceList(orgId)
  4561. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  4562. _, config := service.FindXTHisRecordByOrgId(orgId)
  4563. if err == nil {
  4564. this.ServeSuccessJSON(map[string]interface{}{
  4565. "list": list,
  4566. "drug": drug,
  4567. "adviceList": adviceList,
  4568. "config": config,
  4569. "tablelist": tablelist,
  4570. })
  4571. return
  4572. } else {
  4573. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4574. return
  4575. }
  4576. }
  4577. func (this *DialysisApiController) GetDialysisParameterGoodList() {
  4578. orgId := this.GetAdminUserInfo().CurrentOrgId
  4579. schedule_type, _ := this.GetInt64("schedule_type")
  4580. partion_type, _ := this.GetInt64("partion_type")
  4581. start_time := this.GetString("selected_date")
  4582. timeLayout := "2006-01-02"
  4583. loc, _ := time.LoadLocation("Local")
  4584. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4585. list, err := service.GetDialysisParameterGoodList(orgId, schedule_type, partion_type, startTime.Unix())
  4586. if err == nil {
  4587. this.ServeSuccessJSON(map[string]interface{}{
  4588. "list": list,
  4589. })
  4590. return
  4591. } else {
  4592. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4593. return
  4594. }
  4595. }
  4596. func (this *DialysisApiController) SaveHisDialysis() {
  4597. var ids []string
  4598. advice_ids := this.GetString("ids")
  4599. ids = strings.Split(advice_ids, ",")
  4600. orgId := this.GetAdminUserInfo().CurrentOrgId
  4601. service.SaveHisDialysis(orgId, ids)
  4602. returnData := make(map[string]interface{}, 0)
  4603. returnData["msg"] = "ok"
  4604. this.ServeSuccessJSON(returnData)
  4605. return
  4606. }
  4607. func (this *DialysisApiController) GetHisDialysisGoodCount() {
  4608. orgId := this.GetAdminUserInfo().CurrentOrgId
  4609. schedule_type, _ := this.GetInt64("schedule_type")
  4610. //partion_type, _ := this.GetInt64("partion_type")
  4611. partion_type := this.GetString("partion_type")
  4612. var ids []string
  4613. ids = strings.Split(partion_type, ",")
  4614. start_time := this.GetString("selected_date")
  4615. timeLayout := "2006-01-02"
  4616. loc, _ := time.LoadLocation("Local")
  4617. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4618. list, _ := service.GetHisDialysisGoodCountTwo(orgId, schedule_type, ids, startTime.Unix())
  4619. this.ServeSuccessJSON(map[string]interface{}{
  4620. "list": list,
  4621. })
  4622. return
  4623. }
  4624. func (this *DialysisApiController) GetPatientSchedule() {
  4625. orgId := this.GetAdminUserInfo().CurrentOrgId
  4626. patient_id, _ := this.GetInt64("patient_id")
  4627. schedule_date, _ := this.GetInt64("schedule_date")
  4628. schedulePatient, _ := service.GetScheduleByPatient(patient_id, schedule_date, orgId)
  4629. this.ServeSuccessJSON(map[string]interface{}{
  4630. "schedulePatient": schedulePatient,
  4631. })
  4632. }
  4633. func (c *DialysisApiController) GetSchedulePrintList() {
  4634. page, _ := c.GetInt64("page", 1)
  4635. limit, _ := c.GetInt64("limit", 10)
  4636. schedulType, _ := c.GetInt64("schedule_type", 0)
  4637. partitionType, _ := c.GetInt64("partition_type", 0)
  4638. keywords := c.GetString("keywords")
  4639. schedule_date := c.GetString("schedule_date")
  4640. timeLayout := "2006-01-02"
  4641. loc, _ := time.LoadLocation("Local")
  4642. var theStartTime int64
  4643. if len(schedule_date) > 0 {
  4644. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", schedule_date+" 00:00:00", loc)
  4645. if err != nil {
  4646. utils.ErrorLog(err.Error())
  4647. }
  4648. theStartTime = theTime.Unix()
  4649. }
  4650. adminUserInfo := c.GetAdminUserInfo()
  4651. list, total, _ := service.GetSchedulePrintList(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4652. for _, item := range list {
  4653. order, _ := service.GetLastOrder(item.UserOrgId, item.PatientId, item.ScheduleDate)
  4654. item.DialysisOrderTwenty = order
  4655. }
  4656. listOne, _ := service.GetSchedulePrintListOne(page, limit, schedulType, partitionType, keywords, theStartTime, adminUserInfo.CurrentOrgId)
  4657. numberList, _ := service.GetAllBedNumberSix(adminUserInfo.CurrentOrgId)
  4658. c.ServeSuccessJSON(map[string]interface{}{
  4659. "list": list,
  4660. "total": total,
  4661. "numberList": numberList,
  4662. "listOne": listOne,
  4663. })
  4664. }
  4665. func (this *DialysisApiController) GetSolutionListByOrgId() {
  4666. orgId := this.GetAdminUserInfo().CurrentOrgId
  4667. list, _ := service.GetSolutionListByOrgId(orgId)
  4668. for _, item := range list {
  4669. //获取该模式最新的1条数据
  4670. solution, _ := service.GetNewPatientSolutionByModeId(item.PatientId, item.ModeId, orgId)
  4671. //更新状态值
  4672. service.UpdateDialysisSolutionStatus(solution.ID, item.ModeId, orgId, item.PatientId)
  4673. }
  4674. this.ServeSuccessJSON(map[string]interface{}{
  4675. "list": list,
  4676. })
  4677. }
  4678. func (this *DialysisApiController) ExcutionDoctorAdvice() {
  4679. orgId := this.GetAdminUserInfo().CurrentOrgId
  4680. is_open, _ := this.GetInt64("is_open")
  4681. idsStr := this.GetString("str")
  4682. recordIDStrs := strings.Split(idsStr, ",")
  4683. start_time := this.GetString("advice_date")
  4684. exec_time, _ := this.GetInt64("exec_time")
  4685. timeLayout := "2006-01-02"
  4686. loc, _ := time.LoadLocation("Local")
  4687. var startTime int64
  4688. if len(start_time) > 0 {
  4689. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4690. if err != nil {
  4691. //fmt.Println(err)
  4692. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4693. return
  4694. }
  4695. startTime = theTime.Unix()
  4696. }
  4697. config, _ := service.GetDrugOpenConfigOne(orgId)
  4698. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  4699. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4700. //his医嘱
  4701. if is_open == 1 {
  4702. groupList, _ := service.GetHisExcutionDoctorAdviceListGroupList(recordIDStrs, startTime, orgId)
  4703. //查找未执行医嘱
  4704. list, _ := service.GetHisExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4705. for _, item := range list {
  4706. if item.Checker == this.GetAdminUserInfo().AdminUser.Id {
  4707. this.ServeSuccessJSON(map[string]interface{}{
  4708. "msg": "3",
  4709. })
  4710. return
  4711. }
  4712. }
  4713. for _, item := range groupList {
  4714. for _, it := range list {
  4715. if item.DrugId == it.DrugId {
  4716. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4717. }
  4718. }
  4719. }
  4720. for _, item := range groupList {
  4721. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4722. var sum_out_count int64
  4723. for _, it := range item.ChildDoctorAdvice {
  4724. var prescribing_number int64
  4725. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4726. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4727. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4728. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4729. }
  4730. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4731. prescribing_number = parseIntPrescribingNumber
  4732. }
  4733. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4734. prescribing_number = parseIntPrescribingNumber
  4735. }
  4736. sum_out_count += prescribing_number
  4737. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4738. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4739. //库存不足
  4740. if sum_out_count > drugStockOut.FlushCount {
  4741. this.ServeSuccessJSON(map[string]interface{}{
  4742. "msg": "2",
  4743. "drug": medical,
  4744. })
  4745. return
  4746. }
  4747. }
  4748. }
  4749. creater := this.GetAdminUserInfo().AdminUser.Id
  4750. //执行出库逻辑
  4751. for _, item := range list {
  4752. hisadvice := &models.HisDoctorAdviceInfo{
  4753. ID: item.ID,
  4754. UserOrgId: item.UserOrgId,
  4755. PatientId: item.PatientId,
  4756. AdviceType: item.AdviceType,
  4757. AdviceDate: item.AdviceDate,
  4758. StartTime: item.StartTime,
  4759. AdviceName: item.AdviceName,
  4760. AdviceDesc: item.AdviceDesc,
  4761. ReminderDate: item.ReminderDate,
  4762. SingleDose: item.SingleDose,
  4763. SingleDoseUnit: item.SingleDoseUnit,
  4764. DrugSpec: item.DrugSpec,
  4765. DrugSpecUnit: item.DrugSpecUnit,
  4766. PrescribingNumber: item.PrescribingNumber,
  4767. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4768. DeliveryWay: item.DeliveryWay,
  4769. ExecutionFrequency: item.ExecutionFrequency,
  4770. AdviceDoctor: item.AdviceDoctor,
  4771. Status: 1,
  4772. CreatedTime: item.CreatedTime,
  4773. UpdatedTime: item.UpdatedTime,
  4774. AdviceAffirm: item.AdviceAffirm,
  4775. Remark: item.Remark,
  4776. StopTime: item.StopTime,
  4777. StopReason: item.StopReason,
  4778. StopDoctor: item.StopDoctor,
  4779. StopState: item.StopState,
  4780. ParentId: item.ParentId,
  4781. ExecutionTime: item.ExecutionTime,
  4782. ExecutionStaff: creater,
  4783. ExecutionState: item.ExecutionState,
  4784. Checker: item.Checker,
  4785. RecordDate: item.RecordDate,
  4786. DialysisOrderId: item.DialysisOrderId,
  4787. CheckTime: item.CheckTime,
  4788. CheckState: item.CheckState,
  4789. RemindType: item.RemindType,
  4790. FrequencyType: item.FrequencyType,
  4791. DayCount: item.DayCount,
  4792. WeekDay: item.WeekDay,
  4793. TemplateId: item.TemplateId,
  4794. Modifier: item.Modifier,
  4795. Way: item.Way,
  4796. DrugId: item.DrugId,
  4797. ExecutionFrequencyId: item.ExecutionFrequencyId,
  4798. }
  4799. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4800. if medical.IsUse == 2 {
  4801. if config.IsOpen != 1 {
  4802. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4803. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4804. }
  4805. //不通过药房发药
  4806. if pharmacyConfig.IsOpen != 1 {
  4807. service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, hisadvice)
  4808. }
  4809. //查询默认仓库
  4810. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4811. //查询默认仓库剩余多少库存
  4812. var sum_count int64
  4813. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4814. for _, its := range stockInfo {
  4815. if its.MaxUnit == medical.MaxUnit {
  4816. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  4817. }
  4818. sum_count += its.StockMaxNumber + its.StockMinNumber
  4819. }
  4820. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4821. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4822. }
  4823. }
  4824. info := models.HisDoctorAdviceInfo{
  4825. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4826. ExecutionTime: exec_time,
  4827. ExecutionState: 1,
  4828. UpdatedTime: time.Now().Unix(),
  4829. }
  4830. //执行医嘱
  4831. service.UpdateHisDoctorAdviceExecution(info, item.ID)
  4832. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  4833. redis := service.RedisClient()
  4834. //清空key 值
  4835. redis.Set(key, "", time.Second)
  4836. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  4837. redis.Set(keyTwo, "", time.Second)
  4838. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4839. redis.Set(keyThree, "", time.Second)
  4840. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  4841. theTime := toTime.Format("2006-01-02")
  4842. fmt.Println("theTIME", theTime)
  4843. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  4844. redis.Set(keyFour, "", time.Second)
  4845. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4846. redis.Set(keyFive, "", time.Second)
  4847. }
  4848. } else {
  4849. groupList, _ := service.GetExcutionDoctorAdviceGroupList(recordIDStrs, startTime, orgId)
  4850. //查找未执行医嘱
  4851. list, _ := service.GetExcutionDoctorAdviceList(recordIDStrs, startTime, orgId)
  4852. for _, item := range groupList {
  4853. for _, it := range list {
  4854. if item.DrugId == it.DrugId {
  4855. item.ChildDoctorAdvice = append(item.ChildDoctorAdvice, it)
  4856. }
  4857. }
  4858. }
  4859. for _, item := range groupList {
  4860. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4861. var sum_out_count int64
  4862. for _, it := range item.ChildDoctorAdvice {
  4863. var prescribing_number int64
  4864. stringPrescribingNumber := strconv.FormatFloat(it.PrescribingNumber, 'f', -1, 64)
  4865. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  4866. if it.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  4867. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  4868. }
  4869. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  4870. prescribing_number = parseIntPrescribingNumber
  4871. }
  4872. if it.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  4873. prescribing_number = parseIntPrescribingNumber
  4874. }
  4875. sum_out_count += prescribing_number
  4876. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  4877. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(it.DrugId, orgId, houseConfig.DrugStorehouseOut)
  4878. //库存不足
  4879. if sum_out_count > drugStockOut.FlushCount {
  4880. this.ServeSuccessJSON(map[string]interface{}{
  4881. "msg": "2",
  4882. "drug": medical,
  4883. })
  4884. return
  4885. }
  4886. }
  4887. }
  4888. for _, item := range list {
  4889. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  4890. dadvice := &models.DoctorAdvice{
  4891. ID: item.ID,
  4892. UserOrgId: item.UserOrgId,
  4893. PatientId: item.PatientId,
  4894. AdviceType: item.AdviceType,
  4895. AdviceDate: item.AdviceDate,
  4896. StartTime: item.StartTime,
  4897. AdviceName: item.AdviceName,
  4898. AdviceDesc: item.AdviceDesc,
  4899. ReminderDate: item.ReminderDate,
  4900. SingleDose: item.SingleDose,
  4901. SingleDoseUnit: item.SingleDoseUnit,
  4902. DrugSpec: item.DrugSpec,
  4903. DrugSpecUnit: item.DrugSpecUnit,
  4904. PrescribingNumber: item.PrescribingNumber,
  4905. PrescribingNumberUnit: item.PrescribingNumberUnit,
  4906. DeliveryWay: item.DeliveryWay,
  4907. ExecutionFrequency: item.ExecutionFrequency,
  4908. AdviceDoctor: item.AdviceDoctor,
  4909. Status: 1,
  4910. CreatedTime: item.CreatedTime,
  4911. UpdatedTime: item.UpdatedTime,
  4912. AdviceAffirm: item.AdviceAffirm,
  4913. Remark: item.Remark,
  4914. StopTime: item.StopTime,
  4915. StopReason: item.StopReason,
  4916. StopDoctor: item.StopDoctor,
  4917. StopState: item.StopState,
  4918. ParentId: item.ParentId,
  4919. ExecutionTime: item.ExecutionTime,
  4920. ExecutionStaff: item.ExecutionStaff,
  4921. ExecutionState: item.ExecutionState,
  4922. Checker: item.Checker,
  4923. RecordDate: item.ReminderDate,
  4924. DialysisOrderId: item.DialysisOrderId,
  4925. CheckTime: item.CheckTime,
  4926. CheckState: item.CheckState,
  4927. RemindType: item.RemindType,
  4928. FrequencyType: item.FrequencyType,
  4929. DayCount: item.DayCount,
  4930. WeekDay: item.WeekDay,
  4931. TemplateId: item.TemplateId,
  4932. Modifier: item.Modifier,
  4933. Way: item.Way,
  4934. DrugId: item.DrugId,
  4935. }
  4936. if medical.IsUse == 2 {
  4937. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  4938. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4939. }
  4940. if pharmacyConfig.IsOpen != 1 {
  4941. service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, dadvice)
  4942. }
  4943. //更新字典里面的库存
  4944. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4945. var sum_count int64
  4946. for _, its := range stockInfo {
  4947. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4948. if its.MaxUnit == baseDrug.MaxUnit {
  4949. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4950. }
  4951. sum_count += its.StockMaxNumber + its.StockMinNumber
  4952. }
  4953. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4954. //剩余库存
  4955. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  4956. }
  4957. info := models.DoctorAdvice{
  4958. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  4959. ExecutionTime: exec_time,
  4960. ExecutionState: 1,
  4961. UpdatedTime: time.Now().Unix(),
  4962. }
  4963. //执行医嘱
  4964. service.UpdateDoctorAdviceExecution(info, item.ID)
  4965. }
  4966. }
  4967. this.ServeSuccessJSON(map[string]interface{}{
  4968. "msg": "1",
  4969. })
  4970. return
  4971. }
  4972. func (this *DialysisApiController) CheckNewDoctorAdvice() {
  4973. orgId := this.GetAdminUserInfo().CurrentOrgId
  4974. idsStr := this.GetString("str")
  4975. recordIDStrs := strings.Split(idsStr, ",")
  4976. start_time := this.GetString("advice_date")
  4977. timeLayout := "2006-01-02"
  4978. loc, _ := time.LoadLocation("Local")
  4979. var startTime int64
  4980. if len(start_time) > 0 {
  4981. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4982. if err != nil {
  4983. //fmt.Println(err)
  4984. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4985. return
  4986. }
  4987. startTime = theTime.Unix()
  4988. }
  4989. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  4990. if config.IsOpen == 1 {
  4991. creater := this.GetAdminUserInfo().AdminUser.Id
  4992. //查询未核对的医嘱
  4993. advicelist, _ := service.GetHisCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  4994. for _, item := range advicelist {
  4995. if item.ExecutionStaff == creater {
  4996. this.ServeSuccessJSON(map[string]interface{}{
  4997. "msg": "2",
  4998. "advice": item,
  4999. })
  5000. return
  5001. }
  5002. service.CheckHisDoctorAdvice(item.ID, creater)
  5003. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5004. redis := service.RedisClient()
  5005. //清空key 值
  5006. redis.Set(key, "", time.Second)
  5007. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5008. redis.Set(keyTwo, "", time.Second)
  5009. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5010. redis.Set(keyThree, "", time.Second)
  5011. theTime := time.Now()
  5012. recordDate := theTime.Format("2006-01-02")
  5013. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5014. redis.Set(keyFour, "", time.Second)
  5015. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5016. redis.Set(keyFive, "", time.Second)
  5017. }
  5018. } else {
  5019. //查询未核对的医嘱
  5020. advicelist, _ := service.GetCheckDoctorAdvice(orgId, recordIDStrs, startTime)
  5021. creater := this.GetAdminUserInfo().AdminUser.Id
  5022. for _, item := range advicelist {
  5023. if item.ExecutionStaff == creater {
  5024. this.ServeSuccessJSON(map[string]interface{}{
  5025. "msg": "2",
  5026. "advice": item,
  5027. })
  5028. return
  5029. }
  5030. service.CheckDoctorAdvice(item.ID, creater)
  5031. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":doctor_advices"
  5032. redis := service.RedisClient()
  5033. //清空key 值
  5034. redis.Set(key, "", time.Second)
  5035. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":advice_list_all"
  5036. redis.Set(keyTwo, "", time.Second)
  5037. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5038. redis.Set(keyThree, "", time.Second)
  5039. theTime := time.Now()
  5040. recordDate := theTime.Format("2006-01-02")
  5041. keyFour := "scheduals_" + recordDate + "_" + strconv.FormatInt(orgId, 10)
  5042. redis.Set(keyFour, "", time.Second)
  5043. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5044. redis.Set(keyFive, "", time.Second)
  5045. }
  5046. }
  5047. this.ServeSuccessJSON(map[string]interface{}{
  5048. "msg": "1",
  5049. })
  5050. return
  5051. }
  5052. func (this *DialysisApiController) SettleNewDoctorAdvice() {
  5053. orgId := this.GetAdminUserInfo().CurrentOrgId
  5054. is_open, _ := this.GetInt64("is_open")
  5055. idsStr := this.GetString("str")
  5056. recordIDStrs := strings.Split(idsStr, ",")
  5057. start_time := this.GetString("advice_date")
  5058. timeLayout := "2006-01-02"
  5059. loc, _ := time.LoadLocation("Local")
  5060. var startTime int64
  5061. if len(start_time) > 0 {
  5062. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5063. if err != nil {
  5064. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5065. return
  5066. }
  5067. startTime = theTime.Unix()
  5068. }
  5069. if is_open == 1 {
  5070. service.SettleHisNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5071. } else {
  5072. service.SettleNewDoctorAdvice(recordIDStrs, startTime, orgId)
  5073. }
  5074. this.ServeSuccessJSON(map[string]interface{}{
  5075. "msg": "1",
  5076. })
  5077. return
  5078. }
  5079. func (this *DialysisApiController) ExcutionDoctorAdviceById() {
  5080. advice_id, _ := this.GetInt64("advice_id")
  5081. start_time := this.GetString("advice_date")
  5082. orgId := this.GetAdminUserInfo().CurrentOrgId
  5083. config, _ := service.FindXTHisRecordByOrgIdSix(orgId)
  5084. exec_time, _ := this.GetInt64("exec_time")
  5085. //his医嘱
  5086. if config.IsOpen == 1 {
  5087. //查询医嘱
  5088. advice, _ := service.GetHisDocById(advice_id, orgId)
  5089. if advice.Checker == this.GetAdminUserInfo().AdminUser.Id {
  5090. this.ServeSuccessJSON(map[string]interface{}{
  5091. "msg": "3",
  5092. })
  5093. return
  5094. }
  5095. medical, _ := service.GetBaseDrugMedical(orgId)
  5096. var prescribing_number int64
  5097. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5098. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5099. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5100. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5101. }
  5102. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5103. prescribing_number = parseIntPrescribingNumber
  5104. }
  5105. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5106. prescribing_number = parseIntPrescribingNumber
  5107. }
  5108. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5109. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5110. //库存不足
  5111. if prescribing_number > drugStockOut.FlushCount {
  5112. this.ServeSuccessJSON(map[string]interface{}{
  5113. "msg": "2",
  5114. "drug": medical,
  5115. })
  5116. return
  5117. }
  5118. info := models.HisDoctorAdviceInfo{
  5119. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5120. ExecutionTime: exec_time,
  5121. ExecutionState: 1,
  5122. UpdatedTime: time.Now().Unix(),
  5123. }
  5124. //执行医嘱
  5125. service.UpdateHisDoctorAdviceExecution(info, advice.ID)
  5126. key := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":doctor_advices"
  5127. redis := service.RedisClient()
  5128. //清空key 值
  5129. redis.Set(key, "", time.Second)
  5130. keyTwo := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":advice_list_all"
  5131. redis.Set(keyTwo, "", time.Second)
  5132. keyThree := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5133. redis.Set(keyThree, "", time.Second)
  5134. toTime, _ := utils.ParseTimeStringToTime("2006-01-02 15:04:05", start_time)
  5135. theTime := toTime.Format("2006-01-02")
  5136. fmt.Println("theTIME", theTime)
  5137. keyFour := "scheduals_" + theTime + "_" + strconv.FormatInt(orgId, 10)
  5138. redis.Set(keyFour, "", time.Second)
  5139. keyFive := strconv.FormatInt(orgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5140. redis.Set(keyFive, "", time.Second)
  5141. //出库
  5142. if prescribing_number <= drugStockOut.FlushCount {
  5143. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5144. //执行出库逻辑
  5145. hisadvice := &models.HisDoctorAdviceInfo{
  5146. ID: advice.ID,
  5147. UserOrgId: advice.UserOrgId,
  5148. PatientId: advice.PatientId,
  5149. AdviceType: advice.AdviceType,
  5150. AdviceDate: advice.AdviceDate,
  5151. StartTime: advice.StartTime,
  5152. AdviceName: advice.AdviceName,
  5153. AdviceDesc: advice.AdviceDesc,
  5154. ReminderDate: advice.ReminderDate,
  5155. SingleDose: advice.SingleDose,
  5156. SingleDoseUnit: advice.SingleDoseUnit,
  5157. DrugSpec: advice.DrugSpec,
  5158. DrugSpecUnit: advice.DrugSpecUnit,
  5159. PrescribingNumber: advice.PrescribingNumber,
  5160. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5161. DeliveryWay: advice.DeliveryWay,
  5162. ExecutionFrequency: advice.ExecutionFrequency,
  5163. AdviceDoctor: advice.AdviceDoctor,
  5164. Status: 1,
  5165. CreatedTime: advice.CreatedTime,
  5166. UpdatedTime: advice.UpdatedTime,
  5167. AdviceAffirm: advice.AdviceAffirm,
  5168. Remark: advice.Remark,
  5169. StopTime: advice.StopTime,
  5170. StopReason: advice.StopReason,
  5171. StopDoctor: advice.StopDoctor,
  5172. StopState: advice.StopState,
  5173. ParentId: advice.ParentId,
  5174. ExecutionTime: advice.ExecutionTime,
  5175. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5176. ExecutionState: advice.ExecutionState,
  5177. Checker: advice.Checker,
  5178. RecordDate: advice.RecordDate,
  5179. DialysisOrderId: advice.DialysisOrderId,
  5180. CheckTime: advice.CheckTime,
  5181. CheckState: advice.CheckState,
  5182. RemindType: advice.RemindType,
  5183. FrequencyType: advice.FrequencyType,
  5184. DayCount: advice.DayCount,
  5185. WeekDay: advice.WeekDay,
  5186. TemplateId: advice.TemplateId,
  5187. Modifier: advice.Modifier,
  5188. Way: advice.Way,
  5189. DrugId: advice.DrugId,
  5190. ExecutionFrequencyId: advice.ExecutionFrequencyId,
  5191. }
  5192. if medical.IsUse == 2 {
  5193. if config.IsOpen != 1 {
  5194. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5195. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5196. }
  5197. //不通过药房发药
  5198. if pharmacyConfig.IsOpen != 1 {
  5199. service.HisDrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, hisadvice)
  5200. }
  5201. //查询默认仓库
  5202. storeHouseConfig, _ := service.GetAllStoreHouseConfig(advice.UserOrgId)
  5203. //查询默认仓库剩余多少库存
  5204. var sum_count int64
  5205. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5206. for _, its := range stockInfo {
  5207. if its.MaxUnit == medical.MaxUnit {
  5208. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5209. }
  5210. sum_count += its.StockMaxNumber + its.StockMinNumber
  5211. }
  5212. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5213. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5214. }
  5215. }
  5216. }
  5217. this.ServeSuccessJSON(map[string]interface{}{
  5218. "msg": "1",
  5219. })
  5220. return
  5221. }
  5222. if config.IsOpen == 2 || config.IsOpen == 0 {
  5223. advice, _ := service.GetBloodDocById(advice_id, orgId)
  5224. medical, _ := service.GetBaseDrugMedical(orgId)
  5225. pharmacyConfig, _ := service.FindPharmacyConfig(orgId)
  5226. storeHouseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5227. var prescribing_number int64
  5228. stringPrescribingNumber := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5229. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5230. if advice.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5231. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5232. }
  5233. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5234. prescribing_number = parseIntPrescribingNumber
  5235. }
  5236. if advice.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5237. prescribing_number = parseIntPrescribingNumber
  5238. }
  5239. houseConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5240. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(advice.DrugId, orgId, houseConfig.DrugStorehouseOut)
  5241. //库存不足
  5242. if prescribing_number > drugStockOut.FlushCount {
  5243. this.ServeSuccessJSON(map[string]interface{}{
  5244. "msg": "2",
  5245. "drug": medical,
  5246. })
  5247. return
  5248. }
  5249. info := models.DoctorAdvice{
  5250. ExecutionStaff: this.GetAdminUserInfo().AdminUser.Id,
  5251. ExecutionTime: exec_time,
  5252. ExecutionState: 1,
  5253. UpdatedTime: time.Now().Unix(),
  5254. }
  5255. //执行医嘱
  5256. service.UpdateDoctorAdviceExecution(info, advice.ID)
  5257. dadvice := &models.DoctorAdvice{
  5258. ID: advice.ID,
  5259. UserOrgId: advice.UserOrgId,
  5260. PatientId: advice.PatientId,
  5261. AdviceType: advice.AdviceType,
  5262. AdviceDate: advice.AdviceDate,
  5263. StartTime: advice.StartTime,
  5264. AdviceName: advice.AdviceName,
  5265. AdviceDesc: advice.AdviceDesc,
  5266. ReminderDate: advice.ReminderDate,
  5267. SingleDose: advice.SingleDose,
  5268. SingleDoseUnit: advice.SingleDoseUnit,
  5269. DrugSpec: advice.DrugSpec,
  5270. DrugSpecUnit: advice.DrugSpecUnit,
  5271. PrescribingNumber: advice.PrescribingNumber,
  5272. PrescribingNumberUnit: advice.PrescribingNumberUnit,
  5273. DeliveryWay: advice.DeliveryWay,
  5274. ExecutionFrequency: advice.ExecutionFrequency,
  5275. AdviceDoctor: advice.AdviceDoctor,
  5276. Status: 1,
  5277. CreatedTime: advice.CreatedTime,
  5278. UpdatedTime: advice.UpdatedTime,
  5279. AdviceAffirm: advice.AdviceAffirm,
  5280. Remark: advice.Remark,
  5281. StopTime: advice.StopTime,
  5282. StopReason: advice.StopReason,
  5283. StopDoctor: advice.StopDoctor,
  5284. StopState: advice.StopState,
  5285. ParentId: advice.ParentId,
  5286. ExecutionTime: advice.ExecutionTime,
  5287. ExecutionStaff: advice.ExecutionStaff,
  5288. ExecutionState: advice.ExecutionState,
  5289. Checker: advice.Checker,
  5290. RecordDate: advice.ReminderDate,
  5291. DialysisOrderId: advice.DialysisOrderId,
  5292. CheckTime: advice.CheckTime,
  5293. CheckState: advice.CheckState,
  5294. RemindType: advice.RemindType,
  5295. FrequencyType: advice.FrequencyType,
  5296. DayCount: advice.DayCount,
  5297. WeekDay: advice.WeekDay,
  5298. TemplateId: advice.TemplateId,
  5299. Modifier: advice.Modifier,
  5300. Way: advice.Way,
  5301. DrugId: advice.DrugId,
  5302. }
  5303. if medical.IsUse == 2 {
  5304. if pharmacyConfig.IsOpen == 1 && medical.IsPharmacy == 0 {
  5305. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5306. }
  5307. if pharmacyConfig.IsOpen != 1 {
  5308. service.DrugsDelivery(advice.UserOrgId, advice.ExecutionStaff, dadvice)
  5309. }
  5310. //更新字典里面的库存
  5311. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, advice.UserOrgId, advice.DrugId)
  5312. var sum_count int64
  5313. for _, its := range stockInfo {
  5314. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  5315. if its.MaxUnit == baseDrug.MaxUnit {
  5316. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  5317. }
  5318. sum_count += its.StockMaxNumber + its.StockMinNumber
  5319. }
  5320. service.UpdateBaseDrugSumTwo(advice.DrugId, sum_count, advice.UserOrgId)
  5321. //剩余库存
  5322. service.UpdateDrugStockCount(advice.DrugId, advice.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5323. }
  5324. }
  5325. this.ServeSuccessJSON(map[string]interface{}{
  5326. "msg": "1",
  5327. })
  5328. return
  5329. }
  5330. func (this *DialysisApiController) GetDialysisAdviceToday() {
  5331. orgId := this.GetAdminUserInfo().CurrentOrgId
  5332. schedule_type, _ := this.GetInt64("schedule_type")
  5333. //partion_type, _ := this.GetInt64("partion_type")
  5334. partion_type := this.GetString("partion_type")
  5335. var ids []string
  5336. ids = strings.Split(partion_type, ",")
  5337. start_time := this.GetString("selected_date")
  5338. timeLayout := "2006-01-02"
  5339. loc, _ := time.LoadLocation("Local")
  5340. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5341. list, err := service.GetDialysisAdviceSchedulistTen(orgId, schedule_type, ids, startTime.Unix())
  5342. drug, _ := service.GetAllBaseDrugListTwenty(orgId)
  5343. _, config := service.FindXTHisRecordByOrgId(orgId)
  5344. appId := this.GetAdminUserInfo().CurrentAppId
  5345. doctorList, _ := service.GetAllAdminUsers(orgId, appId)
  5346. if err == nil {
  5347. this.ServeSuccessJSON(map[string]interface{}{
  5348. "list": list,
  5349. "drug": drug,
  5350. "config": config,
  5351. "doctorList": doctorList,
  5352. })
  5353. return
  5354. } else {
  5355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5356. return
  5357. }
  5358. }
  5359. func (this *DialysisApiController) GetMobileScheduleList() {
  5360. orgId := this.GetAdminUserInfo().CurrentOrgId
  5361. schedule, _ := service.GetMobileScheduleList(orgId)
  5362. if len(schedule) > 0 {
  5363. for _, its := range schedule {
  5364. //prescription, _ := service.GetPrescriptionList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5365. //its.DialysisPrescription = prescription
  5366. //monitor, _ := service.GetLastMonitorRecordList(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5367. //its.MonitoringRecord = monitor
  5368. //after, _ := service.GetLastAfter(its.PatientId, its.ScheduleDate, its.UserOrgId)
  5369. //its.XtAssessmentAfterDislysis = after
  5370. order, _ := service.GetLastOrder(its.UserOrgId, its.PatientId, its.ScheduleDate)
  5371. service.UpdateDoctorSix(order.StartTime, order.PatientId, order.DialysisDate, order.UserOrgId)
  5372. }
  5373. }
  5374. this.ServeSuccessJSON(map[string]interface{}{
  5375. "schedule": schedule,
  5376. })
  5377. return
  5378. }