check_weight_api_controller.go 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. package mobile_api_controllers
  2. import (
  3. "Xcx_New/enums"
  4. "Xcx_New/models"
  5. "Xcx_New/service"
  6. _ "Xcx_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 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 {
  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.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  373. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  374. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  375. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  376. newprescribe.CreatedTime = time.Now().Unix()
  377. newprescribe.UpdatedTime = time.Now().Unix()
  378. newprescribe.RecordDate = theAssessmentDateTime
  379. newprescribe.DewaterAmount = dewater_amount
  380. newprescribe.TargetUltrafiltration = dewater_amount
  381. newprescribe.Status = 1
  382. err := service.AddSigleRecord(&newprescribe)
  383. if err != nil {
  384. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  385. }
  386. }
  387. if dialysisPrescribe == nil && dialysisSolution == nil {
  388. if lastDialysisPrescribe != nil {
  389. var newprescribe models.DialysisPrescription
  390. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  391. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  392. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  393. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  394. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  395. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  396. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  397. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  398. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  399. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  400. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  401. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  402. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  403. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  404. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  405. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  406. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  407. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  408. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  409. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  410. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  411. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  412. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  413. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  414. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  415. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  416. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  417. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  418. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  419. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  420. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  421. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  422. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  423. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  424. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  425. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  426. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  427. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  428. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  429. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  430. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  431. newprescribe.CreatedTime = time.Now().Unix()
  432. newprescribe.UpdatedTime = time.Now().Unix()
  433. newprescribe.RecordDate = theAssessmentDateTime
  434. newprescribe.DewaterAmount = dewater_amount
  435. newprescribe.TargetUltrafiltration = dewater_amount
  436. newprescribe.Status = 1
  437. err := service.AddSigleRecord(&newprescribe)
  438. if err != nil {
  439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  440. }
  441. } else if system_dialysisPrescribe != nil {
  442. var newprescribe models.DialysisPrescription
  443. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  444. newprescribe.PatientId = id
  445. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  446. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  447. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  448. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  449. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  450. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  451. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  452. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  453. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  454. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  455. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  456. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  457. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  458. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  459. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  460. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  461. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  462. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  463. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  464. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  465. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  466. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  467. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  468. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  469. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  470. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  471. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  472. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  473. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  474. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  475. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  476. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  477. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  478. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  479. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  480. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  481. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  482. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  483. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  484. newprescribe.CreatedTime = time.Now().Unix()
  485. newprescribe.UpdatedTime = time.Now().Unix()
  486. newprescribe.RecordDate = theAssessmentDateTime
  487. newprescribe.DewaterAmount = dewater_amount
  488. newprescribe.TargetUltrafiltration = dewater_amount
  489. newprescribe.Status = 1
  490. fmt.Println(newprescribe.DewaterAmount)
  491. fmt.Println(newprescribe.TargetUltrafiltration)
  492. err := service.AddSigleRecord(&newprescribe)
  493. if err != nil {
  494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  495. }
  496. } else {
  497. var newprescribe models.DialysisPrescription
  498. newprescribe.UserOrgId = adminUserInfo.Org.Id
  499. newprescribe.PatientId = id
  500. newprescribe.ModeId = mode_id
  501. newprescribe.CreatedTime = time.Now().Unix()
  502. newprescribe.UpdatedTime = time.Now().Unix()
  503. newprescribe.RecordDate = theAssessmentDateTime
  504. newprescribe.DewaterAmount = dewater_amount
  505. newprescribe.TargetUltrafiltration = dewater_amount
  506. newprescribe.Status = 1
  507. err := service.AddSigleRecord(&newprescribe)
  508. if err != nil {
  509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  510. }
  511. }
  512. }
  513. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  514. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  515. dialysisPrescribe.RecordDate = theAssessmentDateTime
  516. dialysisPrescribe.DewaterAmount = dewater_amount
  517. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  518. dialysisPrescribe.Status = 1
  519. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  520. if updateErr != nil {
  521. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  522. }
  523. }
  524. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  525. if getPEErr != nil {
  526. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  528. return
  529. }
  530. var evaluation models.PredialysisEvaluation
  531. if theEvaluation != nil {
  532. evaluation = *theEvaluation
  533. }
  534. // 如果今天没有透前评估,则插入新的数据
  535. if theEvaluation == nil {
  536. evaluation.CreatedTime = time.Now().Unix()
  537. evaluation.Status = 1
  538. evaluation.AssessmentDate = theAssessmentDateTime
  539. evaluation.PatientId = id
  540. evaluation.UserOrgId = adminUserInfo.Org.Id
  541. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  542. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  543. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  544. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  545. if getAADErr != nil {
  546. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  548. return
  549. }
  550. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  551. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  552. if err == gorm.ErrRecordNotFound {
  553. if lastPredialysisEvaluation != nil {
  554. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  555. } else {
  556. evaluation.DryWeight = 0
  557. }
  558. } else {
  559. evaluation.DryWeight = weight.DryWeight
  560. }
  561. if assessmentAfterDislysis != nil {
  562. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  563. }
  564. if lastPredialysisEvaluation != nil {
  565. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  566. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  567. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  568. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  569. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  570. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  571. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  572. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  573. evaluation.Complication = lastPredialysisEvaluation.Complication
  574. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  575. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  576. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  577. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  578. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  579. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  580. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  581. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  582. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  583. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  584. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  585. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  586. }
  587. } else {
  588. evaluation.UpdatedTime = time.Now().Unix()
  589. }
  590. evaluation.WeightBefore = weighing_before
  591. evaluation.AssessmentTime = time.Now().Unix()
  592. err := service.UpadatePredialysisEvaluation(&evaluation)
  593. if err != nil {
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  595. return
  596. }
  597. c.ServeSuccessJSON(map[string]interface{}{
  598. "msg": "ok",
  599. "evaluation": evaluation,
  600. })
  601. return
  602. } else {
  603. // 保存透后相关数据
  604. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysis(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  605. if getAADErr != nil {
  606. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  608. return
  609. }
  610. var afterevaluation models.AssessmentAfterDislysis
  611. if assessmentAfterDislysis != nil {
  612. afterevaluation = *assessmentAfterDislysis
  613. }
  614. if assessmentAfterDislysis == nil {
  615. afterevaluation.CreatedTime = time.Now().Unix()
  616. afterevaluation.Status = 1
  617. afterevaluation.AssessmentDate = theAssessmentDateTime
  618. afterevaluation.PatientId = id
  619. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  620. } else {
  621. afterevaluation.UpdatedTime = time.Now().Unix()
  622. }
  623. afterevaluation.WeightAfter = weight_after
  624. afterevaluation.WeightLoss = weight_loss
  625. // if (adminUserInfo.Org.Id == 9538){
  626. // afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  627. // } else {
  628. // afterevaluation.ActualUltrafiltration = weight_loss // 计量单位是L
  629. // }
  630. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  631. if err == nil {
  632. c.ServeSuccessJSON(map[string]interface{}{
  633. "assessmentAfterDislysis": afterevaluation,
  634. })
  635. }
  636. }
  637. }
  638. func (c *CheckWeightApiController) SetSyncTime() {
  639. sn := c.GetString("sn")
  640. if len(sn) > 0 {
  641. redis := service.RedisClient()
  642. defer redis.Close()
  643. redis.Set(sn, 0, 0)
  644. }
  645. serviceTime := time.Now().Unix()
  646. c.ServeSuccessJSON(map[string]interface{}{
  647. "status": 1,
  648. "servicetime": serviceTime,
  649. })
  650. }
  651. func (c *CheckWeightApiController) GetPatientList() {
  652. ftype, _ := c.GetInt64("type", 0)
  653. sn := c.GetString("sn")
  654. syncTime := int64(0)
  655. redis := service.RedisClient()
  656. defer redis.Close()
  657. if len(sn) > 0 {
  658. syncTimeStr, _ := redis.Get(sn).Result()
  659. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  660. }
  661. if ftype == 1 {
  662. timeNow := time.Now().Unix()
  663. redis.Set(sn, timeNow, 0)
  664. }
  665. adminUserInfo := c.GetMobileAdminUserInfo()
  666. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  667. need_update := 0
  668. if syncTime == 0 {
  669. need_update = 1
  670. }
  671. if error != nil {
  672. c.ErrorLog("获取病人列表失败:%v", error)
  673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  674. return
  675. }
  676. serviceTime := time.Now().Unix()
  677. c.ServeSuccessJSON(map[string]interface{}{
  678. "need_update": need_update,
  679. "patientlist": patientList,
  680. "total": total,
  681. "servicetime": serviceTime,
  682. })
  683. }
  684. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  685. thisTime := time.Now()
  686. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  687. timeLayout := "2006-01-02 15:04:05"
  688. loc, _ := time.LoadLocation("Local")
  689. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  690. syncTime := theStartTime.Unix()
  691. adminUserInfo := c.GetMobileAdminUserInfo()
  692. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  693. patientSchedule := make([]map[string]interface{}, 0)
  694. for _, item := range patientList {
  695. patientTemp := make(map[string]interface{})
  696. patientTemp["patient_id"] = item.PatientId
  697. patientTemp["patient_name"] = item.Patient.Name
  698. patientTemp["schedule_type"] = item.ScheduleType
  699. patientSchedule = append(patientSchedule, patientTemp)
  700. }
  701. if error != nil {
  702. c.ErrorLog("获取病人列表失败:%v", error)
  703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  704. return
  705. }
  706. serviceTime := time.Now().Unix()
  707. c.ServeSuccessJSON(map[string]interface{}{
  708. "patientlist": patientSchedule,
  709. "total": total,
  710. "servicetime": serviceTime,
  711. })
  712. }
  713. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  714. patient_name := c.GetString("patient_name") //脉率
  715. thisTime := time.Now()
  716. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  717. timeLayout := "2006-01-02 15:04:05"
  718. loc, _ := time.LoadLocation("Local")
  719. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  720. syncTime := theStartTime.Unix()
  721. adminUserInfo := c.GetMobileAdminUserInfo()
  722. if len(patient_name) == 0 {
  723. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  724. patientSchedule := make([]map[string]interface{}, 0)
  725. for _, item := range patientList {
  726. patientTemp := make(map[string]interface{})
  727. patientTemp["patient_id"] = item.PatientId
  728. patientTemp["patient_name"] = item.Patient.Name
  729. patientTemp["schedule_type"] = item.ScheduleType
  730. patientSchedule = append(patientSchedule, patientTemp)
  731. }
  732. if error != nil {
  733. c.ErrorLog("获取病人列表失败:%v", error)
  734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  735. return
  736. }
  737. serviceTime := time.Now().Unix()
  738. c.ServeSuccessJSON(map[string]interface{}{
  739. "patientlist": patientSchedule,
  740. "total": total,
  741. "servicetime": serviceTime,
  742. })
  743. } else {
  744. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  745. patientSchedule := make([]map[string]interface{}, 0)
  746. for _, item := range patientList {
  747. if item.Patient.ID > 0 {
  748. patientTemp := make(map[string]interface{})
  749. patientTemp["patient_id"] = item.PatientId
  750. patientTemp["patient_name"] = item.Patient.Name
  751. patientTemp["schedule_type"] = item.ScheduleType
  752. patientSchedule = append(patientSchedule, patientTemp)
  753. }
  754. }
  755. if error != nil {
  756. c.ErrorLog("获取病人列表失败:%v", error)
  757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  758. return
  759. }
  760. serviceTime := time.Now().Unix()
  761. c.ServeSuccessJSON(map[string]interface{}{
  762. "patientlist": patientSchedule,
  763. "total": total,
  764. "servicetime": serviceTime,
  765. })
  766. }
  767. }
  768. func (c *CheckWeightApiController) GetPatientListById() {
  769. patientId, _ := c.GetInt64("patient_id", 0)
  770. if patientId <= 0 {
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. adminUserInfo := c.GetMobileAdminUserInfo()
  775. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  776. if error != nil {
  777. c.ErrorLog("获取病人详情失败:%v", error)
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  779. return
  780. }
  781. c.ServeSuccessJSON(map[string]interface{}{
  782. "patientinfo": patient,
  783. })
  784. }
  785. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  786. id, _ := c.GetInt64("patient", 0)
  787. if id <= 0 {
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  789. return
  790. }
  791. adminUserInfo := c.GetMobileAdminUserInfo()
  792. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  793. if patient.ID <= 0 {
  794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  795. return
  796. }
  797. var dialysisinfo map[string]interface{}
  798. dialysisinfo = make(map[string]interface{})
  799. dialysisinfo["id"] = patient.ID
  800. dialysisinfo["name"] = patient.Name
  801. dialysisinfo["dialysis_no"] = patient.DialysisNo
  802. thisTime := time.Now()
  803. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  804. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  805. timeLayout := "2006-01-02 15:04:05"
  806. loc, _ := time.LoadLocation("Local")
  807. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  808. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  809. startTime := theStartTime.Unix()
  810. endTime := theEndTime.Unix()
  811. // 判断当前用户是透析前还是透析后
  812. var dialysistype int
  813. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  814. if dialysisOrder == nil {
  815. dialysistype = 1
  816. } else {
  817. dialysistype = 2
  818. }
  819. // 获取当前或者下次排班信息
  820. var sc map[string]interface{}
  821. sc = make(map[string]interface{})
  822. if dialysistype == 1 {
  823. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  824. if len(daySchedule) <= 0 {
  825. sc["code"] = 1
  826. sc["msg"] = "抱歉,您今天没有排版!"
  827. sc["mode"] = 0
  828. sc["data"] = daySchedule
  829. } else {
  830. if daySchedule[0].Schedule.ID > 0 {
  831. sc["code"] = 0
  832. sc["msg"] = ""
  833. sc["mode"] = daySchedule[0].Schedule.ModeId
  834. sc["data"] = daySchedule
  835. } else {
  836. sc["code"] = 1
  837. sc["msg"] = "抱歉,您今天没有排版!"
  838. sc["mode"] = 0
  839. sc["data"] = daySchedule
  840. }
  841. }
  842. // 排队叫号的签到
  843. go func() {
  844. ssoDomain := beego.AppConfig.String("call_domain")
  845. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  846. values := make(url.Values)
  847. http.PostForm(api, values)
  848. }()
  849. } else {
  850. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  851. if len(nextSchedule) <= 0 {
  852. sc["code"] = 1
  853. sc["msg"] = "抱歉,您后续没有排版!"
  854. sc["mode"] = 0
  855. sc["data"] = nextSchedule
  856. } else {
  857. if nextSchedule[0].Schedule.ID > 0 {
  858. sc["code"] = 0
  859. sc["msg"] = ""
  860. sc["mode"] = nextSchedule[0].Schedule.ModeId
  861. sc["data"] = nextSchedule
  862. } else {
  863. sc["code"] = 1
  864. sc["msg"] = "抱歉,您后续没有排版!"
  865. sc["mode"] = 0
  866. sc["data"] = nextSchedule
  867. }
  868. }
  869. }
  870. switch sc["mode"] {
  871. case 1:
  872. sc["mode"] = "HD"
  873. case 2:
  874. sc["mode"] = "HDF"
  875. case 3:
  876. sc["mode"] = "HD+HP"
  877. case 4:
  878. sc["mode"] = "HP"
  879. case 5:
  880. sc["mode"] = "HF"
  881. case 6:
  882. sc["mode"] = "SCUF"
  883. case 7:
  884. sc["mode"] = "IUF"
  885. case 8:
  886. sc["mode"] = "HFHD"
  887. case 9:
  888. sc["mode"] = "HFHD+HP"
  889. case 10:
  890. sc["mode"] = "PHF"
  891. case 11:
  892. sc["mode"] = "HFR"
  893. case 12:
  894. sc["mode"] = "HDF+HP"
  895. case 13:
  896. sc["mode"] = "CRRT"
  897. case 14:
  898. sc["mode"] = "腹水回输"
  899. case 15:
  900. sc["mode"] = "HD前置换"
  901. case 16:
  902. sc["mode"] = "HD后置换"
  903. case 17:
  904. sc["mode"] = "HDF前置换"
  905. case 18:
  906. sc["mode"] = "HDF后置换"
  907. default:
  908. sc["mode"] = "HD"
  909. }
  910. // 获取患者透前干体重或者获取患者透前体重
  911. var dry_weight map[string]interface{}
  912. dry_weight = make(map[string]interface{})
  913. var after_dry_weight map[string]interface{}
  914. after_dry_weight = make(map[string]interface{})
  915. if dialysistype == 1 {
  916. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  917. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  918. if err == gorm.ErrRecordNotFound {
  919. if getLPEErr != nil {
  920. dry_weight["code"] = 1
  921. dry_weight["dry_weight"] = nil
  922. } else {
  923. if lastPredialysisEvaluation == nil {
  924. dry_weight["code"] = 1
  925. dry_weight["dry_weight"] = nil
  926. } else {
  927. // 传输的干体重实际为干体重加上衣服重
  928. dry_weight["code"] = 0
  929. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  930. }
  931. }
  932. } else {
  933. if err != nil {
  934. dry_weight["code"] = 1
  935. dry_weight["dry_weight"] = nil
  936. } else {
  937. dry_weight["code"] = 0
  938. if getLPEErr != nil {
  939. dry_weight["code"] = 0
  940. dry_weight["dry_weight"] = weight.DryWeight
  941. } else {
  942. if lastPredialysisEvaluation == nil {
  943. dry_weight["code"] = 1
  944. dry_weight["dry_weight"] = weight.DryWeight
  945. } else {
  946. // 传输的干体重实际为干体重加上衣服重
  947. dry_weight["code"] = 0
  948. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  949. }
  950. }
  951. }
  952. }
  953. } else {
  954. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  955. if getPEErr != nil {
  956. dry_weight["code"] = 1
  957. dry_weight["dry_weight"] = nil
  958. } else {
  959. if predialysisEvaluation == nil {
  960. dry_weight["code"] = 1
  961. dry_weight["dry_weight"] = nil
  962. } else {
  963. dry_weight["code"] = 0
  964. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  965. }
  966. }
  967. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  968. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  969. if err == gorm.ErrRecordNotFound {
  970. if getLPEErr != nil {
  971. after_dry_weight["code"] = 1
  972. after_dry_weight["dry_weight"] = nil
  973. } else {
  974. if lastPredialysisEvaluation == nil {
  975. after_dry_weight["code"] = 1
  976. after_dry_weight["dry_weight"] = nil
  977. } else {
  978. // 传输的干体重实际为干体重加上衣服重
  979. after_dry_weight["code"] = 0
  980. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  981. }
  982. }
  983. } else {
  984. if err != nil {
  985. after_dry_weight["code"] = 1
  986. after_dry_weight["dry_weight"] = nil
  987. } else {
  988. after_dry_weight["code"] = 0
  989. if getLPEErr != nil {
  990. after_dry_weight["code"] = 0
  991. after_dry_weight["dry_weight"] = weight.DryWeight
  992. } else {
  993. if lastPredialysisEvaluation == nil {
  994. after_dry_weight["code"] = 1
  995. after_dry_weight["dry_weight"] = weight.DryWeight
  996. } else {
  997. // 传输的干体重实际为干体重加上衣服重
  998. after_dry_weight["code"] = 0
  999. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1000. }
  1001. }
  1002. }
  1003. }
  1004. }
  1005. c.ServeSuccessJSON(map[string]interface{}{
  1006. "dialysistype": dialysistype,
  1007. "patient": dialysisinfo,
  1008. "schedule": sc,
  1009. "dryweight": dry_weight,
  1010. "after_dry_weight": after_dry_weight,
  1011. })
  1012. return
  1013. }
  1014. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1015. id, _ := c.GetInt64("patient", 0)
  1016. if id <= 0 {
  1017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1018. return
  1019. }
  1020. adminUserInfo := c.GetMobileAdminUserInfo()
  1021. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1022. if patient.ID == 0 {
  1023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1024. return
  1025. }
  1026. var dialysisinfo map[string]interface{}
  1027. dialysisinfo = make(map[string]interface{})
  1028. dialysisinfo["id"] = patient.ID
  1029. dialysisinfo["name"] = patient.Name
  1030. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1031. thisTime := time.Now()
  1032. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1033. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1034. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1035. timeLayout := "2006-01-02 15:04:05"
  1036. loc, _ := time.LoadLocation("Local")
  1037. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1038. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1039. fmt.Println(theStartTime, theEndTime)
  1040. startTime := theStartTime.Unix()
  1041. endTime := theEndTime.Unix()
  1042. var sc map[string]interface{}
  1043. sc = make(map[string]interface{})
  1044. //一天只有排班一次
  1045. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1046. if daySchedule.ID > 0 {
  1047. switch daySchedule.ModeId {
  1048. case 1:
  1049. sc["mode"] = "HD"
  1050. case 2:
  1051. sc["mode"] = "HDF"
  1052. case 3:
  1053. sc["mode"] = "HD+HP"
  1054. case 4:
  1055. sc["mode"] = "HP"
  1056. case 5:
  1057. sc["mode"] = "HF"
  1058. case 6:
  1059. sc["mode"] = "SCUF"
  1060. case 7:
  1061. sc["mode"] = "IUF"
  1062. case 8:
  1063. sc["mode"] = "HFHD"
  1064. case 9:
  1065. sc["mode"] = "HFHD+HP"
  1066. case 10:
  1067. sc["mode"] = "PHF"
  1068. case 11:
  1069. sc["mode"] = "HFR"
  1070. case 12:
  1071. sc["mode"] = "HDF+HP"
  1072. case 13:
  1073. sc["mode"] = "CRRT"
  1074. case 14:
  1075. sc["mode"] = "腹水回输"
  1076. case 15:
  1077. sc["mode"] = "HD前置换"
  1078. case 16:
  1079. sc["mode"] = "HD后置换"
  1080. case 17:
  1081. sc["mode"] = "HDF前置换"
  1082. case 18:
  1083. sc["mode"] = "HDF后置换"
  1084. default:
  1085. sc["mode"] = "HD"
  1086. }
  1087. sc["code"] = 0
  1088. sc["msg"] = ""
  1089. sc["data"] = daySchedule
  1090. } else {
  1091. sc["code"] = 1
  1092. sc["msg"] = "抱歉,您今天没有排版!"
  1093. sc["mode"] = ""
  1094. sc["data"] = daySchedule
  1095. }
  1096. fmt.Println(sc)
  1097. type dryWeight struct {
  1098. code int
  1099. dry_weight float64
  1100. }
  1101. var dry_weight map[string]interface{}
  1102. dry_weight = make(map[string]interface{})
  1103. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1104. if getLPEErr != nil {
  1105. dry_weight["code"] = 1
  1106. dry_weight["dry_weight"] = nil
  1107. } else {
  1108. if lastPredialysisEvaluation == nil {
  1109. dry_weight["code"] = 1
  1110. dry_weight["dry_weight"] = nil
  1111. } else {
  1112. dry_weight["code"] = 0
  1113. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1114. }
  1115. }
  1116. c.ServeSuccessJSON(map[string]interface{}{
  1117. "patient": dialysisinfo,
  1118. "schedule": sc,
  1119. "dryweight": dry_weight,
  1120. })
  1121. return
  1122. }