xHeliotrope / redcap-wdc

REDCap Web Data Connector for Tableau
6 stars 7 forks source link

Not pulling Survey Timestamp when exportSurveyFields set to true #2

Open jjscarlett opened 7 years ago

jjscarlett commented 7 years ago

For some reason, I cannot get the auto-generated Survey Timestamp to appear after using the WDC via Tableau Desktop.

The Record ID and all of my survey fields come across fine, but no auto generated timestamp. We're on version 6.13.3 but setting exportSurveyFields to true (which is already set in the code) simply doesn't seem to be having any effect.

FYI, Modifying the html by adding rawOrLabel = 'label', did seem to work just fine.

API documentation

exportSurveyFields true, false [default] - specifies whether or not to export the survey identifier field (e.g., "redcap_survey_identifier") or survey timestamp fields (e.g., instrument+"_timestamp") when surveys are utilized in the project. If you do not pass in this flag, it will default to "false". If set to "true", it will return the redcap_survey_identifier field and also the survey timestamp field for a particular survey when at least one field from that survey is being exported. NOTE: If the survey identifier field or survey timestamp fields are imported via API data import, they will simply be ignored since they are not real fields in the project but rather are pseudo-fields.

lynatruong commented 7 years ago

If you read into the API documentation for exportSurveyFields it notes that if the survey timestamp fields are imported via API data import, they will simply be ignored since they are "pseudo-fields." I've also wrangled with this quite a bit, and the only workaround is to create a date-time field in your survey and use the action tags to hide the field from the user and set the default time.

jjscarlett commented 7 years ago

I read that too, but to me it seems to indicate that if you try to write data into REDCap (import) it will ignore it since these are their own fields and you can't overwrite them.

When I use Alteryx I get the timestamp field no problem. When I use the REDCap API Playground I can format the output and get the timestamps as well.

My suspicion is that the Tableau dataType might not be accepting it ... but this is a wild guess.

I too have added my own "complete timestamp" field with @HIDDEN-SURVEY @TODAY @NOW in the field annotation to hide and populate the data.

DanKlaver15 commented 6 years ago

I also had the same issue, but the workaround I ended up using was to actually pull the records to define the schema as well instead of the field names. REDCap does include the timestamps in the records. However, when pulling the records to define the schema, I change my type to "eav", that gives me the column information I need but when I populate the schema with data, I stick to "type: 'flat'".

myConnector.getSchema = function(schemaCallback) {
          var recordsInfo = [];
          $.ajax({
              url: JSON.parse(tableau.connectionData)['url'],
              method: "POST",
              data: {
                  token: JSON.parse(tableau.connectionData)['token'],
                  content: 'record',
                  format: 'json',
                  returnFormat: 'json',
                  type: 'eav',
                  rawOrLabel: 'label',
                  rawOrLabelHeaders: 'label',
                  exportCheckboxLabel: 'true',
                  exportSurveyFields: 'true',
                  exportDataAccessGroups: 'false'
              },
...

myConnector.getData = function(table, doneCallback) {

        var tableData = [];
          $.ajax({
            url: JSON.parse(tableau.connectionData)['url'],
            type: "POST",
            data: {
              token: JSON.parse(tableau.connectionData)['token'],
              content: 'record',
              format: 'json',
              returnFormat: 'json',
              type: 'flat',
              rawOrLabel: 'label',
              rawOrLabelHeaders: 'label',
              exportCheckboxLabel: 'true',
              exportSurveyFields: 'true',
              exportDataAccessGroups: 'false'
            },

The only big issue I've had with this, is that Tableau cannot pivot json. Anyone have ideas about this? I've contemplated using the JS to pivot, but the least complicated solution i've come up with is getting it in XML format to then pivot in Tableau. Unfortunately, changing the type over to XML has proven just as difficult and it ends up crashing Tableau. Any ideas?

@jjscarlett @wtquirks @xHeliotrope

jeffkritzman commented 6 years ago

Hi @dklaver15 - I'm not very advanced with JSON / XML / etc, but I did find a workaround to pivot from this WDC. I left joined to a specially made excel sheet to pseudo-pivot. Namely, I used month (a field in my WDC data) to densify by the 8 variables I wanted to pivot to. Then I used calculations to get my metric, i.e.

CASE [pivot] WHEN "dr in yes" THEN [dr in yes] WHEN "dr in no" THEN [dr in no] ... END

image