Module: Canql::Nodes::Anomaly::WithCondition

Defined in:
lib/canql/nodes/anomaly.rb

Instance Method Summary collapse

Instance Method Details

#anomaly_screening_status_typeObject



15
16
17
# File 'lib/canql/nodes/anomaly.rb', line 15

def anomaly_screening_status_type
  screening_status_type.text_value.strip
end

#anomaly_screening_status_type_filterObject



51
52
53
# File 'lib/canql/nodes/anomaly.rb', line 51

def anomaly_screening_status_type_filter
  { Canql::EQUALS => anomaly_screening_status_type }
end

#anomaly_status_typeObject



11
12
13
# File 'lib/canql/nodes/anomaly.rb', line 11

def anomaly_status_type
  status_type.text_value.strip
end

#anomaly_status_type_filterObject



47
48
49
# File 'lib/canql/nodes/anomaly.rb', line 47

def anomaly_status_type_filter
  { Canql::EQUALS => anomaly_status_type }
end

#anomaly_typeObject



7
8
9
# File 'lib/canql/nodes/anomaly.rb', line 7

def anomaly_type
  natal_period.text_value.strip
end

#anomaly_type_filterObject



43
44
45
# File 'lib/canql/nodes/anomaly.rb', line 43

def anomaly_type_filter
  { Canql::EQUALS => anomaly_type }
end

#clean_code_array(code_array) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/canql/nodes/anomaly.rb', line 81

def clean_code_array(code_array)
  code_array[:icd_code].flatten!
  code_array[:icd_code].compact_blank!
  code_array[:code_group].flatten!
  code_array[:code_group].compact_blank!
  code_array[:fasp_rating].flatten!
  code_array[:fasp_rating].compact_blank!
end

#code_filterObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/canql/nodes/anomaly.rb', line 90

def code_filter
  return {} if code_data.text_value.blank?

  code_arrays = { icd_code: [], code_group: [], fasp_rating: [] }
  code_arrays[code_type(code_data.first)] << code_value(code_data.first)
  code_data.rest.elements.each do |code|
    code_arrays[code_type(code)] << code_value(code)
  end
  prepare_code_filters(code_arrays)
end

#code_filters(anomaly_hash) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/canql/nodes/anomaly.rb', line 31

def code_filters(anomaly_hash)
  anomaly_hash['icd_codes'] = code_filter[:icd_code] if code_filter[:icd_code].present?
  anomaly_hash['code_groups'] = code_filter[:code_group] if code_filter[:code_group].present?
  return if code_filter[:fasp_rating].blank?

  anomaly_hash['fasp_rating'] = code_filter[:fasp_rating]
end

#code_type(code) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/canql/nodes/anomaly.rb', line 55

def code_type(code)
  return :icd_code if code.respond_to?(:to_code) && code.to_code.present?
  return :code_group if code.respond_to?(:to_code_group) && code.to_code_group.present?
  return :fasp_rating if code.respond_to?(:to_fasp_rating) && code.to_fasp_rating.present?

  raise 'Unable to find code type'
end

#code_value(code) ⇒ Object



63
64
65
66
67
68
# File 'lib/canql/nodes/anomaly.rb', line 63

def code_value(code)
  return code.to_code if :icd_code == code_type(code)
  return code.to_code_group if :code_group == code_type(code)

  code.to_fasp_rating
end

#existence_filterObject



39
40
41
# File 'lib/canql/nodes/anomaly.rb', line 39

def existence_filter
  { Canql::EQUALS => existence_modifier.text_value.strip != 'no' }
end

#prepare_code_filters(code_array) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/canql/nodes/anomaly.rb', line 70

def prepare_code_filters(code_array)
  clean_code_array(code_array)

  code_filters = {}
  code_filters[:icd_code] = { Canql::BEGINS => code_array[:icd_code] } if code_array[:icd_code].any?
  code_filters[:code_group] = { Canql::EQUALS => code_array[:code_group] } if code_array[:code_group].any?
  code_filters[:fasp_rating] = { Canql::EQUALS => code_array[:fasp_rating] } if code_array[:fasp_rating].any?

  code_filters
end

#to_anomalyObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/canql/nodes/anomaly.rb', line 19

def to_anomaly
  anomaly_hash = { 'exists' => existence_filter }
  anomaly_hash['type'] = anomaly_type_filter if anomaly_type.present?
  anomaly_hash['status'] = anomaly_status_type_filter if anomaly_status_type.present?
  if anomaly_screening_status_type.present?
    anomaly_hash['screening_status'] = anomaly_screening_status_type_filter
  end
  code_filters(anomaly_hash)

  anomaly_hash
end