check_weight_api_controller.go 57KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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. _ "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. _ "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "net/http"
  14. "net/url"
  15. "strconv"
  16. _ "strings"
  17. // "fmt"
  18. _ "reflect"
  19. "time"
  20. )
  21. type CheckWeightApiController struct {
  22. MobileBaseAPIAuthController
  23. }
  24. func (c *CheckWeightApiController) SaveBloodPressure() {
  25. id, _ := c.GetInt64("patient", 0)
  26. dialysistype, _ := c.GetInt64("dialysistype", 0)
  27. systolic_blood_pressure, _ := c.GetFloat("systolic_blood_pressure", 0) //收缩压
  28. diastolic_blood_pressure, _ := c.GetFloat("diastolic_blood_pressure", 0) //舒张压
  29. pulse_frequency, _ := c.GetFloat("pulse_frequency", 0) //脉率
  30. if id <= 0 {
  31. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  32. return
  33. }
  34. if dialysistype <= 0 {
  35. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  36. return
  37. }
  38. if systolic_blood_pressure <= 0 {
  39. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  40. return
  41. }
  42. if diastolic_blood_pressure <= 0 {
  43. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  44. return
  45. }
  46. adminUserInfo := c.GetMobileAdminUserInfo()
  47. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  48. if patient.ID == 0 {
  49. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  50. return
  51. }
  52. thisTime := time.Now()
  53. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  54. timeLayout := "2006-01-02 15:04:05"
  55. loc, _ := time.LoadLocation("Local")
  56. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  57. theAssessmentDateTime := theStartTime.Unix()
  58. if dialysistype == 1 {
  59. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  60. if getPEErr != nil {
  61. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  62. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  63. return
  64. }
  65. var evaluation models.PredialysisEvaluation
  66. if theEvaluation != nil {
  67. evaluation = *theEvaluation
  68. }
  69. // 如果今天没有透前评估,则插入新的数据
  70. if theEvaluation == nil {
  71. evaluation.CreatedTime = time.Now().Unix()
  72. evaluation.Status = 1
  73. evaluation.AssessmentDate = theAssessmentDateTime
  74. evaluation.PatientId = id
  75. evaluation.UserOrgId = adminUserInfo.Org.Id
  76. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  77. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  78. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  79. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  80. if getAADErr != nil {
  81. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  82. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  83. return
  84. }
  85. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  86. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  87. if err == gorm.ErrRecordNotFound {
  88. if lastPredialysisEvaluation != nil {
  89. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  90. } else {
  91. evaluation.DryWeight = 0
  92. }
  93. } else {
  94. evaluation.DryWeight = weight.DryWeight
  95. }
  96. if assessmentAfterDislysis != nil {
  97. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  98. }
  99. if lastPredialysisEvaluation != nil {
  100. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  101. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  102. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight // 衣物重
  103. //从化益达 备注默认上一次数据
  104. if adminUserInfo.Org.Id == 10318 {
  105. evaluation.Remark = lastPredialysisEvaluation.Remark
  106. }
  107. }
  108. } else {
  109. evaluation.UpdatedTime = time.Now().Unix()
  110. }
  111. evaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  112. evaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  113. evaluation.PulseFrequency = pulse_frequency // 脉率
  114. evaluation.AssessmentTime = time.Now().Unix()
  115. err := service.UpadatePredialysisEvaluation(&evaluation)
  116. //记录日志
  117. byterequest, _ := json.Marshal(evaluation)
  118. assessmentBeforeDislysisLog := models.XtAssessmentBeforeDislysisLog{
  119. UserOrgId: adminUserInfo.Org.Id,
  120. AdminUserId: adminUserInfo.AdminUser.Id,
  121. ErrLog: string(byterequest),
  122. PatientId: evaluation.PatientId,
  123. RecordDate: evaluation.AssessmentDate,
  124. Ctime: time.Now().Unix(),
  125. Mtime: 0,
  126. Status: 1,
  127. Source: "物联网上传透前血压",
  128. }
  129. service.CreateBeforLog(assessmentBeforeDislysisLog)
  130. assessdateDateStart := thisTime.Format("2006-01-02")
  131. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  132. redis := service.RedisClient()
  133. defer redis.Close()
  134. //清空key 值
  135. redis.Set(key, "", time.Second)
  136. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  137. redis.Set(keyOne, "", time.Second)
  138. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  139. redis.Set(keyTwo, "", time.Second)
  140. redis.Close()
  141. if err != nil {
  142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  143. return
  144. }
  145. c.ServeSuccessJSON(map[string]interface{}{
  146. "msg": "ok",
  147. "evaluation": evaluation,
  148. })
  149. return
  150. } else {
  151. // 保存透后相关数据
  152. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  153. if getAADErr != nil {
  154. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  156. return
  157. }
  158. var afterevaluation models.AssessmentAfterDislysis
  159. if assessmentAfterDislysis != nil {
  160. afterevaluation = *assessmentAfterDislysis
  161. }
  162. if assessmentAfterDislysis == nil {
  163. afterevaluation.CreatedTime = time.Now().Unix()
  164. afterevaluation.Status = 1
  165. afterevaluation.AssessmentDate = theAssessmentDateTime
  166. afterevaluation.PatientId = id
  167. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  168. } else {
  169. afterevaluation.UpdatedTime = time.Now().Unix()
  170. }
  171. afterevaluation.SystolicBloodPressure = systolic_blood_pressure // 收缩压
  172. afterevaluation.DiastolicBloodPressure = diastolic_blood_pressure // 舒张压
  173. afterevaluation.PulseFrequency = pulse_frequency // 脉率
  174. if adminUserInfo.Org.Id == 10138 {
  175. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  176. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  177. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  178. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk //跌倒风险
  179. }
  180. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  181. //记录日志
  182. byterequest, _ := json.Marshal(afterevaluation)
  183. afterLog := models.XtAssessmentAfterDialysisLog{
  184. UserOrgId: adminUserInfo.Org.Id,
  185. AdminUserId: adminUserInfo.AdminUser.Id,
  186. ErrLog: string(byterequest),
  187. PatientId: afterevaluation.PatientId,
  188. RecordDate: afterevaluation.AssessmentDate,
  189. Ctime: time.Now().Unix(),
  190. Mtime: 0,
  191. Status: 1,
  192. Source: "物联网上传透后血压",
  193. }
  194. service.CreateAfterDialysisLog(afterLog)
  195. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  196. redis := service.RedisClient()
  197. //清空key 值
  198. redis.Set(key, "", time.Second)
  199. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  200. redis.Set(keyThree, "", time.Second)
  201. assessdateDateStart := thisTime.Format("2006-01-02")
  202. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  203. redis.Set(keyTwo, "", time.Second)
  204. defer redis.Close()
  205. if err == nil {
  206. c.ServeSuccessJSON(map[string]interface{}{
  207. "assessmentAfterDislysis": afterevaluation,
  208. })
  209. }
  210. }
  211. }
  212. func (c *CheckWeightApiController) SavePatientInfoDialysis() {
  213. id, _ := c.GetInt64("patient", 0)
  214. dialysistype, _ := c.GetInt64("dialysistype", 0)
  215. if id <= 0 {
  216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  217. return
  218. }
  219. if dialysistype <= 0 {
  220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  221. return
  222. }
  223. adminUserInfo := c.GetMobileAdminUserInfo()
  224. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  225. if patient.ID == 0 {
  226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  227. return
  228. }
  229. thisTime := time.Now()
  230. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  231. // scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  232. timeLayout := "2006-01-02 15:04:05"
  233. loc, _ := time.LoadLocation("Local")
  234. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  235. // theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  236. theAssessmentDateTime := theStartTime.Unix()
  237. // endTime := theEndTime.Unix()
  238. // dry_weight,_ := c.GetFloat("dry_weight",0) // 干体重
  239. weighing_before, _ := c.GetFloat("weighing_before", 0) // 透前体重
  240. dewater_amount, _ := c.GetFloat("dewater_amount", 0) // 目标脱水量(L)
  241. weight_after, _ := c.GetFloat("weight_after", 0) // 透后体重
  242. weight_loss, _ := c.GetFloat("weight_loss", 0) // 体重减少
  243. schedual, _ := service.MobileGetSchedualDetail(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix())
  244. //dialysisSolution,_ := service.MobileGetDialysisSolutionByModeId(adminUserInfo.Org.Id,patient.ID,schedual.ModeId)
  245. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  246. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  247. //dialysisPrescribe, _ := service.MobileGetDialysisPrescribeByModeId(adminUserInfo.Org.Id, patient.ID, theStartTime.Unix(),schedual.ModeId)
  248. // 查询当前用户今天有没有排班,没有排班,则不处理
  249. // daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, theAssessmentDateTime, endTime, id)
  250. // if(len(daySchedule) <= 0) {
  251. // c.ServeSuccessJSON(map[string]interface{}{
  252. // "msg": "ok",
  253. // })
  254. // return
  255. // }
  256. template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
  257. 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 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 || adminUserInfo.Org.Id == 10432 || adminUserInfo.Org.Id == 10441 || adminUserInfo.Org.Id == 10445 || adminUserInfo.Org.Id == 10138 || adminUserInfo.Org.Id == 10278 || adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10440 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
  258. if adminUserInfo.Org.Id != 10447 {
  259. dewater_amount = dewater_amount * 1000
  260. }
  261. }
  262. if dewater_amount < 0 {
  263. dewater_amount = 0
  264. }
  265. if dialysistype == 1 {
  266. // 保存透前相关数据
  267. // 获取透析处方
  268. var lastDialysisPrescribe *models.DialysisPrescription
  269. var dialysisSolution *models.DialysisSolution
  270. var dialysisPrescribe *models.DialysisPrescription
  271. var system_dialysisPrescribe *models.SystemPrescription
  272. var mode_id int64
  273. //weightfirst, _ := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  274. //if weightfirst.DryWeight > weighing_before {
  275. // return
  276. //}
  277. dialysisPrescribe, _ = service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  278. if schedual != nil {
  279. // 获取透析模版
  280. dialysisSolution, _ = service.MobileGetDialysisSolutionByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  281. system_dialysisPrescribe, _ = service.MobileGetSystemDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, schedual.ModeId)
  282. lastDialysisPrescribe, _ = service.MobileGetLastDialysisPrescribeByModeIdSix(adminUserInfo.Org.Id, id, schedual.ModeId)
  283. //判断透析模式,针对河间咸的
  284. if adminUserInfo.Org.Id == 10090 {
  285. if dialysisSolution.ModeId != 2 && dialysisSolution.ModeId != 5 && dialysisSolution.ModeId != 12 {
  286. dialysisSolution.DisplaceLiquiPart = 0
  287. dialysisSolution.DisplaceLiquiValue = 0
  288. }
  289. if lastDialysisPrescribe.ModeId != 2 && lastDialysisPrescribe.ModeId != 5 && lastDialysisPrescribe.ModeId != 12 {
  290. dialysisSolution.DisplaceLiquiPart = 0
  291. dialysisSolution.DisplaceLiquiValue = 0
  292. }
  293. }
  294. mode_id = schedual.ModeId
  295. } else {
  296. // 获取透析模版
  297. dialysisSolution, _ = service.MobileGetDialysisSolution(adminUserInfo.Org.Id, id)
  298. if dialysisPrescribe == nil && dialysisSolution != nil {
  299. mode_id = dialysisSolution.ModeId
  300. }
  301. if dialysisPrescribe == nil && dialysisSolution == nil {
  302. mode_id = 0
  303. }
  304. }
  305. // 插入透析处方
  306. if dialysisPrescribe == nil && dialysisSolution != nil {
  307. var newprescribe models.DialysisPrescription
  308. newprescribe.UserOrgId = dialysisSolution.UserOrgId
  309. newprescribe.PatientId = dialysisSolution.PatientId
  310. newprescribe.Anticoagulant = dialysisSolution.Anticoagulant
  311. newprescribe.AnticoagulantShouji = dialysisSolution.AnticoagulantShouji
  312. newprescribe.AnticoagulantWeichi = dialysisSolution.AnticoagulantWeichi
  313. newprescribe.AnticoagulantZongliang = dialysisSolution.AnticoagulantZongliang
  314. newprescribe.AnticoagulantGaimingcheng = dialysisSolution.AnticoagulantGaimingcheng
  315. newprescribe.AnticoagulantGaijiliang = dialysisSolution.AnticoagulantGaijiliang
  316. newprescribe.ModeId = dialysisSolution.ModeId
  317. newprescribe.DialysisDuration = dialysisSolution.DialysisDuration
  318. newprescribe.ReplacementWay = dialysisSolution.ReplacementWay
  319. newprescribe.HemodialysisMachine = dialysisSolution.HemodialysisMachine
  320. newprescribe.BloodFilter = dialysisSolution.BloodFilter
  321. newprescribe.PerfusionApparatus = dialysisSolution.PerfusionApparatus
  322. newprescribe.BloodFlowVolume = dialysisSolution.BloodFlowVolume
  323. newprescribe.DisplaceLiqui = dialysisSolution.DisplaceLiqui
  324. newprescribe.Glucose = dialysisSolution.Glucose
  325. newprescribe.DialysateFlow = dialysisSolution.DialysateFlow
  326. newprescribe.Kalium = dialysisSolution.Kalium
  327. newprescribe.Sodium = dialysisSolution.Sodium
  328. newprescribe.Calcium = dialysisSolution.Calcium
  329. newprescribe.Bicarbonate = dialysisSolution.Bicarbonate
  330. newprescribe.DialysateTemperature = dialysisSolution.DialysateTemperature
  331. newprescribe.Conductivity = dialysisSolution.Conductivity
  332. newprescribe.BodyFluid = dialysisSolution.BodyFluid
  333. newprescribe.SpecialMedicine = dialysisSolution.SpecialMedicine
  334. newprescribe.SpecialMedicineOther = dialysisSolution.SpecialMedicineOther
  335. newprescribe.DisplaceLiquiPart = dialysisSolution.DisplaceLiquiPart
  336. newprescribe.DisplaceLiquiValue = dialysisSolution.DisplaceLiquiValue
  337. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  338. newprescribe.Ultrafiltration = dialysisSolution.Ultrafiltration
  339. newprescribe.DialysisDurationHour = dialysisSolution.DialysisDurationHour
  340. newprescribe.DialysisDurationMinute = dialysisSolution.DialysisDurationMinute
  341. newprescribe.TargetUltrafiltration = dialysisSolution.TargetUltrafiltration
  342. newprescribe.DialysateFormulation = dialysisSolution.DialysateFormulation
  343. newprescribe.Dialyzer = dialysisSolution.Dialyzer
  344. newprescribe.ReplacementTotal = dialysisSolution.ReplacementTotal
  345. newprescribe.DialyzerPerfusionApparatus = dialysisSolution.DialyzerPerfusionApparatus
  346. newprescribe.DialysisIrrigation = dialysisSolution.DialysisIrrigation
  347. newprescribe.DialysisDialyszers = dialysisSolution.DialysisDialyszers
  348. newprescribe.BodyFluidOther = dialysisSolution.BodyFluidOther
  349. newprescribe.TargetKtv = dialysisSolution.TargetKtv
  350. newprescribe.CreatedTime = time.Now().Unix()
  351. newprescribe.UpdatedTime = time.Now().Unix()
  352. newprescribe.RecordDate = theAssessmentDateTime
  353. newprescribe.DewaterAmount = dewater_amount
  354. newprescribe.TargetUltrafiltration = dewater_amount
  355. newprescribe.PrescriptionWater = dewater_amount
  356. newprescribe.Chaptalization = dialysisSolution.Chaptalization
  357. newprescribe.PrescribingNumber = 1
  358. newprescribe.Status = 1
  359. if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
  360. newprescribe.Remark = dialysisSolution.Remark
  361. }
  362. if adminUserInfo.Org.Id == 10340 {
  363. newprescribe.TargetUltrafiltration = 0
  364. newprescribe.Sodium = 138
  365. newprescribe.Bicarbonate = 31.1
  366. newprescribe.DialysateFlow = 500
  367. }
  368. // 针对新化博翔
  369. if adminUserInfo.Org.Id == 10447 {
  370. newprescribe.DisplaceLiquiPart = 1
  371. newprescribe.DisplaceLiquiValue = 32
  372. newprescribe.DialysateFlow = 500
  373. }
  374. if adminUserInfo.Org.Id == 10121 {
  375. newprescribe.DialysisDurationHour = 4
  376. newprescribe.DialysisDurationMinute = 0
  377. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  378. }
  379. if adminUserInfo.Org.Id == 10445 {
  380. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  381. newprescribe.Remark = lastDialysisPrescription.Remark
  382. }
  383. //插入透析处方
  384. err := service.AddSigleRecord(&newprescribe)
  385. //记录日志
  386. byterequest, _ := json.Marshal(newprescribe)
  387. prescriptionLog := models.XtDialysisPrescriptionLog{
  388. UserOrgId: newprescribe.UserOrgId,
  389. Ctime: time.Now().Unix(),
  390. Mtime: 0,
  391. ErrLog: string(byterequest),
  392. AdminUserId: adminUserInfo.AdminUser.Id,
  393. RecordDate: newprescribe.RecordDate,
  394. PatientId: newprescribe.PatientId,
  395. Source: "物联网上传",
  396. Status: 1,
  397. }
  398. service.CreatePrescriptionLog(prescriptionLog)
  399. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  400. redis := service.RedisClient()
  401. //清空key 值
  402. redis.Set(key, "", time.Second)
  403. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  404. redis.Set(keyTwo, "", time.Second)
  405. scheduleDateStartOne := thisTime.Format("2006-01-02")
  406. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  407. redis.Set(keyThree, "", time.Second)
  408. defer redis.Close()
  409. if err != nil {
  410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  411. }
  412. }
  413. if dialysisPrescribe == nil && dialysisSolution == nil {
  414. if lastDialysisPrescribe != nil {
  415. var newprescribe models.DialysisPrescription
  416. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  417. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  418. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  419. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  420. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  421. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  422. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  423. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  424. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  425. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  426. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  427. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  428. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  429. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  430. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  431. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  432. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  433. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  434. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  435. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  436. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  437. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  438. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  439. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  440. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  441. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  442. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  443. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  444. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  445. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  446. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  447. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  448. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  449. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  450. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  451. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  452. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  453. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  454. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  455. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  456. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  457. newprescribe.CreatedTime = time.Now().Unix()
  458. newprescribe.UpdatedTime = time.Now().Unix()
  459. newprescribe.RecordDate = theAssessmentDateTime
  460. newprescribe.DewaterAmount = dewater_amount
  461. newprescribe.TargetUltrafiltration = dewater_amount
  462. newprescribe.PrescriptionWater = dewater_amount
  463. newprescribe.Status = 1
  464. if adminUserInfo.Org.Id != 10490 {
  465. newprescribe.Remark = lastDialysisPrescribe.Remark
  466. } else {
  467. newprescribe.Remark = ""
  468. }
  469. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  470. newprescribe.PrescribingNumber = 1
  471. if adminUserInfo.Org.Id == 10340 {
  472. newprescribe.TargetUltrafiltration = 0
  473. }
  474. if adminUserInfo.Org.Id == 10121 {
  475. newprescribe.DialysisDurationHour = 4
  476. newprescribe.DialysisDurationMinute = 0
  477. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  478. }
  479. if adminUserInfo.Org.Id == 10445 {
  480. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  481. newprescribe.Remark = lastDialysisPrescription.Remark
  482. }
  483. err := service.AddSigleRecord(&newprescribe)
  484. //记录日志
  485. byterequest, _ := json.Marshal(newprescribe)
  486. prescriptionLog := models.XtDialysisPrescriptionLog{
  487. UserOrgId: adminUserInfo.Org.Id,
  488. Ctime: time.Now().Unix(),
  489. Mtime: 0,
  490. ErrLog: string(byterequest),
  491. AdminUserId: adminUserInfo.AdminUser.Id,
  492. RecordDate: newprescribe.RecordDate,
  493. PatientId: id,
  494. Source: "物联网上传",
  495. Status: 1,
  496. }
  497. service.CreatePrescriptionLog(prescriptionLog)
  498. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  499. redis := service.RedisClient()
  500. //清空key 值
  501. redis.Set(key, "", time.Second)
  502. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  503. redis.Set(keyTwo, "", time.Second)
  504. scheduleDateStartOne := thisTime.Format("2006-01-02")
  505. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  506. redis.Set(keyThree, "", time.Second)
  507. defer redis.Close()
  508. if err != nil {
  509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  510. }
  511. } else if system_dialysisPrescribe != nil {
  512. var newprescribe models.DialysisPrescription
  513. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  514. newprescribe.PatientId = id
  515. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  516. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  517. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  518. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  519. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  520. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  521. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  522. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  523. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  524. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  525. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  526. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  527. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  528. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  529. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  530. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  531. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  532. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  533. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  534. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  535. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  536. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  537. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  538. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  539. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  540. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  541. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  542. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  543. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  544. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  545. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  546. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  547. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  548. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  549. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  550. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  551. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  552. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  553. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  554. newprescribe.CreatedTime = time.Now().Unix()
  555. newprescribe.UpdatedTime = time.Now().Unix()
  556. newprescribe.RecordDate = theAssessmentDateTime
  557. newprescribe.DewaterAmount = dewater_amount
  558. newprescribe.TargetUltrafiltration = dewater_amount
  559. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  560. newprescribe.Status = 1
  561. newprescribe.PrescribingNumber = 1
  562. if adminUserInfo.Org.Id == 10340 {
  563. newprescribe.TargetUltrafiltration = 0
  564. }
  565. if adminUserInfo.Org.Id == 10121 {
  566. newprescribe.DialysisDurationHour = 4
  567. newprescribe.DialysisDurationMinute = 0
  568. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  569. }
  570. if adminUserInfo.Org.Id == 10445 {
  571. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  572. newprescribe.Remark = lastDialysisPrescription.Remark
  573. }
  574. err := service.AddSigleRecord(&newprescribe)
  575. //记录日志
  576. byterequest, _ := json.Marshal(newprescribe)
  577. prescriptionLog := models.XtDialysisPrescriptionLog{
  578. UserOrgId: adminUserInfo.Org.Id,
  579. Ctime: time.Now().Unix(),
  580. Mtime: 0,
  581. ErrLog: string(byterequest),
  582. AdminUserId: adminUserInfo.AdminUser.Id,
  583. RecordDate: newprescribe.RecordDate,
  584. PatientId: id,
  585. Source: "物联网上传",
  586. Status: 1,
  587. }
  588. service.CreatePrescriptionLog(prescriptionLog)
  589. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  590. redis := service.RedisClient()
  591. //清空key 值
  592. redis.Set(key, "", time.Second)
  593. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  594. redis.Set(keyTwo, "", time.Second)
  595. scheduleDateStartOne := thisTime.Format("2006-01-02")
  596. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  597. redis.Set(keyThree, "", time.Second)
  598. defer redis.Close()
  599. if err != nil {
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  601. }
  602. } else {
  603. var newprescribe models.DialysisPrescription
  604. newprescribe.UserOrgId = adminUserInfo.Org.Id
  605. newprescribe.PatientId = id
  606. newprescribe.ModeId = mode_id
  607. newprescribe.CreatedTime = time.Now().Unix()
  608. newprescribe.UpdatedTime = time.Now().Unix()
  609. newprescribe.RecordDate = theAssessmentDateTime
  610. newprescribe.DewaterAmount = dewater_amount
  611. newprescribe.TargetUltrafiltration = dewater_amount
  612. newprescribe.Status = 1
  613. if adminUserInfo.Org.Id == 10445 {
  614. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  615. newprescribe.Remark = lastDialysisPrescription.Remark
  616. }
  617. err := service.AddSigleRecord(&newprescribe)
  618. //记录日志
  619. byterequest, _ := json.Marshal(newprescribe)
  620. prescriptionLog := models.XtDialysisPrescriptionLog{
  621. UserOrgId: adminUserInfo.Org.Id,
  622. Ctime: time.Now().Unix(),
  623. Mtime: 0,
  624. ErrLog: string(byterequest),
  625. AdminUserId: adminUserInfo.AdminUser.Id,
  626. RecordDate: newprescribe.RecordDate,
  627. PatientId: id,
  628. Source: "物联网上传",
  629. Status: 1,
  630. }
  631. service.CreatePrescriptionLog(prescriptionLog)
  632. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  633. redis := service.RedisClient()
  634. //清空key 值
  635. redis.Set(key, "", time.Second)
  636. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  637. redis.Set(keyTwo, "", time.Second)
  638. scheduleDateStartOne := thisTime.Format("2006-01-02")
  639. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  640. redis.Set(keyThree, "", time.Second)
  641. defer redis.Close()
  642. if err != nil {
  643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  644. }
  645. }
  646. }
  647. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  648. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  649. dialysisPrescribe.RecordDate = theAssessmentDateTime
  650. dialysisPrescribe.DewaterAmount = dewater_amount
  651. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  652. dialysisPrescribe.Status = 1
  653. if adminUserInfo.Org.Id == 10340 {
  654. dialysisPrescribe.TargetUltrafiltration = 0
  655. }
  656. if adminUserInfo.Org.Id == 10445 {
  657. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  658. dialysisPrescribe.Remark = lastDialysisPrescription.Remark
  659. }
  660. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  661. //记录日志
  662. byterequest, _ := json.Marshal(dialysisPrescribe)
  663. prescriptionLog := models.XtDialysisPrescriptionLog{
  664. UserOrgId: adminUserInfo.Org.Id,
  665. Ctime: time.Now().Unix(),
  666. Mtime: 0,
  667. ErrLog: string(byterequest),
  668. AdminUserId: adminUserInfo.AdminUser.Id,
  669. RecordDate: dialysisPrescribe.RecordDate,
  670. PatientId: id,
  671. Source: "物联网上传",
  672. Status: 1,
  673. }
  674. service.CreatePrescriptionLog(prescriptionLog)
  675. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  676. redis := service.RedisClient()
  677. //清空key 值
  678. redis.Set(key, "", time.Second)
  679. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  680. redis.Set(keyTwo, "", time.Second)
  681. scheduleDateStartOne := thisTime.Format("2006-01-02")
  682. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  683. redis.Set(keyThree, "", time.Second)
  684. defer redis.Close()
  685. if updateErr != nil {
  686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  687. }
  688. }
  689. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  690. if getPEErr != nil {
  691. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  693. return
  694. }
  695. var evaluation models.PredialysisEvaluation
  696. if theEvaluation != nil {
  697. evaluation = *theEvaluation
  698. }
  699. // 如果今天没有透前评估,则插入新的数据
  700. if theEvaluation == nil {
  701. evaluation.CreatedTime = time.Now().Unix()
  702. evaluation.Status = 1
  703. evaluation.AssessmentDate = theAssessmentDateTime
  704. evaluation.PatientId = id
  705. evaluation.UserOrgId = adminUserInfo.Org.Id
  706. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  707. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  708. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  709. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  710. if getAADErr != nil {
  711. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  712. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  713. return
  714. }
  715. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  716. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  717. if err == gorm.ErrRecordNotFound {
  718. if lastPredialysisEvaluation != nil {
  719. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  720. } else {
  721. evaluation.DryWeight = 0
  722. }
  723. } else {
  724. evaluation.DryWeight = weight.DryWeight
  725. }
  726. if assessmentAfterDislysis != nil {
  727. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  728. }
  729. if lastPredialysisEvaluation != nil {
  730. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  731. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  732. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  733. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  734. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  735. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  736. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  737. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  738. evaluation.Complication = lastPredialysisEvaluation.Complication
  739. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  740. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  741. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  742. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  743. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  744. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  745. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  746. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  747. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  748. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  749. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  750. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  751. evaluation.Remark = lastPredialysisEvaluation.Remark
  752. if adminUserInfo.Org.Id == 10318 || adminUserInfo.Org.Id == 10490 {
  753. evaluation.Remark = ""
  754. }
  755. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
  756. evaluation.BreathingRate = "20"
  757. }
  758. if adminUserInfo.Org.Id == 10445 {
  759. evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  760. }
  761. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
  762. evaluation.PulseFrequency = 80
  763. }
  764. if adminUserInfo.Org.Id == 10440 {
  765. evaluation.Temperature = 36.5
  766. }
  767. if adminUserInfo.Org.Id == 10469 {
  768. evaluation.Temperature = 36.5
  769. }
  770. if adminUserInfo.Org.Id == 10471 {
  771. evaluation.Temperature = 36.5
  772. }
  773. }
  774. } else {
  775. evaluation.UpdatedTime = time.Now().Unix()
  776. }
  777. evaluation.WeightBefore = weighing_before
  778. evaluation.AssessmentTime = time.Now().Unix()
  779. err := service.UpadatePredialysisEvaluation(&evaluation)
  780. //记录日志
  781. byterequest, _ := json.Marshal(evaluation)
  782. beforLog := models.XtAssessmentBeforeDislysisLog{
  783. UserOrgId: adminUserInfo.Org.Id,
  784. Ctime: time.Now().Unix(),
  785. Mtime: 0,
  786. ErrLog: string(byterequest),
  787. AdminUserId: adminUserInfo.AdminUser.Id,
  788. RecordDate: evaluation.AssessmentDate,
  789. PatientId: id,
  790. Source: "物联网上传",
  791. Status: 1,
  792. }
  793. service.CreateBeforLog(beforLog)
  794. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  795. redis := service.RedisClient()
  796. //清空key 值
  797. redis.Set(key, "", time.Second)
  798. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  799. redis.Set(keyOne, "", time.Second)
  800. assessdateDateStart := thisTime.Format("2006-01-02")
  801. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  802. redis.Set(keyTwo, "", time.Second)
  803. redis.Close()
  804. if err != nil {
  805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  806. return
  807. }
  808. c.ServeSuccessJSON(map[string]interface{}{
  809. "msg": "ok",
  810. "evaluation": evaluation,
  811. })
  812. return
  813. } else {
  814. // 保存透后相关数据
  815. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  816. if getAADErr != nil {
  817. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  819. return
  820. }
  821. var afterevaluation models.AssessmentAfterDislysis
  822. if assessmentAfterDislysis != nil {
  823. afterevaluation = *assessmentAfterDislysis
  824. }
  825. if assessmentAfterDislysis == nil {
  826. afterevaluation.CreatedTime = time.Now().Unix()
  827. afterevaluation.Status = 1
  828. afterevaluation.AssessmentDate = theAssessmentDateTime
  829. afterevaluation.PatientId = id
  830. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  831. } else {
  832. afterevaluation.UpdatedTime = time.Now().Unix()
  833. }
  834. afterevaluation.WeightAfter = weight_after
  835. afterevaluation.WeightLoss = weight_loss
  836. if adminUserInfo.Org.Id == 10138 {
  837. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  838. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  839. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  840. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  841. }
  842. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  843. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  844. }
  845. //北方营口
  846. if adminUserInfo.Org.Id == 10445 {
  847. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  848. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  849. }
  850. //蓬安济民
  851. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  852. afterevaluation.PulseFrequency = 80
  853. }
  854. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  855. //记录日志
  856. byterequest, _ := json.Marshal(afterevaluation)
  857. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  858. UserOrgId: afterevaluation.UserOrgId,
  859. PatientId: afterevaluation.PatientId,
  860. RecordDate: afterevaluation.AssessmentDate,
  861. Status: 1,
  862. ErrLog: string(byterequest),
  863. AdminUserId: adminUserInfo.AdminUser.Id,
  864. Ctime: time.Now().Unix(),
  865. Mtime: 0,
  866. Source: "物联网称重",
  867. }
  868. service.CreateAfterDialysisLog(afterDialysisLog)
  869. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  870. redis := service.RedisClient()
  871. //清空key 值
  872. redis.Set(key, "", time.Second)
  873. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  874. redis.Set(keyThree, "", time.Second)
  875. assessdateDateStart := thisTime.Format("2006-01-02")
  876. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  877. redis.Set(keyTwo, "", time.Second)
  878. redis.Close()
  879. if err == nil {
  880. c.ServeSuccessJSON(map[string]interface{}{
  881. "assessmentAfterDislysis": afterevaluation,
  882. })
  883. }
  884. }
  885. }
  886. func (c *CheckWeightApiController) SetSyncTime() {
  887. sn := c.GetString("sn")
  888. if len(sn) > 0 {
  889. redis := service.RedisClient()
  890. defer redis.Close()
  891. redis.Set(sn, 0, 0)
  892. }
  893. serviceTime := time.Now().Unix()
  894. c.ServeSuccessJSON(map[string]interface{}{
  895. "status": 1,
  896. "servicetime": serviceTime,
  897. })
  898. }
  899. func (c *CheckWeightApiController) GetPatientList() {
  900. ftype, _ := c.GetInt64("type", 0)
  901. sn := c.GetString("sn")
  902. syncTime := int64(0)
  903. redis := service.RedisClient()
  904. defer redis.Close()
  905. if len(sn) > 0 {
  906. syncTimeStr, _ := redis.Get(sn).Result()
  907. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  908. }
  909. if ftype == 1 {
  910. timeNow := time.Now().Unix()
  911. redis.Set(sn, timeNow, 0)
  912. }
  913. adminUserInfo := c.GetMobileAdminUserInfo()
  914. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  915. need_update := 0
  916. if syncTime == 0 {
  917. need_update = 1
  918. }
  919. if error != nil {
  920. c.ErrorLog("获取病人列表失败:%v", error)
  921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  922. return
  923. }
  924. serviceTime := time.Now().Unix()
  925. c.ServeSuccessJSON(map[string]interface{}{
  926. "need_update": need_update,
  927. "patientlist": patientList,
  928. "total": total,
  929. "servicetime": serviceTime,
  930. })
  931. }
  932. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  933. thisTime := time.Now()
  934. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  935. timeLayout := "2006-01-02 15:04:05"
  936. loc, _ := time.LoadLocation("Local")
  937. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  938. syncTime := theStartTime.Unix()
  939. adminUserInfo := c.GetMobileAdminUserInfo()
  940. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  941. patientSchedule := make([]map[string]interface{}, 0)
  942. for _, item := range patientList {
  943. patientTemp := make(map[string]interface{})
  944. patientTemp["patient_id"] = item.PatientId
  945. patientTemp["patient_name"] = item.Patient.Name
  946. patientTemp["schedule_type"] = item.ScheduleType
  947. patientSchedule = append(patientSchedule, patientTemp)
  948. }
  949. if error != nil {
  950. c.ErrorLog("获取病人列表失败:%v", error)
  951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  952. return
  953. }
  954. serviceTime := time.Now().Unix()
  955. c.ServeSuccessJSON(map[string]interface{}{
  956. "patientlist": patientSchedule,
  957. "total": total,
  958. "servicetime": serviceTime,
  959. })
  960. }
  961. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  962. patient_name := c.GetString("patient_name") //脉率
  963. thisTime := time.Now()
  964. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  965. timeLayout := "2006-01-02 15:04:05"
  966. loc, _ := time.LoadLocation("Local")
  967. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  968. syncTime := theStartTime.Unix()
  969. adminUserInfo := c.GetMobileAdminUserInfo()
  970. if len(patient_name) == 0 {
  971. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  972. patientSchedule := make([]map[string]interface{}, 0)
  973. for _, item := range patientList {
  974. patientTemp := make(map[string]interface{})
  975. patientTemp["patient_id"] = item.PatientId
  976. patientTemp["patient_name"] = item.Patient.Name
  977. patientTemp["schedule_type"] = item.ScheduleType
  978. patientSchedule = append(patientSchedule, patientTemp)
  979. }
  980. if error != nil {
  981. c.ErrorLog("获取病人列表失败:%v", error)
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  983. return
  984. }
  985. serviceTime := time.Now().Unix()
  986. c.ServeSuccessJSON(map[string]interface{}{
  987. "patientlist": patientSchedule,
  988. "total": total,
  989. "servicetime": serviceTime,
  990. })
  991. } else {
  992. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  993. patientSchedule := make([]map[string]interface{}, 0)
  994. for _, item := range patientList {
  995. if item.Patient.ID > 0 {
  996. patientTemp := make(map[string]interface{})
  997. patientTemp["patient_id"] = item.PatientId
  998. patientTemp["patient_name"] = item.Patient.Name
  999. patientTemp["schedule_type"] = item.ScheduleType
  1000. patientSchedule = append(patientSchedule, patientTemp)
  1001. }
  1002. }
  1003. if error != nil {
  1004. c.ErrorLog("获取病人列表失败:%v", error)
  1005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1006. return
  1007. }
  1008. serviceTime := time.Now().Unix()
  1009. c.ServeSuccessJSON(map[string]interface{}{
  1010. "patientlist": patientSchedule,
  1011. "total": total,
  1012. "servicetime": serviceTime,
  1013. })
  1014. }
  1015. }
  1016. func (c *CheckWeightApiController) GetPatientListById() {
  1017. patientId, _ := c.GetInt64("patient_id", 0)
  1018. if patientId <= 0 {
  1019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1020. return
  1021. }
  1022. adminUserInfo := c.GetMobileAdminUserInfo()
  1023. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  1024. if error != nil {
  1025. c.ErrorLog("获取病人详情失败:%v", error)
  1026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1027. return
  1028. }
  1029. c.ServeSuccessJSON(map[string]interface{}{
  1030. "patientinfo": patient,
  1031. })
  1032. }
  1033. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  1034. id, _ := c.GetInt64("patient", 0)
  1035. if id <= 0 {
  1036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1037. return
  1038. }
  1039. adminUserInfo := c.GetMobileAdminUserInfo()
  1040. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1041. if patient.ID <= 0 {
  1042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1043. return
  1044. }
  1045. var dialysisinfo map[string]interface{}
  1046. dialysisinfo = make(map[string]interface{})
  1047. dialysisinfo["id"] = patient.ID
  1048. dialysisinfo["name"] = patient.Name
  1049. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1050. thisTime := time.Now()
  1051. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1052. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1053. timeLayout := "2006-01-02 15:04:05"
  1054. loc, _ := time.LoadLocation("Local")
  1055. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1056. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1057. startTime := theStartTime.Unix()
  1058. endTime := theEndTime.Unix()
  1059. // 判断当前用户是透析前还是透析后
  1060. var dialysistype int
  1061. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  1062. if dialysisOrder == nil {
  1063. dialysistype = 1
  1064. } else {
  1065. dialysistype = 2
  1066. }
  1067. // 获取当前或者下次排班信息
  1068. var sc map[string]interface{}
  1069. sc = make(map[string]interface{})
  1070. if dialysistype == 1 {
  1071. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  1072. if len(daySchedule) <= 0 {
  1073. sc["code"] = 1
  1074. sc["msg"] = "抱歉,您今天没有排版!"
  1075. sc["mode"] = 0
  1076. sc["data"] = daySchedule
  1077. } else {
  1078. if daySchedule[0].Schedule.ID > 0 {
  1079. sc["code"] = 0
  1080. sc["msg"] = ""
  1081. sc["mode"] = daySchedule[0].Schedule.ModeId
  1082. sc["data"] = daySchedule
  1083. } else {
  1084. sc["code"] = 1
  1085. sc["msg"] = "抱歉,您今天没有排版!"
  1086. sc["mode"] = 0
  1087. sc["data"] = daySchedule
  1088. }
  1089. }
  1090. // 排队叫号的签到
  1091. go func() {
  1092. ssoDomain := beego.AppConfig.String("call_domain")
  1093. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  1094. values := make(url.Values)
  1095. http.PostForm(api, values)
  1096. }()
  1097. } else {
  1098. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  1099. if len(nextSchedule) <= 0 {
  1100. sc["code"] = 1
  1101. sc["msg"] = "抱歉,您后续没有排版!"
  1102. sc["mode"] = 0
  1103. sc["data"] = nextSchedule
  1104. } else {
  1105. if nextSchedule[0].Schedule.ID > 0 {
  1106. sc["code"] = 0
  1107. sc["msg"] = ""
  1108. sc["mode"] = nextSchedule[0].Schedule.ModeId
  1109. sc["data"] = nextSchedule
  1110. } else {
  1111. sc["code"] = 1
  1112. sc["msg"] = "抱歉,您后续没有排版!"
  1113. sc["mode"] = 0
  1114. sc["data"] = nextSchedule
  1115. }
  1116. }
  1117. }
  1118. switch sc["mode"] {
  1119. case 1:
  1120. sc["mode"] = "HD"
  1121. case 2:
  1122. sc["mode"] = "HDF"
  1123. case 3:
  1124. sc["mode"] = "HD+HP"
  1125. case 4:
  1126. sc["mode"] = "HP"
  1127. case 5:
  1128. sc["mode"] = "HF"
  1129. case 6:
  1130. sc["mode"] = "SCUF"
  1131. case 7:
  1132. sc["mode"] = "IUF"
  1133. case 8:
  1134. sc["mode"] = "HFHD"
  1135. case 9:
  1136. sc["mode"] = "HFHD+HP"
  1137. case 10:
  1138. sc["mode"] = "PHF"
  1139. case 11:
  1140. sc["mode"] = "HFR"
  1141. case 12:
  1142. sc["mode"] = "HDF+HP"
  1143. case 13:
  1144. sc["mode"] = "CRRT"
  1145. case 14:
  1146. sc["mode"] = "腹水回输"
  1147. case 15:
  1148. sc["mode"] = "HD前置换"
  1149. case 16:
  1150. sc["mode"] = "HD后置换"
  1151. case 17:
  1152. sc["mode"] = "HDF前置换"
  1153. case 18:
  1154. sc["mode"] = "HDF后置换"
  1155. default:
  1156. sc["mode"] = "HD"
  1157. }
  1158. // 获取患者透前干体重或者获取患者透前体重
  1159. var dry_weight map[string]interface{}
  1160. dry_weight = make(map[string]interface{})
  1161. var after_dry_weight map[string]interface{}
  1162. after_dry_weight = make(map[string]interface{})
  1163. if dialysistype == 1 {
  1164. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1165. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1166. if err == gorm.ErrRecordNotFound {
  1167. if getLPEErr != nil {
  1168. dry_weight["code"] = 1
  1169. dry_weight["dry_weight"] = nil
  1170. } else {
  1171. if lastPredialysisEvaluation == nil {
  1172. dry_weight["code"] = 1
  1173. dry_weight["dry_weight"] = nil
  1174. } else {
  1175. // 传输的干体重实际为干体重加上衣服重
  1176. dry_weight["code"] = 0
  1177. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1178. }
  1179. }
  1180. } else {
  1181. if err != nil {
  1182. dry_weight["code"] = 1
  1183. dry_weight["dry_weight"] = nil
  1184. } else {
  1185. dry_weight["code"] = 0
  1186. if getLPEErr != nil {
  1187. dry_weight["code"] = 0
  1188. dry_weight["dry_weight"] = weight.DryWeight
  1189. } else {
  1190. if lastPredialysisEvaluation == nil {
  1191. dry_weight["code"] = 1
  1192. dry_weight["dry_weight"] = weight.DryWeight
  1193. } else {
  1194. // 传输的干体重实际为干体重加上衣服重
  1195. dry_weight["code"] = 0
  1196. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1197. }
  1198. }
  1199. }
  1200. }
  1201. } else {
  1202. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1203. if getPEErr != nil {
  1204. dry_weight["code"] = 1
  1205. dry_weight["dry_weight"] = nil
  1206. } else {
  1207. if predialysisEvaluation == nil {
  1208. dry_weight["code"] = 1
  1209. dry_weight["dry_weight"] = nil
  1210. } else {
  1211. dry_weight["code"] = 0
  1212. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1213. }
  1214. }
  1215. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1216. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1217. if err == gorm.ErrRecordNotFound {
  1218. if getLPEErr != nil {
  1219. after_dry_weight["code"] = 1
  1220. after_dry_weight["dry_weight"] = nil
  1221. } else {
  1222. if lastPredialysisEvaluation == nil {
  1223. after_dry_weight["code"] = 1
  1224. after_dry_weight["dry_weight"] = nil
  1225. } else {
  1226. // 传输的干体重实际为干体重加上衣服重
  1227. after_dry_weight["code"] = 0
  1228. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1229. }
  1230. }
  1231. } else {
  1232. if err != nil {
  1233. after_dry_weight["code"] = 1
  1234. after_dry_weight["dry_weight"] = nil
  1235. } else {
  1236. after_dry_weight["code"] = 0
  1237. if getLPEErr != nil {
  1238. after_dry_weight["code"] = 0
  1239. after_dry_weight["dry_weight"] = weight.DryWeight
  1240. } else {
  1241. if lastPredialysisEvaluation == nil {
  1242. after_dry_weight["code"] = 1
  1243. after_dry_weight["dry_weight"] = weight.DryWeight
  1244. } else {
  1245. // 传输的干体重实际为干体重加上衣服重
  1246. after_dry_weight["code"] = 0
  1247. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. c.ServeSuccessJSON(map[string]interface{}{
  1254. "dialysistype": dialysistype,
  1255. "patient": dialysisinfo,
  1256. "schedule": sc,
  1257. "dryweight": dry_weight,
  1258. "after_dry_weight": after_dry_weight,
  1259. })
  1260. return
  1261. }
  1262. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1263. id, _ := c.GetInt64("patient", 0)
  1264. if id <= 0 {
  1265. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1266. return
  1267. }
  1268. adminUserInfo := c.GetMobileAdminUserInfo()
  1269. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1270. if patient.ID == 0 {
  1271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1272. return
  1273. }
  1274. var dialysisinfo map[string]interface{}
  1275. dialysisinfo = make(map[string]interface{})
  1276. dialysisinfo["id"] = patient.ID
  1277. dialysisinfo["name"] = patient.Name
  1278. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1279. thisTime := time.Now()
  1280. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1281. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1282. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1283. timeLayout := "2006-01-02 15:04:05"
  1284. loc, _ := time.LoadLocation("Local")
  1285. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1286. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1287. fmt.Println(theStartTime, theEndTime)
  1288. startTime := theStartTime.Unix()
  1289. endTime := theEndTime.Unix()
  1290. var sc map[string]interface{}
  1291. sc = make(map[string]interface{})
  1292. //一天只有排班一次
  1293. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1294. if daySchedule.ID > 0 {
  1295. switch daySchedule.ModeId {
  1296. case 1:
  1297. sc["mode"] = "HD"
  1298. case 2:
  1299. sc["mode"] = "HDF"
  1300. case 3:
  1301. sc["mode"] = "HD+HP"
  1302. case 4:
  1303. sc["mode"] = "HP"
  1304. case 5:
  1305. sc["mode"] = "HF"
  1306. case 6:
  1307. sc["mode"] = "SCUF"
  1308. case 7:
  1309. sc["mode"] = "IUF"
  1310. case 8:
  1311. sc["mode"] = "HFHD"
  1312. case 9:
  1313. sc["mode"] = "HFHD+HP"
  1314. case 10:
  1315. sc["mode"] = "PHF"
  1316. case 11:
  1317. sc["mode"] = "HFR"
  1318. case 12:
  1319. sc["mode"] = "HDF+HP"
  1320. case 13:
  1321. sc["mode"] = "CRRT"
  1322. case 14:
  1323. sc["mode"] = "腹水回输"
  1324. case 15:
  1325. sc["mode"] = "HD前置换"
  1326. case 16:
  1327. sc["mode"] = "HD后置换"
  1328. case 17:
  1329. sc["mode"] = "HDF前置换"
  1330. case 18:
  1331. sc["mode"] = "HDF后置换"
  1332. default:
  1333. sc["mode"] = "HD"
  1334. }
  1335. sc["code"] = 0
  1336. sc["msg"] = ""
  1337. sc["data"] = daySchedule
  1338. } else {
  1339. sc["code"] = 1
  1340. sc["msg"] = "抱歉,您今天没有排版!"
  1341. sc["mode"] = ""
  1342. sc["data"] = daySchedule
  1343. }
  1344. fmt.Println(sc)
  1345. type dryWeight struct {
  1346. code int
  1347. dry_weight float64
  1348. }
  1349. var dry_weight map[string]interface{}
  1350. dry_weight = make(map[string]interface{})
  1351. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1352. if getLPEErr != nil {
  1353. dry_weight["code"] = 1
  1354. dry_weight["dry_weight"] = nil
  1355. } else {
  1356. if lastPredialysisEvaluation == nil {
  1357. dry_weight["code"] = 1
  1358. dry_weight["dry_weight"] = nil
  1359. } else {
  1360. dry_weight["code"] = 0
  1361. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1362. }
  1363. }
  1364. c.ServeSuccessJSON(map[string]interface{}{
  1365. "patient": dialysisinfo,
  1366. "schedule": sc,
  1367. "dryweight": dry_weight,
  1368. })
  1369. return
  1370. }