> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rcintell.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Facility management

> Register and manage healthcare facilities for knowledge resolution

Facilities are the root entity in the RCI knowledge graph. Each facility is identified by a **CCN** (CMS Certification Number) and optionally an **NPI** (National Provider Identifier). Registering a facility enables cached knowledge resolution, enrichment for agent queries, and facility-level analytics.

## Why register facilities?

When you register a facility, RCI:

1. **Parses the CCN** to determine the state, facility type, and payment system
2. **Resolves L1-L6 knowledge layers** and caches them for fast lookups
3. **Links the MAC**, GPCI locality, and CBSA data to the facility profile
4. **Enables agent enrichment** — agent jobs submitted with the facility's CCN automatically receive the full knowledge context

## Register a facility

```bash theme={null}
curl -X POST https://api-dev.rcintell.com/v1/facilities/ \
  -H "X-API-Key: kp_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "ccn": "170001",
    "name": "Sunflower Medical Center",
    "npi": "1234567890",
    "city": "Topeka",
    "state": "KS",
    "zip_code": "66601"
  }'
```

### Request body

| Field           | Type   | Required | Description                                                                                                                                                                                             |
| --------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ccn`           | string | Yes      | 6-digit Medicare Provider Number                                                                                                                                                                        |
| `name`          | string | Yes      | Facility display name                                                                                                                                                                                   |
| `npi`           | string | No       | 10-digit National Provider Identifier                                                                                                                                                                   |
| `address_line1` | string | No       | Street address                                                                                                                                                                                          |
| `city`          | string | No       | City                                                                                                                                                                                                    |
| `state`         | string | No       | 2-letter state code                                                                                                                                                                                     |
| `zip_code`      | string | No       | 5 or 9-digit ZIP                                                                                                                                                                                        |
| `county`        | string | No       | County name                                                                                                                                                                                             |
| `cbsa`          | string | No       | CBSA code (used for OPPS wage-index lookup)                                                                                                                                                             |
| `facility_type` | enum   | No       | One of `short_term_acute`, `critical_access_hospital`, `inpatient_psych`, `rehab_hospital`, `long_term_care`, `ambulatory_surgical_center`, `outpatient_hospital`, etc. Inferred from CCN when omitted. |
| `pos_code`      | string | No       | CMS Place-of-Service code (e.g. `22` outpatient hospital, `24` ASC).                                                                                                                                    |
| `is_rural`      | bool   | No       | Whether the facility is in a CMS-designated rural area. Affects sole-community-hospital and rural-add-on payments.                                                                                      |

### Response

```json theme={null}
{
  "id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
  "ccn": "170001",
  "name": "Sunflower Medical Center",
  "npi": "1234567890",
  "city": "Topeka",
  "state": "KS",
  "zip_code": "66601",
  "is_active": true,
  "resolved_layers": {
    "l1_location": { "state_name": "Kansas", "mac_jurisdiction": "JL", "gpci_locality": "00" },
    "l2_facility_type": { "facility_type": "Short-term Hospital", "payment_system": "OPPS", "billing_form": "UB-04" }
  },
  "mac": { "mac_name": "WPS Government Health Administrators", "jurisdiction": "JL" },
  "gpci": { "work_gpci": 1.000, "pe_gpci": 0.876, "mp_gpci": 0.407 },
  "created_at": "2026-03-31T10:00:00Z"
}
```

## List facilities

```bash theme={null}
curl https://api-dev.rcintell.com/v1/facilities/ \
  -H "X-API-Key: kp_test_..."
```

Returns a paginated list of all facilities registered under your tenant:

```json theme={null}
{
  "facilities": [ { "id": "...", "ccn": "170001", "name": "Sunflower Medical Center", "..." } ],
  "total": 12
}
```

## Get a facility by CCN

```bash theme={null}
curl https://api-dev.rcintell.com/v1/facilities/170001 \
  -H "X-API-Key: kp_test_..."
```

Returns the full facility profile with cached knowledge layers, MAC, GPCI, and CBSA data.

## Update a facility

```bash theme={null}
curl -X PUT https://api-dev.rcintell.com/v1/facilities/170001 \
  -H "X-API-Key: kp_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "npi": "9876543210",
    "county": "Shawnee",
    "facility_type": "short_term_acute",
    "pos_code": "22",
    "is_rural": false,
    "cbsa": "45820"
  }'
```

All fields are optional — only the fields you include will be updated. The same expanded set as `POST` is supported (`cbsa`, `facility_type`, `pos_code`, `is_rural`).

## Delete a facility

The `DELETE` endpoint supports both **soft** and **hard** delete:

```bash theme={null}
# Soft delete (default) — sets is_active=false but keeps the record for audit
curl -X DELETE "https://api-dev.rcintell.com/v1/facilities/170001" \
  -H "X-API-Key: kp_test_..."

# Hard delete — permanently removes the row
curl -X DELETE "https://api-dev.rcintell.com/v1/facilities/170001?hard=true" \
  -H "X-API-Key: kp_test_..."
```

Response:

```json theme={null}
{
  "ccn": "170001",
  "deleted": true,
  "hard": false,
  "message": "Facility 170001 marked inactive"
}
```

<Warning>
  Hard delete is irreversible and removes any cached knowledge layers, MAC/GPCI links, and historical resolutions tied to that CCN. Use soft delete unless you have a compliance reason to purge.
</Warning>

## Facility and knowledge resolution

You don't need to register a facility to use knowledge resolution. The `/v1/knowledge/resolve` endpoint accepts any valid CCN:

```bash theme={null}
curl -X POST https://api-dev.rcintell.com/v1/knowledge/resolve \
  -H "X-API-Key: kp_test_..." \
  -H "Content-Type: application/json" \
  -d '{"ccn": "170001", "cpt": "99213"}'
```

The difference is that registered facilities get **cached layers** for faster responses and **enrichment** on agent jobs, while ad-hoc resolution computes layers on the fly.

<CardGroup cols={2}>
  <Card title="CCN format" icon="barcode" href="/facilities/ccn-format">
    Learn how the 6-digit CCN encodes state, facility type, and sequence.
  </Card>

  <Card title="Knowledge resolution" icon="layer-group" href="/knowledge/overview">
    See how L1-L6 layers build on a facility's CCN.
  </Card>
</CardGroup>
