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) { 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); }
Modifier and Type | Field and Description |
---|---|
protected ContentItemFactory |
contentItemFactory |
protected static 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,
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).
|
protected ContentItemFactory contentItemFactory
protected static String contentItemIdentiferPrefix
public XMLRepresentationOfStructuredReportObjectFactory() throws ParserConfigurationException
Construct a factory object, which can be used to get XML documents from DICOM objects.
ParserConfigurationException
public static void createDocumentAndWriteIt(AttributeList list, OutputStream out) throws IOException, DicomException
Serialize an XML document (DOM tree) created from a DICOM Structured Report.
list
- the attribute listout
- the output stream to write toIOException
DicomException
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.
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 toIOException
DicomException
public static void createDocumentAndWriteIt(StructuredReport sr, OutputStream out) throws IOException, DicomException
Serialize an XML document (DOM tree) created from a DICOM Structured Report.
sr
- the Structured Reportout
- the output stream to write toIOException
DicomException
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.
document
- the XML documentDicomException
ParserConfigurationException
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.
stream
- the input stream containing the XML documentIOException
SAXException
ParserConfigurationException
DicomException
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.
name
- the input file containing the XML documentIOException
SAXException
ParserConfigurationException
DicomException
protected CodedSequenceItem getCodedSequenceItem(Node node) throws DicomException
DicomException
public 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 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 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 String getNamedNodeAttributeOrNull(NamedNodeMap attributes, String name)
protected ContentItem getNextContentItemFromXMLNodeSiblings(Node node) throws DicomException
DicomException
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.
document
- the XML documentDicomException
ParserConfigurationException
public static String getTextValueOfNamedChildElementOrNull(Node parent, String name)
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.
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 String toString(Node documentNode, int indent)
documentNode
- indent
- public static void write(OutputStream out, Document document) throws IOException, TransformerConfigurationException, TransformerException
Serialize an XML document (DOM tree).
out
- the output stream to write todocument
- the XML documentIOException
TransformerConfigurationException
TransformerException