roqua-rom-api 0.1.5 → 0.1.6
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/ChangeLog.md +7 -0
- data/Guardfile +1 -1
- data/README.md +34 -7
- data/config/locales/nl.yml +2 -4
- data/lib/roqua/rom_api/endpoint.rb +3 -1
- data/lib/roqua/rom_api/sessions/basic_auth_session.rb +1 -1
- data/lib/roqua/rom_api/start_fill_out_session.rb +7 -3
- data/lib/roqua/rom_api/version.rb +1 -1
- data/spec/lib/roqua/rom_api/create_fill_out_request_spec.rb +12 -11
- data/spec/lib/roqua/rom_api/endpoint_spec.rb +27 -7
- data/spec/lib/roqua/rom_api/list_protocol_subscriptions_spec.rb +1 -1
- data/spec/lib/roqua/rom_api/list_responses_spec.rb +1 -1
- data/spec/lib/roqua/rom_api/start_fill_out_session_spec.rb +23 -8
- data/spec/lib/roqua/rom_api/start_protocol_subscription_spec.rb +3 -3
- data/spec/lib/roqua/rom_api/stop_protocol_subscription_spec.rb +2 -3
- data/spec/spec_helper.rb +4 -0
- data/spec/support/httparty_helpers.rb +5 -0
- data/spec/support/test.yml +8 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3f8ea4f36ee2e5dc8e00beed8c9a5becfb4f378
|
4
|
+
data.tar.gz: 8efa2129625a8f6efca60d7d6ab8731a49b432ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f340bf0b6bba37bcc393461fa3d8e90b5c373dad5f071e5947a5ed0ee77dd7aff97a4283e80aa2889f5b27341e5cf7a99fa943b69b8d1e41001c2ecca57af981
|
7
|
+
data.tar.gz: 36459698211d7cfc780f3f2d1dada4e7c2314180f19ccd70c8d252900986adfc20a52864cef1a88a02a5a746df91b039fbaabc2e4e1caf13034d11f0bef27d04
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### 0.1.6 / 2014-07-02
|
2
|
+
|
3
|
+
* Implement start\_fill\_out session for aborted answers
|
4
|
+
* Add id to the responses api
|
5
|
+
* Add 'aborted' status to the responses api
|
6
|
+
* Allow multiple questionnaires in start\_fill\_out_session api
|
7
|
+
|
1
8
|
### 0.1.5 / 2014-06-10
|
2
9
|
|
3
10
|
* Added CreateFillOutRequest
|
data/Guardfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
guard :rspec, cmd: 'bundle exec rspec --format Fuubar --colour' do
|
4
|
+
guard :rspec, cmd: 'bundle exec rspec --format Fuubar --colour', failed_mode: :none do
|
5
5
|
watch(%r{^spec/.+_spec\.rb$})
|
6
6
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
7
|
watch('spec/spec_helper.rb') { "spec" }
|
data/README.md
CHANGED
@@ -12,21 +12,47 @@ An HTTP basic auth username password combination can be generated in the RoQua a
|
|
12
12
|
|
13
13
|
By default the ROM API Gem supports the `:nl` language only. If you use another locale or want to change some of the messages, simply extend your locale file by providing a value for some or all of the keys defined `config/locales/*.yml` in the root of this Gem.
|
14
14
|
|
15
|
-
## FillOut Sessions
|
16
15
|
|
17
|
-
|
16
|
+
## Fill Out Requests
|
17
|
+
|
18
|
+
See [api](http://roqua.github.io/developer/rom_v1/dossier/fill_out_requests/) for more info what this does and format of callbacks.
|
19
|
+
|
20
|
+
To create a fill out request run:
|
21
|
+
|
22
|
+
Roqua::RomApi::CreateFillOutRequest.run! dossier_id: dossier_id,
|
23
|
+
questionnaire_keys: ['key1', 'key2'],
|
24
|
+
callback_url: notify_callback_path(token: 'secret')
|
25
|
+
|
26
|
+
#### Parameters
|
27
|
+
|
28
|
+
* `dossier_id` [Required] - Unique dossier identifier string for the patient about to fill out questionnaires
|
29
|
+
* `questionnaire_keys [Required] - Array of keys of questionnaires to fill out
|
30
|
+
* open_from - Time the patient can start filling out the questionnaires and time.
|
31
|
+
* open_till - Time the patient can no longer fill in the questionnaire.
|
32
|
+
* callback_url [Required] - Url for event callbacks
|
33
|
+
* reminders - Array of durations after which a reminder should be sent if fill_out_request has not been finished.
|
34
|
+
* respondent_type - Defaults to 'patient_version', each type is a separate list of questionnaires to fill out.
|
35
|
+
|
36
|
+
|
37
|
+
## Fill Out Sessions
|
38
|
+
|
39
|
+
To start filling out a set of questionnaires run:
|
18
40
|
|
19
41
|
outcome = Roqua::RomApi::StartFillOutSession.run dossier_id: dossier_id,
|
20
|
-
|
42
|
+
questionnaire_keys: questionnaire_keys,
|
21
43
|
return_to: '/some/return/url/or/path'
|
22
44
|
|
23
45
|
#### Parameters
|
24
46
|
|
25
|
-
* `dossier_id:`
|
26
|
-
* `
|
27
|
-
* `
|
47
|
+
* `dossier_id:` [Required] - Unique dossier identifier for the patient about to fill out a questionnaire.
|
48
|
+
* `questionnaire_keys:` - Array of keys uniquely identifying the questionnaires to be filled out.
|
49
|
+
* `response_ids:` - Array of ids uniquely identifying aborted responses for which filling out has to be resumed.
|
50
|
+
* `return_to:` [Required] - Address to return to after filling out the questionnaire.
|
28
51
|
|
29
|
-
|
52
|
+
When questionnaire keys are provided, a set of blank questionnaires will be filled out. When response ids are provided,
|
53
|
+
filling out questionnaires for these responses is resumed.
|
54
|
+
|
55
|
+
Redirect to the fill_out url received when the outcome is valid:
|
30
56
|
|
31
57
|
if outcome.valid?
|
32
58
|
redirect_to outcome.result
|
@@ -37,6 +63,7 @@ or do something with the validation errors:
|
|
37
63
|
log_or_display outcome.errors.full_messages
|
38
64
|
end
|
39
65
|
|
66
|
+
|
40
67
|
## Protocol Subscriptions
|
41
68
|
|
42
69
|
### Index
|
data/config/locales/nl.yml
CHANGED
@@ -4,15 +4,13 @@ nl:
|
|
4
4
|
models:
|
5
5
|
roqua/rom_api/start_fill_out_session:
|
6
6
|
attributes:
|
7
|
-
questionnaire_key:
|
8
|
-
questionnaire_not_found_by_key: met sleutel '%{value}' niet gevonden
|
9
7
|
roqua/rom_api/start_protocol_subscription:
|
10
8
|
attributes:
|
11
9
|
protocol_key:
|
12
10
|
protocol_not_found_by_key: met sleutel '%{value}' niet gevonden
|
13
11
|
attributes:
|
14
12
|
roqua/rom_api/start_fill_out_session:
|
15
|
-
|
13
|
+
questionnaire_keys: Vragenlijsten
|
16
14
|
return_to: Return url
|
17
15
|
roqua/rom_api/start_protocol_subscription:
|
18
|
-
protocol_key: Protocol
|
16
|
+
protocol_key: Protocol
|
@@ -6,12 +6,14 @@ module Roqua
|
|
6
6
|
|
7
7
|
def validate_response_for
|
8
8
|
response = yield
|
9
|
-
if response.is_a?(Hash) && response['errors']
|
9
|
+
if response.parsed_response.is_a?(Hash) && response['errors'].present?
|
10
10
|
response['errors'].each do |attribute, attribute_errors|
|
11
11
|
attribute_errors.each do |error|
|
12
12
|
errors.add attribute.to_sym, error.to_sym
|
13
13
|
end
|
14
14
|
end
|
15
|
+
elsif response.code == 422
|
16
|
+
errors.add :base, 'Validations failed!'
|
15
17
|
else
|
16
18
|
response_to_result response
|
17
19
|
end
|
@@ -3,21 +3,25 @@ module Roqua
|
|
3
3
|
# @api private
|
4
4
|
class StartFillOutSession < Endpoint
|
5
5
|
string :dossier_id
|
6
|
-
string
|
6
|
+
array :questionnaire_keys, default: [] do string end
|
7
|
+
array :response_ids, default: [] do integer end
|
7
8
|
string :return_to
|
8
9
|
string :stylesheet, default: nil
|
9
10
|
|
11
|
+
validates :questionnaire_keys, presence: {unless: -> { response_ids.present? }}
|
12
|
+
|
10
13
|
def execute
|
11
14
|
validate_response_for do
|
12
15
|
RomApi.basic_auth_session.post("/dossiers/#{dossier_id}/fill_out_sessions",
|
13
|
-
|
16
|
+
questionnaire_keys: questionnaire_keys,
|
17
|
+
response_ids: response_ids,
|
14
18
|
return_to: return_to,
|
15
19
|
stylesheet: stylesheet)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def response_to_result(response)
|
20
|
-
response['
|
24
|
+
response['fill_out_url']
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CreateFillOutRequest do
|
4
|
-
let(:options)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
let(:session)
|
12
|
-
let(:response) {
|
4
|
+
let(:options) { {dossier_id: 'some_dossier_id',
|
5
|
+
questionnaire_keys: ['qkey1', 'qkey2'],
|
6
|
+
respondent_type: 'patient_version',
|
7
|
+
callback_url: 'http://callback.url',
|
8
|
+
reminders: [1000, 2000],
|
9
|
+
open_from: Time.now,
|
10
|
+
open_till: Time.now + 100_000} }
|
11
|
+
let(:session) { Sessions::BasicAuthSession.new }
|
12
|
+
let(:response) { httparty_response({}) }
|
13
13
|
before do
|
14
14
|
allow(Sessions::BasicAuthSession).to receive(:new).and_return session
|
15
15
|
allow(session).to receive(:post).and_return response
|
@@ -27,12 +27,13 @@ describe CreateFillOutRequest do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns the id of the created fill_out_request' do
|
30
|
-
|
30
|
+
response['id'] = 'fill_out_request_id'
|
31
31
|
outcome = CreateFillOutRequest.run(options)
|
32
32
|
expect(outcome.result).to eq('fill_out_request_id')
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'accepts explicit nil values' do
|
36
|
+
response['id'] = 'fill_out_request_id'
|
36
37
|
options[:open_from] = nil
|
37
38
|
options[:open_till] = nil
|
38
39
|
options[:reminders] = nil
|
@@ -40,7 +41,7 @@ describe CreateFillOutRequest do
|
|
40
41
|
expect(args[:fill_out_request][:open_from]).to eq nil
|
41
42
|
expect(args[:fill_out_request][:open_till]).to eq nil
|
42
43
|
expect(args[:fill_out_request][:reminders]).to eq nil
|
43
|
-
|
44
|
+
response
|
44
45
|
end
|
45
46
|
CreateFillOutRequest.run!(options)
|
46
47
|
end
|
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Endpoint do
|
4
4
|
class TestEndpoint < Endpoint
|
5
|
-
|
5
|
+
model :response, class: RSpec::Mocks::Mock
|
6
6
|
|
7
7
|
def execute
|
8
8
|
validate_response_for do
|
9
|
-
response
|
9
|
+
response
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -16,31 +16,51 @@ describe Endpoint do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'with validations' do
|
19
|
+
let(:response) do
|
20
|
+
double('httparty_repsonse', code: 200, parsed_response: {}).tap do |response|
|
21
|
+
allow(response).to receive(:[]).with('key').and_return ['values']
|
22
|
+
allow(response).to receive(:[]).with('errors').and_return []
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
19
26
|
it 'returns the parsed response' do
|
20
|
-
outcome = TestEndpoint.run response:
|
27
|
+
outcome = TestEndpoint.run response: response
|
21
28
|
expect(outcome.result).to eq(['values'])
|
22
29
|
end
|
23
30
|
|
24
31
|
it 'is valid' do
|
25
|
-
result = TestEndpoint.run response:
|
32
|
+
result = TestEndpoint.run response: response
|
26
33
|
expect(result).to be_valid
|
27
34
|
end
|
28
35
|
|
29
36
|
context 'when the response contains errors' do
|
37
|
+
before do
|
38
|
+
allow(response).to receive(:[]).with('errors').and_return('base' => ['some_annoying_error'])
|
39
|
+
end
|
40
|
+
|
30
41
|
it 'adds the errors' do
|
31
|
-
outcome = TestEndpoint.run response:
|
42
|
+
outcome = TestEndpoint.run response: response
|
32
43
|
expect(outcome.errors.full_messages.first).to match('Some annoying error')
|
33
44
|
end
|
34
45
|
|
35
46
|
it 'marks the outcome as invalid' do
|
36
|
-
outcome = TestEndpoint.run response:
|
47
|
+
outcome = TestEndpoint.run response: response
|
37
48
|
expect(outcome).not_to be_valid
|
38
49
|
end
|
39
50
|
|
40
51
|
it 'does not return a result' do
|
41
|
-
outcome = TestEndpoint.run response:
|
52
|
+
outcome = TestEndpoint.run response: response
|
42
53
|
expect(outcome.result).to be_nil
|
43
54
|
end
|
44
55
|
end
|
56
|
+
|
57
|
+
context 'when the response code is 422 but the response contains no errors' do
|
58
|
+
it 'adds an error to base' do
|
59
|
+
allow(response).to receive(:code).and_return 422
|
60
|
+
outcome = TestEndpoint.run response: response
|
61
|
+
expect(outcome).not_to be_valid
|
62
|
+
expect(outcome.errors.full_messages).to include('Validations failed!')
|
63
|
+
end
|
64
|
+
end
|
45
65
|
end
|
46
66
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ListProtocolSubscriptions do
|
4
4
|
let(:options) { {dossier_id: '1'} }
|
5
5
|
let(:api_path) { "/dossiers/#{options[:dossier_id]}/protocol_subscriptions" }
|
6
|
-
let(:response) { [{
|
6
|
+
let(:response) { httparty_response [{'id' => 1}] }
|
7
7
|
let(:session) { Fabricate :basic_auth_session }
|
8
8
|
before { allow(BasicAuthSession).to receive(:new).and_return session }
|
9
9
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ListResponses do
|
4
4
|
let(:options) { {dossier_id: '1'} }
|
5
5
|
let(:api_path) { "/dossiers/#{options[:dossier_id]}/responses" }
|
6
|
-
let(:response) { [{"questionnaire_name" => "response_1"}, {"questionnaire_name" => "response_2"}] }
|
6
|
+
let(:response) { httparty_response [{"questionnaire_name" => "response_1"}, {"questionnaire_name" => "response_2"}] }
|
7
7
|
let(:session) { Fabricate :basic_auth_session }
|
8
8
|
before { allow(BasicAuthSession).to receive(:new).and_return session }
|
9
9
|
|
@@ -1,26 +1,41 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StartFillOutSession do
|
4
|
-
let(:options)
|
5
|
-
|
6
|
-
let(:session)
|
7
|
-
let(:response) {
|
4
|
+
let(:options) { {dossier_id: 'some_dossier_id', questionnaire_keys: ['some_key'],
|
5
|
+
return_to: '/some/return/url', stylesheet: 'https://example.org/stylesheet.css'} }
|
6
|
+
let(:session) { Sessions::BasicAuthSession.new }
|
7
|
+
let(:response) { httparty_response 'fill_out_url' => 'some_fill_out_url' }
|
8
8
|
before do
|
9
9
|
allow(Sessions::BasicAuthSession).to receive(:new).and_return session
|
10
10
|
allow(session).to receive(:post).and_return response
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'does a post to the rom fill_out_sessions api' do
|
14
|
+
options[:response_ids] = [1, 2]
|
14
15
|
expect(session).to receive(:post).with("/dossiers/#{options[:dossier_id]}/fill_out_sessions",
|
15
|
-
|
16
|
+
questionnaire_keys: options[:questionnaire_keys],
|
17
|
+
response_ids: options[:response_ids],
|
16
18
|
return_to: options[:return_to],
|
17
19
|
stylesheet: options[:stylesheet])
|
18
20
|
StartFillOutSession.run!(options)
|
19
21
|
end
|
20
22
|
|
21
|
-
it 'returns the received
|
22
|
-
allow(session).to receive(:post).and_return 'questionnaire_url' => 'some_questionnaire_url'
|
23
|
+
it 'returns the received fill_out url' do
|
23
24
|
outcome = StartFillOutSession.run(options)
|
24
|
-
expect(outcome.result).to eq('
|
25
|
+
expect(outcome.result).to eq('some_fill_out_url')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'validates the presence of questionnaire keys' do
|
29
|
+
options[:questionnaire_keys] = []
|
30
|
+
outcome = StartFillOutSession.run(options)
|
31
|
+
expect(outcome).not_to be_valid
|
32
|
+
expect(outcome.errors.full_messages).to include("Questionnaire keys can't be blank")
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not validate the presence of questionnaire keys when answer_ids are given' do
|
36
|
+
options[:questionnaire_keys] = []
|
37
|
+
options[:response_ids] = [1, 2]
|
38
|
+
outcome = StartFillOutSession.run(options)
|
39
|
+
expect(outcome).to be_valid
|
25
40
|
end
|
26
41
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe StartProtocolSubscription do
|
4
|
-
let(:options)
|
5
|
-
let(:session)
|
6
|
-
let(:response) {
|
4
|
+
let(:options) { {dossier_id: 'some_dossier_id', protocol_key: 'some_key'} }
|
5
|
+
let(:session) { Sessions::BasicAuthSession.new }
|
6
|
+
let(:response) { httparty_response({}) }
|
7
7
|
before do
|
8
8
|
allow(Sessions::BasicAuthSession).to receive(:new).and_return session
|
9
9
|
allow(session).to receive(:post).and_return response
|
@@ -2,9 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe StopProtocolSubscription do
|
4
4
|
let(:options) { {dossier_id: 'some_dossier_id', protocol_subscription_id: 'some_protsub_id'} }
|
5
|
-
let(:response) {
|
6
|
-
|
7
|
-
let(:session) { Fabricate :basic_auth_session }
|
5
|
+
let(:response) { httparty_response({}) }
|
6
|
+
let(:session) { Fabricate :basic_auth_session }
|
8
7
|
before do
|
9
8
|
allow(Sessions::BasicAuthSession).to receive(:new).and_return session
|
10
9
|
allow(session).to receive(:delete).and_return response
|
data/spec/spec_helper.rb
CHANGED
@@ -4,3 +4,7 @@ require 'roqua-rom-api'
|
|
4
4
|
include Roqua::RomApi
|
5
5
|
include Roqua::RomApi::Sessions
|
6
6
|
include Roqua::RomApi::Models
|
7
|
+
|
8
|
+
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'support', '*.rb')].each {|f| require f}
|
9
|
+
|
10
|
+
I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'support', '*.yml')]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roqua-rom-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Esposito
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -168,6 +168,8 @@ files:
|
|
168
168
|
- spec/lib/roqua/rom_api/stop_protocol_subscription_spec.rb
|
169
169
|
- spec/lib/roqua_rom_api_spec.rb
|
170
170
|
- spec/spec_helper.rb
|
171
|
+
- spec/support/httparty_helpers.rb
|
172
|
+
- spec/support/test.yml
|
171
173
|
homepage: https://github.com/roqua/roqua/blob/master/rom_api/README.md
|
172
174
|
licenses:
|
173
175
|
- MIT
|
@@ -188,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
190
|
version: '0'
|
189
191
|
requirements: []
|
190
192
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.2.
|
193
|
+
rubygems_version: 2.2.2
|
192
194
|
signing_key:
|
193
195
|
specification_version: 4
|
194
196
|
summary: API wrapper gem around RoQua's ROM API
|
@@ -206,4 +208,6 @@ test_files:
|
|
206
208
|
- spec/lib/roqua/rom_api/stop_protocol_subscription_spec.rb
|
207
209
|
- spec/lib/roqua_rom_api_spec.rb
|
208
210
|
- spec/spec_helper.rb
|
211
|
+
- spec/support/httparty_helpers.rb
|
212
|
+
- spec/support/test.yml
|
209
213
|
has_rdoc:
|