0

Given a Resource such as DeviceObservationReport, a number of fields have cardinality 0..many. In some cases these contain reference(s) to other Resource(s) which may also have cardinality 0..many. I am having considerable difficulty in deciding how to support 'chained' queries over referenced Resources which may be two or three steps 'deep' (for want of a better term).

For example, in a single DeviceObservationReport there may be multiple Observation Resource references. It is entirely probable that a client may wish to perform a query which requests all instances of an Observation with a specific code, which have a timestamp (appliesDate) later than a specific instant in time. The named Search Parameter observation would appear to be the obvious starting point and the Path to the observation is specified as virtualDevice.channel.metric.observation. Given that the virtualDevice, channel, and metric fields have cardinality 0..*, would a 'simple' query to retrieve all DeviceObservationReport instances which contain observations with code TESTCODE and observed later than 14:00 on 10 October 2014 look something like:

../data/DeviceObservationReport?virtualDevice[0].channel[0].metric[0].observation.name=TESTCODE&virtualDevice[0].channel[0].metric[0].observation.date>2014-10-10%2014:00

Secondly, if the client requests that the result set be sorted on date, how would that be expressed in the query, because, from the various attempts I have made to implement this, at this point support for the query becomes rather more complex, and thus far I have not been able to come up with a satisfactory solution.

DavidF
  • 3
  • 1
  • @Scott, thanks. Where the field being queried is a reference to another Resource, I interpret the DSTU to mean the path must be used - virtualDevice[].channel[].metric[].observation.??? - (compared to 'non-reference' field which can be queried directly - for example channel). For now I achieve this using name/value pairs which are extracted by the server when the initial DeviceObservationReport bundle is received. Sorting appears to be much more complex, with the only obvious option being to drill back into the the database for all matched Observation Resources followed by an in-memory sort. – DavidF Oct 20 '14 at 20:50

1 Answers1

0

firstly, the path for the parameter is the path within the resource, and chaining links between the defined names. So your query would look like this:

../data/DeviceObservationReport?observation.name=TESTCODE&observation.date=>2014-10-10%2014:00

e.g. the search parameters are aliases within the resource. However the problem with this search is that the parameters are anded at the root, not the leaf - which means this finds all device observation reports that have an observation with a TESTCODE, and that have an observation with date >DATE, which is subtly different to what you probably want: all device observation reports that have an observation with a TESTCODE, and a date >DATE. This will be addressed in the next major release of FHIR.

Sorting is tough with a chained query. I ended up extracting the field that I sort by, but not actually sorting by it - I insert the raw matches into a holding table, and then sort by the sort field as I access the secondary table. The principle reason for this is to make paging robust against on-going changes to the resources.

Grahame Grieve
  • 3,538
  • 3
  • 15
  • 17
  • Thanks Grahame, that answers both of my issues. Yes, the concept of brackets to group the name and date as a unit would give me the results I require. I did suspect that sorting wasn't going to be something I could simply do in SQL or XQuery. – DavidF Oct 21 '14 at 19:22