|
|
@@ -159,79 +159,82 @@ namespace HealthMonitor.WebApi |
|
|
|
var schedule_push = await _serviceEtcd.GetValAsync(key).ConfigureAwait(false); |
|
|
|
if (string.IsNullOrWhiteSpace(schedule_push)) |
|
|
|
{ |
|
|
|
// 胎心数据建模 |
|
|
|
if (key.Contains("pregnancy_heart_rate")) |
|
|
|
{ |
|
|
|
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); |
|
|
|
var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; |
|
|
|
|
|
|
|
if (isFetalHeartEnable) |
|
|
|
using (_logger.BeginScope(new Dictionary<string, object> { ["RequestId"] = $"MODE-{imeiDel}-{DateTime.Now.ToString("yyyyMMddHHmmss")}" })) |
|
|
|
{ |
|
|
|
// 高频心率采样间隔 highFreqSampleInterval = highFreqSampleInterval+5,增加5秒兼容 |
|
|
|
//var highFreqSampleInterval = (int)watchConfig!["highFreqSampleInterval"]! + 5; |
|
|
|
// 高频心率采样间隔 highFreqSampleInterval = highFreqSampleInterval+5,增加5秒兼容(最小highFreqSampleInterval=60) |
|
|
|
var highFreqSampleInterval = (int)watchConfig!["highFreqSampleInterval"]! >= 60 ? (int)watchConfig!["highFreqSampleInterval"]! + 5 : 60; |
|
|
|
// 处理孕妇业务,计算一般心率并下发 |
|
|
|
var commonPHR = await _serviceTDengine.InitPregnancyCommonHeartRateModeAsync(imeiDel, highFreqSampleInterval: highFreqSampleInterval); |
|
|
|
if (commonPHR == null) |
|
|
|
{ |
|
|
|
// 建模中 |
|
|
|
var flag = await _serviceIotApi.SetFetalConfig(imeiDel); |
|
|
|
_logger.LogInformation($"{imeiDel} 建模建模中"); |
|
|
|
} |
|
|
|
else |
|
|
|
#region 胎心数据建模 |
|
|
|
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); |
|
|
|
var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; |
|
|
|
|
|
|
|
if (isFetalHeartEnable) |
|
|
|
{ |
|
|
|
// 建模完成 |
|
|
|
var flag = await _serviceIotApi.SetFetalConfig(imeiDel, 1, commonPHR.MaxValue, commonPHR.MinValue); |
|
|
|
_logger.LogInformation($"{imeiDel} 建模完成"); |
|
|
|
// 保存到TDengine数据库 |
|
|
|
await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", commonPHR); |
|
|
|
_logger.LogInformation($"保存TDengine完成"); |
|
|
|
|
|
|
|
// |
|
|
|
// 高频心率采样间隔 highFreqSampleInterval = highFreqSampleInterval+5,增加5秒兼容 |
|
|
|
//var highFreqSampleInterval = (int)watchConfig!["highFreqSampleInterval"]! + 5; |
|
|
|
// 高频心率采样间隔 highFreqSampleInterval = highFreqSampleInterval+5,增加5秒兼容(最小highFreqSampleInterval=60) |
|
|
|
var highFreqSampleInterval = (int)watchConfig!["highFreqSampleInterval"]! >= 60 ? (int)watchConfig!["highFreqSampleInterval"]! + 5 : 60; |
|
|
|
// 处理孕妇业务,计算一般心率并下发 |
|
|
|
var commonPHR = await _serviceTDengine.InitPregnancyCommonHeartRateModeAsync(imeiDel, highFreqSampleInterval: highFreqSampleInterval); |
|
|
|
if (commonPHR == null) |
|
|
|
{ |
|
|
|
// 建模中 |
|
|
|
var flag = await _serviceIotApi.SetFetalConfig(imeiDel); |
|
|
|
_logger.LogInformation($"{imeiDel} 建模建模中"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 建模完成 |
|
|
|
var flag = await _serviceIotApi.SetFetalConfig(imeiDel, 1, commonPHR.MaxValue, commonPHR.MinValue); |
|
|
|
_logger.LogInformation($"{imeiDel} 建模完成"); |
|
|
|
// 保存到TDengine数据库 |
|
|
|
await _serviceTDengine.InsertAsync<PregnancyCommonHeartRateModel>("hm_pchr", commonPHR); |
|
|
|
_logger.LogInformation($"保存TDengine完成"); |
|
|
|
|
|
|
|
// |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
#region 注册定时下发 |
|
|
|
var startTime = DateTime.Now; |
|
|
|
// 注册下次下推 |
|
|
|
var endTime = DateTime.Now; |
|
|
|
#region 注册定时下发 |
|
|
|
var startTime = DateTime.Now; |
|
|
|
// 注册下次下推 |
|
|
|
var endTime = DateTime.Now; |
|
|
|
|
|
|
|
#if DEBUG |
|
|
|
|
|
|
|
|
|
|
|
//long ttl = (long)((60 * 1000-(endTime-startTime).TotalMilliseconds)/1000); |
|
|
|
//await _serviceEtcd.PutValAsync(key, imeiDel,ttl, false).ConfigureAwait(false); |
|
|
|
//long ttl = (long)((60 * 1000-(endTime-startTime).TotalMilliseconds)/1000); |
|
|
|
//await _serviceEtcd.PutValAsync(key, imeiDel,ttl, false).ConfigureAwait(false); |
|
|
|
|
|
|
|
var interval = 0; |
|
|
|
// 获取当前时间 |
|
|
|
DateTime now = DateTime.Now; |
|
|
|
var interval = 0; |
|
|
|
// 获取当前时间 |
|
|
|
DateTime now = DateTime.Now; |
|
|
|
|
|
|
|
// 计算距离下一个$interval天后的8点的时间间隔 |
|
|
|
DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute + 2, 0).AddDays(interval); |
|
|
|
TimeSpan timeUntilNextRun = nextRunTime - now; |
|
|
|
// 计算距离下一个$interval天后的8点的时间间隔 |
|
|
|
DateTime nextRunTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute + 2, 0).AddDays(interval); |
|
|
|
TimeSpan timeUntilNextRun = nextRunTime - now; |
|
|
|
|
|
|
|
// 如果当前时间已经超过了8点,将等待到明天后的8点 |
|
|
|
if (timeUntilNextRun < TimeSpan.Zero) |
|
|
|
{ |
|
|
|
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromMinutes(1)); |
|
|
|
nextRunTime += timeUntilNextRun; |
|
|
|
} |
|
|
|
// 如果当前时间已经超过了8点,将等待到明天后的8点 |
|
|
|
if (timeUntilNextRun < TimeSpan.Zero) |
|
|
|
{ |
|
|
|
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromMinutes(1)); |
|
|
|
nextRunTime += timeUntilNextRun; |
|
|
|
} |
|
|
|
|
|
|
|
//long ttl = timeUntilNextRun.Milliseconds/1000; |
|
|
|
long ttl = (long)((timeUntilNextRun.TotalMilliseconds - (endTime - startTime).TotalMilliseconds) / 1000); |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
create_time = now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
ttl, |
|
|
|
next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
//long ttl = timeUntilNextRun.Milliseconds/1000; |
|
|
|
long ttl = (long)((timeUntilNextRun.TotalMilliseconds - (endTime - startTime).TotalMilliseconds) / 1000); |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
create_time = now.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
ttl, |
|
|
|
next_run_time = nextRunTime.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
|
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
#else |
|
|
@@ -266,7 +269,9 @@ namespace HealthMonitor.WebApi |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
#endif |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// health_monitor/schedule_push/cal_fetal_heart_rate/imei/ |
|
|
|
else if (key.Contains("health_monitor/schedule_push/cal_fetal_heart_rate/imei/")) |
|
|
@@ -418,51 +423,55 @@ namespace HealthMonitor.WebApi |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
// 胎动计算 |
|
|
|
//health_monitor/schedule_push/cal_fetal_movement/imei/ |
|
|
|
else if (key.Contains("health_monitor/schedule_push/cal_fetal_movement/imei/")) |
|
|
|
{ |
|
|
|
|
|
|
|
#region 胎动延时计算 |
|
|
|
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); |
|
|
|
_logger.LogInformation($"触发胎动计算,设备配置{JsonConvert.SerializeObject(watchConfig)}"); |
|
|
|
var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; |
|
|
|
if (isFetalHeartEnable) |
|
|
|
using (_logger.BeginScope(new Dictionary<string, object> { ["RequestId"] = $"FM-{imeiDel}-{DateTime.Now.ToString("yyyyMMddHHmmss")}" })) |
|
|
|
{ |
|
|
|
var edoc = DateTimeUtil.ToDateTime(watchConfig!["EDOC"]!.ToString()); |
|
|
|
// 已经建模 |
|
|
|
var commonPHR = await _serviceTDengine.GetLastAsync<PregnancyCommonHeartRateModel>(imeiDel); |
|
|
|
if (commonPHR != null) |
|
|
|
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); |
|
|
|
_logger.LogInformation($"触发胎动计算,设备配置{JsonConvert.SerializeObject(watchConfig)}"); |
|
|
|
var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; |
|
|
|
if (isFetalHeartEnable) |
|
|
|
{ |
|
|
|
var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(imeiDel, 7); |
|
|
|
_logger.LogInformation($"{imeiDel} 计算胎动数据 "); |
|
|
|
var edoc = DateTimeUtil.ToDateTime(watchConfig!["EDOC"]!.ToString()); |
|
|
|
// 已经建模 |
|
|
|
var commonPHR = await _serviceTDengine.GetLastAsync<PregnancyCommonHeartRateModel>(imeiDel); |
|
|
|
if (commonPHR != null) |
|
|
|
{ |
|
|
|
var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(imeiDel, 7); |
|
|
|
_logger.LogInformation($"{imeiDel} 计算胎动数据 "); |
|
|
|
|
|
|
|
var fmNow = DateTime.Now; |
|
|
|
// 两小时前 |
|
|
|
var fmNowSubtract = fmNow.AddMinutes(-fmNow.Minute).AddSeconds(-fmNow.Second).AddMilliseconds(-fmNow.Millisecond); |
|
|
|
|
|
|
|
var fetalMovementSampleTime = DateTimeUtil.ConvertToTimeStamp(fmNowSubtract).ToString()[..10]; |
|
|
|
var fmNow = DateTime.Now; |
|
|
|
// 两小时前 |
|
|
|
var fmNowSubtract = fmNow.AddMinutes(-fmNow.Minute).AddSeconds(-fmNow.Second).AddMilliseconds(-fmNow.Millisecond); |
|
|
|
|
|
|
|
// 统计开始时间 |
|
|
|
var statStartTime = fmNowSubtract.AddHours(-2); |
|
|
|
// 统计结束时间 |
|
|
|
var statEndTime = fmNowSubtract; |
|
|
|
var fetalMovementSampleTime = DateTimeUtil.ConvertToTimeStamp(fmNowSubtract).ToString()[..10]; |
|
|
|
|
|
|
|
var isFetalMovementExisted = await _deviceCacheMgr.FetalMovementIsExistedAsync(imeiDel, fetalMovementSampleTime); |
|
|
|
_logger.LogInformation($"{imeiDel} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 开始"); |
|
|
|
// 统计开始时间 |
|
|
|
var statStartTime = fmNowSubtract.AddHours(-2); |
|
|
|
// 统计结束时间 |
|
|
|
var statEndTime = fmNowSubtract; |
|
|
|
|
|
|
|
if (!isFetalMovementExisted) |
|
|
|
{ |
|
|
|
/// 开始计算 |
|
|
|
var phrRange = phr.Where(i => i.LastUpdate >= statStartTime && i.LastUpdate <= statEndTime) |
|
|
|
.OrderByDescending(i => i.LastUpdate) |
|
|
|
.Select(i => i.LastUpdate) |
|
|
|
.ToList(); |
|
|
|
// 判断是否有持续佩戴 |
|
|
|
if (phrRange.Count >= 2) |
|
|
|
var isFetalMovementExisted = await _deviceCacheMgr.FetalMovementIsExistedAsync(imeiDel, fetalMovementSampleTime); |
|
|
|
_logger.LogInformation($"{imeiDel} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 开始"); |
|
|
|
|
|
|
|
if (!isFetalMovementExisted) |
|
|
|
{ |
|
|
|
// 读取胎心数据 |
|
|
|
GeneralParam param = new() |
|
|
|
/// 开始计算 |
|
|
|
var phrRange = phr.Where(i => i.LastUpdate >= statStartTime && i.LastUpdate <= statEndTime) |
|
|
|
.OrderByDescending(i => i.LastUpdate) |
|
|
|
.Select(i => i.LastUpdate) |
|
|
|
.ToList(); |
|
|
|
// 判断是否有持续佩戴 |
|
|
|
if (phrRange.Count >= 2) |
|
|
|
{ |
|
|
|
Filters = new List<QueryFilterCondition> |
|
|
|
// 读取胎心数据 |
|
|
|
GeneralParam param = new() |
|
|
|
{ |
|
|
|
Filters = new List<QueryFilterCondition> |
|
|
|
{ |
|
|
|
new () |
|
|
|
{ |
|
|
@@ -479,152 +488,152 @@ namespace HealthMonitor.WebApi |
|
|
|
// Operator=QueryOperatorEnum.GreaterEqual |
|
|
|
//}, |
|
|
|
}, |
|
|
|
OrderBys = new List<OrderByCondition> |
|
|
|
OrderBys = new List<OrderByCondition> |
|
|
|
{ |
|
|
|
new (){ |
|
|
|
IsDesc=true, |
|
|
|
Key=nameof(HisGpsFetalHeartRate.SampleTime) |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
var fetalHeartRateIsAbnormal = 0; |
|
|
|
var fhr = await _hisFetalHeartApiClient.GetFirstAsync(param, imeiDel[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") }); |
|
|
|
|
|
|
|
// 胎心数据时间与胎动时间一致 |
|
|
|
var time = long.Parse(fhr.SampleTime.Length < 13 ? fhr.SampleTime.PadRight(13, '0') : fhr.SampleTime); |
|
|
|
var fhrSampleTime = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(time); |
|
|
|
}; |
|
|
|
var fetalHeartRateIsAbnormal = 0; |
|
|
|
var fhr = await _hisFetalHeartApiClient.GetFirstAsync(param, imeiDel[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") }); |
|
|
|
|
|
|
|
// 胎心数据时间与胎动时间一致,最后一条胎心数据与胎动数据的小时差不大于2 |
|
|
|
if ((DateTime.Now.Hour - fhrSampleTime.Hour) <= 2) |
|
|
|
{ |
|
|
|
var duringMins = Math.Abs((phrRange.First() - phrRange.Last()).TotalMinutes); |
|
|
|
//在餐后时间段(8:00~10:00,12:00~14:00,18:00~20:00,22:00~24:00)取中间值。其他时间段取正常起始值 |
|
|
|
bool isInTimeRanges = IsLastUpdateInTimeRanges(phrRange.First()); |
|
|
|
// 胎心数据时间与胎动时间一致 |
|
|
|
var time = long.Parse(fhr.SampleTime.Length < 13 ? fhr.SampleTime.PadRight(13, '0') : fhr.SampleTime); |
|
|
|
var fhrSampleTime = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(time); |
|
|
|
|
|
|
|
int pregnancyWeeks = (DateTime.Now - edoc.AddDays(-280)).Days / 7; |
|
|
|
if (pregnancyWeeks >= 12 && pregnancyWeeks <= 50) |
|
|
|
// 胎心数据时间与胎动时间一致,最后一条胎心数据与胎动数据的小时差不大于2 |
|
|
|
if ((DateTime.Now.Hour - fhrSampleTime.Hour) <= 2) |
|
|
|
{ |
|
|
|
var fetalMovementMap = _mgrFetalMovementNormalValueRangeCache.GetFetalMovements(); |
|
|
|
|
|
|
|
var fetalMovementMapValue = isInTimeRanges ? fetalMovementMap |
|
|
|
.Where(i => |
|
|
|
i.PregnancyPeriod![0] <= pregnancyWeeks && |
|
|
|
i.PregnancyPeriod[1] >= pregnancyWeeks) |
|
|
|
.Select(i => i.MedianMovement) |
|
|
|
.FirstOrDefault() |
|
|
|
: |
|
|
|
fetalMovementMap |
|
|
|
.Where(i => |
|
|
|
i.PregnancyPeriod![0] <= pregnancyWeeks && |
|
|
|
i.PregnancyPeriod[1] >= pregnancyWeeks) |
|
|
|
.Select(i => i.InitialMovement) |
|
|
|
.FirstOrDefault() |
|
|
|
; |
|
|
|
|
|
|
|
var fetalMovementValue = (fetalMovementMapValue * duringMins * 2) / 120; |
|
|
|
// 四舍五入 |
|
|
|
var fetalMovement = (int)Math.Round(fetalMovementValue, 0, MidpointRounding.AwayFromZero); |
|
|
|
// _logger.LogInformation($"{imeiDel} segmentCountFMIndex: {i} -- fetalMovementSampleTime:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")} -- statStartTime: {statStartTime} -- statEndTime: {statEndTime}-- isFetalMovementExisted: {isFetalMovementExisted} "); |
|
|
|
|
|
|
|
#region 生理健康与胎动的关系 |
|
|
|
/// (步数)运动步数超过1500步则加1; |
|
|
|
/// (体温)低烧则胎动减1,高烧胎动减2;低烧是37.3~38.5,38.6以上是高烧。 |
|
|
|
/// (血压)血压收缩压大于160则加1。 |
|
|
|
/// (心理)心理压力高加2,压力中加1; |
|
|
|
|
|
|
|
var fetalMovementStepVar = 0; |
|
|
|
var fetalMovementTempVar = 0; |
|
|
|
var fetalMovementBpVar = 0; |
|
|
|
var fetalMovementPpVar = 0; |
|
|
|
var fetalMovementFhrVar = 0; |
|
|
|
// 步数 |
|
|
|
if (true) |
|
|
|
var duringMins = Math.Abs((phrRange.First() - phrRange.Last()).TotalMinutes); |
|
|
|
//在餐后时间段(8:00~10:00,12:00~14:00,18:00~20:00,22:00~24:00)取中间值。其他时间段取正常起始值 |
|
|
|
bool isInTimeRanges = IsLastUpdateInTimeRanges(phrRange.First()); |
|
|
|
|
|
|
|
int pregnancyWeeks = (DateTime.Now - edoc.AddDays(-280)).Days / 7; |
|
|
|
if (pregnancyWeeks >= 12 && pregnancyWeeks <= 50) |
|
|
|
{ |
|
|
|
var step = await _personCacheMgr.GetStepPeriodicityAsync(imeiDel); |
|
|
|
if (step != null) |
|
|
|
var fetalMovementMap = _mgrFetalMovementNormalValueRangeCache.GetFetalMovements(); |
|
|
|
|
|
|
|
var fetalMovementMapValue = isInTimeRanges ? fetalMovementMap |
|
|
|
.Where(i => |
|
|
|
i.PregnancyPeriod![0] <= pregnancyWeeks && |
|
|
|
i.PregnancyPeriod[1] >= pregnancyWeeks) |
|
|
|
.Select(i => i.MedianMovement) |
|
|
|
.FirstOrDefault() |
|
|
|
: |
|
|
|
fetalMovementMap |
|
|
|
.Where(i => |
|
|
|
i.PregnancyPeriod![0] <= pregnancyWeeks && |
|
|
|
i.PregnancyPeriod[1] >= pregnancyWeeks) |
|
|
|
.Select(i => i.InitialMovement) |
|
|
|
.FirstOrDefault() |
|
|
|
; |
|
|
|
|
|
|
|
var fetalMovementValue = (fetalMovementMapValue * duringMins * 2) / 120; |
|
|
|
// 四舍五入 |
|
|
|
var fetalMovement = (int)Math.Round(fetalMovementValue, 0, MidpointRounding.AwayFromZero); |
|
|
|
// _logger.LogInformation($"{imeiDel} segmentCountFMIndex: {i} -- fetalMovementSampleTime:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")} -- statStartTime: {statStartTime} -- statEndTime: {statEndTime}-- isFetalMovementExisted: {isFetalMovementExisted} "); |
|
|
|
|
|
|
|
#region 生理健康与胎动的关系 |
|
|
|
/// (步数)运动步数超过1500步则加1; |
|
|
|
/// (体温)低烧则胎动减1,高烧胎动减2;低烧是37.3~38.5,38.6以上是高烧。 |
|
|
|
/// (血压)血压收缩压大于160则加1。 |
|
|
|
/// (心理)心理压力高加2,压力中加1; |
|
|
|
|
|
|
|
var fetalMovementStepVar = 0; |
|
|
|
var fetalMovementTempVar = 0; |
|
|
|
var fetalMovementBpVar = 0; |
|
|
|
var fetalMovementPpVar = 0; |
|
|
|
var fetalMovementFhrVar = 0; |
|
|
|
// 步数 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
if (DateTime.Now.Hour - ((DateTime)step?.LastUpdate!).Hour <= 2) |
|
|
|
var step = await _personCacheMgr.GetStepPeriodicityAsync(imeiDel); |
|
|
|
if (step != null) |
|
|
|
{ |
|
|
|
if (step.Steps > 1500) fetalMovementStepVar = 1; |
|
|
|
if (DateTime.Now.Hour - ((DateTime)step?.LastUpdate!).Hour <= 2) |
|
|
|
{ |
|
|
|
if (step.Steps > 1500) fetalMovementStepVar = 1; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期步数 时间无效"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期步数 时间无效"); |
|
|
|
_logger.LogWarning($"{imeiDel} 周期步数无数据"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期步数无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 体温 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
var temp = await _personCacheMgr.GetTemperaturePeriodicityAsync(imeiDel); |
|
|
|
if (temp != null) |
|
|
|
// 体温 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
if (DateTime.Now.Hour - ((DateTime)temp?.LastUpdate!).Hour <= 2) |
|
|
|
var temp = await _personCacheMgr.GetTemperaturePeriodicityAsync(imeiDel); |
|
|
|
if (temp != null) |
|
|
|
{ |
|
|
|
// 中烧 |
|
|
|
if (temp.Temperature >= 37.3M && temp.Temperature <= 38.5M) |
|
|
|
if (DateTime.Now.Hour - ((DateTime)temp?.LastUpdate!).Hour <= 2) |
|
|
|
{ |
|
|
|
fetalMovementTempVar = -1; |
|
|
|
// 中烧 |
|
|
|
if (temp.Temperature >= 37.3M && temp.Temperature <= 38.5M) |
|
|
|
{ |
|
|
|
fetalMovementTempVar = -1; |
|
|
|
} |
|
|
|
// 高烧 |
|
|
|
if (temp.Temperature >= 38.6M) |
|
|
|
{ |
|
|
|
fetalMovementTempVar = -2; |
|
|
|
} |
|
|
|
} |
|
|
|
// 高烧 |
|
|
|
if (temp.Temperature >= 38.6M) |
|
|
|
else |
|
|
|
{ |
|
|
|
fetalMovementTempVar = -2; |
|
|
|
_logger.LogWarning($"{imeiDel} 周期体温 时间无效"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期体温 时间无效"); |
|
|
|
_logger.LogWarning($"{imeiDel} 周期体温无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期体温无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 血压 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
var bp = await _personCacheMgr.GetBloodPressPeriodicityAsync(imeiDel); |
|
|
|
if (bp != null) |
|
|
|
// 血压 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
if (DateTime.Now.Hour - ((DateTime)bp?.LastUpdate!).Hour <= 2) |
|
|
|
var bp = await _personCacheMgr.GetBloodPressPeriodicityAsync(imeiDel); |
|
|
|
if (bp != null) |
|
|
|
{ |
|
|
|
if (bp.SystolicValue > 160) |
|
|
|
if (DateTime.Now.Hour - ((DateTime)bp?.LastUpdate!).Hour <= 2) |
|
|
|
{ |
|
|
|
if (bp.SystolicValue > 160) |
|
|
|
{ |
|
|
|
fetalMovementBpVar = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fetalMovementBpVar = 1; |
|
|
|
_logger.LogWarning($"{imeiDel} 周期血压 时间无效"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期血压 时间无效"); |
|
|
|
_logger.LogWarning($"{imeiDel} 周期血压无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
// 心理 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期血压无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
// 心理 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
//-1 不处理, |
|
|
|
//0 正常, |
|
|
|
//1 轻度, |
|
|
|
//2 中度; |
|
|
|
//3 重度; |
|
|
|
GeneralParam psychResultParam = new() |
|
|
|
{ |
|
|
|
Filters = new List<QueryFilterCondition> |
|
|
|
//-1 不处理, |
|
|
|
//0 正常, |
|
|
|
//1 轻度, |
|
|
|
//2 中度; |
|
|
|
//3 重度; |
|
|
|
GeneralParam psychResultParam = new() |
|
|
|
{ |
|
|
|
Filters = new List<QueryFilterCondition> |
|
|
|
{ |
|
|
|
new () |
|
|
|
{ |
|
|
@@ -641,157 +650,158 @@ namespace HealthMonitor.WebApi |
|
|
|
// Operator=QueryOperatorEnum.GreaterEqual |
|
|
|
//}, |
|
|
|
}, |
|
|
|
OrderBys = new List<OrderByCondition> |
|
|
|
OrderBys = new List<OrderByCondition> |
|
|
|
{ |
|
|
|
new (){ |
|
|
|
IsDesc=true, |
|
|
|
Key=nameof(HisGpsPsychResult.Serialno) |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
var psych = await _hisPsychResultApiClient.GetFirstAsync(psychResultParam, imeiDel[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") }); |
|
|
|
if (psych != null) |
|
|
|
{ |
|
|
|
if (psych?.StressScore == 2) |
|
|
|
}; |
|
|
|
var psych = await _hisPsychResultApiClient.GetFirstAsync(psychResultParam, imeiDel[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") }); |
|
|
|
if (psych != null) |
|
|
|
{ |
|
|
|
fetalMovementPpVar = 1; |
|
|
|
} |
|
|
|
if (psych?.StressScore == 2) |
|
|
|
{ |
|
|
|
fetalMovementPpVar = 1; |
|
|
|
} |
|
|
|
|
|
|
|
if (psych?.StressScore == 3) |
|
|
|
if (psych?.StressScore == 3) |
|
|
|
{ |
|
|
|
fetalMovementPpVar = 2; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fetalMovementPpVar = 2; |
|
|
|
_logger.LogWarning($"{imeiDel} 周期心理压力无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 周期心理压力无数据"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 胎心与胎动的关系 |
|
|
|
/// 胎心值过缓时,则胎动数量减1;胎心值过速时,则胎动也加1。 |
|
|
|
/// 此值允许在上限值上继续增加,在下限值上继续减少,最小值为0。 |
|
|
|
/// 告警上限阀值 |
|
|
|
#region 胎心与胎动的关系 |
|
|
|
/// 胎心值过缓时,则胎动数量减1;胎心值过速时,则胎动也加1。 |
|
|
|
/// 此值允许在上限值上继续增加,在下限值上继续减少,最小值为0。 |
|
|
|
/// 告警上限阀值 |
|
|
|
|
|
|
|
//1表示偏高;2表示偏低 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
if (fhr.IsAbnormal == 2) |
|
|
|
//1表示偏高;2表示偏低 |
|
|
|
if (true) |
|
|
|
{ |
|
|
|
fetalMovementPpVar = -1; |
|
|
|
} |
|
|
|
if (fhr.IsAbnormal == 2) |
|
|
|
{ |
|
|
|
fetalMovementPpVar = -1; |
|
|
|
} |
|
|
|
|
|
|
|
if (fhr.IsAbnormal == 1) |
|
|
|
{ |
|
|
|
fetalMovementPpVar = 1; |
|
|
|
if (fhr.IsAbnormal == 1) |
|
|
|
{ |
|
|
|
fetalMovementPpVar = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
_logger.LogInformation($"{imeiDel} 原始胎动值:{fetalMovementValue}, 步数参数变动值:{fetalMovementStepVar},体温参数变动值:{fetalMovementTempVar},血压参数变动值:{fetalMovementBpVar},心理压力参数变动值:{fetalMovementPpVar},胎心参数变动值:{fetalMovementFhrVar}"); |
|
|
|
#endregion |
|
|
|
|
|
|
|
_logger.LogInformation($"{imeiDel} 原始胎动值:{fetalMovementValue}, 步数参数变动值:{fetalMovementStepVar},体温参数变动值:{fetalMovementTempVar},血压参数变动值:{fetalMovementBpVar},心理压力参数变动值:{fetalMovementPpVar},胎心参数变动值:{fetalMovementFhrVar}"); |
|
|
|
|
|
|
|
fetalMovementValue = fetalMovementValue + fetalMovementStepVar + fetalMovementTempVar + fetalMovementBpVar + fetalMovementPpVar + fetalMovementFhrVar; |
|
|
|
|
|
|
|
fetalMovementValue = fetalMovementValue + fetalMovementStepVar + fetalMovementTempVar + fetalMovementBpVar + fetalMovementPpVar + fetalMovementFhrVar; |
|
|
|
|
|
|
|
_logger.LogInformation($"{imeiDel} 孕周:{pregnancyWeeks},胎动数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 采样周期:{statStartTime}-{statEndTime}, 原始胎动值:{fetalMovementMapValue}, 佩戴时间 :{duringMins}|{phrRange.Last()}-{phrRange.First()}, 胎动计算值:{fetalMovementValue}, 胎动最终值:{fetalMovement} 已完成."); |
|
|
|
|
|
|
|
// 获取胎心数据状态与胎动数据状态一致 |
|
|
|
//etalHeartRateIsAbnormal= fhr.IsAbnormal; |
|
|
|
var feltalMovementIsAbnormal = fetalHeartRateIsAbnormal; |
|
|
|
_logger.LogInformation($"{imeiDel} 孕周:{pregnancyWeeks},胎动数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 采样周期:{statStartTime}-{statEndTime}, 原始胎动值:{fetalMovementMapValue}, 佩戴时间 :{duringMins}|{phrRange.Last()}-{phrRange.First()}, 胎动计算值:{fetalMovementValue}, 胎动最终值:{fetalMovement} 已完成."); |
|
|
|
|
|
|
|
await _serviceIotApi.SetFetalMovementConfig(imeiDel, fetalMovement, fetalMovementSampleTime, feltalMovementIsAbnormal); |
|
|
|
// 获取胎心数据状态与胎动数据状态一致 |
|
|
|
//etalHeartRateIsAbnormal= fhr.IsAbnormal; |
|
|
|
var feltalMovementIsAbnormal = fetalHeartRateIsAbnormal; |
|
|
|
|
|
|
|
// 保存到MySQL数据库 |
|
|
|
HisGpsFetalMovement fm = new() |
|
|
|
{ |
|
|
|
FetalMovementId = Guid.NewGuid().ToString("D"), |
|
|
|
PersonId = commonPHR!.PersonId, |
|
|
|
Serialno = imeiDel, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
IsAbnormal = feltalMovementIsAbnormal, |
|
|
|
FetalMovementValue = fetalMovement, |
|
|
|
SampleTime = fetalMovementSampleTime, |
|
|
|
Method = 1, |
|
|
|
IsDisplay = 1, |
|
|
|
DeviceKey = commonPHR!.DeviceKey |
|
|
|
}; |
|
|
|
await _hisFetalMovementApiClient.AddAsync(fm).ConfigureAwait(false); |
|
|
|
|
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(imeiDel).ConfigureAwait(false); |
|
|
|
var fmMsgId = $"{imeiDel}-{fetalMovementSampleTime}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|
var fmMsgTime = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(fetalMovementSampleTime.Length < 13 ? fetalMovementSampleTime.PadRight(13, '0') : fetalMovementSampleTime)).ToString("yyyy-MM-dd HH:mm:ss"); |
|
|
|
// 胎动数据推送到第三方 |
|
|
|
var topic = "topic.push.third"; |
|
|
|
var fmThridMsg = new |
|
|
|
{ |
|
|
|
messageId = fmMsgId, |
|
|
|
topic = topic, |
|
|
|
time = fmMsgTime, |
|
|
|
data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
value = fetalMovement, |
|
|
|
isAbnormal = feltalMovementIsAbnormal, |
|
|
|
type = "fetalMovement" |
|
|
|
} |
|
|
|
}; |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fmMsgId, topic, 31, fmThridMsg).ConfigureAwait(false); |
|
|
|
await _serviceIotApi.SetFetalMovementConfig(imeiDel, fetalMovement, fetalMovementSampleTime, feltalMovementIsAbnormal); |
|
|
|
|
|
|
|
// 胎动数据推送到微信 |
|
|
|
if (feltalMovementIsAbnormal != 0) |
|
|
|
{ |
|
|
|
topic = "topic.push.wx"; |
|
|
|
var fmMsg = new |
|
|
|
// 保存到MySQL数据库 |
|
|
|
HisGpsFetalMovement fm = new() |
|
|
|
{ |
|
|
|
FetalMovementId = Guid.NewGuid().ToString("D"), |
|
|
|
PersonId = commonPHR!.PersonId, |
|
|
|
Serialno = imeiDel, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
IsAbnormal = feltalMovementIsAbnormal, |
|
|
|
FetalMovementValue = fetalMovement, |
|
|
|
SampleTime = fetalMovementSampleTime, |
|
|
|
Method = 1, |
|
|
|
IsDisplay = 1, |
|
|
|
DeviceKey = commonPHR!.DeviceKey |
|
|
|
}; |
|
|
|
await _hisFetalMovementApiClient.AddAsync(fm).ConfigureAwait(false); |
|
|
|
|
|
|
|
var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(imeiDel).ConfigureAwait(false); |
|
|
|
var fmMsgId = $"{imeiDel}-{fetalMovementSampleTime}-{Guid.NewGuid().ToString("D")[^3..]}"; |
|
|
|
var fmMsgTime = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(fetalMovementSampleTime.Length < 13 ? fetalMovementSampleTime.PadRight(13, '0') : fetalMovementSampleTime)).ToString("yyyy-MM-dd HH:mm:ss"); |
|
|
|
// 胎动数据推送到第三方 |
|
|
|
var topic = "topic.push.third"; |
|
|
|
var fmThridMsg = new |
|
|
|
{ |
|
|
|
messageId = Guid.NewGuid().ToString("D"), |
|
|
|
messageId = fmMsgId, |
|
|
|
topic = topic, |
|
|
|
time = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(fetalMovementSampleTime.Length < 13 ? fetalMovementSampleTime.PadRight(13, '0') : fetalMovementSampleTime)).ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
time = fmMsgTime, |
|
|
|
data = new |
|
|
|
{ |
|
|
|
deviceId = device?.DeviceId, |
|
|
|
imei = imeiDel, |
|
|
|
alarmTypeId = 12, |
|
|
|
alarmDeviceName = imeiDel, |
|
|
|
alarmRemarks = JsonConvert.SerializeObject(new { fetalMovementValue = fetalMovement, isAbnormal = feltalMovementIsAbnormal }), |
|
|
|
address = string.Empty, |
|
|
|
deviceKey = device?.DeviceId |
|
|
|
value = fetalMovement, |
|
|
|
isAbnormal = feltalMovementIsAbnormal, |
|
|
|
type = "fetalMovement" |
|
|
|
} |
|
|
|
}; |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fmMsgId, topic, fmMsg).ConfigureAwait(false); |
|
|
|
} |
|
|
|
// 设置入库缓存记录 |
|
|
|
await _deviceCacheMgr.SetFetalMovementAsync(imeiDel, fetalMovementSampleTime, fm); |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fmMsgId, topic, 31, fmThridMsg).ConfigureAwait(false); |
|
|
|
|
|
|
|
// 胎动数据推送到微信 |
|
|
|
if (feltalMovementIsAbnormal != 0) |
|
|
|
{ |
|
|
|
topic = "topic.push.wx"; |
|
|
|
var fmMsg = new |
|
|
|
{ |
|
|
|
messageId = Guid.NewGuid().ToString("D"), |
|
|
|
topic = topic, |
|
|
|
time = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(long.Parse(fetalMovementSampleTime.Length < 13 ? fetalMovementSampleTime.PadRight(13, '0') : fetalMovementSampleTime)).ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
data = new |
|
|
|
{ |
|
|
|
deviceId = device?.DeviceId, |
|
|
|
imei = imeiDel, |
|
|
|
alarmTypeId = 12, |
|
|
|
alarmDeviceName = imeiDel, |
|
|
|
alarmRemarks = JsonConvert.SerializeObject(new { fetalMovementValue = fetalMovement, isAbnormal = feltalMovementIsAbnormal }), |
|
|
|
address = string.Empty, |
|
|
|
deviceKey = device?.DeviceId |
|
|
|
} |
|
|
|
}; |
|
|
|
await _serviceMqProcess.ProcessIMEIEventMessageAsync(fmMsgId, topic, fmMsg).ConfigureAwait(false); |
|
|
|
} |
|
|
|
// 设置入库缓存记录 |
|
|
|
await _deviceCacheMgr.SetFetalMovementAsync(imeiDel, fetalMovementSampleTime, fm); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 孕周 {pregnancyWeeks},超出胎动计算范围"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 孕周 {pregnancyWeeks},超出胎动计算范围"); |
|
|
|
_logger.LogWarning($"{imeiDel} 最后一条胎心数据与胎动数据的小时差大于2,不计算胎动数据"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogWarning($"{imeiDel} 最后一条胎心数据与胎动数据的小时差大于2,不计算胎动数据"); |
|
|
|
_logger.LogInformation($"{imeiDel} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 不足两条,不能判断是否持续佩戴"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogInformation($"{imeiDel} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 不足两条,不能判断是否持续佩戴"); |
|
|
|
|
|
|
|
_logger.LogInformation($"{imeiDel} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 已处理"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
_logger.LogInformation($"{imeiDel} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{fmNowSubtract.ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 已处理"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endregion |
|
|
|
} |
|
|
|