Skip to content

Commit

Permalink
2.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjpearson committed Jul 10, 2020
1 parent 57ebad3 commit 4814b0b
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 148 deletions.
4 changes: 4 additions & 0 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public static function getGrantClasses() {
return CareerDev::getGrantClasses();
}

public static function refreshRecordSummary($token, $server, $pid, $recordId) {
return CareerDev::refreshRecordSummary($token, $server, $pid, $recordId);
}

public static function getProgramName() {
return CareerDev::getProgramName();
}
Expand Down
15 changes: 13 additions & 2 deletions CareerDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ class CareerDev {
public static $passedModule = NULL;

public static function getVersion() {
return "2.14.8";
return "2.15.0";
}

public static function getLockFile($pid) {
return APP_PATH_TEMP.date("Ymdhis")."_6_makeSummary.$pid.lock";
}

public static function getUnknown() {
public static function refreshRecordSummary($token, $server, $pid, $recordId) {
if (self::getSetting("auto_recalculate", $pid)) {
require_once(dirname(__FILE__) . "/drivers/6d_makeSummary.php");
try {
makeSummary($token, $server, $pid, $recordId);
} catch (\Exception $e) {
echo "<div class='centered padded red'>" . $e->getMessage() . "</div>\n";
}
}
}

public static function getUnknown() {
return "Unknown";
}

Expand Down
384 changes: 354 additions & 30 deletions FlightTrackerExternalModule.php

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions add.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@
}
}
}
list($upload, $emails) = processLines($lines, $recordId, $token, $server);
list($upload, $emails, $newRecordIds) = processLines($lines, $recordId, $token, $server);
$feedback = array();
if (!empty($upload)) {
$feedback = Upload::rows($upload, $token, $server);
} else {
foreach ($newRecordIds as $recordId) {
Application::refreshRecordSummary($token, $server, $pid, $recordId);
}
} else {
$mssg = "No data specified.";
header("Location: ".CareerDev::link("add.php")."&mssg=".urlencode($mssg));
}
Expand Down Expand Up @@ -129,6 +132,7 @@ function processLines($lines, $nextRecordId, $token, $server) {
$lineNum = 1;
$metadata = Download::metadata($token, $server);
$metadataFields = REDCapManagement::getFieldsFromMetadata($metadata);
$recordIds = [];
foreach ($lines as $nodes) {
if (count($nodes) >= 6) {
$firstName = $nodes[0];
Expand Down Expand Up @@ -236,9 +240,19 @@ function processLines($lines, $nextRecordId, $token, $server) {
$mentor = "";
}
if ($nodes[14]) {
$trainingStart = importMDY2YMD($nodes[14], "Start of Training");
if (REDCapManagement::isDate($nodes[14])) {
$trainingStart = importMDY2YMD($nodes[14], "Start of Training");
$orcid = "";
} else {
$trainingStart = "";
$orcid = $nodes[14];
}
} else {
$trainingStart = "";
$orcid = "";
}
if ($nodes[15]) {
$trainingStart = importMDY2YMD($nodes[15], "Start of Training");
}

$uploadRow["imported_dob"] = $dob;
Expand All @@ -251,13 +265,17 @@ function processLines($lines, $nextRecordId, $token, $server) {
$uploadRow["imported_mentor"] = $mentor;
if (in_array("identifier_start_of_training", $metadataFields)) {
$uploadRow["identifier_start_of_training"] = $trainingStart;
}
if ($orcid && in_array("identifier_orcid", $metadataFields)) {
$uploadRow["identifier_orcid"] = $orcid;
}
}
$upload[] = $uploadRow;
$recordIds[] = $uploadRow["record_id"];
}
$lineNum++;
}
return array($upload, $emails);
return array($upload, $emails, $recordIds);
}

