Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add support for question reference syntax in redcap parser. closes #124

  • Loading branch information...
commit a95169e36afc047c41e78b7fe156f8c37948b6a5 1 parent 7de0a8d
Mark Yoon authored
View
14 features/redcap_parser.feature
@@ -17,3 +17,17 @@ Feature: Survey creation
| rule |
| A |
| A and B |
+ Scenario: question level dependencies
+ Given I parse redcap file "redcap_siblings.csv"
+ Then there should be 1 survey with:
+ ||
+ And there should be 2 questions with:
+ ||
+ And there should be 2 answers with:
+ ||
+ And there should be 1 resolved dependency_conditions with:
+ | rule_key |
+ | A |
+ And there should be 1 dependencies with:
+ | rule |
+ | A |
View
1  features/support/redcap_siblings.csv
@@ -0,0 +1 @@
+Variable / Field Name,Form Name,Field Units,Section Header,Field Type,Field Label,Choices OR Calculations,Field Note,Text Validation Type,Text Validation Min,Text Validation Max,Identifier?,Branching Logic (Show field only if...),Required Field? sibs,a3_subject_family_history,,,text,How many full siblings did the subject have?,,99 = Unknown,integer,0,20,,, sib1yob,a3_subject_family_history,,,text,Sibling 1 year of birth,,9999 = Unknown,integer,1875,2011,,[sibs] > 0,
View
10 lib/surveyor/redcap_parser.rb
@@ -81,6 +81,10 @@ def self.build_and_set(context, r)
:pick => pick_from_field_type(r[:field_type]),
:display_type => display_type_from_field_type(r[:field_type])
})
+ unless context[:question].reference_identifier.blank?
+ context[:lookup] ||= []
+ context[:lookup] << [context[:question].reference_identifier, nil, context[:question]]
+ end
print "question_#{context[:question].reference_identifier} "
end
def self.pick_from_field_type(ft)
@@ -152,7 +156,11 @@ class DependencyCondition < ActiveRecord::Base
def resolve_references
return unless lookup_reference
print "resolve(#{question_reference},#{answer_reference})"
- if row = lookup_reference.find{|r| r[0] == question_reference and r[1] == answer_reference}
+ if answer_reference.blank? and (row = lookup_reference.find{|r| r[0] == question_reference and r[1] == nil}) and row[2].answers.size == 1
+ print "...found "
+ self.question = row[2]
+ self.answer = self.question.answers.first
+ elsif row = lookup_reference.find{|r| r[0] == question_reference and r[1] == answer_reference}
print "...found "
self.answer = row[2]
self.question = self.answer.question
Please sign in to comment.
Something went wrong with that request. Please try again.