Class XMLRepresentationOfStructuredReportObjectFactory
- java.lang.Object
-
- com.pixelmed.dicom.XMLRepresentationOfStructuredReportObjectFactory
-
public class XMLRepresentationOfStructuredReportObjectFactory extends java.lang.ObjectA 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
Fields Modifier and Type Field Description protected ContentItemFactorycontentItemFactoryprotected static java.lang.StringcontentItemIdentiferPrefix
-
Constructor Summary
Constructors Constructor Description XMLRepresentationOfStructuredReportObjectFactory()Construct a factory object, which can be used to get XML documents from DICOM objects.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidcreateDocumentAndWriteIt(AttributeList list, java.io.OutputStream out)Serialize an XML document (DOM tree) created from a DICOM Structured Report.static voidcreateDocumentAndWriteIt(StructuredReport sr, AttributeList list, java.io.OutputStream out)Serialize an XML document (DOM tree) created from a DICOM Structured Report.static voidcreateDocumentAndWriteIt(StructuredReport sr, java.io.OutputStream out)Serialize an XML document (DOM tree) created from a DICOM Structured Report.AttributeListgetAttributeList(java.io.InputStream stream)Given a DICOM SR object encoded as an XML document in a stream convert it to a list of attributes.AttributeListgetAttributeList(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.AttributeListgetAttributeList(org.w3c.dom.Document document)Given a DICOM SR object encoded as an XML document convert it to a list of attributes.protected CodedSequenceItemgetCodedSequenceItem(org.w3c.dom.Node node)org.w3c.dom.DocumentgetDocument(AttributeList list)Given a DICOM attribute list encoding a Structured Report, get an XML document as a DOM tree.org.w3c.dom.DocumentgetDocument(StructuredReport sr)Given a DICOM Structured Report, get an XML document of the content tree only as a DOM tree.org.w3c.dom.DocumentgetDocument(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.NodegetNamedChildElement(org.w3c.dom.Node parent, java.lang.String name)static java.lang.StringgetNamedNodeAttributeOrNull(org.w3c.dom.NamedNodeMap attributes, java.lang.String name)protected ContentItemgetNextContentItemFromXMLNodeSiblings(org.w3c.dom.Node node)StructuredReportgetStructuredReport(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.StringgetTextValueOfNamedChildElementOrNull(org.w3c.dom.Node parent, java.lang.String name)static voidmain(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.StringtoString(org.w3c.dom.Node documentNode)static java.lang.StringtoString(org.w3c.dom.Node documentNode, int indent)static voidwrite(java.io.OutputStream out, org.w3c.dom.Document document)Serialize an XML document (DOM tree).
-
-
-
Field Detail
-
contentItemIdentiferPrefix
protected static java.lang.String contentItemIdentiferPrefix
-
contentItemFactory
protected ContentItemFactory contentItemFactory
-
-
Constructor Detail
-
XMLRepresentationOfStructuredReportObjectFactory
public XMLRepresentationOfStructuredReportObjectFactory() throws javax.xml.parsers.ParserConfigurationExceptionConstruct 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 modellist- 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)
-
getCodedSequenceItem
protected CodedSequenceItem getCodedSequenceItem(org.w3c.dom.Node node) throws DicomException
- Throws:
DicomException
-
getNextContentItemFromXMLNodeSiblings
protected ContentItem getNextContentItemFromXMLNodeSiblings(org.w3c.dom.Node node) throws DicomException
- Throws:
DicomException
-
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:
DicomExceptionjavax.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:
DicomExceptionjavax.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.IOExceptionorg.xml.sax.SAXExceptionjavax.xml.parsers.ParserConfigurationExceptionDicomException
-
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.IOExceptionorg.xml.sax.SAXExceptionjavax.xml.parsers.ParserConfigurationExceptionDicomException
-
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.TransformerExceptionSerialize an XML document (DOM tree).
- Parameters:
out- the output stream to write todocument- the XML document- Throws:
java.io.IOExceptionjavax.xml.transform.TransformerConfigurationExceptionjavax.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 listout- the output stream to write to- Throws:
java.io.IOExceptionDicomException
-
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 Reportout- the output stream to write to- Throws:
java.io.IOExceptionDicomException
-
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 modellist- the attribute list may be null if only the sr content tree is to be writtenout- the output stream to write to- Throws:
java.io.IOExceptionDicomException
-
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
-
-