bulk_health_worker_read_otherids_json
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $code := $careServicesRequest/code/text()
let $aa := $careServicesRequest/assigningAuthorityName/text()
let $xml:=
<json type="object">
<results type='array'>
{
for $ent_id in $careServicesRequest/id
let $req_id := upper-case(string($ent_id/@entityID))
let $provider := (/CSD/providerDirectory/provider[upper-case(string(@entityID)) = $req_id])[1]
let $other_ids_0 :=
if ($code)
then $provider/otherID[@code = $code]
else $provider/otherID
let $other_ids_1 :=
if ($aa)
then $other_ids_0[@assigningAuthorityName = $aa]
else $other_ids_0
return
if (exists($provider) and count($other_ids_1) > 0)
then
<_ type='object'>
<entityID>{string($provider/@entityID)}</entityID>
<otherID type="array">
{
for $id in $other_ids_1
return
<_ type='object'>
<code>{string($id/@code)}</code>
<authority>{string($id/@assigningAuthorityName)}</authority>
<value>{$id/text()}</value>
</_>
}
</otherID>
</_>
else ()
}
</results>
</json>
return json:serialize($xml,map{"format":"direct"})
facility_get_urns
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 := if (exists($careServicesRequest/id)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else /CSD/facilityDirectory/*
let $facs1 := if (exists($careServicesRequest/otherID)) then csd_bl:filter_by_other_id($facs0,$careServicesRequest/otherID) else $facs0
let $facs2 := if (exists($careServicesRequest/codedType)) then csd_bl:filter_by_coded_type($facs1,$careServicesRequest/codedType) else $facs1
let $facs3 := if (exists($careServicesRequest/address/addressLine)) then csd_bl:filter_by_address($facs2, $careServicesRequest/address/addressLine) else $facs2
let $facs4 := if (exists($careServicesRequest/record)) then csd_bl:filter_by_record($facs3,$careServicesRequest/record) else $facs3
let $facs5 := if (exists($careServicesRequest/start) and exists($careServicesRequest/max)) then csd_bl:limit_items($facs4,$careServicesRequest/start,$careServicesRequest/max) else $facs4
let $facs6 := for $entityID in $facs5/@entityID
return <facility entityID="{$entityID}"/>
return csd_bl:wrap_facilities(($facs6))
facility_indices_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id)
else (/CSD/facilityDirectory/*)
let $facs1:=
for $facility in $facs0
return
<facility entityID="{$facility/@entityID}">
{
for $address in $facility/address
return <address type="{$address/@type}"/>
}
</facility>
return csd_bl:wrap_facilities($facs1)
facility_indices_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id)
else (/CSD/facilityDirectory/*)
let $facs1:=
for $facility in $facs0
return
<facility entityID="{$facility/@entityID}">
{
for $cp at $pos in $facility/contactPoint
return <contactPoint position="{$pos}"/>
}
</facility>
return csd_bl:wrap_facilities($facs1)
facility_indices_organization
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id)
else (/CSD/facilityDirectory/*)
let $facs1:=
for $facility in $facs0
return
<facility entityID="{$facility/@entityID}">
<organizations>
{
for $org in $facility/organizations/organization
return
<organization entityID="{$org/@entityID}"></organization>
}
</organizations>
</facility>
return csd_bl:wrap_facilities($facs1)
facility_indices_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id)
else (/CSD/facilityDirectory/*)
let $facs1:=
for $facility in $facs0
return
<facility entityID="{$facility/@entityID}">
{
for $id at $pos in $facility/otherID
return <otherID position="{$pos}"/>
}
</facility>
return csd_bl:wrap_facilities($facs1)
facility_indices_service
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id)
else (/CSD/facilityDirectory/*)
let $facs1:=
for $facility in $facs0
return
<facility entityID="{$facility/@entityID}">
<organizations>
{
let $facs :=
if (exists($careServicesRequest/organization/@entityID))
then
$facility/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
else $facility/organizations/organization
for $fac in $facs
return
<organization entityID="{$fac/@entityID}">
{
for $srvc at $pos in $fac/service
return <service position="{$pos}" entityID="{$srvc/@entityID}"/>
}
</organization>
}
</organizations>
</facility>
return csd_bl:wrap_facilities($facs1)
Performs a search for all facilities by name, type, address or ID.
The result set consists of the primary name of all facilities matching the search parameters ( id, primaryName, name, codedType and address ).
The results set may be further restricted according to the limit parameters (start, max, record/@status and record/@updated). An ordering of the result set is not specified.
Response
Results are returned as a valid CSD document with a root document element of <CSD/>. The results set is contained entirely within the <facilityDirectory/> element and consists of the full content of the <facility/> elements of matching facilities as maintained by the Care Services InfoManager.
Parameters Query
Parameters are defined as the content of following elements:
<id/> csd:uniqueID: (optional) If present and the @urn attribute contains a non-empty value, it is a ID which uniquely identifies a facility. This is an exact match.
<primaryName/> xs:string: (optional) If present and contains a non-empty value, then the result set should be restricted to those facilities whose <primaryName/> contains this value. Case insensitive.
<name/> xs:string: (optional) If present and contains a non-empty value, then the result set should be restricted to those facilities which have a <primaryName/> or <otherName/> element containing this value. Case insensitive.
<codedType/> csd:codedtype: If present and contains a non-empty value the result set should be restricted to those facilities whose <codedType/@code> equals this value for the coding schema specified by the @codingSchema attribute. Case insensitive.
<address/> csd:address: (optional) Contains of any-number of child <addressLine/> elements as follows:
Text content xs:string: (optional) If present and contains a non-empty value, then the results set should be restricted to those facilities whose have an <addressLine/> with specified @component containing this value exactly. Case insensitive.
@component xs:string : (Required attribute) The component of the address we are searching. Case insensitive.
<start/> xs:int: (optional) The starting index for results returned. Defaults to 1, which indexes the first facility matching the search parameters
<max/> xs:int: (optional) The maximum number of results returned. A value of less than zero implies no maximum.
<record/> csd:record : (optional) A child element to limit results according to
@status xs:string: (optional) If present and contains a non-empty value, the result set should be restricted to those facilities whose record/@status equals this value. Case insensitive.
@updated xs:dateTime: (optional) If present and contains a non-empty value, the result set should be restricted to those facilities whose record/@updated is at least the given value.
Example Request
<careServicesRequest>
<function uuid='c7640530-f600-11e2-b778-0800200c9a66'>
<codedType code='OPC' codingSchema="USDVA"/>
<address>
<addressLine component='city'>Chapel Hill</addressLine>
</address>
<max>5</max>
</function>
</careServicesRequest>
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
<CSD xmlns:csd="urn:ihe:iti:csd:2013" >
<organizationDirectory/>
<serviceDirectory/>
<facilityDirectory>
{
let $facs0 := if (exists($careServicesRequest/id))
then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id)
else /CSD/facilityDirectory/*
let $facs1 := if (exists($careServicesRequest/primaryName))
then csd_bl:filter_by_primary_name($facs0,$careServicesRequest/primaryName)
else $facs0
let $facs2 := if (exists($careServicesRequest/name))
then csd_bl:filter_by_name($facs1,$careServicesRequest/name)
else $facs1
let $facs3 := if(exists($careServicesRequest/codedType))
then csd_bl:filter_by_coded_type($facs2,$careServicesRequest/codedType)
else $facs2
let $facs4 := if(exists($careServicesRequest/address/addressLine))
then csd_bl:filter_by_address($facs3, $careServicesRequest/address/addressLine)
else $facs3
let $facs5 := if (exists($careServicesRequest/record))
then csd_bl:filter_by_record($facs4,$careServicesRequest/record)
else $facs4
let $facs6 := if(exists($careServicesRequest/otherID))
then csd_bl:filter_by_other_id($facs5,$careServicesRequest/otherID)
else $facs5
let $facs7:= if (exists($careServicesRequest/start)) then
if (exists($careServicesRequest/max))
then csd_bl:limit_items($facs6,$careServicesRequest/start,$careServicesRequest/max)
else csd_bl:limit_items($facs6,$careServicesRequest/start,<max/>)
else
if (exists($careServicesRequest/max))
then csd_bl:limit_items($facs6,<start/>,$careServicesRequest/max)
else $facs6
return for $fac in $facs7
return
<facility entityID='{$fac/@entityID}'>
{$fac/primaryName}
</facility>
}
</facilityDirectory>
<providerDirectory/>
</CSD>
facilty_read_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 := if (exists($careServicesRequest/address/@type)) then /CSD/facilityDirectory/* else ()
let $facs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($facs0,$careServicesRequest/id) else ()
let $facs2 :=
if (count($facs1) = 1)
then
let $facility := $facs1[1]
return
<facility entityID="{$facility/@entityID}">
{(
for $address in $facility/address[@type = $careServicesRequest/address/@type]
return $address
)}
{$facility/record}
</facility>
else ()
return csd_bl:wrap_facilities($facs2)
facility_read_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 := if (exists($careServicesRequest/contactPoint/@position)) then /CSD/facilityDirectory/* else ()
let $facs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($facs0,$careServicesRequest/id) else ()
let $facs2 :=
if (count($facs1) = 1)
then
let $facility := $facs1[1]
return
<facility entityID="{$facility/@entityID}">
{
if (exists($careServicesRequest/contactPoint) and exists($careServicesRequest/contactPoint/@position))
then
for $cp in $facility/contactPoint[position() = $careServicesRequest/contactPoint/@position]
return <contactPoint position="{$careServicesRequest/contactPoint/@position}">{$cp/*}</contactPoint>
else
()
}
{$facility/record}
</facility>
else ()
return csd_bl:wrap_facilities($facs2)
facility_read_organization
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 := if (exists($careServicesRequest/organization/@entityID)) then /CSD/facilityDirectory/* else ()
let $facs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($facs0,$careServicesRequest/id) else ()
let $facs2 :=
if (count($facs1) = 1)
then
let $facility := $facs1[1]
return
<facility entityID="{$facility/@entityID}">
{
(
<organizations>
{
for $org in $facility/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID ) ]
return
<organization entityID="{$org/@entityID}"></organization>
}
</organizations>
,
$facility/record
)
}
</facility>
else ()
return csd_bl:wrap_facilities($facs2)
facility_read_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 := if (exists($careServicesRequest/otherID/@position)) then /CSD/facilityDirectory/* else ()
let $facs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($facs0,$careServicesRequest/id) else ()
let $facs2 :=
if (count($facs1) = 1)
then
let $facility := $facs1[1]
return
<facility entityID="{$facility/@entityID}">
{(
if (exists($careServicesRequest/otherID/@position))
then
for $id in $facility/otherID[position() = $careServicesRequest/otherID/@position]
return
<otherID
position="{$careServicesRequest/otherID/@position}"
code="{$id/@code}"
assigningAuthorityName="{$id/@assigningAuthorityName}">{string($id)}</otherID>
else
()
,
$facility/record
)}
</facility>
else ()
return csd_bl:wrap_facilities($facs2)
facility_read_service
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $facs0 := if (exists($careServicesRequest/organization/@entityID)) then /CSD/providerDirectory/* else ()
let $facs1 := if (exists($careServicesRequest/organization/service/@position)) then $facs0 else ()
let $facs2 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($facs1,$careServicesRequest/id) else ()
let $facs3 :=
if (count($facs2) = 1)
then
let $facility := $facs2[1]
return
<facility entityID="{$facility/@entityID}">
{
if (exists($careServicesRequest/organization/@entityID) and exists($careServicesRequest/organization/service/@position))
then
<organizations>
<organization entityID="{$careServicesRequest/organization/@entityID}">
{
for $srvc in $facility/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]/service[position() = $careServicesRequest/organization/service/@position]
return <service position="{$careServicesRequest/organization/service/@position}" entityID="{$srvc/@entityID}">{$srvc/*}</service>
}
</organization>
</organizations>
else
()
}
{$facility/record}
</facility>
else ()
return csd_bl:wrap_facilities($facs3)
health_worker_get_urns
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else /CSD/providerDirectory/*
let $provs1 := if (exists($careServicesRequest/otherID)) then csd_bl:filter_by_other_id($provs0,$careServicesRequest/otherID) else $provs0
let $provs2 := if (exists($careServicesRequest/commonName)) then csd_bl:filter_by_common_name($provs1,$careServicesRequest/commonName) else $provs1
let $provs3 := if (exists($careServicesRequest/codedType)) then csd_bl:filter_by_coded_type($provs2,$careServicesRequest/codedType) else $provs2
let $provs4 := if (exists($careServicesRequest/address/addressLine)) then csd_bl:filter_by_address($provs3, $careServicesRequest/address/addressLine) else $provs3
let $provs5 := if (exists($careServicesRequest/record)) then csd_bl:filter_by_record($provs4,$careServicesRequest/record) else $provs4
let $provs6 := if (exists($careServicesRequest/start) and exists($careServicesRequest/max)) then csd_bl:limit_items($provs5,$careServicesRequest/start,$careServicesRequest/max) else $provs5
let $provs7 := for $entityID in $provs6/@entityID
return <provider entityID="{$entityID}"/>
return csd_bl:wrap_providers($provs7)
health_worker_indices_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<demographic>
{
for $address in $provider/demographic/address
return <address type="{$address/@type}"/>
}
</demographic>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<demographic>
{
for $cp at $pos in $provider/demographic/contactPoint
return <contactPoint position="{$pos}"/>
}
</demographic>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
{
for $cred in $provider/credential
return
<credential >{$cred/codedType}</credential>
}
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_name
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<demographic>
{
for $name at $pos in $provider/demographic/name
return <name position="{$pos}"/>
}
</demographic>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<facilities>
{
let $facs :=
if (exists($careServicesRequest/facility/@entityID))
then
$provider/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]
else $provider/facilities/facility
for $fac in $facs
return
<facility entityID="{$fac/@entityID}">
{
if ($careServicesRequest/facility/service/@position)
then
for $srvc in $fac/service[position()= $careServicesRequest/facility/service/@position]
return
<service position="{$careServicesRequest/facility/service/@position}">
{for $oh at $ohpos in $srvc/operatingHours return <operatingHours position="{$ohpos}"/>}
</service>
else
for $srvc at $spos in $fac/service
return
<service position="{$spos}">
{for $oh at $ohpos in $srvc/operatingHours return <operaingHours position="{$ohpos}"/>}
</service>
}
</facility>
}
</facilities>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_org_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<organizations>
{
let $orgs :=
if (exists($careServicesRequest/organization/@entityID))
then
$provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
else $provider/organizations/organization
for $org in $orgs
return
<organization entityID="{$org/@entityID}">
{
for $address in $org/address
return <address type="{$address/@type}"/>
}
</organization>
}
</organizations>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_org_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<organizations>
{
let $orgs :=
if (exists($careServicesRequest/organization/@entityID))
then
$provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
else $provider/organizations/organization
for $org in $orgs
return
<organization entityID="{$org/@entityID}">
{
for $cp at $pos in $org/contactPoint
return <contactPoint position="{$pos}"/>
}
</organization>
}
</organizations>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
{
for $id at $pos in $provider/otherID
return <otherID position="{$pos}"/>
}
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_provider_facility
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<facilities>
{
for $fac in $provider/facilities/facility
return
<facility entityID="{$fac/@entityID}"></facility>
}
</facilities>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_provider_organization
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<organizations>
{
for $org in $provider/organizations/organization
return
<organization entityID="{$org/@entityID}"></organization>
}
</organizations>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_indices_service
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else (/CSD/providerDirectory/*)
let $provs1:=
for $provider in $provs0
return
<provider entityID="{$provider/@entityID}">
<facilities>
{
let $facs :=
if (exists($careServicesRequest/facility/@entityID))
then
$provider/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]
else $provider/facilities/facility
for $fac in $facs
return
<facility entityID="{$fac/@entityID}">
{
for $srvc at $pos in $fac/service
return <service position="{$pos}" entityID="{$srvc/@entityID}"/>
}
</facility>
}
</facilities>
</provider>
return csd_bl:wrap_providers($provs1)
health_worker_read_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/address/@type)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
return
<provider entityID="{$provider/@entityID}">
<demographic>
{(
for $address in $provider/demographic/address[@type = $careServicesRequest/address/@type]
return $address
)}
</demographic>
{$provider/record}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/contactPoint/@position)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
return
<provider entityID="{$provider/@entityID}">
{
if (exists($careServicesRequest/contactPoint) and exists($careServicesRequest/contactPoint/@position))
then
<demographic>
{
for $cp in $provider/demographic/contactPoint[position() = $careServicesRequest/contactPoint/@position]
return <contactPoint position="{$careServicesRequest/contactPoint/@position}">{$cp/*}</contactPoint>
}
</demographic>
else
()
}
{$provider/record}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingScheme) ) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
let $code:= $careServicesRequest/credential/codedType/@code
let $codingScheme:= $careServicesRequest/credential/codedType/@codingScheme
return
<provider entityID="{$provider/@entityID}">
{
(
$provider/credential/codedType[@code = $code and @codingScheme = $codingScheme]/..
,
$provider/record
)
}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_name
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/name/@position)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
return
<provider entityID="{$provider/@entityID}">
{
if (exists($careServicesRequest/name) and exists($careServicesRequest/name/@position))
then
<demographic>
{
for $name in $provider/demographic/name[position() = $careServicesRequest/name/@position]
return <name position="{$careServicesRequest/name/@position}">{$name/*}</name>
}
</demographic>
else
()
}
{$provider/record}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/facility/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/facility/service/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/facility/service/operatingHours/@position)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs2,$careServicesRequest/id) else ()
let $srvc := $provs3[1]/facilities/facility[upper-case(@entityID) =upper-case($careServicesRequest/facility/@entityID)]/service[position() = $careServicesRequest/facility/service/@position]
let $provs4:=
if (count($srvc) = 1)
then
let $oh := $srvc/operatingHours[position() = $careServicesRequest/facility/service/operatingHours/@position]
return <provider entityID="{$careServicesRequest/id/@entityID}">
<facilities>
<facility entityID="{$careServicesRequest/facility/@entityID}">
<service position="{$careServicesRequest/facility/service/@position}" >
<operatingHours position="{$careServicesRequest/facility/service/operatingHours/@position}">{$oh/*}</operatingHours>
</service>
</facility>
</facilities>
{$careServicesRequest}
</provider>
else ()
return csd_bl:wrap_providers($provs4)
health_worker_read_org_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/organization/@entityID) and exists($careServicesRequest/organization/address/@type)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
return
<provider entityID="{$provider/@entityID}">
<organizations>
<organization entityID="{$careServicesRequest/organization/@entityID}">
{
$provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]/address[@type = $careServicesRequest/organization/address/@type]
}
</organization>
</organizations>
{$provider/record}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_org_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/organization/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/organization/contactPoint/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs1,$careServicesRequest/id) else ()
let $provs3 :=
if (count($provs2) = 1)
then
let $provider := $provs2[1]
return
<provider entityID="{$provider/@entityID}">
{
if (exists($careServicesRequest/organization/@entityID) and exists($careServicesRequest/organization/contactPoint/@position))
then
<organizations>
<organization entityID="{$careServicesRequest/organization/@entityID}">
{
for $cp in $provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]/contactPoint[position() = $careServicesRequest/organization/contactPoint/@position]
return <contactPoint position="{$careServicesRequest/organization/contactPoint/@position}">{$cp/*}</contactPoint>
}
</organization>
</organizations>
else
()
}
{$provider/record}
</provider>
else ()
return csd_bl:wrap_providers($provs3)
health_worker_read_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/otherID/@position)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
return
<provider entityID="{$provider/@entityID}">
{(
if (exists($careServicesRequest/otherID/@position))
then
for $id in $provider/otherID[position() = $careServicesRequest/otherID/@position]
return
<otherID
position="{$careServicesRequest/otherID/@position}"
code="{$id/@code}"
assigningAuthorityName="{$id/@assigningAuthorityName}">{string($id)}</otherID>
else
()
,
$provider/record
)}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_otherids
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/otherID/@position)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
let $other_ids :=
if ($careServicesRequest/code/text())
then $provider/otherID[@code = $careServicesRequest/code/text()]
else $provider/otherID
return
<provider entityID="{$provider/@entityID}">
{(
$other_ids
,
$provider/record
)}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_otherids_json
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id( /CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provider := $provs1[1]
let $other_ids :=
if ($careServicesRequest/code/text())
then $provider/otherID[@code = $careServicesRequest/code/text()]
else $provider/otherID
let $xml:=
<json type="object">
<entityID>{string($provider/@entityID)}</entityID>
<otherID type="array">
{
for $id in $other_ids
return
<_ type='object'>
<code>{string($id/@code)}</code>
<authority>{string($id/@assigningAuthorityName)}</authority>
<value>{$id/text()}</value>
</_>
}
</otherID>
</json>
return json:serialize($xml,map{"format":"direct"})
health_worker_read_provider
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then
let $prov := $provs0[1]
return
<provider entityID="{$prov/@entityID}">
{(
$prov/codedType,
<demographic>
{(
if (exists($prov/demographic/gender)) then $prov/demographic/gender else (),
if (exists($prov/demographic/dateOfBirth)) then $prov/demographic/dateOfBirth else ()
)}
</demographic>,
$prov/language,
$prov/specialty,
$prov/record
)}
</provider>
else ()
return csd_bl:wrap_providers($provs1)
health_worker_read_provider_facility
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/facility/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
return
<provider entityID="{$provider/@entityID}">
{
(
<facilities>
{
for $fac in $provider/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID) ]
return
<facility entityID="{$fac/@entityID}"></facility>
}
</facilities>
,
$provider/record
)
}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_provider_organization
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/organization/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $provs2 :=
if (count($provs1) = 1)
then
let $provider := $provs1[1]
return
<provider entityID="{$provider/@entityID}">
{
(
<organizations>
{
for $org in $provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID ) ]
return
<organization entityID="{$org/@entityID}"></organization>
}
</organizations>
,
$provider/record
)
}
</provider>
else ()
return csd_bl:wrap_providers($provs2)
health_worker_read_service
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/facility/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/facility/service/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs1,$careServicesRequest/id) else ()
let $provs3 :=
if (count($provs2) = 1)
then
let $provider := $provs2[1]
return
<provider entityID="{$provider/@entityID}">
{
if (exists($careServicesRequest/facility/@entityID) and exists($careServicesRequest/facility/service/@position))
then
<facilities>
<facility entityID="{$careServicesRequest/facility/@entityID}">
{
for $srvc in $provider/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]/service[position() = $careServicesRequest/facility/service/@position]
return <service position="{$careServicesRequest/facility/service/@position}" entityID="{$srvc/@entityID}">{$srvc/*}</service>
}
</facility>
</facilities>
else
()
}
{$provider/record}
</provider>
else ()
return csd_bl:wrap_providers($provs3)
health_worker_urn_search_by_id
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/otherID)) then csd_bl:filter_by_other_id(/CSD/providerDirectory/*,$careServicesRequest/otherID) else ()
let $provs1 := if (exists($careServicesRequest/start) and exists($careServicesRequest/max)) then csd_bl:limit_items($provs0,$careServicesRequest/start,$careServicesRequest/max) else $provs0
let $provs2:= for $entityID in $provs1/@entityID
return <provider entityID="{$entityID}"/>
return csd_bl:wrap_providers($provs2)
organization_get_urns
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/id)) then csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id) else /CSD/organizationDirectory/*
let $orgs1 := if (exists($careServicesRequest/otherID)) then csd_bl:filter_by_other_id($orgs0,$careServicesRequest/otherID) else $orgs0
let $orgs2 := if (exists($careServicesRequest/codedType)) then csd_bl:filter_by_coded_type($orgs1,$careServicesRequest/codedType) else $orgs1
let $orgs3 := if (exists($careServicesRequest/address/addressLine)) then csd_bl:filter_by_address($orgs2, $careServicesRequest/address/addressLine) else $orgs2
let $orgs4 := if (exists($careServicesRequest/record)) then csd_bl:filter_by_record($orgs3,$careServicesRequest/record) else $orgs3
let $orgs5 := if (exists($careServicesRequest/start) and exists($careServicesRequest/max)) then csd_bl:limit_items($orgs4,$careServicesRequest/start,$careServicesRequest/max) else $orgs4
let $orgs6 := for $entityID in $orgs5/@entityID
return <organization entityID="{$entityID}"/>
return csd_bl:wrap_organizations(($orgs6))
organization_indices_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id)
else (/CSD/organizationDirectory/*)
let $orgs1:=
for $organization in $orgs0
return
<organization entityID="{$organization/@entityID}">
{
for $address in $organization/address
return <address type="{$address/@type}"/>
}
</organization>
return csd_bl:wrap_organizations($orgs1)
organization_indices_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id)
else (/CSD/organizationDirectory/*)
let $orgs1:=
for $organization in $orgs0
return
<organization entityID="{$organization/@entityID}">
{
for $cp at $pos in $organization/contactPoint
return <contactPoint position="{$pos}"/>
}
</organization>
return csd_bl:wrap_organizations($orgs1)
organization_indices_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id)
else (/CSD/organizationDirectory/*)
let $orgs1:=
for $organization in $orgs0
return
<organization entityID="{$organization/@entityID}">
{
for $cred in $organization/credential
return
<credential >{$cred/codedType}</credential>
}
</organization>
return csd_bl:wrap_organizations($orgs1)
organization_indices_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 :=
if (exists($careServicesRequest/id/@entityID)) then
csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id)
else (/CSD/organizationDirectory/*)
let $orgs1:=
for $organization in $orgs0
return
<organization entityID="{$organization/@entityID}">
{
for $id at $pos in $organization/otherID
return <otherID position="{$pos}"/>
}
</organization>
return csd_bl:wrap_organizations($orgs1)
Performs a search for all organizations by name, coded type, address or ID.
The result set consists of the primary name of all organizations matching the search parameters ( id, primaryName, name, codedType and address ).
The results set may be further restricted according to the limit parameters (start, max, record/@status and record/@updated). An ordering of the result set is not specified.
Response
Results are returned as a valid CSD document with a root document element of <CSD/>. The results set is contained entirely within the <organizationDirectory/> element and consists of the full content of the <organization/> elements of matching organizations as maintained by the Care Services InfoManager.
Parameters Query
Parameters are defined as the content of following elements:
<id/> csd:uniqueID: (optional) If present and the @urn attribute contains a non-empty value, it is a ID which uniquely identifies an organization. This is an exact match.
<primaryName/> xs:string: (optional) If present and contains a non-empty value, then the result set should be restricted to those organizations whose <primaryName/> contains this value. Case insensitive.
<name/> xs:string: (optional) If present and contains a non-empty value, then the result set should be restricted to those organizations which have a <primaryName/> or <otherName/> element containing this value. Case insensitive.
<codedType/> csd:codedtype: If present and contains a non-empty value the result set should be restricted to those organizations whose <codedType/@code> equals this value for the coding schema specified by the @codingSchema attribute. Case insensitive.
<address/> csd:address: (optional) Contains of any-number of child <addressLine/> elements as follows:
Text content xs:string: (optional) If present and contains a non-empty value, then the results set should be restricted to those organizations whose have an <addressLine/> with specified @component containing this value exactly. Case insensitive.
@component xs:string : (Required attribute) The component of the address we are searching. Case insensitive.
<start/> xs:int: (optional) The starting index for results returned. Defaults to 1, which indexes the first organization matching the search parameters
<max/> xs:int: (optional) The maximum number of results returned. A value of less than zero implies no maximum.
<record/> csd:record : (optional) A child element to limit results according to
@status xs:string: (optional) If present and contains a non-empty value, the result set should be restricted to those organizations whose record/@status equals this value. Case insensitive.
@updated xs:dateTime: (optional) If present and contains a non-empty value, the result set should be restricted to those organizations whose record/@updated is at least the given value.
Example Request
<careServicesRequest>
<function uuid='dc6aedf0-f609-11e2-b778-0800200c9a66'>
<codedType codingSchema="moh.gov.rw" code="FBO" />
<address>
<addressLine component='city'>Kigali</addressLine>
</address>
<max>5</max>
</function>
</careServicesRequest>
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
<CSD xmlns:csd="urn:ihe:iti:csd:2013" >
<organizationDirectory>
{
let $orgs0 := if (exists($careServicesRequest/id))
then csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id)
else /CSD/organizationDirectory/*
let $orgs1 := if (exists($careServicesRequest/primaryName))
then csd_bl:filter_by_primary_name($orgs0,$careServicesRequest/primaryName)
else $orgs0
let $orgs2 := if(exists($careServicesRequest/name))
then csd_bl:filter_by_name($orgs1,$careServicesRequest/name)
else $orgs1
let $orgs3 := if(exists($careServicesRequest/codedType))
then csd_bl:filter_by_coded_type($orgs2,$careServicesRequest/codedType)
else $orgs2
let $orgs4 :=if (exists($careServicesRequest/address/addressLine))
then csd_bl:filter_by_address($orgs3, $careServicesRequest/address/addressLine)
else $orgs3
let $orgs5 := if (exists($careServicesRequest/record))
then csd_bl:filter_by_record($orgs4,$careServicesRequest/record)
else $orgs4
let $orgs6 := if (exists($careServicesRequest/otherID))
then csd_bl:filter_by_other_id($orgs5,$careServicesRequest/otherID)
else $orgs5
let $orgs7 := if (exists($careServicesRequest/start)) then
if (exists($careServicesRequest/max))
then csd_bl:limit_items($orgs6,$careServicesRequest/start,$careServicesRequest/max)
else csd_bl:limit_items($orgs6,$careServicesRequest/start,<max/>)
else
if (exists($careServicesRequest/max))
then csd_bl:limit_items($orgs6,<start/>,$careServicesRequest/max)
else $orgs6
return for $org in $orgs7
return<organization urn='{$org/@urn}'>
{$org/primaryName}
</organization>
}
</organizationDirectory>
<serviceDirectory/>
<facilityDirectory/>
<providerDirectory/>
</CSD>
facilty_read_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/address/@type)) then /CSD/organizationDirectory/* else ()
let $orgs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($orgs0,$careServicesRequest/id) else ()
let $orgs2 :=
if (count($orgs1) = 1)
then
let $organization := $orgs1[1]
return
<organization entityID="{$organization/@entityID}">
{(
for $address in $organization/address[@type = $careServicesRequest/address/@type]
return $address
)}
{$organization/record}
</organization>
else ()
return csd_bl:wrap_organizations($orgs2)
organization_read_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/contactPoint/@position)) then /CSD/organizationDirectory/* else ()
let $orgs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($orgs0,$careServicesRequest/id) else ()
let $orgs2 :=
if (count($orgs1) = 1)
then
let $organization := $orgs1[1]
return
<organization entityID="{$organization/@entityID}">
{
if (exists($careServicesRequest/contactPoint) and exists($careServicesRequest/contactPoint/@position))
then
for $cp in $organization/contactPoint[position() = $careServicesRequest/contactPoint/@position]
return <contactPoint position="{$careServicesRequest/contactPoint/@position}">{$cp/*}</contactPoint>
else
()
}
{$organization/record}
</organization>
else ()
return csd_bl:wrap_organizations($orgs2)
organization_read_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingScheme) ) then /CSD/organizationDirectory/* else ()
let $orgs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($orgs0,$careServicesRequest/id) else ()
let $orgs2 :=
if (count($orgs1) = 1)
then
let $organization := $orgs1[1]
let $code:= $careServicesRequest/credential/codedType/@code
let $codingScheme:= $careServicesRequest/credential/codedType/@codingScheme
return
<organization entityID="{$organization/@entityID}">
{
(
$organization/credential/codedType[@code = $code and @codingScheme = $codingScheme]/..
,
$organization/record
)
}
</organization>
else ()
return csd_bl:wrap_organizations($orgs2)
organization_read_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/otherID/@position)) then /CSD/organizationDirectory/* else ()
let $orgs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($orgs0,$careServicesRequest/id) else ()
let $orgs2 :=
if (count($orgs1) = 1)
then
let $organization := $orgs1[1]
return
<organization entityID="{$organization/@entityID}">
{(
if (exists($careServicesRequest/otherID/@position))
then
for $id in $organization/otherID[position() = $careServicesRequest/otherID/@position]
return
<otherID
position="{$careServicesRequest/otherID/@position}"
code="{$id/@code}"
assigningAuthorityName="{$id/@assigningAuthorityName}">{string($id)}</otherID>
else
()
,
$organization/record
)}
</organization>
else ()
return csd_bl:wrap_organizations($orgs2)
Performs a search for all providers by name, coded type, address or ID.
The result set consists of all names providers matching the search parameters ( id,
otherID, commonName,codedType and address ).
The results set may be further restricted according to the limit parameters
(start, max, record/@status and record/@updated). An ordering of
the result set is not specified.
Response Results are returned as a valid CSD document with a root document element of
<CSD/>. The results set is contained entirely within the <providerDirectory/>
element and consists of the full content of the <provider/> elements of matching
providers as maintained by the Care Services InfoManager.
Parameters Query Parameters are defined as the content of following elements:
<id/> csd:uniqueID: (optional) If present and the @urn attribute contains a
non-empty value, it is a ID which uniquely identifies a provider. This is an exact match.
<otherID/> csd:otherID: (optional) If present and the
@assigningAuthorityName attribute contains a non-empty value, then the result set is
restricted to only those providers which have a <otherID/> with the given
assigingAuthorityName and @code <commonName/> xsd:string: (optional)
If present and contains a non-empty value, then the result set should be restricted to those
providers which have a <demographic/name/commonName/> containing this value. Case
insensitive.
<codedType/> csd:codedtype: If present and contains a non-empty value the
result set should be restricted to those providers whose <codeType/@code> equals this
value for the coding schema specified by the @codingSchema attribute. Case insensitive.
<address/> csd:address: (optional) Contains of any-number of child
<addressLine/> elements as follows:
Text content xsd:string: (optional) If present and contains a non-empty value,
then the results set should be restricted to those providers whose have an
<addressLine/> with specified @component containing this value exactly. Case
insensitive.
@component xsd:string : (Required attribute) The component of the address we
are searching. Case insensitive.
<start/> xsd:int: (optional) The starting index for results returned.
Defaults to 1, which indexes the first provider matching the search parameters
<max/> xsd:int: (optional) The maximum number of results returned. A value
of less than zero implies no maximum.
<record/> csd:record : (optional) A child element to limit results
according to
@status xsd:string: (optional) If present and contains a non-empty value, the
result set should be restricted to those providers whose record/@status equals this
value. Case insensitive.
@updated xsd:dateTime: (optional) If present and contains a non-empty value,
the result set should be restricted to those providers whose record/@updated is at least
the given value.
Example Request
<careServicesRequest>
<function uuid='4e8bbeb9-f5f5-11e2-b778-0800200c9a66'>
<codedType code="2221" codingSchema="ISCO-08" /<
<address>
<addressLine component='city'>Kigali</addressLine>
</address>
<max>5</max>
</function>
</careServicesRequest>
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
<CSD xmlns:csd="urn:ihe:iti:csd:2013" >
<organizationDirectory/>
<serviceDirectory/>
<facilityDirectory/>
<providerDirectory>
{
let $provs0 := if (exists($careServicesRequest/id))
then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id)
else /CSD/providerDirectory/*
let $provs1 := if(exists($careServicesRequest/otherID))
then csd_bl:filter_by_other_id($provs0,$careServicesRequest/otherID)
else $provs0
let $provs2 := if(exists($careServicesRequest/commonName))
then csd_bl:filter_by_common_name($provs1,$careServicesRequest/commonName)
else $provs1
let $provs3 := if (exists($careServicesRequest/codedType))
then csd_bl:filter_by_coded_type($provs2,$careServicesRequest/codedType)
else $provs2
let $provs4 := if (exists($careServicesRequest/address/addressLine))
then csd_bl:filter_by_demographic_address($provs3, $careServicesRequest/address/addressLine)
else $provs3
let $provs5 := if (exists($careServicesRequest/record))
then csd_bl:filter_by_record($provs4,$careServicesRequest/record)
else $provs4
let $provs6:= if (exists($careServicesRequest/start)) then
if (exists($careServicesRequest/max))
then csd_bl:limit_items($provs5,$careServicesRequest/start,$careServicesRequest/max)
else csd_bl:limit_items($provs5,$careServicesRequest/start,<max/>)
else
if (exists($careServicesRequest/max))
then csd_bl:limit_items($provs5,<start/>,$careServicesRequest/max)
else $provs5
return
for $prov in $provs6
return
<provider entityID='{$prov/@entityID}'>
<demogrpahic>
{$prov/demographic/name}
</demogrpahic>
</provider>
}
</providerDirectory>
</CSD>
service_get_urns
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $srvcs0 := if (exists($careServicesRequest/id)) then csd_bl:filter_by_primary_id(/CSD/serviceDirectory/*,$careServicesRequest/id) else /CSD/serviceDirectory/*
let $srvcs1 := if (exists($careServicesRequest/codedType)) then csd_bl:filter_by_coded_type($srvcs0,$careServicesRequest/codedType) else $srvcs0
let $srvcs2 := if (exists($careServicesRequest/record)) then csd_bl:filter_by_record($srvcs1,$careServicesRequest/record) else $srvcs1
let $srvcs3 := if (exists($careServicesRequest/start) and exists($careServicesRequest/max)) then csd_bl:limit_items($srvcs2,$careServicesRequest/start,$careServicesRequest/max) else $srvcs2
let $srvcs4 := for $entityID in $srvcs3/@entityID
return <service entityID="{$entityID}"/>
return csd_bl:wrap_services(($srvcs4))
facility_create_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/address/@type)) then $fac1 else ()
return
if ( count($fac2) = 1 )
then
let $facility:= $fac2[1]
return
let $fac3:=
<facility entityID="{$facility/@entityID}">
<address type="{$careServicesRequest/address/@type}"/>
</facility>
return (
insert node
$careServicesRequest/address
into $facility
,
csd_blu:wrap_updating_facilities($fac3)
)
else csd_blu:wrap_updating_facilities(())
facility_create_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/contactPoint)) then $fac1 else ()
return
if ( count($fac2) = 1 )
then
let $facility:= $fac2[1]
let $position := count($facility/contactPoint) +1
let $cp :=
<contactPoint>
{(
if (exists($careServicesRequest/contactPoint/codedType)) then $careServicesRequest/contactPoint/codedType else (),
if (exists($careServicesRequest/contactPoint/equipment)) then $careServicesRequest/contactPoint/equipment else (),
if (exists($careServicesRequest/contactPoint/purpose)) then $careServicesRequest/contactPoint/purpose else (),
if (exists($careServicesRequest/contactPoint/certificate)) then $careServicesRequest/contactPoint/certificate else ()
)}
</contactPoint>
let $fac3:=
<facility entityID="{$facility/@entityID}">
<contactPoint position="{$position}"/>
</facility>
return
(insert node $cp into $facility ,
csd_blu:wrap_updating_facilities($fac3)
)
else csd_blu:wrap_updating_facilities(())
facility_create_geocode
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/geocode) and count($fac1/geocode) = 0) then $fac1 else ()
return
if ( count($fac2) = 1 )
then
let $facility:= $fac2[1]
return
let $fac3:=
<facility entityID="{$facility/@entityID}">
<geocode/>
</facility>
return (
insert node
$careServicesRequest/geocode
into $facility
,
csd_blu:wrap_updating_facilities($fac3)
)
else csd_blu:wrap_updating_facilities(())
facility_create_language
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/language/@code) and exists($careServicesRequest/language/@codingScheme)) then $fac1 else ()
let $lang0 := $fac2/language[@code = $careServicesRequest/language/@code and @codingScheme = $fac2/language/@codingScheme]
return
if ( count($fac2) = 1 and count($lang0) = 0)
then
let $facility:= $fac2[1]
return
let $fac3:=
<facility entityID="{$facility/@entityID}">
<language code="{$careServicesRequest/language/@code}" codingScheme="{$careServicesRequest/language/@codingScheme}"/>
</facility>
return (
insert node
$careServicesRequest/language
into $facility
,
csd_blu:wrap_updating_facilities($fac3)
)
else csd_blu:wrap_updating_facilities(())
facility_create_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/operatingHours)) then $fac1 else ()
return
if ( count($fac2) = 1 )
then
let $facility:= $fac2[1]
return
let $fac3:=
<facility entityID="{$facility/@entityID}">
<operatingHours/>
</facility>
return (
insert node
$careServicesRequest/operatingHours
into $facility
,
csd_blu:wrap_updating_facilities($fac3)
)
else csd_blu:wrap_updating_facilities(())
facility_create_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/otherID/@code)) then $fac1 else ()
return
if ( count($fac2) = 1 )
then
let $facility:= $fac2[1]
let $position := count($facility/otherID) +1
let $id :=
if (exists($careServicesRequest/otherID/@assigningAuthorityName)) then
<otherID code="{$careServicesRequest/otherID/@code}" assigningAuthorityName="{$careServicesRequest/otherID/@assigningAuthorityName}">{string($careServicesRequest/otherID)}</otherID>
else
<otherID code="{$careServicesRequest/otherID/@code}">{string($careServicesRequest/otherID)}</otherID>
let $fac3:=
<facility entityID="{$facility/@entityID}">
<otherID position="{$position}"/>
</facility>
return
(insert node $id into $facility ,
csd_blu:wrap_updating_facilities($fac3)
)
else csd_blu:wrap_updating_facilities(())
facility_delete_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/address/@type)) then $fac1 else ()
let $address:= $fac2[1]/address[@type = $careServicesRequest/address/@type]
return
let $fac:=
<facility entityID="{$fac2/@entityID}">
<address type="{$careServicesRequest/address/@type}"/>
</facility>
return (
if (exists($address)) then (delete node $address) else ()
,
csd_blu:wrap_updating_facilities($fac)
)
facility_delete_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/contactPoint/@position))
then
let $facilities := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
return
if ( count($facilities) = 1 )
then
let $cp := $facilities[1]/contactPoint[position() = $careServicesRequest/contactPoint/@position]
return if (exists($cp)) then (delete node $cp) else ()
else ()
else ()
facility_delete_geocode
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/geocode)) then $fac1 else ()
let $geocode:= $fac2[1]/geocode
return
let $fac:=
<facility entityID="{$fac2/@entityID}">
<geocode/>
</facility>
return (
if (exists($geocode)) then (delete node $geocode) else ()
,
csd_blu:wrap_updating_facilities($fac)
)
facility_delete_language
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/language/@code)) then $fac1 else ()
let $language:= $fac2[1]/language[@code = $careServicesRequest/language/@code]
return
let $fac:=
<facility entityID="{$fac2/@entityID}">
<language code="{$careServicesRequest/language/@code}"/>
</facility>
return (
if (exists($language)) then (delete node $language) else ()
,
csd_blu:wrap_updating_facilities($fac)
)
facility_delete_name
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/primaryName/@position))
then
let $facilities := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
return
if ( count($facilities) = 1 )
then
let $name := $facilities[1]/primaryName[position() = $careServicesRequest/primaryName/@position]
return if (exists($name)) then (delete node $name) else ()
else ()
else ()
facility_delete_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/organization/@entityID)) then /CSD/facilityDirectory/* else ()
let $fac1 := if (exists($careServicesRequest/organization/service/@position)) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/organization/service/operatingHours/@position)) then $fac1 else ()
let $fac3 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($fac2,$careServicesRequest/id) else ()
let $oh := $fac3[1]/organizations/organization[upper-case(@entityID) =upper-case($careServicesRequest/organization/@entityID)]/service[position() = $careServicesRequest/organization/service/@position]/operatingHours[position() = $careServicesRequest/organization/service/operatingHours/@position]
return
if (count($oh) = 1)
then (delete node $oh) else ()
facility_delete_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu" ;
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/otherID/@position))
then
let $facilities := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
return
if ( count($facilities) = 1 )
then
let $id := $facilities[1]/otherID[position() = $careServicesRequest/otherID/@position]
return if (exists($id)) then (delete node $id) else ()
else ()
else ()
facility_update_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/address/@type)) then $fac1 else ()
let $facility:= $fac2[1]
let $address:= $facility/address[@type = $careServicesRequest/address/@type]
return
if ( not(exists($address))) then
csd_blu:wrap_updating_facilities(()) (: Address does not exist. Do not update:)
else
let $fac3:=
<facility entityID="{$facility/@entityID}">
<address type="{$careServicesRequest/address/@type}"/>
</facility>
return (
csd_blu:bump_timestamp($facility),
replace node $address with $careServicesRequest/address
,
csd_blu:wrap_updating_facilities($fac3)
)
facility_update_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/contactPoint/@position)) then /CSD/facilityDirectory/* else ()
let $fac1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($fac0,$careServicesRequest/id) else ()
let $old_cp := $fac1[1]/contactPoint[position() = $careServicesRequest/contactPoint/@position]
return
if (count($fac1) = 1 and exists($old_cp))
then
let $new_cp := $careServicesRequest/contactPoint
let $fac2 :=
<facility entityID="{$fac1[1]/@entityID}">
<contactPoint position="{$careServicesRequest/contactPoint/@position}"/>
</facility>
return
(
csd_blu:bump_timestamp($fac1[1]),
if (exists($new_cp/codedType)) then (delete node $old_cp/codedType,insert node $new_cp/codedType into $old_cp) else (),
if (exists($new_cp/equipment)) then (delete node $old_cp/equipment,insert node $new_cp/equipment into $old_cp) else (),
if (exists($new_cp/purpose)) then (delete node $old_cp/purpose,insert node $new_cp/purpose into $old_cp) else (),
if (exists($new_cp/certificate)) then (delete node $old_cp/certificate,insert node $new_cp/certificate into $old_cp) else (),
csd_blu:wrap_updating_facilities($fac2)
)
else csd_blu:wrap_updating_facilities(())
facility_update_name
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/primaryName/@position)) then /CSD/facilityDirectory/* else ()
let $fac1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($fac0,$careServicesRequest/id) else ()
let $name := $fac1[1]/primaryName[position() = $careServicesRequest/primaryName/@position]
return
if (count($fac1) = 1 and exists($name))
then
let $fac2 :=
<facility entityID="{$fac1[1]/@entityID}">
<name position="{$careServicesRequest/primaryName/@position}"/>
</facility>
let $new_name := $careServicesRequest/primaryName
return
(
csd_blu:bump_timestamp($fac1[1]),
replace node $name with $new_name,
csd_blu:wrap_updating_facilities($fac2)
)
else csd_blu:wrap_updating_facilities(())
facility_update_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/organization/@entityID)) then /CSD/facilityDirectory/* else ()
let $fac1 := if (exists($careServicesRequest/organization/service/@position)) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/organization/service/operatingHours/@position)) then $fac1 else ()
let $fac3 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($fac2,$careServicesRequest/id) else ()
let $oh := $fac3[1]/organizations/organization[upper-case(@entityID) =upper-case($careServicesRequest/organization/@entityID)]/service[position() = $careServicesRequest/organization/service/@position]/operatingHours[position() = $careServicesRequest/organization/service/operatingHours/@position]
return
if (count($oh) = 1 and count($fac3) = 1)
then
let $new_oh := $careServicesRequest/organization/service/operatingHours
let $fac4 :=
<facility entityID="{$fac1[1]/@entityID}">
<organizations>
<organization entityID="{$careServicesRequest/organization/@entityID}">
<service position="{$careServicesRequest/organization/service/@position}" >
<operatingHours position="{$careServicesRequest/organization/service/operatingHours/@position}"/>
</service>
</organization>
</organizations>
</facility>
return
(
csd_blu:bump_timestamp($fac3[1]),
if (exists($new_oh/openFlag)) then (delete node $oh/openFlag,insert node $new_oh/openFlag into $oh) else (),
if (exists($new_oh/dayOfTheWeek)) then (delete node $oh/dayOfTheWeek,insert node $new_oh/dayOfTheWeek into $oh) else (),
if (exists($new_oh/beginningHour)) then (delete node $oh/beginningHour,insert node $new_oh/beginningHour into $oh) else (),
if (exists($new_oh/endingHour)) then (delete node $oh/endingHour,insert node $new_oh/endingHour into $oh) else (),
if (exists($new_oh/beginEffectiveDate)) then (delete node $oh/beginEffectiveDate,insert node $new_oh/beginEffectiveDate into $oh) else (),
if (exists($new_oh/endEffectiveDate)) then (delete node $oh/endEffectiveDate,insert node $new_oh/endEffectiveDate into $oh) else (),
csd_blu:wrap_updating_facilities($fac4)
)
else csd_blu:wrap_updating_facilities(())
facility_update_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/otherID)) then /CSD/facilityDirectory/* else ()
let $fac1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($fac0,$careServicesRequest/id) else ()
let $id := $fac1[1]/otherID[position() = $careServicesRequest/otherID/@position]
return
if (count($fac1) = 1 and exists($id))
then
let $fac2 :=
<facility entityID="{$fac1[1]/@entityID}">
<otherID position="{$careServicesRequest/otherID/@position}"/>
</facility>
return
(
csd_blu:bump_timestamp($fac1[1]),
if ($careServicesRequest/otherID/@code)
then
if (exists($id/@code))
then (replace value of node $id/@code with $careServicesRequest/otherID/@code)
else (insert node $careServicesRequest/otherID/@code into $id)
else (),
if (exists($careServicesRequest/otherID/@assigningAuthorityName) )
then
if (exists($id/@assigningAuthorityName))
then replace value of node $id/@assigningAuthorityName with $careServicesRequest/otherID/@assigningAuthorityName
else insert node $careServicesRequest/otherID/@assigningAuthorityName into $id
else (),
if (not(string($careServicesRequest/otherID) = ''))
then (replace value of node $id with string($careServicesRequest/otherID))
else (),
csd_blu:wrap_updating_facilities($fac2)
)
else csd_blu:wrap_updating_facilities(())
health_worker_create_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/address/@type)) then $provs1 else ()
return
if ( count($provs2) = 1 )
then
let $provider:= $provs2[1]
let $demo := $provider/demographic
return if (exists($demo/address[@type = $careServicesRequest/address/@type]))
then
csd_blu:wrap_updating_providers(()) (: Do not allow the same type to be created more than once:)
else
let $provs3:=
<provider entityID="{$provider/@entityID}">
<demographic><address type="{$careServicesRequest/address/@type}"/></demographic>
</provider>
return (
if (not(exists($demo)))
then
insert node
<demographic>{$careServicesRequest/address}</demographic>
into $provider
else
insert node $careServicesRequest/address into $demo
,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/contactPoint)) then $provs1 else ()
return
if ( count($provs2) = 1 )
then
let $provider:= $provs2[1]
let $position := count($provider/demographic/contactPoint) +1
let $cp :=
<contactPoint>
{(
if (exists($careServicesRequest/contactPoint/codedType)) then $careServicesRequest/contactPoint/codedType else (),
if (exists($careServicesRequest/contactPoint/equipment)) then $careServicesRequest/contactPoint/equipment else (),
if (exists($careServicesRequest/contactPoint/purpose)) then $careServicesRequest/contactPoint/purpose else (),
if (exists($careServicesRequest/contactPoint/certificate)) then $careServicesRequest/contactPoint/certificate else ()
)}
</contactPoint>
let $provs3:=
<provider entityID="{$provider/@entityID}">
<demographic>
<contactPoint position="{$position}"/>
</demographic>
</provider>
return
(insert node $cp into $provider/demographic ,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingScheme) ) then $provs1 else ()
let $cred_request := $careServicesRequest/credential
let $code:= $cred_request/codedType/@code
let $codingScheme:= $cred_request/codedType/@codingScheme
let $creds0 := $provs2/credential/codedType[@code = $code and @codingScheme = $codingScheme]
return
if ( count($provs2) = 1 and count($creds0) = 0) (:DO NOT ALLOW SAME CRED TWICE :)
then
let $provider:= $provs2[1]
let $cred_rec :=
<credential>
<codedType code="{$code}" codingScheme="{$codingScheme}"/>
</credential>
let $cred_new :=
<credential>
<codedType code="{$code}" codingScheme="{$codingScheme}"/>
{(
if (exists($cred_request/number)) then $cred_request/number else (),
if (exists($cred_request/issuingAuthority)) then $cred_request/issuingAuthority else (),
if (exists($cred_request/credentialIssueDate)) then $cred_request/credentialIssueDate else (),
if (exists($cred_request/credentialRenewalDate)) then $cred_request/credentialRenewalDate else ()
)}
</credential>
let $provs3:=
<provider entityID="{$provider/@entityID}">{$cred_rec}</provider>
return
(
insert node $cred_new into $provider,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_name
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/name)) then $provs1 else ()
return
if ( count($provs2) = 1 )
then
let $provider:= $provs2[1]
let $position := count($provider/demographic/name) +1
let $provs3:=
<provider entityID="{$provider/@entityID}">
<demographic>
<name position="{$position}"/>
</demographic>
</provider>
return
(
if (exists($provider/demographic))
then insert node $careServicesRequest/name into $provider/demographic
else
insert node <demographic>{$careServicesRequest/name}</demographic> into $provider
, csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/facility/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/facility/service/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/facility/service/operatingHours)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs2,$careServicesRequest/id) else ()
let $srvc := $provs3[1]/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]/service[position() = $careServicesRequest/facility/service/@position]
return if (count($srvc) = 1)
then
let $position := count($srvc/operatingHours)
let $provs4:=
<provider entityID="{$careServicesRequest/id/@entityID}">
<facilities>
<facility entityID="{$careServicesRequest/facility/@entityID}">
<service position="{$careServicesRequest/facility/service/@position}" entityID="{$careServicesRequest/facility/service/@entityID}">
<operatingHours position="{$position}" />
</service>
</facility>
</facilities>
</provider>
return
(insert node $careServicesRequest/facility/service/operatingHours into $srvc[1] ,
csd_blu:wrap_updating_providers($provs4)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_org_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/organization/@entityID)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/organization/address/@type)) then $provs2 else ()
let $provider:= $provs3[1]
let $orgs := $provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
let $org := if(count($orgs) =1) then $orgs[1] else ()
let $address := $org/address[@type = $careServicesRequest/organization/address/@type]
return if (not(exists($org)) or exists($address))
then csd_blu:wrap_updating_providers(()) (:do not create an already existing one :)
else
(
insert node $careServicesRequest/organization/address into $org,
csd_blu:wrap_updating_providers(
<provider entityID="{$provider/@entityID}">
<organizations>
<organization entityID="{$org/@entityID}">
<contactPoint position="{$careServicesRequest/organization/address/@type}"/>
</organization>
</organizations>
</provider>
)
)
health_worker_create_org_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/organization/@entityID)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/organization/contactPoint)) then $provs2 else ()
return
if ( count($provs3) = 1 )
then
let $provider:= $provs3[1]
let $orgs := $provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
return
if (count($orgs) = 1)
then
let $org := $orgs[1]
let $position := count($org/contactPoint) +1
let $new_cp := $careServicesRequest/organization/contactPoint
let $cp :=
<contactPoint>
{(
if (exists($new_cp/codedType)) then $new_cp/codedType else (),
if (exists($new_cp/equipment)) then $new_cp/equipment else (),
if (exists($new_cp/purpose)) then $new_cp/purpose else (),
if (exists($new_cp/certificate)) then $new_cp/certificate else ()
)}
</contactPoint>
let $provs3:=
<provider entityID="{$provider/@entityID}">
<organizations>
<organization entityID="{$org/@entityID}">
<contactPoint position="{$position}"/>
</organization>
</organizations>
</provider>
return
(insert node $cp into $org ,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
else csd_blu:wrap_updating_providers(())
health_worker_create_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/otherID/@code)) then $provs1 else ()
return
if ( count($provs2) = 1 )
then
let $provider:= $provs2[1]
let $position := count($provider/otherID) +1
let $id :=
if (exists($careServicesRequest/otherID/@assigningAuthorityName)) then
<otherID code="{$careServicesRequest/otherID/@code}" assigningAuthorityName="{$careServicesRequest/otherID/@assigningAuthorityName}">{string($careServicesRequest/otherID)}</otherID>
else
<otherID code="{$careServicesRequest/otherID/@code}">{string($careServicesRequest/otherID)}</otherID>
let $provs3:=
<provider entityID="{$provider/@entityID}">
<otherID position="{$position}"/>
</provider>
return
(insert node $id into $provider ,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_provider
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
(:
import module namespace random = "http://basex.org/modules/random";
:)
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if (count($provs0) > 0) then (csd_blu:wrap_updating_providers(())) (:do not allow duplicate ENTITYIDs:)
else
let $entityID :=
if (exists($careServicesRequest/id/@entityID) and not($careServicesRequest/id/@entityID = '')) then $careServicesRequest/id/@entityID
else concat('urn:uuid:', random:uuid())
let $time :=current-dateTime()
let $prov :=
<provider entityID="{$entityID}">
{(
$careServicesRequest/codedType,
<demographic>
{(
$careServicesRequest/gender,
$careServicesRequest/dateOfBirth
)}
</demographic>,
$careServicesRequest/language,
$careServicesRequest/specialty,
if ($careServicesRequest/status)
then
<record created="{$time}" updated="{$time}" status="{$careServicesRequest/status}" sourceDirectory="{$careServicesRequest/sourceDirectory}"/>
else
<record created="{$time}" updated="{$time}" status="Active" sourceDirectory="{$careServicesRequest/sourceDirectory}"/>
)}
</provider>
return (
insert node $prov into /CSD/providerDirectory,
csd_blu:wrap_updating_providers(<provider entityID="{$entityID}"/>)
)
health_worker_create_provider_facility
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/facility/@entityID)) then $provs1 else ()
let $facs0 := $provs2/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]
let $facilities := $provs2/facilities[1]
return
if ( count($provs2) = 1 and count($facs0) = 0) (:DO NOT ALLOW SAME ORG TWICE :)
then
let $provider:= $provs2[1]
let $fac := <facility entityID="{$careServicesRequest/facility/@entityID}"/>
let $facs_new := <facilities>{$fac}</facilities>
let $provs3:=
<provider entityID="{$provider/@entityID}">{$facs_new}</provider>
return
if (exists($facilities))
then
(insert node $fac into $facilities,
csd_blu:wrap_updating_providers($provs3)
)
else
(
insert node $facs_new into $provider,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_provider_organization
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/organization/@entityID)) then $provs1 else ()
let $orgs0 := $provs2/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
let $organizations := $provs2/organizations[1]
return
if ( count($provs2) = 1 and count($orgs0) = 0) (:DO NOT ALLOW SAME ORG TWICE :)
then
let $provider:= $provs2[1]
let $org := <organization entityID="{$careServicesRequest/organization/@entityID}"/>
let $orgs_new := <organizations>{$org}</organizations>
let $provs3:=
<provider entityID="{$provider/@entityID}">{$orgs_new}</provider>
return
if (exists($organizations))
then
(insert node $org into $organizations,
csd_blu:wrap_updating_providers($provs3)
)
else
(
insert node $orgs_new into $provider,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_create_service
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/facility/@entityID)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/facility/service/@entityID)) then $provs2 else ()
let $provider:= if ( count($provs3) = 1 ) then $provs3[1] else ()
let $facs := $provider/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]
let $fac := if (count($facs) = 1) then $facs[1] else ()
return if (exists($fac))
then
let $position := count($fac/service) +1
let $srvc :=
<service entityID="{$careServicesRequest/facility/service/@entityID}">
{(
$careServicesRequest/facility/service/organization,
$careServicesRequest/facility/service/language,
$careServicesRequest/facility/service/freeBusyURI
)}
</service>
let $provs3:=
<provider entityID="{$provider/@entityID}">
<facilities>
<facility entityID="{$fac/@entityID}">
<service position="{$position}" entityID="{$careServicesRequest/facility/service/@entityID}"/>
</facility>
</facilities>
</provider>
return
(insert node $srvc into $fac ,
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_delete_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl"; import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu"; declare default element namespace "urn:ihe:iti:csd:2013"; 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 :) let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else () let $provs1 := if (count($provs0) = 1) then $provs0 else () let $provs2 := if (exists($careServicesRequest/address/@type)) then $provs1 else () let $address:= $provs2[1]/demographic/address[@type = $careServicesRequest/address/@type] return if (exists($address)) then (delete node $address) else ()
health_worker_delete_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/contactPoint/@position))
then
let $providers := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if ( count($providers) = 1 )
then
let $cp := $providers[1]/demographic/contactPoint[position() = $careServicesRequest/contactPoint/@position]
return if (exists($cp)) then (delete node $cp) else ()
else ()
else ()
health_worker_delete_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingScheme) ) then $provs1 else ()
let $cred_new := $careServicesRequest/credential
let $code:= $cred_new/codedType/@code
let $codingScheme:= $cred_new/codedType/@codingScheme
let $creds0 := $provs2/credential[@code = $code and @codingScheme = $codingScheme]
return
if ( count($provs2) = 1 and count($creds0) = 1) then
delete node $creds0[1]
else
()
health_worker_delete_name
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/name/@position))
then
let $providers := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if ( count($providers) = 1 )
then
let $name := $providers[1]/demographic/name[position() = $careServicesRequest/name/@position]
return if (exists($name)) then (delete node $name) else ()
else ()
else ()
health_worker_delete_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/facility/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/facility/service/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/facility/service/operatingHours/@position)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs2,$careServicesRequest/id) else ()
let $oh := $provs3[1]/facilities/facility[upper-case(@entityID) =upper-case($careServicesRequest/facility/@entityID)]/service[position() = $careServicesRequest/facility/service/@position]/operatingHours[position() = $careServicesRequest/facility/service/operatingHours/@position]
return
if (count($oh) = 1)
then (delete node $oh) else ()
health_worker_delete_org_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl"; import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu"; declare default element namespace "urn:ihe:iti:csd:2013"; 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 :) let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else () let $provs1 := if (count($provs0) = 1) then $provs0 else () let $provs2 := if (exists($careServicesRequest/organization/@entityID)) then $provs1 else () let $provs3 := if (exists($careServicesRequest/organization/address/@type)) then $provs2 else () let $provider:= $provs3[1] let $orgs := $provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)] let $org := if(count($orgs) =1) then $orgs[1] else () let $address := $org/address[@type = $careServicesRequest/organization/address/@type] return if (exists($address)) then (delete node $address) else ()
health_worker_delete_org_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/organization/contactPoint/@position) and exists($careServicesRequest/organization/@entityID))
then
let $providers := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if ( count($providers) = 1 )
then
let $orgs := $providers[1]/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
return
if (count($orgs) = 1) then
let $cp := $orgs[1]/contactPoint[position() = $careServicesRequest/organization/contactPoint/@position]
return if (exists($cp)) then (delete node $cp) else ()
else ()
else ()
else ()
health_worker_delete_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu" ;
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/otherID/@position))
then
let $providers := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if ( count($providers) = 1 )
then
let $id := $providers[1]/otherID[position() = $careServicesRequest/otherID/@position]
return if (exists($id)) then (delete node $id) else ()
else ()
else ()
health_worker_delete_provider
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl"; import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu"; declare default element namespace "urn:ihe:iti:csd:2013"; 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 :) let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else () return if (count($provs0) = 1) then delete node $provs0[1] else ()
health_worker_delete_provider_facility
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/facility/@entityID))
then
let $providers := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if ( count($providers) = 1 )
then
let $fac := $providers[1]/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]
return if (exists($fac)) then (delete node $fac) else ()
else ()
else ()
health_worker_delete_provider_organization
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/organization/@entityID))
then
let $providers := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if ( count($providers) = 1 )
then
let $org := $providers[1]/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
return if (exists($org)) then (delete node $org) else ()
else ()
else ()
health_worker_delete_service
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
if (exists($careServicesRequest/facility/service/@position) and exists($careServicesRequest/facility/@entityID))
then
let $providers := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if ( count($providers) = 1 )
then
let $facs := $providers[1]/facilities/facility[upper-case(@entityID) = upper-case($careServicesRequest/facility/@entityID)]
return
if (count($facs) = 1) then
let $srvc := $facs[1]/service[position() = $careServicesRequest/facility/service/@position]
return if (exists($srvc)) then (delete node $srvc) else ()
else ()
else ()
else ()
health_worker_update_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/address/@type)) then $provs1 else ()
let $provider:= $provs2[1]
let $demo := $provider/demographic
let $address:= $demo/address[@type = $careServicesRequest/address/@type]
return
if ( not(exists($address))) then
csd_blu:wrap_updating_providers(()) (: Address does not exist. Do not update:)
else
let $provs3:=
<provider entityID="{$provider/@entityID}">
<demographic><address type="{$careServicesRequest/address/@type}"/></demographic>
</provider>
return (
csd_blu:bump_timestamp($provider),
replace node $address with $careServicesRequest/address
,
csd_blu:wrap_updating_providers($provs3)
)
health_worker_update_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/contactPoint/@position)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $old_cp := $provs1[1]/demographic/contactPoint[position() = $careServicesRequest/contactPoint/@position]
return
if (count($provs1) = 1 and exists($old_cp))
then
let $new_cp := $careServicesRequest/contactPoint
let $provs2 :=
<provider entityID="{$provs1[1]/@entityID}">
<demographic>
<contactPoint position="{$careServicesRequest/contactPoint/@position}"/>
</demographic>
</provider>
return
(
csd_blu:bump_timestamp($provs1[1]),
delete node $old_cp/codeType,
if (exists($new_cp/codeType)) then insert node $new_cp/codeType into $old_cp else (),
delete node $old_cp/equipment,
if (exists($new_cp/equipment)) then insert node $new_cp/equipment into $old_cp else (),
delete node $old_cp/purpose,
if (exists($new_cp/purpose)) then insert node $new_cp/purpose into $old_cp else (),
delete node $old_cp/certificate,
if (exists($new_cp/certificate)) then insert node $new_cp/certificate into $old_cp else (),
csd_blu:wrap_updating_providers($provs2)
)
else csd_blu:wrap_updating_providers(())
health_worker_update_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingScheme) ) then $provs1 else ()
let $cred_new := $careServicesRequest/credential
let $code:= $cred_new/codedType/@code
let $codingScheme:= $cred_new/codedType/@codingScheme
let $creds0 := $provs2/credential/codedType[@code = $code and @codingScheme = $codingScheme]
return
if ( count($provs2) = 1 and count($creds0) = 1) (:Update only:)
then
let $cred_old := $creds0[1]/..
let $provider:= $provs2[1]
let $provs3 :=
<provider entityID="{$provider/@entityID}">
<credential>
<codedType code="{$code}" codingScheme="{$codingScheme}"/>
</credential>
</provider>
return
(
csd_blu:bump_timestamp($provider),
if (exists($cred_new/issuingAuthority)) then
(if (exists($cred_old/issuingAuthority)) then (delete node $cred_old/issuingAuthority) else (),
insert node $cred_new/issuingAuthority into $cred_old)
else (),
if (exists($cred_new/number)) then
(if (exists($cred_old/number)) then (delete node $cred_old/number) else (),
insert node $cred_new/number into $cred_old)
else (),
if (exists($cred_new/credentialIssueDate)) then
(if (exists($cred_old/credentialIssueDate)) then (delete node $cred_old/credentialIssueDate) else (),
insert node $cred_new/credentialIssueDate into $cred_old)
else (),
if (exists($cred_new/credentialRenewalDate)) then
(if (exists($cred_old/credentialRenewalDate)) then (delete node $cred_old/credentialRenewalDate) else (),
insert node $cred_new/credentialRenewalDate into $cred_old)
else (),
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_update_name
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/name/@position)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $name := $provs1[1]/demographic/name[position() = $careServicesRequest/name/@position]
return
if (count($provs1) = 1 and exists($name))
then
let $provs2 :=
<provider entityID="{$provs1[1]/@entityID}">
<demographic>
<name position="{$careServicesRequest/name/@position}"/>
</demographic>
</provider>
let $new_name :=
<name>
{$careServicesRequest/name/*}
</name>
return
(
csd_blu:bump_timestamp($provs1[1]),
replace node $name with $new_name,
csd_blu:wrap_updating_providers($provs2)
)
else csd_blu:wrap_updating_providers(())
health_worker_update_operating_hours
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/facility/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/facility/service/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/facility/service/operatingHours/@position)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs2,$careServicesRequest/id) else ()
let $oh := $provs3[1]/facilities/facility[upper-case(@entityID) =upper-case($careServicesRequest/facility/@entityID)]/service[position() = $careServicesRequest/facility/service/@position]/operatingHours[position() = $careServicesRequest/facility/service/operatingHours/@position]
return
if (count($oh) = 1 and count($provs3) = 1)
then
let $new_oh := $careServicesRequest/facility/service/operatingHours
let $provs4 :=
<provider entityID="{$provs1[1]/@entityID}">
<facilities>
<facility entityID="{$careServicesRequest/facility/@entityID}">
<service position="{$careServicesRequest/facility/service/@position}" >
<operatingHours position="{$careServicesRequest/facility/service/operatingHours/@position}"/>
</service>
</facility>
</facilities>
</provider>
return
(
csd_blu:bump_timestamp($provs3[1]),
delete node $oh/openFlag,
if (exists($new_oh/openFlag)) then insert node $new_oh/openFlag into $oh else (),
delete node $oh/dayOfTheWeek,
if (exists($new_oh/dayOfTheWeek)) then insert node $new_oh/dayOfTheWeek into $oh else (),
delete node $oh/beginningHour,
if (exists($new_oh/beginningHour)) then insert node $new_oh/beginningHour into $oh else (),
delete node $oh/endingHour,
if (exists($new_oh/endingHour)) then insert node $new_oh/endingHour into $oh else (),
delete node $oh/beginEffectiveDate,
if (exists($new_oh/beginEffectiveDate)) then insert node $new_oh/beginEffectiveDate into $oh else (),
delete node $oh/endEffectiveDate,
if (exists($new_oh/endEffectiveDate)) then insert node $new_oh/endEffectiveDate into $oh else (),
csd_blu:wrap_updating_providers($provs4)
)
else csd_blu:wrap_updating_providers(())
health_worker_update_org_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
let $provs1 := if (count($provs0) = 1) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/organization/@entityID)) then $provs1 else ()
let $provs3 := if (exists($careServicesRequest/organization/address/@type)) then $provs2 else ()
let $provider:= $provs3[1]
let $org_container := $provider/organizations[1]
let $orgs := $provider/organizations/organization[upper-case(@entityID) = upper-case($careServicesRequest/organization/@entityID)]
let $org := if(count($orgs) =1) then $orgs[1] else ()
let $address := $org/address[@type = $careServicesRequest/organization/address/@type]
return if (not(exists($address)))
then csd_blu:wrap_updating_providers((<bad0/>,$careServicesRequest)) (:do not update an non-existent one :)
else
(
csd_blu:bump_timestamp($provider),
replace node $address with $careServicesRequest/organization/address ,
csd_blu:wrap_updating_providers(
<provider entityID="{$provider/@entityID}">
<organizations>
<organization entityID="{$org/@entityID}">
<contactPoint position="{$address/@type}"/>
</organization>
</organizations>
</provider>
)
)
health_worker_update_org_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/organization/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/organization/contactPoint/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs1,$careServicesRequest/id) else ()
let $old_cp := $provs2[1]/organizations/organization[upper-case(@entityID) =upper-case($careServicesRequest/organization/@entityID)]/contactPoint[position() = $careServicesRequest/organization/contactPoint/@position]
return
if (count($provs2) = 1 and exists($old_cp))
then
let $new_cp := $careServicesRequest/organization/contactPoint
let $provs3 :=
<provider entityID="{$provs1[1]/@entityID}">
<organizations>
<organization entityID="{$careServicesRequest/organization/@entityID}">
<contactPoint position="{$careServicesRequest/organization/contactPoint/@position}"/>
</organization>
</organizations>
</provider>
return
(
csd_blu:bump_timestamp($provs2[1]),
delete node $old_cp/codeType,
if (exists($new_cp/codeType)) then insert node $new_cp/codeType into $old_cp else (),
delete node $old_cp/equipment,
if (exists($new_cp/equipment)) then insert node $new_cp/equipment into $old_cp else (),
delete node $old_cp/purpose,
if (exists($new_cp/purpose)) then insert node $new_cp/purpose into $old_cp else (),
delete node $old_cp/certificate,
if (exists($new_cp/certificate)) then insert node $new_cp/certificate into $old_cp else (),
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
health_worker_update_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/otherID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs0,$careServicesRequest/id) else ()
let $id := $provs1[1]/otherID[position() = $careServicesRequest/otherID/@position]
return
if (count($provs1) = 1 and exists($id))
then
let $provs2 :=
<provider entityID="{$provs1[1]/@entityID}">
<otherID position="{$careServicesRequest/otherID/@position}"/>
</provider>
return
(
csd_blu:bump_timestamp($provs1[1]),
if ($careServicesRequest/otherID/@code)
then
if (exists($id/@code))
then (replace value of node $id/@code with $careServicesRequest/otherID/@code)
else (insert node $careServicesRequest/otherID/@code into $id)
else (),
if (exists($careServicesRequest/otherID/@assigningAuthorityName) )
then
if (exists($id/@assigningAuthorityName))
then replace value of node $id/@assigningAuthorityName with $careServicesRequest/otherID/@assigningAuthorityName
else insert node $careServicesRequest/otherID/@assigningAuthorityName into $id
else (),
if (not(string($careServicesRequest/otherID) = ''))
then (replace value of node $id with string($careServicesRequest/otherID))
else (),
csd_blu:wrap_updating_providers($provs2)
)
else csd_blu:wrap_updating_providers(())
health_worker_update_provider
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/providerDirectory/*,$careServicesRequest/id) else ()
return
if (not (count($provs0) = 1))
then ( csd_blu:wrap_updating_providers((<bad/>))) (:do nothing :)
else
let $provider := $provs0[1]
let $demo := $provider/demographic
let $dob := $demo/dateOfBirth
let $gender := $demo/gender
return
(
csd_blu:bump_timestamp($provider),
delete node $provider/codedType,
insert node $careServicesRequest/codedType into $provider,
if (not(exists($demo)))
then
insert node
<demographic>
{($careServicesRequest/gender,$careServicesRequest/dateOfBirth)}
</demographic>
into $provider
else
(
if (not(exists($dob))) then insert node $careServicesRequest/dateOfBirth into $demo else replace value of node $demo/dateOfBirth with $careServicesRequest/dateOfBirth,
if (not(exists($gender))) then insert node $careServicesRequest/gender into $demo else replace value of node $demo/gender with $careServicesRequest/gender
),
delete node $provider/language,
insert node $careServicesRequest/language into $provider,
delete node $provider/specialty,
insert node $careServicesRequest/specialty into $provider,
if (exists($provider/record/@status))
then replace value of node $provider/record/@status with $careServicesRequest/status
else insert node attribute { 'status' } { string($careServicesRequest/status) } into $provider/record,
csd_blu:wrap_updating_providers(<provider entityID="{$provider/@entityID}" />)
)
health_worker_update_provider_facility
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl"; import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu"; declare default element namespace "urn:ihe:iti:csd:2013"; 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 :) () (: does nothing:)
health_worker_update_provider_organization
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl"; import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu"; declare default element namespace "urn:ihe:iti:csd:2013"; 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 :) () (: does nothing:)
health_worker_update_service
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $provs0 := if (exists($careServicesRequest/facility/@entityID)) then /CSD/providerDirectory/* else ()
let $provs1 := if (exists($careServicesRequest/facility/service/@position)) then $provs0 else ()
let $provs2 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id($provs1,$careServicesRequest/id) else ()
let $old_srvc := $provs2[1]/facilities/facility[upper-case(@entityID) =upper-case($careServicesRequest/facility/@entityID)]/service[position() = $careServicesRequest/facility/service/@position]
return
if (count($provs2) = 1 and exists($old_srvc))
then
let $new_srvc := $careServicesRequest/facility/service
let $provs3 :=
<provider entityID="{$provs1[1]/@entityID}">
<facilities>
<facility entityID="{$careServicesRequest/facility/@entityID}">
<service position="{$careServicesRequest/facility/service/@position}" />
</facility>
</facilities>
</provider>
return
(
csd_blu:bump_timestamp($provs2[1]),
delete node $old_srvc/freeBusyURI,
if (exists($new_srvc/freeBusyURI)) then insert node $new_srvc/freeBusyURI into $old_srvc else (),
delete node $old_srvc/organization,
if (exists($new_srvc/organization)) then insert node $new_srvc/organization into $old_srvc else (),
delete node $old_srvc/language,
if (exists($new_srvc/language)) then insert node $new_srvc/language into $old_srvc else (),
csd_blu:wrap_updating_providers($provs3)
)
else csd_blu:wrap_updating_providers(())
facility_create_address
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $fac0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/facilityDirectory/*,$careServicesRequest/id) else ()
let $fac1 := if (count($fac0) = 1) then $fac0 else ()
let $fac2 := if (exists($careServicesRequest/address/@type)) then $fac1 else ()
return
if ( count($fac2) = 1 )
then
let $facility:= $fac2[1]
return
let $fac3:=
<facility entityID="{$facility/@entityID}">
<address type="{$careServicesRequest/address/@type}"/>
</facility>
return (
insert node
$careServicesRequest/address
into $facility
,
csd_blu:wrap_updating_facilities($fac3)
)
else csd_blu:wrap_updating_facilities(())
organization_create_contact_point
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id) else ()
let $orgs1 := if (count($orgs0) = 1) then $orgs0 else ()
let $orgs2 := if (exists($careServicesRequest/contactPoint)) then $orgs1 else ()
return
if ( count($orgs2) = 1 )
then
let $organization:= $orgs2[1]
let $position := count($organization/contactPoint) +1
let $cp :=
<contactPoint>
{(
if (exists($careServicesRequest/contactPoint/codedType)) then $careServicesRequest/contactPoint/codedType else (),
if (exists($careServicesRequest/contactPoint/equipment)) then $careServicesRequest/contactPoint/equipment else (),
if (exists($careServicesRequest/contactPoint/purpose)) then $careServicesRequest/contactPoint/purpose else (),
if (exists($careServicesRequest/contactPoint/certificate)) then $careServicesRequest/contactPoint/certificate else ()
)}
</contactPoint>
let $orgs3:=
<organization entityID="{$organization/@entityID}">
<contactPoint position="{$position}"/>
</organization>
return
(insert node $cp into $organization ,
csd_blu:wrap_updating_organizations($orgs3)
)
else csd_blu:wrap_updating_organizations(())
organization_create_credential
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id) else ()
let $orgs1 := if (count($orgs0) = 1) then $orgs0 else ()
let $orgs2 := if (exists($careServicesRequest/credential/codedType/@code) and exists($careServicesRequest/credential/codedType/@codingScheme) ) then $orgs1 else ()
let $cred_request := $careServicesRequest/credential
let $code:= $cred_request/codedType/@code
let $codingScheme:= $cred_request/codedType/@codingScheme
let $creds0 := $orgs2/credential/codedType[@code = $code and @codingScheme = $codingScheme]
return
if ( count($orgs2) = 1 and count($creds0) = 0) (:DO NOT ALLOW SAME CRED TWICE :)
then
let $organization:= $orgs2[1]
let $cred_rec :=
<credential>
<codedType code="{$code}" codingScheme="{$codingScheme}"/>
</credential>
let $cred_new :=
<credential>
<codedType code="{$code}" codingScheme="{$codingScheme}"/>
{(
if (exists($cred_request/number)) then $cred_request/number else (),
if (exists($cred_request/issuingAuthority)) then $cred_request/issuingAuthority else (),
if (exists($cred_request/credentialIssueDate)) then $cred_request/credentialIssueDate else (),
if (exists($cred_request/credentialRenewalDate)) then $cred_request/credentialRenewalDate else ()
)}
</credential>
let $orgs3:=
<organization entityID="{$organization/@entityID}">{$cred_rec}</organization>
return
(
insert node $cred_new into $organization,
csd_blu:wrap_updating_organizations($orgs3)
)
else csd_blu:wrap_updating_organizations(())
organization_create_otherid
import module namespace csd_bl = "https://github.com/openhie/openinfoman/csd_bl";
import module namespace csd_blu = "https://github.com/openhie/openinfoman/csd_blu";
declare default element namespace "urn:ihe:iti:csd:2013";
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
:)
let $orgs0 := if (exists($careServicesRequest/id/@entityID)) then csd_bl:filter_by_primary_id(/CSD/organizationDirectory/*,$careServicesRequest/id) else ()
let $orgs1 := if (count($orgs0) = 1) then $orgs0 else ()
let $orgs2 := if (exists($careServicesRequest/otherID/@code)) then $orgs1 else ()
return
if ( count($orgs2) = 1 )
then
let $organization:= $orgs2[1]
let $position := count($organization/otherID) +1
let $id :=
if (exists($careServicesRequest/otherID/@assigningAuthorityName)) then
<otherID code="{$careServicesRequest/otherID/@code}" assigningAuthorityName="{$careServicesRequest/otherID/@assigningAuthorityName}">{string($careServicesRequest/otherID)}</otherID>
else
<otherID code="{$careServicesRequest/otherID/@code}">{string($careServicesRequest/otherID)}</otherID>
let $orgs3:=
<organization entityID="{$organization/@entityID}">
<otherID position="{$position}"/>
</organization>
return
(insert node $id into $organization ,
csd_blu:wrap_updating_organizations($orgs3)
)
else csd_blu:wrap_updating_organizations(())