Sha256: 3c7a2cff622f0ae81f3b37fc5c926a496373cfbae928c0591e6d57588a18b2f4

Contents?: true

Size: 1.72 KB

Versions: 7

Compression:

Stored size: 1.72 KB

Contents

require 'roqua/healthy/a19/response_parser'

module Roqua
  module Healthy
    module A19
      class ResponseValidator
        attr_reader :response_code
        attr_reader :parser
        attr_reader :patient_id

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

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

        def validate_200
          failure = parser.fetch("HL7Message")
          raise ::Roqua::Healthy::PatientNotFound if failure.key?("ERR") && failure.fetch("ERR").fetch("ERR.1").fetch("ERR.1.4").fetch("ERR.1.4.2") =~ /Patient \(@\) niet gevonden\(.*\)/
          raise ::Roqua::Healthy::MirthErrors::WrongPatient if failure.key?('QRD') && failure.fetch("QRD").fetch("QRD.8").fetch("QRD.8.1") != patient_id
          true
        end

        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
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
roqua-healthy-1.1.3 lib/roqua/healthy/a19/response_validator.rb
roqua-healthy-1.1.2 lib/roqua/healthy/a19/response_validator.rb
roqua-healthy-1.1.1 lib/roqua/healthy/a19/response_validator.rb
roqua-healthy-1.1.0 lib/roqua/healthy/a19/response_validator.rb
roqua-healthy-1.0.2 lib/roqua/healthy/a19/response_validator.rb
roqua-healthy-1.0.1 lib/roqua/healthy/a19/response_validator.rb
roqua-healthy-1.0.0 lib/roqua/healthy/a19/response_validator.rb