Skip to content
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

Add ProjectID to scanner candidate #914

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dicom-archive/profileTemplate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# extracts the subject and timepoint identifiers from the patient name
# assumes identifers are stored as <PSCID>_<DCCID>_<visit> in PatientName field, where <visit> is 3 digits.
sub getSubjectIDs {
my ($patientName, $patientID, $scannerID, $dbhr, $db) = @_;
my ($patientName, $scannerID, $dbhr, $db) = @_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't removing the patientID field in the prod file function getSubjectIDs break some projects that might be using DICOM header PatientID instead of PatientName to determine subject IDs? Unless the value $patientName is either PatientName header or PatientID header based on the lookupCenterName config value?

@nicolasbrossard thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not necessary if it breaks things. I just noticed it was not used in the default logic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK then, if you can revert this specific change just in case there is a project that is using PatientID in their prod file. Thanks!


my %subjectID; # Will stored subject IDs.

Expand Down Expand Up @@ -127,7 +127,6 @@ sub getSubjectIDs {
"\n ProjectID is: " . $subjectID{'ProjectID'} . "\n";
}

# Return subjectIDs
return \%subjectID;
}

Expand Down
9 changes: 6 additions & 3 deletions docs/scripts_md/MRI.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ referenced by `$file_ref`.

INPUT: file hash ref

### findScannerID($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $dbhr, $db)
### findScannerID($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $projectID, $dbhr, $db)

Finds the scanner ID for the scanner as defined by `$manufacturer`, `$model`,
`$serialNumber`, `$softwareVersion`, using the database attached to the DBI
Expand All @@ -197,12 +197,13 @@ INPUTS:
- $serialNumber : scanner's serial number
- $softwareVersion: scanner's software version
- $centerID : scanner's center ID
- $projectID : scanner's project ID
- $dbhr : database handle reference
- $db : database object

RETURNS: (int) scanner ID

### registerScanner($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $dbhr, $db)
### registerScanner($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $projectID, $dbhr, $db)

Registers the scanner as defined by `$manufacturer`, `$model`,
`$serialNumber`, `$softwareVersion`, into the database attached to the DBI
Expand All @@ -214,6 +215,7 @@ INPUTS:
- $serialNumber : scanner's serial number
- $softwareVersion: scanner's software version
- $centerID : scanner's center ID
- $projectID : scanner's project ID
- $dbhr : database handle reference
- $db : database object

Expand Down Expand Up @@ -243,7 +245,7 @@ RETURNS: a two element array:
- first is the MRI alias of the PSC or "UNKN"
- second is the `CenterID` or 0

### getProject($patientName, $dbhr, $db)
### getProject($subjectIDsref, $dbhr, $db)

Looks for the project id using the C<session> table C<ProjectID> as
a first resource, then using the C<candidate> table C<RegistrationProjectID>,
Expand All @@ -252,6 +254,7 @@ otherwise, look for the default_project config value, and return C<ProjectID>.
INPUTS:
- $subjectIDsref: subject's information hash ref
- $dbhr : database handle reference
- $db : database object

RETURNS: the C<ProjectID> or an error if not found

Expand Down
8 changes: 5 additions & 3 deletions docs/scripts_md/MRIProcessingUtility.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ utilities

my ($center_name, $centerID) = $utility->determinePSC(\%tarchiveInfo,0);

my $scannerID = $utility->determineScannerID(\%tarchiveInfo, 0, $centerID);
my $projectID = $utility->determineProjectID(\%tarchiveInfo);
my $scannerID = $utility->determineScannerID(\%tarchiveInfo, 0, $centerID, $projectID);

