R4 Ballot #1 (Mixed Normative/Trial use) FHIR CI-Build

This page is part of the FHIR Specification (v3.3.0: R4 Ballot 2). The current version which supercedes this version is 5.0.0 . For a full list Continuous Integration Build of available versions, see FHIR (will be incorrect/inconsistent at times).
See the Directory of published versions icon . Page versions: R5 R4B R4 R3 R2

Maturity Level : 5
Responsible Owner: FHIR Infrastructure icon Work Group Ballot Standards Status : Normative
Normative Candidate Note: This page is candidate normative content for R4 in the Infrastructure Package . Once normative, it will lose it's Maturity Level, and breaking changes will no longer be made.

Searching for resources is fundamental to the mechanics of FHIR. Search operations traverse through an existing set of resources filtering by parameters supplied to the search operation. The text below describes the FHIR search framework, starting with simple cases moving to the more complex. Implementers need only implement the amount of complexity that they require for their implementations. Servers SHALL declare what features of search they require through their CapabilityStatement search declarations § 0 , and clients are encouraged to do this too.

3.1.1.1

In FHIR Search is the simplest case, a primary mechanism used to find and list resource instances. The search mechanism is executed by performing a GET operation in designed to be flexible enough to meet the RESTful framework: needs of a wide variety of use cases, and yet be simple enough to be commonly useful.

GET [base]/[type]?name=value&...{&_format=[mime-type]}}

For this RESTful search (see definition in RESTful API ), the parameters are In a series typical RESTful interface, collections of name=[value] pairs encoded in the URL or instances are returned as an application/x-www-form-urlencoded submission for a POST: POST [base]/[type]/_search{?[parameters]{&_format=[mime-type]}} The server determines which arrays of the set a type. In order to include related information (e.g., number of resources it serves meet the specific criteria, total results), support extended functionality (e.g., paging), and returns the results allow multiple resource types in the HTTP response as results (e.g., returning Patient and Encounter resources), FHIR Search instead returns a bundle Bundle which includes the resources that are the results resource, with a type of searchset . Resources included in the search. results appear as individual entries in such a bundle. Note that the _format parameter works for search like for other interactions . More information about returned contents and elements can be found in Managing Returned Resources

Search operations There are safety issues associated with the implementation of searching that implementers need to always keep in mind. Implementers SHOULD review the safety checklist . § 1

Note that for the readability of this document, syntaxes and examples are executed shown without URL-Encoding escaping applied. For example, a syntax of [url]|[version] will be URL encoded during transmission as [url]%7C[version] . when describing the format of token parameters, the vertical pipe character (


|
) is used instead of the URL-Encoded value of

%7C
.

As noted in one the Escaping Search Parameters section, URL Encoding is transparent when processing. Clients and servers SHOULD be robust in their handling of three URLs present in the content of FHIR bundles, such as in Bundle.link.url . § 2

For example, the following unencoded request:

Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?patient.identifier=http://example.com/fhir/identifier/mrn|123456 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded patient.identifier=http://example.com/fhir/identifier/mrn|123456

would actually be transmitted over-the-wire as:

Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?patient.identifier=http%3A%2F%2Fexample.com%2Ffhir%2Fidentifier%2Fmrn%7C123456 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded patient.identifier=http%3A%2F%2Fexample.com%2Ffhir%2Fidentifier%2Fmrn%7C123456

Though search operations are typically performed via REST, search is defined contexts to be useful independently of HTTP. Note that control which set while different formats of resources search requests are being searched: functionally equivalent, implementation considerations can result in differences inherent to searching via a particular protocol. Details can be found on the Search section of the HTTP page.

Input to search operations are referred to as Search Parameters . A search parameter can be:

  • A specified resource type: a filter across all resources (e.g., GET [base]/[type]?parameter(s) _id , which is present on every resource),
  • A specified compartment , perhaps with a specified filter on a specific resource type in that compartment: (e.g., GET [base]/Patient/[id]/[type]?parameter(s) Patient.birthDate , which applies to the Patient resource,)
  • All resource types: GET [base]?parameter(s) (parameters common to all types only) a textual search across a resource, or
  • a parameter that affects search results .

Search There is a single page that lists all the search parameters published with this specification. Note that search parameter names are case sensitive, though this specification never defines different parameters with names that differ only in case. Clients SHOULD use correct case, and servers SHALL NOT define additional parameters with different meanings with names that only differ in case. § 3

Order of operations can also be implemented is not driven by order in the messaging framework . URL - with the exception of sort. First all filters are applied, then the result set is sorted, then paging is applied, and then included resources ( _include , _revinclude ) are added for each page.

The server determines which of their resources meet the criteria contained in the search parameters as described below. However However, the server has the prerogative to return additional search results if it believes them to be relevant. Note: There is a special search for the most relevant context in which the search set is indeterminate: Patient MPI Search .

Search using In the absence of any search filters, e.g., GET [base] , GET [base]/Patient , or POST [base]/_search may include sensitive information or POST [base]/Patient/_search with no body, a server SHOULD return all records in scope of the search parameters. Therefore, secure communications context. § 4 Servers MAY reject a search as overly-broad, and endpoint management SHOULD return an appropriate error in that situation (e.g., too-costly ). § 5

For more information about how search inputs are recommended, tested against resources, please see Security Communications Search Parameters .

Search operations are executed in one of three defined contexts that control which set of resources are being searched:

  • All resource types: Note that if the _type parameter is included, all other search parameters SHALL be common to all provided types, and if _type is not included, all parameters SHALL be common to all resource types. § 6 Show as unencoded: HTTP GET | HTTP POST GET [base]?parameter(s) POST [base]/_search Content-Type: application/x-www-form-urlencoded parameter(s)
  • A specified resource type: Show as unencoded: HTTP GET | HTTP POST GET [base]/[type]?parameter(s) POST [base]/[type]/_search Content-Type: application/x-www-form-urlencoded parameter(s)
  • A specified compartment , perhaps with a specified resource type in that compartment. Note that the literal * (asterisk) is valid as the [type] in a GET-based compartment search. This syntax is for disambiguation between an instance read and a compartment search, which would otherwise share the same URL.

    The outcome of a compartment search is the same as the equivalent system or type search and will have full URLs that are not compartment-specific (e.g. fullUrls reference [base]/Observation/[id] , not [base]/Patient/[pat-id]/Observation/[id] ). References within returned resources are also not rewritten to include the compartment path.

    Show as unencoded: HTTP GET | HTTP POST GET [base]/[compartment]/[id]/[type]?parameter(s) POST [base]/[compartment]/[id]/[type]/_search Content-Type: application/x-www-form-urlencoded parameter(s)

Search responses are always returned as a Bundle . Search result bundles convey a lot of metadata in addition to any possible results, using the various elements available in the bundle resource.

The response to any search operation is always a list of resources in a Bundle. An alternative approach is to use GraphQL .

Search result bundles will always have the Bundle.type of searchset . The Bundle.type value of searchset designates that a bundle is a search response and may be used in processing to classify bundles.

In order to allow the client to be confident about what search parameters were used as criteria by a server, servers SHALL return the parameters that were actually used to process a search. § 7 Applications processing search results SHALL check these returned values where necessary. § 8 For example, if a server did not support some of the filters specified in the search, a client might manually apply those filters to the retrieved result set, display a warning message to the user or take some other action.

These parameters are encoded in the self link of the returned bundle - a bundle.link with the relation set to self : Show as: FHIR+JSON | FHIR+XML { "resourceType": "Bundle", "type": "searchset", ... "link": { "relation": "self", "url": "http://example.org/Patient?name=peter" } ... } <Bundle> <type value="searchset"/> ... <link> <relation value="self"/> <url value="http://example.org/Patient?name=peter"/> </link> ... </Bundle>

Self links SHALL be expressed as an HTTP GET-based search with the relevant parameters included as query parameters, because of the semantics around the link types. § 9 This means that the same self link is a valid response for any equivalent search, regardless of how a search is performed (e.g., HTTP GET, HTTP POST, Messaging, etc.).

Self links MAY be returned as absolute URIs or URIs relative to the base URL of a server and MAY or MAY NOT be resolvable. § 10 A server that does not support search via GET will return links in the same style as a server that does not support search via POST. Note that this makes the self link special in the context of bundle links, as all other links are intended to be resolvable by a client.

Clients SHALL review the returned parameters in the self link to ensure proper processing of results. § 11 Generally, ignored parameters will result in clients receiving more results than intended. In those situations, clients SHOULD filter received records to account for additional data. § 12

In some cases, a server might introduce additional search parameters into the executed query based on authorization rules. Servers MAY include such filters in the self link. § 13 Clients SHOULD be able to handle search parameters in a self link that they did not request. § 14 Servers SHOULD consider whether exposing search parameters in the self link would constitute inappropriate leakage of security information. § 15

In addition to the self link, many bundles may contain links relevant to paging. These are identified via the relation value in the links. Common links include: first , last , next , prev , and previous . Note that prev and previous are widely-used synonyms and are interchangeable.

As with the self link, all relevant paging links SHALL be expressed as GET requests. § 16 Servers SHOULD NOT include content that is considered sensitive in URLs, excluding the self link. § 17

For best practices on when to include or exclude paging links, see the Paging Best Practices section on the FHIR HTTP page.

Within the results bundle, there are three types of entries that may be present, identified by the search mode of the entry: match , include , or outcome .

Note that entries are unique (not allowed to repeat) and there is only one mode per entry. In some corner cases, a resource may be included because it is both a match and an include . In these circumstances, match takes precedence.

Entries marked with match in search results indicate that a record is being returned because it meets the parameters specified in the search request (e.g., a record the client requested).

Entries marked with include in search results indicate that a record is being returned either because it is referred to from a record in the result set or that the server believes is useful or necessary for the client to process other results.

Entries marked with outcome in search results are OperationOutcome resources with information related to the processing of a search. For example, a server may use an outcome record to report to a client that a search was unacceptable.

If a server is unable to execute a search request, it may MAY either return an error for the request or return success with an outcome containing details of the error. § 18 A HTTP status code of 403 signifies that the server refused to perform the search, while other 4xx and 5xx codes signify that some sort of error has occurred. When the search fails, a server SHOULD return an OperationOutcome detailing the cause of the failure. Note: An § 19 Note that an empty search result is not a failure. an error.

In some cases, parameters may cause an error, or might not be able to match anything. For instance:

