Browse Source

常规心率计算

datasub12_fetal_heart_rate
H Vs 2 months ago
parent
commit
f4f29955f0
2 changed files with 46 additions and 28 deletions
  1. +41
    -28
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs
  2. +5
    -0
      HealthMonitor.WebApi/Worker.cs

+ 41
- 28
HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs View File

@@ -169,7 +169,7 @@ namespace HealthMonitor.Service.Resolver
// EDOC
var edoc = DateTimeUtil.ToDateTime(watchConfig!["EDOC"]!.ToString());
// interval (分钟) 固定15分钟
//var intervalFHR = 15;//int)watchConfig["interval"]!;
var intervalFHR = 15;//int)watchConfig["interval"]!;



@@ -242,11 +242,14 @@ namespace HealthMonitor.Service.Resolver
_logger.LogInformation($"{heartRate.Serialno} 进入高频心率启动状态 timeDiffInSeconds {timeDiffInSeconds},highFreqSampleInterval:{highFreqSampleInterval}");
// 设置高频状态
_logger.LogInformation($"{heartRate.Serialno} phr.Count {phr.Count}");
var freqFirstPhr = phr.OrderByDescending(i => i.LastUpdate).First();
var freqFirstPhr = phr.OrderByDescending(i => i.LastUpdate)
.Skip(1)
.First();
await _deviceCacheMgr.SetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno, freqFirstPhr);
_logger.LogInformation($"{heartRate.Serialno} 设置高频状态");
phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno);
}
/// phr PregnancyHeartRate 连续连续正常次数个值都是正常(大于等于triggerHighFreqLow,少于等于triggerHighFreqHig),
/// 取连续正常次数正常值的平均值,推送到api/v1/open/OpenIot/SetFetalHeartRateConfig
#region 检查高频状态是否连续12个心率值都是正常的
@@ -387,21 +390,22 @@ namespace HealthMonitor.Service.Resolver
var phrFlashBack = daysPhr.Where(p => p.LastUpdate >= phrFreqstatus!.LastUpdate)
.OrderByDescending(i => i.LastUpdate);
// 取得高频数据
var freqCollection = new List<PregnancyHeartRateModel>();
PregnancyHeartRateModel? previousItem = null;

foreach (var item in phrFlashBack)
{
if (previousItem != null)
{
var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds;
if (timeNextDiff <= highFreqSampleInterval)
{
freqCollection.Add(item);
}
}
previousItem = item;
}
var freqCollection = phrFlashBack.ToList();
//var freqCollection = new List<PregnancyHeartRateModel>();
//PregnancyHeartRateModel? previousItem = null;

//foreach (var item in phrFlashBack)
//{
// if (previousItem != null)
// {
// var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds;
// if (timeNextDiff <= highFreqSampleInterval)
// {
// freqCollection.Add(item);
// }
// }
// previousItem = item;
//}

_logger.LogInformation($"{heartRate.Serialno} 高频数据个数{freqCollection.Count},触发高频开始时间{phrFreqstatus!.LastUpdate}");
if (freqCollection.Count>=stopHighFreqSampleCount)
@@ -436,21 +440,21 @@ namespace HealthMonitor.Service.Resolver
_logger.LogInformation($"{heartRate.Serialno} 超时结束高频心率状态 timeDiffInSeconds {timeDiffInSeconds},highFreqSampleInterval:{highFreqSampleInterval},高频状态持续{(firstTwoPhr[1] - phrFreqstatus!.LastUpdate).TotalSeconds} 秒");

// 计算本次常规心率的胎心数据
//await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR);
// 使用延后计算
var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}";
var fhrScheduleTTL = 60;
await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate);
await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR);
//// 使用延后计算
//var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}";
//var fhrScheduleTTL = 60;
//await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate);
}
// 常规心率
else
{
// 计算本次常规心率的胎心数据
//await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR);
await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR);
// 使用延后计算
var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}";
var fhrScheduleTTL = 60;
await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate);
//var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}";
//var fhrScheduleTTL = 60;
//await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate);
}
}

@@ -485,7 +489,10 @@ namespace HealthMonitor.Service.Resolver
// 上15分钟的数据
// 获取当前时间
DateTime nowInterval = (DateTime)heartRate.LastUpdate!;

if (nowInterval.Second > 0)
{
nowInterval = nowInterval.AddMinutes(1);
}
// 计算last_update到上一间隔的分钟数
int minutesToSubtract = nowInterval.Minute % intervalFHR;

@@ -596,7 +603,13 @@ namespace HealthMonitor.Service.Resolver
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false);

// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal);
// 推送最后一条常规心率计算的胎心数据到iot设备
var lastPhr = await _serviceTDengine.GetLastAsync<PregnancyHeartRateModel>(heartRate.Serialno);
if (lastPhr.MessageId == heartRate.MessageId && phrFreqstatus == null)
{
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal);
_logger.LogInformation($"{heartRate.Serialno} 推送最后一条常规心率计算的胎心数据到iot设备");
}


var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false);


+ 5
- 0
HealthMonitor.WebApi/Worker.cs View File

@@ -266,6 +266,7 @@ namespace HealthMonitor.WebApi
// health_monitor/schedule_push/cal_fetal_heart_rate/imei/
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))
@@ -405,6 +406,10 @@ namespace HealthMonitor.WebApi
{
_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/"))


Loading…
Cancel
Save