Skip to content

Commit

Permalink
Create getDefaultCohort and getDefaultProject in ConfigOB
Browse files Browse the repository at this point in the history
  • Loading branch information
laemtl committed Mar 3, 2023
1 parent 516b093 commit 797eb1e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 23 deletions.
4 changes: 2 additions & 2 deletions dicom-archive/profileTemplate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ sub getSubjectIDs {

$subjectID{'createVisitLabel'} = 1;

# $subjectID{'CohortID'} = undef;
# When createVisitLabel is set to 1, CohortID must also
# $subjectID{'CohortID'} = undef;
# When createVisitLabel is set to 1, CohortID must also
# be set to the ID of the cohort that the newly created
# visit should have. Assuming for example that all patient
# names end with "_<myCohortID>", then we could write:
Expand Down
12 changes: 12 additions & 0 deletions docs/scripts_md/ConfigOB.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ Get the createVisit Config setting.

RETURN: (boolean) 1 if createVisit is set to Yes in the Config module, 0 otherwise

### getDefaultProject()

Get the default_project Config setting.

RETURN: value (string) of the default_project config in the Config table.

### getDefaultCohort()

Get the default_cohort Config setting.

RETURN: value (string) of the default_cohort config in the Config table.

### getPythonConfigFile()

Get the MriPythonConfigFile Config setting.
Expand Down
33 changes: 16 additions & 17 deletions uploadNeuroDB/NeuroDB/MRI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ sub getProject {
my ($subjectIDsref, $dbhr) = @_;
my $PSCID = $subjectIDsref->{'PSCID'};
my $visitLabel = $subjectIDsref->{'visitLabel'};
my $configOB = NeuroDB::objectBroker::ConfigOB->new(db => $db);

## Get the ProjectID from the session table, if the PSCID and visit labels exist
## and could be extracted
Expand Down Expand Up @@ -1176,14 +1177,13 @@ sub getProject {
}

## Otherwise, use the default_project config value
my $query = "SELECT p.ProjectID
FROM Config c
JOIN ConfigSettings cs ON c.ConfigID = cs.ID
JOIN Project p ON p.Name = c.Value
WHERE cs.Name = 'default_project'";
my $query = "SELECT ProjectID
FROM Project
WHERE Name = ?";

my $default_project = $configOB->getDefaultProject();
my $sth = $${dbhr}->prepare($query);
$sth->execute();
$sth->execute($default_project);
if ( $sth->rows > 0) {
my $row = $sth->fetchrow_hashref();
if ($row->{'ProjectID'}) {
Expand Down Expand Up @@ -1217,6 +1217,7 @@ sub getCohort {
my ($subjectIDsref, $projectID, $dbhr) = @_;
my $PSCID = $subjectIDsref->{'PSCID'};
my $visitLabel = $subjectIDsref->{'visitLabel'};
my $configOB = NeuroDB::objectBroker::ConfigOB->new(db => $db);

## Get the CohortID from the session table, if the PSCID and visit labels exist
## and could be extracted
Expand All @@ -1234,18 +1235,16 @@ sub getCohort {
}

## Otherwise, use the default_cohort config value
my $query = "SELECT c.Value
FROM Config c
JOIN ConfigSettings cs ON c.ConfigID = cs.ID
WHERE cs.Name = 'default_cohort'
AND Value IN (
SELECT title
FROM cohort
JOIN `project_cohort_rel` USING (CohortID)
WHERE ProjectID = ?)";

my $query = "SELECT CohortID
FROM cohort
JOIN project_cohort_rel USING (CohortID)
JOIN Project USING(ProjectID)
WHERE title = ? AND Name = ?";

my $default_cohort = $configOB->getDefaultCohort();
my $default_project = $configOB->getDefaultProject();
my $sth = $${dbhr}->prepare($query);
$sth->execute($projectID);
$sth->execute($default_cohort, $default_project);
if ( $sth->rows > 0) {
my $row = $sth->fetchrow_hashref();
if ($row->{'Value'}) {
Expand Down
6 changes: 3 additions & 3 deletions uploadNeuroDB/NeuroDB/MRIProcessingUtility.pm
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ sub determineSubjectID {

my $this = shift;
my ($scannerID, $tarchiveInfo, $to_log, $upload_id, $User, $centerID) = @_;
my $dbhr = $this->{dbhr};
my $dbhr = $this->{dbhr};

$to_log = 1 unless defined $to_log;
if (!defined(&Settings::getSubjectIDs)) {
Expand All @@ -421,8 +421,8 @@ sub determineSubjectID {
$subjectIDsref->{'ProjectID'} = $projectID;
}

if (!$subjectIDsref->{'SubprojectID'}) {
$subjectIDsref->{'SubprojectID'} = NeuroDB::MRI::getCohort($subjectIDsref, $subjectIDsref->{'ProjectID'}, $dbhr);
if (!$subjectIDsref->{'CohortID'}) {
$subjectIDsref->{'CohortID'} = NeuroDB::MRI::getCohort($subjectIDsref, $subjectIDsref->{'ProjectID'}, $dbhr);
}

# create the candidate if it does not exist
Expand Down
28 changes: 27 additions & 1 deletion uploadNeuroDB/NeuroDB/objectBroker/ConfigOB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ use NeuroDB::objectBroker::ObjectBrokerException;

use TryCatch;

<<<<<<< HEAD
use constant TARCHIVE_LIBRARY_DIR => 'tarchiveLibraryDir';
use constant DATA_DIR_BASE_PATH => 'dataDirBasepath';
use constant MAIL_USER => 'mail_user';
Expand Down Expand Up @@ -96,6 +95,7 @@ use constant BIDS_README_TEXT => 'bids_readme_text';
use constant BIDS_VALIDATOR_OPTIONS_TO_IGNORE => 'bids_validator_options_to_ignore';
use constant CREATE_CANDIDATES => 'createCandidates';
use constant CREATE_VISIT => 'createVisit';
use constant DEFAULT_COHORT => 'default_cohort';

=pod
Expand Down Expand Up @@ -464,6 +464,32 @@ sub getCreateVisit {
return $getBooleanRef->($value);
}

=head3 getDefaultProject()
Get the default_project Config setting.
RETURN: value (string) of the default_project config in the Config table.
=cut
sub getDefaultProject {
my $self = shift;

return &$getConfigSettingRef($self, DEFAULT_PROJECT);
}

=head3 getDefaultCohort()
Get the default_cohort Config setting.
RETURN: value (string) of the default_cohort config in the Config table.
=cut
sub getDefaultCohort {
my $self = shift;

return &$getConfigSettingRef($self, DEFAULT_COHORT);
}

=head3 getPythonConfigFile()
Get the MriPythonConfigFile Config setting.
Expand Down

0 comments on commit 797eb1e

Please sign in to comment.