Skip to content

Commit

Permalink
[imaging_uploader] Fix auto-populating VisitLabel (#8881)
Browse files Browse the repository at this point in the history
Properly handle parsing/auto-populating of visit label when there is a suffix after the visit label in the file name.

Fixes #8803
  • Loading branch information
zaliqarosli authored Sep 12, 2023
1 parent b381816 commit 80740e4
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions modules/imaging_uploader/jsx/UploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
}
}

Expand Down

0 comments on commit 80740e4

Please # to comment.