roqua-healthy 1.0.2 → 1.1.0

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: e8816a868a01da4c523089c72f78f23e62026280
4
- data.tar.gz: 408c2a873db4743e7937eadb234a526f2c271427
3
+ metadata.gz: 8eb7c6e8f253cbe1f2a7768a9cff7f8fceef6c15
4
+ data.tar.gz: 6489b577b4f97629a98df40bcc8feab3cb9e4701
5
5
  SHA512:
6
- metadata.gz: ff8b9b02d19b29025d07bf7177c037fb4c3d2c19a901d15e6112619d4fbcbb66fbe4fd5313f92ae9009ada39cfdeafc90e20220284c573ed557f279b53ecb569
7
- data.tar.gz: 61ebbe34d3a25fdb81182d0f6108d301df5a0488d1f8fc34f46e8ed9c5004d832798d3e2b53366318eeddd058353864b11e750085bdfc2fdbab0abb44e011fee
6
+ metadata.gz: ba34e6ff1aeb443ed8dc03fcdd45a93e9e53de4a131f9a43eb82d9091265c174170a9436cf5ae90fad387251ddaa7cd196a9da7afd95771b322243a2825de31e
7
+ data.tar.gz: 9ffccccbbfbaa6f553c0729e23918e5de2cdb0ae730fa23cb63ff9bac521dd4beeb750340c87e8deb8f2696d138ece366ebe47974581ede2bb1676a72297c182
data/Guardfile CHANGED
@@ -5,7 +5,7 @@ guard 'rspec', cmd: 'bundle exec rspec -f Fuubar' do
5
5
  watch(%r{^spec/fixtures/([^_]+)_.*.xml}) { |m| "spec/integration/#{m[1]}_spec.rb" }
6
6
  end
7
7
 
8
- guard :rubocop do
8
+ guard :rubocop, cli: ['-D'] do
9
9
  watch(%r{.+\.rb$})
10
10
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
11
11
  end
data/README.md CHANGED
@@ -8,6 +8,13 @@
8
8
  Healthy::A19.fetch(patient_identifier)
