Index: /ruby/trunk/lib/models/rm/data_types/quantity.rb
===================================================================
--- /ruby/trunk/lib/models/rm/data_types/quantity.rb	(revision 143)
+++ /ruby/trunk/lib/models/rm/data_types/quantity.rb	(revision 144)
@@ -56,12 +56,12 @@
 
         class DV_Quantified < DV_Ordered
-
-          def initialize(normal_range=nil, normal_status = nil,
+          attr_reader :magnitude, :accuracy, :magnitude_status
+
+          def initialize(magnitude, magnitude_status=nil,
+                         normal_range=nil, normal_status = nil,
                          other_reference_ranges=nil)
             super(normal_range, normal_status, other_reference_ranges)
-          end
-
-          def magnitude
-            
+            self.magnitude = magnitude
+            self.magnitude_status = magnitude_status
           end
 
@@ -70,6 +70,34 @@
           end
 
-          def valid_magnitude_status(s)
-
+          def magnitude=(magnitude)
+            raise ArgumentError, 'magnitude should not be nil' if magnitude.nil?
+            @magnitude = magnitude
+          end
+
+          def magnitude_status=(magnitude_status)
+            if magnitude_status.nil?
+              @magnitude_status = '='
+            elsif DV_Quantified.valid_magnitude_status?(magnitude_status)
+              @magnitude_status = magnitude_status
+            else
+              raise ArgumentError, 'magnitude_status invalid'
+            end
+          end
+
+          def accuracy=(accuracy)
+            raise NotImplementedError, 'subclasses need to implemented'
+          end
+
+          def accuracy_unknown?
+            return accuracy.nil?
+          end
+
+          def self.valid_magnitude_status?(s)
+            if s == '=' || s == '>' || s == '<' || s == '<=' ||
+                s == '>=' || s == '~'
+              return true
+            else
+              return false
+            end
           end
         end
@@ -153,8 +181,9 @@
 
         class Reference_Range
-          attr_reader :meaning
-
-          def initialize(meaning)
+          attr_reader :meaning, :range
+
+          def initialize(meaning, range)
             self.meaning = meaning
+            self.range = range
           end
 
@@ -164,4 +193,15 @@
             end
             @meaning = meaning
+          end
+
+          def range=(range)
+            if range.nil?
+              raise ArgumentError, 'range should not be nil'
+            end
+            @range = range
+          end
+
+          def is_in_range?(val)
+            return @range.has?(val)
           end
         end
Index: /ruby/trunk/lib/models/tests/rm/test_data_types.rb
===================================================================
--- /ruby/trunk/lib/models/tests/rm/test_data_types.rb	(revision 143)
+++ /ruby/trunk/lib/models/tests/rm/test_data_types.rb	(revision 144)
@@ -165,19 +165,22 @@
       @dv_ordered = OpenEHR::RM::Data_Types::Quantity::DV_Ordered.new }
     assert_nothing_raised(Exception){
-      @dv_interval = OpenEHR::RM::Data_Types::Quantity::DV_Interval.new(1,10)}
-    meaning = OpenEHR::RM::Data_Types::Text::DV_Text.new('normal')
-    assert_nothing_raised(Exception){
-      @reference_range = OpenEHR::RM::Data_Types::Quantity::Reference_Range.new(meaning)}
-    assert_nothing_raised(Exception){
       terminology = OpenEHR::RM::Support::Identification::Terminology_ID.new('urine', '')
       code_phrase = OpenEHR::RM::Data_Types::Text::Code_Phrase.new('protein',terminology)
       urinary_protein = OpenEHR::RM::Data_Types::Text::DV_Coded_Text.new('+', code_phrase)
-      @dv_ordinal = OpenEHR::RM::Data_Types::Quantity::DV_Ordinal.new(1, urinary_protein)}
-    assert_nothing_raised(Exception){
-      @dv_quantified = OpenEHR::RM::Data_Types::Quantity::DV_Quantified.new }
-    assert_nothing_raised(Exception){
-      @dv_amount = OpenEHR::RM::Data_Types::Quantity::DV_Amount.new}
-    assert_nothing_raised(Exception){
-      @dv_quantity = OpenEHR::RM::Data_Types::Quantity::DV_Quantity.new}
+      @dv_ordinal1 = OpenEHR::RM::Data_Types::Quantity::DV_Ordinal.new(1, urinary_protein)
+      code_phrase = OpenEHR::RM::Data_Types::Text::Code_Phrase.new('protein',terminology)
+      urinary_protein = OpenEHR::RM::Data_Types::Text::DV_Coded_Text.new('+++', code_phrase)
+      @dv_ordinal2 = OpenEHR::RM::Data_Types::Quantity::DV_Ordinal.new(3, urinary_protein)}
+    assert_nothing_raised(Exception){
+      @dv_interval = OpenEHR::RM::Data_Types::Quantity::DV_Interval.new(@dv_ordinal1, @dv_ordinal2)}
+    meaning = OpenEHR::RM::Data_Types::Text::DV_Text.new('normal')
+    assert_nothing_raised(Exception){
+      @reference_range = OpenEHR::RM::Data_Types::Quantity::Reference_Range.new(meaning, @dv_interval)}
+    assert_nothing_raised(Exception){
+      @dv_quantified = OpenEHR::RM::Data_Types::Quantity::DV_Quantified.new(1,'=')}
+    assert_nothing_raised(Exception){
+      @dv_amount = OpenEHR::RM::Data_Types::Quantity::DV_Amount.new(1)}
+    assert_nothing_raised(Exception){
+      @dv_quantity = OpenEHR::RM::Data_Types::Quantity::DV_Quantity.new(1)}
    end
 
