diff --git a/web/src/views/SubmissionPortal/HarmonizerView.vue b/web/src/views/SubmissionPortal/HarmonizerView.vue index ad0b17ae..3e88a0c5 100644 --- a/web/src/views/SubmissionPortal/HarmonizerView.vue +++ b/web/src/views/SubmissionPortal/HarmonizerView.vue @@ -355,11 +355,19 @@ export default defineComponent({ if (!template || !template.sampleDataSlot || !template.schemaClass) { return; } + + // The spreadsheet has slot names as the header row. So `sheet_to_json` will produce array + // of objects with slot names as keys. But we want the imported data to be keyed on slot + // IDs. This code reads the worksheet data and remaps the keys from slot names to IDs. + const slotIdToNameMap = harmonizerApi.getHeaderRow(template.schemaClass); + const slotNameToIdMap = Object.fromEntries(Object.entries(slotIdToNameMap).map(([k, v]) => [v, k])); + const worksheetData: Record[] = utils.sheet_to_json(worksheet); + const remappedData = worksheetData.map((row) => Object.fromEntries(Object.entries(row) + .filter(([slotName]) => slotNameToIdMap[slotName] !== undefined) + .map(([slotName, value]) => [slotNameToIdMap[slotName], value]))); + imported[template.sampleDataSlot] = harmonizerApi.unflattenArrayValues( - utils.sheet_to_json(worksheet, { - header: harmonizerApi.getOrderedAttributeNames(template.schemaClass), - range: 1, - }), + remappedData, template.schemaClass, ); });