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); }
StructuredReport
,
XMLRepresentationOfDicomObjectFactory
,
XPathQuery
,
Document
Modifier and Type | Field and Description |
---|---|
protected ContentItemFactory |
contentItemFactory |
protected static java.lang.String |
contentItemIdentiferPrefix |
Constructor and Description |
---|
XMLRepresentationOfStructuredReportObjectFactory()
Construct a factory object, which can be used to get XML documents from DICOM objects.
|
Modifier and Type | Method and Description |
---|---|
static void |
createDocumentAndWriteIt(AttributeList list,
java.io.OutputStream out)
Serialize an XML document (DOM tree) created from a DICOM Structured Report.
|
static void |
createDocumentAndWriteIt(StructuredReport sr,
AttributeList list,
java.io.OutputStream out)
Serialize an XML document (DOM tree) created from a DICOM Structured Report.
|
static void |
createDocumentAndWriteIt(StructuredReport sr,
java.io.OutputStream out)
Serialize an XML document (DOM tree) created from a DICOM Structured Report.
|
AttributeList |
getAttributeList(org.w3c.dom.Document document)
Given a DICOM SR object encoded as an XML document
convert it to a list of attributes.
|
AttributeList |
getAttributeList(java.io.InputStream stream)
Given a DICOM SR object encoded as an XML document in a stream
convert it to a list of attributes.
|
AttributeList |
getAttributeList(java.lang.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(org.w3c.dom.Node node) |
org.w3c.dom.Document |
getDocument(AttributeList list)
Given a DICOM attribute list encoding a Structured Report, get an XML document as a DOM tree.
|
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.
|
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.
|
static org.w3c.dom.Node |
getNamedChildElement(org.w3c.dom.Node parent,
java.lang.String name) |
static java.lang.String |
getNamedNodeAttributeOrNull(org.w3c.dom.NamedNodeMap attributes,
java.lang.String name) |
protected ContentItem |
getNextContentItemFromXMLNodeSiblings(org.w3c.dom.Node node) |
StructuredReport |
getStructuredReport(org.w3c.dom.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 java.lang.String |
getTextValueOfNamedChildElementOrNull(org.w3c.dom.Node parent,
java.lang.String name) |
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.
|
static java.lang.String |
toString(org.w3c.dom.Node documentNode) |
static java.lang.String |
toString(org.w3c.dom.Node documentNode,
int indent) |
static void |
write(java.io.OutputStream out,
org.w3c.dom.Document document)
Serialize an XML document (DOM tree).
|
protected ContentItemFactory contentItemFactory
protected static java.lang.String contentItemIdentiferPrefix
public XMLRepresentationOfStructuredReportObjectFactory() throws javax.xml.parsers.ParserConfigurationException
Construct a factory object, which can be used to get XML documents from DICOM objects.
javax.xml.parsers.ParserConfigurationException
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.
list
- the attribute listout
- the output stream to write tojava.io.IOException
DicomException
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.
sr
- the Structured Report may be null if list is not - will build an sr tree modellist
- the attribute list may be null if only the sr content tree is to be writtenout
- the output stream to write tojava.io.IOException
DicomException
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.
sr
- the Structured Reportout
- the output stream to write tojava.io.IOException
DicomException
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.
document
- the XML documentDicomException
javax.xml.parsers.ParserConfigurationException
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.
stream
- the input stream containing the XML documentjava.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
DicomException
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.
name
- the input file containing the XML documentjava.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
DicomException
protected CodedSequenceItem getCodedSequenceItem(org.w3c.dom.Node node) throws DicomException
DicomException
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.
list
- the attribute listpublic 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.
sr
- the Structured Reportpublic 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.
sr
- the Structured Report may be null if list is not - will build an sr tree modellist
- the attribute list may be null if only the sr content tree is to be addedpublic static org.w3c.dom.Node getNamedChildElement(org.w3c.dom.Node parent, java.lang.String name)
public static java.lang.String getNamedNodeAttributeOrNull(org.w3c.dom.NamedNodeMap attributes, java.lang.String name)
protected ContentItem getNextContentItemFromXMLNodeSiblings(org.w3c.dom.Node node) throws DicomException
DicomException
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.
document
- the XML documentDicomException
javax.xml.parsers.ParserConfigurationException
public static java.lang.String getTextValueOfNamedChildElementOrNull(org.w3c.dom.Node parent, java.lang.String name)
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.
arg
- either one filename of the file containing the DICOM dataset, or a direction argument (toDICOM or toXML, case insensitive) and an input filenamepublic static java.lang.String toString(org.w3c.dom.Node documentNode)
documentNode
- public static java.lang.String toString(org.w3c.dom.Node documentNode, int indent)
documentNode
- indent
- 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).
out
- the output stream to write todocument
- the XML documentjava.io.IOException
javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerException