# Patient

Source: https://www.flexpa.com/docs/fhir/patient
Description: Patient is the FHIR resource for demographics. How Flexpa returns Patient from medical record systems, health insurers, and national exchanges, with fields and examples.

[**Patient**](https://www.hl7.org/fhir/patient.html) is a FHIR resource that contains demographic and administrative information about an individual receiving healthcare services. It serves as the central reference point for all other healthcare data.

The Patient resource captures essential demographic data including names, addresses, contact information, birth date, gender, and identifiers. It also includes administrative information such as marital status, language preferences, and managing organization references.

As the foundational resource in FHIR, Patient is referenced by virtually all other clinical and administrative resources.

Patient data is structured according to several implementation guides:

- **[US Core Patient Profile](https://hl7.org/fhir/us/core/StructureDefinition-us-core-patient.html)** - Defines the minimum conformance requirements for Patient resources in US healthcare
- **[CARIN for Blue Button® Patient Profile](https://hl7.org/fhir/us/carin-bb/StructureDefinition-C4BB-Patient.html)** - Extends US Core with additional payer-specific requirements

This reference explains the key elements of the Patient resource and how they are used in patient-authorized health records. Data types used in this reference are defined in the [FHIR R4 Data Types](https://hl7.org/fhir/R4/datatypes.html) specification.

*FHIR API*

```bash
https://api.flexpa.com/fhir/Patient
```

```bash
https://api.flexpa.com/fhir/Patient/[id]
```

```bash
https://api.flexpa.com/fhir/Patient/$everything
```

```bash
https://api.flexpa.com/fhir/Patient/[id]/$summary
```

```bash
https://api.flexpa.com/fhir/Patient/[id]/$health-cards-issue
```

New to FHIR?

Need all patient data?

## Schema

### All Patients

The FHIR R4 [**Patient**](https://hl7.org/fhir/R4/patient.html) resource represents an individual receiving healthcare services. As a FHIR resource, it follows standard FHIR patterns with common elements like `resourceType`, `id`, `meta`, and `identifier`.

Patient resources contain demographic and administrative information that is essential for identifying individuals and coordinating their care across healthcare systems.

The Patient FHIR Resource specification includes a comprehensive set of data elements. The elements documented below represent the core FHIR R4 Patient resource elements that are commonly used across all implementations.

**Elements**

- `meta` (Meta):
Metadata about the resource. See also [Tags](https://www.flexpa.com/docs/records#tags) defined by Flexpa.

  - `lastUpdated` (instant):
The last time the patient record was updated in the source system

  - `security` (array):
Security labels applied to this resource. For identity-verified (IAL2) patients, this includes an identity assurance level code from the [SMART Health Cards code system](https://build.fhir.org/ig/HL7/fhir-shc-vaccination-ig/CodeSystem-identity-assurance-level-code-system.html) (`https://smarthealth.cards/ial`). An `IAL2` code indicates the patient's identity was verified via remote or in-person proofing per [NIST SP 800-63A](https://pages.nist.gov/800-63-4/). See [Patient linking](https://www.flexpa.com/docs/guides/patient-linking) for more details.

- `active` (boolean):
Whether this patient record is in active use - typically `true` for all current records

- `name` (array):
Names associated with the patient

  - `use` (code):
The context / formality in which this name is used

  - `text` (string):
Text representation of the full name

  - `family` (string):
Family name (often called 'Surname' or 'Last Name')

  - `given` (array):
Given names (not always 'first'). Includes middle names

  - `prefix` (array):
Parts that come before the name (e.g., Dr, Mr, Ms)

  - `suffix` (array):
Parts that come after the name (e.g., Jr, III, MD)

  - `period` (Period):
Time period when this name was valid for use

- `telecom` (array):
Contact details for the patient

  - `system` (code):
Telecommunications form for contact

  - `value` (string):
The actual contact point details (phone number, email address, etc.)

  - `use` (code):
Purpose of this contact point

  - `rank` (positiveInt):
Preferred order of use (1 = highest)

  - `period` (Period):
Time period when the contact point was/is in use

- `gender` (code):
Administrative gender - may be used for administrative purposes

- `birthDate` (date):
The date of birth for the patient

- `deceasedDateTime` (dateTime):
Date and time of death if applicable

- `address` (array):
Addresses for the patient

  - `use` (code):
The purpose of this address

  - `type` (code):
The type of address

  - `text` (string):
Text representation of the full address

  - `line` (array):
Street name, number, direction & P.O. Box etc.

  - `city` (string):
Name of city, town etc.

  - `state` (string):
[USPS Two Letter Alphabetic Codes](https://hl7.org/fhir/us/core/ValueSet-us-core-usps-state.html)

  - `postalCode` (string):
US Zip Codes

  - `country` (string):
Country (e.g., may be ISO 3166 2 or 3 letter code)

  - `period` (Period):
Time period when address was/is in use

- `link` (array):
Links to other patient or related person resources. This element is used to establish relationships between patient records, such as during record merging or when linking records across different healthcare systems. See the [FHIR Patient Linking documentation](https://hl7.org/fhir/R4/patient.html#linking) for more details.

  - `other` (Reference(Patient|RelatedPerson)):
The other patient or related person resource that the link refers to

  - `type` (code):
The type of link

*Patient Example*

```json
{
  "resourceType": "Patient",
  "id": "f8b7c4d2-9e3a-4f5b-a1c6-2d8e7b9f5c3a",
  "meta": {
    "lastUpdated": "2023-01-01T00:00:00Z"
  },
  "active": true,
  "name": [
    {
      "use": "official",
      "family": "Doe",
      "given": ["John", "Michael"],
      "prefix": ["Mr."]
    }
  ],
  "telecom": [
    {
      "system": "phone",
      "value": "555-123-4567",
      "use": "home"
    },
    {
      "system": "email",
      "value": "john.doe@example.com",
      "use": "home"
    }
  ],
  "gender": "male",
  "birthDate": "1985-07-15",
  "address": [
    {
      "use": "home",
      "type": "both",
      "line": ["123 Main Street", "Apt 4B"],
      "city": "Anytown",
      "state": "CA",
      "postalCode": "12345",
      "country": "USA"
    }
  ]
}
```

---

### US Core Patients

The [US Core Patient Profile](https://hl7.org/fhir/us/core/StructureDefinition-us-core-patient.html) defines additional constraints and extensions for Patient resources used in the United States healthcare context. This profile builds upon the base FHIR Patient resource and establishes minimum requirements for interoperability.

US Core requires specific elements to be supported and adds additional constraints to ensure consistent implementation across US healthcare systems.

**Elements**

- `meta` (Meta):
Resource metadata

  - `profile` (array):
`http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient`

- `extension` (array):
US Core Extensions - array of extension objects identified by their URL

  - `url` (uri):
Identifies which extension is being used. US Core defines the following extensions:
    - `http://hl7.org/fhir/us/core/StructureDefinition/us-core-race` - Race
    - `http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity` - Ethnicity
    - `http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex` - Birth Sex

  - `extension` (array):
For `us-core-race` and `us-core-ethnicity` extensions - nested extension arrays are used

    - `url` (string):
Sub-extension type: `ombCategory`, `detailed`, or `text`

    - `valueCoding` (Coding):
When extension is `us-core-race` and the sub-extension is `ombCategory`, the value represents one of the 5 OMB race categories from [Standards for Maintaining, Collecting, and Presenting Federal Data on Race and Ethnicity, Statistical Policy Directive No. 15, as revised, October 30, 1997](https://www.govinfo.gov/content/pkg/FR-1997-10-30/pdf/97-28653.pdf)

A limited subset of [CDC Race & Ethnicity Codes (CDCREC)](https://www.cdc.gov/phin/resources/vocabulary/documents/PH_RaceAndEthnicity_CDC_v1.2.xlsx)

Additional codes for cases where race information was requested but not obtained or is unknown

    - `valueCoding` (Coding):
When extension is `us-core-race` and the sub-extension is `detailed`, all available codes from [CDC Race & Ethnicity Codes (CDCREC)](https://www.cdc.gov/phin/resources/vocabulary/documents/PH_RaceAndEthnicity_CDC_v1.2.xlsx) are used

The full set of CDCREC codes

    - `valueCoding` (Coding):
When extension is `us-core-ethnicity` and the sub-extension is `ombCategory`, the value represents one of the 2 OMB ethnicity categories from [Standards for Maintaining, Collecting, and Presenting Federal Data on Race and Ethnicity, Statistical Policy Directive No. 15, as revised, October 30, 1997](https://www.govinfo.gov/content/pkg/FR-1997-10-30/pdf/97-28653.pdf)

A two code subset of [CDC Race & Ethnicity Codes (CDCREC)](https://www.cdc.gov/phin/resources/vocabulary/documents/PH_RaceAndEthnicity_CDC_v1.2.xlsx)

Additional codes for cases where ethnicity information was requested but not obtained or is unknown

    - `valueCoding` (Coding):
When extension is `us-core-ethnicity` and the sub-extension is `detailed`, a subset of 41 codes from [CDC Race & Ethnicity Codes (CDCREC)](https://www.cdc.gov/phin/resources/vocabulary/documents/PH_RaceAndEthnicity_CDC_v1.2.xlsx) are used that are grouped into the 2 OMB ethnicity categories

A [41 code subset](https://hl7.org/fhir/us/core/STU6.1/ValueSet-detailed-ethnicity.html) of [CDC Race & Ethnicity Codes (CDCREC)](https://www.cdc.gov/phin/resources/vocabulary/documents/PH_RaceAndEthnicity_CDC_v1.2.xlsx) for detailed ethnicity

Additional codes for cases where detailed ethnicity information was requested but not obtained, is unknown, or is other than the defined values

    - `valueString` (string):
For `text` sub-extension for either the `us-core-race` or `us-core-ethnicity` extensions, this is free text that may have been reported by patient

  - `valueCode` (code):
When extension is `us-core-birthsex`, the value represents birth sex assigned at birth

Birth sex codes from HL7 v3 Administrative Gender

Additional codes for cases where birth sex information was requested but not obtained, is unknown, or is other than male/female

- `communication` (BackboneElement):
Language communication abilities

  - `language` (CodeableConcept):
The language for communication

  - `preferred` (boolean):
Language preference indicator

*US Core Patient Example*

```json
{
  "resourceType": "Patient",
  "id": "c7e5a4b9-3f2d-4e1a-8b6c-9d8e7f5c2a1b",
  "meta": {
    "lastUpdated": "2023-10-15T14:30:00Z",
    "profile": [
      "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
    ]
  },
  "extension": [
    {
      "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race",
      "extension": [
        {
          "url": "ombCategory",
          "valueCoding": {
            "system": "urn:oid:2.16.840.1.113883.6.238",
            "code": "2106-3",
            "display": "White"
          }
        },
        {
          "url": "detailed",
          "valueCoding": {
            "system": "urn:oid:2.16.840.1.113883.6.238",
            "code": "2113-9",
            "display": "Irish"
          }
        },
        {
          "url": "text",
          "valueString": "White - Irish"
        }
      ]
    },
    {
      "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity",
      "extension": [
        {
          "url": "ombCategory",
          "valueCoding": {
            "system": "urn:oid:2.16.840.1.113883.6.238",
            "code": "2186-5",
            "display": "Not Hispanic or Latino"
          }
        },
        {
          "url": "text",
          "valueString": "Not Hispanic or Latino"
        }
      ]
    },
    {
      "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
      "valueCode": "F"
    }
  ],
  "name": [
    {
      "family": "O'Sullivan",
      "given": ["Siobhan", "Mary"]
    }
  ],
  "gender": "female",
  "birthDate": "1985-08-23",
  "address": [
    {
      "line": ["742 Evergreen Terrace"],
      "city": "San Diego",
      "state": "CA",
      "postalCode": "92101"
    }
  ],
  "telecom": [
    {
      "system": "phone",
      "value": "619-555-7890",
      "use": "mobile"
    },
    {
      "system": "email",
      "value": "siobhan.osullivan@example.com"
    }
  ],
  "communication": [
    {
      "language": {
        "coding": [
          {
            "system": "urn:ietf:bcp:47",
            "code": "en",
            "display": "English"
          }
        ]
      },
      "preferred": true
    }
  ]
}
```

---

### CARIN Blue Button Patients

The [CARIN Consumer Directed Payer Data Exchange (CARIN IG) for Blue Button®](https://hl7.org/fhir/us/carin-bb/StructureDefinition-C4BB-Patient.html) Patient Profile extends the US Core Patient Profile with additional requirements specific to payer data exchange scenarios.

This profile is designed to support consumer-directed exchange of health insurance information and ensures that payer systems can provide consistent patient demographic data to members.

**Elements**

- `meta` (Meta):
Resource metadata

  - `profile` (array):
`http://hl7.org/fhir/us/carin-bb/StructureDefinition/C4BB-Patient`

- `identifier` (array):
Business and administrative identifiers for the Patient

  - `type` (CodeableConcept):
Must include member identifier type (`MB`)

HL7-defined code system of concepts specifying type of identifier used in [HL7 Version 2.x](http://terminology.hl7.org/CodeSystem/v2-0203)

Identifier Type codes that extend those defined in [HL7 Version 2.x](http://terminology.hl7.org/CodeSystem/v2-0203) to define the type of identifier payers and providers assign to claims and patients

*CARIN Patient Example*

```json
{
  "resourceType": "Patient",
  "id": "c7e5a4b9-3f2d-4e1a-8b6c-9d8e7f5c2a1b",
  "meta": {
    "lastUpdated": "2023-10-15T14:30:00Z",
    "profile": [
      "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient",
      "http://hl7.org/fhir/us/carin-bb/StructureDefinition/C4BB-Patient"
    ]
  },
  "identifier": [
    {
      "type": {
        "coding": [
          {
            "system": "http://terminology.hl7.org/CodeSystem/v2-0203",
            "code": "MB",
            "display": "Member Number"
          }
        ]
      },
      "system": "https://example-payer.com/member-ids",
      "value": "987654321"
    },
    {
      "type": {
        "coding": [
          {
            "system": "http://hl7.org/fhir/us/carin-bb/CodeSystem/C4BBIdentifierType",
            "code": "um",
            "display": "Unique Member ID"
          }
        ]
      },
      "system": "https://example-payer.com/unique-member-ids",
      "value": "UM-987654321"
    }
  ],
  "extension": [
    {
      "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race",
      "extension": [
        {
          "url": "ombCategory",
          "valueCoding": {
            "system": "urn:oid:2.16.840.1.113883.6.238",
            "code": "2106-3",
            "display": "White"
          }
        },
        {
          "url": "detailed",
          "valueCoding": {
            "system": "urn:oid:2.16.840.1.113883.6.238",
            "code": "2113-9",
            "display": "Irish"
          }
        },
        {
          "url": "text",
          "valueString": "White - Irish"
        }
      ]
    },
    {
      "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity",
      "extension": [
        {
          "url": "ombCategory",
          "valueCoding": {
            "system": "urn:oid:2.16.840.1.113883.6.238",
            "code": "2186-5",
            "display": "Not Hispanic or Latino"
          }
        },
        {
          "url": "text",
          "valueString": "Not Hispanic or Latino"
        }
      ]
    },
    {
      "url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-birthsex",
      "valueCode": "F"
    }
  ],
  "name": [
    {
      "family": "O'Sullivan",
      "given": ["Siobhan", "Mary"]
    }
  ],
  "gender": "female",
  "birthDate": "1985-08-23",
  "address": [
    {
      "line": ["742 Evergreen Terrace"],
      "city": "San Diego",
      "state": "CA",
      "postalCode": "92101"
    }
  ],
  "telecom": [
    {
      "system": "phone",
      "value": "619-555-7890",
      "use": "mobile"
    },
    {
      "system": "email",
      "value": "siobhan.osullivan@example.com"
    }
  ],
  "communication": [
    {
      "language": {
        "coding": [
          {
            "system": "urn:ietf:bcp:47",
            "code": "en",
            "display": "English"
          }
        ]
      },
      "preferred": true
    }
  ]
}
```

## API

### Read

A read is the most basic operation in FHIR. It allows you to retrieve the current version of a single resource by its ID.

**Note:**
When using the read operation with Patient resources, you can use the `$PATIENT_ID` [wildcard](https://www.flexpa.com/records#wildcard-parameters) which will automatically be replaced with the authenticated patient's ID.

**Request headers**

- `Authorization` (string):
An `Authorization: Bearer` header value must be presented with a [Patient Access Token](https://www.flexpa.com/records#patient-access-token) or an [Application Access Token](https://www.flexpa.com/records#application-access-token)

**Request path parameters**

- `id` (string):
The identifier of the resource to be retrieved - use `$PATIENT_ID` to automatically reference the authenticated patient

*Request*

```bash
ACCESS_TOKEN=patient-access-token

curl https://api.flexpa.com/fhir/Patient/$PATIENT_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```js
const ACCESS_TOKEN="patient-access-token"

const response = await fetch("https://api.flexpa.com/fhir/Patient/$PATIENT_ID", {
  headers: {
    "content-type": "application/json",
    "authorization": `Bearer ${ACCESS_TOKEN}`,
  },
});

const resource = await response.json();
```

```json
{
  "resourceType": "Patient",
  "id": "a85f4c92-1b6d-4e3a-9c2f-8d7e5b3f2a1c",
  "meta": {
    "lastUpdated": "2023-01-01T00:00:00Z"
  },
  "active": true,
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": ["John"]
    }
  ],
  "gender": "male",
  "birthDate": "1980-01-01"
}
```

---

### Search

Searches on Flexpa API follow the RESTful style of the FHIR specification by submitting a GET HTTP request to the base URL of the resource with parameters to define the exact search criteria to filter the response.

**Request headers**

- `Authorization` (string):
An `Authorization: Bearer` header value must be presented with a [Patient Access Token](#patient-access-token) or an [Application Access Token](#application-access-token)

**Search parameters**

**Note:**
Flexpa supports all Patient `SearchParameter` values defined in the [FHIR R4 specification](https://www.hl7.org/fhir/R4/patient.html#search)

- `identifier` (token):
A patient identifier

- `name` (string):
A server defined search that may match any of the string fields in HumanName

- `given` (string):
A portion of the given name of the patient

- `family` (string):
A portion of the family name of the patient

- `gender` (token):
Gender of the patient

- `birthdate` (date):
The patient's date of birth

- `telecom` (token):
The value in any kind of telecom details of the patient

- `email` (token):
A value in an email contact

- `phone` (token):
A value in a phone contact

- `organization` (reference):
The organization that is the custodian of the patient record

- `active` (token):
Whether the patient record is active

- `language` (token):
Language code (from Patient.communication.language)

- `link` (reference):
All patients linked to the given patient

*Request*

```bash
ACCESS_TOKEN=patient-access-token

curl https://api.flexpa.com/fhir/Patient \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```js
const ACCESS_TOKEN="patient-access-token"

const response = await fetch("https://api.flexpa.com/fhir/Patient", {
  headers: {
    "content-type": "application/json",
    "authorization": `Bearer ${ACCESS_TOKEN}`,
  },
});

const bundle = await response.json();
```

```json
{
  "resourceType": "Bundle",
  "type": "searchset",
  "total": 1,
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "id": "a85f4c92-1b6d-4e3a-9c2f-8d7e5b3f2a1c",
        "meta": {
          "lastUpdated": "2023-01-01T00:00:00Z"
        },
        "active": true,
        "name": [
          {
            "use": "official",
            "family": "Smith",
            "given": ["John"]
          }
        ],
        "gender": "male",
        "birthDate": "1980-01-01"
      }
    }
  ]
}
```

---

### $everything

Unique to the Patient resource, the [Patient $everything Operation](https://hl7.org/fhir/R4/operation-patient-everything.html) returns all [patient-compartmentalized](https://hl7.org/fhir/R4/compartmentdefinition-patient.html) resources, as well as any Organization, Location, Practitioner, and Medication resources that are present in the patient's FHIR data.

**Note:**
This request returns large Bundles. The client should be prepared to handle a potentially large single response.

**Request headers**

- `Authorization` (string):
An `Authorization: Bearer` header value must be presented with a [Patient Access Token](#patient-access-token) or an [Application Access Token](#application-access-token)

**Request path parameters**

- `id` (string):
The identifier of the patient - use `$PATIENT_ID` to automatically reference the authenticated patient

**Response fields**

- `Response` (Bundle):
Patient $everything returns a Bundle that contains all resources that reference the Patient resource.

*Request*

```bash
ACCESS_TOKEN=patient-access-token

curl 'https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$everything' \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```js
const ACCESS_TOKEN="patient-access-token"

const response = await fetch("https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$everything", {
  headers: {
    "content-type": "application/json",
    "authorization": `Bearer ${ACCESS_TOKEN}`,
  },
});

const bundle = await response.json();
```

```json
{
  "resourceType": "Bundle",
  "entry": [
    { "resource": {"resourceType": "Patient", ...} },
    { "resource": {"resourceType": "Coverage", ...} },
    { "resource": {"resourceType": "InsurancePlan", ...} },
    { "resource": {"resourceType": "ExplanationOfBenefit", ...} },
  ]
}
```

---

### $summary

The `$summary` operation generates an [International Patient Summary](https://hl7.org/fhir/uv/ips/) (IPS) document for a patient. It returns a `Bundle` of type `document` containing a `Composition` resource that organizes clinical data into 14 standardized sections. The generated document includes status-based filtering (only clinically relevant resources), human-readable section narratives, `emptyReason` on sections with no data (`unavailable`) or excluded sections (`withheld`), and a `meta.security` confidentiality high water mark.

Use the `_section` query parameter to restrict which IPS sections appear in the summary. This is useful when patients want to share only specific categories of health data. Values can be LOINC section codes or short aliases. When `_section` is omitted, all available sections are returned.

| Alias | LOINC code | Section |
|-------|------------|---------|
| `allergies` | 48765-2 | Allergies |
| `medications` | 10160-0 | Medications |
| `problems` | 11450-4 | Problem list |
| `immunizations` | 11369-6 | Immunizations |
| `procedures` | 47519-4 | Procedures |
| `results` | 30954-2 | Results |
| `vitalsigns` | 8716-3 | Vital signs |
| `socialhistory` | 29762-2 | Social history |
| `devices` | 46264-8 | Devices |
| `planofcare` | 18776-5 | Plan of treatment |
| `functionalstatus` | 47420-5 | Functional status |
| `pastillness` | 11348-0 | History of past illness |
| `pregnancy` | 10162-6 | Pregnancy history |
| `advancedirectives` | 42348-3 | Advance directives |

**Note:**
When `_section` is provided, excluded sections remain in the Composition (preserving the IPS structure) but contain no entries and are marked as `withheld`. Only resources referenced by included sections are present in the Bundle. Patient, Composition, and author resources are always retained.

**Request headers**

- `Authorization` (string):
An `Authorization: Bearer` header value must be presented with a [Patient Access Token](#patient-access-token) or an [Application Access Token](#application-access-token)

**Request path parameters**

- `id` (string):
The identifier of the patient - use `$PATIENT_ID` to automatically reference the authenticated patient

**Request query parameters**

- `_section` (string):
One or more LOINC section codes or aliases to include. Repeat for multiple sections. When omitted, all sections are returned.

**Response fields**

- `Response` (Bundle):
Patient $summary returns a document Bundle containing a Composition resource and all referenced clinical resources organized into IPS sections.

*Request*

```bash
ACCESS_TOKEN=patient-access-token

curl 'https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$summary' \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```js
const ACCESS_TOKEN="patient-access-token"

const response = await fetch("https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$summary", {
  headers: {
    "content-type": "application/json",
    "authorization": `Bearer ${ACCESS_TOKEN}`,
  },
});

const bundle = await response.json();
```

*Filtered request*

```bash
ACCESS_TOKEN=patient-access-token

curl 'https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$summary?_section=allergies&_section=medications' \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

```js
const ACCESS_TOKEN="patient-access-token"

const response = await fetch(
  "https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$summary?_section=allergies&_section=medications",
  {
    headers: {
      "content-type": "application/json",
      "authorization": `Bearer ${ACCESS_TOKEN}`,
    },
  }
);

const bundle = await response.json();
```

```json
{
  "resourceType": "Bundle",
  "type": "document",
  "entry": [
    {
      "resource": {
        "resourceType": "Composition",
        "type": {
          "coding": [{ "system": "http://loinc.org", "code": "60591-5" }]
        },
        "section": [
          {
            "title": "Allergies",
            "code": {
              "coding": [{ "system": "http://loinc.org", "code": "48765-2" }]
            },
            "entry": [{ "reference": "AllergyIntolerance/allergy-1" }]
          }
        ]
      }
    },
    { "resource": { "resourceType": "Patient", "..." : "..." } },
    { "resource": { "resourceType": "AllergyIntolerance", "..." : "..." } }
  ]
}
```

---

### $expunge

The `$expunge` operation deletes all resources in a specific Patient resource [compartment](https://hl7.org/fhir/R4/compartmentdefinition.html).
This operation performs a "hard" delete, meaning all data, including resource history, is permanently removed from the server.

Once the data is deleted, any subsequent FHIR requests to retrieve the data will return a 404 status code.

**Request headers**

- `Authorization` (string):
An `Authorization: Bearer` header value must be presented with a [Patient Access Token](#patient-access-token)

**Request path parameters**

- `id` (string):
The identifier of the patient whose data you want to delete - use `$PATIENT_ID` to automatically reference the authenticated patient

**Response fields**

- `Response` (OperationOutcome):
The Patient $expunge operation returns an OperationOutcome resource, indicating the success or failure of the expunge request.

*Request*

```bash
ACCESS_TOKEN=patient-access-token

curl 'https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$expunge' \
      -H "Authorization: Bearer $ACCESS_TOKEN" \
      -X POST
```

```js
const ACCESS_TOKEN="patient-access-token"

const response = await fetch("https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$expunge", {
  headers: {
    "content-type": "application/json",
    "authorization": `Bearer ${ACCESS_TOKEN}`,
  },
  method: 'POST'
});

const result = await response.json();
```

```json
{
  "resourceType": "OperationOutcome",
  "id": "accepted",
  "issue": [
    {
      "severity": "information",
      "code": "informational",
      "details": {
        "text": "Accepted"
      },
      "diagnostics": "expunge-patient-15c72fcc-267e-4372-a85e-26fa20b01634"
    }
  ]
}
```

---

### $health-cards-issue

The `$health-cards-issue` operation creates a SMART Health Card containing the patient's health data as a verifiable credential. This operation generates a digitally signed JWT that packages the patient's FHIR data according to the [SMART Health Cards specification](https://spec.smarthealth.cards/).

The operation always uses the patient's complete data set (equivalent to Patient/$everything), ensuring comprehensive health information is included in the credential.

**Note:**
The health card is returned as a signed JWT string within a Parameters resource, not as a raw SMART Health Card file. The JWT can be converted to a QR code or shared directly as a verifiable credential.

**Request headers**

- `Authorization` (string):
An `Authorization: Bearer` header value must be presented with a [Patient Access Token](https://www.flexpa.com/records#patient-access-token)

**Request path parameters**

- `id` (string):
The identifier of the patient - use `$PATIENT_ID` to automatically reference the authenticated patient

**Request body**

- `resourceType` (string):
Must be `Parameters`

- `parameter` (array):
Array containing exactly one parameter object

  - `name` (string):
Must be `credentialType`

  - `valueUri` (string):
Must be `Patient/$everything` (currently the only supported credential type)

**Response fields**

- `Response` (Parameters):
Returns FHIR Parameters resource containing the SMART Health Card

  - `parameter` (array):
Array containing exactly one parameter object

    - `name` (string):
Will be `verifiableCredential`

    - `valueString` (string):
The signed SMART Health Card as a JWT string

*Request*

```bash
ACCESS_TOKEN=patient-access-token

curl 'https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$health-cards-issue' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{
    "resourceType": "Parameters",
    "parameter": [
      {
        "name": "credentialType",
        "valueUri": "Patient/$everything"
      }
    ]
  }'
```

```js
const ACCESS_TOKEN="patient-access-token"

const response = await fetch("https://api.flexpa.com/fhir/Patient/$PATIENT_ID/$health-cards-issue", {
  method: 'POST',
  headers: {
    "content-type": "application/json",
    "authorization": `Bearer ${ACCESS_TOKEN}`,
  },
  body: JSON.stringify({
    resourceType: "Parameters",
    parameter: [
      {
        name: "credentialType",
        valueUri: "Patient/$everything"
      }
    ]
  })
});

const result = await response.json();
```

```json
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "credentialType",
      "valueUri": "Patient/$everything"
    }
  ]
}
```

```json
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "verifiableCredential",  
      "valueString": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsImtpZCI6IjNLZmRnLVh3UC03Z..."
    }
  ]
}
```
