roqua-rom-api 0.0.9 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e4c9540bc5e468f4b51c4cfab6016fbcea74241
4
- data.tar.gz: 1404eaf705529199115775862aa7fe202fe80d16
3
+ metadata.gz: 475ac6de577ac65fdf2e2da65ec85adf70dbbfaf
4
+ data.tar.gz: 31f5cb17b157a41080c1b9bf547a263c804a1e99
5
5
  SHA512:
6
- metadata.gz: afcb437a07656bc8035000c59412f0799456b25f898409a976e1d8cd63f3676deca20919ecd9eea4501747223f585a60acd621e80500544238dca2be60847988
7
- data.tar.gz: 288b8f042d92285cce3cbd16c793fb0cdd233d789ad3178794a8bb765086a068bdea06f24c96504fc71ff495627ef28bc12b8c5bae3d597495bce35df33fe9bd
6
+ metadata.gz: 6a1cc7174e50cb2efd8166ea1b0494576c4e13b826dac3a4445434bace1f8f596022d2e032c636814cf33966ddbd9dc80d6960324b40d49f14418a5bc67f4765
7
+ data.tar.gz: 7abe459bd3921fc2a6f757d841080aee2da6c557bf047c9ada203f000b8866b5a6a471cbb994786bddfc29b826ce5b8354e834010c4d31691b1bde41d6de0077
data/ChangeLog.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.1.1 / 2014-0-23
2
+
3
+ * Validate api responses
4
+ * From now on the Responses API is accessible through the Responses interactor. The received responses can be obtained through the `#responses` accessor when the interactor outcome is valid.
5
+ * Similarly the the ProtocolSubscriptions API is hence forth accessible through the ProtocolSubscriptions interactor. The received protocol subscriptions can be obtained through the `#protocol_subscriptions` accessor when the interactor outcome is valid.
6
+ * Add accessor for fill_out_session api questionnaire_url
7
+ * Update documentation in README
8
+
1
9
  ### 0.0.9 / 2014-04-14
2
10
 
3
11
  * Added Virtus to the gemspec
data/README.md CHANGED
@@ -2,26 +2,125 @@
2
2
 
3
3
  Make sure the following environment variables are defined:
4
4
 
5
- ENV['ROM_HOST'] # uri of the RoQua application whose API you are targeting
5
+ ENV['ROM_HOST'] # URI of the RoQua application whose API you are targeting
6
6
  ENV['ROM_KEY'] # username used for HTTP basic authentication on the RoQua API
7
7
  ENV['ROM_SECRET'] # password used for HTTP basic authentication on the RoQua API
8
8
 
9
9
  An HTTP basic auth username password combination can be generated in the RoQua admin interface integration tab
10
10
 
11
+ ## FillOut Sessions
12
+
13
+ To start filling out a questionnaire run:
14
+
15
+ outcome = Roqua::RomApi::StartFillOutSession.run dossier_id: dossier_id,
16
+ questionnaire_key: questionnaire_key,
17
+ return_to: '/some/return/url/or/path'
18
+
19
+ #### Parameters
20
+
21
+ * `dossier_id:` [Required] - Unique dossier identifier for the patient about to fill out a questionnaire.
22
+ * `questionnaire_key:` [Required] - Key uniquely identifying the questionnaire to be filled out.
23
+ * `return_to:` [Required] - Address to return to after filling out the questionnaire.
24
+
25
+ Redirect to the questionnaire url received when the outcome is valid:
26
+
27
+ if outcome.valid?
28
+ redirect_to outcome.questionnaire_url
29
+
30
+ or do something with the validation errors:
31
+
32
+ else
33
+ log_or_display outcome.errors.full_messages
34
+ end
35
+
11
36
  ## Protocol Subscriptions
12
37
 
38
+ ### Index
39
+ To retrieve active protocol subscriptions run:
40
+
41
+ outcome = Roqua::RomApi::ProtocolSubscription.run dossier_id: dossier_id
42
+
43
+ #### Parameters
44
+
45
+ * `dossier_id:` [Required] - Unique dossier identifier for the patient you want the subscriptions for.
46
+
47
+ When the request succeeds, the subscriptions can be accessed through `#protocol_subscriptions`:
48
+
49
+ if outcome.valid?
50
+ subscriptions = outcome.protocol_subscriptions
51
+
52
+ Else some validation errors can be shown:
53
+
54
+ else
55
+ log_or_display outcome.errors.full_messages
56
+ end
57
+
58
+ ### Create
13
59
  To subscribe to a protocol run the following command:
14
60
 
15
- Roqua::RomApi::StartProtocolSubscription.run dossier_id: dossier_id,
16
- protocol_key: protocol_key,
17
- start_at: start_at
61
+ outcome = Roqua::RomApi::StartProtocolSubscription.run dossier_id: dossier_id,
62
+ protocol_key: protocol_key,
63
+ start_at: start_at
18
64
 
19
- #### Subscription options
65
+ #### Parameters
20
66
 
21
- * `dossier_id:` [Required] - Unique identifier for the patient to be subscribed.
67
+ * `dossier_id:` [Required] - Unique dossier identifier for the patient to be subscribed.
22
68
  * `protocol_key:` [Required] - Key uniquely identifying the protocol of interest as specified in RoQua.
23
69
  * `start_at:` [Defaults to the present] - Timestamp specifying when the first measurement should be prepared.
24
70
 
71
+ When the subscription succeeds, the subscription object is available through the `#result` accessor:
72
+
73
+ if outcome.valid?
74
+ subscription = outcome.result
75
+
76
+ Else the validation errors can be inspected:
77
+
78
+ else
79
+ log_or_display outcome.errors.full_messages
80
+ end
81
+
82
+ ### Destroy
83
+ To unsubscribe from a protocol run the command:
84
+
85
+ outcome = Roqua::RomApi::StopProtocolSubscription.run dossier_id: dossier_id,
86
+ protocol_subscription_id: subscription_id
87
+
88
+ #### Parameters
89
+
90
+ * `dossier_id:` [Required] - Unique dossier identifier for the patient to be unsubscribed.
91
+ * `protocol_subscription_id:` [Required] - Unique identifier for the protocolsubscription to be stopped.
92
+
93
+ When stopping the subscription succeeds, the subscription object is available through the `#result` accessor:
94
+
95
+ if outcome.valid?
96
+ subscription = outcome.result
97
+
98
+ Else the validation errors can be inspected:
99
+
100
+ else
101
+ log_or_display outcome.errors.full_messages
102
+ end
103
+
104
+ ## Responses
105
+
106
+ To retrieve filled out, pending or scheduled questionnaires run:
107
+
108
+ outcome = Roqua::RomApi::Responses.run dossier_id: dossier_id
109
+
110
+ #### Parameters
111
+
112
+ * `dossier_id:` [Required] - Unique dossier identifier for the patient you want the responses for.
113
+
114
+ When the request succeeds, the responses can be accessed through `#responses`:
115
+
116
+ if outcome.valid?
117
+ responses = outcome.responses
118
+
119
+ Else some validation errors can be shown:
120
+
121
+ else
122
+ log_or_display outcome.errors.full_messages
123
+ end
25
124
 
26
125
  ## Contributing to roqua-rom-api
27
126
 
@@ -0,0 +1,18 @@
1
+ module Roqua
2
+ module RomApi
3
+ # @api private
4
+ class Endpoint < ActiveInteraction::Base
5
+ private
6
+
7
+ def validate_response_for
8
+ response = yield
9
+ if response && response['errors']
10
+ response['errors'].each do |error|
11
+ errors.add :base, error
12
+ end
13
+ end
14
+ response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Roqua
2
+ module RomApi
3
+ # @api private
4
+ class ProtocolSubscriptions < Endpoint
5
+ string :dossier_id
6
+
7
+ def execute
8
+ validate_response_for do
9
+ RomApi.basic_auth_session.get "/dossiers/#{dossier_id}/protocol_subscriptions"
10
+ end
11
+ end
12
+
13
+ def protocol_subscriptions
14
+ result['protocol_subscriptions'].map { |s| Models::ProtocolSubscription.new(s) }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module Roqua
2
+ module RomApi
3
+ # @api private
4
+ class Responses < Endpoint
5
+ string :dossier_id
6
+
7
+ def execute
8
+ validate_response_for do
9
+ RomApi.basic_auth_session.get "/dossiers/#{dossier_id}/responses"
10
+ end
11
+ end
12
+
13
+ def responses
14
+ result['responses'].map { |r| Models::Response.new(r) }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,15 +1,21 @@
1
1
  module Roqua
2
2
  module RomApi
3
3
  # @api private
4
- class StartFillOutSession < ActiveInteraction::Base
4
+ class StartFillOutSession < Endpoint
5
5
  string :dossier_id
6
6
  string :questionnaire_key
7
7
  string :return_to
8
8
 
9
9
  def execute
