check_weight_api_controller.go 57KB

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