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 { /// /// 监控数据 /// public class MonitorData //: BaseAuditableEntity { public int DeviceId { get; set; } // public CollectDevice Device { get; set; } = null!; public int CollectDataId { get; set; } /// /// 心率 /// [Display(Name = "心率")] [Range(20.00, 180.00)] public decimal HR { get; set; } /// /// 氧饱和度 /// [Display(Name = "氧饱和度")] [Range(70.00, 100.00)] public decimal SPO2 { get; set; } /// /// 自主呼吸 /// [Display(Name = "自主呼吸")] [Range(3.00, 50.00)] public decimal Resp { get; set; } /// /// 体温 /// [Display(Name = "体温")] [Range(30.00, 45.00)] public decimal Temp { get; set; } /// /// 无创收缩压 /// [Display(Name = "无创收缩压")] [Range(20.00, 238.00)] public decimal Sys { get; set; } /// /// 无创舒张压 /// [Display(Name = "无创舒张压")] [Range(20.00, 230.00)] public decimal Dia { get; set; } /// /// 有创收缩压 /// [Display(Name = "有创收缩压")] [Range(30.00, 160.00)] public decimal Sys_H { get; set; } /// /// 有创舒张压 /// [Display(Name = "有创舒张压")] [Range(20.00, 230.00)] public decimal Dia_H { get; set; } /// /// 动脉压 /// [Display(Name = "动脉压")] [Range(10.00, 80.00)] public decimal MAP { get; set; } /// /// 脉率 /// [Display(Name = "脉率")] [Range(20.00, 238.00)] public decimal PR { get; set; } /// /// 呼末二氧化碳 /// [Display(Name = "呼末二氧化碳")] [Range(20.00, 230.00)] public decimal EtCO2 { get; set; } /// /// 无创血压 /// [Display(Name = "无创血压")] public string IBP => (Sys == default || Dia == default) ? null : $"{Sys}/{Dia}"; /// /// 有创血压 /// [Display(Name = "有创血压")] public string NBP => (Sys_H == default || Dia_H == default) ? null : $"{Sys_H}/{Dia_H}"; /// /// 备用数据 /// [Column(TypeName = "jsonb")] public Dictionary FallbackData { get; set; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// /// 扩展数据 /// [Column(TypeName = "jsonb")] public Dictionary ExtensionData { get; set; } = new Dictionary(StringComparer.OrdinalIgnoreCase); public DateTime CollectTime { get; set; } public void Combine(MonitorData recent) { this.FallbackData = new Dictionary(StringComparer.OrdinalIgnoreCase); recent.FallbackData = new Dictionary(StringComparer.OrdinalIgnoreCase); var prperties = typeof(MonitorData).GetProperties(); foreach (var property in prperties) { var display = property.GetCustomAttribute(); 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; } } }