# Update a medication

Operation ID: `patient.updateMedication`

Update a medication's `status`, `notes`, and/or `discontinued_reason` (only the supplied fields are changed). Requires a patient Bearer JWT.

## Public method

`updateMedicationStatus`

Signature: `patient.updateMedicationStatus(medicationId, request)`

Return type: `Promise<MedicationUpdateResponse>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`PUT /patients/medications/{med_id}`

## Path parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `med_id` | `string` | Yes |  |  |  | No |  |

## Query parameters

None.

## Body parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `body` | [`UpdateMedicationRequest`](../models/UpdateMedicationRequest.md) | No |  |  |  | No |  |

Request model: [`UpdateMedicationRequest`](../models/UpdateMedicationRequest.md)

## Request example

```json
{
  "discontinued_reason": "Treatment completed",
  "notes": "Synthetic medication update",
  "resource_type": "MedicationRequest",
  "status": "stopped"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`UpdateMedicationResponse`](../models/UpdateMedicationResponse.md) | application/json | Medication updated |

## Success response examples

### 200

```json
{
  "fhir_id": "190e6baa-28c6-41f7-99b6-7107347478c2",
  "updated": true
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | Bad request — resource_type or status is invalid |
| `401` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | Authorization required — missing, invalid, expired, or non-patient Bearer JWT |
| `404` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | The authenticated patient has no FHIR Patient record |

## Error examples

### 400 — The status value is not a valid MedicationStatus

```json
{
  "error": "'not-a-real-status' is not a valid MedicationStatus"
}
```

### 401 — Missing or invalid access token

```json
{
  "error": "Authorization required"
}
```

### 404 — Patient not found

```json
{
  "error": "Patient not found"
}
```

## NodeJS / TypeScript implementation

```ts
import { HCSDK } from "@healthcloudai/hc-sdk";
import type { MedicationStatusUpdateRequest } from "@healthcloudai/hc-sdk";
```

```ts
const medicationId = "<MEDICATION_ID>";

const request = {
  "discontinued_reason": "Treatment completed",
  "notes": "Synthetic medication update",
  "resource_type": "MedicationRequest",
  "status": "stopped"
};

const result = await patient.updateMedicationStatus(medicationId, request);
```

## cURL

```bash
curl -X PUT \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"discontinued_reason":"Treatment completed","notes":"Synthetic medication update","resource_type":"MedicationRequest","status":"stopped"}' \
  'https://dev-api-patient.health.cloud/patients/medications/%3CMED_ID%3E'
```

## Notes

- The `med_id` path parameter must be the medication's `fhir_id` from the create response, not its `medication_id`. Passing `medication_id` returns a 400/404. Confirmed live against DEV on 2026-08-10.

## Prepared Test Console scenario

No canonical scenario is currently associated.

## Real response

No approved real integration response is currently published. Unapproved candidates are never rendered as examples.
