class Crucible::Tests::ConnectathonLabOrderTrackTest

Public Class Methods

new(client1, client2=nil) click to toggle source
Calls superclass method Crucible::Tests::BaseTest::new
# File lib/tests/suites/connectathon_lab_order_track.rb, line 13
def initialize(client1, client2=nil)
  super(client1, client2)
  # @tags.append('connectathon')
  @category = {id: 'connectathon', title: 'Connectathon'}
end

Public Instance Methods

description() click to toggle source
# File lib/tests/suites/connectathon_lab_order_track.rb, line 9
def description
  'Connectathon Lab Order Track focuses on DiagnosticRequest, Order, Observation and Specimen.'
end
id() click to toggle source
# File lib/tests/suites/connectathon_lab_order_track.rb, line 5
def id
  'ConnectathonLabOrderTrackTest'
end
setup() click to toggle source
# File lib/tests/suites/connectathon_lab_order_track.rb, line 19
def setup
  @resources = Crucible::Generator::Resources.new

  @records = {}

  patient = @resources.load_fixture('patient/patient-uslab-example1.xml')
  provider = @resources.load_fixture('practitioner/pract-uslab-example1.xml')
  performer = @resources.load_fixture('practitioner/pract-uslab-example3.xml')
  organization = @resources.load_fixture('organization/org-uslab-example3.xml')

  specimen_100 = @resources.load_fixture('specimen/spec-100.xml')
  specimen_400 = @resources.load_fixture('specimen/spec-400.xml')
  specimen_uslab = @resources.load_fixture('specimen/spec-400.xml')

  # Create our reference patient
  create_object(patient, :patient)

  # Create our reference provider (Order Orderer)
  create_object(provider, :provider)

  # Create our reference performer (Order performer)
  create_object(performer, :performer)

  # Create the Organization all of these belong to
  create_object(organization, :organization)

  specimen_100.subject = @records[:patient].to_reference
  create_object(specimen_100, :spec_100)

  specimen_400.subject = @records[:patient].to_reference
  create_object(specimen_400, :spec_400)

  specimen_uslab.subject = @records[:patient].to_reference
  create_object(specimen_uslab, :spec_uslab)
end
teardown() click to toggle source
# File lib/tests/suites/connectathon_lab_order_track.rb, line 55
def teardown
  resourceType = ['DiagnosticReport','DiagnosticRequest','Observation','Specimen','Practitioner','Patient','Organization']
  resourceType.each do |type|
    @records.each_value do |value|
      @client.destroy(value.class, value.id) if value.resourceType==type
    end
  end
end

Private Instance Methods

create_diagnostic_report(specimen_name, observation_fixture_paths, diagnostic_report_fixture_path, dr_name, diag_order) click to toggle source
create_object(order_response, response_name)

end

# File lib/tests/suites/connectathon_lab_order_track.rb, line 201
def create_diagnostic_report(specimen_name, observation_fixture_paths, diagnostic_report_fixture_path, dr_name, diag_order)
  diag_report = @resources.load_fixture(diagnostic_report_fixture_path)
  diag_report.subject = @records[:patient].to_reference
  diag_report.issued = DateTime.now.iso8601
  diag_report.effectiveDateTime = DateTime.now.iso8601
  diag_report.performer = @records[:performer].to_reference
  diag_report.request = [diag_order.to_reference]
  diag_report.specimen = [@records[specimen_name].to_reference]
  diag_report.result = []

  observation_fixture_paths.each_with_index do |obs, index|
    observation = @resources.load_fixture(obs)
    observation.specimen = @records[specimen_name].to_reference
    observation.subject = @records[:patient].to_reference
    observation.performer = @records[:performer].to_reference
    observation_name = "#{dr_name}_observation_#{index}".to_sym
    create_object(observation, observation_name)
    diag_report.result << @records[observation_name].to_reference
  end

  create_object(diag_report, dr_name)
end
create_diagnostic_request(fixture_path, order_name, specimen_name = nil) click to toggle source
create_object(order, order_name)

end

# File lib/tests/suites/connectathon_lab_order_track.rb, line 182
def create_diagnostic_request(fixture_path, order_name, specimen_name = nil)
  diag_order = @resources.load_fixture(fixture_path)
  diag_order.subject = @records[:patient].to_reference
  diag_order.requester = @records[:provider].to_reference
  diag_order.supportingInformation = [@records[specimen_name].to_reference] if specimen_name

  create_object(diag_order, order_name)
end
create_object(obj, obj_sym) click to toggle source
# File lib/tests/suites/connectathon_lab_order_track.rb, line 254
def create_object(obj, obj_sym)
  obj.id = nil
  reply = @client.create obj
  assert_response_ok(reply)
  obj.id = reply.id
  @records[obj_sym] = obj

  warning { assert_valid_resource_content_type_present(reply) }
  warning { assert_valid_content_location_present(reply) }
end
get_diagnostic_report(dr_name) click to toggle source
# File lib/tests/suites/connectathon_lab_order_track.rb, line 224
def get_diagnostic_report(dr_name)

  assert @records[dr_name], "No DiagnosticReport with that name present"
  reply = @client.read FHIR::DiagnosticReport, @records[dr_name].id
  assert_response_ok(reply)

  assert reply.resource.equals?(@records[dr_name], ['text', 'meta', 'presentedForm', 'extension']), "DiagnosticReport/#{@records[dr_name].id} doesn't match retrieved DiagnosticReport. Mismatched fields: #{reply.resource.mismatch(@records[dr_name], ['text', 'meta', 'presentedForm', 'extension'])}"
end
update_diagnostic_request(order_name) click to toggle source
# File lib/tests/suites/connectathon_lab_order_track.rb, line 233
def update_diagnostic_request(order_name)
  assert @records[order_name], "No DiagnosticRequest with that name present"
  
  reply = @client.read FHIR::DiagnosticRequest, @records[order_name].id
  
  assert_response_ok(reply)
  assert reply.resource.equals?(@records[order_name], ['text', 'meta', 'presentedForm', 'extension']), "Reply did not match DiagnosticRequest/#{@records[order_name].id}. Mismatched fields: #{reply.resource.mismatch(@records[order_name], ['text', 'meta', 'presentedForm', 'extension'])}"
  assert reply.resource.status == 'active', 'DiagnosticRequest status should be active.'

  @records[order_name].status = 'completed'
  reply = @client.update @records[order_name], @records[order_name].id
  
  assert_response_ok(reply)

  reply = @client.read FHIR::DiagnosticRequest, @records[order_name].id
  
  assert_response_ok(reply)
  assert reply.resource.equals?(@records[order_name], ['text', 'meta', 'presentedForm', 'extension']), "Reply did not match #{@records[order_name]}. Mismatched fields: #{reply.resource.mismatch(@records[order_name], ['text', 'meta', 'presentedForm', 'extension'])}"
  assert reply.resource.status == 'completed', 'DiagnosticRequest status should have updated to completed.'
end