check_weight_api_controller.go 37KB

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