Show as unencoded: HTTP GET | HTTP POST
Issue Search
A parameter may refer to a non-existent resource e.g. GET [base]/Observation?subject=101 , where resource, such as if no Observation with an id of "101" does not exist exists GET [base]/Observation?_id=101 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _id=101
A parameter may refer to a non-existent resource e.g. GET [base]/Observation?patient.identifier=http://example.com/fhir/identifier/mrn|123456 , where there is resource, such as if no patient for Patient with MRN 123456 "1234" exists GET [base]/Observation?patient.identifier=http://example.com/fhir/mrn|1234 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded patient.identifier=http://example.com/fhir/mrn|1234
A parameter may refer to an unknown code e.g. GET [base]/Observation?code=loinc|1234-1 , where the code, such as if LOINC code "1234-1" is not known to the server GET [base]/Observation?code=loinc|1234-1 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code=loinc|1234-1
A parameter may refer to a time that is out of scope e.g. GET [base]/Condition?onset=le1995 , where scope, such as if the system only has data going back to 2001 GET [base]/Condition?onset=le1995 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded onset=le1995
A parameter may use an illegal or unacceptable modifier e.g. GET [base]/Condition?onset:text=1995 , where modifier, such as if the modifier cannot be processed by the server GET [base]/Condition?onset:text=1995 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded onset:text=1995
A data time parameter may have incorrect format e.g. format, such as if the modifier cannot be processed by the server GET [base]/Condition?onset=23%20May%202009 [base]/Condition?onset=23.May.2009 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded onset=23.May.2009
A parameter may be unknown or unsupported (see (more details below) GET [base]/Condition?myInvalidParameter=true POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded myInvalidParameter=true

Note: Empty parameters are not an error - they are just ignored by the server.

Where the content of the parameter is syntactically incorrect, servers SHOULD return an error. § 20 However, where the issue is a logical condition (e.g. (e.g., unknown subject or code), the server SHOULD process the search, including processing the parameter - with the result of returning an empty search set, since the parameter cannot be satisfied. § 21

In such cases, the search process MAY may include an OperationOutcome in the search set that contains additional hints and warnings about the search process. This is included in the search results as an entry with a search mode = of outcome . Clients can use this information to improve future searches. If, for example, a client performed the following search: GET [base]/Observation?patient.identifier=http://example.com/fhir/identifier/mrn|123456 Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?patient.identifier=http://example.com/fhir/identifier/mrn|123456 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded patient.identifier=http://example.com/fhir/identifier/mrn|123456 and there is no patient for MRN 123456, the server would may return a bundle with no results and a warning outcome, such as this .

Unknown and unsupported parameters

Servers may can receive parameters from the client that they do not recognize, or may receive parameters they recognize but do not support (either in general, or for a specific search). In general, servers SHOULD ignore unknown or unsupported parameters for the following reasons: § 22

  • Various HTTP stacks and proxies may add parameters that aren't under the control of the client
  • The client can determine what parameters the server used by examining the self link in the return (see below )

Clients can specify how the request specific server should behave, behavior by using the prefer header header:

  • Prefer: handling=strict: handling=strict : Client requests that the server return an error for any unknown or unsupported parameter
  • Prefer: handling=lenient: handling=lenient : Client requests that the server ignore any unknown or unsupported parameter

Servers SHOULD honor the client's prefer request, but are not required to do so. § 23 For more information, see HTTP Headers on the HTTP Page.

This specification defines FHIR Search operations in both HTTP POST and GET . For details about the HTTP methods regarding search, please see the Search section of the HTTP page.

The following parameters apply to all resources : _content , _id , _lastUpdated , _profile , _query , _security , _source , _tag . Some servers expose a FHIR endpoint that actually represents multiple data stores. For example, a system might expose a single Observation endpoint, even though internally there are distinct systems for labs, vitals, clinical assessments, and symptoms. Alternatively, a system might expose a single Patient endpoint even though it is backed by multiple distinct Patient repositories.

In addition, these "single endpoint/multiple back-end" scenarios, it is possible that the search parameter _text and _filter , (documented below) also applies internal repositories have different capabilities when it comes to all resources (as do the search result parameters). search.

The search parameter _id refers At present, there is no standard way to the logical id declare such limitations as part of the resource, and can be used when the search context specifies CapabilityStatement , other than through custom extensions. A future release of FHIR could provide a resource type: more standard way of performing such declarations.

GET [base]/Patient?_id=23

This search finds the patient resource with the given id (there In any event, systems can only handle such limitations in at least four ways:

  1. By requiring that some searches include certain mandatory criteria. For example, Observation searches might require that the category parameter be present (and only have one resource for a given id). Functionally, this is equivalent to a simple read operation : GET [base]/Patient/23 However, value) or Patient searches might require that the search with parameter _id organization returns a bundle with the requested resource, instead of just the resource itself. Additional parameters parameter be present. These permitted combinations can be added which may provide additional functionality conveyed by extensions on top of this base read equivalence (e.g. the _include ). Note CapabilityStatement . Clients that although fail to satisfy the _id parameter has a type of token, because servers SHALL use exact match with it, there is no 'combination' rules will not be able to search successfully.
  2. By having the intermediary system for that handles the _id parameter. Note dispatch to different back ends perform supplementary filtering such that matches on _id are always case sensitive. The any search parameter _lastUpdated can parameters that cannot be used to select resources based on enforced by the back-end system are instead applied at the intermediary layer, and thus from a 'client' perspective the last time they were changed: GET [base]/Observation?_lastUpdated=gt2010-10-01 This search finds any observations changed since 1-Oct 2010. When this search parameter is used, applications should consider synchronization approaches ( RESTful history or was executed as desired.
  3. By returning a warning message in the Subscription resource ). The search parameters _tag , _profile OperationOutcome and _security (see also: Handling Errors parameters search ) indicating that not all filters were applied on the equivalent elements in the meta element . For example, GET [base]/Condition?_tag=http://acme.org/codes|needs-review searches for all Condition resources with the tag: { "system" : "http://acme.org/codes", "code" : "needs-review" } In the same manner: GET [base]/DiagnosticReport?_profile=http://hl7.org/fhir/StructureDefinition/lipid GET [base]/DiagnosticReport?_profile=Profile/lipid restricts the search to resources. This SHOULD only DiagnosticReport resources that are tagged as conforming to a particular profile. The second reference occur in situations where it is relative, known that some filters haven't been applied. § 24
  4. By exposing distinct FHIR endpoints for each data source and refers a local profile on the same server. different capabilities in an endpoint-specific manner.

_tag , _profile and _security parameters are all token types (see below ).

In addition to the _id parameter which exists for all resources, each FHIR resource type defines its own set of search parameters with their names, types, and meanings. These search parameters are on the same page as the resource definitions, and are also published as part of the standard Capability statement ( XML Servers MAY support batching or JSON multiple requests. § 25 ). In general, the defined search parameters correspond context of search, this allows several searches to be performed serially via a single element in the resource, but this request. Note that each operation of a batch is independent, so it is not required, and some search parameters refer possible to use the same type results of element in multiple places, or refer one request as input to derived values. another in the same batch.

Some When submitting multiple requests via a batch or transaction, the returned bundle is for the batch or transaction as an operation. Therefore, two search parameters defined by resources are associated with more than one path requests in a resource. This means batch would return a bundle that the search parameter matches if any contains at least two entries, each of the paths contain matching content. If a path matches, the whole resource which is returned in the result of a search results. The client may have to examine request (e.g., the resource to determine which path contains batch result bundle will contain entries that are the match. search result bundles).

Servers When bundling requests via batch or transaction , HTTP verbs and the URLs for RESTful interfaces are used. When requesting searches in a bundle, systems SHOULD accept searches via GET, even if they do not required typically accept GET-based searches. § 26 There is no standard way to implement any of convey POST-based searches within a Bundle and the standard architectural differences when searching via GET or POST are not relevant within a Bundle. Servers receiving searches within a Bundle SHOULD NOT impose any GET-specific limitations on search parameters (except for (i.e., restrictions not imposed on POST-based searches) that they would impose if the _id parameter GET-based search had been received outside a Bundle. § 27

Servers MAY support FHIR Messaging . § 28 The mapping of search requests into messages is described above), and may define their own parameters. in more detail in the section Invoking Search via Messages .

Each While search parameters are typically transmitted as URL-Encoded strings (e.g., HTTP Parameters or x-www-form-urlencoded body content), FHIR is modeled with a rich set of primitive and complex data types to describe the data encountered in healthcare. To provide consistent mapping between the two formats, each search parameter is defined by a type that specifies how the search parameter behaves. These are the defined search parameter types:

number Search parameter SHALL be a number (a whole number, or a decimal).
date Search parameter is on a date/time. The date format is the standard XML format, though other formats may be supported.
string Search parameter is a simple string, like a name part. Search is case-insensitive and accent-insensitive. May match just the start of a string. String parameters may contain spaces.
token Search parameter on a coded element or identifier. May be used to search through the text, display, code and code/codesystem (for codes) and label, system and key (for identifier). Its value is either a string or a pair of namespace and value, separated by a "|", depending on the modifier used.
reference A reference to another resource (Reference or canonical).
composite A composite search parameter that combines a search on two values together.
quantity A search parameter that searches on a quantity.
uri A search parameter that searches on a URI (RFC 3986).
special Special logic applies to this parameter per the description of the search parameter.
resource A search parameter defined to chain through into embedded resources.

The Individual search parameters can MAY also append allow "modifiers" that control their behavior. § 29 The kinds of modifiers that available is dependent depend on the type of the search parameter. More details can be found in the Modifiers section of the search page.

Some search parameter being modified. types allow "prefixes" (or "comparators") which can be used to request different match-testing functionality (e.g., greater-than instead of equality). The kinds of comparators allowed depends on the type of the search parameter. More details can be found in the Prefixes section of the search page.

Parameters Generally, an single search test can be broken down into a few parts:

  • a search input value to test with,
  • the type of test being used, and
  • zero or more values from a resource to test against.

For example, a search against the Patient resource for given=value is a request to a server to compare values in the given name of a patient against "value", using the default string test (see string for details). Each of these 'parts' of a search test have a lot of flexibility.

Search inputs are dereferenced by a server based on their listing in the server's CapabilityStatement , according to the CapabilityStatement.rest.resource.searchParam.name element. These values are typically a computer-friendly code defined per by the SearchParameter resource for the parameter, either in SearchParameter.code or SearchParameter.alias . Note that the values listed in the SearchParameter resource are only suggestions, though some implementation guides will add requirements for improved interoperability.

Search input values are parsed according to the search parameter type, as defined in the relevant SearchParameter resource. Parameter names may specify The rules for parsing a modifier as search input value into the equivalent FHIR type can be found on the search page (e.g., converting a suffix. token input into a Coding ).

The modifiers type of test used to compare values are separated from controlled by the search parameter type and a search modifier OR a search prefix, if present. For example, the number search parameter type describes the default search test as an equality test (i.e., {element value} equals {input value} ). A Search Modifier , such as not changes the test - in this case negating the default behavior (i.e., not({element value} equals {input value}) ). Finally, a Search Prefix , allowed on the number search type, can be used to change the test to something like a 'greater than' (i.e., {element value} is greater than {input value} ). Note that a single test cannot contain both a modifier and a prefix.

Many elements in FHIR are defined as arrays (or collections) of values (e.g., a patient can have more than one name or address). When performing a search test against elements that have a cardinality of more than one, the test is considered a 'contains' type test against the collection of values. For example, if a patient has two name elements with values, a test is considered a match if at least one of the values is a match.

When a search parameter points to a complex or backbone element (an element that contains sub-elements), by default the search is interpreted as a colon. Modifiers are: search against one or more values in sub-elements with an appropriate type, as selected by the implementation. A search parameter MAY instead explicitly choose elements by using an expression that instead points directly to the sub-elements. § 30

For all

Search combination logic is defined by an equivalent set logic on the results of individual tests, performed at the resource level. "OR" joined parameters (except combination): :missing are "unions of sets" and "AND" joined parameters are "intersections of sets". Note that the joins are considered at the resource level and search parameters are unordered. This means that complex combinations of "AND" and "OR" are not possible using the basic search syntax. Uses requiring advanced combination logic can consider the _filter ; e.g. gender:missing=true (or false). Searching parameter or Named Queries .

When multiple search parameters passed to a single search, they are used to create an intersection of the results - in other words, multiple parameters are joined via "AND". For example, a search for a patient that includes a given name and a family name will only return records that match BOTH: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?given=valueGiven&family=valueFamily POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given=valueGiven&family=valueFamily will return only Patient records with a family name of "valueFamily" and a given name of "valueGiven".

It is also possible to use an "AND" join repeated on the same element. When doing so, the join behavior is the same as when using different elements. For example, a search that asks for having two specific given names: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?given=valueGivenA&given=valueGivenB POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given=valueGivenA&given=valueGivenB will return records that have BOTH a match for the given name of "valueGivenA" AND a match for the given name of "valueGivenB". Note that this will match both patient records that have a single gender:missing=true name containing multiple given elements as well as records that have a multiple name elements that, in total , contain the values: Show as: FHIR+JSON | FHIR+XML "Patient": { "name": [{ "given": [ "valueA", "valueB" ] }] } "Patient": { "name": [{ "given": [ "valueA" ] }, { "given": [ "valueB" ] }] } <Patient> <name> <given value="valueA"/> <given value="valueB"/> </name> </Patient> <Patient> <name> <given value="valueA"/> </name> <name> <given value="valueB"/> </name> </Patient>

In order to search for unions of results (values joined by "OR"), values can be separated by a comma (",") character. For example, a search for a patient with EITHER of two given names: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?given=valueGivenA,valueGivenB POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given=valueGivenA,valueGivenB will return all Patient records with EITHER a given name of "valueGivenA" OR "valueGivenB". This includes patient records that have BOTH "valueGivenA" and "valueGivenB" (e.g., inclusive or).

Each value of an "OR" query may contain a prefix if allowed by the resources search type. For example, a search for a heart rate value ( LOINC 8867-4 icon ) outside of the 'normal resting range of adults': Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?code=http://loinc.org|8867-4&value-quantity=lt60,gt100 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code=http://loinc.org|8867-4&value-quantity=lt60,gt100 will match against Observations that don't have the LOINC code for a Heart Rate and have a value that is EITHER less than 60 OR greater than 100.

If a modifier is used on a search parameter, it applies to each value of an "OR" query. For example, searching for either of two exact given names: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?given:exact=GivenA,GivenB POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given:exact=GivenA,GivenB will match against Patients that contain a given name of exactly "GivenA", Patients that contain a given name of exactly "GivenB", and Patients that contain both values.

It is possible to combine both "AND" and "OR" type queries together in a single request. For example, a search that includes a family name and either of two given names: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?given=valueGivenA,valueGivenB&family=valueFamily POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given=valueGivenA,valueGivenB&family=valueFamily will return records that match a family name of "valueFamily" AND a given name of either "valueGivenA" OR "valueGivenB".

Note that there is not a syntax to request unions on different elements (OR joins). For example, a client that wants records with either a given OR family name of "valueName". However, it is possible to define search parameters that operate on multiple elements. For example, the gender described use case of searching for a patient by any part of their name has a search parameter (which usually equates on Patient called name , which matches any part of a name (e.g., name=valueName ). It is also possible to define composite search parameters , which allows servers to provide this functionality.

If a client wants results based on OR-joins of unrelated elements, or if there is not having a combined search parameter defined or supported on a server, the relevant results can be retrieved by issuing multiple queries, either serially or in a batch.

The following table contains examples of how joins work depending on their element types. Note that this table is illustrative and not comprehensive. Additionally, the joins listed below can be combined in a single request to form more complicated logic. For brevity, this table demonstrates the joins only against the same element type, though this is not a requirement. For example, it is common to join one parameter against a simple scalar element with another that is an array of complex elements. In this table, the following definitions are used:

  • Scalar refers to elements that have a maximum cardinality of one.
  • Array refers to elements that have a maximum cardinality greater than one.
  • Simple refers to elements that do not contain additional elements (e.g., Primitive Types ).
  • Complex refers to elements that contain additional elements (e.g., HumanName , etc.)

Show as unencoded: HTTP GET | HTTP POST
Context Short Example
AND , Scalar , Simple Intersection of records that match each of the search criteria GET [base]/Patient?death-date=ge2022-01-01&death-date=lt2023-01-01 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded death-date=ge2022-01-01&death-date=lt2023-01-01
The search is asking for patients with a death-date on or after January 1, 2022 and a death-date before January 1, 2023. The results are the intersection of patients with a deceasedDateTime on or after January 1, 2022 and patients with a deceasedDateTime before January 1, 2023. Each match will contain a single value in the resource). Searching requested range.
OR , Scalar , Simple Union of records that match each of the search criteria GET [base]/Patient?death-date=ge2030-01-01,lt1980-01-01 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded death-date=ge2030-01-01,lt1900-01-01
The search is asking for patients with a gender:missing=false death-date on or after January 1, 2030 or a death-date before January 1, 1900. The results are the union of patients with a deceasedDateTime on or after January 1, 2030 and patients with a deceasedDateTime before January 1, 1900. Each match will return all contain a single value in the resources requested range (e.g., checking for dates outside the allowed range).
AND , Array , Simple Intersection of records that contain at least one match for each search criteria GET [base]/AllergyIntolerance?category=medication&category=biologic POST [base]/AllergyIntolerance/_search Content-Type: application/x-www-form-urlencoded category=medication&category=biologic
The search is asking for allergies or intolerances with a category of medication and a category of biologic . The results are the intersection of AllergyIntolerance records records with each of the requested category values. Each matching record will contain at least one of each of the requested category values.
OR , Array , Simple Union of records that contain at least one match for each search criteria GET [base]/AllergyIntolerance?category=medication,biologic POST [base]/AllergyIntolerance/_search Content-Type: application/x-www-form-urlencoded category=medication,biologic
The search is asking for allergies or intolerances with a category of either medication or biologic . The results are the union of AllergyIntolerance records records with any of the requested category values. Each matching record will contain at least one of either of the requested category values, and can contain both.
AND , Array , Complex Intersection of records that contain at least one match for each search criteria GET [base]/Patient?name=valueA&name=valueB POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded name=valueA&name=valueB
The search is asking for patients with a name of 'valueA' a name of 'valueB'. The results are the intersection of patients that have each of the requested values in any component of their name. Each match will contain each of the requested values in some form. E.g., a patient with the given names of both 'valueA' and 'valueB' will match, as well as a patient with a given name of 'valueA' and a family name of 'valueB', etc..
OR , Array , Complex Union of records that contain at least one match for any search criteria GET [base]/Patient?name=valueA,valueB POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded name=valueA,valueB
The search is asking for patients with a name of either 'valueA' or 'valueB'. The results are the union of patients with 'valueA' anywhere in their name and patients with 'valueB' anywhere in their name. Each matching record will contain at least one of the search criteria.

Generally, search parameters are used as filters to refine search results based on one or more resource elements. For example, a query might find patients born in a certain year by using the birthdate search parameter, which maps to the Patient.birthDate element. Sometimes it is necessary or desirable to use a search parameter with a different behavior, for example, searching for patients that do not have a birth date in their records. Instead of requiring many search parameters on an element to cover each type of use, this specification defines modifiers that can be used to change the meaning of a search parameter while leaving element mappings intact.

Search parameter modifiers are defined by the search-modifier-code code system. Search parameter definitions MAY include a list of allowed modifiers in the SearchParameter.modifier element, which is bound to the search-modifier-code value set. § 31 Servers SHALL support any modifiers present in search parameters the server advertises support for. § 32 Servers MAY choose to support additional modifiers. § 33 Note that servers MAY support modifiers on types not defined in this specification. § 34

In search requests, search modifiers are used by appending the modifier as a suffix to the search parameter name, with the syntax of: [name]:[modifier] , such as birthdate:missing . Note that only a single modifier is allowed on a single search parameter. If multiple layers of modification are necessary, a new search parameter can be defined with the appropriate behavior. If the desired behavior is not possible to define in a search parameter without multiple stacked modifiers, an operation can be defined.

Since modifiers change the meaning of a search parameter, a server SHALL reject any search request that contains a search parameter with an unsupported modifier. § 35 For example, if the server supports the name search parameter, but not the :exact modifier on the name, it would reject a search with the parameter name:exact=Bill , using an HTTP 400 error with an OperationOutcome with a clear error message .

While support for modifiers is applied per search parameter, modifiers are generally defined according to search parameter type. For example, the ":exact" modifier has meaning when applied to string-type search parameters but has no meaning and cannot be used with token-type search parameters. The exception is the search parameters type special . The definition for any search parameter of type "special" SHALL explicitly list any allowed modifiers; this list MAY include any value from the search-modifier-code code system. § 36

The modifiers defined by this specification are:

gender above reference , token , uri Tests whether the value in a resource is or subsumes the supplied parameter value (is-a, or hierarchical relationships).
below reference , token , uri Tests whether the value in a resource is or is subsumed by the supplied parameter value (is-a, or hierarchical relationships).
code-text reference , token Tests whether a coded value (e.g., Coding.code ) in a resource matches the supplied parameter value using basic string matching (starts with or is, case-insensitive).
contains reference , string , uri Tests whether the value in a resource includes the supplied parameter value anywhere within the field being searched or if a hierarchial relationship has a matching value within the tree it covers.
exact string Tests whether the value in a resource exactly matches the supplied parameter value (the whole string, including casing and accents).
identifier reference Tests whether the Reference.identifier in a resource (rather than the Reference.reference ) matches the supplied parameter value.
in token Tests whether the value in a resource is a member of the supplied parameter ValueSet.
iterate n/a (not allowed anywhere by default) The search parameter indicates an inclusion directive (_include, _revinclude) that is applied to an included resource instead of the matching resource.
missing date , number , quantity , reference , string , token , uri Tests whether the value in a resource is present (when the supplied parameter value is true ) or absent (when the supplied parameter value is false ).
not token Tests whether the value in a resource does not match the specified parameter value. Note that this includes resources that have no value for the parameter.
not-in reference , token Tests whether the value in a resource is not a member of the supplied parameter ValueSet.
of-type token (only Identifier ) Tests whether the Identifier value in a resource matches the supplied parameter value.
text reference , token Tests whether the textual value in a resource (e.g., CodeableConcept.text , Coding.display , Identifier.type.text , or Reference.display ) matches the supplied parameter value using basic string matching (begins with or is, case-insensitive).
text string The search parameter value is to be processed as input to a search with advanced text handling.
text-advanced reference , token Tests whether the value in a resource matches the supplied parameter value using advanced text handling that searches text associated with the code/value - e.g., CodeableConcept.text , Coding.display , or Identifier.type.text .
[type] reference Tests whether the value in a resource points to a resource of the supplied parameter type. Note: a concrete ResourceType is specified as the modifier (e.g., not the literal :[type], but a value such as :Patient ).

Note that modifiers are allowed in searches that combine multiple terms. When using a modifier in "or" joined search parameter values, the modifier applies to ALL values present. For simple example, in given:exact=valueA,valueB , the exact modifier is used for both "valueA" and "valueB". Additional details can be found in the Searching Multiple Values section of the Search page.

The above modifier allows clients to search hierarchies of data based on relationships. The above modifier is only allowed on search parameters with search types reference , token , and uri . The exact semantics for use vary depending on the type elements, :missing=true will match of search parameter:

When the above modifier is used with a reference type search parameter and the target is an element with the FHIR type Reference , the search is interpreted as a hierarchical search on linked resources of the same type, including exact matches and all elements children of those matches. The above modifier is only valid for circular references - that is, references that point to another instance of the same type of resource where either those references establish a hierarchy. For example, the underlying Location resource can define a hierarchy using the partOf element to track locations that are inside each other (e.g., Location/A101 , a room, is omitted or where partOf Location/A , a floor). Meanwhile, the Patient resource could refer to other patient resources via the link element, but no hierarchical meaning is intended. Further discussion about the requirements and uses for this type of search can be found in the section Searching Hierarchies .

When using the above modifier on a reference search type parameter, all typically-valid search parameter reference inputs are allowed. Note that the actual Resources that establish hierarchical references and the search parameters used are listed in the Circular Resource References section of the References page.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Procedure?location:above=A101 POST [base]/Procedure/_search Content-Type: application/x-www-form-urlencoded location:above=A101 would match any Procedure resources with locations:

  • A101 , Location/A101 , https://example.org/Location/A101 - this location by ID
  • A100 , Location/A100 , https://example.org/Location/A100 - parent of A101, representing the first floor (A101 - A199)
  • BuildingA , Location/BuildingA , https://example.org/Location/BuildingA - parent of A100, representing the building 'A'

When the above modifier is used with a reference type search parameter and the target is an element with the FHIR type canonical , the search is present interpreted as a version search against the canonical resource. The format of the parameter is either [url] or [url]|[version] (see Encoding Note ). This search is only allowed if the version scheme for the resource is either specified or the server chooses to infer it. Version-related search criteria against resources with extensions but unknown versioning schemes SHALL be either ignored or rejected. § 37 The above modifier comparison is performed as a 'greater than' against the version-scheme defined by the resource. Any versions that match the specified search are excluded from the result. The versions returned will be listed in no @value particular order.

When using the above modifier on a canonical reference, all typically-valid search parameter token inputs are allowed. Note that any vertical pipe ( | ) characters that are part of the URL must be escaped ( %7C ) and can cause issues with parsing of the parameter.

More information can be found in the section References and Versions .

When the above modifier is used with a token type search parameter, the supplied token is a concept with the form [system]|[code] (see Encoding Note ) and the intention is to test whether the coding in a resource subsumes the specified search code. Matches to the input token concept have an is-a relationship with the coding in the resource, and this includes the coding itself.

When using the above modifier on a token, all typically-valid search parameter token inputs are allowed.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?code:above=http://snomed.info/sct|3738000 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code:above=http://snomed.info/sct|3738000 for Observations with a code above SNOMED 'Viral hepatitis (disorder)' will match any Observation resources with codes:

  • SNOMED 3738000 - Viral hepatitis (this code)
  • SNOMED 235862008 - Hepatitis due to infection (parent of 'Viral hepatitis')
  • SNOMED 128241005 - Inflammatory disease of liver (parent of 'Hepatitis due to infection')
  • etc.
  • SNOMED 312130009 - Viral infection by site (parent of 'Viral hepatitis')
  • SNOMED 301810000 - Infection by site (parent of 'Viral infection by site')
  • etc.
Note that there are two hierarchical parents to the requested code and parent matches traverse up each path.

When the above modifier is used with a uri type search parameter, the value is used for partial matching based on URL path segments. Because of the hierarchical behavior of above , the modifier only applies to URIs that are URLs and cannot be used with URNs such as OIDs. Note that there are not many use cases where above is useful compared to a below search.

When using the above modifier on a uri, all typically-valid search parameter uri inputs are allowed.

For string: :exact example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/ValueSet?url:above=http://acme.org/fhir/ValueSet/123/_history/5 POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url:above=http://acme.org/fhir/ValueSet/123/_history/5 would match any ValueSet resources with a url of:

  • http://acme.org/fhir/ValueSet/123/_history/5 (the - full match needs
  • http://acme.org/fhir/ValueSet/123/_history - parent of requested URI
  • http://acme.org/fhir/ValueSet/123 - ancestor of requested URI
  • http://acme.org/fhir/ValueSet - ancestor of requested URI
  • http://acme.org/fhir - ancestor of requested URI
  • http://acme.org/ - ancestor of requested URI

The below modifier allows clients to be exact, search hierarchies of data based on relationships. The below modifier is only allowed on search parameters of type reference , token , and uri . The exact semantics for use vary depending on the type of search parameter:

When the below modifier is used with a reference type search parameter and the target is an element with the FHIR type Reference , the search is interpreted as a hierarchical search on linked resources of the same type, including exact matches and all children of those matches. The below modifier is only valid for circular references - that is, references that point to another instance of the same type of resource where those references establish a hierarchy. For example, the Location resource can define a hierarchy using the partOf element to track locations that are inside each other (e.g., Location/A101 , a room, is partOf Location/A , a floor). Meanwhile, the Patient resource could refer to other patient resources via the link element, but no partial matches, case sensitive hierarchical meaning is intended. Further discussion about the requirements and accent-sensitive), or :contains uses for this type of search can be found in the section Searching Hierarchies .

When using the below (case insensitive modifier on a hierarchical reference, all typically-valid search parameter reference inputs are allowed. Note that the actual Resources that establish hierarchical references and accent-insensitive, partial the search parameters used are listed in the Circular Resource References section of the References page.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Procedure?location:below=BuildingA POST [base]/Procedure/_search Content-Type: application/x-www-form-urlencoded location:below=BuildingA for Procedures with a location below BuildingA would match at start or end), instead any Procedure resources with locations:

  • BuildingA , Location/BuildingA , https://example.org/Location/BuildingA - this location by ID
  • A100 , Location/A100 , https://example.org/Location/A100 - child of BuildingA, representing the default behavior (case insensitive and accent-insensitive, partial matches at first floor
  • A101 , Location/A101 , https://example.org/Location/A101 - child of A100, room 101
  • A1.. , etc. - child of A100, rooms on the start first floor
  • A200 , Location/A200 , https://example.org/Location/A200 - child of BuildingA, representing the string). second floor
  • etc.

When the below modifier is used with a reference type search parameter and the target is an element with the FHIR type canonical , the search is interpreted as a version search against the canonical resource. The format of the parameter is either [url] or [url]|[version] (see Encoding Note ). This search is only allowed if the version scheme for the resource is either specified or the server chooses to infer it. Version-related search criteria against resources with unknown versioning schemes SHALL be either ignored or rejected. § 38 The below modifier comparison is performed as a 'less than' against the version-scheme defined by the resource. Any versions that match the specified search are excluded from the result. The versions returned will be listed in no particular order.

When using the below modifier on a canonical reference, all typically-valid search parameter token inputs are allowed. Note that any vertical pipe ( | ) characters that are part of the URL must be escaped ( %7C ) and can cause issues with parsing of the parameter.

More information can be found in the section References and Versions .

When the below modifier is used with a token type search parameter, the supplied token is a concept with the form [system]|[code] (see Encoding Note ) and the intention is to test whether the coding in a resource is subsumed by the specified search code. Matches include resources that have a coding that has an is-a relationship with the input concept, and this includes the coding itself.

When using the below modifier on a token, all typically-valid search parameter token inputs are allowed.

For token: :text example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?code:below=http://snomed.info/sct|235862008 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code:below=http://snomed.info/sct|235862008 for Observations with a code below (the SNOMED 'Hepatitis due to infection' would match does any Observation resources with codes:

  • SNOMED 235862008 - Hepatitis due to infection (this code)
  • SNOMED 773113008 - Acute infectious hepatitis (child)
  • SNOMED 95897009 - Amebic hepatitis (child)
  • etc.

Note that there is no limit inherent to the referential search. If child concepts contain child concepts of their own, the search continues down the tree in each path until reaching a terminal node.

The below modifier is useful when trying to resolve MIME types. Further documentation can be found in the Searching MIME Types section of this page.

When the below modifier is used with a uri type search parameter, the value is used for partial searches matching based on URL path segments. Because of the text portion hierarchical behavior of below , the modifier only applies to URIs that are URLs and cannot be used with URNs such as OIDs.

When using the below modifier on a CodeableConcept uri, all typically-valid search parameter uri inputs are allowed.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/ValueSet?url:below=http://acme.org/fhir POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url:above=http://acme.org/fhir would match any ValueSet resources with a url of:

  • http://acme.org/fhir - full match
  • http://acme.org/fhir/ValueSet - child of requested URI
  • http://acme.org/fhir/ValueSet/123 - descendant of requested URI
  • http://acme.org/fhir/ValueSet/123/_history - descendant of requested URI
  • http://acme.org/fhir/ValueSet/123/_history/1 - descendant of requested URI
  • etc.

The code-text modifier allows clients to indicate that a supplied string input is used as a case-insensitive and combining-character insensitive test when matching against the start of target string. This modifier is used to do a 'standard' string search against code values. Note that the handling of extended grapheme clusters icon is within the discretion of the server, i.e., the server decides if a search parameter matches on canonically equivalent characters or matches on the display portion actual used Unicode code points. Case-insensitive comparisons do not take locale into account, and will result in unsatisfactory results for certain locales. Character case definitions and conversions are out of scope for the FHIR standard, and the results of such operations are implementation dependent.

code-text is only allowed on reference and token type search parameters. When using the 'code-text' modifier, all typically-valid search parameter string inputs are allowed.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?language:code-text=en POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded language:code-text=EN would match any Patient resources with a Coding), instead communication language of:

  • en - requested code text (case-insensitive)
  • en-AU - starts with requested code text (case-insensitive)
  • en-CA - starts with requested code text (case-insensitive)
  • en-GB - starts with requested code text (case-insensitive)
  • etc.

The contains modifier allows clients to indicate that a supplied input is used as a containment test when matching against the target value. The exact semantics for use vary depending on the type of search parameter.

When using the default contains modifier with reference type search which uses codes. Other defined modifiers parameters, reference test values are :in , :below , allowed (e.g., a logical identifier).

The search parameter is a reference to a resource that is part of a hierarchical tree, and the search should return the specified resource along with all resources above (ancestors) and below (descendants) it in the hierarchy. This is equivalent to combining both :above and :not-in :below which searches plus the specified resource itself.

This modifier is useful when you need the full context of a hierarchical resource in a single query. For example, when working on a specific task in a task tree, you may want to see the entire branch from root to leaves in one request.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Task?part-of:contains=Task/T1A POST [base]/Task/_search Content-Type: application/x-www-form-urlencoded part-of:contains=Task/T1A would match any Task resources that contain task T1A in a hierarchy, including T1A itself, its ancestors, and its descendants. Given a task tree where:

  • T1 is the root task
  • T1A and T1B are described below. sub-tasks of T1
  • For reference: :[type] T1A1 and T1A2 are sub-tasks of T1A

This search would return: T1 (ancestor), T1A (the specified task), T1A1 and T1A2 (descendants).

Note: The contains where [type] modifier can only be used with reference search parameters that support hierarchical relationships (typically those that reference the same resource type they are defined on, like Location.partOf or Task.partOf ).

When using the contains modifier with string or uri type search parameters, all typically-valid search parameter string inputs are allowed.

The contains modifier in this context allows clients to indicate that a supplied string input is used as a case-insensitive and combining-character insensitive test when matching anywhere in the name target string. Note that the handling of extended grapheme clusters icon is within the discretion of the server, i.e., the server decides if a type string search parameter matches on canonically equivalent characters or matches on the actual used Unicode code points. Case-insensitive comparisons do not take locale into account, and will result in unsatisfactory results for certain locales. Character case definitions and conversions are out of resource, :identifier, and, scope for some parameters, :above the FHIR standard, and :below the results of such operations are implementation dependent.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?family:contains=son POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded family:contains=son would match any Patient resources with a family names such as:

  • Son - requested string (case-insensitive)
  • For uri: :below , :above Sonder - begins with requested string (case-insensitive)
  • Erikson - ends with requested string (case-insensitive)
  • Samsonite - contains requested string (case-insensitive)
  • etc.

The exact modifier allows clients to indicate that instead of an a supplied string input is the complete and exact value that tested for a match, either including casing and combining characters. Note that the handling of extended grapheme clusters icon is within the discretion of the server, i.e., the server decides if a string search term left parameter matches the value, on canonically equivalent characters or vice-versa. matches on the actual used Unicode code points. Case-insensitive comparisons do not take locale into account, and will result in unsatisfactory results for certain locales. Character case definitions and conversions are out of scope for the FHIR standard, and the results of such operations are implementation dependent.

exact is only allowed on string type search parameters. When using the 'exact' modifier, all typically-valid search parameter string inputs are allowed.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?family:exact=Son POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded family:exact=Son will only match Patient resources with a family name of:

  • Son - requested string (case-sensitive)

The identifier modifier allows clients to indicate that a supplied token is used to match against the Reference.identifier element of a reference instead of the Reference.reference element. The format of the parameter is [system]|[code] (see Encoding Note ). Note that chaining behavior is not defined when using the identifier modifier, nor is the behavior defined when targeting references without explicit reference values (e.g., canonical references, etc.). Server SHALL reject any implementers have discretion on behavior for searches in these cases.

identifier is only allowed on reference type search request parameters and target elements that are the Reference FHIR type. When using the 'identifier' modifier, all typically-valid search parameter token inputs are allowed.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?subject:identifier=http://example.org/fhir/mrn|12345 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded subject:identifier=http://example.org/fhir/mrn|12345 for observations with a subject containing the identifier 'http://example.org/fhir/mrn|12345' would match Observation resources such as: Show as: FHIR+JSON | FHIR+XML "Observation": { "subject": { "reference": "Patient/abc", "identifier": { "system": "http://example.org/fhir/mrn", "value": "12345" } } } <Observation> <subject> <reference value="Patient/abc"/> <identifier> <system value="http://example.org/fhir/mrn"/> <value value="12345"/> </identifier> </subject> </Observation> but will not match: Show as: FHIR+JSON | FHIR+XML "Observation": { "subject": { "reference": "Patient/abc" } } <Observation> <subject> <reference value="Patient/abc"/> </subject> </Observation> even if the Patient resource for Patient/abc includes the requested identifier among its Patient.identifier values.

For more details about the difference between the identifier modifier and chained-searches on the identifier element, see Searching Identifiers .

The in modifier is used to filter based on value membership of codes in Value Sets. The in modifier is only allowed on token type search parameters.

When the in modifier is used with a token search parameter, the input is a uri (relative or absolute) that identifies a value set, and the search parameter tests whether the coding is in the specified value set. The search input value may be literal (to an address where the value set can be found) or logical (values of ValueSet.url ). If the server can treat the value as a literal URL, it does, else it tries to match known logical ValueSet.url values. Note that the URI need not point to the root value set, http://snomed.info/sct?fhir_vs=isa/235862008 is a valid input as a reference to a subset of SNOMED CT 'Hepatitis due to infection', but the parameter value will need to be URL Encoded in order to be a valid parameter.

When using the in modifier on a token, only tokens targeting value sets are allowed (e.g., a boolean token parameter target is not allowed).

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Condition?code:in=ValueSet/123 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:in=ValueSet/123 would match any conditions that contain any code from 'ValueSet/123'.

Similarly, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Condition?code:in=http://snomed.info/sct?fhir_vs=isa/235862008 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:in=http://snomed.info/sct?fhir_vs=isa/235862008 would match any conditions that contain any code from SNOMED CT that contains is suffixed by a 235862008 , e.g.:

  • SNOMED 235862008 - Hepatitis due to infection (this code)
  • SNOMED 773113008 - Acute infectious hepatitis (is-a 235862008)
  • SNOMED 95897009 - Amebic hepatitis (is-a 235862008)
  • etc.

The iterate modifier is used to indicate that an inclusion directive should be applied to included resources as well, rather than only the matching resources. Note that this modifier is not defined for any search parameter types and can only be applied to the search result parameters of _include and _revinclude .

When the iterate modifier is used, the input provided is the same as the input for the inclusion directive (see Including other resources ).

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?code=http://snomed.info/sct|3738000&_include=Observation:patient&_include:iterate=Patient:link POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code=http://snomed.info/sct|3738000&_include=Observation:patient&_include:iterate=Patient:link would match any observations with the SNOMED code 3738000 (Viral hepatitis (disorder)). The results would include resources found by following the chained search reference Observation.patient , which are Patient resources linked via Observation.subject . Additionally, the server does would iterate through the included patient records and follow the Patient.link FHIR references, including linked Patient or RelatedPerson resources.

More information can be found in the section Including other resources

Note that the iterate modifier causes implementations to perform a sub-query for each iterate directive for each resource it is based on. Using iterate directives can often reduce the total processing time of a set of queries (by reducing the number of round-trips) but can significantly increase the processing time of a single query.As noted in Including Referenced Resources , servers have discretion about limiting the depth of recursion, which iterations to support, and how many resources to include. When results are truncated, it is recommended for servers to inform clients via search outcome.

 

The missing modifier allows clients to filter based on whether resources contain values that can match a search parameter. Usually, this equates to testing if a resource has an element or not.

missing is allowed on search parameter types that represent single-elements: date , number , quantity , reference , string , token , uri . When using the 'missing' modifier, the only valid input values are the literal values true and false .

Searching for [parameter]:missing=true requests all resources that do not support have a value in the matching element or where the element is present with extensions, but no value is specified.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?given:missing=true POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given:missing=true would match any Patient records that do not have any value in Patient.name that contains a value for given , even if a patient contains a Patient.name that parameter. has a given with an extension and no value (e.g., a Data Absent Reason).

Searching for [parameter]:missing=false requests all resources that do have a value in the matching element.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?given:missing=false POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given:missing=false would match any Patient records that have any value in Patient.name that contains a value for given .

The not modifier allows clients to filter based on whether resources do not contain a specified token based on the search parameter input.

not is only allowed on search parameters of type token . When using the 'not' modifier, all typically-valid search parameter token inputs are allowed.

