Class XMLRepresentationOfStructuredReportObjectFactory


  • public class XMLRepresentationOfStructuredReportObjectFactory
    extends java.lang.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) {
        slf4jlogger.error("",e);
     }
     

    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) {
        slf4jlogger.error("",e);
     }
     

    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) {
        slf4jlogger.error("",e);
     }
     
    See Also:
    StructuredReport, XMLRepresentationOfDicomObjectFactory, XPathQuery, Document
    • Field Detail

      • contentItemIdentiferPrefix

        protected static java.lang.String contentItemIdentiferPrefix
    • Constructor Detail

      • XMLRepresentationOfStructuredReportObjectFactory

        public XMLRepresentationOfStructuredReportObjectFactory()
                                                         throws javax.xml.parsers.ParserConfigurationException

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

        Throws:
        javax.xml.parsers.ParserConfigurationException
    • Method Detail

      • getDocument

        public org.w3c.dom.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 org.w3c.dom.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 org.w3c.dom.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 java.lang.String getNamedNodeAttributeOrNull​(org.w3c.dom.NamedNodeMap attributes,
                                                                   java.lang.String name)
      • getNamedChildElement

        public static org.w3c.dom.Node getNamedChildElement​(org.w3c.dom.Node parent,
                                                            java.lang.String name)
      • getTextValueOfNamedChildElementOrNull

        public static java.lang.String getTextValueOfNamedChildElementOrNull​(org.w3c.dom.Node parent,
                                                                             java.lang.String name)
      • getStructuredReport

        public StructuredReport getStructuredReport​(org.w3c.dom.Document document)
                                             throws DicomException,
                                                    javax.xml.parsers.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
        javax.xml.parsers.ParserConfigurationException
      • getAttributeList

        public AttributeList getAttributeList​(org.w3c.dom.Document document)
                                       throws DicomException,
                                              javax.xml.parsers.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
        javax.xml.parsers.ParserConfigurationException
      • getAttributeList

        public AttributeList getAttributeList​(java.io.InputStream stream)
                                       throws java.io.IOException,
                                              org.xml.sax.SAXException,
                                              javax.xml.parsers.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:
        java.io.IOException
        org.xml.sax.SAXException
        javax.xml.parsers.ParserConfigurationException
        DicomException
      • getAttributeList

        public AttributeList getAttributeList​(java.lang.String name)
                                       throws java.io.IOException,
                                              org.xml.sax.SAXException,
                                              javax.xml.parsers.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:
        java.io.IOException
        org.xml.sax.SAXException
        javax.xml.parsers.ParserConfigurationException
        DicomException
      • toString

        public static java.lang.String toString​(org.w3c.dom.Node documentNode,
                                                int indent)
        Parameters:
        documentNode -
        indent -
      • toString

        public static java.lang.String toString​(org.w3c.dom.Node documentNode)
        Parameters:
        documentNode -
      • write

        public static void write​(java.io.OutputStream out,
                                 org.w3c.dom.Document document)
                          throws java.io.IOException,
                                 javax.xml.transform.TransformerConfigurationException,
                                 javax.xml.transform.TransformerException

        Serialize an XML document (DOM tree).

        Parameters:
        out - the output stream to write to
        document - the XML document
        Throws:
        java.io.IOException
        javax.xml.transform.TransformerConfigurationException
        javax.xml.transform.TransformerException
      • createDocumentAndWriteIt

        public static void createDocumentAndWriteIt​(AttributeList list,
                                                    java.io.OutputStream out)
                                             throws java.io.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:
        java.io.IOException
        DicomException
      • createDocumentAndWriteIt

        public static void createDocumentAndWriteIt​(StructuredReport sr,
                                                    java.io.OutputStream out)
                                             throws java.io.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:
        java.io.IOException
        DicomException
      • createDocumentAndWriteIt

        public static void createDocumentAndWriteIt​(StructuredReport sr,
                                                    AttributeList list,
                                                    java.io.OutputStream out)
                                             throws java.io.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:
        java.io.IOException
        DicomException
      • main

        public static void main​(java.lang.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