Using XPath can ID/IDREF use be checked? - xpath

With XML Schema we can define ID/IDREF links between components in an XML document. I'm looking for a way, using XPath, to ensure that only certain IDs can be used as IDREFs - i.e. only those values which logically make senses in the context of the schema design.
Using the example below, how do I ensure that a book's library_id is actually one of the available library_ids and not some other id which could appear in the message and be used for some entirely different purpose (but still be schema valid).
<books>
<book library_id="lib1">
<author>A</author>
<title>B</title>
</book>
<book library_id="lib2">
<author>C</author>
<title>D</title>
</book>
<library id="lib1">
<name>X</name>
<city>Y</city>
</library>
<library id="lib2">
<name>X</name>
<city>Y</city>
</library>
</books>
The closest I've come to getting this to work is to use the XPath contains function e.g.
contains(//library/#id,//book/#library_id)
but this throws an error because a sequence of more than one item is not allowed as the first argument of contains() ("lib1","lib2").
Thanks

I hope that understood correctly what you want
Books with library_id present in library list
//book[#library_id = //library/#id]
Books with incorrect library_id
//book[not(#library_id = //library/#id)]

Why not use XSD's key/keyref constraints instead of ID/IDREF? These are much more flexible: they can be scoped to any element rather than the whole document; you can have different kinds of IDs within a document and the refs must match up to the same kind; the values can be composite (e.g. first name + last name); the values can be of any data type.

Related

XPath expression to pluck out attribute value

I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor (value for the payload's class attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[#class="vendor"]#class
But this requires the expression to already know that vendor is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar. Any ideas where I'm going awry?
If you need #class value from payload node, you can use
/dataEnvelope/payload[#class]/#class
or just
/dataEnvelope/payload/#class
At first, your two XML files are out-of-sync - one references envelope and the other references dataEnvelope. So exchange one for the other, if necessary.
So, to get the attribute value of payload, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[#buzz='3']]/#class
Output is:
vendor
If the document element can/will change, then you can keep the XPath more generic and select the value of the class attribute from the payload element that is a child of any element:
/*/payload/#class
If you know that it will always be a child of envelope, then this would be more specific(but the above would still work):
/envelope/payload/#class

Mapping existing resource to hl7-fhir response

Trying to understand the concept of the code datatype in hl7-fhir. Looking at the appointment (https://www.hl7.org/fhir/appointment.html) resource as an example it has a status parameter with suggested values of "proposed | pending | booked" etc.
Given an existing database with it's own custom status' (Attended, Confirmed, Attended but late) what is the correct way to handle a hl7-fhir response to a consumer?
If the "code" data type is used, then the FHIR binding strength is always "required" - which means you are required to use the FHIR-defined list of codes and no others.
It appears that two of your statuses - "Attended" and "Attended but late" aren't actually statuses of the appointment - the booking, but are instead commentary about the resulting encounter. So I would capture those as extensions. "confirmed" sounds similar to "booked", though I'd need to know the definition to know for sure. Do you have any appointment statuses for appointments that are not yet confirmed (let alone attended)?
To extend on Lloyds notes, you will want to put the extension under the status property, and map your existing values to the provided FHIR values, and put your local actual value in the extension underneath.
This way when other systems read the resource and don't know about your extension status values, they will still be able to act sensibly based on the core values.
<status value="fulfilled">
<extension url="http://yourorg.com/fhir/.../ExtendedAppointmentStatuses">
<valueCoding>
<code value="abl" />
<display value="Attended but late" />
</valueCoding>
</extension>
</status>

Why can't I search DocumentReferences for a particular subject using Spark server for FHIR DSTU-2 1.0.1?

I have a Patient resource at this url: http://localhost:49911/fhir/Patient/PHFId1
and DocumentReference resource with the following element:
<subject>
<reference value=" http://localhost:49911/fhir/Patient/PHFId1" />
</subject>
I want to be able to get a list of all DocumentReferences belonging to a certain patient but everything I have tried either returns no results, or else returns all Document References on the system. Some of the variations I have tried include:
fhir/Patient/PHFId1/DocumentReference (404 Not Found)
fhir/DocumentReference?subject:Patient=PHFId1 (no results)
fhir/DocumentReference?fhir/Patient/PHFId1 (no results)
fhir/DocumentReference?subject.reference=PHFId1 (no results)
What am I doing wrong? It must be a common use case to require a list of all documents relating to a Patient. Perhaps I have set up the linkage incorrectly by using the subject element?
Thanks in advance
The search syntax you've used is only correct in the second line, but other than that you're not doing anything wrong. This is a known issue in the Spark server (see https://github.com/furore-fhir/spark/issues/6).

add xpath transformation to root document

In xades4j, in case of multiple enveloping signature i will have my signed document with, at the end, more Signature elements, but i need to tell to each reference to signed document (URI="") that he must not refers to other Signature element that represent other Signature, i need so to add this transformation
<ds:Reference URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2002/06/xmldsig-filter2">
<dsig-xpath:XPath Filter="subtract">/descendant::ds:Signature</dsig-xpath:XPath>
</ds:Transform>
</ds:Transforms>
....
Telling that it must not to consider ds:Signature element for signature production.
How xades4j permit the use of this kind of transformation?
Thanks
Michele
You can add the transforms when defining the DataObjectReference. Check the examples on the wiki page and the XPath2FilterTransform class documentation.

how to get the attribute value by another attribute's value in xpath

<?xml version="1.0" encoding="UTF-8"?>
<serviceOfferings xmlns="http://www.abc.com/aaa" xmlns:ns2="http://www.w3.org/2005/Atom">
<serviceOffering type="provider">
<links>
<link title="Service Provider" type="application/xml" rel="self" href="https://www.yahoo.com"/>
<link rel="create" href="https://www.google.com/create"/>
</links>
</serviceOffering>
</serviceOfferings>
How do I get the href value for the link which attribute rel is create
The target element is in a default namespace. First, you'll need to register that namespace with your XPath engine. How you do this depends on the tool you're using, which means it's outside the scope of this question (since you haven't told us how you're evaluting your expressions).
Let's assume you've registered the namespace to a prefix called aaa. Select the desired link like this:
//aaa:link[#rel='create']
Or, more specifically:
/*/*/*/aaa:link[#rel='create']
For completeness, in most cases this can also be achieved without registering a namespace, at the cost of reduced readability:
/*/*/*/*[name()='link' and #rel='create']
This selects all elements whose name is "link" (regardless of the namespace they belong to) and that have a rel attribute whose string value is "create", and that are grand-grand-children of the top element of the XML document.

Resources