Changeset 411


Ignore:
Timestamp:
Apr 23, 2010, 12:00:31 AM (14 years ago)
Author:
KOBAYASHI, Shinji
Message:

fixed archetype ontology bugs

Location:
ruby/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ruby/trunk/lib/open_ehr/am/archetype/ontology.rb

    r403 r411  
    44      module Ontology
    55        class ArchetypeOntology
    6           attr_accessor :constraint_codes, :specialisation_depth
    7           attr_accessor :term_attribute_names, :term_codes
    8           attr_reader :terminologies_available
     6          attr_accessor :constraint_definitions, :specialisation_depth
     7          attr_accessor :term_attribute_names, :term_bindings
     8          attr_reader :terminologies_available, :term_definitions
    99
    1010          def initialize(args = { })
    11             self.terminologies_available = args[:terminologies_available]
    1211            self.specialisation_depth = args[:specialisation_depth]
    13             self.term_codes = args[:term_codes]
    14             self.constraint_codes = args[:constraint_codes]
    15             self.term_attribute_names = args[:term_attribute_names]
     12            self.term_definitions = args[:term_definitions]
     13            self.constraint_definitions = args[:constraint_definitions]
     14            self.term_bindings = args[:term_bindings]
    1615          end
    1716
    18           def terminologies_available=(terminologies_available)
    19             if terminologies_available.nil?
    20               raise ArgumentError, 'terminologies_available is mandatory'
     17          # def terminologies_available=(terminologies_available)
     18          #   if terminologies_available.nil?
     19          #     raise ArgumentError, 'terminologies_available is mandatory'
     20          #   end
     21          #   @terminologies_available = terminologies_available
     22          # end
     23
     24          def term_definitions=(term_definitions)
     25            if term_definitions.nil?
     26              raise ArgumentError, 'term_definitions is mandatory'
    2127            end
    22             @terminologies_available = terminologies_available
     28            @term_definitions = term_definitions
     29          end
     30
     31          def term_codes
     32            return @term_definitions.values.collect {|value|
     33              value.collect {|term| term.code}}.flatten.uniq
     34          end
     35
     36          def constraint_codes
     37            if @constraint_definitions.nil?
     38              return nil
     39            else
     40              return @constraint_definitions.values.collect {|value|
     41                value.collect {|term| term.code}}.flatten.uniq
     42            end
    2343          end
    2444
  • ruby/trunk/lib/open_ehr/serializer.rb

    r410 r411  
    102102
    103103      def ontology
     104        ao = @archetype.ontology
     105        ontology = 'ontology'+NL
     106        ontology << INDENT + 'term_definitions = <' + NL
     107        ao.term_codes.each do |term, items|
     108          ontology << INDENT*2 + "[\"#{term}\"] = <" + NL
     109          ontology << INDENT*3 + 'items = <'  + NL
     110          items.each do |code, attribute|
     111            ontology << INDENT*4 + "[\"#{code}\] = <" + NL
     112            terms.each do |name, description|
     113              ontology << INDENT*5 + "#{name} = <\"#{description}\">" +NL
     114            end
     115            ontology << INDENT*4 + '>'+NL
     116          end
     117          ontogoly << INDENT*3 + '>' + NL
     118          ontology << INDENT*2 + '>' + NL
     119        end
     120        ontology << INDENT + '>' + NL
    104121      end
    105122
  • ruby/trunk/spec/lib/open_ehr/am/archetype/ontology/archetype_ontology_spec.rb

    r403 r411  
    11require File.dirname(__FILE__) + '/../../../../../spec_helper'
    22include OpenEHR::AM::Archetype::Ontology
     3include OpenEHR::RM::DataTypes::Text
    34
    45describe ArchetypeOntology do
    56  before(:each) do
    6     terminologies_available = stub(Set, :size =>1)
    7     term_codes = stub(Array, :size => 2)
    8     constraint_codes = stub(Array, :size => 3)
    9     term_attribute_names = stub(Array, :size => 4)
     7    items = {'TEXT' => 'text', 'DESC' => 'description'}
     8    term1 = ArchetypeTerm.new(:code => 'at0000', :items => items)
     9    items = {'TEXT' => 'concept'}
     10    term2 = ArchetypeTerm.new(:code => 'at0001', :items => items)
     11    term_definitions = {'ja' => [term1, term2]}
     12    items = {'text' => 'test', 'description' => 'test item'}
     13    term3 = ArchetypeTerm.new(:code => 'ac0000', :items => items)
     14    constraint_definitions = {'ja' => [term3]}
     15    code_phrase = stub(CodePhrase, :code_string => '163020007')
     16    bind = {'at0000' => code_phrase}
     17    term_bindings = {'SNOMED-CT(2003)' => [bind]}
    1018    @archetype_ontology =
    11       ArchetypeOntology.new(:terminologies_available => terminologies_available,
    12                             :specialisation_depth => 0,
    13                             :term_codes => term_codes,
    14                             :constraint_codes => constraint_codes,
    15                             :term_attribute_names => term_attribute_names)
     19      ArchetypeOntology.new(:term_definitions => term_definitions,
     20                            :constraint_definitions => constraint_definitions,
     21                            :term_bindings => term_bindings,
     22                            :specialisation_depth => 0)
    1623  end
    1724
     
    2027  end
    2128
    22   it 'terminologies_available should be assigned properly' do
    23     @archetype_ontology.terminologies_available.size.should be_equal 1
    24   end
    25 
    26   it 'should raise ArgumentError if terminologies_available is nil' do
    27     lambda {
    28       @archetype_ontology.terminologies_available = nil
    29     }.should raise_error ArgumentError
    30   end
    31 
    32   it 'term_codes should be assigned properly' do
    33     @archetype_ontology.term_codes.size.should be_equal 2
    34   end
    35 
    3629  it 'specialisation depth should be assigned properly' do
    3730    @archetype_ontology.specialisation_depth.should be_equal 0
    3831  end
    3932
    40   it 'constraint_codes should be assigned properly' do
    41     @archetype_ontology.constraint_codes.size.should be_equal 3
     33  it 'term_definitions should be assigned properly' do
     34    @archetype_ontology.term_definitions['ja'][0].code.should == 'at0000'
    4235  end
    4336
    44   it 'term_attribute_names should be assigned properly' do
    45     @archetype_ontology.term_attribute_names.size.should be_equal 4
     37  it 'term_codes should returnd all at codes' do
     38    @archetype_ontology.term_codes.should == ['at0000','at0001']
     39  end
     40
     41  it 'constraint_definitions should be assigned properly' do
     42    @archetype_ontology.constraint_definitions['ja'][0].items['text'].
     43      should == 'test'
     44  end
     45
     46  it 'constrant_codes should return all ac codes' do
     47    @archetype_ontology.constraint_codes.should == ['ac0000']
     48  end
     49
     50  it 'term_bindings should be assigned properly' do
     51    @archetype_ontology.term_bindings['SNOMED-CT(2003)'][0]['at0000'].
     52      code_string.should == '163020007'
    4653  end
    4754end
  • ruby/trunk/spec/lib/open_ehr/am/archetype/ontology/archetype_term_spec.rb

    r403 r411  
    44describe ArchetypeTerm do
    55  before(:each) do
    6     items = Hash['TEXT', 'text']
     6    items = {'TEXT' => 'text', 'DESC' => 'description'}
    77    @archetype_term = ArchetypeTerm.new(:code => 'at0001',
    88                                        :items => items)
     
    3434
    3535  it 'keys should be a set of keys of item' do
    36     @archetype_term.keys.should == Set.new('TEXT')
     36    @archetype_term.keys.should == Set['TEXT', 'DESC']
    3737  end
    3838
  • ruby/trunk/spec/lib/open_ehr/serializer/adl_serializer_spec.rb

    r409 r411  
    1515    @sample_description = adl[9..22].join
    1616    @sample_definition = adl[24..25].join
     17    @sample_ontology = adl[27..37].join
    1718    adl_file.close
    1819  end
     
    3738    @adl_serializer.definition.should == @sample_definition
    3839  end
     40
     41  it 'ontology should return ADL formatted ontology' do
     42    @adl_serializer.ontology.should == @sample_definition
     43  end
    3944end
Note: See TracChangeset for help on using the changeset viewer.