Hi Lars
On 8/9/13 3:30 AM,
lars.eg...@vgregion.se wrote:> Hi,
> How do I read a specific parameter from one of the "triplets", Code
> Value, Coding Scheme Designator and Code Meaning? Pixelmed has functions
> to read for example Total DLP etc but I need to read the data that
> indicates the type of study (Ex T-04000., SRT, Breast) from a RDSR
> object. Is there a function for that or must I read it in a more "basic"
> way? Can you give me a "hint" or an example Code (Java)?
There are various ways to do this, depending on whether the SR
you are reading conforms to a template that is supported by
the toolkit with an equivalent Java class, or whether it is
more generic and you have to access nodes of the SR content
item tree directly.
If it is a CT RDSR, then you can use the CTDose class and its
related classes to get the target region, accounting for the
fact that the anatomy is specified for each acquisition and
so you need to iterate (null return checking and exception
handling elided for clarity):
AttributeList list = new AttributeList();
list.read(file);
CTDose ctDose = new CTDose(list);
int nAcq = ctDose.getNumberOfAcquisitions();
for (int iAcq=0; iAcq<nAcq; ++iAcq) {
CTDoseAcquisition acq = ctDose.getAcquisition(iAcq);
CTAcquisitionParameters ap = acq.getAcquisitionParameters();
CodedSequenceItem anatomy = ap.getAnatomy();
String cv = anatomy.getCodeValue();
...
}
If you need to walk the SR tree looking for the node anywhere it
occurs, regardless of the template structure:
StructuredReport sr = new StructuredReport(list);
CodedSequenceItem lookingFor = new
CodedSequenceItem("123014","DCM","Target Region");
findContentItem((ContentItem)(sr.getRoot()),lookingFor);
static void findContentItem(ContentItem ci,CodedSequenceItem
lookingFor) {
if (lookingFor.equals(ci.getConceptName())
&& ci instanceof ContentItemFactory.CodeContentItem) {
CodedSequenceItem csiv =
((ContentItemFactory.CodeContentItem)ci).getConceptCode();
String cv = csiv.getCodeValue();
System.err.println(cv);
}
else {
int n = ci.getChildCount();
for (int i=0; i<n; ++i) {
findContentItem((ContentItem)(ci.getChildAt(i)),lookingFor);
}
}
}
Alternatively, if you want to follow the template structure you can
descend through the tree using the getNamedChild(CodedSequenceItem)
method of ContentItem.
Another (much slower but expedient) approach is to convert to XML
and then use XPath, to descend the template properly and handle
the possibility of more than one acquisition:
String path = "/DicomStructuredReport/DicomStructuredReportContent"
+ "/container[concept/@cv='113701' and concept/@csd='DCM']"
+ "/container[concept/@cv='113819' and concept/@csd='DCM']"
+ "/code[concept/@cv='123014' and concept/@csd='DCM']";
Document document = new
XMLRepresentationOfStructuredReportObjectFactory().getDocument(sr,list);
XPathFactory xpf = XPathFactory.newInstance();
NodeList targetRegions = (NodeList)
(xpf.newXPath().evaluate(path,document,XPathConstants.NODESET));
for (int i=0; i<targetRegions.getLength(); ++i) {
Node targetRegion = targetRegions.item(i);
String cv = xpf.newXPath().evaluate("value/@cv",targetRegion);
System.err.println(cv);
}
or if you want to find any such nodes anywhere, and assume one
acquisition (not cool in this case, but useful for other singletons)
you can just use:
String cv = xpf.newXPath().evaluate(
"//code[concept/@cv='123014' and concept/@csd='DCM']/value/@cv",
document);
David