Skip to content

Commit

Permalink
Better search capability on searching in private tags
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Dec 28, 2023
1 parent c4e6b71 commit 065382e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
31 changes: 17 additions & 14 deletions DicomGrep/Models/SearchCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

/// <summary>
/// Only Group & Element, not considering the private creator
/// </summary>
private string _searchTagFlattened;
private DicomTag _dicomSearchTag;
[JsonIgnore]
public string SearchTagFlattened => _searchTagFlattened;
public DicomTag DicomSearchTag => _dicomSearchTag;

public string FileTypes { get; set; }

Expand Down Expand Up @@ -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);
}
}
}
9 changes: 7 additions & 2 deletions DicomGrep/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ private IList<ResultDicomItem> 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 ||
Expand Down Expand Up @@ -278,6 +278,11 @@ private IList<ResultDicomItem> 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))
Expand Down

0 comments on commit 065382e

Please sign in to comment.