Index: ruby/trunk/lib/adl_parser/test/adl/openEHR-EHR-COMPOSITION.encounter.v1draft.adl
===================================================================
--- ruby/trunk/lib/adl_parser/test/adl/openEHR-EHR-COMPOSITION.encounter.v1draft.adl	(revision 329)
+++ ruby/trunk/lib/adl_parser/test/adl/openEHR-EHR-COMPOSITION.encounter.v1draft.adl	(revision 369)
@@ -10,5 +10,5 @@
 		["name"] = <"Thomas Beale">
 		["organisation"] = <"Ocean Informatics">
-		["date"] = <"2005-10-10">
+		["date"] = <"10/10/2005">
 	>
 	details = <
Index: ruby/trunk/lib/models/rm.rb
===================================================================
--- ruby/trunk/lib/models/rm.rb	(revision 329)
+++ 	(revision )
@@ -1,53 +1,0 @@
-$:.unshift File.join(File.dirname(__FILE__))
-# component: openEHR Ruby reference implementation
-# description: This file contains rm.packages.domain classes
-# keywords: archetype
-# author: Shinji KOBAYASHI, Akimichi TATSUKAWA
-# support: openEHR.jp
-# license: openEHR open source license
-#
-
-# OpenEHR::RM
-module OpenEHR
-
-  autoload :Assumed_Library_Types, "assumed_library_types.rb"
-
-  module RM
-    autoload :Demographic, "rm/demographic.rb"
-    autoload :Security, "rm/security.rb"
-
-    module Common
-      autoload :Resource, "rm/common/resource.rb"
-      autoload :Archetyped, "rm/common/archetyped.rb"
-      autoload :Generic, "rm/common/generic.rb"
-      autoload :Directory, "rm/common/directory.rb"
-      autoload :Change_Control, "rm/common/change_control.rb"
-    end
-
-    module Support
-      autoload :Definition, "rm/support/definition.rb"
-      autoload :Identification, "rm/support/identification.rb"
-      autoload :Terminology, "rm/support/terminology.rb"
-    end
-
-    module Data_Types
-      autoload :Basic, "rm/data_types/basic.rb"
-      autoload :Text, "rm/data_types/text.rb"
-      autoload :URI, "rm/data_types/uri.rb"
-      autoload :Quantity, "rm/data_types/quantity.rb"
-      autoload :Encapsulated, "rm/data_types/encapsulated.rb"
-      autoload :Time_Specification, 'rm/data_types/time_specification.rb'
-    end
-
-    module Data_Structures
-      autoload :Data_Structure, "rm/data_structure.rb"
-      autoload :History, 'rm/data_structures/history.rb'
-      autoload :Item_Structure, 'rm/data_structures/item_structure.rb'
-    end
-
-    module Security
-      autoload :Security, 'rm/security.rb'
-    end
-  end
-
-end
Index: ruby/trunk/lib/models/tests/rm/test_common.rb
===================================================================
--- ruby/trunk/lib/models/tests/rm/test_common.rb	(revision 329)
+++ ruby/trunk/lib/models/tests/rm/test_common.rb	(revision 369)
@@ -86,5 +86,4 @@
 class RM_Common_Archetyped_Test < Test::Unit::TestCase
   def setup
-
     @dv_text = OpenEhr::RM::DataTypes::Text::DvText.new('Test')
     @uid_based_id = OpenEhr::RM::Support::Identification::UidBasedId.new('rrip::0.0.5')
Index: ruby/trunk/lib/open_ehr/assumed_library_types.rb
===================================================================
--- ruby/trunk/lib/open_ehr/assumed_library_types.rb	(revision 329)
+++ ruby/trunk/lib/open_ehr/assumed_library_types.rb	(revision 369)
@@ -583,5 +583,7 @@
         self.minutes = $13.to_i
         self.seconds = $15.to_i
-        self.fractional_second = $16.to_f
+        unless $16.nil?
+          self.fractional_second = $16.to_f
+        end
       end
     end # end of ISO8601Duration
