@@ -66,10 +66,22 @@ class UploadForm extends Component {
66
66
let ids = patientName . split ( '_' ) ;
67
67
formData . candID = ids [ 1 ] ;
68
68
formData . pSCID = ids [ 0 ] ;
69
- // visitLabel can contain underscores
70
- // join the remaining elements of patientName and use as visitLabel
69
+ // visitLabel can contain underscores, filename can have suffix appended to PSCID_CandID_VisitLabel
70
+ // join the remaining elements of patientName and pattern match
71
+ // against each visit label. Use as visitLabel the best (longest) match
71
72
ids . splice ( 0 , 2 ) ;
72
- formData . visitLabel = ids . join ( '_' ) ;
73
+ const suffix = ids . join ( '_' ) ;
74
+ const visitLabels = Object . keys ( form . visitLabel . options ) ;
75
+ let bestMatch = '' ;
76
+ visitLabels . map ( ( visitLabel ) => {
77
+ if ( suffix . match ( visitLabel ) !== null ) {
78
+ // consider the first match only
79
+ if ( suffix . match ( visitLabel ) [ 0 ] . length > bestMatch . length ) {
80
+ bestMatch = suffix . match ( visitLabel ) [ 0 ] ;
81
+ }
82
+ }
83
+ } ) ;
84
+ formData . visitLabel = bestMatch ;
73
85
}
74
86
}
75
87
@@ -81,10 +93,22 @@ class UploadForm extends Component {
81
93
let ids = patientName . split ( '_' ) ;
82
94
formData . candID = ids [ 1 ] ;
83
95
formData . pSCID = ids [ 0 ] ;
84
- // visitLabel can contain underscores
85
- // join the remaining elements of patientName and use as visitLabel
96
+ // visitLabel can contain underscores, filename can have suffix appended to PSCID_CandID_VisitLabel
97
+ // join the remaining elements of patientName and pattern match
98
+ // against each visit label. Use as visitLabel the best (longest) match
86
99
ids . splice ( 0 , 2 ) ;
87
- formData . visitLabel = ids . join ( '_' ) ;
100
+ const suffix = ids . join ( '_' ) ;
101
+ const visitLabels = Object . keys ( form . visitLabel . options ) ;
102
+ let bestMatch = '' ;
103
+ visitLabels . map ( ( visitLabel ) => {
104
+ if ( suffix . match ( visitLabel ) !== null ) {
105
+ // consider the first match only
106
+ if ( suffix . match ( visitLabel ) [ 0 ] . length > bestMatch . length ) {
107
+ bestMatch = suffix . match ( visitLabel ) [ 0 ] ;
108
+ }
109
+ }
110
+ } ) ;
111
+ formData . visitLabel = bestMatch ;
88
112
}
89
113
}
90
114
0 commit comments