Subscribe to new Patient resource
From this tutorial you will learn how to make Aidbox notify your service when a new Patient resource is created using Subscription module.
Aidbox subscriptions module is a way to subscribe and get notifications about updating resources on server. It introduces two new resourceTypes into Aidbox:
  • SubsSubscription — a meta-resource, which binds events (create/update/delete resource) with communication channel through which a subscriber will be notified about.
  • SubsNotification — a resource, which represents the notification with its status (sent or not).
In order to start receive notifications, you have to register your services as a subscriber in Aidbox by creating a SubsSubscription resource.
As external service to integrate Aidbox with, we will use RequestCatcher. We will use aidbox name, so the final name of our service will be https://aidbox.requestcatcher.com/. You can use your own name.
Open https://aidbox.requestcatcher.com/ in new tab, then create next SubsSubsription resource in your Aidbox instance:
1
POST /SubsSubscription
2
​
3
id: new-patient-sub
4
status: active
5
trigger:
6
Patient:
7
event: ['create']
8
channel:
9
type: rest-hook
10
endpoint: https://aidbox.requestcatcher.com/new-patient
11
timeout: 1000
12
payload:
13
content: full-resource
14
contentType: json
Copied!
After that, aidbox sends a handshake notification on channel.endpoint, which you can see on your opened tab with RequestCatcher.
Let's create a new patient then.
1
POST /Patient
2
​
3
id: john-smith
4
name:
5
- given: [John]
6
family: Smith
7
​
8
# Response: 201 Created
Copied!
Then you can back to RequestCatcher service and see a new notification.
And next, you can see SubsNotification resource created for this notification in Aidbox.
1
GET /SubsNotification?_sort=-lastUpdated
2
​
3
# Response
4
​
5
type: searchset
6
resourceType: Bundle
7
entry:
8
- resource:
9
id: 17efebc5-c4e2-4db8-b999-dd5c24b7dfc5
10
resourceType: SubsNotification
11
status: success
12
duration: 99
13
response: {body: request caught, status: 200}
14
notification:
15
type: notification
16
event: create
17
resource:
18
id: john-smith
19
name:
20
- given: [John]
21
family: Smith
22
resourceType: Patient
23
subscription: {id: new-patient-sub, resourceType: SubsSubscription}
24
# ... other notification
Copied!
If you will update your patient, then the notification will not be created, because we subscribed only for the creation of a Patient resource.
1
PUT /Patient/john-smith
2
​
3
name:
4
- given: [John]
5
family: Smith
6
gender: male
7
​
8
# Response: 200 OK
Copied!
Check RequestCatcher and SubsNotification. You will not find new notifications there.
Copy link