Index: /ruby/trunk/lib/adl_parser/lib/parser.rb
===================================================================
--- /ruby/trunk/lib/adl_parser/lib/parser.rb	(revision 256)
+++ /ruby/trunk/lib/adl_parser/lib/parser.rb	(revision 257)
@@ -11,10 +11,9 @@
 $:.unshift File.join(File.dirname(__FILE__))
 require 'logger'
-#require 'lib/util.rb'
-#require 'lib/scanner.rb'
-require 'lib/adl_parser.rb'
+#require 'lib/adl_parser.rb'
 require 'rubygems'
+require 'adl_parser.rb'
 require 'am.rb'
-$DEBUG = false
+require 'rm.rb'
 
 
@@ -24,5 +23,5 @@
     class Parser < Racc::Parser
 
-module_eval(<<'...end parser.y/module_eval...', 'parser.y', 1183)
+module_eval(<<'...end parser.y/module_eval...', 'parser.y', 1187)
 
 def assert_at(file,line, message = "")
@@ -152,6 +151,10 @@
       when /\A[A-Z][a-zA-Z0-9_]*/
         yield :V_TYPE_IDENTIFIER, $&
-      when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/   #V_ARCHETYPE_ID
-        yield :V_ARCHETYPE_ID, $&
+#      when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/   #V_ARCHETYPE_ID
+      when /\A(\w+)-(\w+)-(\w+)\.(\w+)(-\w+)?\.(v[0-9]+)/   #V_ARCHETYPE_ID
+        object_id, rm_originator, rm_name, rm_entity, concept_name, specialisation, version_id = $&, $1, $2, $3, $4, $5, $6
+        archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new(object_id, concept_name, rm_name, rm_entity, rm_originator, specialisation, version_id)
+#        yield :V_ARCHETYPE_ID, $&
+        yield :V_ARCHETYPE_ID, archetype_id
       when /\A[a-z][a-zA-Z0-9_]*/
 #        word = $&.downcase
@@ -235,5 +238,5 @@
         yield :Question_mark_code, :Question_mark_code
       when /\A[0-9]+\.[0-9]+(\.[0-9]+)*/   # ?
-        yield :V_VERSION_STRING, :V_VERSION_STRING
+        yield :V_VERSION_STRING, $&
       when /\A\|/   # |
         if @in_interval
@@ -253,4 +256,6 @@
         yield :Right_bracket_code, :Right_bracket_code
 
+      when /\A"([^"]*)"/m #V_STRING
+        yield :V_STRING, $1
       when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/   #ERR_V_QUALIFIED_TERM_CODE_REF
         yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
@@ -270,6 +275,4 @@
         yield :V_REAL, $&
         #    when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
-      when /\A"([^"]*)"/m #V_STRING
-        yield :V_STRING, $1
       when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
         yield :V_URI, $&
@@ -1306,5 +1309,5 @@
   1, 109, :_reduce_12,
   0, 99, :_reduce_none,
-  2, 99, :_reduce_none,
+  2, 99, :_reduce_14,
   2, 99, :_reduce_none,
   2, 100, :_reduce_16,
@@ -2040,4 +2043,5 @@
     
     archetype_id = val[0][:archetype_id]
+    parent_archtype_id = val[1][:parent_archtype_id] if val[1]
     adl_version = val[0][:arch_head][:arch_meta_data][:adl_version]
     concept = val[2]
@@ -2045,4 +2049,5 @@
     archetype = OpenEHR::AM::Archetype::ARCHETYPE.create(
                                                          :archetype_id => archetype_id,
+                                                         :parent_archtype_id => parent_archtype_id,
                                                          :adl_version => adl_version,
                                                          :concept => concept,
@@ -2060,5 +2065,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 61)
+module_eval(<<'.,.,', 'parser.y', 63)
   def _reduce_4(val, _values, result)
         result = {:arch_head => val[0], :archetype_id => val[1] }
@@ -2068,5 +2073,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 65)
+module_eval(<<'.,.,', 'parser.y', 67)
   def _reduce_5(val, _values, result)
         raise
@@ -2076,5 +2081,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 70)
+module_eval(<<'.,.,', 'parser.y', 72)
   def _reduce_6(val, _values, result)
         result = {:arch_meta_data => nil }
@@ -2084,5 +2089,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 74)
+module_eval(<<'.,.,', 'parser.y', 76)
   def _reduce_7(val, _values, result)
         result = val[1]
@@ -2092,5 +2097,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 79)
+module_eval(<<'.,.,', 'parser.y', 81)
   def _reduce_8(val, _values, result)
         result = {:arch_meta_data => val[1] }
@@ -2100,5 +2105,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 84)
+module_eval(<<'.,.,', 'parser.y', 86)
   def _reduce_9(val, _values, result)
         result = val[0]
@@ -2108,5 +2113,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 88)
+module_eval(<<'.,.,', 'parser.y', 90)
   def _reduce_10(val, _values, result)
         result = val[0].merge(val[2])
@@ -2116,5 +2121,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 94)
+module_eval(<<'.,.,', 'parser.y', 96)
   def _reduce_11(val, _values, result)
         result = {:adl_version => val[2], :is_controlled => false }
@@ -2124,5 +2129,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 98)
+module_eval(<<'.,.,', 'parser.y', 100)
   def _reduce_12(val, _values, result)
         result = {:is_controlled => true }
@@ -2134,9 +2139,15 @@
 # reduce 13 omitted
 
-# reduce 14 omitted
+module_eval(<<'.,.,', 'parser.y', 108)
+  def _reduce_14(val, _values, result)
+        result = {:parent_archtype_id => val[1]}
+  
+    result
+  end
+.,.,
 
 # reduce 15 omitted
 
-module_eval(<<'.,.,', 'parser.y', 109)
+module_eval(<<'.,.,', 'parser.y', 114)
   def _reduce_16(val, _values, result)
         result = {:arch_concept => val[1] }
@@ -2148,5 +2159,5 @@
 # reduce 17 omitted
 
-module_eval(<<'.,.,', 'parser.y', 119)
+module_eval(<<'.,.,', 'parser.y', 124)
   def _reduce_18(val, _values, result)
         result = {:arch_language => nil}
@@ -2156,5 +2167,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 123)
+module_eval(<<'.,.,', 'parser.y', 128)
   def _reduce_19(val, _values, result)
         result = {:arch_language => val[1]}
@@ -2168,5 +2179,5 @@
 # reduce 21 omitted
 
-module_eval(<<'.,.,', 'parser.y', 134)
+module_eval(<<'.,.,', 'parser.y', 139)
   def _reduce_22(val, _values, result)
         result = OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION.new(:details => val[1])
@@ -2178,5 +2189,5 @@
 # reduce 23 omitted
 
-module_eval(<<'.,.,', 'parser.y', 142)
+module_eval(<<'.,.,', 'parser.y', 147)
   def _reduce_24(val, _values, result)
         result = val[1]
@@ -2188,5 +2199,5 @@
 # reduce 25 omitted
 
