From 9f819a625caf7069a3904ac95f7205fc1a3da393 Mon Sep 17 00:00:00 2001 From: Damion Dooley Date: Tue, 9 Nov 2021 15:06:29 +0100 Subject: [PATCH 1/2] VirusSeq updates --- template/canada_covid19/export.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/template/canada_covid19/export.js b/template/canada_covid19/export.js index 35b10935..1e6932bd 100644 --- a/template/canada_covid19/export.js +++ b/template/canada_covid19/export.js @@ -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) @@ -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 = []; @@ -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')) { @@ -685,7 +710,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; From 6bd2472f92b25586ebd06a0e4eb21136a31166be Mon Sep 17 00:00:00 2001 From: Damion Dooley Date: Tue, 9 Nov 2021 15:41:16 +0100 Subject: [PATCH 2/2] correct title case on null values --- template/canada_covid19/export.js | 38 +++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/template/canada_covid19/export.js b/template/canada_covid19/export.js index 1e6932bd..9a435166 100644 --- a/template/canada_covid19/export.js +++ b/template/canada_covid19/export.js @@ -652,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 = []; @@ -685,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; } @@ -725,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); @@ -745,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; +}