# MeasurementsResource

Canonical page: https://docs.ovok.com/java-sdk/reference/measurements-resource

```java
public final class MeasurementsResource
```

Builds, saves and reads measurement Observations. Get it from [`Ovok.measurements()`](/java-sdk/reference/ovok#measurements).

## Methods [#methods]

### save [#save]

```java
public MeasurementsResource.SaveObservationsResult save(
        Map<String, ?> parameters) throws IOException, InterruptedException
```

Builds Observations from measurement values and saves them in one FHIR transaction.

**Parameters:**

- `parameters`: the measurement values; `patientId` names the patient, otherwise the signed-in user's patient is used

**Returns:** the save status and the FHIR transaction response

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public MeasurementsResource.SaveObservationsResult save(
        Map<String, ?> parameters,
        SaveObservationsOptions options) throws IOException, InterruptedException
```

Builds Observations from measurement values and saves them in one FHIR transaction.

**Parameters:**

- `parameters`: the measurement values; `patientId` names the patient, otherwise the signed-in user's patient is used
- `options`: save options; `null` uses the defaults

**Returns:** the save status and the FHIR transaction response

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### saveObservations [#saveobservations]

```java
public MeasurementsResource.SaveObservationsResult saveObservations(
        List<JsonNode> observations) throws IOException, InterruptedException
```

Saves Observations in one FHIR transaction.

**Parameters:**

- `observations`: the Observations to save

**Returns:** the save status and the FHIR transaction response

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public MeasurementsResource.SaveObservationsResult saveObservations(
        List<JsonNode> observations,
        SaveObservationsOptions options) throws IOException, InterruptedException
```

Saves Observations in one FHIR transaction.

**Parameters:**

- `observations`: the Observations to save
- `options`: save options; `null` uses the defaults

**Returns:** the save status and the FHIR transaction response

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response
- [`OvokConflictException`](/java-sdk/reference/ovok-conflict-exception): if the signed-in account changes during the save

### build [#build]

```java
public List<JsonNode> build(Map<String, ?> parameters)
```

Builds Observations from measurement values without sending them.

**Parameters:**

- `parameters`: the measurement values; `patientId` names the patient, otherwise the signed-in user's patient is used

**Returns:** the Observations

**Throws:**

- [`OvokValidationException`](/java-sdk/reference/ovok-validation-exception): if no patient is named and no user is signed in

### latest [#latest]

```java
public JsonNode latest(Map<String, ?> parameters) throws IOException, InterruptedException
```

Reads the latest Observation per code (`GET /fhir/Observation/$lastn`).

**Parameters:**

- `parameters`: `patientId` or `me: true`, `codes`, and an optional `date` lower bound

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode latest(
        Map<String, ?> parameters,
        RequestOptions options) throws IOException, InterruptedException
```

Reads the latest Observation per code (`GET /fhir/Observation/$lastn`).

**Parameters:**

- `parameters`: `patientId` or `me: true`, `codes`, and an optional `date` lower bound
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### lastForPatient [#lastforpatient]

```java
public JsonNode lastForPatient(
        String patientId,
        Map<String, ?> query) throws IOException, InterruptedException
```

Reads a patient's last observations (`GET /patient/{patientId}/observation`).

**Parameters:**

- `patientId`: the patient ID
- `query`: query parameters, sent as given

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

```java
public JsonNode lastForPatient(
        String patientId,
        Map<String, ?> query,
        RequestOptions options) throws IOException, InterruptedException
```

Reads a patient's last observations (`GET /patient/{patientId}/observation`).

**Parameters:**

- `patientId`: the patient ID
- `query`: query parameters, sent as given
- `options`: per-request options, such as the timeout

**Returns:** the response body

**Throws:**

- `IOException`: if the request cannot be sent or the response cannot be read
- `InterruptedException`: if the thread is interrupted while waiting for the response

### codesFor [#codesfor]

```java
public String codesFor(List<String> measurementTypes)
```

Returns the comma-separated LOINC codes for measurement types.

**Parameters:**

- `measurementTypes`: the measurement type names

**Returns:** the codes, joined with commas

## MeasurementsResource.SaveObservationsResult [#measurementsresourcesaveobservationsresult]

```java
public static record SaveObservationsResult(String status, JsonNode response)
```

Result of saving Observations.

**Components:**

- `status`: the save status, `saved`
- `response`: the FHIR transaction response
