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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generator/codes_to_json.rb', line 13

def self.from_value_sets(value_sets)
  # make sure we have a string keyed hash
  value_sets = JSON.parse(value_sets.to_json)
  translation = {}
  value_sets.each do |value_set|
    code_sets = {}
    value_set["code_sets"].each do |code_set|
      code_sets[code_set["code_set"]] ||= []
      code_sets[code_set["code_set"]].concat(code_set["codes"])
    end
    
    translation[value_set["oid"]] = code_sets
  end
  
  translation
end

.from_xls(code_systems_file) ⇒ Object



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

def self.from_xls(code_systems_file)
  value_sets = HQMF::ValueSet::Parser.new().parse(code_systems_file)
  from_value_sets(value_sets)
end

.from_xml(code_systems_file) ⇒ Object

Create a new Nokogiri::XML::Document instance by parsing at file at the supplied path from an IHE SVS XML document then converts into a JSON format. The original XML is of the format:

Originally formatted like this: <CodeSystems>

<ValueSet id="2.16.840.1.113883.3.464.1.14" displayName="birth date">
  <ConceptList xml:lang="en-US">
    <Concept code="00110" codeSystemName="HL7" displayName="Date/Time of birth (TS)"
      codeSystemVersion="3"/>
   </ConceptList>
</ValueSet>

</CodeSystems>

The translated JSON will be in this structure: {

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

}



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

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



9
10
11
# File 'lib/generator/codes_to_json.rb', line 9

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)


75
76
77
# File 'lib/generator/codes_to_json.rb', line 75

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