If you're using Aidbox with zen, all resources will be validated by zen, not Attributes. In this case, you should use zen profiles.
If you don't use zen, you can use Attributes.
Define new extension with Attribute
In Aidbox, you can define first-class extensions using the custom resource Attribute.
Let's create an extension definition of type Reference in the REST Console of Aidbox:
Create new extension in the Aidbox format:
PUT /Attribute/ServiceRequest.requestedOrganizationDepartmentdescription:Department in the organization that made the service requestresource: {id:ServiceRequest,resourceType:Entity}path: [requestedOrganizationDepartment]type: {id:Reference,resourceType:Entity}refers: - OrganizationextensionUrl:urn:extension:requestedOrganizationDepartment
description - string.
Attribute text description
resource - required, Reference(Entity).
Reference to a target resource type
path - required, an array of strings.
Path to a new attribute location in the target resource type
type - Reference(Entity).
Type of data stored in this attribute. It can be any primitive or complex type.
If omitted, treated asBackboneElement, i.e. a complex-type object with structure defined via other Attributes relying on this attribute in their path
isCollection - boolean.
Whether the attribute is a collection, i.e. if true sets attribute cardinality to ..*
isRequired - boolean.
Whether the attribute is required, i.e. if true sets attribute cardinality to 1..
isUnique - boolean.
Sets unique restriction on the attribute.
refers - Reference(Entity).
Only for type=Reference. Specifies to which resourceTypes this reference can refer to
extensionUrl - string.
URL which will be used to create extension element in FHIR format. If omitted, the Attribute won't be transformed into the FHIR format
Note: you can not use Attributes and zen profiles on the same resource at the same time
Use your extension
Now, you can create the ServiceRequest resource using the new attribute requestedOrganizationDepartment in the root of the resource:
Create resource in the Aidbox format:
PUT /ServiceRequest/servicerequest-with-aidbox-native-extensionsrequestedOrganizationDepartment:resourceType:Organizationdisplay:City Hospital Neurology Departmentidentifier: {system:'urn:oid:1.2.3.4.5.6.7.8',value:'456'}category:- coding: - {code:'183829003',system:'http://snomed.info/sct',display:"Refer for imaging"}authoredOn:'2020-01-18T15:08:00'resourceType:ServiceRequestrequester:resourceType:PractitionerRoledisplay:Din Morganidentifier: {value:"1760",system:'urn:oid:1.2.3.4.5.6.7.6'}priority:routinestatus:activeintent:original-orderperformer:- resourceType:Organizationdisplay:Aga Khan University Hospital Laboratoryidentifier: {value:"1514",system:'urn:oid:1.2.3.4.5.6.7.8'}subject:resourceType:Patientdisplay:Jack Black, 10.12.1941identifier: {value:'2155800871000065',system:'urn:oid:1.2.3.4.5.6.7.9'}
FHIR Format
You can get the resource in the FHIR format where our new attribute is rendered as the extension element:
Note that the URL is different:GET /fhir/ServiceRequest/
Get the resource in the FHIR format:
GET /fhir/ServiceRequest/servicerequest-with-aidbox-native-extensions
Let's create an extension of type Reference and list allowed resource types (Organization in that case) in the refers property.
managingOrganization
PUT /Attribute/ServiceRequest.managingOrganizationresourceType:Attributedescription:Organization that made the service requestresource: {id:ServiceRequest,resourceType:Entity}path: [managingOrganization]id:ServiceRequest.managingOrganizationtype: {id:Reference,resourceType:Entity}refers: - OrganizationextensionUrl:urn:extension:requestedOrganization
Extension of type Coding:
paymentType
PUT /Attribute/ServiceRequest.paymentTyperesourceType:Attributedescription:Payment type for the service request, e.g. government health insuranceid:ServiceRequest.paymentTyperesource:id:ServiceRequestresourceType:Entitypath:- paymentTypetype:id:CodingresourceType:EntityextensionUrl:urn:extension:paymentType
Create resource using these extensions:
PUT /ServiceRequest/servicerequest-with-aidbox-native-extensionsmanagingOrganization:resourceType:Organizationdisplay:City Hospitalidentifier: {value:"123",system:'urn:oid:1.2.3.4.5.6.7.8'}requestedOrganizationDepartment:resourceType:Organizationdisplay:City Hospital Neurology Departmentidentifier: {system:'urn:oid:1.2.3.4.5.6.7.8',value:'456'}paymentType: {system:'urn:CodeSystem:paymentType',code:"1",display:"Government Health Insurance"}resourceType:ServiceRequeststatus:activeintent:original-ordersubject:resourceType:Patientdisplay:Jack Black, 10.12.1941identifier: {value:'2155800871000065',system:'urn:oid:1.2.3.4.5.6.7.9'}
Get resource in the FHIR format:
GET /fhir/ServiceRequest/servicerequest-with-aidbox-native-extensions
PUT /Attribute/ServiceRequest.performerInforesourceType:Attributedescription:Information filled in by performerresource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo]id:ServiceRequest.performerInfoextensionUrl:urn:extension:performerInfo
performerInfo.performedBy
PUT /Attribute/ServiceRequest.performerInfo.performedByresourceType:Attributedescription:'Information filled in by performer: performed by ["Practitioner" "PractitionerRole" "Organization" "CareTeam" "HealthcareService" "Patient" "Device" "RelatedPerson"]'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,performedBy]id:ServiceRequest.performerInfo.performedBytype: {id:Reference,resourceType:Entity}isCollection:truerefers: - Practitioner - PractitionerRole - Organization - CareTeam - HealthcareService - Patient - Device - RelatedPersonextensionUrl:urn:extension:performerInfo.performedBy
performerInfo.actualLocationReference
PUT /Attribute/ServiceRequest.performerInfo.actualLocationReferenceresourceType:Attributedescription:'Information filled in by performer: actual location reference'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,actualLocationReference]id:ServiceRequest.performerInfo.actualLocationReferencetype: {id:Reference,resourceType:Entity}isCollection:truerefers: - LocationextensionUrl:urn:extension:performerInfo.actualLocationReference
performerInfo.requestStatus
PUT /Attribute/ServiceRequest.performerInfo.requestStatusresourceType:Attributedescription:'Information filled in by performer: request status'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,requestStatus]id:ServiceRequest.performerInfo.requestStatustype: {id:code,resourceType:Entity}enum: - draft - new - in-progress - suspended - expanded - completed - archive - cancelledextensionUrl:urn:extension:performerInfo.requestStatus
performerInfo.requestActionHistory
PUT /Attribute/ServiceRequest.performerInfo.requestActionHistoryresourceType:Attributedescription:'Information filled in by performer: request action history'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,requestActionHistory]id:ServiceRequest.performerInfo.requestActionHistoryisCollection:trueextensionUrl:urn:extension:performerInfo.requestActionHistory
performerInfo.requestActionHistory.action
PUT /Attribute/ServiceRequest.performerInfo.requestActionHistory.actionresourceType:Attributedescription:'Information filled in by performer: request action history - action'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,requestActionHistory,action]id:ServiceRequest.performerInfo.requestActionHistory.actiontype: {id:string,resourceType:Entity}extensionUrl:urn:extension:performerInfo.requestActionHistory.action
performerInfo.requestActionHistory.date
PUT /Attribute/ServiceRequest.performerInfo.requestActionHistory.dateresourceType:Attributedescription:'Information filled in by performer: request action history - date'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,requestActionHistory,date]id:ServiceRequest.performerInfo.requestActionHistory.datetype: {id:dateTime,resourceType:Entity}extensionUrl:urn:extension:performerInfo.requestActionHistory.date
performerInfo.requestActionHistory.subject
PUT /Attribute/ServiceRequest.performerInfo.requestActionHistory.subjectresourceType:Attributedescription:'Information filled in by performer: request action history - subject'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,requestActionHistory,subject]id:ServiceRequest.performerInfo.requestActionHistory.subjecttype: {id:Reference,resourceType:Entity}extensionUrl:urn:extension:performerInfo.requestActionHistory.subject
performerInfo.requestActionHistory.note
PUT /Attribute/ServiceRequest.performerInfo.requestActionHistory.noteresourceType:Attributedescription:'Information filled in by performer: request action history - note'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,requestActionHistory,note]id:ServiceRequest.performerInfo.requestActionHistory.notetype: {id:string,resourceType:Entity}extensionUrl:urn:extension:performerInfo.requestActionHistory.note
performerInfo.requestActionHistory.author
PUT /Attribute/ServiceRequest.performerInfo.requestActionHistory.authorresourceType:Attributedescription:'Information filled in by performer: request action history - author'resource: {id:ServiceRequest,resourceType:Entity}path: [performerInfo,requestActionHistory,author]id:ServiceRequest.performerInfo.requestActionHistory.authortype: {id:Reference,resourceType:Entity}extensionUrl:urn:extension:performerInfo.requestActionHistory.author
PUT /Attribute/ServiceRequest.preconditionresourceType:Attributedescription:"The condition or state of the patient, prior or during the diagnostic procedure or test, for example, fasting, at-rest, or post-operative. This captures circumstances that may influence the measured value and have bearing on the interpretation of the result."resource: {id:ServiceRequest,resourceType:Entity}path: [precondition]id:ServiceRequest.preconditiontype: {id:CodeableConcept,resourceType:Entity}isCollection:trueextensionUrl:"http://hl7.org/fhir/StructureDefinition/servicerequest-precondition"
FHIR primitive named fieldName can be extended with _fieldName field. Aidbox treats fieldName as independent from fieldName. Aidbox do not validate fields with names started with underscore.
Suppose we need to extend Patient.gender attribute with primitive type. It means, that we need to create Patient._gender attribute.
PUT /Attribute/Patient._genderpath: - _genderresource:id:PatientresourceType:Entityid:Patient._genderresourceType:Attribute
Now we can add an extension attribute into _gender attribute.
PUT /Attribute/Patient._gender.extensionpath: - _gender - extensionresource:id:PatientresourceType:Entityid:Patient._gender.extensionisCollection:truetype:id:ExtensionresourceType:EntityresourceType:Attribute
Finally, add Patient with extended gender.
PUT /Patient/p-gendergender:male_gender:extension: - valueCodeableConcept:coding: - code:code-malesystem:system-genderurl:https://example.com