function importMDY2YMD($mdyDate, $col) {
Expand Down
3 changes: 2 additions & 1 deletion addNewScholar.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
}
$feedback = Upload::oneRow($uploadRow, $token, $server);
\Vanderbilt\FlightTrackerExternalModule\queueUpInitialEmail($recordId);
if ($feedback['error']) {
Application::refreshRecordSummary($token, $server, $pid, $recordId);
if ($feedback['error']) {
echo "<div class='red padded'>ERROR! ".$feedback['error']."</div>\n";
} else {
echo "<div class='green padded'>Scholar successfully added to Record $recordId. They will be automatically processed and updated with each overnight run.</div>\n";
Expand Down
24 changes: 23 additions & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use \Vanderbilt\CareerDevLibrary\Upload;
use \Vanderbilt\CareerDevLibrary\Scholar;
use \Vanderbilt\CareerDevLibrary\REDCapManagement;
use \Vanderbilt\FlightTrackerExternalModule\FlightTrackerExternalModule;

require_once(dirname(__FILE__)."/CareerDev.php");
require_once(dirname(__FILE__)."/classes/Download.php");
Expand Down Expand Up @@ -325,7 +326,9 @@ function makeSettings($module) {
array_push($ary["Installation Variables"], makeSetting("grant_number", "text", "Grant Number"));
array_push($ary["Installation Variables"], makeSetting("departments", "textarea", "Department Names"));
array_push($ary["Installation Variables"], makeSetting("resources", "textarea", "Resources"));
array_push($ary["Installation Variables"], makeSetting("send_error_logs", "yesno", "Report Fatal Errors to Development Team?"));
array_push($ary["Installation Variables"], makeSetting("send_error_logs", "yesno", "Report Fatal Errors to Development Team?"));
array_push($ary["Installation Variables"], makeCheckboxes("shared_forms", FlightTrackerExternalModule::getConfigurableForms(), "Report Fatal Errors to Development Team?"));
array_push($ary["Installation Variables"], makeSetting("auto_recalculate", "yesno", "Automatically Re-summarize After Data Saves? (No waits until overnight.)", 0));

$ary["Automated Emails"] = array();
array_push($ary["Automated Emails"], makeHelperText("An initial email can automatically be sent out during the first month after the new record is added to the database. If you desire to use this feature, please complete the following fields."));
Expand Down Expand Up @@ -361,6 +364,25 @@ function makeHelperText($str) {
return "<tr><td colspan='2' class='centered'>".$str."</td></tr>";
}

function makeCheckboxes($var, $fieldChoices, $label, $defaultChecked = []) {
$sharedForms = CareerDev::getSetting($var);
if (!$sharedForms) {
$sharedForms = $defaultChecked;
}
$html = "";
$html .= "<tr><td>\n";
foreach ($fieldChoices as $idx => $fieldLabel) {
if (in_array($idx, $sharedForms)) {
$selected = " checked";
} else {
$selected = "";
}
$html .= "<input type='checkbox' name='$var"."[]' id='$var"."___$idx' value='$idx'$selected><label for='$var"."___$idx'> $fieldLabel</label>\n";
}
$html .= "</td></tr>\n";
return $html;
}

function makeSetting($var, $type, $label, $default = "", $fieldChoices = array()) {
$value = CareerDev::getSetting($var);
$html = "";
Expand Down
12 changes: 8 additions & 4 deletions cronLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,20 @@ function checkMetadataForFields($token, $server) {
$vars = array();
$vars['coeus'] = FALSE;
$vars['vfrs'] = FALSE;
$vars['news'] = FALSE;
$vars['news'] = FALSE;
$vars['ldap'] = FALSE;

foreach ($metadata as $row) {
$field = $row['field_name'];
if (preg_match("/^coeus_/", $field)) {
$vars['coeus'] = TRUE;
}
if (preg_match("/^vfrs_/", $field)) {
$vars['vfrs'] = TRUE;
}
if (preg_match("/^vfrs_/", $field)) {
$vars['vfrs'] = TRUE;
}
if (preg_match("/^ldap_/", $field)) {
$vars['ldap'] = TRUE;
}
if ($field == "summary_news") {
$vars['news'] = TRUE;
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/2n_updateReporters.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function updateReporter($token, $server, $pid) {
$listOfNames[] = $fn." ".$ln;
}
}
}
if ($firstName && $lastName && !in_array($firstName." ".$lastName, $listOfNames)) {
}
if ($firstName && $lastName && !in_array($firstName." ".$lastName, $listOfNames)) {
$listOfNames[] = strtoupper($firstName." ".$lastName);
}

Expand Down
97 changes: 3 additions & 94 deletions hooks/saveHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
require_once(dirname(__FILE__)."/../classes/Citation.php");
require_once(dirname(__FILE__)."/../classes/Download.php");

global $token, $server;

if ($instrument == "identifiers") {
$sql = "SELECT field_name FROM redcap_data WHERE project_id = ".db_real_escape_string($project_id)." AND record = '".db_real_escape_string($record)."' AND field_name LIKE '%_complete'";
$q = db_query($sql);
Expand All @@ -25,98 +27,5 @@
}
}
}
} else if (in_array($instrument, array("followup", "initial_survey"))) {
$pubFields = array();
if ($instrument == "followup") {
$pubFields = array(
"followup_accepted_pubs" => "Final",
"followup_not_associated_pubs" => "Omit",
"followup_not_addressed_pubs" => "Not Done",
);
} else if ($instrument == "initial_survey") {
$pubFields = array(
"check_accepted_pubs" => "Final",
"check_not_associated_pubs" => "Omit",
"check_not_addressed_pubs" => "Not Done",
);
}

$redcapData = array();
if (!empty($pubFields)) {
$fields = array_merge(Application::$citationFields, $pubFields);
$json = \REDCap::getData($project_id, "json", array($record), $fields);
$redcapData = json_decode($json, TRUE);
}

$normativeRow = array();
if ($instrument == "followup") {
foreach ($redcapData as $row) {
if (($row['redcap_repeat_instrument'] == "followup") && ($row['redcap_repeat_instance'] == $repeat_instance)) {
$normativeRow = $row;
break;
}
}
} else if ($instrument == "initial_survey") {
foreach ($redcapData as $row) {
if ($row['redcap_repeat_instrument'] == "") {
$normativeRow = $row;
break;
}
}
}

$metadata = Download::metadata($token, $server);
$pubs = new Publications($token, $server, $metadata);
$pubs->setRows($redcapData);

$functions = array(
"Final" => "includePub",
"Omit" => "omit",
"Not Done" => "stageForReview",
);
foreach ($pubFields as $pubField => $citCollName) {
$citColls[$citCollName] = $pubs->getCitationCollection($citCollName);
}
foreach ($pubFields as $pubField => $citCollName1) {
if ($row[$pubField]) {
$currIds = json_decode($row[$pubField], TRUE);

# add and change; never delete
foreach ($currIds as $currPmid) {
$status = "New";
foreach ($citColls as $citCollName2 => $citColl) {
if ($citColl->has($currPmid)) {
if ($citCollName2 == $citCollName1) {
$status = "Keep";
} else {
$status = "Move";
}
break;
}
}

$func = $functions[$citCollName1];
switch($status) {
case "New":
$instance = Citation::findMaxInstance($token, $server, $record, $redcapData);
$citation = new Citation($token, $server, $record, $instance);
$citation->$func(); // writes to REDCap
$citColls[$citCollName1]->addCitation($citation);
break;
case "Move":
$citation = $citColls[$citCollName1]->getCitation($currPmid);
$citation->$func(); // writes to REDCap

# these calls affect future calculations, but do not write them to REDCap
$citColls[$citCollName2]->addCitation($citation);
$citColls[$citCollName1]->removePMID($currPmid);
break;
case "Keep":
break;
default:
break;
}
}
}
}
}
Application::refreshRecordSummary($token, $server, $project_id, $record);
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function makeWarning($str) {
<p class='centered'><a href='<?= CareerDev::link("help/why.php") ?>'>Why Use Flight Tracker?</a></p>
<p class='centered'><a href='<?= CareerDev::link("help/how.php") ?>'>How to Use Flight Tracker?</a></p>
<p class='centered'><a href='javascript:;' onclick='toggleHelp("<?= CareerDev::getHelpLink() ?>", "<?= CareerDev::getHelpHiderLink() ?>", "index.php");'>Enable Help on All Pages</a></p>
<p class='centered'><a href='https://github.com/scottjpearson/flight-tracker/releases'>Release Notes</a></p>
<p class='centered'><a href='https://github.com/vanderbilt-redcap/flight-tracker/releases'>Release Log</a> (<a href='https://github.com/scottjpearson/flight-tracker/releases'>Old Releases</a>)</p>
<h3><i class='fa fa-globe-americas'></i> Consortium</h3>
<p class='centered'><a href='<?= CareerDev::link("community.php") ?>'>About the Consortium</a></p>
<h4 class='nomargin'>Monthly Planning Meetings</h4>
Expand Down
2 changes: 2 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
'run_tonight' => FALSE,
'grant_class' => $_POST['grant_class'],
'grant_number' => $_POST['grant_number'],
'auto_recalculate' => '1',
'shared_forms' => [],
);
setupModuleSettings($projectId, $settingFields);

Expand Down
5 changes: 3 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@
{"field_name":"followup_name_middle","form_name":"followup","section_header":"","field_type":"text","field_label":"Middle Name","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"y","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"followup_name_last","form_name":"followup","section_header":"","field_type":"text","field_label":"Last Name","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"y","branching_logic":"","required_field":"y","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"followup_email","form_name":"followup","section_header":"","field_type":"text","field_label":"Email","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"email","text_validation_min":"","text_validation_max":"","identifier":"y","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"followup_name_preferred","form_name":"followup","section_header":"","field_type":"yesno","field_label":"Do you prefer to be called a name other than [check_name_first]?","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"[followup_name_first] <> ''","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"followup_name_preferred","form_name":"followup","section_header":"","field_type":"yesno","field_label":"Do you prefer to be called a name other than [followup_name_first]?","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"[followup_name_first] <> ''","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"followup_name_preferred_enter","form_name":"followup","section_header":"","field_type":"text","field_label":"Preferred Name","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"y","branching_logic":"[followup_name_preferred] = '1'","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"followup_name_maiden","form_name":"followup","section_header":"","field_type":"yesno","field_label":"Do you have a maiden name?","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"followup_name_maiden_enter","form_name":"followup","section_header":"","field_type":"text","field_label":"Maiden Name","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"y","branching_logic":"[followup_name_maiden] = '1'","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
Expand Down Expand Up @@ -1143,4 +1143,5 @@
{"field_name":"imported_disadvantaged","form_name":"manual_import","section_header":"","field_type":"dropdown","field_label":"Disadvantaged? Criteria:1) comes from low-income background and/or 2) comes from social/ cultural/ educational environment (i.e.: certain inner-city/rural that demonstrably and recently directly inhibited individuals from obtaining knowledge, skills and abilities necessary to develop and participate in research careers)","select_choices_or_calculations":"1, Yes|2, No|3, Prefer not to answer","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"imported_disabled","form_name":"manual_import","section_header":"","field_type":"dropdown","field_label":"Disability? (Those with physical or mental impairments that substantially limits one or more major life activities)","select_choices_or_calculations":"1, Yes|2, No|3, Prefer not to answer","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"imported_citizenship","form_name":"manual_import","section_header":"","field_type":"dropdown","field_label":"Citizenship:","select_choices_or_calculations":"1, U.S. citizen|2, Non U.S. citizen with permanent residency|3, Non U.S. citizen, will have permanent residency by July 1, 2014|4, Non U.S. citizen, temporary visa","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"imported_mentor","form_name":"manual_import","section_header":"","field_type":"text","field_label":"Primary Mentor","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""}]
{"field_name":"imported_mentor","form_name":"manual_import","section_header":"","field_type":"text","field_label":"Primary Mentor","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""},
{"field_name":"imported_institution","form_name":"manual_import","section_header":"Institution","field_type":"text","field_label":"All Other Institutions/Organizations [Institution Name(s); Comma-Separated]","select_choices_or_calculations":"","field_note":"","text_validation_type_or_show_slider_number":"","text_validation_min":"","text_validation_max":"","identifier":"","branching_logic":"","required_field":"","custom_alignment":"","question_number":"","matrix_group_name":"","matrix_ranking":"","field_annotation":""}]
Loading

0 comments on commit 4814b0b

Please sign in to comment.