using System.Collections.Generic; using System.Linq; namespace fis.Vid { /// /// Carotid scan direction /// public enum CarotidDirection { TopToBottom, BottomToTop } public enum CarotidType { Left, Right } public class VinnoCarotidExtendedData { private const string CarotidGroup = "Carotid"; private const string ScanDistanceElement = "ScanDistance"; private const string ScanTypeElement = "ScanType"; private const string ScanDirectionElement = "ScanDirection"; private readonly VidExtendedData _extendedData; /// /// Get CarotidType. /// public CarotidType CarotidType { get; } /// /// Get CarotidDirection /// public CarotidDirection CarotidDirection { get; } /// /// Get ScanDistance. /// public float ScanDistance { get; } public VinnoCarotidExtendedData(float scanDistance, CarotidType carotidType,CarotidDirection carotidDirection) { ScanDistance = scanDistance; CarotidType = carotidType; CarotidDirection = carotidDirection; var dic = new Dictionary { {new VidTag(CarotidGroup, ScanDistanceElement), new VidFloatValueElement(scanDistance)}, {new VidTag(CarotidGroup, ScanTypeElement), new VidIntegerValueElement((int)carotidType)}, {new VidTag(CarotidGroup, ScanDirectionElement), new VidIntegerValueElement((int)carotidDirection)} }; _extendedData = new VidExtendedData(dic); } /// /// Object to bytes. /// /// public byte[] ToBytes() { return _extendedData.ToBytes(); } public static bool IsCarotid(byte[] bytes) { if (bytes != null) { var extendedData = VidExtendedData.FromBytes(bytes); if (extendedData != null) { var vidTags = extendedData.Data.Keys.Where(k => k.Group == CarotidGroup).ToList(); if (vidTags.Count > 2) { return true; } } } return false; } /// /// Convert from bytes. /// /// bytes. /// Instance of vinno carotid extended data. public static VinnoCarotidExtendedData FromBytes(byte[] bytes) { var extendedData = VidExtendedData.FromBytes(bytes); if (extendedData != null) { var vidTags = extendedData.Data.Keys.Where(k => k.Group == CarotidGroup).ToList(); if (vidTags.Count > 2) { var scanDistanceTag = vidTags.FirstOrDefault(t => t.Element.Equals(ScanDistanceElement)); var carotidTypeTag = vidTags.FirstOrDefault(t => t.Element.Equals(ScanTypeElement)); var carotidDirectionTag = vidTags.FirstOrDefault(t => t.Element.Equals(ScanDirectionElement)); if (scanDistanceTag == null || carotidTypeTag == null || carotidDirectionTag==null) { return null; } var scanDistance =extendedData.Data[scanDistanceTag]; var carotidType = extendedData.Data[carotidTypeTag]; var carotidDirection = extendedData.Data[carotidDirectionTag]; if (scanDistance is VidFloatValueElement distance && carotidType is VidIntegerValueElement scanType && carotidDirection is VidIntegerValueElement direction) { return new VinnoCarotidExtendedData(distance.Value, (CarotidType)scanType.Value,(CarotidDirection)direction.Value); } } } return null; } } }