Skip to content

Commit

Permalink
Merge pull request #233 from cidgoh/vocabulary-update
Browse files Browse the repository at this point in the history
Vocabulary update
  • Loading branch information
ddooley authored Nov 9, 2021
2 parents 8cd7f40 + 6bd2472 commit f663164
Showing 1 changed file with 53 additions and 14 deletions.
67 changes: 53 additions & 14 deletions template/canada_covid19/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ var exportVirusSeq_Portal = (baseName, hot, data, xlsx, fileType) => {
['restricted access', 'Restricted Access']
]);

studyMap = {
'Alberta Precision Labs (APL)': 'ABPL-AB',
'BCCDC Public Health Laboratory': 'BCCDC-BC',
'Manitoba Cadham Provincial Laboratory': 'MCPL-MB',
'New Brunswick - Vitalité Health Network': 'VHN-NB',
'Newfoundland and Labrador - Eastern Health': 'EH-NL',
'Nova Scotia Health Authority': 'NSHA-NS',
'Public Health Ontario (PHO)': 'PHO-ON',
'Laboratoire de santé publique du Québec (LSPQ)': 'LSPQ-QC',
'Saskatchewan - Roy Romanow Provincial Laboratory (RRPL)': 'RRPL-SK',
}

const sourceFields = getFields(data);
const sourceFieldNameMap = getFieldNameMap(sourceFields);
// Fills in the above mapping (or just set manually above)
Expand All @@ -74,6 +86,7 @@ var exportVirusSeq_Portal = (baseName, hot, data, xlsx, fileType) => {
// Copy headers to 1st row of new export table
const outputMatrix = [[...ExportHeaders.keys()]];

const numeric_datatypes = new Set(['xs:nonNegativeInteger', 'xs:decimal']);

for (const inputRow of getTrimmedData(hot)) {
const outputRow = [];
Expand All @@ -86,7 +99,19 @@ var exportVirusSeq_Portal = (baseName, hot, data, xlsx, fileType) => {
// Otherwise apply source (many to one) to target field transform:
var value = getMappedField(headerName, inputRow, sources, sourceFields, sourceFieldNameMap, ':', 'VirusSeq_Portal');

const numeric_datatypes = new Set(['xs:nonNegativeInteger', 'xs:decimal']);
if (headerName == 'study_id') {

// Autopopulate study_id based on studyMap
const lab = inputRow[sourceFieldNameMap['sequence submitted by']];
if (lab && lab in studyMap) {
value = studyMap[lab];
}
}

// Add % to breadth of coverage since required.
if (headerName == 'breadth of coverage value' && value && value.length && value.substr(-1) != '%') {
value = value + '%';
}

// Some columns have an extra ' null reason' field for demultiplexing null value into.
if (ExportHeaders.has(headerName + ' null reason')) {
Expand Down Expand Up @@ -627,16 +652,13 @@ var exportNML_LIMS = (baseName, hot, data, xlsx, fileType) => {
// Copy headers to 1st row of new export table
const outputMatrix = [[...ExportHeaders.keys()]];

// Conversion of all cancogen metadata keywords to NML LIMS version
/*
nullOptionsMap = new Map([
['Not Applicable', 'NA'],
['Missing', 'MISSING'],
['Not Collected', 'NOT_COLLECTED'],
['Not Provided', 'NOT_PROVIDED'],
['Restricted Access', 'RESTRICTED_ACCESS']
['not applicable', 'Not Applicable'],
['missing', 'Missing'],
['not collected', 'Not Collected'],
['not provided', 'Not Provided'],
['restricted access', 'Restricted Access']
]);
*/

for (const inputRow of getTrimmedData(hot)) {
const outputRow = [];
Expand All @@ -660,9 +682,9 @@ var exportNML_LIMS = (baseName, hot, data, xlsx, fileType) => {
// Handle granularity of "HC_COLLECT_DATE"
// by looking at year or month in "sample collection date precision"
if (headerName === 'HC_COLLECT_DATE') {
const value = inputRow[sourceFieldNameMap['sample collection date']] || '';
let value = inputRow[sourceFieldNameMap['sample collection date']] || '';
value = fixNullOptionCase(value,nullOptionsMap);
const date_unit = inputRow[sourceFieldNameMap['sample collection date precision']];

outputRow.push(setDateChange(date_unit, value, '01'));
continue;
}
Expand All @@ -685,7 +707,7 @@ var exportNML_LIMS = (baseName, hot, data, xlsx, fileType) => {
}
if (fieldName === 'host (scientific name)' || fieldName === 'host (common name)') {
if (value === 'Homo sapiens' || value === 'Human')
cellValue = 'HUMAN'
cellValue = 'Human'
else
cellValue = 'ANIMAL'
break;
Expand All @@ -700,8 +722,8 @@ var exportNML_LIMS = (baseName, hot, data, xlsx, fileType) => {
}

// Otherwise apply source (many to one) to target field transform:
const value = getMappedField(headerName, inputRow, sources, sourceFields, sourceFieldNameMap, ';', 'NML_LIMS');

let value = getMappedField(headerName, inputRow, sources, sourceFields, sourceFieldNameMap, ';', 'NML_LIMS');
value = fixNullOptionCase(value, nullOptionsMap);
outputRow.push(value);
}
outputMatrix.push(outputRow);
Expand All @@ -720,3 +742,20 @@ var EXPORT_FORMATS = {

};

/**
* If given value is a null value, normalize its capitalization
* @param {String} value to check.
* @param {Object} nullOptionsMap dictionary of null values.
* @return {String} value
*/
var fixNullOptionCase = (value, nullOptionsMap) => {
if (value) {
const valuelc = value.toLowerCase();
if (nullOptionsMap.has(valuelc)) {
const value2 = nullOptionsMap.get(valuelc);
if (value != value2)
value = value2;
}
}
return value;
}

0 comments on commit f663164

Please sign in to comment.