Skip to content

Commit

Permalink
Merge pull request #117 from brainlife/enh/metadata_alert_fix
Browse files Browse the repository at this point in the history
[FIX] Resolved a merging issue that occurred on last PR
  • Loading branch information
dlevitas authored Feb 15, 2024
2 parents 086195a + 5dce92f commit 2203407
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 150 deletions.
4 changes: 2 additions & 2 deletions ui/src/SeriesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ export default defineComponent({
s.series_idx,
s.type
);
// console.log(s.type);
// console.log('metadataAlertsFields', metadataAlertsFields);
console.log(s.series_idx, s.type);
console.log('metadataAlertsFields', metadataAlertsFields);
if (metadataAlertsFields.length) {
let warn: string = `'Required metadata is missing and/or provided metadata field values have improper
format. Please click on the "Edit Metadata" button below to resolve. You may skip fields for which you
Expand Down
137 changes: 99 additions & 38 deletions ui/src/components/modalityForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>

<el-input
v-if="formatType(item.details.type) == 'integer'"
v-model="formData[item.field]"
type="text"
inputmode="numeric"
:name="item.field"
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>
</el-col>
<el-col :span="8">
<el-select
Expand Down Expand Up @@ -185,6 +195,17 @@
@input="$refs.form.validate()"
></el-input>

<el-input
v-if="inputType(item) == 'input-integer'"
v-model="formData[item.field]"
type="text"
inputmode="numeric"
:name="item.field"
:placeholder="getPlaceholderByType(item.details.type)"
class="input-fullwidth"
@input="$refs.form.validate()"
></el-input>

<el-select
v-if="inputType(item) == 'select-boolean'"
v-model="formData[item.field]"
Expand Down Expand Up @@ -225,6 +246,16 @@
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>

<el-input
v-if="formatType(item.details.type) == 'integer'"
v-model="formData[item.field]"
type="text"
inputmode="numeric"
:name="item.field"
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>
</el-col>
<el-col :span="8">
<el-select
Expand Down Expand Up @@ -307,6 +338,16 @@
@input="$refs.form.validate()"
></el-input>

<el-input
v-if="inputType(item) == 'input-integer'"
v-model="formData[item.field]"
type="text"
inputmode="numeric"
:name="item.field"
:placeholder="getPlaceholderByType(item.details.type)"
@input="$refs.form.validate()"
></el-input>

<el-select
v-if="inputType(item) == 'select-boolean'"
v-model="formData[item.field]"
Expand Down Expand Up @@ -347,6 +388,16 @@
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>

<el-input
v-if="formatType(item.details.type) == 'integer'"
v-model="formData[item.field]"
type="text"
inputmode="numeric"
:name="item.field"
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>
</el-col>
<el-col :span="8">
<el-select
Expand Down Expand Up @@ -424,6 +475,16 @@
@input="$refs.form.validate()"
></el-input>

<el-input
v-if="inputType(item) == 'input-integer'"
v-model="formData[item.field]"
type="text"
inputmode="numeric"
:name="item.field"
:placeholder="getPlaceholderByType(item.details.type)"
@input="$refs.form.validate()"
></el-input>

<el-select
v-if="inputType(item) == 'select-boolean'"
v-model="formData[item.field]"
Expand Down Expand Up @@ -464,6 +525,16 @@
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>

<el-input
v-if="formatType(item.details.type) == 'integer'"
v-model="formData[item.field]"
type="text"
inputmode="numeric"
:name="item.field"
:placeholder="getPlaceholderByType(formatType(item.details.type))"
@input="$refs.form.validate()"
></el-input>
</el-col>
<el-col :span="8">
<el-select
Expand Down Expand Up @@ -574,6 +645,7 @@ export default defineComponent({
) {
if (type == 'string') value = value.replace(/"/g, ''); // don't let user add unnecessary quotes
if (type == 'number') value = Number(value);
if (type == 'integer') value = Number(value);
if (type == 'boolean') value = Boolean(value);
if (type == 'array') {
value = this.parseArrayValues(value, details);
Expand All @@ -598,6 +670,7 @@ export default defineComponent({
)
return 'input';
if (item.details.type == 'number') return 'input-number';
if (item.details.type == 'integer') return 'input-integer';
if (item.details.type == 'boolean') return 'select-boolean';
if (item.details.enum) return 'select-enum';
},
Expand Down Expand Up @@ -684,6 +757,8 @@ export default defineComponent({
// fields with level 'required' or 'recommended' are included in the list
for (const [field, metadata] of Object.entries(fields)) {
// Skip some metadata fields that are either handled seaprately by ezBIDS, or not worthwhile
// ezBIDS handles IntendedFor and TaskName separately, so don't worry about them here
if (['IntendedFor', 'TaskName'].includes(field)) {
continue;
Expand All @@ -703,6 +778,21 @@ export default defineComponent({
if (type.startsWith('func') && ['VolumeTiming', 'Units'].includes(field)) {
continue;
}
//MEG data is weird sometimes, especially when certain metadata field values are objects
if (
type === 'meg/meg' &&
[
'AssociatedEmptyRoom',
'MEGCoordinateSystem',
'MEGCoordinateUnits',
'SoftwareFilters',
'HardwareFilters',
'HeadCoilCoordinates',
'AnatomicalLandmarkCoordinates',
].includes(field)
) {
continue;
}
// get the metadata from the metadata.yaml
const details = metadataInfo[field] || {};
Expand Down Expand Up @@ -827,14 +917,7 @@ export default defineComponent({
expectedValue &&
(value == null || value === '')
) {
callback(
new Error(
'This field is required based on the condition ' +
fieldName +
' == ' +
expectedValue
)
);
callback(new Error('Required because ' + fieldName + ' == ' + expectedValue));
return;
}
}
Expand All @@ -849,14 +932,7 @@ export default defineComponent({
String(this.formData[fieldName]) === expectedValue &&
!value
) {
callback(
new Error(
'This field is required based on the condition ' +
fieldName +
' == ' +
expectedValue
)
);
callback(new Error('Required because ' + fieldName + ' == ' + expectedValue));
return;
}
}
Expand All @@ -872,14 +948,7 @@ export default defineComponent({
String(this.formData[fieldName]) === expectedValue &&
!value
) {
callback(
new Error(
'This field is required based on the condition ' +
fieldName +
' == ' +
expectedValue
)
);
callback(new Error('Required because ' + fieldName + ' == ' + expectedValue));
return;
}
}
Expand All @@ -898,14 +967,7 @@ export default defineComponent({
String(this.formData[fieldName]) === expectedValue &&
!value
) {
callback(
new Error(
'This field is required based on the condition ' +
fieldName +
' == ' +
expectedValue
)
);
callback(new Error('Required because ' + fieldName + ' == ' + expectedValue));
return;
}
}
Expand All @@ -925,7 +987,7 @@ export default defineComponent({
) {
callback(
new Error(
'This field is required based on the condition ' +
'Required because ' +
fieldName +
' == ' +
expectedValue1 +
Expand Down Expand Up @@ -956,10 +1018,7 @@ export default defineComponent({
) {
callback(
new Error(
'This field is required based on the condition ' +
fieldName +
' == ' +
expectedValues.join(' or ')
'Required because ' + fieldName + ' == ' + expectedValues.join(' or ')
)
);
return;
Expand All @@ -983,7 +1042,7 @@ export default defineComponent({
return rules;
},
addNumericValidationRule(rules, item) {
if (item.details && item.details.type === 'number') {
if (['number', 'integer'].includes(item.details && item.details.type)) {
if (!rules[item.field]) {
rules[item.field] = [];
}
Expand Down Expand Up @@ -1112,6 +1171,7 @@ export default defineComponent({
parseDefaultValue(type: string) {
if (type == 'string') return '';
if (type == 'number') return null;
if (type == 'integer') return null;
if (type == 'boolean') return undefined;
if (type == 'array') return []; // will help user to identify its an array
if (type == 'object') return {}; // will help user to identify its an object
Expand All @@ -1124,6 +1184,7 @@ export default defineComponent({
getPlaceholderByType(type) {
if (type == 'string') return 'Enter string';
if (type == 'number') return 'Enter number';
if (type == 'integer') return 'Enter integer';
if (type == 'boolean') return 'Select';
if (type == 'array') return 'Enter array []';
if (type == 'object') return 'Enter object {}';
Expand Down
20 changes: 14 additions & 6 deletions ui/src/libUnsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1736,7 +1736,7 @@ export function metadataAlerts(
let suffix = type.split('/')[1];
for (let key in bidsDatatypeMetadata) {
const metadataEntry = bidsDatatypeMetadata[key];
const selectors = metadataEntry.selectors;
const selectors: any = metadataEntry.selectors;
const fields = metadataEntry.fields;
let proceed = 'no';
// Need to ensure that we're dealing with the proper sequence datatype and suffix.
Expand All @@ -1751,19 +1751,23 @@ export function metadataAlerts(
) {
proceed = 'yes';
}
} else {
if (datatype === 'meg' && suffix === 'meg' && !selectors.includes('suffix == "coordsystem"')) {
proceed = 'yes';
}
}
if (proceed === 'yes') {
for (let fieldName in fields) {
if (fields.hasOwnProperty(fieldName) && fieldName !== 'IntendedFor') {
if (fields.hasOwnProperty(fieldName) && !['IntendedFor', 'TaskName'].includes(fieldName)) {
let field = fields[fieldName];
let severity: any = '';
if (field.hasOwnProperty('level')) {
severity = field.level;
} else {
severity = field;
}

if (severity === 'required') {
// console.log(type, fieldName)
if (!sidecarMetadata.hasOwnProperty(fieldName)) {
// Required based on datatype/suffix pairing, no conditionals
// BIDS metadata field not in sequence sidecar
Expand Down Expand Up @@ -1796,7 +1800,6 @@ export function metadataAlerts(
if (context === 'is in') {
let sidecarMetadataKey = bidsMetadataKey;
let sidecarMetadataValue = sidecarMetadata[sidecarMetadataKey];
console.log('dan', sidecarMetadataValue, bidsMetadataValue);
if (bidsMetadataValue.includes(sidecarMetadataValue)) {
requiredFields.push(fieldName);
}
Expand Down Expand Up @@ -1842,6 +1845,11 @@ export function metadataAlerts(
if (sidecarMetadataValueType === 'object' && Array.isArray(sidecarMetadataValue)) {
sidecarMetadataValueType = 'array';
}
if (bidsMetadataValueType === 'integer' && sidecarMetadataValueType === 'number') {
if (Number.isInteger(sidecarMetadataValue)) {
sidecarMetadataValueType = 'integer';
}
}

// Does sequence metadata field key type match what BIDS expects
if (sidecarMetadataValueType !== bidsMetadataValueType) {
Expand Down Expand Up @@ -1915,7 +1923,7 @@ export function metadataAlerts(
}

let metadataAlertFields = requiredFields.concat(typoFields);
console.log('required', requiredFields);
console.log('typo', typoFields);
// console.log('required', requiredFields);
// console.log('typo', typoFields);
return metadataAlertFields;
}
Loading

0 comments on commit 2203407

Please sign in to comment.