Kaynağa Gözat

胎动计算

datasub12_fetal_heart_rate_0
H Vs 3 ay önce
ebeveyn
işleme
ceddfdca56
6 değiştirilmiş dosya ile 361 ekleme ve 138 silme
  1. +96
    -0
      HealthMonitor.Service/Cache/FetalMovementCacheManager.cs
  2. +1
    -1
      HealthMonitor.Service/HealthMonitor.Service.csproj
  3. +167
    -41
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs
  4. +1
    -1
      HealthMonitor.WebApi/HealthMonitor.WebApi.csproj
  5. +1
    -0
      HealthMonitor.WebApi/Program.cs
  6. +95
    -95
      HealthMonitor.WebApi/Worker.cs

+ 96
- 0
HealthMonitor.Service/Cache/FetalMovementCacheManager.cs Dosyayı Görüntüle

@@ -0,0 +1,96 @@
using HealthMonitor.Common;
using HealthMonitor.Model.Service.Mapper;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TelpoDataService.Util.Clients;
using TelpoDataService.Util.Entities.GpsLocationHistory;
using TelpoDataService.Util.Models;
using TelpoDataService.Util.QueryObjects;

namespace HealthMonitor.Service.Cache
{
public class FetalMovementCacheManager
{
private readonly ILogger<FetalMovementCacheManager> _logger;
private readonly GpsLocationHistoryAccessorClient<HisGpsFetalMovement> _hisFetalMovementApiClient;

private const string CACHE_KEY_FETALMOVEMENT = "FM_";

public FetalMovementCacheManager(ILogger<FetalMovementCacheManager> logger, GpsLocationHistoryAccessorClient<HisGpsFetalMovement> hisFetalMovementApiClient)
{
_logger = logger;
_hisFetalMovementApiClient = hisFetalMovementApiClient;
}
public async Task SetFetalMovementAsync(string serialNo, string sampleTime)
{
try
{
var key = $"{CACHE_KEY_FETALMOVEMENT}_{serialNo}_{sampleTime}";
var time = long.Parse(sampleTime.Length < 13 ? sampleTime.PadRight(13, '0') : sampleTime);
var value = DateTimeUtil.GetDateTimeFromUnixTimeMilliseconds(time).ToString("yyyy-MM-dd HH:mm:ss");
await RedisHelper.SetAsync(key, value, 2 * 3600).ConfigureAwait(false);
}
catch (Exception ex)
{

_logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
}
}


public async Task<bool> FetalMovementIsExistedAsync(string serialNo, string sampleTime)
{
try
{
var key = $"{CACHE_KEY_FETALMOVEMENT}_{serialNo}_{sampleTime}";
var res = await RedisHelper.GetAsync(key).ConfigureAwait(false);

if (string.IsNullOrEmpty(res))
{
GeneralParam param = new()
{
Filters = new List<QueryFilterCondition>
{
new ()
{
Key=nameof(HisGpsFetalHeartRate.Serialno),
Value=serialNo,
ValueType=QueryValueTypeEnum.String,
Operator=QueryOperatorEnum.Equal
},
new ()
{
Key=nameof(HisGpsFetalHeartRate.SampleTime),
Value=sampleTime,
ValueType=QueryValueTypeEnum.String,
Operator=QueryOperatorEnum.Equal
},
}
};
var isFetalMovementExist = await _hisFetalMovementApiClient.GetFirstAsync(param, serialNo[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") });
if (isFetalMovementExist != null)
{
await SetFetalMovementAsync(serialNo,sampleTime);
return true;
}
}
else
{
return true;
}

}
catch (Exception ex)
{
_logger.LogWarning($"Redis 发生异常:{ex.Message}, {ex.StackTrace}");
}
return false;
}
}
}

+ 1
- 1
HealthMonitor.Service/HealthMonitor.Service.csproj Dosyayı Görüntüle

@@ -15,7 +15,7 @@
<PackageReference Include="SqlSugarCore" Version="5.1.4.160" />
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="TDengine.Connector" Version="3.0.2" />
<PackageReference Include="TelpoDataService.Util" Version="1.6.9.30-beta1" />
<PackageReference Include="TelpoDataService.Util" Version="1.6.9.31-beta1" />
</ItemGroup>

<ItemGroup>


+ 167
- 41
HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs Dosyayı Görüntüle

@@ -18,7 +18,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TelpoDataService.Util.Clients;
using TelpoDataService.Util.Entities.GpsCard;
using TelpoDataService.Util.Entities.GpsLocationHistory;
using TelpoDataService.Util.Models;
using TelpoDataService.Util.QueryObjects;

namespace HealthMonitor.Service.Resolver
{
@@ -37,12 +40,20 @@ namespace HealthMonitor.Service.Resolver
private readonly EtcdService _serviceEtcd;

private readonly GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> _hisFetalHeartApiClient;
private readonly GpsLocationHistoryAccessorClient<HisGpsFetalMovement> _hisFetalMovementApiClient;

private readonly FetalMovementNormalValueRangeCacheManager _mgrFetalMovementNormalValueRangeCache;

private readonly FetalMovementCacheManager _mgrFetalMovement;


public PregnancyHeartRateResolver(ILogger<PregnancyHeartRateResolver> logger,
HttpHelper httpHelper, EtcdService serviceEtcd, DeviceCacheManager deviceCacheMgr,
IotApiService iotApiService, TDengineService serviceDengine, GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartApiClient)
IotApiService iotApiService, TDengineService serviceDengine, FetalMovementNormalValueRangeCacheManager fetalMovementNormalValueRangeCacheMgr,
GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartApiClient,
FetalMovementCacheManager fetalMovementCacheManager,
GpsLocationHistoryAccessorClient<HisGpsFetalMovement> hisFetalMovementApiClient
)
{
_logger = logger;
_httpHelper = httpHelper;
@@ -51,6 +62,9 @@ namespace HealthMonitor.Service.Resolver
_deviceCacheMgr = deviceCacheMgr;
_serviceIotApi = iotApiService;
_hisFetalHeartApiClient = hisFetalHeartApiClient;
_hisFetalMovementApiClient = hisFetalMovementApiClient;
_mgrFetalMovementNormalValueRangeCache = fetalMovementNormalValueRangeCacheMgr;
_mgrFetalMovement = fetalMovementCacheManager;
}

public void SetResolveInfo(PackageMsgModel msg)
@@ -100,6 +114,8 @@ namespace HealthMonitor.Service.Resolver
var upperAlarmThreshold = (int)watchConfig["upperAlarmThreshold"]!;
// 告警下限阀值
var lowerAlarmThreshold = (int)watchConfig["lowerAlarmThreshold"]!;
// EDOC
var edoc = DateTimeUtil.ToDateTime(watchConfig!["EDOC"]!.ToString());


var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(heartRate.Serialno, 7);
@@ -200,12 +216,13 @@ namespace HealthMonitor.Service.Resolver
}
#endregion

#region 计算胎心数据
#region 计算胎心和胎动数据
var commonPHR = await _serviceTDengine.GetLastAsync<PregnancyCommonHeartRateModel>(heartRate.Serialno);
if (commonPHR != null)
{

#region 计算胎心数据
_logger.LogInformation($"{heartRate.Serialno} 计算胎心数据 ");
// 上15分钟的数据
// 获取当前时间
DateTime nowQuarter = (DateTime)heartRate.LastUpdate!;
@@ -246,8 +263,8 @@ namespace HealthMonitor.Service.Resolver
var fetalHeartRate = SafeType.SafeInt(qarterPhrValue * commonPHR?.StatModeAvgFprCoefficient!);


var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0);
var fetalHeartRateIsAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0);
fetalHeartRateIsAbnormal = 0;// 不是高频数据,按正常值
HisGpsFetalHeartRate gpsFetalHeartRate = new()
{
FetalHeartRateId = Guid.NewGuid().ToString("D"),
@@ -255,7 +272,7 @@ namespace HealthMonitor.Service.Resolver
Serialno = heartRate.Serialno,
HeartRate = fetalHeartRate,
SampleTime = sampleTime.Length > 10 ? sampleTime.Substring(0, 10) : sampleTime,
IsAbnormal = isAbnormal,
IsAbnormal = fetalHeartRateIsAbnormal,
StatStartTime = filteredPhr.OrderBy(i => i.LastUpdate).First().LastUpdate,
StatEndTime = filteredPhr.OrderBy(i => i.LastUpdate).Last().LastUpdate,
CreateTime = DateTime.Now,
@@ -267,14 +284,112 @@ namespace HealthMonitor.Service.Resolver
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false);

// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal);
await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, fetalHeartRateIsAbnormal);
#endregion

#region 计算胎动数据
_logger.LogInformation($"{heartRate.Serialno} 计算胎动数据 ");

var fetalMovementNow = (DateTime)heartRate.LastUpdate!;

var midNight = new DateTime(fetalMovementNow.Year, fetalMovementNow.Month, fetalMovementNow.Day, 0, 0, 0);

TimeSpan fetalMovementTS = fetalMovementNow - midNight;

// 当天每隔2小时的段数,取整数部分
int segmentCount = (int)(fetalMovementTS.TotalHours / 2);

for (int i = 0; i < segmentCount; i++)
{
// 每两小时
var fetalMovementSampleTime = DateTimeUtil.ConvertToTimeStamp(midNight.AddHours(2 * i)).ToString()[..10];
// 统计开始时间
var statStartTime = midNight.AddHours(2 * i);
// 统计结束时间
var statEndTime = midNight.AddHours(2 * (i+1));

//var isFetalMovementExist = await _hisFetalMovementApiClient.GetFirstAsync(param, heartRate.Serialno[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") });
var isFetalMovementExisted = await _mgrFetalMovement.FetalMovementIsExistedAsync(heartRate.Serialno, fetalMovementSampleTime);
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 duringMins = Math.Abs((phrRange.First()- statStartTime).TotalMinutes);
//在餐后时间段(8:00~10:00,12:00~14:00,18:00~20:00,22:00~24:00)取中间值。其他时间段取正常起始值
bool isInTimeRanges = IsLastUpdateInTimeRanges(fetalMovementNow);

int pregnancyWeeks = (DateTime.Now - edoc.AddDays(-280)).Days / 7;
if (pregnancyWeeks >= 12 && pregnancyWeeks <= 50)
{
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($"{heartRate.Serialno} segmentCountIndex: {i} -- fetalMovementSampleTime:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")} -- statStartTime: {statStartTime} -- statEndTime: {statEndTime}-- isFetalMovementExisted: {isFetalMovementExisted} ");

_logger.LogInformation($"{heartRate.Serialno} 胎动数据采样时间:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")}, 采样周期:{statStartTime}-{statEndTime}, 原始胎动值:{fetalMovementMapValue}, 佩戴时间 :{duringMins}|{statStartTime}-{phrRange.First()}, 胎动计算值:{fetalMovementValue}, 胎动最终值:{fetalMovement}");