-module_eval(<<'.,.,', 'parser.y', 150)
+module_eval(<<'.,.,', 'parser.y', 155)
   def _reduce_26(val, _values, result)
         assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT)}
@@ -2198,5 +2209,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 156)
+module_eval(<<'.,.,', 'parser.y', 161)
   def _reduce_27(val, _values, result)
         result = val[0]
@@ -2206,5 +2217,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 163)
+module_eval(<<'.,.,', 'parser.y', 168)
   def _reduce_28(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
@@ -2218,5 +2229,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 171)
+module_eval(<<'.,.,', 'parser.y', 176)
   def _reduce_29(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.create(:attributes => val[3]) do |c_complex_object|
@@ -2230,5 +2241,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 182)
+module_eval(<<'.,.,', 'parser.y', 187)
   def _reduce_30(val, _values, result)
         result = {:c_complex_object_id => val[0], :c_occurrences => val[1]}
@@ -2238,5 +2249,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 187)
+module_eval(<<'.,.,', 'parser.y', 192)
   def _reduce_31(val, _values, result)
         result = {:type_identifier => val[0]}
@@ -2246,5 +2257,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 191)
+module_eval(<<'.,.,', 'parser.y', 196)
   def _reduce_32(val, _values, result)
         result = {:type_identifier => val[0], :local_term_code_ref => val[1]}
@@ -2256,5 +2267,5 @@
 # reduce 33 omitted
 
-module_eval(<<'.,.,', 'parser.y', 197)
+module_eval(<<'.,.,', 'parser.y', 202)
   def _reduce_34(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT.new(:attributes => val[0])
@@ -2264,5 +2275,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 205)
+module_eval(<<'.,.,', 'parser.y', 210)
   def _reduce_35(val, _values, result)
         result = val[0]
@@ -2272,5 +2283,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 209)
+module_eval(<<'.,.,', 'parser.y', 214)
   def _reduce_36(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_complex_object = #{val[0].inspect} at #{@filename}:#{@lineno}")
@@ -2281,5 +2292,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 214)
+module_eval(<<'.,.,', 'parser.y', 219)
   def _reduce_37(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_INTERNAL_REF.create do |archetype_internal_ref|
@@ -2293,5 +2304,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 222)
+module_eval(<<'.,.,', 'parser.y', 227)
   def _reduce_38(val, _values, result)
         result = val[0]
@@ -2301,5 +2312,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 226)
+module_eval(<<'.,.,', 'parser.y', 231)
   def _reduce_39(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::CONSTRAINT_REF.create do |constraint_ref|
@@ -2311,5 +2322,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 232)
+module_eval(<<'.,.,', 'parser.y', 237)
   def _reduce_40(val, _values, result)
         result = val[0]
@@ -2319,5 +2330,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 236)
+module_eval(<<'.,.,', 'parser.y', 241)
   def _reduce_41(val, _values, result)
         result = val[0]
@@ -2327,5 +2338,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 240)
+module_eval(<<'.,.,', 'parser.y', 245)
   def _reduce_42(val, _values, result)
         result = val[0]
@@ -2339,5 +2350,5 @@
 # reduce 44 omitted
 
-module_eval(<<'.,.,', 'parser.y', 255)
+module_eval(<<'.,.,', 'parser.y', 260)
   def _reduce_45(val, _values, result)
         result = val[1]
@@ -2347,5 +2358,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 261)
+module_eval(<<'.,.,', 'parser.y', 266)
   def _reduce_46(val, _values, result)
         result = {:type_identifier => val[1], :c_occurrences => val[2], :absolute_path => val[3] }
@@ -2357,5 +2368,5 @@
 # reduce 47 omitted
 
-module_eval(<<'.,.,', 'parser.y', 268)
+module_eval(<<'.,.,', 'parser.y', 273)
   def _reduce_48(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::ARCHETYPE_SLOT.create do |archetype_slot|
@@ -2370,5 +2381,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 277)
+module_eval(<<'.,.,', 'parser.y', 282)
   def _reduce_49(val, _values, result)
         result = {:c_archetype_slot_id => val[0],:c_occurrences => val[1]}
@@ -2378,5 +2389,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 282)
+module_eval(<<'.,.,', 'parser.y', 287)
   def _reduce_50(val, _values, result)
         result = val[1]
@@ -2390,5 +2401,5 @@
 # reduce 52 omitted
 
-module_eval(<<'.,.,', 'parser.y', 290)
+module_eval(<<'.,.,', 'parser.y', 295)
   def _reduce_53(val, _values, result)
         assert_at(__FILE__,__LINE__){val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_PRIMITIVE)}
@@ -2401,5 +2412,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 298)
+module_eval(<<'.,.,', 'parser.y', 303)
   def _reduce_54(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_integer = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2414,5 +2425,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 307)
+module_eval(<<'.,.,', 'parser.y', 312)
   def _reduce_55(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_real = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2423,5 +2434,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 312)
+module_eval(<<'.,.,', 'parser.y', 317)
   def _reduce_56(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_date = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2432,5 +2443,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 317)
+module_eval(<<'.,.,', 'parser.y', 322)
   def _reduce_57(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_time = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2441,5 +2452,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 322)
+module_eval(<<'.,.,', 'parser.y', 327)
   def _reduce_58(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_date_time = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2450,5 +2461,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 327)
+module_eval(<<'.,.,', 'parser.y', 332)
   def _reduce_59(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_duration = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2459,5 +2470,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 332)
+module_eval(<<'.,.,', 'parser.y', 337)
   def _reduce_60(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: c_string = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2468,5 +2479,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 337)
+module_eval(<<'.,.,', 'parser.y', 342)
   def _reduce_61(val, _values, result)
         assert_at(__FILE__,__LINE__){val[0].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN)}
@@ -2480,5 +2491,5 @@
 # reduce 62 omitted
 
-module_eval(<<'.,.,', 'parser.y', 349)
+module_eval(<<'.,.,', 'parser.y', 354)
   def _reduce_63(val, _values, result)
         result = [val[0]]
@@ -2488,5 +2499,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 353)
+module_eval(<<'.,.,', 'parser.y', 358)
   def _reduce_64(val, _values, result)
         result = (val[0] << val[1])
@@ -2496,5 +2507,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 359)
+module_eval(<<'.,.,', 'parser.y', 364)
   def _reduce_65(val, _values, result)
         assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
@@ -2507,5 +2518,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 366)
+module_eval(<<'.,.,', 'parser.y', 371)
   def _reduce_66(val, _values, result)
         assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
@@ -2516,5 +2527,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 371)
+module_eval(<<'.,.,', 'parser.y', 376)
   def _reduce_67(val, _values, result)
         assert_at(__FILE__,__LINE__){ val[0].kind_of?(OpenEHR::AM::Archetype::Constraint_Model::C_ATTRIBUTE)}
@@ -2525,5 +2536,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 378)
+module_eval(<<'.,.,', 'parser.y', 383)
   def _reduce_68(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]}, c_existence = #{val[1]} at #{@filename}")
