Class: OpenEHR::Serializer::ADLSerializer

Inherits:
BaseSerializer show all
Defined in:
lib/open_ehr/serializer.rb

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/open_ehr/serializer.rb', line 83

def definition
  ad = @archetype.definition
  definition = 'definition'+NL
  definition << INDENT+ad.rm_type_name+"[#{ad.node_id}] matches {"
  if ad.any_allowed?
    definition << '*}'+NL
  else
    definition << NL
    if ad.attributes
      attributes = ad.attributes
      indents = 2
      while attributes
        definition << INDENT*indents+attributes.rm_type_name
        definition << "[#{attributes.node_id}] "
        definition << existence(attributes.existence)
        definition << " matches {"
      end
    end
  end
end

#descriptionObject



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/open_ehr/serializer.rb', line 34

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.original_resource_uri.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



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/open_ehr/serializer.rb', line 21

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



124
125
126
# File 'lib/open_ehr/serializer.rb', line 124

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

#ontologyObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/open_ehr/serializer.rb', line 104

def ontology
  ao = @archetype.ontology
  ontology = 'ontology'+NL
  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 |item|
      ontology << INDENT*4 + "[\"#{item.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
end