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

Commit

Permalink
NMA-653-Added Function to send past 3 months from the current date on…
Browse files Browse the repository at this point in the history
… the DB mediator for DHIS2
  • Loading branch information
Collin-jehonia committed Nov 2, 2022
1 parent 4d9456f commit 0b56885
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`

3 changes: 2 additions & 1 deletion src/dhis2/pushData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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)
})
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit 0b56885

Please sign in to comment.