check_weight_api_controller.go 40KB

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