bht_survey 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +158 -32
- data/bht_survey.gemspec +4 -4
- data/lib/bht_survey/version.rb +1 -1
- metadata +21 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 211e992fe10e1f31f8f25030139ba555f7486e2c
|
|
4
|
+
data.tar.gz: 59312878717278bb730abcf176b073be63e720e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed541a1279581111037243b8e429748863df836585fbb4c81c7e8dbd6880cd1ad3e3834215c5389f1947cdb8af3c6eec9a0381cee61faf18026ba44f5665f91b
|
|
7
|
+
data.tar.gz: 1755dcd36df458d0e4e83be4c2707dfec45aca328ac9d32750fdaaefbe96c3002b384b09a6b09b40a04b8a23b975fffa4c3faadbc246638cfa8fac7d5db8b980
|
data/README.md
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# BhtSurvey
|
|
2
|
-
|
|
3
|
-
This is a wrapper for Faraday access to the Qualtric Interface Service. It generates the workspace key separately from individual API calls.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Add this line to your application's Gemfile:
|
|
8
|
-
|
|
9
|
-
```ruby
|
|
10
|
-
gem 'bht_survey'
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
And then execute:
|
|
14
|
-
|
|
15
|
-
$ bundle
|
|
16
|
-
$ rake assets:precompile
|
|
17
|
-
|
|
18
1
|
## Development
|
|
19
2
|
|
|
20
3
|
Application Controller Code needed for workspace and status callback
|
|
@@ -26,9 +9,9 @@ Application Controller Code needed for workspace and status callback
|
|
|
26
9
|
ENV['API_URL'} ||= 'http://api-assessment.bhtcloud.org/'
|
|
27
10
|
ENV['QUALTRICS_ID'] = 'a qualtrics api token'
|
|
28
11
|
ENV['QUALTRICS_LIBRARY'] = 'a qualtrics library id'
|
|
29
|
-
ENV['STUDY_WORKSPACE_NAME'] = 'a
|
|
12
|
+
ENV['STUDY_WORKSPACE_NAME'] = 'a unique name for the study on a specific deploy'
|
|
30
13
|
|
|
31
|
-
##
|
|
14
|
+
## Interface
|
|
32
15
|
|
|
33
16
|
Controller
|
|
34
17
|
|
|
@@ -36,18 +19,161 @@ Application Controller Code needed for workspace and status callback
|
|
|
36
19
|
- returns 'not started', 'in progress', 'responded'
|
|
37
20
|
get_participant_link(participant_id, survey_name)['unique_link']
|
|
38
21
|
- returns link to qualtrics
|
|
22
|
+
get_results(participant_id, survey_name)['answers']
|
|
23
|
+
- returns a hash of question=>respose values
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
39
26
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
Participants have activities thru the activity_participants join record. Typical activities are:
|
|
28
|
+
interest
|
|
29
|
+
consent
|
|
30
|
+
phone (phone assessment)
|
|
31
|
+
time_1 (pre)
|
|
32
|
+
time_2 (post)
|
|
33
|
+
time_3 (post_6)
|
|
34
|
+
time_4 (post_12)
|
|
35
|
+
|
|
36
|
+
The survey name referenced in the interface is:
|
|
37
|
+
survey_name = ENV['STUDY_WORKSPACE_NAME'] + '-' + activity
|
|
38
|
+
|
|
39
|
+
#### app/helpers/shuti/study_helper.rb (see git blame for lines 40-70)
|
|
40
|
+
|
|
41
|
+
There is a horrific method called main_btn_state that governs the appearance
|
|
42
|
+
of the big yellow button on the landing page for the intervention.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Here is an extension of that code. Style Notes: the ruby multiple assignment syntax is used:
|
|
46
|
+
a,b= something. Obviously this code could be refactored
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
include QualtricsInterface
|
|
50
|
+
def assessment_status assessment_key
|
|
51
|
+
main_button=[]
|
|
52
|
+
@participant = Participant.find(@participant.id)
|
|
53
|
+
assessment_uuid = Activity.find_by(key: assessment_key).uuid
|
|
54
|
+
if @participant.assessment_available_or_in_progress?(assessment_key[-1])
|
|
55
|
+
survey_name = ENV['STUDY_WORKSPACE_NAME'] + '-' + assessment_key
|
|
56
|
+
main_button[0] = activities_path(survey_name: survey_name, activity_uuid: assessment_uuid)
|
|
57
|
+
state = get_participant_state(@participant.id, survey_name)
|
|
58
|
+
main_button[1] = "#{state == 'not started' ? 'Start' : 'Continue'} #{assessment_key.humanize} Survey"
|
|
59
|
+
if state == 'responded'
|
|
60
|
+
#STALE CACHE WORKAROUND
|
|
61
|
+
raise StaleAASMException unless @participant.activity(assessment_key).in_progress?
|
|
62
|
+
@participant.activity(assessment_key).complete!
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
[@participant.assessment_available_or_in_progress?(assessment_key[-1]), main_button]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def main_btn_state
|
|
69
|
+
unless @main_btn_state
|
|
70
|
+
@main_btn_state = []
|
|
71
|
+
if ['Experimental', 'Control'].include?(@participant.participant_type)
|
|
72
|
+
assessment_active, @main_btn_state = assessment_status 'time_4'
|
|
73
|
+
return @main_btn_state if assessment_active && @participant.study_phase == 'time_4'
|
|
74
|
+
assessment_active, @main_btn_state = assessment_status 'time_3'
|
|
75
|
+
return @main_btn_state if assessment_active && @participant.study_phase == 'time_3'
|
|
76
|
+
assessment_active, @main_btn_state = assessment_status 'time_2'
|
|
77
|
+
return @main_btn_state if assessment_active && @participant.study_phase == 'time_2'
|
|
78
|
+
assessment_active, @main_btn_state = assessment_status 'time_1'
|
|
79
|
+
return @main_btn_state if assessment_active && @participant.study_phase == 'time_1'
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#### app/controllers/activities/assessments_controller.rb
|
|
83
|
+
|
|
84
|
+
The assessment links are accessed by a redirect from the main button state. We redirect to the start route
|
|
85
|
+
in the Assesments controller to set the in progress state.
|
|
86
|
+
|
|
87
|
+
We redirect from Qualtrics to the complete route in order to update the assessment to complete.
|
|
88
|
+
|
|
89
|
+
class Activities::AssessmentsController < ApplicationController
|
|
90
|
+
include QualtricsInterface
|
|
91
|
+
|
|
92
|
+
prepend_before_action only: [:complete] { request.env["devise.skip_timeout"] = true }
|
|
93
|
+
|
|
94
|
+
def start
|
|
95
|
+
survey_name = params['survey_name']
|
|
96
|
+
activity_key = Activity.uuid_to_key(params['activity_uuid'])
|
|
97
|
+
participant = current_user.participant
|
|
98
|
+
activity = participant.activity(activity_key)
|
|
99
|
+
activity.start! unless activity.in_progress?
|
|
100
|
+
#STALE CACHE WORKAROUND
|
|
101
|
+
raise StaleAASMException unless activity.in_progress?
|
|
102
|
+
link = get_participant_link(participant.id, survey_name)['unique_link']
|
|
103
|
+
redirect_to link
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def complete
|
|
107
|
+
participant = current_user.participant
|
|
108
|
+
activity_key = Activity.uuid_to_key(params['assessment_uuid'])
|
|
109
|
+
participant.activity(activity_key).complete!
|
|
110
|
+
redirect_to root_path
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#### app/controllers/activities/consents_controller.rb
|
|
114
|
+
|
|
115
|
+
The consent links are accessed by a similar controller.
|
|
116
|
+
|
|
117
|
+
class Activities::ConsentsController < ActionController::Base
|
|
118
|
+
include QualtricsInterface
|
|
119
|
+
|
|
120
|
+
before_action :init_session
|
|
121
|
+
|
|
122
|
+
def init_session
|
|
123
|
+
session[:init] = true
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def start
|
|
127
|
+
uuid=params[:uuid]
|
|
128
|
+
survey_name = ENV['STUDY_WORKSPACE_NAME'] + '-' + 'consent'
|
|
129
|
+
participant = User.find_by(uuid: uuid).participant
|
|
130
|
+
link = get_participant_link(participant.id, survey_name)['unique_link']
|
|
131
|
+
activity = participant.activity('consent')
|
|
132
|
+
activity.start! unless activity.in_progress?
|
|
133
|
+
redirect_to link
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def complete
|
|
137
|
+
CompleteConsentWorker.new.perform
|
|
138
|
+
redirect_to consent_thanks_path
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def download
|
|
142
|
+
send_file(
|
|
143
|
+
"#{Rails.root}/consent_forms/pid_#{params[:id]}_consent_form.pdf",
|
|
144
|
+
filename: "pid_#{params[:id]}_consent_form.pdf",
|
|
145
|
+
type: 'application/pdf'
|
|
146
|
+
)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
The actual Consent completion process is handled by
|
|
151
|
+
###### app/workers/complete_consent_worker.rb
|
|
152
|
+
The actual Consent completion process invoked by the complete function. This worker synchronously
|
|
153
|
+
updates the status of the Participant, allowing the study to proceed.
|
|
154
|
+
|
|
155
|
+
###### app/workers/generate_consent_pdf_worker.rb
|
|
156
|
+
The Consent form PDF generation invoked with perform_async by the Consent completion worker.
|
|
157
|
+
It should be possible for this worker to fail and be retried by Sidekiq. When this succeeds
|
|
158
|
+
it also sends an email with the PDF.
|
|
159
|
+
|
|
160
|
+
### Qualtrics callbacks
|
|
161
|
+
|
|
162
|
+
The Qualtrics callback for a survey is build with the UUID of an activity. This
|
|
163
|
+
callback is found under Survey Options on Qualtrics. Near the bottom of the options
|
|
164
|
+
is an option to enter a Redirect URL.
|
|
165
|
+
|
|
166
|
+
Here's a example for localhost testing.
|
|
167
|
+
|
|
168
|
+
http://localhost:3000/activities/assessments/complete/045939cd-7ede-47c3-9ae9-3022521c11d
|
|
169
|
+
|
|
170
|
+
This is routed to a completion endpoint.
|
|
171
|
+
which converts that UUID into a activity, like time_1.
|
|
172
|
+
Then it updates the status of the current participant.
|
|
173
|
+
|
|
174
|
+
These UUIDs are in db/seeds/activities.seeds.rb.
|
|
175
|
+
|
|
176
|
+
Here is what the consent form callback URL looks like for localhost.
|
|
177
|
+
|
|
178
|
+
http://localhost:3000/activities/consents/complete
|
|
53
179
|
|
data/bht_survey.gemspec
CHANGED
|
@@ -6,8 +6,8 @@ require 'bht_survey/version'
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "bht_survey"
|
|
8
8
|
spec.version = BhtSurvey::VERSION
|
|
9
|
-
spec.authors = ["
|
|
10
|
-
spec.email = ["
|
|
9
|
+
spec.authors = ["gdh7y", "spj4g"]
|
|
10
|
+
spec.email = ["gdh7y@virginia.edu", "spj4g@virginia.edu"]
|
|
11
11
|
|
|
12
12
|
spec.summary = %q{Shim for Faraday access to the APIs of Qualtrics Interface Service}
|
|
13
13
|
spec.description = %q{#Requires a hash with three key values
|
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
#Requires an API_URL to access the Qualtrics Interface Service
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
spec.homepage = "https://github.com/
|
|
22
|
+
spec.homepage = "https://github.com/BHT/bht_survey.git"
|
|
23
23
|
spec.license = "MIT"
|
|
24
24
|
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
@@ -33,4 +33,4 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
34
34
|
spec.add_development_dependency "rspec", "~> 3.2"
|
|
35
35
|
spec.add_dependency "rails", "~> 5.0"
|
|
36
|
-
end
|
|
36
|
+
end
|
data/lib/bht_survey/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,69 +1,70 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bht_survey
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- gdh7y
|
|
8
|
+
- spj4g
|
|
8
9
|
autorequire:
|
|
9
10
|
bindir: exe
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
12
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: bundler
|
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
|
16
17
|
requirements:
|
|
17
|
-
- -
|
|
18
|
+
- - ~>
|
|
18
19
|
- !ruby/object:Gem::Version
|
|
19
20
|
version: '1.14'
|
|
20
21
|
type: :development
|
|
21
22
|
prerelease: false
|
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
24
|
requirements:
|
|
24
|
-
- -
|
|
25
|
+
- - ~>
|
|
25
26
|
- !ruby/object:Gem::Version
|
|
26
27
|
version: '1.14'
|
|
27
28
|
- !ruby/object:Gem::Dependency
|
|
28
29
|
name: rake
|
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
|
30
31
|
requirements:
|
|
31
|
-
- -
|
|
32
|
+
- - ~>
|
|
32
33
|
- !ruby/object:Gem::Version
|
|
33
34
|
version: '10.0'
|
|
34
35
|
type: :development
|
|
35
36
|
prerelease: false
|
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
38
|
requirements:
|
|
38
|
-
- -
|
|
39
|
+
- - ~>
|
|
39
40
|
- !ruby/object:Gem::Version
|
|
40
41
|
version: '10.0'
|
|
41
42
|
- !ruby/object:Gem::Dependency
|
|
42
43
|
name: rspec
|
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
|
44
45
|
requirements:
|
|
45
|
-
- -
|
|
46
|
+
- - ~>
|
|
46
47
|
- !ruby/object:Gem::Version
|
|
47
48
|
version: '3.2'
|
|
48
49
|
type: :development
|
|
49
50
|
prerelease: false
|
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
52
|
requirements:
|
|
52
|
-
- -
|
|
53
|
+
- - ~>
|
|
53
54
|
- !ruby/object:Gem::Version
|
|
54
55
|
version: '3.2'
|
|
55
56
|
- !ruby/object:Gem::Dependency
|
|
56
57
|
name: rails
|
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
|
58
59
|
requirements:
|
|
59
|
-
- -
|
|
60
|
+
- - ~>
|
|
60
61
|
- !ruby/object:Gem::Version
|
|
61
62
|
version: '5.0'
|
|
62
63
|
type: :runtime
|
|
63
64
|
prerelease: false
|
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
66
|
requirements:
|
|
66
|
-
- -
|
|
67
|
+
- - ~>
|
|
67
68
|
- !ruby/object:Gem::Version
|
|
68
69
|
version: '5.0'
|
|
69
70
|
description: "#Requires a hash with three key values\n #@workspace = {\n 'qualtrics_id'
|
|
@@ -71,14 +72,15 @@ description: "#Requires a hash with three key values\n #@workspace = {\n
|
|
|
71
72
|
\ 'study_workspace_name' => 'Shuti-Example'\n }\n #Requires an API_URL
|
|
72
73
|
to access the Qualtrics Interface Service\n "
|
|
73
74
|
email:
|
|
74
|
-
-
|
|
75
|
+
- gdh7y@virginia.edu
|
|
76
|
+
- spj4g@virginia.edu
|
|
75
77
|
executables: []
|
|
76
78
|
extensions: []
|
|
77
79
|
extra_rdoc_files: []
|
|
78
80
|
files:
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
81
|
+
- .gitignore
|
|
82
|
+
- .rspec
|
|
83
|
+
- .travis.yml
|
|
82
84
|
- Gemfile
|
|
83
85
|
- LICENSE.txt
|
|
84
86
|
- README.md
|
|
@@ -94,7 +96,7 @@ files:
|
|
|
94
96
|
- lib/bht_survey/engine.rb
|
|
95
97
|
- lib/bht_survey/qualtrics_interface.rb
|
|
96
98
|
- lib/bht_survey/version.rb
|
|
97
|
-
homepage: https://github.com/
|
|
99
|
+
homepage: https://github.com/BHT/bht_survey.git
|
|
98
100
|
licenses:
|
|
99
101
|
- MIT
|
|
100
102
|
metadata: {}
|
|
@@ -104,17 +106,17 @@ require_paths:
|
|
|
104
106
|
- lib
|
|
105
107
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
108
|
requirements:
|
|
107
|
-
- -
|
|
109
|
+
- - '>='
|
|
108
110
|
- !ruby/object:Gem::Version
|
|
109
111
|
version: '0'
|
|
110
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
113
|
requirements:
|
|
112
|
-
- -
|
|
114
|
+
- - '>='
|
|
113
115
|
- !ruby/object:Gem::Version
|
|
114
116
|
version: '0'
|
|
115
117
|
requirements: []
|
|
116
118
|
rubyforge_project:
|
|
117
|
-
rubygems_version: 2.
|
|
119
|
+
rubygems_version: 2.0.14.1
|
|
118
120
|
signing_key:
|
|
119
121
|
specification_version: 4
|
|
120
122
|
summary: Shim for Faraday access to the APIs of Qualtrics Interface Service
|