Searching for [parameter]:not=[value] requests all resources that do not have any matching value in the searched element(s).

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?gender:not=male POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded gender:not=male would match any Patient records that do not have male as the value in Patient.gender . This includes:

Similarly, the server supports search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Composition?section:not=48765-2 POST [base]/Composition/_search Content-Type: application/x-www-form-urlencoded Composition?section:not=48765-2 for documents without an "Allergies and adverse reaction" section ( LOINC 48765-2 icon ) would return all Composition records that do not contain any section with a code of '48765-2'. This search does not return "any document that has a section that is not an Allergies and adverse reaction section". In the presence of multiple possible matches, the negation applies to the set and not each individual entry.

Note that the name not modifier can behave in undesirable ways with "or"-joined parameter values. Specifically, consider a query that uses a scalar (max cardinality one) value, such as: gender:not=male,female . Using the 'default' rules, the query is expanded to be the union of the sets of: patients that do not have a gender element value or that contain any value other than "male", and patients that do not have a gender element value or that contain any value other than "female" - the union of those sets will always contain all records.

Implementer feedback is requested on this behavior and if additional rules concerning the not modifier would be appropriate. In the meantime, use of the not modifier with "or"-joined search param, but terms is not recommended. Implementers are instead recommended to use either the :exact _filter parameter or Named Queries .

 

The not-in modifier is used to filter based on a value exclusion test for codes of Value Sets. The not-in modifier is only allowed on token type search parameters.

When the name, not-in modifier is used with a token search parameter, the input is a uri (relative or absolute) that identifies a value set, and the search parameter tests whether the coding is not in the specified value set. The search input value may be literal (to an address where the value set can be found) or logical (values of ValueSet.url ). If the server can treat the value as a literal URL, it should reject does, else it tries to match known logical ValueSet.url values. Note that the URI need not point to the root value set, http://snomed.info/sct?fhir_vs=isa/235862008 is a valid input as a reference to a subset of SNOMED CT 'Hepatitis due to infection', but the parameter value will need to be URL Encoded in order to be a valid parameter.

When using the not-in modifier on a token, only tokens targeting value sets are allowed (e.g., a boolean token parameter target is not allowed).

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Condition?code:not-in=ValueSet/123 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:not-in=ValueSet/123 would match any conditions that do not contain any code from 'ValueSet/123'.

Similarly, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Condition?code:not-in=http://snomed.info/sct?fhir_vs=isa/235862008 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:not-in=http://snomed.info/sct?fhir_vs=isa/235862008 would match any conditions that do not contain any code from SNOMED CT that is a 235862008 , e.g., all codes excluding :

  • SNOMED 235862008 - Hepatitis due to infection (this code)
  • SNOMED 773113008 - Acute infectious hepatitis (is-a 235862008)
  • SNOMED 95897009 - Amebic hepatitis (is-a 235862008)
  • etc.

The of-type modifier allows clients to filter for resource Identifier , based on the Identifier.type.coding.system , Identifier.type.coding.code and Identifier.value . This allows searches for specific values only within a specific identifier code system. The format when using 'of-type' is [system]|[code]|[value] (see Encoding Note ), where [system] and [code] refer to the code and system in Identifier.type.coding ; the system and code portion is considered a match if the the system|code token would match a given Identifier.type.coding . The [value] test is a string match against Identifier.value . All three parts must be present.

of-type is only allowed on search parameters of type token , and further restricted to parameters targeting the Identifier type. When using the 'of-type' modifier, all typically-valid token values are valid for the system and code segments, and all typically-valid string values are valid for the value segment. Note that input values need to escaped in order to be processed correctly and values including reserved characters such as a vertical pipe ( | ) can cause parsing issues.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?identifier:of-type=http://terminology.hl7.org/CodeSystem/v2-0203|MR|12345 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded identifier:of-type=http://terminology.hl7.org/CodeSystem/v2-0203|MR|12345 for patients that contain an identifier that has a type coding of with a system of http://terminology.hl7.org/CodeSystem/v2-0203 , a code of MR (which identifies Medical Record Numbers), and a value of 12345 will return records such as: Show as: FHIR+JSON | FHIR+XML "Patient": { "identifier": [{ "type": { "coding" : { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } } "system": "http://example.org/ehr-primary/", "value": "12345" }] } <Patient> <identifier> <type> <coding> <system value="http://terminology.hl7.org/CodeSystem/v2-0203"/> <value value="MR"/> </coding> </type> <system value="http://example.org/ehr-primary"/> <value value="12345"/> </identifier> </Patient> This can be used to disambiguate between data sets that contain collisions. For example, the above search will NOT return values with a different identifying type, such as: Show as: FHIR+JSON | FHIR+XML "Patient": { "identifier": [{ "type": { "coding" : { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MRT" } } "system": "http://example.org/ehr-er", "value": "12345" }] } <Patient> <identifier> <type> <coding> <system value="http://terminology.hl7.org/CodeSystem/v2-0203"/> <value value="MRT"/> </coding> </type> <system value="http://example.org/ehr-er"/> <value value="12345"/> </identifier> </Patient> which signifies that the identifier is a Temporary Medical Record Number.

The text modifier on search parameters of type reference and token allows clients to indicate that a supplied string is to be used to perform a string search against a textual value associated with a code or value. For example, CodeableConcept.text , Coding.display , Identifier.type.text , or Identifier.assigner.display . Search matching is performed using basic string matching rules - begins with or is, case-insensitive.

In this context, the text modifier is only allowed on reference and token type search parameters. When using the 'text' modifier, all typically-valid search parameter string inputs are allowed.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Condition?code:text=headache POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:text=headache would match Condition resources containing any codes that start with or equal the string 'headache' (case-insensitive), such as:

  • SNOMED name:exact=Bill 25064002 - Headache finding
  • SNOMED 398987004 - Headache following lumbar puncture
  • SNOMED 230480006 - Headache following myelography (disorder)
  • ICD-10 R51 - Headache
  • ICD-10 R51.0 - Headache with orthostatic component, not elsewhere classified
  • ICD-10 R51.9 - Headache, unspecified
  • etc.

Note that the search is not expected to return results with codes such as SNOMED 735938006 , since the code text of 'Acute headache' does not match a default string search of the term headache (case-insensitive, begins with or equals). For advanced searching of related text, see the text-advanced search modifier.

For more details about the difference between the identifier modifier and chained-searches on the identifier element, see Searching Identifiers .

The text modifier allows clients to request matching based on advanced string processing of the search parameter input. Implementers of the text modifier SHOULD support a sophisticated search functionality of the type offered by typical text indexing services. § 39 The value of the parameter is a text-based search, which may involve searching multiple words with thesaurus and proximity considerations, and logical operations such as AND, OR, etc.. Note that only a few servers are expected to offer this facility.

Implementers could consider using the rules specified by the OData specification for the $search parameter icon. Typical implementations would use Lucene, Solr, an SQL-based full text search, or some similar indexing service.

text is only allowed on search parameters of type string . When using the 'text' modifier, all typically-valid search parameter string inputs are allowed.

For example, assuming a search parameter section-text that applies to Composition.section.text , the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Composition?section:text=(bone OR liver) and metastases POST [base]/Composition/_search Content-Type: application/x-www-form-urlencoded section:text=(bone OR liver) and metastases for compositions about metastases in the bones or liver of subjects will search for those literal values, but may also search for terms such as 'cancerous growth', 'tumor', etc..

The 400 text-advanced error modifier allows clients to request matching based on advanced string processing of the search parameter input against the text associated with a code or value. For example, CodeableConcept.text , Coding.display , or Identifier.type.text . Implementers of the text-advanced modifier SHOULD support a sophisticated search functionality of the type offered by typical text indexing services, but MAY support only basic search with minor additions (e.g., word-boundary recognition). § 40 The value of the parameter is a text-based search, which may involve searching multiple words with thesaurus and proximity considerations, and logical operations such as AND, OR, etc..

text-advanced is allowed on search parameters of type reference and token . When using the 'text-advanced' modifier, all typically-valid search parameter string inputs are allowed.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Condition?code:text-advanced=headache POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:text-ad=headache would match Condition resources containing codes with text that equals or begins with 'headache', case-insensitive (e.g., same as the text modifier) such as:

  • SNOMED 25064002 - Headache finding
  • SNOMED 398987004 - Headache following lumbar puncture
  • SNOMED 230480006 - Headache following myelography (disorder)
  • ICD-10 R51 - Headache
  • ICD-10 R51.0 - Headache with orthostatic component, not elsewhere classified
  • ICD-10 R51.9 - Headache, unspecified
  • etc.

However, it would also match Condition resources containing codes with text containing the word 'headache' such as:

  • SNOMED 735938006 - Acute headache
  • SNOMED 95660002 - Thunderclap headache
  • SNOMED 4969004 - Sinus headache
  • ICD-10 G44.019 - Episodic cluster headache, not intractable
  • ICD-10 G44.81 - Hypnic headache
  • etc.

Additionally, a server may return Condition resources with codes containing synonymous text such as conditions with the codes:

  • SNOMED 37796009 - Migraine
  • SNOMED 49605003 - Ophthalmoplegic migraine (disorder)
  • ICD-10 G43.4 - Hemiplegic migraine
  • ICD-10 G43.B0 - Ophthalmoplegic migraine, not intractable
  • etc.

The [type] modifier allows clients to restrict the resource type when following a resource reference. The modifier does not use the literal '[type]' in any way, but rather the name of a resource - e.g., Patient , Encounter , etc.. Note that servers can impose restrictions on the use of the modifier (e.g., only allowing on local references, only allowing if Reference.type is populated, etc.) and allow for extended behavior (e.g., allowing on canonical references, etc.). Note that since external references are always absolute references, there can be no ambiguity about the resource type when resolving.

When resolving references, it is possible that a resolved resource does not match the specified type. In this case, the reference is considered to not match the search parameter. If a reference resolves to a type different than indicated or expected, a server SHOULD consider if it is appropriate to include the issue via an OperationOutcome in the response. § 41

[type] is only allowed on reference type search parameters that target elements with a clear error message . the Reference FHIR type. When using the '[type]' modifier, all typically-valid search parameter reference inputs are allowed, but the value format is restricted to only [id] .

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?subject:Patient=23 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded subject:Patient=23 for observations where the subject is 'Patient 23' is functionally equivalent to: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?subject=Patient/23 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded subject=Patient/23 as well as: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?patient=23 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded patient=23 However, the modifier becomes more useful when used with Chaining and Reverse Chaining of search parameters.

For the ordered parameter types of number , date , and quantity , a prefix to the parameter value may be used to control the nature of the matching. To avoid URL escaping and visual confusion, the following prefixes described in the table below are used: used. Note that in the following table:

  • parameter value refers to the value provided to search against (e.g., the parameter value in the request)
  • resource value refers to the value being tested against in a resource (e.g., an element value in a data store)

Prefix Code Description Formal Definition
eq the value for the parameter in the The resource value is equal to or fully contained by the provided value parameter value. the The range of the search parameter value fully contains the range of the target resource value.
Boundary interpretation: The lower boundary of the resource value is greater than or equal to the lower boundary of the parameter value AND the upper boundary of the resource value is less than or equal to the upper boundary of the parameter value.
Resource interval tests:
  resource-lower: [parameter-lower, parameter-upper]
  resource-upper: [parameter-lower, parameter-upper]
ne the value for the parameter in the The resource value is not equal to the provided value parameter value. the The range of the search parameter value does not fully contain the range of the target resource value.
Boundary interpretation: The lower boundary of the resource value is greater than the upper boundary of the parameter value OR the upper boundary of the resource value is less than the lower boundary of the parameter value.
Resource interval tests:
  resource-lower: (parameter-upper, ∞)
  resource-upper: (-∞, parameter-lower)
