Class: HealthDataStandards::Import::C32::SectionImporter

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/health-data-standards/import/c32/section_importer.rb

Overview

Class that can be used to create an importer for a section of a HITSP C32 document. It usually operates by selecting all CDA entries in a section and then creates entries for them.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_xpath, code_xpath = "./cda:code", status_xpath = nil, priority_xpath = nil, description_xpath = "./cda:code/cda:originalText/cda:reference[@value] | ./cda:text/cda:reference[@value] ") ⇒ SectionImporter

Creates a new SectionImporter

Parameters:

  • id_map (Hash)

    A hash of all ID tags to values for the enclosing document. Used to look up descriptions.

  • entry_xpath (String)

    An XPath expression that can be used to find the desired entries

  • code_xpath (String) (defaults to: "./cda:code")

    XPath expression to find the code element as a child of the desired CDA entry. Defaults to “./cda:code”

  • status_xpath (String) (defaults to: nil)

    XPath expression to find the status element as a child of the desired CDA entry. Defaults to nil. If not provided, a status will not be checked for since it is not applicable to all enrty types



18
19
20
21
22
23
24
25
# File 'lib/health-data-standards/import/c32/section_importer.rb', line 18

def initialize(entry_xpath, code_xpath="./cda:code", status_xpath=nil,priority_xpath=nil, description_xpath="./cda:code/cda:originalText/cda:reference[@value] | ./cda:text/cda:reference[@value] ")
  @entry_xpath = entry_xpath
  @code_xpath = code_xpath
  @status_xpath = status_xpath
  @priority_xpath = priority_xpath
  @description_xpath = description_xpath
  @check_for_usable = true               # Pilot tools will set this to false
end

Instance Attribute Details

#check_for_usableObject

Returns the value of attribute check_for_usable.



9
10
11
# File 'lib/health-data-standards/import/c32/section_importer.rb', line 9

def check_for_usable
  @check_for_usable
end

Instance Method Details

#create_entries(doc, id_map = {}) ⇒ Array

Traverses that HITSP C32 document passed in using XPath 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



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/health-data-standards/import/c32/section_importer.rb', line 48

def create_entries(doc,id_map = {})
  entry_list = []
  entry_elements = doc.xpath(@entry_xpath)
  entry_elements.each do |entry_element|
    entry = create_entry(entry_element, id_map)
    if @check_for_usable
      entry_list << entry if entry.usable?
    else
      entry_list << entry
    end
  end
  entry_list
end

#create_entry(entry_element, id_map = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/health-data-standards/import/c32/section_importer.rb', line 62

def create_entry(entry_element, id_map={})
  entry = Entry.new
  extract_codes(entry_element, entry)
  extract_dates(entry_element, entry)
  extract_value(entry_element, entry)
  if @status_xpath
    extract_status(entry_element, entry)
  end
  if @description_xpath
    extract_description(entry_element, entry, id_map)
  end
  entry
end

#lookup_tag(tag, id_map) ⇒ String

Returns text description of tag.

Parameters:

  • tag (String)
  • id_map (Hash)

    A map of ids to all tagged text in the narrative portion of a document

Returns:

  • (String)

    text description of tag



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/health-data-standards/import/c32/section_importer.rb', line 30

def lookup_tag(tag, id_map)
  value = id_map[tag]
  # Not sure why, but sometimes the reference is #<Reference> and the ID value is <Reference>, and 
  # sometimes it is #<Reference>.  We look for both.
  if !value and tag[0] == '#'  
    tag = tag[1,tag.length]
    value = id_map[tag]
  end

  value
end