Skip to content

Commit

Permalink
adding multitenancy support
Browse files Browse the repository at this point in the history
  • Loading branch information
ashaban committed Mar 23, 2021
1 parent 3c41a16 commit 64d0afa
Show file tree
Hide file tree
Showing 15 changed files with 839 additions and 637 deletions.
Binary file modified dhis2App/GOFR.zip
Binary file not shown.
26 changes: 7 additions & 19 deletions facility-recon-backend/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
"port": 3000
},
"mCSD": {
"url": "http://localhost:8081/hapi5/fhir",
"username": "",
"password": "",
"fakeOrgId": "eac583d2-d1ba-11e8-a8d5-f2801f1b9fd1",
"fakeOrgName": "Taifafeki",
"cacheTime": 1200
"cacheTime": 1200,
"registryDB": "facilityregistry",
"requestsDB": "facilityregistryrequests"
},
"dbArchives": {
"maxArchives": 2
Expand Down Expand Up @@ -108,22 +113,5 @@
}, {
"uri": "http://codesystem.digitalhealth.intrahealth.org/facilityaddrequest",
"name": "facilityAddRequest"
}],
"hapi": {
"DBUser": "hapi",
"DBPassword": "hapi",
"defaultDBName": "gofr_empty",
"requestsDBName": "gofrrequests_empty",
"fhirVersion": "R4",
"DBDependencyGrpID": "org.postgresql",
"DBDependencyArtfactID": "postgresql",
"DBDriver": "org.postgresql.Driver",
"DBDialect": "org.hibernate.dialect.PostgreSQL95Dialect",
"serverStarterPath": "/home/ally/hapi-fhir-jpaserver-starter",
"tomcatPath": "/opt/tomcat"
},
"pg": {
"user": "gofr",
"password": "gofr"
}
}]
}

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

7 changes: 4 additions & 3 deletions facility-recon-backend/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ if (ops && ops.conf) {
const environment = nconf.get('NODE_ENV') || 'development';
nconf.file('environment', path.resolve(`${global.appRoot}/config`, `${environment}.json`));
nconf.file('default', path.resolve(`${global.appRoot}/config`, 'default.json'));
// nconf.file('custom', path.resolve(`${global.appRoot}/config`, 'default_multiple_instances.json'))
}

if (ops && ops.createIndexes) {
Expand All @@ -48,12 +47,14 @@ function setConf(key, value) {
}

setConf('DB_HOST', process.env.DB_HOST || 'localhost');
setConf('DB_NAME', process.env.DB_NAME || 'GOFR_NEW1');
setConf('DB_NAME', process.env.DB_NAME || 'GOFR');
setConf('DB_USER', process.env.DB_USER || '');
setConf('DB_PASSWORD', process.env.DB_PASSWORD || '');
setConf('DB_PORT', process.env.DB_PORT || '27017');
setConf('REDIS_HOST', process.env.REDIS_HOST || '127.0.0.1');
setConf('mCSD:url', process.env.HEARTH_URL || 'http://localhost:8081');
if (process.env.FHIR_BASE_URL) {
setConf('mCSD:url', process.env.FHIR_BASE_URL);
}
setConf('server:port', process.env.GOFR_PORT || getConf('server:port'));

exports.getConf = getConf;
Expand Down
3 changes: 0 additions & 3 deletions facility-recon-backend/lib/cronjobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const config = require('./config');
const dhis = require('./dhis')();
const fhir = require('./fhir')();

const topOrgId = config.getConf('mCSD:fakeOrgId');
const topOrgName = config.getConf('mCSD:fakeOrgName');

function getCrontime(callback) {
Expand Down Expand Up @@ -63,7 +62,6 @@ getCrontime((time) => {
name,
sourceOwner,
clientId,
topOrgId,
topOrgName,
false,
false,
Expand All @@ -79,7 +77,6 @@ getCrontime((time) => {
name,
sourceOwner,
clientId,
topOrgId,
topOrgName,
);
}
Expand Down
8 changes: 4 additions & 4 deletions facility-recon-backend/lib/dhis.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const credentials = {

module.exports = function () {
return {
sync(host, username, password, name, sourceOwner, clientId, topOrgId, topOrgName, reset, full, dousers, doservices) {
sync(host, username, password, name, sourceOwner, clientId, topOrgName, reset, full, dousers, doservices) {
const dhis2URL = url.parse(host);
const auth = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
credentials.dhis2URL = dhis2URL;
credentials.clientId = clientId;
credentials.auth = auth;
credentials.name = name;
credentials.sourceOwner = sourceOwner;
credentials.topOrgId = topOrgId;
credentials.topOrgId = mixin.getTopOrgId(name + sourceOwner);
credentials.topOrgName = topOrgName;

if (reset) {
Expand Down Expand Up @@ -237,7 +237,7 @@ function processOrgUnit(metadata, hasKey) {
clientId,
} = credentials;

const database = mixin.toTitleCase(name) + credentials.sourceOwner;
const database = mixin.toTitleCase(name + credentials.sourceOwner);
let counter = 0;
const max = metadata.organisationUnits.length;
// adding the fake orgid as the top orgid
Expand Down Expand Up @@ -446,7 +446,7 @@ function setLastUpdate(hasKey, lastUpdate) {
dhis2URL,
} = credentials;
const userID = credentials.sourceOwner;
const database = mixin.toTitleCase(name) + userID;
const database = mixin.toTitleCase(name + userID);
winston.info('setting lastupdated time');
const req = (dhis2URL.protocol == 'https:' ? https : http).request({
hostname: dhis2URL.hostname,
Expand Down
Loading

0 comments on commit 64d0afa

Please sign in to comment.