# Method: fhir.Observation-lastn

**Full name**: projects.locations.datasets.fhirStores.fhir.Observation-lastn

Retrieves the N most recent `Observation` resources for a subject matching search criteria specified as query parameters, grouped by `Observation.code`, sorted from most recent to oldest.

Implements the FHIR extended operation Observation-lastn ([STU3](https://hl7.org/fhir/STU3/observation-operations.html#lastn), [R4](https://hl7.org/fhir/R4/observation-operation-lastn.html), [R5](https://hl7.org/fhir/R5/observation-operation-lastn.html)).

DSTU2 doesn't define the Observation-lastn method, but the server supports it the same way it supports STU3.

Search terms are provided as query parameters following the same pattern as the `https://docs.cloud.google.com/healthcare-api/docs/reference/rest/v1beta1/projects.locations.datasets.fhirStores.fhir/search#google.cloud.healthcare.v1beta1.fhir.rest.FhirService.SearchResources` method. The following search parameters must be provided:

    - `subject` or `patient` to specify a subject for the Observation.
    - `code`, `category` or any of the composite parameters that include
      `code`.

Any other valid Observation search parameters can also be provided. This operation accepts an additional query parameter `max`, which specifies N, the maximum number of Observations to return from each group, with a default of 1.

Searches with over 1000 results are rejected. Results are counted before grouping and limiting the results with `max`. To stay within the limit, constrain these searches using Observation search parameters such as `_lastUpdated` or `date`.

On success, the response body contains a JSON-encoded representation of a `Bundle` resource of type `searchset`, containing the results of the operation. Errors generated by the FHIR store contain a JSON-encoded `OperationOutcome` resource describing the reason for the error. If the request cannot be mapped to a valid API method on a FHIR store, a generic GCP error might be returned instead.

### HTTP request

`GET https://healthcare.googleapis.com/v1beta1/{parent=projects/*/locations/*/datasets/*/fhirStores/*}/fhir/Observation/$lastn`

The URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.

### Path parameters

| Parameters ||
|---|---|
| `parent` | `string` Required. Name of the FHIR store to retrieve resources from. Authorization requires the following [IAM](https://cloud.google.com/iam/docs/) permission on the specified resource `parent`: - `healthcare.fhirResources.search` |

### Request body

The request body must be empty.

### Response body

If successful, the response is a generic HTTP response whose format is defined by the method.

### Authorization scopes

Requires one of the following OAuth scopes:

- `https://www.googleapis.com/auth/cloud-healthcare`
- `https://www.googleapis.com/auth/cloud-platform`

For more information, see the [Authentication Overview](https://docs.cloud.google.com/docs/authentication#authorization-gcp).