@@ -2538,5 +2549,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 387)
+module_eval(<<'.,.,', 'parser.y', 392)
   def _reduce_69(val, _values, result)
         assert_at(__FILE__,__LINE__){ val[2].instance_of?(OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY) }
@@ -2552,5 +2563,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 398)
+module_eval(<<'.,.,', 'parser.y', 403)
   def _reduce_70(val, _values, result)
         result = Array[val[0]]
@@ -2560,5 +2571,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 402)
+module_eval(<<'.,.,', 'parser.y', 407)
   def _reduce_71(val, _values, result)
         result = (val[0] << val[1])
@@ -2568,5 +2579,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 406)
+module_eval(<<'.,.,', 'parser.y', 411)
   def _reduce_72(val, _values, result)
         result = Array[val[0]]
@@ -2578,5 +2589,5 @@
 # reduce 73 omitted
 
-module_eval(<<'.,.,', 'parser.y', 414)
+module_eval(<<'.,.,', 'parser.y', 419)
   def _reduce_74(val, _values, result)
         result = val[1]
@@ -2588,5 +2599,5 @@
 # reduce 75 omitted
 
-module_eval(<<'.,.,', 'parser.y', 422)
+module_eval(<<'.,.,', 'parser.y', 427)
   def _reduce_76(val, _values, result)
         result = val[1]
@@ -2612,5 +2623,5 @@
 # reduce 84 omitted
 
-module_eval(<<'.,.,', 'parser.y', 442)
+module_eval(<<'.,.,', 'parser.y', 447)
   def _reduce_85(val, _values, result)
         dadl_section = val[1]
@@ -2629,5 +2640,5 @@
 # reduce 89 omitted
 
-module_eval(<<'.,.,', 'parser.y', 457)
+module_eval(<<'.,.,', 'parser.y', 462)
   def _reduce_90(val, _values, result)
         result = Array[val[0]]
@@ -2637,5 +2648,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 461)
+module_eval(<<'.,.,', 'parser.y', 466)
   def _reduce_91(val, _values, result)
         result = (val[0] << val[1])
@@ -2645,5 +2656,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 465)
+module_eval(<<'.,.,', 'parser.y', 470)
   def _reduce_92(val, _values, result)
         result = (val[0] << val[2])
@@ -2653,5 +2664,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 470)
+module_eval(<<'.,.,', 'parser.y', 475)
   def _reduce_93(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: attr_id = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
@@ -2662,5 +2673,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 476)
+module_eval(<<'.,.,', 'parser.y', 481)
   def _reduce_94(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2673,5 +2684,5 @@
 # reduce 95 omitted
 
-module_eval(<<'.,.,', 'parser.y', 483)
+module_eval(<<'.,.,', 'parser.y', 488)
   def _reduce_96(val, _values, result)
         result = val[0]
@@ -2681,5 +2692,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 487)
+module_eval(<<'.,.,', 'parser.y', 492)
   def _reduce_97(val, _values, result)
         result = val[0]
@@ -2689,5 +2700,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 492)
+module_eval(<<'.,.,', 'parser.y', 497)
   def _reduce_98(val, _values, result)
         result = val[0]
@@ -2697,5 +2708,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 496)
+module_eval(<<'.,.,', 'parser.y', 501)
   def _reduce_99(val, _values, result)
         result = val[0]
@@ -2705,5 +2716,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 501)
+module_eval(<<'.,.,', 'parser.y', 506)
   def _reduce_100(val, _values, result)
         result = {:untyped_multiple_attr_object_block => val[0]}
@@ -2713,5 +2724,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 505)
+module_eval(<<'.,.,', 'parser.y', 510)
   def _reduce_101(val, _values, result)
         result = {:type_identifier => val[0], :untyped_multiple_attr_object_block => val[1]}
@@ -2721,5 +2732,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 510)
+module_eval(<<'.,.,', 'parser.y', 515)
   def _reduce_102(val, _values, result)
         result = {:multiple_attr_object_block_head => val[0], :keyed_objects => val[1]}
@@ -2729,5 +2740,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 515)
+module_eval(<<'.,.,', 'parser.y', 520)
   def _reduce_103(val, _values, result)
         @@log.info("SYM_START_DBLOCK: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2738,5 +2749,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 521)
+module_eval(<<'.,.,', 'parser.y', 526)
   def _reduce_104(val, _values, result)
         result = Array[val[0]]
@@ -2746,5 +2757,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 525)
+module_eval(<<'.,.,', 'parser.y', 530)
   def _reduce_105(val, _values, result)
         result = (val[0] << val[1])
@@ -2754,5 +2765,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 530)
+module_eval(<<'.,.,', 'parser.y', 535)
   def _reduce_106(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: keyed_object = #{val[0]}, object_block = #{val[2]} at #{@filename}:#{@lineno}")
@@ -2763,5 +2774,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 536)
+module_eval(<<'.,.,', 'parser.y', 541)
   def _reduce_107(val, _values, result)
         @@log.info("object_key: [#{val[1]}] at #{@filename}:#{@lineno}")
@@ -2772,5 +2783,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 542)
+module_eval(<<'.,.,', 'parser.y', 547)
   def _reduce_108(val, _values, result)
         result = {:untyped_single_attr_object_block => val[0]}
@@ -2780,5 +2791,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 546)
+module_eval(<<'.,.,', 'parser.y', 551)
   def _reduce_109(val, _values, result)
         result = {:type_identifier => val[0], :untyped_single_attr_object_block => val[1]}
@@ -2788,5 +2799,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 551)
+module_eval(<<'.,.,', 'parser.y', 556)
   def _reduce_110(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2797,5 +2808,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 556)
+module_eval(<<'.,.,', 'parser.y', 561)
   def _reduce_111(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]}, attr_vals = #{val[1]} at #{@filename}:#{@lineno}")
@@ -2808,5 +2819,5 @@
 # reduce 112 omitted
 
-module_eval(<<'.,.,', 'parser.y', 562)
+module_eval(<<'.,.,', 'parser.y', 567)
   def _reduce_113(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: untyped_primitive_object_block = #{val[0]} at #{@filename}:#{@lineno}")
@@ -2817,5 +2828,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 567)
+module_eval(<<'.,.,', 'parser.y', 572)
   def _reduce_114(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: type_identifier = #{val[0]}, untyped_primitive_object_block = #{val[1]} at #{@filename}:#{@lineno}")
@@ -2826,5 +2837,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 572)
+module_eval(<<'.,.,', 'parser.y', 577)
   def _reduce_115(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: primitive_object_block = <#{val[1]}> at #{@filename}:#{@lineno}")
@@ -2835,5 +2846,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 577)
+module_eval(<<'.,.,', 'parser.y', 582)
   def _reduce_116(val, _values, result)
         result = val[0]
@@ -2843,5 +2854,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 581)
+module_eval(<<'.,.,', 'parser.y', 586)
   def _reduce_117(val, _values, result)
         result = val[0]
