{"id":931,"date":"2020-07-22T14:19:58","date_gmt":"2020-07-22T06:19:58","guid":{"rendered":"https:\/\/www.yohz.com\/blogs\/?p=931"},"modified":"2020-08-16T14:44:09","modified_gmt":"2020-08-16T06:44:09","slug":"dicom-search-querying-the-database-preview-2","status":"publish","type":"post","link":"https:\/\/www.yohz.com\/blogs\/2020\/07\/22\/dicom-search-querying-the-database-preview-2\/","title":{"rendered":"DICOM Search &#8211; querying the database (preview 2)"},"content":{"rendered":"<p>Once DICOM Search has <a href=\"https:\/\/www.yohz.com\/blogs\/?p=922\">indexed the DICOM tags in your images<\/a>, you can run queries against the <strong>tags<\/strong> table.\u00a0 Selecting everything from the <strong>tags<\/strong> table, while possible, isn&#8217;t very useful and is very slow.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-930\" src=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex07.png\" alt=\"\" width=\"829\" height=\"647\" srcset=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex07.png 829w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex07-300x234.png 300w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex07-768x599.png 768w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex07-624x487.png 624w\" sizes=\"(max-width: 829px) 100vw, 829px\" \/><\/p>\n<p>The reason is because there are over 2800 fields, and DICOM Search will struggle to maintain and display that many columns.\u00a0 Thus, it is recommended that you select only the fields you are interested in.<\/p>\n<p>You can quickly see which fields are available in your database by pressing <strong>F2<\/strong> when in the SQL editor to bring up the <strong>Tags and Fields<\/strong> window.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-941\" src=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex15.png\" alt=\"\" width=\"486\" height=\"493\" srcset=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex15.png 486w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex15-296x300.png 296w\" sizes=\"(max-width: 486px) 100vw, 486px\" \/><\/p>\n<p>Clicking on any of the tag values will add that value to the SQL editor area, so you do not need to manually enter the tag name.\u00a0 In addition to the DICOM tags, there are also additional fields that DICOM Search populates in the tags table, as listed in the <strong>Field names<\/strong> tab.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-942\" src=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex16.png\" alt=\"\" width=\"486\" height=\"493\" srcset=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex16.png 486w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex16-296x300.png 296w\" sizes=\"(max-width: 486px) 100vw, 486px\" \/><\/p>\n<p>In addition to your key fields, the other fields are used by DICOM Search to maintain a record of the processed images.\u00a0 For the users, the useful fields are <strong>ds_thumbnail<\/strong> and <strong>ds_filename<\/strong>.\u00a0 <strong>ds_thumbnail<\/strong> stores a thumbnail of the image and <strong>ds_filename<\/strong> stores the location of the image file when exported from your database, or when processed from your folder.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-944\" src=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex17.png\" alt=\"\" width=\"1156\" height=\"551\" srcset=\"https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex17.png 1156w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex17-300x143.png 300w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex17-1024x488.png 1024w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex17-768x366.png 768w, https:\/\/www.yohz.com\/blogs\/wp-content\/uploads\/2020\/07\/dicomex17-624x297.png 624w\" sizes=\"(max-width: 1156px) 100vw, 1156px\" \/><\/p>\n<p>If the listed file name is present on your computer, you can open the image file in your DICOM viewer by double-clicking on the file name in DICOM Search.<\/p>\n<p>Please see this <a href=\"https:\/\/www.yohz.com\/blogs\/?p=922\">post<\/a> on how to index and extract images from your database to your computer using DICOM Search, and also how to add thumbnails to the tags database.<\/p>\n<p>&nbsp;<\/p>\n<h2>SQL syntax<\/h2>\n<p>The tag values are stored in a SQLite database, so you will use the SQLite SQL syntax to query the database.\u00a0 In our example, our key fields are <strong>patientID<\/strong> and <strong>studyID<\/strong>, so we will always select those columns in case we want to query the source database.\u00a0 We also select the <strong>ds_thumbnail<\/strong> and <strong>ds_filename<\/strong> columns to view the image thumbnail, and also have a link to the actual image.<\/p>\n<p>Here are some examples of the types of queries you can run:<\/p>\n<ul>\n<li>searching text values<br \/>\nE.g. the <strong>Patient Name<\/strong> (tag group and element 0010,0010):SELECT patientID, studyID, ds_thumbnail, ds_filename FROM tags WHERE [00100010] = &#8216;Rubo&#8217;<\/li>\n<li>searching for part of a text value<br \/>\nE.g. to return all images where the patient name starts with Rubo:SELECT patientID, studyID, ds_thumbnail, ds_filename FROM tags WHERE [00100010] LIKE &#8216;Rubo%&#8217;E.g. to return all images where the patient name contains the word Rubo:SELECT patientID, studyID, ds_thumbnail, ds_filename FROM tags WHERE [00100010] LIKE &#8216;%Rubo%&#8217;<\/p>\n<p>E.g. to retrieve all images there the patient name ends with Rubo:<\/p>\n<p>SELECT patientID, studyID, ds_thumbnail, ds_filename FROM tags WHERE [00100010] LIKE &#8216;%Rubo&#8217;<\/li>\n<li>searching date values<br \/>\nE.g. the <strong>Study Date<\/strong> tag (tag group and element 0008,0020) for all studies made between Jan 1 1993 and Jan 1 1994:SELECT patientID, studyID, ds_thumbnail, ds_filename, [00080020] FROM tags WHERE <strong>[00080020] &gt;= &#8216;1993-01-01&#8217;<\/strong> AND <strong>[00080020] &lt; &#8216;1994-01-01&#8217;<\/strong>Key point is you need to always enter the value you want to search for using <strong>yyyy-mm-dd<\/strong> format (year-month-date)<\/li>\n<li>searching time values<br \/>\nE.g. the <strong>Study Time<\/strong> tag (tag group and element 0008,0030), for all studies made between 1 PM and 2 PM.SELECT patientID, studyID, ds_thumbnail, ds_filename, [00080030] FROM tags WHERE <strong>[00080030] &gt;= &#8217;13:00&#8242;<\/strong> AND <strong>[00080030] &lt; &#8217;14:00&#8242;<\/strong>Key point is you need to always enter the value you want to search for using <strong>hh:mm:ss<\/strong> format (hour:minutes:seconds).<\/li>\n<li>searching numbers<br \/>\nYou can use all the usual equality and comparison symbols for numbers e.g. =, &gt;, &gt;=, &lt;, &lt;=E.g. the <strong>Intervention Drug Dose<\/strong> tag (tag group and element 0018,0028), where the value is greater than 25SELECT patientID, studyID, ds_thumbnail, ds_filename, [00180028] FROM tags WHERE <strong>[00180028] &gt; 25<\/strong><\/li>\n<\/ul>\n<p>You can combine multiple conditions using the <strong>AND<\/strong> and <strong>OR<\/strong> operators e.g.<\/p>\n<p>SELECT patientID, studyID, ds_thumbnail, ds_filename, [00080030] FROM tags WHERE ([00080020] &gt;= &#8216;1993-01-01&#8217; <strong>AND<\/strong> [00080020] &lt; &#8216;1994-01-01&#8217; <strong>AND<\/strong> [00080030] &gt;= &#8217;13:00&#8242; <strong>AND<\/strong> [00080030] &lt; &#8217;14:00&#8242;) <strong>OR<\/strong> ([00100010] = &#8216;Rubo&#8217;)<\/p>\n<p>To sort the results, use the <strong>ORDER BY<\/strong> option, and specify the field to sort by e.g. to sort the results by patient name (tag group and element<\/p>\n<p>SELECT patientID, studyID, ds_thumbnail, ds_filename, [00080030] FROM tags WHERE ([00080020] &gt;= &#8216;1993-01-01&#8217; AND [00080020] &lt; &#8216;1994-01-01&#8217;) <strong>ORDER BY<\/strong>\u00a0[00100010]\n<p>To sort in descending order, add the <strong>DESC<\/strong> option after the field name e.g.<\/p>\n<p>SELECT patientID, studyID, ds_thumbnail, ds_filename, [00080030] FROM tags WHERE ([00080020] &gt;= &#8216;1993-01-01&#8217; AND [00080020] &lt; &#8216;1994-01-01&#8217;) <strong>ORDER BY<\/strong> [00100010] <strong>DESC<\/strong><\/p>\n<p>To limit the number of rows returned, use the LIMIT option.\u00a0 For e.g. to retrieve the first 30 rows where the <strong>Intervention Drug Dose<\/strong> value is greater than 25, sorted by that field in descending order<\/p>\n<p>SELECT patientID, studyID, ds_thumbnail, ds_filename, [00180028] FROM tags WHERE [00180028] &gt; 25 ORDER BY [00180028] DESC <strong>LIMIT 30<\/strong><\/p>\n<p>See also:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.yohz.com\/blogs\/?p=960\">DICOM Seach walkthrough<\/a><\/li>\n<\/ul>\n<div class=\"fcbkbttn_buttons_block\" id=\"fcbkbttn_left\"><div class=\"fcbkbttn_like \"><fb:like href=\"https:\/\/www.yohz.com\/blogs\/2020\/07\/22\/dicom-search-querying-the-database-preview-2\/\" action=\"like\" colorscheme=\"light\" layout=\"button\"  size=\"small\"><\/fb:like><\/div><div class=\"fb-share-button  \" data-href=\"https:\/\/www.yohz.com\/blogs\/2020\/07\/22\/dicom-search-querying-the-database-preview-2\/\" data-type=\"button\" data-size=\"small\"><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Once DICOM Search has indexed the DICOM tags in your images, you can run queries against the tags table.\u00a0 Selecting everything from the tags table, while possible, isn&#8217;t very useful and is very slow. The reason is because there are over 2800 fields, and DICOM Search will struggle to maintain and display that many columns.\u00a0 [&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":[128,129,130],"_links":{"self":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/931"}],"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=931"}],"version-history":[{"count":5,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/931\/revisions"}],"predecessor-version":[{"id":977,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/posts\/931\/revisions\/977"}],"wp:attachment":[{"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/media?parent=931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/categories?post=931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yohz.com\/blogs\/wp-json\/wp\/v2\/tags?post=931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}