Class: Roqua::Healthy::A19::ResponseValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/roqua/healthy/a19/response_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_code, parser, patient_id) ⇒ ResponseValidator

Returns a new instance of ResponseValidator.



11
12
13
14
15
# File 'lib/roqua/healthy/a19/response_validator.rb', line 11

def initialize(response_code, parser, patient_id)
  @response_code = response_code
  @parser        = parser
  @patient_id    = patient_id
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



8
9
10
# File 'lib/roqua/healthy/a19/response_validator.rb', line 8

def parser
  @parser
end

#patient_idObject (readonly)

Returns the value of attribute patient_id.



9
10
11
# File 'lib/roqua/healthy/a19/response_validator.rb', line 9

def patient_id
  @patient_id
end

#response_codeObject (readonly)

Returns the value of attribute response_code.



7
8
9
# File 'lib/roqua/healthy/a19/response_validator.rb', line 7

def response_code
  @response_code
end

Instance Method Details

#validateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roqua/healthy/a19/response_validator.rb', line 17

def validate
  case response_code
  when '200'
    validate_200
  when '403'
    validate_403
  when '404'
    validate_404
  when '500'
    validate_500
  else
    raise ::Roqua::Healthy::UnknownFailure, "Unexpected HTTP response code #{response_code}."
  end
end

#validate_200Object



32
33
34
35
36
37
# File 'lib/roqua/healthy/a19/response_validator.rb', line 32

def validate_200
  parsed_message = parser.fetch("HL7Message")
  ensure_patient_found(parsed_message)
  ensure_correct_patient(parsed_message)
  true
end

#validate_403Object



39
40
41
# File 'lib/roqua/healthy/a19/response_validator.rb', line 39

def validate_403
  raise ::Roqua::Healthy::AuthenticationFailure
end

#validate_404Object



43
44
45
# File 'lib/roqua/healthy/a19/response_validator.rb', line 43

def validate_404
  raise ::Roqua::Healthy::PatientNotFound
end

#validate_500Object



47
48
49
50
51
52
53
# File 'lib/roqua/healthy/a19/response_validator.rb', line 47

def validate_500
  failure = parser.fetch("failure")
  raise ::Roqua::Healthy::Timeout, failure["error"]           if failure["error"] == "Timeout waiting for ACK"
  raise ::Roqua::Healthy::Timeout, failure["error"]           if failure["error"] == "Unable to connect to destination\tSocketTimeoutException\tconnect timed out"
  raise ::Roqua::Healthy::ConnectionRefused, failure["error"] if failure["error"] == "Unable to connect to destination\tConnectException\tConnection refused"
  raise ::Roqua::Healthy::UnknownFailure, failure["error"]
end