Skip to content

Commit

Permalink
[MRI violations] Fix multiple rows for file protocol violations not r…
Browse files Browse the repository at this point in the history
…esolvable (#8662)

This fixes a bug where the violation could not be resolved when there is more than one Protocol Violation returned for a file/timerun combination.
Only show one row per pname/timeRun/mincFile/scanType in the main menu filter table when there are multiple Protocol Violation for a given file (the list of violations will be displayed when clicking on the Protocol Violation link.
When selecting a resolution, loop through all entries in mri_violations_log matching the timeRun/mincFile and update the resolution status for all matching entries in the violations_resolved table.

Resolves  #8626
  • Loading branch information
cmadjar authored May 11, 2023
1 parent 06d27dc commit 2f52b10
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
5 changes: 4 additions & 1 deletion modules/mri_violations/php/provisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Provisioner extends \LORIS\Data\Provisioners\DBRowProvisioner
PhaseEncodingDirection,EchoTime,EchoNumber
)
) AS hash,
mrl.LogID AS join_id,
MIN(mrl.LogID) AS join_id,
p.CenterID AS Site,
COALESCE(
violations_resolved.Resolved, 'unresolved'
Expand All @@ -112,6 +112,9 @@ class Provisioner extends \LORIS\Data\Provisioners\DBRowProvisioner
mrl.Visit_label = s.Visit_label AND mrl.CandID=s.CandID
)
LEFT JOIN psc p ON (p.CenterID = s.CenterID)
GROUP BY PatientName, TimeRun, Project, Cohort, MincFile,
Scan_type, SeriesUID, Site, hash, Resolved, TarchiveID,
CandID, PSCID
UNION
SELECT PatientName,
TimeRun,
Expand Down
33 changes: 18 additions & 15 deletions modules/mri_violations/php/resolve.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ class Resolve extends \NDB_Page
if (!empty($ID_mri_protocol_violated_scans)) {
$newlyResolved['TypeTable'] = 'mri_protocol_violated_scans';
$newlyResolved['ExtID'] = $ID_mri_protocol_violated_scans;
$DB->insert('violations_resolved', $newlyResolved);
}

// Table 2: mri_violations_log
$ID_mri_violations_log = $DB->pselectOne(
"SELECT LogID
FROM mri_violations_log
// Table 2: MRICandidateErrors
$ID_MRICandidateErrors = $DB->pselectOne(
"SELECT ID
FROM MRICandidateErrors
WHERE (:hash = md5(concat_WS(
':',MincFile,PatientName,SeriesUID,TimeRun,
PhaseEncodingDirection,EchoTime,EchoNumber)
Expand All @@ -121,28 +122,30 @@ class Resolve extends \NDB_Page
['hash' => $hash]
);

if (!empty($ID_mri_violations_log)) {
$newlyResolved['TypeTable'] = 'mri_violations_log';
$newlyResolved['ExtID'] = $ID_mri_violations_log;
if (!empty($ID_MRICandidateErrors)) {
$newlyResolved['TypeTable'] = 'MRICandidateErrors';
$newlyResolved['ExtID'] = $ID_MRICandidateErrors;
$DB->insert('violations_resolved', $newlyResolved);
}

// Table 3: MRICandidateErrors
$ID_MRICandidateErrors = $DB->pselectOne(
"SELECT ID
FROM MRICandidateErrors
// Table 3: mri_violations_log
$mri_violations_log_ID_list = $DB->pselect(
"SELECT LogID
FROM mri_violations_log
WHERE (:hash = md5(concat_WS(
':',MincFile,PatientName,SeriesUID,TimeRun,
PhaseEncodingDirection,EchoTime,EchoNumber)
)
)",
['hash' => $hash]
);
error_log(print_r($mri_violations_log_ID_list, true));

if (!empty($ID_MRICandidateErrors)) {
$newlyResolved['TypeTable'] = 'MRICandidateErrors';
$newlyResolved['ExtID'] = $ID_MRICandidateErrors;
foreach ($mri_violations_log_ID_list as $entry) {
$newlyResolved['TypeTable'] = 'mri_violations_log';
$newlyResolved['ExtID'] = $entry['LogID'];
$DB->insert('violations_resolved', $newlyResolved);
}
$DB->insert('violations_resolved', $newlyResolved);

// Created
$response = $response->withStatus(201);
Expand Down
8 changes: 4 additions & 4 deletions modules/mri_violations/test/mri_violationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ public function testDashboardWidgetAllSites()
]
);
$this->safeGet($this->url . '/dashboard/');
// Raisin bread has 173 unresolved violated scans. We are adding three
// in setup(): one resolved, and two unresolved. The total
// number of unresolved violations is thus 175
// Raisin bread has 169 unique unresolved violated scans. We are adding
// three in setup(): one resolved, and two unresolved. The total
// number of unresolved violations is thus 172
$this->_testMytaskPanelAndLink(
".mri_violations",
"175",
"172",
"- MRI Violated Scans"
);
$this->resetPermissions();
Expand Down

0 comments on commit 2f52b10

Please # to comment.