com.pixelmed.dicom
Class XMLRepresentationOfStructuredReportObjectFactory

java.lang.Object
  extended by com.pixelmed.dicom.XMLRepresentationOfStructuredReportObjectFactory

public class XMLRepresentationOfStructuredReportObjectFactory
extends Object

A class to encode a representation of a DICOM Structured Report object in an XML form, suitable for analysis as human-readable text, or for feeding into an XSLT-based validator.

Note that XML representations can either contain only the content tree, or also the additional top level DICOM attributes other than those that encode the content tree, as individual DICOM attributes, in the manner of XMLRepresentationOfDicomObjectFactory.

A typical example of usage to extract just the content tree would be:

try {
    AttributeList list = new AttributeList();
    list.read("dicomsrfile",null,true,true);
        StructuredReport sr = new StructuredReport(list);
    Document document = new XMLRepresentationOfStructuredReportObjectFactory().getDocument(sr);
    XMLRepresentationOfStructuredReportObjectFactory.write(System.out,document);
} catch (Exception e) {
    e.printStackTrace(System.err);
 }
 

or to include the top level attributes as well as the content tree, supply the attribute list as well as the parsed SR content to the write() method:

try {
    AttributeList list = new AttributeList();
    list.read("dicomsrfile",null,true,true);
        StructuredReport sr = new StructuredReport(list);
    Document document = new XMLRepresentationOfStructuredReportObjectFactory().getDocument(sr,list);
    XMLRepresentationOfStructuredReportObjectFactory.write(System.out,document);
} catch (Exception e) {
    e.printStackTrace(System.err);
 }
 

or even simpler, if there is no further use for the XML document or the SR tree model:

try {
    AttributeList list = new AttributeList();
    list.read("dicomsrfile",null,true,true);
    XMLRepresentationOfStructuredReportObjectFactory.createDocumentAndWriteIt(list,System.out);
} catch (Exception e) {
    e.printStackTrace(System.err);
 }
 

See Also:
StructuredReport, XMLRepresentationOfDicomObjectFactory, XPathQuery, Document

Field Summary
protected  ContentItemFactory contentItemFactory
           
protected static String contentItemIdentiferPrefix
           
 
Constructor Summary
XMLRepresentationOfStructuredReportObjectFactory()
          Construct a factory object, which can be used to get XML documents from DICOM objects.
 
Method Summary
static void createDocumentAndWriteIt(AttributeList list, OutputStream out)
          Serialize an XML document (DOM tree) created from a DICOM Structured Report.
static void createDocumentAndWriteIt(StructuredReport sr, AttributeList list, OutputStream out)
          Serialize an XML document (DOM tree) created from a DICOM Structured Report.
static void createDocumentAndWriteIt(StructuredReport sr, OutputStream out)
          Serialize an XML document (DOM tree) created from a DICOM Structured Report.
 AttributeList getAttributeList(Document document)
          Given a DICOM SR object encoded as an XML document convert it to a list of attributes.
 AttributeList getAttributeList(InputStream stream)
          Given a DICOM SR object encoded as an XML document in a stream convert it to a list of attributes.
 AttributeList getAttributeList(String name)
          Given a DICOM SR object encoded as an XML document in a named file convert it to a list of attributes.
protected  CodedSequenceItem getCodedSequenceItem(Node node)
           
 Document getDocument(AttributeList list)
          Given a DICOM attribute list encoding a Structured Report, get an XML document as a DOM tree.
 Document getDocument(StructuredReport sr)
          Given a DICOM Structured Report, get an XML document of the content tree only as a DOM tree.
 Document getDocument(StructuredReport sr, AttributeList list)
          Given a DICOM Structured Report, get an XML document of the content tree and the top level DICOM elements as a DOM tree.
static Node getNamedChildElement(Node parent, String name)
           
static String getNamedNodeAttributeOrNull(NamedNodeMap attributes, String name)
           
protected  ContentItem getNextContentItemFromXMLNodeSiblings(Node node)
           
 StructuredReport getStructuredReport(Document document)
          Given a DICOM SR object encoded as an XML document convert it to a StructuredReport using the content tree and ignoring any header attributes.
static String getTextValueOfNamedChildElementOrNull(Node parent, String name)
           
static void main(String[] arg)
          Read a DICOM dataset (that contains a structured report) and write an XML representation of it to the standard output, or vice versa.
static String toString(Node documentNode)
           
static String toString(Node documentNode, int indent)
           
static void write(OutputStream out, Document document)
          Serialize an XML document (DOM tree).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contentItemIdentiferPrefix

protected static String contentItemIdentiferPrefix

contentItemFactory

protected ContentItemFactory contentItemFactory
Constructor Detail

XMLRepresentationOfStructuredReportObjectFactory

public XMLRepresentationOfStructuredReportObjectFactory()
                                                 throws ParserConfigurationException

