Procházet zdrojové kódy

调整低于高频阀值的心率值的算法

datasub12_fetal_heart_rate_1
H Vs před 1 měsícem
rodič
revize
a3e12066ce
2 změnil soubory, kde provedl 228 přidání a 11 odebrání
  1. +152
    -9
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs
  2. +76
    -2
      HealthMonitor.WebApi/Worker.cs

+ 152
- 9
HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs Zobrazit soubor

@@ -441,8 +441,8 @@ namespace HealthMonitor.Service.Resolver
if (ts < highFreqSampleTimes)
{
/// 不够10分钟最近12个数据生成胎心值
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);
heartRate.HeartRate = selectedHrValue;
_logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据中取 {heartRate.HeartRate} 生成胎心值");

@@ -452,7 +452,9 @@ namespace HealthMonitor.Service.Resolver
{

/// 超过10分钟最近12个数据生成胎心值
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);

heartRate.HeartRate = selectedHrValue;
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据中取 {heartRate.HeartRate} 生成胎心值");
}
@@ -516,7 +518,9 @@ namespace HealthMonitor.Service.Resolver
if (ts < highFreqSampleTimes)
{
/// 不够10分钟最近12个数据生成胎心值
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);

heartRate.HeartRate = selectedHrValue;
_logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据中取 {heartRate.HeartRate} 生成胎心值");
@@ -524,7 +528,9 @@ namespace HealthMonitor.Service.Resolver
}
else
{
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);

heartRate.HeartRate = selectedHrValue;
/// 超过10分钟最近12个数据生成胎心值
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据中取 {heartRate.HeartRate} 生成胎心值");
@@ -577,7 +583,9 @@ namespace HealthMonitor.Service.Resolver
if (ts < highFreqSampleTimes)
{
/// 不够10分钟最近12个数据的成胎心值
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);

heartRate.HeartRate = selectedHrValue;
_logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据中取 {heartRate.HeartRate} 生成胎心值");
@@ -585,7 +593,9 @@ namespace HealthMonitor.Service.Resolver
}
else
{
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);

heartRate.HeartRate = selectedHrValue;
/// 超过10分钟最近12个数据的生成胎心值
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据的中取 {heartRate.HeartRate} 生成胎心值");
@@ -648,7 +658,9 @@ namespace HealthMonitor.Service.Resolver
if (ts < highFreqSampleTimes)
{
/// 不够10分钟最近12个数据生成胎心值
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);

heartRate.HeartRate = selectedHrValue;
_logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据中取 {heartRate.HeartRate} 生成胎心值");
@@ -656,7 +668,8 @@ namespace HealthMonitor.Service.Resolver
}
else
{
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(heartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(heartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);
heartRate.HeartRate = selectedHrValue;
/// 超过10分钟最近12个数据生成胎心值
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据中取 {heartRate.HeartRate} 生成胎心值");
@@ -826,6 +839,136 @@ namespace HealthMonitor.Service.Resolver
selectedHrValue = selectedHrMin;
}


return selectedHrValue;
}

/// <summary>
/// 从高频心率数据中取心率值计算胎心值
/// </summary>
/// <param name="sn"></param>
/// <param name="triggerHighFreqHigh"></param>
/// <param name="triggerHighFreqLow"></param>
/// <param name="highFreqSampleTimes"></param>
/// <param name="firstFreqPhr"></param>
/// <param name="lastPhr"></param>
/// <returns></returns>
private int SelectValueFromFreqHeartRate(string sn, int triggerHighFreqHigh, int triggerHighFreqLow,int highFreqSampleTimes, PregnancyHeartRateModel firstFreqPhr, List<PregnancyHeartRateModel> lastPhr)
{
// 连续12个心率的值的最小值
var selectedHrValue = lastPhr.Select(i => i.PregnancyHeartRate).Min();
_logger.LogInformation($"{sn} 最近12个数据的最小值 {selectedHrValue}");
/// 高频状态下,取值心率低于高频最小值阀值,则需要取最大值进行计算。刚好跟大于高频最大值阀值刚好相反
if (selectedHrValue < triggerHighFreqLow)
{
// 低于高频最小值阀值,则需要取最大值
var selectedHrMax = lastPhr.Select(i => i.PregnancyHeartRate).Max();
_logger.LogInformation($"{sn} 最近12个数据的最小值 {selectedHrValue},低于高频最小值阀值 {triggerHighFreqLow},取最近12个数据的最大值{selectedHrMax}作为心率");
selectedHrValue = selectedHrMax;
}

if (selectedHrValue > triggerHighFreqHigh)
{
var selectedHrMin = lastPhr.Select(i => i.PregnancyHeartRate).Min();
_logger.LogInformation($"{sn} 最近12个数据的最小值 {selectedHrValue},低于高频最大值阀值 {triggerHighFreqHigh},最近12个数据的最小值{selectedHrMin}作为心率");
selectedHrValue = selectedHrMin;
}

#region 判断是否有低于低频阀值引起的高频
/// 低频阀值引起的高频情况下,选择的心率值是正常心率的最小值,之后的区间选择的心率值是正常心率的最小值,不足10分钟没有正常值取最小阀值,超过10分钟没有正常值取最大阀值

if (firstFreqPhr.PregnancyHeartRate < triggerHighFreqLow)
{
_logger.LogInformation($"{sn} 低频阀值引起的高频,低频心率引起值 {firstFreqPhr.PregnancyHeartRate}");

var phr = lastPhr.Where(i => i.PregnancyHeartRate <= triggerHighFreqHigh && i.PregnancyHeartRate >= triggerHighFreqLow);

var lastFreqHr = lastPhr.First();

var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, (DateTime) firstFreqPhr.LastUpdate!);


if (!phr.Any())
{
if (ts<highFreqSampleTimes)
{
selectedHrValue = triggerHighFreqLow;
_logger.LogInformation($"{sn} 高频不足10分钟没有正常值取最小阀值");
}
else
{
selectedHrValue = triggerHighFreqHigh;
_logger.LogInformation($"{sn} 高频超过10分钟没有正常值取最大阀值");
}
}
else
{
selectedHrValue = lastPhr.Where(i => i.PregnancyHeartRate <= triggerHighFreqHigh && i.PregnancyHeartRate >= triggerHighFreqLow)
.ToList()
.Select(i => i.PregnancyHeartRate).Min();
}

}
#endregion

