dialysis_api_controller.go 210KB

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