NextGen Knowledge Center

Notes on Implementation

First, note that certain interactions have been selectively enabled for certain resource types. For this example we'll only actually be implementing some interactions, so this is largely for illustration. You can enable or disable interactions as you see fit, so that the generated conformance statement will reflect that support to clients.

On the source connector settings, we also have a custom "response" variable selected. This indicates that the FhirResponse object the FHIR Listener uses will be retrieved from the response map.

Source Transformer

Here we have a single step. We use destination set filtering to decide in advance which destination to send a message to. Each destination is named according to one of the possible FHIR interactions, like "create" or "update". Because the interaction of the request will be in the "fhirInteraction" source map variable, we can use that to directly filter on destinations:
var interaction = sourceMap.get('fhirInteraction');
 
if (interaction == 'operation') {
    // Operation destinations will have a name of "$name".
    destinationSet.removeAllExcept([sourceMap.get('fhirOperationName')]);
} else if (interaction.startsWith('history')) {
    // This will match history-system, history-type, and history-instance
    destinationSet.removeAllExcept(['history']);
} else if (interaction.startsWith('search')) {
    // This will match search-system and search-type
    destinationSet.removeAllExcept(['search']);
} else {
    // All other destinations should have a name equal to the interaction
    destinationSet.removeAllExcept([interaction]);
}

Destinations

We'll look at one, the "create" destination. As the name implies, this destination will handle all create interactions that flow through the channel. It's a JavaScript Writer that will take a resource posted to the channel and store it in a database (the one you created above). The JavaScript code in the destination simply inserts the resource into the database, and uses FhirResponseFactory to create a FhirResponse object. Then it places that response into the response map, with the key "response".

The other destinations in the channel are much the same. For example the "read" destination will use similar code to select resource data from the same database table, and return the data in an appropriate FhirResponse object. The "history" and "search" destinations are a little more complex because it involves selecting multiple resources and compiling them into a Bundle resource.