diff --git a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs index 43780cb..e6af944 100644 --- a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs +++ b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs @@ -380,8 +380,9 @@ namespace HealthMonitor.Service.Resolver var freqFirstPhr = phr.OrderByDescending(i => i.LastUpdate) .Skip(1) //在高频第二条才能判断,所以要去除本条记录 .First(); + _logger.LogInformation($"首条高频附近的3条:{string.Join(',', phr.OrderByDescending(i => i.LastUpdate).Take(3).Select(i=>i.MessageId))}"); await _deviceCacheMgr.SetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno, freqFirstPhr); - _logger.LogInformation($"{heartRate.Serialno} 设置高频状态"); + _logger.LogInformation($"{heartRate.Serialno} 设置高频状态,首条高频心率ID:{freqFirstPhr.MessageId}"); phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); HisGpsHeartRate freqFirstHR = new() { @@ -430,18 +431,23 @@ namespace HealthMonitor.Service.Resolver // 高频不停,15分钟内只下发一条 if (string.IsNullOrEmpty(freqSaveAndPushFetalHeartRate)) { + //await SaveAndPushFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); heartRate.HeartRate = (int)avgPhr; //await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); - - var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)heartRate.LastUpdate!, phrFreqstatus!.LastUpdate); + // 最后一条高频心率 + var lastFreqHr = lastPhr.First(); + var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, phrFreqstatus!.LastUpdate); // 判断是否够highFreqSampleTimes,540s if (ts < highFreqSampleTimes) { /// 不够10分钟最近12个数据的最小值生成胎心值 + _logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据的最小值生成胎心值"); heartRate.HeartRate = lastPhr.Select(i=>i.PregnancyHeartRate).Min(); + heartRate.LastUpdate = lastFreqHr.LastUpdate; } + _logger.LogInformation($"{heartRate.Serialno} 高频数据触发连续12个值都是正常的的高频心率处理"); await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR,highFreqSampleTimes ,upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); // 删除高频状态的首条记录 @@ -492,13 +498,19 @@ namespace HealthMonitor.Service.Resolver heartRate.HeartRate = (int)avgPhr; //await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); - var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)heartRate.LastUpdate!, phrFreqstatus!.LastUpdate); + // 最后一条高频心率 + var lastFreqHr = lastPhr.First(); + + var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, phrFreqstatus!.LastUpdate); // 判断是否够highFreqSampleTimes,540s if (ts < highFreqSampleTimes) { /// 不够10分钟最近12个数据的最小值生成胎心值 + _logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据的最小值生成胎心值"); heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); + heartRate.LastUpdate = lastFreqHr.LastUpdate; } + _logger.LogInformation($"{heartRate.Serialno} 高频结束后的highFreqSampleTimes=0的高频心率处理"); await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, highFreqSampleTimes, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); } @@ -527,7 +539,7 @@ namespace HealthMonitor.Service.Resolver .Take(stopHighFreqSampleCount) // 计算最后12条 .Select(i => i.PregnancyHeartRate).Average(); - _logger.LogInformation($"{heartRate.Serialno} 高频状态已经持续{(FreqStatsEnd - phrFreqstatus!.LastUpdate).TotalSeconds} 秒,超过约定的 {highFreqSampleTimes} 秒,即将结束高频状态,高频心率平均值:{(int)avgPhr},将下发指令"); + //_logger.LogInformation($"{heartRate.Serialno} 高频状态已经持续{(FreqStatsEnd - phrFreqstatus!.LastUpdate).TotalSeconds} 秒,约定的 {highFreqSampleTimes} 秒,即将结束高频状态,高频心率平均值:{(int)avgPhr},将下发指令"); //计算高频 //await SaveAndPushFetalHeartRateAsync(heartRate, commonPHR, upperAlarmThreshold, lowerAlarmThreshold, avgPhr, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); heartRate.HeartRate = (int)avgPhr; @@ -537,13 +549,20 @@ namespace HealthMonitor.Service.Resolver var lastPhr = filterPhr .OrderByDescending(i => i.LastUpdate) .Take(stopHighFreqSampleCount); - var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)heartRate.LastUpdate!, phrFreqstatus!.LastUpdate); + + // 最后一条高频心率 + var lastFreqHr = lastPhr.First(); + + var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, phrFreqstatus!.LastUpdate); if (ts < highFreqSampleTimes) { /// 不够10分钟最近12个数据的最小值生成胎心值 + _logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据的最小值生成胎心值"); heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); + heartRate.LastUpdate = lastFreqHr.LastUpdate; } + _logger.LogInformation($"{heartRate.Serialno} 高频结束后的在highFreqSampleTimes>0 正常心率(通常情况)触发的高频心率处理"); await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, highFreqSampleTimes, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); } else @@ -607,12 +626,18 @@ namespace HealthMonitor.Service.Resolver var lastPhr = freqCollection .OrderByDescending(i => i.LastUpdate) .Take(stopHighFreqSampleCount); - var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)heartRate.LastUpdate!, phrFreqstatus!.LastUpdate); + // 最后一条高频心率 + var lastFreqHr = lastPhr.First(); + + var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, phrFreqstatus!.LastUpdate); if (ts < highFreqSampleTimes) { /// 不够10分钟最近12个数据的最小值生成胎心值 + _logger.LogInformation($"{heartRate.Serialno} 不够10分钟最近12个数据的最小值生成胎心值"); heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); + heartRate.LastUpdate = lastFreqHr.LastUpdate; } + _logger.LogInformation($"{heartRate.Serialno} 高频结束后的时间倒序的正常心率触发的高频心率处理"); await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, highFreqSampleTimes, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); _logger.LogInformation($"{heartRate.Serialno} 高频数据个数{freqCollection.Count},触发高频开始时间{phrFreqstatus!.LastUpdate},时间倒叙"); @@ -1236,6 +1261,23 @@ namespace HealthMonitor.Service.Resolver } } + /// + /// 高频胎心处理 + /// 1. 高频数据触发连续12个值都是正常的的高频心率处理 + /// 2. 高频结束后的highFreqSampleTimes=0的高频心率处理 + /// 3. 高频结束后的在highFreqSampleTimes>0 正常心率触发的高频心率处理(常态) + /// 4. 高频结束后的时间倒序的正常心率触发的高频心率处理 + /// 5. 高频结束后计算胎心数据,防止结束后与常规心理的胎心处理过长,定时器时长highFreqSampleInterval触发的高频心率处理 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// private async Task SaveAndPushFetalHeartRateEndFreqHeartRateAsync(HisGpsHeartRate heartRate, PregnancyCommonHeartRateModel commonPHR, int highFreqSampleTimes, int upperAlarmThreshold, int lowerAlarmThreshold, string sampleTime, DateTime statStartTime, DateTime statEndTime) { // 计算胎心=孕妇心率*系数 @@ -1499,6 +1541,7 @@ namespace HealthMonitor.Service.Resolver } else { + // 不断修改时长,直到最后的一条高频胎心 await _serviceEtcd.PutValAsync(key, schedulePush, interval, false).ConfigureAwait(false); } diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index cbe6b14..e56aee6 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -352,12 +352,18 @@ namespace HealthMonitor.WebApi // 判断是否够highFreqSampleTimes,540s var lastPhr = phrInFreqstatus; - var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)triggerHeartRate.LastUpdate!, phrFreqstatus!.LastUpdate); + // 最后一条高频心率 + var lastFreqHr = phrInFreqstatus.First(); + var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, phrFreqstatus!.LastUpdate); if (ts < highFreqSampleTimes) { /// 不够10分钟最近12个数据的最小值生成胎心值 + _logger.LogInformation($"{triggerHeartRate.Serialno} 不够10分钟最近12个数据的最小值生成胎心值"); triggerHeartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); + triggerHeartRate.LastUpdate = lastFreqHr.LastUpdate; } + _logger.LogInformation($"{triggerHeartRate.Serialno} 高频结束后计算胎心数据,防止结束后与常规心理的胎心处理过长,定时器时长highFreqSampleInterval触发的高频心率处理"); + await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(triggerHeartRate, commonPHR, highFreqSampleTimes, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); } else @@ -2083,6 +2089,23 @@ namespace HealthMonitor.WebApi } } + /// + /// 高频胎心处理 + /// 1. 高频数据触发连续12个值都是正常的的高频心率处理 + /// 2. 高频结束后的highFreqSampleTimes=0的高频心率处理 + /// 3. 高频结束后的在highFreqSampleTimes>0 正常心率触发的高频心率处理(常态) + /// 4. 高频结束后的时间倒序的正常心率触发的高频心率处理 + /// * 5. 高频结束后计算胎心数据,防止结束后与常规心理的胎心处理过长,定时器时长highFreqSampleInterval触发的高频心率处理 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// private async Task SaveAndPushFetalHeartRateEndFreqHeartRateAsync(HisGpsHeartRate heartRate, PregnancyCommonHeartRateModel commonPHR, int highFreqSampleTimes, int upperAlarmThreshold, int lowerAlarmThreshold, string sampleTime, DateTime statStartTime, DateTime statEndTime) { // 计算胎心=孕妇心率*系数