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



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

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.



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

def check_for_usable
  @check_for_usable
end

#code_xpathObject

Returns the value of attribute code_xpath.



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

def code_xpath
  @code_xpath
end

#codesObject

Returns the value of attribute codes.



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

def codes
  @codes
end

#codes_modifiersObject

Returns the value of attribute codes_modifiers.



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

def codes_modifiers
  @codes_modifiers
end

#status_xpathObject

Returns the value of attribute status_xpath.



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

def status_xpath
  @status_xpath
end

#warningsObject

Returns the value of attribute warnings.



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

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



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

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



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

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



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

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