gt the value for the parameter in the The resource value is greater than the provided value parameter value. the The range above the search parameter value intersects (i.e. (i.e., overlaps) with the range of the target resource value.
Boundary interpretation: The upper boundary of the resource value is greater than the upper boundary of the parameter value.
Resource interval tests:
  resource-upper: (parameter-upper, ∞)
lt ge the value for the parameter in the The resource value is less than greater or equal to the provided value parameter value. the The combined range below from the search parameter value (inclusive) to +infinite intersects (i.e. (i.e., overlaps) with the range of the target resource value.
Boundary interpretation: The lower OR upper boundaries of the resource value are greater than or equal to the upper boundary of the parameter value.
Resource interval tests:
  resource-lower: [parameter-lower, ∞)
  resource-upper: [parameter-lower, ∞)
ge lt the value for the parameter in the The resource value is greater or equal to less than the provided value parameter value. the The range above below the search parameter value intersects (i.e. (i.e., overlaps) with the range of the target value, or the range resource value.
Boundary interpretation: The lower boundary of the search resource value fully contains is less than the range lower boundary of the target value parameter value.
Resource interval tests:
  resource-lower: (-∞, parameter-lower)
le the value for the parameter in the The resource value is less or equal to the provided value parameter value. the The combined range below from -infinite to the search parameter value (inclusive) intersects (i.e. (i.e., overlaps) with the range of the target value or the range resource value.
Boundary interpretation: The upper OR lower boundaries of the search resource value fully contains are less than or equal to the range upper boundary of the target value parameter value.
Resource interval tests:
  resource-lower: (-∞, parameter-upper]
  resource-upper: (-∞, parameter-upper]
sa the value for the parameter in the The resource value starts after the provided value parameter value. the The range of the search parameter value does not overlap with the range of the target resource value, and the range above the search parameter value contains the range of the target resource value.
Boundary interpretation: The lower boundary of the resource value is greater than the upper boundary of the parameter value.
Resource interval tests:
  resource-lower: (parameter-upper, ∞)
eb the value for the parameter in the The resource value ends before the provided value parameter value. the The range of the search parameter value does overlap not overlap with the range of the target resource value, and the range below the search parameter value contains the range of the target resource value.
Boundary interpretation: The upper boundary of the resource value is less than the lower boundary of the parameter value.
Resource interval tests:
  resource-upper: (-∞, parameter-lower)
ap the value for the parameter in the The resource value is approximately the same to the provided parameter value.
Note that the recommended value for the approximation is 10% of the stated value (or for a date, 10% of the gap between now and the date), but systems may choose other values where appropriate appropriate.
the The range of the search parameter value overlaps with the range of the target resource value.
Boundary interpretation: The lower boundary of the resource value is less than or approximately the upper boundary of the parameter value AND the upper boundary of the resource value is greater than or approximately the lower boundary of the parameter value.
  resource-lower: [~parameter-lower, ~parameter-lower]
  resource-upper: [~parameter-upper, ~parameter-upper]

Following is a table showing some example ranges and how they interact with the prefixes, with [P] representing the parameter range and [R] representing the resource range, with each additional column showing whether the test result is a match or not. Empty columns indicate no match, while a match for a particular test will show the prefix code used for that test. Note that for 'approximately', the actuality of a match depends on both the actual spans of ranges and the server's definition of 'approximately'. Any test that could possibly match is indicated with ap .

Test eq ne gt ge lt le sa eb ap

             |--[P]--|
|--[R]--|
ne lt le eb

        |--[P]--|
|--[R]--|
ne lt le

    |--[P]--|
|--[R]--|
ne lt le

    |--[P]--|
|--[R]------|
ne lt le

  |--[P]--|
|----[R]----|
ne gt ge lt le ap

 |----[P]----|
[R]
eq ge le ap

|----[P]----|
|--[R]--|
eq ge le ap

|--[P]--|
|--[R]--|
eq ge le ap

|--[P]--|
|--[R]----|
ne gt ge ap

|----[P]----|
|--[R]--|
eq ge le ap

|---[P]---|
|--[R]--|
eq ge le ap

|--[P]--|
|--[R]--|
ne gt ge ap

|----[P]----|
[R]
eq ge le ap
|--[P]--|
|--[R]--|
ne gt ge le

|--[P]--|
|--[R]--|
ne gt ge sa

Note that prefixes always test against values present in elements. In all cases, a prefix-based test against an element that does not exist will fail the test. To search for elements missing values, the use of search modifiers is required - either missing or not .

Prefixes are allowed in searches that combine multiple terms. When using a prefix in "or" joined search parameter values, the prefix only applies to the value it precedes. For example, in value-quantity=lt60,gt100 , the lt prefix is applied to the value "60" and the gt prefix is applied to the value "100". Additional details can be found in the Searching Multiple Values section of the Search page.

If no prefix is present, the prefix eq is assumed. Note that the way search parameters operate is not the same as the way the operations on two numbers work in a mathematical sense. sa ( starts-after ) and eb ( ends-before ) are not used with integer values. values but are used for decimals.

For each prefix above, two interpretations are provided - the simple intent of the prefix and the interpretation of the parameter when applied to ranges. The range interpretation is provided for decimals and dates. Searches that support prefixes are always performed on values that are implicitly or explicitly a range. For instance, the number 2.0 has an implicit range of 1.95 to 2.05, and the date 2015-08-12 has an implicit range of all the time during that day. If the target resource value is a Range , a Period , or a Timing , then the target is explicitly a range. Three ranges are identified:

Decimal Values
range of the value The limits implied by the precision of the value The number 2.0 has a range of 1.95 to 2.05
The date 2015-08-12 range 1.5 -> 2.3 has a range from 00:00 1.50000000000000000000 to 00:00 exclusive 2.50000000000000000000 (range is explicit, boundaries are treated as precise)
range below the value Up to the specified value The range below 2.0 includes any value less or equal to <2.00000000000000000000
The range before 2015-08-12T05:23:45 below 1.5 -> 2.3 includes any time up value less or equal to 2015-08-12T05:23:45.000000000000000 <1.50000000000000000000
range above the value The specified value and up The range above 2.0 includes any value greater or equal to <2.00000000000000000000
The range above 1.5 -> 2.3 includes any value greater or equal to <2.30000000000000000000
Date / Time Values
range of the value The limits implied by the precision of the value The date 2015-08-12 has a range from 2015-08-12T00:00:00.0000 inclusive to 2015-08-13T00:00:00.0000 exclusive
The date 2015-08 has a range from 2015-08-12T00:00:00.0000 inclusive to 2015-09-01T00:00:00.0000 exclusive
range below the value Up to the specified value The range before 2015-08-12T05:23:45 includes any time up to 2015-08-12T05:23:45.000000000000000
The range before 2015-08 includes any time up to 2015-08-00T00:00:00.000000000000000
range above the value The specified value and up The range after 2015-08-12T05:23:45 includes any time from 2015-08-12T05:23:46.000000000000000 and later
The range after 2015-08-12T05:23:45.000000000000000 2015-08 includes any time from 2015-09-01T00:00:00.000000000000000 and later

The proper use of these Additional details about how ranges is discussed further below. are applied are specific to each data type and are documented in the relevant search data type.

Searching on In the rules described above, special rules are defined for the characters $ ,,, and | . As a simple numerical value consequence, if these characters appear in an actual parameter value, they must be differentiated from their use as separator characters. When any of these characters appear in an actual parameter value, they must be prepended by the character \ , which also must be used to prepend itself. Therefore, param=xxx$xxx indicates that it is a resource. Examples: composite parameter, while [parameter]=100 param=xx\$xx indicates that the parameter has the literal value xx$xx . The parameter value xx\xx is illegal, and the parameter value param=xx\\xx indicates a literal value of xx\xx . This means that: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?code=a,b POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code=a,b is a request for any Observation that has a code of either a or b , whereas: Show as unencoded: HTTP GET | HTTP POST Values GET [base]/Observation?code=a\,b POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code=a\,b is a request for any Observation that equal 100, has a code of a,b .

This escaping is at a different level to 3 significant figures precision, so range [99.5 ... 100.5) the percent encoding that applies to all URL parameters (as defined in RFC 3986 icon ). Standard percent escaping still applies, such that these URL strings have the same meaning:

  • http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124,ValueSet/125
  • [parameter]=100.00 http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124\,ValueSet/125
  • Values that equal 100, to 5 significant figures precision, so range [99.995 ... 100.005). Whole numbers also equal 100.00, but not 100.01 http%3A%2F%2Facme.org%2Ffhir%2FValueSet%2F123%2Chttp%3A%2F%2Facme.org%2Ffhir%2FValueSet%2F124%2CValueSet%2F125

Note that all of the above representations would be transmitted via an HTTP request in the same form as: Show as unencoded: HTTP GET | HTTP POST GET [base]/ValueSet?url=http%3A%2F%2Facme.org%2Ffhir%2FValueSet%2F123%2Chttp%3A%2F%2Facme.org%2Ffhir%2FValueSet%2F124%2CValueSet%2F125 POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url=http%3A%2F%2Facme.org%2Ffhir%2FValueSet%2F123%2Chttp%3A%2F%2Facme.org%2Ffhir%2FValueSet%2F124%2CValueSet%2F125

Note that an escaped delimiter (e.g., an escaped comma) can appear within a multi-value delimited request, for example: Show as unencoded: HTTP GET | HTTP POST GET [base]/ValueSet?url=http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124\,ValueSet/125 POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url=http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124\,ValueSet/125 is a request for ValueSets with a url literal of [parameter]=lt100 http://acme.org/fhir/ValueSet/123 or http://acme.org/fhir/ValueSet/124,ValueSet/125 .

This specification defines this additional form of escape because the escape syntax using backslash-escaping ( \ ) applies to all parameter values after they have been 'unescaped' on the server while being read from the HTTP headers.

The following table shows the mapping between search types and FHIR types that they can be tested against.

Note that in addition to elements of the specified type, any search type is allowed to be tested against elements that contain other elements, such as Backbone Elements and complex datatypes , that contain at least one element of a valid FHIR type.

Generally, search testing against complex elements are performed by "or-joining" each valid sub-element of an appropriate FHIR type (see Combining for details). However, some types may include additional guidance or specific behavior - for example, when performing string searches against HumanName and Address elements (see string ). For clarity, the table below generally excludes FHIR types that are less than 100 just containers for other elements.

Note: Uncertainty does not factor in evaluations. The precision of the numbers is considered arbitrarily high. (The way search parameters operate in resources is not the same as whether two numbers are equal to each other in a mathematical sense). Here are some example searches:
Search Type Short FHIR Types
[parameter]=le100 date Values that are less Partial or equal to 100 complete date or time values date , dateTime , instant , Period , Timing
[parameter]=gt100 number Values that are greater than 100 Numbers of various types decimal , integer , integer64 , unsignedInt , positiveInt
[parameter]=ge100 quantity Values that are greater or equal to 100 Quantity values (including currencies) Age , Count , Distance , Duration , MoneyQuantity , Quantity , SimpleQuantity ,
[parameter]=ne100 reference Values that are not equal References to 100 other resources canonical , OID , URI , URL , UUID , Reference
Search string Description String values id , markdown , string , xHTML
GET [base]/Encounter?length=gt20 token Search for all the encounters longer than 20 days Token values boolean , canonical , code , CodeableConcept , Coding , ContactPoint , id , Identifier , OID , string , URI , URL , UUID
GET [base]/ImmunizationRecommendation?deo-number=2 uri Search for any immunization recommendation recommending a second dose URI values canonical , OID , URI , URL , UUID

A date parameter searches on a date/time or period. As is usual for date/time related functionality, while the concepts are relatively straight-forward, there are a number of subtleties involved in ensuring consistent behavior.

The date parameter format is yyyy-mm-ddThh:mm:ss[Z|(+|-)hh:mm] yyyy-mm-ddThh:mm:ss.ssss[Z|(+|-)hh:mm] (the standard XML format). Note that fractional seconds MAY be ignored by servers. § 42

Technically, this is The date search type can be used to represent data from any of the date , dateTime , and instant data types; e.g. datatypes. Any degree of precision can be provided, but it SHALL be populated from the left (e.g. (e.g., can't specify a month without a year), except that the minutes SHALL be present if an hour is present, and you SHOULD provide a time zone timezone if the time part is present. § 43 Note: Time can consist of hours and minutes with no seconds, unlike the XML Schema dateTime type. Some user agents may escape the : characters in the URL, and servers SHALL handle this correctly. § 44

Date searches are intrinsically matches against 'periods', regardless of the underlying element type. Date parameters may can be used with the following data types:

date The range of the value is period start and end are both set to the day, month, or year as specified date value.
dateTime The range of period start and end are both set to the value as defined above; e.g. For example, dateTime value; e.g., the date 2013-01-10 specifies all the time from 00:00 on 10-Jan 2013 to immediately before 00:00 on 11-Jan 2013 2013.
instant An instant is considered a fixed point in time with an interval smaller than the precision of The period start and end are both set to the system, i.e. an interval with an effective width of 0 instant value.
Period Explicit, No conversion necessary; the period is explicit, though note that the upper or lower bound might not actually be specified in resources.
Timing The period has a start of the lowest dateTime within the timing and an end of the highest dateTime within the timing. The specified scheduling details are ignored and only the outer limits matter. For instance, a schedule that specifies a certain time on every second day between 31-Jan 2013 and 24-Mar 2013 includes 1-Feb 2013, even though that is on an odd day that is not specified by the period. Similarly, the period would include the start of 31-Jan 2023 through the end of 24-Mar 2023, ignoring the scheduled time (unless the outer limits were accurate to that time). This is to keep the server load processing queries reasonable. Note that servers are allowed to process internal intervals, if it is desired and relevant.

Implicitly, The 'period' of a date search is from the earliest instant of the value through to the latest instant of the value. When comparing, the period start is adjusted to have maximum precision with the lowest possible value of all non-specified levels. For example, first month of the year, first day of the month, 0-filled time. The period end is adjusted to have maximum precision with the highest possible value of all non-specified levels - last month of the year, last day of the month (allowing for leap years), last time of the day (i.e. 23:59:59.99999).

For more information about how the different search prefixes work when comparing periods/ranges, refer to the Prefixes section.

A missing lower boundary is "less than" any actual date. A missing upper boundary is "greater than" any actual date. The Date searches can be controlled through the use of prefixes as described in the prefixes: following table:

[parameter]=eq2013-01-14
  • 2013-01-14T00:00 matches (obviously)
  • 2013-01-14T10:00 matches
  • 2013-01-15T00:00 does not match - it's not in the range
[parameter]=ne2013-01-14
  • 2013-01-15T00:00 matches - it's not in the range
  • 2013-01-14T00:00 does not match - it's in the range
  • 2013-01-14T10:00 does not match - it's in the range
[parameter]=lt2013-01-14T10:00
  • 2013-01-14 matches, because it includes the part of 14-Jan 2013 before 10am
  • "2013-01-13T12:00 to 2013-01-14T12:00" matches, because it includes the part of 14-Jan 2013 until noon
  • "2013-01-14T08:00 to 2013-01-15T08:00" matches, because it includes the part of 14-Jan 2013 before 10:00
[parameter]=gt2013-01-14T10:00
  • 2013-01-14 matches, because it includes the part of 14-Jan 2013 after 10am
  • "2013-01-13T12:00 to 2013-01-14T12:00" matches, because it includes the part of 14-Jan 2013 until noon
  • "2013-01-14T12:00 to 2013-01-15T12:00" matches, because it includes the part of 14-Jan 2013 after noon
[parameter]=ge2013-03-14
  • "from 21-Jan 2013 onwards" is included because that period may include times after 14-Mar 2013
[parameter]=ge2015-04-13T20:27:01-04:00
  • matches a Period [2015-04-13T20:27:01-04:00, 2015-04-13T20:42:01-04:00) because the combined search range overlaps starting at the boundary instant.
  • does NOT match a Period [2015-04-13T20:26:01-04:00, 2015-04-13T20:27:01-04:00) because the resource ends exactly at the parameter instant and the end is exclusive, so there is no overlap.
[parameter]=le2013-03-14
  • "from 21-Jan 2013 onwards" is included because that period may include times before 14-Mar 2013
[parameter]=le2015-04-13T20:27:01-04:00
  • matches a Period with range [2015-04-13T20:27:01-04:00, 2015-04-13T20:42:01-04:00) because the combined search range overlaps the resource at the inclusive boundary instant.
  • does NOT match a Period [2015-04-13T20:27:02-04:00, 2015-04-13T20:42:01-04:00) because there is no overlap with (-∞, 2015-04-13T20:27:01-04:00] .
[parameter]=sa2013-03-14
  • "from 15-Mar 2013 onwards" is included because that period starts after 14-Mar 2013
  • "from 21-Jan 2013 onwards" is not included because that period starts before 14-Mar 2013
  • "before and including 21-Jan 2013" is not included because that period starts (and ends) before 14-Mar 2013
  • "2013-01-13T12:00 to 2013-01-14T12:00" does not match, because it starts before 14-Jan 2013 begins
  • "2013-01-14T12:00 to 2013-01-15T12:00" does not match, because it starts before 14-Jan 2013 ends
[parameter]=eb2013-03-14
  • "from 15-Mar 2013 onwards" is not included because that period starts after 14-Mar 2013
  • "from 21-Jan 2013 onwards" is not included because that period starts before 14-Mar 2013, but does not end before it
  • "before and including 21-Jan 2013" is not included because that period ends before 14-Mar 2013
  • "2013-01-13T12:00 to 2013-01-14T12:00" does not match, because it ends after 14-Jan 2013 begins
  • "2013-01-14T12:00 to 2013-01-15T12:00" does not match, because it starts before 14-Jan 2013 ends
[parameter]=ap2013-03-14
  • Note that actual comparison used for the ap prefix for date search types is an implementation detail. For these examples, the system will be based on a 10% difference between target and execution date, and execution on 01-Jan 2023.
  • 14-Mar 2013 is included - as included, because it exactly matches
  • 21-Jan 2013 is not included included, because that it is near 14-Mar 2013 (less than 10% difference between search date and current date)
  • 15-Jun 2015 is not included - as included, because it is not near 14-Mar 2013. Note that 2013 (more than 10% difference between search date and current date)

Please note in particular the differences between range comparison and boundary comparison prefixes when comparing ranges on both sides. Tests such as 'greater than' are evaluated true if any part of the exact value here range is at higher than the discretion test range. Similarly, a test such as 'starts after' is non-inclusive of the system range of the test value, so a request such as sa2013-01-14 is requesting values that start after January 14th has passed, not after January 14th started. In order to avoid unintentional overlapping of ranges, requests can increase the specificity of their request. For example, the test for sa2013-01-14T00:00:00 is a much clearer test.

Other notes:

  • When the date parameter is not fully specified, matches Matches against it dates are based on the behavior of intervals, where:
    • Dates with only the year specified are equivalent to an interval that starts at the first instant of January 1st to the last instant of December 31st, e.g. e.g., 2000 is equivalent to an interval of [2000-01-01T00:00, 2000-12-31T23:59].
    • Dates with the year and month are equivalent to an interval that starts at the first instant of the first day of the month and ends on the last instant of the last day of the month, e.g. e.g., 2000-04 is equivalent to an interval of [2000-04-01T00:00, 2000-04-30T23:59].
    • Dates with the year, month, and day are equivalent to an interval that starts at the first instant of day and ends on the last instant of the day, e.g. 2000-04-04 is equivalent to an interval of [2000-04-04T00:00, 2000-04-04T23:59.9999].
  • Where possible, the system should SHOULD correct for timezones when performing queries. § 45 Dates do not have time zones, timezones, and time zones should not timezones SHOULD NOT be considered. § 46 Where both search parameters and resource element date times date-times do not have time zones, timezones, the servers local time zone should timezone SHOULD be assumed. § 47

To search for all the procedures in a patient compartment that occurred over a 2 year 2-year period: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient/23/Procedure?date=ge2010-01-01&date=le2011-12-31 POST [base]/Patient/23/_search Content-Type: application/x-www-form-urlencoded Patient/23/Procedure?date=ge2010-01-01&date=le2011-12-31

Managing timezones and offsets and their impact on search is a very difficult area. The FHIR implementation community is still investigating and debating the best way to handle timezones. Implementation guides may make additional rules in this regard.

Future versions of this specification may impose rules around the use of timezones with dates. Implementers and authors of implementation guides should be aware of ongoing work in this area.

Implementer feedback is welcome on the issue tracker icon or chat.fhir.org icon.

 

Searching on a simple numerical value in a resource. Examples:

[parameter]=100 Values that equal 100, to 3 significant figures precision, so this is actually searching for values in the range [99.5 ... 100.5)
[parameter]=100.00 Values that equal 100, to 5 significant figures precision, so this is actually searching for values in the range [99.995 ... 100.005)
[parameter]=1e2 Values that equal 100, to 1 significant figure precision, so this is actually searching for values in the range [50 ... 150)
[parameter]=lt100 Values that are less than exactly 100
[parameter]=le100 Values that are less or equal to exactly 100
[parameter]=gt100 Values that are greater than exactly 100
[parameter]=ge100 Values that are greater or equal to exactly 100
[parameter]=ne100 Values that are not equal to 100 (actually, in the range 99.5 to 100.5)

Notes about searching on Numbers:

  • When a number search is used against a resource element that stores a simple integer (e.g. ImmunizationRecommendation.recommendation.doseNumber icon ), and the search parameter is not expressed using the exponential forms, and does not include any non-zero digits after a decimal point, the significance issues cancel out and searching is based on exact matches. Note that if there are non-zero digits after a decimal point, there cannot be any matches
  • When a comparison prefix in the set gt, lt, ge, le, sa & eb is provided, the implicit precision of the number is ignored, and they are treated as if they have arbitrarily high precision
  • The way search parameters operate in resources is not the same as whether two numbers are equal to each other in a mathematical sense
  • Searching on decimals without using one of the comparisons listed in the earlier bullet involves an implicit range. The number of significant digits of the implicit range is the number of digits specified in the search parameter value, excluding leading zeros. So 100 and 1.00e2 both have the same number of significant digits - three

Here are some example searches:

Show as unencoded: HTTP GET | HTTP POST
Search Description
GET [base]/RiskAssessment?probability=gt0.8 POST [base]/RiskAssessment/_search Content-Type: application/x-www-form-urlencoded probability=gt0.8 Search for all the Risk Assessments with probability great than 0.8 (could also be probability=gt8e-1 using exponential form)
GET [base]/ImmunizationRecommendation?dose-number=2 POST [base]/ImmunizationRecommendation/_search Content-Type: application/x-www-form-urlencoded dose-number=2 Search for any immunization recommendation recommending a second dose

A quantity parameter searches on the Quantity datatype. The syntax for the value follows the form (see Encoding Note ):

  • [parameter]={[prefix]}[number] matches a quantity by value , with an optional prefix
  • [parameter]={[prefix]}[number]|[system]|[code] matches a quantity by value , system and code , with an optional prefix
  • [parameter]={[prefix]}[number]||[code] matches a quantity by value and code or unit , with an optional prefix

The prefix is optional, and is as described in the section on Prefixes , both regarding how precision and comparator/range operators are interpreted. Like a number parameter, the number part of the search value can be a decimal in exponential format. The system and code follow the same pattern as token parameters are also optional. Note that when the [system] component has a value, it is implied that a precise (and potentially canonical) match is desired. In this case, it is inappropriate to search on the human display for the unit, which can be is uncontrolled and may unpredictable. Example searches:

Show as unencoded: HTTP GET | HTTP POST
Search Description
GET [base]/Observation?value-quantity=5.4|http://unitsofmeasure.org|mg POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded value-quantity=5.4|http://unitsofmeasure.org|mg Search for all the observations with a value of 5.4(+/-0.05) mg where mg is understood as a UCUM unit ( system / code )
GET [base]/Observation?value-quantity=5.40e-3|http://unitsofmeasure.org|g POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded value-quantity=5.40e-3|http://unitsofmeasure.org|g Search for all the observations with a value of 0.0054(+/-0.00005) g where g is understood as a UCUM unit ( system / code )
GET [base]/Observation?value-quantity=5.4||mg POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded value-quantity=5.4||mg Search for all the observations with a value of 5.4(+/-0.05) mg where the unit - either the code ( code ) or the stated human unit ( unit ) are "mg"
GET [base]/Observation?value-quantity=5.4 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded value-quantity=5.4 Search for all the observations with a value of 5.4(+/-0.05) irrespective of the unit
GET [base]/Observation?value-quantity=le5.4|http://unitsofmeasure.org|mg POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded value-quantity=le5.4|http://unitsofmeasure.org|mg Search for all the observations where the value of is less than 5.4 mg exactly where mg is understood as a UCUM unit
GET [base]/Observation?value-quantity=ap5.4|http://unitsofmeasure.org|mg POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded value-quantity=ap5.4|http://unitsofmeasure.org|mg Search for all the observations where the value of is about 5.4 mg where mg is understood as a UCUM unit (typically, within 10% of the value - see above)

Specifying a system and a code for the search implies that the search is based on a particular code system - usually UCUM icon, and that a precise (and potentially canonical) match is desired. In this case, it is inappropriate to search on the human display for the unit, which can be is uncontrolled and may be unpredictable.

The search processor may choose to perform a search based on canonical units (e.g., any value where the units can be converted to a value in mg in the case above). For example, an observation may have a value of 23 mm/hr . This is equal to 0.023 m/hr . The search processor can choose to normalize all the values to a canonical unit such as 6.4e-6 m/sec , and convert search terms to the same units (m/sec). Such conversions can be performed based on the semantics defined in UCUM icon. Servers that do not search based on canonical units will not be able to search against ranges whose low and high quantities use different units or where the search expression uses different units than are found in low and high.

The reference search parameter type is used to search references between resources . For example, find all Conditions where the subject is a particular patient, where the patient is selected by name or identifier. The interpretation of a reference parameter is either (see Encoding Note ):

  • [parameter]=[id] the logical [id] of a resource using a local reference (i.e., a relative reference).
  • [parameter]=[type]/[id] the logical [id] of a resource of a specified type using a local reference (i.e., a relative reference), for when the reference can point to different types of resources (e.g., Observation.subject ).
  • [parameter]=[type]/[id]/_history/[version] the logical [id] of a resource of a specified type using a local reference (i.e., a relative reference), for when the reference can point to different types of resources and a specific version is requested. Note that server implementations may return an error when using this syntax if resource versions are not supported. For more information, see References and Versions .
  • [parameter]=[url] where the [url] is an absolute URL - a reference to a resource by its absolute location, or by its canonical URL
  • [parameter]=[url]|[version] where the search element is a canonical reference, the [url] is an absolute URL, and a specific version or partial version is desired. For more information, see References and Versions .

Notes:

  • A relative reference resolving to the same value as a specified absolute URL, or vice versa, qualifies as a match.
  • If a reference value is a non-versioned relative reference (e.g., does not contain [url] or _history/[version] parts), the search SHOULD match instances that match the reference in it contains a versioned reference. § 48

For example, if the base URL of a server is http://example.org/fhir, the search: Show as unencoded: HTTP GET | HTTP POST GET http://example.org/fhir/Observation?subject=Patient/123 POST http://example.org/fhir/Observation/_search Content-Type: application/x-www-form-urlencoded subject=Patient/123 will match Observations with subject.reference values:

  • Patient/123 - exact match of search input
  • http://example.org/fhir/Patient/123 - search input with implicit resolution to the local server
  • Patient/123/_history/1 - reference to a specific version of the search input

Similarly, the search: Show as unencoded: HTTP GET | HTTP POST GET http://example.org/fhir/Observation?subject=http://example.org/fhir/Patient/123 POST http://example.org/fhir/Observation/_search Content-Type: application/x-www-form-urlencoded subject=http://example.org/fhir/Patient/123 will match Observations with subject.reference values:

  • http://example.org/fhir/Patient/123 - exact match of search input
  • Patient/123 - search input with implicit reference to the local server
Note that it will not match an Observation with Patient/123/_history/1 , since the original reference was not a relative reference.

Also, the search: Show as unencoded: HTTP GET | HTTP POST GET http://example.org/fhir/Observation?subject=123 POST http://example.org/fhir/Observation/_search Content-Type: application/x-www-form-urlencoded subject=123 will match Observations with subject.reference values:

  • Patient/123 - search input of type Patient
  • http://example.org/fhir/Patient/123 - search input with implicit resolution to the local server, of type Patient
  • Practitioner/123 - search input of type Practitioner
  • http://example.org/fhir/Practitioner/123 - search input with implicit resolution to the local server, of type Practitioner
  • etc.

Some resource references may point to more than one type of resource; e.g., subject: Reference(Patient|Group|Device|..) . In these cases, multiple resources may have the same logical identifier. Servers SHOULD fail a search where the logical id in a reference refers to more than one matching resource across different types. § 49 In order to allow the client to perform a search in these situations the type is specified explicitly: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?subject=Patient/23 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded subject=Patient/23

This searches for any observations where the subject refers to the patient resource with the logical identifier "23". A modifier is also defined to allow the client to be explicit about the intended type: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?subject:Patient=23 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded subject:Patient=23

This has the same effect as the previous search. The modifier becomes useful when used with chaining as explained in the next section. Note: The [type] modifier can't be used with a reference to a resource found on another server, since the server would not usually know what type that resource has. However, since external references are always absolute references, there can be no ambiguity about the type.

In some cases, search parameters are defined with an implicitly limited scope. For example, Observation has an element subject , which is a reference to one of a number of types. This has a matching search parameter subject , which refers to any of the possible types. In addition to this, there is another search parameter patient , which also refers to Observation.subject , but is limited to only include references of type Patient . When using the patient search parameter, there is no need to specify ":Patient" as a modifier, or "Patient/" in the search value, as this must always be true.

FHIR References are also allowed to have an identifier . The modifier :identifier allows for searching by the identifier rather than the literal reference: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?subject:identifier=http://acme.org/fhir/identifier/mrn|123456 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded subject:identifier=http://acme.org/fhir/identifier/mrn|123456

This is a search for all observations that reference a patient by a particular patient MRN. When the :identifier modifier is used, the search value works as a token search . The :identifier modifier is not supported on canonical elements since they do not have an identifier separate from the reference itself.

Chaining is not supported when using the :identifier modifier, nor are chaining, includes or reverse includes supported for reference search parameters that target elements without a reference element. For example, a search parameter that targets an element with the Reference FHIR type can be chained through, but a search parameter that targets a canonical element cannot.

The reference search parameter type is mostly used for resource elements of type Reference or canonical . However, it is also be used to search resource elements of type Resource - i.e., where one resource is directly nested within another - see the Bundle search parameters 'message' and 'composition' as an example of this.

GET [base]/Patient/23/Procedure?date=ge2010-01-01&date=le2011-12-31

For a simple string search, a string parameter serves as the input for a case- and accent-insensitive search against sequences of characters. This search is insensitive to casing and included combining characters, like accents or other diacritical marks. Punctuation and non-significant whitespace (e.g., repeated space characters, tab vs space) SHOULD also be ignored. § 50 Note that case-insensitive comparisons do not take locale into account, and will result in unsatisfactory results for certain locales. Character case definitions and conversions are out of scope for the FHIR standard, and the results of such operations are implementation dependent. By default, a field matches a string query if the value of the field equals or starts with the supplied parameter value, after both have been normalized by case and accent. combining characters. Therefore, the default string search only operates on the base characters of the string parameter. The :contains modifier returns results that include the supplied parameter value anywhere within the field being searched. The :exact modifier returns results that match the entire supplied parameter, including casing and accents.

When a string type search parameter points to a complex or backbone element (an element that contains sub-elements), by default the search SHOULD be considered as a search against one or more string values in sub-elements, as selected by the implementation. § 51 A search parameter MAY explicitly choose elements by using an expression that instead points directly to the sub-elements. § 52

For example, if a search parameter is of type string and the expression points to Patient.name , the implementation can test against any one or more elements of the HumanName datatype (e.g., given , family , prefix , suffix , etc.). However, if the search parameter intends to explicitly match against given and family only, the search parameter should use an expression of Patient.name.given | Patient.name.family .

If the SearchParameter's narrative description includes additional considerations about what fields are indexed, SearchParameter.processingMode should have the value other .

Examples:

Show as unencoded: HTTP GET | HTTP POST
GET [base]/Patient?given=eve POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given=eve Any patients with a name containing a given part with "eve" at the start of the name. This would include patients with the given name "Eve", "Evelyn".
GET [base]/Patient?given:contains=eve POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given:contains=eve Any patients with a name with a given part containing "eve" at any position. This would include patients with the given name "Eve", "Evelyn", and also "Severine".
GET [base]/Patient?given:exact=Eve POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded given:exact=Eve Any patients with a name with a given part that is exactly "Eve". Note: This would not include patients with the given name "eve" or "EVE".

An additional modifier :text can be used to specify a search with advanced text handling (see below ) though only a few servers are expected to offer this facility.

When a string search parameter refers to the types HumanName and Address , the search covers the elements of type string, and does not cover elements such as use and period . For robust search, servers should SHOULD search the parts of a family name independently. E.g. Searching § 53 e.g., searching either Carreno "Carreno" or Quinones "Quinones" should match a family name of "Carreno Quinones". HL7 affiliates may MAY make more specific recommendations about how search should work expectations regarding names in their specific culture. § 54

It is at the discretion of the server whether to pre-process names, addresses, and contact details to remove separator characters prior to matching in order to ensure more consistent behavior. For example, a server might remove all spaces and - characters from phone numbers. What is most appropriate varies depending on culture and context. A server may also use a free-text style searches on this property to achieve the best results results.
When searching whole names and addresses (not parts), servers may also use flexible match or a free-text style searches on names to achieve the best results.

3.1.1.4.9 uri The uri parameter refers to a URI ( RFC 3986 ) element. Matches are precise (e.g. case, accent, and escape) sensitive, and the entire URI must match. The modifier :above or :below can be used to indicate that partial matching is used. For example: GET [base]/ValueSet?url=http://acme.org/fhir/ValueSet/123 GET [base]/ValueSet?url:below=http://acme.org/fhir/ GET [base]/ValueSet?url:above=http://acme.org/fhir/ValueSet/123/_history/5 GET [base]/ValueSet?url=urn:oid:1.2.3.4.5 The first line is a request to find any value set with the exact url "http://acme.org/fhir/ValueSet/123" The second line performs a search that will return any value sets that have a URL that starts with "http://acme.org/fhir/" The third line shows the converse - search for any value set above a given specific URL. This will match on any value set with the specified URL, but also on http://acme.org/ValueSet/123. Note that there are not many use cases where :above is useful as compared to the :below search The fourth line shows an example of searching by an OID. Note that the :above and :below modifiers only apply to URLs, and not URNS such as OIDs Note that for uri parameters that refer to Canonical URLs , servers SHOULD support searching by Canonical URL, and SHOULD support automatically detecting a |[version] portion as part of the Canonical URL, and interpreting that portion as a search on the version.

A token type is a parameter that provides an a close to exact match search on a string of characters, potentially scoped by a URI. It is mostly used against a code or identifier data type datatype where the value may have a URI that scopes its meaning, where the search is performed against the pair from a Coding or an Identifier. Tokens are also used against other fields where exact matches are required - uris, booleans, and ContactPoints , and ids . In these cases, cases the URI portion ( [system]| ) is not used. used (only the [code] portion).

For tokens, matches are literal (e.g. (e.g., not based on subsumption or other code system features). Match is case sensitive unless the underlying semantics for the context indicate that the token should tokens are to be interpreted case-insensitively (see, e.g. e.g., CodeSystem.caseSensitive ). Note that matches on _id are always case sensitive. If the underlying data type datatype is string then the search is not case sensitive.

Note : There are many challenging issues around case senstivity sensitivity and token searches. Some code systems are case sensitive (e.g. (e.g., UCUM) while others are known not to be. For many code systems, it's ambiguous. Other kinds of values are also ambiguous. When in doubt, servers SHOULD treat tokens in a case-insensitive manner, on the grounds that including undesired data has less safety implications than excluding desired behavior. § 55 Clients SHOULD always use the correct case when possible, and allow for the server to perform case-insensitive matching. § 56

To use subsumption based subsumption-based logic, use the modifiers below, or list all the codes in the hierarchy. The syntax for the value is one of the following: following (see Encoding Note ):

  • [parameter]=[code] : the value of [code] matches a Coding.code or Identifier.value irrespective of the value of the system property
  • [parameter]=[system]|[code] : the value of [code] matches a Coding.code or Identifier.value, and the value of [system] matches the system property of the Identifier or Coding
  • [parameter]=|[code] : the value of [code] matches a Coding.code or Identifier.value, and the Coding/Identifier has no system property
  • [parameter]=[system]| : any element where the value of [system] matches the system property of the Identifier or Coding

Notes:

  • The namespace URI and code both must be escaped correctly. If a system is not applicable (e.g. (e.g., an element of type uri , ), then just the form [parameter]=[code] is used.
  • For token parameters on elements of type id , ContactPoint , uri , or boolean , the presence of the pipe symbol SHALL not NOT be used - only the [parameter]=[code] form is allowed § 57

Token search parameters are used for the following data types: datatypes:

Data Type Datatype URI Code Comments
Coding Coding.system Coding.code
CodeableConcept CodeableConcept.coding.system CodeableConcept.coding.code Matches against any coding in the CodeableConcept
Identifier Identifier.system Identifier.value Clients can search by type not system using the :of-type modifier, see below below. To search on a CDA II.root - which may appear in either Identifier.system or Identifier.value , use the syntax identifier=|[root],[root]
ContactPoint ContactPoint.value At the discretion of the server, token searches on ContactPoint may use special handling, such as ignoring punctuation, performing partial searches etc.
code (implicit) code the system is defined in the value set (though it's not usually needed)
boolean boolean The implicit system for boolean values is http://hl7.org/fhir/special-values http://terminology.hl7.org/CodeSystem/special-values icon but this is never actually used
id id
uri uri
string n/a string Token is sometimes used for string to indicate that exact case-insensitive full-string matching is the correct default search stategy strategy

Note: The use of token search parameters for boolean fields: the boolean values "true" and "false" are also represented as formal codes in the Special Values icon code system, which is useful when boolean values need to be represented in a Coding data type. datatype. The namespace for these codes is http://hl7.org/fhir/special-values, http://terminology.hl7.org/CodeSystem/special-values, though there is usually no reason to use this, as a simple true or false is sufficient.

Modifiers: Modifier Use :text The search parameter is processed as a string that searches text associated with the code/value - either CodeableConcept.text , Coding.display , or Identifier.type.text . :not Reverse the code matching described in the paragraph above: return all resources that do not have a matching item. Note that this includes resources that have no value for the parameter - e.g. ?gender:not=male includes all patients that do not have gender = male, including patients that do not have a gender at all :above The search parameter is a concept with the form [system]|[code] , and the search parameter tests whether the coding in a resource subsumes the specified search code. For example, the search concept has an is-a relationship with the coding in the resource, and this includes the coding itself. :below the search parameter is a concept with the form [system]|[code] , and the search parameter tests whether the coding in a resource is subsumed by the specified search code. For example, the coding in the resource has an is-a relationship with the search concept, and this includes the coding itself. :in The search parameter is a URI (relative or absolute) that identifies a value set, and the search parameter tests whether the coding is in the specified value set . The reference may be literal (to an address where the value set can be found) or logical (a reference to ValueSet.url). If the server can treat the reference as a literal URL, it does, else it tries to match known logical ValueSet.url values. :not-in The search parameter is a URI (relative or absolute) that identifies a value set, and the search parameter tests whether the coding is not in the specified value set. :of-type The search parameter has the format system|code|value, where the system and code refer to a Identifier.type.coding.system and .code , and match if any of the type codes match. All 3 parts must be present Most servers will only process value sets that are already known/registered/supported internally. However, servers can elect to accept any valid reference to a value set. Servers may elect to consider concept mappings when testing for subsumption relationships.

Example searches:

Show as unencoded: HTTP GET | HTTP POST
Search Description
GET [base]/Patient?identifier=http://acme.org/patient|2345 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded identifier=http://acme.org/patient|2345 Search for all the patients with an identifier with key = "2345" in the system "http://acme.org/patient"
GET [base]/Patient?gender=male POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded gender=male Search for any patient with a gender that has the code "male"
GET [base]/Patient?gender:not=male POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded gender:not=male Search for any patient with a gender that does not have the code "male". Note "male", including those that for :not , the search does do not return any resources that have a gen code for gender at all.
GET [base]/Composition?section=48765-2 POST [base]/Composition/_search Content-Type: application/x-www-form-urlencoded section=48765-2 Search for any Composition that contains an Allergies and adverse reaction section
GET [base]/Composition?section:not=48765-2 POST [base]/Composition/_search Content-Type: application/x-www-form-urlencoded section:not=48765-2 Search for any Composition that does not contain an Allergies and adverse reaction section. Note that this search does not return "any document that has a section that is not an Allergies and adverse reaction section" (e.g. (e.g., in the presence of multiple possible matches, the negation applies to the set, not each individual entry)
GET [base]/Patient?active=true POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded active=true Search for any patients that are active
GET [base]/Condition?code=http://acme.org/conditions/codes|ha125 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code=http://acme.org/conditions/codes|ha125 Search for any condition with a code "ha125" in the code system "http://acme.org/conditions/codes"
GET [base]/Condition?code=ha125 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code=ha125 Search for any condition with a code "ha125". Note that there is not often any useful overlap in literal symbols between code systems, so the previous example is generally preferred
GET [base]/Condition?code:text=headache POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:text=headache Search for any Condition with a code that has a text "headache" associated with it (either in the text, or a display)
GET [base]/Condition?code:in=http%3A%2F%2Fsnomed.info%2Fsct%3Ffhir_vs%3Disa%2F126851005 [base]/Condition?code:in=http://snomed.info/sct?fhir_vs=isa/126851005 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:in=http://snomed.info/sct?fhir_vs=isa/126851005 Search for any condition in the SNOMED CT value set "http://snomed.info/sct?fhir_vs=isa/126851005" that includes all descendants of "Neoplasm of liver"
GET [base]/Condition?code:below=126851005 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:below=126851005 Search for any condition that is subsumed by the SNOMED CT Code "Neoplasm of liver". Note: This is the same outcome as the previous search
GET [base]/Condition?code:in=http://acme.org/fhir/ValueSet/cardiac-conditions POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded code:in=http://acme.org/fhir/ValueSet/cardiac-conditions Search for any condition that is in the institutions list of cardiac conditions
GET [base]/Patient?identifier:otype=http://hl7.org/fhir/v2/0203|MR|446053 [base]/Patient?identifier:of-type=http://terminology.hl7.org/CodeSystem/v2-0203|MR|446053 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded identifier:of-type=http://terminology.hl7.org/CodeSystem/v2-0203|MR|446053 Search for the Medical Record Number 446053 - this is useful where the system id for the MRN is not known

A quantity The uri search parameter searches on the Quantity type is used to search elements that contain a URI ( RFC 3986 icon data type. The syntax for ). By default, matches are precise, case and accent sensitive, and the value follows entire URI must match. The modifier :above or :below can be used to indicate that partial matching is used. For example (note that the form: search parameter ValueSet.url is of type uri ): Show as unencoded: HTTP GET | HTTP POST GET [base]/ValueSet?url=http://acme.org/fhir/ValueSet/123 POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url=http://acme.org/fhir/ValueSet/123 GET [base]/ValueSet?url:below=http://acme.org/fhir/ POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url:below=http://acme.org/fhir/ GET [base]/ValueSet?url:above=http://acme.org/fhir/ValueSet/123/_history/5 POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url:above=http://acme.org/fhir/ValueSet/123/_history/5 GET [base]/ValueSet?url=urn:oid:1.2.3.4.5 POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded url=urn:oid:1.2.3.4.5

  • [parameter]=[prefix][number]|[system]|[code] matches The first line is a quantity request to find any value set with the exact url "http://acme.org/fhir/ValueSet/123"
  • The second line performs a search that will return any value sets that have a URL that starts with "http://acme.org/fhir/"
  • The third line shows the converse - search for any value set above a given unit specific URL. This will match on any value set with the specified URL, but also on http://acme.org/ValueSet/123. Note that there are not many use cases where :above is useful as compared to the :below search
  • The fourth line shows an example of searching by an OID. Note that the :above and :below modifiers only apply to URLs, and not URNS such as OIDs

The prefix search type uri can be used with elements of type canonical , uri , and url . The search type reference can also be used for those same types and is optional, always used for the type Reference . The search type reference is generally preferred for elements of type canonical because it can handle versioned canonical values. Where more than one search type can apply to a search parameter, the decision of which to use is based on the desired search behavior.

A few parameters have the type 'special'. That indicates that the way this parameter works is unique to the parameter and described with the parameter. The general modifiers and comparators do not apply, except as stated in the description.

Implementers will generally need to do special implementations for these parameters. These parameters are special:

Composite search parameters allow joining multiple elements into distinct single values with a $ . This is different from doing a simple intersection - the intersection rules apply at the resource level, so, for example, an Observation with multiple component repetitions may match because one repetition has a desired code and a different repetition matches a value filter.

The composite parameter approach works in this context because it allows searches based on a tuples of values. For example: Show as described above unencoded: HTTP GET | HTTP POST GET [base]/Observation?code-value-quantity=loinc|12907-2$ge150|http://unitsofmeasure.org|mmol/L POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code-value-quantity=loinc|12907-2$ge150|http://unitsofmeasure.org|mmol/L will match Observation records with a LOINC code of "12907-2" (Sodium [Moles/volume] in Red Blood Cells) AND a value greater than "150 mmol/L".

Note that the sequence is a single value and itself can be composed into a set of values. For example, searching Group.characteristic , both regarding how precision searching for multiple key/value pairs (instead of an intersection of matches on key and comparator/range operators value): Show as unencoded: HTTP GET | HTTP POST GET [base]/Group?characteristic-value=gender$mixed,owner$john-smith POST [base]/Group/_search Content-Type: application/x-www-form-urlencoded characteristic-value=gender$mixed,owner$john-smith will match Groups that have a gender characteristic of "mixed" (the group contains people of multiple genders) OR the group has a owner characteristic of "john-smith".

Note that search modifiers are interpreted. Example searches: NOT allowed on composite parameters.

Composite search parameters SHALL NOT declare components that reference other composite search parameters. § 58 All components of a composite search parameter must be non-composite (i.e., of one of the other basic or extended types). If a desired design would logically include the behavior of an existing composite search parameter, that nesting can be flattened by listing the underlying "leaf" component search parameters directly in the new composite.

For example, instead of defining a composite parameter code-value-quantity-and-device whose components are the existing code-value-quantity composite plus a device component (which would constitute nesting), define a new composite parameter with components code , value-quantity , and device (each pointing to the appropriate non-composite search parameters).

Examples of using composite parameters:

Show as unencoded: HTTP GET | HTTP POST
Search Description
GET [base]/Observation?value-quantity=5.4|http://unitsofmeasure.org|mg [base]/DiagnosticReport?result.code-value-quantity=http://loinc.org|2823-3$gt5.4|http://unitsofmeasure.org|mmol/L POST [base]/DiagnosticReport/_search Content-Type: application/x-www-form-urlencoded result.code-value-quantity=http://loinc.org|2823-3$gt5.4|http://unitsofmeasure.org|mmol/L Search for all the observations diagnostic reports that contain an observation with a potassium value of 5.4 mg where mg is understood as a UCUM unit ( system / code ) >5.4 mmol/L (UCUM)
GET [base]/Observation?value-quantity=5.4||mg [base]/Observation?component-code-value-quantity=http://loinc.org|8480-6$lt60 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded component-code-value-quantity=http://loinc.org|8480-6$lt60 Search for all the observations with a value of 5.4 mg where the unit - either the code ( code ) or systolic blood pressure < 60. Note that in this case, the stated human unit ( unit ) are "mg" is assumed (everyone uses mmHg)
GET [base]/Observation?value-quantity=le5.4|http://unitsofmeasure.org|mg [base]/Group?characteristic-value=gender$mixed POST [base]/Group/_search Content-Type: application/x-www-form-urlencoded characteristic-value=gender$mixed Search for all the observations where the groups that have a characteristic "gender" with a text value of is less than 5.4 mg where mg is understood as a UCUM unit "mixed"
GET [base]/Observation?value-quantity=ap5.4|http://unitsofmeasure.org|mg [base]/Questionnaire?context-type-value=focus$http://snomed.info/sct|408934002 POST [base]/Questionnaire/_search Content-Type: application/x-www-form-urlencoded context-type-value=focus$http://snomed.info/sct|408934002 Search for all the observations where the value of is about 5.4 mg where mg is understood as questionnaires that have a UCUM unit clinical focus = "Substance abuse prevention assessment (procedure)"

Specifying A resource type parameter is a system and special case parameter type that is used to enable chaining through elements that are actual resources (e.g., Bundle.entry.resource ).

Note that the resource search parameter type does not define a code test behavior for the search implies that parameter itself. For example, when using the Bundle-composition search parameter, the behavior of a test such as Bundle?composition=Composition/123 is based on undefined . Since search parameters of resource type are only defined to chain a particular code system - usually UCUM search through to a resource, thus the correct search would be shaped like Bundle?composition._id=123 .

Implementers will generally need to do special implementations for these parameters.

,

Implementation Note:

In FHIR R5 and that a precise (and potentially canonical) match is desired. earlier versions, the resource search type did not exist and some search parameters of type reference were defined expecting to chain through embedded resources.

In this case, it is inappropriate addition to search on the human display 'basic' searching, this specification defines behaviors for many 'special' cases that are common across implementations.

Explicit boundary searching on elements with the unit, which Range datatype can be is uncontrolled and may unpredictable. performed using composite search parameters . Composite search parameters allow a single search to test against multiple aspects of the same range.

The When a composite search processor may choose parameter references the same underlying search parameter that targets an element with a Range type multiple times, the search performs object-level joining rather than set-level joining. This means that the criteria apply to perform the same Range instance, not independently across multiple Range values in a repeating element.

For example, if we define a search based on canonical units parameter for Observation.valueRange named value-range and a composite search parameter named value-range-values that includes two components both referencing value-range , then a search such as: Show as unencoded: HTTP GET (e.g. any | HTTP POST GET [base]/Observation?value-range-values=ge20$le30 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded value-range-values=le20$ge30 will match Observation records with a value where the units can be converted range that has a low boundary greater than or equal to 20 AND a high boundary less than or equal to 30 on the same Range instance .

Note that this search will NOT match an Observation with two value in mg in ranges, one with a low of 25 and another with a high of 28, because the case above). low and high values do not belong to the same Range instance.

A reference parameter refers In FHIR data, there are a few types of identifiers that may apply to references between resources . For example, find all Conditions where the subject reference is a particular patient, where resource: a single logical identifier (the Resource.id of a resource), zero or more Identifier-type elements (e.g., Patient.Identifier ), and, if the patient resource is selected by name or identifier. The interpretation a Canonical Resource , a canonical url . Each of these 'identifiers' have a reference parameter is either: different datatype and expose different search functionality. Some details about each are included below.

The Logical Identifier of a resource using represents a local reference (i.e. unique key for an instance within a relative reference) specific context (e.g., a single resource type in a server collection, a resource in a bundle, etc.). Searching by the logical id of an instance is done via the [parameter]=[type]/[id] _id search parameter.

Given that a logical id is unique in the context, searching by logical [id] id will always result in either zero or one records. In many ways, the search is functionally equivalent to an equivalent simple read operation . However, there are some differences in using search instead of read:

  • Search operations always return bundles.
    • If the logical id exists and the resource can be returned, the result will be a bundle containing the resource (search) instead of the resource itself (read).
    • If the logical id does not exist or cannot be returned, the result of a specified type using a local reference (i.e. valid search will still be a relative reference), for when bundle. The bundle may include further information in the reference can point to different types form of resources (e.g. Observation.subject an OperationOutcome . See Handling Errors ) for more information.
  • [parameter]=[url] where Related resources can be requested and/or returned in the [url] is an absolute URL same request - see Including Other Resources for more information.
  • Additional search functionality is available. For example, asking for a reference to a Patient resource by its absolute location logical id, but also setting the search criteria of deceased to true would only return the Patient if they are deceased.

Note: A relative reference resolving to the same value as Since _id requires a specified absolute URL, resource type context and there can only be zero or vice versa, qualifies as one resources of a match. For example, if type with a given logical id, the search parameter value is Patient/123, then this will find references like this: <patient> <reference value="Patient/123"/> </patient> If the server base address is http://example.org/fhir, then functionally equivalent to the full URL for that reference is http://example.org/fhir/Patient/123, which simple read operation of GET [base]/Patient/23 . However, searching by logical identifier means that the all other search term also matches patient references like this: <patient> <reference value="http://example.org/fhir/Patient/123"/> </patient> In addition, searching for functionality is available - e.g., reference=http://example.org/fhir/Patient/123 OperationOutcome will also match both references. resources for issues, additional search parameters, inclusion of related resources, etc..

Some references resources (e.g., Group , List , and CareTeam ) are allowed to point used to more than one type maintain collections of resource; e.g. subject : Reference(Patient|Group|Device|..). In these cases, multiple resources may have the same logical identifier. Servers SHOULD reject other resources. For example, a search where the logical id refers to more than one matching resource across different types. In order Group of Patients representing a cohort or a List of patient allergies. While it is possible to allow retrieve the client to perform a search in these situations collection resource, iterate over the type is entries, and fetch each resource listed therein, using search criterion allows for fewer round-trips and additional search criteria to be specified explicitly: in-line.

GET [base]/Observation?subject=Patient/23

This searches for any observations where the subject refers to the patient resource with the logical identifier "23". A modifier is also There are two standard search parameters defined by this specification to support searching against collection resources:

GET [base]/Observation?subject:Patient=23

This has the same effect as the previous search. The modifier becomes useful when Identifier datatype is typically only used with chaining as explained on by a single element in the next section. Note: a resource and is typically named identifier . The element is typically cardinality [type] modifier can't be used with a reference 0..* , meaning that resources may have zero, one, or more identifiers attached to them (e.g., a resource found on another server, since the server would not single patient record with MRNs for several related facilities).

Resources containing identifier elements usually know what expose a matching search parameter, e.g., Patient.identifier or CanonicalResource.identifier . Given the structure of the identifier type, the search parameter is a token type that resource has. However, since these are absolute references, there can be no ambiguity about - see the type. token search type for details.

In some cases, It is often useful to search parameters are defined with an implicitly limited scope. via identifier across resource links. For example, if you have the MRN for a patient and do not know the logical identifier, it is desireable to perform searches like "encounters for the patient with MRN 1234". When elements are of the Reference FHIR type, there are two ways of traversing resource references by identifier, depending on how data is stored in the system: via chaining or via the Observation identifier has an element subject , which is search modifier.

Chaining functions by resolving a resource reference to one of a number of types. This has a matching and then searching inside it. In this case, requesting: Show as unencoded: HTTP GET | HTTP POST GET [base]/Encounter?patient.identifier=http://example.org/facilityA|1234 POST [base]/Encounter/_search Content-Type: application/x-www-form-urlencoded patient.identifier=http://example.org/facilityA|1234 will search parameter subject , which refers to any of Encounter resources, following references in the possible types. In addition to this, there is another patient search parameter ("the patient , which also refers to present at the encounter"), and testing those Patient resources against the Observation.subject , Patient.identifier value of 1234 in system http://example.org/facilityA . In short, this search will return all Encounters for Patient records matching "1234" in "facilityA".

This search is flexible, but does require resolving (searching against) Patient resources, even though the request is limited to only for Encounters. If a system wants to enable searches via identifiers without chaining, the server can include references of type additional information in the Reference Datatype (in Reference.identifier ), which is then accessible by the Patient identifier . When using search modifier. Note that this approach requires additional bookkeeping by the server - if a patient search parameter, there record is no modified, e.g., to add an additional identifier, every resource that refers to that patient record would need to specify ":Patient" as a modifier, or "Patient/" in the search value, as this must always be true. updated.

References are also allowed to have an The identifier . The modifier :identifier allows for searching functions by testing the identifier rather than the literal reference: GET [base]/Observation?subject:identifier=http://acme.org/fhir/identifier/mrn|123456 This is a Reference.identifier element within resources. In this case, requesting: Show as unencoded: HTTP GET | HTTP POST GET [base]/Encounter?patient:identifier=http://example.org/facilityA|1234 POST [base]/Encounter/_search Content-Type: application/x-www-form-urlencoded patient:identifier=http://example.org/facilityA|1234 will search for all observations that reference a patient by a particular patient MRN. When Encounter resources, testing the :identifier modifier is used, Encounter.subject.identifier element against the search value works as a token of 1234 in system http://example.org/facilityA . In short, this search . The :identifier modifier is not supported on canonical elements since they do not will return all Encounters for that have an Patient references and include the identifier separate "1234" from the reference itself. "facilityA".

Chaining Note that the difference between the two searches is not supported when using a single character - the :identifier modifier, nor are chaining, includes or reverse includes supported for reference elements that do not have . (period) in the first example represents a reference chained search and the : element. (colon) in the second indicates the use of a search modifier.

The reference search parameter is mostly used for resource elements of type Reference or Canonical Resources are identified by their url and possibly a version. Similarly, references to canonical . However, it is also resources are made with the canonical datatype. More details about canonical references can be used to search resource elements found in the Canonical URLs section of the references page.

When searching canonical references, the search type Resource - i.e. where one resource is directly nested within another - reference , though with an additional syntax for version information. For more information about version resolution, see the Bundle search parameters 'message' References and 'composition' as an example Versions section of this. this page.

Implementation note: Elements of the FHIR type Reference may contain a References are allowed to be version specific . versioned reference: Show as: FHIR+JSON | FHIR+XML { "resourceType": "Condition", ... "evidence": { "detail": { "reference": "Observation/123/_history/234234" } }, ... } <Condition> ... <evidence> <detail> <reference value="Observation/123/_history/234234"/> </detail> </evidence> ... </Condition>

When searching on version specific references, versioned References, the following rules apply:

  • If a resource has a reference that is version-specific versioned and chaining is performed, the criteria should will ideally be evaluated against the version referenced, but most systems will not be capable of this because search is only defined to function against the current version of a resource
  • Where a search does not act on the referenced version, search results SHOULD contain a OperationOutcome with a warning that indicates the discrepancy discrepancy. § 59
  • If a resource has a reference that is version-specific versioned and _include the resource is performed, included (e.g., _include , _revinclude ), the specified version SHOULD be provided. § 60
  • If a reference-type search parameter does not contain a version (i.e., no /_history/[version] in the URL), the search will match against resources containing both versioned and un-versioned references.

Elements of type canonical may contain a version specific reference, but this version is different in both meaning and format to version specific references that might be found in a Reference : Show as: FHIR+JSON | FHIR+XML { "resourceType": "QuestionnaireResponse", ... "questionnaire": "http://example.org/fhir/questionnaire/patient-intake|3.0", ... } <QuestionnaireResponse> ... <questionnaire value="http://example.org/fhir/questionnaire/patient-intake|3.0"/> ... </QuestionnaireResponse>

This version is a canonical reference to the business version of the resource.

For canonical references, servers SHOULD support searching by Canonical URLs, and SHOULD support automatically detecting a |[version] portion as part of the search parameter and interpreting that portion as a search on the business version of the target resource. § 61 The modifier :below is used with canonical references, to control whether the version is considered in the search. The search: Show as unencoded: HTTP GET | HTTP POST GET [base]/QuestionnaireResponse?questionnaire:below=http://example.org/fhir/questionnaire/patient-intake POST [base]/QuestionnaireResponse/_search Content-Type: application/x-www-form-urlencoded questionnaire:below=http://example.org/fhir/questionnaire/patient-intake would match QuestionnaireResponses based on Questionnaires:

  • http://example.org/fhir/questionnaire/patient-intake|1.0
  • http://example.org/fhir/questionnaire/patient-intake|1.1
  • http://example.org/fhir/questionnaire/patient-intake|2.0
  • etc.

The search: Show as unencoded: HTTP GET | HTTP POST GET [base]/QuestionnaireResponse?questionnaire:below=http://example.org/fhir/questionnaire/patient-intake|1 POST [base]/QuestionnaireResponse/_search Content-Type: application/x-www-form-urlencoded questionnaire:below=http://example.org/fhir/questionnaire/patient-intake|1 would match QuestionnaireResponses based on Questionnaires with a major version of '1', e.g.:

  • http://example.org/fhir/questionnaire/patient-intake|1.0
  • http://example.org/fhir/questionnaire/patient-intake|1.1
When a canonical URL with an appended version (i.e. [canonical]|[version] ) is supplied in a search parameter, the version portion is matched by the versionAlgorithm of the resource if known (explicit or derived). If the server does not know the algorithm of the versioning scheme, the version matching falls back to an exact-match, equivalent to token search semantics. If additional version matching behavior is required, the :above and :below modifiers can be used.

For further information about searching canonical references, see Choosing the right Canonical Reference .

Some resource references are circular - that is, the reference Reference points to another resource of the same type. When the reference establishes a strict hierarchy, the modifiers :above above and :below may below can be used to search transitively through the hierarchy: Show as unencoded: HTTP GET | HTTP POST GET [base]/Procedure?location:below=42 POST [base]/Procedure/_search Content-Type: application/x-www-form-urlencoded location:below=42

GET [base]/Procedure?location:below=42

This search returns no not only all procedures that occurred at location with id 42, but also any procedures that occurred in locations that are part of location with id 42.

GET [base]/MedicationAdministration?encounter:above=21

Show as unencoded: HTTP GET | HTTP POST GET [base]/MedicationAdministration?encounter:above=21 POST [base]/MedicationAdministration/_search Content-Type: application/x-www-form-urlencoded encounter:above=21

Returns all medication administrations that happened during encounter with id 21 or during any "parent" encounter of that encounter.

Resources that establish hierarchical references are listed in the Circular Resource References section of the References page.

Servers indicate that :above/:below above / below is supported on a search parameter by defining them as Modifiers on the Search Parameter definition.

The :below modifier is also very useful with searching MIME type icon, such as the search parameter DocumentReference.contenttype , which refers to Attachment.contentType . A simple search such as: Show as unencoded: HTTP GET | HTTP POST GET [base]/DocumentReference?contenttype=text/xml POST [base]/DocumentReference/_search Content-Type: application/x-www-form-urlencoded contenttype=text/xml will miss documents with a MIME type such as text/xml; charset=UTF-8 . This search will find all text/xml documents: Show as unencoded: HTTP GET | HTTP POST GET [base]/DocumentReference?contenttype:below=text/xml POST [base]/DocumentReference/_search Content-Type: application/x-www-form-urlencoded contenttype:below=text/xml

For ease of processing on the server, servers are only required to support :below on the base part of the MIME type; servers are not required to sort between different parameters and do formal subsumption logic.

Additionally, the below modifier can be applied to the first segment only: Show as unencoded: HTTP GET | HTTP POST GET [base]/DocumentReference?contenttype:below=image POST [base]/DocumentReference/_search Content-Type: application/x-www-form-urlencoded contenttype:below=image will match all image/ content types, e.g., "image/png", "image/jpeg", etc.

In order to save a client from performing a series of search operations, some reference parameters may be "chained" by appending them with a period ( . ) followed by the name of a search parameter defined for the target resource. This can be done recursively, following a logical path through a graph of related resources, separated by . . Note that chaining is only defined for reference type search parameters that target Reference FHIR type elements and resource type search parameters. Server implementers have discretion regarding additional requirements in content (e.g., whether external references are allowed) and behavior in extended scenarios (e.g., if canonical resolution is performed, etc.).

When chaining through references, it is possible that a resolved resource does not match the expected type. In this case, the reference is considered to not match the search parameter. If a reference resolves to a type different than allowed via the reference, a server SHOULD consider if it is appropriate to include the issue via an OperationOutcome in the response. § 62

For instance, given that the resource DiagnosticReport has a search parameter named subject , which is usually a reference to a Patient resource, and the Patient resource includes a parameter name which searches on patient name, then the search GET [base]/DiagnosticReport?subject.name=peter search: Show as unencoded: HTTP GET | HTTP POST GET [base]/DiagnosticReport?subject.name=peter POST [base]/DiagnosticReport/_search Content-Type: application/x-www-form-urlencoded subject.name=peter is a request to return all the lab reports that have a subject whose name includes "peter". Because the Diagnostic Report subject can be one of a set of different resources, it's necessary to limit the search to a particular type: GET [base]/DiagnosticReport?subject:Patient.name=peter Show as unencoded: HTTP GET | HTTP POST GET [base]/DiagnosticReport?subject:Patient.name=peter POST [base]/DiagnosticReport/_search Content-Type: application/x-www-form-urlencoded subject:Patient.name=peter This request returns all the lab reports that have a subject which is a patient, whose name includes "peter".

Note that chained parameters are applied independently to the target resource. For example, GET Patient?general-practitioner.name=Joe&general-practitioner.address-state=MN may return Patients cared Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?general-practitioner.name=Joe&general-practitioner.address-state=MN POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded general-practitioner.name=Joe&general-practitioner.address-state=MN is asking for by Joe from CA Patients that have any general practitioner with 'Joe' in their name and Jane from MN: no one that have any general practitioner need satisfy both conditions. E.g. that resides in Minnesota. Each chained parameter is evaluated individually, so a Patient that sees 'Dr. Joe' in California and 'Dr. Jane' in Minnesota matches. Following the logic, an implementation will:

  • find the set of Patients that have a generalPractitioner with a name matching "Joe"
  • find the set of Patients that have a generalPractitioner with an address matching "MN"
  • join the two sets of results with and logic at the Patient level.
E.g., the chains are evaluated separately. For use cases where the joins must be evaluated in groups, there are implementers can use either Composite search parameters, parameters or the _filter parameter.

Note that chained search parameters are not intended to work with search modifiers . While their use is not prohibited, searches requiring advanced matching across resources are encouraged to use Named Queries or Advanced filtering .

Advanced Search Note: Where a chained parameter searches a resource reference that may have more than one type of resource as its target, the parameter chain may end up referring to search parameters with the same name on more than one kind of resource at once. Servers SHOULD reject fail a search where the logical id of a reference refers to more than one matching resource across different types. For example, § 63 In those scenarios, the client has to specify the type explicitly using the syntax in the second example above.

The _has parameter provides limited support for reverse chaining - that is, selecting resources based on the properties of resources that refer to them (instead of chaining, above, where resources can be selected based on the properties of resources that they refer to). Here is an example of the _has parameter: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?_has:Observation:patient:code=1234-5 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _has:Observation:patient:code=1234-5

GET [base]/Patient?_has:Observation:patient:code=1234-5

This requests the server to return Patient resources, where the patient resource is referred to by at least one Observation where the observation has a code of 1234, and where the Observation refers to the patient resource in the patient search parameter.

"Or" searches are allowed (e.g. GET [base]/Patient?_has:Observation:patient:code=123,456), (e.g., _has:Observation:patient:code=123,456 ), and multiple _has parameters are allowed (e.g. GET [base]/Patient?_has:Observation:patient:code=123&_has:Observation:patient:code=456). (e.g., _has:Observation:patient:code=123&_has:Observation:patient:code=456 ). Note that each _has parameter is processed independently of other _has parameters.

The _has parameter can be chained, nested, like this: GET [base]/Patient?_has:Observation:patient:_has:AuditEvent:entity:user=MyUserId Fetch Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?_has:Observation:patient:_has:AuditEvent:entity:agent=MyUserId POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _has:Observation:patient:_has:AuditEvent:entity:agent=MyUserId This search will fetch all the patients Patient records that have an Observation where the observation has an audit event from a specific user.

3.1.1.4.16 Composite Search Parameters

Composite search parameters support joining single values with a $ . For example, the result of the search operation is the intersection of the resources that match the criteria specified by each individual search parameter. If a parameter repeats, such as /Patient?language=FR&language=NL , then this matches a patient who speaks both languages. This is known as an AND search parameter, since the server is expected to respond only with results which match both values. If, instead, the search is to find patients that speak either language, then this is a single parameter with multiple values, separated by a , . For example, The /Patient?language=FR,NL . This is known as an OR search parameter, since the server is expected to respond with results which match either value. Every search _has parameter may can also be used with comma-separated values in this fashion; this includes the use of search parameters with modifiers, such as `?code:text=this,that. AND parameters and OR parameters may also be combined, chained-searches, for example: /Patient?language=FR,NL&language=EN would refer to any patient who speaks English, as well Show as either French or Dutch. This approach allows for simple combinations of and/or values, but doesn't allow a unencoded: HTTP GET | HTTP POST GET [base]/Encounter?patient._has:Group:member:_id=102 POST [base]/Encounter/_search Content-Type: application/x-www-form-urlencoded patient._has:Group:member:_id=102 to search based on a pair of values, such as all observations with a sodium value >150 mmol/L (particularly as for the end criteria of a chained search), or searching on Group.characteristic where you need find a combination Encounters of key/value, not an intersection patients that are members of separate matches on key and value. Another example is spatial coordinates when doing geographical searches. the Group "102".

To allow these searches, a resource may also specify composite parameters that take sequences of single values Note that match other defined reverse-chained search parameters as an argument. The matching parameter of each component in such a sequence are not intended to work with search modifiers . While their use is documented in not prohibited, the definition syntax of the parameter. These sequences are formed by joining the single values with a $ . Note: This sequence is a single value _has makes construction and itself can be composed into a set of values, so that, for example, multiple parsing error-prone. Searches requiring advanced matching state-on-date parameters can be specified as state-on-date=new$2013-05-04,active$2013-05-05 . Note: Modifiers across resources are not used on composite parameters. Examples of using composite parameters: encouraged to use Named Queries or Advanced filtering .

Search Description GET [base]/DiagnosticReport?result.code-value-quantity=http://loinc.org|2823-3$gt5.4|http://unitsofmeasure.org|mmol/L Search for all diagnostic reports that contain on observation with a potassium value of >5.4 mmol/L (UCUM) GET [base]/Observation?component-code-value-quantity=http://loinc.org|8480-6$lt60 Search for all the observations with a systolic blood pressure < 60. Note that in this case, the unit is assumed (everyone uses mmHg) GET [base]/Group?characteristic-value=gender$mixed Search for all groups that have a characteristic "gender" with a text value of "mixed"

Consider the case of searching for all AllergyIntolerance resources: Show as unencoded: HTTP GET | HTTP POST GET [base]/AllergyIntolerance?clinical-status=http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical|active POST [base]/AllergyIntolerance/_search Content-Type: application/x-www-form-urlencoded clinical-status=http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical|active

GET [base]/AllergyIntolerance?clinical-status=active

This search will only return resources that have a value for clinicalStatus: Show as: FHIR+JSON | FHIR+XML { "resourceType" : "AllergyIntolerance", "clinicalStatus": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical", "code": "active" } ] } } <AllergyIntolerance> <clinicalStatus> <coding> <system value="http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"/> <code value="active"/> </coding> </clinicalStatus> </AllergyIntolerance>

{ "resourceType" : "AllergyIntolerance", "clinicalStatus" : "active" }

Resources missing a clinicalStatus will not be returned. This is probably unsafe - it would not usually be appropriate to ignore AllergyIntolerance warnings with an unknown clinical status, and only return resources with an explicit clinicalStatus. Instead, it might be desired to return AllergyIntolerance resources with either an explicit value for clinicalStatus, or none: Show as unencoded: HTTP GET | HTTP POST GET [base]/AllergyIntolerance?clinical-status=http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical|active POST [base]/AllergyIntolerance/_search Content-Type: application/x-www-form-urlencoded clinical-status=http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical|active GET [base]/AllergyIntolerance?clinical-status:missing=true POST [base]/AllergyIntolerance/_search Content-Type: application/x-www-form-urlencoded clinical-status:missing=true

GET [base]/AllergyIntolerance?clinical-status=active GET [base]/AllergyIntolerance?clinical-status:missing=true

Note that this is 2 separate queries. They can be combined in a batch , but not in a single operation. This query will always return an empty list, as no resource can satisfy both criteria at once: Show as unencoded: HTTP GET | HTTP POST GET [base]/AllergyIntolerance?clinical-status=http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical|active&clinical-status:missing=true POST [base]/AllergyIntolerance/_search Content-Type: application/x-www-form-urlencoded clinical-status=http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical|active&clinical-status:missing=true

GET [base]/AllergyIntolerance?clinical-status=active&clinical-status:missing=true

There is no way to use the :missing modifier and mix with a value using the comma syntax documented above for composite search parameters.

An alternative approach is to use the _filter parameter, for servers that support this parameter.

3.1.1.4.18 Escaping Search Parameters In the rules described above, special rules are defined for the characters $ , , , and | . As a consequence, if these characters appear in an actual parameter value, they must be differentiated from their use as separator characters. When any of these characters appear in an actual parameter value, they must be prepended by the character \ , which also must be used to prepend itself. Therefore, param=xxx$xxx indicates that it is a composite parameter, while param=xx\$xx indicates that the parameter has the literal value xx$xx . The parameter value xx\xx is illegal, and the parameter value param=xx\\xx indicates a literal value of xx\xx . This specification defines this additional form of escape for a reason. The classic %xx escaping which is part of normal HTTP URLs ensures that the character appears at the FHIR server correctly, while the , versus \ becomes important once it has reached the server and the query is parsed. Therefore: GET [base]/ValueSet?url=http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124%2CValueSet/125 uses url escaping to make sure the FHIR server received: GET [base]/ValueSet?url=http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124,125 This request will compare the URL against three values: the last one being a relative and incorrect url, which is likely not the actual intent. However: GET [base]/ValueSet?url=http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124\,125 is equivalent to: GET [base]/ValueSet?url=http://acme.org/fhir/ValueSet/123,http://acme.org/fhir/ValueSet/124\%2C125 which would mean: url = http://.....123 OR http://....124,125 . 3.1.1.4.19 Text Search Parameters The special text search parameters, _text and _content , search on the narrative of the resource, and the entire content of the resource respectively. These parameters SHOULD support a sophisticated search functionality of the type offered by typical text indexing services. The value of the parameter is a text-based search, which may involve searching multiple words with thesaurus and proximity considerations, and logical operations such as AND, OR etc. For example: GET [base]/Condition?_text=(bone OR liver) and metastases This request returns all Condition resources with the word "metastases" and either "bone" or "liver" in the narrative. The server MAY choose to search for related words as well. STU Note: The issues around standardizing text search are not fully resolved. During the trial use period for this specification, we recommend that systems use the rules specified by the OData specification for the $ search parameter . Typical implementations would use Lucene, an sql-based full text search, or some indexing service. Feedback is welcome here . 3.1.1.4.20 Searching by list The _list parameter allows for the retrieval of resources that are referenced by a List resource. GET [base]/Patient?_list=42 This request returns all Patient resources that are referenced from the list found at [base]/List/42 ) in List.entry.item. While it is possible to retrieve the list, and then iterate the entries in the list fetching each patient, using a list as a search criteria allows for additional search criteria to be specified. For instance: GET [base]/Patient?_list=42&gender=female This request will return all female patients in the list. The server can return the list referred to in the search parameter as an included resource, but is not required to do so. In addition, a system can support searching by lists by their logical function. For example: GET [base]/AllergyIntolerance?patient=42&_list=$current-allergies This request will return all allergies in patient 42's "Current Allergy List". The server returns all relevant AllergyIntolerance resources, and can also choose to return the list. For further information, refer to the definition of "$current-allergies" , and the List Operation "Find" . Note: Servers are not required to make these lists available to the clients as list resources, but may choose to do so.

The search mechanism described above is flexible, and easy to implement for simple cases, but is limited in its ability to express combination queries. To complement this mechanism, the "_filter" _filter search expression parameter can be used.

For example, "Find all the observations for patient with a name including peter that have a LOINC code 1234-5 ": Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?code=http://loinc.org|1234-5&patient.name=peter POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded code=http://loinc.org|1234-5&patient.name=peter

GET [base]/Observation?code=http://loinc.org|1234-5&subject.name=peter

Using the _filter parameter, the search would be expressed like this: this (note that the value is unescaped for readability): Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_filter=code eq http://loinc.org|1234-5 and patient.name co "peter" POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _filter=code eq http://loinc.org|1234-5 and patient.name co "peter"

GET [base]/Observation?_filter=name eq http://loinc.org|1234-5 and subject.name co "peter"

The _filter parameter is described in detail on the "_Filter Parameter" page .

Normally, a search is initiated against a known type of resource, e.g. GET [base]/Observation?params... e.g.: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?params... POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded params... However, in some circumstances, a search is executed where there is no fixed type of resource: resource, for example:

  • Using search across all resource types (GET [base]?params...) ( [base]?params... )
  • Using search with messaging
  • Some search specifications inside other services e.g. e.g., decision support usage

In these circumstances, the search criteria may need to specify one or more resource types that the search applies to. This can be done by using the standard search parameter _type parameter: .

GET [base]/?_type=Observation,Condition&other params...

Note that If no type is specified, the only search parameters that be can be used in global search like this are the base parameters that apply to all resources. In other contexts, searches on resources .

If a single type is specified, all search parameters for that type are allowed.

If multiple types may allow resource specific are specified, all search parameters, but implementation experience will parameters that can be required referenced commonly between resources can be used (e.g., listed with the same name in the CapabilityStatement, typically the value of SearchParameter.code or one of its SearchParameter.alias values). For example, both Patient and Person define a search parameter referenced by name . Assuming a server implements both parameters and uses name to determine do so, the correct name parameter can be used to search across both Patient and Person resources. Note that this is allowed even though the search parameters do not share a common definition. If a request references multiple parameters that are not the same type (e.g., if one parameter is a number type and another is a token type, despite sharing the same name), this is an error and servers SHOULD return a 400 status. § 64

Some resources are defined implicitly rather than as explicit instances (e.g., Implicit Code Systems ). When searching resources where implicit instances might exist, it is up to the server whether they will include implicit resources as part of the search set. Implementation Guides MAY set specific expectations about search behavior around implicit resources. § 65

The search framework described above is a useful framework for providing a simple search based on indexed criteria, but more sophisticated query capability is needed to handle precise queries, complex decision support-based requests, and direct queries that have human resolution. To support more advanced functionality, this specification defines a method for creating and using named queries .

The _query parameter names a custom search profile that describes a specific query operation. A named query may define additional named parameters that are used with that particular named query. Servers can define their own additional named queries to meet their own uses using an OperationDefinition .

Query operations are only allowed in these cases. the base and type search contexts . Named queries cannot be defined at the instance level. Named-query operations SHOULD NOT be invoked via any method other than search with the _query parameter (e.g., servers SHOULD NOT execute query operations via [base]/$[operation code] or [base]/[type]/$[operation code] , etc.). § 66

Technically, For named queries, all the standard search parameters (parameters for all resources and search result parameters) are potentially available for use in addition to any parameters defined by the query operation. In addition, if the query operation is defined in the scope of a specific resource, the search parameters for that resource are also potentially available. For example, a named query with a scope of _type Patient could include the _lastUpdated , _sort , and/or Patient.gender search parameters, even if those aren't explicitly listed as parameters on the query operation.

Servers do not need to support ANY such 'inherited' parameters unless explicitly documented in the operation's description. Clients SHOULD NOT assume the availability of any search parameter that is not supported for general queries (i.e., listed in the server's CapabilityStatement , either in CapabilityStatement.rest.searchParam or CapabilityStatement.rest.resource.searchParam ). § 67 Servers MAY further document the search parameters they support for a token specific query operation - either in text or by defining a constrained operation based on the original that explicitly enumerates all supported parameters. § 68

In order to ensure consistent behavior, authors SHOULD include relevant search parameters in the named query definition ( OperationDefinition ). § 69

For example, the operation definition: Show as: FHIR+JSON | FHIR+XML { "resourceType": "OperationDefinition", "id": "current-high-risk", "url": "http://example.org/OperationDefinition/current-high-risk", "version": "0.0.1", "name": "Current High-Risk Patients", "status": "draft", "kind": "query", "description": "Filter Patients based on risk assessments", "code": "current-high-risk", "resource": [ "Patient" ], "system": false, "type": true, "instance": false, "parameter": [ { "name": "ward", "use": "in", "min": 0, "max": "*", "documentation": "Ward filters to apply to patient locations", "type": "string", "searchType": "reference" }, { "name": "return", "use": "out", "min": 1, "max": "1", "documentation": "Searchset bundle", "type": "Bundle" } ] } <OperationDefinition xmlns="http://hl7.org/fhir"> <id value="current-high-risk" /> <url value="http://example.org/OperationDefinition/current-high-risk" /> <version value="0.0.1" /> <name value="Current High-Risk Patients" /> <status value="draft" /> <kind value="query" /> <description value="Filter Patients based on risk assessments" /> <code value="current-high-risk" /> <resource value="Patient" /> <system value="false" /> <type value="true" /> <instance value="false" /> <parameter> <name value="ward" /> <use value="in" /> <min value="0" /> <max value="*" /> <documentation value="Ward filters to apply to patient locations" /> <type value="string" /> <searchType value="reference" /> </parameter> <parameter> <name value="return" /> <use value="out" /> <min value="1" /> <max value="1" /> <documentation value="Searchset bundle" /> <type value="Bundle" /> </parameter> </OperationDefinition> can be executed via: Show as unencoded: HTTP GET | HTTP POST

Request Description
GET [base]/Patient?_query=current-high-risk POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _query=current-high-risk Query with no additional parameters
GET [base]/Patient?_query=current-high-risk&ward=Location/A1 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _query=current-high-risk&ward=Location/A1 Query with a ward parameter value passed to the filter
GET [base]/Patient?_query=current-high-risk&birthdate=ge1970-01-1 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _query=current-high-risk&birthdate=ge1970-01-01 Query with a no additional parameters, filter results according to a standard patient birthdate query.
Note that servers SHOULD accept query parameters that are not enumerated in named queries based on their standard support (e.g., parameters that are supported for a given resource type), but servers MAY choose to ignore parameters not specified by the Resource Types OperationDefinition. § 70 Value Set.
GET [base]/Patient?_query=current-high-risk&birthdate=ge1970-01-01&ward=Location/A1 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _query=current-high-risk&birthdate=ge1970-01-01&ward=Location/A1 Query with both a ward parameter value passed to the named query and a standard patient query filter by birthdate.
Note that query parameters are unordered, so parameters to a named query MAY appear in any location or sequence. § 71

FHIR allows specifications to define "additional" resources beyond those in the core set. These are defined outside the base specification but use the same infrastructure and search framework. There is no special behavior or different syntax required when searching for these resources: servers and clients use the same search parameter names and processing rules as for "standard" (core) resources.

The specification (or Implementation Guide) that defines an additional resource SHOULD define a set of standard search parameters for that resource § 72 so that a minimal level of interoperability is possible. Other specifications are free to define further search parameters (subject to the usual namespacing and conformance declarations). Servers MAY also define custom parameters as with any other resource type.

Clients might encounter previously unknown additional resource types in search results. This can happen if the server returns them via unrequested _include / _revinclude processing or if they appear as contained resources within search bundle entries. Clients SHOULD be robust in the presence of such resources (e.g., safely ignore, render generically, or retrieve definitions as appropriate) and avoid failing the entire response simply due to an unfamiliar additional resource type.

No extra conformance statement elements or flags are needed to enable searching additional resources beyond those already described for ordinary resources; capability exposure and parameter support are declared in the same way (e.g., via CapabilityStatement.rest.resource and associated searchParam elements).

Along with search parameters that are used as input to search filters, there are also Search Result Parameters defined by this specification to modify the results of a performed search. These parameters control aspects of the results such as sort order, including related resources, etc., and are defined in the following sections. Note that since these are not search parameters, they do not have definitions as SearchParameter resources and do not appear in the search parameter registry .

Note that with the exception of _include and _revinclude , search result parameters SHOULD only appear once in a search. If such a parameter appears more than once, the behavior is undefined and a server MAY treat the situation as an error. § 73

The search result parameters defined by this specification are:

_contained Request different types of handling for contained resources.
_count Limit the number of match results per page of response.
_elements Request that only a specific set of elements be returned for resources.
_graph Include related resources according to a GraphDefinition .
_include Include related resources, based on following links forward across references.
_maxresults Limit the total number of match results a request can return.
_revinclude Include related resources, based on following reverse links across references.
_score Request match relevance in results.
_sort Request which order results are returned in.
_summary Return only portions of resources, based on pre-defined levels.
_total Request a precision of the total number of results for a request.

The client can indicate which order to return the results by using the parameter _sort , which can contains contain a comma-separated list of sort rules in priority order: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_sort=status,-date,category POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _sort=status,-date,category

GET [base]/Observation?_sort=status,-date,category

Each item in the comma separated comma-separated list is a search parameter, optionally with a '-' prefix. The prefix indicates decreasing order; in its absence, the parameter is applied in increasing order.

Notes:

  • When sorting, the actual sort value used is not returned explicitly by the server for each resource, just the resource contents.
  • To sort by relevance, use _score .
  • The server returns the sort it performs as part of the returned search parameters (see below ).
  • A Servers have discretion on the implementation of sorting for both repeated elements and complex elements. For example, if requesting a sort on Patient.name , servers might search parameter can refer to an element that repeats, by family name then given, given name then family, or prefix, family, and therefore there can be then given. Similarly, when sorting with multiple values for a given search parameter for a single resource. In this case, names, the sort is might be based on the item in the set of multiple parameters that comes earliest 'earliest' name in the specified sort order when ordering or the returned resources. first name in the instance.
  • When sorting on string search parameters, sorting SHOULD be performed on a case-insensitive basis. § 74 Accents may either be ignored or sorted as per realm convention.
  • This specification does not specify exacts exact rules for consistency of sorting across servers. In general, this is deemed to be not as essential as consistency of filtering (though even that is a little variable). The purpose of sorting is to provide data in a "reasonable" order for end-users. "Reasonable" may vary by use case and realm, particularly for accented characters.
  • When sorting on search parameters of reference and token types, the search parameter can include the text modifier to request sorting based on the text or display portions of the element values. For example, _sort=code:text or _sort:-code:text . Servers MAY or MAY NOT support the text sort modifier behavior, and MAY fall back to token-based sorting or disregard the value. § 75
  • When sorting on search parameters of date type, if the source data is not a single instance (e.g., a Period ) the sort behavior is server-defined. If more prescribed search behavior is needed, custom search parameters that assert specific behavior can be defined. Note that most reference implementations search by the start of the period.

The return Bundle has an element total which is the number of resources that match the search parameters.

Note that Bundle.total represents the total number of matches, not how many resources are returned in a particular response (see paging ).

Providing a precise number of matching resources may be onerous for the server, depending on how the server is designed. To help reduce the server load, a client can provide the parameter _total to indicate its preference with regard to the total, which can have one of the following values:

none There is no need to populate the total count; the client will not use it
estimate A rough estimate of the number of matching resources is sufficient
accurate The client requests that the server provide an exact total of the number of matching resources

The Bundle.total element is still optional, and the servers can ignore the _total parameter: it is just an optimization hint, that might possibly save the server some work.

The _total parameter has the status trial-use pending real-world experience of its use.

In order to keep the load on clients, servers servers, and the network minimized, the server may choose to return the results in a series of pages. The search result set contains the URLs that the client uses to request additional pages from the search set. For a simple RESTful search, the page links are contained in the returned bundle as links .

Typically, a server will provide its own parameters in the links that it uses to manage the state of the search as pages are retrieved. These parameters do not need to be understood or processed by the client.

The parameter _count is defined as a hint an instruction to the server regarding how many the maximum number of resources should that can be returned in a single page. Servers SHALL NOT return more resources in a single page than requested, even if they don't support paging, but are allowed to MAY return less than the client requested. The server should repeat § 76 NOTE: This means that all servers that support search or history SHALL support checking the original _count parameter in its returned page links so parameter. § 77 The server SHOULD ensure that subsequent paging requests honor any pages reachable via links (e.g., previous/next) respect the the original requested _count . expectations (or a server-overridden max page size). § 78 Note: It is at the discretion of the search engine as to how to handle ongoing updates to the resources while the search is proceeding.

Note: The combination of _sort and _count can be used to return only the latest resource that meets a particular criteria - set the criteria, and then sort by date in descending order, with _count=1 . This way, the last matching resource will be returned.

if If _count has the value 0, 0 (zero), this shall SHALL be treated the same as _summary=count : the server returns a bundle that reports the total number of resources that match in Bundle.total, Bundle.total , but with no entries, and no prev/next/last previous/next/last links. § 79 Note that the Bundle.total only include includes the total number of matching resources. It does not count extra resources such as OperationOutcome or included resources that may also be returned. In the same way, the _count parameter only applies to resources with entry.search.mode = match , and does not include included resources or operation outcomes.

The _count parameter has no impact on the value of Bundle.total as the latter represents the total number of matches, not how many are returned in a single Bundle response.

In some scenarios, a client knows that it will only process a certain number of results for a search, regardless of how many records there are. For example, if an application is providing an overview of patient activity and will only display the most recent observation on a summary screen, telling the server that additional records will never be retrieved allows the server to free any resources that might have been reserved for paging.

The parameter _maxresults is defined as a hint to the server regarding the limit on how many total resources to returned from a query. If supported, a server SHOULD NOT return more resources than requested. § 80 As with other parameters, servers supporting _maxresults SHALL include this parameter in result the Self Link when returning results if it is used. § 81

The _maxresults parameter has no impact on the value of Bundle.total as the latter represents the total number of matches, not how many are returned in a response.

The _maxresults parameter only affects the number of resources returned as matches ( _include entry.search.mode=match and ). It does not affect the number of resources returned as included resources ( _revinclude entry.search.mode=include ) or operation outcomes ( entry.search.mode=outcome ).

The combination of _sort and _maxresults can be used to return only the latest resource that meets a particular criteria - set the criteria, and then sort by date in descending order, with _maxresults=1 . This way, the last matching resource will be returned.

Note that _maxresults does not absolve a server from paging requirements. For example, a client can request _maxresults=10&_count=5 to receive (at most) two pages of five results each.

Clients may The client can request that the engine server to return only a portion of the resources related by using the parameter _summary : Show as unencoded: HTTP GET | HTTP POST GET [base]/ValueSet?_summary=true POST [base]/ValueSet/_search Content-Type: application/x-www-form-urlencoded _summary=true

The _summary parameter requests the server to return a subset of the search results, resource. It can contain one of the following values:

true Return a limited subset of elements from the resource. This subset SHOULD consist solely of all supported elements that are marked as "summary" in order the base definition of the resource(s) (see ElementDefinition.isSummary ). § 82
text Return only the text , id , meta , and top-level mandatory elements (these mandatory elements are included to reduce ensure that the overall network delay payload is valid FHIR; servers MAY omit elements within these sub-trees as long as they ensure that the payload is valid). § 83 Servers MAY return extensions in summary mode, but clients SHOULD NOT rely on extensions being present and SHOULD use another search mode if data contained in extensions is required. § 84
data Remove the text element
count Search only: just return a count of repeated retrievals the matching resources, without returning the actual matches
false Return all parts of related resources. This the resource(s)

The intent of the _summary parameter is to reduce the total processing load on server, client, and resources between them such as the network. It is most useful when for resources that are large, particularly ones that include images or elements that may repeat many times. The purpose of the summary form is to allow a client to quickly retrieve a large set of resources, and let a user pick the appropriate one. The summary for an element is searching defined to allow a user to quickly sort and filter the resources, and typically omit important content on the basis that the entire resource will be retrieved when the user selects a clinical resource, but resource.

Servers are not obliged to return just a summary as requested. There are only a limited number of summary forms defined for every such resource returned, resources in order to allow servers to store the client will also need summarized form(s) in advance. Servers SHOULD mark the subject (patient) resource by populating meta.tag resources with the code SUBSETTED icon to ensure that the clinical incomplete resource refers to. The is not accidentally used to overwrite a complete resource. § 85

Note that the self link in the search result Bundle is important for the interpretation of the result and SHALL always be returned, regardless of the type of _summary . § 86

Note that the _include and _revinclude parameters cannot be mixed with _summary=text .

Implementation Note: There is some question about the inclusion of extensions in the summary. Additional rules may be made around this in the future.

If one of the summary views defined above is not appropriate, a client can use request a specific set of elements be returned as part of a resource in the search results using the _include _elements parameter: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?_elements=identifier,active,link POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _elements=identifier,active,link

The _elements parameter to indicate that consists of a comma-separated list of base element names such as, elements defined at the subject resources root level in the resource. Each element name SHALL be included the base element name without specifying [x] or one of the types (e.g., "value" is valid, while "value[x]" and "valueQuantity" are not). § 87 Only elements that are listed are to be returned. Clients SHOULD list all mandatory and modifier elements in a resource as part of the results. An alternative scenario list of elements. § 88 Servers have the right to return more data than request, however clients can generally expect that returned elements will be:

  • elements explicity requested,
  • mandatory elements, or
  • modifier elements that have values.

This parameter is where allowed to be used for interactions other than 'search'. See the client wishes RESTful API page.

Servers are not obliged to fetch a particular resource, return just the requested elements. Servers SHOULD return mandatory and any modifier elements whether they are requested or not. § 89 Servers SHOULD mark the resources that refer with the tag SUBSETTED icon to it. For example, ensure that the incomplete resource is not actually used to overwrite a complete resource. § 90

If a client supplies _elements values prefixed with resource types, such as _elements=Patient.gender , then servers SHOULD apply these element-level restrictions to all resources in the returned bundle, rather than just to direct search matches (i.e., restrictions should be applied to bundle entries with any search.mode). § 91

Where a search specifies a non-deterministic sort, the search algorithm may wish generate a ranking score to fetch indicate which resources meet the specified criteria better than others. The server can return this score in entry.score : Show as: FHIR+JSON | FHIR+XML "entry": { "score": 0.45, "resource": { "resourceType": "Patient", ... patient data ... } } <entry> <score value=".45"/> <resource> <Patient> ... patient data ... </Patient> </resource> </entry>

The score is a MedicationRequest, decimal number with a value between (and including) 0 and any provenance 1, where 1 is best match, and 0 is least match.

Along with resources matching search criteria, clients may request that refer related resources are included with results (i.e., to reduce the prescription. overall network delay of repeated retrievals). For example, when searching for clinical resources (e.g., Condition , Observation , etc.), the client will also generally need the subject ( Patient ) resource that the clinical resource refers to. This section describes several mechanisms for requesting additional data within FHIR search.

Note that implementers can also consider whether using GraphQL is known as a reverse include, and an appropriate approach. GraphQL is specified by providing a outside the scope of FHIR Search and thus not described here.

Both The most common method for requesting related resources is inline, via the search result parameters _include and _revinclude . The parameters are based on similar to chaining search parameters, rather than paths in the resource, since joins, such as chaining , are already done by that they follow links between resources based on search parameter. parameters.

Each The parameter _include parameter specifies a search parameter is used to join on: follow links 'forward'. For example, to include relevant Patient resources for requested Encounter matches, based on the Encounter.subject element, using either the subject or patient search parameters.

GET [base]/MedicationRequest?_include=MedicationRequest:patient GET [base]/MedicationRequest?_revinclude=Provenance:target

The first search requests all matching MedicationRequests, parameter _revinclude is used to follow reverse links. For example, to include any patient that relevant Observation resources for requested Patient matches, based on the medication prescriptions in Observation.subject element, using either the result set refer to. The second subject or patient search requests all matching prescriptions, return all the provenance resources that refer to them. parameters.

Parameter values for both Both _include and _revinclude have share the same syntax - up to three parts, components, separated by a colon characters ( : character: ). The details of the syntax are:

  • The [_include|_revinclude]=* : the wildcard literal * (asterisk) is requesting all resources and references supported by the server (will typically only be supported references that are indexed).
  • [_include|_revinclude]=[resource]:* : where [resource] is the name of the source resource from which the join comes and the wildcard literal * (asterisk) is requesting all supported reference and resource type search parameters for that resource. Note that the list of search parameters supported for _include or _revinclude is not the same as the list of supported search parameters.
  • The [_include|_revinclude]=[resource]:[parameter] : where [resource] is the name of the source resource from which the join comes and [parameter] is the name of a search parameter which must be of type reference .
  • (Optional) A specific [_include|_revinclude]=[resource]:[parameter]:[targetType] : where [resource] is the name of type the source resource from which the join comes, [parameter] is the name of target a search parameter which must be of type reference or resource , and [targetType] is a specific resource type (for when the a search parameter refers to references of multiple possible target types) types).

Note that implementers intending to support wildcard ( * ) segments SHOULD advertise them along with other resources and search parameters in their capability statement (e.g., in CapabilityStatement.rest.resource.searchInclude ). § 92

_include and _revinclude parameters do not include multiple values. Instead, the parameters are repeated for each different include criteria.

Each _include parameter specifies a search parameter to join on: Show as unencoded: HTTP GET | HTTP POST GET [base]/MedicationRequest?_include=MedicationRequest:requester POST [base]/MedicationRequest/_search Content-Type: application/x-www-form-urlencoded _include=MedicationRequest:requester GET [base]/MedicationRequest?_revinclude=Provenance:target POST [base]/MedicationRequest/_search Content-Type: application/x-www-form-urlencoded _revinclude=Provenance:target

The first search requests all matching MedicationRequests, and asks the server to follow the resource references found via the requester search parameter value for each medication returned, and include them in the result set. The second search requests all prescriptions and any Provenance resources that refer to those prescriptions.

For each returned resource, the server identifies the resources that meet the criteria expressed in the join, and adds to the results, with the entry.search.mode set to "include" include . Note that if a resource is both a match directly and an include , the mode will be set to match (in some searches, it is not obvious which resources are matches, arematches, and which are includes). If there is no reference, or value in the reference element, no matching resource, or the resource cannot be retrieved (e.g. (e.g., on a different server), then the resource is omitted, omitted and no error is returned.

The inclusion process can be recursive, if Servers SHOULD resolve _include and _revinclude requests for version-specific references by resolving the modifier :recurse version named in the reference. § 93

_include is included. and _revinclude are, by default, invoked only on the initial results of the search set, not on any 'included' resources. To repeatedly perform the _include and _revinclude instructions on included resources, use the iterate modifier.

For example, this search returns all Medication Request MedicationRequest resources and their prescribing Practitioner Resources for the matching Medication Dispense MedicationDispense resources: Show as unencoded: HTTP GET | HTTP POST GET [base]/MedicationDispense?_include=Medication:prescription &_include:iterate=MedicationRequest:requester&criteria... POST [base]/MedicationDispense/_search Content-Type: application/x-www-form-urlencoded _include=MedicationDispense:prescription&_include:iterate=MedicationRequest:requester&criteria...

Details about the iterate modifier can be found in the section Modifier: iterate , including potential performance considerations.

GET [base]/MedicationDispense?_include=MedicationDispense:authorizingPrescription &_include:recurse=MedicationRequest:prescriber&criteria...

This technique applies to circular relationships as well. For example, the first of these two searches includes any related observations to the target relationships, but only those directly related. The second search asks for the _include based on related parameter to be executed recursively, iteratively, so it will retrieve observations that are directly related, and also any related observations to any other included observation. Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_include=Observation:has-member&criteria... POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _include=Observation:has-member&criteria... GET [base]/Observation?_include:iterate=Observation:has-member&criteria... POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _include:iterate=Observation:has-member&criteria...

GET [base]/Observation?_include=Observation:related-target&criteria... GET [base]/Observation?_include:recurse=Observation:related-target&criteria...

Both _include and _revinclude use allow the use of a wild card "*" for the search parameter name, indicating that any search parameter of type=reference or type=resource be included. Though both Both clients and servers need to take care not to request or return too many resources when doing this. Most notably, using recursive iterative wildcards inclusions might lead to the retrieval of the full patient's record, or even more: more than that: resources are organized into an interlinked network and broad _include paths may eventually traverse all possible paths on the server. For servers, these recursive iterative and wildcard _include s are demanding and may slow the search response time significantly.

It is at the server's discretion how deep to recursively iteratively evaluate the inclusions. Servers are expected to limit the number of iterations done to an appropriate level and are not obliged to honor requests to include additional related resources in the search results. Because iterative search is generally resource intensive, it is not the default behavior.

When search results are paged, each page of search results should SHOULD include the matching includes for the resources in each page, so that each page stands alone as a coherent package. § 94

If the _include path selects a reference that refers to a resource on another server, the server can elect to include that resource in the search results for the convenience of the client.

If the _include path selects a reference that refers to an entity that is not a Resource, such as an image attachment, the server may also elect to include this in the returned results as a Binary resource. For example, the include path may point to an attachment which is by reference, like this: Show as: FHIR+JSON | FHIR+XML "content": { "contentType": "image/jpeg", "url": "http://example.org/images/2343434/234234.jpg" } <content> <contentType>image/jpeg</contentType> <url>http://example.org/images/2343434/234234.jpg</url> </content>

The server can retrieve the target of this reference, and add it to the results for the convenience of the client.

When including resources referenced via canonical elements, servers perform resolution as described for Canonical Identifiers . Server implementers have discretion about whether or not to support canonical resolution in includes and reverse includes, and may impose additional restrictions (e.g., only resolving canonicals that are pre-loaded, from specific packages, or within certain namespaces).

Servers that support canonical resolution in includes SHOULD advertise this capability by listing the relevant search parameters in CapabilityStatement.rest.resource.searchInclude and .revInclude. § 95 Including a search parameter in these elements indicates that the server will attempt to resolve and include the referenced resources.

For example, some servers will want to allow inclusion of Questionnaire resources referenced by QuestionnaireResponse resources via the questionnaire canonical reference element: Show as unencoded: HTTP GET | HTTP POST GET [base]/QuestionnaireResponse?_include=QuestionnaireResponse:questionnaire POST [base]/QuestionnaireResponse/_search Content-Type: application/x-www-form-urlencoded _include=QuestionnaireResponse:questionnaire

While inline requests for related resources are flexible, there are times when a more structured approach is desired (e.g., optimizing frequent requests, etc.). To facilitate a structured approach, the _graph result parameter is defined.

The _graph result parameter functions as a reference type search parameter. The input is a reference to a GraphDefinition icon resource, which is used to define the graph of desired resources for inclusion.

By default, search results only include resources that are not contained in other resources. A However, chained condition will parameters SHOULD be evaluated inside contained resources. § 96 To illustrate this, consider a MedicationRequest resource (id: MedicationRequest/23 ) that has a contained Medication resource specifying a custom formulation that has ingredient with a an itemCodeableConcept "abc" in "http://acme.com./medications". "http://example.org/medications" (id: Medication/m1 ).

In this case, a the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/MedicationRequest?medication.ingredient-code=abc POST [base]/MedicationRequest/_search Content-Type: application/x-www-form-urlencoded medication.ingredient-code=abc

GET MedicationRequest?medication.ingredient-code=abc

will include MedicationRequest/23 in the MedicationRequest results as a match. The search chained into the contained resource in and met the results. However, this search: search criteria.

GET Medication?ingredient-code=abc

However, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Medication?ingredient-code=abc POST [base]/Medication/_search Content-Type: application/x-www-form-urlencoded ingredient-code=abc will not include find Medication/m1 - the medication is a contained Medication resource in the results, since within a MedicationRequest and not subject to search. This is because either the wrong type of resource would be returned, returned (the MedicationRequest containing the Medication), or the contained resource would be returned without its container resource, resource (just the Medication), which provides would be missing the required context to provided by the contained container resource.

Clients are able to can modify this the search behavior for contained resources using the _contained parameter, which can have one of the following values:

  • false (default): Do not search and return contained resources
  • true: true : search and return only contained resources
  • both: both : search and return both contained and non-contained (normal) resources

When contained resources are being returned, the server should can return either the container resource, or the contained resource alone. The client can specify which by using the _containedType parameter, which can have one of the following values:

  • container (default): Return the container resources
  • contained: contained : return only the contained resource

When returning a container resource, To return just the server simply puts this in contained Medication ( Medication/m1 ), the following search results: <Bundle> ... <entry> <resource> <MedicationRequest> <id value="23"> .... <contained> <Medication> <id value="m1"> ... </Medication> <contained> </MedicationRequest> </resource> <search> <mode value="match"/> </search> </entry> </Bundle> In could be used: Show as unencoded: HTTP GET | HTTP POST GET [base]/Medication?ingredient-code=abc&_contained=true&_containedType=contained POST [base]/Medication/_search Content-Type: application/x-www-form-urlencoded ingredient-code=abc&_contained=true&_containedType=contained This search would return a result bundle with the case of returning container resources, contained Medication records. Note that the server SHALL populate fullUrl of the entry.search.mode element, as shown, so that entry points to the client can pick apart matches containing resource first and includes (since the usual approach of doing it by type might not work). If the return type is required resolution for the contained resource, this must be done slightly differently: resource: Show as: FHIR+JSON | FHIR+XML { "resourceType": "Bundle", ... "entry": [{ "fullUrl": "http://example.com/fhir/MedicationRequest/23#m1", "resource": { "resourceType": "Medication", "id": "m1", ... }, "search": { "mode": "match" } }] } <Bundle> ... <entry> <fullUrl value="http://example.com/fhir/MedicationRequest/23#m1"/> <resource> <Medication> <id value="m1"> ... </Medication> </resource> <search> <mode value="match"/> </search> </entry> </Bundle>

<Bundle> ... <entry> <fullUrl value="http://example.com/fhir/MedicationRequest/23#m1"/> <resource> <Medication> <id value="m1"> ... </Medication> </resource> <search> <mode value="match"/> </search> </entry> </Bundle>

In this case, the fullUrl informs the client that this is a contained resource, along with indicating Similarly, the identity of search could be performed to return the MedicationRequests containing resource. the Medication records: Show as unencoded: HTTP GET 3.1.1.5.5 External References | HTTP POST If GET [base]/Medication?ingredient-code=abc&_contained=true&_containedType=container POST [base]/Medication/_search Content-Type: application/x-www-form-urlencoded ingredient-code=abc&_contained=true&_containedType=container This search would return a result bundle with the container _include MedicationRequest path selects a reference that refers to a resource on another server, records and the server can elect to include relevant contained resources. Note that resource in even though the search results request was for the convenience of the client. If the _include Medication path selects a reference that refers to an entity that is not a Resource, such as an image attachment, the server may also elect to include this in the returned results as a Binary resource. For example, the include path may point to an attachment which is by reference, like this: <content> <contentType>image/jpeg</contentType> <url>http://example.org/images/2343434/234234.jpg</url> </content> The server can retrieve the target of this reference, and add it to resources, the results for container MedicationRequest entries are categorized with the convenience mode of the client. match : Show as: FHIR+JSON | FHIR+XML { "resourceType": "Bundle", ... "entry": [{ "resource": { "resourceType": "MedicationRequest", "id": "23", ... "contained": [{ "resourceType": "Medication", "id": "m1", ... }], ... }, "search": { "mode": "match" } }] } <Bundle> ... <entry> <resource> <MedicationRequest> <id value="23"> ... <contained> <Medication> <id value="m1"> ... </Medication> <contained> </MedicationRequest> </resource> <search> <mode value="match"/> </search> </entry> </Bundle>

3.1.1.5.6

When returning paged results for a search with _include resources, all _include resources that are related to the primary resources returned for the page SHOULD also be returned as part of that same page, even if some of those resource instances have previously been returned on previous pages. § 97 This approach allows both sender and receiver to avoid caching results of other pages.

The client Search parameters can request be defined in either the server to return only core specification or externally (e.g., via Implementation Guides). The parameters defined in the core specification fall into a portion few categories, as listed below. Note that all search parameters defined in this specification are listed by the search parameter registry .

Note that if a 'base' SearchParameter defined by HL7 or an implementation guide (i.e., one that does not inherit from another SearchParameter definition) is referenced and the SearchParameter does not otherwise enumerate the modifiers and comparators, then all modifiers and prefixes that are permitted for that parameter's search type are expected to be supported. If an implementation wishes to restrict which modifiers they support, the implementation must define their own SearchParameter instance, which SHOULD inherit from the original definition. § 98 The definition of any locally-defined search parameters SHALL be available to clients, either as resources at the [base]/SearchParameter endpoint or as contained resources by using in the CapabilityStatement . § 99

The following parameters apply to all resources : _content , _filter , _has , _id , _in , _language , _lastUpdated , _list , _profile , _query , _security , _source , _tag , _type . Note that in addition to these search parameters, the search result parameters also apply to all resources.

The standard search parameter _summary : _content is used to allow searching all textual content of a resource.

GET [base]/ValueSet?_summary=true

The _summary _content search parameter requests is defined as a special type parameter. While the server actual format used by the parameter is implementation-dependant, the search is some form of string which can be used for advanced searching (similar to return _text ).

For example, the following search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_content=cancer OR metastases OR tumor POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _content=cancer OR metastases OR tumor is a subset search for Observations that contain any of the phrases "cancer", "metastases", and "tumor" anywhere in the resource. It can contain one For example, the key words may appear in:

  • Observation.text - Text summary of the following values: resource, for human interpretation
  • Observation.code.text - Type of observation, Plain text representation of the concept
  • Observation.note - Comments about the observation
  • etc.

The server may choose to search for related terms (e.g., "carcinoma", etc.), but is not required to do so.

More information can be found in the section Text Search Parameters .

true

The _has parameter provides limited support for reverse chaining - that is, selecting resources based on the properties of resources that refer to them. Details and examples can be found in the base definition Reverse Chaining section of the resource(s) (see ElementDefinition.isSummary search page.

)

The standard search parameter _id is used to allow searching based on the logical identifier of resources ( Resource.id ). The parameter requires a resource type specified in the search context - it can only be used in searches that contain a [type] component in the "text" element, search request.

The _id search parameter is defined as a token type parameter, with the 'id' element, restriction that only the 'meta' element, code segment is allowed (e.g., no vertical pipes). This means that the literal provided as search input is matched as a code instead of a string - e.g., exact match instead of case-insensitive starts-with.

For example, the following search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?_id=23 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _id=23 is a search for Patient records with a logical id of "23".

For information about the difference between performing a read operation and only top-level mandatory elements searching by identifier, see Searching Identifiers .

The standard search parameter _in is used to match resources against active membership in collection resources. Matching is performed against the Resource.id of the resource against the membership test of a collection resource (e.g., CareTeam, Group, List). Details about how each resource applies the active membership test can be found on the relevant resource pages:

The _in search parameter is defined as a count reference type parameter. The target of the matching resources, without returning the actual matches reference must be one of: CareTeam , Group , or List .

For example: Show as unencoded: HTTP GET | HTTP POST

Description false Search
Return all parts Any resource in a CareTeam, List, or Group with id "101" GET [base]/?_in=101 POST [base]/_search Content-Type: application/x-www-form-urlencoded _in=101
Conditions in List "102" GET [base]/Condition?_in=List/102 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded _in=List/102
Patients which are participants of CareTeam "103" GET [base]/Patient?_in=CareTeam/103 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _in=CareTeam/103
Encounters for Patients in Group "104" GET [base]/Encounter?patient._in=Group/104 POST [base]/Encounter/_search Content-Type: application/x-www-form-urlencoded patient._in=Group/104
Smooth muscle relaxant medications that are not in the resource(s) allergy list "105" GET [base]/Medication?code:below=http://snomed.info/sct|90000002&ingredient._in:not=List/105 POST [base]/Medication/_search Content-Type: application/x-www-form-urlencoded code:below=http://snomed.info/sct|90000002&ingredient._in:not=List/105

Note that inactive/excluded members are not considered 'in' the membership. If a full reference is required, chaining can be used to search all references.

For more information about membership testing, see Searching by Membership .

The intent standard search parameter _language is used to match resources based on the language of the resource used. Note that match testing is performed against the element _summary Resource.language and does not match against the actual language used in elements.

The _language search parameter is defined as a token type parameter. Resource.language is restricted to reduce the total processing load on server, client, Common Languages and All Languages .

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Questionnaire?_language=es POST [base]/Questionnaire/_search Content-Type: application/x-www-form-urlencoded _language=es will match Questionnaire resources between them such with a Resource.language of es (Spanish).

The standard search parameter _lastUpdated is used to match resources based on when the most recent change has been made.

The _lastUpdated search parameter is defined as a date type parameter. Matching is performed against the network. element Resource.meta.lastUpdated , or an implementation's internal equivalent.

Note that there may be situations where the returned data elements might change without any change to the lastUpdated element. For example, if a server returns a code value and its corresponding display by using a foreign-key reference to a code system, updates to the code system that affect the display name might not be reflected in the lastUpdated value of the resource holding the code. It is most useful also possible that an underlying record might be updated in a way that is not surfaced in the FHIR representation of a resource (e.g., changing non-exposed metadata) which can cause lastUpdated to change even when there is no apparent change in the data.

For example, the following search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_lastUpdated=gt2010-10-01 POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _lastUpdated=gt2010-10-01

is a search for Observations changed since October 1, 2010. Applications considering using this parameter should also consider defined synchronization approaches - RESTful history and Subscriptions framework .

The standard search parameter _list is used to test resources that against references in a List resource.

The _list search parameter is defined as a special type parameter. Input values are large, particularly ones that include images treated as token values - either the logical identifier (id) of a List or elements a literal for a functional list, as defined in Current Resource Lists . Note that when using functional lists, servers are not required to make the lists available to the clients as List resources, but may repeat many times. choose to do so.

For example: Show as unencoded: HTTP GET | HTTP POST

Description Search
Any resource referenced by List "101" GET [base]/?_list=101 POST [base]/_search Content-Type: application/x-www-form-urlencoded _list=101
Conditions referenced by List "102" GET [base]/Condition?_list=102 POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded _list=102
Female Patients referenced by List "103" GET [base]/Patient?_list=013&gender=female POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _list=013&gender=female
Encounters for Patients in Group "104" GET [base]/Encounter?patient._in=Group/104 POST [base]/Encounter/_search Content-Type: application/x-www-form-urlencoded patient._in=Group/104
Current allergy list for patient "42" GET [base]/AllergyIntolerance?patient=42&_list=\$current-allergies POST [base]/AllergyIntolerance/_search Content-Type: application/x-www-form-urlencoded patient=42&_list=\$current-allergies

For more information about membership testing, see Searching by Membership .

The purpose standard search parameter _profile is used to match resources based on values in the Resource.meta.profile element. Note that the profile search does not test conformance of a resource against any profile, just the summary form values of that element.

The _profile search parameter is to allow defined as a client reference type parameter.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_profile=http://hl7.org/fhir/StructureDefinition/bp POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _profile=http://hl7.org/fhir/StructureDefinition/bp will match Observation resources that contain a Resource.meta.profile of http://hl7.org/fhir/StructureDefinition/bp .

The standard search parameter _query is used to quickly retrieve execute a pre-defined and named query operation. Note that there can only ever be one _query parameter in a large set of resources, and let search parameters. Servers processing search requests SHALL refuse to process a user pick search request if they do not recognize the appropriate one. _query parameter value. § 100

The summary for an element _query search parameter is defined as a special type parameter. Input to allow the parameter is treated as a user token-based search, requiring an exact match to quickly sort and filter the query name, as defined by the OperationDefinition.code element.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?_query=current-high-risk&ward=1A POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _query=current-high-risk&ward=1A is a request to run the named query current-high-risk against Patient resources, and typically omit important content on with a parameter named ward set to the basis that value 1A . If a server does not have a definition for current-high-risk , it would reject the entire resource will request.

More information about named queries can be retrieved when found in the user selects a resource. section Named Queries .

Servers are not obliged The standard search parameter _security is used to return just match resources based on security labels in the Resource.meta.security element.

The _security search parameter is defined as a summary token type parameter.

For example, the search: Show as requested. There are only unencoded: HTTP GET | HTTP POST GET [base]/Observation?_security=http://terminology.hl7.org/CodeSystem/v3-Confidentiality|R POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _security=http://terminology.hl7.org/CodeSystem/v3-Confidentiality|R will match Observation resources that contain a limited number Resource.meta.security value matching the system http://terminology.hl7.org/CodeSystem/v3-Confidentiality and code of summary forms defined for R .

For more information about security labels, please see the Security Labels page.

The standard search parameter _source is used to match resources based on source information in order to allow servers to store the summarized form(s) in advance. Servers SHOULD mark Resource.meta.source element. Meta.source is a lightweight way of providing minimal provenance for resources. If more functionality is required, use of Provenance is recommended.

The _source search parameter is defined as a uri type parameter.

For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Patient?_source=http://example.com/Organization/123 POST [base]/Patient/_search Content-Type: application/x-www-form-urlencoded _source=http://example.com/Organization/123 will match Patient resources with that contain the tag SUBSETTED Resource.meta.source value of http://example.com/Organization/123 .

The standard search parameter _tag is used to ensure that match resources based on tag information in the incomplete resource is not acidentally Resource.meta.tag element. Tags are intended to be used to overwrite identify and relate resources to process and workflow.

The _tag search parameter is defined as a complete resource. token type parameter.

Note For example, the search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_tag=http://terminology.hl7.org/ValueSet/v3-SeverityObservation|H POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _tag=http://terminology.hl7.org/ValueSet/v3-SeverityObservation|H will match Observation resources that contain a tag value matching the system _include http://terminology.hl7.org/ValueSet/v3-SeverityObservation and code _revinclude parameters cannot be mixed H , indicating that an observation has been tagged as potentially life-threatening or with _summary=text . the potential cause permanent injury.

STU Note: There are open issues around The standard search parameter _text is used to perform searches against the definitions narrative content of a resource.

The _text search parameter is defined as a special type parameter. While the actual format used by the parameter is implementation-dependant, the search is some form of text which elements are in can be used for advanced searching.

For example, the summary following search: Show as unencoded: HTTP GET | HTTP POST GET [base]/Observation?_text=cancer OR metastases OR tumor POST [base]/Observation/_search Content-Type: application/x-www-form-urlencoded _text=cancer OR metastases OR tumor is a search for each resource. There are 2 kinds Observations that contain any of problems the phrases "cancer", "metastases", and "tumor" in their narrative text ( Observation.text ). For example, the existing definitions: key words may appear in:

  • Elements are marked as 'include in summary', but their parent element is not Observation.text - Text summary of the resource, for human interpretation
  • Elements have minimum cardinality > 0, but are not included in the summary (and their parent element is) Observation.code.text - so sumarised resources will not be schema valid Type of observation, Plain text representation of the concept

These issues will be resolved for FHIR Release 4. In the meantime, implementers The server may choose to override which elements are marked as 'included in summary', and implementations may vary. search for related terms (e.g., "carcinoma", etc.), but is not required to do so.

Feedback on which elements should More information can be found in the summaries is welcome here section Text Search Parameters .

If one The standard search parameter _type is used to allow filtering of types in searches that are performed across multiple resource types (e.g., searches across the summary views defined above server root).

The _type search parameter is not appropriate, a client can request defined as a specific set special type parameter, because there is no standard path expression for searching the types of elements be returned resources. However, the parameter is a token parameter restricted to the Resource Types Value Set.

For example, the following search: Show as part of unencoded: HTTP GET | HTTP POST GET [base]/?_type=Observation,Condition&patient=Patient/123 POST [base]/_search Content-Type: application/x-www-form-urlencoded _type=Observation,Condition&patient=Patient/123 is a resource using search for Observations and Conditions that are about the patient _elements Patient/123 . Since the patient parameter: GET [base]/Patient?_elements=identifier,active,link search parameter is valid on both the Observation and Condition resources, the search is valid. The same search would not be valid if the _elements _type parameter consists of was excluded, since patient is not a comma-separated list of base element names such as, elements defined at the root level search parameter that works across all resources.

More information can be found in the resource. Only elements that are listed are section Searching Multiple Resource Types .

In addition to be returned. Clients SHOULD list the common parameters defined for all mandatory resources, each FHIR resource type defines its own set of search parameters with their names, types, and modifier elements in a meanings. These search parameters are on the same page as the resource definitions, and are also published as part of the list of elements. The list of elements does standard Capability statement ( XML or JSON ).

In general, the defined search parameters correspond to a single element in the resource, but this is not apply required, and some search parameters refer to included the same type of element in multiple places, or refer to derived values.

Some search parameters defined by resources . are associated with more than one path in a resource. This means that the search parameter matches if any of the paths contain matching content. If a path matches, the whole resource is returned in the search results. The client may have to examine the resource to determine which path contains the match.

Servers are not obliged required to return just implement any of the requested elements. Servers SHOULD always return mandatory elements whether they are requested or not. Servers standard search parameters. However, servers SHOULD mark the resources with support the tag SUBSETTED _id to ensure parameter. § 101 Servers MAY also define their own search parameters. § 102

Note that all search parameters defined in this specification, both common and resource-specific, are listed in the incomplete resource is not actually used to overwrite a complete resource. search parameter registry .

Where a The special text search specifies a non-deterministic sort, parameters _text and _content search on the narrative of the resource and the entire content of the resource respectively. Just like string parameters using the :text modifier, the _text and _content parameters SHOULD support a sophisticated search algorithm may generate some kind functionality of ranking score to indicate which resources meet the specified criteria better than others. The server can return this score in entry.score : <entry> <score value=".45"/> <Patient> ... patient data ... </Patient> </entry> type offered by typical text indexing services. § 103 The score value of the parameter is a decimal number text-based search, which may involve searching multiple words with a value between (and including) 0 thesaurus and 1, where 1 is best match, proximity considerations, and 0 is least match. logical operations such as AND, OR etc. For example (note that the values are unescaped for clarity): Show as unencoded: HTTP GET | HTTP POST GET [base]/Condition?_text=(bone OR liver) AND metastases POST [base]/Condition/_search Content-Type: application/x-www-form-urlencoded _text=(bone OR liver) AND metastases

This request returns all Condition resources with the word "metastases" and either "bone" or "liver" in the narrative. The server may choose to search for related words as well.

Implementers could consider using the rules specified by the OData specification for the $ search parameter icon. Typical implementations would use Lucene, Solr, an SQL-based full text search, or some similar indexing service.

In order to allow the client to be confident about what search parameters were used as criteria by the server, the server SHALL return the parameters that were actually used to process the search. § 104 Applications processing search results SHALL check these returned values where necessary. § 105 For example, if the server did not support some of the filters specified in the search, a client might manually apply those filters to the retrieved result set, display a warning message to the user or take some other action.

In the case of a RESTful search, these parameters are encoded in the self link in the bundle that is returned: Show as: FHIR+JSON | FHIR+XML "link": { "relation": "self", "url": "http://example.org/Patient?name=peter" } <link> <relation value="self"/> <url value="http://example.org/Patient?name=peter"/> </link>

<link> <relation value="self"/> <url value="http://example.org/Patient?name=peter"/> </link>

In other respects, servers have considerable discretion with regards to supporting search:

  • Servers can choose which parameters to support (other than _id above).
  • Servers can choose when and where to implement parameter chaining, and when and where they support the _include parameter.
  • Servers are able to can declare additional parameters in the profiles referenced from their Capability statements. Servers should SHOULD define custom search parameters with codes starting with a "-" hyphen ("-") character to ensure that the names they choose do not clash with future parameters defined by this specification. § 106
  • Servers are not required to enforce case sensitivity on parameter names, though the names are case sensitive (and URLs are generally case-sensitive).
  • Servers may can choose how many results to return, though the client can use _count as above to limit.
  • Servers can choose how to sort the return results, though they SHOULD honor the _sort parameter. § 107 3.1.1.7 Advanced Search The search framework described above is a useful framework for providing a simple search based on indexed criteria, but more sophisticated query capability is needed to handle precise queries, complex decision support based requests, and direct queries that have human resolution. More advanced search operations are specified by the _query parameter: GET [base]/Patient?_query=name&parameters... The _query parameter names a custom search profile that describes a specific query operation. The named query may define additional named parameters that are used with that particular named query. Servers can define their own additional named queries to meet their own uses using an OperationDefinition . There can only ever be one _query parameter in a set of search parameters. Servers processing search requests SHALL refuse to process a search request if they do not recognize the _query parameter value.

The results of a search operation are only guaranteed to be current at the moment instant the operation is executed. After the operation is executed, ongoing actions performed on the resources against which the search was executed will render the results increasingly stale. The significance of this depends on the nature of the search, and the kind of use that is being made of the results.

This is particularly relevant when the server is returning the results in a series of pages. It is at the discretion of the search engine of how to handle ongoing updates to the resources while the search is proceeding.

Note: Performing a search operation does not change the set of resources on the server, with the possible exception of the creation of Audit Event resources auditing the search itself.

Conformance Statement Summary

  • § 0 Servers SHALL declare what features of search they require through their CapabilityStatement search declarations
  • § 1 Implementers SHOULD review the safety checklist .
  • § 2 Clients and servers SHOULD be robust in their handling of URLs present in the content of FHIR bundles, such as in Bundle.link.url .
  • § 3 Clients SHOULD use correct case, and servers SHALL NOT define additional parameters with different meanings with names that only differ in case.
  • § 4 In the absence of any search filters, e.g., GET [base] , GET [base]/Patient , or POST [base]/_search or POST [base]/Patient/_search with no body, a server SHOULD return all records in scope of the search context.
  • § 5 Servers MAY reject a search as overly-broad, and SHOULD return an appropriate error in that situation (e.g., too-costly ).
  • § 6 Note that if the _type parameter is included, all other search parameters SHALL be common to all provided types, and if _type is not included, all parameters SHALL be common to all resource types.
  • § 7 In order to allow the client to be confident about what search parameters were used as criteria by a server, servers SHALL return the parameters that were actually used to process a search.
  • § 8 Applications processing search results SHALL check these returned values where necessary.
  • § 9 Self links SHALL be expressed as an HTTP GET-based search with the relevant parameters included as query parameters, because of the semantics around the link types.
  • § 10 Self links MAY be returned as absolute URIs or URIs relative to the base URL of a server and MAY or MAY NOT be resolvable.
  • § 11 Clients SHALL review the returned parameters in the self link to ensure proper processing of results.
  • § 12 In those situations, clients SHOULD filter received records to account for additional data.
  • § 13 Servers MAY include such filters in the self link.
  • § 14 Clients SHOULD be able to handle search parameters in a self link that they did not request.
  • § 15 Servers SHOULD consider whether exposing search parameters in the self link would constitute inappropriate leakage of security information.
  • § 16 As with the self link, all relevant paging links SHALL be expressed as GET requests.
  • § 17 Servers SHOULD NOT include content that is considered sensitive in URLs, excluding the self link.
  • § 18 If a server is unable to execute a search request, it MAY either return an error for the request or return success with an outcome containing details of the error.
  • § 19 When the search fails, a server SHOULD return an OperationOutcome detailing the cause of the failure.
  • § 20 Where the content of the parameter is syntactically incorrect, servers SHOULD return an error.
  • § 21 However, where the issue is a logical condition (e.g., unknown subject or code), the server SHOULD process the search, including processing the parameter - with the result of returning an empty search set, since the parameter cannot be satisfied.
  • § 22 In general, servers SHOULD ignore unknown or unsupported parameters for the following reasons:
  • § 23 Servers SHOULD honor the client's prefer request, but are not required to do so.
  • § 24 This SHOULD only occur in situations where it is known that some filters haven't been applied.
  • § 25 Servers MAY support batching multiple requests.
  • § 26 When requesting searches in a bundle, systems SHOULD accept searches via GET, even if they do not typically accept GET-based searches.
  • § 27 Servers receiving searches within a Bundle SHOULD NOT impose any GET-specific limitations on search (i.e., restrictions not imposed on POST-based searches) that they would impose if the GET-based search had been received outside a Bundle.
  • § 28 Servers MAY support FHIR Messaging .
  • § 29 Individual search parameters MAY also allow "modifiers" that control their behavior.
  • § 30 A search parameter MAY instead explicitly choose elements by using an expression that instead points directly to the sub-elements.
  • § 31 Search parameter definitions MAY include a list of allowed modifiers in the SearchParameter.modifier element, which is bound to the search-modifier-code value set.
  • § 32 Servers SHALL support any modifiers present in search parameters the server advertises support for.
  • § 33 Servers MAY choose to support additional modifiers.
  • § 34 Note that servers MAY support modifiers on types not defined in this specification.
  • § 35 Since modifiers change the meaning of a search parameter, a server SHALL reject any search request that contains a search parameter with an unsupported modifier.
  • § 36 The definition for any search parameter of type "special" SHALL explicitly list any allowed modifiers; this list MAY include any value from the search-modifier-code code system.
  • § 37 Version-related search criteria against resources with unknown versioning schemes SHALL be either ignored or rejected.
  • § 38 Version-related search criteria against resources with unknown versioning schemes SHALL be either ignored or rejected.
  • § 39 Implementers of the text modifier SHOULD support a sophisticated search functionality of the type offered by typical text indexing services.
  • § 40 Implementers of the text-advanced modifier SHOULD support a sophisticated search functionality of the type offered by typical text indexing services, but MAY support only basic search with minor additions (e.g., word-boundary recognition).
  • § 41 If a reference resolves to a type different than indicated or expected, a server SHOULD consider if it is appropriate to include the issue via an OperationOutcome in the response.
  • § 42 The date parameter format is yyyy-mm-ddThh:mm:ss.ssss[Z|(+|-)hh:mm] (the standard XML format). Note that fractional seconds MAY be ignored by servers.
  • § 43 Any degree of precision can be provided, but it SHALL be populated from the left (e.g., can't specify a month without a year), except that the minutes SHALL be present if an hour is present, and you SHOULD provide a timezone if the time part is present.
  • § 44 Note: Time can consist of hours and minutes with no seconds, unlike the XML Schema dateTime type. Some user agents may escape the : characters in the URL, and servers SHALL handle this correctly.
  • § 45 Where possible, the system SHOULD correct for timezones when performing queries.
  • § 46 Dates do not have timezones, and timezones SHOULD NOT be considered.
  • § 47 Where both search parameters and resource element date-times do not have timezones, the servers local timezone SHOULD be assumed.
  • § 48 If a reference value is a non-versioned relative reference (e.g., does not contain [url] or _history/[version] parts), the search SHOULD match instances that match the reference in it contains a versioned reference.
  • § 49 Servers SHOULD fail a search where the logical id in a reference refers to more than one matching resource across different types.
  • § 50 Punctuation and non-significant whitespace (e.g., repeated space characters, tab vs space) SHOULD also be ignored.
  • § 51 When a string type search parameter points to a complex or backbone element (an element that contains sub-elements), by default the search SHOULD be considered as a search against one or more string values in sub-elements, as selected by the implementation.
  • § 52 A search parameter MAY explicitly choose elements by using an expression that instead points directly to the sub-elements.
  • § 53 For robust search, servers SHOULD search the parts of a family name independently.
  • § 54 HL7 affiliates MAY make more specific recommendations about search expectations regarding names in their specific culture.
  • § 55 When in doubt, servers SHOULD treat tokens in a case-insensitive manner, on the grounds that including undesired data has less safety implications than excluding desired behavior.
  • § 56 Clients SHOULD always use the correct case when possible, and allow for the server to perform case-insensitive matching.
  • § 57 For token parameters on elements of type id , ContactPoint , uri , or boolean , the pipe symbol SHALL NOT be used - only the [parameter]=[code] form is allowed
  • § 58 Composite search parameters SHALL NOT declare components that reference other composite search parameters.
  • § 59 Where a search does not act on the referenced version, search results SHOULD contain a OperationOutcome with a warning that indicates the discrepancy.
  • § 60 If a resource has a reference that is versioned and the resource is included (e.g., _include , _revinclude ), the specified version SHOULD be provided.
  • § 61 For canonical references, servers SHOULD support searching by Canonical URLs, and SHOULD support automatically detecting a |[version] portion as part of the search parameter and interpreting that portion as a search on the business version of the target resource.
  • § 62 If a reference resolves to a type different than allowed via the reference, a server SHOULD consider if it is appropriate to include the issue via an OperationOutcome in the response.
  • § 63 Servers SHOULD fail a search where the logical id of a reference refers to more than one matching resource across different types.
  • § 64 If a request references multiple parameters that are not the same type (e.g., if one parameter is a number type and another is a token type, despite sharing the same name), this is an error and servers SHOULD return a 400 status.
  • § 65 Implementation Guides MAY set specific expectations about search behavior around implicit resources.
  • § 66 Named-query operations SHOULD NOT be invoked via any method other than search with the _query parameter (e.g., servers SHOULD NOT execute query operations via [base]/$[operation code] or [base]/[type]/$[operation code] , etc.).
  • § 67 Clients SHOULD NOT assume the availability of any search parameter that is not supported for general queries (i.e., listed in the server's CapabilityStatement , either in CapabilityStatement.rest.searchParam or CapabilityStatement.rest.resource.searchParam ).
  • § 68 Servers MAY further document the search parameters they support for a specific query operation - either in text or by defining a constrained operation based on the original that explicitly enumerates all supported parameters.
  • § 69 In order to ensure consistent behavior, authors SHOULD include relevant search parameters in the named query definition ( OperationDefinition ).
  • § 70 Note that servers SHOULD accept query parameters that are not enumerated in named queries based on their standard support (e.g., parameters that are supported for a given resource type), but servers MAY choose to ignore parameters not specified by the OperationDefinition.
  • § 71 Note that query parameters are unordered, so parameters to a named query MAY appear in any location or sequence.
  • § 72 The specification (or Implementation Guide) that defines an additional resource SHOULD define a set of standard search parameters for that resource
  • § 73 Note that with the exception of _include and _revinclude , search result parameters SHOULD only appear once in a search. If such a parameter appears more than once, the behavior is undefined and a server MAY treat the situation as an error.
  • § 74 When sorting on string search parameters, sorting SHOULD be performed on a case-insensitive basis.
  • § 75 Servers MAY or MAY NOT support the text sort modifier behavior, and MAY fall back to token-based sorting or disregard the value.
  • § 76 Servers SHALL NOT return more resources in a single page than requested, even if they don't support paging, but MAY return less than the client requested.
  • § 77 NOTE: This means that all servers that support search or history SHALL support checking the _count parameter.
  • § 78 The server SHOULD ensure that any pages reachable via links (e.g., previous/next) respect the the original requested _count expectations (or a server-overridden max page size).
  • § 79 If _count has the value 0 (zero), this SHALL be treated the same as _summary=count : the server returns a bundle that reports the total number of resources that match in Bundle.total , but with no entries, and no previous/next/last links.
  • § 80 If supported, a server SHOULD NOT return more resources than requested.
  • § 81 As with other parameters, servers supporting _maxresults SHALL include this parameter in the Self Link when returning results if it is used.
  • § 82 This subset SHOULD consist solely of all supported elements that are marked as "summary" in the base definition of the resource(s) (see ElementDefinition.isSummary ).
  • § 83 Return only the text , id , meta , and top-level mandatory elements (these mandatory elements are included to ensure that the payload is valid FHIR; servers MAY omit elements within these sub-trees as long as they ensure that the payload is valid).
  • § 84 Servers MAY return extensions in summary mode, but clients SHOULD NOT rely on extensions being present and SHOULD use another search mode if data contained in extensions is required.
  • § 85 Servers SHOULD mark the by populating meta.tag resources with the code SUBSETTED icon to ensure that the incomplete resource is not accidentally used to overwrite a complete resource.
  • § 86 Note that the self link in the search result Bundle is important for the interpretation of the result and SHALL always be returned, regardless of the type of _summary .
  • § 87 Each element name SHALL be the base element name without specifying [x] or one of the types (e.g., "value" is valid, while "value[x]" and "valueQuantity" are not).
  • § 88 Clients SHOULD list all mandatory and modifier elements in a resource as part of the list of elements.
  • § 89 Servers SHOULD return mandatory and modifier elements whether they are requested or not.
  • § 90 Servers SHOULD mark the resources with the tag SUBSETTED icon to ensure that the incomplete resource is not actually used to overwrite a complete resource.
  • § 91 If a client supplies _elements values prefixed with resource types, such as _elements=Patient.gender , then servers SHOULD apply these element-level restrictions to all resources in the returned bundle, rather than just to direct search matches (i.e., restrictions should be applied to bundle entries with any search.mode).
  • § 92 Note that implementers intending to support wildcard ( * ) segments SHOULD advertise them along with other resources and search parameters in their capability statement (e.g., in CapabilityStatement.rest.resource.searchInclude ).
  • § 93 Servers SHOULD resolve _include and _revinclude requests for version-specific references by resolving the version named in the reference.
  • § 94 When search results are paged, each page of search results SHOULD include the matching includes for the resources in each page, so that each page stands alone as a coherent package.
  • § 95 Servers that support canonical resolution in includes SHOULD advertise this capability by listing the relevant search parameters in CapabilityStatement.rest.resource.searchInclude and .revInclude.
  • § 96 However, chained parameters SHOULD be evaluated inside contained resources.
  • § 97 When returning paged results for a search with _include resources, all _include resources that are related to the primary resources returned for the page SHOULD also be returned as part of that same page, even if some of those resource instances have previously been returned on previous pages.
  • § 98 If an implementation wishes to restrict which modifiers they support, the implementation must define their own SearchParameter instance, which SHOULD inherit from the original definition.
  • § 99 The definition of any locally-defined search parameters SHALL be available to clients, either as resources at the [base]/SearchParameter endpoint or as contained resources in the CapabilityStatement .
  • § 100 Servers processing search requests SHALL refuse to process a search request if they do not recognize the _query parameter value.
  • § 101 However, servers SHOULD support the _id parameter.
  • § 102 Servers MAY also define their own search parameters.
  • § 103 Just like string parameters using the :text modifier, the _text and _content parameters SHOULD support a sophisticated search functionality of the type offered by typical text indexing services.
  • § 104 In order to allow the client to be confident about what search parameters were used as criteria by the server, the server SHALL return the parameters that were actually used to process the search.
  • § 105 Applications processing search results SHALL check these returned values where necessary.
  • § 106 Servers SHOULD define custom search parameters with codes starting with a hyphen ("-") character to ensure that the names they choose do not clash with future parameters defined by this specification.
  • § 107 Servers can choose how to sort the return results, though they SHOULD honor the _sort parameter.
Common Parameters defined for all resources:
Name Type Description Paths
_id _content string Text search against the entire resource
_filter special Filter search parameter which supports a more sophisticated grammar for searching
_has special Provides limited support for reverse chaining
_id token Resource id (not a full URL) Resource.id
_in reference Group, List, or CareTeam membership Resource.id
_lastUpdated _language token Language of the resource content Resource.language
_lastUpdated date Date last updated. Server has discretion on the boundary precision Resource.meta.lastUpdated
_tag _list token string Search by All resources in nominated list (by id, not a resource tag full URL) Resource.meta.tag
_profile uri reference Search for all resources tagged with a profile Resource.meta.profile
_security _query token string Search by a security label Custom named query Resource.meta.security
_text _security string token Text search against the narrative Search by a security label Resource.meta.security
_content _source string uri Text search against Search by where the entire resource comes from Resource.meta.source
_list _tag string token All resources in nominated list (by id, not Search by a full URL) resource tag Resource.meta.tag
_query _text string Custom named query Text search against the narrative
Search Control Parameters:
Name Type Description Allowable Content
_sort _contained string Order Whether to sort results return resources contained in (can repeat for inner sort orders) other resources in the search matches true | false | both ( false is default)
_containedType string Name of a valid search parameter If returning contained resources, whether to return the contained or container resources container | contained
_count number Number of results per page Whole number
_include _elements token Request that only a specific set of elements be returned for resources
_graph reference Include related resources according to a GraphDefinition
_include string Other resources to include in the search results that search matches point to SourceType:searchParam(:targetType)
_revinclude _maxresults number Hint to a server that only the first 'n' results will ever be processed Whole number
_revinclude string Other resources to include in the search results when they refer to search matches SourceType:searchParam(:targetType)
_summary _score string token Just return the summary elements (for resources where this is defined) Request match relevance in results true | false ( false is default)
_contained _sort string Whether Order to return resources contained in other resources sort results in the (can repeat for inner sort orders) Name of a valid search matches parameter
true _summary | string Just return the summary elements (for resources where this is defined) false true | both false ( false is default)
_containedType _total string token If returning contained resources, whether to return Request a precision of the contained or container resources total number of results for a request container none | contained estimate | accurate

Cross-map between search parameter types and Data types: Datatypes:

Data Type Datatype number date string reference token quantity reference uri quantity string uri token
Primitive Types
base64Binary Not used in search
boolean N N N N N N Y . true|false (System = http://hl7.org/fhir/special-values http://terminology.hl7.org/CodeSystem/special-values but not usually needed)
canonical N N Y N Y N Y
code N N N N N N Y . (System, if desired, is defined in the underlying value set for eeach each code)
date N Y N N N N N
date dateTime N Y N N N N N
dateTime decimal N Y Y N N N N N N
decimal id Y N N N N N N N Y
instant N Y N N N N N
integer Y N N N N N N
markdown Not used in search
oid Not used in search (but see uri)
positiveInt Not used in search (but see integer)
string N N Y N Y N N N Y Y
time Not used in search
unsignedInt Not used in search (but see integer)
uri N N N Y N Y N Y N
url Not used in search (but see uri)
uuid Not used in search (but see uri)
Datatypes
Address N N Y N search on any string element in the address N N N Y search on any string element in the address N
Annotation Age N N N N Y N N N
Annotation Not used in search
Attachment Not used in search
CodeableConcept N N N Y N N N N Y
CodeableReference Not used in search (searches either refer to .concept or .reference)
Coding N N N Y N N N N Y
Count Not used in search
ContactPoint N N N Y N N N N Y
Distance Not used in search
Duration N N N N Y N Y N N
HumanName N N Y N Search on any string element in the name N N N Y Search on any string element in the name N
Identifier N N N Y N N N N Y
Period Money N Y N N N Y N N N
Quantity Period N N Y N N N Y N N
Range Quantity N N N N Y N N N
Reference Range N N N N Y Y N N N
SampledData Ratio Not used in search
N Reference N N Y N N N N
SampledData Not used in search
Signature Not used in search
Timing N Y N N N N N