check_weight_api_controller.go 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  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. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  659. if len(patientList) > 0 {
  660. need_update := 0
  661. if syncTime == 0 {
  662. need_update = 1
  663. }
  664. if error != nil {
  665. c.ErrorLog("获取病人列表失败:%v", error)
  666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  667. return
  668. }
  669. serviceTime := time.Now().Unix()
  670. c.ServeSuccessJSON(map[string]interface{}{
  671. "need_update": need_update,
  672. "patientlist": patientList,
  673. "total": total,
  674. "servicetime": serviceTime,
  675. })
  676. }
  677. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  678. thisTime := time.Now()
  679. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  680. timeLayout := "2006-01-02 15:04:05"
  681. loc, _ := time.LoadLocation("Local")
  682. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  683. syncTime := theStartTime.Unix()
  684. adminUserInfo := c.GetMobileAdminUserInfo()
  685. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  686. patientSchedule := make([]map[string]interface{}, 0)
  687. for _, item := range patientList {
  688. patientTemp := make(map[string]interface{})
  689. patientTemp["patient_id"] = item.PatientId
  690. patientTemp["patient_name"] = item.Patient.Name
  691. patientTemp["schedule_type"] = item.ScheduleType
  692. patientSchedule = append(patientSchedule, patientTemp)
  693. }
  694. if error != nil {
  695. c.ErrorLog("获取病人列表失败:%v", error)
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  697. return
  698. }
  699. serviceTime := time.Now().Unix()
  700. c.ServeSuccessJSON(map[string]interface{}{
  701. "patientlist": patientSchedule,
  702. "total": total,
  703. "servicetime": serviceTime,
  704. })
  705. }
  706. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  707. patient_name := c.GetString("patient_name") //脉率
  708. thisTime := time.Now()
  709. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  710. timeLayout := "2006-01-02 15:04:05"
  711. loc, _ := time.LoadLocation("Local")
  712. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  713. syncTime := theStartTime.Unix()
  714. adminUserInfo := c.GetMobileAdminUserInfo()
  715. if len(patient_name) == 0 {
  716. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  717. patientSchedule := make([]map[string]interface{}, 0)
  718. for _, item := range patientList {
  719. patientTemp := make(map[string]interface{})
  720. patientTemp["patient_id"] = item.PatientId
  721. patientTemp["patient_name"] = item.Patient.Name
  722. patientTemp["schedule_type"] = item.ScheduleType
  723. patientSchedule = append(patientSchedule, patientTemp)
  724. }
  725. if error != nil {
  726. c.ErrorLog("获取病人列表失败:%v", error)
  727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  728. return
  729. }
  730. serviceTime := time.Now().Unix()
  731. c.ServeSuccessJSON(map[string]interface{}{
  732. "patientlist": patientSchedule,
  733. "total": total,
  734. "servicetime": serviceTime,
  735. })
  736. } else {
  737. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  738. patientSchedule := make([]map[string]interface{}, 0)
  739. for _, item := range patientList {
  740. if item.Patient.ID > 0 {
  741. patientTemp := make(map[string]interface{})
  742. patientTemp["patient_id"] = item.PatientId
  743. patientTemp["patient_name"] = item.Patient.Name
  744. patientTemp["schedule_type"] = item.ScheduleType
  745. patientSchedule = append(patientSchedule, patientTemp)
  746. }
  747. }
  748. if error != nil {
  749. c.ErrorLog("获取病人列表失败:%v", error)
  750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  751. return
  752. }
  753. serviceTime := time.Now().Unix()
  754. c.ServeSuccessJSON(map[string]interface{}{
  755. "patientlist": patientSchedule,
  756. "total": total,
  757. "servicetime": serviceTime,
  758. })
  759. }
  760. }
  761. func (c *CheckWeightApiController) GetPatientListById() {
  762. patientId, _ := c.GetInt64("patient_id", 0)
  763. if patientId <= 0 {
  764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  765. return
  766. }
  767. adminUserInfo := c.GetMobileAdminUserInfo()
  768. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  769. if error != nil {
  770. c.ErrorLog("获取病人详情失败:%v", error)
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  772. return
  773. }
  774. c.ServeSuccessJSON(map[string]interface{}{
  775. "patientinfo": patient,
  776. })
  777. }
  778. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  779. id, _ := c.GetInt64("patient", 0)
  780. if id <= 0 {
  781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  782. return
  783. }
  784. adminUserInfo := c.GetMobileAdminUserInfo()
  785. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  786. if patient.ID <= 0 {
  787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  788. return
  789. }
  790. var dialysisinfo map[string]interface{}
  791. dialysisinfo = make(map[string]interface{})
  792. dialysisinfo["id"] = patient.ID
  793. dialysisinfo["name"] = patient.Name
  794. dialysisinfo["dialysis_no"] = patient.DialysisNo
  795. thisTime := time.Now()
  796. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  797. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  798. timeLayout := "2006-01-02 15:04:05"
  799. loc, _ := time.LoadLocation("Local")
  800. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  801. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  802. startTime := theStartTime.Unix()
  803. endTime := theEndTime.Unix()
  804. // 判断当前用户是透析前还是透析后
  805. var dialysistype int
  806. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  807. if dialysisOrder == nil {
  808. dialysistype = 1
  809. } else {
  810. dialysistype = 2
  811. }
  812. // 获取当前或者下次排班信息
  813. var sc map[string]interface{}
  814. sc = make(map[string]interface{})
  815. if dialysistype == 1 {
  816. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  817. if len(daySchedule) <= 0 {
  818. sc["code"] = 1
  819. sc["msg"] = "抱歉,您今天没有排版!"
  820. sc["mode"] = 0
  821. sc["data"] = daySchedule
  822. } else {
  823. if daySchedule[0].Schedule.ID > 0 {
  824. sc["code"] = 0
  825. sc["msg"] = ""
  826. sc["mode"] = daySchedule[0].Schedule.ModeId
  827. sc["data"] = daySchedule
  828. } else {
  829. sc["code"] = 1
  830. sc["msg"] = "抱歉,您今天没有排版!"
  831. sc["mode"] = 0
  832. sc["data"] = daySchedule
  833. }
  834. }
  835. // 排队叫号的签到
  836. go func() {
  837. ssoDomain := beego.AppConfig.String("call_domain")
  838. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  839. values := make(url.Values)
  840. http.PostForm(api, values)
  841. }()
  842. } else {
  843. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  844. if len(nextSchedule) <= 0 {
  845. sc["code"] = 1
  846. sc["msg"] = "抱歉,您后续没有排版!"
  847. sc["mode"] = 0
  848. sc["data"] = nextSchedule
  849. } else {
  850. if nextSchedule[0].Schedule.ID > 0 {
  851. sc["code"] = 0
  852. sc["msg"] = ""
  853. sc["mode"] = nextSchedule[0].Schedule.ModeId
  854. sc["data"] = nextSchedule
  855. } else {
  856. sc["code"] = 1
  857. sc["msg"] = "抱歉,您后续没有排版!"
  858. sc["mode"] = 0
  859. sc["data"] = nextSchedule
  860. }
  861. }
  862. }
  863. switch sc["mode"] {
  864. case 1:
  865. sc["mode"] = "HD"
  866. case 2:
  867. sc["mode"] = "HDF"
  868. case 3:
  869. sc["mode"] = "HD+HP"
  870. case 4:
  871. sc["mode"] = "HP"
  872. case 5:
  873. sc["mode"] = "HF"
  874. case 6:
  875. sc["mode"] = "SCUF"
  876. case 7:
  877. sc["mode"] = "IUF"
  878. case 8:
  879. sc["mode"] = "HFHD"
  880. case 9:
  881. sc["mode"] = "HFHD+HP"
  882. case 10:
  883. sc["mode"] = "PHF"
  884. case 11:
  885. sc["mode"] = "HFR"
  886. case 12:
  887. sc["mode"] = "HDF+HP"
  888. case 13:
  889. sc["mode"] = "CRRT"
  890. case 14:
  891. sc["mode"] = "腹水回输"
  892. case 15:
  893. sc["mode"] = "HD前置换"
  894. case 16:
  895. sc["mode"] = "HD后置换"
  896. case 17:
  897. sc["mode"] = "HDF前置换"
  898. case 18:
  899. sc["mode"] = "HDF后置换"
  900. default:
  901. sc["mode"] = "HD"
  902. }
  903. // 获取患者透前干体重或者获取患者透前体重
  904. var dry_weight map[string]interface{}
  905. dry_weight = make(map[string]interface{})
  906. var after_dry_weight map[string]interface{}
  907. after_dry_weight = make(map[string]interface{})
  908. if dialysistype == 1 {
  909. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  910. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  911. if err == gorm.ErrRecordNotFound {
  912. if getLPEErr != nil {
  913. dry_weight["code"] = 1
  914. dry_weight["dry_weight"] = nil
  915. } else {
  916. if lastPredialysisEvaluation == nil {
  917. dry_weight["code"] = 1
  918. dry_weight["dry_weight"] = nil
  919. } else {
  920. // 传输的干体重实际为干体重加上衣服重
  921. dry_weight["code"] = 0
  922. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  923. }
  924. }
  925. } else {
  926. if err != nil {
  927. dry_weight["code"] = 1
  928. dry_weight["dry_weight"] = nil
  929. } else {
  930. dry_weight["code"] = 0
  931. if getLPEErr != nil {
  932. dry_weight["code"] = 0
  933. dry_weight["dry_weight"] = weight.DryWeight
  934. } else {
  935. if lastPredialysisEvaluation == nil {
  936. dry_weight["code"] = 1
  937. dry_weight["dry_weight"] = weight.DryWeight
  938. } else {
  939. // 传输的干体重实际为干体重加上衣服重
  940. dry_weight["code"] = 0
  941. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  942. }
  943. }
  944. }
  945. }
  946. } else {
  947. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  948. if getPEErr != nil {
  949. dry_weight["code"] = 1
  950. dry_weight["dry_weight"] = nil
  951. } else {
  952. if predialysisEvaluation == nil {
  953. dry_weight["code"] = 1
  954. dry_weight["dry_weight"] = nil
  955. } else {
  956. dry_weight["code"] = 0
  957. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  958. }
  959. }
  960. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  961. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  962. if err == gorm.ErrRecordNotFound {
  963. if getLPEErr != nil {
  964. after_dry_weight["code"] = 1
  965. after_dry_weight["dry_weight"] = nil
  966. } else {
  967. if lastPredialysisEvaluation == nil {
  968. after_dry_weight["code"] = 1
  969. after_dry_weight["dry_weight"] = nil
  970. } else {
  971. // 传输的干体重实际为干体重加上衣服重
  972. after_dry_weight["code"] = 0
  973. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  974. }
  975. }
  976. } else {
  977. if err != nil {
  978. after_dry_weight["code"] = 1
  979. after_dry_weight["dry_weight"] = nil
  980. } else {
  981. after_dry_weight["code"] = 0
  982. if getLPEErr != nil {
  983. after_dry_weight["code"] = 0
  984. after_dry_weight["dry_weight"] = weight.DryWeight
  985. } else {
  986. if lastPredialysisEvaluation == nil {
  987. after_dry_weight["code"] = 1
  988. after_dry_weight["dry_weight"] = weight.DryWeight
  989. } else {
  990. // 传输的干体重实际为干体重加上衣服重
  991. after_dry_weight["code"] = 0
  992. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  993. }
  994. }
  995. }
  996. }
  997. }
  998. c.ServeSuccessJSON(map[string]interface{}{
  999. "dialysistype": dialysistype,
  1000. "patient": dialysisinfo,
  1001. "schedule": sc,
  1002. "dryweight": dry_weight,
  1003. "after_dry_weight": after_dry_weight,
  1004. })
  1005. return
  1006. }
  1007. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1008. id, _ := c.GetInt64("patient", 0)
  1009. if id <= 0 {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. adminUserInfo := c.GetMobileAdminUserInfo()
  1014. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1015. if patient.ID == 0 {
  1016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1017. return
  1018. }
  1019. var dialysisinfo map[string]interface{}
  1020. dialysisinfo = make(map[string]interface{})
  1021. dialysisinfo["id"] = patient.ID
  1022. dialysisinfo["name"] = patient.Name
  1023. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1024. thisTime := time.Now()
  1025. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1026. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1027. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1028. timeLayout := "2006-01-02 15:04:05"
  1029. loc, _ := time.LoadLocation("Local")
  1030. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1031. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1032. fmt.Println(theStartTime, theEndTime)
  1033. startTime := theStartTime.Unix()
  1034. endTime := theEndTime.Unix()
  1035. var sc map[string]interface{}
  1036. sc = make(map[string]interface{})
  1037. //一天只有排班一次
  1038. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1039. if daySchedule.ID > 0 {
  1040. switch daySchedule.ModeId {
  1041. case 1:
  1042. sc["mode"] = "HD"
  1043. case 2:
  1044. sc["mode"] = "HDF"
  1045. case 3:
  1046. sc["mode"] = "HD+HP"
  1047. case 4:
  1048. sc["mode"] = "HP"
  1049. case 5:
  1050. sc["mode"] = "HF"
  1051. case 6:
  1052. sc["mode"] = "SCUF"
  1053. case 7:
  1054. sc["mode"] = "IUF"
  1055. case 8:
  1056. sc["mode"] = "HFHD"
  1057. case 9:
  1058. sc["mode"] = "HFHD+HP"
  1059. case 10:
  1060. sc["mode"] = "PHF"
  1061. case 11:
  1062. sc["mode"] = "HFR"
  1063. case 12:
  1064. sc["mode"] = "HDF+HP"
  1065. case 13:
  1066. sc["mode"] = "CRRT"
  1067. case 14:
  1068. sc["mode"] = "腹水回输"
  1069. case 15:
  1070. sc["mode"] = "HD前置换"
  1071. case 16:
  1072. sc["mode"] = "HD后置换"
  1073. case 17:
  1074. sc["mode"] = "HDF前置换"
  1075. case 18:
  1076. sc["mode"] = "HDF后置换"
  1077. default:
  1078. sc["mode"] = "HD"
  1079. }
  1080. sc["code"] = 0
  1081. sc["msg"] = ""
  1082. sc["data"] = daySchedule
  1083. } else {
  1084. sc["code"] = 1
  1085. sc["msg"] = "抱歉,您今天没有排版!"
  1086. sc["mode"] = ""
  1087. sc["data"] = daySchedule
  1088. }
  1089. fmt.Println(sc)
  1090. type dryWeight struct {
  1091. code int
  1092. dry_weight float64
  1093. }
  1094. var dry_weight map[string]interface{}
  1095. dry_weight = make(map[string]interface{})
  1096. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1097. if getLPEErr != nil {
  1098. dry_weight["code"] = 1
  1099. dry_weight["dry_weight"] = nil
  1100. } else {
  1101. if lastPredialysisEvaluation == nil {
  1102. dry_weight["code"] = 1
  1103. dry_weight["dry_weight"] = nil
  1104. } else {
  1105. dry_weight["code"] = 0
  1106. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1107. }
  1108. }
  1109. c.ServeSuccessJSON(map[string]interface{}{
  1110. "patient": dialysisinfo,
  1111. "schedule": sc,
  1112. "dryweight": dry_weight,
  1113. })
  1114. return
  1115. }