Skip to content

Commit

Permalink
Merge pull request #327 from RADAR-base/update-script
Browse files Browse the repository at this point in the history
Update Redcap parser
  • Loading branch information
mpgxvii authored Nov 23, 2024
2 parents c3e297a + 29406de commit 4dff260
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion utilities/RedcapParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ function REDCapConverter(redcap_json) {
var finalLabel = value2.substring(value2.indexOf(',') + 1);
}
arrayOfObjectsAndCodes.push({
code: removeFirstWhiteSpace(values[0]),
code: removeSpecialCharacters(removeFirstWhiteSpace(values[0])),
label: removeFirstWhiteSpace(finalLabel),
});
});
rawContent[key].select_choices_or_calculations = arrayOfObjectsAndCodes;
}
// If the field type is slider, then we need to add range property
if (rawContent[key].field_type === 'slider') {
rawContent[key].range = {
"min": arrayOfObjectsAndCodes[0].code,
"max": arrayOfObjectsAndCodes[arrayOfObjectsAndCodes.length - 1].code,
"step": 1,
"labelLeft": arrayOfObjectsAndCodes[0].label,
"labelRight": arrayOfObjectsAndCodes[arrayOfObjectsAndCodes.length - 1].label
}
rawContent[key].select_choices_or_calculations = [];
}
});
return rawContent;
};
Expand Down Expand Up @@ -116,6 +127,8 @@ function REDCapConverter(redcap_json) {
rawContent[key].field_type = 'range-info';
} else if (rawContent[key].field_annotation.includes('info-type')) {
rawContent[key].field_type = 'info';
} else if (rawContent[key].field_note.includes('info-type')) {
rawContent[key].field_type = 'info';
} else if (
rawContent[key].field_annotation.includes('matrix-radio-type')
) {
Expand Down Expand Up @@ -154,6 +167,13 @@ function REDCapConverter(redcap_json) {
return val;
};

removeSpecialCharacters = function(val) {
if (val) {
return val.replace(/[^a-zA-Z0-9]/g, '');
}
return val;
}

return this.parseRedCap(redcap_json);
}

Expand Down

0 comments on commit 4dff260

Please sign in to comment.