Index: /ruby/trunk/lib/models/rm/data_types/quantity.rb
===================================================================
--- /ruby/trunk/lib/models/rm/data_types/quantity.rb	(revision 145)
+++ /ruby/trunk/lib/models/rm/data_types/quantity.rb	(revision 146)
@@ -56,5 +56,5 @@
 
         class DV_Quantified < DV_Ordered
-          attr_reader :magnitude, :magnitude_status, :accuracy
+          attr_reader :magnitude, :magnitude_status
 
           def initialize(magnitude, magnitude_status=nil,
@@ -165,5 +165,5 @@
 
         class DV_Amount < DV_Quantified
-          attr_reader :accuracy_is_percent
+          attr_reader :accuracy, :accuracy_percent
           def initialize(magnitude, magnitude_status=nil, accuracy=nil,
                          accuracy_percent=nil, normal_range=nil,
@@ -171,5 +171,9 @@
             super(magnitude, magnitude_status, normal_range,
                   normal_status, other_reference_ranges)
-            set_accuracy(accuracy, accuracy_percent) unless accuracy.nil?
+            unless accuracy.nil?
+              set_accuracy(accuracy, accuracy_percent)
+            else
+              @accuracy, @accuracy_percent = nil, nil
+            end
           end
           def +(other)
@@ -196,5 +200,56 @@
 
         class DV_Quantity < DV_Amount
-
+          attr_reader :units, :precision
+          def initialize(magnitude, units, magnitude_status=nil, precision=nil,
+                         accuracy=nil, accuracy_percent=nil, normal_range=nil,
+                         normal_status = nil, other_reference_ranges=nil)
+            super(magnitude, magnitude_status, accuracy, accuracy_percent,
+                  normal_range, normal_status, other_reference_ranges)
+            self.units = units
+            self.precision = precision
+          end
+
+          def units=(units)
+            raise ArgumentError, 'units should not be nil' if units.nil?
+            @units = units
+          end
+
+          def precision=(precision)
+            unless precision.nil? || precision >= -1
+              raise ArgumentError, 'precision invalid'
+            end
+            @precision = precision
+          end
+
+          def is_strictly_comparable_to?(others)
+            return false if others.nil?
+            if others.instance_of?(DV_Quantity) && others.units == @units
+              return true
+            else
+              return false
+            end
+          end
+
+          def is_integral?
+            if @precision.nil? || precision != 0
+              return false
+            else
+              return true
+            end
+          end
+# accuracy???
+          def +(other)
+            unless self.is_strictly_comparable_to?(other)
+              raise ArgumentError, 'type mismatch'
+            end
+            return DV_Quantity.new(@magnitude+other.magnitude, @units,
+                                   @magnitude_status, @precision,
+                                   @accuracy, @accuracy_percent, @normal_range,
+                                   @normal_status, @other_reference_ranges)
+          end
+          def -(other)
+            other.magnitude = - other.magnitude
+            self+(other)
+          end
         end
 
Index: /ruby/trunk/lib/models/tests/rm/test_data_types.rb
===================================================================
--- /ruby/trunk/lib/models/tests/rm/test_data_types.rb	(revision 145)
+++ /ruby/trunk/lib/models/tests/rm/test_data_types.rb	(revision 146)
@@ -182,5 +182,5 @@
       @dv_amount = OpenEHR::RM::Data_Types::Quantity::DV_Amount.new(2,'<')}
     assert_nothing_raised(Exception){
-      @dv_quantity = OpenEHR::RM::Data_Types::Quantity::DV_Quantity.new(3,'~')}
+      @dv_quantity = OpenEHR::RM::Data_Types::Quantity::DV_Quantity.new(3, 'mg', '~')}
    end
 
@@ -275,4 +275,25 @@
     assert_nothing_raised(Exception){@dv_ordinal1.limits = limit_reference_range}
     assert_equal 'limits', @dv_ordinal1.limits.meaning.value
+  end
+
+  def test_dv_quantity
+    assert_equal 3, @dv_quantity.magnitude
+    assert_equal 'mg', @dv_quantity.units
+    assert_equal '~', @dv_quantity.magnitude_status
+    dv_quantity2 = OpenEHR::RM::Data_Types::Quantity::DV_Quantity.new(4, 'mg', '~')
+    assert_equal 'mg', dv_quantity2.units
+    assert @dv_quantity.is_strictly_comparable_to?(dv_quantity2)
+    assert_nothing_raised(Exception){@dv_quantity.precision = -1}
+    assert_equal(-1, @dv_quantity.precision)
+    assert !@dv_quantity.is_integral?
+    assert_raise(ArgumentError){@dv_quantity.precision = -1.1}
+    @dv_quantity.precision = 0
+    assert @dv_quantity.is_integral?
+    dv_quantity3 = @dv_quantity + dv_quantity2
+    assert_equal 7, dv_quantity3.magnitude
+    assert_equal 'mg', dv_quantity3.units
+    dv_quantity3 = @dv_quantity - dv_quantity2
+    assert_equal(-1, dv_quantity3.magnitude)
+    assert_equal 'mg', dv_quantity3.units
   end
 
