All resource types in Aidbox are stored in different tables, named with a lowercased resource type name. All these tables have a similar schema:
CREATE TABLE "patient" (id text PRIMARY KEY, // id of resourcetxid bigint not null, // version id and logical transaction idts timestamptz DEFAULT NOW(), // last updated timeresource_type text, // resource typestatus resource_status not null, // resource statusresource jsonb not null // resource body);
You use the DB Console to explore the database:
select * from "entity" limit 10
As you can see, resources are stored as JSONB documents in the resource column.
Resources are stored in Aidbox JSON format, which is more friendly for storage, and converted into FHIR in REST API on the fly!
You can access attributes of resources using PostgreSQL JSON functions:
SELECTresource#>>'{name,0,famly}' as last_name,resource#>>'{name,0,given,0}' as first_nameFROM "patient"LIMIT 10
You can define and expose over REST API sophisticated queries in SQL on FHIR data using Custom Queries.
Check out our video tutorial about SQL on FHIR in PostgreSQL:
​