Index: ruby/trunk/lib/open_ehr/rm/composition.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/composition.rb	(revision 369)
+++ ruby/trunk/lib/open_ehr/rm/composition.rb	(revision 369)
@@ -0,0 +1,100 @@
+# rm::composition
+# composition module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109005072243_448526_217Report.html
+# refs #79
+include OpenEHR::RM::Common::Archetyped
+module OpenEHR
+  module RM
+    module Composition
+      class Composition < Locatable
+        attr_reader :language, :category, :territory, :composer
+        attr_accessor :content, :context
+
+        def initialize(args = { })
+          super(args)
+          self.language = args[:language]
+          self.category = args[:category]
+          self.territory = args[:territory]
+          self.composer = args[:composer]
+          self.content = args[:content]
+          self.context = args[:context]
+        end
+
+        def language=(language)
+          if language.nil?
+            raise ArgumentError, 'language is mandatory'
+          end
+          @language = language
+        end
+
+        def category=(category)
+          if category.nil?
+            raise ArgumentError, 'category is mandatory'
+          end
+          @category = category
+        end
+
+        def territory=(territory)
+          if territory.nil?
+            raise ArgumentError, 'territory is mandatory'
+          end
+          @territory = territory
+        end
+
+        def composer=(composer)
+          if composer.nil?
+            raise ArgumentError, 'composer is mandatory'
+          end
+          @composer = composer
+        end
+
+        def is_persistent?
+          return category.value == 'persistent'
+        end
+      end
+
+      class EventContext < Pathable
+        attr_reader :start_time, :setting, :participations, :location
+        attr_accessor :end_time, :other_context
+
+        def initialize(args = { })
+          super(args)
+          self.start_time = args[:start_time]
+          self.setting = args[:setting]
+          self.end_time = args[:end_time]
+          self.participations = args[:participations]
+          self.location = args[:location]
+          self.other_context = args[:other_context]
+        end
+
+        def start_time=(start_time)
+          if start_time.nil?
+            raise ArgumentError, 'start_time is mandatory'
+          end
+          @start_time = start_time
+        end
+
+        def setting=(setting)
+          if setting.nil?
+            raise ArgumentError, 'setting is mandatory'
+          end
+          @setting = setting
+        end
+
+        def participations=(participations)
+          if !participations.nil? and participations.empty?
+            raise ArgumentError, 'participations should not be empty'
+          end
+          @participations = participations
+        end
+
+        def location=(location)
+          if !location.nil? and location.empty?
+            raise ArgumentError, 'location should not be empty'
+          end
+          @location = location
+        end
+      end
+    end # end of Composition
+  end # end of RM
+end # end of OpenEHR
Index: ruby/trunk/lib/open_ehr/rm/composition/content.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/composition/content.rb	(revision 369)
+++ ruby/trunk/lib/open_ehr/rm/composition/content.rb	(revision 369)
@@ -0,0 +1,17 @@
+# rm::composition::content
+# content module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_5_1_76d0249_1140524925046_706492_3290Report.html
+# refs #58
+include OpenEHR::RM::Common::Archetyped
+
+module OpenEHR
+  module RM
+    module Composition
+      module Content
+        class ContentItem < Locatable
+
+        end
+      end # end of Content
+    end # end of Composition
+  end # end of RM
+end # end of OpenEHR
Index: ruby/trunk/lib/open_ehr/rm/composition/content/entry.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/composition/content/entry.rb	(revision 329)
+++ ruby/trunk/lib/open_ehr/rm/composition/content/entry.rb	(revision 369)
@@ -1,23 +1,246 @@
-module OpenEhr
+# rm::composition::content::entry
+# entry module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109264528523_312165_346Report.html
+# refs #56
+include OpenEHR::RM::Composition::Content
+
+module OpenEHR
   module RM
