-
Notifications
You must be signed in to change notification settings - Fork 174
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
Transfer mri violations to resolved tab in bulk #1776
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c7af24
Transfer mri violations to resolved tab in bulk
gluneau ceed117
removed IBIS specific MincFileViolated column
gluneau cf43884
Merge branch '16.1-dev' into mri_violation-resolved-tool
gluneau 815a3be
Merge branch '16.1-dev' into mri_violation-resolved-tool
gluneau d64a755
Merge branch '16.1-dev' into mri_violation-resolved-tool
gluneau 74f8d91
more documentation and a confirm argument, phpcs
gluneau 8547b28
Merge branch 'mri_violation-resolved-tool' of github.com:gluneau/Lori…
gluneau 6045620
new print_r and syntax correction
gluneau 5f0ebdc
changed lorisadmin by get_current_user()
gluneau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
/** | ||
* This script is used to move mri violations to the resolved tab in bulk. | ||
* This is the first step for a project that wants to insert scans that were | ||
* previously excluded. | ||
* Just modify the where clause and test on the front end with same filter first. | ||
* | ||
* Usage: php mri_violations_resolver.php [confirm] | ||
* | ||
* PHP Version 5 | ||
* | ||
* @category MRI | ||
* @package Main | ||
* @author Gregory Luneau <gregory.luneau@mcgill.ca> | ||
* @license Loris License | ||
* @link https://www.github.com/aces/Loris/ | ||
*/ | ||
|
||
set_include_path(get_include_path().":../project/libraries:../php/libraries:"); | ||
|
||
// path to config file | ||
$configFile = "../project/config.xml"; | ||
|
||
require_once __DIR__ . "/../vendor/autoload.php"; | ||
require_once "NDB_Client.class.inc"; | ||
|
||
|
||
$confirm = false; | ||
if (isset($argv[1]) && $argv[1] === "confirm") { | ||
$confirm = true; | ||
} | ||
|
||
$client = new NDB_Client(); | ||
$client->makeCommandLine(); | ||
$client->initialize($configFile); | ||
|
||
$DB =& Database::singleton(); | ||
|
||
// Query as it is in the mri violation module | ||
// It is complete as it apears in the module for two reasons: | ||
// 1. for reproducibility, this tools expects that you have validated your search | ||
// in LORIS front end first. | ||
// 2. for future feature improvements that will use currently unused part of this | ||
// query. | ||
$query = "SELECT v.PatientName, v.Project, v.Subproject, v.Site, v.TimeRun, | ||
v.MincFile, v.Series_Description as Series_Description_Or_Scan_Type, | ||
v.Problem, v.SeriesUID, v.hash, v.join_id, v.Resolved FROM ( | ||
SELECT PatientName as PatientName, | ||
time_run as TimeRun, | ||
c.ProjectID as Project, | ||
s.SubprojectID as Subproject, | ||
minc_location as MincFile, | ||
series_description as Series_Description, | ||
'Could not identify scan type' as Problem, | ||
SeriesUID, | ||
md5(concat_WS(':',minc_location,PatientName,SeriesUID,time_run)) as hash, | ||
mri_protocol_violated_scans.ID as join_id, | ||
p.CenterID as Site, | ||
violations_resolved.Resolved as Resolved | ||
FROM mri_protocol_violated_scans | ||
LEFT JOIN violations_resolved | ||
ON (violations_resolved.ExtID=mri_protocol_violated_scans.ID | ||
AND violations_resolved.TypeTable='mri_protocol_violated_scans') | ||
LEFT JOIN candidate c | ||
ON (mri_protocol_violated_scans.CandID = c.CandID) | ||
LEFT JOIN session s | ||
ON (mri_protocol_violated_scans.CandID = s.CandID) | ||
LEFT JOIN psc p | ||
ON (p.CenterID = c.CenterID) | ||
WHERE Resolved is NULL UNION SELECT PatientName, | ||
TimeRun, | ||
c.ProjectID as Project, | ||
s.SubprojectID as Subproject, | ||
MincFile, | ||
mri_scan_type.Scan_type, | ||
'Protocol Violation', | ||
SeriesUID, | ||
md5(concat_WS(':',MincFile,PatientName,SeriesUID,TimeRun)) as hash, | ||
mri_violations_log.LogID as join_id, | ||
p.CenterID as Site, | ||
violations_resolved.Resolved as Resolved | ||
FROM mri_violations_log | ||
LEFT JOIN mri_scan_type | ||
ON (mri_scan_type.ID=mri_violations_log.Scan_type) | ||
LEFT JOIN violations_resolved | ||
ON (violations_resolved.ExtID=mri_violations_log.LogID | ||
AND violations_resolved.TypeTable='mri_violations_log') | ||
LEFT JOIN candidate c | ||
ON (mri_violations_log.CandID=c.CandID) | ||
LEFT JOIN session s | ||
ON (mri_violations_log.CandID = s.CandID) | ||
LEFT JOIN psc p | ||
ON (p.CenterID = c.CenterID) | ||
WHERE Resolved is NULL UNION SELECT PatientName, | ||
TimeRun, | ||
c.ProjectID as Project, | ||
s.SubprojectID as Subproject, | ||
MincFile, | ||
null, | ||
Reason, | ||
SeriesUID, | ||
md5(concat_WS(':',MincFile,PatientName,SeriesUID,TimeRun)) as hash, | ||
MRICandidateErrors.ID as join_id, | ||
p.CenterID as Site, | ||
violations_resolved.Resolved as Resolved | ||
FROM MRICandidateErrors | ||
LEFT JOIN violations_resolved | ||
ON (violations_resolved.ExtID=MRICandidateErrors.ID | ||
AND violations_resolved.TypeTable='MRICandidateErrors') | ||
LEFT JOIN candidate c | ||
ON (SUBSTRING_INDEX(MRICandidateErrors.PatientName,'_',1)=c.PSCID) | ||
LEFT JOIN session s | ||
ON (c.CandID = s.CandID) | ||
LEFT JOIN psc p | ||
ON (p.CenterID = c.CenterID) | ||
WHERE Resolved is NULL) | ||
as v WHERE | ||
v.problem = :pr and | ||
v.series_description like :sd | ||
ORDER BY v.TimeRun DESC"; | ||
|
||
// Filter values to modify | ||
$where = array( | ||
'pr' => 'Protocol Violation', | ||
'sd' => '%t1%', | ||
); | ||
$results = $DB->pselect($query, $where); | ||
|
||
foreach ($results AS $result) { | ||
|
||
$newlyResolved = array(); | ||
$newlyResolved['hash'] = $result['hash']; | ||
$newlyResolved['Resolved'] = 'inserted_flag'; | ||
$newlyResolved['User'] = get_current_user(); | ||
$newlyResolved['ChangeDate'] = date("Y-m-d H:i:s"); | ||
$newlyResolved['TypeTable'] = 'mri_violations_log'; | ||
$newlyResolved['ExtID'] = $result['join_id']; | ||
|
||
// Does a hash and a ExtID already exists? | ||
$row = $DB->pselectRow( | ||
"SELECT * FROM violations_resolved | ||
WHERE hash = :ha and ExtID = :ex ", | ||
array( | ||
'ha' => $result['hash'], | ||
'ex' => $result['join_id'], | ||
) | ||
); | ||
|
||
// Insert if new | ||
if (empty($row)) { | ||
if ($confirm) { | ||
$DB->insert('violations_resolved', $newlyResolved); | ||
print "inserting\t"; | ||
} | ||
print_r($newlyResolved); | ||
} else { | ||
print "skip\n"; | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you confirm that $argv[1] is correct when run with "php" as documented?