core.medplumclient.subscribetocriteria | Medplum

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, subscriptionProps?: Partial<Subscription>): SubscriptionEmitter;

Parameters [​](/content/docs/sdk/core.medplumclient.subscribetocriteria#parameters "Direct link to Parameters"/index.html)

Parameter Type Description
criteria string The criteria to subscribe to.
subscriptionProps Partial (Optional) Optional properties to add to the created Subscription resource.

Returns:

SubscriptionEmitter

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

Example [​](/content/docs/sdk/core.medplumclient.subscribetocriteria#example "Direct link to Example"/index.html)

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
});