roqua-healthy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +31 -0
  6. data/.yardopts +1 -0
  7. data/ChangeLog.md +10 -0
  8. data/Gemfile +8 -0
  9. data/Guardfile +11 -0
  10. data/LICENSE.txt +20 -0
  11. data/README.md +31 -0
  12. data/Rakefile +33 -0
  13. data/bin/get +8 -0
  14. data/bin/get_old_mirth_processing_result +6 -0
  15. data/bin/get_xml_for_patient +6 -0
  16. data/bin/parse_local_xml +9 -0
  17. data/healthy.gemspec +42 -0
  18. data/lib/roqua/healthy/a19/address_parser.rb +46 -0
  19. data/lib/roqua/healthy/a19/cdis_name_parser.rb +23 -0
  20. data/lib/roqua/healthy/a19/correct_patient_check.rb +18 -0
  21. data/lib/roqua/healthy/a19/fetcher.rb +61 -0
  22. data/lib/roqua/healthy/a19/name_parser.rb +52 -0
  23. data/lib/roqua/healthy/a19/response_parser.rb +27 -0
  24. data/lib/roqua/healthy/a19/response_validator.rb +45 -0
  25. data/lib/roqua/healthy/a19/transformer.rb +102 -0
  26. data/lib/roqua/healthy/a19.rb +25 -0
  27. data/lib/roqua/healthy/errors.rb +16 -0
  28. data/lib/roqua/healthy/message_cleaner.rb +44 -0
  29. data/lib/roqua/healthy/version.rb +6 -0
  30. data/lib/roqua/healthy.rb +14 -0
  31. data/lib/roqua-healthy.rb +1 -0
  32. data/spec/fixtures/cdis_gerda_geit.xml +181 -0
  33. data/spec/fixtures/cdis_jan_fictief.xml +177 -0
  34. data/spec/fixtures/cdis_piet_fictief.xml +177 -0
  35. data/spec/fixtures/comez_patient.xml +259 -0
  36. data/spec/fixtures/medo_patient.xml +101 -0
  37. data/spec/fixtures/oru-requests/spsy1218j.hl7 +82 -0
  38. data/spec/fixtures/oru-requests/spsy1218o.hl7 +76 -0
  39. data/spec/fixtures/oru-requests/spsy1218o2.hl7 +77 -0
  40. data/spec/fixtures/oru-requests/spsy411o.hl7 +73 -0
  41. data/spec/fixtures/oru-requests/spsy411o2.hl7 +71 -0
  42. data/spec/fixtures/oru-requests/spsyl.hl7 +71 -0
  43. data/spec/fixtures/oru-responses/xmcare_nack.hl7 +5 -0
  44. data/spec/fixtures/user_patient.xml +251 -0
  45. data/spec/fixtures/user_patient_with_gsm_and_email.xml +281 -0
  46. data/spec/fixtures/user_patient_with_maiden_name.xml +251 -0
  47. data/spec/fixtures/xmcare_impersonating_cdis.xml +245 -0
  48. data/spec/fixtures/xmcare_patient.xml +252 -0
  49. data/spec/fixtures/xmcare_patient_email_in_field_number_four.xml +245 -0
  50. data/spec/fixtures/xmcare_patient_not_found.xml +93 -0
  51. data/spec/fixtures/xmcare_patient_with_maiden_name.xml +252 -0
  52. data/spec/fixtures/xmcare_patient_without_birthdate.xml +250 -0
  53. data/spec/fixtures/xmcare_timeout_waiting_for_ack.xml +4 -0
  54. data/spec/healthy_spec.rb +7 -0
  55. data/spec/integration/cdis_spec.rb +72 -0
  56. data/spec/integration/comez_spec.rb +26 -0
  57. data/spec/integration/medo_spec.rb +26 -0
  58. data/spec/integration/mirth_spec.rb +17 -0
  59. data/spec/integration/user_spec.rb +72 -0
  60. data/spec/integration/xmcare_spec.rb +127 -0
  61. data/spec/spec_helper.rb +29 -0
  62. data/spec/support/fixtures.rb +14 -0
  63. data/spec/unit/a19/address_parser_spec.rb +132 -0
  64. data/spec/unit/a19/correct_patient_check_spec.rb +22 -0
  65. data/spec/unit/a19/fetcher_spec.rb +54 -0
  66. data/spec/unit/a19_spec.rb +4 -0
  67. data/spec/unit/message_cleaner_spec.rb +47 -0
  68. metadata +361 -0
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fetching A19 from USER' do
4
+ describe 'a patient' do
5
+ before { load_fixture 'user_patient', '00000123' }
6
+ subject { Roqua::Healthy::A19.fetch("00000123") }
7
+
8
+ it { expect(subject[:status]).to eq('SUCCESS') }
9
+ it { expect(subject[:error]).to be_nil }
10
+ it { expect(subject[:source]).to eq('IMPULSE') }
11
+ it { expect(subject[:identities]).to eq([{ident: '000123', authority: 'PI'}]) }
12
+ it { expect(subject[:firstname]).to eq('Alice') }
13
+ it { expect(subject[:initials]).to eq('A.B.') }
14
+ it { expect(subject[:lastname]).to eq('Achternaam') }
15
+ it { expect(subject[:display_name]).to be_nil }
16
+ it { expect(subject[:email]).to be_nil }
17
+ it { expect(subject[:address_type]).to eq('L') }
18
+ it { expect(subject[:street]).to eq('Straatnaam 37') }
19
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
20
+ it { expect(subject[:zipcode]).to eq('1234 AB') }
21
+ it { expect(subject[:country]).to eq('6030') }
22
+ it { expect(subject[:birthdate]).to eq('17070415') }
23
+ it { expect(subject[:gender]).to eq('M') }
24
+ it { expect(subject[:phone_cell]).to be_nil }
25
+ end
26
+
27
+ describe 'a patient' do
28
+ before { load_fixture 'user_patient_with_maiden_name', '00000123' }
29
+ subject { Roqua::Healthy::A19.fetch("00000123") }
30
+
31
+ it { expect(subject[:status]).to eq('SUCCESS') }
32
+ it { expect(subject[:error]).to be_nil }
33
+ it { expect(subject[:source]).to eq('IMPULSE') }
34
+ it { expect(subject[:identities]).to eq([{ident: '00000123', authority: 'PI'}]) }
35
+ it { expect(subject[:firstname]).to eq('Babette') }
36
+ it { expect(subject[:initials]).to eq('A.B.C.') }
37
+ it { expect(subject[:lastname]).to eq('Achternaam') }
38
+ it { expect(subject[:display_name]).to be_nil }
39
+ it { expect(subject[:email]).to be_nil }
40
+ it { expect(subject[:address_type]).to eq('L') }
41
+ it { expect(subject[:street]).to eq('Straatnaam 37') }
42
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
43
+ it { expect(subject[:zipcode]).to eq('1234 AB') }
44
+ it { expect(subject[:country]).to eq('6030') }
45
+ it { expect(subject[:birthdate]).to eq('17070415') }
46
+ it { expect(subject[:gender]).to eq('F') }
47
+ it { expect(subject[:phone_cell]).to be_nil }
48
+ end
49
+
50
+ describe 'a patient with gsm number and email address' do
51
+ before { load_fixture 'user_patient_with_gsm_and_email', '00000033' }
52
+ subject { Roqua::Healthy::A19.fetch("00000033") }
53
+
54
+ it { expect(subject[:status]).to eq('SUCCESS') }
55
+ it { expect(subject[:error]).to be_nil }
56
+ it { expect(subject[:source]).to eq('IMPULSE') }
57
+ it { expect(subject[:identities]).to eq([{ident: '00000033', authority: 'PI'}]) }
58
+ it { expect(subject[:firstname]).to eq('Albert') }
59
+ it { expect(subject[:initials]).to eq('A.') }
60
+ it { expect(subject[:lastname]).to eq("Pati\u00EBnt") }
61
+ it { expect(subject[:display_name]).to be_nil }
62
+ it { expect(subject[:email]).to eq('apatient@info.nl') }
63
+ it { expect(subject[:address_type]).to eq('L') }
64
+ it { expect(subject[:street]).to eq('Straatnaam 37') }
65
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
66
+ it { expect(subject[:zipcode]).to eq('1234 AB') }
67
+ it { expect(subject[:country]).to eq('6030') }
68
+ it { expect(subject[:birthdate]).to eq('17070415') }
69
+ it { expect(subject[:gender]).to eq('M') }
70
+ it { expect(subject[:phone_cell]).to be_nil }
71
+ end
72
+ end
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Fetching A19 from XMcare' do
4
+ describe 'a patient' do
5
+ before { load_fixture 'xmcare_patient', '12345678901' }
6
+ subject { Roqua::Healthy::A19.fetch("12345678901") }
7
+
8
+ it { expect(subject[:status]).to eq('SUCCESS') }
9
+ it { expect(subject[:error]).to be_nil }
10
+ it { expect(subject[:source]).to eq('ZIS') }
11
+ it { expect(subject[:identities]).to eq([{ident: '12345678901', authority: 'PI'}, {ident: '123456789', authority: 'NNNLD'}]) }
12
+ it { expect(subject[:firstname]).to eq('Babette') }
13
+ it { expect(subject[:initials]).to eq('A B') }
14
+ it { expect(subject[:lastname]).to eq('Achternaam') }
15
+ it { expect(subject[:display_name]).to eq('Achternaam') }
16
+ it { expect(subject[:email]).to eq('') }
17
+ it { expect(subject[:address_type]).to eq('H') }
18
+ it { expect(subject[:street]).to eq('Straatnaam 37') }
19
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
20
+ it { expect(subject[:zipcode]).to eq('1234AB') }
21
+ it { expect(subject[:country]).to eq('NL') }
22
+ it { expect(subject[:birthdate]).to eq('17070415') }
23
+ it { expect(subject[:gender]).to eq('F') }
24
+ it { expect(subject[:phone_cell]).to eq('06-12345678') }
25
+ end
26
+
27
+ describe 'a patient with a maiden name' do
28
+ before { load_fixture 'xmcare_patient_with_maiden_name', '12345678901' }
29
+ subject { Roqua::Healthy::A19.fetch("12345678901") }
30
+
31
+ it { expect(subject[:status]).to eq('SUCCESS') }
32
+ it { expect(subject[:error]).to be_nil }
33
+ it { expect(subject[:source]).to eq('ZIS') }
34
+ it { expect(subject[:identities]).to eq([{ident: '12345678901', authority: 'PI'}, {ident: '123456789', authority: 'NNNLD'}]) }
35
+ it { expect(subject[:firstname]).to eq('Babette') }
36
+ it { expect(subject[:initials]).to eq('A B') }
37
+ it { expect(subject[:lastname]).to eq('Achternaam') }
38
+ it { expect(subject[:display_name]).to eq('Meisjesnaam - Achternaam') }
39
+ it { expect(subject[:email]).to eq('email@example.com') }
40
+ it { expect(subject[:address_type]).to eq('H') }
41
+ it { expect(subject[:street]).to eq('Straatnaam 37') }
42
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
43
+ it { expect(subject[:zipcode]).to eq('1234AB') }
44
+ it { expect(subject[:country]).to eq('NL') }
45
+ it { expect(subject[:birthdate]).to eq('17070415') }
46
+ it { expect(subject[:gender]).to eq('F') }
47
+ it { expect(subject[:phone_cell]).to eq('06-12345678') }
48
+ end
49
+
50
+ describe 'a patient without a known birthdate' do
51
+ before { load_fixture 'xmcare_patient_without_birthdate', '12345678901' }
52
+ subject { Roqua::Healthy::A19.fetch("12345678901") }
53
+
54
+ it { expect(subject[:status]).to eq('SUCCESS') }
55
+ it { expect(subject[:error]).to be_nil }
56
+ it { expect(subject[:source]).to eq('ZIS') }
57
+ it { expect(subject[:identities]).to eq([{ident: '12345678901', authority: 'PI'}, {ident: '123456789', authority: 'NNNLD'}]) }
58
+ it { expect(subject[:firstname]).to eq('Babette') }
59
+ it { expect(subject[:initials]).to eq('A B') }
60
+ it { expect(subject[:lastname]).to eq('Achternaam') }
61
+ it { expect(subject[:display_name]).to eq('Achternaam') }
62
+ it { expect(subject[:email]).to eq('') }
63
+ it { expect(subject[:address_type]).to eq('H') }
64
+ it { expect(subject[:street]).to eq('Straatnaam 37') }
65
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
66
+ it { expect(subject[:zipcode]).to eq('1234AB') }
67
+ it { expect(subject[:country]).to eq('NL') }
68
+ it { expect(subject[:birthdate]).to be_nil }
69
+ it { expect(subject[:gender]).to eq('F') }
70
+ it { expect(subject[:phone_cell]).to eq('06-12345678') }
71
+ end
72
+
73
+ describe 'a patient with an email in an alternate place' do
74
+ before { load_fixture 'xmcare_patient_email_in_field_number_four', '12345678901' }
75
+ subject { Roqua::Healthy::A19.fetch("12345678901") }
76
+
77
+ it { expect(subject[:status]).to eq('SUCCESS') }
78
+ it { expect(subject[:error]).to be_nil }
79
+ it { expect(subject[:source]).to eq('ZIS') }
80
+ it { expect(subject[:identities]).to eq([{ident: '12345678901', authority: 'PI'}, {ident: '123456789', authority: 'NNNLD'}]) }
81
+ it { expect(subject[:firstname]).to eq('Babette') }
82
+ it { expect(subject[:initials]).to eq('A B') }
83
+ it { expect(subject[:lastname]).to eq('Achternaam') }
84
+ it { expect(subject[:display_name]).to eq('Achternaam') }
85
+ it { expect(subject[:email]).to eq('email@example.com') }
86
+ it { expect(subject[:address_type]).to eq('H') }
87
+ it { expect(subject[:street]).to eq('Straatnaam 37') }
88
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
89
+ it { expect(subject[:zipcode]).to eq('1234AB') }
90
+ it { expect(subject[:country]).to eq('NL') }
91
+ it { expect(subject[:birthdate]).to eq('17070415') }
92
+ it { expect(subject[:gender]).to eq('F') }
93
+ it { expect(subject[:phone_cell]).to eq('06 12 34 56 78') }
94
+
95
+ end
96
+
97
+ describe 'a patient from an xmcare instance impersonating cdis' do
98
+ before { load_fixture 'xmcare_impersonating_cdis', '12345678901' }
99
+ subject { Roqua::Healthy::A19.fetch("12345678901") }
100
+
101
+ it { expect(subject[:status]).to eq('SUCCESS') }
102
+ it { expect(subject[:error]).to be_nil }
103
+ it { expect(subject[:source]).to eq('UMCG') }
104
+ it { expect(subject[:identities]).to eq([{ident: '12345678901', authority: 'PI'}, {ident: '123456789', authority: 'NNNLD'}]) }
105
+ it { expect(subject[:firstname]).to eq('A') }
106
+ it { expect(subject[:initials]).to eq('B C') }
107
+ it { expect(subject[:lastname]).to eq('Achternaam') }
108
+ it { expect(subject[:display_name]).to eq('Achternaam') }
109
+ it { expect(subject[:email]).to eq('') }
110
+ it { expect(subject[:address_type]).to eq('H') }
111
+ it { expect(subject[:street]).to eq('Straatnaam 37 h-42') }
112
+ it { expect(subject[:city]).to eq('PLAATSNAAM') }
113
+ it { expect(subject[:zipcode]).to eq('1234AB') }
114
+ it { expect(subject[:country]).to eq('NLD') }
115
+ it { expect(subject[:birthdate]).to eq('17070415') }
116
+ it { expect(subject[:gender]).to eq('M') }
117
+ it { expect(subject[:phone_cell]).to eq('06-12345678') }
118
+ end
119
+
120
+ describe 'a patient that does not exist' do
121
+ before { load_fixture 'xmcare_patient_not_found', '12345678901' }
122
+
123
+ it 'raises PatientNotFound' do
124
+ expect { Roqua::Healthy::A19.fetch("12345678901") }.to raise_error(Roqua::Healthy::PatientNotFound)
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,29 @@
1
+ require 'rspec'
2
+
3
+ require 'webmock/rspec'
4
+ WebMock.disable_net_connect! allow: "codeclimate.com"
5
+
6
+ if ENV["CODECLIMATE_REPO_TOKEN"]
7
+ require "codeclimate-test-reporter"
8
+ CodeClimate::TestReporter.start
9
+ end
10
+
11
+ # Requires supporting ruby files with custom matchers and macros, etc,
12
+ # in spec/support/ and its subdirectories.
13
+ Dir["spec/support/**/*.rb"].each { |filename| load filename }
14
+
15
+ require 'roqua/healthy'
16
+ Roqua::Healthy.a19_endpoint = "http://10.220.0.101:60101"
17
+
18
+ require 'stringio'
19
+ LOG_FILE = StringIO.new
20
+ Roqua.logger = Logger.new(LOG_FILE)
21
+
22
+ RSpec.configure do |config|
23
+ config.after(:suite) do
24
+ if ENV["DEBUG"]
25
+ LOG_FILE.rewind
26
+ puts "", "Log file: ", LOG_FILE.read
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ def stub_mirth(patient_id = '123')
2
+ stub_request(:post, Roqua::Healthy.a19_endpoint)
3
+ .with(body: {application: 'healthy', method: 'A19', patient_id: patient_id})
4
+ end
5
+
6
+ def stub_mirth_response(response, status = 200, patient_id = '123')
7
+ stub_mirth(patient_id).to_return(status: status, headers: {}, body: response)
8
+ end
9
+
10
+ def load_fixture(name, patient_id = '123')
11
+ fixture_filename = File.expand_path(File.join(__FILE__, "../../fixtures", "#{name}.xml"))
12
+ response = File.read(fixture_filename)
13
+ stub_mirth_response(response, 200, patient_id)
14
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roqua::Healthy::A19::AddressParser do
4
+ def msg(*types)
5
+ addresses = []
6
+ addresses << {'PID.11.7' => 'M',
7
+ 'PID.11.1' => {'PID.11.1.1' => 'Mailstreet 1'},
8
+ 'PID.11.3' => 'Mailcity',
9
+ 'PID.11.5' => 'Mailzipcode',
10
+ 'PID.11.6' => 'Mailcountry'
11
+ } if types.include?('M')
12
+ addresses << {'PID.11.7' => 'H',
13
+ 'PID.11.1' => {'PID.11.1.1' => 'Homestreet 1'},
14
+ 'PID.11.3' => 'Homecity',
15
+ 'PID.11.5' => 'Homezipcode',
16
+ 'PID.11.6' => 'Homecountry'
17
+ } if types.include?('H')
18
+ addresses << {'PID.11.7' => '?',
19
+ 'PID.11.1' => {'PID.11.1.1' => '????street 1'},
20
+ 'PID.11.3' => '????city',
21
+ 'PID.11.5' => '????zipcode',
22
+ 'PID.11.6' => '????country'
23
+ } if types.include?('?')
24
+ {'PID' => {'PID.11' => addresses}}
25
+ end
26
+
27
+ describe '#address_type' do
28
+ it 'returns M if mail address is present' do
29
+ message = msg('M', 'H', '?')
30
+ parser = described_class.new(message)
31
+ expect(parser.address_type).to eq("M")
32
+ end
33
+
34
+ it 'returns H if home address is present' do
35
+ message = msg('H', '?')
36
+ parser = described_class.new(message)
37
+ expect(parser.address_type).to eq("H")
38
+ end
39
+
40
+ it 'returns nil if no known address types are present' do
41
+ message = msg('?')
42
+ parser = described_class.new(message)
43
+ expect(parser.address_type).to be_nil
44
+ end
45
+
46
+ it 'returns nil if no addresses are present' do
47
+ message = msg('?')
48
+ parser = described_class.new(message)
49
+ expect(parser.address_type).to be_nil
50
+ end
51
+ end
52
+
53
+ describe '#street' do
54
+ it 'returns mail street' do
55
+ message = msg('M', 'H', '?')
56
+ parser = described_class.new(message)
57
+ expect(parser.street).to eq("Mailstreet 1")
58
+ end
59
+
60
+ it 'returns home street' do
61
+ message = msg('H', '?')
62
+ parser = described_class.new(message)
63
+ expect(parser.street).to eq("Homestreet 1")
64
+ end
65
+
66
+ it 'returns nil otherwise' do
67
+ message = msg('?')
68
+ parser = described_class.new(message)
69
+ expect(parser.street).to be_nil
70
+ end
71
+ end
72
+
73
+ describe '#city' do
74
+ it 'returns mail city' do
75
+ message = msg('M', 'H', '?')
76
+ parser = described_class.new(message)
77
+ expect(parser.city).to eq("Mailcity")
78
+ end
79
+
80
+ it 'returns home city' do
81
+ message = msg('H', '?')
82
+ parser = described_class.new(message)
83
+ expect(parser.city).to eq("Homecity")
84
+ end
85
+
86
+ it 'returns nil otherwise' do
87
+ message = msg('?')
88
+ parser = described_class.new(message)
89
+ expect(parser.city).to be_nil
90
+ end
91
+ end
92
+
93
+ describe '#zipcode' do
94
+ it 'returns mail zipcode' do
95
+ message = msg('M', 'H', '?')
96
+ parser = described_class.new(message)
97
+ expect(parser.zipcode).to eq("Mailzipcode")
98
+ end
99
+
100
+ it 'returns home zipcode' do
101
+ message = msg('H', '?')
102
+ parser = described_class.new(message)
103
+ expect(parser.zipcode).to eq("Homezipcode")
104
+ end
105
+
106
+ it 'returns nil otherwise' do
107
+ message = msg('?')
108
+ parser = described_class.new(message)
109
+ expect(parser.zipcode).to be_nil
110
+ end
111
+ end
112
+
113
+ describe '#country' do
114
+ it 'returns mail country' do
115
+ message = msg('M', 'H', '?')
116
+ parser = described_class.new(message)
117
+ expect(parser.country).to eq("Mailcountry")
118
+ end
119
+
120
+ it 'returns home country' do
121
+ message = msg('H', '?')
122
+ parser = described_class.new(message)
123
+ expect(parser.country).to eq("Homecountry")
124
+ end
125
+
126
+ it 'returns nil otherwise' do
127
+ message = msg('?')
128
+ parser = described_class.new(message)
129
+ expect(parser.country).to be_nil
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module Roqua
4
+ module Healthy
5
+ module A19
6
+ describe CorrectPatientCheck do
7
+ let(:id) { "12345678" }
8
+ let(:record) { {identities: [{ident: '12345678'}]} }
9
+
10
+ it 'returns true if record is for correct patient id' do
11
+ checker = CorrectPatientCheck.new(id, record)
12
+ expect(checker.check).to be_truthy
13
+ end
14
+
15
+ it 'returns false if record is for different patient id' do
16
+ checker = CorrectPatientCheck.new('999', record)
17
+ expect(checker.check).to be_falsey
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roqua::Healthy::A19::Fetcher do
4
+ it 'succeeds when upstream returns XML' do
5
+ stub_mirth_response("<HL7Message></HL7Message>")
6
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.not_to raise_error
7
+ end
8
+
9
+ it "raises when upstream does not return HTTP 200" do
10
+ stub_mirth_response "Request not successful", 500
11
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception
12
+ end
13
+
14
+ it 'raises when upstream responds with illegal XML' do
15
+ stub_mirth_response "<patient><firstname>Jan & Piet</firstname></patient>"
16
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse)
17
+
18
+ stub_mirth_response "<patient><firstname>Jan</patient>"
19
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse)
20
+ end
21
+
22
+ it "raises upstream is returning 'Timeout waiting for ACK' messages" do
23
+ 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)
25
+ end
26
+
27
+ it "raises upstream is returning 'connection timeout' messages" do
28
+ 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)
30
+ end
31
+
32
+ it "raises upstream is returning 'connection refuesed' messages" do
33
+ 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)
35
+ end
36
+
37
+ it "raises when upstream does not accept connections" do
38
+ stub_mirth.to_raise Errno::ECONNREFUSED
39
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused)
40
+ end
41
+
42
+ it 'raises when upstream is unreachable' do
43
+ stub_mirth.to_raise Errno::EHOSTUNREACH
44
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::HostUnreachable)
45
+ end
46
+
47
+ it "raises when upstream is timing out" do
48
+ stub_mirth.to_timeout
49
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout)
50
+
51
+ stub_mirth.to_raise Errno::ETIMEDOUT
52
+ expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout)
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roqua::Healthy::A19 do
4
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roqua::Healthy::MessageCleaner do
4
+ let(:message) { {key: ""} }
5
+
6
+ describe '#message' do
7
+ it 'leaves clean messages untouched' do
8
+ message = {key: 'value', other_key: double}
9
+ cleaned = Roqua::Healthy::MessageCleaner.new(message).message
10
+ expect(cleaned).to eq(message)
11
+ end
12
+
13
+ it 'cleans strings that contain only a pair of double quotes' do
14
+ message = {key: '""'}
15
+ cleaned = Roqua::Healthy::MessageCleaner.new(message).message
16
+ expect(cleaned).to eq(key: '')
17
+ end
18
+
19
+ it 'cleans strings in subhashes' do
20
+ message = {key: {subkey: '""'}}
21
+ cleaned = Roqua::Healthy::MessageCleaner.new(message).message
22
+ expect(cleaned).to eq(key: {subkey: ''})
23
+ end
24
+
25
+ it 'cleans strings in arrays' do
26
+ message = {key: [{subkey: '""'}, {subkey: 'foo'}]}
27
+ cleaned = Roqua::Healthy::MessageCleaner.new(message).message
28
+ expect(cleaned).to eq(key: [{subkey: ''}, {subkey: 'foo'}])
29
+ end
30
+ end
31
+
32
+ describe '#clean_string' do
33
+ let(:cleaner) { Roqua::Healthy::MessageCleaner.new("") }
34
+
35
+ it 'does not change clean strings' do
36
+ expect(cleaner.clean_string("a string")).to eq("a string")
37
+ end
38
+
39
+ it 'strips whitespace' do
40
+ expect(cleaner.clean_string(" a string ")).to eq("a string")
41
+ end
42
+
43
+ it 'sanitizes strings that are only a pair of double quotes' do
44
+ expect(cleaner.clean_string('""')).to eq('')
45
+ end
46
+ end
47
+ end