10
- RomApi.basic_auth_session.post("/dossiers/#{dossier_id}/fill_out_sessions",
11
- questionnaire_key: questionnaire_key,
12
- return_to: return_to).parsed_response
10
+ validate_response_for do
11
+ RomApi.basic_auth_session.post("/dossiers/#{dossier_id}/fill_out_sessions",
12
+ questionnaire_key: questionnaire_key,
13
+ return_to: return_to)
14
+ end
15
+ end
16
+
17
+ def questionnaire_url
18
+ result['questionnaire_url']
13
19
  end
14
20
  end
15
21
  end
@@ -1,7 +1,7 @@
1
1
  module Roqua
2
2
  module RomApi
3
3
  # @api private
4
- class StartProtocolSubscription < ActiveInteraction::Base
4
+ class StartProtocolSubscription < Endpoint
5
5
  string :dossier_id
6
6
  string :protocol_key
7
7
  time :start_at, default: nil
@@ -9,7 +9,9 @@ module Roqua
9
9
  def execute
10
10
  options = {protocol_key: protocol_key}
11
11
  options[:start_at] = start_at.to_i if start_at
12
- RomApi.basic_auth_session.post("/dossiers/#{dossier_id}/protocol_subscriptions", options).parsed_response
12
+ validate_response_for do
13
+ RomApi.basic_auth_session.post("/dossiers/#{dossier_id}/protocol_subscriptions", options)
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -1,13 +1,14 @@
1
1
  module Roqua
2
2
  module RomApi
3
3
  # @api private
4
- class StopProtocolSubscription < ActiveInteraction::Base
4
+ class StopProtocolSubscription < Endpoint
5
5
  string :dossier_id
6
6
  string :protocol_subscription_id
7
7
 
8
8
  def execute
9
- url = "/dossiers/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}"
10
- RomApi.basic_auth_session.delete(url).parsed_response
9
+ validate_response_for do
10
+ RomApi.basic_auth_session.delete("/dossiers/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}")
11
+ end
11
12
  end
12
13
  end
13
14
  end
@@ -1,5 +1,5 @@
1
1
  module Roqua
2
2
  module RomApi
3
- VERSION = '0.0.9'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
data/lib/roqua/rom_api.rb CHANGED
@@ -2,11 +2,12 @@ require 'active_interaction'
2
2
  require 'roqua/rom_api/version'
3
3
  require 'roqua/rom_api/sessions'
4
4
  require 'roqua/rom_api/models'
5
+ require 'roqua/rom_api/endpoint'
6
+ require 'roqua/rom_api/protocol_subscriptions'
7
+ require 'roqua/rom_api/responses'
8
+ require 'roqua/rom_api/start_fill_out_session'
5
9
  require 'roqua/rom_api/start_protocol_subscription'
6
10
  require 'roqua/rom_api/stop_protocol_subscription'
7
- require 'roqua/rom_api/start_fill_out_session'
8
- require 'roqua/rom_api/list_responses'
9
- require 'roqua/rom_api/list_protocol_subscriptions'
10
11
 
11
12
  module Roqua
12
13
  module RomApi
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Endpoint do
4
+ class TestEndpoint < Endpoint
5
+ hash :response, strip: false
6
+
7
+ def execute
8
+ validate_response_for do
9
+ response.stringify_keys
10
+ end
11
+ end
12
+ end
13
+
14
+ describe 'with validations' do
15
+ it 'returns the response' do
16
+ outcome = TestEndpoint.run response: {'some' => ['values']}
17
+ expect(outcome.result).to eq('some' => ['values'])
18
+ end
19
+
20
+ it 'is valid' do
21
+ result = TestEndpoint.run response: {'some' => ['values']}
22
+ expect(result).to be_valid
23
+ end
24
+
25
+ context 'when the response contains errors' do
26
+ it 'adds the errors' do
27
+ result = TestEndpoint.run response: {'errors' => ['Some annoying error.']}
28
+ expect(result.errors.full_messages).to include('Some annoying error.')
29
+ end
30
+
31
+ it 'marks the result as invalid' do
32
+ result = TestEndpoint.run response: {'errors' => ['Some annoying error.']}
33
+ expect(result).not_to be_valid
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ListProtocolSubscriptions do
3
+ describe ProtocolSubscriptions do
4
4
  let(:options) { {dossier_id: '1'} }
5
5
  let(:api_path) { "/dossiers/#{options[:dossier_id]}/protocol_subscriptions" }
6
6
  let(:response) { {"protocol_subscriptions" => [{"id" => 1}]} }
