Module health.fhir.templates.international401.device
ballerinax/health.fhir.templates.international401.device Ballerina library
FHIR Device API Template
This Ballerina-based template implementation provides a RESTful FHIR API for managing Device
resources, adhering to the FHIR R4 specification. The API is designed to support CRUD operations International FHIR R4 Device FHIR API.
Module/Element | Version |
---|---|
FHIR version | r4 |
Implementation Guide | http://hl7.org/fhir |
Profile URL | http://hl7.org/fhir/StructureDefinition/Device |
Note: If you are having FHIR profiles from regional or custom implementation guides, you can use the Ballerina Health tool to generate the FHIR API templates for the FHIR profiles. For more information, see the Ballerina Health tool.
- Ballerina (2201.10.2 or later)
- VSCode as the IDE and install the required vscode plugins
- Ballerina (https://marketplace.visualstudio.com/items?itemName=WSO2.ballerina)
- Ballerina Integrator (https://marketplace.visualstudio.com/items?itemName=WSO2.ballerina-integrator)
bal new -t healthcare/health.fhir.r4.international401.device DeviceAPI
Run the Ballerina project created by the service template by executing:
bal run
Once successfully executed, the listener will be started at port 9090
. Then, you can invoke the service using the following curl command:
curl http://localhost:9090/fhir/r4/Device
Now, the service will be invoked and return an OperationOutcome
, until the code template is implemented completely.
Note: This template is designed to be used as a starting point for implementing the FHIR API. The template is not complete and will return an
OperationOutcome
until the code is implemented.
GET /fhir/r4/Device/{id}
- Response: Returns a
Device
resource or anOperationOutcome
if not found.
GET /fhir/r4/Device/{id}/_history/{vid}
- Response: Returns a specific historical version of a
Device
resource.
GET /fhir/r4/Device
- Response: Returns a
Bundle
containing matchingDevice
resources.
POST /fhir/r4/Device
- Request Body:
Device
resource. - Response: Returns the created
Device
resource.
PUT /fhir/r4/Device/{id}
- Request Body: Updated
Device
resource. - Response: Returns the updated
Device
resource.
PATCH /fhir/r4/Device/{id}
- Request Body: JSON Patch object.
- Response: Returns the updated
Device
resource.
DELETE /fhir/r4/Device/{id}
- Response: Returns an
OperationOutcome
indicating success or failure.
GET /fhir/r4/Device/{id}/_history
- Response: Returns a
Bundle
of historical versions of theDevice
resource.
GET /fhir/r4/Device/_history
- Response: Returns a
Bundle
of historical versions of allDevice
resources.
The template is designed to work as a Facade API to expose your data as in FHIR. The following are the key steps which you can follow to implement the business logic:
- Handle business logic to work with search parameters.
- Implement the source system backend connection logic to fetch data.
- Perform data mapping inside the service to align with the FHIR models.
Modify apiConfig
in the fhirr4:Listener
initialization if needed to adjust service settings.
The apiConfig
object is used to configure the FHIR API. By default, it consists of the search parameters for the FHIR API defined for the Implementation Guide. If there are custom search parameters, they can be defined in the apiConfig
object. Following is an example of how to add a custom search parameter:
searchParameters: [ .... { name: "custom-search-parameter", // Custom search parameter name active: true // Whether the search parameter is active information: { // Optional information about the search parameter description: "Custom search parameter description", builtin: false, } } ]
Following are the steps to add a custom operation to the FHIR API template:
- The
apiConfig
object is used to configure the FHIR API. By default, it consists of the operations for the FHIR API defined for the Implementation Guide. If there are custom operations, they can be defined in theapiConfig
object. Following is an example of how to add a custom operation:
operations: [ .... { name: "custom-operation", // Custom operation name active: true // Whether the operation is active information: { // Optional information about the operation description: "Custom operation description", builtin: false, } } ]
- Add the context related to the custom operation in the service.bal file. Following is an example of how to add a custom operation:
isolated resource function post fhir/r4/Device/\$custom\-operation(r4:FHIRContext fhirContext, Device procedure) returns r4:OperationOutcome|r4:FHIRError { return r4:createFHIRError("Not implemented", r4:ERROR, r4:INFORMATIONAL, httpStatusCode = http:STATUS_NOT_IMPLEMENTED); }
Additionally, If you want to have a custom profile or a combination of profiles served from this same API template, you can add them to this FHIR API template. To add a custom profile, follow the steps below:
- Add the profile type to the aggregated resource type.
- Example:
public type Device r4:Device|<Other_Device_Profile>;
- Example:
- Add the new profile URL in
api_config.bal
file. You need to add it as a string inside theprofiles
array.- Example:
profiles: ["http://hl7.org/fhir/StructureDefinition/Device", "new_profile_url"]
- Example:
This project is subject to the WSO2 Software License.