// 获取胎心数据状态与胎动数据状态一致
var feltalMovementIsAbnormal = fetalHeartRateIsAbnormal;
// 推送到api/v1/open/OpenIot/SetFetalMovementConfig
await _serviceIotApi.SetFetalMovementConfig(heartRate.Serialno, fetalMovement, fetalMovementSampleTime, feltalMovementIsAbnormal);
// 保存到MySQL数据库
HisGpsFetalMovement fm = new()
{
FetalMovementId = Guid.NewGuid().ToString("D"),
PersonId = commonPHR!.PersonId,
Serialno = heartRate.Serialno,
CreateTime = DateTime.Now,
IsAbnormal = feltalMovementIsAbnormal,
FetalMovementValue = fetalMovement,
SampleTime = fetalMovementSampleTime,
Method = 1,
IsDisplay = 1,
DeviceKey = commonPHR!.DeviceKey
};
await _hisFetalMovementApiClient.AddAsync(fm).ConfigureAwait(false);

// 设置入库缓存记录
await _mgrFetalMovement.SetFetalMovementAsync(heartRate.Serialno, fetalMovementSampleTime);
}
}
}

}
#endregion
}
#endregion




#region 定时计算胎心数据触发器 {interval} 秒后
//var fetalKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}";
//await SetIntervalTriggerAsync(fetalKey, heartRate.Serialno, 60 * 15);
@@ -303,43 +418,22 @@ namespace HealthMonitor.Service.Resolver
#endregion

#region 定时计算胎动数据触发器 0 点开始
var fetalMovementKey = $"health_monitor/schedule_push/cal_fetal_movement/imei/{heartRate.Serialno}";
/// 计算 0 点秒数
DateTime now = DateTime.Now;
var rand = new Random();
var pushSec = rand.Next(59);
int pushMin = int.TryParse(heartRate.Serialno.AsSpan(heartRate.Serialno.Length - 1), out pushMin) ? pushMin : 10;
DateTime nextRunTime = new (now.Year, now.Month, now.Day, 0, pushMin, pushSec);
TimeSpan timeUntilNextRun = nextRunTime - now;
if (timeUntilNextRun < TimeSpan.Zero)
{
timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1));
nextRunTime += timeUntilNextRun;
}
var ttl = (long)timeUntilNextRun.TotalSeconds;

await SetIntervalTriggerAsync(fetalMovementKey, heartRate.Serialno, ttl);

//var scheduleFetalMovementPush = await _serviceEtcd.GetValAsync(fetalMovementKey).ConfigureAwait(false);
//if (string.IsNullOrWhiteSpace(scheduleFetalMovementPush))
//var fetalMovementKey = $"health_monitor/schedule_push/cal_fetal_movement/imei/{heartRate.Serialno}";
///// 计算 0 点秒数
//DateTime now = DateTime.Now;
//var rand = new Random();
//var pushSec = rand.Next(59);
//int pushMin = int.TryParse(heartRate.Serialno.AsSpan(heartRate.Serialno.Length - 1), out pushMin) ? pushMin : 10;
//DateTime nextRunTime = new (now.Year, now.Month, now.Day, 0, pushMin, pushSec);
//TimeSpan timeUntilNextRun = nextRunTime - now;
//if (timeUntilNextRun < TimeSpan.Zero)
//{
// var fetalMovementInterval = 60 * 15;
// var fetalMovementNow = DateTime.Now;
// var fetalMovementTimeNextRun = fetalMovementNow.Add(TimeSpan.FromSeconds(fetalMovementInterval));
// var fetalMovementTTL = fetalMovementInterval;
// var data = new
// {
// imei = heartRate.Serialno,
// create_time = fetalMovementNow.ToString("yyyy-MM-dd HH:mm:ss"),
// fetalMovementTTL,
// next_run_time = fetalMovementTimeNextRun.ToString("yyyy-MM-dd HH:mm:ss")
// };
// var result = JsonConvert.SerializeObject(data);

// await _serviceEtcd.PutValAsync(fetalKey, result, fetalMovementTTL, false).ConfigureAwait(false);

// timeUntilNextRun = timeUntilNextRun.Add(TimeSpan.FromDays(1));
// nextRunTime += timeUntilNextRun;
//}
//var ttl = (long)timeUntilNextRun.TotalSeconds;

//await SetIntervalTriggerAsync(fetalMovementKey, heartRate.Serialno, ttl);
#endregion
}

@@ -473,5 +567,37 @@ namespace HealthMonitor.Service.Resolver
await _serviceEtcd.PutValAsync(key, result, interval, false).ConfigureAwait(false);
}
}

public static bool IsNowInTimeRanges()
{
var now = DateTime.Now.TimeOfDay;

var timeRanges = new List<(TimeSpan Start, TimeSpan End)>
{
// 8:00~10:00,12:00~14:00,18:00~20:00,22:00~24:00
(new TimeSpan(8, 0, 0), new TimeSpan(10, 0, 0)),
(new TimeSpan(12, 0, 0), new TimeSpan(14, 0, 0)),
(new TimeSpan(18, 0, 0), new TimeSpan(20, 0, 0)),
(new TimeSpan(22, 0, 0), new TimeSpan(24, 0, 0))
};

return timeRanges.Any(range => now >= range.Start && now <= range.End);
}

