Skip to main content

core.medplumclient.subscribetocriteria

Home > @medplum/core > MedplumClient > subscribeToCriteria

MedplumClient.subscribeToCriteria() method

Subscribes to a given criteria, listening to notifications over WebSockets.

This uses Medplum's WebSocket Subscriptions under the hood.

A SubscriptionEmitter is returned from this function, which can be used to listen for updates to resources described by the given criteria.

When subscribing to the same criteria multiple times, the same SubscriptionEmitter will be returned, and a reference count will be incremented.

-----

Signature:

subscribeToCriteria(criteria: string): SubscriptionEmitter;

Parameters

ParameterTypeDescription
criteriastringThe criteria to subscribe to.

Returns:

SubscriptionEmitter

a SubscriptionEmitter that emits Bundle resources containing changes to resources based on the given criteria.

Example

const emitter = medplum.subscribeToCriteria('Communication');

emitter.addEventListener('message', (bundle: Bundle) => {
// Called when a `Communication` resource is created or modified
console.log(bundle?.entry?.[1]?.resource); // Logs the `Communication` resource that was updated
});