diff --git a/HealthMonitor.Service/Cache/PersonCacheManager.cs b/HealthMonitor.Service/Cache/PersonCacheManager.cs index ae97234..ec0b78d 100644 --- a/HealthMonitor.Service/Cache/PersonCacheManager.cs +++ b/HealthMonitor.Service/Cache/PersonCacheManager.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using TelpoDataService.Util; using TelpoDataService.Util.Clients; using TelpoDataService.Util.Entities.GpsCard; +using TelpoDataService.Util.Entities.GpsLocationHistory; using TelpoDataService.Util.Models; using TelpoDataService.Util.QueryObjects; @@ -23,8 +24,17 @@ namespace HealthMonitor.Service.Cache //注意要改用 redis DB7 数据库 ,Prefix=TELPO private const string CACHE_HASH_KEY_GPSDEVICEPERSON = "#GPSDEVICE_PERSON_HASH"; - //注意要改用 redis DB7 数据库 ,Prefix=TELPO + #region db10 + // 周期性体温 + private const string CACHE_HASH_KEY_TEMP_PERIODICITY = "#HM_PERIODICITY_TEMP_HASH"; + + // 周期性步数 + private const string CACHE_HASH_KEY_STEP_PERIODICITY = "#HM_PERIODICITY_STEP_HASH"; + + // 周期性血压 + private const string CACHE_HASH_KEY_BLOODPRESS_PERIODICITY = "#HM_PERIODICITY_BLOODPRESS_HASH"; + #endregion private readonly GpsCardAccessorClient _personApiClient; private readonly ILogger _logger; @@ -165,5 +175,69 @@ namespace HealthMonitor.Service.Cache return flag; } + + + #region 生理健康(步数、周期性体温、周期性血压) + // 周期性体温 + public async Task GetTemperaturePeriodicityAsync(string sn) + { + try + { + var res=await RedisHelper.HGetAsync(CACHE_HASH_KEY_TEMP_PERIODICITY, sn); + if (!string.IsNullOrEmpty(res)) + { + return JsonConvert.DeserializeObject(res)!; + } + + } + catch (Exception ex) + { + + _logger.LogError($"Redis发生异常:{ex.Message}, {ex.StackTrace}"); + } + return null; + + } + + // 周期性步数 + public async Task GetStepPeriodicityAsync(string sn ) + { + try + { + var res = await RedisHelper.HGetAsync(CACHE_HASH_KEY_STEP_PERIODICITY, sn); + if (!string.IsNullOrEmpty(res)) + { + return JsonConvert.DeserializeObject(res)!; + } + } + catch (Exception ex) + { + + _logger.LogError($"Redis发生异常:{ex.Message}, {ex.StackTrace}"); + } + return null; + } + + // 周期性血压 + public async Task GetBloodPressPeriodicityAsync(string sn) + { + try + { + var res = await RedisHelper.HGetAsync(CACHE_HASH_KEY_BLOODPRESS_PERIODICITY, sn); + if (!string.IsNullOrEmpty(res)) + { + return JsonConvert.DeserializeObject(res)!; + } + } + catch (Exception ex) + { + + _logger.LogError($"Redis发生异常:{ex.Message}, {ex.StackTrace}"); + } + return null; + } + + #endregion + } } diff --git a/HealthMonitor.Service/HealthMonitor.Service.csproj b/HealthMonitor.Service/HealthMonitor.Service.csproj index 94bca01..84476d2 100644 --- a/HealthMonitor.Service/HealthMonitor.Service.csproj +++ b/HealthMonitor.Service/HealthMonitor.Service.csproj @@ -16,7 +16,7 @@ - + diff --git a/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj b/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj index 8261728..3e98ffa 100644 --- a/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj +++ b/HealthMonitor.WebApi/HealthMonitor.WebApi.csproj @@ -11,7 +11,7 @@ - + diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index 6deb6b4..774427c 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -53,6 +53,8 @@ namespace HealthMonitor.WebApi private readonly GpsLocationHistoryAccessorClient _hisFetalHeartApiClient; private readonly GpsLocationHistoryAccessorClient _hisFetalMovementApiClient; + private readonly GpsLocationHistoryAccessorClient _hisPsychResultApiClient; + private readonly MqProcessLogic _serviceMqProcess; private CancellationTokenSource _tokenSource = default!; @@ -63,6 +65,7 @@ namespace HealthMonitor.WebApi TDengineDataSubcribe tdEngineDataSubcribe, TDengineService serviceDengine, GpsLocationHistoryAccessorClient hisFetalHeartApiClient, GpsLocationHistoryAccessorClient hisFetalMovementApiClient, + GpsLocationHistoryAccessorClient hisGpsPsychResultApiClient, FetalMovementNormalValueRangeCacheManager fetalMovementNormalValueRangeCacheMgr, MqProcessLogic serviceMqProcess, HttpHelper httpHelper, EtcdService serviceEtcd, DeviceCacheManager deviceCacheMgr) { @@ -80,8 +83,10 @@ namespace HealthMonitor.WebApi _deviceCacheMgr = deviceCacheMgr; _hisFetalHeartApiClient = hisFetalHeartApiClient; _hisFetalMovementApiClient = hisFetalMovementApiClient; + _hisPsychResultApiClient = hisGpsPsychResultApiClient; _serviceMqProcess = serviceMqProcess; _mgrFetalMovementNormalValueRangeCache = fetalMovementNormalValueRangeCacheMgr; + } public override Task StartAsync(CancellationToken cancellationToken) @@ -521,6 +526,127 @@ namespace HealthMonitor.WebApi var fetalMovement = (int)Math.Round(fetalMovementValue, 0, MidpointRounding.AwayFromZero); // _logger.LogInformation($"{imeiDel} segmentCountFMIndex: {i} -- fetalMovementSampleTime:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")} -- statStartTime: {statStartTime} -- statEndTime: {statEndTime}-- isFetalMovementExisted: {isFetalMovementExisted} "); + #region 生理健康与胎动的关系 + /// (步数)运动步数超过1500步则加1; + /// (体温)低烧则胎动减1,高烧胎动减2;低烧是37.3~38.5,38.6以上是高烧。 + /// (血压)血压收缩压大于160则加1。 + /// (心理)心理压力高加2,压力中加1; + + var fetalMovementStepVar = 0; + var fetalMovementTempVar = 0; + var fetalMovementBpVar = 0; + var fetalMovementPpVar = 0; + // 步数 + if (true) + { + var step = await _personCacheMgr.GetStepPeriodicityAsync(imeiDel); + if (DateTime.Now.Hour - ((DateTime)step?.LastUpdate!).Hour <= 2) + { + if (step.Steps > 1500) fetalMovementStepVar = 1; + } + else + { + _logger.LogWarning($"{imeiDel} 周期步数 时间无效"); + } + } + + // 体温 + if (true) + { + var temp = await _personCacheMgr.GetTemperaturePeriodicityAsync(imeiDel); + if (DateTime.Now.Hour - ((DateTime)temp?.LastUpdate!).Hour <= 2) + { + // 中烧 + if (temp.Temperature>=37.3M&& temp.Temperature<= 38.5M) + { + fetalMovementTempVar = -1; + } + // 高烧 + if (temp.Temperature >= 38.6M) + { + fetalMovementTempVar = -2; + } + } + else + { + _logger.LogWarning($"{imeiDel} 周期体温 时间无效"); + } + } + + // 血压 + if (true) + { + var bp = await _personCacheMgr.GetBloodPressPeriodicityAsync(imeiDel); + if (DateTime.Now.Hour - ((DateTime)bp?.LastUpdate!).Hour <= 2) + { + if (bp.SystolicValue>160) + { + fetalMovementBpVar = 1; + } + } + else + { + _logger.LogWarning($"{imeiDel} 周期血压 时间无效"); + } + } + // 心理 + if (true) + { + //-1 不处理, + //0 正常, + //1 轻度, + //2 中度; + //3 重度; + GeneralParam psychResultParam = new() + { + Filters = new List + { + new () + { + Key=nameof(HisGpsPsychResult.Serialno), + Value=imeiDel, + ValueType=QueryValueTypeEnum.String, + Operator=QueryOperatorEnum.Equal + }, + //new () + //{ + // Key=nameof(HisGpsFetalHeartRate.SampleTime), + // Value=sampleTime, + // ValueType=QueryValueTypeEnum.String, + // Operator=QueryOperatorEnum.GreaterEqual + //}, + }, + OrderBys = new List + { + new (){ + IsDesc=true, + Key=nameof(HisGpsPsychResult.Serialno) + } + } + }; + var psych = await _hisPsychResultApiClient.GetFirstAsync(psychResultParam, imeiDel[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") }); + + if (psych?.StressScore == 2) + { + fetalMovementPpVar = 1; + } + + if (psych?.StressScore == 3) + { + fetalMovementPpVar = 2; + } + } + + _logger.LogInformation($"{imeiDel} 原始胎动值:{fetalMovementValue}, 步数变动值:{fetalMovementStepVar},体温变动值:{fetalMovementTempVar},血压变动值:{fetalMovementBpVar},心理压力变动值{fetalMovementPpVar}"); + fetalMovementValue = fetalMovementValue + fetalMovementStepVar + fetalMovementTempVar + fetalMovementBpVar + fetalMovementPpVar; + #endregion + + #region 胎心与胎动的关系 + // 胎心值过缓时,则胎动数量减1;胎心值过速时,则胎动也加1。 + // 此值允许在上限值上继续增加,在下限值上继续减少,最小值为0。 + + #endregion + _logger.LogInformation($"{imeiDel} 孕周:{pregnancyWeeks},胎动数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 采样周期:{statStartTime}-{statEndTime}, 原始胎动值:{fetalMovementMapValue}, 佩戴时间 :{duringMins}|{phrRange.Last()}-{phrRange.First()}, 胎动计算值:{fetalMovementValue}, 胎动最终值:{fetalMovement} 已完成."); // 获取胎心数据状态与胎动数据状态一致