Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Commit

Permalink
NMA-681(Added mediator config file)
Browse files Browse the repository at this point in the history
  • Loading branch information
Collin-jehonia committed Nov 8, 2022
1 parent e410140 commit cb6fd9c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ CMD npm start

RUN npm install -g sequelize-cli

EXPOSE 4000
EXPOSE 7000

VOLUME [ "/app/node_modules" ]
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ services:
# volumes:
# - ./default.json:/usr/share/nginx/html/config/default.json

mpi-emr-mediator:
container_name: mpi_emr_mediator
build:
./
emr-mpi-mediator:
container_name: emr-mpi-mediator
ports:
- "127.0.0.1:7000:7000"
build:
./
restart: unless-stopped

volumes:
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"express": "^4.18.2",
"node-fetch": "^2.0.0",
"nodemon": "^2.0.20",
"openhim-mediator-utils": "^0.2.4",
"request": "^2.88.2",
"xhr2": "^0.2.1"
}
Expand Down
30 changes: 30 additions & 0 deletions src/config/mediator-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"urn": "urn:mediator:emr-mpi-mediator",
"version": "1.0.0",
"name": "EMR Endpoint Mediator",
"description": "This mediator is intended sending request to sante mpi mediator",
"defaultChannelConfig": [{
"name": "EMR Endpoint Mediator",
"urlPattern": "^/emr-mpi-mediator$",
"routes": [{
"name": "EMR Endpoint Mediator Route",
"host": "emr-mpi-mediator",
"path": "/",
"port": "7000",
"primary": true,
"type": "http"
}],
"allow": ["admin"],
"methods": ["GET", "PATCH","POST","PUT"],
"type": "http"
}],
"endpoints": [{
"name": "EMR Endpoint Mediator Endpoint",
"host": "emr-mpi-mediator",
"path": "/",
"port": "7000",
"primary": false,
"type": "http"
}],
"configDefs": []
}
21 changes: 17 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
const express = require("express");
const router = require("./routes");
const privateConfig = require("./config/private-config.json");
const { getQueryParameters } = require('./openHIM/initialize.js');

const config = require("./config/private-config.json")
//openHIM
getQueryParameters();

const app = express();

app.use('/', router);
// app.use('/', router);
app.use('/',router, async (req, res) => {
// Starts when a new request is triggered by the polling channel
res.status(res.statusCode).send(res.body);
console.log(`\n---------------------------------------------------------------------------------`,
`\n${new Date().toUTCString('en-GB', { timeZone: 'UTC' })} - `,
`The EMR Endpoint Mediator has received a new request. \n`
);
});

app.listen(7000, ()=> {
console.log(`Server is listening on port ${config.appConfig.PORT}`);
//Server PORT
app.listen(privateConfig.appConfig.PORT, (err) => {
if (err) console.log(`Error: ${err}`)
console.log(`${privateConfig.appConfig.mediatorName} listening on port ${privateConfig.appConfig.PORT}... \n`);
})
41 changes: 41 additions & 0 deletions src/openHIM/initialize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const privateConfig = require('../config/private-config.json');
const mediatorConfig = require('../config/mediator-config.json');

// OpenHIM
const { registerMediator, activateHeartbeat, fetchConfig } = require('openhim-mediator-utils');
let queryParams;
const openhimVars = privateConfig.openhimConfig;
const openhimConfig = {
username: openhimVars.username,
password: openhimVars.password,
apiURL: openhimVars.apiURL,
trustSelfSigned: true,
urn: mediatorConfig.urn
}
const emitter = activateHeartbeat(openhimConfig);

registerMediator(openhimConfig, mediatorConfig, err => {
if (err) {
throw new Error(`Failed to register mediator. Check your Config. ${err}`)
}
});

fetchConfig(openhimConfig, (err, initialConfig) => {
if (err) {
throw new Error(`Failed to fetch initial config. ${err}`)
}
console.log('Initial Config: ', JSON.stringify(initialConfig))
queryParams = initialConfig.labResultsParams
});

emitter.on('error', err => {
console.error('Heartbeat failed: ', err)
});

emitter.on('config', newConfig => {
console.log('Received updated config:', JSON.stringify(newConfig))
queryParams = newConfig.labResultsParams
});

function getQueryParameters() { return queryParams }
module.exports = { getQueryParameters, queryParams };

0 comments on commit cb6fd9c

Please sign in to comment.