Class: HQMF2::Value

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

Overview

Represents a bound within a HQMF pauseQuantity, has a value, a unit and an inclusive/exclusive indicator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#attr_val, attr_val, #strip_tokens, #to_xml

Methods included from HQMF::Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(entry, default_type = 'PQ', force_inclusive = false, _parent = nil) ⇒ Value

Returns a new instance of Value.



24
25
26
27
28
29
30
31
32
33
# File 'lib/hqmf-parser/2.0/types.rb', line 24

def initialize(entry, default_type = 'PQ', force_inclusive = false, _parent = nil)
  @entry = entry
  @type = attr_val('./@xsi:type') || default_type
  @unit = attr_val('./@unit')
  @value = attr_val('./@value')
  @force_inclusive = force_inclusive

  # FIXME: Remove below when lengthOfStayQuantity unit is fixed
  @unit = 'd' if @unit == 'days'
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/hqmf-parser/2.0/types.rb', line 22

def type
  @type
end

#unitObject (readonly)

Returns the value of attribute unit.



22
23
24
# File 'lib/hqmf-parser/2.0/types.rb', line 22

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



22
23
24
# File 'lib/hqmf-parser/2.0/types.rb', line 22

def value
  @value
end

Instance Method Details

#derived?Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
94
95
# File 'lib/hqmf-parser/2.0/types.rb', line 88

def derived?
  case attr_val('./@nullFlavor')
  when 'DER'
    true
  else
    false
  end
end

#expressionObject



97
98
99
100
101
102
103
# File 'lib/hqmf-parser/2.0/types.rb', line 97

def expression
  if !derived?
    nil
  else
    attr_val('./cda:expression/@value')
  end
end

#inclusive?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
# File 'lib/hqmf-parser/2.0/types.rb', line 35

def inclusive?
  # If the high and low value are at any time the same, then it must be an inclusive value.
  equivalent = attr_val('../cda:low/@value') == attr_val('../cda:high/@value')

  # If and inclusivity value is set for any specific value, then mark the value as inclusive.
  # IDEA: This could be limited in future iterations by including the parent type (temporal reference, subset code,
  # etc.)
  inclusive_temporal_ref? || inclusive_length_of_stay? || inclusive_basic_values? || inclusive_subsets? ||
    equivalent || @force_inclusive
end

#inclusive_basic_values?Boolean

Check is the basic values should be marked as inclusive, currently only checks for greater than case

Returns:

  • (Boolean)


71
72
73
74
75
76
77
# File 'lib/hqmf-parser/2.0/types.rb', line 71

def inclusive_basic_values?
  # Basic values - EP65, EP9, and more
  attr_val('../cda:high/@nullFlavor') == 'PINF' &&
    attr_val('../cda:low/@value') &&
    attr_val('../@lowClosed') != 'false' &&
    attr_val('../@xsi:type') == 'IVL_PQ'
end

#inclusive_length_of_stay?Boolean

Check whether the length of stay should be inclusive.

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
# File 'lib/hqmf-parser/2.0/types.rb', line 59

def inclusive_length_of_stay?
  # lengthOfStay - EH111, EH108
  less_than_equal_los = attr_val('../cda:low/@nullFlavor') == 'NINF' &&
                        attr_val('../@highClosed') != 'false'

  greater_than_equal_los = attr_val('../cda:high/@nullFlavor') == 'PINF' &&
                           attr_val('../@lowClosed') != 'false'
  # Both less and greater require that the type is PQ
  (less_than_equal_los || greater_than_equal_los) && attr_val('@xsi:type') == 'PQ'
end

#inclusive_subsets?Boolean

Check if subset values should be marked as inclusive. Currently only handles greater than

Returns:

  • (Boolean)


80
81
82
83
84
85
86
# File 'lib/hqmf-parser/2.0/types.rb', line 80

def inclusive_subsets?
  # subset - EP128, EH108
  attr_val('../cda:low/@value') != '0' &&
    !attr_val('../cda:high/@value') &&
    attr_val('../@lowClosed') != 'false' &&
    !attr_val('../../../../../qdm:subsetCode/@code').nil?
end

#inclusive_temporal_ref?Boolean

Check whether the temporal reference should be marked as inclusive

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
55
56
# File 'lib/hqmf-parser/2.0/types.rb', line 47

def inclusive_temporal_ref?
  # FIXME: NINF is used instead of 0 sometimes...? (not in the IG)
  # FIXME: Given nullFlavor, but IG uses it and nullValue everywhere...
  less_than_equal_tr = attr_val('../@highClosed') == 'true' &&
                       (attr_val('../cda:low/@value') == '0' || attr_val('../cda:low/@nullFlavor') == 'NINF')
  greater_than_equal_tr = attr_val('../cda:high/@nullFlavor') == 'PINF' &&
                          attr_val('../cda:low/@value')
  # Both less and greater require lowClosed to be set to true
  (less_than_equal_tr || greater_than_equal_tr) && attr_val('../@lowClosed') == 'true'
end

#to_modelObject

Generates this classes hqmf-model equivalent



106
107
108
# File 'lib/hqmf-parser/2.0/types.rb', line 106

def to_model
  HQMF::Value.new(type, unit, value, inclusive?, derived?, expression)
end