Browse Source

高频心率产生的胎心sample_time使用首条心率时间

datasub12_fetal_heart_rate_0
H Vs 3 months ago
parent
commit
cb1506b318
2 changed files with 45 additions and 21 deletions
  1. +1
    -1
      HealthMonitor.Service/Biz/db/TDengineService.cs
  2. +44
    -20
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs

+ 1
- 1
HealthMonitor.Service/Biz/db/TDengineService.cs View File

@@ -1023,7 +1023,7 @@ namespace HealthMonitor.Service.Biz.db
// _logger.LogInformation($"{serialNo} 心率数据不足,无法计算其众数"); // _logger.LogInformation($"{serialNo} 心率数据不足,无法计算其众数");
// return null; // return null;
//} //}
_logger.LogInformation($"{serialNo} 去除高频数据后的数据集: " + string.Join(", ", filteredCollection));
_logger.LogInformation($"{serialNo} 去除高频数据后的数据集: " + string.Join(", ", res));


#region 计算众数 #region 计算众数
var mode = res.GroupBy(n => n) var mode = res.GroupBy(n => n)


+ 44
- 20
HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs View File

@@ -151,7 +151,9 @@ namespace HealthMonitor.Service.Resolver


// 如果需要,将时间差转换为秒 // 如果需要,将时间差转换为秒
var timeDiffInSeconds = timeDiff.TotalSeconds; var timeDiffInSeconds = timeDiff.TotalSeconds;

// 高频统计结束时间
var FreqStatsEnd = DateTime.Now;
// 高频心率启动 // 高频心率启动
if (timeDiffInSeconds <= highFreqSampleInterval) if (timeDiffInSeconds <= highFreqSampleInterval)
{ {
@@ -179,8 +181,10 @@ namespace HealthMonitor.Service.Resolver
// 计算一般心率得到胎心系数 // 计算一般心率得到胎心系数
//await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString()); //await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString());
// 高频数据不建模 // 高频数据不建模
await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString());

FreqStatsEnd = (DateTime)heartRate.LastUpdate!;
_logger.LogInformation($"{heartRate.Serialno} 高频状态已经持续{(FreqStatsEnd- phrFreqstatus!.LastUpdate).TotalSeconds} 秒,连续 {stopHighFreqSampleCount} 次采样心率正常,将下发指令");
await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString());
} }
#endregion #endregion
} }
@@ -204,7 +208,10 @@ namespace HealthMonitor.Service.Resolver
//await SaveAndPushFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr); //await SaveAndPushFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr);
//await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString()); //await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString());
// 高频数据不建模 // 高频数据不建模
await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString());
FreqStatsEnd = firstTwoPhr[1];
_logger.LogInformation($"{heartRate.Serialno} 高频状态已经持续{(FreqStatsEnd - phrFreqstatus!.LastUpdate).TotalSeconds} 秒,highFreqSampleTimes={highFreqSampleTimes}秒,即将结束高频状态,将下发指令");

await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString());


} }


@@ -224,15 +231,16 @@ namespace HealthMonitor.Service.Resolver
//await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString()); //await SaveAndPushFreqFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString());
//await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString()); //await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString());
// 高频数据不建模 // 高频数据不建模
await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString());
FreqStatsEnd = firstTwoPhr[1];
_logger.LogInformation($"{heartRate.Serialno} 高频状态已经持续{(FreqStatsEnd - phrFreqstatus!.LastUpdate).TotalSeconds} 秒,超过规定的 {highFreqSampleTimes} 秒,即将结束高频状态,将下发指令");


await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString());
} }


// 删除高频状态的首条记录 // 删除高频状态的首条记录
await _deviceCacheMgr.DelPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); await _deviceCacheMgr.DelPregnancyHeartRateFreqStatusAsync(heartRate.Serialno);


/// 设置高频状态
_logger.LogInformation($"{heartRate.Serialno} 结束高频心率状态 timeDiffInSeconds {timeDiffInSeconds},highFreqSampleInterval:{highFreqSampleInterval}");
_logger.LogInformation($"{heartRate.Serialno} 结束高频心率状态 timeDiffInSeconds {timeDiffInSeconds},highFreqSampleInterval:{highFreqSampleInterval},高频状态持续{(firstTwoPhr[1] - phrFreqstatus!.LastUpdate).TotalSeconds} 秒");
} }
// 正常心率 // 正常心率
else else
@@ -242,23 +250,23 @@ namespace HealthMonitor.Service.Resolver
// 获取当前时间 // 获取当前时间
DateTime nowInterval = (DateTime)heartRate.LastUpdate!; DateTime nowInterval = (DateTime)heartRate.LastUpdate!;


// 计算last_update到上一刻钟的分钟数
// 计算last_update到上一间隔的分钟数
int minutesToSubtract = nowInterval.Minute % intervalFHR; int minutesToSubtract = nowInterval.Minute % intervalFHR;


// 计算上一刻钟的时间
// 计算上一间隔的时间
DateTime previousInterval = nowInterval.AddMinutes(-minutesToSubtract).AddSeconds(-nowInterval.Second).AddMilliseconds(-nowInterval.Millisecond); DateTime previousInterval = nowInterval.AddMinutes(-minutesToSubtract).AddSeconds(-nowInterval.Second).AddMilliseconds(-nowInterval.Millisecond);


// 使用 last_update 上一刻 // 使用 last_update 上一刻
var sampleTimeFHR = DateTimeUtil.ConvertToTimeStamp(previousInterval).ToString(); var sampleTimeFHR = DateTimeUtil.ConvertToTimeStamp(previousInterval).ToString();


