Class: HQMF2JS::Generator::CodesToJson

Inherits:
Object
  • Object
show all
Defined in:
lib/generator/codes_to_json.rb

Class Method Summary collapse

Class Method Details

.from_value_sets(value_sets) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generator/codes_to_json.rb', line 10

def self.from_value_sets(value_sets)
  # make sure we have a string keyed hash
  translation = {}
  value_sets.each do |value_set|
    code_sets = {}
    value_set.concepts.each do |code_set|
      code_sets[code_set.code_system_name] ||= []
      code_sets[code_set.code_system_name].concat(code_set.code.to_a)
    end
    
    translation[value_set.oid] = code_sets
  end
  
  translation
end

.from_xml(code_systems_file) ⇒ Object

codeSystemVersion=“3”/>

   </ConceptList>
</ValueSet>

</CodeSystems>

The translated JSON will be in this structure: {

'2.16.840.1.113883.3.464.1.14' => {
                                    'HL7' => [ 00110 ]
                                  }

}



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/generator/codes_to_json.rb', line 46

def self.from_xml(code_systems_file)
  doc = HQMF2JS::Generator::CodesToJson.parse(code_systems_file)
  translation = {}
  doc.xpath('//ValueSet').each do |set|
    set_list = {}
    set_id = set.at_xpath('@id').value
      
    set.xpath('ConceptList').each do |list|
      list.xpath('Concept').each do |concept|
        system = concept.at_xpath('@codeSystemName').value
        code = concept.at_xpath('@code').value
        
        codes = set_list[system] || []
        codes << code
        set_list[system] = codes
      end
    end
    
    translation[set_id] = set_list
  end
  
  translation
end

.hash_to_js(hash) ⇒ Object



6
7
8
# File 'lib/generator/codes_to_json.rb', line 6

def self.hash_to_js(hash)
  hash.to_json.gsub(/\"/, "'")
end

.parse(path) ⇒ Nokogiri::XML::Document

Parse an XML document at the supplied path

Returns:

  • (Nokogiri::XML::Document)


72
73
74
# File 'lib/generator/codes_to_json.rb', line 72

def self.parse(path)
  doc = Nokogiri::XML(File.new(path))
end