class Roqua::Healthy::A19::ResponseValidator

Attributes

parser[R]
patient_id[R]
response_code[R]

Public Class Methods

new(response_code, parser, patient_id) click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 12
def initialize(response_code, parser, patient_id)
  @response_code = response_code
  @parser        = parser
  @patient_id    = patient_id
end

Public Instance Methods

validate() click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 18
def validate
  case response_code
  when '200'
    validate200
  when '401', '403'
    validate403
  when '404'
    validate404
  when '500'
    validate500
  else
    raise ::Roqua::Healthy::UnknownFailure, "Unexpected HTTP response code #{response_code}."
  end
end

Private Instance Methods

ensure_correct_patient(parsed_message) click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 61
def ensure_correct_patient(parsed_message)
  raise ::Roqua::Healthy::MirthErrors::WrongPatient if parsed_message.key?('QRD') && parsed_message.fetch("QRD").fetch("QRD.8").fetch("QRD.8.1") != patient_id
end
ensure_patient_found(parsed_message) click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 56
def ensure_patient_found(parsed_message)
  raise ::Roqua::Healthy::PatientNotFound if parsed_message.key?("ERR") && parsed_message.fetch("ERR").fetch("ERR.1").fetch("ERR.1.4").fetch("ERR.1.4.2") =~ /Patient \(@\) niet gevonden\(.*\)/
  raise ::Roqua::Healthy::PatientNotFound if parsed_message.key?("QAK") && parsed_message.fetch("QAK").fetch("QAK.2").fetch("QAK.2.1") == "NF"
end
validate200() click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 35
def validate200
  parsed_message = parser.fetch("HL7Message")
  ensure_patient_found(parsed_message)
  ensure_correct_patient(parsed_message)
  true
end
validate403() click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 42
def validate403
  raise ::Roqua::Healthy::AuthenticationFailure
end
validate404() click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 46
def validate404
  raise ::Roqua::Healthy::PatientNotFound
end
validate500() click to toggle source
# File lib/roqua/healthy/a19/response_validator.rb, line 50
def validate500
  error = parser.fetch('failure')['error']
  raise ::Roqua::Healthy::ERRORS[error], error if ::Roqua::Healthy::ERRORS[error]
  raise ::Roqua::Healthy::UnknownFailure, error
end