Custom datatype derived from MRScan

278 views
Skip to first unread message

plxna...@gmail.com

unread,
Oct 2, 2013, 6:30:43 AM10/2/13
to xnat_di...@googlegroups.com
Hello dear XNATers,

I have a problem: I'd like to add an additional string element to the mrScanData datatype: Something like "studyUsability"

I downloaded the scan.xml of an existing MRScan via XNATRestClient -m GET and started editing:

First I tried to upload a modified scan.xml which contained an additional element (<Teststring>Hello</Teststring>) to my experiments. However, this did not work. I'm assuming that the xml validation failed when it encountered an unknown element. 

After this I google'd for a while until I came to the conclusion, that I need to create a custom datatype which extends the mrScanData. So I created a new datatype called MRScanExt which extends mrScanData and contains only one additional string as an element. I managed to add the datatype to XNAT with update.sh -Ddeploy=true and psql etc. (with the help of the XNATwiki tutorial).

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema targetNamespace="http://nrg.wustl.edu/ext"
xmlns:ext="http://nrg.wustl.edu/ext"
xmlns:xdat="http://nrg.wustl.edu/xdat"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xnat="http://nrg.wustl.edu/xnat" elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:import namespace="http://nrg.wustl.edu/xnat" schemaLocation="../xnat/xnat.xsd"/>

<xs:element name="mrScanExt" type="ext:mrScanExt"/>

<xs:complexType name="mrScanExt">

<xs:complexContent>

<xs:extension base="xnat:mrScanData">

<xs:sequence>

<xs:element name="Teststring" minOccurs="0" maxOccurs="1" type="xs:string"/>

</xs:sequence>

</xs:extension>

</xs:complexContent>

</xs:complexType>

</xs:schema>



However, wehen I tried to upload data as the new datatype via XNATRestClient, I failed.Here is what I did to test whether my new datatype works:

I took the old scan.xml and added a new xml element (e.g.: <ext:Teststring>Hello</ext:Teststring>).So my new scan.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<ext:mrScanExt ID="4" type="t1_mpr_1mm_p2_pos50" UID="1.3.12.2.1107.5.2.32.35177.3.2006121409284535196417894.0.0.0" xmlns:arc="http://nrg.wustl.edu/arc" xmlns:ext="http://nrg.wustl.edu/ext" xmlns:val="http://nrg.wustl.edu/val" xmlns:pipe="http://nrg.wustl.edu/pipe" xmlns:wrk="http://nrg.wustl.edu/workflow" xmlns:scr="http://nrg.wustl.edu/scr" xmlns:xdat="http://nrg.wustl.edu/security" xmlns:cat="http://nrg.wustl.edu/catalog" xmlns:prov="http://www.nbirn.net/prov" xmlns:xnat="http://nrg.wustl.edu/xnat" xmlns:xnat_a="http://nrg.wustl.edu/xnat_assessments" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nrg.wustl.edu/workflow http://localhost:8080/xnat/schemas/pipeline/workflow.xsd http://nrg.wustl.edu/catalog http://localhost:8080/xnat/schemas/catalog/catalog.xsd http://nrg.wustl.edu/pipe http://localhost:8080/xnat/schemas/pipeline/repository.xsd http://nrg.wustl.edu/scr http://localhost:8080/xnat/schemas/screening/screeningAssessment.xsd http://nrg.wustl.edu/arc http://localhost:8080/xnat/schemas/project/project.xsd http://nrg.wustl.edu/val http://localhost:8080/xnat/schemas/validation/protocolValidation.xsd http://nrg.wustl.edu/xnat http://localhost:8080/xnat/schemas/xnat/xnat.xsd http://nrg.wustl.edu/ext http://localhost:8080/xnat/schemas/mrScanExt/mrScanExt.xsd http://nrg.wustl.edu/xnat_assessments http://localhost:8080/xnat/schemas/assessments/assessments.xsd http://www.nbirn.net/prov http://localhost:8080/xnat/schemas/birn/birnprov.xsd http://nrg.wustl.edu/security http://localhost:8080/xnat/schemas/security/security.xsd">
<!--hidden_fields[xnat_imageScanData_id="37"]-->
<xnat:image_session_ID>XNAT_E00001</xnat:image_session_ID>
<xnat:quality>usable</xnat:quality>
<xnat:series_description>t1_mpr_1mm_p2_pos50</xnat:series_description>
<xnat:scanner manufacturer="SIEMENS" model="TrioTim">MEDPC</xnat:scanner>
<xnat:frames>176</xnat:frames>
<ext:Teststring>HELLO</ext:Teststring>
<xnat:file label="DICOM" URI="/opt/xnat/data/archive/prj001/arc001/prj001_subj001_exp001/SCANS/4/DICOM/scan_4_catalog.xml" format="DICOM" content="RAW" xsi:type="xnat:resourceCatalog">
<!--hidden_fields[xnat_abstractResource_id="59",xnat_imageScanData_xnat_imagescandata_id="37"]-->
</xnat:file>
<xnat:file label="SNAPSHOTS" URI="/opt/xnat/data/archive/prj001/arc001/prj001_subj001_exp001/SCANS/4/SNAPSHOTS/SNAPSHOTS_catalog.xml" format="GIF" content="SNAPSHOTS" xsi:type="xnat:resourceCatalog">
<!--hidden_fields[xnat_abstractResource_id="62",xnat_imageScanData_xnat_imagescandata_id="37"]-->
</xnat:file>
<xnat:startTime>09:37:11</xnat:startTime>
<xnat:fieldStrength>3.0</xnat:fieldStrength>
<xnat:parameters>
<xnat:voxelRes x="1.0" y="1.0" z="1.0"/>
<xnat:orientation>Sag</xnat:orientation>
<xnat:fov x="256" y="256"/>
<xnat:tr>2400.0</xnat:tr>
<xnat:te>3.08</xnat:te>
<xnat:ti>1000.0</xnat:ti>
<xnat:flip>8</xnat:flip>
<xnat:sequence>*tfl3d1_ns</xnat:sequence>
<xnat:imageType>ORIGINAL\PRIMARY\M\ND\NORM</xnat:imageType>
<xnat:scanSequence>GR\IR</xnat:scanSequence>
<xnat:seqVariant>SP\MP\OSP</xnat:seqVariant>
<xnat:scanOptions>IR</xnat:scanOptions>
<xnat:acqType>3D</xnat:acqType>
<xnat:pixelBandwidth>220.0</xnat:pixelBandwidth>
</xnat:parameters>
</ext:mrScanExt>

