Index: ruby/branches/0.5/lib/open_ehr/rm/demographic.rb
===================================================================
--- ruby/branches/0.5/lib/open_ehr/rm/demographic.rb	(revision 363)
+++ ruby/branches/0.5/lib/open_ehr/rm/demographic.rb	(revision 364)
@@ -183,14 +183,81 @@
 
       class Role < Party
-
+        attr_reader :performer, :capabilities
+        attr_accessor :time_validity
+
+        def initialize(args = { })
+          super(args)
+          self.performer = args[:performer]
+          self.capabilities = args[:capabilities]
+          self.time_validity = args[:time_validity]
+        end
+
+        def performer=(performer)
+          if performer.nil?
+            raise ArgumentError, 'performer is mandatory'
+          end
+          @performer = performer
+        end
+
+        def capabilities=(capabilities)
+          if !capabilities.nil? && capabilities.empty?
+            raise ArgumentError, 'capability should not be empty'
+          end
+          @capabilities = capabilities
+        end
       end
 
       class Capability < Locatable
-        attr_reader :credentials, :time_validity
-
+        attr_reader :credentials
+        attr_accessor :time_validity
+
+        def initialize(args = { })
+          super(args)
+          self.credentials = args[:credentials]
+          self.time_validity = args[:time_validity]
+        end
+
+        def credentials=(credentials)
+          if credentials.nil?
+            raise ArgumentError, 'credentials are mandatory'
+          end
+          @credentials = credentials
+        end
       end
 
       class PartyRelationship < Locatable
