check_weight_api_controller.go 40KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. package mobile_api_controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. _ "XT_New/utils"
  7. _ "encoding/json"
  8. "fmt"
  9. _ "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. _ "strings"
  12. // "fmt"
  13. _ "reflect"
  14. _ "strconv"
  15. "time"
  16. )
  17. type CheckWeightApiController struct {
  18. MobileBaseAPIAuthController
  19. }
  20. func (c *CheckWeightApiController) SaveBloodPressure() {
  21. id, _ := c.GetInt64("patient", 0)
  22. dialysistype, _ := c.GetInt64("dialysistype", 0)
  23. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0) //收缩压
  24. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0) //舒张压
  25. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0) //脉率
  26. if id <= 0 {
  27. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  28. return
  29. }
  30. if dialysistype <= 0 {
  31. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  32. return
  33. }
  34. if systolic_blood_pressure <= 0 {
  35. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  36. return
  37. }
  38. if diastolic_blood_pressure <= 0 {
  39. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  40. return
  41. }
  42. adminUserInfo := c.GetMobileAdminUserInfo()
  43. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  44. if patient.ID == 0 {
  45. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  46. return
  47. }
  48. thisTime := time.Now()
  49. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  50. timeLayout := "2006-01-02 15:04:05"
  51. loc, _ := time.LoadLocation("Local")
  52. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  53. theAssessmentDateTime := theStartTime.Unix()
  54. if dialysistype == 1 {
  55. // 保存透前相关数据
  56. // 获取透析处方
  57. dialysisPrescribe, getDialysisPrescribeErr := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  58. if getDialysisPrescribeErr != nil {
  59. c.ErrorLog("获取透析处方失败:%v", getDialysisPrescribeErr)
  60. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  61. return
  62. }
  63. // 获取透析模版
  64. dialysisSolution, getDialysisSolutionErr := service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  65. if getDialysisSolutionErr != nil {
  66. c.ErrorLog("获取透析方案失败:%v", getDialysisSolutionErr)
  67. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  68. return
  69. }
  70. // 插入透析处方
  71. if dialysisPrescribe == nil && dialysisSolution != nil {
  72. var newprescribe models.DialysisPrescription
  73. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  74. newprescribe.PatientId = dialysisSolution.PatientId
  75. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  76. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  77. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  78. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  79. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  80. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  81. newprescribe.ModeId = dialysisSolution.ModeId
  82. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  83. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  84. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  85. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  86. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  87. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  88. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  89. newprescribe.Glucose = dialysisSolution.Glucose
  90. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  91. newprescribe.Kalium = dialysisSolution.Kalium
  92. newprescribe.Sodium = dialysisSolution.Sodium
  93. newprescribe.Calcium = dialysisSolution.Calcium
  94. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  95. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  96. newprescribe.Conductivity = dialysisSolution.Conductivity
  97. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  98. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  99. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  100. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  101. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  102. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  103. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  104. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  105. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  106. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  107. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  108. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  109. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  110. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  111. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  112. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  113. newprescribe.CreatedTime = time.Now().Unix()
  114. newprescribe.UpdatedTime = time.Now().Unix()
  115. newprescribe.RecordDate = theAssessmentDateTime
  116. // newprescribe.DewaterAmount = dewater_amount
  117. // newprescribe.TargetUltrafiltration = dewater_amount
  118. newprescribe.Status = 1
  119. err := service.AddSigleRecord(&newprescribe)
  120. if err != nil {
  121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  122. }
  123. }
  124. if dialysisPrescribe == nil && dialysisSolution == nil {
  125. var newprescribe models.DialysisPrescription
  126. newprescribe.UserOrgId = adminUserInfo.Org.Id
  127. newprescribe.PatientId = id
  128. newprescribe.CreatedTime = time.Now().Unix()
  129. newprescribe.UpdatedTime = time.Now().Unix()
  130. newprescribe.RecordDate = theAssessmentDateTime
  131. // newprescribe.DewaterAmount = dewater_amount
  132. // newprescribe.TargetUltrafiltration = dewater_amount
  133. newprescribe.Status = 1
  134. err := service.AddSigleRecord(&newprescribe)
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  137. }
  138. }
  139. if dialysisPrescribe != nil {
  140. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  141. dialysisPrescribe.RecordDate = theAssessmentDateTime
  142. // dialysisPrescribe.DewaterAmount = dewater_amount
  143. // dialysisPrescribe.TargetUltrafiltration = dewater_amount
  144. dialysisPrescribe.Status = 1
  145. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  146. if updateErr != nil {
  147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  148. }
  149. }
  150. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  151. if getPEErr != nil {
  152. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  154. return
  155. }
  156. var evaluation models.PredialysisEvaluation
  157. if theEvaluation != nil {
  158. evaluation = *theEvaluation
  159. }
  160. // 如果今天没有透前评估,则插入新的数据
  161. if theEvaluation == nil {
  162. evaluation.CreatedTime = time.Now().Unix()
  163. evaluation.Status = 1
  164. evaluation.AssessmentDate = theAssessmentDateTime
  165. evaluation.PatientId = id
  166. evaluation.UserOrgId = adminUserInfo.Org.Id
  167. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  168. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  169. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  170. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  171. if getAADErr != nil {
  172. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  174. return
  175. }
  176. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  177. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  178. if err == gorm.ErrRecordNotFound {
  179. if lastPredialysisEvaluation != nil {
  180. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  181. } else {
  182. evaluation.DryWeight = 0
  183. }
  184. } else {
  185. evaluation.DryWeight = weight.DryWeight
  186. }
  187. if assessmentAfterDislysis != nil {
  188. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  189. }
  190. if lastPredialysisEvaluation != nil {
  191. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  192. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  193. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight // 衣物重
  194. }
  195. } else {
  196. evaluation.UpdatedTime = time.Now().Unix()
  197. }
  198. evaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  199. evaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  200. evaluation.PulseFrequency = pulse_frequency // 脉率
  201. evaluation.AssessmentTime = time.Now().Unix()
  202. err := service.UpadatePredialysisEvaluation(&evaluation)
  203. if err != nil {
  204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  205. return
  206. }
  207. c.ServeSuccessJSON(map[string]interface{}{
  208. "msg": "ok",
  209. "evaluation": evaluation,
  210. })
  211. return
  212. } else {
  213. // 保存透后相关数据
  214. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  215. if getAADErr != nil {
  216. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  217. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  218. return
  219. }
  220. var afterevaluation models.AssessmentAfterDislysis
  221. if assessmentAfterDislysis != nil {
  222. afterevaluation = *assessmentAfterDislysis
  223. }
  224. if assessmentAfterDislysis == nil {
  225. afterevaluation.CreatedTime = time.Now().Unix()
  226. afterevaluation.Status = 1
  227. afterevaluation.AssessmentDate = theAssessmentDateTime
  228. afterevaluation.PatientId = id
  229. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  230. } else {
  231. afterevaluation.UpdatedTime = time.Now().Unix()
  232. }
  233. afterevaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  234. afterevaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  235. afterevaluation.PulseFrequency = pulse_frequency // 脉率
  236. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  237. if err == nil {
  238. c.ServeSuccessJSON(map[string]interface{}{
  239. "assessmentAfterDislysis": afterevaluation,
  240. })
  241. }
  242. }
  243. }
  244. func (c *CheckWeightApiController) SavePatientInfoDialysis() {
  245. id, _ := c.GetInt64("patient", 0)
  246. dialysistype, _ := c.GetInt64("dialysistype", 0)
  247. if id <= 0 {
  248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  249. return
  250. }
  251. if dialysistype <= 0 {
  252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  253. return
  254. }
  255. adminUserInfo := c.GetMobileAdminUserInfo()
  256. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  257. if patient.ID == 0 {
  258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  259. return
  260. }
  261. thisTime := time.Now()
  262. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  263. // scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  264. timeLayout := "2006-01-02 15:04:05"
  265. loc, _ := time.LoadLocation("Local")
  266. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  267. // theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  268. theAssessmentDateTime := theStartTime.Unix()
  269. // endTime := theEndTime.Unix()
  270. // dry_weight,_ := c.GetFloat("dry_weight",0) // 干体重
  271. weighing_before, _ := c.GetFloat("weighing_before", 0) // 透前体重
  272. dewater_amount, _ := c.GetFloat("dewater_amount", 0) // 目标脱水量(L)
  273. weight_after, _ := c.GetFloat("weight_after", 0) // 透后体重
  274. weight_loss, _ := c.GetFloat("weight_loss", 0) // 体重减少
  275. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix())
  276. //dialysisSolution,_ := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id,patient.ID,schedual.ModeId)
  277. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  278. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  279. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  280. // 查询当前用户今天有没有排班,没有排班,则不处理
  281. // daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, theAssessmentDateTime, endTime, id)
  282. // if(len(daySchedule) <= 0) {
  283. // c.ServeSuccessJSON(map[string]interface{}{
  284. // "msg": "ok",
  285. // })
  286. // return
  287. // }
  288. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  289. if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 {
  290. dewater_amount = dewater_amount * 1000
  291. if dewater_amount < 0 {
  292. dewater_amount = 0
  293. }
  294. }
  295. if dialysistype == 1 {
  296. // 保存透前相关数据
  297. // 获取透析处方
  298. var lastDialysisPrescribe *models.DialysisPrescription
  299. var dialysisSolution *models.DialysisSolution
  300. var dialysisPrescribe *models.DialysisPrescription
  301. var system_dialysisPrescribe *models.SystemPrescription
  302. var mode_id int64
  303. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  304. if schedual != nil {
  305. // 获取透析模版
  306. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  307. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  308. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  309. mode_id = schedual.ModeId
  310. } else {
  311. // 获取透析模版
  312. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  313. if dialysisPrescribe == nil && dialysisSolution != nil {
  314. mode_id = dialysisSolution.ModeId
  315. }
  316. if dialysisPrescribe == nil && dialysisSolution == nil {
  317. mode_id = 0
  318. }
  319. }
  320. // 插入透析处方
  321. if dialysisPrescribe == nil && dialysisSolution != nil {
  322. var newprescribe models.DialysisPrescription
  323. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  324. newprescribe.PatientId = dialysisSolution.PatientId
  325. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  326. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  327. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  328. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  329. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  330. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  331. newprescribe.ModeId = dialysisSolution.ModeId
  332. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  333. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  334. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  335. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  336. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  337. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  338. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  339. newprescribe.Glucose = dialysisSolution.Glucose
  340. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  341. newprescribe.Kalium = dialysisSolution.Kalium
  342. newprescribe.Sodium = dialysisSolution.Sodium
  343. newprescribe.Calcium = dialysisSolution.Calcium
  344. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  345. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  346. newprescribe.Conductivity = dialysisSolution.Conductivity
  347. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  348. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  349. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  350. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  351. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  352. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  353. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  354. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  355. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  356. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  357. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  358. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  359. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  360. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  361. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  362. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  363. newprescribe.CreatedTime = time.Now().Unix()
  364. newprescribe.UpdatedTime = time.Now().Unix()
  365. newprescribe.RecordDate = theAssessmentDateTime
  366. newprescribe.DewaterAmount = dewater_amount
  367. newprescribe.TargetUltrafiltration = dewater_amount
  368. newprescribe.Status = 1
  369. err := service.AddSigleRecord(&newprescribe)
  370. if err != nil {
  371. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  372. }
  373. }
  374. if dialysisPrescribe == nil && dialysisSolution == nil {
  375. if lastDialysisPrescribe != nil {
  376. var newprescribe models.DialysisPrescription
  377. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  378. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  379. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  380. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  381. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  382. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  383. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  384. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  385. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  386. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  387. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  388. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  389. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  390. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  391. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  392. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  393. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  394. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  395. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  396. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  397. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  398. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  399. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  400. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  401. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  402. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  403. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  404. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  405. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  406. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  407. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  408. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  409. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  410. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  411. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  412. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  413. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  414. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  415. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  416. newprescribe.CreatedTime = time.Now().Unix()
  417. newprescribe.UpdatedTime = time.Now().Unix()
  418. newprescribe.RecordDate = theAssessmentDateTime
  419. newprescribe.DewaterAmount = dewater_amount
  420. newprescribe.TargetUltrafiltration = dewater_amount
  421. newprescribe.Status = 1
  422. err := service.AddSigleRecord(&newprescribe)
  423. if err != nil {
  424. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  425. }
  426. } else if system_dialysisPrescribe != nil {
  427. var newprescribe models.DialysisPrescription
  428. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  429. newprescribe.PatientId = id
  430. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  431. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  432. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  433. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  434. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  435. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  436. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  437. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  438. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  439. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  440. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  441. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  442. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  443. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  444. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  445. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  446. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  447. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  448. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  449. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  450. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  451. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  452. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  453. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  454. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  455. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  456. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  457. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  458. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  459. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  460. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  461. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  462. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  463. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  464. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  465. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  466. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  467. newprescribe.CreatedTime = time.Now().Unix()
  468. newprescribe.UpdatedTime = time.Now().Unix()
  469. newprescribe.RecordDate = theAssessmentDateTime
  470. newprescribe.DewaterAmount = dewater_amount
  471. newprescribe.TargetUltrafiltration = dewater_amount
  472. newprescribe.Status = 1
  473. fmt.Println(newprescribe.DewaterAmount)
  474. fmt.Println(newprescribe.TargetUltrafiltration)
  475. err := service.AddSigleRecord(&newprescribe)
  476. if err != nil {
  477. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  478. }
  479. } else {
  480. var newprescribe models.DialysisPrescription
  481. newprescribe.UserOrgId = adminUserInfo.Org.Id
  482. newprescribe.PatientId = id
  483. newprescribe.ModeId = mode_id
  484. newprescribe.CreatedTime = time.Now().Unix()
  485. newprescribe.UpdatedTime = time.Now().Unix()
  486. newprescribe.RecordDate = theAssessmentDateTime
  487. newprescribe.DewaterAmount = dewater_amount
  488. newprescribe.TargetUltrafiltration = dewater_amount
  489. newprescribe.Status = 1
  490. err := service.AddSigleRecord(&newprescribe)
  491. if err != nil {
  492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  493. }
  494. }
  495. }
  496. if dialysisPrescribe != nil {
  497. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  498. dialysisPrescribe.RecordDate = theAssessmentDateTime
  499. dialysisPrescribe.DewaterAmount = dewater_amount
  500. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  501. dialysisPrescribe.Status = 1
  502. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  503. if updateErr != nil {
  504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  505. }
  506. }
  507. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  508. if getPEErr != nil {
  509. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  511. return
  512. }
  513. var evaluation models.PredialysisEvaluation
  514. if theEvaluation != nil {
  515. evaluation = *theEvaluation
  516. }
  517. // 如果今天没有透前评估,则插入新的数据
  518. if theEvaluation == nil {
  519. evaluation.CreatedTime = time.Now().Unix()
  520. evaluation.Status = 1
  521. evaluation.AssessmentDate = theAssessmentDateTime
  522. evaluation.PatientId = id
  523. evaluation.UserOrgId = adminUserInfo.Org.Id
  524. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  525. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  526. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  527. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  528. if getAADErr != nil {
  529. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  530. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  531. return
  532. }
  533. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  534. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  535. if err == gorm.ErrRecordNotFound {
  536. if lastPredialysisEvaluation != nil {
  537. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  538. } else {
  539. evaluation.DryWeight = 0
  540. }
  541. } else {
  542. evaluation.DryWeight = weight.DryWeight
  543. }
  544. if assessmentAfterDislysis != nil {
  545. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  546. }
  547. if lastPredialysisEvaluation != nil {
  548. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  549. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  550. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  551. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  552. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  553. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  554. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  555. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  556. evaluation.Complication = lastPredialysisEvaluation.Complication
  557. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  558. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  559. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  560. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  561. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  562. }
  563. } else {
  564. evaluation.UpdatedTime = time.Now().Unix()
  565. }
  566. evaluation.WeightBefore = weighing_before
  567. evaluation.AssessmentTime = time.Now().Unix()
  568. err := service.UpadatePredialysisEvaluation(&evaluation)
  569. if err != nil {
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  571. return
  572. }
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "msg": "ok",
  575. "evaluation": evaluation,
  576. })
  577. return
  578. } else {
  579. // 保存透后相关数据
  580. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  581. if getAADErr != nil {
  582. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  584. return
  585. }
  586. var afterevaluation models.AssessmentAfterDislysis
  587. if assessmentAfterDislysis != nil {
  588. afterevaluation = *assessmentAfterDislysis
  589. }
  590. if assessmentAfterDislysis == nil {
  591. afterevaluation.CreatedTime = time.Now().Unix()
  592. afterevaluation.Status = 1
  593. afterevaluation.AssessmentDate = theAssessmentDateTime
  594. afterevaluation.PatientId = id
  595. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  596. } else {
  597. afterevaluation.UpdatedTime = time.Now().Unix()
  598. }
  599. afterevaluation.WeightAfter = weight_after
  600. afterevaluation.WeightLoss = weight_loss
  601. // if (adminUserInfo.Org.Id == 9538){
  602. // afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  603. // } else {
  604. // afterevaluation.ActualUltrafiltration = weight_loss // 计量单位是L
  605. // }
  606. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  607. if err == nil {
  608. c.ServeSuccessJSON(map[string]interface{}{
  609. "assessmentAfterDislysis": afterevaluation,
  610. })
  611. }
  612. }
  613. }
  614. func (c *CheckWeightApiController) GetPatientList() {
  615. syncTime, _ := c.GetInt64("synctime", 0)
  616. force, _ := c.GetInt64("force", 0)
  617. adminUserInfo := c.GetMobileAdminUserInfo()
  618. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, syncTime, force)
  619. if error != nil {
  620. c.ErrorLog("获取病人列表失败:%v", error)
  621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  622. return
  623. }
  624. serviceTime := time.Now().Unix()
  625. c.ServeSuccessJSON(map[string]interface{}{
  626. "patientlist": patientList,
  627. "total": total,
  628. "servicetime": serviceTime,
  629. })
  630. }
  631. func (c *CheckWeightApiController) GetPatientListById() {
  632. patientId, _ := c.GetInt64("patient_id", 0)
  633. if patientId <= 0 {
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  635. return
  636. }
  637. adminUserInfo := c.GetMobileAdminUserInfo()
  638. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  639. if error != nil {
  640. c.ErrorLog("获取病人详情失败:%v", error)
  641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  642. return
  643. }
  644. c.ServeSuccessJSON(map[string]interface{}{
  645. "patientinfo": patient,
  646. })
  647. }
  648. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  649. id, _ := c.GetInt64("patient", 0)
  650. if id <= 0 {
  651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  652. return
  653. }
  654. adminUserInfo := c.GetMobileAdminUserInfo()
  655. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  656. if patient.ID <= 0 {
  657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  658. return
  659. }
  660. var dialysisinfo map[string]interface{}
  661. dialysisinfo = make(map[string]interface{})
  662. dialysisinfo["id"] = patient.ID
  663. dialysisinfo["name"] = patient.Name
  664. dialysisinfo["dialysis_no"] = patient.DialysisNo
  665. thisTime := time.Now()
  666. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  667. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  668. timeLayout := "2006-01-02 15:04:05"
  669. loc, _ := time.LoadLocation("Local")
  670. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  671. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  672. startTime := theStartTime.Unix()
  673. endTime := theEndTime.Unix()
  674. // 判断当前用户是透析前还是透析后
  675. var dialysistype int
  676. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  677. if dialysisOrder == nil {
  678. dialysistype = 1
  679. } else {
  680. dialysistype = 2
  681. }
  682. // 获取当前或者下次排班信息
  683. var sc map[string]interface{}
  684. sc = make(map[string]interface{})
  685. if dialysistype == 1 {
  686. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  687. if len(daySchedule) <= 0 {
  688. sc["code"] = 1
  689. sc["msg"] = "抱歉,您今天没有排版!"
  690. sc["mode"] = 0
  691. sc["data"] = daySchedule
  692. } else {
  693. if daySchedule[0].Schedule.ID > 0 {
  694. sc["code"] = 0
  695. sc["msg"] = ""
  696. sc["mode"] = daySchedule[0].Schedule.ModeId
  697. sc["data"] = daySchedule
  698. } else {
  699. sc["code"] = 1
  700. sc["msg"] = "抱歉,您今天没有排版!"
  701. sc["mode"] = 0
  702. sc["data"] = daySchedule
  703. }
  704. }
  705. } else {
  706. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  707. if len(nextSchedule) <= 0 {
  708. sc["code"] = 1
  709. sc["msg"] = "抱歉,您后续没有排版!"
  710. sc["mode"] = 0
  711. sc["data"] = nextSchedule
  712. } else {
  713. if nextSchedule[0].Schedule.ID > 0 {
  714. sc["code"] = 0
  715. sc["msg"] = ""
  716. sc["mode"] = nextSchedule[0].Schedule.ModeId
  717. sc["data"] = nextSchedule
  718. } else {
  719. sc["code"] = 1
  720. sc["msg"] = "抱歉,您后续没有排版!"
  721. sc["mode"] = 0
  722. sc["data"] = nextSchedule
  723. }
  724. }
  725. }
  726. switch sc["mode"] {
  727. case 1:
  728. sc["mode"] = "HD"
  729. case 2:
  730. sc["mode"] = "HDF"
  731. case 3:
  732. sc["mode"] = "HD+HP"
  733. case 4:
  734. sc["mode"] = "HP"
  735. case 5:
  736. sc["mode"] = "HF"
  737. case 6:
  738. sc["mode"] = "SCUF"
  739. case 7:
  740. sc["mode"] = "IUF"
  741. case 8:
  742. sc["mode"] = "HFHD"
  743. case 9:
  744. sc["mode"] = "HFHD+HP"
  745. case 10:
  746. sc["mode"] = "PHF"
  747. case 11:
  748. sc["mode"] = "HFR"
  749. case 12:
  750. sc["mode"] = "HDF+HP"
  751. case 13:
  752. sc["mode"] = "CRRT"
  753. case 14:
  754. sc["mode"] = "腹水回输"
  755. case 15:
  756. sc["mode"] = "HD前置换"
  757. case 16:
  758. sc["mode"] = "HD后置换"
  759. case 17:
  760. sc["mode"] = "HDF前置换"
  761. case 18:
  762. sc["mode"] = "HDF后置换"
  763. default:
  764. sc["mode"] = "HD"
  765. }
  766. // 获取患者透前干体重或者获取患者透前体重
  767. var dry_weight map[string]interface{}
  768. dry_weight = make(map[string]interface{})
  769. var after_dry_weight map[string]interface{}
  770. after_dry_weight = make(map[string]interface{})
  771. if dialysistype == 1 {
  772. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  773. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  774. if err == gorm.ErrRecordNotFound {
  775. if getLPEErr != nil {
  776. dry_weight["code"] = 1
  777. dry_weight["dry_weight"] = nil
  778. } else {
  779. if lastPredialysisEvaluation == nil {
  780. dry_weight["code"] = 1
  781. dry_weight["dry_weight"] = nil
  782. } else {
  783. // 传输的干体重实际为干体重加上衣服重
  784. dry_weight["code"] = 0
  785. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  786. }
  787. }
  788. } else {
  789. if err != nil {
  790. dry_weight["code"] = 1
  791. dry_weight["dry_weight"] = nil
  792. } else {
  793. dry_weight["code"] = 0
  794. if getLPEErr != nil {
  795. dry_weight["code"] = 0
  796. dry_weight["dry_weight"] = weight.DryWeight
  797. } else {
  798. if lastPredialysisEvaluation == nil {
  799. dry_weight["code"] = 1
  800. dry_weight["dry_weight"] = weight.DryWeight
  801. } else {
  802. // 传输的干体重实际为干体重加上衣服重
  803. dry_weight["code"] = 0
  804. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  805. }
  806. }
  807. }
  808. }
  809. } else {
  810. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  811. if getPEErr != nil {
  812. dry_weight["code"] = 1
  813. dry_weight["dry_weight"] = nil
  814. } else {
  815. if predialysisEvaluation == nil {
  816. dry_weight["code"] = 1
  817. dry_weight["dry_weight"] = nil
  818. } else {
  819. dry_weight["code"] = 0
  820. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  821. }
  822. }
  823. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  824. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  825. if err == gorm.ErrRecordNotFound {
  826. if getLPEErr != nil {
  827. after_dry_weight["code"] = 1
  828. after_dry_weight["dry_weight"] = nil
  829. } else {
  830. if lastPredialysisEvaluation == nil {
  831. after_dry_weight["code"] = 1
  832. after_dry_weight["dry_weight"] = nil
  833. } else {
  834. // 传输的干体重实际为干体重加上衣服重
  835. after_dry_weight["code"] = 0
  836. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  837. }
  838. }
  839. } else {
  840. if err != nil {
  841. after_dry_weight["code"] = 1
  842. after_dry_weight["dry_weight"] = nil
  843. } else {
  844. after_dry_weight["code"] = 0
  845. if getLPEErr != nil {
  846. after_dry_weight["code"] = 0
  847. after_dry_weight["dry_weight"] = weight.DryWeight
  848. } else {
  849. if lastPredialysisEvaluation == nil {
  850. after_dry_weight["code"] = 1
  851. after_dry_weight["dry_weight"] = weight.DryWeight
  852. } else {
  853. // 传输的干体重实际为干体重加上衣服重
  854. after_dry_weight["code"] = 0
  855. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  856. }
  857. }
  858. }
  859. }
  860. }
  861. c.ServeSuccessJSON(map[string]interface{}{
  862. "dialysistype": dialysistype,
  863. "patient": dialysisinfo,
  864. "schedule": sc,
  865. "dryweight": dry_weight,
  866. "after_dry_weight": after_dry_weight,
  867. })
  868. return
  869. }
  870. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  871. id, _ := c.GetInt64("patient", 0)
  872. if id <= 0 {
  873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  874. return
  875. }
  876. adminUserInfo := c.GetMobileAdminUserInfo()
  877. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  878. if patient.ID == 0 {
  879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  880. return
  881. }
  882. var dialysisinfo map[string]interface{}
  883. dialysisinfo = make(map[string]interface{})
  884. dialysisinfo["id"] = patient.ID
  885. dialysisinfo["name"] = patient.Name
  886. dialysisinfo["dialysis_no"] = patient.DialysisNo
  887. thisTime := time.Now()
  888. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  889. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  890. fmt.Println(scheduleDateStart, scheduleDateEnd)
  891. timeLayout := "2006-01-02 15:04:05"
  892. loc, _ := time.LoadLocation("Local")
  893. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  894. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  895. fmt.Println(theStartTime, theEndTime)
  896. startTime := theStartTime.Unix()
  897. endTime := theEndTime.Unix()
  898. var sc map[string]interface{}
  899. sc = make(map[string]interface{})
  900. //一天只有排班一次
  901. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  902. if daySchedule.ID > 0 {
  903. switch daySchedule.ModeId {
  904. case 1:
  905. sc["mode"] = "HD"
  906. case 2:
  907. sc["mode"] = "HDF"
  908. case 3:
  909. sc["mode"] = "HD+HP"
  910. case 4:
  911. sc["mode"] = "HP"
  912. case 5:
  913. sc["mode"] = "HF"
  914. case 6:
  915. sc["mode"] = "SCUF"
  916. case 7:
  917. sc["mode"] = "IUF"
  918. case 8:
  919. sc["mode"] = "HFHD"
  920. case 9:
  921. sc["mode"] = "HFHD+HP"
  922. case 10:
  923. sc["mode"] = "PHF"
  924. case 11:
  925. sc["mode"] = "HFR"
  926. case 12:
  927. sc["mode"] = "HDF+HP"
  928. case 13:
  929. sc["mode"] = "CRRT"
  930. case 14:
  931. sc["mode"] = "腹水回输"
  932. case 15:
  933. sc["mode"] = "HD前置换"
  934. case 16:
  935. sc["mode"] = "HD后置换"
  936. case 17:
  937. sc["mode"] = "HDF前置换"
  938. case 18:
  939. sc["mode"] = "HDF后置换"
  940. default:
  941. sc["mode"] = "HD"
  942. }
  943. sc["code"] = 0
  944. sc["msg"] = ""
  945. sc["data"] = daySchedule
  946. } else {
  947. sc["code"] = 1
  948. sc["msg"] = "抱歉,您今天没有排版!"
  949. sc["mode"] = ""
  950. sc["data"] = daySchedule
  951. }
  952. fmt.Println(sc)
  953. type dryWeight struct {
  954. code int
  955. dry_weight float64
  956. }
  957. var dry_weight map[string]interface{}
  958. dry_weight = make(map[string]interface{})
  959. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  960. if getLPEErr != nil {
  961. dry_weight["code"] = 1
  962. dry_weight["dry_weight"] = nil
  963. } else {
  964. if lastPredialysisEvaluation == nil {
  965. dry_weight["code"] = 1
  966. dry_weight["dry_weight"] = nil
  967. } else {
  968. dry_weight["code"] = 0
  969. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  970. }
  971. }
  972. c.ServeSuccessJSON(map[string]interface{}{
  973. "patient": dialysisinfo,
  974. "schedule": sc,
  975. "dryweight": dry_weight,
  976. })
  977. return
  978. }