When uploading this xml file via XNATRestClient, I always get the following error message: "The server encountered an unexpected condition which prevented him from fulfilling the request". When I take the unmodified scan.xml and try to upload it as MRScanExt, the server said my additional element <Teststring> was missing, so that worked at least a little bit. But no matter how hard I try to add my element <ext:Teststring> I can't seem to get it working whitout the server running into the unexpected condition.

I tried also: <xnat:Teststring> and <Teststring> instead of <ext:Teststring>

I also get an processing exception in XNAT/prj001/..../scan/4:

Modified mrSessionExt: Failed: Start Time: Time and date

I've read all the wiki pages and the resources from the workshops about creating custom datatypes, however nowhere can I find instructions how to actually put data in a custom datatype into XNAT. I assume that I'm trying the wrong way. Does it work the way I think it does(get scan.xml via Rest GET, create new datatype, and add additional elements to the old scan.xml and then upload the scan.xml via REST to its original path) or is there something else that I need to do in order to put MR data into my custom datatype / custom data to the existing mrScanData?

I would really appreciate any help from you.

-Philip

Tim Olsen

unread,
Oct 2, 2013, 11:18:11 AM10/2/13
to xnat_di...@googlegroups.com

Philip,

 

A few things:

·         Extending the scan data type is an option, but it should be avoided if possible, as it might require more work down the road.

·         How is your studyUsability field different from the usability property that is already at the scan level?  Could it be used instead?  Depending on what you are storing, this may actually be the purpose of this field.

·         Another option is that there is a way to add any field you want to the scan without modifying the schema.  The parameters element allows an unbounded list of additional parameters (name/value pairs).  You can add one by adding this kind of element, right before the </parameters> tag.

<xnat:addParam name="studyUsability">value</xnat:addParam>

 

What are your goals for this field?  Do you just need something that will show up in the session report?  Do you need something that is queryable?  Via the UI/REST?

 

Tim

--
You received this message because you are subscribed to the Google Groups "xnat_discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xnat_discussi...@googlegroups.com.
To post to this group, send email to xnat_di...@googlegroups.com.
Visit this group at http://groups.google.com/group/xnat_discussion.
For more options, visit https://groups.google.com/groups/opt_out.

plxna...@gmail.com

unread,
Oct 2, 2013, 2:59:27 PM10/2/13
to xnat_di...@googlegroups.com
Hello Tim,

thanks for your answer! I am currently checking lots of MRScans for some parameters via pipeline+bash. If the parameters match the ones given in our study I want to add a field to the Scan.xml where I can write down the type of scan that I determined with my script. But my problem is, that I don't want to change any existing field because in our XNAT, many of those fields are already used by others... Basically, I need an additional element just for my own type-string. I would love if it would appear in the session report(like type, series_description, quality etc.) and if I could search for the types (e.g. search for all my types:3DT1...)! I don't know if it's hard to make it work like this, but I would really appreciate any help/tips/tricks or tutorials I couldn't find on google!

Thank you very much,

Philip

Tim Olsen

unread,
Oct 2, 2013, 3:53:39 PM10/2/13
to xnat_di...@googlegroups.com

