class OpenEHR::Serializer::XMLSerializer

Public Instance Methods

definition() click to toggle source
# File lib/openehr/serializer.rb, line 201
def definition
  definition = ''
  ad = @archetype.definition
  xml = Builder::XmlMarkup.new(:indent => 2, :target => definition)
  xml.definition do
    xml.rm_type_name ad.rm_type_name
    xml.occurrence do
      oc = ad.occurrences
      xml.lower_included oc.lower_included? unless oc.lower_included?.nil?
      xml.upper_included oc.upper_included? unless oc.upper_included?.nil?
      xml.lower_unbounded oc.lower_unbounded?
      xml.upper_unbounded oc.upper_unbounded?
      xml.lower oc.lower
      xml.upper oc.lower
    end
    xml.node_id ad.node_id
  end
  return definition
end
description() click to toggle source
# File lib/openehr/serializer.rb, line 157
def description
  desc = ''
  xml = Builder::XmlMarkup.new(:indent => 2, :target => desc)
  ad = @archetype.description
  if ad
    xml.description do
      ad.original_author.each do |key,value|
        xml.original_author(value,"id"=>key)
      end
      if ad.other_contributors
        ad.other_contributors.each do |co|
          xml.other_contributors co
        end
      end
      xml.lifecycle_state ad.lifecycle_state
      xml.details do
        ad.details.each do |lang, item|
          xml.language do
            xml.terminology_id do
              xml.value item.language.terminology_id.value
            end
            xml.code_string lang
          end
          xml.purpose item.purpose
          if item.keywords then
            item.keywords.each do |word|
              xml.keywords word
            end
          end
          xml.use item.use if item.use
          xml.misuse item.misuse if item.misuse
          xml.copyright item.copyright if item.copyright
          if ad.other_details
            ad.other_details.each do |key,value|
              xml.other_details(value, "id"=>key)
            end
          end
        end
      end
    end
  end
  return desc
end
header() click to toggle source
# File lib/openehr/serializer.rb, line 141
def header
  header = ''
  xml = Builder::XmlMarkup.new(:indent => 2, :target => header)
  xml.archetype_id do 
    xml.value @archetype.archetype_id.value
  end
  xml.concept @archetype.concept
  xml.original_language do
    xml.terminology_id do
      xml.value @archetype.original_language.terminology_id.value
    end
    xml.code_string @archetype.original_language.code_string
  end
  return header
end
merge() click to toggle source
# File lib/openehr/serializer.rb, line 248
def merge
  archetype = "<?xml version='1.0' encoding='UTF-8'?>" + NL +
    "<archetype xmlns=\"http://schemas.openehr.org/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + NL +
    header + description + definition +
    ontology + '</archetype>'
  return archetype
end
ontology() click to toggle source
# File lib/openehr/serializer.rb, line 221
def ontology
  ontology = ''
  ao = @archetype.ontology
  xml = Builder::XmlMarkup.new(:indent => 2, :target => ontology)
  xml.ontology do
    xml.specialisation_depth ao.specialisation_depth
    xml.term_definitions do
      ao.term_definitions.each do |lang, terms|
        xml.language lang
        xml.terms do
          terms.each do |term|
            xml.code term.code
            xml.items do
              term.items.each do |key, value|
                xml.item do
                  xml.key key
                  xml.value value
                end
              end
            end
          end
        end
      end
    end
  end
end