@@ -2851,5 +2862,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 585)
+module_eval(<<'.,.,', 'parser.y', 590)
   def _reduce_118(val, _values, result)
         result = val[0]
@@ -2859,5 +2870,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 589)
+module_eval(<<'.,.,', 'parser.y', 594)
   def _reduce_119(val, _values, result)
         result = val[0]
@@ -2867,5 +2878,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 593)
+module_eval(<<'.,.,', 'parser.y', 598)
   def _reduce_120(val, _values, result)
         result = val[0]
@@ -2875,5 +2886,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 597)
+module_eval(<<'.,.,', 'parser.y', 602)
   def _reduce_121(val, _values, result)
         @@log.info("string_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2884,5 +2895,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 602)
+module_eval(<<'.,.,', 'parser.y', 607)
   def _reduce_122(val, _values, result)
         @@log.info("integer_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2893,5 +2904,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 607)
+module_eval(<<'.,.,', 'parser.y', 612)
   def _reduce_123(val, _values, result)
         @@log.info("real_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2902,5 +2913,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 612)
+module_eval(<<'.,.,', 'parser.y', 617)
   def _reduce_124(val, _values, result)
         @@log.info("boolean_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2911,5 +2922,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 617)
+module_eval(<<'.,.,', 'parser.y', 622)
   def _reduce_125(val, _values, result)
         @@log.info("character_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2920,5 +2931,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 622)
+module_eval(<<'.,.,', 'parser.y', 627)
   def _reduce_126(val, _values, result)
         @@log.info("date_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2929,5 +2940,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 627)
+module_eval(<<'.,.,', 'parser.y', 632)
   def _reduce_127(val, _values, result)
         @@log.info("time_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2938,5 +2949,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 632)
+module_eval(<<'.,.,', 'parser.y', 637)
   def _reduce_128(val, _values, result)
         @@log.info("date_time_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2947,5 +2958,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 637)
+module_eval(<<'.,.,', 'parser.y', 642)
   def _reduce_129(val, _values, result)
         @@log.info("duration_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2956,5 +2967,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 642)
+module_eval(<<'.,.,', 'parser.y', 647)
   def _reduce_130(val, _values, result)
         @@log.info("uri_value: #{val[0]} at #{@filename}:#{@lineno}")
@@ -2995,5 +3006,5 @@
 # reduce 145 omitted
 
-module_eval(<<'.,.,', 'parser.y', 665)
+module_eval(<<'.,.,', 'parser.y', 670)
   def _reduce_146(val, _values, result)
         @@log.info("V_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
@@ -3004,5 +3015,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 670)
+module_eval(<<'.,.,', 'parser.y', 675)
   def _reduce_147(val, _values, result)
         @@log.info("V_GENERIC_TYPE_IDENTIFIER: #{val[0]} at #{@filename}:#{@lineno}")
@@ -3013,5 +3024,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 676)
+module_eval(<<'.,.,', 'parser.y', 681)
   def _reduce_148(val, _values, result)
         @@log.info("V_STRING: #{val[0]} at #{@filename}:#{@lineno}")
@@ -3028,5 +3039,5 @@
 # reduce 151 omitted
 
-module_eval(<<'.,.,', 'parser.y', 686)
+module_eval(<<'.,.,', 'parser.y', 691)
   def _reduce_152(val, _values, result)
         begin
@@ -3041,5 +3052,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 695)
+module_eval(<<'.,.,', 'parser.y', 700)
   def _reduce_153(val, _values, result)
         begin
@@ -3054,5 +3065,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 704)
+module_eval(<<'.,.,', 'parser.y', 709)
   def _reduce_154(val, _values, result)
         begin
@@ -3091,5 +3102,5 @@
 # reduce 166 omitted
 
-module_eval(<<'.,.,', 'parser.y', 730)
+module_eval(<<'.,.,', 'parser.y', 735)
   def _reduce_167(val, _values, result)
         begin
@@ -3104,5 +3115,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 739)
+module_eval(<<'.,.,', 'parser.y', 744)
   def _reduce_168(val, _values, result)
         begin
@@ -3117,5 +3128,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 748)
+module_eval(<<'.,.,', 'parser.y', 753)
   def _reduce_169(val, _values, result)
         begin
@@ -3154,5 +3165,5 @@
 # reduce 181 omitted
 
-module_eval(<<'.,.,', 'parser.y', 773)
+module_eval(<<'.,.,', 'parser.y', 778)
   def _reduce_182(val, _values, result)
         result = true
@@ -3162,5 +3173,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 777)
+module_eval(<<'.,.,', 'parser.y', 782)
   def _reduce_183(val, _values, result)
         result = false
@@ -3262,5 +3273,5 @@
 # reduce 229 omitted
 
-module_eval(<<'.,.,', 'parser.y', 840)
+module_eval(<<'.,.,', 'parser.y', 845)
   def _reduce_230(val, _values, result)
         @@log.info("V_ISO8601_DURATION: #{val[0]} at #{@filename}:#{@lineno}")
@@ -3295,5 +3306,5 @@
 # reduce 242 omitted
 
-module_eval(<<'.,.,', 'parser.y', 860)
+module_eval(<<'.,.,', 'parser.y', 865)
   def _reduce_243(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: V_QUALIFIED_TERM_CODE_REF = #{val[0]} at #{@filename}:#{@lineno}")
@@ -3310,5 +3321,5 @@
 # reduce 246 omitted
 
-module_eval(<<'.,.,', 'parser.y', 870)
+module_eval(<<'.,.,', 'parser.y', 875)
   def _reduce_247(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}: V_URI = #{val[0]} at #{@filename}:#{@lineno}")
@@ -3399,5 +3410,5 @@
 # reduce 287 omitted
 
-module_eval(<<'.,.,', 'parser.y', 940)
+module_eval(<<'.,.,', 'parser.y', 945)
   def _reduce_288(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
@@ -3407,5 +3418,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 944)
+module_eval(<<'.,.,', 'parser.y', 949)
   def _reduce_289(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{val[0]} at #{@filename}") 
@@ -3415,5 +3426,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 955)
+module_eval(<<'.,.,', 'parser.y', 960)
   def _reduce_290(val, _values, result)
         result = Range.new(1,1)
@@ -3423,5 +3434,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 959)
+module_eval(<<'.,.,', 'parser.y', 964)
   def _reduce_291(val, _values, result)
         result = val[3]
@@ -3431,5 +3442,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 964)
+module_eval(<<'.,.,', 'parser.y', 969)
   def _reduce_292(val, _values, result)
         begin
@@ -3444,5 +3455,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 973)
+module_eval(<<'.,.,', 'parser.y', 978)
   def _reduce_293(val, _values, result)
         begin
@@ -3458,5 +3469,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 984)
+module_eval(<<'.,.,', 'parser.y', 989)
   def _reduce_294(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::CARDINALITY.new
@@ -3482,5 +3493,5 @@
 # reduce 302 omitted
 
-module_eval(<<'.,.,', 'parser.y', 998)
+module_eval(<<'.,.,', 'parser.y', 1003)
   def _reduce_303(val, _values, result)
         result = val[0]
@@ -3490,5 +3501,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1002)
+module_eval(<<'.,.,', 'parser.y', 1007)
   def _reduce_304(val, _values, result)
         result = val[0]
