diff --git a/DicomGrep/Models/SearchCriteria.cs b/DicomGrep/Models/SearchCriteria.cs index 9183ae6..5e5e7a2 100644 --- a/DicomGrep/Models/SearchCriteria.cs +++ b/DicomGrep/Models/SearchCriteria.cs @@ -19,24 +19,20 @@ public string SearchTag set { _searchTag = value; - _searchTagFlattened = value?.Substring(0, value.IndexOf(':') > 0 ? value.IndexOf(':') : value.Length) - .Replace("(", "") - .Replace(")", "") - .Replace(",", "") - .Replace(".", "") - .Replace(" ", "") - .Replace("x", "0") //private tag - .Replace("X", "0") //private tag - .ToUpper(); + try + { + _dicomSearchTag = ParseDicomTag(value); + } + catch + { + // unable to parse the string + } } } - /// - /// Only Group & Element, not considering the private creator - /// - private string _searchTagFlattened; + private DicomTag _dicomSearchTag; [JsonIgnore] - public string SearchTagFlattened => _searchTagFlattened; + public DicomTag DicomSearchTag => _dicomSearchTag; public string FileTypes { get; set; } @@ -65,5 +61,12 @@ public override string ToString() $"SearchInResults = {SearchInResults}, " + $"SearchThreads = {SearchThreads}"; } + + private DicomTag ParseDicomTag(string value) + { + // escape the "xx" in private tag string. No worries, it will apply the 0xFF mask again during the search. + value = value.Replace(",xx", ",00").Replace(",XX", ",00").Replace(",Xx", ",00").Replace(",xX", ",00"); + return DicomTag.Parse(value); + } } } diff --git a/DicomGrep/Services/SearchService.cs b/DicomGrep/Services/SearchService.cs index 0d8eca1..e743493 100644 --- a/DicomGrep/Services/SearchService.cs +++ b/DicomGrep/Services/SearchService.cs @@ -213,8 +213,8 @@ private IList CompareDicomTagAndValue(DicomDataset dataset, ref else { // check the tag first - if ( string.IsNullOrEmpty(criteria.SearchTagFlattened) || - dicomItem.Tag.ToString("J",null) == criteria.SearchTagFlattened) // both of the string are in UPPER case + if ( string.IsNullOrWhiteSpace(criteria.SearchTag) || + CompareDicomTag(dicomItem.Tag, criteria.DicomSearchTag)) { // skip binary VRs if (dicomItem.ValueRepresentation == DicomVR.OB || @@ -278,6 +278,11 @@ private IList CompareDicomTagAndValue(DicomDataset dataset, ref return resultDicomItems; } + private bool CompareDicomTag(DicomTag dicomTag, DicomTag criteriaDicomTag) + { + return criteriaDicomTag.Equals(dicomTag); + } + private bool CompareString(string refString, SearchCriteria criteria, bool isDicomTag) { if (string.IsNullOrEmpty(refString))