Overview

Metriport’s Realtime Patient Notifications are your way to receive realtime updates on a patient’s journey through a health system. You can trigger a workflow once a patient is admitted to a health system, check their diagnosis within moments of them being discharged, and so much more.

Working with Realtime Patient Notifications

Webhook schema (Event Reference)

Each realtime notification we send via webhook has a payload that includes key information about the event, and a url field to JSON containing robust clinical data for the encounter.

{
  "meta": {
    "messageId": "1e82424a-1220-473d-a0d1-6e5fde15159e",
    "when": "2025-01-30T23:00:01.000Z",
    "type": "patient.admit"
  },
  "payload": {
    "url": "<presigned-download-url>",
    "patientId": "metriport-patient-uuid",
    "externalId": "your-first-party-id",
    "additionalIds": {
      "athenahealth": ["99992"]
    },
    "admitTimestamp": "2025-01-28T23:00:00.000Z"
  }
}

If you want to access the clinical data, you need only download the json from the url. To work with the data, we recommend you understand The Encounter Model below.

The URL remains valid and available for download for 600 seconds (10 minutes).

The Encounter Model

For each patient you intend to receive realtime notifications for, Metriport maintains the real-time state of their journey through the health system. Each of these patient journeys is represented via FHIR data - a FHIR Encounter.

{
  "resourceType": "Encounter",
  "status": "finished",
  "period": {
    "start": "2024-03-15T14:20:00.000Z",
    "end": "2024-03-15T16:45:00.000Z"
  },
  "reasonCode": [
    {
      "text": "Chest pain"
    }
  ],
  "location": [
    {
      "location": {
        "reference": "Location/3ca5e8d2-7c84-45ab-91e7-834f8becde12",
        "type": "Location",
        "display": "Memorial Hospital"
      }
    }
  ],
  // And much more
}

But FHIR data relies on references to function. An Encounter might reference a subject, a practitioner, or a location - as the example above does (see the reference field in location.). Each root unit of data in FHIR is called a ‘Resource’ and each of type of resource has its own corresponding schema. It’s common for resources to include references to one another.

To provide comprehensive data about the Encounter, we serve a FHIR Bundle via the url in the patient notification.

{
    "resourceType": "Bundle",
    "type": "message",
    "timestamp": "2020-05-08T13:10:15Z",
    "id": "message-uuid",
    "entry": [
      { /* a FHIR Encounter */ },
      // Other resources that are directly or transitively referenced via the FHIR encounter
      { /* Another resource */ },
      { /* Another resource */ },
      { /* Another resource */ },
      ...
    ]
}

The first item in every bundle for a Metriport’s Patient Notification is the root Encounter. Every item thereafter is a resource referenced by the Encounter. The bundle acts as a container for all resources, ensuring you have a standalone package of clinical data.

If you’re unfamiliar with FHIR, please read our FHIR Overview.

Handling Patient Notifications

We may extend the patient notification types, so we recommend that you do a strict match when checking the handler type. If using a typed language like typescript, this also allows you to typecast the payload based on the appropriate event type.

See below.

import {
  PatientAdmitPayload,
  PatientDischargePayload,
} from "@metriport/api-sdk";

if (event.meta.type === "patient.admit") {
  const payload = event.payload as PatientAdmitPayload;
  // process admit message
}
if (event.meta.type === "patient.discharge") {
  const payload = event.payload as PatientDischargePayload;
  // process discharge message
}

Event Reference

patient.admit

A Patient Admit event is emitted when a patient undergoes the admission process, assigning them a bed. It signals the official start of a patient’s stay in a healthcare facility. It includes short stay and “John Doe” (patient name unknown) admissions.

Schema

meta
required

Metadata about the message.

payload
PatientAdmitPayload
required

Example payload

{
  "meta": {
    "messageId": "1e82424a-1220-473d-a0d1-6e5fde15159e",
    "when": "2025-01-30T23:00:01.000Z",
    "type": "patient.admit"
  },
  "payload": {
    "url": "<presigned-download-url>",
    "patientId": "metriport-patient-uuid",
    "externalId": "your-first-party-id",
    "additionalIds": {
      "athenahealth": ["99992"]
    },
    "admitTimestamp": "2025-01-28T23:00:00.000Z"
  }
}

patient.discharge

A Patient Discharge event indicates the end of a patient’s stay in a healthcare facility. The patient now has the status “discharged” and an officially recorded discharge date.

Schema

meta
required

Metadata about the message.

payload
PatientDischargePayload
required

Example payload

{
  "meta": {
    "messageId": "1e82424a-1220-473d-a0d1-6e5fde15159e",
    "when": "2025-01-30T23:00:01.000Z",
    "type": "patient.discharge"
  },
  "payload": {
    "url": "<presigned-download-url>",
    "patientId": "metriport-patient-uuid",
    "externalId": "your-first-party-id",
    "additionalIds": {
      "athenahealth": ["99992"]
    },
    "admitTimestamp": "2025-01-28T23:00:00.000Z",
    "dischargeTimestamp": "2025-01-30T23:00:00.000Z"
  }
}

Additional Resources

Full FHIR Encounter

The below is an example of a full FHIR encounter

{
  "resourceType": "Encounter",
  "id": "uuid",
  "meta": {
    "extension": [
      {
        "url": "https://api.metriport.com/created-at",
        "valueInstant": "2025-03-15T16:45:10.000+00:00"
      }
    ],
    "versionId": "0.1.0"
  },
  "status": "finished",
  "period": {
    "start": "2024-03-15T14:20:00.000Z",
    "end": "2024-03-15T16:45:00.000Z"
  },
  "class": {
    "system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
    "code": "AMB",
    "display": "Ambulatory"
  },
  "serviceType": {
    "coding": [
      {
        "code": "394592004",
        "display": "Cardiology"
      }
    ],
    "text": "Cardiology"
  },
  "subject": {
    "reference": "Patient/78a4d9e5-f2b3-42c8-9a84-52f3e21c2b9d",
    "type": "Patient",
    "display": "Sarah Johnson"
  },
  "location": [
    {
      "location": {
        "reference": "Location/3ca5e8d2-7c84-45ab-91e7-834f8becde12",
        "type": "Location",
        "display": "Memorial Hospital"
      }
    }
  ],
  "participant": [
    {
      "type": [
        {
          "coding": [
            {
              "system": "http://terminology.hl7.org/CodeSystem/v3-ParticipationType",
              "code": "ATND",
              "display": "attender"
            }
          ]
        }
      ],
      "individual": {
        "reference": "Practitioner/49e3c8f1-d67a-47b8-b9a2-cf23e8d0e941",
        "type": "Practitioner",
        "display": "Dr. Maria Rodriguez"
      }
    }
  ],
  "reasonCode": [
    {
      "text": "Chest pain"
    }
  ],
  "diagnosis": [
    {
      "condition": {
        "reference": "Condition/8724f6e9-c531-48ba-9d34-7e2a81c05fb3",
        "type": "Condition",
        "display": "Stable Angina"
      },
      "use": {
        "coding": [
          {
            "system": "https://terminology.hl7.org/5.2.0/CodeSystem-v2-0052.html",
            "code": "AD",
            "display": "Final diagnosis"
          }
        ]
      },
      "rank": 1
    }
  ],
  "identifier": [
    {
      "type": {
        "coding": [
          {
            "system": "http://terminology.hl7.org/CodeSystem/v2-0203",
            "code": "VN",
            "display": "visit number"
          }
        ],
        "text": "visit number"
      },
      "value": "987654321"
    }
  ]
}