diff --git a/modules/imaging_uploader/jsx/UploadForm.js b/modules/imaging_uploader/jsx/UploadForm.js index 3b2fe0251a1..1561f009b20 100644 --- a/modules/imaging_uploader/jsx/UploadForm.js +++ b/modules/imaging_uploader/jsx/UploadForm.js @@ -66,10 +66,22 @@ class UploadForm extends Component { let ids = patientName.split('_'); formData.candID = ids[1]; formData.pSCID = ids[0]; - // visitLabel can contain underscores - // join the remaining elements of patientName and use as visitLabel + // visitLabel can contain underscores, filename can have suffix appended to PSCID_CandID_VisitLabel + // join the remaining elements of patientName and pattern match + // against each visit label. Use as visitLabel the best (longest) match ids.splice(0, 2); - formData.visitLabel = ids.join('_'); + const suffix = ids.join('_'); + const visitLabels = Object.keys(form.visitLabel.options); + let bestMatch = ''; + visitLabels.map((visitLabel) => { + if (suffix.match(visitLabel) !== null) { + // consider the first match only + if (suffix.match(visitLabel)[0].length > bestMatch.length) { + bestMatch = suffix.match(visitLabel)[0]; + } + } + }); + formData.visitLabel = bestMatch; } } @@ -81,10 +93,22 @@ class UploadForm extends Component { let ids = patientName.split('_'); formData.candID = ids[1]; formData.pSCID = ids[0]; - // visitLabel can contain underscores - // join the remaining elements of patientName and use as visitLabel + // visitLabel can contain underscores, filename can have suffix appended to PSCID_CandID_VisitLabel + // join the remaining elements of patientName and pattern match + // against each visit label. Use as visitLabel the best (longest) match ids.splice(0, 2); - formData.visitLabel = ids.join('_'); + const suffix = ids.join('_'); + const visitLabels = Object.keys(form.visitLabel.options); + let bestMatch = ''; + visitLabels.map((visitLabel) => { + if (suffix.match(visitLabel) !== null) { + // consider the first match only + if (suffix.match(visitLabel)[0].length > bestMatch.length) { + bestMatch = suffix.match(visitLabel)[0]; + } + } + }); + formData.visitLabel = bestMatch; } }