red_cap 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/red_cap/client.rb +16 -6
- data/lib/red_cap/form/fields.rb +26 -24
- data/lib/red_cap/form.rb +15 -8
- data/lib/red_cap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aff79d0a3d8f11d798bc3ea044f6e9ecaf6120f104b8b9d619a4c9b4f8f08db3
|
4
|
+
data.tar.gz: 7171c90ea289a8706c800d0df102065b84cb9cdc7754afdd0c5b4d327925d7a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53a38cf69401b1820e148d42d0c32ac748f4b034a4f98bba960c74e808f78f0d6e209a35e7c6df648cc8650ddab6a32f8a204c33de96c73c18b0f85455d89ffa
|
7
|
+
data.tar.gz: d05eee71134492e2925db33fc85705ed3c77cd167e5d2dbbf9105860f83fc7b3280a099e288f167ab257d32009a08e780625ee35532c817d95ed51ff716fc680
|
data/lib/red_cap/client.rb
CHANGED
@@ -10,12 +10,17 @@ module REDCap
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def records filter=nil
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
enumerator = fetch_study_ids(filter).in_groups_of(@per_page, false)
|
14
|
+
if block_given?
|
15
|
+
enumerator.each do |study_ids|
|
16
|
+
json_api_request(content: "record", records: study_ids.join(",")).each do |record|
|
17
|
+
yield record
|
18
|
+
end
|
19
|
+
end
|
20
|
+
else
|
21
|
+
enumerator.flat_map do |study_ids|
|
22
|
+
json_api_request(content: "record", records: study_ids.join(","))
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
@@ -38,6 +43,11 @@ module REDCap
|
|
38
43
|
|
39
44
|
private
|
40
45
|
|
46
|
+
def fetch_study_ids filter=nil
|
47
|
+
json_api_request(content: "record", fields: "study_id", filterLogic: filter)
|
48
|
+
.map { |hash| hash["study_id"] }
|
49
|
+
end
|
50
|
+
|
41
51
|
def json_api_request options
|
42
52
|
response = base_request(options.reverse_merge({
|
43
53
|
format: "json",
|
data/lib/red_cap/form/fields.rb
CHANGED
@@ -2,7 +2,7 @@ require "active_support/core_ext/object/blank"
|
|
2
2
|
|
3
3
|
module REDCap
|
4
4
|
class Form
|
5
|
-
class Field < Struct.new(:
|
5
|
+
class Field < Struct.new(:attributes, :options, :associated_fields)
|
6
6
|
KEYS = [
|
7
7
|
:field_name,
|
8
8
|
:form_name,
|
@@ -28,7 +28,7 @@ module REDCap
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def value
|
31
|
+
def value responses
|
32
32
|
responses[field_name]
|
33
33
|
end
|
34
34
|
|
@@ -44,7 +44,7 @@ module REDCap
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def associated_fields_for_key key
|
47
|
-
|
47
|
+
associated_fields.select do |field|
|
48
48
|
field.branching_logic == %{[#{field_name}(#{key})]="1"}
|
49
49
|
end
|
50
50
|
end
|
@@ -61,15 +61,15 @@ module REDCap
|
|
61
61
|
class Sql < Field; end
|
62
62
|
|
63
63
|
class File < Field
|
64
|
-
def value
|
65
|
-
if
|
64
|
+
def value responses
|
65
|
+
if super.present?
|
66
66
|
field_name
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
class Yesno < Field
|
72
|
-
def value
|
72
|
+
def value responses
|
73
73
|
if options.has_key?(:default) && super == ""
|
74
74
|
options[:default]
|
75
75
|
else
|
@@ -79,8 +79,8 @@ module REDCap
|
|
79
79
|
end
|
80
80
|
|
81
81
|
class RadioButtons < Field
|
82
|
-
def value
|
83
|
-
options[
|
82
|
+
def value responses
|
83
|
+
options[super]
|
84
84
|
end
|
85
85
|
|
86
86
|
def options
|
@@ -97,13 +97,13 @@ module REDCap
|
|
97
97
|
Radio = RadioButtons
|
98
98
|
|
99
99
|
class Checkboxes < RadioButtons
|
100
|
-
def value
|
101
|
-
selected_options.values
|
100
|
+
def value responses
|
101
|
+
selected_options(responses).values
|
102
102
|
end
|
103
103
|
|
104
104
|
private
|
105
105
|
|
106
|
-
def selected_options
|
106
|
+
def selected_options responses
|
107
107
|
options.select do |key, value|
|
108
108
|
responses["#{field_name}___#{key}"] == "1"
|
109
109
|
end
|
@@ -111,10 +111,10 @@ module REDCap
|
|
111
111
|
end
|
112
112
|
|
113
113
|
class CheckboxesWithOther < Checkboxes
|
114
|
-
def value
|
115
|
-
selected_options.map do |key, value|
|
114
|
+
def value responses
|
115
|
+
selected_options(responses).map do |key, value|
|
116
116
|
if other?(key)
|
117
|
-
"#{value}: #{other_text_field(key).value}"
|
117
|
+
"#{value}: #{other_text_field(key).value(responses)}"
|
118
118
|
else
|
119
119
|
value
|
120
120
|
end
|
@@ -134,16 +134,16 @@ module REDCap
|
|
134
134
|
Checkbox = CheckboxesWithOther
|
135
135
|
|
136
136
|
class CheckboxesWithRadioButtonsOrOther < CheckboxesWithOther
|
137
|
-
def value
|
138
|
-
radio_or_other_values = selected_options.keys.map do |key|
|
137
|
+
def value responses
|
138
|
+
radio_or_other_values = selected_options(responses).keys.map do |key|
|
139
139
|
if other?(key)
|
140
|
-
other_text_field(key)&.value
|
140
|
+
other_text_field(key)&.value(responses)
|
141
141
|
else
|
142
|
-
radio_field_for(key)&.value
|
142
|
+
radio_field_for(key)&.value(responses)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
Hash[selected_options.values.zip(radio_or_other_values)]
|
146
|
+
Hash[selected_options(responses).values.zip(radio_or_other_values)]
|
147
147
|
end
|
148
148
|
|
149
149
|
private
|
@@ -154,15 +154,17 @@ module REDCap
|
|
154
154
|
end
|
155
155
|
|
156
156
|
class CheckboxesWithCheckboxesOrOther < CheckboxesWithOther
|
157
|
-
def value
|
158
|
-
left = selected_options.values
|
157
|
+
def value responses
|
158
|
+
left = selected_options(responses).values
|
159
159
|
|
160
|
-
right = selected_options.keys.map do |key|
|
161
|
-
checkbox_fields_for(key).map
|
160
|
+
right = selected_options(responses).keys.map do |key|
|
161
|
+
checkbox_fields_for(key).map do |field|
|
162
|
+
field.value(responses)
|
163
|
+
end
|
162
164
|
end
|
163
165
|
|
164
166
|
if selected_options.keys.include?("501")
|
165
|
-
right[-1] = [other_text_field("501")&.value]
|
167
|
+
right[-1] = [other_text_field("501")&.value(responses)]
|
166
168
|
end
|
167
169
|
|
168
170
|
Hash[left.zip(right)]
|
data/lib/red_cap/form.rb
CHANGED
@@ -3,12 +3,11 @@ require "active_support/core_ext/string/inflections"
|
|
3
3
|
|
4
4
|
module REDCap
|
5
5
|
class Form
|
6
|
-
def initialize data_dictionary
|
6
|
+
def initialize data_dictionary
|
7
7
|
@data_dictionary = data_dictionary
|
8
|
-
@responses = responses
|
9
8
|
end
|
10
9
|
|
11
|
-
|
10
|
+
attr_accessor :data_dictionary, :responses
|
12
11
|
|
13
12
|
# field accessors
|
14
13
|
def method_missing method, *args, **kwargs, &block
|
@@ -19,7 +18,7 @@ module REDCap
|
|
19
18
|
field_class = lookup_field_class(field_class.to_s)
|
20
19
|
end
|
21
20
|
if field = find_field(key, field_class, options)
|
22
|
-
field.value
|
21
|
+
field.value(responses)
|
23
22
|
else
|
24
23
|
super
|
25
24
|
end
|
@@ -27,15 +26,23 @@ module REDCap
|
|
27
26
|
|
28
27
|
def find_field key, field_class, options
|
29
28
|
field = fields.find { |field| field.field_name == key }
|
30
|
-
field = field_class.new(
|
29
|
+
field = field_class.new(field.attributes) if field_class
|
31
30
|
field.options = options
|
32
31
|
field
|
33
32
|
end
|
34
33
|
|
35
34
|
def fields
|
36
|
-
@fields ||=
|
37
|
-
|
38
|
-
|
35
|
+
@fields ||= begin
|
36
|
+
fs = data_dictionary.map do |attributes|
|
37
|
+
klass = lookup_field_class(attributes["field_type"])
|
38
|
+
klass.new(attributes)
|
39
|
+
end
|
40
|
+
fs.each do |field|
|
41
|
+
field.associated_fields = fs.select do |f|
|
42
|
+
f.branching_logic =~ /^\[#{field.field_name}\(.+\)\]="1"$/
|
43
|
+
end
|
44
|
+
end
|
45
|
+
fs
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
data/lib/red_cap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red_cap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|