dialysis_api_controller.go 219KB

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