$validate

Introduction

The tool introduced by FHIR to provide a separate validation mechanism for 2-steps commit workflow or for development needs. It works for create, update and delete operations, is called using ?mode= query parameter with values create, update, delete but changes won't be committed. Instead a requester will get an OperationOutcome with information about validation results. See http://hl7.org/fhir/resource-operation-validate.html for the official documentation.
1
#FHIR format endpoint:
2
POST /fhir/<resourceType>/$validate
3
POST /fhir/<resourceType>/<id>/$validate
4
​
5
#Aidbox format endpoint:
6
POST /<resourceType>/$validate
7
POST /<resourceType>/<id>/$validate
Copied!
Such requests check the resource structure, internal business rules and return a list of problems if some exist.
200 OK β€” those requests always return status 200 Success and failure of a validation request is determined by id of OperationOutcome resource. allok and validationfail are self-descriptive.
$validate supports two ways to pass arguments:
By FHIR spec it receives a Parameters resource as a body:
1
POST .../$validate
2
​
3
resourceType: Parameters
4
parameter:
5
- name: mode
6
value: {string: <mode>}
7
- name: profile
8
value: {uri: <StructureDefinition.url>}
9
- name: esource
10
resource: <resource>
11
​
Copied!
Parameters are specified in query string; body is the resource to validate:
1
POST .../$validate?mode=<mode>&profile=<StructureDefinition.url>
2
​
3
<resource>
Copied!
Parameter
Description
resourceType
Required. Type of the resource which needs validation
id
Optional for mode=create. Can either be passed in the resource body or be specified in the route params
resource
Optional for mode=delete, required otherwise. Resource to be validated
mode
Optional. Default is create. Possible values are create, update, delete, patch
profile
Optional. Can be passed multiple times. Used to validate with specific profiles. Value should be StructureDefinition.url of the profile defined as zen schema​
mode
Description
create
Ignores errors about attributesid & lastUpdated being required
update
Validates without ignoring errors about attributesid & lastUpdated
delete
Checks if resource with such id exists in Aidbox
patch
Merges the existing resource to the received resource and then validates as update.
Patching strategy will be determined as described here​
merge-patch
simple deep merge semantics (read more in RFC)
json-patch
advanced JSON transformation (read more in RFC)

Examples

Validation Success

Request contains valid Patient resource inside the body.
1
# Request:
2
POST /fhir/Patient/$validate?mode=create
3
​
4
name: [{given: [John]}]
5
​
6
# Response
7
HTTP 200 OK
8
​
9
id: allok
10
resourceType: OperationOutcome
11
issue:
12
- {severity: informational, code: informational, diagnostics: all ok}
Copied!
Request contains same valid Patient resource and passed as Parameters.
1
# Request:
2
POST /fhir/Patient/$validate
3
​
4
resourceType: Parameters
5
parameter:
6
- name: mode
7
value: {string: create}
8
- name: resource
9
resource: {name: [{given: [John]}]}
10
​
11
​
12
# Response
13
HTTP 200 OK
14
​
15
id: allok
16
resourceType: OperationOutcome
17
issue:
18
- {severity: informational, code: informational, diagnostics: all ok}
Copied!

Validation Failure

Patient name must be an array, test is a non-existing field.
1
# Request:
2
POST /fhir/Patient/$validate?mode=create
3
​
4
name: "Bob"
5
test: "foo"
6
​
7
# Response
8
HTTP 200 OK
9
​
10
id: validationfail
11
resourceType: OperationOutcome
12
text: {status: generated, div: Invalid resource}
13
issue:
14
- severity: fatal
15
code: invalid
16
expression: [Patient.name]
17
diagnostics: expected array
18
- severity: fatal
19
code: invalid
20
expression: [Patient.test]
21
diagnostics: extra property
22
​
Copied!
Request contains same invalid Patient resource and passed as Parameters.
1
# Request:
2
POST /fhir/Patient/$validate?mode=create
3
​
4
name: "Bob"
5
test: "foo"
6
​
7
# Response
8
HTTP 200 OK
9
​
10
resourceType: Parameters
11
parameter:
12
- name: mode
13
value: {string: create}
14
- name: resource
15
resource: {name: Bob, test: foo}
Copied!
Last modified 6mo ago