-
+        attr_accessor :details, :time_validity
+        attr_reader :source, :target
+        alias :type :name
+
+        def initialize(args = { })
+          super(args)
+          self.uid = args[:uid]
+          self.details = args[:details]
+          self.time_validity = args[:time_validity]
+          self.source = args[:source]
+          self.target = args[:target]
+        end
+
+        def uid=(uid)
+          if uid.nil?
+            raise ArgumentError, 'uid is mandatory'
+          end
+          @uid = uid
+        end
+
+        def source=(source)
+          if source.nil? or source.id.value != @uid.value
+            raise ArgumentError, 'source is invalid'
+          end
+          @source = source
+        end
+
+        def target=(target)
+          if target.nil?
+            raise ArgumentError, 'taraget is invalid'
+          end
+          @target = target
+        end
       end
 
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/capability_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/capability_spec.rb	(revision 364)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/capability_spec.rb	(revision 364)
@@ -0,0 +1,37 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe Capability do
+  before(:each) do
+    name = DvText.new(:value => 'party relation')
+    credentials = stub(ItemStructure, :archetype_node_id => 'at0001')
+    lower = DvDate.new(:value => '2009-11-21')
+    time_validity = stub(DvInterval, :lower => lower)
+    @capability = Capability.new(:archetype_node_id => 'at0000',
+                                 :name => name,
+                                 :credentials => credentials,
+                                 :time_validity => time_validity)
+  end
+
+  it 'should be an instance of Capability' do
+    @capability.should be_an_instance_of Capability
+  end
+
+  it 'credential should be assigned properly' do
+    @capability.credentials.archetype_node_id.should == 'at0001'
+  end
+
+  it 'should raise ArgumentError when nil assigned to credentials' do
+    lambda {
+      @capability.credentials = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'time_validity should be assigned properly' do
+    @capability.time_validity.lower.value.should == '2009-11-21'
+  end
+end
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb	(revision 364)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/party_relationship_spec.rb	(revision 364)
@@ -0,0 +1,84 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataStructures::ItemStructure
+
+describe PartyRelationship do
+  before(:each) do
+    name = DvText.new(:value => 'party relation')
+    uid = HierObjectID.new(:value => '01')
+    details = stub(ItemStructure, :archetype_node_id => 'at0002')
+    upper = DvDate.new(:value => '2009-11-21')
+    time_validity = stub(DvInterval, :upper => upper)
+    source_id = ObjectID.new(:value => '01')
+    source = stub(PartyRef, :id => source_id, :type => 'source')
+    target_id = ObjectID.new(:value => '02')
+    target = stub(PartyRef, :id => target_id)
+    @party_relationship =
+      PartyRelationship.new(:archetype_node_id => 'at0000',
+                            :name => name,
+                            :uid => uid,
+                            :details => details,
+                            :time_validity => time_validity,
+                            :source => source,
+                            :target => target)
+  end
+
+  it 'should be an instance of PartyRelationship' do
+    @party_relationship.should be_an_instance_of PartyRelationship
+  end
+
+  it 'uid should be assigned properly' do
+    @party_relationship.uid.value.should == '01'
+  end
+
+  it 'should raise ArgumentError when nil assigned to uid' do
+    lambda {
+      @party_relationship.uid = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'details should be assigned properly' do
+    @party_relationship.details.archetype_node_id.should == 'at0002'
+  end
+
+  it 'time_validity should be assigned properly' do
+    @party_relationship.time_validity.upper.value.should == '2009-11-21'
+  end
+
+  it 'source should be_assigned properly' do
+    @party_relationship.source.type.should == 'source'
+  end
+
+  it 'should raise ArgumentError when source is assinged nil' do
+    lambda {
+      @party_relationship.source = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError when source is not matched with source' do
+    invalid_id = ObjectID.new(:value => '10')
+    invalid_source = stub(PartyRef, :id => invalid_id)
+    lambda {
+      @party_relationship.source = invalid_source
+    }.should raise_error ArgumentError
+  end
+
+  it 'target should be assined properly' do
+    @party_relationship.target.id.value.should == '02'
+  end
+
+  it 'should raise ArgumentError with target is assigned by nil' do
+    lambda {
+      @party_relationship.target =nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'type should be inherited of name' do
+    @party_relationship.type.value.should == 'party relation'
+  end
+end
+  
+                            
Index: ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/role_spec.rb
===================================================================
--- ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/role_spec.rb	(revision 364)
+++ ruby/branches/0.5/spec/lib/open_ehr/rm/demographic/role_spec.rb	(revision 364)
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::Demographic
+include OpenEHR::RM::DataTypes::Text
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+include OpenEHR::RM::Support::Identification
+
+describe Role do
+  before(:each) do
+    name = DvText.new(:value => 'role')
+    uid = HierObjectID.new(:value => '01')
+    identities = stub(Set, :empty? => false)
+    capabilities = stub(Array, :size => 2, :empty? => false)
+    lower = DvDate.new(:value => '2009-11-21')
+    time_validity = stub(DvInterval, :lower => lower)
+    performer = stub(PartyRef, :type => 'ROLE')
+    @role = Role.new(:archetype_node_id => 'at0000',
+                     :name => name,
+                     :uid => uid,
+                     :identities => identities,
+                     :performer => performer,
+                     :capabilities => capabilities,
+                     :time_validity => time_validity)
+  end
+
+  it 'should be an instance of Role' do
+    @role.should be_an_instance_of Role
+  end
+
+  it 'performer should assigned properly' do
+    @role.performer.type.should == 'ROLE'
+  end
+
+  it 'should raise ArgumentError with nil performer' do
+    lambda {
+      @role.performer = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'capabilities should be assigned properly' do
+    @role.capabilities.size.should be_equal 2
+  end
+
+  it 'should raise ArgumentError with empty capabilities' do
+    lambda {
+      @role.capabilities = [ ]
+    }.should raise_error ArgumentError
+  end
+
+  it 'should not raise ArgumentError with nil capabilities' do
+    lambda {
+      @role.capabilities = nil
+    }.should_not raise_error ArgumentError
+  end
+
+  it 'time_validity should be properly assigned' do
+    @role.time_validity.lower.value.should == '2009-11-21'
+  end
+end
