Combo Search Parameter Examples

 

This page contains examples of Combo Search Parameters.

Example: Indexed Search Parameter Combination

 

The following example shows a sample Non-unique Combo Index Search parameter, and it assumes that you have already created the three individual SearchParameter resources based on the Patient resource's properties being used here (family, gender and birthdate).

This Combo Search Parameter would be helpful to speed up searches that combine the family, gender and birthdate search parameters, for example: Patient?family=Smith&gender=male&birthdate=1980-01-01.

Note that the SearchParameter.comonent.definition values here are local references to the individual SearchParameter resources (it is also acceptable to use canonical URLs found in SearchParameter.url instead of these local references). The referenced SearchParameters apply to multiple resource types (Patient and Practitioner in these cases) but the combo search parameter will only index and apply to Patient resources because the combo search parameter has a SearchParameter.base of Patient.

{
  "resourceType": "SearchParameter",
  "extension": [
    {
      "url": "http://hapifhir.io/fhir/StructureDefinition/sp-unique",
      "valueBoolean": false
    }
  ],
  "status": "active",
  "code": "family-gender-birthdate",
  "base": [
    "Patient"
  ],
  "type": "composite",
  "component": [
    {
      "definition": "SearchParameter/individual-family"
    },
    {
      "definition": "SearchParameter/individual-gender"
    },
    {
      "definition": "SearchParameter/individual-birthdate"
    }
  ]
}

Example: Index Document Bundles with Ranged Date

 

Consider the common scenario for a document repository, where you want to search for document Bundle resources for a given subject and date range. This example could easily be expanded to include additional parameters such as the document type or category.

First, a SearchParameter is created for the document subject:

{
  "resourceType": "SearchParameter",
  "id": "Bundle-composition-subject",
  "url": "http://example.org/SearchParameter/Bundle-composition-subject",
  "name": "composition.subject",
  "status": "active",
  "code": "composition.subject",
  "base": [ "Bundle" ],
  "type": "reference",
  "expression": "Bundle.where(type = 'document').entry[0].resource.as(Composition).subject"
}

Then, a SearchParameter is created for the document date:

{
  "resourceType": "SearchParameter",
  "id": "Bundle-composition-date",
  "url": "http://example.org/SearchParameter/Bundle-composition-date",
  "name": "composition.date",
  "status": "active",
  "code": "composition.date",
  "base": [ "Bundle" ],
  "type": "date",
  "expression": "Bundle.where(type = 'document').entry[0].resource.as(Composition).date"
}

Finally, a non-unique Combo Search Parameter is created for the subject and date. Note the sp-combo-date-ranged extension on the date component:

{
  "resourceType": "SearchParameter",
  "id": "Bundle-composition-subject-and-date",
  "extension": [ {
    "url": "http://hapifhir.io/fhir/StructureDefinition/sp-unique",
    "valueBoolean": false
  } ],
  "status": "active",
  "code": "bundle-composition-subject-and-type",
  "base": [ "Bundle" ],
  "type": "composite",
  "component": [ {
    "definition": "SearchParameter/Bundle-composition-subject"
  }, {
    "definition": "SearchParameter/Bundle-composition-date",
    "extension": [ {
      "url": "http://hapifhir.io/fhir/StructureDefinition/sp-combo-date-ranged",
      "valueBoolean": true
    } ]
  } ]
}

The following searches would be supported by this Combo Search Parameter, and would be expected to perform well at scale:

  • Bundle?composition.date=2022-01-02&composition.subject=Patient/PAT-0
  • Bundle?composition.date=ge2022-01-01&composition.subject=Patient/PAT-0
  • Bundle?composition.date=gt2022-01-01&composition.subject=Patient/PAT-0
  • Bundle?composition.date=lt2022-01-03&composition.subject=Patient/PAT-0
  • Bundle?composition.date=le2022-01-03&composition.subject=Patient/PAT-0

Multiple date parameters can also be combined in order to construct a range search:

  • Bundle?composition.date=ge2022-01-01&composition.date=le2022-01-03&composition.subject=Patient/PAT-0

If the parameter value has a precision greater than DAY, the search will use the Combo Search Parameter index, but it will also use the standard date SearchParameter index to verify the additional precision. This can result in a performance impact at scale.

  • Bundle?composition.date=ge2022-01-01T12:00:00Z&composition.subject=Patient/PAT-0

Example: Unique Identifier for Specific Identifier System

 

For example, suppose you want to create an index which enforces uniqueness for Patient identifiers, but only enforces identifiers with a specific Identifier.system value (meaning that identifiers with other identifier systems are not restricted). This could be accomplished by adding the following extension to the SearchParameter.component repetition pointing to the identifier SearchParameter, as shown below.

This example uses a canonical URL as the reference in SearchParameter.component.definition.

{
  "resourceType": "SearchParameter",
  "id": "Patient-uniq-identifier",
  "extension": [ {
    "url": "http://hapifhir.io/fhir/StructureDefinition/sp-unique",
    "valueBoolean": true
  } ],
  "status": "active",
  "code": "patient-uniq-identifier",
  "base": [ "Patient" ],
  "type": "composite",
  "component": [ {
    "definition": "http://hl7.org/fhir/SearchParameter/Patient-identifier",
    "extension": [ {
      "url": "http://hapifhir.io/fhir/StructureDefinition/sp-combo-component-filter-allowlist",
      "valueIdentifier": {
        "system": "http://my-identifier-system"
      }
    } ]
  } ]
}

Example: Index Specific Meta Tag and Profile Values

 

This example shows a non-unique combo search parameter used to index only specific values for thw _tag and _profile parameters.

Specifically, this combo search parameter can efficiently support the following searches:

  • Patient?_tag=http://tag-to-index|value1&_profile=http://profile-to-index
  • Patient?_tag=http://tag-to-index|value2&_profile=http://profile-to-index

No combo indexes are generated for any other tags or profile declarations, which saves space if a large number of tags and profiles are used on the server.

{
  "resourceType": "SearchParameter",
  "id": "tag-profile-combo",
  "extension": [ {
    "url": "http://hapifhir.io/fhir/StructureDefinition/sp-unique",
    "valueBoolean": false
  } ],
  "status": "active",
  "base": [ "Patient" ],
  "type": "composite",
  "code": "tag-profile-combo",
  "component": [ {
    "extension": [ {
      "url": "http://hapifhir.io/fhir/StructureDefinition/sp-combo-component-filter-allowlist",
      "valueIdentifier": {
        "system": "http://tag-to-index",
        "value": "value1"
      }
    }, {
      "url": "http://hapifhir.io/fhir/StructureDefinition/sp-combo-component-filter-allowlist",
      "valueIdentifier": {
        "system": "http://tag-to-index",
        "value": "value2"
      }
    } ],
    "definition": "SearchParameter/Resource-tag",
    "expression": "Patient"
  }, {
    "extension": [ {
      "url": "http://hapifhir.io/fhir/StructureDefinition/sp-combo-component-filter-allowlist",
      "valueUri": "http://profile-to-index"
    } ],
    "definition": "SearchParameter/Resource-profile",
    "expression": "Patient"
  } ]
}