{"id":1084,"date":"2020-12-07T22:10:48","date_gmt":"2020-12-07T14:10:48","guid":{"rendered":"https:\/\/www.yohz.com\/blogs\/?p=1084"},"modified":"2020-12-16T09:58:31","modified_gmt":"2020-12-16T01:58:31","slug":"searching-for-numbers-in-dicom-text-tags","status":"publish","type":"post","link":"https:\/\/www.yohz.com\/blogs\/2020\/12\/07\/searching-for-numbers-in-dicom-text-tags\/","title":{"rendered":"Searching for numbers in DICOM text tags"},"content":{"rendered":"<p>Some DICOM tags store a numerical value along with some textual information.\u00a0 \u00a0This makes it difficult to search for a specific value using mathematical operators.<\/p>\n<p>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.<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1086\" src=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/12\/dicomnumber02.png\" alt=\"\" width=\"1015\" height=\"402\" srcset=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/12\/dicomnumber02.png 1015w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/12\/dicomnumber02-300x119.png 300w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/12\/dicomnumber02-768x304.png 768w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/12\/dicomnumber02-624x247.png 624w\" sizes=\"(max-width: 1015px) 100vw, 1015px\" \/><\/p>\n<p>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:<\/p>\n<p>age IN (&#8216;050Y&#8217;, &#8216;051Y&#8217;, &#8216;052Y&#8217;, &#8216;053Y&#8217;, &#8216;054Y&#8217;, &#8216;055Y&#8217;, &#8216;056Y&#8217;, &#8216;057Y&#8217;, &#8216;058Y&#8217;, &#8216;059Y&#8217;, &#8216;060Y&#8217;)<\/p>\n<p>which is very tedious and error-prone.\u00a0 In <a href=\"https:\/\/www.dicomsearch.com\">DICOM Search<\/a> 1.2, we added the <strong>EXTRACTNUMBER<\/strong> and <strong>EXTRACTNUMBERDEF<\/strong> functions to deal with this issue.<\/p>\n<p><strong>EXTRACTNUMBER<\/strong> will extract the first sequence of digits from the tag value and return the number.\u00a0 If there is no valid digits, the value 0 is returned.\u00a0 We can then rewrite our search query this way:<\/p>\n<p>EXTRACTNUMBER(age) &gt;= 50 AND EXTRACTNUMBER(age) &lt;= 60<\/p>\n<p>or<\/p>\n<p>EXTRACTNUMBER(age) &gt; 49 AND EXTRACTNUMBER(age) &lt; 61<\/p>\n<p>or<\/p>\n<p>EXTRACTNUMBER(age) IN (50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60)<\/p>\n<p>The <strong>EXTRACTNUMBERDEF<\/strong> function accepts a 2nd parameter as the default value to use when no digits exist in the value.\u00a0 If our search query was written this way:<\/p>\n<p>EXTRACTNUMBERDEF(age, -1) = -1<\/p>\n<p>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.<\/p>\n<div class=\"fcbkbttn_buttons_block\" id=\"fcbkbttn_left\"><div class=\"fcbkbttn_like \"><fb:like href=\"https:\/\/www.yohz.com\/blogs\/2020\/12\/07\/searching-for-numbers-in-dicom-text-tags\/\" action=\"like\" colorscheme=\"light\" layout=\"button\"  size=\"small\"><\/fb:like><\/div><div class=\"fb-share-button  \" data-href=\"https:\/\/www.yohz.com\/blogs\/2020\/12\/07\/searching-for-numbers-in-dicom-text-tags\/\" data-type=\"button\" data-size=\"small\"><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Some DICOM tags store a numerical value along with some textual information.\u00a0 \u00a0This 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[126],"tags":[129],"_links":{"self":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/1084"}],"collection":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/comments?post=1084"}],"version-history":[{"count":2,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/1084\/revisions"}],"predecessor-version":[{"id":1116,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/1084\/revisions\/1116"}],"wp:attachment":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/media?parent=1084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/categories?post=1084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/tags?post=1084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}