|
| 1 | +# Subscriptions |
| 2 | + |
| 3 | +The FHIR Subscription resource is used to define a push-based subscription from a server to another system. |
| 4 | +Once a subscription is registered with the server, the server checks every resource that is created or updated, |
| 5 | +and if the resource matches the given criteria, it sends a message on the defined channel so that another system can take an appropriate action. |
| 6 | + |
| 7 | +FHIR Works on AWS implements Subscriptions v4.0.1: https://www.hl7.org/fhir/R4/subscription.html |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Getting Started |
| 12 | + |
| 13 | +1. As an additional security measure, all destination endpoints must be allow-listed before notifications can be delivered to them. |
| 14 | +Update [src/subscriptions/allowList.ts](src/subscriptions/allowList.ts) to configure your allow-list. |
| 15 | + |
| 16 | + |
| 17 | +2. Use the `enableSubscriptions` option when deploying the stack: |
| 18 | + |
| 19 | + ```bash |
| 20 | + serverless deploy --enableSubscriptions true |
| 21 | + ``` |
| 22 | + |
| 23 | + |
| 24 | +**Note** |
| 25 | +Enabling subscriptions incurs a cost even if there are no active subscriptions. It is recommended to only enable it if you intend to use it. |
| 26 | + |
| 27 | +## Creating Subscriptions |
| 28 | + |
| 29 | +A Subscription is a FHIR resource. Use the REST API to create, update or delete Subscriptions. |
| 30 | +Refer to the [FHIR documentation](https://www.hl7.org/fhir/R4/subscription.html#resource) for the details of the Subscription resource. |
| 31 | + |
| 32 | +Create Subscription example: |
| 33 | +``` |
| 34 | +POST <API_URL>/Subscription |
| 35 | +{ |
| 36 | + "resourceType": "Subscription", |
| 37 | + "status": "requested", |
| 38 | + "end": "2022-01-01T00:00:00Z", |
| 39 | + "reason": "Monitor new neonatal function", |
| 40 | + "criteria": "Observation?code=http://loinc.org|1975-2", |
| 41 | + "channel": { |
| 42 | + "type": "rest-hook", |
| 43 | + "endpoint": "https://my-endpoint.com/on-result", |
| 44 | + "payload": "application/fhir+json" |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +After the example Subscription is created, whenever an Observation is created or updated that matches the `criteria`, |
| 50 | +a notification will be sent to `https://my-endpoint.com/on-result`. |
| 51 | + |
| 52 | +Consider the following when working with Subscriptions: |
| 53 | + |
| 54 | +* Subscriptions start sending notifications within 1 minute of being created. |
| 55 | +* Notifications are delivered at-least-once and with best-effort ordering. |
| 56 | + |
| 57 | +## Supported Features |
| 58 | + |
| 59 | +Currently the only supported channel is **REST Hook**. |
| 60 | + |
| 61 | +If a Subscription has an `end` date, it is automatically deleted on that date. |
| 62 | + |
| 63 | +FWoA supports 2 types of notifications |
| 64 | + |
| 65 | +- **Empty notification** |
| 66 | + |
| 67 | + This kind of notification occurs for Subscriptions without a `channel.payload` defined. Example: |
| 68 | + ```json |
| 69 | + { |
| 70 | + "resourceType": "Subscription", |
| 71 | + "criteria": "Observation?name=http://loinc.org|1975-2", |
| 72 | + "channel": { |
| 73 | + "type": "rest-hook", |
| 74 | + "endpoint": "https://my-endpoint.com/on-result" |
| 75 | + } |
| 76 | + } |
| 77 | + ``` |
| 78 | + When a matching Observation is created/updated, FWoA Sends a POST request with an **empty body** to: |
| 79 | + ``` |
| 80 | + POST https://my-endpoint.com/on-result |
| 81 | + ``` |
| 82 | + |
| 83 | +- **Id-only notification** |
| 84 | + |
| 85 | + This kind of notification occurs for Subscriptions with `channel.payload` set to `application/fhir+json`. Example: |
| 86 | + ```json |
| 87 | + { |
| 88 | + "resourceType": "Subscription", |
| 89 | + "criteria": "Observation?name=http://loinc.org|1975-2", |
| 90 | + "channel": { |
| 91 | + "type": "rest-hook", |
| 92 | + "payload": "application/fhir+json", |
| 93 | + "endpoint": "https://my-endpoint.com/on-result" |
| 94 | + } |
| 95 | + } |
| 96 | + ``` |
| 97 | + When a matching Observation is created/updated, FWoA Sends a PUT request with an **empty body** to: |
| 98 | + ``` |
| 99 | + PUT https://my-endpoint.com/on-result/Observation/<matching ObservationId> |
| 100 | + ``` |
| 101 | + **Note** |
| 102 | + The Id-only notifications differ slightly from the FHIR spec. |
| 103 | + The spec indicates that the entire matching FHIR resource is sent in JSON format, but we chose to only send the Id since |
| 104 | + sending the entire resource poses a security risk. |
0 commit comments