Skip to content

Commit

Permalink
removing restrictions on uploaded facility code, generate uuid based …
Browse files Browse the repository at this point in the history
…on uploaded facility code
  • Loading branch information
ashaban committed Jun 5, 2020
1 parent bf41380 commit b86c383
Show file tree
Hide file tree
Showing 4 changed files with 762 additions and 676 deletions.
38 changes: 19 additions & 19 deletions facility-recon-backend/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3099,24 +3099,24 @@ if (cluster.isMaster) {
populateData(headerMapping, data, 'Missing Facility ID', invalid);
rowMarkedInvalid = true;
}
let invalidCharsFound = false;
for (const char of data[headerMapping.code]) {
if (char === '.' || char === '-') {
continue;
}
if (char === '_') {
invalidCharsFound = true
break
}
let validate = /^\w+$/.test(char)
if (!validate) {
invalidCharsFound = true
}
}
if (invalidCharsFound) {
populateData(headerMapping, data, 'Invalid Characters In Facility ID, allowed chars are Aa-Zz, - and .', invalid);
rowMarkedInvalid = true;
}
// let invalidCharsFound = false;
// for (const char of data[headerMapping.code]) {
// if (char === '.' || char === '-') {
// continue;
// }
// if (char === '_') {
// invalidCharsFound = true
// break
// }
// let validate = /^\w+$/.test(char)
// if (!validate) {
// invalidCharsFound = true
// }
// }
// if (invalidCharsFound) {
// populateData(headerMapping, data, 'Invalid Characters In Facility ID, allowed chars are Aa-Zz, - and .', invalid);
// rowMarkedInvalid = true;
// }
if (!mixin.isFloat(data[headerMapping.lat]) && !mixin.isInt(data[headerMapping.lat])) {
populateData(headerMapping, data, 'Invalid Characters In latitude', invalid);
rowMarkedInvalid = true;
Expand Down Expand Up @@ -3219,4 +3219,4 @@ if (cluster.isMaster) {

server.listen(config.getConf('server:port'));
winston.info(`Server is running and listening on port ${config.getConf('server:port')}`);
}
}
181 changes: 91 additions & 90 deletions facility-recon-backend/lib/mcsd.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ module.exports = () => ({

getLocationParentsFromDB(database, entityParent, topOrg, details, callback) {
const parents = [];
if (entityParent == null
|| entityParent == false
|| entityParent == undefined
|| !topOrg
|| !database
if (entityParent == null ||
entityParent == false ||
entityParent == undefined ||
!topOrg ||
!database
) {
return callback(parents);
}
Expand Down Expand Up @@ -328,10 +328,10 @@ module.exports = () => ({
// if this is a topOrg then end here,we dont need to fetch the upper org which is continent i.e Africa
else if (topOrg && sourceEntityID.endsWith(topOrg)) {
return callback(parents);
} else if (body.entry[0].resource.hasOwnProperty('partOf')
&& body.entry[0].resource.partOf.reference != false
&& body.entry[0].resource.partOf.reference != null
&& body.entry[0].resource.partOf.reference != undefined) {
} else if (body.entry[0].resource.hasOwnProperty('partOf') &&
body.entry[0].resource.partOf.reference != false &&
body.entry[0].resource.partOf.reference != null &&
body.entry[0].resource.partOf.reference != undefined) {
entityParent = body.entry[0].resource.partOf.reference;
getPar(entityParent, (parents) => {
callback(parents);
Expand Down Expand Up @@ -391,10 +391,10 @@ module.exports = () => ({
winston.error('parent details (either id,names or all) to be returned not specified');
}

if (entry.resource.hasOwnProperty('partOf')
&& entry.resource.partOf.reference != false
&& entry.resource.partOf.reference != null
&& entry.resource.partOf.reference != undefined) {
if (entry.resource.hasOwnProperty('partOf') &&
entry.resource.partOf.reference != false &&
entry.resource.partOf.reference != null &&
entry.resource.partOf.reference != undefined) {
entityParent = entry.resource.partOf.reference;
filter(entityParent, parents => callback(parents));
} else {
Expand Down Expand Up @@ -931,85 +931,85 @@ module.exports = () => ({

const me = this;
async.parallel({
source1Mapped(callback) {
me.getLocationByID(mappingDB, source1Id, false, (mapped) => {
if (mapped.entry.length > 0) {
winston.error('Attempting to mark an already mapped location as no match');
return callback(null, 'This location was already mapped, recalculate scores to update the level you are working on');
}
return callback(null, null);
});
source1Mapped(callback) {
me.getLocationByID(mappingDB, source1Id, false, (mapped) => {
if (mapped.entry.length > 0) {
winston.error('Attempting to mark an already mapped location as no match');
return callback(null, 'This location was already mapped, recalculate scores to update the level you are working on');
}
return callback(null, null);
});
},
},
},
(err, res) => {
if (res.source1Mapped !== null) {
return callback(res.source1Mapped);
}
me.getLocationByID(source1DB, source1Id, false, (mcsd) => {
const fhir = {};
fhir.entry = [];
fhir.type = 'document';
const entry = [];
const resource = {};
resource.resourceType = 'Location';
resource.name = mcsd.entry[0].resource.name;
resource.id = source1Id;

if (mcsd.entry[0].resource.hasOwnProperty('partOf')) {
resource.partOf = {
display: mcsd.entry[0].resource.partOf.display,
reference: mcsd.entry[0].resource.partOf.reference,
};
}
if (recoLevel == totalLevels) {
var typeCode = 'bu';
var typeName = 'building';
} else {
var typeCode = 'jdn';
var typeName = 'Jurisdiction';
(err, res) => {
if (res.source1Mapped !== null) {
return callback(res.source1Mapped);
}
resource.physicalType = {
coding: [{
code: typeCode,
display: typeName,
system: 'http://hl7.org/fhir/location-physical-type',
}],
};
resource.identifier = [];
const source1URL = URI(config.getConf('mCSD:url')).segment(source1DB).segment('fhir').segment('Location')
.segment(source1Id)
.toString();
resource.identifier.push({
system: source1System,
value: source1URL,
});
me.getLocationByID(source1DB, source1Id, false, (mcsd) => {
const fhir = {};
fhir.entry = [];
fhir.type = 'document';
const entry = [];
const resource = {};
resource.resourceType = 'Location';
resource.name = mcsd.entry[0].resource.name;
resource.id = source1Id;

resource.tag = [];
if (type == 'nomatch') {
resource.tag.push({
system: source1System,
code: noMatchCode,
display: 'No Match',
});
} else if (type == 'ignore') {
resource.tag.push({
if (mcsd.entry[0].resource.hasOwnProperty('partOf')) {
resource.partOf = {
display: mcsd.entry[0].resource.partOf.display,
reference: mcsd.entry[0].resource.partOf.reference,
};
}
if (recoLevel == totalLevels) {
var typeCode = 'bu';
var typeName = 'building';
} else {
var typeCode = 'jdn';
var typeName = 'Jurisdiction';
}
resource.physicalType = {
coding: [{
code: typeCode,
display: typeName,
system: 'http://hl7.org/fhir/location-physical-type',
}],
};
resource.identifier = [];
const source1URL = URI(config.getConf('mCSD:url')).segment(source1DB).segment('fhir').segment('Location')
.segment(source1Id)
.toString();
resource.identifier.push({
system: source1System,
code: ignoreCode,
display: 'Ignore',
value: source1URL,
});
}
entry.push({
resource,
});
fhir.entry = fhir.entry.concat(entry);
me.saveLocations(fhir, mappingDB, (err, res) => {
if (err) {
winston.error(err);

resource.tag = [];
if (type == 'nomatch') {
resource.tag.push({
system: source1System,
code: noMatchCode,
display: 'No Match',
});
} else if (type == 'ignore') {
resource.tag.push({
system: source1System,
code: ignoreCode,
display: 'Ignore',
});
}
callback(err);
entry.push({
resource,
});
fhir.entry = fhir.entry.concat(entry);
me.saveLocations(fhir, mappingDB, (err, res) => {
if (err) {
winston.error(err);
}
callback(err);
});
});
});
});
},
breakMatch(source1Id, mappingDB, source1DB, callback) {
if (!source1Id) {
Expand Down Expand Up @@ -1064,6 +1064,7 @@ module.exports = () => ({
code: matchBrokenCode,
display: 'Match Broken',
});
winston.error(location)
this.saveLocations(location, source1DB, (err, res) => {});
}
});
Expand Down Expand Up @@ -1137,10 +1138,10 @@ module.exports = () => ({
let facilityParent = null;
let facilityParentUUID = null;
async.eachSeries(levels, (level, nxtLevel) => {
if (data[headerMapping[level]] != null
&& data[headerMapping[level]] != undefined
&& data[headerMapping[level]] != false
&& data[headerMapping[level]] != ''
if (data[headerMapping[level]] != null &&
data[headerMapping[level]] != undefined &&
data[headerMapping[level]] != false &&
data[headerMapping[level]] != ''
) {
let name = data[headerMapping[level]].trim();
name = mixin.toTitleCaseSpace(name);
Expand Down Expand Up @@ -1330,7 +1331,7 @@ module.exports = () => ({
resource.status = 'active';
resource.mode = 'instance';
resource.name = building.name;
resource.id = building.id;
resource.id = building.uuid;
resource.identifier = [];
resource.identifier.push({
system: 'https://digitalhealth.intrahealth.org/source1',
Expand Down Expand Up @@ -1489,4 +1490,4 @@ module.exports = () => ({
return callback(tree);
});
},
});
});
32 changes: 16 additions & 16 deletions facility-recon-backend/lib/scores.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ module.exports = function () {
const lev = levenshtein.get(source2Name.toLowerCase(), source1Name.toLowerCase());
// when parent constraint is On then automatch by name is also enabled by default
// when parent constraint is off then check if name automatch is also on
if (lev == 0
&& !matchBroken
&& (parentsDiffer == false || (parentConstraint.enabled == false && parentConstraint.nameAutoMatch == true) || recoLevel == 2)
if (lev == 0 &&
!matchBroken &&
(parentsDiffer == false || (parentConstraint.enabled == false && parentConstraint.nameAutoMatch == true) || recoLevel == 2)
) {
const source2IdHierarchy = mixin.createIdHierarchy(mcsdSource2, source2Entry.resource.id);
ignore.push(source2Entry.resource.id);
Expand Down Expand Up @@ -711,10 +711,10 @@ module.exports = function () {
}
mcsd.getLocationParentsFromData(entityParent, mcsdSource1All, 'names', (source1Parents) => {
const ident = source1Entry.resource.identifier.find(identifier => identifier.system == 'https://digitalhealth.intrahealth.org/source1');
let source1BuildingId = null;
if (ident) {
source1BuildingId = ident.value;
}
let source1BuildingId = source1Entry.resource.id;
// if (ident) {
// source1BuildingId = ident.value;
// }
const source1IdHierarchy = mixin.createIdHierarchy(mcsdSource1, source1BuildingId);
thisRanking.source1 = {
name: source1Entry.resource.name,
Expand Down Expand Up @@ -828,11 +828,11 @@ module.exports = function () {
}
source1ParentReceived.then(() => {
thisRanking = {};
let source1BuildingId = null;
let source1BuildingId = source1Entry.resource.id;
const ident = source1Entry.resource.identifier.find(identifier => identifier.system == 'https://digitalhealth.intrahealth.org/source1');
if (ident) {
source1BuildingId = ident.value;
}
// if (ident) {
// source1BuildingId = ident.value;
// }
let parents;
if (source1Parents[source1Parents.length - 1].id == topOrgId) {
parents = source1ParentNames.slice(0, source1Parents.length - 1);
Expand Down Expand Up @@ -969,8 +969,8 @@ module.exports = function () {

const lev = levenshtein.get(source2Name.toLowerCase(), source1Name.toLowerCase());

if (lev == 0 && !matchBroken
&& (parentsDiffer == false || (parentConstraint.enabled == false && parentConstraint.nameAutoMatch == true) || recoLevel == 2)
if (lev == 0 && !matchBroken &&
(parentsDiffer == false || (parentConstraint.enabled == false && parentConstraint.nameAutoMatch == true) || recoLevel == 2)
) {
const source2IdHierarchy = mixin.createIdHierarchy(mcsdSource2, source2Entry.resource.id);
ignore.push(source2Entry.resource.id);
Expand Down Expand Up @@ -1169,8 +1169,8 @@ module.exports = function () {
return callback();
}
const status = mcsdMapped.entry.find(
entry => entry.resource.id === id
|| (entry.resource.hasOwnProperty('identifier') && entry.resource.identifier.find(identifier => identifier.value === id)),
entry => entry.resource.id === id ||
(entry.resource.hasOwnProperty('identifier') && entry.resource.identifier.find(identifier => identifier.value === id)),
);
return callback(status);
},
Expand Down Expand Up @@ -1408,4 +1408,4 @@ module.exports = function () {
},

};
};
};
Loading

0 comments on commit b86c383

Please sign in to comment.