Kaynağa Gözat

完善日志描述

datasub12_fetal_heart_rate_0
H Vs 3 ay önce
ebeveyn
işleme
fefafd711d
5 değiştirilmiş dosya ile 164 ekleme ve 207 silme
  1. +154
    -2
      HealthMonitor.Service/Cache/DeviceCacheManager.cs
  2. +0
    -94
      HealthMonitor.Service/Cache/FetalHeartRateCacheManager.cs
  3. +0
    -98
      HealthMonitor.Service/Cache/FetalMovementCacheManager.cs
  4. +10
    -11
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs
  5. +0
    -2
      HealthMonitor.WebApi/Program.cs

+ 154
- 2
HealthMonitor.Service/Cache/DeviceCacheManager.cs Dosyayı Görüntüle

@@ -2,7 +2,12 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TelpoDataService.Util.Clients;
using TelpoDataService.Util.Entities.GpsCard;
using TelpoDataService.Util.Entities.GpsLocationHistory;
using TelpoDataService.Util.Models;
using TelpoDataService.Util.QueryObjects;
using HealthMonitor.Common;

namespace HealthMonitor.Service.Cache
{
@@ -11,11 +16,22 @@ namespace HealthMonitor.Service.Cache
private readonly ILogger<DeviceCacheManager> _logger;
private const string CACHE_KEY_DEVICE = "Device_";
private const string CACHE_KEY_GPSDEVICE_WATCH_CONFIG = "#GPSDEVICE_WATCH_CONFIG_HASH";
private const string CACHE_KEY_FETALMOVEMENT = "FM_";
private const string CACHE_KEY_FETALHEARTRATE = "FHR_";

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

public DeviceCacheManager(ILogger<DeviceCacheManager> logger)



public DeviceCacheManager(ILogger<DeviceCacheManager> logger
, GpsLocationHistoryAccessorClient<HisGpsFetalMovement> hisFetalMovementApiClient
, GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartRateApiClient)
{
_logger = logger;
_hisFetalMovementApiClient = hisFetalMovementApiClient;
_hisFetalHeartRateApiClient = hisFetalHeartRateApiClient;
}


@@ -55,7 +71,7 @@ namespace HealthMonitor.Service.Cache
}


#region 心率状态
#region 心率相关
/// <summary>
/// 读取高频状态
/// </summary>
@@ -104,6 +120,142 @@ namespace HealthMonitor.Service.Cache
}
}

public async Task SetFetalHeartRateAsync(string serialNo, string sampleTime)
{
try
{
var key = $"{CACHE_KEY_FETALHEARTRATE}_{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, 7200).ConfigureAwait(false);
}
catch (Exception ex)
{

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

public async Task<bool> FetalHeartRateIsExistedAsync(string serialNo, string sampleTime)
{
try
{
var key = $"{CACHE_KEY_FETALHEARTRATE}_{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 _hisFetalHeartRateApiClient.GetFirstAsync(param, serialNo[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") });
if (isFetalMovementExist != null)
{
await SetFetalHeartRateAsync(serialNo, sampleTime);
return true;
}
}
else
{
return true;
}

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

#endregion

#region 胎动相关
public async Task SetFetalMovementAsync(string serialNo, string sampleTime, HisGpsFetalMovement fm)
{
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");

fm.SampleTime = value;

await RedisHelper.SetAsync(key, JsonConvert.SerializeObject(fm), 7200).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(HisGpsFetalMovement.Serialno),
Value=serialNo,
ValueType=QueryValueTypeEnum.String,
Operator=QueryOperatorEnum.Equal
},
new ()
{
Key=nameof(HisGpsFetalMovement.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, isFetalMovementExist);
return true;
}
}
else
{
return true;
}

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

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

