dialysis_api_controller.go 207KB

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