Class: Roqua::Healthy::A19::Fetcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patient_id, client) ⇒ Fetcher

Returns a new instance of Fetcher.



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

def initialize(patient_id, client)
  @patient_id = patient_id
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#patient_idObject (readonly)

Returns the value of attribute patient_id.



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

def patient_id
  @patient_id
end

Instance Method Details

#fetchObject



19
20
21
22
23
24
25
26
# File 'lib/roqua/healthy/a19/fetcher.rb', line 19

def fetch
  response = mirth_response
  parser   = ResponseParser.new(response)

  if ResponseValidator.new(response.code, parser, patient_id).validate
    parser.fetch("HL7Message")
  end
end

#mirth_responseObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/roqua/healthy/a19/fetcher.rb', line 28

def mirth_response
  Net::HTTP.start(remote_url.host, remote_url.port, use_ssl: use_ssl?) do |http|
    request = Net::HTTP::Post.new(remote_url.path)
    request.set_form_data(mirth_params)
    http.request request
  end
rescue ::Timeout::Error, Errno::ETIMEDOUT => error
  raise ::Roqua::Healthy::Timeout, error.message
rescue Errno::EHOSTUNREACH => error
  raise ::Roqua::Healthy::HostUnreachable, error.message
rescue Errno::ECONNREFUSED => error
  raise ::Roqua::Healthy::ConnectionRefused, error.message
end