@@ -9,10 +9,10 @@ describe ListProtocolSubscriptions do
9
9
 
10
10
  it 'returns an array of response objects' do
11
11
  allow(session).to receive(:get).with(api_path).and_return response
12
- result = ListProtocolSubscriptions.run(options).result
12
+ protocol_subscriptions = ProtocolSubscriptions.run(options).protocol_subscriptions
13
13
 
14
- expect(result).to be_a(Array)
15
- expect(result.first).to be_a(ProtocolSubscription)
16
- expect(result.first.id).to eq(1)
14
+ expect(protocol_subscriptions).to be_a(Array)
15
+ expect(protocol_subscriptions.first).to be_a(ProtocolSubscription)
16
+ expect(protocol_subscriptions.first.id).to eq(1)
17
17
  end
18
18
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ListResponses do
3
+ describe Responses do
4
4
  let(:options) { {dossier_id: '1'} }
5
5
  let(:api_path) { "/dossiers/#{options[:dossier_id]}/responses" }
6
6
  let(:response) { {"responses" => [{"name" => "response_1"}, {"name" => "response_2"}]} }
@@ -9,10 +9,10 @@ describe ListResponses do
9
9
 
10
10
  it 'returns an array of response objects' do
11
11
  allow(session).to receive(:get).with(api_path).and_return response
12
- result = ListResponses.run(options).result
12
+ responses = Responses.run(options).responses
13
13
 
14
- expect(result).to be_a(Array)
15
- expect(result.first).to be_a(Response)
16
- expect(result.first.name).to eq('response_1')
14
+ expect(responses).to be_a(Array)
15
+ expect(responses.first).to be_a(Response)
16
+ expect(responses.first.name).to eq('response_1')
17
17
  end
18
18
  end
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
  describe StartFillOutSession do
4
4
  let(:options) { {dossier_id: 'some_dossier_id', questionnaire_key: 'some_key', return_to: '/some/return/url'} }
5
5
  let(:session) { Sessions::BasicAuthSession.new }
6
- let(:parsed_response) { double('parsed_response') }
7
- let(:response) { double('response', parsed_response: parsed_response) }
6
+ let(:response) { double('response', :[] => nil) }
8
7
  before do
9
8
  allow(Sessions::BasicAuthSession).to receive(:new).and_return session
10
9
  allow(session).to receive(:post).and_return response
@@ -17,7 +16,13 @@ describe StartFillOutSession do
17
16
  StartFillOutSession.run!(options)
18
17
  end
19
18
 
20
- it 'returns the parsed response' do
21
- expect(StartFillOutSession.run!(options)).to eq(parsed_response)
19
+ it 'returns the response' do
20
+ expect(StartFillOutSession.run!(options)).to eq(response)
22
21
  end
23
- end
22
+
23
+ it 'gives access to the received questionnaire url' do
24
+ allow(session).to receive(:post).and_return 'questionnaire_url' => 'some_questionnaire_url'
25
+ outcome = StartFillOutSession.run(options)
26
+ expect(outcome.questionnaire_url).to eq('some_questionnaire_url')
27
+ end
28
+ end
@@ -3,8 +3,7 @@ require 'spec_helper'
3
3
  describe StartProtocolSubscription do
4
4
  let(:options) { {dossier_id: 'some_dossier_id', protocol_key: 'some_key'} }
5
5
  let(:session) { Sessions::BasicAuthSession.new }
6
- let(:parsed_response) { double('parsed_response') }
7
- let(:response) { double('response', parsed_response: parsed_response) }
6
+ let(:response) { double('response', :[] => nil) }
8
7
  before do
9
8
  allow(Sessions::BasicAuthSession).to receive(:new).and_return session
10
9
  allow(session).to receive(:post).and_return response
@@ -24,7 +23,7 @@ describe StartProtocolSubscription do
24
23
  StartProtocolSubscription.run!(options.merge start_at: start_at)
25
24
  end
26
25
 
27
- it 'returns the parsed response' do
28
- expect(StartProtocolSubscription.run!(options)).to eq(parsed_response)
26
+ it 'returns the response' do
27
+ expect(StartProtocolSubscription.run!(options)).to eq(response)
29
28
  end
30
29
  end
@@ -2,8 +2,7 @@ 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(:parsed_response) { double('parsed_response') }
6
- let(:response) { double('response', parsed_response: parsed_response) }
5
+ let(:response) { double('response', :[] => nil) }
7
6
 
8
7
  let(:session) { Fabricate :basic_auth_session }
