diff --git a/server/config/config_cicd_template.json b/server/config/config_cicd_template.json index 2862e57e..6f67da7a 100644 --- a/server/config/config_cicd_template.json +++ b/server/config/config_cicd_template.json @@ -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" diff --git a/server/config/config_development_template.json b/server/config/config_development_template.json index d16599dd..de5e9ace 100644 --- a/server/config/config_development_template.json +++ b/server/config/config_development_template.json @@ -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" diff --git a/server/config/config_docker_template.json b/server/config/config_docker_template.json index 0561782d..14b48793 100644 --- a/server/config/config_docker_template.json +++ b/server/config/config_docker_template.json @@ -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" diff --git a/server/config/config_production_template.json b/server/config/config_production_template.json index d16599dd..de5e9ace 100644 --- a/server/config/config_production_template.json +++ b/server/config/config_production_template.json @@ -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" diff --git a/server/config/config_test_template.json b/server/config/config_test_template.json index d16599dd..de5e9ace 100644 --- a/server/config/config_test_template.json +++ b/server/config/config_test_template.json @@ -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" diff --git a/server/lib/app.js b/server/lib/app.js index 6e5fa613..2abeb39c 100644 --- a/server/lib/app.js +++ b/server/lib/app.js @@ -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'); @@ -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; } diff --git a/server/lib/mixins/generalMixin.js b/server/lib/mixins/generalMixin.js index 5edda387..9530dd44 100644 --- a/server/lib/mixins/generalMixin.js +++ b/server/lib/mixins/generalMixin.js @@ -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; diff --git a/server/lib/mixins/matchMixin.js b/server/lib/mixins/matchMixin.js index 1d11d70f..11f2e892 100644 --- a/server/lib/mixins/matchMixin.js +++ b/server/lib/mixins/matchMixin.js @@ -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'; @@ -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({ @@ -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) => { diff --git a/tests/sampleSinglePatient.json b/tests/sampleSinglePatient.json index 39389ffe..9136dd2b 100644 --- a/tests/sampleSinglePatient.json +++ b/tests/sampleSinglePatient.json @@ -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" diff --git a/ui/vue.config.js b/ui/vue.config.js index a6eee6fd..0d7c6e71 100644 --- a/ui/vue.config.js +++ b/ui/vue.config.js @@ -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 }