From 839aa83f3452dacb8cba24c47b8a30cd367e5cda Mon Sep 17 00:00:00 2001 From: Andy Arenson Date: Mon, 24 Sep 2018 14:43:50 -0400 Subject: [PATCH] Add exportfFieldFormat, allowing users to specify whether Tableau variables should be named after REDCap variable names or REDCap field labels --- TableauConnector.php | 25 +++++++++++++++++++++++-- config.json | 8 ++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/TableauConnector.php b/TableauConnector.php index ca80455..c5bb30b 100644 --- a/TableauConnector.php +++ b/TableauConnector.php @@ -67,6 +67,7 @@ public function printConnectorPageContent() { $pageTitle = $this->getSystemSettingOrDefault('connector-page-title'); $instructionText = $this->getSystemSettingOrDefault('connector-page-instruction-text'); $formatLabelText = $this->getSystemSettingOrDefault('connector-page-format-label'); + $fieldFormatLabelText = $this->getSystemSettingOrDefault('connector-page-fieldformat-label'); $dagLabelText = $this->getSystemSettingOrDefault('connector-page-dag-label'); $tokenLabelText = $this->getSystemSettingOrDefault('connector-page-token-label'); $fieldListLabelText = $this->getSystemSettingOrDefault('connector-page-fieldlist-label'); @@ -99,6 +100,13 @@ public function printConnectorPageContent() { +
+ + + + + +
@@ -190,6 +198,7 @@ public function printConnectorPageContent() { type: 'flat', fields: fieldList, rawOrLabel: connectionData.raworlabel, + varOrLabel: connectionData.varorlabel, rawOrLabelHeaders: 'raw', exportCheckboxLabel: false, exportSurveyFields: connectionData.surveyfields, @@ -248,7 +257,12 @@ function buildDataSource(connectionData, response){ var f = {}; f.id = rcExportVarname; - f.alias = rcExportVarname; + + if (connectionData.varorlabel==='var') { + f.alias = rcExportVarname; + } else { + f.alias = varNode.find( 'TranslatedText' ).text(); + } f.description = varNode.find( 'TranslatedText' ).text(); var dataType = 'string'; @@ -258,7 +272,10 @@ function buildDataSource(connectionData, response){ } if (rcFType==='checkbox') { - f.description = getCheckboxChoiceLabel($response, rcExportVarname)+' | '+f.description; + if (connectionData.varorlabel==='label') { + f.alias = f.description+' (choice='+getCheckboxChoiceLabel($response, rcExportVarname)+')'; + } + f.description = getCheckboxChoiceLabel($response, rcExportVarname)+' | '+f.description; } f.dataType = odmTypeToTableauType(dataType); @@ -343,6 +360,9 @@ function getCheckboxChoiceLabel($response, rcExportVarname) { $("#submitButton").click(function() { var exportFormat = $("input[name=\"raworlabel\"]:checked").val(); exportFormat = (exportFormat==='label') ? exportFormat : 'raw'; + + var exportFieldFormat = $("input[name=\"varorlabel\"]:checked").val(); + exportFieldFormat = (exportFieldFormat==='label') ? exportFieldFormat : 'var'; var includeDag = ("1" == $("input[name=\"incldag\"]:checked").val()); @@ -356,6 +376,7 @@ function getCheckboxChoiceLabel($response, rcExportVarname) { */ var connectionData = { raworlabel: exportFormat, + varorlabel: exportFieldFormat, surveyfields: false, // can't yet tell from odm xml whiat instruments are surveys dags: includeDag, token: $("input#token").val(), diff --git a/config.json b/config.json index 24304b6..67840e6 100644 --- a/config.json +++ b/config.json @@ -85,6 +85,14 @@ "type": "text", "default": "Raw data or labels?" }, + { + "key": "connector-page-fieldformat-label", + "name": "Connector page export field format field label", + "required": true, + "allow-project-overrides": false, + "type": "text", + "default": "Variable name or field label?" + }, { "key": "connector-page-dag-label", "name": "Connector page include DAG field label",