Skip to content

Commit

Permalink
use different system URI per POS to identify internal ID. Add ability…
Browse files Browse the repository at this point in the history
… to update configurations via API
  • Loading branch information
ashaban committed Jul 15, 2021
1 parent 967774f commit ee3b3a5
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 16 deletions.
10 changes: 10 additions & 0 deletions server/config/config_cicd_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
],
"systems": {
"CRBaseURI": "http://openclientregistry.org/fhir",
"internalid": {
"uri": [
"http://health.go.ug/cr/internalid",
"http://openmrs.org/openmrs2",
"http://clientregistry.org/openmrs",
"http://clientregistry.org/dhis2",
"http://clientregistry.org/lims"
],
"displayName": "Internal ID"
},
"nationalid": {
"uri": "http://health.go.ug/cr/natioanlid",
"displayName": "National ID"
Expand Down
10 changes: 10 additions & 0 deletions server/config/config_development_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
],
"systems": {
"CRBaseURI": "http://openclientregistry.org/fhir",
"internalid": {
"uri": [
"http://health.go.ug/cr/internalid",
"http://openmrs.org/openmrs2",
"http://clientregistry.org/openmrs",
"http://clientregistry.org/dhis2",
"http://clientregistry.org/lims"
],
"displayName": "Internal ID"
},
"nationalid": {
"uri": "http://clientregistry.org/cr/natioanlid",
"displayName": "National ID"
Expand Down
10 changes: 10 additions & 0 deletions server/config/config_docker_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@
],
"systems": {
"CRBaseURI": "http://openclientregistry.org/fhir",
"internalid": {
"uri": [
"http://health.go.ug/cr/internalid",
"http://openmrs.org/openmrs2",
"http://clientregistry.org/openmrs",
"http://clientregistry.org/dhis2",
"http://clientregistry.org/lims"
],
"displayName": "Internal ID"
},
"nationalid": {
"uri": "http://health.go.ug/cr/natioanlid",
"displayName": "National ID"
Expand Down
10 changes: 10 additions & 0 deletions server/config/config_production_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
],
"systems": {
"CRBaseURI": "http://openclientregistry.org/fhir",
"internalid": {
"uri": [
"http://health.go.ug/cr/internalid",
"http://openmrs.org/openmrs2",
"http://clientregistry.org/openmrs",
"http://clientregistry.org/dhis2",
"http://clientregistry.org/lims"
],
"displayName": "Internal ID"
},
"nationalid": {
"uri": "http://clientregistry.org/cr/natioanlid",
"displayName": "National ID"
Expand Down
10 changes: 10 additions & 0 deletions server/config/config_test_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
],
"systems": {
"CRBaseURI": "http://openclientregistry.org/fhir",
"internalid": {
"uri": [
"http://health.go.ug/cr/internalid",
"http://openmrs.org/openmrs2",
"http://clientregistry.org/openmrs",
"http://clientregistry.org/dhis2",
"http://clientregistry.org/lims"
],
"displayName": "Internal ID"
},
"nationalid": {
"uri": "http://clientregistry.org/cr/natioanlid",
"displayName": "National ID"
Expand Down
42 changes: 42 additions & 0 deletions server/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const prerequisites = require('./prerequisites');
const medUtils = require('openhim-mediator-utils');
const jwt = require('jsonwebtoken');
const fs = require('fs');
const async = require('async');
const https = require('https');
const cacheFHIR = require('./tools/cacheFHIR');
const generalMixin = require('./mixins/generalMixin');
Expand Down Expand Up @@ -127,6 +128,47 @@ function appRoutes() {
app.use('/csv', csvRoutes);
app.use('/config', configRoutes);

app.post('/updateConfig', (req, res) => {
let configsPath;
try {
configsPath = JSON.parse(req.body);
} catch (err) {
configsPath = req.body;
}
const env = process.env.NODE_ENV || 'development';
const configFile = `${__dirname}/../config/config_${env}.json`;
const configData = require(configFile);
async.eachSeries(configsPath, (configPath, nxt) => {
let path = Object.keys(configPath)[0];
let value = Object.values(configPath)[0];
config.set(path, value);
setNestedKey(configData, path.split(":"), value, () => {
return nxt();
});
}, () => {
if(!configData) {
return res.status(500).send();
}
fs.writeFile(configFile, JSON.stringify(configData, 0, 2), (err) => {
if (err) {
logger.error(err);
return res.status(500).send(err);
}
logger.info('Done updating config file');
return res.status(200).send();
});
});

function setNestedKey (obj, path, value, callback) {
if (path.length === 1) {
obj[path] = value;
return callback();
}
setNestedKey(obj[path[0]], path.slice(1), value, () => {
return callback();
});
}
});
return app;
}

Expand Down
4 changes: 3 additions & 1 deletion server/lib/mixins/generalMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ const getClientDisplayName = (clientid) => {
};

const getClientIdentifier = (resource) => {
const internalIdURI = config.get("systems:internalid:uri");
const validSystem = resource.identifier && resource.identifier.find(identifier => {
return 'http://openclientregistry.org/fhir/sourceid' && identifier.value;
return internalIdURI.includes(identifier.system) && identifier.value;
});
return validSystem;
};

const setNestedKey = (obj, path, value, callback) => {
if (path.length === 1) {
obj[path] = value;
Expand Down
23 changes: 13 additions & 10 deletions server/lib/mixins/matchMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,17 +994,17 @@ const addPatient = (clientID, patientsBundle, callback) => {
display: clientName
});
}
// const internalIdURI = config.get("systems:internalid:uri");
// if (!internalIdURI || internalIdURI.length === 0) {
// operSummary.outcome = '8';
// operSummary.outcomeDesc = 'URI for internal id is not defined on configuration files';
// logger.error('URI for internal id is not defined on configuration files, stop processing patient');
// operationSummary.push(operSummary);
// return nxtPatient();
// }
const internalIdURI = config.get("systems:internalid:uri");
if (!internalIdURI || internalIdURI.length === 0) {
operSummary.outcome = '8';
operSummary.outcomeDesc = 'URI for internal id is not defined on configuration files';
logger.error('URI for internal id is not defined on configuration files, stop processing patient');
operationSummary.push(operSummary);
return nxtPatient();
}

const validSystem = newPatient.resource.identifier && newPatient.resource.identifier.find(identifier => {
return identifier.system === sourceIdURI && identifier.value;
return internalIdURI.includes(identifier.system) && identifier.value;
});
if (!validSystem) {
operSummary.outcome = '4';
Expand Down Expand Up @@ -1045,13 +1045,14 @@ const addPatient = (clientID, patientsBundle, callback) => {
}
fhirWrapper.saveResource({
resourceData: bundle,
}, (err) => {
}, (err, body) => {
if (err) {
operSummary.outcome = '8';
operSummary.outcomeDesc = 'An error occured while saving a bundle that contians matches of a submitted resource and the submitted resource itself';
operationSummary.push(operSummary);
return nxtPatient();
}
responseBundle.entry = responseBundle.entry.concat(body.entry);
operSummary.what = newPatient.resource.resourceType + '/' + newPatient.resource.id;
if (config.get("matching:tool") === "elasticsearch") {
cacheFHIR.fhir2ES({
Expand Down Expand Up @@ -1140,10 +1141,12 @@ const addPatient = (clientID, patientsBundle, callback) => {
hasHumanAdjudTag: adjudTag,
operSummary
}, (err) => {
console.log('here');
if (err) {
operationSummary.push(operSummary);
return nxtPatient();
}
console.log('here1');
fhirWrapper.saveResource({
resourceData: bundle,
}, (err, body) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/sampleSinglePatient.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
}]
},
"identifier": [{
"system": "http://openclientregistry.org/fhir/sourceid",
"value": "sourceid11"
"system": "http://clientregistry.org/openmrs",
"value": "sourceid17"
}, {
"system": "http://health.go.ug/cr/nationalid",
"value": "228374844"
Expand Down
6 changes: 3 additions & 3 deletions ui/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ module.exports = {
host: "localhost",
proxy: {
"/ocrux": {
target: "http://localhost:3000",
target: "https://localhost:3000",
secure: false,
changeOrigin: true
},
"/fhir": {
target: "http://localhost:3000",
target: "https://localhost:3000",
secure: false,
changeOrigin: true
},
"/tmp": {
target: "http://localhost:3000",
target: "https://localhost:3000",
secure: false,
changeOrigin: true
}
Expand Down

0 comments on commit ee3b3a5

Please sign in to comment.