Skip to content

Commit

Permalink
2.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjpearson committed Jan 29, 2021
1 parent c942d33 commit 119f570
Show file tree
Hide file tree
Showing 27 changed files with 639 additions and 141 deletions.
30 changes: 22 additions & 8 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ public static function getEmailName($record) {
}

public static function getCitationFields($metadata) {
$metadataFields = REDCapManagement::getFieldsFromMetadata($metadata);
$fields = ["record_id"];
foreach (self::$citationFields as $field) {
if (in_array($field, $metadataFields)) {
$fields[] = $field;
}
}
return $fields;
return REDCapManagement::screenForFields($metadata, self::$citationFields);
}

public static function getCustomFields($metadata) {
return REDCapManagement::screenForFields($metadata, self::$customFields);
}

public static function getExporterFields($metadata) {
return REDCapManagement::screenForFields($metadata, CareerDev::$exporterFields);
}

public static function getInstitution() {
Expand Down Expand Up @@ -431,13 +432,26 @@ public static function getIndividualKLength() {
"citation_month",
"citation_day",
"citation_pages",
"citation_abstract",
"citation_is_research",
"citation_num_citations",
"citation_citations_per_year",
"citation_expected_per_year",
"citation_field_citation_rate",
"citation_nih_percentile",
"citation_rcr",
"citation_icite_last_update",
"citation_altmetric_score",
"citation_altmetric_image",
"citation_altmetric_details_url",
"citation_altmetric_id",
"citation_altmetric_fbwalls_count",
"citation_altmetric_feeds_count",
"citation_altmetric_gplus_count",
"citation_altmetric_posts_count",
"citation_altmetric_tweeters_count",
"citation_altmetric_accounts_count",
"citation_altmetric_last_update",
);

public static $customFields = array(
Expand Down
67 changes: 40 additions & 27 deletions CareerDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CareerDev {
public static $passedModule = NULL;

public static function getVersion() {
return "2.29.0";
return "2.30.0";
}

public static function getLockFile($pid) {
Expand Down Expand Up @@ -690,32 +690,44 @@ public static function getMenu($menuName) {
return array();
}

public static $citationFields = array(
"record_id",
"citation_doi",
"citation_pmid",
"citation_include",
"citation_source",
"citation_pmcid",
"citation_authors",
"citation_title",
"citation_pub_types",
"citation_mesh_terms",
"citation_journal",
"citation_volume",
"citation_issue",
"citation_year",
"citation_month",
"citation_day",
"citation_pages",
"citation_is_research",
"citation_num_citations",
"citation_citations_per_year",
"citation_expected_per_year",
"citation_field_citation_rate",
"citation_nih_percentile",
"citation_rcr",
);
public static $citationFields = [
"record_id",
"citation_pmid",
"citation_include",
"citation_source",
"citation_pmcid",
"citation_authors",
"citation_title",
"citation_pub_types",
"citation_mesh_terms",
"citation_journal",
"citation_volume",
"citation_issue",
"citation_year",
"citation_month",
"citation_day",
"citation_pages",
"citation_abstract",
"citation_is_research",
"citation_num_citations",
"citation_citations_per_year",
"citation_expected_per_year",
"citation_field_citation_rate",
"citation_nih_percentile",
"citation_rcr",
"citation_icite_last_update",
"citation_altmetric_score",
"citation_altmetric_image",
"citation_altmetric_details_url",
"citation_altmetric_id",
"citation_altmetric_fbwalls_count",
"citation_altmetric_feeds_count",
"citation_altmetric_gplus_count",
"citation_altmetric_posts_count",
"citation_altmetric_tweeters_count",
"citation_altmetric_accounts_count",
"citation_altmetric_last_update",
];

public static $smallCitationFields = array(
"record_id",
Expand Down Expand Up @@ -820,6 +832,7 @@ public static function getMenu($menuName) {
"exporter_indirect_cost_amt",
"exporter_total_cost",
"exporter_total_cost_sub_project",
"exporter_abstract",
"exporter_last_update",
);

Expand Down
3 changes: 3 additions & 0 deletions FlightTrackerExternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require_once(dirname(__FILE__)."/classes/Download.php");
require_once(dirname(__FILE__)."/classes/NameMatcher.php");
require_once(dirname(__FILE__)."/cronLoad.php");
require_once(APP_PATH_DOCROOT."Classes/System.php");

class FlightTrackerExternalModule extends AbstractExternalModule
{
Expand Down Expand Up @@ -397,6 +398,8 @@ private function shareDataInternally($pids) {
}

function cron() {
\System::increaseMaxExecTime(7200); // 2 hours

$this->setupApplication();
$pids = $this->framework->getProjectsWithModuleEnabled();
CareerDev::log($this->getName()." running for pids ".json_encode($pids));
Expand Down
4 changes: 4 additions & 0 deletions bulkImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
$unmatchedLines = [];
$maxInstances = [];
$i = 0;
$customFields = Application::getCustomFields($metadata);
foreach ($lines as $line) {
$firstName = $line[0];
$lastName = $line[1];
Expand Down Expand Up @@ -81,6 +82,9 @@
"custom_last_update" => date("Y-m-d"),
"custom_grant_complete" => "2",
];
if (in_array("custom_costs_total", $customFields)) {
$uploadRow["custom_costs_total"] = $line[11];
}
$upload[] = $uploadRow;
} else if ($title == "Positions") {
list($department, $other) = findDepartment($line[8], $choices, "promotion_department");
Expand Down
20 changes: 11 additions & 9 deletions charts/makeCDATable.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function getTimeSpan($row, $i) {
$start = $row['summary_award_date_'.$i];
$end = $row['summary_award_date_'.($i + 1)];
if ($start && $end) {
return floor(REDCapManagement::datediff($start, $end, "y") * 10) / 10;
return round(REDCapManagement::datediff($start, $end, "y") * 10) / 10;
}
return "";
}
Expand Down Expand Up @@ -370,14 +370,16 @@ function appendCitationLabel($num) {
}
}
} else {
# main path
echo "<td class='cell $rightBox'>$type$date$mech$budget$link</td>";
$ts = getTimeSpan($normativeRow, $i);
if ($ts !== "") {
echo "<td class='spacer'><div class='spacerYears'>$ts</div><div class='spacerYear'>years<br>b/w<br>starts</div></td>";
} else {
echo "<td class='spacer'></td>";
}
if (!in_array($grant->getVariable("type"), ["Research Fellowship"])) {
# main path
echo "<td class='cell $rightBox'>$type$date$mech$budget$link</td>";
$ts = getTimeSpan($normativeRow, $i);
if ($ts !== "") {
echo "<td class='spacer'><div class='spacerYears'>$ts</div><div class='spacerYear'>years<br>b/w<br>starts</div></td>";
} else {
echo "<td class='spacer'></td>";
}
}
}
}
$i++;
Expand Down
50 changes: 39 additions & 11 deletions classes/Crons.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,38 @@ public function addCron($file, $method, $dayOfWeek, $records = []) {
if (!empty($records)) {
$cronjob->setRecords($records);
}
// Application::log("Has day of week $dayOfWeek and timestamp for ".date("Y-m-d", $dateTs));
if ($this->isDebug) {
Application::log("Has day of week $dayOfWeek and timestamp for ".date("Y-m-d", $dateTs));
}
if (in_array($dayOfWeek, $possibleDays)) {
# Weekday
if (!isset($this->crons[$dayOfWeek])) {
$this->crons[$dayOfWeek] = [];
// Application::log("Reset cron list for $dayOfWeek");
if ($this->isDebug) {
Application::log("Reset cron list for $dayOfWeek");
}
}
$this->crons[$dayOfWeek][] = $cronjob;
// Application::log("Assigned cron for $dayOfWeek");
if ($this->isDebug) {
Application::log("Assigned cron for $dayOfWeek");
}
} else if ($dateTs) {
# Y-M-D
$date = date(self::getDateFormat(), $dateTs);
if (!isset($this->crons[$date])) {
$this->crons[$date] = [];
// Application::log("Reset cron list for $date");
if ($this->isDebug) {
Application::log("Reset cron list for $date");
}
}
$this->crons[$date][] = $cronjob;
// Application::log("Assigned cron for $date");
if ($this->isDebug) {
Application::log("Assigned cron for $date");
}
}
// Application::log("Added cron $method: ".$this->getNumberOfCrons()." total crons now");
if ($this->isDebug) {
Application::log("Added cron $method: ".$this->getNumberOfCrons()." total crons now");
}
}

private static function getDaysOfWeek() {
Expand Down Expand Up @@ -138,13 +150,15 @@ public function run($adminEmail = "", $tokenName = "", $additionalEmailText = ""
$records = $recordsToRun;
}
}
Application::log("Running ".$cronjob->getTitle());
Application::log("Running ".$cronjob->getTitle()." with ".count($records)." records");
$run[$cronjob->getTitle()] = array("text" => "Attempted", "ts" => self::getTimestamp());
try {
if (!$this->token || !$this->server) {
throw new \Exception("Could not pass token '".$this->token."' or server '".$this->server."' to cron job");
}
$cronjob->run($this->token, $this->server, $this->pid, $records);
if (!$this->isDebug) {
$cronjob->run($this->token, $this->server, $this->pid, $records);
}
$run[$cronjob->getTitle()] = array("text" => "Succeeded", "ts" => self::getTimestamp());
} catch(\Throwable $e) {
$this->handle($e, $adminEmail, $cronjob);
Expand All @@ -153,6 +167,13 @@ public function run($adminEmail = "", $tokenName = "", $additionalEmailText = ""
}
}
if (count($toRun) > 0) {
if ($this->isDebug) {
Application::log("Attempting to save current date");
Application::saveCurrentDate("Test", $this->pid);
Application::removeCurrentDate("Test", $this->pid);
Application::log("Done attempting to save current date");
}

$text = $tokenName." ".$this->server."<br><br>";
foreach ($run as $title => $mssgAry) {
$mssg = $mssgAry['text'];
Expand All @@ -168,12 +189,18 @@ public function run($adminEmail = "", $tokenName = "", $additionalEmailText = ""
}
if (!class_exists("\REDCap") || !method_exists("\REDCap", "email")) {
throw new \Exception("Could not instantiate REDCap class!");
}
Application::log("Sending ".Application::getProgramName()." email for pid ".$this->pid." to $adminEmail");
\REDCap::email($adminEmail, "[email protected]", Application::getProgramName()." Cron Report", $text);
}
if (!$this->isDebug) {
Application::log("Sending ".Application::getProgramName()." email for pid ".$this->pid." to $adminEmail");
\REDCap::email($adminEmail, "[email protected]", Application::getProgramName()." Cron Report", $text);
}
}
}

public function setDebug($isDebug) {
$this->isDebug = $isDebug;
}

public function handle($e, $adminEmail, $cronjob) {
Application::log("Exception ".json_encode($e));
if (!class_exists("\REDCap") || !method_exists("\REDCap", "email")) {
Expand All @@ -200,6 +227,7 @@ public function handle($e, $adminEmail, $cronjob) {
private $sendErrorLogs;
private static $lastAdminEmail;
private static $lastSendErrorLogs;
private $isDebug = FALSE;
}

class CronJob {
Expand Down
15 changes: 9 additions & 6 deletions classes/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ public static function primaryMentors($token, $server) {
return $mentors;
}

public static function trainingGrants($token, $server, $fields = array(), $traineeTypes = array(5, 6, 7), $records = []) {
public static function trainingGrants($token, $server, $fields = [], $traineeTypes = [5, 6, 7], $records = [], $metadata = []) {
if (empty($fields)) {
$fields = Application::$customFields; // default
if (empty($metadata)) {
$metadata = self::metadata($token, $server);
}
$fields = Application::getCustomFields($metadata); // default
}
if (empty($records)) {
$records = self::recordIds($token, $server);
Expand All @@ -203,8 +206,8 @@ public static function trainingGrants($token, $server, $fields = array(), $train
return $filteredData;
}

public static function appointmentsForRecord($token, $server, $record, $traineeTypes = [5, 6, 7]) {
$redcapData = self::trainingGrants($token, $server, array("record_id", "custom_role"), $traineeTypes, [$record]);
public static function appointmentsForRecord($token, $server, $record, $traineeTypes = [5, 6, 7], $metadata = []) {
$redcapData = self::trainingGrants($token, $server, array("record_id", "custom_role"), $traineeTypes, [$record], $metadata);
$types = [];
foreach ($redcapData as $row) {
$roleType = $row['custom_role'];
Expand All @@ -215,8 +218,8 @@ public static function appointmentsForRecord($token, $server, $record, $traineeT
return $types;
}

public static function recordsWithTrainees($token, $server, $traineeTypes = array(5, 6, 7)) {
$redcapData = self::trainingGrants($token, $server, array("record_id", "custom_role"), $traineeTypes);
public static function recordsWithTrainees($token, $server, $traineeTypes = [5, 6, 7], $metadata = []) {
$redcapData = self::trainingGrants($token, $server, array("record_id", "custom_role"), $traineeTypes, $metadata);
$records = array();
foreach ($redcapData as $row) {
$recordId = $row['record_id'];
Expand Down
13 changes: 11 additions & 2 deletions classes/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,11 @@ private function getCurrentType()
$specs = $this->specs;
$awardNo = $this->getNumber();

if ($specs['pi_flag'] == 'N') {
if (SHOW_GRANT_DEBUG) { Application::log($awardNo.": pi_flag is N"); }
return "N/A";
}

if (SHOW_GRANT_DEBUG) { Application::log($awardNo.": First Pass"); }
if ($type = $this->lexicallyTranslate($awardNo)) {
return $type;
Expand Down Expand Up @@ -1322,8 +1327,8 @@ public static function calculateAwardType($specs, $awardNo) {
return "K Equivalent";
} else if (preg_match("/^\d?[Rr]00/", $awardNo) || preg_match("/^\d?[Kk]\s*99/", $awardNo)) {
return "K99/R00";
} else if (preg_match("/^\d?[Rr]01/", $awardNo)) {
return "R01";
} else if (preg_match("/^\d?[Rr]01/", $awardNo)) {
return "R01";
} else if (preg_match("/^\d?[Tt]\d\d/", $awardNo) || preg_match("/^\d?[Dd]43/", $awardNo)) {
return "Training Grant Admin";
} else if ($specs['direct_budget'] && ($specs['direct_budget'] >= 750000)) {
Expand Down Expand Up @@ -1368,6 +1373,10 @@ public static function calculateAwardType($specs, $awardNo) {
return "R01 Equivalent";
} else if (preg_match("/^\d?R35/", $awardNo)) {
return "R01 Equivalent";
} else if (preg_match("/^\d?[Dd][Pp]1/", $awardNo)) {
return "R01 Equivalent";
} else if (preg_match("/^\d?DP7/", $awardNo) || preg_match("/^\d?[Rr]25/", $awardNo) || preg_match("/^\d?[Tt]90/", $awardNo)) {
return "Training Grant Admin";
} else if (preg_match("/Internal K/", $awardNo)) {
return "Internal K";
} else if (preg_match("/K12\/KL2/", $awardNo)) {
Expand Down
Loading

0 comments on commit 119f570

Please sign in to comment.