-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix logging of MRI violations log #327
Fix logging of MRI violations log #327
Conversation
…n CheckID from mri_violations_log since not used anywhere in the code)
@cmadjar I just want to make sure we are all on the same page with all these open PRs and what should stay and what should be closed; |
|
||
# grep all valid ranges and regex to compare with value in the file | ||
my (@valid_ranges, @valid_regexs); | ||
while (my $check = $sth->fetchrow_hashref()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest removing the declaration of @valid_ranges
and @valid_regexs
and replacing with:
my @rows = @{ $sth->fetchall_arrayref( { ValidRange => 1, ValidRegex => 1 } ) };
my @valid_ranges = grep($_->{'ValidRange'}, @rows);
my @valid_regexs = grep($_->{'ValidRegex'}, @rows);
Just remember that from now on both arrays contain references to the rows that contain non-null ranges/regexs.
# type, severity and header | ||
next if (!@valid_ranges && !@valid_regexs); | ||
|
||
# loop through all checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would reduce this to
next if grep(NeuroDB::MRI::in_range($value, $_->{'ValidRange'}), @valid_ranges);
and if we get past this point, we know that @valid_ranges
will only contain references to rows for which $value
is not in range.
push(@failed_valid_ranges, $valid_range); | ||
} | ||
} | ||
foreach my $valid_regex (@valid_regexs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same logic here:
next if grep($value =~ /$_->{'ValidRegex'}/, @valid_regexs);
and if we get past this point, we know that @valid_regexs will only contain references to rows for which $value
does not match the regex for that row.
# value in one of the valid ranges or regex set for that scan type, | ||
# header and severity | ||
next if $is_valid; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More concise IMHO
$valid_fields{$header} = {
ScanType => $scan_type,
HeaderValue => $value,
ValidRanges => [ map { $_->{'ValidRange'} } @valid_ranges ],
ValidRegexs => [ map { $_->{'ValidRegex'} } @valid_regexs ]
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am suggesting some code refactoring. Let me know what you think.
@MounaSafiHarab I know it gets confusing. This PR is only taking care of the comma normalization of Does that clarify a bit? |
@nicolasbrossard Thank you very much for the code suggestions!! Looks so much better now :). Ready for another round of review when you are ready. |
$this->{LOG}->print($message); | ||
# 'warn' and 'exclude' are errors, while 'pass' is not | ||
# log in the notification_spool_table the $Verbose flag accordingly | ||
if (!($checks[0] eq 'pass')){ | ||
if (!($extra_validation_status eq 'pass')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
if($extra_validation_status ne 'pass') {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more refactoring that I didn't think about during the first pass.
|
||
} | ||
# grep the excluded headers from mri_protocol_check for the scan type | ||
my @exclude_headers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would replace the rest of the code for this function with this
foreach(qw/exclude warning/) {
$sth->execute($scan_type, $severity);
my @headers = map { $_->{'Header'} } @{ $sth->fetchall_arrayref({}) };
my %validFields = $this->loop_through_protocol_violations_checks(
$scan_type, $severity, \@headers, $file
);
if(%validFields) {
$this->insert_into_mri_violations_log(
\%validFields, $severity, $pname, $candID, $visit_label, $file
);
return $severity;
}
}
return 'pass';
@nicolasbrossard Thank you for the suggestions!! All done and ready for another review :) |
@cmadjar I will put passed manual tests but will wait for @nicolasbrossard to test it as well before merging |
I tested this PR "through" 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little changes in the documentation
- @checks : array of extra checks | ||
- $acquisitionProtocol : acquisition protocol | ||
- $acquisitionProtocolID : acquisition protocol ID | ||
- $extra\_validation\_status : extra validation status ("pass", "exclude", "warn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace "warn" by "warning" (method was refactored)
- @checks : array of extra checks | ||
- $acquisitionProtocol : acquisition protocol | ||
- $acquisitionProtocolID : acquisition protocol ID | ||
- $extra_validation_status : extra validation status ("pass", "exclude", "warn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"warn" should be replaced by "warning"
@nicolasbrossard Thanks! Changes made :) |
This pull request fixes the logic of scan insertion into the
mri_violations_log
table that got compromised with the refactoring ofmri_protocol_checks
(no comma allowed anymore).Description of the bug:
Let's say that for the MINC header
xspace:length
of a T1W, there are multiplevalidRange
in themri_protocol_checks
like below:For a T1W scan with a
xspace:length
of176
(fitting the second row in the table above), the insertion pipeline will exclude the T1W scan from insertion and log an entry in themri_violations_log
table saying that thevalidRange
for a T1W and this header is 10-20 (not taking into consideration the second valid range).New logic of the pipeline after the fix (validated with Dave on Friday)
Header
values in themri_protocol_checks
table for the identifiedScan_type