Class: OpenEHR::Serializer::ADLSerializer

Inherits:
BaseSerializer show all
Includes:
AM::Archetype::ConstraintModel
Defined in:
lib/openehr/serializer/adl_serializer.rb

Constant Summary collapse

Primitive =
OpenEHR::AM::Archetype::ConstraintModel::Primitive
OpenEHRProfile =
OpenEHR::AM::OpenEHRProfile

Instance Method Summary collapse

Methods inherited from BaseSerializer

#initialize, #serialize

Constructor Details

This class inherits a constructor from OpenEHR::Serializer::BaseSerializer

Instance Method Details

#definitionObject



68
69
70
# File 'lib/openehr/serializer/adl_serializer.rb', line 68

def definition
  'definition' + NL + emit_c_object(@archetype.definition, 1)
end

#descriptionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/openehr/serializer/adl_serializer.rb', line 19

def description
  desc = ''
  if @archetype.description
    ad = @archetype.description
    desc << 'description' + NL
    desc << INDENT + 'original_author = <' + NL
    ad.original_author.each do |k,v|
      desc << INDENT+INDENT+'["'+k+'"] = <"'+v+'">'+NL
    end
    desc << INDENT+'>'+NL
    desc << INDENT+'lifecycle_state = <"'+ad.lifecycle_state+'">'+NL
    desc << INDENT+'details = <'+NL
    ad.details.each do |lang,item|
      desc << INDENT*2+'["'+lang+'"] = <'+NL
      desc << INDENT*3+'language = <['+
        item.language.terminology_id.value+'::'+
        item.language.code_string+']>'+NL
      desc << INDENT*3+'purpose = <"'+item.purpose+'">'+NL
      if item.keywords then
        desc << INDENT*3+'keywords = <'
        item.keywords.each do |word|
          desc << '"'+word+'",'
        end
        desc.chop! << '>'+NL
      end
      desc << INDENT*3+'use = <"'+item.use+'">'+NL if item.use
      desc << INDENT*3+'misuse = <"'+item.misuse+'">'+NL if item.misuse
      desc << INDENT*3+'copyright = <"'+item.copyright+'">'+NL if item.copyright
      if item.original_resource_uri
        desc << INDENT*3 + 'original_resource_uri = <'
        item.original_resource_uri.each do |k,v|
          desc << INDENT*4+'["'+k+'"] = <"'+v+'">'+NL
        end
        desc << INDENT*3+'>'+NL
      end
      if item.other_details
        desc << INDENT*3 + 'other_details = <'
        item.other_details.each do |k,v|
          desc << INDENT*4+'["'+k+'"] = <"'+v+'">'+NL
        end
        desc << INDENT*3+'>'+NL
      end
      desc << INDENT*2+'>'+NL
    end
    desc << INDENT+'>'+NL
  end
  return desc
end

#headerObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/openehr/serializer/adl_serializer.rb', line 6

def header
  hd = 'archetype'
  unless @archetype.adl_version.nil?
    hd << " (adl_version = #{@archetype.adl_version})"
  end
  hd << NL+INDENT + "#{@archetype.archetype_id.value}"+NL*2
  hd << 'concept'+NL+ INDENT+"[#{@archetype.concept}]"+NL
  hd << NL+'language'+NL+INDENT+'original_language = <['+
    @archetype.original_language.terminology_id.value+'::'+
    @archetype.original_language.code_string+']>'+NL
  return hd
end

#mergeObject



96
97
98
# File 'lib/openehr/serializer/adl_serializer.rb', line 96

def merge
  return header + NL + description + NL + definition + NL + ontology
end

#ontologyObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/openehr/serializer/adl_serializer.rb', line 72

def ontology
  ao = @archetype.ontology
  ontology = 'ontology'+NL
  ontology << string_list_line('languages_available', ao.languages_available)
  ontology << string_list_line('terminologies_available', ao.terminologies_available)
  ontology << INDENT + 'term_definitions = <' + NL
  ao.term_definitions.each do |lang, items|
    ontology << INDENT*2 + "[\"#{lang}\"] = <" + NL
    ontology << INDENT*3 + 'items = <'  + NL
    items.each do |code, item|
      ontology << INDENT*4 + "[\"#{code}\"] = <" + NL
      item.items.each do |name, desc|
        ontology << INDENT*5 + "#{name} = <\"#{desc}\">" + NL
      end
      ontology << INDENT*4 + '>'+NL
    end
    ontology << INDENT*3 + '>' + NL
    ontology << INDENT*2 + '>' + NL
  end
  ontology << INDENT + '>' + NL
  ontology << term_bindings_block(ao.term_bindings)
  ontology
end