// 计算last_update到下一刻钟的分钟数
// 计算last_update到下一间隔的分钟数
int minutesToAdd = intervalFHR - (nowInterval.Minute % intervalFHR); int minutesToAdd = intervalFHR - (nowInterval.Minute % intervalFHR);
if (minutesToAdd == intervalFHR) if (minutesToAdd == intervalFHR)
{ {
minutesToAdd = 0; // 如果已经是刻钟,则不需要增加分钟
minutesToAdd = 0; // 如果已经是间隔,则不需要增加分钟
} }


// 计算下一刻钟的时间
// 计算下一间隔的时间
DateTime nextInterval = nowInterval.AddMinutes(minutesToAdd) DateTime nextInterval = nowInterval.AddMinutes(minutesToAdd)
.AddSeconds(-nowInterval.Second) .AddSeconds(-nowInterval.Second)
.AddMilliseconds(-nowInterval.Millisecond); .AddMilliseconds(-nowInterval.Millisecond);
@@ -289,7 +297,7 @@ namespace HealthMonitor.Service.Resolver


fetalHeartRateIsAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); fetalHeartRateIsAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0);
fetalHeartRateIsAbnormal = 0;// 不是高频数据,按正常值 fetalHeartRateIsAbnormal = 0;// 不是高频数据,按正常值
HisGpsFetalHeartRate gpsFetalHeartRate = new()
/* HisGpsFetalHeartRate gpsFetalHeartRate = new()
{ {
FetalHeartRateId = Guid.NewGuid().ToString("D"), FetalHeartRateId = Guid.NewGuid().ToString("D"),
PersonId = commonPHR!.PersonId, PersonId = commonPHR!.PersonId,
@@ -334,6 +342,11 @@ namespace HealthMonitor.Service.Resolver
}; };
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic, fhrMsg).ConfigureAwait(false); await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic, fhrMsg).ConfigureAwait(false);
} }

*/
await SaveAndPushFreqFetalHeartRateAsync(heartRate, commonPHR!, upperAlarmThreshold, lowerAlarmThreshold, phrValue, sampleTimeFHR,false);


} }
} }


@@ -510,17 +523,17 @@ namespace HealthMonitor.Service.Resolver
//await SetIntervalTriggerAsync(fetalKey, heartRate.Serialno, 60 * 15); //await SetIntervalTriggerAsync(fetalKey, heartRate.Serialno, 60 * 15);
#endregion #endregion


#region 定时计算胎心数据触发器下一刻钟
#region 定时计算胎心数据触发器下一间隔
//// 获取当前时间 //// 获取当前时间
//DateTime nowInterval = DateTime.Now; //DateTime nowInterval = DateTime.Now;


//// 计算下一个15分钟的刻钟
//// 计算下一个15分钟的间隔
//int minutesToAdd = 15 - (nowInterval.Minute % 15); //int minutesToAdd = 15 - (nowInterval.Minute % 15);
//if (minutesToAdd == 15) //if (minutesToAdd == 15)
//{ //{
// minutesToAdd = 0; // 如果已经是刻钟,则不需要增加分钟
// minutesToAdd = 0; // 如果已经是间隔,则不需要增加分钟
//} //}
//// 计算下一刻钟的时间
//// 计算下一间隔的时间
//DateTime nextInterval = nowInterval.AddMinutes(minutesToAdd) //DateTime nextInterval = nowInterval.AddMinutes(minutesToAdd)
// .AddSeconds(-nowInterval.Second) // .AddSeconds(-nowInterval.Second)
// .AddMilliseconds(-nowInterval.Millisecond); // .AddMilliseconds(-nowInterval.Millisecond);
@@ -722,12 +735,23 @@ namespace HealthMonitor.Service.Resolver
// } // }
//} //}


private async Task SaveAndPushFreqFetalHeartRateAsync(HisGpsHeartRate heartRate, PregnancyCommonHeartRateModel commonPHR, int upperAlarmThreshold, int lowerAlarmThreshold, double avgPhr,string sampleTime)
/// <summary>
///
/// </summary>
/// <param name="heartRate"></param>
/// <param name="commonPHR"></param>
/// <param name="upperAlarmThreshold"></param>
/// <param name="lowerAlarmThreshold"></param>
/// <param name="phr"></param>
/// <param name="sampleTime">使用高频心率的首条last_update</param>
/// <param name="isFreq"></param>
/// <returns></returns>
private async Task SaveAndPushFreqFetalHeartRateAsync(HisGpsHeartRate heartRate, PregnancyCommonHeartRateModel commonPHR, int upperAlarmThreshold, int lowerAlarmThreshold, double phr,string sampleTime,bool isFreq = true)
{ {
// 计算胎心=孕妇心率*系数 // 计算胎心=孕妇心率*系数
var fetalHeartRate = SafeType.SafeInt(avgPhr * commonPHR?.StatModeAvgFprCoefficient!);
var fetalHeartRate = SafeType.SafeInt(phr * commonPHR?.StatModeAvgFprCoefficient!);
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0);

if (!isFreq) isAbnormal = 0;
// 保存到 数据服务 MySQL 数据库 // 保存到 数据服务 MySQL 数据库
HisGpsFetalHeartRate gpsFetalHeartRate = new() HisGpsFetalHeartRate gpsFetalHeartRate = new()
{ {


Loading…
Cancel
Save