Changes API
Simple API to react on resource changes
Changes API can be used to get changes of resourceType or specific resource by versions. Each event (creating, updating, deleting) will increase version of the resource by 1.
Polling request is cheap! If you want to watch rare changes (minutes-hours), this API is very resource efficient (no subscriptions, no queues) and provides you lots of control. If nothing has been changed, you will get a response with status 304
, otherwise Changes API will response with a list of changes and a new version to poll next time.
Endpoints
GET /<resourceType>/$changes
— returns the latest version for the resourceType
.
GET /<resourceType>/$changes?<parameters>
— depending on parameters returns changes of the resourceType
.
GET /<resourceType>/<id>/$changes
— returns latest version of a specific resource.
GET /<resourceType>/<id>/$changes?<parameters>
— depending on parameters returns changes of the specific resource.
Query-string parameters
Below are parameters to use in both resourceType and specific resource endpoints.
version=<version>
Returns changes since the specified version
version=<lower-version>,<upper-version>
Returns changes after the lower-version
(exclusive) up to theupper-version
(inclusive)
fhir=<boolean>
If set to true
converts changes.*.resource
to the FHIR format
(note: since Changes API is not /fhir/
endpoint, the rest of the body isn't FHIR compliant)
omit-resources=<boolean>
If set to true
omits resources leaving only id
& resourceType
fields
_count
& _page
Work as described here
_total
& _totalMethod
Work as described here
With parameters which start with dot you can filter resources by equality, e.g. .name.0.family=<string>
Example
Get the latest version of the Patient resource.
Assume the latest version is 1, no changes since version 1.
Let's add 2 patients to change version of Patient resource.
Since version 1, two events happened: created 2 patients.
We can filter events by dot expressions. Filtering Patient events by family name:
Check changes happened since version 1 until version 2.
Check version of patient with id pt-1
.
Use omit-resources=true
to request only id and resourceType fields in resources.
Cache performance
Changes API uses a cache to track a resourceType last change. To build the cache it runs a query to get the max
value of the txid
column. To make this operation efficient, it is recommended to build an index on the txid
column for tables where Changes API will be used.
Use query:
Replace <resourceType> with table name, for example:
CREATE INDEX IF NOT EXISTS patient_txid_btree ON patient using btree(txid);
CREATE INDEX IF NOT EXISTS patient_history_txid_btree ON patient_history using btree(txid);
Last updated