Stored Functions

Content-Type: text/xml


    Peforms a search request on a provider's common name according to the OpenSearch 1.1 Specification:
    Returns search results in opensearch feed for a provider by common name including link to free busy information on Zimbra for scheduling information.


import module namespace osf = "";
import module namespace functx = '';

declare namespace csd =  "urn:ihe:iti:csd:2013";
declare namespace rss = "";
declare namespace atom = "";
declare namespace html = "";
declare namespace os  = "";

declare variable $careServicesRequest as item() external;

   The query will be executed against the root element of the CSD document.    
   The dynamic context of this query has $careServicesRequest set to contain any of the search 
   and limit paramaters as sent by the Service Finder

(:Get the search terms passed in the request :)
let $search_terms := xs:string($careServicesRequest/os:searchTerms/text())
(:Find the matching providers -- to be customized for your search:)
let $filter:= function($common_name) {
  functx:contains-case-insensitive($common_name,  $search_terms)  
let $matched_providers :=  
  if ($search_terms) then
    for $provider in /csd:CSD/csd:providerDirectory/csd:provider
    let $common_names := $provider/csd:demographic/csd:name/csd:commonName
    where  count(filter($common_names,$filter)) > 0
    return $provider  
  else ()

let $html_func := function($provider,$doc_name,$search_name) {
  if (local-name-from-QName(node-name($provider)) = 'provider' and namespace-uri-from-QName(node-name($provider)) = "urn:ihe:iti:csd:2013") then
    let $demo:= $provider/csd:demographic[1]
    let $oid := string($provider/@oid)
    let $adapter_link := concat($careServicesRequest/@base_url,"CSD/adapter/zimbra/" , $search_name, "/" , $doc_name,"/scheduling")
	<html:a href="{osf:get_entity_link($provider,$search_name)}">
	  {$demo/csd:name[1]/csd:surname/text()}, {$demo/csd:name[1]/csd:forename/text()}
	<html:a href="{$adapter_link}?oid={$oid}">Scheduling with Free Busy</html:a>
	<html:div class='description_html'>{osf:get_provider_desc_html($provider,$doc_name)}</html:div>

let $processors := map{
  'html' := $html_func

(:Produce the feed in the neccesary format :)
return osf:create_feed_from_entities($matched_providers,$careServicesRequest,$processors)