return selectedHrValue;
}


/// <summary>
/// 从高频心率数据中取心率值计算胎心值
/// </summary>
/// <param name="heartRate"></param>
/// <param name="triggerHighFreqHigh"></param>
/// <param name="triggerHighFreqLow"></param>
/// <param name="lastPhr"></param>
/// <returns></returns>
private async Task<int> SelectValueFromFreqHeartRateAsync(HisGpsHeartRate heartRate, int triggerHighFreqHigh, int triggerHighFreqLow, List<PregnancyHeartRateModel> lastPhr)
{
// 连续12个心率的值的最小值
var selectedHrValue = lastPhr.Select(i => i.PregnancyHeartRate).Min();
_logger.LogInformation($"{heartRate.Serialno} 最近12个数据的最小值 {selectedHrValue}");
/// 高频状态下,取值心率低于高频最小值阀值,则需要取最大值进行计算。刚好跟大于高频最大值阀值刚好相反
if (selectedHrValue < triggerHighFreqLow)
{
// 低于高频最小值阀值,则需要取最大值
var selectedHrMax = lastPhr.Select(i => i.PregnancyHeartRate).Max();
_logger.LogInformation($"{heartRate.Serialno} 最近12个数据的最小值 {selectedHrValue},低于高频最小值阀值 {triggerHighFreqLow},取最近12个数据的最大值{selectedHrMax}作为心率");
selectedHrValue = selectedHrMax;
}

if (selectedHrValue > triggerHighFreqHigh)
{
var selectedHrMin = lastPhr.Select(i => i.PregnancyHeartRate).Min();
_logger.LogInformation($"{heartRate.Serialno} 最近12个数据的最小值 {selectedHrValue},低于高频最大值阀值 {triggerHighFreqHigh},最近12个数据的最小值{selectedHrMin}作为心率");
selectedHrValue = selectedHrMin;
}

#region 判断是否有低于低频阀值引起的高频
/// 低频阀值引起的高频情况下,选择的心率值是正常心率的最小值,之后的区间选择的心率值是正常心率的最小值,不足10分钟没有正常值取最小阀值,超过10分钟没有正常值取最大 阀值
var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno);

if (phrFreqstatus?.PregnancyHeartRate < triggerHighFreqLow)
{
_logger.LogInformation($"{heartRate.Serialno} 低频阀值引起的高频,低频心率引起值 {phrFreqstatus?.PregnancyHeartRate}");

var phr = lastPhr.Where(i => i.PregnancyHeartRate <= triggerHighFreqHigh && i.PregnancyHeartRate >= triggerHighFreqLow);

if (!phr.Any())
{
selectedHrValue = triggerHighFreqLow;
}
else
{
selectedHrValue = lastPhr.Where(i => i.PregnancyHeartRate <= triggerHighFreqHigh && i.PregnancyHeartRate >= triggerHighFreqLow)
.ToList()
.Select(i => i.PregnancyHeartRate).Min();
}

}
#endregion

return selectedHrValue;
}



+ 76
- 2
HealthMonitor.WebApi/Worker.cs Zobrazit soubor

