Class: EncounterPrincipalDiagnosis

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Attributes::Dynamic, Mongoid::Document
Defined in:
lib/health-data-standards/models/encounter_principal_diagnosis.rb

Instance Method Summary collapse

Instance Method Details

#preferred_code(preferred_code_sets = nil, codes_attribute = nil, value_set_map = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/health-data-standards/models/encounter_principal_diagnosis.rb', line 7

def preferred_code(preferred_code_sets=nil, codes_attribute=nil, value_set_map=nil)
  if @attributes.key?('code') and @attributes.key?('code_system')
    # This encounter principal diagnosis has the standard 'code' and
    # 'code_system' attributes, so only one code possible.
    return {'code' => @attributes['code'], 'code_set' => @attributes['code_system']}
  elsif @attributes.key?('codes')
    # This encounter principal diagnosis has the special 'codes' attribute
    # set, so return the first code in the first code set.
    code_set, code_set_codes = @attributes['codes'].first
    return {'code' => code_set_codes.first, 'code_set' => code_set}
  end
end

#translation_codes(preferred_code_sets = nil, value_set_map = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/health-data-standards/models/encounter_principal_diagnosis.rb', line 20

def translation_codes(preferred_code_sets=nil ,value_set_map=nil)
  tx_codes = []
  # Translations are only necessary when the encounter principal diagnosis
  # contains the special 'codes' attribute rather than the normal 'code' and
  # 'code_system', as 'codes' supports multiple codes/code sets.
  if @attributes.key?('codes')
    @attributes['codes'].each do |code_set, code_set_codes|
      for code in code_set_codes
        tx_codes.push({'code' => code, 'code_set' => code_set})
      end
    end
    tx_codes.shift
  end
  tx_codes
end