Bläddra i källkod

调整普通常规心率延迟处理和高频心率结束的常规心率实时处理

datasub12_fetal_heart_rate
H Vs 3 månader sedan
förälder
incheckning
067fb438c6
2 ändrade filer med 26 tillägg och 24 borttagningar
  1. +16
    -14
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs
  2. +10
    -10
      HealthMonitor.WebApi/Worker.cs

+ 16
- 14
HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs Visa fil

@@ -231,7 +231,7 @@ namespace HealthMonitor.Service.Resolver
var FreqStatsEnd = DateTime.Now;


// 高频心率启动
// 高频心率启动(在高频第二条才能判断)
if (timeDiffInSeconds <= highFreqSampleInterval)
{

@@ -243,7 +243,7 @@ namespace HealthMonitor.Service.Resolver
// 设置高频状态
_logger.LogInformation($"{heartRate.Serialno} phr.Count {phr.Count}");
var freqFirstPhr = phr.OrderByDescending(i => i.LastUpdate)
.Skip(1)
.Skip(1) //在高频第二条才能判断,所以要去除本条记录
.First();
await _deviceCacheMgr.SetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno, freqFirstPhr);
_logger.LogInformation($"{heartRate.Serialno} 设置高频状态");
@@ -364,10 +364,10 @@ namespace HealthMonitor.Service.Resolver
//.Where(i => i.PregnancyHeartRate < triggerHighFreqLow || i.PregnancyHeartRate > triggerHighFreqHigh)
.Select(i => i.PregnancyHeartRate).Average();

// 高频数据不建模
FreqStatsEnd = firstTwoPhr[1];
_logger.LogInformation($"{heartRate.Serialno} 高频状态已经持续{(FreqStatsEnd - phrFreqstatus!.LastUpdate).TotalSeconds} 秒,超过约定的 {highFreqSampleTimes} 秒,即将结束高频状态,将下发指令");
//计算高频
await SaveAndPushFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd);

}
@@ -381,8 +381,8 @@ namespace HealthMonitor.Service.Resolver
else
{

// 高频结束后与周期性的心率时间倒叙
if ((firstTwoPhr[1] - phrFreqstatus!.LastUpdate).TotalSeconds<0)
// 高频结束后与常规的心率时间倒叙
if ((firstTwoPhr[1] - phrFreqstatus!.LastUpdate).TotalSeconds < 0)
{
_logger.LogInformation($"{heartRate.Serialno} 高频结束出现时间倒叙,计算当条心率创建之前的高频心率");
#region 计算当条心率创建之前的高频心率
@@ -408,7 +408,7 @@ namespace HealthMonitor.Service.Resolver
//}

_logger.LogInformation($"{heartRate.Serialno} 高频数据个数{freqCollection.Count},触发高频开始时间{phrFreqstatus!.LastUpdate}");
if (freqCollection.Count>=stopHighFreqSampleCount)
if (freqCollection.Count >= stopHighFreqSampleCount)
{
// 计算高频产生的胎心
var avgPhr = freqCollection
@@ -439,22 +439,24 @@ 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);
}
// 常规心率
// 常规心率(本次心率可能是高频心率的首条,所以要使用延后计算胎心率)
else
{
// 计算本次常规心率的胎心数据
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 = 30;
await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate);
_logger.LogInformation($"{heartRate.Serialno} 延时50秒,判断当前数据是否为高频首条");

}
}



+ 10
- 10
HealthMonitor.WebApi/Worker.cs Visa fil

@@ -266,7 +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))
@@ -313,18 +313,20 @@ namespace HealthMonitor.WebApi
var intervalFHR = 15;
await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR);
}
// 不一致,触发心率是高频心率的首条
// 最后一条孕妇心率与解析器的触发心率不一致,触发心率是高频心率的首条
else
{
var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(imeiDel, 7);
// 修改缓存中高频状态触发心率
var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(imeiDel);
if (phrFreqstatus != null)
{
#region 修改首条高频心率
var freqFirstPhr = phr.Where(p => p.MessageId == triggerHeartRate?.MessageId).First();
await _deviceCacheMgr.SetPregnancyHeartRateFreqStatusAsync(imeiDel, freqFirstPhr);
_logger.LogInformation($"{imeiDel} 设置高频状态,修正触发的孕妇心率记录");

#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
}
// 不在高频状态状态,但触发孕妇心率与最后一条孕妇心率不一致,
@@ -334,8 +336,6 @@ namespace HealthMonitor.WebApi
_logger.LogInformation($"{imeiDel} 常规心率数据是批量上报,需要计算每条心率对应的胎心数据");

#region 计算每条心率对应的胎心数据


phr = phr.OrderByDescending(i => i.LastUpdate).ToList();
// 获取高频数据
var freqCollection = new List<PregnancyHeartRateModel>();
@@ -407,7 +407,7 @@ namespace HealthMonitor.WebApi
_logger.LogWarning($"{imeiDel} trigger is not set");
}

*/

}


Laddar…
Avbryt
Spara