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.
bind:id:Practitioner# Target resource type "Practitoner"resourceType:Entity
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.
POST /AidboxProfileresourceType:AidboxProfileid:custom-patient-constraintbind:id:PatientresourceType:Entityschema:type:objectrequired: - name - gender
POST [base]/AidboxProfile{"resourceType": "AidboxProfile","id": "custom-patient-constraint","bind": {"id":"Patient","resourceType":"Entity" },"schema": {"type":"object","required": ["name","gender" ] }}
Now, let's try to create a Patient resource without name and/or gender . You will receive the error.
POST /PatientresourceType:PatientbirthDate:'1985-01-11'
POST [base]/Patient{"resourceType": "Patient","birthDate": "1985-01-11"}
STATUS:422{"resourceType": "OperationOutcome","errors": [{"path": [],"message":"Property name is required","profile": {"id":"custom-patient-constraint","resourceType":"AidboxProfile" } }, {"path": [],"message":"Property gender is required","profile": {"id":"custom-patient-constraint","resourceType":"AidboxProfile" } } ],"warnings": []}
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.
POST /AidboxProfileresourceType:AidboxProfileid:custom-patient-constraintbind:id:PatientresourceType:Entityschema:type:objectrequired: - nameproperties:name:type:arrayminItems:1items:type:objectrequired: - given - familyproperties:given:type:arrayminItems:1items:type:stringfamily:type:string
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.
POST /Patientname:- text:John Malcovichgiven: - John
POST [base]/Patient{"name": [ {"text":"John Malcovich","given": ["John" ] } ]}
STATUS:422{"resourceType": "OperationOutcome","errors": [ {"path": ["name",0 ],"message":"Property family is required","profile": {"id":"custom-patient-constraint","resourceType":"AidboxProfile" } } ],"warnings": []}