CRUD
Fhirbase provides functions to Create, Read, Delete and Update resources. There are two variants of these functions: first accepts txid and second does not.

fhirbase_create (resource jsonb, [txid bigint])

This function creates or recreates a FHIR resource. When a resource with the same ID exist, it will be moved into the history table and the new resource will have recreated status. If resource argument doesn't contain an id attribute, the value returned by fhirbase_genid function will be used as an ID.
1
SELECT fhirbase_create('{"resourceType": "Patient", "id": "pt1"}'::jsonb);
2
3
> {
4
> "resourceType": "Patient",
5
> "id": "pt1",
6
> "meta": {"versionId": "90", "lastUpdated": "2018-08-11T19:33:37.845344+00:00"}
7
> }
8
9
-- without an ID
10
SELECT fhirbase_create(
11
'{"resourceType": "Patient", "name": [{"family": "Smith"}]}'::jsonb
12
);
13
14
-- with txid
15
SELECT fhirbase_create('{"resourceType": "Patient", "id": "pt2"}'::jsonb, 100);
Copied!
Last modified 3yr ago