diff --git a/src/org/ohmage/domain/Configuration.java b/src/org/ohmage/domain/Configuration.java index c75e3766..2bacd46b 100644 --- a/src/org/ohmage/domain/Configuration.java +++ b/src/org/ohmage/domain/Configuration.java @@ -26,12 +26,14 @@ /** - * Immutable bean-style wrapper for accessing and validating campaign properties. + * Immutable bean-style wrapper for accessing and validating campaign configuration properties. The methods in this class assume + * that the caller has validated that the parameters (i.e., prompt ids, survey ids, repeatable set ids) are valid for a + * particular configuration instance. * * @author Joshua Selsky */ public class Configuration { - // private static Logger _logger = Logger.getLogger(Configuration.class); + //private static Logger _logger = Logger.getLogger(Configuration.class); private String _urn; private String _name; private String _description; @@ -169,11 +171,10 @@ public Prompt getPrompt(String surveyId, String repeatableSetId, String promptId } public int getIndexForPrompt(String surveyId, String promptId) { - // Check to see if the prompt is in a repeatable set Survey survey = _surveyMap.get(surveyId); - String repeatableSetId = survey.getRepeatableSetIdForPromptId(promptId); - if(null != repeatableSetId) { + if(isPromptInRepeatableSet(surveyId, promptId)) { + String repeatableSetId = survey.getRepeatableSetIdForPromptId(promptId); return ((RepeatableSet) survey.getSurveyItemMap().get(repeatableSetId)).getPromptMap().get(promptId).getIndex(); } @@ -183,6 +184,26 @@ public int getIndexForPrompt(String surveyId, String promptId) { public boolean isPromptInRepeatableSet(String surveyId, String promptId) { return null != _surveyMap.get(surveyId).getRepeatableSetIdForPromptId(promptId); } + + public boolean promptContainsSingleChoiceValues(String promptId) { + if(null != promptId) { + String surveyId = getSurveyIdForPromptId(promptId); + if(isPromptInRepeatableSet(surveyId, promptId)) { + String repeatableSetId = _surveyMap.get(surveyId).getRepeatableSetIdForPromptId(promptId); + Prompt p = ((RepeatableSet) _surveyMap.get(surveyId).getSurveyItemMap().get(repeatableSetId)).getPromptMap().get(promptId); + if("single_choice".equals(p.getType())) { + return p.getProperties().containsKey("value"); + } + } else { + Prompt p = ((Prompt) _surveyMap.get(surveyId).getSurveyItemMap().get(promptId)); + if("single_choice".equals(p.getType())) { + return p.getProperties().containsKey("value"); + } + } + } + + return false; + } public int getNumberOfPromptsInSurvey(String surveyId) { return _surveyMap.get(surveyId).getSurveyItemMap().keySet().size(); diff --git a/src/org/ohmage/jee/servlet/writer/SurveyResponseReadCsvOutputBuilder.java b/src/org/ohmage/jee/servlet/writer/SurveyResponseReadCsvOutputBuilder.java index c04c8912..57c5845b 100644 --- a/src/org/ohmage/jee/servlet/writer/SurveyResponseReadCsvOutputBuilder.java +++ b/src/org/ohmage/jee/servlet/writer/SurveyResponseReadCsvOutputBuilder.java @@ -200,7 +200,7 @@ public String createMultiResultOutput(int numberOfSurveys, // Build the column headers // For the CSV output, user advocates have requested that the column names be made shorter and that single_choice // prompts have both their label and value present in the output - List copyOfCanonicalColumnList = new ArrayList (canonicalColumnList); + List copyOfCanonicalColumnList = new ArrayList (canonicalColumnList); int s = copyOfCanonicalColumnList.size(); int i = 0; @@ -214,7 +214,13 @@ public String createMultiResultOutput(int numberOfSurveys, String type = promptResponseMetadataMap.get(internalPromptId).getPromptType(); if("single_choice".equals(type)) { - shortHeader = internalPromptId + ":label," + internalPromptId + ":value"; + Configuration config = req.getConfiguration(); + if(config.promptContainsSingleChoiceValues(internalPromptId)) { + shortHeader = internalPromptId + ":label," + internalPromptId + ":value"; + } + else { + shortHeader = internalPromptId + ":label"; + } } else { shortHeader = key.replace("urn:ohmage:prompt:id:", ""); @@ -365,8 +371,11 @@ else if(canonicalColumnId.contains("prompt:id")) { SingleChoicePromptValueAndLabel valueLabel = (SingleChoicePromptValueAndLabel) promptResponseMap.get(promptId); - builder.append(valueLabel.getLabel()).append(",").append(valueLabel.getValue()); - + if(null != valueLabel.getValue()) { + builder.append(valueLabel.getLabel()).append(",").append(valueLabel.getValue()); + } else { + builder.append(valueLabel.getLabel()); + } } else {