-    module Content
-      module Entry
-        class Entry < Content_Item
-        end
-        class CareEntry < Entry
-        end
-        class Action < CareEntry
-          attr_accessor :description, :time
-          attr_accessor :ism_transition, :instruction_details
-          def initialize(description, time, ism_transition, instruction_details)
-            raise Exception.new("invalid argument") if description == nil || time == nil || ism_transition == nil
-            @description = description
-            @time = time
-            @ism_transition = ism_transition
-            @instruction_details = instruction_details if instruction_details != nil
-          end
-        end # end of Action
-      end # end of Entry
-    end # end of Content
-  end # end of RM
-end # end of OpenEHR
+    module Composition
+      module Content
+        module Entry
+          class Entry < ContentItem
+            attr_reader :language, :encoding, :subject
+            attr_accessor :provider, :other_participations, :workflow_id
+            def initialize(args = { })
+              super(args)
+              self.language = args[:language]
+              self.encoding = args[:encoding]
+              self.subject = args[:subject]
+              self.provider = args[:provider]
+              self.other_participations = args[:other_participations]
+              self.workflow_id = args[:workflow_id]
+            end
+
+            def language=(language)
+              raise ArgumentError, 'language is mandatory' if language.nil?
+              @language = language
+            end
+
+            def encoding=(encoding)
+              raise ArgumentError, 'encoding is mandatory' if encoding.nil?
+              @encoding = encoding
+            end
+
+            def subject=(subject)
+              raise ArgumentError, 'subject is mandatory' if subject.nil?
+              @subject = subject
+            end
+
+            def subject_is_self?
+              return @subject.instance_of? PartySelf
+            end
+          end
+
+          class AdminEntry < Entry
+            attr_reader :data
+
+            def initialize(args = { })
+              super(args)
+              self.data = args[:data]
+            end
+
+            def data=(data)
+              raise ArgumentError, 'data are mandatory' if data.nil?
+              @data = data
+            end
+          end
+          class CareEntry < Entry
+            attr_accessor :protocol, :guideline_id
+
+            def initialize(args = { })
+              super(args)
+              self.protocol = args[:protocol]
+              self.guideline_id = args[:guideline_id]
+            end
+          end
+
+          class Observation < CareEntry
+            attr_reader :data
+            attr_accessor :state
+
+            def initialize(args = { })
+              super(args)
+              self.data = args[:data]
+              self.state = args[:state]
+            end
+
+            def data=(data)
+              raise ArgumentError, 'data are mandatory' if data.nil?
+              @data = data
+            end
+          end
+
+          class Evaluation < CareEntry
+            attr_reader :data
+
+            def initialize(args = { })
+              super(args)
+              self.data = args[:data]
+            end
+
+            def data=(data)
+              raise ArgumentError, 'data are mandatory' if data.nil?
+              @data = data
+            end
+          end
+
+          class Instruction < CareEntry
+            attr_reader :narrative, :activities
+            attr_accessor :expiry_time, :wf_definition
+
+            def initialize(args = { })
+              super(args)
+              self.narrative = args[:narrative]
+              self.activities = args[:activities]
+              self.expiry_time = args[:expiry_time]
+              self.wf_definition = args[:wf_definition]
+            end
+
+            def narrative=(narrative)
+              if narrative.nil?
+                raise ArgumentError, 'narrative is mandatory'
+              end
+              @narrative = narrative
+            end
+
+            def activities=(activities)
+              if !activities.nil? && activities.empty?
+                raise ArgumentError, 'activities should not be empty'
+              end
+              @activities = activities
+            end
+          end
+
+          class Activity < Locatable
+            attr_reader :description, :timing, :action_archetype_id
+
+            def initialize(args = { })
+              super(args)
+              self.description = args[:description]
+              self.timing = args[:timing]
+              self.action_archetype_id = args[:action_archetype_id]
+            end
+
+            def description=(description)
+              if description.nil?
+                raise ArgumentError, 'description is mandatory'
+              end
+              @description = description
+            end
+
+            def timing=(timing)
+              if timing.nil?
+                raise ArgumentError, 'timing is mandatory'
+              end
+              @timing = timing
+            end
+          end
+
+          def action_archetype_id=(action_archetype_id)
+            if action_archetype_id.nil? || action_archetype_id.empty?
+              raise ArgumentError, 'action_archetype_id is mandatory'
+            end
+            @action_archetype_id = action_archetype_id
+          end
+
+          class Action < CareEntry
+            attr_reader :time, :description, :ism_transition
+            attr_accessor :instruction_details
+            
+            def initialize(args = { })
+              super(args)
+              self.description = args[:description]
+              self.time = args[:time]
+              self.ism_transition = args[:ism_transition]
+              self.instruction_details = args[:instruction_details]
+            end
+
+            def time=(time)
+              if time.nil?
+                raise ArgumentError, 'time is mandatory'
+              end
+              @time = time
+            end
+
+            def description=(description)
+              if description.nil?
+                raise ArgumentError, 'description is mandatory'
+              end
+              @description = description
+            end
+
+            def ism_transition=(ism_transition)
+              if ism_transition.nil?
+                raise ArgumentError
+              end
+              @ism_transition = ism_transition
+            end
+          end
+
+          class InstructionDetails < Pathable
+            attr_reader :instruction_id, :activity_id
+            attr_accessor :wf_details
+
+            def initialize(args = { })
+              super(args)
+              self.instruction_id = args[:instruction_id]
+              self.activity_id = args[:activity_id]
+              self.wf_details = args[:wf_details]
+            end
+
+            def instruction_id=(instruction_id)
+              if instruction_id.nil?
+                raise ArgumentError, 'instruction_id is mandatory'
+              end
+              @instruction_id = instruction_id
+            end
+
+            def activity_id=(activity_id)
+              if activity_id.nil? || activity_id.empty?
+                raise ArgumentError, 'activity_id is mandatory'
+              end
+              @activity_id = activity_id
+            end
+          end
+
+          class IsmTransition < Pathable
+            attr_reader :current_state, :transition
+            attr_accessor :careflow_step
+
+            def initialize(args = { })
+              super(args)
+              self.current_state = args[:current_state]
+              self.transition = args[:transition]
+              self.careflow_step = args[:careflow_step]
+            end
+
+            def current_state=(current_state)
+              if current_state.nil?
+                raise ArgumentError, 'current_state is mandatory'
+              end
+              @current_state = current_state
+            end
+
+            def transition=(transition)
+              if transition.nil?
+                raise ArgumentError, 'transition is mandatory'
+              end
+              @transition = transition
+            end
+          end
+        end # of Entry
+      end # of Content
+    end # of Composition
+  end # of RM
+end # of OpenEHR
Index: ruby/trunk/lib/open_ehr/rm/composition/content/navigation.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/composition/content/navigation.rb	(revision 369)
+++ ruby/trunk/lib/open_ehr/rm/composition/content/navigation.rb	(revision 369)
@@ -0,0 +1,31 @@
+# rm::composition::content::navigation
+# navigation module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109264528523_312165_346Report.html
+# refs #56
+include OpenEHR::RM::Composition::Content
+
+module OpenEHR
+  module RM
+    module Composition
+      module Content
+        module Navigation
+          class Section < ContentItem
+            attr_reader :items 
+
+            def initialize(args = { })
+              super(args)
+              self.items = args[:items]
+            end
+
+            def items=(items)
+              if !items.nil? && items.empty?
+                raise ArgumentError, 'items should not be empty'
+              end
+              @items = items
+            end
+          end
+        end
+      end # end of Content
+    end # end of Composition
+  end # end of RM
+end # end of OpenEHR
Index: ruby/trunk/lib/open_ehr/rm/data_structures/history.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/data_structures/history.rb	(revision 369)
+++ ruby/trunk/lib/open_ehr/rm/data_structures/history.rb	(revision 369)
@@ -0,0 +1,114 @@
+# rm::data_structures::history
+# history module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109157527311_729550_7234Report.html
+# refs #55
+require 'time'
+include OpenEHR::RM::DataStructures
+include OpenEHR::RM::Common::Archetyped
+
+module OpenEHR
+  module RM
+    module DataStructures
+      module History
+        class History < DataStructure
+          attr_reader :origin, :events
+          attr_accessor :duration, :period, :summary
+
+          def initialize(args = { })
+            super(args)
+            self.origin = args[:origin]
+            self.duration = args[:duration]
+            self.period = args[:period]
+            self.events = args[:events]
+            self.summary = args[:summary]
+          end
+
+          def origin=(origin)
+            raise ArgumentError, 'origin is mandatory' if origin.nil?
+            @origin = origin
+          end
+
+          def events=(events)
+            if !events.nil? and events.empty?
+              raise ArgumentError, 'events should not be empty'
+            end
+            @events = events
+          end
+
+          def is_periodic?
+            return !@period.nil?
+          end
+        end
+
+        class Event < Locatable
+          attr_reader :data, :time
+          attr_accessor :state
+
+          def initialize(args = { })
+            super(args)
+            self.data = args[:data]
+            self.time = args[:time]
+            self.state = args[:state]
+          end
+
+          def data=(data)
+            raise ArgumentError, 'data is mandatory' if data.nil?
+            @data = data
+          end
+
+          def time=(time)
+            raise ArgumentError, 'time is mandatory' if time.nil?
+            @time = time
+          end
+
+          def offset
+            return @time.diff(@parent.origin)
+          end
+        end
+
+        class PointEvent < Event
+
+        end
+
+        class IntervalEvent < Event
+          attr_reader :width, :math_function
+          attr_accessor :sample_count
+
+          def initialize(args = { })
+            super(args)
+            self.width = args[:width]
+            self.math_function = args[:math_function]
+            self.sample_count = args[:sample_count]
+          end
+
+          def width=(width)
+            raise ArgumentError, 'width is mandatory' if width.nil?
+            @width = width
+          end
+
+          def math_function=(math_function)
+            if math_function.nil?
+              raise ArgumentError, 'math_function is mandatory'
+            end
+            @math_function = math_function
+          end
+
+          def interval_start_time
+            date_time = ::Time.iso8601(time.as_string)
+            start_time = (@width.years).years.ago date_time
+            start_time = (@width.months).months.ago start_time
+            start_time = (@width.days).days.ago start_time
+            start_time = (@width.hours).hours.ago start_time
+            start_time = (@width.minutes).minutes.ago start_time
+            seconds = @width.seconds
+            unless @width.fractional_second.nil?
+              seconds += @width.fractional_second
+            end
+            start_time = seconds.ago start_time
+            return DvDateTime.new(:value => start_time.iso8601)
+          end
+        end
+      end # end of History
+    end # end of DataStructure
+  end # end of RM
+end # end of OpenEHR
Index: ruby/trunk/lib/open_ehr/rm/data_structures/item_structure.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/data_structures/item_structure.rb	(revision 329)
+++ ruby/trunk/lib/open_ehr/rm/data_structures/item_structure.rb	(revision 369)
@@ -54,5 +54,5 @@
               return item if item.name.value == a_name
             end
