From 12c82afd82f951ee4292df2c9e390dc1dd0a6878 Mon Sep 17 00:00:00 2001 From: Kyle Chesney Date: Fri, 25 Sep 2020 12:18:30 -0400 Subject: [PATCH 1/6] explicitly check that field to hide is present in a form prevents bug on multipage forms --- js/default_when_visible.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/default_when_visible.js b/js/default_when_visible.js index eebce37..b3f52c6 100644 --- a/js/default_when_visible.js +++ b/js/default_when_visible.js @@ -33,7 +33,10 @@ autoPopulateFields.defaultWhenVisible.init = function() { } } catch ( e ) { - evalLogicSubmit( fieldName, false, false ); + // field specified in equation was not present + if ( document.getElementsByName(fieldName).length !== 0 ) { // must check if fieldName is present on multipage forms + evalLogicSubmit( fieldName, false, false ); + } } }); From b0609def7ba70b6c7ad7858357b20bc533ab6f1b Mon Sep 17 00:00:00 2001 From: Kyle Chesney Date: Fri, 25 Sep 2020 15:39:41 -0400 Subject: [PATCH 2/6] allow APF to apply action tags in the survey context added property to action_tag_class to elements in survey --- ExternalModule.php | 12 ++++++++++++ config.json | 1 + 2 files changed, 13 insertions(+) diff --git a/ExternalModule.php b/ExternalModule.php index 1ebc806..c0611f4 100644 --- a/ExternalModule.php +++ b/ExternalModule.php @@ -17,6 +17,7 @@ * ExternalModule class for Auto Populate Fields. */ class ExternalModule extends AbstractExternalModule { + private $survey_APF_fields = []; /** * @inheritdoc @@ -41,6 +42,16 @@ function redcap_every_page_top($project_id) { } } + function redcap_survey_page_top($project_id) { + global $elements; + // set the action_tag_class as it would be in the DataEntry context + foreach( $elements as &$element) { + if ( in_array($element['name'], $this->survey_APF_fields) ) { + $element['action_tag_class'] = '@DEFAULT'; + } + } + } + /** * Extends @DEFAULT action tag. * @@ -229,6 +240,7 @@ function setDefaultValues() { // The first non empty default value wins! $misc = $this->overrideActionTag('@DEFAULT', $default_value, $misc); $aux_metadata[$field_name]['misc'] = $misc; + array_push($this->survey_APF_fields, $field_name); break; } diff --git a/config.json b/config.json index 032ef61..dafc30f 100644 --- a/config.json +++ b/config.json @@ -7,6 +7,7 @@ }, "permissions": [ "redcap_every_page_top", + "redcap_survey_page_top", "redcap_module_system_enable", "redcap_module_system_change_version" ], From 19ef4ba89126fad9d48771f9ce2af8cf92e9c786 Mon Sep 17 00:00:00 2001 From: Kyle Chesney Date: Fri, 25 Sep 2020 16:02:43 -0400 Subject: [PATCH 3/6] stop searching form elements once all actiontags are set --- ExternalModule.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ExternalModule.php b/ExternalModule.php index c0611f4..2234f55 100644 --- a/ExternalModule.php +++ b/ExternalModule.php @@ -46,8 +46,11 @@ function redcap_survey_page_top($project_id) { global $elements; // set the action_tag_class as it would be in the DataEntry context foreach( $elements as &$element) { - if ( in_array($element['name'], $this->survey_APF_fields) ) { + $i = array_search($element['name'], $this->survey_APF_fields); + if ( $i !== FALSE ) { $element['action_tag_class'] = '@DEFAULT'; + unset($this->survey_APF_fields[$i]); + if ( empty($this->survey_APF_fields) ) break; } } } From 59dafbde9d5a71ac7e59786b9dc581e79f7cfabd Mon Sep 17 00:00:00 2001 From: Kyle Chesney Date: Fri, 25 Sep 2020 16:20:07 -0400 Subject: [PATCH 4/6] add project-level toggle for survey use --- ExternalModule.php | 5 +++-- config.json | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ExternalModule.php b/ExternalModule.php index 2234f55..4d9f31f 100644 --- a/ExternalModule.php +++ b/ExternalModule.php @@ -31,7 +31,7 @@ function redcap_every_page_top($project_id) { if (PAGE == 'Design/online_designer.php') { $this->includeJs('js/helper.js'); } - elseif ( (PAGE == 'DataEntry/index.php' || PAGE == 'surveys/index.php') && !empty($_GET['id'])) { + elseif ( (PAGE == 'DataEntry/index.php' || PAGE == 'surveys/index.php') && !empty($_GET['id']) ) { if (!$this->currentFormHasData()) { $this->setDefaultValues(); } @@ -43,11 +43,12 @@ function redcap_every_page_top($project_id) { } function redcap_survey_page_top($project_id) { + if ( !$this->getProjectSetting('use_in_survey') ) return; global $elements; // set the action_tag_class as it would be in the DataEntry context foreach( $elements as &$element) { $i = array_search($element['name'], $this->survey_APF_fields); - if ( $i !== FALSE ) { + if ( $i !== false ) { $element['action_tag_class'] = '@DEFAULT'; unset($this->survey_APF_fields[$i]); if ( empty($this->survey_APF_fields) ) break; diff --git a/config.json b/config.json index dafc30f..a8943b2 100644 --- a/config.json +++ b/config.json @@ -29,6 +29,11 @@ } ], "project-settings": [ + { + "key": "use_in_survey", + "name": "Enable Auto Populate Fields on survey pages", + "type": "checkbox" + }, { "key": "chronological_previous_event", "name": "Enable chronological previous event detection (useful when the events are not necessarily arranged in a chronological order)", From fbd57552ad48933f3588716eaa06d990fd979c79 Mon Sep 17 00:00:00 2001 From: Kyle Chesney Date: Fri, 25 Sep 2020 16:28:00 -0400 Subject: [PATCH 5/6] upade test_project to enable surveys --- examples/test_project.xml | 122 +++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/examples/test_project.xml b/examples/test_project.xml index 499e7d5..7a62bee 100644 --- a/examples/test_project.xml +++ b/examples/test_project.xml @@ -1,21 +1,36 @@ - - + + - auto_populate_fields test - This file contains the metadata, events, and data for REDCap project "auto_populate_fields test". - auto_populate_fields test + APF - multisurvey + This file contains the metadata, events, and data for REDCap project "APF - multisurvey". + APF - multisurvey 1 0 - 0 + 1 - 2 - 7 + 0 + + + + + + + + - + @@ -66,6 +81,7 @@ + @@ -73,19 +89,24 @@ - + - + - + + + + + + @@ -106,7 +127,8 @@ - + + @@ -116,7 +138,8 @@ - + + @@ -127,7 +150,8 @@ - + + @@ -137,6 +161,15 @@ Study ID + + Survey Identifier + + + Survey Timestamp + + + Survey Timestamp + Date subject signed consent @@ -165,6 +198,9 @@ Complete? + + Survey Timestamp + dropdown from previous @@ -189,6 +225,9 @@ Complete? + + Survey Timestamp + birthdate_mdy @@ -211,6 +250,9 @@ Complete? + + Survey Timestamp + Show choice 2? @@ -238,15 +280,15 @@ 5-10 6-15 - + Checked Unchecked - + Checked Unchecked - + Checked Unchecked @@ -272,7 +314,7 @@ - + @@ -297,7 +339,7 @@ - + @@ -309,7 +351,7 @@ - + @@ -317,11 +359,11 @@ - + - + @@ -330,38 +372,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file From 16c80b1b47098683126bf23a191886b134b1a71a Mon Sep 17 00:00:00 2001 From: Philip Chase Date: Fri, 9 Oct 2020 14:57:42 -0400 Subject: [PATCH 6/6] Bump VERSION and update CHANGELOG.md for release 2.6.0 --- CHANGELOG.md | 10 ++++++++++ VERSION | 1 + 2 files changed, 11 insertions(+) create mode 100644 VERSION diff --git a/CHANGELOG.md b/CHANGELOG.md index 0debc87..4812a4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,16 @@ # Change Log All notable changes to the Auto-Populate Fields project will be documented in this file. + +## [2.6.0] - 2020-10-09 +### Changed +- Upgrade test_project to enable surveys (Kyle Chesney) +- Explicitly check that field to hide is present in a form prevents bug on multipage forms in surveys. (Kyle Chesney) + +### Added +- Add support for Surveys (Kyle Chesney) + + ## [2.5.2] - 2020-08-21 ### Changed - Added a element check to prevent attempting to hide nonexistent elements (James Pence) diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..e70b452 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2.6.0