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.



14
15
16
17
18
# File 'lib/roqua/healthy/a19/response_validator.rb', line 14

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.



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

def parser
  @parser
end

#patient_idObject (readonly)

Returns the value of attribute patient_id.



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

def patient_id
  @patient_id
end

#response_codeObject (readonly)

Returns the value of attribute response_code.



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

def response_code
  @response_code
end

Instance Method Details

#validateObject



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

def validate
  case response_code
  when '200'
    validate_200
  when '401', '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



35
36
37
38
39
40
# File 'lib/roqua/healthy/a19/response_validator.rb', line 35

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

#validate_403Object



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

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

#validate_404Object



46
47
48
# File 'lib/roqua/healthy/a19/response_validator.rb', line 46

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

#validate_500Object

Raises:



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

def validate_500
  error = parser.fetch('failure')['error']
  raise ::Roqua::Healthy::ERRORS[error], error if ::Roqua::Healthy::ERRORS[error]
  raise ::Roqua::Healthy::UnknownFailure, error
end