Ticket #17 (new enhancement)

Opened 12 years ago

Support saved functions

Reported by: ebmoore Owned by: detwiler
Priority: minor Milestone:
Component: xbrain Version:
Keywords: Cc:

Description

XBrain should support saved XQuery functions. This would make writing queries by hand and reading them much easier as we could build on previous functions without using copy/paste. This will likely require Ticket #16 to be addressed.

The functions should be bound to namespace sig. Additionally it would be nice if the system only included the functions that were used in the shipped query (by scanning for sig:'function_name' and only including hits. This would require recursively scanning all included functions as well)

Possible functions would be:

  • sig:printStimsite($site as node()*)as node() (:for printing default sites:)
  • sig:printTrial($trial as node()*) as node() (:for printing default trials with sites:)
  • sig:printPatientData($patient as node()) as node() (:for printing pnum, sex, viq, age, whatever else we want to always appear)
  • sig:getTrialUnderSite($patient as node()*) as node() (:for getting a structure with trials under sites:)
  • many more

Example: if we just had a function: sig:printTrial then the template query's size is reduced by about half:

<results>
{
 let $code := '2'
 for $p in $pv/patient
 let $csm:=$p/surgery/csmstudy 
 where $csm/trial[stimulated='Y']/trialcode/term[type='CSM error code']/abbrev/text()=$code
 return 
 <patient> 
  {$p/pnum} 
  {$p/sex} 
  <age>{$p/age_at_registration/text()}</age> 
  {$p/viq} 
  {
    for $t in $csm/trial 
    where $t[stimulated='Y']/trialcode/term[type='CSM error code']/abbrev/text()=$code 
    return sig:printTrial($t)
  }
  </patient>
 } 
</results>
Note: See TracTickets for help on using tickets.