9
9
  ```
10
10
 
11
+ or if you need multiple configurations
12
+
13
+ ```ruby
14
+ client = Healthy::A19::Client(a19_endpoint: 'https://...')
15
+ client.fetch_a19(patient_identifier)
16
+ ```
17
+
11
18
  ### Adding integration tests
12
19
 
13
20
  If you find any A19 response that Healthy currently does not handle correctly, please add a fixture and integration test for it.
@@ -9,9 +9,11 @@ module Roqua
9
9
  module A19
10
10
  class Fetcher
11
11
  attr_reader :patient_id
12
+ attr_reader :client
12
13
 
13
- def initialize(patient_id)
14
+ def initialize(patient_id, client)
14
15
  @patient_id = patient_id
16
+ @client = client
15
17
  end
16
18
 
17
19
  def fetch
@@ -50,7 +52,7 @@ module Roqua
50
52
  def remote_url
51
53
  return @remote_url if @remote_url
52
54
 
53
- url = Addressable::URI.parse(Healthy.a19_endpoint)
55
+ url = Addressable::URI.parse(client.a19_endpoint)
54
56
  url.path = "/"
55
57
 
56
58
  @remote_url = URI.parse(url.to_s)
@@ -1,8 +1,6 @@
1
1
  module Roqua
2
2
  module Healthy
3
3
  module A19
4
- extend ::Roqua::Logging
5
-
6
4
  # Fetches a patient record given a `patient_id` and returns a hash containing
7
5
  # the interesting information that was returned from an upstream `ADR^A19`
8
6
  # response.
@@ -10,11 +8,7 @@ module Roqua
10
8
  # @param patient_id [String] the patient identifier
11
9
  # @return [Hash] the patient details.
12
10
  def self.fetch(patient_id)
13
- eventlog.lifecycle('roqua.hl7.a19', patient_id: patient_id) do
14
- message = Fetcher.new(patient_id).fetch
15
- patient = Transformer.new(message).to_patient
16
- patient
17
- end
11
+ Client.new.fetch_a19(patient_id)
18
12
  end
19
13
  end
20
14
  end
@@ -0,0 +1,27 @@
1
+ module Roqua
2
+ module Healthy
3
+ class Client
4
+ include ::Roqua::Logging
5
+
6
+ attr_accessor :a19_endpoint
7
+
8
+ def initialize(options = {})
9
+ @a19_endpoint = options[:a19_endpoint]
10
+ end
11
+
12
+ def a19_endpoint
13
+ @a19_endpoint || Roqua::Healthy.a19_endpoint
14
+ end
15
+
16
+ def fetch_a19(patient_id)
17
+ eventlog.lifecycle('roqua.hl7.a19', patient_id: patient_id) do
18
+ message = A19::Fetcher.new(patient_id, self).fetch
19
+ patient = A19::Transformer.new(message).to_patient
20
+ patient
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ require_relative 'a19'
@@ -1,6 +1,6 @@
1
1
  module Roqua
2
2
  module Healthy
3
3
  # healthy version
4
- VERSION = "1.0.2"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
  end
data/lib/roqua/healthy.rb CHANGED
@@ -3,6 +3,7 @@ require 'roqua/support'
3
3
  require 'roqua/healthy/version'
4
4
  require 'roqua/healthy/message_cleaner'
5
5
  require 'roqua/healthy/a19'
6
+ require 'roqua/healthy/client'
6
7
  require 'roqua/healthy/errors'
7
8
 
8
9
  module Roqua
@@ -34,7 +34,7 @@ Gem::Specification.new do |gem|
34
34
  gem.add_development_dependency 'guard-rspec', '~> 4.2.4'
35
35
  gem.add_development_dependency 'listen', '~> 2.1'
36
36
  gem.add_development_dependency 'guard-rubocop', '~> 1.0.1'
37
- gem.add_development_dependency 'rubocop', '~> 0.15'
37
+ gem.add_development_dependency 'rubocop', '~> 0.17'
38
38
  gem.add_development_dependency 'fuubar'
39
39
 
40
40
  # Documentation generation
@@ -1,54 +1,70 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Roqua::Healthy::A19::Fetcher do
4
+ let(:client) { Roqua::Healthy::Client.new }
5
+
6
+ subject { Roqua::Healthy::A19::Fetcher.new("123", client) }
7
+
4
8
  it 'succeeds when upstream returns XML' do
5
9
  stub_mirth_response("<HL7Message></HL7Message>")
6
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.not_to raise_error
10
+ expect { subject.fetch }.not_to raise_error
7
11
  end
8
12
 
9
13
  it "raises when upstream does not return HTTP 200" do
10
14
  stub_mirth_response "Request not successful", 500
11
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception
15
+ expect { subject.fetch }.to raise_exception
12
16
  end
13
17
 
14
18
  it 'raises when upstream responds with illegal XML' do
15
19
  stub_mirth_response "<patient><firstname>Jan & Piet</firstname></patient>"
16
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse)
20
+ expect { subject.fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse)
17
21
 
18
22
  stub_mirth_response "<patient><firstname>Jan</patient>"
19
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse)
23
+ expect { subject.fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse)
20
24
  end
21
25
 
22
26
  it "raises upstream is returning 'Timeout waiting for ACK' messages" do
23
27
  stub_mirth_response "<failure><error>Timeout waiting for ACK</error></failure>", 500
24
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout)
28
+ expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout)
25
29
  end
26
30
 
27
31
  it "raises upstream is returning 'connection timeout' messages" do
28
32
  stub_mirth_response "<failure><error>Unable to connect to destination\tSocketTimeoutException\tconnect timed out</error></failure>", 500
29
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout)
33
+ expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout)
30
34
  end
31
35
 
32
- it "raises upstream is returning 'connection refuesed' messages" do
36
+ it "raises upstream is returning 'connection refused' messages" do
33
37
  stub_mirth_response "<failure><error>Unable to connect to destination\tConnectException\tConnection refused</error></failure>", 500
34
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused)
38
+ expect { subject.fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused)
35
39
  end
36
40
 
37
41
  it "raises when upstream does not accept connections" do
38
42
  stub_mirth.to_raise Errno::ECONNREFUSED
39
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused)
43
+ expect { subject.fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused)
40
44
  end
41
45
 
42
46
  it 'raises when upstream is unreachable' do
43
47
  stub_mirth.to_raise Errno::EHOSTUNREACH
44
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::HostUnreachable)
48
+ expect { subject.fetch }.to raise_exception(Roqua::Healthy::HostUnreachable)
45
49
  end
46
50
 
47
51
  it "raises when upstream is timing out" do
48
52
  stub_mirth.to_timeout
49
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout)
53
+ expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout)
50
54
 
51
55
  stub_mirth.to_raise Errno::ETIMEDOUT
52
- expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout)
56
+ expect { subject.fetch }.to raise_exception(Roqua::Healthy::Timeout)
57
+ end
58
+
59
+ it 'saves the client' do
60
+ expect(subject.client).to eq client
61
+ end
62
+
63
+ describe '#remote_url' do
64
+ let(:fetcher) { Roqua::Healthy::A19::Fetcher.new("123", client) }
65
+ it 'uses the client config if available' do
66
+ expect(client).to receive(:a19_endpoint).and_call_original
67
+ fetcher.send(:remote_url)
68
+ end
53
69
  end
54
70
  end
@@ -1,4 +1,4 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Roqua::Healthy::A19 do
4
- end
4
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roqua::Healthy::Client do
4
+ context 'fully configured client' do
5
+ subject { Roqua::Healthy::Client.new(a19_endpoint: 'http://a19_endpoint.dev') }
6
+
7
+ it { expect(subject.a19_endpoint).to eq 'http://a19_endpoint.dev' }
8
+ end
9
+
10
+ context 'unconfigured client' do
11
+ subject { Roqua::Healthy::Client.new }
12
+
13
+ it 'defaults to system wide config' do
14
+ expect(subject.a19_endpoint).to eq Roqua::Healthy.a19_endpoint
15
+ end
16
+
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roqua-healthy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -190,14 +190,14 @@ dependencies:
190
190
  requirements:
191
191
  - - ~>
192
192
  - !ruby/object:Gem::Version
193
- version: '0.15'
193
+ version: '0.17'
194
194
  type: :development
195
195
  prerelease: false
196
196
  version_requirements: !ruby/object:Gem::Requirement
197
197
  requirements:
198
198
  - - ~>
199
199
  - !ruby/object:Gem::Version
200
- version: '0.15'
200
+ version: '0.17'
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: fuubar
203
203
  requirement: !ruby/object:Gem::Requirement
@@ -259,6 +259,7 @@ files:
259
259
  - lib/roqua/healthy/a19/response_parser.rb
260
260
  - lib/roqua/healthy/a19/response_validator.rb
261
261
  - lib/roqua/healthy/a19/transformer.rb
262
+ - lib/roqua/healthy/client.rb
262
263
  - lib/roqua/healthy/errors.rb
263
264
  - lib/roqua/healthy/message_cleaner.rb
264
265
  - lib/roqua/healthy/version.rb
@@ -298,6 +299,7 @@ files:
298
299
  - spec/unit/a19/correct_patient_check_spec.rb
299
300
  - spec/unit/a19/fetcher_spec.rb
300
301
  - spec/unit/a19_spec.rb
302
+ - spec/unit/client_spec.rb
301
303
  - spec/unit/message_cleaner_spec.rb
302
304
  homepage: https://github.com/roqua/healthy
303
305
  licenses:
@@ -359,5 +361,6 @@ test_files:
359
361
  - spec/unit/a19/correct_patient_check_spec.rb
360
362
  - spec/unit/a19/fetcher_spec.rb
361
363
  - spec/unit/a19_spec.rb
364
+ - spec/unit/client_spec.rb
362
365
  - spec/unit/message_cleaner_spec.rb
363
366
  has_rdoc: