|
|
@@ -433,11 +433,7 @@ 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 lastFreqHr = lastPhr.First(); |
|
|
|
var ts = DateTimeUtil.GetTimeDifferenceInSeconds((DateTime)lastFreqHr.LastUpdate!, phrFreqstatus!.LastUpdate); |
|
|
@@ -449,6 +445,12 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
heartRate.HeartRate = lastPhr.Select(i=>i.PregnancyHeartRate).Min(); |
|
|
|
heartRate.LastUpdate = lastFreqHr.LastUpdate; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); |
|
|
|
/// 超过10分钟最近12个数据的最小值生成胎心值 |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据的最小值生成胎心值"); |
|
|
|
} |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 高频数据触发连续12个值都是正常的的高频心率处理"); |
|
|
|
await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR,highFreqSampleTimes ,upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); |
|
|
|
|
|
|
@@ -512,6 +514,12 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); |
|
|
|
heartRate.LastUpdate = lastFreqHr.LastUpdate; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); |
|
|
|
/// 超过10分钟最近12个数据的最小值生成胎心值 |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据的最小值生成胎心值"); |
|
|
|
} |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 高频结束后的highFreqSampleTimes=0的高频心率处理"); |
|
|
|
await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, highFreqSampleTimes, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); |
|
|
|
|
|
|
@@ -564,6 +572,12 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); |
|
|
|
heartRate.LastUpdate = lastFreqHr.LastUpdate; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); |
|
|
|
/// 超过10分钟最近12个数据的最小值生成胎心值 |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据的最小值生成胎心值"); |
|
|
|
} |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 高频结束后的在highFreqSampleTimes>0 正常心率(通常情况)触发的高频心率处理"); |
|
|
|
await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, highFreqSampleTimes, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); |
|
|
|
} |
|
|
@@ -639,6 +653,12 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); |
|
|
|
heartRate.LastUpdate = lastFreqHr.LastUpdate; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
heartRate.HeartRate = lastPhr.Select(i => i.PregnancyHeartRate).Min(); |
|
|
|
/// 超过10分钟最近12个数据的最小值生成胎心值 |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 超过10分钟最近12个数据的最小值生成胎心值"); |
|
|
|
} |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 高频结束后的时间倒序的正常心率触发的高频心率处理"); |
|
|
|
await SaveAndPushFetalHeartRateEndFreqHeartRateAsync(heartRate, commonPHR, highFreqSampleTimes, upperAlarmThreshold, lowerAlarmThreshold, DateTimeUtil.ConvertToTimeStamp(phrFreqstatus!.LastUpdate).ToString(), phrFreqstatus!.LastUpdate, FreqStatsEnd); |
|
|
|
|
|
|
@@ -841,429 +861,6 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
_logger.LogInformation($"{heartRate.Serialno}--{heartRate.MessageId} 触发延时计算常规胎心"); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// |
|
|
|
/// </summary> |
|
|
|
/// <param name="heartRate"></param> |
|
|
|
/// <param name="commonPHR"></param> |
|
|
|
/// <param name="upperAlarmThreshold"></param> |
|
|
|
/// <param name="lowerAlarmThreshold"></param> |
|
|
|
/// <param name="phrValue"></param> |
|
|
|
/// <param name="sampleTime"></param> |
|
|
|
/// <param name="statStartTime"></param> |
|
|
|
/// <param name="statEndTime"></param> |
|
|
|
/// <returns></returns> |
|
|
|
private async Task SaveAndPushFetalHeartRateAsync(HisGpsHeartRate heartRate, PregnancyCommonHeartRateModel commonPHR, int upperAlarmThreshold, int lowerAlarmThreshold, double phrValue, string sampleTime, DateTime statStartTime, DateTime statEndTime) |
|
|
|
{ |
|
|
|
// 计算胎心=孕妇心率*系数 |
|
|
|
/** |
|
|
|
var fetalHeartRate = SafeType.SafeInt(phrValue * commonPHR?.StatModeAvgFprCoefficient!); |
|
|
|
fetalHeartRate = fetalHeartRate > 220 ? 220 : fetalHeartRate; // 胎心的最大值调整为220,超过都按该值220输出 |
|
|
|
if (fetalHeartRate >= 220) |
|
|
|
{ |
|
|
|
// 先使用最小系数计算 |
|
|
|
var statMaxValueFprCoefficient = commonPHR?.StatMaxValueFprCoefficient!; |
|
|
|
var statMinValueFprCoefficient = commonPHR?.StatMinValueFprCoefficient!; |
|
|
|
var coefficient = statMaxValueFprCoefficient < statMinValueFprCoefficient ? statMaxValueFprCoefficient : statMinValueFprCoefficient; |
|
|
|
fetalHeartRate = SafeType.SafeInt(phrValue * coefficient); |
|
|
|
if (fetalHeartRate < 220) |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 使用极值系数 {coefficient} ,建模数据可能出现异常,请检查"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fetalHeartRate = 220; |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 使用所有系数都不能放映实际,建模数据可能出现异常,请检查"); |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
#region 胎心系数使用基于心率与中位数对比 |
|
|
|
var coefficient = 0f; |
|
|
|
// 孕妇心率少于中位数,取StatMinValueFprCoefficient |
|
|
|
if (heartRate.HeartRate < commonPHR!.Mode) |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatMinValueFprCoefficient!; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率少于中位数,使用最小值系数 {coefficient}"); |
|
|
|
} |
|
|
|
// 孕妇心率大于中位数,取StatMaxValueFprCoefficient与StatModeAvgFprCoefficient中少的那个 |
|
|
|
else if (heartRate.HeartRate > commonPHR.Mode) |
|
|
|
{ |
|
|
|
if (commonPHR.StatModeAvgFprCoefficient > commonPHR.StatMaxValueFprCoefficient) |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatMaxValueFprCoefficient!; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率大于中位数,使用最大值系数 {coefficient}"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatModeAvgFprCoefficient!; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率大于中位数,使用均值系数 {coefficient}"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatModeAvgFprCoefficient; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率等于中位数,使用均值系数 {coefficient}"); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
var fetalHeartRate = SafeType.SafeInt(phrValue * coefficient); |
|
|
|
// 胎心的最大值调整为220,超过都按该值220输出 |
|
|
|
// fetalHeartRate = fetalHeartRate>= 220 ? 220 : fetalHeartRate; |
|
|
|
|
|
|
|
if (fetalHeartRate > 220) |
|
|
|
{ |
|
|
|
fetalHeartRate = 220; |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 大于220,按220输出,计算因子:孕妇心率 {heartRate.HeartRate},系数 {coefficient},周期 周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); |
|
|
|
} |
|
|
|
|
|
|
|
// 胎心的最小值调整为90,超过都按该值90 |
|
|
|
if (fetalHeartRate < 90) |
|
|
|
{ |
|
|
|
fetalHeartRate = 90; |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 小于90,按90输出,计算因子:孕妇心率 {heartRate.HeartRate},系数 {coefficient},周期 周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); |
|
|
|
var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); |
|
|
|
if (phrFreqstatus == null) isAbnormal = 0; |
|
|
|
var statsusDesc = (phrFreqstatus == null) ? "常规" : "高频"; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 在 {statsusDesc} 状态,生成胎心值:{fetalHeartRate},统计周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); |
|
|
|
//if (!isFreq) |
|
|
|
//{ |
|
|
|
// statStartTime = heartRate.LastUpdate; |
|
|
|
// |
|
|
|
//} |
|
|
|
// 保存到 数据服务 MySQL 数据库 |
|
|
|
HisGpsFetalHeartRate gpsFetalHeartRate = new() |
|
|
|
{ |
|
|
|
FetalHeartRateId = Guid.NewGuid().ToString("D"), |
|
|
|
PersonId = commonPHR!.PersonId, |
|
|
|
Serialno = heartRate.Serialno, |
|
|
|
HeartRate = fetalHeartRate, |
|
|
|
SampleTime = sampleTime.Length > 10 ? sampleTime.Substring(0, 10) : sampleTime, |
|
|
|
IsAbnormal = isAbnormal, |
|
|
|
StatStartTime = statStartTime, |
|
|
|
StatEndTime = statEndTime,//commonPHR.StatEndTime, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Method = 1, |
|
|
|
IsDisplay = 1, |
|
|
|
DeviceKey = commonPHR!.DeviceKey |
|
|
|
}; |
|
|
|
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); |
|
|
|
|
|
|
|
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
|
// 推送最后一条常规心率计算的胎心数据到iot设备 |
|
|
|
#region 推送最后一条常规心率计算的胎心数据到iot设备 |
|
|
|
|
|
|
|
// 高频(<=12)-常规 |
|
|
|
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设备,高频(<=12)-常规"); |
|
|
|
} |
|
|
|
// 高频(13)-常规-高频(13) |
|
|
|
if (phrFreqstatus != null) |
|
|
|
{ |
|
|
|
var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(heartRate.Serialno, 1); |
|
|
|
phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); |
|
|
|
// 获取高频数据 |
|
|
|
var freqCollection = new List<PregnancyHeartRateModel>(); |
|
|
|
PregnancyHeartRateModel? previousItem = null; |
|
|
|
foreach (var item in phr) |
|
|
|
{ |
|
|
|
if (previousItem != null) |
|
|
|
{ |
|
|
|
var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; |
|
|
|
if (timeNextDiff <= 60) |
|
|
|
{ |
|
|
|
freqCollection.Add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
// 高频最后一条 |
|
|
|
if (lastPhr.MessageId == item.MessageId) |
|
|
|
{ |
|
|
|
freqCollection.Add(item); |
|
|
|
} |
|
|
|
|
|
|
|
previousItem = item; |
|
|
|
} |
|
|
|
//去除高频 |
|
|
|
foreach (var item in freqCollection) |
|
|
|
{ |
|
|
|
phr.Remove(item); |
|
|
|
} |
|
|
|
lastPhr = phr.FirstOrDefault(); |
|
|
|
if (lastPhr?.MessageId == heartRate.MessageId) |
|
|
|
{ |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 推送最后一条常规心率计算的胎心数据到iot设备,高频(13)-常规-高频(13)"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 高频心率计算胎心数据到iot设备 |
|
|
|
// 高频(17) ,连续12个高频正常,也不停止且数据偏高和偏低也推送到iot |
|
|
|
if (phrFreqstatus != null && isAbnormal!=0) |
|
|
|
{ |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); |
|
|
|
var fhrMsgId = $"{heartRate.Serialno}-{sampleTime}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|
var fhrMsgTime = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(sampleTime.Length < 13 ? sampleTime.PadRight(13, '0') : sampleTime)).ToString("yyyy-MM-dd HH:mm:ss"); |
|
|
|
// 胎心数据推送到第三方 |
|
|
|
var topic = "topic.push.third"; |
|
|
|
var fhrThridMsg = new |
|
|
|
{ |
|
|
|
messageId = fhrMsgId, |
|
|
|
topic = topic, |
|
|
|
time = fhrMsgTime, |
|
|
|
data = new |
|
|
|
{ |
|
|
|
imei = heartRate.Serialno, |
|
|
|
value = fetalHeartRate, |
|
|
|
isAbnormal, |
|
|
|
type = "fetalHeart" |
|
|
|
} |
|
|
|
}; |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic, 31, fhrThridMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
// 胎心数据推送到微信 |
|
|
|
if (isAbnormal != 0) |
|
|
|
{ |
|
|
|
|
|
|
|
topic = "topic.push.wx"; |
|
|
|
var fhrMsg = new |
|
|
|
{ |
|
|
|
messageId = fhrMsgId, |
|
|
|
topic = topic, |
|
|
|
time = fhrMsgTime, |
|
|
|
data = new |
|
|
|
{ |
|
|
|
deviceId = device?.DeviceId, |
|
|
|
imei = heartRate.Serialno, |
|
|
|
alarmTypeId = 12, |
|
|
|
alarmDeviceName = heartRate.Serialno, |
|
|
|
alarmRemarks = JsonConvert.SerializeObject(new { fetalHeartValue = fetalHeartRate, isAbnormal = isAbnormal }), |
|
|
|
address = string.Empty, |
|
|
|
deviceKey = device?.DeviceId |
|
|
|
} |
|
|
|
}; |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic, fhrMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task SaveAndPushFetalHeartRateEndFreqHeartRateAsync(HisGpsHeartRate heartRate, PregnancyCommonHeartRateModel commonPHR, int upperAlarmThreshold, int lowerAlarmThreshold, string sampleTime, DateTime statStartTime, DateTime statEndTime) |
|
|
|
{ |
|
|
|
// 计算胎心=孕妇心率*系数 |
|
|
|
/** |
|
|
|
var fetalHeartRate = SafeType.SafeInt(phrValue * commonPHR?.StatModeAvgFprCoefficient!); |
|
|
|
fetalHeartRate = fetalHeartRate > 220 ? 220 : fetalHeartRate; // 胎心的最大值调整为220,超过都按该值220输出 |
|
|
|
if (fetalHeartRate >= 220) |
|
|
|
{ |
|
|
|
// 先使用最小系数计算 |
|
|
|
var statMaxValueFprCoefficient = commonPHR?.StatMaxValueFprCoefficient!; |
|
|
|
var statMinValueFprCoefficient = commonPHR?.StatMinValueFprCoefficient!; |
|
|
|
var coefficient = statMaxValueFprCoefficient < statMinValueFprCoefficient ? statMaxValueFprCoefficient : statMinValueFprCoefficient; |
|
|
|
fetalHeartRate = SafeType.SafeInt(phrValue * coefficient); |
|
|
|
if (fetalHeartRate < 220) |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 使用极值系数 {coefficient} ,建模数据可能出现异常,请检查"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fetalHeartRate = 220; |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 使用所有系数都不能放映实际,建模数据可能出现异常,请检查"); |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
#region 胎心系数使用基于心率与中位数对比 |
|
|
|
var coefficient = 0f; |
|
|
|
// 孕妇心率少于中位数,取StatMinValueFprCoefficient |
|
|
|
if (heartRate.HeartRate < commonPHR!.Mode) |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatMinValueFprCoefficient!; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率少于中位数,使用最小值系数 {coefficient}"); |
|
|
|
} |
|
|
|
// 孕妇心率大于中位数,取StatMaxValueFprCoefficient与StatModeAvgFprCoefficient中少的那个 |
|
|
|
else if (heartRate.HeartRate > commonPHR.Mode) |
|
|
|
{ |
|
|
|
if (commonPHR.StatModeAvgFprCoefficient > commonPHR.StatMaxValueFprCoefficient) |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatMaxValueFprCoefficient!; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率大于中位数,使用最大值系数 {coefficient}"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatModeAvgFprCoefficient!; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率大于中位数,使用均值系数 {coefficient}"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
coefficient = commonPHR.StatModeAvgFprCoefficient; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 孕妇心率等于中位数,使用均值系数 {coefficient}"); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
var fetalHeartRate = SafeType.SafeInt(heartRate.HeartRate! * coefficient); |
|
|
|
// 胎心的最大值调整为220,超过都按该值220输出 |
|
|
|
// fetalHeartRate = fetalHeartRate>= 220 ? 220 : fetalHeartRate; |
|
|
|
|
|
|
|
if (fetalHeartRate > 220) |
|
|
|
{ |
|
|
|
fetalHeartRate = 220; |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 大于220,按220输出,计算因子:孕妇心率 {heartRate.HeartRate},系数 {coefficient},周期 周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); |
|
|
|
} |
|
|
|
|
|
|
|
// 胎心的最小值调整为90,超过都按该值90 |
|
|
|
if (fetalHeartRate < 90) |
|
|
|
{ |
|
|
|
fetalHeartRate = 90; |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 小于90,按90输出,计算因子:孕妇心率 {heartRate.HeartRate},系数 {coefficient},周期 周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); |
|
|
|
var phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); |
|
|
|
if (phrFreqstatus == null) isAbnormal = 0; |
|
|
|
var statsusDesc = (phrFreqstatus == null) ? "常规" : "高频"; |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 在 {statsusDesc} 状态,生成胎心值:{fetalHeartRate},统计周期:{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}----{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); |
|
|
|
//if (!isFreq) |
|
|
|
//{ |
|
|
|
// statStartTime = heartRate.LastUpdate; |
|
|
|
// |
|
|
|
//} |
|
|
|
// 保存到 数据服务 MySQL 数据库 |
|
|
|
HisGpsFetalHeartRate gpsFetalHeartRate = new() |
|
|
|
{ |
|
|
|
FetalHeartRateId = Guid.NewGuid().ToString("D"), |
|
|
|
PersonId = commonPHR!.PersonId, |
|
|
|
Serialno = heartRate.Serialno, |
|
|
|
HeartRate = fetalHeartRate, |
|
|
|
SampleTime = sampleTime.Length > 10 ? sampleTime.Substring(0, 10) : sampleTime, |
|
|
|
IsAbnormal = isAbnormal, |
|
|
|
StatStartTime = statStartTime, |
|
|
|
StatEndTime = statEndTime,//commonPHR.StatEndTime, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Method = 1, |
|
|
|
IsDisplay = 1, |
|
|
|
DeviceKey = commonPHR!.DeviceKey |
|
|
|
}; |
|
|
|
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); |
|
|
|
|
|
|
|
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
|
// 推送最后一条常规心率计算的胎心数据到iot设备 |
|
|
|
#region 推送最后一条常规心率计算的胎心数据到iot设备 |
|
|
|
|
|
|
|
// 高频(<=12)-常规 |
|
|
|
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设备,高频(<=12)-常规"); |
|
|
|
} |
|
|
|
// 高频(13)-常规-高频(13) |
|
|
|
if (phrFreqstatus != null) |
|
|
|
{ |
|
|
|
var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(heartRate.Serialno, 1); |
|
|
|
phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); |
|
|
|
// 获取高频数据 |
|
|
|
var freqCollection = new List<PregnancyHeartRateModel>(); |
|
|
|
PregnancyHeartRateModel? previousItem = null; |
|
|
|
foreach (var item in phr) |
|
|
|
{ |
|
|
|
if (previousItem != null) |
|
|
|
{ |
|
|
|
var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; |
|
|
|
if (timeNextDiff <= 60) |
|
|
|
{ |
|
|
|
freqCollection.Add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
// 高频最后一条 |
|
|
|
if (lastPhr.MessageId == item.MessageId) |
|
|
|
{ |
|
|
|
freqCollection.Add(item); |
|
|
|
} |
|
|
|
|
|
|
|
previousItem = item; |
|
|
|
} |
|
|
|
//去除高频 |
|
|
|
foreach (var item in freqCollection) |
|
|
|
{ |
|
|
|
phr.Remove(item); |
|
|
|
} |
|
|
|
lastPhr = phr.FirstOrDefault(); |
|
|
|
if (lastPhr?.MessageId == heartRate.MessageId) |
|
|
|
{ |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 推送最后一条常规心率计算的胎心数据到iot设备,高频(13)-常规-高频(13)"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 高频心率计算胎心数据到iot设备 |
|
|
|
// 高频(17) ,连续12个高频正常,也不停止且数据偏高和偏低也推送到iot |
|
|
|
if (phrFreqstatus != null && isAbnormal != 0) |
|
|
|
{ |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); |
|
|
|
var fhrMsgId = $"{heartRate.Serialno}-{sampleTime}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|
var fhrMsgTime = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(sampleTime.Length < 13 ? sampleTime.PadRight(13, '0') : sampleTime)).ToString("yyyy-MM-dd HH:mm:ss"); |
|
|
|
// 胎心数据推送到第三方 |
|
|
|
var topic = "topic.push.third"; |
|
|
|
var fhrThridMsg = new |
|
|
|
{ |
|
|
|
messageId = fhrMsgId, |
|
|
|
topic = topic, |
|
|
|
time = fhrMsgTime, |
|
|
|
data = new |
|
|
|
{ |
|
|
|
imei = heartRate.Serialno, |
|
|
|
value = fetalHeartRate, |
|
|
|
isAbnormal, |
|
|
|
type = "fetalHeart" |
|
|
|
} |
|
|
|
}; |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic, 31, fhrThridMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
// 胎心数据推送到微信 |
|
|
|
if (isAbnormal != 0) |
|
|
|
{ |
|
|
|
|
|
|
|
topic = "topic.push.wx"; |
|
|
|
var fhrMsg = new |
|
|
|
{ |
|
|
|
messageId = fhrMsgId, |
|
|
|
topic = topic, |
|
|
|
time = fhrMsgTime, |
|
|
|
data = new |
|
|
|
{ |
|
|
|
deviceId = device?.DeviceId, |
|
|
|
imei = heartRate.Serialno, |
|
|
|
alarmTypeId = 12, |
|
|
|
alarmDeviceName = heartRate.Serialno, |
|
|
|
alarmRemarks = JsonConvert.SerializeObject(new { fetalHeartValue = fetalHeartRate, isAbnormal = isAbnormal }), |
|
|
|
address = string.Empty, |
|
|
|
deviceKey = device?.DeviceId |
|
|
|
} |
|
|
|
}; |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fhrMsgId, topic, fhrMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// 高频胎心处理 |
|
|
|
/// 1. 高频数据触发连续12个值都是正常的的高频心率处理 |
|
|
@@ -1345,7 +942,7 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{heartRate.Serialno} 高频持续不足10分钟,在高频警告下限阀值 {lowerAlarmThreshold} 和 高频警告上限阀值:{upperAlarmThreshold}之间,最后胎心值{fetalHeartRate},并且不告警"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
// 超过highFreqSampleTimes,540s |
|
|
|
else |
|
|
@@ -1390,64 +987,15 @@ namespace HealthMonitor.Service.Resolver |
|
|
|
}; |
|
|
|
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); |
|
|
|
|
|
|
|
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
|
// 推送最后一条常规心率计算的胎心数据到iot设备 |
|
|
|
#region 推送最后一条常规心率计算的胎心数据到iot设备 |
|
|
|
|
|
|
|
// 高频(<=12)-常规 |
|
|
|
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设备,高频(<=12)-常规"); |
|
|
|
} |
|
|
|
// 高频(13)-常规-高频(13) |
|
|
|
if (phrFreqstatus != null) |
|
|
|
{ |
|
|
|
var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(heartRate.Serialno, 1); |
|
|
|
phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); |
|
|
|
// 获取高频数据 |
|
|
|
var freqCollection = new List<PregnancyHeartRateModel>(); |
|
|
|
PregnancyHeartRateModel? previousItem = null; |
|
|
|
foreach (var item in phr) |
|
|
|
{ |
|
|
|
if (previousItem != null) |
|
|
|
{ |
|
|
|
var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; |
|
|
|
if (timeNextDiff <= 60) |
|
|
|
{ |
|
|
|
freqCollection.Add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
// 高频最后一条 |
|
|
|
if (lastPhr.MessageId == item.MessageId) |
|
|
|
{ |
|
|
|
freqCollection.Add(item); |
|
|
|
} |
|
|
|
|
|
|
|
previousItem = item; |
|
|
|
} |
|
|
|
//去除高频 |
|
|
|
foreach (var item in freqCollection) |
|
|
|
{ |
|
|
|
phr.Remove(item); |
|
|
|
} |
|
|
|
lastPhr = phr.FirstOrDefault(); |
|
|
|
if (lastPhr?.MessageId == heartRate.MessageId) |
|
|
|
{ |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
_logger.LogInformation($"{heartRate.Serialno} 推送最后一条常规心率计算的胎心数据到iot设备,高频(13)-常规-高频(13)"); |
|
|
|
} |
|
|
|
} |
|
|
|
#region 高频心率计算胎心数据到iot设备 |
|
|
|
|
|
|
|
#endregion |
|
|
|
//if (phrFreqstatus != null && isAbnormal != 0) |
|
|
|
//{ |
|
|
|
// await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
//} |
|
|
|
// 高频有数据都推送到iot |
|
|
|
|
|
|
|
#region 高频心率计算胎心数据到iot设备 |
|
|
|
// 高频(17) ,连续12个高频正常,也不停止且数据偏高和偏低也推送到iot |
|
|
|
if (phrFreqstatus != null && isAbnormal != 0) |
|
|
|
{ |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
} |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
#endregion |
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); |
|
|
|
var fhrMsgId = $"{heartRate.Serialno}-{sampleTime}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|