@@ -365,14 +365,16 @@ namespace HealthMonitor.WebApi
//triggerHeartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min();
/// 不够10分钟最近12个数据生成胎心值
int selectedHrValue = SelectValueFromFreqHeartRate(triggerHeartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(triggerHeartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(triggerHeartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);
triggerHeartRate.HeartRate = selectedHrValue;
_logger.LogInformation($"{triggerHeartRate.Serialno} 不够10分钟最近12个数据数据中取 {triggerHeartRate.HeartRate} 生成胎心值");
}
else
{
//triggerHeartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min();
int selectedHrValue = SelectValueFromFreqHeartRate(triggerHeartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
//int selectedHrValue = SelectValueFromFreqHeartRate(triggerHeartRate, triggerHighFreqHigh, triggerHighFreqLow, lastPhr);
int selectedHrValue = SelectValueFromFreqHeartRate(triggerHeartRate.Serialno, triggerHighFreqHigh, triggerHighFreqLow, highFreqSampleTimes, phrFreqstatus, lastPhr);
triggerHeartRate.HeartRate = selectedHrValue;
/// 超过10分钟最近12个数据生成胎心值
_logger.LogInformation($"{triggerHeartRate.Serialno} 超过10分钟最近12个数据数据中取 {triggerHeartRate.HeartRate} 生成胎心值");
@@ -1806,6 +1808,78 @@ namespace HealthMonitor.WebApi
return selectedHrValue;
}


/// <summary>
/// 从高频心率数据中取心率值计算胎心值
/// </summary>
/// <param name="sn"></param>
/// <param name="triggerHighFreqHigh"></param>
/// <param name="triggerHighFreqLow"></param>
/// <param name="highFreqSampleTimes"></param>
/// <param name="firstFreqPhr"></param>
/// <param name="lastPhr"></param>
/// <returns></returns>
private int SelectValueFromFreqHeartRate(string sn, int triggerHighFreqHigh, int triggerHighFreqLow, int highFreqSampleTimes, PregnancyHeartRateModel firstFreqPhr, List<PregnancyHeartRateModel> lastPhr)
{
// 连续12个心率的值的最小值
var selectedHrValue = lastPhr.Select(i => i.PregnancyHeartRate).Min();
_logger.LogInformation($"{sn} 最近12个数据的最小值 {selectedHrValue}");
/// 高频状态下,取值心率低于高频最小值阀值,则需要取最大值进行计算。刚好跟大于高频最大值阀值刚好相反
if (selectedHrValue < triggerHighFreqLow)
{
// 低于高频最小值阀值,则需要取最大值
var selectedHrMax = lastPhr.Select(i => i.PregnancyHeartRate).Max();
_logger.LogInformation($"{sn} 最近12个数据的最小值 {selectedHrValue},低于高频最小值阀值 {triggerHighFreqLow},取最近12个数据的最大值{selectedHrMax}作为心率");
selectedHrValue = selectedHrMax;
}

if (selectedHrValue > triggerHighFreqHigh)
{
var selectedHrMin = lastPhr.Select(i => i.PregnancyHeartRate).Min();
_logger.LogInformation($"{sn} 最近12个数据的最小值 {selectedHrValue},低于高频最大值阀值 {triggerHighFreqHigh},最近12个数据的最小值{selectedHrMin}作为心率");
selectedHrValue = selectedHrMin;
}

#region 判断是否有低于低频阀值引起的高频
/// 低频阀值引起的高频情况下,选择的心率值是正常心率的最小值,之后的区间选择的心率值是正常心率的最小值,不足10分钟没有正常值取最小阀值,超过10分钟没有正常值取最大阀值

if (firstFreqPhr.PregnancyHeartRate < triggerHighFreqLow)
{
_logger.LogInformation($"{sn} 低频阀值引起的高频,低频心率引起值 {firstFreqPhr.PregnancyHeartRate}");

var phr = lastPhr.Where(i => i.PregnancyHeartRate <= triggerHighFreqHigh && i.PregnancyHeartRate >= triggerHighFreqLow);

var lastFreqHr = lastPhr.First();

var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, (DateTime)firstFreqPhr.LastUpdate!);


if (!phr.Any())
{
if (ts < highFreqSampleTimes)
{
selectedHrValue = triggerHighFreqLow;
_logger.LogInformation($"{sn} 高频不足10分钟没有正常值取最小阀值");
}
else
{
selectedHrValue = triggerHighFreqHigh;
_logger.LogInformation($"{sn} 高频超过10分钟没有正常值取最大阀值");
}
}
else
{
selectedHrValue = lastPhr.Where(i => i.PregnancyHeartRate <= triggerHighFreqHigh && i.PregnancyHeartRate >= triggerHighFreqLow)
.ToList()
.Select(i => i.PregnancyHeartRate).Min();
}

}
#endregion

return selectedHrValue;
}

/// <summary>
/// 高频胎心处理
/// 1. 高频数据触发连续12个值都是正常的的高频心率处理


Načítá se…
Zrušit
Uložit