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.



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

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#patient_idObject (readonly)

Returns the value of attribute patient_id.



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

def patient_id
  @patient_id
end

Instance Method Details

#fetchObject



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

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

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

#mirth_responseObject



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

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