Class: QRDA::Cat1::SectionImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/qrda-import/base-importers/section_importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_finder) ⇒ SectionImporter

Returns a new instance of SectionImporter.



8
9
10
11
12
13
14
15
16
17
# File 'lib/qrda-import/base-importers/section_importer.rb', line 8

def initialize(entry_finder)
  @entry_finder = entry_finder
  @code_xpath = "./cda:code"
  @entry_id_map = {}
  @check_for_usable = true
  @entry_class = QDM::DataElement
  @warnings = []
  @codes = Set.new
  @codes_modifiers = {}
end

Instance Attribute Details

#check_for_usableObject

Returns the value of attribute check_for_usable.



6
7
8
# File 'lib/qrda-import/base-importers/section_importer.rb', line 6

def check_for_usable
  @check_for_usable
end

#code_xpathObject

Returns the value of attribute code_xpath.



6
7
8
# File 'lib/qrda-import/base-importers/section_importer.rb', line 6

def code_xpath
  @code_xpath
end

#codesObject

Returns the value of attribute codes.



6
7
8
# File 'lib/qrda-import/base-importers/section_importer.rb', line 6

def codes
  @codes
end

#codes_modifiersObject

Returns the value of attribute codes_modifiers.



6
7
8
# File 'lib/qrda-import/base-importers/section_importer.rb', line 6

def codes_modifiers
  @codes_modifiers
end

#status_xpathObject

Returns the value of attribute status_xpath.



6
7
8
# File 'lib/qrda-import/base-importers/section_importer.rb', line 6

def status_xpath
  @status_xpath
end

#warningsObject

Returns the value of attribute warnings.



6
7
8
# File 'lib/qrda-import/base-importers/section_importer.rb', line 6

def warnings
  @warnings
end

Instance Method Details

#create_entries(doc, nrh = NarrativeReferenceHandler.new) ⇒ Array

Traverses an HL7 CDA document passed in and creates an Array of Entry objects based on what it finds

Parameters:

  • doc (Nokogiri::XML::Document)

    It is expected that the root node of this document will have the “cda” namespace registered to “urn:hl7-org:v3” measure definition

Returns:

  • (Array)

    will be a list of Entry objects



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/qrda-import/base-importers/section_importer.rb', line 25

def create_entries(doc, nrh = NarrativeReferenceHandler.new)
  entry_list = []
  @entry_id_map = {}
  entry_elements = @entry_finder.entries(doc)
  entry_elements.each do |entry_element|
    entry = create_entry(entry_element, nrh)
    if @check_for_usable
      entry_list << entry if usable_entry?(entry)
    else
      entry_list << entry
    end
  end
  [entry_list, @entry_id_map]
end

#create_entry(entry_element, _nrh = NarrativeReferenceHandler.new) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/qrda-import/base-importers/section_importer.rb', line 44

def create_entry(entry_element, _nrh = NarrativeReferenceHandler.new)
  entry = @entry_class.new
  # This is the id found in the QRDA file
  entry_qrda_id = extract_id(entry_element, @id_xpath)
  # Create a hash to map all of entry.ids to the same QRDA ids. This will be used to merge QRDA entries
  # that represent the same event.
  @entry_id_map["#{entry_qrda_id.value}_#{entry_qrda_id.namingSystem}"] ||= []
  @entry_id_map["#{entry_qrda_id.value}_#{entry_qrda_id.namingSystem}"] << entry.id
  entry.dataElementCodes = extract_codes(entry_element, @code_xpath)
  extract_dates(entry_element, entry)
  if @result_xpath
    entry.result = extract_result_values(entry_element)
  end
  extract_negation(entry_element, entry)
  entry
end

#usable_entry?(entry) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/qrda-import/base-importers/section_importer.rb', line 40

def usable_entry?(entry)
  entry.dataElementCodes.present?
end