# Set preferred pharmacy

Operation ID: `patient.setPreferredPharmacy`

Set or replace the authenticated patient's preferred-pharmacy FHIR Organization and link it via the patient's `preferred-pharmacy-ref` extension. Requires a patient Bearer JWT.

## Public method

`setPreferredPharmacy`

Signature: `patient.setPreferredPharmacy(data)`

Return type: `Promise<JsonValue>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`PUT /patients/preferred-pharmacy`

## Path parameters

None.

## Query parameters

None.

## Body parameters

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

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

## Request example

```json
{
  "address": {
    "city": "string",
    "country": "string",
    "line": [
      "string"
    ],
    "postalCode": "string",
    "state": "string"
  },
  "name": "string",
  "phone": "string",
  "place_id": "string"
}
```

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`SetPreferredPharmacyResponse`](../models/SetPreferredPharmacyResponse.md) | application/json | The saved preferred-pharmacy FHIR Organization resource, plus the Athena mirror outcome |

## Success response examples

### 200

```json
{
  "athena_pharmacy_error": "string",
  "athena_pharmacy_status": "string",
  "openloop_pharmacy_error": "string",
  "openloop_pharmacy_status": "string",
  "steadymd_pharmacy_error": "string",
  "steadymd_pharmacy_status": "string"
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | The pharmacy payload failed validation |
| `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 pharmacy payload is invalid

```json
{
  "error": "name is required"
}
```

### 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";
```

```ts
const data = "<DATA>";

const result = await patient.setPreferredPharmacy(data);
```

## cURL

```bash
curl -X PUT \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{"address":{"city":"string","country":"string","line":["string"],"postalCode":"string","state":"string"},"name":"string","phone":"string","place_id":"string"}' \
  'https://dev-api-patient.health.cloud/patients/preferred-pharmacy'
```

## Notes

None.

## 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.