-            retrun nil
+            return nil
           end
 
@@ -111,9 +111,5 @@
           def ith_row(i)
             raise ArgumentError, 'invalid index' if i<=0 or i>@rows.size
-            if @rows.nil?
-              return []
-            else
-              return @rows[i - 1]
-            end
+            return @rows[i - 1]
           end
 
@@ -139,5 +135,4 @@
               return row if row.items[0].name.value == key
             end
-            return []
           end
 
@@ -191,4 +186,25 @@
             self.items = args[:items]
           end
+
+          def has_element_path?(path)
+            paths = [ ]
+            @items.each do |item|
+              paths << item.archetype_node_id
+            end
+            return paths.include? path
+          end
+
+          def element_at_path(path)
+            @items.each do |item|
+              return item if item.archetype_node_id == path
+            end
+            return nil
+          end
+
+          def as_hierarchy
+            return Cluster.new(:name => @name,
+                               :archetype_node_id => @archetype_node_id,
+                               :items => @items)
+          end
         end
       end # of ItemStructure
Index: ruby/trunk/lib/open_ehr/rm/data_types/quantity.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/data_types/quantity.rb	(revision 329)
+++ ruby/trunk/lib/open_ehr/rm/data_types/quantity.rb	(revision 369)
@@ -66,5 +66,5 @@
 
           def <=>(others)
-            @magnitude <=> others.magnitude
+            self.magnitude <=> others.magnitude
           end
 
@@ -151,5 +151,5 @@
           def add(a_diff)
             type_check(a_diff)
