dialysis_api_controller.go 218KB

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