check_weight_api_controller.go 46KB

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