my $subjectIDsref = $utility->determineSubjectID(
$scannerID,
Expand Down Expand Up @@ -169,7 +170,7 @@ INPUTS:

RETURNS: array of two elements: center name and center ID

### determineScannerID($tarchiveInfo, $to\_log, $centerID, $upload\_id)
### determineScannerID($tarchiveInfo, $to\_log, $centerID, $projectID, $upload\_id)

Determines which scanner ID was used for DICOM acquisitions. Note, if
a scanner ID is not already associated to the scanner information found
Expand All @@ -178,7 +179,8 @@ in the DICOM headers, then a new scanner will automatically be created.
INPUTS:
- $tarchiveInfo: archive information hash ref
- $to\_log : whether this step should be logged
- $centerID : center ID
- $centerID : center ID
- $projectID : project ID
- $upload\_id : upload ID of the study

RETURNS: scanner ID
Expand Down
20 changes: 10 additions & 10 deletions uploadNeuroDB/NeuroDB/MRI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ sub mapDicomParameters {
}
=pod

=head3 findScannerID($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $dbhr, $db)
=head3 findScannerID($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $projectID, $dbhr, $db)

Finds the scanner ID for the scanner as defined by C<$manufacturer>, C<$model>,
C<$serialNumber>, C<$softwareVersion>, using the database attached to the DBI
Expand All @@ -974,6 +974,7 @@ INPUTS:
- $serialNumber : scanner's serial number
- $softwareVersion: scanner's software version
- $centerID : scanner's center ID
- $projectID : scanner's project ID
- $dbhr : database handle reference
- $db : database object

Expand All @@ -982,7 +983,7 @@ RETURNS: (int) scanner ID
=cut

sub findScannerID {
my ($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $dbhr, $db) = @_;
my ($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $projectID, $dbhr, $db) = @_;

my $mriScannerOB = NeuroDB::objectBroker::MriScannerOB->new( db => $db );
my $resultsRef = $mriScannerOB->get( {
Expand All @@ -996,14 +997,14 @@ sub findScannerID {
return $resultsRef->[0]->{'ID'} if @$resultsRef;

# register new scanners
my $scanner_id = registerScanner($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $dbhr, $db);
my $scanner_id = registerScanner($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $projectID, $dbhr, $db);

return $scanner_id;
}

=pod

=head3 registerScanner($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $dbhr, $db)
=head3 registerScanner($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $projectID, $dbhr, $db)

Registers the scanner as defined by C<$manufacturer>, C<$model>,
C<$serialNumber>, C<$softwareVersion>, into the database attached to the DBI
Expand All @@ -1015,6 +1016,7 @@ INPUTS:
- $serialNumber : scanner's serial number
- $softwareVersion: scanner's software version
- $centerID : scanner's center ID
- $projectID : scanner's project ID
- $dbhr : database handle reference
- $db : database object

Expand All @@ -1023,7 +1025,7 @@ RETURNS: (int) scanner ID
=cut

sub registerScanner {
my ($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $dbhr, $db) = @_;
my ($manufacturer, $model, $serialNumber, $softwareVersion, $centerID, $projectID, $dbhr, $db) = @_;
# my $scanner_id = 0;
my @results = ();
my $dbh = $$dbhr;
Expand All @@ -1036,11 +1038,10 @@ sub registerScanner {
if(!defined($candID) || ($candID eq 'NULL')) {
$candID = createNewCandID($dbhr);
$query = "INSERT INTO candidate "
. "(CandID, PSCID, RegistrationCenterID, Date_active, "
. " Date_registered, UserID, Entity_type ) "
. "(CandID, PSCID, RegistrationCenterID, RegistrationProjectID, Date_active, "
. " Date_registered, UserID, Entity_type) "
. "VALUES "
. "($candID, 'scanner', $centerID, NOW(), "
. " NOW(), 'NeuroDB::MRI', 'Scanner' ) ";
. "($candID, 'scanner', $centerID, $projectID, NOW(), NOW(), 'NeuroDB::MRI', 'Scanner')";
$dbh->do($query);
}

Expand Down Expand Up @@ -1105,7 +1106,6 @@ sub getPSC {
my $subjectIDsref = Settings::getSubjectIDs(
$patientName,
undef,
undef,
$dbhr,
$db
);
Expand Down
47 changes: 41 additions & 6 deletions uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ utilities

my ($center_name, $centerID) = $utility->determinePSC(\%tarchiveInfo,0);

my $scannerID = $utility->determineScannerID(\%tarchiveInfo, 0, $centerID);
my $projectID = $utility->determineProjectID(\%tarchiveInfo);
my $scannerID = $utility->determineScannerID(\%tarchiveInfo, 0, $centerID, $projectID);
laemtl marked this conversation as resolved.
Show resolved Hide resolved

my $subjectIDsref = $utility->determineSubjectID(
$scannerID,
Expand Down Expand Up @@ -386,8 +387,8 @@ INPUTS:
- $User : user running the insertion pipeline
- $centerID : center ID of the candidate

RETURNS: subject's ID hash ref containing C<CandID>, C<PSCID>, Visit Label
and C<CandMismatchError> information
RETURNS: subject's ID hash ref containing C<CandID>, C<PSCID>, Visit Label,
ProjectID, CohortID and C<CandMismatchError> information

=cut

Expand All @@ -414,7 +415,7 @@ sub determineSubjectID {
my $patientID = $tarchiveInfo->{'PatientID'};
my $patientName = $tarchiveInfo->{'PatientName'};
my $subjectIDsref = Settings::getSubjectIDs(
$patientName, $patientID, $scannerID, $this->{dbhr}, $this->{'db'}
$patientName, $scannerID, $dbhr, $this->{'db'}
);

if (!$subjectIDsref->{'createVisitLabel'}) {
Expand Down Expand Up @@ -641,7 +642,39 @@ sub determinePSC {

=pod

=head3 determineScannerID($tarchiveInfo, $to_log, $centerID, $upload_id)
=head3 determineProjectID($tarchiveInfo)

Determines the Project.

INPUTS:
- $tarchiveInfo: archive information hash ref

RETURNS: project ID

=cut

sub determineProjectID {

my $this = shift;
my ($tarchiveInfo) = @_;
my $subjectIDsref = Settings::getSubjectIDs(
$tarchiveInfo->{'PatientName'},
undef,
$this->{dbhr},
$this->{db}
);

if (defined $subjectIDsref->{'ProjectID'}) {
return $subjectIDsref->{'ProjectID'}
}

return NeuroDB::MRI::getProject($subjectIDsref, $this->{dbhr}, $this->{db});
}


=pod

=head3 determineScannerID($tarchiveInfo, $to_log, $centerID, $projectID, $upload_id)

Determines which scanner ID was used for DICOM acquisitions. Note, if
a scanner ID is not already associated to the scanner information found
Expand All @@ -651,6 +684,7 @@ INPUTS:
- $tarchiveInfo: archive information hash ref
- $to_log : whether this step should be logged
- $centerID : center ID
- $projectID : project ID
- $upload_id : upload ID of the study

RETURNS: scanner ID
Expand All @@ -660,7 +694,7 @@ RETURNS: scanner ID
sub determineScannerID {

my $this = shift;
my ($tarchiveInfo, $to_log, $centerID, $upload_id) = @_;
my ($tarchiveInfo, $to_log, $centerID, $projectID, $upload_id) = @_;
my $message = '';
$to_log = 1 unless defined $to_log;
if ($to_log) {
Expand All @@ -676,6 +710,7 @@ sub determineScannerID {
$tarchiveInfo->{'ScannerSerialNumber'},
$tarchiveInfo->{'ScannerSoftwareVersion'},
$centerID,
$projectID,
$this->{dbhr},
$this->{'db'}
);
Expand Down
3 changes: 2 additions & 1 deletion uploadNeuroDB/minc_insertion.pl
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ =head2 Methods

## Determine PSC, ScannerID and Subject IDs
my ($center_name, $centerID) = $utility->determinePSC(\%studyInfo, 0, $upload_id);
my $scannerID = $utility->determineScannerID(\%studyInfo, 0, $centerID, $upload_id);
my $projectID = $utility->determineProjectID(\%studyInfo);
my $scannerID = $utility->determineScannerID(\%studyInfo, 0, $centerID, $projectID, $upload_id);
my $subjectIDsref = $utility->determineSubjectID(
$scannerID, \%studyInfo, 0, $upload_id, $User, $centerID
);
Expand Down
57 changes: 32 additions & 25 deletions uploadNeuroDB/register_processed_data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,31 @@ =head2 Methods
}


# ----- STEP 3: Determine ScannerID based:
# ----- STEP 3: Determine using sourceFileID:
# - subject's identifiers
# - sessionID
my ($sessionID,$subjectIDsref) = getSessionID($sourceFileID,$dbh);
if (!defined($sessionID)) {
print LOG "\nERROR: could not determine sessionID based on sourceFileID "
. "$sourceFileID. Are you sure the sourceFile was registered "
. "in DB?\n\n";
exit $NeuroDB::ExitCodes::SELECT_FAILURE;
}
print LOG "\n==> Data found for candidate : $subjectIDsref->{'CandID'} - Visit: $subjectIDsref->{'visitLabel'}\n";
$file->setFileData('SessionID', $sessionID);
print LOG "\t -> Set SessionID to $sessionID.\n";
$file->setFileData('SourceFileID', $sourceFileID);
print LOG "\t -> Set SourceFileID to $sourceFileID.\n";


# ----- STEP 4: Verify project information
my $projectID = NeuroDB::MRI::getProject($subjectIDsref, \$dbh, $db);
print LOG "\nERROR: No project found for this candidate \n\n";
exit $NeuroDB::ExitCodes::SELECT_FAILURE;
print LOG "\n==> ProjectID : $projectID\n";


# ----- STEP 5: Determine ScannerID based:
# - on mincheader information if minc file
# - on sourceFileID for other type of files
my $scannerID;
Expand All @@ -264,10 +288,10 @@ =head2 Methods
$scannerID = NeuroDB::MRI::findScannerID(
$scannerInfo{'ScannerManufacturer'}, $scannerInfo{'ScannerModel'},
$scannerInfo{'ScannerSerialNumber'}, $scannerInfo{'ScannerSoftwareVersion'},
$centerID, \$dbh,
$db
$centerID, $projectID,
\$dbh, $db
);
}else {
} else {
$scannerID = getScannerID($sourceFileID,$dbh);
}

Expand All @@ -280,24 +304,7 @@ =head2 Methods
print LOG "\t -> Set ScannerID to $scannerID.\n";


# ----- STEP 4: Determine using sourceFileID:
# - subject's identifiers
# - sessionID
my ($sessionID,$subjectIDsref) = getSessionID($sourceFileID,$dbh);
if (!defined($sessionID)) {
print LOG "\nERROR: could not determine sessionID based on sourceFileID "
. "$sourceFileID. Are you sure the sourceFile was registered "
. "in DB?\n\n";
exit $NeuroDB::ExitCodes::SELECT_FAILURE;
}
print LOG "\n==> Data found for candidate : $subjectIDsref->{'CandID'} - Visit: $subjectIDsref->{'visitLabel'}\n";
$file->setFileData('SessionID', $sessionID);
print LOG "\t -> Set SessionID to $sessionID.\n";
$file->setFileData('SourceFileID', $sourceFileID);
print LOG "\t -> Set SourceFileID to $sourceFileID.\n";


# ----- STEP 5: Determine AcquisitionProtocolID based on $scanType
# ----- STEP 6: Determine AcquisitionProtocolID based on $scanType
my ($acqProtID) = getAcqProtID($scanType,$dbh);
if (!defined($acqProtID)) {
print LOG "\nERROR: could not determine AcquisitionProtocolID based on scanType $scanType.\n\n";
Expand All @@ -307,7 +314,7 @@ =head2 Methods
print LOG "\t -> Set AcquisitionProtocolID to $acqProtID.\n";


# ----- STEP 6: Set other parameters based on command line arguments
# ----- STEP 7: Set other parameters based on command line arguments
$file->setFileData('CoordinateSpace',$coordinateSpace);
print LOG "\t -> Set CoordinateSpace to $coordinateSpace.\n";
$file->setFileData('SourcePipeline',$sourcePipeline);
Expand All @@ -321,7 +328,7 @@ =head2 Methods
print LOG "\t -> Set ProcessProtocolID to $protocolID.\n";
}

# ----- STEP 7: Compute the md5 hash
# ----- STEP 8: Compute the md5 hash
my $md5hash = &NeuroDB::MRI::compute_hash(\$file);
$file->setParameter('md5hash', $md5hash);
print LOG "\t -> Set md5hash to $md5hash.\n";
Expand All @@ -331,7 +338,7 @@ =head2 Methods
}


# ----- STEP 8: Copy files to assembly folder and register them into the db.
# ----- STEP 9: Copy files to assembly folder and register them into the db.
# Rename and copy file into assembly folder
my $file_protocol_identified = &copy_file(\$filename, $subjectIDsref, $scanType, \$file);
my $file_path = $filename;
Expand Down
3 changes: 2 additions & 1 deletion uploadNeuroDB/tarchiveLoader.pl
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,9 @@ =head2 Methods
################################################################
######### Determine the ScannerID ##############################
################################################################
my $projectID = $utility->determineProjectID(\%tarchiveInfo);
my $scannerID = $utility->determineScannerID(
\%tarchiveInfo, 0, $centerID, $upload_id
\%tarchiveInfo, 0, $centerID, $projectID, $upload_id
);

################################################################
Expand Down
Loading