Class XMLRepresentationOfStructuredReportObjectFactory
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);
}
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a factory object, which can be used to get XML documents from DICOM objects. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateDocumentAndWriteIt(AttributeList list, OutputStream out) Serialize an XML document (DOM tree) created from a DICOM Structured Report.static voidcreateDocumentAndWriteIt(StructuredReport sr, AttributeList list, OutputStream out) Serialize an XML document (DOM tree) created from a DICOM Structured Report.static voidSerialize an XML document (DOM tree) created from a DICOM Structured Report.getAttributeList(InputStream stream) Given a DICOM SR object encoded as an XML document in a stream convert it to a list of attributes.getAttributeList(String name) Given a DICOM SR object encoded as an XML document in a named file convert it to a list of attributes.getAttributeList(Document document) Given a DICOM SR object encoded as an XML document convert it to a list of attributes.protected CodedSequenceItemgetCodedSequenceItem(Node node) getDocument(AttributeList list) Given a DICOM attribute list encoding a Structured Report, get an XML document as a DOM tree.Given a DICOM Structured Report, get an XML document of the content tree only as a DOM tree.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 NodegetNamedChildElement(Node parent, String name) static StringgetNamedNodeAttributeOrNull(NamedNodeMap attributes, String name) protected ContentItemgetStructuredReport(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 StringgetTextValueOfNamedChildElementOrNull(Node parent, String name) static voidRead a DICOM dataset (that contains a structured report) and write an XML representation of it to the standard output, or vice versa.static Stringstatic Stringstatic voidwrite(OutputStream out, Document document) Serialize an XML document (DOM tree).
-
Field Details
-
contentItemIdentiferPrefix
-
contentItemFactory
-
-
Constructor Details
-
XMLRepresentationOfStructuredReportObjectFactory
Construct a factory object, which can be used to get XML documents from DICOM objects.
- Throws:
ParserConfigurationException
-
-
Method Details
-
getDocument
Given a DICOM attribute list encoding a Structured Report, get an XML document as a DOM tree.
- Parameters:
list- the attribute list
-
getDocument
Given a DICOM Structured Report, get an XML document of the content tree only as a DOM tree.
- Parameters:
sr- the Structured Report
-
getDocument
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
-
getNamedChildElement
-
getTextValueOfNamedChildElementOrNull
-
getCodedSequenceItem
- Throws:
DicomException
-
getNextContentItemFromXMLNodeSiblings
- 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:
DicomExceptionParserConfigurationException
-
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:
DicomExceptionParserConfigurationException
-
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:
IOExceptionSAXExceptionParserConfigurationExceptionDicomException
-
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:
IOExceptionSAXExceptionParserConfigurationExceptionDicomException
-
toString
- Parameters:
documentNode-indent-
-
toString
- 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 todocument- the XML document- Throws:
IOExceptionTransformerConfigurationExceptionTransformerException
-
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 listout- the output stream to write to- Throws:
IOExceptionDicomException
-
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 Reportout- the output stream to write to- Throws:
IOExceptionDicomException
-
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 modellist- the attribute list may be null if only the sr content tree is to be writtenout- the output stream to write to- Throws:
IOExceptionDicomException
-
main
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
-