|
|
@@ -21,6 +21,8 @@ using System.Reflection; |
|
|
|
using System.Threading.Channels; |
|
|
|
using TDengineDriver; |
|
|
|
using TDengineTMQ; |
|
|
|
using TelpoDataService.Util.Clients; |
|
|
|
using TelpoDataService.Util.Entities.GpsLocationHistory; |
|
|
|
|
|
|
|
namespace HealthMonitor.WebApi |
|
|
|
{ |
|
|
@@ -37,10 +39,18 @@ namespace HealthMonitor.WebApi |
|
|
|
private readonly BoodPressResolverConfig _configBoodPressResolver; |
|
|
|
private readonly BloodPressReferenceValueCacheManager _bpRefValCacheManager; |
|
|
|
private readonly PersonCacheManager _personCacheMgr; |
|
|
|
private readonly DeviceCacheManager _deviceCacheMgr; |
|
|
|
|
|
|
|
private readonly GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> _hisFetalHeartApiClient; |
|
|
|
|
|
|
|
private CancellationTokenSource _tokenSource = default!; |
|
|
|
|
|
|
|
public Worker(ILogger<Worker> logger, IServiceProvider services, PersonCacheManager personCacheMgr, BloodPressReferenceValueCacheManager bpRefValCacheManager, IotApiService IotApiService, IOptions<BoodPressResolverConfig> optionBoodPressResolver, PackageProcess processor, TDengineDataSubcribe tdEngineDataSubcribe, TDengineService serviceDengine, HttpHelper httpHelper, EtcdService serviceEtcd) |
|
|
|
public Worker(ILogger<Worker> logger, IServiceProvider services, PersonCacheManager personCacheMgr, |
|
|
|
BloodPressReferenceValueCacheManager bpRefValCacheManager, IotApiService IotApiService, |
|
|
|
IOptions<BoodPressResolverConfig> optionBoodPressResolver, PackageProcess processor, |
|
|
|
TDengineDataSubcribe tdEngineDataSubcribe, TDengineService serviceDengine, |
|
|
|
GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartApiClient, |
|
|
|
HttpHelper httpHelper, EtcdService serviceEtcd, DeviceCacheManager deviceCacheMgr) |
|
|
|
{ |
|
|
|
_logger = logger; |
|
|
|
_tdEngineDataSubcribe = tdEngineDataSubcribe; |
|
|
@@ -53,6 +63,8 @@ namespace HealthMonitor.WebApi |
|
|
|
_configBoodPressResolver = optionBoodPressResolver.Value; |
|
|
|
_bpRefValCacheManager = bpRefValCacheManager; |
|
|
|
_personCacheMgr = personCacheMgr; |
|
|
|
_deviceCacheMgr = deviceCacheMgr; |
|
|
|
_hisFetalHeartApiClient = hisFetalHeartApiClient; |
|
|
|
} |
|
|
|
|
|
|
|
public override Task StartAsync(CancellationToken cancellationToken) |
|
|
@@ -222,6 +234,82 @@ namespace HealthMonitor.WebApi |
|
|
|
await _serviceEtcd.PutValAsync(key, result, ttl, false).ConfigureAwait(false); |
|
|
|
#endif |
|
|
|
#endregion |
|
|
|
} |
|
|
|
// health_monitor/schedule_push/cal_fetal_heart_rate/imei/ |
|
|
|
else if (key.Contains("health_monitor/schedule_push/cal_fetal_heart_rate/imei/")) |
|
|
|
{ |
|
|
|
|
|
|
|
var watchConfig = await _deviceCacheMgr.GetGpsDeviceWatchConfigCacheObjectBySerialNoAsync(imeiDel, "0067"); |
|
|
|
var isFetalHeartEnable = watchConfig != null && (int)watchConfig["enabled"]! == 1; |
|
|
|
|
|
|
|
if (isFetalHeartEnable) |
|
|
|
{ |
|
|
|
// 处理胎心计算业务,计算一般心率获取胎心系数 |
|
|
|
var commonPHR = await _serviceTDengine.InitPregnancyCommonHeartRateModeAsync(imeiDel); |
|
|
|
if (commonPHR != null) |
|
|
|
{ |
|
|
|
# region 计算胎心数据 |
|
|
|
// 告警上限阀值 |
|
|
|
var upperAlarmThreshold = (int)watchConfig!["upperAlarmThreshold"]!; |
|
|
|
// 告警下限阀值 |
|
|
|
var lowerAlarmThreshold = (int)watchConfig["lowerAlarmThreshold"]!; |
|
|
|
|
|
|
|
var lastPhr = await _serviceTDengine.GetLastAsync<PregnancyHeartRateModel>(); |
|
|
|
// 计算胎心=孕妇心率*系数 |
|
|
|
var fetalHeartRate = SafeType.SafeInt(lastPhr.PregnancyHeartRate * commonPHR?.StatModeAvgFprCoefficient!); |
|
|
|
|
|
|
|
var sampleTime = DateTimeUtil.ConvertToTimeStamp(DateTime.Now).ToString(); |
|
|
|
|
|
|
|
var isAbnormal = fetalHeartRate > upperAlarmThreshold ? 1 : (fetalHeartRate < lowerAlarmThreshold ? 2 : 0); |
|
|
|
|
|
|
|
HisGpsFetalHeartRate gpsFetalHeartRate = new() |
|
|
|
{ |
|
|
|
FetalHeartRateId = Guid.NewGuid().ToString("D"), |
|
|
|
PersonId = commonPHR!.PersonId, |
|
|
|
Serialno = imeiDel, |
|
|
|
HeartRate = fetalHeartRate, |
|
|
|
SampleTime = sampleTime, |
|
|
|
IsAbnormal = isAbnormal, |
|
|
|
StatStartTime = commonPHR.StatStartTime, |
|
|
|
StatEndTime = commonPHR.StatEndTime, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Method = 1, |
|
|
|
IsDisplay = 1, |
|
|
|
DeviceKey = commonPHR!.DeviceKey |
|
|
|
}; |
|
|
|
// 保存到 数据服务 MySQL 数据库 |
|
|
|
await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); |
|
|
|
|
|
|
|
// 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig |
|
|
|
await _serviceIotApi.SetFetalHeartRateConfig(imeiDel, fetalHeartRate, sampleTime, isAbnormal); |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region 注册定时计算胎心数据触发器 {interval} 秒后 |
|
|
|
//var fetalKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{imeiDel}"; |
|
|
|
var fetalKey = key; |
|
|
|
var scheduleFetalPush = await _serviceEtcd.GetValAsync(fetalKey).ConfigureAwait(false); |
|
|
|
if (string.IsNullOrWhiteSpace(scheduleFetalPush)) |
|
|
|
{ |
|
|
|
var fetalInterval = (int)watchConfig!["interval"]!; |
|
|
|
|
|
|
|
var fetalNow = DateTime.Now; |
|
|
|
var fetalTimeNextRun = fetalNow.Add(TimeSpan.FromSeconds(fetalInterval)); |
|
|
|
var fetalTTL = fetalInterval; |
|
|
|
var data = new |
|
|
|
{ |
|
|
|
imei = imeiDel, |
|
|
|
create_time = fetalNow.ToString("yyyy-MM-dd HH:mm:ss"), |
|
|
|
fetalTTL, |
|
|
|
next_run_time = fetalTimeNextRun.ToString("yyyy-MM-dd HH:mm:ss") |
|
|
|
}; |
|
|
|
var result = JsonConvert.SerializeObject(data); |
|
|
|
await _serviceEtcd.PutValAsync(fetalKey, result, fetalTTL, false).ConfigureAwait(false); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|