dialysis_api_controller.go 148KB

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