Skip to content
HL7 FHIR Based Secure Data Repository
Scala Java Other
Branch: master
Clone or download

README.md

onFHIR FHIR Repository

onFHIR is a FHIR compliant secure health data repository that you can use as a central data service for your FHIR compliant healthcare applications. You can use it as a standalone server, or you can extend it with your further custom FHIR Operations to build your own application layer in addition to having standart FHIR repository capabilities. onFhir.io is using FHIR Infrastructure Resource definitions (CapabilityStatement, StructureDefinition, SearchParameter, etc) to tailor the FHIR server to your specific FHIR capabilities you required; resource profiles, search parameters, FHIR interactions you wanted to support.
It is implemented with Scala, based on Akka and MongoDB.

Basic Configuration

You can copy and update onfhir-core/src/main/resources/application.conf file, which is the entrypoint configuration to configure onFHIR repository based on your needs.

For logger configurations, check onfhir-core/src/main/resources/logback.xml

For configuration of the FHIR API to be provided, you need to provide the followings;

  • A file providing your Conformance statement (FHIR Capability Statement - See http://hl7.org/fhir/capabilitystatement.html) that describes the capabilities of the FHIR server you want to provide
  • A folder including all your Profile definitions (FHIR StructureDefinition - See http://hl7.org/fhir/structuredefinition.html) including resource, data type and extension definitions that will be used in the FHIR server you want to provide
  • A folder including all your Compartment definitions (FHIR CompartmentDefinition - See http://hl7.org/fhir/2016Sep/compartmentdefinition.html) for all compartments that you want to support for search
  • A folder including all your Search parameter definitions (FHIR SearchParameter - See http://hl7.org/fhir/searchparameter.html) for all extra search parameters (apart from what is available from the base FHIR standard) that you define and support for your resources
  • A folder including all your Value sets (FHIR ValueSet - See http://hl7.org/fhir/valueset.html) that you define and refer in your resource profiles
  • A folder including all your Operation definitions (FHIR OperationDefinition - http://hl7.org/fhir/operationdefinition.html) that you define and refer from capability statement in operations part (For your OperationDefinitions write the full class path of your implementation of operation in OperationDefinition.name)

You can also provide the zip file for FHIR base definitions (Validation package - 'validation-min.xml.zip') that you want to support specifically. Currently all versions are supported and we created a module for each version that have specific standard definitions and special configurators.

  • DSTU2 >> onfhir-server-dstu2
  • STU3 >> onfhir-server-stu3
  • R4 >> onfhir-server-r4

Prerequisites

onFHIR requires a MongoDB database up and running. If you do not use the given docker containers, the MongoDB configuration parameters (host, port, dbname etc.) should be passed to onFHIR through either application.conf file or as runtime parameters. The parameter names can be seen in the provided application.conf file.

Build & Run

You need to run the below command to build fhir-repository. This will compile your code, execute unit tests and create a single standalone jar with all the dependencies:

$ mvn package

Unit tests may take some time, so you can add -DskipTests=true command line parameter to the above command to skip the test execution but it is not recommended:

$ mvn package -DskipTests=true

Executable standalone jars target/fhir-repository-standalone.jar will be created under each onfhir-server for different FHIR version. Executing the following command will run the onRHI server for that version with nearly whole FHIR capabilities.

$ java -jar target/fhir-repository-standalone.jar

You can override in-app configurations by supplying an external application.conf file or JAVA arguments using the following commands:

$ java -Dconfig.file={path-to-application.conf} -jar target/fhir-repository-standalone.jar
$ java -Dserver.port=9999 -Dserver.host=172.17.0.1 -jar target/fhir-repository-standalone.jar

Extensibility

You can develop your own FHIR compliant backend application based on onFHIR. In order to do this you can import the corresponding server module as dependency to your project and write a scala App (Boot) that initiates onFHIR with a custom configuration. Onfhir.scala is the main entrypoint to the project. The following is the default server Boot configuration for onfhir-server-r4. It initiates a FHIR R4 server with the given configurations.

object Boot extends App {
  //Initialize onfhir for R4
  var onfhir = Onfhir.apply(new R4Configurator())
  //Start it
  onfhir.start
}

You can extend the onFHIR by implementing certain custom mechanisms;

  • Custom Authorizer (Implementing io.onfhir.authz.IAAuthorizer interface): In default(if you configure), onFHIR supports the authorization mechanism defined in SmartOnFhir initiative which is based on OAuth2.0 Bearer Token based authorization. If you need a custom authorization mechanism with different set of scopes (permissions), you can implement a authorizer module and register it to onFHIR.
  • Custom Token Resolver (Implementing io.onfhir.authz.ITokenResolver interface): onFHIR supports two default token resolution methods; Signed JWT tokens and OAuth2.0 Token Introspection. You can use them by configurations or implement a new module.
  • Custom Audit Handler (Implementing io.onfhir.audit.ICustomAuditHandler): In default, you can configure onFHIR to store FHIR AuditEvent records to its own local repository, or a remote FHIR server running as a seperate audit repository. If you want to create audit events/logs in different format and send them to a custom audit repository (ElasticSearch+Kibana, etc), you can extend this interface with your module and register it.
  • Further FHIR Operations: You can implement custom FHIR Operations by extending io.onfhir.api.service.FHIROperationHandlerService and preparing an OperationDefinition file for onFhir configuration while setting
    the class path of your module to the OperationDefinition.name parameter.
  • External Akka Routes: You can also implement non-FHIR REST services for your server and register them to onFHIR.
object Boot extends App {
  //Initialize onfhir for R4
  var onfhir = 
     Onfhir.apply(
        fhirConfigurator = new R4Configurator(),
        customAuthorizer = new MyAuthorizer(),
        customAuditHandler = new MyAuditHandler(),
        externalRoutes = ...my non-fhir routes 
     )
  //Start it
  onfhir.start
}

Docker

We also provide a simple docker setup for onFHIR under 'docker' folder. It provides a docker-compose file with two containers; one for MongoDB database and one for onFHIR application. You can run it with our sample onFHIR setup given with 'sample-setup' directory. You can copy the 'onfhir-standalone.jar' file to this sample-setup directory and run the sample setup as it is with the following command;

$ cd docker
$ cp ../onfhir-server-r4/target/onfhir-standalone.jar ./sample-setup/.
$ docker-compose -f docker-compose.yml -p onfhir up -d

Then you will be able to send requests to this running instance over your docker machine. The following will return the CapabilityStatement

$ curl http://127.0.0.1:8080/fhir/metadata

Tests

fhir-repository uses specs2 for unit testing. To execute tests for each build with the following command:

$ mvn test
You can’t perform that action at this time.