This page is part of the FHIR Specification (v0.5.0: DSTU 2 Ballot 2). The current version which supercedes this version is 5.0.0.  For a full list of available versions, see the Directory of published versions  . Page versions: R5 R4B R4 R3 R2
. Page versions: R5 R4B R4 R3 R2


The _filter parameter is a parameter that can be used with the Search Operation. It uses the same set of standard parameters defined for the resources, and provides a syntax for expressing a set of query expressions on the underlying resources.
Here's some example filters:
The _filter syntax has the following features:
Note that the only difference between a "string" value and a "token" value is that a string can contain spaces and ) and ]. There is otherwise no significant difference between them.
This is the formal grammar for the syntax:
filter       = paramExp / logExp / ("not") "(" filter ")"
logExp       = filter ("and" / "or" filter)+
paramExp     = paramPath SP compareOp SP compValue
compareOp    = (see table below)
compValue    = string / numberOrDate / token
string       = json string
token        = any sequence of non-whitespace characters (by Unicode rules) except "]" and ")"
paramPath    = paramName (("[" filter "]") "." paramPath)
paramName    = ALPHA (nameChar)*
nameChar     = "_" / "-" / DIGIT / ALPHA
numberOrDate = DIGIT (DateChar)*
dateChar     = DIGIT / "T" / "-" / "." / "+"
Notes about using the syntax:

This table summarises the comparison operations available:
| Operation | Definition | 
| eq | an item in the set has an equal value | 
| ne | An item in the set has an unequal value | 
| co | An item in the set contains this value | 
| sw | An item in the set starts with this value | 
| ew | An item in the set ends with this value | 
| gt / lt / ge / le | A value in the set is (greater than, less than, greater or equal, less or equal) the given value | 
| pr | The set is empty or not (value is false or true) | 
| po | True if a (implied) date period in the set overlaps with the implied period in the value | 
| ss | True if the value subsumes a concept in the set | 
| sb | True if the value is subsumed by a concept in the set | 
| in | True if one of the concepts is in the nominated value set by URI, either a relative, literal or logical vs | 
| ni | True if none of the concepts are in the nominated value set by URI, either a relative, literal or logical vs | 
| re | True if one of the references in set points to the given URL | 
The interpretation of the operation depends on the type of the search parameter it is being evaulated against. This table contains those details:
| Operation | String | Number | Date | Token | Reference | Quantity | 
| Eq | Character sequence is the same (case insensitive) | Number is the same incl same precision | Date is the same including same precision and timezone if provided | Token is the same, including namespace if specified (case insensitive) | n/a | Unit and value are the same | 
| Ne | (same) | |||||
| Co | Character sequence matches somewhere (case insensitive) | An item in the set's implicit imprecision includes the stated value | An item in the set's implicit period includes the stated value | n/a | n/a | n/a? | 
| Sw | Character sequence matches from first digit (left most, when L->R) (case insensitive) | n/a | n/a | n/a | n/a | n/a | 
| ew | Character sequence matches up to last digit (right most, when L->R) (case insensitive) | n/a | n/a | n/a | n/a | n/a | 
| gt / lt / ge / le | Based on Integer comparison of Unicode code points of starting character (trimmed) (case insensitive) | Based on numerical comparison | Based on date period comparison per 2.2.2.3 | n/a | n/a | Based on numerical comparison if units are the same (or are canonicalised) | 
| pr | ||||||
| po | n/a | n/a | Based on date period comparison per 2.2.2.3 | n/a | n/a | |
| ss | n/a | n/a | n/a | Based on logical subsumption; potentially catering for mapping between tx | n/a | n/a | 
| sb | n/a | n/a | n/a | Based on logical subsumption; potentially catering for mapping between tx | n/a | n/a | 
| in | n/a | n/a | n/a | Based on logical subsumption; potentially catering for mapping between tx | n/a | n/a | 
| re | n/a | n/a | n/a | n/a | Relative or absolute url | n/a | 
Notes:

Some additional parameters are defined for the filter parameter (to do: move these into the standard parameters):
| Resource Type | Parameter Name | Children | 
| Observation | related | target = related-target Type = related-type | 
| Group | characteristic | value = value code = characteristic | 
| DocumentReference | relatesTo | code = relation target = relatesTo | 
| DiagnosticOrder | event | status = event-status | 
| DiagnosticOrder | item | status = item-status code = item-code site = bodysite event = item-event | 
| DiagnosticOrder | item-event | status = item-past-status | 
Explanation: