FHIR © HL7.org  |  Server Home  |  Health Intersections FHIR Server v1.0.287  |  FHIR Version 4.0.0  | User: ANONYMOUS (Unknown)  

Resource "Observation-lastn" Version "1" (OperationDefinition)

Tags:

XML or JSON representation . provenance for this resource

Last N Observations Query

OPERATION: Last N Observations Query

The official URL for this operation definition is:

http://hl7.org/fhir/OperationDefinition/Observation-lastn

The lastn query meets the common need for searching for the most recent or last n=number of observations for a subject. For example, retrieving the last 5 temperatures for a patient to view trends or fetching the most recent laboratory results or vitals signs. To ask a server to return the last n=number of observations, the lastn query uses the normal search parameters defined for the Observation resource. However, rather than their normal use, they are interpreted as inputs - i.e.. instead of requiring that the resources literally contain the search parameters, they are passed to a server algorithm of some kind that uses them to determine the most appropriate matches.

The request for a lastn query SHALL include:

  • A $lastn operation parameter
  • A subject using either the patient or subject search parameter
  • A category parameter and/or a search parameter that contains a code element in its FHIRpath expression. ( e.g., code or code-value-concept)

The request for a lastn query MAY include:

  • Other Observation search parameters and modifiers

The response from a lastn query is a set of observations:

  • Filtered by additional parameters
    • If not explicitly filtered by status then will include statuses of 'entered-in-error'
  • 'GROUP BY' Observation.code
    • Codes SHALL be considered equivalent if the coding.value and coding.system are the same.
    • Text only codes SHALL be treated and grouped based on the text.
    • For codes with translations (multiple codings), the code translations are assumed to be equal and the grouping by code SHALL follow the transitive property of equality.

for example:

Observation.code for observation a Observation.code for observation b Observation.code for observation c number of groups [codes/text in each group]
a b c 3 [a],[b],[c]
a b a,c 2 [a.c],[b]
a b a,b 1 [a,b]
'textM' 'Text' 't e x t' 3 ['text'],['Text'],['t e x t']
  • Sorted from most recent to the oldest
  • Limited to the number of requested responses per group specified by the optional max query parameter
    • In case of a tie - when the effective times for >1 Observations are equal - both will be returned. Therefore, more Observations may be returned than is specified in max. For example, 4 Observations instead of 3 if the 3rd and 4th most recent observation had the same effective time.
  • If no maximum number is given then only the most recent Observation in each group is returned.

The set of returned observations should represent distinct real world observations and not the same observation with changes in status or versions. If there are no matches, the lastn query SHALL return an empty search set with no error, but may include an operation outcome with further advice.

URL: [base]/Observation/$lastn

Parameters

Use Name Cardinality Type Binding Documentation
IN max 0..1 positiveInt

max is an optional input parameter to the lastn query operation. It is used to specify the maximum number of Observations to return from each group. For example for the query "Fetch the last 3 results for all vitals for a patient" max = 3.

OUT return 1..1 Bundle

The set of most recent N Observations that match the lastn query search criteria.

The key differences between this query operation and simply searching Observation using the combination of _count and _sort parameters are:

  • The lastn query returns only the last N resource grouped by code. Using the _count query method doesn't restrict the total matches so you may need to page through several "A" Observations before getting to Observation "B".
  • The server is responsible for grouping the observations by codes. This frees the client from needing to determine which codes she should ask for.

This operation cannot be performed on observations that the user is not authorized to see. It is assumed that the server has identified and secured the context appropriately, and can either associate the authorization context with a single patient, or determine whether the context has the rights to the nominated patient, if there is one. If there is no nominated patient (e.g. the operation is invoked at the system level) and the context is not associated with a single patient record, then the server should return an error. Specifying the relationship between the context, a user and patient records is outside the scope of this specification.