@@ -1,94 +0,0 @@
using HealthMonitor.Common;
using Microsoft.Extensions.Logging;
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 FetalHeartRateCacheManager
{
private readonly ILogger<FetalHeartRateCacheManager> _logger;

private readonly GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> _hisFetalHeartRateApiClient;

private const string CACHE_KEY_FETALHEARTRATE = "FHR_";

public FetalHeartRateCacheManager(ILogger<FetalHeartRateCacheManager> logger, GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartRateApiClient)
{
_logger = logger;
_hisFetalHeartRateApiClient = hisFetalHeartRateApiClient;
}

public async Task SetFetalHeartRateAsync(string serialNo, string sampleTime)
{
try
{
var key = $"{CACHE_KEY_FETALHEARTRATE}_{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, 7200).ConfigureAwait(false);
}
catch (Exception ex)
{

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

public async Task<bool> FetalHeartRateIsExistedAsync(string serialNo, string sampleTime)
{
try
{
var key = $"{CACHE_KEY_FETALHEARTRATE}_{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 _hisFetalHeartRateApiClient.GetFirstAsync(param, serialNo[^2..], null, new RequestHeader { RequestId = Guid.NewGuid().ToString("D") });
if (isFetalMovementExist != null)
{
await SetFetalHeartRateAsync(serialNo, sampleTime);
return true;
}
}
else
{
return true;
}

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

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

@@ -1,98 +0,0 @@
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, HisGpsFetalMovement fm)
{
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");

fm.SampleTime = value;

await RedisHelper.SetAsync(key, JsonConvert.SerializeObject(fm), 7200).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(HisGpsFetalMovement.Serialno),
Value=serialNo,
ValueType=QueryValueTypeEnum.String,
Operator=QueryOperatorEnum.Equal
},
new ()
{
Key=nameof(HisGpsFetalMovement.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, isFetalMovementExist);
return true;
}
}
else
{
return true;
}

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

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

@@ -44,15 +44,13 @@ namespace HealthMonitor.Service.Resolver

private readonly FetalMovementNormalValueRangeCacheManager _mgrFetalMovementNormalValueRangeCache;

private readonly FetalMovementCacheManager _mgrFetalMovement;
private readonly FetalHeartRateCacheManager _mgrFetalHeartRateCache;



public PregnancyHeartRateResolver(ILogger<PregnancyHeartRateResolver> logger,
HttpHelper httpHelper, EtcdService serviceEtcd, DeviceCacheManager deviceCacheMgr,
IotApiService iotApiService, TDengineService serviceDengine, FetalMovementNormalValueRangeCacheManager fetalMovementNormalValueRangeCacheMgr,
GpsLocationHistoryAccessorClient<HisGpsFetalHeartRate> hisFetalHeartApiClient,
FetalMovementCacheManager fetalMovementCacheManager, FetalHeartRateCacheManager fetalHeartRateCacheManager,
GpsLocationHistoryAccessorClient<HisGpsFetalMovement> hisFetalMovementApiClient
)
{
@@ -65,8 +63,6 @@ namespace HealthMonitor.Service.Resolver
_hisFetalHeartApiClient = hisFetalHeartApiClient;
_hisFetalMovementApiClient = hisFetalMovementApiClient;
_mgrFetalMovementNormalValueRangeCache = fetalMovementNormalValueRangeCacheMgr;
_mgrFetalMovement = fetalMovementCacheManager;
_mgrFetalHeartRateCache = fetalHeartRateCacheManager;
}

public void SetResolveInfo(PackageMsgModel msg)
@@ -597,9 +593,8 @@ namespace HealthMonitor.Service.Resolver
// 统计结束时间
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);
//_logger.LogInformation($"{heartRate.Serialno} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime}, ");
var isFetalMovementExisted = await _deviceCacheMgr.FetalMovementIsExistedAsync(heartRate.Serialno, fetalMovementSampleTime);
_logger.LogInformation($"{heartRate.Serialno} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 开始");

if (!isFetalMovementExisted)
{
@@ -640,7 +635,7 @@ namespace HealthMonitor.Service.Resolver
var fetalMovement = (int)Math.Round(fetalMovementValue, 0, MidpointRounding.AwayFromZero);
// _logger.LogInformation($"{heartRate.Serialno} segmentCountFMIndex: {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}");
_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;
@@ -666,18 +661,22 @@ namespace HealthMonitor.Service.Resolver
await _hisFetalMovementApiClient.AddAsync(fm).ConfigureAwait(false);

// 设置入库缓存记录
await _mgrFetalMovement.SetFetalMovementAsync(heartRate.Serialno, fetalMovementSampleTime,fm);
await _deviceCacheMgr.SetFetalMovementAsync(heartRate.Serialno, fetalMovementSampleTime,fm);
}
else
{
_logger.LogWarning($"{heartRate.Serialno} 孕周 {pregnancyWeeks},超出胎动计算范围");
}
}
else
{
_logger.LogInformation($"{heartRate.Serialno} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 不足两条,不能判断是否持续佩戴");

}
}
else
{
_logger.LogInformation($"{heartRate.Serialno} 胎动记录{isFetalMovementExisted},数据采样时间:{fetalMovementSampleTime}|{midNight.AddHours(2 * i).ToString("yyyy-MM-dd HH:mm:ss")}, 周期:{statStartTime}-{statEndTime} 已处理");

}

}


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

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


Yükleniyor…
İptal
Kaydet