public static bool IsLastUpdateInTimeRanges(DateTime lastUpdate)
{
var now = lastUpdate.TimeOfDay;

var timeRanges = new List<(TimeSpan Start, TimeSpan End)>
{
// 8:00~10:00,12:00~14:00,18:00~20:00,22:00~24:00
(new TimeSpan(8, 0, 0), new TimeSpan(10, 0, 0)),
(new TimeSpan(12, 0, 0), new TimeSpan(14, 0, 0)),
(new TimeSpan(18, 0, 0), new TimeSpan(20, 0, 0)),
(new TimeSpan(22, 0, 0), new TimeSpan(24, 0, 0))
};

return timeRanges.Any(range => now >= range.Start && now <= range.End);
}
}
}

+ 1
- 1
HealthMonitor.WebApi/HealthMonitor.WebApi.csproj Dosyayı Görüntüle

@@ -11,7 +11,7 @@
<PackageReference Include="Serilog.Expressions" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="TelpoDataService.Util" Version="1.6.9.30-beta1" />
<PackageReference Include="TelpoDataService.Util" Version="1.6.9.31-beta1" />
</ItemGroup>

<ItemGroup>


+ 1
- 0
HealthMonitor.WebApi/Program.cs Dosyayı Görüntüle

@@ -173,6 +173,7 @@ namespace HealthMonitor.WebApi
builder.Services
.AddSingleton<PersonCacheManager>()
.AddSingleton<DeviceCacheManager>()
.AddSingleton<FetalMovementCacheManager>()
.AddSingleton<FhrPhrMapCacheManager>()
.AddSingleton<FetalMovementNormalValueRangeCacheManager>()
.AddSingleton<BloodPressReferenceValueCacheManager>();


+ 95
- 95
HealthMonitor.WebApi/Worker.cs Dosyayı Görüntüle

