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



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

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



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

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



37
38
39
# File 'lib/canql/nodes/anomaly.rb', line 37

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

#code_filterObject



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

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

  code_arrays = { icd_code: [], code_group: [] }
  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_type(code) ⇒ Object



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

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?

  raise 'Unable to find code type'
end

#code_value(code) ⇒ Object



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

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

  code.to_code_group
end

#existance_filterObject



33
34
35
# File 'lib/canql/nodes/anomaly.rb', line 33

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

#prepare_code_filters(code_array) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/canql/nodes/anomaly.rb', line 62

def prepare_code_filters(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_filters = {}
  if code_array[:icd_code].any?
    code_filters[:icd_code] = { Canql::BEGINS => code_array[:icd_code] }
  end
  return code_filters if code_array[:code_group].blank?

  code_filters[:code_group] = { Canql::EQUALS => code_array[:code_group] }
  code_filters
end

#to_anomalyObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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
  anomaly_hash['icd_codes'] = code_filter[:icd_code] if code_filter[:icd_code].present?
  return anomaly_hash if code_filter[:code_group].blank?

  anomaly_hash['code_groups'] = code_filter[:code_group]
  anomaly_hash
end