# Find nearby healthcare locations

Operation ID: `patient.nearestLocations`

Return nearby clinics/providers via Google Places, searched by `location` (free text) or `lat`/`lon`. Falls back to a hardcoded response when no Google Places API key is configured for this deployment. Requires a Bearer JWT (any authenticated pool type).

## Public method

`nearestLocations`

Signature: `patient.nearestLocations(query)`

Return type: `Promise<ListNearestLocationsResponse>`

## Authentication

Classification: **AUTHENTICATED**

Schemes: `bearerAuth`

## Prerequisites

None documented.

## HTTP

`GET /locations/nearest`

## Path parameters

None.

## Query parameters

| Name | Type | Required | Format | Allowed values | Default | Nullable | Description |
|---|---|---:|---|---|---|---:|---|
| `lat` | `number` | No |  |  |  | No |  |
| `location` | `string` | No |  |  |  | No |  |
| `lon` | `number` | No |  |  |  | No |  |
| `radius_km` | `number` | No |  |  | `10` | No |  |
| `type` | `string` | No |  |  | `"hospital"` | No | Place type: hospital, pharmacy, doctor, etc. |

## Body parameters

None.

Request model: None.

## Request example

None declared in canonical OpenAPI.

## Success responses

| Status | Shape | Content type | Description |
|---|---|---|---|
| `200` | [`NearestLocationsResponse`](../models/NearestLocationsResponse.md) | application/json | Nearest healthcare locations |

## Success response examples

### 200

```json
{
  "location": "Testville, CA",
  "locations": [
    {
      "distance_km": 2.4,
      "geometry": {
        "location": {
          "lat": 37.7749,
          "lng": -122.4194
        }
      },
      "name": "Example Health Clinic",
      "open_now": true,
      "phone": "+15550100006",
      "place_id": "place-example-001",
      "rating": 4.8,
      "types": [
        "health"
      ],
      "vicinity": "100 Clinic Way, Testville, CA"
    }
  ],
  "note": "Results are ordered by distance from the supplied location.",
  "radius_km": 10,
  "source": "google_places",
  "total": 1
}
```

## Common errors

| Status | Shape | Content type | Description |
|---|---|---|---|
| `400` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | Bad request — lat/lon are mismatched, or neither location nor lat+lon was given |
| `401` | [`patient.ErrorResponse`](../models/patient.ErrorResponse.md) | application/json | Authorization required — missing or invalid Bearer JWT |

## Error examples

### 400 — lat and lon must both be provided

```json
{
  "error": "lat and lon must be provided together"
}
```

### 400 — No location was given

```json
{
  "error": "location or both lat and lon query parameters are required"
}
```

### 401 — Missing or invalid access token

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

## NodeJS / TypeScript implementation

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

```ts
const query = {
  "lat": 1,
  "location": "<LOCATION>",
  "lon": 1,
  "radius_km": 10,
  "type": "hospital"
};

const result = await patient.nearestLocations(query);
```

## cURL

```bash
curl -X GET \
  -H 'Authorization: Bearer <ACCESS_TOKEN>' \
  'https://dev-api-patient.health.cloud/locations/nearest?lat=1&location=%3CLOCATION%3E&lon=1&radius_km=10&type=hospital'
```

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