dialysis_api_controller.go 166KB

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