AIMS/AIMSEntity/Extensions/MonitorData.cs
2023-08-21 08:28:12 +08:00

174 lines
5.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace AIMSEntity
{
/// <summary>
/// 监控数据
/// </summary>
public class MonitorData //: BaseAuditableEntity
{
public int DeviceId { get; set; }
// public CollectDevice Device { get; set; } = null!;
public int CollectDataId { get; set; }
/// <summary>
/// 心率
/// </summary>
[Display(Name = "心率")]
[Range(20.00, 180.00)]
public decimal HR { get; set; }
/// <summary>
/// 氧饱和度
/// </summary>
[Display(Name = "氧饱和度")]
[Range(70.00, 100.00)]
public decimal SPO2 { get; set; }
/// <summary>
/// 自主呼吸
/// </summary>
[Display(Name = "自主呼吸")]
[Range(3.00, 50.00)]
public decimal Resp { get; set; }
/// <summary>
/// 体温
/// </summary>
[Display(Name = "体温")]
[Range(30.00, 45.00)]
public decimal Temp { get; set; }
/// <summary>
/// 无创收缩压
/// </summary>
[Display(Name = "无创收缩压")]
[Range(20.00, 238.00)]
public decimal Sys { get; set; }
/// <summary>
/// 无创舒张压
/// </summary>
[Display(Name = "无创舒张压")]
[Range(20.00, 230.00)]
public decimal Dia { get; set; }
/// <summary>
/// 有创收缩压
/// </summary>
[Display(Name = "有创收缩压")]
[Range(30.00, 160.00)]
public decimal Sys_H { get; set; }
/// <summary>
/// 有创舒张压
/// </summary>
[Display(Name = "有创舒张压")]
[Range(20.00, 230.00)]
public decimal Dia_H { get; set; }
/// <summary>
/// 动脉压
/// </summary>
[Display(Name = "动脉压")]
[Range(10.00, 80.00)]
public decimal MAP { get; set; }
/// <summary>
/// 脉率
/// </summary>
[Display(Name = "脉率")]
[Range(20.00, 238.00)]
public decimal PR { get; set; }
/// <summary>
/// 呼末二氧化碳
/// </summary>
[Display(Name = "呼末二氧化碳")]
[Range(20.00, 230.00)]
public decimal EtCO2 { get; set; }
/// <summary>
/// 无创血压
/// </summary>
[Display(Name = "无创血压")]
public string IBP => (Sys == default || Dia == default) ? null : $"{Sys}/{Dia}";
/// <summary>
/// 有创血压
/// </summary>
[Display(Name = "有创血压")]
public string NBP => (Sys_H == default || Dia_H == default) ? null : $"{Sys_H}/{Dia_H}";
/// <summary>
/// 备用数据
/// </summary>
[Column(TypeName = "jsonb")]
public Dictionary<string, MonitorDataHistory> FallbackData { get; set; } = new Dictionary<string, MonitorDataHistory>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// 扩展数据
/// </summary>
[Column(TypeName = "jsonb")]
public Dictionary<string, object> ExtensionData { get; set; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
public DateTime CollectTime { get; set; }
public void Combine(MonitorData recent)
{
this.FallbackData = new Dictionary<string, MonitorDataHistory>(StringComparer.OrdinalIgnoreCase);
recent.FallbackData = new Dictionary<string, MonitorDataHistory>(StringComparer.OrdinalIgnoreCase);
var prperties = typeof(MonitorData).GetProperties();
foreach (var property in prperties)
{
var display = property.GetCustomAttribute<DisplayAttribute>();
if (display == null)
{
continue;
}
var value = property.GetValue(this);
if (value is decimal v && v == 0)
{
var oldV = property.GetValue(recent);
if (oldV is decimal old && old != 0)
{
var history = new MonitorDataHistory(recent.DeviceId, property.Name, old, recent.CollectTime);
FallbackData[property.Name] = history;
}
else if (recent.FallbackData.TryGetValue(property.Name, out var history))
{
FallbackData[property.Name] = history;
}
}
}
}
}
public class MonitorDataHistory
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Value { get; set; }
public DateTime CollectTime { get; set; }
public MonitorDataHistory(int id, string name, decimal value, DateTime collectTime)
{
Id = id;
Name = name;
Value = value;
CollectTime = collectTime;
}
}
}