check_weight_api_controller.go 42KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  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) GetPatientListForSchedules() {
  644. thisTime := time.Now()
  645. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  646. timeLayout := "2006-01-02 15:04:05"
  647. loc, _ := time.LoadLocation("Local")
  648. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  649. syncTime := theStartTime.Unix()
  650. adminUserInfo := c.GetMobileAdminUserInfo()
  651. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  652. patientSchedule := make([]map[string]interface{},0)
  653. for _, item := range patientList {
  654. patientTemp := make(map[string]interface{})
  655. patientTemp["patient_id"] = item.PatientId
  656. patientTemp["patient_name"] = item.Patient.Name
  657. patientTemp["schedule_type"] = item.ScheduleType
  658. patientSchedule = append(patientSchedule, patientTemp)
  659. }
  660. if error != nil {
  661. c.ErrorLog("获取病人列表失败:%v", error)
  662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  663. return
  664. }
  665. serviceTime := time.Now().Unix()
  666. c.ServeSuccessJSON(map[string]interface{}{
  667. "patientlist": patientSchedule,
  668. "total": total,
  669. "servicetime": serviceTime,
  670. })
  671. }
  672. func (c *CheckWeightApiController) GetPatientListById() {
  673. patientId, _ := c.GetInt64("patient_id", 0)
  674. if patientId <= 0 {
  675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  676. return
  677. }
  678. adminUserInfo := c.GetMobileAdminUserInfo()
  679. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  680. if error != nil {
  681. c.ErrorLog("获取病人详情失败:%v", error)
  682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  683. return
  684. }
  685. c.ServeSuccessJSON(map[string]interface{}{
  686. "patientinfo": patient,
  687. })
  688. }
  689. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  690. id, _ := c.GetInt64("patient", 0)
  691. if id <= 0 {
  692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  693. return
  694. }
  695. adminUserInfo := c.GetMobileAdminUserInfo()
  696. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  697. if patient.ID <= 0 {
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  699. return
  700. }
  701. var dialysisinfo map[string]interface{}
  702. dialysisinfo = make(map[string]interface{})
  703. dialysisinfo["id"] = patient.ID
  704. dialysisinfo["name"] = patient.Name
  705. dialysisinfo["dialysis_no"] = patient.DialysisNo
  706. thisTime := time.Now()
  707. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  708. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  709. timeLayout := "2006-01-02 15:04:05"
  710. loc, _ := time.LoadLocation("Local")
  711. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  712. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  713. startTime := theStartTime.Unix()
  714. endTime := theEndTime.Unix()
  715. // 判断当前用户是透析前还是透析后
  716. var dialysistype int
  717. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  718. if dialysisOrder == nil {
  719. dialysistype = 1
  720. } else {
  721. dialysistype = 2
  722. }
  723. // 获取当前或者下次排班信息
  724. var sc map[string]interface{}
  725. sc = make(map[string]interface{})
  726. if dialysistype == 1 {
  727. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  728. if len(daySchedule) <= 0 {
  729. sc["code"] = 1
  730. sc["msg"] = "抱歉,您今天没有排版!"
  731. sc["mode"] = 0
  732. sc["data"] = daySchedule
  733. } else {
  734. if daySchedule[0].Schedule.ID > 0 {
  735. sc["code"] = 0
  736. sc["msg"] = ""
  737. sc["mode"] = daySchedule[0].Schedule.ModeId
  738. sc["data"] = daySchedule
  739. } else {
  740. sc["code"] = 1
  741. sc["msg"] = "抱歉,您今天没有排版!"
  742. sc["mode"] = 0
  743. sc["data"] = daySchedule
  744. }
  745. }
  746. // 排队叫号的签到
  747. ssoDomain := beego.AppConfig.String("call_domain")
  748. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  749. values := make(url.Values)
  750. http.PostForm(api, values)
  751. } else {
  752. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  753. if len(nextSchedule) <= 0 {
  754. sc["code"] = 1
  755. sc["msg"] = "抱歉,您后续没有排版!"
  756. sc["mode"] = 0
  757. sc["data"] = nextSchedule
  758. } else {
  759. if nextSchedule[0].Schedule.ID > 0 {
  760. sc["code"] = 0
  761. sc["msg"] = ""
  762. sc["mode"] = nextSchedule[0].Schedule.ModeId
  763. sc["data"] = nextSchedule
  764. } else {
  765. sc["code"] = 1
  766. sc["msg"] = "抱歉,您后续没有排版!"
  767. sc["mode"] = 0
  768. sc["data"] = nextSchedule
  769. }
  770. }
  771. }
  772. switch sc["mode"] {
  773. case 1:
  774. sc["mode"] = "HD"
  775. case 2:
  776. sc["mode"] = "HDF"
  777. case 3:
  778. sc["mode"] = "HD+HP"
  779. case 4:
  780. sc["mode"] = "HP"
  781. case 5:
  782. sc["mode"] = "HF"
  783. case 6:
  784. sc["mode"] = "SCUF"
  785. case 7:
  786. sc["mode"] = "IUF"
  787. case 8:
  788. sc["mode"] = "HFHD"
  789. case 9:
  790. sc["mode"] = "HFHD+HP"
  791. case 10:
  792. sc["mode"] = "PHF"
  793. case 11:
  794. sc["mode"] = "HFR"
  795. case 12:
  796. sc["mode"] = "HDF+HP"
  797. case 13:
  798. sc["mode"] = "CRRT"
  799. case 14:
  800. sc["mode"] = "腹水回输"
  801. case 15:
  802. sc["mode"] = "HD前置换"
  803. case 16:
  804. sc["mode"] = "HD后置换"
  805. case 17:
  806. sc["mode"] = "HDF前置换"
  807. case 18:
  808. sc["mode"] = "HDF后置换"
  809. default:
  810. sc["mode"] = "HD"
  811. }
  812. // 获取患者透前干体重或者获取患者透前体重
  813. var dry_weight map[string]interface{}
  814. dry_weight = make(map[string]interface{})
  815. var after_dry_weight map[string]interface{}
  816. after_dry_weight = make(map[string]interface{})
  817. if dialysistype == 1 {
  818. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  819. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  820. if err == gorm.ErrRecordNotFound {
  821. if getLPEErr != nil {
  822. dry_weight["code"] = 1
  823. dry_weight["dry_weight"] = nil
  824. } else {
  825. if lastPredialysisEvaluation == nil {
  826. dry_weight["code"] = 1
  827. dry_weight["dry_weight"] = nil
  828. } else {
  829. // 传输的干体重实际为干体重加上衣服重
  830. dry_weight["code"] = 0
  831. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  832. }
  833. }
  834. } else {
  835. if err != nil {
  836. dry_weight["code"] = 1
  837. dry_weight["dry_weight"] = nil
  838. } else {
  839. dry_weight["code"] = 0
  840. if getLPEErr != nil {
  841. dry_weight["code"] = 0
  842. dry_weight["dry_weight"] = weight.DryWeight
  843. } else {
  844. if lastPredialysisEvaluation == nil {
  845. dry_weight["code"] = 1
  846. dry_weight["dry_weight"] = weight.DryWeight
  847. } else {
  848. // 传输的干体重实际为干体重加上衣服重
  849. dry_weight["code"] = 0
  850. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  851. }
  852. }
  853. }
  854. }
  855. } else {
  856. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  857. if getPEErr != nil {
  858. dry_weight["code"] = 1
  859. dry_weight["dry_weight"] = nil
  860. } else {
  861. if predialysisEvaluation == nil {
  862. dry_weight["code"] = 1
  863. dry_weight["dry_weight"] = nil
  864. } else {
  865. dry_weight["code"] = 0
  866. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  867. }
  868. }
  869. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  870. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  871. if err == gorm.ErrRecordNotFound {
  872. if getLPEErr != nil {
  873. after_dry_weight["code"] = 1
  874. after_dry_weight["dry_weight"] = nil
  875. } else {
  876. if lastPredialysisEvaluation == nil {
  877. after_dry_weight["code"] = 1
  878. after_dry_weight["dry_weight"] = nil
  879. } else {
  880. // 传输的干体重实际为干体重加上衣服重
  881. after_dry_weight["code"] = 0
  882. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  883. }
  884. }
  885. } else {
  886. if err != nil {
  887. after_dry_weight["code"] = 1
  888. after_dry_weight["dry_weight"] = nil
  889. } else {
  890. after_dry_weight["code"] = 0
  891. if getLPEErr != nil {
  892. after_dry_weight["code"] = 0
  893. after_dry_weight["dry_weight"] = weight.DryWeight
  894. } else {
  895. if lastPredialysisEvaluation == nil {
  896. after_dry_weight["code"] = 1
  897. after_dry_weight["dry_weight"] = weight.DryWeight
  898. } else {
  899. // 传输的干体重实际为干体重加上衣服重
  900. after_dry_weight["code"] = 0
  901. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  902. }
  903. }
  904. }
  905. }
  906. }
  907. c.ServeSuccessJSON(map[string]interface{}{
  908. "dialysistype": dialysistype,
  909. "patient": dialysisinfo,
  910. "schedule": sc,
  911. "dryweight": dry_weight,
  912. "after_dry_weight": after_dry_weight,
  913. })
  914. return
  915. }
  916. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  917. id, _ := c.GetInt64("patient", 0)
  918. if id <= 0 {
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. adminUserInfo := c.GetMobileAdminUserInfo()
  923. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  924. if patient.ID == 0 {
  925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  926. return
  927. }
  928. var dialysisinfo map[string]interface{}
  929. dialysisinfo = make(map[string]interface{})
  930. dialysisinfo["id"] = patient.ID
  931. dialysisinfo["name"] = patient.Name
  932. dialysisinfo["dialysis_no"] = patient.DialysisNo
  933. thisTime := time.Now()
  934. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  935. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  936. fmt.Println(scheduleDateStart, scheduleDateEnd)
  937. timeLayout := "2006-01-02 15:04:05"
  938. loc, _ := time.LoadLocation("Local")
  939. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  940. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  941. fmt.Println(theStartTime, theEndTime)
  942. startTime := theStartTime.Unix()
  943. endTime := theEndTime.Unix()
  944. var sc map[string]interface{}
  945. sc = make(map[string]interface{})
  946. //一天只有排班一次
  947. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  948. if daySchedule.ID > 0 {
  949. switch daySchedule.ModeId {
  950. case 1:
  951. sc["mode"] = "HD"
  952. case 2:
  953. sc["mode"] = "HDF"
  954. case 3:
  955. sc["mode"] = "HD+HP"
  956. case 4:
  957. sc["mode"] = "HP"
  958. case 5:
  959. sc["mode"] = "HF"
  960. case 6:
  961. sc["mode"] = "SCUF"
  962. case 7:
  963. sc["mode"] = "IUF"
  964. case 8:
  965. sc["mode"] = "HFHD"
  966. case 9:
  967. sc["mode"] = "HFHD+HP"
  968. case 10:
  969. sc["mode"] = "PHF"
  970. case 11:
  971. sc["mode"] = "HFR"
  972. case 12:
  973. sc["mode"] = "HDF+HP"
  974. case 13:
  975. sc["mode"] = "CRRT"
  976. case 14:
  977. sc["mode"] = "腹水回输"
  978. case 15:
  979. sc["mode"] = "HD前置换"
  980. case 16:
  981. sc["mode"] = "HD后置换"
  982. case 17:
  983. sc["mode"] = "HDF前置换"
  984. case 18:
  985. sc["mode"] = "HDF后置换"
  986. default:
  987. sc["mode"] = "HD"
  988. }
  989. sc["code"] = 0
  990. sc["msg"] = ""
  991. sc["data"] = daySchedule
  992. } else {
  993. sc["code"] = 1
  994. sc["msg"] = "抱歉,您今天没有排版!"
  995. sc["mode"] = ""
  996. sc["data"] = daySchedule
  997. }
  998. fmt.Println(sc)
  999. type dryWeight struct {
  1000. code int
  1001. dry_weight float64
  1002. }
  1003. var dry_weight map[string]interface{}
  1004. dry_weight = make(map[string]interface{})
  1005. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1006. if getLPEErr != nil {
  1007. dry_weight["code"] = 1
  1008. dry_weight["dry_weight"] = nil
  1009. } else {
  1010. if lastPredialysisEvaluation == nil {
  1011. dry_weight["code"] = 1
  1012. dry_weight["dry_weight"] = nil
  1013. } else {
  1014. dry_weight["code"] = 0
  1015. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1016. }
  1017. }
  1018. c.ServeSuccessJSON(map[string]interface{}{
  1019. "patient": dialysisinfo,
  1020. "schedule": sc,
  1021. "dryweight": dry_weight,
  1022. })
  1023. return
  1024. }