check_weight_api_controller.go 39KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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. if dialysistype == 1 {
  289. // 保存透前相关数据
  290. // 获取透析处方
  291. var lastDialysisPrescribe *models.DialysisPrescription
  292. var dialysisSolution *models.DialysisSolution
  293. var dialysisPrescribe *models.DialysisPrescription
  294. var system_dialysisPrescribe *models.SystemPrescription
  295. var mode_id int64
  296. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  297. if schedual != nil {
  298. // 获取透析模版
  299. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  300. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeId(adminUserInfo.Org.Id, schedual.ModeId)
  301. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeId(adminUserInfo.Org.Id, id, schedual.ModeId)
  302. mode_id = schedual.ModeId
  303. } else {
  304. // 获取透析模版
  305. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  306. if dialysisPrescribe == nil && dialysisSolution != nil {
  307. mode_id = dialysisSolution.ModeId
  308. }
  309. if dialysisPrescribe == nil && dialysisSolution == nil {
  310. mode_id = 0
  311. }
  312. }
  313. // 插入透析处方
  314. if dialysisPrescribe == nil && dialysisSolution != nil {
  315. var newprescribe models.DialysisPrescription
  316. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  317. newprescribe.PatientId = dialysisSolution.PatientId
  318. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  319. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  320. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  321. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  322. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  323. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  324. newprescribe.ModeId = dialysisSolution.ModeId
  325. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  326. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  327. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  328. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  329. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  330. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  331. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  332. newprescribe.Glucose = dialysisSolution.Glucose
  333. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  334. newprescribe.Kalium = dialysisSolution.Kalium
  335. newprescribe.Sodium = dialysisSolution.Sodium
  336. newprescribe.Calcium = dialysisSolution.Calcium
  337. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  338. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  339. newprescribe.Conductivity = dialysisSolution.Conductivity
  340. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  341. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  342. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  343. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  344. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  345. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  346. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  347. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  348. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  349. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  350. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  351. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  352. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  353. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  354. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  355. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  356. newprescribe.CreatedTime = time.Now().Unix()
  357. newprescribe.UpdatedTime = time.Now().Unix()
  358. newprescribe.RecordDate = theAssessmentDateTime
  359. newprescribe.DewaterAmount = dewater_amount
  360. newprescribe.TargetUltrafiltration = dewater_amount
  361. newprescribe.Status = 1
  362. err := service.AddSigleRecord(&newprescribe)
  363. if err != nil {
  364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  365. }
  366. }
  367. if dialysisPrescribe == nil && dialysisSolution == nil {
  368. if lastDialysisPrescribe != nil {
  369. var newprescribe models.DialysisPrescription
  370. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  371. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  372. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  373. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  374. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  375. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  376. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  377. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  378. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  379. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  380. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  381. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  382. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  383. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  384. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  385. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  386. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  387. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  388. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  389. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  390. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  391. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  392. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  393. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  394. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  395. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  396. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  397. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  398. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  399. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  400. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  401. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  402. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  403. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  404. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  405. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  406. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  407. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  408. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  409. newprescribe.CreatedTime = time.Now().Unix()
  410. newprescribe.UpdatedTime = time.Now().Unix()
  411. newprescribe.RecordDate = theAssessmentDateTime
  412. newprescribe.DewaterAmount = dewater_amount
  413. newprescribe.TargetUltrafiltration = dewater_amount
  414. newprescribe.Status = 1
  415. err := service.AddSigleRecord(&newprescribe)
  416. if err != nil {
  417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  418. }
  419. } else if system_dialysisPrescribe != nil {
  420. var newprescribe models.DialysisPrescription
  421. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  422. newprescribe.PatientId = id
  423. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  424. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  425. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  426. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  427. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  428. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  429. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  430. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  431. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  432. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  433. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  434. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  435. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  436. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  437. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  438. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  439. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  440. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  441. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  442. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  443. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  444. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  445. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  446. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  447. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  448. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  449. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  450. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  451. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  452. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  453. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  454. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  455. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  456. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  457. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  458. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  459. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  460. newprescribe.CreatedTime = time.Now().Unix()
  461. newprescribe.UpdatedTime = time.Now().Unix()
  462. newprescribe.RecordDate = theAssessmentDateTime
  463. newprescribe.DewaterAmount = dewater_amount
  464. newprescribe.TargetUltrafiltration = dewater_amount
  465. newprescribe.Status = 1
  466. fmt.Println(newprescribe.DewaterAmount)
  467. fmt.Println(newprescribe.TargetUltrafiltration)
  468. err := service.AddSigleRecord(&newprescribe)
  469. if err != nil {
  470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  471. }
  472. } else {
  473. var newprescribe models.DialysisPrescription
  474. newprescribe.UserOrgId = adminUserInfo.Org.Id
  475. newprescribe.PatientId = id
  476. newprescribe.ModeId = mode_id
  477. newprescribe.CreatedTime = time.Now().Unix()
  478. newprescribe.UpdatedTime = time.Now().Unix()
  479. newprescribe.RecordDate = theAssessmentDateTime
  480. newprescribe.DewaterAmount = dewater_amount
  481. newprescribe.TargetUltrafiltration = dewater_amount
  482. newprescribe.Status = 1
  483. err := service.AddSigleRecord(&newprescribe)
  484. if err != nil {
  485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  486. }
  487. }
  488. }
  489. if dialysisPrescribe != nil {
  490. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  491. dialysisPrescribe.RecordDate = theAssessmentDateTime
  492. dialysisPrescribe.DewaterAmount = dewater_amount
  493. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  494. dialysisPrescribe.Status = 1
  495. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  496. if updateErr != nil {
  497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  498. }
  499. }
  500. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  501. if getPEErr != nil {
  502. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  504. return
  505. }
  506. var evaluation models.PredialysisEvaluation
  507. if theEvaluation != nil {
  508. evaluation = *theEvaluation
  509. }
  510. // 如果今天没有透前评估,则插入新的数据
  511. if theEvaluation == nil {
  512. evaluation.CreatedTime = time.Now().Unix()
  513. evaluation.Status = 1
  514. evaluation.AssessmentDate = theAssessmentDateTime
  515. evaluation.PatientId = id
  516. evaluation.UserOrgId = adminUserInfo.Org.Id
  517. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  518. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  519. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  520. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  521. if getAADErr != nil {
  522. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  524. return
  525. }
  526. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  527. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  528. if err == gorm.ErrRecordNotFound {
  529. if lastPredialysisEvaluation != nil {
  530. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  531. } else {
  532. evaluation.DryWeight = 0
  533. }
  534. } else {
  535. evaluation.DryWeight = weight.DryWeight
  536. }
  537. if assessmentAfterDislysis != nil {
  538. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  539. }
  540. if lastPredialysisEvaluation != nil {
  541. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  542. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  543. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  544. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  545. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  546. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  547. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  548. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  549. evaluation.Complication = lastPredialysisEvaluation.Complication
  550. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  551. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  552. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  553. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  554. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  555. }
  556. } else {
  557. evaluation.UpdatedTime = time.Now().Unix()
  558. }
  559. evaluation.WeightBefore = weighing_before
  560. evaluation.AssessmentTime = time.Now().Unix()
  561. err := service.UpadatePredialysisEvaluation(&evaluation)
  562. if err != nil {
  563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  564. return
  565. }
  566. c.ServeSuccessJSON(map[string]interface{}{
  567. "msg": "ok",
  568. "evaluation": evaluation,
  569. })
  570. return
  571. } else {
  572. // 保存透后相关数据
  573. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  574. if getAADErr != nil {
  575. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  577. return
  578. }
  579. var afterevaluation models.AssessmentAfterDislysis
  580. if assessmentAfterDislysis != nil {
  581. afterevaluation = *assessmentAfterDislysis
  582. }
  583. if assessmentAfterDislysis == nil {
  584. afterevaluation.CreatedTime = time.Now().Unix()
  585. afterevaluation.Status = 1
  586. afterevaluation.AssessmentDate = theAssessmentDateTime
  587. afterevaluation.PatientId = id
  588. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  589. } else {
  590. afterevaluation.UpdatedTime = time.Now().Unix()
  591. }
  592. afterevaluation.WeightAfter = weight_after
  593. afterevaluation.WeightLoss = weight_loss
  594. // if (adminUserInfo.Org.Id == 9538){
  595. // afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  596. // } else {
  597. // afterevaluation.ActualUltrafiltration = weight_loss // 计量单位是L
  598. // }
  599. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  600. if err == nil {
  601. c.ServeSuccessJSON(map[string]interface{}{
  602. "assessmentAfterDislysis": afterevaluation,
  603. })
  604. }
  605. }
  606. }
  607. func (c *CheckWeightApiController) GetPatientList() {
  608. syncTime, _ := c.GetInt64("synctime", 0)
  609. force, _ := c.GetInt64("force", 0)
  610. adminUserInfo := c.GetMobileAdminUserInfo()
  611. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, syncTime, force)
  612. if error != nil {
  613. c.ErrorLog("获取病人列表失败:%v", error)
  614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  615. return
  616. }
  617. serviceTime := time.Now().Unix()
  618. c.ServeSuccessJSON(map[string]interface{}{
  619. "patientlist": patientList,
  620. "total": total,
  621. "servicetime": serviceTime,
  622. })
  623. }
  624. func (c *CheckWeightApiController) GetPatientListById() {
  625. patientId, _ := c.GetInt64("patient_id", 0)
  626. if patientId <= 0 {
  627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  628. return
  629. }
  630. adminUserInfo := c.GetMobileAdminUserInfo()
  631. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  632. if error != nil {
  633. c.ErrorLog("获取病人详情失败:%v", error)
  634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  635. return
  636. }
  637. c.ServeSuccessJSON(map[string]interface{}{
  638. "patientinfo": patient,
  639. })
  640. }
  641. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  642. id, _ := c.GetInt64("patient", 0)
  643. if id <= 0 {
  644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  645. return
  646. }
  647. adminUserInfo := c.GetMobileAdminUserInfo()
  648. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  649. if patient.ID <= 0 {
  650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  651. return
  652. }
  653. var dialysisinfo map[string]interface{}
  654. dialysisinfo = make(map[string]interface{})
  655. dialysisinfo["id"] = patient.ID
  656. dialysisinfo["name"] = patient.Name
  657. dialysisinfo["dialysis_no"] = patient.DialysisNo
  658. thisTime := time.Now()
  659. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  660. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  661. timeLayout := "2006-01-02 15:04:05"
  662. loc, _ := time.LoadLocation("Local")
  663. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  664. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  665. startTime := theStartTime.Unix()
  666. endTime := theEndTime.Unix()
  667. // 判断当前用户是透析前还是透析后
  668. var dialysistype int
  669. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  670. if dialysisOrder == nil {
  671. dialysistype = 1
  672. } else {
  673. dialysistype = 2
  674. }
  675. // 获取当前或者下次排班信息
  676. var sc map[string]interface{}
  677. sc = make(map[string]interface{})
  678. if dialysistype == 1 {
  679. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  680. if len(daySchedule) <= 0 {
  681. sc["code"] = 1
  682. sc["msg"] = "抱歉,您今天没有排版!"
  683. sc["mode"] = 0
  684. sc["data"] = daySchedule
  685. } else {
  686. if daySchedule[0].Schedule.ID > 0 {
  687. sc["code"] = 0
  688. sc["msg"] = ""
  689. sc["mode"] = daySchedule[0].Schedule.ModeId
  690. sc["data"] = daySchedule
  691. } else {
  692. sc["code"] = 1
  693. sc["msg"] = "抱歉,您今天没有排版!"
  694. sc["mode"] = 0
  695. sc["data"] = daySchedule
  696. }
  697. }
  698. } else {
  699. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  700. if len(nextSchedule) <= 0 {
  701. sc["code"] = 1
  702. sc["msg"] = "抱歉,您后续没有排版!"
  703. sc["mode"] = 0
  704. sc["data"] = nextSchedule
  705. } else {
  706. if nextSchedule[0].Schedule.ID > 0 {
  707. sc["code"] = 0
  708. sc["msg"] = ""
  709. sc["mode"] = nextSchedule[0].Schedule.ModeId
  710. sc["data"] = nextSchedule
  711. } else {
  712. sc["code"] = 1
  713. sc["msg"] = "抱歉,您后续没有排版!"
  714. sc["mode"] = 0
  715. sc["data"] = nextSchedule
  716. }
  717. }
  718. }
  719. switch sc["mode"] {
  720. case 1:
  721. sc["mode"] = "HD"
  722. case 2:
  723. sc["mode"] = "HDF"
  724. case 3:
  725. sc["mode"] = "HD+HP"
  726. case 4:
  727. sc["mode"] = "HP"
  728. case 5:
  729. sc["mode"] = "HF"
  730. case 6:
  731. sc["mode"] = "SCUF"
  732. case 7:
  733. sc["mode"] = "IUF"
  734. case 8:
  735. sc["mode"] = "HFHD"
  736. case 9:
  737. sc["mode"] = "HFHD+HP"
  738. case 10:
  739. sc["mode"] = "PHF"
  740. case 11:
  741. sc["mode"] = "HFR"
  742. case 12:
  743. sc["mode"] = "HDF+HP"
  744. case 13:
  745. sc["mode"] = "CRRT"
  746. case 14:
  747. sc["mode"] = "腹水回输"
  748. case 15:
  749. sc["mode"] = "HD前置换"
  750. case 16:
  751. sc["mode"] = "HD后置换"
  752. case 17:
  753. sc["mode"] = "HDF前置换"
  754. case 18:
  755. sc["mode"] = "HDF后置换"
  756. default:
  757. sc["mode"] = "HD"
  758. }
  759. // 获取患者透前干体重或者获取患者透前体重
  760. var dry_weight map[string]interface{}
  761. dry_weight = make(map[string]interface{})
  762. if dialysistype == 1 {
  763. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  764. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  765. if err == gorm.ErrRecordNotFound {
  766. if getLPEErr != nil {
  767. dry_weight["code"] = 1
  768. dry_weight["dry_weight"] = nil
  769. } else {
  770. if lastPredialysisEvaluation == nil {
  771. dry_weight["code"] = 1
  772. dry_weight["dry_weight"] = nil
  773. } else {
  774. // 传输的干体重实际为干体重加上衣服重
  775. dry_weight["code"] = 0
  776. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  777. }
  778. }
  779. } else {
  780. if err != nil {
  781. dry_weight["code"] = 1
  782. dry_weight["dry_weight"] = nil
  783. } else {
  784. dry_weight["code"] = 0
  785. if getLPEErr != nil {
  786. dry_weight["code"] = 0
  787. dry_weight["dry_weight"] = weight.DryWeight
  788. } else {
  789. if lastPredialysisEvaluation == nil {
  790. dry_weight["code"] = 1
  791. dry_weight["dry_weight"] = weight.DryWeight
  792. } else {
  793. // 传输的干体重实际为干体重加上衣服重
  794. dry_weight["code"] = 0
  795. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  796. }
  797. }
  798. }
  799. }
  800. } else {
  801. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  802. if getPEErr != nil {
  803. dry_weight["code"] = 1
  804. dry_weight["dry_weight"] = nil
  805. } else {
  806. if predialysisEvaluation == nil {
  807. dry_weight["code"] = 1
  808. dry_weight["dry_weight"] = nil
  809. } else {
  810. dry_weight["code"] = 0
  811. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  812. }
  813. }
  814. }
  815. c.ServeSuccessJSON(map[string]interface{}{
  816. "dialysistype": dialysistype,
  817. "patient": dialysisinfo,
  818. "schedule": sc,
  819. "dryweight": dry_weight,
  820. })
  821. return
  822. }
  823. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  824. id, _ := c.GetInt64("patient", 0)
  825. if id <= 0 {
  826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  827. return
  828. }
  829. adminUserInfo := c.GetMobileAdminUserInfo()
  830. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  831. if patient.ID == 0 {
  832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  833. return
  834. }
  835. var dialysisinfo map[string]interface{}
  836. dialysisinfo = make(map[string]interface{})
  837. dialysisinfo["id"] = patient.ID
  838. dialysisinfo["name"] = patient.Name
  839. dialysisinfo["dialysis_no"] = patient.DialysisNo
  840. thisTime := time.Now()
  841. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  842. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  843. fmt.Println(scheduleDateStart, scheduleDateEnd)
  844. timeLayout := "2006-01-02 15:04:05"
  845. loc, _ := time.LoadLocation("Local")
  846. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  847. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  848. fmt.Println(theStartTime, theEndTime)
  849. startTime := theStartTime.Unix()
  850. endTime := theEndTime.Unix()
  851. var sc map[string]interface{}
  852. sc = make(map[string]interface{})
  853. //一天只有排班一次
  854. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  855. if daySchedule.ID > 0 {
  856. switch daySchedule.ModeId {
  857. case 1:
  858. sc["mode"] = "HD"
  859. case 2:
  860. sc["mode"] = "HDF"
  861. case 3:
  862. sc["mode"] = "HD+HP"
  863. case 4:
  864. sc["mode"] = "HP"
  865. case 5:
  866. sc["mode"] = "HF"
  867. case 6:
  868. sc["mode"] = "SCUF"
  869. case 7:
  870. sc["mode"] = "IUF"
  871. case 8:
  872. sc["mode"] = "HFHD"
  873. case 9:
  874. sc["mode"] = "HFHD+HP"
  875. case 10:
  876. sc["mode"] = "PHF"
  877. case 11:
  878. sc["mode"] = "HFR"
  879. case 12:
  880. sc["mode"] = "HDF+HP"
  881. case 13:
  882. sc["mode"] = "CRRT"
  883. case 14:
  884. sc["mode"] = "腹水回输"
  885. case 15:
  886. sc["mode"] = "HD前置换"
  887. case 16:
  888. sc["mode"] = "HD后置换"
  889. case 17:
  890. sc["mode"] = "HDF前置换"
  891. case 18:
  892. sc["mode"] = "HDF后置换"
  893. default:
  894. sc["mode"] = "HD"
  895. }
  896. sc["code"] = 0
  897. sc["msg"] = ""
  898. sc["data"] = daySchedule
  899. } else {
  900. sc["code"] = 1
  901. sc["msg"] = "抱歉,您今天没有排版!"
  902. sc["mode"] = ""
  903. sc["data"] = daySchedule
  904. }
  905. fmt.Println(sc)
  906. type dryWeight struct {
  907. code int
  908. dry_weight float64
  909. }
  910. var dry_weight map[string]interface{}
  911. dry_weight = make(map[string]interface{})
  912. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  913. if getLPEErr != nil {
  914. dry_weight["code"] = 1
  915. dry_weight["dry_weight"] = nil
  916. } else {
  917. if lastPredialysisEvaluation == nil {
  918. dry_weight["code"] = 1
  919. dry_weight["dry_weight"] = nil
  920. } else {
  921. dry_weight["code"] = 0
  922. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  923. }
  924. }
  925. c.ServeSuccessJSON(map[string]interface{}{
  926. "patient": dialysisinfo,
  927. "schedule": sc,
  928. "dryweight": dry_weight,
  929. })
  930. return
  931. }