From e9e46f7902fbb4d6addd9d2d9f1a23b087471193 Mon Sep 17 00:00:00 2001 From: Damion Dooley Date: Thu, 24 Oct 2024 11:13:51 -0700 Subject: [PATCH] Version bump + new getFieldTitleMap function And moving getRowMap to phac_dexa export.js since it is only used there. --- lib/DataHarmonizer.js | 64 +++++++++++-------------------------------- package.json | 2 +- 2 files changed, 17 insertions(+), 49 deletions(-) diff --git a/lib/DataHarmonizer.js b/lib/DataHarmonizer.js index 4c012c40..dc886500 100644 --- a/lib/DataHarmonizer.js +++ b/lib/DataHarmonizer.js @@ -1608,11 +1608,24 @@ class DataHarmonizer { * @return {Dictionary} Dictionary of all fields. */ getFieldNameMap(fields) { - const titleMap = {}; + const map = {}; for (const [fieldIndex, field] of fields.entries()) { - titleMap[field.name] = fieldIndex; + map[field.name] = fieldIndex; } - return titleMap; + return map; + } + + /** + * Get a dictionary of source field TITLES pointing to column index + * @param {Object} fields A flat version of data.js. + * @return {Dictionary} Dictionary of all fields. + */ + getFieldTitleMap(fields) { + const map = {}; + for (const [fieldIndex, field] of fields.entries()) { + map[field.title] = fieldIndex; + } + return map; } /** @@ -1912,51 +1925,6 @@ class DataHarmonizer { return result; } - /** - * Get a dictionary of empty arrays for each ExportHeader field - * FUTURE: enable it to work with hierarchic vocabulary lists - * - * @param {Array} sourceRow array of values to be exported. - * @param {Array} sourceFields list of source fields to examine for mappings. - * @param {Array} RuleDB list of export fields modified by rules. - * @param {Array} fields list of export fields modified by rules. - * @param {Array} titleMap map of field names to column index. - * @param {String} prefix of export format to examine. - * @return {Array} fields Dictionary of all fields. - */ - - getRowMap(sourceRow, sourceFields, RuleDB, fields, titleMap, prefix) { - for (const title of sourceFields) { - const sourceIndex = titleMap[title]; - let value = sourceRow[sourceIndex]; // All text values. - // Sets source field to data value so that rules can reference it easily. - RuleDB[title] = value; - // Check to see if value is in vocabulary of given select field, and if it - // has a mapping for export to a GRDI target field above, then set target - // to value. - if (value && value.length > 0) { - const vocab_list = fields[sourceIndex]['schema:ItemList']; - if (value in vocab_list) { - const term = vocab_list[value]; - // Looking for term.exportField['GRDI'] for example: - if ('exportField' in term && prefix in term.exportField) { - for (let mapping of term.exportField[prefix]) { - // Here mapping involves a value substitution - if ('value' in mapping) { - value = mapping.value; - // Changed on a copy of data, not handsongrid table - sourceRow[sourceIndex] = value; - } - if ('field' in mapping && mapping['field'] in RuleDB) { - RuleDB[mapping['field']] = value; - } - } - } - } - } - } - } - /** * Return first and last items of a delimited string * @param {String} value A string of values separated by delimiter. diff --git a/package.json b/package.json index 0e0f29cb..3351ddd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-harmonizer", - "version": "1.7.1", + "version": "1.7.2", "description": "A standardized spreadsheet editor and validator that can be run offline and locally", "repository": "git@github.com:cidgoh/DataHarmonizer.git", "license": "MIT",