Skip to content

Commit

Permalink
Merge branch 'release/2.6.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbchase committed Sep 3, 2024
2 parents 885981d + e455050 commit ae03b67
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# auto_populate_fields 2.6.2 (released 2024-09-03)
- Set a minimum PHP version of 7.4 (@saipavan10-git, #64, #65)
- Remove eval() from the module (@saipavan10-git, #64, #65)
- Bump framework version to 15 (@saipavan10-git, #63, #65)

# auto_populate_fields 2.6.1 (released 2024-08-26)
- Initialize eventsForms[$event] as an array if null (@saipavan10-git, #61, #62)
- Preserves survey field action tags (@michael-bentz, #52, #53)
Expand Down
43 changes: 24 additions & 19 deletions ExternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function redcap_every_page_top($project_id) {
// the REDCap action tag @DEFAULT in the case that any custom actions tags (@DEFAULT-*)
// have been applied to a field.
function redcap_survey_page_top($project_id) {
if ( !$this->getProjectSetting('use_in_survey') ) return;
$project_settings = $this->getProjectSettings();
if (!$project_settings['use_in_survey']) return;
global $elements;
// set the action_tag_class as it would be in the DataEntry context
foreach( $elements as &$element) {
Expand Down Expand Up @@ -105,22 +106,26 @@ function setDefaultValues() {
// record is already exists.
array_unshift($action_tags_to_look, '@DEFAULT-FROM-PREVIOUS-EVENT');

if ($this->getProjectSetting('chronological_previous_event')) {
$project_settings = $this->getProjectSettings();
if ($project_settings['chronological_previous_event']) {
// Getting chronological sequence of events.
$events = array();
$events = [];

$log_event_table = method_exists('\REDCap', 'getLogEventTable') ? \REDCap::getLogEventTable($Proj->project_id) : "redcap_log_event";

$sql = '
SELECT MIN(log_event_id), event_id FROM ' . $log_event_table . '
WHERE pk = "' . db_real_escape_string($_GET['id']) . '" AND
project_id = "' . db_real_escape_string($Proj->project_id) . '"
$sql = "
SELECT MIN(log_event_id), event_id
FROM " . $log_event_table . "
WHERE pk = ? AND project_id = ?
GROUP BY event_id
ORDER BY log_event_id';

if (($q = $this->query($sql)) && db_num_rows($q)) {
while ($result = db_fetch_assoc($q)) {
$events[] = $result['event_id'];
ORDER BY log_event_id
";

$params = [$_GET['id'], $Proj->project_id];

$result = $this->query($sql, $params);
if ($result) {
while ($row = $result->fetch_assoc()) {
$events[] = $row['event_id'];
}
}
}
Expand Down Expand Up @@ -243,7 +248,7 @@ function setDefaultValues() {
$date = \DateTime::createFromFormat($in_format, $default_value);
// This ternary prevents crashing for mixed source and target formats (e.g. YMD -> DMY)
// users will get validation errors
$default_value = ($date) ? $date->format($out_format) : $default_value;
$default_value = $date ? $date->format($out_format) : $default_value;
}
}

Expand Down Expand Up @@ -332,7 +337,7 @@ function currentFormHasData() {
* The sorted list of the fetched action tags.
*/
function getMultipleActionTagsQueue($action_tags, $subject) {
$results = array();
$results = [];

if (is_string($action_tags)) {
$action_tags = array($action_tags);
Expand All @@ -345,7 +350,7 @@ function getMultipleActionTagsQueue($action_tags, $subject) {
$priority = array_flip($action_tags);

// Buiding aux array to assist the sorting procedure.
$aux = array();
$aux = [];
foreach ($action_tags as $tag) {
// Checking first for action tag without number suffix.
if (strpos($subject, $tag . '=') !== false || strpos($subject, $tag . ' ') !== false) {
Expand All @@ -358,7 +363,7 @@ function getMultipleActionTagsQueue($action_tags, $subject) {
list(, $delta) = explode('_', $result);

if (!isset($aux[$delta])) {
$aux[$delta] = array();
$aux[$delta] = [];
}

$aux[$delta][$priority[$tag]] = $result;
Expand Down Expand Up @@ -399,7 +404,7 @@ function getMultipleActionTagsQueue($action_tags, $subject) {
function overrideActionTag($key, $value, $subject, $append_if_not_exists = true) {
if (strpos($subject, $key . '=') !== false) {
// Override action tag if exists.
$regex = '/(' . $key . '\s*=\s*)((\"[^\"]+\")|(\'[^\']+\'))/';
$regex = "/(' . $key . '\s*=\s*)((\"[^\"]+\")|(\'[^\']+\'))/";
$subject = preg_replace($regex, $key . '="' . $value . '"', $subject);
}
elseif ($append_if_not_exists) {
Expand Down Expand Up @@ -448,7 +453,7 @@ public static function getValueInActionTag($subject, $action_tag) {
return $value;
}

preg_match('/' . $action_tag .'\s*=\s*([^\s]+)/', $subject, $matches);
preg_match("/' . $action_tag .'\s*=\s*([^\s]+)/", $subject, $matches);
if (empty($matches[1])) {
return '';
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
This REDCap module provides rich control of default values for data entry fields via a set of action tags. These action tags allow fields to be populated based on values from an ordered list of fields and static values. The fields can be read from the current event or the previous event in longitudinal projects.

## Prerequisites
- REDCap >= 8.0.0 (for versions < 8.0.0, [REDCap Modules](https://github.com/vanderbilt/redcap-external-modules) is required).
- REDCap >= 14.0.2
- PHP >= 7.4

## Installation
- Clone this repo into to `<redcap-root>/modules/auto_populate_fields_v2.2`.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.1
2.6.2
15 changes: 8 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
"name": "Auto Populate Fields",
"namespace": "AutoPopulateFields\\ExternalModule",
"description": "This module provides rich control of default values for data entry fields via a set of action tags. These action tags allow fields to be populated based on values from an ordered list of fields and static values. The fields can be read from the current event or the previous event in longitudinal projects. <strong><a href=\"https://github.com/ctsit/auto_populate_fields\">See full documentation here</a></strong>.",
"framework-version": 15,
"compatibility": {
"redcap-version-min": "8.0.3"
"redcap-version-min": "14.0.2",
"php-version-min": "7.4.0"
},
"permissions": [
"redcap_every_page_top",
"redcap_survey_page_top",
"redcap_module_system_enable",
"redcap_module_system_change_version"
],
"authors": [
{
"name": "Philip Chase",
Expand All @@ -26,6 +22,11 @@
"name": "Kyle Chesney",
"email": "[email protected]",
"institution": "University of Florida - CTSI"
},
{
"name": "Sai Pavan Kamma",
"email": "[email protected]",
"institution": "University of Florida - CTSI"
}
],
"project-settings": [
Expand Down
7 changes: 4 additions & 3 deletions js/default_when_visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ autoPopulateFields.defaultWhenVisible.init = function() {
formSubmitDataEntry = function() {
$.each(autoPopulateFields.defaultWhenVisible.branchingEquations, function(fieldName, equation) {
// If equation result is false, erase field value.
try {
if ( !eval( equation ) ) {
evalLogicSubmit( fieldName, false, false );
try {
var equationResult = new Function('return (' + equation + ')')(); // Use Function constructor instead
if (!equationResult) {
evalLogicSubmit(fieldName, false, false);
}
}
catch ( e ) {
Expand Down

0 comments on commit ae03b67

Please sign in to comment.