Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbchase committed Oct 14, 2024
2 parents ca97bb7 + 3ee7890 commit 92419e4
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 74 deletions.
14 changes: 6 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Change Log
All notable changes to the REDCap Hide Choice by Event module will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
# hide_choice_by_event 1.1.0 (released 2024-10-14)
- Add an example project (@pbchase)
- Bump framework to V15 (@saipavan10-git, #8)
- Fix php 8 error #7 (@saipavan10-git, #7, #8)

## [1.0.1] - 2018-08-17
### Changed
# hide_choice_by_event 1.0.1 (released 2018-08-17)
- Exclude action tags that follow @HIDE-CHOICE-BY-EVENT's parameter by handling nested brackets. (tbembersimeao)


## [1.0.0] - 2018-07-23
### Added
# hide_choice_by_event 1.0.0 (released 2018-07-23)
- Initial release of Hide Choice by Event (Dileep Rajput)
84 changes: 43 additions & 41 deletions ExternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,66 @@
/**
* ExternalModule class for Project Ownership module.
*/
class ExternalModule extends AbstractExternalModule {
class ExternalModule extends AbstractExternalModule
{

/**
* @inheritdoc
*/
function hook_every_page_top($project_id) {
function redcap_every_page_top($project_id)
{
if ($project_id) {
$this->includeJs('js/modify_help_menu.js');
}

//if not on a data entry page or survey, then don't do anything
if (!in_array(PAGE, array('DataEntry/index.php', 'surveys/index.php'))) {
if (!in_array(PAGE, ['DataEntry/index.php', 'surveys/index.php'])) {
return;
}

global $Proj;
$settings = array();
$settings = [];

//get the name of every field on this page.
$fields = array_keys($Proj->forms[$_GET['page']]['fields']);

foreach($fields as $field) {
$field_info = $Proj->metadata[$field];

//continue if the field does not have any action_tags at all.
if (!$action_tags = str_replace("\n", '', $field_info['misc'])) {
continue;
}
$fields = empty($_GET['page']) ? [] : $Proj->forms[$_GET['page']]['fields'];
if (is_array($fields)) {
foreach (array_keys($fields) as $field) {
$field_info = $Proj->metadata[$field];
$misc = $field_info['misc'];

//continue if the field does not have any action_tags at all.
if (!$action_tags = str_replace("\n", '', $misc)) {
continue;
}

//check if @HIDE-CHOICE-BY-EVENT is among action tags.
//did not use \Form::getValueInActionTag methods because of nested
//quotes inside JSON.
if (preg_match('/@HIDE-CHOICE-BY-EVENT\s*=\s*(\[)/', $action_tags, $matches, PREG_OFFSET_CAPTURE)) {
$count = 1;
$json_start = $matches[1][1];
$json_len = 0;
$len = strlen($action_tags);

for ($i = $json_start + 1; $i < $len; $i++) {
if ($action_tags[$i] == '[') {
$count++;
}
elseif ($action_tags[$i] == ']' && !--$count) {
$json_len = $i - $json_start + 1;
break;
//check if @HIDE-CHOICE-BY-EVENT is among action tags.
//did not use \Form::getValueInActionTag methods because of nested
//quotes inside JSON.
if (preg_match('/@HIDE-CHOICE-BY-EVENT\s*=\s*(\[)/', $action_tags, $matches, PREG_OFFSET_CAPTURE)) {
$count = 1;
$json_start = $matches[1][1];
$json_len = 0;
$len = strlen($action_tags);

for ($i = $json_start + 1; $i < $len; $i++) {
if ($action_tags[$i] == '[') {
$count++;
} elseif ($action_tags[$i] == ']' && !--$count) {
$json_len = $i - $json_start + 1;
break;
}
}
}

if (!$json_len) {
continue;
}
if (!$json_len) {
continue;
}

//add to settings variable if it is a valid json
if ($json_config = json_decode(substr($action_tags, $json_start, $json_len), true)) {
$settings[$field] = $json_config;
//add to settings variable if it is a valid json
if ($json_config = json_decode(substr($action_tags, $json_start, $json_len), true)) {
$settings[$field] = $json_config;
}
}
}

}

if (empty($settings)) {
Expand All @@ -92,7 +94,8 @@ function hook_every_page_top($project_id) {
* @param string $path
* The relative path to the js file.
*/
protected function includeJs($path) {
protected function includeJs($path)
{
echo '<script src="' . $this->getUrl($path) . '"></script>';
}

Expand All @@ -103,9 +106,8 @@ protected function includeJs($path) {
* @param array $settings
* an array of keys and values.
*/
protected function setJsSettings($settings) {
protected function setJsSettings($settings)
{
echo '<script>var hideChoiceByEvent = ' . json_encode($settings) . ';</script>';
}
}

?>
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
A REDCap module that implements an action tag to hide a categorical field choice on a specified list of events.

## Prerequisites
- REDCap >= 8.0.3
- REDCap >= 14.0.2
- PHP >= 7.4

## Easy Installation
- Obtain this module from the Consortium [REDCap Repo](https://redcap.vanderbilt.edu/consortium/modules/index.php) from the Control Center.
Expand Down Expand Up @@ -33,6 +34,8 @@ Note that the whitespace in the above example is unnecessary. This example would

To find a list of unique event names to use for the "event" field go to **Project Setup > Define My Events**. The right-most column will contain a list of unique event names.

See [HideChoiceByEventTest.REDCap.xml](examples/HideChoiceByEventTest.REDCap.xml) for an example of _Hide Choice by Event_ in a longitudinal, 2-arm project.

## Limitations

Currently this module only supports radio buttons. It will not hide the choices for any other type of field.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.1.0
32 changes: 8 additions & 24 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,16 @@
"name": "Hide Choice By Event",
"namespace": "HideChoiceByEvent\\ExternalModule",
"description": "Implements an action tag to hide a categorical field choice on a configured list of events",
"permissions": [
"hook_every_page_top"
],
"framework-version": 15,
"compatibility": {
"redcap-version-min": "14.0.2",
"php-version-min": "7.4.0"
},
"authors": [
{
"name": "Philip Chase",
"email": "[email protected]",
"institution": "University of Florida - CTSI"
},
{
"name": "Taryn Stoffs",
"email": "[email protected]",
"institution": "University of Florida - CTSI"
},
{
"name": "Dileep Rajput",
"email": "[email protected]",
"institution": "University of Florida - CTSI"
},
{
"name": "Tiago Bember",
"email": "[email protected]",
"name": "University of Florida CTS-IT",
"email": "[email protected]",
"institution": "University of Florida - CTSI"
}
],
"compatibility": {
"redcap-version-min": "8.0.3"
}
]
}
Loading

0 comments on commit 92419e4

Please sign in to comment.