dialysis_api_controller.go 170KB

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