check_weight_api_controller.go 38KB

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