@@ -3500,5 +3511,5 @@
 # reduce 305 omitted
 
-module_eval(<<'.,.,', 'parser.y', 1009)
+module_eval(<<'.,.,', 'parser.y', 1014)
   def _reduce_306(val, _values, result)
         result = val[3]
@@ -3600,5 +3611,5 @@
 # reduce 352 omitted
 
-module_eval(<<'.,.,', 'parser.y', 1079)
+module_eval(<<'.,.,', 'parser.y', 1084)
   def _reduce_353(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true)
@@ -3608,5 +3619,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1083)
+module_eval(<<'.,.,', 'parser.y', 1088)
   def _reduce_354(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false)
@@ -3616,5 +3627,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1087)
+module_eval(<<'.,.,', 'parser.y', 1092)
   def _reduce_355(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => true,:false_valid => false)
@@ -3624,5 +3635,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1091)
+module_eval(<<'.,.,', 'parser.y', 1096)
   def _reduce_356(val, _values, result)
         result = OpenEHR::AM::Archetype::Constraint_Model::Primitive::C_BOOLEAN.new(:true_valid => false,:false_valid => true)
@@ -3632,5 +3643,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1096)
+module_eval(<<'.,.,', 'parser.y', 1101)
   def _reduce_357(val, _values, result)
         result = val[0]
@@ -3640,5 +3651,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1100)
+module_eval(<<'.,.,', 'parser.y', 1105)
   def _reduce_358(val, _values, result)
         raise 'Not implemented yet'
@@ -3648,5 +3659,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1104)
+module_eval(<<'.,.,', 'parser.y', 1109)
   def _reduce_359(val, _values, result)
         raise 'Not implemented yet'
@@ -3666,5 +3677,5 @@
 # reduce 364 omitted
 
-module_eval(<<'.,.,', 'parser.y', 1116)
+module_eval(<<'.,.,', 'parser.y', 1121)
   def _reduce_365(val, _values, result)
         @in_interval = false
@@ -3675,5 +3686,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1123)
+module_eval(<<'.,.,', 'parser.y', 1128)
   def _reduce_366(val, _values, result)
           result = val[0]
@@ -3683,5 +3694,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1127)
+module_eval(<<'.,.,', 'parser.y', 1132)
   def _reduce_367(val, _values, result)
           result = val[0]
@@ -3699,5 +3710,5 @@
 # reduce 371 omitted
 
-module_eval(<<'.,.,', 'parser.y', 1142)
+module_eval(<<'.,.,', 'parser.y', 1147)
   def _reduce_372(val, _values, result)
           result = val[0]
@@ -3707,5 +3718,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1147)
+module_eval(<<'.,.,', 'parser.y', 1152)
   def _reduce_373(val, _values, result)
           result = val[0]
@@ -3715,5 +3726,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1151)
+module_eval(<<'.,.,', 'parser.y', 1156)
   def _reduce_374(val, _values, result)
         @@log.info("#{__FILE__}:#{__LINE__}, V_ATTRIBUTE_IDENTIFIER = #{word} at #{@filename}")
@@ -3724,5 +3735,5 @@
 .,.,
 
-module_eval(<<'.,.,', 'parser.y', 1162)
+module_eval(<<'.,.,', 'parser.y', 1167)
   def _reduce_375(val, _values, result)
         result = val[0]
Index: /ruby/trunk/lib/adl_parser/lib/parser.y
===================================================================
--- /ruby/trunk/lib/adl_parser/lib/parser.y	(revision 256)
+++ /ruby/trunk/lib/adl_parser/lib/parser.y	(revision 257)
@@ -40,4 +40,5 @@
     
     archetype_id = val[0][:archetype_id]
+    parent_archtype_id = val[1][:parent_archtype_id] if val[1]
     adl_version = val[0][:arch_head][:arch_meta_data][:adl_version]
     concept = val[2]
@@ -45,4 +46,5 @@
     archetype = OpenEHR::AM::Archetype::ARCHETYPE.create(
                                                          :archetype_id => archetype_id,
+                                                         :parent_archtype_id => parent_archtype_id,
                                                          :adl_version => adl_version,
                                                          :concept => concept,
@@ -104,4 +106,7 @@
 arch_specialisation: #-- empty is ok
   | SYM_SPECIALIZE V_ARCHETYPE_ID
+  {
+    result = {:parent_archtype_id => val[1]}
+  }
   | SYM_SPECIALIZE error
 
@@ -548,5 +553,5 @@
   }
 
-untyped_single_attr_object_block: single_attr_object_complex_head SYM_END_DBLOCK # <>
+untyped_single_attr_object_block: single_attr_object_complex_head SYM_END_DBLOCK # >
   {
     @@log.info("#{__FILE__}:#{__LINE__}: single_attr_object_complex_head = #{val[0]} at #{@filename}:#{@lineno}")
@@ -1171,10 +1176,9 @@
 $:.unshift File.join(File.dirname(__FILE__))
 require 'logger'
-#require 'lib/util.rb'
-#require 'lib/scanner.rb'
-require 'lib/adl_parser.rb'
+#require 'lib/adl_parser.rb'
 require 'rubygems'
+require 'adl_parser.rb'
 require 'am.rb'
-$DEBUG = false
+require 'rm.rb'
 
 
@@ -1308,6 +1312,10 @@
       when /\A[A-Z][a-zA-Z0-9_]*/
         yield :V_TYPE_IDENTIFIER, $&
-      when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/   #V_ARCHETYPE_ID
-        yield :V_ARCHETYPE_ID, $&
+#      when /\A[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z][a-zA-Z0-9_-]+\.[a-zA-Z0-9]+/   #V_ARCHETYPE_ID
+      when /\A(\w+)-(\w+)-(\w+)\.(\w+)(-\w+)?\.(v[0-9]+)/   #V_ARCHETYPE_ID
+        object_id, rm_originator, rm_name, rm_entity, concept_name, specialisation, version_id = $&, $1, $2, $3, $4, $5, $6
+        archetype_id = OpenEHR::RM::Support::Identification::Archetype_ID.new(object_id, concept_name, rm_name, rm_entity, rm_originator, specialisation, version_id)
+#        yield :V_ARCHETYPE_ID, $&
+        yield :V_ARCHETYPE_ID, archetype_id
       when /\A[a-z][a-zA-Z0-9_]*/
 #        word = $&.downcase
@@ -1391,5 +1399,5 @@
         yield :Question_mark_code, :Question_mark_code
       when /\A[0-9]+\.[0-9]+(\.[0-9]+)*/   # ?
-        yield :V_VERSION_STRING, :V_VERSION_STRING
+        yield :V_VERSION_STRING, $&
       when /\A\|/   # |
         if @in_interval
@@ -1409,4 +1417,6 @@
         yield :Right_bracket_code, :Right_bracket_code
 
+      when /\A"([^"]*)"/m #V_STRING
+        yield :V_STRING, $1
       when /\A\[[a-zA-Z0-9._\- ]+::[a-zA-Z0-9._\- ]+\]/   #ERR_V_QUALIFIED_TERM_CODE_REF
         yield :ERR_V_QUALIFIED_TERM_CODE_REF, $&