{
  "resourceType" : "OperationDefinition",
  "id" : "Observation-lastn",
  "meta" : {
    "versionId" : "1",
    "lastUpdated" : "2018-12-14T02:02:44.160Z"
  },
  "text" : {
    "status" : "generated",
    "div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n <h2>Last N Observations Query</h2>\n <p>OPERATION: Last N Observations Query</p>\n <p>The official URL for this operation definition is: </p>\n <pre>http://hl7.org/fhir/OperationDefinition/Observation-lastn</pre>\n <div>\n <p>The \n <em>lastn query</em> meets the common need for searching for the most recent or last n=number of observations for a subject. For example, retrieving the last 5 temperatures for a patient to view trends or fetching the most recent laboratory results or vitals signs. To ask a server to return the last n=number of observations, the \n <em>lastn</em> query uses the \n <a href=\"observation.html#search\">normal search parameters</a> defined for the Observation resource. However, rather than their normal use, they are interpreted as inputs - i.e.. instead of requiring that the resources literally contain the search parameters, they are passed to a server algorithm of some kind that uses them to determine the most appropriate matches.\n </p>\n\n <p>The request for a lastn query SHALL include:</p>\n\n <ul>\n\n <li>A \n <code>$lastn</code> operation parameter\n </li>\n\n <li>A subject using either the \n <code>patient</code> or \n <code>subject</code> search parameter\n </li>\n\n <li>A \n <code>category</code> parameter and/or a search parameter that contains a code element in its FHIRpath expression. ( e.g., \n <code>code</code> or \n <code>code-value-concept</code>)\n </li>\n\n </ul>\n\n <p>The request for a lastn query MAY include:</p>\n\n <ul>\n\n <li>Other Observation search parameters and modifiers</li>\n\n </ul>\n\n <p>The response from a lastn query is a set of observations:</p>\n\n <ul>\n\n <li>Filtered by additional parameters\n\n <ul>\n\n <li>If not explicitly filtered by status then will include statuses of 'entered-in-error'</li>\n\n </ul>\n\n </li>\n\n <li>'GROUP BY' \n <code>Observation.code</code>\n\n <ul>\n\n <li>Codes SHALL be considered equivalent if the \n <code>coding.value</code> \n <em>and</em> \n <code>coding.system</code> are the same.\n </li>\n\n <li>Text only codes SHALL be treated and grouped based on the text.</li>\n\n <li>For codes with translations (multiple codings), the code translations are assumed to be equal and the grouping by code SHALL follow the transitive property of equality.</li>\n\n </ul>\n\n </li>\n\n </ul>\n\n <p>for example:</p>\n\n <table class=\"grid\">\n\n <thead>\n\n <tr>\n <th>Observation.code for observation a</th>\n <th>Observation.code for observation b</th>\n <th>Observation.code for observation c</th>\n <th>number of groups [codes/text in each group]</th>\n </tr>\n\n </thead>\n\n <tbody>\n\n <tr>\n <td>a</td>\n <td>b</td>\n <td>c</td>\n <td>3 [a],[b],[c]</td>\n </tr>\n\n <tr>\n <td>a</td>\n <td>b</td>\n <td>a,c</td>\n <td>2 [a.c],[b]</td>\n </tr>\n\n <tr>\n <td>a</td>\n <td>b</td>\n <td>a,b</td>\n <td>1 [a,b]</td>\n </tr>\n\n <tr>\n <td>'textM'</td>\n <td>'Text'</td>\n <td>'t e x t'</td>\n <td>3 ['text'],['Text'],['t e x t']</td>\n </tr>\n\n </tbody>\n\n </table>\n\n <ul>\n\n <li>Sorted from most recent to the oldest</li>\n\n <li>Limited to the number of requested responses per group specified by the optional \n <em>max</em> query parameter\n\n <ul>\n\n <li>In case of a tie - when the effective times for &gt;1 Observations are equal - both will be returned. Therefore, more Observations may be returned than is specified in \n <em>max</em>. For example, 4 Observations instead of 3 if the 3rd and 4th most recent observation had the same effective time.\n </li>\n\n </ul>\n\n </li>\n\n <li>If no maximum number is given then only the most recent Observation in each group is returned.</li>\n\n </ul>\n\n <p>The set of returned observations should represent distinct real world observations and not the same observation with changes in status or versions. If there are no matches, the \n <em>lastn</em> query SHALL return an empty search set with no error, but may include an operation outcome with further advice.\n </p>\n\n </div>\n <p>URL: [base]/Observation/$lastn</p>\n <p>Parameters</p>\n <table class=\"grid\">\n <tr>\n <td>\n <b>Use</b>\n </td>\n <td>\n <b>Name</b>\n </td>\n <td>\n <b>Cardinality</b>\n </td>\n <td>\n <b>Type</b>\n </td>\n <td>\n <b>Binding</b>\n </td>\n <td>\n <b>Documentation</b>\n </td>\n </tr>\n <tr>\n <td>IN</td>\n <td>max</td>\n <td>0..1</td>\n <td>\n <a href=\"datatypes.html#positiveInt\">positiveInt</a>\n </td>\n <td/>\n <td>\n <div>\n <p>\n <code>max</code> is an optional input parameter to the \n <em>lastn</em> query operation. It is used to specify the maximum number of Observations to return from each group. For example for the query \"Fetch the last 3 results for all vitals for a patient\" \n <code>max</code> = 3.\n </p>\n\n </div>\n </td>\n </tr>\n <tr>\n <td>OUT</td>\n <td>return</td>\n <td>1..1</td>\n <td>\n <a href=\"bundle.html\">Bundle</a>\n </td>\n <td/>\n <td>\n <div>\n <p>The set of most recent N Observations that match the \n <em>lastn</em> query search criteria.\n </p>\n\n </div>\n </td>\n </tr>\n </table>\n <div>\n <p>The key differences between this query operation and simply searching Observation using the combination of \n <code>_count</code> and \n <code>_sort</code> parameters are:\n </p>\n\n <ul>\n\n <li>The \n <em>lastn</em> query returns \n <strong>only</strong> the last N resource grouped by code. Using the _count query method doesn't restrict the total matches so you may need to page through several \"A\" Observations before getting to Observation \"B\".\n </li>\n\n <li>The server is responsible for grouping the observations by codes. This frees the client from needing to determine which codes she should ask for.</li>\n\n </ul>\n\n <p>This operation cannot be performed on observations that the user is not authorized to see. It is assumed that the server has identified and secured the context appropriately, and can either associate the authorization context with a single patient, or determine whether the context has the rights to the nominated patient, if there is one. If there is no nominated patient (e.g. the operation is invoked at the system level) and the context is not associated with a single patient record, then the server should return an error. Specifying the relationship between the context, a user and patient records is outside the scope of this specification.</p>\n\n </div>\n </div>"
  },
  "extension" : [
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm",
      "valueInteger" : 3
    },
    {
      "url" : "http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status",
      "valueCode" : "trial-use"
    }
  ],
  "url" : "http://hl7.org/fhir/OperationDefinition/Observation-lastn",
  "version" : "4.0.0",
  "name" : "Last N Observations Query",
  "status" : "draft",
  "kind" : "operation",
  "date" : "2018-12-14T01:14:32+00:00",
  "publisher" : "HL7 (FHIR Project)",
  "contact" : [
    {
      "telecom" : [
        {
          "system" : "url",
          "value" : "http://hl7.org/fhir"
        },
        {
          "system" : "email",
          "value" : "fhir@lists.hl7.org"
        }
      ]
    }
  ],
  "description" : "The *lastn query* meets the common need for searching for the most recent or last n=number of observations for a subject. For example, retrieving the last 5 temperatures for a patient to view trends or fetching the most recent laboratory results or vitals signs. To ask a server to return the last n=number of observations, the *lastn* query uses the [normal search parameters](observation.html#search) defined for the Observation resource. However, rather than their normal use, they are interpreted as inputs - i.e.. instead of requiring that the resources literally contain the search parameters, they are passed to a server algorithm of some kind that uses them to determine the most appropriate matches.\n\nThe request for a lastn query SHALL include:\n\n* A `$lastn` operation parameter\n* A subject using either the `patient` or `subject` search parameter\n* A `category` parameter and/or a search parameter that contains a code element in its FHIRpath expression. ( e.g., `code` or `code-value-concept`)\n\nThe request for a lastn query MAY include:\n\n* Other Observation search parameters and modifiers\n\nThe response from a lastn query is a set of observations:\n\n* Filtered by additional parameters\n * If not explicitly filtered by status then will include statuses of 'entered-in-error'\n* 'GROUP BY' `Observation.code`\n * Codes SHALL be considered equivalent if the `coding.value` *and* `coding.system` are the same.\n * Text only codes SHALL be treated and grouped based on the text.\n * For codes with translations (multiple codings), the code translations are assumed to be equal and the grouping by code SHALL follow the transitive property of equality.\n\nfor example:\n\n|Observation.code for observation a|Observation.code for observation b|Observation.code for observation c|number of groups [codes/text in each group]| \n|---|---|---|---| \n|a|b|c | 3 [a],[b],[c]| \n|a|b|a,c | 2 [a.c],[b]| \n|a|b|a,b | 1 [a,b]| \n|'textM'|'Text'|'t e x t'|3 ['text'],['Text'],['t e x t']|\n\n* Sorted from most recent to the oldest\n* Limited to the number of requested responses per group specified by the optional *max* query parameter\n * In case of a tie - when the effective times for >1 Observations are equal - both will be returned. Therefore, more Observations may be returned than is specified in *max*. For example, 4 Observations instead of 3 if the 3rd and 4th most recent observation had the same effective time.\n* If no maximum number is given then only the most recent Observation in each group is returned.\n\nThe set of returned observations should represent distinct real world observations and not the same observation with changes in status or versions. If there are no matches, the *lastn* query SHALL return an empty search set with no error, but may include an operation outcome with further advice.",
  "code" : "lastn",
  "comment" : "The key differences between this query operation and simply searching Observation using the combination of `_count` and `_sort` parameters are:\r\r* The *lastn* query returns **only** the last N resource grouped by code. Using the _count query method doesn't restrict the total matches so you may need to page through several \"A\" Observations before getting to Observation \"B\".\r* The server is responsible for grouping the observations by codes. This frees the client from needing to determine which codes she should ask for.\r\rThis operation cannot be performed on observations that the user is not authorized to see. It is assumed that the server has identified and secured the context appropriately, and can either associate the authorization context with a single patient, or determine whether the context has the rights to the nominated patient, if there is one. If there is no nominated patient (e.g. the operation is invoked at the system level) and the context is not associated with a single patient record, then the server should return an error. Specifying the relationship between the context, a user and patient records is outside the scope of this specification.",
  "resource" : [
    "Observation"
  ],
  "system" : false,
  "type" : true,
  "instance" : false,
  "parameter" : [
    {
      "name" : "max",
      "use" : "in",
      "min" : 0,
      "max" : "1",
      "documentation" : "`max` is an optional input parameter to the *lastn* query operation. It is used to specify the maximum number of Observations to return from each group. For example for the query \"Fetch the last 3 results for all vitals for a patient\" `max` = 3.",
      "type" : "positiveInt"
    },
    {
      "name" : "return",
      "use" : "out",
      "min" : 1,
      "max" : "1",
      "documentation" : "The set of most recent N Observations that match the *lastn* query search criteria.",
      "type" : "Bundle"
    }
  ]
}