@@ -325,102 +325,102 @@ namespace HealthMonitor.WebApi
//health_monitor/schedule_push/cal_fetal_movement/imei/
else if (key.Contains("health_monitor/schedule_push/cal_fetal_movement/imei/"))
{
// 计算胎动数据
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067");
var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1;
if (isFetalHeartEnable)
{
// 检查胎心建模
var fchr = await _serviceTDengine.GetLastAsync<PregnancyCommonHeartRateModel>(imeiDel);
if (fchr != null)
{
// 获取孕妇心率数据接近最近2小时的数据
var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(imeiDel, 7);
var now = DateTime.Now;
var ago2hrs = now.AddHours(-2);
var phrRange = phr.Where(i => i.LastUpdate >= ago2hrs)
.OrderByDescending(i => i.LastUpdate)
.Select(i => i.LastUpdate)
.ToList();
if (phrRange.Count >= 2)
{
var duringMins = (phrRange.First() - phrRange.Last()).TotalMinutes;
//在餐后时间段(8:00~10:00,12:00~14:00,18:00~20:00,22:00~24:00)取中间值。其他时间段取正常起始值
bool isInTimeRanges = IsNowInTimeRanges();
//long.TryParse(watchConfig!["EDOC"]!.ToString(), out long edoc);
var edoc = DateTimeUtil.ToDateTime(watchConfig!["EDOC"]!.ToString());
int pregnancyWeeks = (DateTime.Now -edoc.AddDays(-280)).Days / 7;
if (pregnancyWeeks >= 12 && pregnancyWeeks <= 50)
{
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 watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067");
//var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1;
//if (isFetalHeartEnable)
//{
// // 检查胎心建模
// var fchr = await _serviceTDengine.GetLastAsync<PregnancyCommonHeartRateModel>(imeiDel);
// if (fchr != null)
// {
// // 获取孕妇心率数据接近最近2小时的数据
// var phr = await _serviceTDengine.GetBySerialNoAsync<PregnancyHeartRateModel>(imeiDel, 7);
// var now = DateTime.Now;
// var ago2hrs = now.AddHours(-2);
// var phrRange = phr.Where(i => i.LastUpdate >= ago2hrs)
// .OrderByDescending(i => i.LastUpdate)
// .Select(i => i.LastUpdate)
// .ToList();
// if (phrRange.Count >= 2)
// {
// var duringMins = (phrRange.First() - phrRange.Last()).TotalMinutes;
// //在餐后时间段(8:00~10:00,12:00~14:00,18:00~20:00,22:00~24:00)取中间值。其他时间段取正常起始值
// bool isInTimeRanges = IsNowInTimeRanges();
// //long.TryParse(watchConfig!["EDOC"]!.ToString(), out long edoc);
// var edoc = DateTimeUtil.ToDateTime(watchConfig!["EDOC"]!.ToString());
// int pregnancyWeeks = (DateTime.Now -edoc.AddDays(-280)).Days / 7;
// if (pregnancyWeeks >= 12 && pregnancyWeeks <= 50)
// {
// 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);
var sampleTime = DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString();
// 告警上限阀值
var upperAlarmThreshold = (int)watchConfig["upperAlarmThreshold"]!;
// 告警下限阀值
var lowerAlarmThreshold = (int)watchConfig["lowerAlarmThreshold"]!;
GeneralParam param = new()
{
Filters = new List<QueryFilterCondition>
{
new ()
{
Key=nameof(HisGpsFetalHeartRate.Serialno),
Value=imeiDel,
ValueType=QueryValueTypeEnum.String,
Operator=QueryOperatorEnum.Equal
}
},
OrderBys = new List<OrderByCondition>
{
new() {
IsDesc=true,
Key=nameof(HisGpsFetalHeartRate.CreateTime)
}
}
};
var frh = await _hisFetalHeartApiClient.GetFirstAsync(param, imeiDel.Substring(imeiDel.Length - 2), null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") }).ConfigureAwait(false);
if (frh != null)
{
var fetalHeartRate = frh.HeartRate;
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0);
// 推送到api/v1/open/OpenIot/SetFetalMovementConfig
await _serviceIotApi.SetFetalMovementConfig(imeiDel, fetalMovement, sampleTime, isAbnormal);
// 保存到MySQL数据库
}
}
}
}
#region 定时计算胎动数据触发器 2小时后
await SetIntervalTriggerAsync(key, imeiDel, 60 * 60 * 2);
#endregion
}
// var fetalMovementValue = fetalMovementMapValue * duringMins * 2 / 120;
// // 四舍五入
// var fetalMovement= (int)Math.Round(fetalMovementValue, 0, MidpointRounding.AwayFromZero);
// var sampleTime = DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString();
// // 告警上限阀值
// var upperAlarmThreshold = (int)watchConfig["upperAlarmThreshold"]!;
// // 告警下限阀值
// var lowerAlarmThreshold = (int)watchConfig["lowerAlarmThreshold"]!;
// GeneralParam param = new()
// {
// Filters = new List<QueryFilterCondition>
// {
// new ()
// {
// Key=nameof(HisGpsFetalHeartRate.Serialno),
// Value=imeiDel,
// ValueType=QueryValueTypeEnum.String,
// Operator=QueryOperatorEnum.Equal
// }
// },
// OrderBys = new List<OrderByCondition>
// {
// new() {
// IsDesc=true,
// Key=nameof(HisGpsFetalHeartRate.CreateTime)
// }
// }
// };
// var frh = await _hisFetalHeartApiClient.GetFirstAsync(param, imeiDel.Substring(imeiDel.Length - 2), null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") }).ConfigureAwait(false);
// if (frh != null)
// {
// var fetalHeartRate = frh.HeartRate;
// var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0);
// // 推送到api/v1/open/OpenIot/SetFetalMovementConfig
// await _serviceIotApi.SetFetalMovementConfig(imeiDel, fetalMovement, sampleTime, isAbnormal);
// // 保存到MySQL数据库
// }
// }
// }
// }
// #region 定时计算胎动数据触发器 2小时后
// await SetIntervalTriggerAsync(key, imeiDel, 60 * 60 * 2);
// #endregion
//}


}


Yükleniyor…
İptal
Kaydet