Examples

Combining features

This query shows you the combination of several features: where, select, and for.

from
    Patient
where
    name[0].family = 'Chalmers'
select
    for name
    select greeting: 'Hello ' & given.first() & ' ' & family

Also note that if you move the for clause to a top-level statement, you will not get rows per resource, but per name.

from
    Patient
where
    name[0].family = 'Chalmers'
for name select
{
    greeting: 'Hello ' & given.first() & ' ' & family
}

Profiles in your project

Lists the name and canonical from all profiles available in your project (including referenced packages):

using scope
from
  StructureDefinition
select
  name, url

Mappings of a profile in a package dependency

Because using scope includes your package dependencies, you can query a profile that you do not maintain yourself. This lists the element mappings of a profile from one of your dependencies:

using scope
from StructureDefinition
where url = 'http://hl7.org/fhir/StructureDefinition/Patient'
for snapshot.element
where mapping.exists()
select
  Path: path,
  Identity: mapping.identity,
  Map: mapping.map

An element can carry more than one mapping, so the last two columns can hold multiple values. To show only one mapping set, filter on its identity:

using scope
from StructureDefinition
where url = 'http://hl7.org/fhir/StructureDefinition/Patient'
for snapshot.element
where mapping.where(identity = 'v2').exists()
select
  Path: path,
  V2: mapping.where(identity = 'v2').map

The mapping declarations themselves (the legend of identities used in the profile) sit at the root of the StructureDefinition:

using scope
from StructureDefinition
where url = 'http://hl7.org/fhir/StructureDefinition/Patient'
for mapping
select identity, name, uri

The snapshot is only available if the package was published with snapshots. If it is missing, query differential.element instead, which holds only the mappings that the author added, not the ones inherited from the base resource.

About profiles in a use case

You can use a capability statement to define a subset of resources that are relevant to your use case.

All capability statements: this query shows the list of all profiled resources that are referenced by any capability statement in this project. It is similar to a flatmap of all profile elements in all CapabilityStatements.

from CapabilityStatement
for profile
select display, reference

One specific CapabilityStatement: if you want the list from only one specific CapabilityStatement, you can filter it by its canonical or id.

from CapabilityStatement
where url = 'http://myusecase'
for profile
select display, reference

List all canonicals

Listing all canonicals in this project:

from StructureDefinition
select url

All Profiles or Examples

Details from all Profiles: lists the name, description and status of every profile (the non-extension StructureDefinitions).

from StructureDefinition
where type != 'Extension'
select name, description, status

Details from all Extensions: the same, but for extensions, including the context they apply to.

from StructureDefinition
where type = 'Extension'
select title , description, status, context.expression

Finding ValueSet compositions

Lists all systems that are used for more than one composition in valuesets, and their frequency. (Note that group by and with are available only in FQL 3 and later.)

from ValueSet
group by
  compose.include.system
select
  system,
  frequency: group.count(),
where
  frequency > 1
order by
  frequency desc
with
  header

Two canonicals

If you want to filter multiple resources by a small set of canonicals:

from StructureDefinition
    where url in ('http://example.org/fhir/StructureDefinition/xxx' | 'http://example.org/fhir/StructureDefinition/yyy')
select
    Name: name,
    Description: description,
    Version: version,
    Status: status,
    URL: url