diff --git a/README.md b/README.md new file mode 100644 index 0000000..9d447b7 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# DHIS2 Mediator +This mediator is intended to send api request to dhis2 server + +# Private Configurations +The `private-config.json` is used to store all the credentials and connection URLs of the mediator. The credentials are currently left out, so the file needs to be renamed with all the required credentials and URLs before installation for the mediator to work. + +# Installation + + +# Running in Localhost + +To run the mediator without connecting it to the OpenHIM server, you can use the following commands if you have `Node.js` installed: + +1. `cd dhis2-mediator` + +2. `npm install` + +3. `npm start` + +# Running in Docker + +The mediator can be built and run using the `docker-compose.yml` file configurations. + +1. Navigate to `dhis2-mediator` folder where the `docker-compose.yml` is. + +2. `docker-compose build` + +3. `docker-compose up -d` + +4. `docker network create openHIM` + diff --git a/src/dhis2/pushData.js b/src/dhis2/pushData.js index 01dfd72..d01bb73 100644 --- a/src/dhis2/pushData.js +++ b/src/dhis2/pushData.js @@ -6,6 +6,7 @@ const multer = require("multer"); const fastcsv = require("fast-csv"); const csv = require('csv-parser'); const privateConfig = require('../config/private-config.json'); +var convert = require('xml-js'); const { convertArrayToCSV } = require('convert-array-to-csv'); const converter = require('convert-array-to-csv'); @@ -15,7 +16,7 @@ const converter = require('convert-array-to-csv'); //A function that takes reponse from dhis2 async function postPtrackerData(csvPath) { await dhis2.postPtrackerData(`./src/csvData/${csvPath}.csv`).then((response) => { - console.log(response.body) + console.log(convert.xml2json(response.body, { compact: true, spaces: 6 })); }).catch(error => { console.log(error) }) diff --git a/src/index.js b/src/index.js index 5bc0579..1c13eba 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,8 @@ const app = express(); const pushData = require('./dhis2/pushData'); const {getQueryParameters}= require('./openhim/initialize'); const cors = require('cors'); +var bodyParser = require('body-parser'); + app.get('/openhim', async (req, res) => { // Starts when a new request is triggered by the polling channel @@ -17,10 +19,13 @@ app.get('/openhim', async (req, res) => { res.json('PTracker data succesfully sent to DHIS2'); }).catch(error => { res.json(`Error retrieving PTracker Data: ${error}`) }) }); + //middlleware -app.use(express.json()) +//app.use(express.json()) app.use(cors()); -app.use(express.urlencoded({extended: true})) +// app.use(express.urlencoded({extended: true})) +app.use(bodyParser.json({limit: "50000000000000000mb"})); +app.use(bodyParser.urlencoded({limit: "50000000000000000mb", extended: true, parameterLimit:50000000000000000})); //routers const router = require('./routes/csvRouter')