Custom Operations Tutorial
This tutorial guides you through the process of adding custom operations to a Smile CDR FHIR Repository. If your operations do not require an underlying FHIR Repository, you should consider using a Hybrid Providers REST Endpoint Module instead.
This tutorial adds two operations to a Smile CDR FHIR Repository:
/$process-message
operationPatient/id/$calculate-y2k-age
operation1. Install Smile CDR
Install Smile CDR either from a tarball or using Docker.
2. Build and Install the Custom Operations Demo Project
Download and unzip the cdr-consent-demoproject using one of the links below.
Make any desired changes to the example custom operations in src/main/java/com/example/resourceprovider/CustomOperations.java
. E.g. you could add new @Operation
methods or change the logic in the existing methods. See the HAPI FHIR documentation for more details on how to define new FHIR operations.
Now build the project and install the interceptor jar file in your smilecdr/customerlib directory.
cd cdr-persistence-custom-operations-demoproject
mvn clean install
target/cdr-persistence-custom-operations-demoproject-*.jar path/to/smilecdr/customerlib
2. Start Smile CDR
Start Smile CDR by running the following command:
$ bin/smilecdr start
3. Access the Web Admin Console
Access the Web Admin Console by navigating to the following URL in your web browser:
http://localhost:9100
Log in with the default credentials "admin", "password".
4. Give the Anonymous User FHIR Client Superuser Permissions
Since this is just a testing sandbox, we will ignore security considerations for now and just give the anonymous user FHIR Client supseruser permissions.
Navigate to Users & Authorization
User Management
.
Click on Edit
next to the ANONYMOUS
user.
Enable the FHIR Client (Superuser) permission (ROLE_FHIR_CLIENT_SUPERUSER).
Click Save User
.
5. Configure the FHIR Endpoint to Use the Custom Operations
Navigate to Configuration
Module Config
.
Click on fhir_endpont
on the left-hand side.
In the Resource Providers
section, set Resource Provider Bean Types
to com.example.customoperations.CustomOperations
.
Click Save
.
Click Restart
to restart the FHIR Endpoint module.
6. Test /$process-message
Using a REST client like Bruno or Postman, test the custom operations.
POST /$process-message?async=false
Content-Type: application/fhir+json
{
"resourceType": "Bundle",
"id": "INPUT-TEST-BUNDLE-ID",
"type": "message",
"entry": [
{
"resource": {
"resourceType": "Patient",
"name": [
{
"given": [
"Toody"
]
}
]
}
}
]
}
The response will look something like this:
{
"resourceType": "Bundle",
"id": "OUTPUT-TEST-BUNDLE-ID"
}
6. Test $process-message
Start by creating a new patient resource:
PUT /Patient/sally-field
Content-Type: application/fhir+json
{
"resourceType": "Patient",
"id": "sally-field",
"birthDate": "1946-11-06"
}
Now test the custom operation:
GET /Patient/sally-field/$calculate-y2k-age
This should produce the following response:
{
"resourceType": "Parameters",
"parameter": [ {
"name": "y2k-age",
"valueInteger": 53
} ]
}
You are about to leave the Smile Digital Health documentation and navigate to the Open Source HAPI-FHIR Documentation.