Construct a factory object, which can be used to get XML documents from DICOM objects.

Throws:
ParserConfigurationException
Method Detail

getDocument

public Document getDocument(AttributeList list)

Given a DICOM attribute list encoding a Structured Report, get an XML document as a DOM tree.

Parameters:
list - the attribute list

getDocument

public Document getDocument(StructuredReport sr)

Given a DICOM Structured Report, get an XML document of the content tree only as a DOM tree.

Parameters:
sr - the Structured Report

getDocument

public Document getDocument(StructuredReport sr,
                            AttributeList list)

Given a DICOM Structured Report, get an XML document of the content tree and the top level DICOM elements as a DOM tree.

Parameters:
sr - the Structured Report may be null if list is not - will build an sr tree model
list - the attribute list may be null if only the sr content tree is to be added

getNamedNodeAttributeOrNull

public static String getNamedNodeAttributeOrNull(NamedNodeMap attributes,
                                                 String name)

getNamedChildElement

public static Node getNamedChildElement(Node parent,
                                        String name)

getTextValueOfNamedChildElementOrNull

public static String getTextValueOfNamedChildElementOrNull(Node parent,
                                                           String name)

getCodedSequenceItem

protected CodedSequenceItem getCodedSequenceItem(Node node)
                                          throws DicomException
Throws:
DicomException

getNextContentItemFromXMLNodeSiblings

protected ContentItem getNextContentItemFromXMLNodeSiblings(Node node)
                                                     throws DicomException
Throws:
DicomException

getStructuredReport

public StructuredReport getStructuredReport(Document document)
                                     throws DicomException,
                                            ParserConfigurationException

Given a DICOM SR object encoded as an XML document convert it to a StructuredReport using the content tree and ignoring any header attributes.

Parameters:
document - the XML document
Returns:
the StructuredReport
Throws:
DicomException
ParserConfigurationException

getAttributeList

public AttributeList getAttributeList(Document document)
                               throws DicomException,
                                      ParserConfigurationException

Given a DICOM SR object encoded as an XML document convert it to a list of attributes.

Parameters:
document - the XML document
Returns:
the list of DICOM attributes
Throws:
DicomException
ParserConfigurationException

getAttributeList

public AttributeList getAttributeList(InputStream stream)
                               throws IOException,
                                      SAXException,
                                      ParserConfigurationException,
                                      DicomException

Given a DICOM SR object encoded as an XML document in a stream convert it to a list of attributes.

Parameters:
stream - the input stream containing the XML document
Returns:
the list of DICOM attributes
Throws:
IOException
SAXException
ParserConfigurationException
DicomException

getAttributeList

public AttributeList getAttributeList(String name)
                               throws IOException,
                                      SAXException,
                                      ParserConfigurationException,
                                      DicomException

Given a DICOM SR object encoded as an XML document in a named file convert it to a list of attributes.

Parameters:
name - the input file containing the XML document
Returns:
the list of DICOM attributes
Throws:
IOException
SAXException
ParserConfigurationException
DicomException

toString

public static String toString(Node documentNode,
                              int indent)
Parameters:
documentNode -
indent -

toString

public static String toString(Node documentNode)
Parameters:
documentNode -

write

public static void write(OutputStream out,
                         Document document)
                  throws IOException,
                         TransformerConfigurationException,
                         TransformerException

Serialize an XML document (DOM tree).

Parameters:
out - the output stream to write to
document - the XML document
Throws:
IOException
TransformerConfigurationException
TransformerException

createDocumentAndWriteIt

public static void createDocumentAndWriteIt(AttributeList list,
                                            OutputStream out)
                                     throws IOException,
                                            DicomException

Serialize an XML document (DOM tree) created from a DICOM Structured Report.

Parameters:
list - the attribute list
out - the output stream to write to
Throws:
IOException
DicomException

createDocumentAndWriteIt

public static void createDocumentAndWriteIt(StructuredReport sr,
                                            OutputStream out)
                                     throws IOException,
                                            DicomException

Serialize an XML document (DOM tree) created from a DICOM Structured Report.

Parameters:
sr - the Structured Report
out - the output stream to write to
Throws:
IOException
DicomException

createDocumentAndWriteIt

public static void createDocumentAndWriteIt(StructuredReport sr,
                                            AttributeList list,
                                            OutputStream out)
                                     throws IOException,
                                            DicomException

Serialize an XML document (DOM tree) created from a DICOM Structured Report.

Parameters:
sr - the Structured Report may be null if list is not - will build an sr tree model
list - the attribute list may be null if only the sr content tree is to be written
out - the output stream to write to
Throws:
IOException
DicomException

main

public static void main(String[] arg)

Read a DICOM dataset (that contains a structured report) and write an XML representation of it to the standard output, or vice versa.

Parameters:
arg - either one filename of the file containing the DICOM dataset, or a direction argument (toDICOM or toXML, case insensitive) and an input filename