check_weight_api_controller.go 41KB

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