FHIRbase API

FHIRbase API is just a set of simple PostgreSQL stored procedures. You can use those functions in select statement. To make fhirbase-plv8 work you have to just after opening connection to postgresql you have to issue command:

SET plv8.start_proc = 'plv8_init';
Work with storage
fhir_create_storage

Create storage for new resource

SELECT fhir_create_storage('{"resourceType": "Patient"}');

fhir_drop_storage

Delete resource storage

SELECT fhir_drop_storage('{"resourceType": "Patient"}');

fhir_truncate_storage

Delete all resources of specified type

SELECT fhir_truncate_storage('{"resourceType": "Patient"}');

Create
fhir_create_resource

Create new FHIR resource

SELECT fhir_create_resource('{"resource": {"resourceType": "Patient", "name": [{"given": ["Smith"]}]}}');

Read
fhir_read_resource

Read resource by id

SELECT fhir_read_resource('{"resourceType": "Patient", "id": "smith"}');

Update
fhir_update_resource

Update specific resource

SELECT fhir_update_resource('{"resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["John"], "family": ["Smith"]}]}}');

Conditional update

SELECT fhir_update_resource('{"ifNoneExist": "identifier=007", "resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["Smith"]}]}}');

Update with contention guard

SELECT fhir_update_resource('{"ifMatch": "..versionid..", "resource": {"resourceType": "Patient", "id": "smith", "name": [{"given": ["Smith"]}]}}');

Delete
fhir_delete_resource

Mark resource as deleted (i.e. keep history)

SELECT fhir_delete_resource('{"resourceType": "Patient", "id": "smith"}');

fhir_terminate_resource

Completely delete resource and its history

SELECT fhir_terminate_resource('{"resourceType": "Patient", "id": "smith"}');

History
fhir_vread_resource

Read specific version of resource

SELECT fhir_vread_resource('{"resourceType": "Patient", "id": "????", "versionId": "????"}');

fhir_resource_history

Show resource history

SELECT fhir_resource_history('{"resourceType": "Patient", "id": "smith"}');

fhir_resource_type_history

Show resource history by resourceType

SELECT fhir_resource_type_history('{"resourceType": "Patient", "queryString": "_count=2&_since=2015-11"}');

Index
fhir_index_parameter

Index by parameter name

SELECT fhir_index_parameter('{"resourceType": "Patient", "name": "name"}');

fhir_unindex_parameter

Unindex by parameter name

SELECT fhir_unindex_parameter('{"resourceType": "Patient", "name": "name"}');

Expand ValueSet
fhir_valueset_expand

Expand ValueSet

SELECT fhir_valueset_expand('{"id": "issue-types", "filter": "err"}');

Conformance
fhir_conformance

Return simple Conformance resource, based on created stores

SELECT fhir_conformance('{"default": "values"}');