Aidbox and FHIR formats
Aidbox stores FHIR resources almost as is with 2 types of isomorphic transformations:
- References
- Union (Choice Types)
References:
In FHIR, references are represented as URI string. In most cases, you are interested in discrete parts of references like resource id and type. For performance and accuracy reasons Aidbox parses reference and stores its parts in discrete fields. There are three types of references - absolute, relative, and local. Aidbox parses them into different attributes.
Relative (interpreted as a reference to a resource on the same server; trigger referential consistency check) :
# FHIR
subject:
reference: "Patient/pt-1"
# Aidbox
subject:
resourceType: "Patient"
id: "pt-1"
reference is parsed into a pair of {id,resourceType} attributes
Absolute (interpreted as a reference to an external resource; no ref validation)
# FHIR
subject:
reference: "http://external/fhir/Patient/pt-1"
# Aidbox
subject:
uri: "http://external/fhir/Patient/pt-1"
reference is parsed into the uri attribute
Local (interpreted as a local ref to contained resources )
# FHIR
subject:
reference: "#pt"
# Aidbox
subject:
localRef: "pt"
reference is parsed into a localRef attribute
Union (Choice) Types:
Some elements can have multiple types. Such elements in FHIR spec prefixed with [x] like Observation.value[x] and represented in JSON in a wrong (postfixed) way likeObservation.valueString . The simple logical check "why it's wrong" is "you could not have a collection of union elements in FHIR JSON!". Aidbox fixes this moving type as a key inside a nested object - valueString:... => value: {string: ...}
#FHIR
resourceType: Observation
valueQuantity:
unit: ...
value: ...
# becomes Aidbox
resourceType: Observation
value:
Quantity:
unit: ...
value: ...
Turn off the Aidbox format API
Available since the 2610 release.
Aidbox serves two REST APIs:
- the FHIR API under
/fhir(for exampleGET /fhir/Patient), which takes and returns FHIR format; - the Aidbox format API outside
/fhir(for exampleGET /Patient), which takes and returns Aidbox format.
The Aidbox format API stores a request body without the FHIR to Aidbox conversion. If you send a FHIR resource there, Aidbox stores subject: {reference: "Patient/pt-1"} as is, and the search GET /fhir/Observation?subject=Patient/pt-1 doesn't find the resource.
To make Aidbox accept data through the FHIR API alone, set BOX_FHIR_AIDBOX_FORMAT_API_ENABLED to false:
BOX_FHIR_AIDBOX_FORMAT_API_ENABLED: false
Aidbox reads the setting from the environment at startup. Restart Aidbox to change it.
Endpoints that turn off
With false, the Aidbox format endpoints answer 404 with <METHOD> <path> not found. Send these requests to the FHIR API:
| Aidbox format API | FHIR API |
|---|---|
/<type>, /<type>/<id>: create, read, update, patch, delete, search | /fhir/<type>, /fhir/<type>/<id> |
GET /<type>/_history, GET /<type>/<id>/_history | GET /fhir/<type>/_history, GET /fhir/<type>/<id>/_history |
POST / with a batch or transaction Bundle | POST /fhir |
POST /$sql | POST /fhir/$sql |
GET /metadata | GET /fhir/metadata |
POST /$validate, POST /<type>/$validate | POST /fhir/$validate, POST /fhir/<type>/$validate |
GET /Patient/<id>/$everything | GET /fhir/Patient/<id>/$everything |
GET /Observation/$lastn | GET /fhir/Observation/$lastn |
GET /$export, GET /Patient/$export, GET /Group/<id>/$export | GET /fhir/$export, GET /fhir/Patient/$export, GET /fhir/Group/<id>/$export |
POST /$import, POST /v2/$import | POST /fhir/$import, POST /v2/fhir/$import |
POST /$load, POST /<type>/$load | POST /fhir/$load, POST /fhir/<type>/$load |
POST /terminology/$import | POST /fhir/terminology/$import |
POST /Mapping/<id>/$apply | POST /fhir/Mapping/<id>/$apply |
POST /$drop-cache | POST /fhir/$drop-cache |
/Organization/<org-id>/aidbox/<type> (organization-based access control) | /Organization/<org-id>/fhir/<type> |
These endpoints have no /fhir counterpart and keep working with false:
POST /rpc;GET /<type>/$dump,GET /<type>/$dump-csvandPOST /$dump-sql;GET /<type>/$changes;GET /$query/<name>andPOST /$query/<name>(AidboxQuery);POST /$psqlandPOST /$to-format/<format>.
Move to the FHIR API
Before you set false, check the clients, policies and configuration resources that call the Aidbox format API:
-
Requests. Add the
/fhirprefix:PUT /Client/my-appbecomesPUT /fhir/Client/my-app. -
Request bodies. Write them in FHIR format:
subject: {reference: "Patient/pt-1"}instead ofsubject: {resourceType: Patient, id: pt-1},valueStringinstead ofvalue: {string: ...}. To convert an Aidbox format resource, send it toPOST /$to-format/fhir. -
AccessPolicy
uripatterns. Amatchopolicy withuri: /Patientdoesn't matchGET /fhir/Patient. Rewrite the pattern with the prefix:engine: matcho matcho: uri: '#^/fhir/Patient' request-method: get -
Mappings. Use
/fhir/<type>URLs in therequest.urlof the transaction a Mapping returns. Aidbox routes each entry like a separate request, sourl: /Patient/pt-1answers404withfalseand$applyfails. HL7 v2 messages that use such a mapping end withstatus: error.
Fix references stored without conversion
To find resources that the Aidbox format API stored with FHIR references, query the reference element with $sql:
POST /fhir/$sql
Content-Type: application/json
["SELECT id FROM observation WHERE resource #>> '{subject,reference}' IS NOT NULL"]
To fix a resource, read it with GET /fhir/Observation/<id> and send the same body back with PUT /fhir/Observation/<id>. Aidbox converts the references on write, and the search by subject finds the resource.