Parsing and Assigning DICOM Dates in DP2

Data capturing is a very powerful and useful feature of DP2, let me provide you a an example of how to use it.  Because DICOM Printer 2 is based on the Qt framework, it employs the default QRegExp syntax, described on this page.

Let’s assume that you use DP2 to send reports to PACS and you want the application to capture study date from it, so that you wouldn’t have to edit study details in PACS every time. Since DICOM Printer 2 extracts text content from every print job and makes it available to ParseJobTextFile action, this is fairly simple feature to implement.

First you need to examine text file contents. You can do that by stopping DICOMPrinterService prior to printing. The files will become available in the queue, accessible through Start -> DP2 -> Links -> Open Queue Folder. When you open the TXT file in the queue you might find line like this:

Report Date: 15-11-12

Which tells us that the report was printed today. There is a problem with this date, though, it is not a valid DICOM date for a number of reasons:

  • it uses a reversed, day-month-year notation,
  • the year is expressed in short, two-decimal form,
  • separators are unnecessary.

A valid DICOM representation of this date would look like this:

20121115

So how can you make it work? First, let’s create a regular expression matching this line. There are many websites allowing you to create and test regular expressions online: this one is the easiest to use but I prefer another one because it not only shows if the expression is valid, but also displays captured elements. Using any of these, you should be able to create expressions quickly.

In our example here’s the result:

Report\s+Date:\s+(\d{2})-(\d{2})-(\d{2})

The expression matches a line containing the word ‘Report’ followed by a non-zero number of spaces, then the word ‘Date’, a colon, another non-zero number of spaces, two digits (decimal), dash, two digits, dash and, again, two digits. Each pair of digits is enclosed with parentheses, which means that they are captured by this expression.

Note that this expression assumes that the date contains leading zeros when the day or month are less than 10, e.g. 01-01-13 for New Year’s day of 2013.

OK, so we have the expression that matches our line and we capture the required numbers. All that is left to do is to arrange them in the DICOM manner. You can do that by using the replacePattern attribute, available to DcmTag elements of both types of parse actions. In our case we want to replace the order and prepend the year with ’20’. Here’s how the attribute should look:

replacePattern="20\3\2\1"

The slash-number notation is used to back-reference a captured group. The default replace pattern for DcmTag elements is ‘\1’, which means that it simply uses the value from the first group.

Here’s how the entire action would appear:

<ParseJobTextFile name="GetDate">
        <DcmTag tag="(0008,0020)" replacePattern="20\3\2\1">Report\s+Date:\s+(\d{2})-(\d{2})-(\d{2})</DcmTag>
</ParseJobTextFile>

You could also add the ‘mandatory’ flag, if you would like DP2 to stop processing when the date is missing from the report.

As always, remember to call your new action from the Workflow block, like so:

  <!-- Your preceding action definitions -->
  <ParseJobTextFile name="GetDate">
        <DcmTag tag="(0008,0020)" replacePattern="20\3\2\1">Report\s+Date:\s+(\d{2})-(\d{2})-(\d{2})</DcmTag>
  </ParseJobTextFile>
</ActionsList>
<Workflow>
  <Perform action="GetDate" onError="Hold" />
  <!-- Rest of your workflow -->
</Workflow>

Leave a Reply

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