Profiling with AidboxProfile
Create a profile with AidboxProfile and validate data
For custom profiling, Aidbox provides additional resource AidboxProfile. This resource specifies resource type and JSON Schema which validates the specified resource type.

AidboxProfile Resource Structure

bind

The bind element is of the type Reference. It specifies the resource type which the profile will be applied to.
Example: Binding to Practitioner resource.
YAML
JSON
1
bind:
2
id: Practitioner # Target resource type "Practitoner"
3
resourceType: Entity
Copied!
1
{
2
"bind": {
3
"id": "Practitioner",
4
"resourceType": "Entity"
5
}
6
}
Copied!

schema

It's a plain JSON Schema object which validates a resource.
Example: Require the name attribute
YAML
JSON
1
schema:
2
type: object
3
required:
4
- name
Copied!
1
{
2
"schema": {
3
"type": "object",
4
"required": ["name"]
5
}
6
}
Copied!

Examples

Require Properties

Let's validate newly created Patient resources by specifying that name and gender properties are required. First, we need to create the appropriate AidboxProfile resource.
Request YAML
Request JSON
Response
1
POST /AidboxProfile
2
​
3
resourceType: AidboxProfile
4
id: custom-patient-constraint
5
bind:
6
id: Patient
7
resourceType: Entity
8
schema:
9
type: object
10
required:
11
- name
12
- gender
Copied!
1
POST [base]/AidboxProfile
2
​
3
{
4
"resourceType": "AidboxProfile",
5
"id": "custom-patient-constraint",
6
"bind": {
7
"id": "Patient",
8
"resourceType": "Entity"
9
},
10
"schema": {
11
"type": "object",
12
"required": [
13
"name",
14
"gender"
15
]
16
}
17
}
Copied!
1
STATUS: 201
2
{
3
"bind": {
4
"id": "Patient",
5
"resourceType": "Entity"
6
},
7
"schema": {
8
"required": [
9
"name",
10
"gender"
11
]
12
},
13
"id": "custom-patient-constraint",
14
"resourceType": "AidboxProfile",
15
"meta": {
16
"lastUpdated": "2018-10-10T14:45:43.801Z",
17
"versionId": "2",
18
"tag": [{
19
"system": "https://aidbox.io",
20
"code": "created"
21
}
22
]
23
}
24
}
Copied!
If you are using Aidbox.Dev below 0.3.1 version, then after creating an AidboxProfile resource, you will need to restart your Aidbox.Dev server.
$ docker-compose down && docker-compose up -d
Now, let's try to create a Patient resource without name and/or gender . You will receive the error.
Request YAML
Request JSON
Response
1
POST /Patient
2
​
3
resourceType: Patient
4
birthDate: '1985-01-11'
Copied!
1
POST [base]/Patient
2
​
3
{
4
"resourceType": "Patient",
5
"birthDate": "1985-01-11"
6
}
Copied!
1
STATUS: 422
2
​
3
{
4
"resourceType": "OperationOutcome",
5
"errors": [{
6
"path": [],
7
"message": "Property name is required",
8
"profile": {
9
"id": "custom-patient-constraint",
10
"resourceType": "AidboxProfile"
11
}
12
}, {
13
"path": [],
14
"message": "Property gender is required",
15
"profile": {
16
"id": "custom-patient-constraint",
17
"resourceType": "AidboxProfile"
18
}
19
}
20
],
21
"warnings": []
22
}
Copied!

Require Nested Properties

Let's require given and family elements of the name property. In this case, we are expecting that name attribute of the type HumanName will contain elements given and family. Let's create the AidboxProfile resource with the code below. Then you will need to restart server if you're on Aidbox.Dev.
Request YAML
Request JSON
Response
1
POST /AidboxProfile
2
​
3
resourceType: AidboxProfile
4
id: custom-patient-constraint
5
bind:
6
id: Patient
7
resourceType: Entity
8
schema:
9
type: object
10
required:
11
- name
12
properties:
13
name:
14
type: array
15
minItems: 1
16
items:
17
type: object
18
required:
19
- given
20
- family
21
properties:
22
given:
23
type: array
24
minItems: 1
25
items:
26
type: string
27
family:
28
type: string
Copied!
1
POST [base]/AidboxProfile
2
​
3
{
4
"resourceType": "AidboxProfile",
5
"id": "custom-patient-constraint",
6
"bind": {
7
"id": "Patient",
8
"resourceType": "Entity"
9
},
10
"schema": {
11
"type": "object",
12
"required": [
13
"name"
14
],
15
"properties": {
16
"name": {
17
"type": "array",
18
"minItems": 1,
19
"items": {
20
"type": "object",
21
"required": [
22
"given",
23
"family"
24
],
25
"properties": {
26
"given": {
27
"type": "array",
28
"minItems": 1,
29
"items": {
30
"type": "string"
31
}
32
},
33
"family": {
34
"type": "string"
35
}
36
}
37
}
38
}
39
}
40
}
41
}
Copied!
1
STATUS: 201
2
​
3
{
4
"bind": {
5
"id": "Patient",
6
"resourceType": "Entity"
7
},
8
"schema": {
9
"type": "object",
10
"required": [
11
"name"
12
],
13
"properties": {
14
"name": {
15
"type": "array",
16
"items": {
17
"type": "object",
18
"required": [
19
"given",
20
"family"
21
],
22
"properties": {
23
"given": {
24
"type": "array",
25
"items": {
26
"type": "string"
27
},
28
"minItems": 1
29
},
30
"family": {
31
"type": "string"
32
}
33
}
34
},
35
"minItems": 1
36
}
37
}
38
},
39
"id": "custom-patient-constraint",
40
"resourceType": "AidboxProfile",
41
"meta": {
42
"lastUpdated": "2018-10-11T09:47:18.147Z",
43
"versionId": "12",
44
"tag": [{
45
"system": "https://aidbox.io",
46
"code": "created"
47
}
48
]
49
}
50
}
Copied!
Now, on the Patient resource creation we will be receiving the validation error. Let's try to create a Patient resource without a family name. You will receive the error.
Request YAML
Request JSON
Response
1
POST /Patient
2
​
3
name:
4
- text: John Malcovich
5
given:
6
- John
Copied!
1
POST [base]/Patient
2
​
3
{
4
"name": [
5
{
6
"text": "John Malcovich",
7
"given": [
8
"John"
9
]
10
}
11
]
12
}
Copied!
1
STATUS: 422
2
​
3
{
4
"resourceType": "OperationOutcome",
5
"errors": [
6
{
7
"path": [
8
"name",
9
0
10
],
11
"message": "Property family is required",
12
"profile": {
13
"id": "custom-patient-constraint",
14
"resourceType": "AidboxProfile"
15
}
16
}
17
],
18
"warnings": []
19
}
Copied!