wiki:TenthQuery
Last modified 12 years ago Last modified on 01/09/07 11:13:44

return to XbrainEvaluation

let $target_x_mni := -65
let $x_dev := 5

let $target_y_mni := -57
let $y_dev := 5

let $target_z_mni := 0
let $z_dev := 5

let $inverse :=
dxq:csm("
<results>
<TransformServerParam coord='magnet_coordinates' source='0' target=''/>
{
for $p in $root/patient
return  
     <patient>
     {$p/pnum}
     {$p/viq}
     {$p/sex}
     <age>{$p/age_at_registration/text()}</age> 
     {
      for $s in $p/surgery
      return 
      <surgery>
      {
       for $site in $s/stimsite
       let $oid := $site/_oid
       return
       <stimsite>
              { $site/surgery}
              { $site/type}
              {$site/site_label}
              { 
                for $sitemap_elt in $p/surgery/sitetoanatomymap[preference='1']/sitetoanatomymapelement[stimsite/_oid = $oid]
                return    
                  <magnet_coordinates x0='{$sitemap_elt/right_coord/text()}' y0='{$sitemap_elt/ant_coord/text()}' 
                      z0='{$sitemap_elt/sup_coord/text()}' space0='P{$p/pnum}' space='MNI'>
                      <ant_coord>{$sitemap_elt/ant_coord/text()}</ant_coord>
                      <sup_coord>{$sitemap_elt/sup_coord/text()}</sup_coord>
                      <right_coord>{$sitemap_elt/right_coord/text()}</right_coord>
                  </magnet_coordinates>
              }    
              { 
                for $anat_elt in $p/surgery/anatomytonamemap[preference='1']/anatomytonamemapelement[stimsite/_oid = $oid]
                return    
                  <anatomical_name>{$anat_elt/term/fullname/text()}</anatomical_name>
              }   
              {
                 for $trialcode in $p//trial[stimsite1/_oid = $oid][stimulated='Y']/trialcode/term[type='CSM error code']/abbrev
                 return 
                 <trialcode>
                     {$trialcode/text()}
                 </trialcode>
             }
       </stimsite>
      }
      </surgery>
     }
     </patient>
}
</results>
")

let $patients_trans := dxq:trans($inverse)

return 
<results>
{
for $patient in $patients_trans//patient
let $sites_in_region :=
    for $stimsite in $patient/surgery/stimsite
    let $x := number($stimsite//magnet_coordinates/@x)
    let $y := number($stimsite//magnet_coordinates/@y)
    let $z := number($stimsite//magnet_coordinates/@z)
    where (exists($stimsite/trialcode) and $target_y_mni - $y_dev lt $y) and ($y lt $target_y_mni + $y_dev) and 
        ($target_z_mni - $z_dev lt $z) and ($z lt $target_z_mni + $z_dev) and 
        ($target_x_mni - $x_dev lt $x) and ($x lt $target_x_mni + $x_dev)    
    return
        $stimsite
where(exists($sites_in_region))
return
<patient>
{$patient/pnum}
{$sites_in_region}
</patient>
}
</results>