Class: HQMF1::Attribute

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/hqmf-parser/1.0/attribute.rb

Overview

Represents a HQMF measure attribute

Instance Method Summary collapse

Methods included from Utilities

#attr_val, #check_nil_conjunction_on_child, #clean_json, #clean_json_recursive

Methods included from HQMF::Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(entry) ⇒ Attribute

Create a new instance based on the supplied HQMF

Parameters:

  • entry (Nokogiri::XML::Element)

    the measure attribute element



9
10
11
# File 'lib/hqmf-parser/1.0/attribute.rb', line 9

def initialize(entry)
  @entry = entry
end

Instance Method Details

#codeString

Get the attribute code

Returns:



15
16
17
18
19
20
21
# File 'lib/hqmf-parser/1.0/attribute.rb', line 15

def code
  if (@entry.at_xpath('./cda:code/@code'))
    @entry.at_xpath('./cda:code/@code').value
  elsif @entry.at_xpath('./cda:code/@nullFlavor')
    @entry.at_xpath('./cda:code/@nullFlavor').value
  end
end

#const_nameObject

Get a JS friendly constant name for this measure attribute



58
59
60
61
# File 'lib/hqmf-parser/1.0/attribute.rb', line 58

def const_name
  components = name.gsub(/\W/,' ').split.collect {|word| word.strip.upcase }
  components.join '_'
end

#idString

Get the attribute id, used elsewhere in the document to refer to the attribute

Returns:



35
36
37
# File 'lib/hqmf-parser/1.0/attribute.rb', line 35

def id
  attr_val('./cda:id/@root')
end

#nameString

Get the attribute name

Returns:



25
26
27
28
29
30
31
# File 'lib/hqmf-parser/1.0/attribute.rb', line 25

def name
  if (@entry.at_xpath('./cda:code/@displayName'))
    @entry.at_xpath('./cda:code/@displayName').value
  elsif @entry.at_xpath('cda:code/cda:originalText')
    @entry.at_xpath('cda:code/cda:originalText').text
  end
end

#to_jsonObject



63
64
65
66
# File 'lib/hqmf-parser/1.0/attribute.rb', line 63

def to_json
  json = {self.const_name => build_hash(self, [:code,:value,:unit,:name,:id])}
  extend_json_for_enhanced_model(json)
end

#unitString

Get the unit of the attribute value or nil if none is defined

Returns:



53
54
55
# File 'lib/hqmf-parser/1.0/attribute.rb', line 53

def unit
  attr_val('./cda:value/@unit')
end

#valueString

Get the attribute value

Returns:



41
42
43
44
45
46
47
48
49
# File 'lib/hqmf-parser/1.0/attribute.rb', line 41

def value
  val = attr_val('./cda:value/@value')
  val ||= attr_val('./cda:value/@extension')
  if val
    val
  else
    @entry.at_xpath('./cda:value').inner_text
  end
end