Class: OpenEHR::Parser::ADLParser

Inherits:
Base
  • Object
show all
Defined in:
lib/openehr/parser/adl_parser.rb

Instance Attribute Summary

Attributes inherited from Base

#filename

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ ADLParser

Returns a new instance of ADLParser.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/openehr/parser/adl_parser.rb', line 12

def initialize(filename)
  super(filename)
  file = File.open(filename, 'r:bom|utf-8')
  data = file.read
  ap = ADLGrammarParser.new
  @result = ap.parse(data)
  file.close
  unless @result
    puts ap.failure_reason
    puts ap.failure_line
    puts ap.failure_column
  end
end

Instance Method Details

#parseObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/openehr/parser/adl_parser.rb', line 26

def parse
  archetype_id = OpenEHR::RM::Support::Identification::ArchetypeID.new(:value => @result.archetype_id)
  ontology = @result.ontology
  original_language = nil
  if @result.original_language
    original_language = @result.original_language
  else
    terminology_id = OpenEHR::RM::Support::Identification::TerminologyID.new(:value => 'ISO639-1')
    original_language = OpenEHR::RM::DataTypes::Text::CodePhrase.new(:terminology_id => terminology_id,
                                :code_string =>ontology.primary_language)
  end
  archetype = OpenEHR::AM::Archetype::Archetype.new(:archetype_id => archetype_id,
                            :adl_version => @result.adl_version,
                            :concept => @result.concept,
                            :original_language => original_language,
                            :translations => @result.translations,
                            :description => @result.description,
                            :definition => @result.definition,
                            :ontology => @result.ontology)
  return archetype
end