dialysis_api_controller.go 209KB

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