Sample Plugin Code

BioT provides a sample JavaScript and Python Plugin code that describes the steps needed in plugin development.
The code is available free under the MIT license and can be browsed here.

Prerequisites

To pack and deploy the sample, you require to installed on your machine:

Download the Code

The sample code is available in both JavaScript and Python.

To download the code, make sure you have GIT installed and execute the following command from our command line:

git clone https://github.com/biot-med/plugin-lambda-seed-public.git
git clone https://github.com/biot-med/plugin-lambda-seed-python-public.git

Next download the dependencies and you should be ready to go.
Instructions of how to do so are in the read-me of each repository.

Basic Plugin Flow

The following boilerplate functions should be executed before the code can be executed:
(You may change them as required)

  • extractDataFromEvent - Extracts the data and metadata from the event.
  • getTraceId - Get a trace ID from the event (or fallback to a trace ID from a BioT service). The trace ID is used for better logging traceability.
  • configureLogger - Create new logs format (including a traceId).
  • authenticate - Authenticate the token sent by the notification service.
  • login - Login to BioT (using a service user) and get a token.
  • perform - An example of the different event types.
  • response - Send response (see errorResponseCreator for error responses).

extractDataFromEvent

A helper function that obtains the raw JSON data from the event.

getTraceId

The trace ID is a unique ID string that is set in the header of each API call and saved to the log. Using this unique ID allows us to trace the whole flow of the call, in case of a problem, beginning with the plugin and going through all the API calls that the plugin made, and any internal API calls made by the platform until the plugin response.

configureLogger

This function prepares the log structure for a well-structured log that will enable easy searching when needed.

authenticate

This function validates the JWT token received from BioT to ensure the call originated from the platform and not from any unauthorized origin.

login

Before making an API call to BioT the plugin needs to obtain a new JWT token using the service user credentials.

perform

According to the event type, the demo plugin maps the event to the appropriate event handler.
Under the src folder, a specific handler was written to each event type:

Notification handler from "./notification/index.js"
Interceptor Post from "./interceptorPost/index.js"
Interceptor Pre from "./interceptorPre/index.js"
Interceptor Post Entity from "./interceptorPostEntity/index.js"

Check the appropriate code for each plugin type for an example on how to handle the event and how to make API calls.

response

The response depends on the plugin and should be updated according to your business logic.

Deploy the Plugin

You will need to zip the source code before deploying it.
Instructions of how to do so are in the readme of each repository.

To deploy the code, refer to Custom Plugin Deployment.

Test Your Plugin

Now register your Plugin as a Notification or Interceptor and verify that it works.