Index: /ruby/branches/0.5/lib/open_ehr/rm/ehr.rb
===================================================================
--- /ruby/branches/0.5/lib/open_ehr/rm/ehr.rb	(revision 348)
+++ /ruby/branches/0.5/lib/open_ehr/rm/ehr.rb	(revision 348)
@@ -0,0 +1,94 @@
+# rm::ehr
+# ehr module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109004889781_854011_47Report.html
+# refs #44
+
+module OpenEHR
+  module RM
+    module EHR
+      class EHR
+        attr_reader :system_id, :ehr_id, :time_created, :contributions,
+                    :ehr_access, :ehr_status, :compositions, :directory
+
+        def initialize(args = { })
+          self.system_id = args[:system_id]
+          self.ehr_id = args[:ehr_id]
+          self.time_created = args[:time_created]
+          self.contributions = args[:contributions]
+          self.ehr_access = args[:ehr_access]
+          self.ehr_status = args[:ehr_status]
+          self.compositions = args[:compositions]
+          self.directory = args[:directory]
+        end
+
+        def system_id=(system_id)
+          if system_id.nil?
+            raise ArgumentError, 'system_id is mandatory'
+          end
+          @system_id = system_id
+        end
+
+        def ehr_id=(ehr_id)
+          if ehr_id.nil?
+            raise ArgumentError, 'ehr_id is mandatory'
+          end
+          @ehr_id = ehr_id
+        end
+
+        def time_created=(time_created)
+          if time_created.nil?
+            raise ArgumentError, 'time_created is mandatory'
+          end
+          @time_created = time_created
+        end
+
+        def contributions=(contributions)
+          unless contributions.nil?
+            contributions.each do |contrib|
+              unless contrib.type == 'CONTRIBUTION'
+                raise ArgumentError, 'contribution type should be CONTRIBUTION'
+              end
+            end
+            @contributions = contributions
+          else
+            raise ArgumentError, 'contributions are mandatory'
+          end
+        end
+
+        def ehr_access=(ehr_access)
+          if ehr_access.nil? || ehr_access.type != 'VERSIONED_EHR_ACCESS'
+            raise ArgumentError, 'ehr_access is invalid'
+          end
+          @ehr_access = ehr_access
+        end
+
+        def ehr_status=(ehr_status)
+          if ehr_status.nil? || ehr_status.type != 'VERSIONED_EHR_STATUS'
+            raise ArgumentError, 'ehr_status is invalid'
+          end
+          @ehr_status = ehr_status
+        end
+
+        def compositions=(compositions)
+          unless compositions.nil?
+            compositions.each do |compo|
+              unless compo.type == 'VERSIONED_COMPOSITION'
+                raise ArgumentError, 'composition type should be VERSIONED_COMPOSITION'
+              end
+            end
+            @compositions = compositions
+          else
+            raise ArgumentError, 'compositions are mandatory'
+          end
+        end
+
+        def directory=(directory)
+          if !directory.nil? && directory.type != 'VERSIONED_FOLDER'
+            raise ArgumentError, 'invalid directory'
+          end
+          @directory = directory
+        end
+      end
+    end # of EHR
+  end # of RM
+end # of OpenEHR
Index: /ruby/branches/0.5/spec/lib/open_ehr/rm/ehr/ehr_spec.rb
===================================================================
--- /ruby/branches/0.5/spec/lib/open_ehr/rm/ehr/ehr_spec.rb	(revision 348)
+++ /ruby/branches/0.5/spec/lib/open_ehr/rm/ehr/ehr_spec.rb	(revision 348)
@@ -0,0 +1,133 @@
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+include OpenEHR::RM::EHR
+include OpenEHR::RM::Support::Identification
+include OpenEHR::RM::DataTypes::Quantity::DateTime
+
+describe EHR do
+  before(:each) do
+    system_id = HierObjectID.new(:value => 'ABC::DEF')
+    ehr_id = HierObjectID.new(:value => 'GHI::JKL')
+    time_created = DvDateTime.new(:value => '2009-11-14T19:01:11')
+    ehr_access = stub(ObjectRef, :type => 'VERSIONED_EHR_ACCESS')
+    ehr_status = stub(ObjectRef, :type => 'VERSIONED_EHR_STATUS')
+    contribution1 = stub(ObjectRef, :type => 'CONTRIBUTION')
+    contribution2 = stub(ObjectRef, :type => 'CONTRIBUTION')
+    contributions = [contribution1, contribution2]
+    directory = stub(ObjectRef, :type => 'VERSIONED_FOLDER')
+    composition1 = stub(ObjectRef, :type => 'VERSIONED_COMPOSITION')
+    composition2 = stub(ObjectRef, :type => 'VERSIONED_COMPOSITION')
+    composition3 = stub(ObjectRef, :type => 'VERSIONED_COMPOSITION')
+    compositions = [composition1, composition2, composition3]
+    @ehr = EHR.new(:system_id => system_id,
+                   :ehr_id => ehr_id,
+                   :time_created => time_created,
+                   :contributions => contributions,
+                   :ehr_access => ehr_access,
+                   :ehr_status => ehr_status,
+                   :directory => directory,
+                   :compositions => compositions)
+  end
+
+  it 'should be an instance of EHR' do
+    @ehr.should be_an_instance_of EHR
+  end
+
+  it 'system_id should be assigned properly' do
+    @ehr.system_id.value.should == 'ABC::DEF'
+  end
+
+  it 'should raise ArgumentError with nil system_id' do
+    lambda {
+      @ehr.system_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'ehr_id should be assigned properly' do
+    @ehr.ehr_id.value.should == 'GHI::JKL'
+  end
+
+  it 'should raise ArgumentError with nil ehr_id' do
+    lambda {
+      @ehr.ehr_id = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'time_created should be assigned properly' do
+    @ehr.time_created.value.should == '2009-11-14T19:01:11'
+  end
+
+  it 'should raise ArgumentError with nil time_created' do
+    lambda {
+      @ehr.time_created = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'contributions should properly assigned' do
+    @ehr.contributions.size.should be_equal 2
+  end
+
+  it 'type contributions should be CONTRIBUTION' do
+    contributions = [stub(ObjectRef, :type => 'PARTY')]
+    lambda {
+      @ehr.contributions = contributions
+    }.should raise_error ArgumentError
+  end
+
+  it 'ehr_access should be assigned properly' do
+    @ehr.ehr_access.type.should == 'VERSIONED_EHR_ACCESS'
+  end
+
+  it 'should raise ArgumentError with nil ehr_access' do
+    lambda {
+      @ehr.ehr_access = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArguemntError with invalid ehr_access type' do
+    lambda {
+      @ehr.ehr_access = stub(ObjectRef, :type => 'VERSIONED_EHR_STATUS')
+    }.should raise_error ArgumentError
+  end
+    
+  it 'ehr_status should be assigned properly' do
+    @ehr.ehr_status.type.should == 'VERSIONED_EHR_STATUS'
+  end
+
+  it 'should raise ArgumentError with nil ehr_status' do
+    lambda {
+      @ehr.ehr_status = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with invalid ehr_statsu type' do
+    lambda {
+      @ehr.ehr_status = stub(ObjectRef, :type => 'VERSIONED_EHR_ACCESS')
+    }.should raise_error ArgumentError
+  end
+
+  it 'should assigned compositions properly' do
+    @ehr.compositions.size.should be_equal 3
+  end
+
+  it 'should raise ArgumentError with nil compositions' do
+    lambda {
+      @ehr.compositions = nil
+    }.should raise_error ArgumentError
+  end
+
+  it 'should raise ArgumentError with invalid type composition' do
+    lambda {
+      @ehr.compositions = [stub(ObjectRef, :type => 'INVALID_COMPOSITION')]
+    }.should raise_error ArgumentError
+  end
+
+  it 'should assigned directory properly' do
+    @ehr.directory.type.should == 'VERSIONED_FOLDER'
+  end
+
+  it 'should raise ArgumentError with invalid type' do
+    lambda {
+      @ehr.directory = stub(ObjectRef, :type => 'INVALID_FOLDER')
+    }.should raise_error ArgumentError
+  end
+end
