Searching for numbers in DICOM text tags

Some DICOM tags store a numerical value along with some textual information.   This makes it difficult to search for a specific value using mathematical operators.

For e.g. the age tag [00101010] in my DICOM images store the patient age together with a prefix (0) and a suffix (Y) i.e.

If we want to search for images where the patient age is between 50 and 60, we would need to write our search query like this:

age IN (‘050Y’, ‘051Y’, ‘052Y’, ‘053Y’, ‘054Y’, ‘055Y’, ‘056Y’, ‘057Y’, ‘058Y’, ‘059Y’, ‘060Y’)

which is very tedious and error-prone.  In DICOM Search 1.2, we added the EXTRACTNUMBER and EXTRACTNUMBERDEF functions to deal with this issue.

EXTRACTNUMBER will extract the first sequence of digits from the tag value and return the number.  If there is no valid digits, the value 0 is returned.  We can then rewrite our search query this way:

EXTRACTNUMBER(age) >= 50 AND EXTRACTNUMBER(age) <= 60

or

EXTRACTNUMBER(age) > 49 AND EXTRACTNUMBER(age) < 61

or

EXTRACTNUMBER(age) IN (50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60)

The EXTRACTNUMBERDEF function accepts a 2nd parameter as the default value to use when no digits exist in the value.  If our search query was written this way:

EXTRACTNUMBERDEF(age, -1) = -1

then any images where the age tag value does not contain numbers will return the value -1, and we can then easily see which of our images does not contain a valid age value.

Leave a Reply

Your email address will not be published. Required fields are marked *