Changeset 407


Ignore:
Timestamp:
Mar 13, 2010, 12:35:11 AM (12 years ago)
Author:
KOBAYASHI, Shinji
Message:

serializer implementation
Sample ADL was generated by LiU Archetype Editor.
There are some differences in XML forms amongs LiU, Ocean, CKM.

Location:
ruby/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • ruby/trunk/lib/open_ehr/serializer.rb

    r406 r407  
    44module OpenEHR
    55  module Serializer
     6    NL = "\r\n"
     7    INDENT = '    '
     8
    69    class BaseSerializer
    710      def initialize(archetype)
     
    1619    class ADLSerializer < BaseSerializer
    1720      def header
    18         return <<HERE
    19 archetype (adl_version = #{@archetype.adl_version})
    20 \t#{@archetype.archetype_id.value}
    21 
    22 concept
    23 \t[#{@archetype.concept}]
    24 HERE
     21        hd = 'archetype'
     22        unless @archetype.adl_version.nil?
     23          hd << " (adl_version = #{@archetype.adl_version})"
     24        end
     25        hd << NL+INDENT + "#{@archetype.archetype_id.value}"+NL+NL
     26        hd << 'concept'+NL+ INDENT+"[#{@archetype.concept}]"+NL
     27        hd << NL+'language'+NL+INDENT+'original_language = <['+
     28          @archetype.original_language.terminology_id.value+'::'+
     29          @archetype.original_language.code_string+']>'+NL
     30        return hd
    2531      end
    2632
     
    5258        end
    5359        xml.concept @archetype.concept
     60        xml.original_language do
     61          xml.code_string @archetype.original_language.code_string
     62          xml.terminology_id do
     63            xml.value @archetype.original_language.terminology_id.value
     64          end
     65        end
    5466        return header
    5567      end
  • ruby/trunk/spec/lib/open_ehr/serializer/adl_serializer_spec.rb

    r406 r407  
    77describe ADLSerializer do
    88  it_should_behave_like 'sample archetype'
     9
     10  before(:all) do
     11    current_dir = File.dirname(__FILE__)
     12    adl_file = File.open(current_dir + '/openEHR-EHR-SECTION.test.v1.adl')
     13    adl = adl_file.readlines
     14    @sample_header = adl[0..7].join
     15    @sample_description = adl[8..24].join
     16    adl_file.close
     17  end
    918
    1019  before(:each) do
     
    1726
    1827  it 'header should return archetype context' do
    19     @adl_serializer.header.should == <<HERE
    20 archetype (adl_version = 1.4)
    21 \tadl-test-ENTRY.most_minimal.v1
    22 
    23 concept
    24 \t[at0000]
    25 HERE
     28    @adl_serializer.header.should == @sample_header
    2629  end
    2730end
  • ruby/trunk/spec/lib/open_ehr/serializer/sample_archetype_spec.rb

    r406 r407  
    11require File.dirname(__FILE__) + '/../../../spec_helper'
    22include OpenEHR::AM::Archetype
     3include OpenEHR::AM::Archetype::ConstraintModel
     4include OpenEHR::AM::Archetype::Ontology
    35include OpenEHR::RM::Support::Identification
    46include OpenEHR::RM::DataTypes::Text
     7include OpenEHR::AssumedLibraryTypes
    58
    69shared_examples_for 'sample archetype' do
    710  before(:all) do
     11    terminologies_available = Set.new('ja')
     12    term_codes = ['at0000']
     13    archetype_term = ArchetypeTerm.new(:code => 'ja',
     14                                       :items => {'text' => 'simple test',
     15                                         'description' => 'simple test for serializer'})
     16    term_definitions = {'ja' => {'at0000' => archetype_term}}
     17    ontology =
     18      ArchetypeOntology.new(:terminologies_available => terminologies_available,
     19                            :specialisation_depth => 0,
     20                            :term_codes => term_codes,
     21                            :constraint_codes => [],
     22                            :term_attribute_names => ['text','description'],
     23                            :term_definitions => term_definitions)
    824    archetype_id = ArchetypeID.new(:value =>
    9                                    'adl-test-ENTRY.most_minimal.v1')
    10     terminology_id = TerminologyID.new(:value => 'ISO_639-1')
    11     original_language = CodePhrase.new(:code_string => 'en',
     25                                   'openEHR-EHR-SECTION.test.v1')
     26    terminology_id = TerminologyID.new(:value => 'openEHR')
     27    original_language = CodePhrase.new(:code_string => 'ja',
    1228                                       :terminology_id => terminology_id)
    13     @archetype = stub(Archetype, :adl_version => '1.4',
    14                       :archetype_id => archetype_id,
    15                       :concept => 'at0000')
     29    occurrences = Interval.new(:upper => 1, :lower => 1)
     30    definition = CComplexObject.new(:path => '/',
     31                                    :rm_type_name => 'SECTION',
     32                                    :occurrences => occurrences,
     33                                    :node_id => 'at0000')
     34    original_author = {'email' => 'skoba@moss.gr.jp',
     35      'organisation' => 'openEHR.jp',
     36      'name' => 'Shinji KOBAYASHI'}
     37    resource_description_item =
     38      ResourceDescriptionItem.new(:language => original_language,
     39                                  :purpose => 'Serializer test',
     40                                  :misuse => 'evaluate message')
     41    details = {'ja' => resource_description_item}
     42    decription = ResourceDescription.new(:original_author => original_author,
     43                                         :lifecycle_state => 'draft',
     44                                         :details => details)
     45    @archetype = Archetype.new(:archetype_id => archetype_id,
     46                               :concept => 'at0000',
     47                               :original_language => original_language,
     48                               :ontology => ontology,
     49                               :description => description,
     50                               :definition => definition)
    1651  end
    1752end
  • ruby/trunk/spec/lib/open_ehr/serializer/xml_serializer_spec.rb

    r406 r407  
    1818    @xml_serializer.header.should == <<END
    1919<archetype_id>
    20   <value>adl-test-ENTRY.most_minimal.v1</value>
     20  <value>openEHR-EHR-SECTION.test.v1</value>
    2121</archetype_id>
    2222<concept>at0000</concept>
     23<original_language>
     24  <code_string>ja</code_string>
     25  <terminology_id>
     26    <value>openEHR</value>
     27  </terminology_id>
     28</original_language>
    2329END
    2430  end
Note: See TracChangeset for help on using the changeset viewer.