diff --git a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs index 1881189..54dfbbe 100644 --- a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs +++ b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs @@ -838,6 +838,7 @@ namespace HealthMonitor.Service.Resolver TimeSpan timeUntilNextRun = nextRunTime - nowInterval; var ttl = (long)timeUntilNextRun.TotalSeconds; await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, ttl, heartRate); + _logger.LogInformation($"{heartRate.Serialno}--{heartRate.MessageId} 触发延时计算常规胎心"); } /// diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index 02d5422..7fa9941 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -301,7 +301,7 @@ namespace HealthMonitor.WebApi using (_logger.BeginScope(new Dictionary { ["RequestId"] = $"FREQ-HR-{triggerHeartRate?.MessageId!}" })) { var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); - _logger.LogInformation($"{imeiDel}高频结束后,延迟计算高频数据产生的胎心数据"); + _logger.LogInformation($"{imeiDel}延迟计算 高频 数据产生的胎心数据,高频结束后"); var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; if (isFetalHeartEnable) { @@ -399,10 +399,10 @@ namespace HealthMonitor.WebApi if (!string.IsNullOrEmpty(trigger)) { var triggerHeartRate = JsonConvert.DeserializeObject(trigger); - using (_logger.BeginScope(new Dictionary { ["RequestId"] = triggerHeartRate?.MessageId! })) + using (_logger.BeginScope(new Dictionary { ["RequestId"] = $"NRML-HR-{triggerHeartRate?.MessageId!}" })) { var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); - _logger.LogInformation($"{imeiDel}延迟常规胎心数据产生的胎心数据"); + _logger.LogInformation($"{imeiDel}延迟 常规 胎心数据产生的胎心数据"); var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; if (isFetalHeartEnable) { @@ -424,154 +424,6 @@ namespace HealthMonitor.WebApi } } } - else if (key.Contains("health_monitor/schedule_push/cal_fetal_heart_rate/imei/")) - { - - - /** - var triggerValue= (JObject)JsonConvert.DeserializeObject(e.PrevKv.Value.ToStringUtf8())!; - var trigger = triggerValue["trigger"]?.ToString(); - if (!string.IsNullOrEmpty(trigger)) - { - var triggerHeartRate= JsonConvert.DeserializeObject(trigger); - using (_logger.BeginScope(new Dictionary { ["RequestId"] = triggerHeartRate?.MessageId! })) - { - var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); - _logger.LogInformation($"触发常规心率计算胎心"); - var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; - - if (isFetalHeartEnable) - { - // 告警上限阀值 - var upperAlarmThreshold = (int)watchConfig!["upperAlarmThreshold"]!; - // 告警下限阀值 - var lowerAlarmThreshold = (int)watchConfig["lowerAlarmThreshold"]!; - - // 高频心率采样间隔 highFreqSampleInterval = highFreqSampleInterval+5,增加5秒兼容(最小highFreqSampleInterval=60) - var highFreqSampleInterval = (int)watchConfig!["highFreqSampleInterval"]! >= 60 ? (int)watchConfig!["highFreqSampleInterval"]! + 5 : 60; - - var commonPHR = await _serviceTDengine.GetLastAsync(imeiDel); - - // 最后一条孕妇心率 - var lastPhr = await _serviceTDengine.GetLastAsync(imeiDel); - var isNormalHeartRate = triggerHeartRate?.MessageId == lastPhr.MessageId; - // 判断最后一条孕妇心率与解析器的触发心率是否一致 - if (isNormalHeartRate) - { - //最后一条孕妇心率与解析器的触发心率一致 - HisGpsHeartRate heartRate = new() - { - CreateTime = lastPhr.CreateTime, - DeviceKey = lastPhr.DeviceKey, - HeartRate = lastPhr.PregnancyHeartRate, - HeartRateId = lastPhr.PregnancyHeartRateId, - IsDisplay = lastPhr.IsDisplay ? 1 : 0, - MessageId = lastPhr.MessageId, - LastUpdate = lastPhr.LastUpdate, - Method = lastPhr.Method, - PersonId = lastPhr.PersonId, - Serialno = lastPhr.SerialNumber - }; - var intervalFHR = 15; - await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); - } - // 最后一条孕妇心率与解析器的触发心率不一致,触发心率是高频心率的首条 - else - { - var phr = await _serviceTDengine.GetBySerialNoAsync(imeiDel, 7); - var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(imeiDel); - - if (phrFreqstatus != null) - { - - #region 高频缓存 - // 高频首条是触发心率,30秒后,高频第二条已经写入首条高频缓存 - var diffCount = phr.Where(i => i.CreateTime >= phrFreqstatus.CreateTime && i.CreateTime <= lastPhr.CreateTime) - .OrderByDescending(i => i.CreateTime); - _logger.LogInformation($"{imeiDel} 存在高频缓存,高频心率首条记录${phrFreqstatus.MessageId},高频首条到当前的MSG ID{string.Join(",",diffCount.Select(i=>i.MessageId))}"); - #endregion - } - // 不在高频状态状态,但触发孕妇心率与最后一条孕妇心率不一致, - // 常规心率数据是批量上报,需要计算每条心率对应的胎心数据 - else - { - _logger.LogInformation($"{imeiDel} 常规心率数据是批量上报,需要计算每条心率对应的胎心数据"); - - #region 计算每条心率对应的胎心数据 - phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); - // 获取高频数据 - var freqCollection = new List(); - PregnancyHeartRateModel? previousItem = null; - foreach (var item in phr) - { - if (previousItem != null) - { - var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; - if (timeNextDiff <= highFreqSampleInterval) - { - freqCollection.Add(item); - } - } - previousItem = item; - } - //去除高频 - foreach (var item in freqCollection) - { - phr.Remove(item); - } - - - // 排序并过滤高频数据 - //var previousItem = phr.OrderByDescending(i => i.LastUpdate).ToList().First(); - //phr = phr.Skip(1) - // .Where(item => - // { - // var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; - // previousItem = item; - // return timeNextDiff > highFreqSampleInterval; - // }) - // .Prepend(previousItem) - // .OrderByDescending(i => i.LastUpdate) - // .ToList(); - - var calFhrTasks = phr.Where(p => p.LastUpdate >= triggerHeartRate!.LastUpdate) - .Select( async p => - { - HisGpsHeartRate heartRate = new() - { - CreateTime = p.CreateTime, - DeviceKey = p.DeviceKey, - HeartRate = p.PregnancyHeartRate, - HeartRateId = p.PregnancyHeartRateId, - IsDisplay = p.IsDisplay ? 1 : 0, - MessageId = p.MessageId, - LastUpdate = p.LastUpdate, - Method = p.Method, - PersonId = p.PersonId, - Serialno = p.SerialNumber - }; - var intervalFHR = 15; - await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); - }); - await Task.WhenAll(calFhrTasks); - #endregion - } - } - } - else - { - _logger.LogWarning($"{imeiDel} 胎心监测功能没有开启"); - } - } - } - else - { - _logger.LogWarning($"{imeiDel} trigger is not set"); - } - - */ - - } // 胎动计算 //health_monitor/schedule_push/cal_fetal_movement/imei/ else if (key.Contains("health_monitor/schedule_push/cal_fetal_movement/imei/")) @@ -2218,64 +2070,15 @@ namespace HealthMonitor.WebApi }; await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); - // 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig - // 推送最后一条常规心率计算的胎心数据到iot设备 - #region 推送最后一条常规心率计算的胎心数据到iot设备 - - // 高频(<=12)-常规 - var lastPhr = await _serviceTDengine.GetLastAsync(heartRate.Serialno); - if (lastPhr.MessageId == heartRate.MessageId && phrFreqstatus == null) - { - await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); - _logger.LogInformation($"{heartRate.Serialno} 推送最后一条常规心率计算的胎心数据到iot设备,高频(<=12)-常规"); - } - // 高频(13)-常规-高频(13) - if (phrFreqstatus != null) - { - var phr = await _serviceTDengine.GetBySerialNoAsync(heartRate.Serialno, 1); - phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); - // 获取高频数据 - var freqCollection = new List(); - PregnancyHeartRateModel? previousItem = null; - foreach (var item in phr) - { - if (previousItem != null) - { - var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; - if (timeNextDiff <= 60) - { - freqCollection.Add(item); - } - } - // 高频最后一条 - if (lastPhr.MessageId == item.MessageId) - { - freqCollection.Add(item); - } - - previousItem = item; - } - //去除高频 - foreach (var item in freqCollection) - { - phr.Remove(item); - } - lastPhr = phr.FirstOrDefault(); - if (lastPhr?.MessageId == heartRate.MessageId) - { - await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); - _logger.LogInformation($"{heartRate.Serialno} 推送最后一条常规心率计算的胎心数据到iot设备,高频(13)-常规-高频(13)"); - } - } + #region 高频心率计算胎心数据到iot设备 - #endregion + //if (phrFreqstatus != null && isAbnormal != 0) + //{ + // await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); + //} + // 高频有数据都推送到iot - #region 高频心率计算胎心数据到iot设备 - // 高频(17) ,连续12个高频正常,也不停止且数据偏高和偏低也推送到iot - if (phrFreqstatus != null && isAbnormal != 0) - { - await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); - } + await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); #endregion var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); var fhrMsgId = $"{heartRate.Serialno}-{sampleTime}-{Guid.NewGuid().ToString("D")[^3..]}";