Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This REDCap Module provides tools to autopopulate fields.
- For each project you want to use this module, go to the project home page, click on **Manage External Modules** link, and then enable Auto Populate Fields for that project.

## Features included
This module provides 3 new [action tags](https://wiki.chpc.utah.edu/pages/viewpage.action?pageId=595001400):
This module provides 4 new [action tags](https://wiki.chpc.utah.edu/pages/viewpage.action?pageId=595001400):

#### @DEFAULT-FROM-FIELD
It allows users to set up a field's default value from an existing field on the same form. Use case examples:
Expand All @@ -22,3 +22,6 @@ If the field is visible it sets the initial value otherwise it removes the value

#### @DEFAULT-FROM-PREVIOUS-EVENT
Sets a field's default value based on its own value in a previous event. To map the default value from another field, you may specify the source as a parameter to the action tag, e.g `@DEFAULT-FROM-PREVIOUS-EVENT="source_field"`.

#### @AE_ID
Generates custom ids for repeating Adverse Events. The custom id consists of record id, event id and repeating instance id.
36 changes: 36 additions & 0 deletions includes/default_ae_id.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Generates a custom instance id for Adverse Events instrument.
*/

require_once 'helper.php';

/**
* Handle @AE_ID tag.
*/
function auto_populate_fields_default_ae_id() {
global $Proj;

// Get required parameters from query.
parse_str($_SERVER['QUERY_STRING'], $qs_params);
$record_id = $qs_params['id'];
$event_id = $qs_params['event_id'];
$instance_id = $qs_params['instance'];
if(empty($instance_id)) {
$instance_id = 1;
}

// Create custom AE_ID.
$ae_id = $record_id."-".$event_id."-".$instance_id;
$tag_name = '@AE_ID';
$fields_arr = array();
foreach (auto_populate_fields_get_fields_names() as $field_name) {
$target_field_info = $Proj->metadata[$field_name];

if(strpos($target_field_info['misc'], $tag_name) !== false) {
$fields_arr[] = $target_field_info['field_name'];
}
}
return array('id' => $ae_id, 'fields' => $fields_arr);
}
?>
1 change: 1 addition & 0 deletions includes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function auto_populate_fields_get_available_features() {

if (PAGE == 'DataEntry/index.php') {
$features[] = 'default_from_previous_event';
$features[] = 'default_ae_id';
}

return $features;
Expand Down
8 changes: 8 additions & 0 deletions js/default_ae_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$(document).ready(function(){
var ae_id = autoPopulateFields.default_ae_id.id;
var fields = autoPopulateFields.default_ae_id.fields;

for(var i=0;i<fields.length;i++) {
$('[name="'+fields[i]+'"]').val(ae_id);
}
});
15 changes: 13 additions & 2 deletions js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ $(document).ready(function() {
return $(this).text() === '@DEFAULT';
}

// Function that checks if text matches the "@APPUSERNAME-APP" string.
var isDefaultAELabelColumn = function() {
return $(this).text() === '@APPUSERNAME-APP';
}

// Getting @DEFAULT row from action tags help table.
var $default_action_tag = $popup.find('td').filter(isDefaultLabelColumn).parent();
if ($default_action_tag.length !== 1) {
Expand All @@ -26,7 +31,8 @@ $(document).ready(function() {
var texts = {
'@DEFAULT-FROM-PREVIOUS-EVENT': 'Sets a field\'s default value based on its own value in a previous event. To map the default value from another field, you may specify the source as a parameter to the action tag, e.g @DEFAULT-FROM-PREVIOUS-EVENT="source_field".',
'@DEFAULT-WHEN-VISIBLE': 'If the field is visible it sets the initial value otherwise it removes the value. This is mainly useful in fields which are visible and hidden by branching logic, e.g. @DEFAULT-FROM-FIELD=\'10\'.',
'@DEFAULT-FROM-FIELD': 'Sets a field\'s default value from an existing field on the same form. This is useful when using hidden fields as source for visible fields, e.g. @DEFAULT-FROM-FIELD=\'hidden_first_name\'.'
'@DEFAULT-FROM-FIELD': 'Sets a field\'s default value from an existing field on the same form. This is useful when using hidden fields as source for visible fields, e.g. @DEFAULT-FROM-FIELD=\'hidden_first_name\'.',
'@AE_ID': 'Generates custom ids for repeating Adverse Events. The custom id consists of record id, event id and repeating instance id.',
};

$.each(texts, function(tag_name, descr) {
Expand All @@ -45,7 +51,12 @@ $(document).ready(function() {
$cols.last().text(descr);

// Placing new action tag.
$new_action_tag.insertAfter($default_action_tag);
if(tag_name == '@AE_ID') {
$default_ae_action_tag = $popup.find('td').filter(isDefaultAELabelColumn).parent();
$new_action_tag.insertBefore($default_ae_action_tag);
} else{
$new_action_tag.insertAfter($default_action_tag);
}
});
});
});