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

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

Instance Method Summary collapse

Instance Method Details

#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



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

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



29
30
31
# File 'lib/canql/nodes/anomaly.rb', line 29

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

#code_filterObject



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

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



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

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



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

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

#existance_filterObject



25
26
27
# File 'lib/canql/nodes/anomaly.rb', line 25

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

#prepare_code_filters(code_array) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/canql/nodes/anomaly.rb', line 48

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



15
16
17
18
19
20
21
22
23
# File 'lib/canql/nodes/anomaly.rb', line 15

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?
  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