Skip to content

Commit

Permalink
Merge pull request #3 from hisptz/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
waltervfaustine authored Mar 31, 2020
2 parents f23c604 + 334b84c commit b8bc705
Show file tree
Hide file tree
Showing 12 changed files with 2,948 additions and 1,408 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ files/*
node_modules
scripts
dump.js
private/
public
report.*
logs/res/*
auth.config.js
metadata.config.js
batch/*
logs/res/*
private/log/*
8 changes: 8 additions & 0 deletions .whitesource
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}
234 changes: 93 additions & 141 deletions helpers/organization-unit.js
Original file line number Diff line number Diff line change
@@ -1,179 +1,131 @@
/***
*
*/
const chalk = require('chalk');

/***
*
*/
const axios = require('axios');
const Authentication = require('../auth/system.auth');
const AuthConfig = require('../config/auth.config');
const Logger = require('../logs/logger.log');
const Utilities = require('../utils/utils');

class OrganizationUnit {
constructor() {}
/***
*
*/
class OrganizationUnitManager {
/***
*
*/
constructor() { }

getOrgunits = async (orgType, dataFromURL, isUsingLiveDhis2, system) => {
/***
*
*/
getOrgUnits = async (
mediatorConfig,
activeSystem,
activeBatch,
activeJob
) => {
const logger = new Logger();
if (system === 'ards') {
logger.printLogMessageInConsole(
'default',
'Organization units from ARDS',
system
);
return await this.getCouncilOrganizationUnits(
dataFromURL,
isUsingLiveDhis2,
system
);
} else if (system === 'nsmis') {
logger.printLogMessageInConsole(
'default',
'Organization units from NSMIS',
system
);
return await this.getCouncilOrganizationUnits(
dataFromURL,
isUsingLiveDhis2,
system
);
} else if (system === 'hmis') {
if (activeSystem) {
const dhis = 'https://dhis.moh.go.tz/';
const orgUnitParam =
mediatorConfig &&
mediatorConfig[activeSystem][activeBatch][activeJob][
'isExecuted'
] &&
mediatorConfig[activeSystem][activeBatch][activeJob].ou
.orgUnits.hasUids
? mediatorConfig[activeSystem][activeBatch][
activeJob
].ou.orgUnits.orgUnitUids
: mediatorConfig[activeSystem][activeBatch][
activeJob
].ou.orgUnits.orgUnitLevel;
const isUsingLiveDhis2 =
mediatorConfig[activeSystem].isUsingLiveDhis2;
const dataFromURL = isUsingLiveDhis2
? dhis
: mediatorConfig[activeSystem].dataFromURL;
const orgUnitUsed =
mediatorConfig[activeSystem].systemInfo.from;
logger.printLogMessageInConsole(
'default',
'Organization units from DHIS2 HMIS',
system
`Organization units loaded from ${chalk.green(
orgUnitUsed.toUpperCase()
)} system`,
activeSystem
);
return await this.getCouncilOrganizationUnits(

return await this.getOrganizationUnitsByCriteria(
dataFromURL,
isUsingLiveDhis2,
system
activeSystem,
orgUnitParam
);
} else {
if (orgType === 'council') {
return await this.getCouncilOrganizationUnits(
dataFromURL,
isUsingLiveDhis2,
system
);
} else if (orgType === 'facilities') {
return await this.getFacilitiesOrganizationUnits(
dataFromURL,
isUsingLiveDhis2,
system
);
} else {
logger.printLogMessageInConsole(
'default',
'No organization unit criterial specified i.e facilities or council'
);
}
}
};

getFacilitiesOrganizationUnits = async (
/***
*
*/
getOrganizationUnitsByCriteria = async (
dataFromURL,
isUsingLiveDhis2,
system
activeSystem,
orgUnitParam
) => {
const authenticator = new Authentication();
const logger = new Logger();
const utilities = new Utilities();
let orgunitsURL = ``;

// Organisation Unit API with Only Public Facilities
const orgunitsURL = `${dataFromURL}api/organisationUnits.json?fields=id,name,code&filter=level:eq:4&&filter=organisationUnitGroups.name:eq:Public&paging=false`;

// Organisation Unit API with All Public And Private Facilities
// const orgunitsURL = `https://hmisportal.moh.go.tz/dhis/api/organisationUnits.json?fields=id,name,code&filter=level:eq:4&paging=false`;
try {
if (isUsingLiveDhis2) {
const orgUnits = await axios.get(
orgunitsURL,
authenticator.getHMISDHIS2SuperAuth()
);
return await orgUnits.data.organisationUnits;
} else {
const orgUnits = await axios.get(
orgunitsURL,
authenticator.getSystemAuth()
);
return await orgUnits.data.organisationUnits;
}
} catch (error) {
logger.printLogMessageInConsole('error', error, system);
if (utilities.isArray(orgUnitParam)) {
orgunitsURL = `${dataFromURL}api/organisationUnits.json?fields=id,name,code&filter=id:in:${orgUnitParam}&paging=false`;
} else {
orgunitsURL = `${dataFromURL}api/organisationUnits.json?fields=id,name,code&filter=level:eq:${orgUnitParam}&paging=false`;
}
};

getCouncilOrganizationUnits = async (
dataFromURL,
isUsingLiveDhis2,
system
) => {
const authenticator = new Authentication();
const logger = new Logger();

if (system === 'ards') {
try {
const orgunitsURL = `${dataFromURL}api/organisationUnits.json?fields=id,name&filter=level:eq:3&paging=false`;
const orgUnits = await axios.get(
orgunitsURL,
authenticator.getARDSSuperAuth()
);
return await orgUnits.data.organisationUnits;
} catch (error) {
logger.printLogMessageInConsole('error', error, system);
}
} else if (system === 'nsmis') {
if (isUsingLiveDhis2) {
logger.printLogMessageInConsole(
'default',
`${chalk.green(
chalk.bold(activeSystem.toUpperCase())
)} is using the DHIS2 Platform ${chalk.blue(
chalk.bold(dataFromURL)
)}`,
activeSystem
);
try {
const orgunitsURL = `${dataFromURL}api/organisationUnits.json?fields=id,name&filter=level:eq:3&paging=false`;
const orgUnits = await axios.get(
orgunitsURL,
authenticator.getNSMISSuperAuth()
authenticator.getSystemAuth(
AuthConfig,
activeSystem
)
);
return await orgUnits.data.organisationUnits;
} catch (error) {
logger.printLogMessageInConsole('error', error, system);
}
} else if (system === 'hmis') {
if (isUsingLiveDhis2) {
logger.printLogMessageInConsole(
'default',
`IS USING PATH::: ${dataFromURL}`,
system
'error',
error,
activeSystem
);
const orgunitsURL = `${dataFromURL}api/organisationUnits.json?fields=id,name,code&filter=level:eq:3&paging=false`;
try {
const orgUnits = await axios.get(
orgunitsURL,
authenticator.getHMISDHIS2SuperAuth()
);
return await orgUnits.data.organisationUnits;
} catch (error) {
logger.printLogMessageInConsole('error', error, system);
}
}
} else {
// Organisation Unit API with Councils
const orgunitsURL = `${dataFromURL}api/organisationUnits.json?fields=id,name,code&filter=level:eq:3&paging=false`;
if (isUsingLiveDhis2) {
logger.printLogMessageInConsole(
'default',
`IS USING PATH::: ${dataFromURL}`,
system
);
try {
const orgUnits = await axios.get(
orgunitsURL,
authenticator.getSystemAuth(AuthConfig, system)
);
return await orgUnits.data.organisationUnits;
} catch (error) {
logger.printLogMessageInConsole('error', error, system);
}
} else {
try {
const orgUnits = await axios.get(
orgunitsURL,
authenticator.getHMISPortalSuperAuth()
);
return await orgUnits.data.organisationUnits;
} catch (error) {
logger.printLogMessageInConsole('error', error, system);
}
}
logger.printLogMessageInConsole(
'default',
`${chalk.green(
chalk.bold(activeSystem.toUpperCase())
)} is using the ADDRESS ${chalk.green(orgunitsURL)}`,
system
);
}
};
}

module.exports = OrganizationUnit;
module.exports = OrganizationUnitManager;
Loading

0 comments on commit b8bc705

Please sign in to comment.