dialysis_api_controller.go 204KB

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