check_weight_api_controller.go 43KB

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