The addParam option I mentioned should work for you.  I think those parameters automatically show up in the scan details section of the MR report (accessible by expanding a scan).  Regarding getting them query able, that will be doable, but with a little more work (involves adding some customized SQL to an existing display.xml).  Have you tried modifying a session xml like I suggested, to see if it works for you?

 

Tim

 

From: xnat_di...@googlegroups.com [mailto:xnat_di...@googlegroups.com] On Behalf Of plxna...@gmail.com


Sent: Wednesday, October 02, 2013 1:59 PM
To: xnat_di...@googlegroups.com

--

plxna...@gmail.com

unread,
Oct 3, 2013, 8:48:43 AM10/3/13
to xnat_di...@googlegroups.com
Hello Tim,

thanks, that was exactly what I was looking for! Another small question: Is it possible to make my element appear in the standard MRSession screen(like type, series_description, usability, etc.)? I tried to get the string from the element similar to the type-string:

<td border=0 style="font-weight:bold; text-align:left;"  NOWRAP>
      $!scan.getProperty("studyUsability")
</td>

But it doesn't show any values. When I download the modified scan.xml it is still there. So the value isn't missing. It would be really helpful for me if I could see it in the overview!

Have a nice day,

-Philip

Timothy Olsen

unread,
Oct 4, 2013, 11:21:00 AM10/4/13
to xnat_di...@googlegroups.com
Try this:

#if($scan.getProperty("xnat:mrScanData/parameters/addParam[name=studyUsability]/addField"))
                                  <tr>
                                                        <td>    </td>
                                                        <td>Study Usability</td>
                                                        <td align="left">$!scan.getStringProperty("xnat:mrScanData/parameters/addParam[name=studyUsability]/addField")</td>
                                  </tr>
                #end


--

plxna...@gmail.com

unread,
Oct 9, 2013, 10:25:08 AM10/9/13
to xnat_di...@googlegroups.com
Hello Tim, it worked fine!

...but wait, there is more! I was wondering if you (or someone else ofc.) could tell me how I can count my scans with my custom parameter in my schematron-rulefile. Basically what I am trying to do is count all MRScans that contain my own parameter

<xnat:addParam name="studyUsability">TEST</xnat:addParam>

with
only the string "TEST" in it.


I  tried count(/xnat:mrScanData/parameters/addParam[@name=studyValidity and string='TEST']) and several permutations of this syntax, including text, content, etc. but nothing seems to work...

I am pretty new to XPath, so I would appreciate any help!

Thanks,

Philip

Tim Olsen

unread,
Oct 9, 2013, 11:56:40 AM10/9/13
to xnat_di...@googlegroups.com, Ramaratnam, Mohana

Unfortunately, I’m not much  more experienced with schematron.  Mohana, any ideas here?

 

Tim

 

From: xnat_di...@googlegroups.com [mailto:xnat_di...@googlegroups.com] On Behalf Of plxna...@gmail.com
Sent: Wednesday, October 09, 2013 9:25 AM
To: xnat_di...@googlegroups.com
Subject: [XNAT Discussion] Re: Custom datatype derived from MRScan

 

Hello Tim, it worked fine!

--

plxna...@gmail.com

unread,
Oct 10, 2013, 8:17:31 AM10/10/13
to xnat_di...@googlegroups.com
No Problem Tim,

you've helped so much already, thanks :-) . Nevertheless, is there anyone out here who can tell me if this is possible at all? I tried so much, but I can't get it working. I've google'd so much and read so many XPath/Schematron tutorials I am already having nightmares about it... My practical training ends tomorrow, so it would be really cool if I could finish my project instead of failing at the last step being the schematron file.

Anyway, thank you guys so much for your awesome newbie support!

- Philip

Mohana Ramaratnam

unread,
Oct 10, 2013, 9:47:56 AM10/10/13
to xnat_di...@googlegroups.com
Hi Philip,

Try this in the schematron file:

<iso:pattern id="Acquisition">
   <iso:rule context="xnat:MRSession/xnat:scans">
<iso:assert test="count(xnat:scan[xnat:parameters/xnat:addParam[@name='studyUsability'] and xnat:parameters/xnat:addParam[text()='TEST']]) >1"> 
<nrgxsl:acquisition>
<nrgxsl:cause-id>StudyUsability Count</nrgxsl:cause-id>
 <iso:value-of select="concat('Found ',count(xnat:scan[xnat:parameters/xnat:addParam[@name='studyUsability'] and xnat:parameters/xnat:addParam[text()='TEST']]))"/> 
</nrgxsl:acquisition> 
</iso:assert>
            </iso:rule>
 </iso:pattern>


Regards
Mohana


--

Mohana Ramaratnam

unread,
Oct 10, 2013, 11:28:23 AM10/10/13
to xnat_di...@googlegroups.com

You may have to replace the namespace xnat: for your schema extension.

Reply all
Reply to author
Forward
0 new messages