-            return result_builder(DvAbsoluteQuantity,
+            return result_builder(self.class,
                                   @magnitude+a_diff.magnitude)
           end
@@ -157,5 +157,5 @@
           def diff(other)
             type_check(other)
-            return result_builder(DvAmount,
+            return result_builder(self.class,
                                   (@magnitude-other.magnitude).abs)
           end
@@ -163,5 +163,5 @@
           def subtract(a_diff)
             type_check(a_diff)
-            return result_builder(DvAbsoluteQuantity,
+            return result_builder(self.class,
                                   @magnitude-a_diff.magnitude)
           end
Index: ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb	(revision 329)
+++ ruby/trunk/lib/open_ehr/rm/data_types/quantity/date_time.rb	(revision 369)
@@ -4,23 +4,20 @@
 require 'assumed_library_types'
 require 'date'
-
-module OpenEhr
+include OpenEHR::RM::DataTypes::Quantity
+include OpenEHR::AssumedLibraryTypes
+
+module OpenEHR
   module RM
     module DataTypes
       module Quantity
         module DateTime
-          class DvTemporal < OpenEhr::RM::DataTypes::Quantity::DvAbsoluteQuantity
-            include Comparable
-            attr_reader :value
-
-            def initialize(value, magnitude_status=nil, accuracy=nil,
-                         normal_range=nil, normal_status=nil,
-                         other_reference_ranges=nil)
-              self.value = value
-              self.magnitude_status = magnitude_status
-              self.accuracy = accuracy
-              self.normal_range = normal_range
-              self.normal_status = normal_status
-              self.other_reference_ranges = other_reference_ranges
+          class DvTemporal < DvAbsoluteQuantity
+            def initialize(args = {})
+              self.value = args[:value]
+              self.magnitude_status = args[:magnitude_status]
+              self.accuracy = args[:accuracy]
+              self.normal_range = args[:normal_range]
+              self.normal_status = args[:normal_status]
+              self.other_reference_ranges = args[:other_reference_ranges]
             end
 
@@ -32,24 +29,15 @@
             end
 
-            def <=>(other)
-              self.magnitude <=> other.magnitude
-            end
+            undef magnitude=
           end
 
           class DvDate < DvTemporal
-            include OpenEhr::AssumedLibraryTypes::ISO8601_DATE_MODULE
+            include ISO8601DateModule
 
             DAYS_IN_MONTH = [0,31,28,31,30,31,30,31,31,30,31,30,31]
 
-            def initialize(value, magnitude_status=nil, accuracy=nil,
-                           normal_range=nil, normal_status=nil,
-                           other_reference_range=nil)
-              super(value, magnitude_status, accuracy, normal_range,
-                    normal_status, other_reference_range)
-            end
-
             def value=(value)
               super(value)
-              iso8601_date = AssumedLibraryTypes::ISO8601_DATE.new(value)
+              iso8601_date = ISO8601Date.new(value)
               @year = iso8601_date.year
               @month = iso8601_date.month
@@ -57,6 +45,4 @@
             end
 
-            undef magnitude=
-
             def magnitude
               return Date.new(@year, @month, @day)-Date.new(0000,1,1)
@@ -73,7 +59,7 @@
                 day = future.day - past.day
               else
-                month -= 1
+                month = -1
                 previous_month = future.month - 1
-                if previous_month <= 0
+                if previous_month == 0
                   previous_month = 12
                 end
@@ -90,6 +76,10 @@
                 month += future.month + 12 - past.month
               end
+              if month < 0
+                year -= 1
+                month += 12
+              end
               year += future.year - past.year
-              return DvDuration.new(
+              return DvDuration.new(:value =>
                    'P' + year.to_s + 'Y' + month.to_s + 'M' + 
                          week.to_s + 'W' + day.to_s + 'D')
@@ -98,15 +88,9 @@
           
           class DvTime < DvTemporal
-            include OpenEhr::AssumedLibraryTypes::ISO8601_TIME_MODULE
-            def initialize(value, magnitude_status=nil, accuracy=nil,
-                           normal_range=nil, normal_status=nil,
-                           other_reference_range=nil)
-              super(value, magnitude_status, accuracy, normal_range,
-                    normal_status, other_reference_range)
-            end
+            include ISO8601TimeModule
 
             def value=(value)
               super(value)
-              iso8601_time = AssumedLibraryTypes::ISO8601_TIME.new(value)
+              iso8601_time = ISO8601Time.new(value)
               @hour = iso8601_time.hour
               @minute = iso8601_time.minute
@@ -116,5 +100,9 @@
 
             def magnitude
-              return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second
+              if @fractional_second.nil?
+                return @hour * 60 * 60 + @minute * 60 + @second
+              else
+                return @hour * 60 * 60 + @minute * 60 + @second + @fractional_second
+              end
             end
 
@@ -125,24 +113,21 @@
               second = (diff - hour * 60 *60 - minute * 60).to_i
               fractional_second = ((diff - diff.to_i)*1000000.0).to_i/1000000.0
-              return DvDuration.new('P0Y0M0W0DT' + hour.to_s + 'H' +
-                        minute.to_s + 'M' +
-                        second.to_s + fractional_second.to_s[1..-1] + 'S')
+              str = 'P0Y0M0W0DT' + hour.to_s + 'H' +
+                minute.to_s + 'M' + second.to_s
+              if @fractional_second.nil?
+                str += 'S'
+              else
+                str += fractional_second.to_s[1..-1] + 'S'
+              end
+              return DvDuration.new(:value => str)
             end
           end
 
           class DvDateTime < DvTemporal
-            include OpenEhr::AssumedLibraryTypes::ISO8601_DATE_TIME_MODULE
-            attr_reader :value
-
-            def initialize(value, magnitude_status=nil, accuracy=nil,
-                           normal_range=nil, normal_status=nil,
-                           other_reference_range=nil)
-              super(value, magnitude_status, accuracy, normal_range,
-                    normal_status, other_reference_range)
-            end
+            include OpenEHR::AssumedLibraryTypes::ISO8601DateTimeModule
 
             def value=(value)              
               super(value)
-              iso8601date_time = AssumedLibraryTypes::ISO8601_DATE_TIME.new(value)
+              iso8601date_time = AssumedLibraryTypes::ISO8601DateTime.new(value)
               self.year = iso8601date_time.year
               self.month = iso8601date_time.month
@@ -156,6 +141,8 @@
 
             def magnitude
-              seconds = DateTime.new(@year,@month,@day,@hour,@minute,@second) - 
-                DateTime.new(0000,1,1,0,0,0)
+              seconds = (((@year * 365.24 +
+                           @month * 30.42 +
+                           @day) * 24 + @hour) * 60 +
+                         @minute) * 60 + @second
               if @fractional_second.nil?
                 return seconds
@@ -164,6 +151,4 @@
               end
             end
-
-            undef magnitude=
 
             def diff(other)
@@ -184,11 +169,14 @@
               minute = ((time_diff - hour*60*60)/60).to_i
               second = (time_diff - hour * 60 *60 - minute * 60).to_i
-              fractional_second = ((time_diff - time_diff.to_i)*1000000.0).to_i/1000000.0
-
-              return DvDuration.new(date_duration.value + 'T' +
-                        hour.to_s + 'H' +
-                        minute.to_s + 'M' +
-                        second.to_s + fractional_second.to_s[1..-1] + 'S')
-                                   
+              str = date_duration.value + 'T' + hour.to_s + 'H' +
+                minute.to_s + 'M' + second.to_s
+              if @fractional_second.nil?
+                return DvDuration.new(:value => str +'S')
+              else
+                fractional_second =
+                  ((time_diff - time_diff.to_i)*1000000.0).to_i/1000000.0
+                return DvDuration.new(:value => str +
+                                      fractional_second.to_s[1..-1] + 'S')
+              end
             end
 
@@ -197,16 +185,18 @@
             def split_date_time(date_time)
               /^(.*)T(.*)$/ =~ date_time.as_string
-              return DvDate.new($1), DvTime.new($2)
+              return DvDate.new(:value => $1), DvTime.new(:value => $2)
             end
           end
 
           class DvDuration < DvAmount
-            include AssumedLibraryTypes::ISO8601_DURATION_MODULE
+            include AssumedLibraryTypes::ISO8601DurationModule
             attr_reader :value
             
-            def initialize(value, magnitude_status=nil, accuracy=nil,
-                         accuracy_percent=nil, normal_range=nil,
-                         normal_status = nil, other_reference_ranges=nil)
-              self.value = value
+            def initialize(args = { })
+              self.value = args[:value]
+              self.magnitude_status = args[:magnitude_status]
+              self.normal_range = args[:normal_range]
+              self.normal_status = args[:normal_status]
+              self.other_reference_ranges = args[:other_reference_ranges]
             end
 
@@ -214,5 +204,5 @@
               raise ArgumentError, 'value must be not nil' if value.nil?
               @value = value
-              iso8601_duration = AssumedLibraryTypes::ISO8601_DURATION.new(value)
+              iso8601_duration = AssumedLibraryTypes::ISO8601Duration.new(value)
               self.years = iso8601_duration.years
               self.months = iso8601_duration.months
Index: ruby/trunk/lib/open_ehr/rm/demographic.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/demographic.rb	(revision 329)
+++ ruby/trunk/lib/open_ehr/rm/demographic.rb	(revision 369)
@@ -2,183 +2,265 @@
 # http://www.openehr.org/uml/release-1.0.1/Browsable/_9_5_76d0249_1118674798473_6021_0Report.html
 # Ticket refs #45
+include OpenEHR::RM::Common::Archetyped
+
 module OpenEHR
   module RM
-    module Demogrphic
-      class Address < OpenEHR::RM::Common::Archetyped::Locatable
-        attr_reader :details
-
-        def as_string
-
-        end
-
-        def type
-
-        end
-      end
-
-      class Capability < OpenEHR::RM::Common::Archetyped::Locatable
-        attr_reader :credentials, :time_validity
-
-      end
-
-      class Party < OpenEHR::RM::Common::Archetyped::Locatable
-        attr_reader :details, :reverse_relationships, :uid
-        attr_reader :idetities, :contacts, :relationships
-        def initialize(uid, archetype_node_id, name, archetype_details,
-                       feeder_audit, links, identities, contacts,
-                       relationships, reverse_relationships, details)
-          super(uid, archetype_node_id, name, archetype_details,
-                feeder_audit, links, nil)
-          uid_valid(uid)
+    module Demographic
+      class Party < Locatable
+        attr_reader :uid, :identities, :contacts, :relationships,
+                    :reverse_relationships
+        attr_accessor :details
+        alias :type :name
+
+        def initialize(args = { })
+          super(args)
+          self.uid = args[:uid]
+          self.identities = args[:identities]
+          self.contacts = args[:contacts]
+          self.relationships = args[:relationships]
+          self.reverse_relationships =
+            args[:reverse_relationships]
+          self.details = args[:details]
+        end
+
+        def uid=(uid)
+          raise ArgumentError, 'uid is mandatory' if uid.nil?
           @uid = uid
-          identities_vaild(identities)
+        end
+
+        def identities=(identities)
+          if identities.nil? || identities.empty?
+            raise ArgumentError, 'identities are mandatory'
+          end
           @identities = identities
-          contacts_valid(contacts)
+        end
+
+        def contacts=(contacts)
+          if !contacts.nil? && contacts.empty?
+            raise ArgumentError, 'contacts should not be empty'
+          end
           @contacts = contacts
-          relationships_valid(relationships)
-        end
-        def type
-          return name
-        end
-        def uid=(uid)
-          uid_valid(uid)
-          @uid = uid
-        end
-        def identities=(identities)
-          identities_vaild(identities)
-          @identities = identities
-        def contacts=(contacts)
-          contacts_valid(contacts)
-          @contacts = contacts
-        end
+        end
+
         def parent=(parent)
           @parent = nil
         end
-        private
-        def uid_valid(uid)
-          raise ArgumentError, "uid is not valid" if uid.nil?
-        end
-        def identities_vaild(identities)
-          if identities.nil?
-            raise ArgumentError, "identities must not be nil"
-          elsif identities.empty?
-            raise ArgumentError, "identities must not be empty"
-          end
-        end
-        def contacts_valid(contacts)
-          if contacs.nil?
-            raise ArgumentError, "contacts must not be nil"
-          elsif contacts.empty?
-            raise ArgumentError, "contacts must not be empty"
-          end          
-        end
-      end
-
-      class PartyIdentity < OpenEHR::RM::Common::Archetyped::Locatable
+
+        def relationships=(relationships)
+          unless relationships.nil?
+            if relationships.empty?
+              raise ArgumentError, 'relationships should not be empty?'
+            else
+              relationships.each do |rel|
+                if rel.source.id.value != @uid.value
+                  raise ArgumentError, 'invalid source of relationships'
+                end
+              end
+            end
+          end
+          @relationships = relationships
+        end
+
+        def reverse_relationships=(reverse_relationships)
+          if !reverse_relationships.nil? && reverse_relationships.empty?
+            raise ArgumentError, 'reverse_relationships should not be empty'
+          end
+          @reverse_relationships = reverse_relationships
+        end
+      end
+
+      class PartyIdentity < Locatable
         attr_reader :details
 
-      end
-
-      class PartyRelationship < OpenEHR::RM::Common::Archetyped::Locatable
-
-      end
-
-      class Versioned_Party < OpenEHR::RM::Common::Archetyped::Locatable
-
-      end
-
-      class Role < Party
-
+        def initialize(args = { })
+          super(args)
+          self.details = args[:details]
+        end
+
+        def details=(details)
+          if details.nil?
+            raise ArgumentError, 'details are mandatory'
+          end
+          @details = details
+        end
+
+        def purpose
+          return @name
+        end
+      end
+
+      class Contact < Locatable
+        attr_accessor :time_validity
+        attr_reader :addresses
+
+        def initialize(args = { })
+          super(args)
+          self.addresses = args[:addresses]
+          self.time_validity = args[:time_validity]
+        end
+
+        def purpose
+          return @name
+        end
+
+        def addresses=(addresses)
+          if addresses.nil? || addresses.empty?
+            raise ArgumentError, 'address is mandatory'
+          end
+          @addresses = addresses
+        end
+      end
+
+      class Address < Locatable
+        attr_reader :details
+
+        def initialize(args = { })
+          super(args)
+          self.details = args[:details]
+        end
+
+        def details=(details)
+          if details.nil?
+            raise ArgumentError, 'details are mandatory'
+          end
+          @details = details
+        end
+
+        def type
+          return @name
+        end
       end
 
       class Actor < Party
-        LEAGAL_IDENTITY = 'leagal identity'
-        attr_reader :languages, :rules
-        def initialize(uid, archetype_node_id, name, archetype_details,
-                       feeder_audit, links, identities, contacts,
-                       relationships, reverse_relationships, details,
-                       languages, rules)
-          super(uid, archetype_node_id, name, archetype_details,
-                feeder_audit, links, relationships, reverse_relationships,
-                details)
-          has_legal_identity?
-          set_languages(languages)
-          set_rules(rules)
-        end
+        LEAGAL_IDENTITY = 'legal identity'
+        attr_reader :languages, :roles
+
+        def initialize(args = { })
+          super(args)
+          self.roles = args[:roles]
+          self.languages = args[:languages]
+        end
+
+        def roles=(roles)
+          if !roles.nil? && roles.empty?
+            raise ArgumentError, 'roles should not be empty'
+          end
+          @roles = roles
+        end
+
         def has_legal_identity?
-          @identities.each {|identity|
-            if (identity.purpose.value == LEAGAL_IDENTITY)
+          @identities.each do |identity|
+            if identity.purpose.value == LEAGAL_IDENTITY
               return true
             end
-          }
-          false
-        end
+          end
+          return false
+        end
+
         def languages=(languages)
-          set_languages(languages)
-        end
-        def values=(values)
-          set_values(values)
-        end
-        private
-        def set_languages(languages)
-          if languages.nil?
-            raise ArgumentError, "languages should not be nil."
-          elsif languages.empty?
-            raise ArgumentError, "languages shouldnot be empty."
+          if !languages.nil? && languages.empty?
+            raise ArgumentError, 'languages should not be empty.'
           end
           @languages = languages
         end
-        def set_values(values)
-          if values.nil?
-            raise ArgumentError, "values should not be nil."
-          elsif values.empty?
-            raise ArgumentError, "values should not be nil."
-          end
-          @values = values
-      end
-      class Contact < OpenEHR::RM::Common::Archetyped::Locatable
+      end
+
+      class Person < Actor
+
+      end
+
+      class Organisation < Actor
+
+      end
+
+      class Group < Actor
+
+      end
+
+      class Agent < Actor
+
+      end
+
+      class Role < Party
+        attr_reader :performer, :capabilities
         attr_accessor :time_validity
-        attr_reader :addresses
-        def initialize(uid, archetype_node_id, name, archetype_details,
-                       feeder_audit, links, parent, time_validity, addresses)
-          super(uid, archetype_node_id, name, archetype_details,
-                feeder_audit, links, parent)
-          address_exists?(addresses)
-          @addresses = addresses
-          @time_validity = time_validity
-        end
-        def purpose
-          @name
-        end
-        def purpose=(purpose)
-          @name = purpose
-        end
-        def addresses=(addresses)
-          address_exists?(addresses)
-          @addresses = addresses
-        end
-        private
-        def address_exists?(addresses)
-          if addresses.nil?
-            raise ArgumentError, "address must not be nil"
-          elsif addresses.empty?
-            raise ArgumentError, "address must not be empty"
-          end
-        end
-      end
-
-      class Agent < Actor
-
-      end
-
-      class Organisation < Actor
-
-      end
-
-      class Person < Actor
-
-      end
-
-      class Group < Actor
+
+        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
+        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
+
+      class VersionedParty < Locatable
 
       end
Index: ruby/trunk/lib/open_ehr/rm/ehr.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/ehr.rb	(revision 369)
+++ ruby/trunk/lib/open_ehr/rm/ehr.rb	(revision 369)
@@ -0,0 +1,162 @@
+# rm::ehr
+# ehr module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_0_76d0249_1109004889781_854011_47Report.html
+# refs #44
+include OpenEHR::RM::Common::ChangeControl
+include OpenEHR::RM::Common::Archetyped
+include OpenEHR::RM::Security
+
+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
+
+      class VersionedEHRAccesss < VersionedObject
+
+      end
+
+      class EHRAccess < Locatable
+        attr_accessor :settings
+        attr_reader :scheme
+
+        def initialize(args = { })
+          super(args)
+          self.settings = args[:settings]
+          self.scheme = args[:scheme]
+        end
+
+        def scheme=(scheme)
+          if scheme.nil? || scheme.empty?
+            raise ArgumentError, 'scheme is mandatory'
+          end
+          @scheme = scheme
+        end
+      end
+
+      class VersionedEHRStatus < VersionedObject
+
+      end
+
+      class EHRStatus < Locatable
+        attr_reader :subject
+        attr_accessor :is_modifiable, :is_queryable, :other_details
+
+        def initialize(args = { })
+          super(args)
+          self.subject = args[:subject]
+          self.is_queryable = args[:is_queryable]
+          self.is_modifiable = args[:is_modifiable]
+          self.other_details = args[:other_details]
+        end
+
+        def subject=(subject)
+          raise ArgumentError, 'subject is mandatory' if subject.nil?
+          @subject = subject
+        end
+
+        def is_queryable?
+          return @is_queryable
+        end
+
+        def is_modifiable?
+          return @is_modifiable
+        end
+
+        def parent=(parent)
+          unless parent.nil?
+            raise ArgumentError, 'parent should be nil'
+          end
+          @parent = parent
+        end
+      end
+
+      class VersionedComposition < VersionedObject
+        def is_persistent?
+          return @all_versions.first.data.is_persistent?
+        end
+      end
+    end # of EHR
+  end # of RM
+end # of OpenEHR
Index: ruby/trunk/lib/open_ehr/rm/integration.rb
===================================================================
--- ruby/trunk/lib/open_ehr/rm/integration.rb	(revision 369)
+++ ruby/trunk/lib/open_ehr/rm/integration.rb	(revision 369)
@@ -0,0 +1,27 @@
+# rm::integration
+# integration module
+# http://www.openehr.org/uml/release-1.0.1/Browsable/_9_5_1_76d0249_1140530578205_529440_4046Report.html
+# refs #42
+include OpenEHR::RM::Composition::Content
+
+module OpenEHR
+  module RM
+    module Integration
+      class GenericEntry < ContentItem
+        attr_reader :data
+
+        def initialize(args = { })
+          super(args)
+          self.data = args[:data]
+        end
+
+        def data=(data)
+          if data.nil?
+            raise ArgumentError, 'data are mandatory'
+          end
+          @data = data
+        end
+      end
+    end # of Integration
+  end # of RM
+end # of OpenEHR
