Smile CDR v2024.08.PRE
On this page:

20.2.1LiveBundle Rule Definition
Trial

 

A LiveBundle rule is configured using JavaScript. Below is an example of a LiveBundle configuration. LiveBundle searches the JavaScript for a function named buildLiveBundleRuleSet(). This function is expected to return a LiveBundleRuleSet object. A LiveBundleRuleSet contains a list of Watchlists and Rules.

20.2.2Loading Rules
Trial

 

When a LiveBundle enabled FHIR Storage module is started, the module will compile the LiveBundle JavaScript and execute the buildLiveBundleRuleSet() function. This will load Watchlists and Rules into Smile CDR so that Subscribers can be added to Watchlists and data collected for those Subscribers.

Changing the definition of a rule after it has been loaded will not change any bundles that had been previously stored for that rule. If you need to rebuild LiveBundles after changing a rule, you will need to unsubscribe and resubscribe all members of that rule's watchlist. This will rebuild all bundles for all rules that use that Watchlist.

20.2.3Example LiveBundle Javascript
Trial

 

Let's start with a fully functional buildLiveBundleRuleSet() method that defines an aggregation rule that keeps the most recent visit details for patients of a Diabetes Ward.

const EXAMPLE_SYSTEM = 'http://myorg.org/diabetes_management';

function buildLiveBundleRuleSet() {

	let ruleSet = LiveBundleRuleSet.create();

	// Add Watchlists

	ruleSet.addWatchlist(LiveBundleWatchlist.create(EXAMPLE_SYSTEM, 'PATIENT_WATCHLIST', 'Patient'));

	// Add Rules

	ruleSet.addRule(lastVisitRule());

	return ruleSet;
}

function lastVisitRule() {
	return LiveBundleRule.create()
		.setFilter(lastVisitFilter())
		.setKeeper(lastVisitKeeper())
		.setSeedCount(100)
		.setRuleToken(EXAMPLE_SYSTEM, 'LAST_VISIT');
}

function lastVisitFilter() {
	return LiveBundleFilter.create()
		.setRootResourceType('Encounter')
		.setCriteria('location=PED.DIABETES')
		.setSubscriberSearchParam('subject')
		.setWatchlistToken(EXAMPLE_SYSTEM, 'PATIENT_WATCHLIST');
}

function lastVisitKeeper() {
	// This is the path we use to determine which resource is the most recent one
	let pathToOrderDate = 'period.start';

	return LiveBundleKeeperFactory.newLatestByPath(pathToOrderDate);
}

20.2.4LiveBundle Watchlist
Trial

 

A LiveBundle watchlist holds subscribers of a certain type. It is created as follows:

LiveBundleWatchlist.create(system, name, subscriberType)
ParameterTypeDescription
systemStringSystem identifier for the Watchlist. Used to manage subscribers and assigned to Filters.
nameStringName identifier for the Watchlist. Used to manage subscribers and assigned to Filters.
subscriberTypeStringthe type of resource references that are stored on this watchlist

20.2.5LiveBundle Rule
Trial

 

A LiveBundle rule defines aggregation rules. It is created as follows:

LiveBundleRule.create()
		.setFilter(filter)
		.setKeeper(keeper)
		.setSeedCount(seedCount)
		.setRuleToken(system, name);
ParameterTypeDescription
filterLiveBundleFilterThe LiveBundle Filter
keeperLiveBundleKeeperThe LiveBundle Keeper
seedCountIntegerWhen a subscriber is added, how many root resources to seed the bundle with
systemStringSystem identifier used to request LiveBundles for this rule
nameStringName identifier used to request LiveBundles for this rule

20.2.6LiveBundle Filter
Trial

 

A LiveBundle filter chooses which incoming Root References are sent to the Keeper for aggregation.

LiveBundleFilter.create()
		.setRootResourceType(rootResourceType)
		.setCriteria(criteria)
		.setSubscriberSearchParam(pathToSubscriber)
		.setWatchlistToken(system, name); 
ParameterTypeDescription
rootResourceTypeStringThe type of resource this filter watches for
criteriaStringThe criteria used to match incoming resources. These must be search criteria that can be evaluated in-memory
pathToSubscriberStringThe path used to find the subscriber reference in the root resource
systemStringSystem identifier of the Watchlist used by this rule
nameStringName identifier of the Watchlist used by this rule

20.2.7Keeper Filters
Trial

 

Some Keepers require a Filter as one of their parameters. Keeper Filters are allowed to have any legal fhir search criteria (not just those that can be evaluated in-memory). However, to allow a Filter to call the database for it's criteria evaluation you must call keeperFilter.setDatabaseSearchAllowed(true) on that keeper filter. LiveBundle will throw an error if DatabaseSearchAllowed is set to true on a Rule Filter. This is only allowed on Keeper Filter for performance reasons.

20.2.8LiveBundle Keeper
Trial

 

The Keeper assigned to a LiveBundle rule decides which references to keep. See LiveBundle Keepers for details.