ECW Library
The ECW Library is an importable library containing functions to connect, authenticate and interact with the eCW API. This library is used in the eCW AdapterPreview.
When imported into projects, typically only the ECWclient module needs to be required in order to create the client and access the API methods.
require "ECW.ECWclient"How it works:
Use the Translator’s built in help to review how to use each function:
Sets up the ECW adapter framework, adding the various method modules to a metatable and storing the configurations added to the custom fields.
ECWcustom takes in any API requests and parameters to make the API call and return the response.
First, the function checks if the token key exists or is still valid (based on the key_expiry). If not, it calls ECWauth to perform the OAuth2.0 authentication workflow to obtain the token to be used in subsequent requests.
Uses the passed configurations API request parameters - the method (ex. post), API (ex. Patient) and parameters for the call (ex. the patient resource to be created) - to build and carry out the appropriate HTTP request.
The ECWauth function builds and makes the HTTP POST token request to obtain the access token required for any resource requests against the Server.
A separate ECWjwt function creates the JSON Header and Payload components of the JWT and calls ECWjwt to sign and return the JWT required for the token request.
If the token requests is successful (HTTP 200 response), the token and token expiry returned are stored in the adapter object (key and key_expiry) and saved in an encrypted file via ECWencrypt.
ECWencrypt provides localized ENCRYPT LibraryPreview functionality via save and load functions that encrypt and decrypt the provided API token and expiry time in an external file. This allows the token to be reused for subsequent API calls.
ECWjwt provides localized OAUTH LibraryPreview functionality. It takes the provided JWT header, JWT payload, signing algorithm, and private key to generate and sign the JWT token.
ECWcreate prepares the arguments and calls ECWcustom for an FHIR Resource Create HTTP POST request.
ECWparameters builds a parameter table template for the specified resource in the argument call.
ECWreadResourceById prepares the API endpoint and arguments to call ECWcustom for a Resource Read HTTP GET request.
ECWsearch prepares the arguments and calls ECWcustom for a Resource Search HTTP GET request.
ECWgetBulk prepares the arguments and calls ECWcustom for a Bulk Export HTTP GET request. It returns a job id that can be used with ECWcheckBulk.
ECWcheckBulk prepares the arguments and calls ECWcustom for a Bulk Export HTTP GET request. It checks the status of a bulk export job and once the job is complete, returns a list of the resource types and the download url for each resource.
ECWdownloadBulk prepares the arguments and calls ECWcustom for a Bulk Export download HTTP GET request. It takes the url returned from ECWcheckBulk to download the resource data and returns the resulting NDJSON as a list of individual JSON strings.