@@ -1426,6 +1436,4 @@
         yield :V_REAL, $&
         #    when /\A"((?:[^"\\]+|\\.)*)"/ #V_STRING
-      when /\A"([^"]*)"/m #V_STRING
-        yield :V_STRING, $1
       when /\A[a-z]+:\/\/[^<>|\\{}^~"\[\] ]*/ #V_URI
         yield :V_URI, $&
Index: /ruby/trunk/lib/adl_parser/test/adl/openEHR-EHR-OBSERVATION.body_mass_index.v1.adl
===================================================================
--- /ruby/trunk/lib/adl_parser/test/adl/openEHR-EHR-OBSERVATION.body_mass_index.v1.adl	(revision 257)
+++ /ruby/trunk/lib/adl_parser/test/adl/openEHR-EHR-OBSERVATION.body_mass_index.v1.adl	(revision 257)
@@ -0,0 +1,162 @@
+archetype (adl_version=1.4)
+	openEHR-EHR-OBSERVATION.body_mass_index.v1
+
+concept
+	[at0000]	-- Body mass index
+language
+	original_language = <[ISO_639-1::en]>
+description
+	original_author = <
+		["name"] = <"Sam Heard">
+		["organisation"] = <"Ocean Informatics">
+		["email"] = <"sam.heard@oceaninformatics.com">
+		["date"] = <"22/03/2006">
+	>
+	details = <
+		["en"] = <
+			language = <[ISO_639-1::en]>
+			purpose = <"To record the Body Mass Index (BMI) of a person.
+Body Mass Index is a calculated ratio describing how an individual's body weight relates to the weight that is regarded as normal, or desirable, for the individual's height. ">
+			use = <"Use to record the Body Mass Index of both adults and children.  
+Use to enter the Body Mass Index either manually (ie calculated and directly entered by the clinician), or automatically (ie calculation and entry is done automatically by a software application, based on separate height and weight measurements).
+Formulas: Body Mass Index is commonly calculated as weight (kg) / [height (m) squared]. This is the assumed formula unless otherwise specified in the Formula element within Protocol. Alternatively estimate Body Mass Index using pounds and inches: weight (lb) / [height (in) squared] x 703 (with ounces (oz) and fractions changed to decimal values).
+In some situations the Body Mass Index formula is corrected eg for use in amputees - this specific formula can be recorded as part of the protocol.  Alternatively the common Body Mass Index calculation can be used with amputees and similar injuries or disabilities if using adjusted height and/or adjusted weight, as appropriate, rather than actual height and weight.   See openEHR-EHR-OBSERVATION.height-adjusted and openEHR-EHR-OBSERVATION.body_weight-adjusted.
+See WHO reference re adjusting height/length for Body Mass Index in paediatrics. 
+In children and teens, BMI needs to be assessed using age-related reference charts. 
+">
+			keywords = <"obesity", "index", "body mass", "BMI", "anorexia", "Quetelet", "malnutrition", "failure to thrive", "bulimia">
+			misuse = <"Not intended to record information regarding Body Mass Index percentiles - these will be recorded in separate archetypes.">
+			copyright = <"copyright (c) 2009 openEHR Foundation">
+		>
+	>
+	lifecycle_state = <"Initial">
+	other_contributors = <"Marja Buur, Medisch Centrum Alkmaar, Netherlands", "Rong Chen, Cambio Healthcare Systems, Sweden", "Angela de Zwart, Orion Health, New Zealand", "Paul Donaldson, Nursing Informatics Australia, Australia", "Sebastian Garde, Ocean Informatics, Germany", "Heather Grain, Llewelyn Grain Informatics, Australia", "Anne Harbison, CPCER, Australia", "Sam Heard, Ocean Informatics, Australia", "Andrew James, University of Toronto, Canada", "Shinji Kobayashi, Ehime University, Japan", "Heather Leslie, Ocean Informatics, Australia (Editor)", "Rikard Lovstrom, Swedish Medical Association, Sweden", "Ian McNicoll, Ocean Informatics, United Kingdom", "Jeroen Meintjens, Medisch Centrum Alkmaar, Netherlands", "Arturo Romero, SESCAM, Spain", "Soon Ghee Yap, Singapore Health Services Pte Ltd, Singapore">
+	other_details = <
+		["MD5-CAM-1.0.1"] = <"1605E211E9BFB4093A72CCE7A9792FF9">
+		["references"] = <"Clinical Guidelines on the Identification, Evaluation, and Treatment of Overweight and Obesity in Adults: The Evidence Report [Internet]. Bethesda (MD): National Heart, Lung, and Blood Institute; NIH Publication No. 98-4083, Sep 1998, [cited 2009 July 02]. Available from: http://www.nhlbi.nih.gov/guidelines/obesity/
+
+About BMI for Children and Teens [Internet]. Atlanta (GA): Division of Nutrition, Physical Activity and Obesity, Centers for Disease Control and Prevention; 2009 Jan 27 [cited 2009 Jul 28 ]. Available from: http://www.cdc.gov/healthyweight/assessing/bmi/childrens_BMI/about_childrens_BMI.html
+
+WHO Child Growth Standards: Length/height-for-age, weight-for-age, weight-for-length, weight-for-height and body mass index-for-age: Methods and development. [Internet] Geneva, Switzerland: WHO Multicentre Growth Reference Study Group, World Health Organization; 2006 [cited 2009 July 02].  Chapter 6, BMI-for-age standards. Available from: http://www.who.int/childgrowth/standards/Chap_6.pdf.
+
+Obesity: Preventing and Managing the Global Epidemic: Report of a WHO Consultation [Internet]. Geneva, Switzerland: World Health Organisation; 2000 [cited 2009 Jul 28]. Available from: http://www.who.int/nutrition/publications/obesity/WHO_TRS_894/en/index.html
+
+Tzamaloukas AH, Patron A, Malhotra D. Body Mass Index in Amputees. Journal of Parenteral and Enteral Nutrition [Internet]. 1994 [cited 2009 Jul 28]; 18 (4): 355. Available from: http://pen.sagepub.com/cgi/content/abstract/18/4/355">
+       >
+
+definition
+	OBSERVATION[at0000] matches {	-- Body mass index
+		data matches {
+			HISTORY[at0001] matches {	-- history
+				events cardinality matches {1..*; unordered} matches {
+					EVENT[at0002] occurrences matches {1..*} matches {	-- Any event
+						data matches {
+							ITEM_TREE[at0003] matches {	-- Single
+								items cardinality matches {1..*; unordered} matches {
+									ELEMENT[at0004] matches {	-- Body Mass Index
+										value matches {
+											C_DV_QUANTITY <
+												property = <[openehr::349]>
+												list = <
+													["1"] = <
+														units = <"kg/m2">
+														magnitude = <|0.0..<1000.0|>
+														precision = <|1|>
+													>
+													["2"] = <
+														units = <"lb/in2">
+														magnitude = <|0.0..<1000.0|>
+														precision = <|1|>
+													>
+												>
+											>
+										}
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+		protocol matches {
+			ITEM_LIST[at0005] matches {	-- List
+				items cardinality matches {0..*; ordered} matches {
+					ELEMENT[at0006] occurrences matches {0..1} matches {	-- Method
+						value matches {
+							DV_CODED_TEXT matches {
+								defining_code matches {
+									[local::
+									at0007, 	-- Automatic entry
+									at0008]	-- Direct entry
+								}
+							}
+						}
+					}
+					ELEMENT[at0010] occurrences matches {0..1} matches {	-- Formula
+						value matches {
+							DV_TEXT matches {*}
+						}
+					}
+					ELEMENT[at0011] occurrences matches {0..1} matches {	-- Comment
+						value matches {
+							DV_TEXT matches {*}
+						}
+					}
+				}
+			}
+		}
+	}
+
+
+ontology
+	term_definitions = <
+		["en"] = <
+			items = <
+				["at0000"] = <
+					text = <"Body mass index">
+					description = <"Calculated measurement which compares a person's weight and height.">
+				>
+				["at0001"] = <
+					text = <"history">
+					description = <"@ internal @">
+				>
+				["at0002"] = <
+					text = <"Any event">
+					description = <"Any timed recording of Body Mass Index.">
+				>
+				["at0003"] = <
+					text = <"Single">
+					description = <"@ internal @">
+				>
+				["at0004"] = <
+					text = <"Body Mass Index">
+					description = <"Index describing ratio of weight to height.">
+				>
+				["at0005"] = <
+					text = <"List">
+					description = <"@ internal @">
+				>
+				["at0006"] = <
+					text = <"Method">
+					description = <"The method of entering the Body Mass Index.">
+				>
+				["at0007"] = <
+					text = <"Automatic entry">
+					description = <"Body Mass Index calculated and entered automatically without user intervention.">
+				>
+				["at0008"] = <
+					text = <"Direct entry">
+					description = <"Body Mass Index calculated and entered directly by user.">
+				>
+				["at0010"] = <
+					text = <"Formula">
+					description = <"Formula used to derive the Body Mass Index.">
+				>
+				["at0011"] = <
+					text = <"Comment">
+					description = <"Comment about the Body Mass Index measurement eg noting that the measurements used were adjusted weight/height.">
+				>
+			>
+		>
+	>
Index: /ruby/trunk/lib/adl_parser/test/parser_test.rb
===================================================================
--- /ruby/trunk/lib/adl_parser/test/parser_test.rb	(revision 256)
+++ /ruby/trunk/lib/adl_parser/test/parser_test.rb	(revision 257)
@@ -1,9 +1,9 @@
-#require 'lib/parser.rb'
-require 'lib/adl_parser.rb'
-require 'test/unit'
+#require 'lib/adl_parser.rb'
+require File.dirname(__FILE__) + '/test_helper.rb'
 
 class ADLParserTest < Test::Unit::TestCase
   def setup
     @parser = ::OpenEHR::ADL::Parser.new
+    $DEBUG = false
   end
 
@@ -13,4 +13,11 @@
 
   def test_parse
+#    body_mass_index = File.read(File.dirname(__FILE__) + '/adl/openEHR-EHR-OBSERVATION.body_mass_index.v1.adl')
+    body_mass_index = File.read('test/adl/openEHR-EHR-OBSERVATION.body_mass_index.v1.adl')
+    assert_nothing_raised do
+      ast = @parser.parse(body_mass_index, 'openEHR-EHR-OBSERVATION.body_mass_index.v1.adl')
+      assert_instance_of OpenEHR::RM::Support::Identification::Archetype_ID, ast.archetype_id
+    end
+
     laboratory_request = File.read('test/adl/openEHR-EHR-ITEM_TREE.Laboratory_request.v1.adl')
     assert_nothing_raised do
@@ -19,5 +26,4 @@
       assert_instance_of OpenEHR::AM::Archetype::Archetype_Description::ARCHETYPE_DESCRIPTION, result.description
       assert_instance_of OpenEHR::AM::Archetype::Constraint_Model::C_COMPLEX_OBJECT, result.definition
-#      assert_equal '', result.definition
     end
 
@@ -61,86 +67,88 @@
       @parser.parse(exam_nervous_system, 'openEHR-EHR-CLUSTER.exam-nervous_system.v1.adl')
     end
+
     exam_generic = File.read('test/adl/openEHR-EHR-CLUSTER.exam-generic.v1.adl')
     assert_nothing_raised do
       @parser.parse(exam_generic, 'openEHR-EHR-CLUSTER.exam-generic.v1.adl')
     end
-    exam_generic_mass = File.read('test/adl/openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(exam_generic_mass, 'openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
-    end
-    exam_generic_lymphnode = File.read('test/adl/openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(exam_generic_lymphnode, 'openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
-    end
-    exam_generic_joint = File.read('test/adl/openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(exam_generic_joint, 'openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
-    end
-    exam_chest = File.read('test/adl/openEHR-EHR-CLUSTER.exam-chest.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(exam_chest, 'openEHR-EHR-CLUSTER.exam-chest.v1.adl')
-    end
-    exam_abdomen = File.read('test/adl/openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(exam_abdomen, 'openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
-    end
-    cluster_auscultation = File.read('test/adl/openEHR-EHR-CLUSTER.auscultation.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(cluster_auscultation, 'openEHR-EHR-CLUSTER.auscultation.v1.adl')
-    end
-    cluster_auscultation_chest = File.read('test/adl/openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(cluster_auscultation_chest, 'openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
-    end
-    vital_signs = File.read('test/adl/openEHR-EHR-SECTION.vital_signs.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(vital_signs, 'openEHR-EHR-SECTION.vital_signs.v1')
-    end
-    summary = File.read('test/adl/openEHR-EHR-SECTION.summary.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(summary, 'openEHR-EHR-SECTION.summary.v1.adl')
-    end
 
-    findings = File.read('test/adl/openEHR-EHR-SECTION.findings.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(findings, 'openEHR-EHR-SECTION.findings.v1.adl')
-    end
+#     exam_generic_mass = File.read('test/adl/openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(exam_generic_mass, 'openEHR-EHR-CLUSTER.exam-generic-mass.v1.adl')
+#     end
+#     exam_generic_lymphnode = File.read('test/adl/openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(exam_generic_lymphnode, 'openEHR-EHR-CLUSTER.exam-generic-lymphnode.v1.adl')
+#     end
+#     exam_generic_joint = File.read('test/adl/openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(exam_generic_joint, 'openEHR-EHR-CLUSTER.exam-generic-joint.v1.adl')
+#     end
+#     exam_chest = File.read('test/adl/openEHR-EHR-CLUSTER.exam-chest.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(exam_chest, 'openEHR-EHR-CLUSTER.exam-chest.v1.adl')
+#     end
+#     exam_abdomen = File.read('test/adl/openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(exam_abdomen, 'openEHR-EHR-CLUSTER.exam-abdomen.v1.adl')
+#     end
+#     cluster_auscultation = File.read('test/adl/openEHR-EHR-CLUSTER.auscultation.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(cluster_auscultation, 'openEHR-EHR-CLUSTER.auscultation.v1.adl')
+#     end
+#     cluster_auscultation_chest = File.read('test/adl/openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(cluster_auscultation_chest, 'openEHR-EHR-CLUSTER.auscultation-chest.v1.adl')
+#     end
+#     vital_signs = File.read('test/adl/openEHR-EHR-SECTION.vital_signs.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(vital_signs, 'openEHR-EHR-SECTION.vital_signs.v1')
+#     end
+#     summary = File.read('test/adl/openEHR-EHR-SECTION.summary.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(summary, 'openEHR-EHR-SECTION.summary.v1.adl')
+#     end
 
-    reason_for_encounter = File.read('test/adl/openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(reason_for_encounter, 'openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
-    end
+#     findings = File.read('test/adl/openEHR-EHR-SECTION.findings.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(findings, 'openEHR-EHR-SECTION.findings.v1.adl')
+#     end
 
-    imaging = File.read('test/adl/openEHR-EHR-ITEM_TREE.imaging.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(imaging, 'openEHR-EHR-ITEM_TREE.imaging.v1.adl')
-    end
-    instruction_referral = File.read('test/adl/openEHR-EHR-INSTRUCTION.referral.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(instruction_referral, 'openEHR-EHR-INSTRUCTION.referral.v1.adl')
-    end
-    instruction_medication = File.read('test/adl/openEHR-EHR-INSTRUCTION.medication.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(instruction_medication, 'openEHR-EHR-INSTRUCTION.medication.v1.adl')
-    end
-    action_referral = File.read('test/adl/openEHR-EHR-ACTION.referral.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(action_referral, 'openEHR-EHR-ACTION.referral.v1.adl')
-    end
+#     reason_for_encounter = File.read('test/adl/openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(reason_for_encounter, 'openEHR-EHR-SECTION.reason_for_encounter.v1.adl')
+#     end
 
-    dimensions_circumference = File.read('test/adl/openEHR-EHR-CLUSTER.dimensions.v1.adl')
-    assert_nothing_raised do
-      @parser.parse(dimensions_circumference, 'openEHR-EHR-CLUSTER.dimensions.v1.adl')
-    end
+#     imaging = File.read('test/adl/openEHR-EHR-ITEM_TREE.imaging.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(imaging, 'openEHR-EHR-ITEM_TREE.imaging.v1.adl')
+#     end
+#     instruction_referral = File.read('test/adl/openEHR-EHR-INSTRUCTION.referral.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(instruction_referral, 'openEHR-EHR-INSTRUCTION.referral.v1.adl')
+#     end
+#     instruction_medication = File.read('test/adl/openEHR-EHR-INSTRUCTION.medication.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(instruction_medication, 'openEHR-EHR-INSTRUCTION.medication.v1.adl')
+#     end
+#     action_referral = File.read('test/adl/openEHR-EHR-ACTION.referral.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(action_referral, 'openEHR-EHR-ACTION.referral.v1.adl')
+#     end
 
-    discharge = File.read('test/adl/openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
-    assert_nothing_raised do
-      @parser.parse(discharge, 'openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
-    end
+#     dimensions_circumference = File.read('test/adl/openEHR-EHR-CLUSTER.dimensions.v1.adl')
+#     assert_nothing_raised do
+#       @parser.parse(dimensions_circumference, 'openEHR-EHR-CLUSTER.dimensions.v1.adl')
+#     end
 
-    encounter = File.read('test/adl/openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
-    assert_nothing_raised do
-      @parser.parse(encounter, 'openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
-    end
+#     discharge = File.read('test/adl/openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
+#     assert_nothing_raised do
+#       @parser.parse(discharge, 'openEHR-EHR-COMPOSITION.discharge.v1draft.adl')
+#     end
+
+#     encounter = File.read('test/adl/openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
+#     assert_nothing_raised do
+#       @parser.parse(encounter, 'openEHR-EHR-COMPOSITION.encounter.v1draft.adl')
+#     end
 
 
Index: /ruby/trunk/lib/adl_parser/test/test_helper.rb
===================================================================
--- /ruby/trunk/lib/adl_parser/test/test_helper.rb	(revision 257)
+++ /ruby/trunk/lib/adl_parser/test/test_helper.rb	(revision 257)
@@ -0,0 +1,7 @@
+require 'test/unit'
+
+$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
+require "rubygems"
+require 'adl_parser.rb'
+require 'rm.rb'
+require 'am.rb'
Index: /ruby/trunk/lib/models/Rakefile
===================================================================
--- /ruby/trunk/lib/models/Rakefile	(revision 256)
+++ /ruby/trunk/lib/models/Rakefile	(revision 257)
@@ -41,4 +41,5 @@
   s.email = 'openehr-jp@openehr.jp'
   s.test_files = FileList['tests/test_*.rb', '*.adl']
+
   candidates = Dir.glob("{am,rm,docs,tests}/**/*") + FileList['COPYING', 'Rakefile','am.rb','assumed_library_types.rb','rm.rb']
   s.files = candidates.delete_if do |item|
Index: /ruby/trunk/lib/models/am/archetype/archetype.rb
===================================================================
--- /ruby/trunk/lib/models/am/archetype/archetype.rb	(revision 256)
+++ /ruby/trunk/lib/models/am/archetype/archetype.rb	(revision 257)
@@ -21,5 +21,5 @@
           @adl_version = args[:adl_version] if args[:adl_version]
           @archetype_id = args[:archetype_id] ? args[:archetype_id] : nil
-          @parent_id = args[:parent_id] if args[:parent_id]
+          @parent_archtype_id = args[:parent_archtype_id] if args[:parent_archtype_id]
           @concept = args[:concept] if args[:concept]
           @is_controled = args[:is_controled] if args[:is_controled]
Index: /ruby/trunk/lib/models/rm/support/identification.rb
===================================================================
--- /ruby/trunk/lib/models/rm/support/identification.rb	(revision 256)
+++ /ruby/trunk/lib/models/rm/support/identification.rb	(revision 257)
@@ -82,5 +82,5 @@
 
           def specialisation=(specialisation)
-            raise ArgumentError, "rm_specialisation not valid" if specialisation.nil? or specialisation.empty?
+#            raise ArgumentError, "rm_specialisation not valid" if specialisation.nil? or specialisation.empty?
             @specialisation = specialisation
           end
