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



53
54
55
# File 'lib/canql/nodes/anomaly.rb', line 53

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



49
50
51
# File 'lib/canql/nodes/anomaly.rb', line 49

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



45
46
47
# File 'lib/canql/nodes/anomaly.rb', line 45

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

#clean_code_array(code_array) ⇒ Object



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

def clean_code_array(code_array)
  code_array[:icd_code].flatten!
  code_array[:icd_code].delete_if(&:blank?)
  code_array[:code_group].flatten!
  code_array[:code_group].delete_if(&:blank?)
  code_array[:fasp_rating].flatten!
  code_array[:fasp_rating].delete_if(&:blank?)
end

#code_filterObject



100
101
102
103
104
105
106
107
108
109
# File 'lib/canql/nodes/anomaly.rb', line 100

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
38
39
# 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?
  if code_filter[:code_group].present?
    anomaly_hash['code_groups'] = code_filter[:code_group]
  end
  return if code_filter[:fasp_rating].blank?

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

#code_type(code) ⇒ Object



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

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



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

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

#existance_filterObject



41
42
43
# File 'lib/canql/nodes/anomaly.rb', line 41

def existance_filter
  { Canql::EQUALS => existance_modifier.text_value.strip != 'no' }
end

#prepare_code_filters(code_array) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/canql/nodes/anomaly.rb', line 72

def prepare_code_filters(code_array)
  clean_code_array(code_array)

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

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

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

  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' => existance_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