9
8
  before do
@@ -16,4 +15,8 @@ describe StopProtocolSubscription do
16
15
  expect(session).to receive(:delete).with(url)
17
16
  StopProtocolSubscription.run!(options)
18
17
  end
18
+
19
+ it 'returns the response' do
20
+ expect(StopProtocolSubscription.run!(options)).to eq(response)
21
+ end
19
22
  end
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.0.9
4
+ version: 0.1.1
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-04-16 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -138,11 +138,12 @@ files:
138
138
  - Rakefile
139
139
  - lib/roqua-rom-api.rb
140
140
  - lib/roqua/rom_api.rb
141
- - lib/roqua/rom_api/list_protocol_subscriptions.rb
142
- - lib/roqua/rom_api/list_responses.rb
141
+ - lib/roqua/rom_api/endpoint.rb
143
142
  - lib/roqua/rom_api/models.rb
144
143
  - lib/roqua/rom_api/models/protocol_subscription.rb
145
144
  - lib/roqua/rom_api/models/response.rb
145
+ - lib/roqua/rom_api/protocol_subscriptions.rb
146
+ - lib/roqua/rom_api/responses.rb
146
147
  - lib/roqua/rom_api/sessions.rb
147
148
  - lib/roqua/rom_api/sessions/basic_auth_session.rb
148
149
  - lib/roqua/rom_api/start_fill_out_session.rb
@@ -151,10 +152,11 @@ files:
151
152
  - lib/roqua/rom_api/version.rb
152
153
  - roqua_rom_api.gemspec
153
154
  - spec/fabricators/basic_auth_session_fabricator.rb
154
- - spec/lib/roqua/rom_api/list_protocol_subscriptions_spec.rb
155
- - spec/lib/roqua/rom_api/list_responses_spec.rb
155
+ - spec/lib/roqua/rom_api/endpoint_spec.rb
156
156
  - spec/lib/roqua/rom_api/models/protocol_subscription_spec.rb
157
157
  - spec/lib/roqua/rom_api/models/response_spec.rb
158
+ - spec/lib/roqua/rom_api/protocol_subscriptions_spec.rb
159
+ - spec/lib/roqua/rom_api/responses_spec.rb
158
160
  - spec/lib/roqua/rom_api/sessions/basic_auth_session_spec.rb
159
161
  - spec/lib/roqua/rom_api/start_fill_out_session_spec.rb
160
162
  - spec/lib/roqua/rom_api/start_protocol_subscription_spec.rb
@@ -187,10 +189,11 @@ specification_version: 4
187
189
  summary: API wrapper gem around RoQua's ROM API
188
190
  test_files:
189
191
  - spec/fabricators/basic_auth_session_fabricator.rb
190
- - spec/lib/roqua/rom_api/list_protocol_subscriptions_spec.rb
191
- - spec/lib/roqua/rom_api/list_responses_spec.rb
192
+ - spec/lib/roqua/rom_api/endpoint_spec.rb
192
193
  - spec/lib/roqua/rom_api/models/protocol_subscription_spec.rb
193
194
  - spec/lib/roqua/rom_api/models/response_spec.rb
195
+ - spec/lib/roqua/rom_api/protocol_subscriptions_spec.rb
196
+ - spec/lib/roqua/rom_api/responses_spec.rb
194
197
  - spec/lib/roqua/rom_api/sessions/basic_auth_session_spec.rb
195
198
  - spec/lib/roqua/rom_api/start_fill_out_session_spec.rb
196
199
  - spec/lib/roqua/rom_api/start_protocol_subscription_spec.rb
@@ -1,12 +0,0 @@
1
- module Roqua
2
- module RomApi
3
- # @api private
4
- class ListProtocolSubscriptions < ActiveInteraction::Base
5
- string :dossier_id
6
- def execute
7
- response = RomApi.basic_auth_session.get "/dossiers/#{dossier_id}/protocol_subscriptions"
8
- response['protocol_subscriptions'].map { |s| Models::ProtocolSubscription.new(s) }
9
- end
10
- end
11
- end
12
- end
@@ -1,12 +0,0 @@
1
- module Roqua
2
- module RomApi
3
- # @api private
4
- class ListResponses < ActiveInteraction::Base
5
- string :dossier_id
6
- def execute
7
- response = RomApi.basic_auth_session.get "/dossiers/#{dossier_id}/responses"
8
- response['responses'].map { |r| Models::Response.new(r) }
9
- end
10
- end
11
- end
12
- end