check_weight_api_controller.go 37KB

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