check_weight_api_controller.go 41KB

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