Skip to main content

FHIR Data Model

ChartChat uses FHIR R4 as its data model, stored in the Medplum FHIR server. All patient data — conditions, medications, lab results, visits, etc. — is stored as standard FHIR resources. ChartChat extends the base spec with a small set of custom resource types for platform-specific data.


Standard FHIR Resources Used

ResourceUsed for
PatientPatient demographics, identity
ConditionDiagnoses, problem list
AllergyIntoleranceAllergy records
MedicationRequestMedication orders
ObservationLab results, vitals, survey responses
DiagnosticReportLab reports grouping Observations
EncounterClinic visits
ImmunizationVaccination records
ProcedureSurgical and procedural history
DocumentReferenceClinical notes, uploaded documents
CarePlanCare plans
AppointmentScheduled appointments
PractitionerTreating physicians
OrganizationHealthcare organizations
CoverageInsurance coverage
BinaryRaw file attachments (PDFs, images)

Custom FHIR Resources

ChartChat adds custom resource types on top of the standard spec. These are defined in packages/definitions/ and built into @medplum/definitions. The npm-published version does not include them — the local build must be used at runtime (see Deployment).

PatientEHRConnection

Tracks a patient's active OAuth connection to an external EHR system.

FieldTypeDescription
patientReference(Patient)The ChartChat patient
ehrProviderstringEHR key (epic, healow, meditech) or HospitalIntegration UUID
externalPatientIdstringPatient's ID in the external EHR
fhirBaseUrlstringThe EHR's FHIR R4 base URL
accessTokenstringEncrypted OAuth access token
refreshTokenstringEncrypted OAuth refresh token (if provided)
tokenExpiresAtdateTimeWhen the access token expires
connectedAtdateTimeWhen the connection was established
statuscodeactive | revoked | token_expired
connectionTypecodeAlways SMART

HospitalIntegration

Represents a hospital or health system configured in the Admin Portal for EHR connections.

FieldTypeDescription
namestringDisplay name
ehrVendorcodeEHR vendor (epic, healow, meditech)
fhirBaseUrlstringThe hospital's FHIR R4 base URL
redirectUristringOAuth redirect URI override
scopestringOAuth scope override
enabledbooleanWhether this integration is active

SSOIntegration

Stores an SSO provider configuration for a specific identity provider (Microsoft, Google, custom OIDC).

FieldTypeDescription
namestringDisplay name
authorizeUrlstringOAuth2 authorization endpoint
tokenUrlstringOAuth2 token endpoint
clientIdstringOAuth2 client ID
clientSecretstringOAuth2 client secret
useSubjectbooleanUse sub claim as user identifier

ChatMessage

Stores a single AI chat message in the Member Portal.

FieldTypeDescription
patientReference(Patient)Owner of the message
sessionIdstringGroups messages into a conversation
rolecodeuser or assistant
contentstringMessage text
intentcodeDetected intent: lab, medications, condition, visits, allergies, general
timestampdateTimeWhen the message was sent

SupportTicket

A support request submitted by a patient via the Member Portal.

FieldTypeDescription
patientReference(Patient)Patient who submitted the ticket (optional — anonymous if absent)
namestringSubmitter display name
emailstringSubmitter email
phonestringSubmitter phone (optional)
categorycodetechnical-issue | health-details | general-inquiry | feedback
descriptionstringFull description of the request
statuscodeunresolved | pending | resolved
prioritycodelow | medium | high
internalNotesstringAdmin-only notes (not shown to patient)
createdAtdateTimeWhen the ticket was submitted

SupportTicketMessage

A single message in a support ticket thread (admin replies only).

FieldTypeDescription
ticketReference(SupportTicket)The parent ticket
bodystringMessage content
sendercodeAlways admin
senderNamestringDisplay name of the admin who replied
createdAtdateTimeWhen the message was sent

PatientNotification

An in-app notification for a Member Portal patient. Created by the server (support events) or the client (EHR sync results). See Notifications for the full architecture.

FieldTypeDescription
patientReference(Patient)Notification recipient
typecodeehr_expired | sync_complete | sync_partial | sync_failed | support_reply | support_status_changed
titlestringShort heading shown in the bell drawer
messagestringBody text
readbooleanfalse until patient reads or dismisses
sentdateTimeCreation timestamp
actionLabelstringOptional CTA button label
actionPathstringOptional client-side route for the CTA

FHIR Search Parameters

ChartChat adds custom search parameters for its custom resource types. They are defined in packages/definitions/src/fhir/r4/search-parameters-medplum.json and must be rebuilt via Admin → Super Admin → Rebuild SearchParameters after updates.

Key custom search parameters:

ParameterResourceTypeDescription
patientPatientEHRConnectionreferenceSearch by patient
ehr-providerPatientEHRConnectiontokenSearch by EHR key or hospital ID
external-patient-idPatientEHRConnectiontokenSearch by EHR-side patient ID
statusPatientEHRConnectiontokenFilter by connection status
patientChatMessagereferenceSearch by patient
session-idChatMessagetokenSearch by session
patientSupportTicketreferenceSearch by patient
statusSupportTickettokenFilter by ticket status
categorySupportTickettokenFilter by category
prioritySupportTickettokenFilter by priority
created-atSupportTicketdateFilter by creation date
ticketSupportTicketMessagereferenceSearch messages by parent ticket
patientPatientNotificationreferenceSearch by patient
readPatientNotificationtokenFilter by read status
typePatientNotificationtokenFilter by notification type
sentPatientNotificationdateFilter by creation timestamp

Access Policies

Access to FHIR resources is controlled by AccessPolicy resources attached to each ProjectMembership.

RolePolicy
PatientdefaultPatientAccessPolicy — read their own FHIR resources, write to ChatMessage
AdminFull access to all resources in the project
System (server)Uses systemRepo — bypasses all access policies for internal operations

See Auth → defaultPatientAccessPolicy for setup details.


PHI Audit Middleware

All FHIR reads are tracked by the PHI audit middleware (fhir/phi-audit-middleware.ts). Each read generates an AuditEvent resource. The breach detection system monitors these events for unusual access patterns.