Class: LIS::HTTPInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/lis/http_interface.rb

Defined Under Namespace

Classes: HTTP

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ HTTPInterface

Returns a new instance of HTTPInterface



13
14
15
# File 'lib/lis/http_interface.rb', line 13

def initialize(endpoint)
  @endpoint = endpoint
end

Instance Method Details

#load_requests(device_name, barcode) ⇒ Object

expects all pending requests for the given device and barcode

{ "id" => "1234",
  "patient" => { "id" => 98,
                 "last_name" => "Sierra",
                 "first_name" => "Rudolph" },
  "types" => [ "TSH", "FT3", "FT4" ] }


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lis/http_interface.rb', line 25

def load_requests(device_name, barcode)
  begin
    result = HTTP.get(uri(device_name, barcode))
    data = LIS::Data::Request.from_yaml(result.body, barcode)
  rescue Exception => e
    puts e
    puts e.backtrace
    data = nil
  end

  data
end

#send_result(device_name, order, result) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lis/http_interface.rb', line 44

def send_result(device_name, order, result)
  barcode = order.specimen_id

  data = {
    "test_name" => order.universal_test_id,
    "value" => result.result_value,
    "unit" => result.unit,
    "status" => result.result_status,
    "flags" => result.abnormal_flags,
    "result_timestamp" => result.test_completed_at,
    "raw" => result.raw_data
  }

  HTTP.post(uri(device_name, barcode, order.universal_test_id), :body => data.to_json)
end

#set_request_status(device_name, data) ⇒ Object



39
40
41
42
# File 'lib/lis/http_interface.rb', line 39

def set_request_status(device_name, data)
  # uri = URI.join(@endpoint, "result_status/#{[device_name, data.id].join('-')}")
  # Net::HTTP.post_form(uri, data.to_hash)
end