class Roqua::Healthy::A19::Fetcher

Attributes

client[R]
patient_id[R]

Public Class Methods

new(patient_id, client) click to toggle source
# File lib/roqua/healthy/a19/fetcher.rb, line 14
def initialize(patient_id, client)
  @patient_id = patient_id
  @client = client
end

Public Instance Methods

fetch() click to toggle source
# File lib/roqua/healthy/a19/fetcher.rb, line 19
def fetch
  response = mirth_response
  parser   = ResponseParser.new(response)

  parser.fetch("HL7Message") if ResponseValidator.new(response.code, parser, patient_id).validate
end
mirth_response() click to toggle source
# File lib/roqua/healthy/a19/fetcher.rb, line 26
def mirth_response
  Roqua::Healthy.convert_generic_errors_to_healthy_errors do
    Net::HTTP.start(remote_url.host, remote_url.port, use_ssl: use_ssl?) do |http|
      request = Net::HTTP::Post.new(remote_url.path)
      request.basic_auth(@client.a19_username, @client.a19_password) if @client.use_basic_auth?
      request.set_form_data(mirth_params)
      http.request request
    end
  end
end

Private Instance Methods

mirth_params() click to toggle source
# File lib/roqua/healthy/a19/fetcher.rb, line 39
def mirth_params
  {'method' => 'A19', 'patient_id' => patient_id.to_s, 'application' => "healthy"}
end
remote_url() click to toggle source
# File lib/roqua/healthy/a19/fetcher.rb, line 47
def remote_url
  return @remote_url if @remote_url

  url = Addressable::URI.parse(client.a19_endpoint)
  url.path = "/"

  @remote_url = URI.parse(url.to_s)
end
use_ssl?() click to toggle source
# File lib/roqua/healthy/a19/fetcher.rb, line 43
def use_ssl?
  remote_url.port == 443 || remote_url.scheme == 'https'
end