LiveBundle Rule Definition
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.
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.
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);
}
A LiveBundle watchlist holds subscribers of a certain type. It is created as follows:
LiveBundleWatchlist.create(system, name, subscriberType)
Parameter | Type | Description |
---|---|---|
system | String | System identifier for the Watchlist. Used to manage subscribers and assigned to Filters. |
name | String | Name identifier for the Watchlist. Used to manage subscribers and assigned to Filters. |
subscriberType | String | the type of resource references that are stored on this watchlist |
A LiveBundle rule defines aggregation rules. It is created as follows:
LiveBundleRule.create()
.setFilter(filter)
.setKeeper(keeper)
.setSeedCount(seedCount)
.setRuleToken(system, name);
Parameter | Type | Description |
---|---|---|
filter | LiveBundleFilter | The LiveBundle Filter |
keeper | LiveBundleKeeper | The LiveBundle Keeper |
seedCount | Integer | When a subscriber is added, how many root resources to seed the bundle with |
system | String | System identifier used to request LiveBundles for this rule |
name | String | Name identifier used to request LiveBundles for this rule |
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);
Parameter | Type | Description |
---|---|---|
rootResourceType | String | The type of resource this filter watches for |
criteria | String | The criteria used to match incoming resources. These must be search criteria that can be evaluated in-memory |
pathToSubscriber | String | The path used to find the subscriber reference in the root resource |
system | String | System identifier of the Watchlist used by this rule |
name | String | Name identifier of the Watchlist used by this rule |
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.
The Keeper assigned to a LiveBundle rule decides which references to keep. See LiveBundle Keepers for details.