check_weight_api_controller.go 57KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  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.BloodAccessPartId = dialysisSolution.BloodAccessPartId
  359. newprescribe.Status = 1
  360. if adminUserInfo.Org.Id != 10013 && adminUserInfo.Org.Id != 10014 {
  361. newprescribe.Remark = dialysisSolution.Remark
  362. }
  363. if adminUserInfo.Org.Id == 10340 {
  364. newprescribe.TargetUltrafiltration = 0
  365. newprescribe.Sodium = 138
  366. newprescribe.Bicarbonate = 31.1
  367. newprescribe.DialysateFlow = 500
  368. }
  369. // 针对新化博翔
  370. if adminUserInfo.Org.Id == 10447 {
  371. newprescribe.DisplaceLiquiPart = 1
  372. newprescribe.DisplaceLiquiValue = 32
  373. newprescribe.DialysateFlow = 500
  374. }
  375. if adminUserInfo.Org.Id == 10121 {
  376. newprescribe.DialysisDurationHour = 4
  377. newprescribe.DialysisDurationMinute = 0
  378. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  379. }
  380. if adminUserInfo.Org.Id == 10445 {
  381. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  382. newprescribe.Remark = lastDialysisPrescription.Remark
  383. }
  384. //插入透析处方
  385. err := service.AddSigleRecord(&newprescribe)
  386. //记录日志
  387. byterequest, _ := json.Marshal(newprescribe)
  388. prescriptionLog := models.XtDialysisPrescriptionLog{
  389. UserOrgId: newprescribe.UserOrgId,
  390. Ctime: time.Now().Unix(),
  391. Mtime: 0,
  392. ErrLog: string(byterequest),
  393. AdminUserId: adminUserInfo.AdminUser.Id,
  394. RecordDate: newprescribe.RecordDate,
  395. PatientId: newprescribe.PatientId,
  396. Source: "物联网上传",
  397. Status: 1,
  398. }
  399. service.CreatePrescriptionLog(prescriptionLog)
  400. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  401. redis := service.RedisClient()
  402. //清空key 值
  403. redis.Set(key, "", time.Second)
  404. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  405. redis.Set(keyTwo, "", time.Second)
  406. scheduleDateStartOne := thisTime.Format("2006-01-02")
  407. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  408. redis.Set(keyThree, "", time.Second)
  409. defer redis.Close()
  410. if err != nil {
  411. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  412. }
  413. }
  414. if dialysisPrescribe == nil && dialysisSolution == nil {
  415. if lastDialysisPrescribe != nil {
  416. var newprescribe models.DialysisPrescription
  417. newprescribe.UserOrgId = lastDialysisPrescribe.UserOrgId
  418. newprescribe.PatientId = lastDialysisPrescribe.PatientId
  419. newprescribe.Anticoagulant = lastDialysisPrescribe.Anticoagulant
  420. newprescribe.AnticoagulantShouji = lastDialysisPrescribe.AnticoagulantShouji
  421. newprescribe.AnticoagulantWeichi = lastDialysisPrescribe.AnticoagulantWeichi
  422. newprescribe.AnticoagulantZongliang = lastDialysisPrescribe.AnticoagulantZongliang
  423. newprescribe.AnticoagulantGaimingcheng = lastDialysisPrescribe.AnticoagulantGaimingcheng
  424. newprescribe.AnticoagulantGaijiliang = lastDialysisPrescribe.AnticoagulantGaijiliang
  425. newprescribe.ModeId = lastDialysisPrescribe.ModeId
  426. newprescribe.DialysisDuration = lastDialysisPrescribe.DialysisDuration
  427. newprescribe.ReplacementWay = lastDialysisPrescribe.ReplacementWay
  428. newprescribe.HemodialysisMachine = lastDialysisPrescribe.HemodialysisMachine
  429. newprescribe.BloodFilter = lastDialysisPrescribe.BloodFilter
  430. newprescribe.PerfusionApparatus = lastDialysisPrescribe.PerfusionApparatus
  431. newprescribe.BloodFlowVolume = lastDialysisPrescribe.BloodFlowVolume
  432. newprescribe.DisplaceLiqui = lastDialysisPrescribe.DisplaceLiqui
  433. newprescribe.Glucose = lastDialysisPrescribe.Glucose
  434. newprescribe.DialysateFlow = lastDialysisPrescribe.DialysateFlow
  435. newprescribe.Kalium = lastDialysisPrescribe.Kalium
  436. newprescribe.Sodium = lastDialysisPrescribe.Sodium
  437. newprescribe.Calcium = lastDialysisPrescribe.Calcium
  438. newprescribe.Bicarbonate = lastDialysisPrescribe.Bicarbonate
  439. newprescribe.DialysateTemperature = lastDialysisPrescribe.DialysateTemperature
  440. newprescribe.Conductivity = lastDialysisPrescribe.Conductivity
  441. newprescribe.BodyFluid = lastDialysisPrescribe.BodyFluid
  442. newprescribe.SpecialMedicine = lastDialysisPrescribe.SpecialMedicine
  443. newprescribe.SpecialMedicineOther = lastDialysisPrescribe.SpecialMedicineOther
  444. newprescribe.DisplaceLiquiPart = lastDialysisPrescribe.DisplaceLiquiPart
  445. newprescribe.DisplaceLiquiValue = lastDialysisPrescribe.DisplaceLiquiValue
  446. newprescribe.BloodAccess = lastDialysisPrescribe.BloodAccess
  447. newprescribe.Ultrafiltration = lastDialysisPrescribe.Ultrafiltration
  448. newprescribe.DialysisDurationHour = lastDialysisPrescribe.DialysisDurationHour
  449. newprescribe.DialysisDurationMinute = lastDialysisPrescribe.DialysisDurationMinute
  450. newprescribe.DialysateFormulation = lastDialysisPrescribe.DialysateFormulation
  451. newprescribe.Dialyzer = lastDialysisPrescribe.Dialyzer
  452. newprescribe.ReplacementTotal = lastDialysisPrescribe.ReplacementTotal
  453. newprescribe.DialyzerPerfusionApparatus = lastDialysisPrescribe.DialyzerPerfusionApparatus
  454. newprescribe.DialysisDialyszers = lastDialysisPrescribe.DialysisDialyszers
  455. newprescribe.DialysisIrrigation = lastDialysisPrescribe.DialysisIrrigation
  456. newprescribe.BodyFluidOther = lastDialysisPrescribe.BodyFluidOther
  457. newprescribe.TargetKtv = lastDialysisPrescribe.TargetKtv
  458. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  459. newprescribe.CreatedTime = time.Now().Unix()
  460. newprescribe.UpdatedTime = time.Now().Unix()
  461. newprescribe.RecordDate = theAssessmentDateTime
  462. newprescribe.DewaterAmount = dewater_amount
  463. newprescribe.TargetUltrafiltration = dewater_amount
  464. newprescribe.PrescriptionWater = dewater_amount
  465. newprescribe.Status = 1
  466. if adminUserInfo.Org.Id != 10490 {
  467. newprescribe.Remark = lastDialysisPrescribe.Remark
  468. } else {
  469. newprescribe.Remark = ""
  470. }
  471. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  472. newprescribe.PrescribingNumber = 1
  473. if adminUserInfo.Org.Id == 10340 {
  474. newprescribe.TargetUltrafiltration = 0
  475. }
  476. if adminUserInfo.Org.Id == 10121 {
  477. newprescribe.DialysisDurationHour = 4
  478. newprescribe.DialysisDurationMinute = 0
  479. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  480. }
  481. if adminUserInfo.Org.Id == 10445 {
  482. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  483. newprescribe.Remark = lastDialysisPrescription.Remark
  484. }
  485. err := service.AddSigleRecord(&newprescribe)
  486. //记录日志
  487. byterequest, _ := json.Marshal(newprescribe)
  488. prescriptionLog := models.XtDialysisPrescriptionLog{
  489. UserOrgId: adminUserInfo.Org.Id,
  490. Ctime: time.Now().Unix(),
  491. Mtime: 0,
  492. ErrLog: string(byterequest),
  493. AdminUserId: adminUserInfo.AdminUser.Id,
  494. RecordDate: newprescribe.RecordDate,
  495. PatientId: id,
  496. Source: "物联网上传",
  497. Status: 1,
  498. }
  499. service.CreatePrescriptionLog(prescriptionLog)
  500. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  501. redis := service.RedisClient()
  502. //清空key 值
  503. redis.Set(key, "", time.Second)
  504. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  505. redis.Set(keyTwo, "", time.Second)
  506. scheduleDateStartOne := thisTime.Format("2006-01-02")
  507. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  508. redis.Set(keyThree, "", time.Second)
  509. defer redis.Close()
  510. if err != nil {
  511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  512. }
  513. } else if system_dialysisPrescribe != nil {
  514. var newprescribe models.DialysisPrescription
  515. newprescribe.UserOrgId = system_dialysisPrescribe.UserOrgId
  516. newprescribe.PatientId = id
  517. newprescribe.Anticoagulant = system_dialysisPrescribe.Anticoagulant
  518. newprescribe.AnticoagulantShouji = system_dialysisPrescribe.AnticoagulantShouji
  519. newprescribe.AnticoagulantWeichi = system_dialysisPrescribe.AnticoagulantWeichi
  520. newprescribe.AnticoagulantZongliang = system_dialysisPrescribe.AnticoagulantZongliang
  521. newprescribe.AnticoagulantGaimingcheng = system_dialysisPrescribe.AnticoagulantGaimingcheng
  522. newprescribe.AnticoagulantGaijiliang = system_dialysisPrescribe.AnticoagulantGaijiliang
  523. newprescribe.ModeId = system_dialysisPrescribe.ModeId
  524. newprescribe.DialysisDuration = system_dialysisPrescribe.DialysisDuration
  525. newprescribe.ReplacementWay = system_dialysisPrescribe.ReplacementWay
  526. newprescribe.HemodialysisMachine = system_dialysisPrescribe.HemodialysisMachine
  527. newprescribe.BloodFilter = system_dialysisPrescribe.BloodFilter
  528. newprescribe.PerfusionApparatus = system_dialysisPrescribe.PerfusionApparatus
  529. newprescribe.BloodFlowVolume = system_dialysisPrescribe.BloodFlowVolume
  530. newprescribe.DisplaceLiqui = system_dialysisPrescribe.DisplaceLiqui
  531. newprescribe.Glucose = system_dialysisPrescribe.Glucose
  532. newprescribe.DialysateFlow = system_dialysisPrescribe.DialysateFlow
  533. newprescribe.Kalium = system_dialysisPrescribe.Kalium
  534. newprescribe.Sodium = system_dialysisPrescribe.Sodium
  535. newprescribe.Calcium = system_dialysisPrescribe.Calcium
  536. newprescribe.Bicarbonate = system_dialysisPrescribe.Bicarbonate
  537. newprescribe.DialysateTemperature = system_dialysisPrescribe.DialysateTemperature
  538. newprescribe.Conductivity = system_dialysisPrescribe.Conductivity
  539. newprescribe.BodyFluid = system_dialysisPrescribe.BodyFluid
  540. newprescribe.SpecialMedicine = system_dialysisPrescribe.SpecialMedicine
  541. newprescribe.SpecialMedicineOther = system_dialysisPrescribe.SpecialMedicineOther
  542. newprescribe.DisplaceLiquiPart = system_dialysisPrescribe.DisplaceLiquiPart
  543. newprescribe.DisplaceLiquiValue = system_dialysisPrescribe.DisplaceLiquiValue
  544. newprescribe.BloodAccess = system_dialysisPrescribe.BloodAccess
  545. newprescribe.Ultrafiltration = system_dialysisPrescribe.Ultrafiltration
  546. newprescribe.DialysisDurationHour = system_dialysisPrescribe.DialysisDurationHour
  547. newprescribe.DialysisDurationMinute = system_dialysisPrescribe.DialysisDurationMinute
  548. newprescribe.DialysateFormulation = system_dialysisPrescribe.DialysateFormulation
  549. newprescribe.Dialyzer = system_dialysisPrescribe.Dialyzer
  550. newprescribe.ReplacementTotal = system_dialysisPrescribe.ReplacementTotal
  551. newprescribe.DialyzerPerfusionApparatus = system_dialysisPrescribe.DialyzerPerfusionApparatus
  552. newprescribe.DialysisIrrigation = system_dialysisPrescribe.DialysisIrrigation
  553. newprescribe.DialysisDialyszers = system_dialysisPrescribe.DialysisDialyszers
  554. newprescribe.BodyFluidOther = system_dialysisPrescribe.BodyFluidOther
  555. newprescribe.TargetKtv = system_dialysisPrescribe.TargetKtv
  556. newprescribe.CreatedTime = time.Now().Unix()
  557. newprescribe.UpdatedTime = time.Now().Unix()
  558. newprescribe.RecordDate = theAssessmentDateTime
  559. newprescribe.DewaterAmount = dewater_amount
  560. newprescribe.TargetUltrafiltration = dewater_amount
  561. newprescribe.Chaptalization = lastDialysisPrescribe.Chaptalization
  562. newprescribe.BloodAccessPartId = lastDialysisPrescribe.BloodAccessPartId
  563. newprescribe.Status = 1
  564. newprescribe.PrescribingNumber = 1
  565. if adminUserInfo.Org.Id == 10340 {
  566. newprescribe.TargetUltrafiltration = 0
  567. }
  568. if adminUserInfo.Org.Id == 10121 {
  569. newprescribe.DialysisDurationHour = 4
  570. newprescribe.DialysisDurationMinute = 0
  571. newprescribe.BloodAccess = dialysisSolution.BloodAccess
  572. }
  573. if adminUserInfo.Org.Id == 10445 {
  574. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  575. newprescribe.Remark = lastDialysisPrescription.Remark
  576. }
  577. err := service.AddSigleRecord(&newprescribe)
  578. //记录日志
  579. byterequest, _ := json.Marshal(newprescribe)
  580. prescriptionLog := models.XtDialysisPrescriptionLog{
  581. UserOrgId: adminUserInfo.Org.Id,
  582. Ctime: time.Now().Unix(),
  583. Mtime: 0,
  584. ErrLog: string(byterequest),
  585. AdminUserId: adminUserInfo.AdminUser.Id,
  586. RecordDate: newprescribe.RecordDate,
  587. PatientId: id,
  588. Source: "物联网上传",
  589. Status: 1,
  590. }
  591. service.CreatePrescriptionLog(prescriptionLog)
  592. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  593. redis := service.RedisClient()
  594. //清空key 值
  595. redis.Set(key, "", time.Second)
  596. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  597. redis.Set(keyTwo, "", time.Second)
  598. scheduleDateStartOne := thisTime.Format("2006-01-02")
  599. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  600. redis.Set(keyThree, "", time.Second)
  601. defer redis.Close()
  602. if err != nil {
  603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  604. }
  605. } else {
  606. var newprescribe models.DialysisPrescription
  607. newprescribe.UserOrgId = adminUserInfo.Org.Id
  608. newprescribe.PatientId = id
  609. newprescribe.ModeId = mode_id
  610. newprescribe.CreatedTime = time.Now().Unix()
  611. newprescribe.UpdatedTime = time.Now().Unix()
  612. newprescribe.RecordDate = theAssessmentDateTime
  613. newprescribe.DewaterAmount = dewater_amount
  614. newprescribe.TargetUltrafiltration = dewater_amount
  615. newprescribe.Status = 1
  616. if adminUserInfo.Org.Id == 10445 {
  617. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  618. newprescribe.Remark = lastDialysisPrescription.Remark
  619. }
  620. err := service.AddSigleRecord(&newprescribe)
  621. //记录日志
  622. byterequest, _ := json.Marshal(newprescribe)
  623. prescriptionLog := models.XtDialysisPrescriptionLog{
  624. UserOrgId: adminUserInfo.Org.Id,
  625. Ctime: time.Now().Unix(),
  626. Mtime: 0,
  627. ErrLog: string(byterequest),
  628. AdminUserId: adminUserInfo.AdminUser.Id,
  629. RecordDate: newprescribe.RecordDate,
  630. PatientId: id,
  631. Source: "物联网上传",
  632. Status: 1,
  633. }
  634. service.CreatePrescriptionLog(prescriptionLog)
  635. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  636. redis := service.RedisClient()
  637. //清空key 值
  638. redis.Set(key, "", time.Second)
  639. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  640. redis.Set(keyTwo, "", time.Second)
  641. scheduleDateStartOne := thisTime.Format("2006-01-02")
  642. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  643. redis.Set(keyThree, "", time.Second)
  644. defer redis.Close()
  645. if err != nil {
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  647. }
  648. }
  649. }
  650. if dialysisPrescribe != nil && dialysisPrescribe.TargetUltrafiltration == 0 {
  651. dialysisPrescribe.UpdatedTime = time.Now().Unix()
  652. dialysisPrescribe.RecordDate = theAssessmentDateTime
  653. dialysisPrescribe.DewaterAmount = dewater_amount
  654. dialysisPrescribe.TargetUltrafiltration = dewater_amount
  655. dialysisPrescribe.Status = 1
  656. if adminUserInfo.Org.Id == 10340 {
  657. dialysisPrescribe.TargetUltrafiltration = 0
  658. }
  659. if adminUserInfo.Org.Id == 10445 {
  660. lastDialysisPrescription, _ := service.GetLastDialysisPrescription(id, adminUserInfo.Org.Id)
  661. dialysisPrescribe.Remark = lastDialysisPrescription.Remark
  662. }
  663. updateErr := service.UpDateDialysisPrescription(dialysisPrescribe)
  664. //记录日志
  665. byterequest, _ := json.Marshal(dialysisPrescribe)
  666. prescriptionLog := models.XtDialysisPrescriptionLog{
  667. UserOrgId: adminUserInfo.Org.Id,
  668. Ctime: time.Now().Unix(),
  669. Mtime: 0,
  670. ErrLog: string(byterequest),
  671. AdminUserId: adminUserInfo.AdminUser.Id,
  672. RecordDate: dialysisPrescribe.RecordDate,
  673. PatientId: id,
  674. Source: "物联网上传",
  675. Status: 1,
  676. }
  677. service.CreatePrescriptionLog(prescriptionLog)
  678. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":" + strconv.FormatInt(mode_id, 10) + ":dialysis_prescribe"
  679. redis := service.RedisClient()
  680. //清空key 值
  681. redis.Set(key, "", time.Second)
  682. keyTwo := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":prescriptions_list_all"
  683. redis.Set(keyTwo, "", time.Second)
  684. scheduleDateStartOne := thisTime.Format("2006-01-02")
  685. keyThree := "scheduals_" + scheduleDateStartOne + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  686. redis.Set(keyThree, "", time.Second)
  687. defer redis.Close()
  688. if updateErr != nil {
  689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCommitFail)
  690. }
  691. }
  692. theEvaluation, getPEErr := service.MobileGetPredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  693. if getPEErr != nil {
  694. c.ErrorLog("获取透前评估失败:%v", getPEErr)
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  696. return
  697. }
  698. var evaluation models.PredialysisEvaluation
  699. if theEvaluation != nil {
  700. evaluation = *theEvaluation
  701. }
  702. // 如果今天没有透前评估,则插入新的数据
  703. if theEvaluation == nil {
  704. evaluation.CreatedTime = time.Now().Unix()
  705. evaluation.Status = 1
  706. evaluation.AssessmentDate = theAssessmentDateTime
  707. evaluation.PatientId = id
  708. evaluation.UserOrgId = adminUserInfo.Org.Id
  709. // 获取上一次透前评估信息,部分数据是需要从上一次透前评估继承
  710. lastPredialysisEvaluation, _ := service.MobileGetLastTimePredialysisEvaluationOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  711. // 获取上一次透后评估,插入本次透前评估的上次透后体重(weight_after_last_transparency)字段
  712. assessmentAfterDislysis, getAADErr := service.MobileGetLastTimeAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  713. if getAADErr != nil {
  714. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  715. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  716. return
  717. }
  718. // 获取干体重,先从干体重配置里去读,如果没有,则读取上一次透前评估的干体重
  719. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  720. if err == gorm.ErrRecordNotFound {
  721. if lastPredialysisEvaluation != nil {
  722. evaluation.DryWeight = lastPredialysisEvaluation.DryWeight
  723. } else {
  724. evaluation.DryWeight = 0
  725. }
  726. } else {
  727. evaluation.DryWeight = weight.DryWeight
  728. }
  729. if assessmentAfterDislysis != nil {
  730. evaluation.WeightAfterLastTransparency = assessmentAfterDislysis.WeightAfter
  731. }
  732. if lastPredialysisEvaluation != nil {
  733. evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
  734. evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
  735. evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight
  736. evaluation.Temperature = lastPredialysisEvaluation.Temperature
  737. evaluation.BreathingRate = lastPredialysisEvaluation.BreathingRate
  738. evaluation.Catheter = lastPredialysisEvaluation.Catheter
  739. evaluation.InternalFistula = lastPredialysisEvaluation.InternalFistula
  740. evaluation.PulseFrequency = lastPredialysisEvaluation.PulseFrequency
  741. evaluation.Complication = lastPredialysisEvaluation.Complication
  742. evaluation.LastPostDialysis = lastPredialysisEvaluation.LastPostDialysis
  743. evaluation.DialysisInterphase = lastPredialysisEvaluation.DialysisInterphase
  744. evaluation.SymptomBeforeDialysis = lastPredialysisEvaluation.SymptomBeforeDialysis
  745. evaluation.PunctureNeedle = lastPredialysisEvaluation.PunctureNeedle
  746. evaluation.PunctureWay = lastPredialysisEvaluation.PunctureWay
  747. evaluation.InternalFistulaSkin = lastPredialysisEvaluation.InternalFistulaSkin //血透通路皮肤情况
  748. evaluation.CatheterBend = lastPredialysisEvaluation.CatheterBend //导管打折
  749. evaluation.IsHemorrhage = lastPredialysisEvaluation.IsHemorrhage //出血
  750. evaluation.IsInfect = lastPredialysisEvaluation.IsInfect //感染
  751. evaluation.Exposed = lastPredialysisEvaluation.Exposed // 外漏
  752. evaluation.DialysisCount = lastPredialysisEvaluation.DialysisCount //呼吸频次
  753. evaluation.Phinholing = lastPredialysisEvaluation.Phinholing //针眼
  754. evaluation.Remark = lastPredialysisEvaluation.Remark
  755. if adminUserInfo.Org.Id == 10318 || adminUserInfo.Org.Id == 10490 {
  756. evaluation.Remark = ""
  757. }
  758. if adminUserInfo.Org.Id == 10340 || adminUserInfo.Org.Id == 10447 {
  759. evaluation.BreathingRate = "20"
  760. }
  761. if adminUserInfo.Org.Id == 10445 {
  762. evaluation.VenousCatheterization = lastPredialysisEvaluation.VenousCatheterization
  763. }
  764. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 || adminUserInfo.Org.Id == 10471 {
  765. evaluation.PulseFrequency = 80
  766. }
  767. if adminUserInfo.Org.Id == 10440 {
  768. evaluation.Temperature = 36.5
  769. }
  770. if adminUserInfo.Org.Id == 10469 {
  771. evaluation.Temperature = 36.5
  772. }
  773. if adminUserInfo.Org.Id == 10471 {
  774. evaluation.Temperature = 36.5
  775. }
  776. }
  777. } else {
  778. evaluation.UpdatedTime = time.Now().Unix()
  779. }
  780. evaluation.WeightBefore = weighing_before
  781. evaluation.AssessmentTime = time.Now().Unix()
  782. err := service.UpadatePredialysisEvaluation(&evaluation)
  783. //记录日志
  784. byterequest, _ := json.Marshal(evaluation)
  785. beforLog := models.XtAssessmentBeforeDislysisLog{
  786. UserOrgId: adminUserInfo.Org.Id,
  787. Ctime: time.Now().Unix(),
  788. Mtime: 0,
  789. ErrLog: string(byterequest),
  790. AdminUserId: adminUserInfo.AdminUser.Id,
  791. RecordDate: evaluation.AssessmentDate,
  792. PatientId: id,
  793. Source: "物联网上传",
  794. Status: 1,
  795. }
  796. service.CreateBeforLog(beforLog)
  797. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_before_dislysis"
  798. redis := service.RedisClient()
  799. //清空key 值
  800. redis.Set(key, "", time.Second)
  801. keyOne := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_befores_list_all"
  802. redis.Set(keyOne, "", time.Second)
  803. assessdateDateStart := thisTime.Format("2006-01-02")
  804. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  805. redis.Set(keyTwo, "", time.Second)
  806. redis.Close()
  807. if err != nil {
  808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  809. return
  810. }
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "msg": "ok",
  813. "evaluation": evaluation,
  814. })
  815. return
  816. } else {
  817. // 保存透后相关数据
  818. assessmentAfterDislysis, getAADErr := service.MobileGetAssessmentAfterDislysisOne(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  819. if getAADErr != nil {
  820. c.ErrorLog("获取透后评估失败:%v", getAADErr)
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  822. return
  823. }
  824. var afterevaluation models.AssessmentAfterDislysis
  825. if assessmentAfterDislysis != nil {
  826. afterevaluation = *assessmentAfterDislysis
  827. }
  828. if assessmentAfterDislysis == nil {
  829. afterevaluation.CreatedTime = time.Now().Unix()
  830. afterevaluation.Status = 1
  831. afterevaluation.AssessmentDate = theAssessmentDateTime
  832. afterevaluation.PatientId = id
  833. afterevaluation.UserOrgId = adminUserInfo.Org.Id
  834. } else {
  835. afterevaluation.UpdatedTime = time.Now().Unix()
  836. }
  837. afterevaluation.WeightAfter = weight_after
  838. afterevaluation.WeightLoss = weight_loss
  839. if adminUserInfo.Org.Id == 10138 {
  840. afterevaluation.LeaveOfficeMethod = assessmentAfterDislysis.LeaveOfficeMethod //离科方式
  841. afterevaluation.Lapse = assessmentAfterDislysis.Lapse //转归
  842. afterevaluation.Consciousness = assessmentAfterDislysis.Consciousness //意识
  843. afterevaluation.Fallrisk = assessmentAfterDislysis.Fallrisk
  844. }
  845. if adminUserInfo.Org.Id == 10307 || adminUserInfo.Org.Id == 10445 {
  846. afterevaluation.ActualUltrafiltration = weight_loss * 1000 //中能建的计量单位是毫升(ml)
  847. }
  848. //北方营口
  849. if adminUserInfo.Org.Id == 10445 {
  850. prescribe, _ := service.MobileGetDialysisPrescribe(adminUserInfo.Org.Id, id, theAssessmentDateTime)
  851. afterevaluation.ActualDisplacement = prescribe.DisplaceLiquiValue
  852. }
  853. //蓬安济民
  854. if adminUserInfo.Org.Id == 9829 || adminUserInfo.Org.Id == 10469 {
  855. afterevaluation.PulseFrequency = 80
  856. }
  857. err := service.UpdateAssessmentAfterDislysisRecord(&afterevaluation)
  858. //记录日志
  859. byterequest, _ := json.Marshal(afterevaluation)
  860. afterDialysisLog := models.XtAssessmentAfterDialysisLog{
  861. UserOrgId: afterevaluation.UserOrgId,
  862. PatientId: afterevaluation.PatientId,
  863. RecordDate: afterevaluation.AssessmentDate,
  864. Status: 1,
  865. ErrLog: string(byterequest),
  866. AdminUserId: adminUserInfo.AdminUser.Id,
  867. Ctime: time.Now().Unix(),
  868. Mtime: 0,
  869. Source: "物联网称重",
  870. }
  871. service.CreateAfterDialysisLog(afterDialysisLog)
  872. key := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis"
  873. redis := service.RedisClient()
  874. //清空key 值
  875. redis.Set(key, "", time.Second)
  876. keyThree := strconv.FormatInt(adminUserInfo.Org.Id, 10) + ":" + strconv.FormatInt(theAssessmentDateTime, 10) + ":assessment_after_dislysis_list_all"
  877. redis.Set(keyThree, "", time.Second)
  878. assessdateDateStart := thisTime.Format("2006-01-02")
  879. keyTwo := "scheduals_" + assessdateDateStart + "_" + strconv.FormatInt(adminUserInfo.Org.Id, 10)
  880. redis.Set(keyTwo, "", time.Second)
  881. redis.Close()
  882. if err == nil {
  883. c.ServeSuccessJSON(map[string]interface{}{
  884. "assessmentAfterDislysis": afterevaluation,
  885. })
  886. }
  887. }
  888. }
  889. func (c *CheckWeightApiController) SetSyncTime() {
  890. sn := c.GetString("sn")
  891. if len(sn) > 0 {
  892. redis := service.RedisClient()
  893. defer redis.Close()
  894. redis.Set(sn, 0, 0)
  895. }
  896. serviceTime := time.Now().Unix()
  897. c.ServeSuccessJSON(map[string]interface{}{
  898. "status": 1,
  899. "servicetime": serviceTime,
  900. })
  901. }
  902. func (c *CheckWeightApiController) GetPatientList() {
  903. ftype, _ := c.GetInt64("type", 0)
  904. sn := c.GetString("sn")
  905. syncTime := int64(0)
  906. redis := service.RedisClient()
  907. defer redis.Close()
  908. if len(sn) > 0 {
  909. syncTimeStr, _ := redis.Get(sn).Result()
  910. syncTime, _ = strconv.ParseInt(syncTimeStr, 10, 64)
  911. }
  912. if ftype == 1 {
  913. timeNow := time.Now().Unix()
  914. redis.Set(sn, timeNow, 0)
  915. }
  916. adminUserInfo := c.GetMobileAdminUserInfo()
  917. patientList, total, error := service.GetPatientListByUpdateTime(adminUserInfo.Org.Id, int64(syncTime))
  918. need_update := 0
  919. if syncTime == 0 {
  920. need_update = 1
  921. }
  922. if error != nil {
  923. c.ErrorLog("获取病人列表失败:%v", error)
  924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  925. return
  926. }
  927. serviceTime := time.Now().Unix()
  928. c.ServeSuccessJSON(map[string]interface{}{
  929. "need_update": need_update,
  930. "patientlist": patientList,
  931. "total": total,
  932. "servicetime": serviceTime,
  933. })
  934. }
  935. func (c *CheckWeightApiController) GetPatientListForSchedules() {
  936. thisTime := time.Now()
  937. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  938. timeLayout := "2006-01-02 15:04:05"
  939. loc, _ := time.LoadLocation("Local")
  940. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  941. syncTime := theStartTime.Unix()
  942. adminUserInfo := c.GetMobileAdminUserInfo()
  943. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  944. patientSchedule := make([]map[string]interface{}, 0)
  945. for _, item := range patientList {
  946. patientTemp := make(map[string]interface{})
  947. patientTemp["patient_id"] = item.PatientId
  948. patientTemp["patient_name"] = item.Patient.Name
  949. patientTemp["schedule_type"] = item.ScheduleType
  950. patientSchedule = append(patientSchedule, patientTemp)
  951. }
  952. if error != nil {
  953. c.ErrorLog("获取病人列表失败:%v", error)
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  955. return
  956. }
  957. serviceTime := time.Now().Unix()
  958. c.ServeSuccessJSON(map[string]interface{}{
  959. "patientlist": patientSchedule,
  960. "total": total,
  961. "servicetime": serviceTime,
  962. })
  963. }
  964. func (c *CheckWeightApiController) GetPatientListForSchedulesFind() {
  965. patient_name := c.GetString("patient_name") //脉率
  966. thisTime := time.Now()
  967. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  968. timeLayout := "2006-01-02 15:04:05"
  969. loc, _ := time.LoadLocation("Local")
  970. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  971. syncTime := theStartTime.Unix()
  972. adminUserInfo := c.GetMobileAdminUserInfo()
  973. if len(patient_name) == 0 {
  974. patientList, total, error := service.GetPatientListBySchedules(adminUserInfo.Org.Id, syncTime)
  975. patientSchedule := make([]map[string]interface{}, 0)
  976. for _, item := range patientList {
  977. patientTemp := make(map[string]interface{})
  978. patientTemp["patient_id"] = item.PatientId
  979. patientTemp["patient_name"] = item.Patient.Name
  980. patientTemp["schedule_type"] = item.ScheduleType
  981. patientSchedule = append(patientSchedule, patientTemp)
  982. }
  983. if error != nil {
  984. c.ErrorLog("获取病人列表失败:%v", error)
  985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  986. return
  987. }
  988. serviceTime := time.Now().Unix()
  989. c.ServeSuccessJSON(map[string]interface{}{
  990. "patientlist": patientSchedule,
  991. "total": total,
  992. "servicetime": serviceTime,
  993. })
  994. } else {
  995. patientList, total, error := service.GetPatientListBySchedulesFind(adminUserInfo.Org.Id, syncTime, patient_name)
  996. patientSchedule := make([]map[string]interface{}, 0)
  997. for _, item := range patientList {
  998. if item.Patient.ID > 0 {
  999. patientTemp := make(map[string]interface{})
  1000. patientTemp["patient_id"] = item.PatientId
  1001. patientTemp["patient_name"] = item.Patient.Name
  1002. patientTemp["schedule_type"] = item.ScheduleType
  1003. patientSchedule = append(patientSchedule, patientTemp)
  1004. }
  1005. }
  1006. if error != nil {
  1007. c.ErrorLog("获取病人列表失败:%v", error)
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1009. return
  1010. }
  1011. serviceTime := time.Now().Unix()
  1012. c.ServeSuccessJSON(map[string]interface{}{
  1013. "patientlist": patientSchedule,
  1014. "total": total,
  1015. "servicetime": serviceTime,
  1016. })
  1017. }
  1018. }
  1019. func (c *CheckWeightApiController) GetPatientListById() {
  1020. patientId, _ := c.GetInt64("patient_id", 0)
  1021. if patientId <= 0 {
  1022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1023. return
  1024. }
  1025. adminUserInfo := c.GetMobileAdminUserInfo()
  1026. patient, error := service.GetPatientListById(adminUserInfo.Org.Id, patientId)
  1027. if error != nil {
  1028. c.ErrorLog("获取病人详情失败:%v", error)
  1029. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1030. return
  1031. }
  1032. c.ServeSuccessJSON(map[string]interface{}{
  1033. "patientinfo": patient,
  1034. })
  1035. }
  1036. func (c *CheckWeightApiController) GetPatientInfoDialysis() {
  1037. id, _ := c.GetInt64("patient", 0)
  1038. if id <= 0 {
  1039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1040. return
  1041. }
  1042. adminUserInfo := c.GetMobileAdminUserInfo()
  1043. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1044. if patient.ID <= 0 {
  1045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1046. return
  1047. }
  1048. var dialysisinfo map[string]interface{}
  1049. dialysisinfo = make(map[string]interface{})
  1050. dialysisinfo["id"] = patient.ID
  1051. dialysisinfo["name"] = patient.Name
  1052. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1053. thisTime := time.Now()
  1054. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1055. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1056. timeLayout := "2006-01-02 15:04:05"
  1057. loc, _ := time.LoadLocation("Local")
  1058. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1059. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1060. startTime := theStartTime.Unix()
  1061. endTime := theEndTime.Unix()
  1062. // 判断当前用户是透析前还是透析后
  1063. var dialysistype int
  1064. _, dialysisOrder := service.FindDialysisRecordById(adminUserInfo.Org.Id, id, startTime)
  1065. if dialysisOrder == nil {
  1066. dialysistype = 1
  1067. } else {
  1068. dialysistype = 2
  1069. }
  1070. // 获取当前或者下次排班信息
  1071. var sc map[string]interface{}
  1072. sc = make(map[string]interface{})
  1073. if dialysistype == 1 {
  1074. daySchedule, _ := service.GetPatientScheduleFormDay(adminUserInfo.Org.Id, startTime, endTime, id)
  1075. if len(daySchedule) <= 0 {
  1076. sc["code"] = 1
  1077. sc["msg"] = "抱歉,您今天没有排版!"
  1078. sc["mode"] = 0
  1079. sc["data"] = daySchedule
  1080. } else {
  1081. if daySchedule[0].Schedule.ID > 0 {
  1082. sc["code"] = 0
  1083. sc["msg"] = ""
  1084. sc["mode"] = daySchedule[0].Schedule.ModeId
  1085. sc["data"] = daySchedule
  1086. } else {
  1087. sc["code"] = 1
  1088. sc["msg"] = "抱歉,您今天没有排版!"
  1089. sc["mode"] = 0
  1090. sc["data"] = daySchedule
  1091. }
  1092. }
  1093. // 排队叫号的签到
  1094. go func() {
  1095. ssoDomain := beego.AppConfig.String("call_domain")
  1096. api := ssoDomain + "/index/patientsign/" + strconv.FormatInt(adminUserInfo.Org.Id, 10) + "/" + strconv.FormatInt(id, 10)
  1097. values := make(url.Values)
  1098. http.PostForm(api, values)
  1099. }()
  1100. } else {
  1101. nextSchedule, _ := service.GetNextSchedule(adminUserInfo.Org.Id, endTime, id)
  1102. if len(nextSchedule) <= 0 {
  1103. sc["code"] = 1
  1104. sc["msg"] = "抱歉,您后续没有排版!"
  1105. sc["mode"] = 0
  1106. sc["data"] = nextSchedule
  1107. } else {
  1108. if nextSchedule[0].Schedule.ID > 0 {
  1109. sc["code"] = 0
  1110. sc["msg"] = ""
  1111. sc["mode"] = nextSchedule[0].Schedule.ModeId
  1112. sc["data"] = nextSchedule
  1113. } else {
  1114. sc["code"] = 1
  1115. sc["msg"] = "抱歉,您后续没有排版!"
  1116. sc["mode"] = 0
  1117. sc["data"] = nextSchedule
  1118. }
  1119. }
  1120. }
  1121. switch sc["mode"] {
  1122. case 1:
  1123. sc["mode"] = "HD"
  1124. case 2:
  1125. sc["mode"] = "HDF"
  1126. case 3:
  1127. sc["mode"] = "HD+HP"
  1128. case 4:
  1129. sc["mode"] = "HP"
  1130. case 5:
  1131. sc["mode"] = "HF"
  1132. case 6:
  1133. sc["mode"] = "SCUF"
  1134. case 7:
  1135. sc["mode"] = "IUF"
  1136. case 8:
  1137. sc["mode"] = "HFHD"
  1138. case 9:
  1139. sc["mode"] = "HFHD+HP"
  1140. case 10:
  1141. sc["mode"] = "PHF"
  1142. case 11:
  1143. sc["mode"] = "HFR"
  1144. case 12:
  1145. sc["mode"] = "HDF+HP"
  1146. case 13:
  1147. sc["mode"] = "CRRT"
  1148. case 14:
  1149. sc["mode"] = "腹水回输"
  1150. case 15:
  1151. sc["mode"] = "HD前置换"
  1152. case 16:
  1153. sc["mode"] = "HD后置换"
  1154. case 17:
  1155. sc["mode"] = "HDF前置换"
  1156. case 18:
  1157. sc["mode"] = "HDF后置换"
  1158. default:
  1159. sc["mode"] = "HD"
  1160. }
  1161. // 获取患者透前干体重或者获取患者透前体重
  1162. var dry_weight map[string]interface{}
  1163. dry_weight = make(map[string]interface{})
  1164. var after_dry_weight map[string]interface{}
  1165. after_dry_weight = make(map[string]interface{})
  1166. if dialysistype == 1 {
  1167. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1168. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1169. if err == gorm.ErrRecordNotFound {
  1170. if getLPEErr != nil {
  1171. dry_weight["code"] = 1
  1172. dry_weight["dry_weight"] = nil
  1173. } else {
  1174. if lastPredialysisEvaluation == nil {
  1175. dry_weight["code"] = 1
  1176. dry_weight["dry_weight"] = nil
  1177. } else {
  1178. // 传输的干体重实际为干体重加上衣服重
  1179. dry_weight["code"] = 0
  1180. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1181. }
  1182. }
  1183. } else {
  1184. if err != nil {
  1185. dry_weight["code"] = 1
  1186. dry_weight["dry_weight"] = nil
  1187. } else {
  1188. dry_weight["code"] = 0
  1189. if getLPEErr != nil {
  1190. dry_weight["code"] = 0
  1191. dry_weight["dry_weight"] = weight.DryWeight
  1192. } else {
  1193. if lastPredialysisEvaluation == nil {
  1194. dry_weight["code"] = 1
  1195. dry_weight["dry_weight"] = weight.DryWeight
  1196. } else {
  1197. // 传输的干体重实际为干体重加上衣服重
  1198. dry_weight["code"] = 0
  1199. dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1200. }
  1201. }
  1202. }
  1203. }
  1204. } else {
  1205. predialysisEvaluation, getPEErr := service.MobileGetPredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1206. if getPEErr != nil {
  1207. dry_weight["code"] = 1
  1208. dry_weight["dry_weight"] = nil
  1209. } else {
  1210. if predialysisEvaluation == nil {
  1211. dry_weight["code"] = 1
  1212. dry_weight["dry_weight"] = nil
  1213. } else {
  1214. dry_weight["code"] = 0
  1215. dry_weight["dry_weight"] = predialysisEvaluation.WeightBefore
  1216. }
  1217. }
  1218. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, endTime)
  1219. weight, err := service.FindLastDryWeightAdjust(adminUserInfo.Org.Id, id)
  1220. if err == gorm.ErrRecordNotFound {
  1221. if getLPEErr != nil {
  1222. after_dry_weight["code"] = 1
  1223. after_dry_weight["dry_weight"] = nil
  1224. } else {
  1225. if lastPredialysisEvaluation == nil {
  1226. after_dry_weight["code"] = 1
  1227. after_dry_weight["dry_weight"] = nil
  1228. } else {
  1229. // 传输的干体重实际为干体重加上衣服重
  1230. after_dry_weight["code"] = 0
  1231. after_dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1232. }
  1233. }
  1234. } else {
  1235. if err != nil {
  1236. after_dry_weight["code"] = 1
  1237. after_dry_weight["dry_weight"] = nil
  1238. } else {
  1239. after_dry_weight["code"] = 0
  1240. if getLPEErr != nil {
  1241. after_dry_weight["code"] = 0
  1242. after_dry_weight["dry_weight"] = weight.DryWeight
  1243. } else {
  1244. if lastPredialysisEvaluation == nil {
  1245. after_dry_weight["code"] = 1
  1246. after_dry_weight["dry_weight"] = weight.DryWeight
  1247. } else {
  1248. // 传输的干体重实际为干体重加上衣服重
  1249. after_dry_weight["code"] = 0
  1250. after_dry_weight["dry_weight"] = weight.DryWeight + lastPredialysisEvaluation.AdditionalWeight
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. c.ServeSuccessJSON(map[string]interface{}{
  1257. "dialysistype": dialysistype,
  1258. "patient": dialysisinfo,
  1259. "schedule": sc,
  1260. "dryweight": dry_weight,
  1261. "after_dry_weight": after_dry_weight,
  1262. })
  1263. return
  1264. }
  1265. func (c *CheckWeightApiController) GetPatientInfoBeforeDialysis() {
  1266. id, _ := c.GetInt64("patient", 0)
  1267. if id <= 0 {
  1268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1269. return
  1270. }
  1271. adminUserInfo := c.GetMobileAdminUserInfo()
  1272. patient, _ := service.FindPatientByIdWithDiseases(adminUserInfo.Org.Id, id)
  1273. if patient.ID == 0 {
  1274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1275. return
  1276. }
  1277. var dialysisinfo map[string]interface{}
  1278. dialysisinfo = make(map[string]interface{})
  1279. dialysisinfo["id"] = patient.ID
  1280. dialysisinfo["name"] = patient.Name
  1281. dialysisinfo["dialysis_no"] = patient.DialysisNo
  1282. thisTime := time.Now()
  1283. scheduleDateStart := thisTime.Format("2006-01-02") + " 00:00:00"
  1284. scheduleDateEnd := thisTime.Format("2006-01-02") + " 23:59:59"
  1285. fmt.Println(scheduleDateStart, scheduleDateEnd)
  1286. timeLayout := "2006-01-02 15:04:05"
  1287. loc, _ := time.LoadLocation("Local")
  1288. theStartTime, _ := time.ParseInLocation(timeLayout, scheduleDateStart, loc)
  1289. theEndTime, _ := time.ParseInLocation(timeLayout, scheduleDateEnd, loc)
  1290. fmt.Println(theStartTime, theEndTime)
  1291. startTime := theStartTime.Unix()
  1292. endTime := theEndTime.Unix()
  1293. var sc map[string]interface{}
  1294. sc = make(map[string]interface{})
  1295. //一天只有排班一次
  1296. daySchedule, _ := service.GetDaySchedule(adminUserInfo.Org.Id, startTime, endTime, id)
  1297. if daySchedule.ID > 0 {
  1298. switch daySchedule.ModeId {
  1299. case 1:
  1300. sc["mode"] = "HD"
  1301. case 2:
  1302. sc["mode"] = "HDF"
  1303. case 3:
  1304. sc["mode"] = "HD+HP"
  1305. case 4:
  1306. sc["mode"] = "HP"
  1307. case 5:
  1308. sc["mode"] = "HF"
  1309. case 6:
  1310. sc["mode"] = "SCUF"
  1311. case 7:
  1312. sc["mode"] = "IUF"
  1313. case 8:
  1314. sc["mode"] = "HFHD"
  1315. case 9:
  1316. sc["mode"] = "HFHD+HP"
  1317. case 10:
  1318. sc["mode"] = "PHF"
  1319. case 11:
  1320. sc["mode"] = "HFR"
  1321. case 12:
  1322. sc["mode"] = "HDF+HP"
  1323. case 13:
  1324. sc["mode"] = "CRRT"
  1325. case 14:
  1326. sc["mode"] = "腹水回输"
  1327. case 15:
  1328. sc["mode"] = "HD前置换"
  1329. case 16:
  1330. sc["mode"] = "HD后置换"
  1331. case 17:
  1332. sc["mode"] = "HDF前置换"
  1333. case 18:
  1334. sc["mode"] = "HDF后置换"
  1335. default:
  1336. sc["mode"] = "HD"
  1337. }
  1338. sc["code"] = 0
  1339. sc["msg"] = ""
  1340. sc["data"] = daySchedule
  1341. } else {
  1342. sc["code"] = 1
  1343. sc["msg"] = "抱歉,您今天没有排版!"
  1344. sc["mode"] = ""
  1345. sc["data"] = daySchedule
  1346. }
  1347. fmt.Println(sc)
  1348. type dryWeight struct {
  1349. code int
  1350. dry_weight float64
  1351. }
  1352. var dry_weight map[string]interface{}
  1353. dry_weight = make(map[string]interface{})
  1354. lastPredialysisEvaluation, getLPEErr := service.MobileGetLastTimePredialysisEvaluation(adminUserInfo.Org.Id, id, startTime)
  1355. if getLPEErr != nil {
  1356. dry_weight["code"] = 1
  1357. dry_weight["dry_weight"] = nil
  1358. } else {
  1359. if lastPredialysisEvaluation == nil {
  1360. dry_weight["code"] = 1
  1361. dry_weight["dry_weight"] = nil
  1362. } else {
  1363. dry_weight["code"] = 0
  1364. dry_weight["dry_weight"] = lastPredialysisEvaluation.DryWeight
  1365. }
  1366. }
  1367. c.ServeSuccessJSON(map[string]interface{}{
  1368. "patient": dialysisinfo,
  1369. "schedule": sc,
  1370. "dryweight": dry_weight,
  1371. })
  1372. return
  1373. }