Name: fhir-flex-reference
Owner: Kinvey
Description: null
Created: 2017-12-11 19:21:48.0
Updated: 2017-12-12 16:22:10.0
Pushed: 2017-12-11 19:22:06.0
Homepage: null
Size: 12
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|---|---|
Michael Salinger | 2017-12-11 19:21:16.0 | 1 |
Other Committers
User | Most Recent Commit | # Commits |
---|
Kinvey's native API format is JSON over HTTP. Many healthcare APIs, use the FHIR standard for transmitting health-related data.
This project is a reference Flex Connector for connecting to FHIR-based APIs.
To use this connector, clone this GitHub repository, and install the associated dependencies:
DLC can either be deployed to the FlexService Runtime, or run locally. To run locally, you must have node.js
or greater. Execute:
This Flex Connector uses the following dependencies, in addition to the kinvey-flex-sdk
:
This reference connector contains sample automated tests, both unit and integration. To run the tests, execute:
verview
Flex Connector implements three methods associated with the Kinvey FlexData API:
GetAll
GetById
GetCount
service objects and handlers are defined in the `index.js` file. The handlers are loaded seperately from `lib/handlers`. This separation is done for two purposes:
to increase modularity and reusability of code
to facilitate unit testing
// Initiate the Flex SDK Service sdk.service((err, flex) => { if (err) {
console.log('Error initializing the Flex SDK, exiting.');
throw err;
}
const data = flex.data; // gets the FlexData object from the service
// Define Service Objects
const patient = data.serviceObject('Patient');
const medication = data.serviceObject('Medication');
const appointment = data.serviceObject('Appointment');
// wire up the events that we want to process
patient.onGetById(handlers.getPatientById);
patient.onGetByQuery(handlers.getPatientByQuery);
patient.onInsert(handlers.createEntity);
patient.onUpdate(handlers.updateEntity);
medication.onGetById(handlers.getMedicationById);
medication.onGetByQuery(handlers.getMedicationByQuery);
medication.onInsert(handlers.createEntity);
medication.onUpdate(handlers.updateEntity);
appointment.onGetById(handlers.getAppointmentById);
appointment.onGetByQuery(handlers.getAppointmentByQuery);
appointment.onInsert(handlers.createEntity);
appointment.onUpdate(handlers.updateEntity);
});
handlers then perform two steps for every request:
ake a request to `lib/fhir-client` for processing the FHIR call and converting the response to JSON
emove the context root and transform the result into valid Kinvey entities `transformers.js`
example, for `onGetById`, the handler makes a call to the `fhir-client`:
The FHIR Client calls the API, gets the result, and converts the result to JSON:
tion _parseResponse(err, response, item, callback) {
(err != null) {
return callback(err);
else if (response != null && response.statusCode > 299) {
return callback(response)
else {
return callback(err, item);
rts.read = function read(resource, item, callback) {
ient.read(resource, item, (err, response, item) => {
_parseResponse(err, response, item, callback);
;
Finally, the transformer is called to return the result:
tion transformEntity(entity, modules) {
(typeof entity !== 'object') {
return new Error('The entity must be an object.');
(Array.isArray(entity)) {
return new Error('Arrays are not permitted. Only a single entity may be supplied.');
(entity.id == null) {
return new Error('No id field (_id) present in the resulting entity');
(modules == null || modules.kinveyEntity == null || modules.kinveyEntity.entity == null) {
return new Error('A valid modules object must be supplied');
nst mappedEntity = modules.kinveyEntity.entity(entity);
ppedEntity._id = entity.id;
turn mappedEntity;
After transforming, we complete the flex request and return the results to the request pipeline for further processing:
rn complete().setBody(result).ok().next();