@@ -187,6 +190,6 @@
      assert_instance_of OpenEHR::RM::Data_Types::Quantity::DV_Interval, @dv_interval
      assert_instance_of OpenEHR::RM::Data_Types::Quantity::Reference_Range, @reference_range
-     
-     assert_instance_of OpenEHR::RM::Data_Types::Quantity::DV_Ordinal, @dv_ordinal
+     assert_instance_of OpenEHR::RM::Data_Types::Quantity::DV_Ordinal, @dv_ordinal1
+     assert_instance_of OpenEHR::RM::Data_Types::Quantity::DV_Ordinal, @dv_ordinal2
      assert_instance_of OpenEHR::RM::Data_Types::Quantity::DV_Quantified, @dv_quantified
      assert_instance_of OpenEHR::RM::Data_Types::Quantity::DV_Amount, @dv_amount
@@ -213,40 +216,54 @@
 
   def test_dv_interval
-    assert 
+    assert @dv_interval.lower < @dv_interval.upper 
   end
 
   def test_reference_range
-    assert_equal 'normal', @reference_range.meaning.value    
-  end
-
-  def test_dv_quantified
-    
-  end
-
-  def test_dv_amount
-
-  end
-
-  def test_dv_ordinal
-    assert_equal 1, @dv_ordinal.value
-    assert_equal '+', @dv_ordinal.symbol.value
-    assert_raise(ArgumentError){@dv_ordinal.symbol = nil}
-    assert_raise(ArgumentError){@dv_ordinal.value = nil}
+    assert_equal 'normal', @reference_range.meaning.value
+    assert_equal 1, @reference_range.range.lower.value
     terminology = OpenEHR::RM::Support::Identification::Terminology_ID.new('urine', '')
     code_phrase = OpenEHR::RM::Data_Types::Text::Code_Phrase.new('protein',terminology)
     urinary_protein = OpenEHR::RM::Data_Types::Text::DV_Coded_Text.new('++', code_phrase)
-    assert_nothing_raised(Exception){
-      @dv_ordinal2 = OpenEHR::RM::Data_Types::Quantity::DV_Ordinal.new(2, urinary_protein)}
-    assert @dv_ordinal.is_strictly_comparable_to?(@dv_ordinal2)
-    assert @dv_ordinal < @dv_ordinal2
-    assert @dv_ordinal2 > @dv_ordinal
-    @dv_ordinal.value = 3
-    assert 3, @dv_ordinal.value
-    assert @dv_ordinal > @dv_ordinal2
-    assert_raise(ArgumentError){@dv_ordinal.limits = @reference_range}
+    dv_ordinal = OpenEHR::RM::Data_Types::Quantity::DV_Ordinal.new(2, urinary_protein)
+    assert @reference_range.is_in_range?(dv_ordinal)
+    dv_ordinal.value = 6
+    assert !@reference_range.is_in_range?(dv_ordinal)
+  end
+
+  def test_dv_quantified
+    assert_equal 1, @dv_quantified.magnitude
+    assert_equal '=', @dv_quantified.magnitude_status
+    assert !OpenEHR::RM::Data_Types::Quantity::DV_Quantified.valid_magnitude_status?('*')
+    assert OpenEHR::RM::Data_Types::Quantity::DV_Quantified.valid_magnitude_status?('>')
+    assert OpenEHR::RM::Data_Types::Quantity::DV_Quantified.valid_magnitude_status?('<')
+    assert OpenEHR::RM::Data_Types::Quantity::DV_Quantified.valid_magnitude_status?('>=')
+    assert OpenEHR::RM::Data_Types::Quantity::DV_Quantified.valid_magnitude_status?('<=')
+    assert OpenEHR::RM::Data_Types::Quantity::DV_Quantified.valid_magnitude_status?('~')
+    assert_nothing_raised(Exception){@dv_quantified.magnitude = 0}
+    assert_equal 0, @dv_quantified.magnitude
+    assert_nothing_raised(Exception){@dv_quantified.magnitude_status = nil}
+    assert_equal '=',  @dv_quantified.magnitude_status
+  end
+
+  def test_dv_amount
+
+  end
+
+  def test_dv_ordinal
+    assert_equal 1, @dv_ordinal1.value
+    assert_equal '+', @dv_ordinal1.symbol.value
+    assert_raise(ArgumentError){@dv_ordinal1.symbol = nil}
+    assert_raise(ArgumentError){@dv_ordinal1.value = nil}
+    assert @dv_ordinal1.is_strictly_comparable_to?(@dv_ordinal2)
+    assert @dv_ordinal1 < @dv_ordinal2
+    assert @dv_ordinal2 > @dv_ordinal1
+    @dv_ordinal1.value = 4
+    assert 4, @dv_ordinal1.value
+    assert @dv_ordinal1 > @dv_ordinal2
+    assert_raise(ArgumentError){@dv_ordinal1.limits = @reference_range}
     meaning = OpenEHR::RM::Data_Types::Text::DV_Text.new('limits')
-    limit_reference_range = OpenEHR::RM::Data_Types::Quantity::Reference_Range.new(meaning)
-    assert_nothing_raised(Exception){@dv_ordinal.limits = limit_reference_range}
-    assert_equal 'limits', @dv_ordinal.limits.meaning.value
+    limit_reference_range = OpenEHR::RM::Data_Types::Quantity::Reference_Range.new(meaning, @dv_interval)
+    assert_nothing_raised(Exception){@dv_ordinal1.limits = limit_reference_range}
+    assert_equal 'limits', @dv_ordinal1.limits.meaning.value
   end
 
