void ReadCArchetypeRoot(XmlReader reader, CArchetypeRoot node)
        {
            ReadCComplexObject(reader, node);

            ArchetypeId archetypeId = new ArchetypeId();

            archetypeId.ReadXml(reader);
            node.ArchetypeId = archetypeId;

            if (reader.LocalName == "template_id")
            {
                TemplateId templateId = new TemplateId();
                templateId.ReadXml(reader);
                node.TemplateId = templateId;
            }

            if (reader.LocalName == "default_values")
            {
                throw new NotImplementedException(CommonStrings.DefaultsSerialisationNotImplemented);
            }

            if (reader.LocalName == "term_definitions")
            {
                System.Collections.Generic.Dictionary <string, AM.Archetype.Ontology.ArchetypeTerm> termDefimitionItemDic
                    = new System.Collections.Generic.Dictionary <string, AM.Archetype.Ontology.ArchetypeTerm>();

                while (reader.LocalName == "term_definitions")
                {
                    AM.Archetype.Ontology.ArchetypeTerm archetypeTerm = new AM.Archetype.Ontology.ArchetypeTerm();
                    amSerializer.ReadArchetypeTerm(reader, archetypeTerm);

                    termDefimitionItemDic.Add(archetypeTerm.Code, archetypeTerm);
                }
                node.TermDefinitions
                    = new Hash <AM.Archetype.Ontology.ArchetypeTerm, string>(termDefimitionItemDic);
            }

            if (reader.LocalName == "term_bindings")
            {
                if (reader.IsEmptyElement)
                {
                    reader.Skip();
                    reader.MoveToContent();
                }
                else
                {
                    System.Collections.Generic.Dictionary <string, Hash <CodePhrase, string> > termBindingDic =
                        new System.Collections.Generic.Dictionary <string, Hash <CodePhrase, string> >();
                    do
                    {
                        System.Collections.Generic.Dictionary <string, CodePhrase> termBindingItemDic
                            = new System.Collections.Generic.Dictionary <string, CodePhrase>();

                        string terminologyString = reader.GetAttribute("terminology");
                        DesignByContract.Check.Assert(!string.IsNullOrEmpty(terminologyString), "terminologyString must not be null or empty.");

                        reader.ReadStartElement();
                        reader.MoveToContent();

                        while (reader.LocalName == "items")
                        {
                            string hashId = reader.GetAttribute("code");

                            reader.ReadStartElement();
                            reader.MoveToContent();

                            CodePhrase codePhrase = new CodePhrase();
                            codePhrase.ReadXml(reader);

                            reader.ReadEndElement();
                            reader.MoveToContent();

                            termBindingItemDic.Add(hashId, codePhrase);
                        }

                        reader.ReadEndElement();
                        reader.MoveToContent();

                        DesignByContract.Check.Assert(termBindingItemDic.Count > 0, "termBindingItemDic must not be empty.");

                        Hash <CodePhrase, string> termBindingItemHash
                            = new Hash <CodePhrase, string>(termBindingItemDic);

                        termBindingDic.Add(terminologyString, termBindingItemHash);
                    } while (reader.LocalName == "term_bindings");

                    DesignByContract.Check.Assert(termBindingDic.Count > 0, "termBindingDic must not be empty.");

                    node.TermBindings = new Hash <Hash <CodePhrase, string>, string>(termBindingDic);
                }
            }

            Check.Assert(reader.NodeType == System.Xml.XmlNodeType.EndElement, "Expected endElement of CArchetypeRoot");

            reader.ReadEndElement();
            reader.MoveToContent();
        }
        public void ReadOperationalTemplate(XmlReader reader, OperationalTemplate template)
        {
            Check.Require(reader != null, string.Format(CommonStrings.XMustNotBeNull, "reader"));
            Check.Require(template != null, string.Format(CommonStrings.XMustNotBeNull, "template"));

            reader.ReadStartElement();  //template
            reader.MoveToContent();

            CodePhrase language = new CodePhrase();

            language.ReadXml(reader);
            template.Language = language;

            if (reader.LocalName == "is_controlled")
            {
                reader.ReadElementContentAsBoolean("is_controlled", RmXmlSerializer.OpenEhrNamespace);
                reader.MoveToContent();
            }

            if (reader.LocalName == "description")
            {
                ResourceDescription description = new ResourceDescription();
                description.ReadXml(reader);
                template.Description = description;
            }

            if (reader.LocalName == "revision_history")
            {
                RevisionHistory revisionHistory = new RevisionHistory();
                revisionHistory.ReadXml(reader);
                template.RevisionHistory = revisionHistory;
            }

            if (reader.LocalName == "uid")
            {
                HierObjectId uid = new HierObjectId();
                uid.ReadXml(reader);
                template.Uid = uid;
            }

            TemplateId templateId = new TemplateId();

            templateId.ReadXml(reader);
            template.TemplateId = templateId;

            template.Concept = reader.ReadElementContentAsString("concept", RmXmlSerializer.OpenEhrNamespace);
            reader.MoveToContent();

            CArchetypeRoot definition = new CArchetypeRoot();

            ReadCArchetypeRoot(reader, definition);
            template.Definition = definition;

            // LMT added 12 May 2010 for TMP-1252
            if (reader.LocalName == "annotations")
            {
                template.Annotations =
                    new List <OpenEhr.RM.Common.Resource.Annotation>();
                OpenEhr.RM.Common.Resource.Annotation currentAnnotation;
                while (reader.LocalName == "annotations")
                {
                    currentAnnotation = ReadAnnotation(reader);
                    template.Annotations.Add(currentAnnotation);
                    reader.MoveToContent();
                }
            }

            if (reader.LocalName == "constraints")
            {
                TConstraint constraints = new TConstraint();
                ReadTConstraint(reader, constraints);
                template.Constraints = constraints;
            }

            if (reader.LocalName == "view")
            {
                TView view = new TView();
                ReadTView(reader, view);
                template.View = view;
            }

            reader.ReadEndElement();    // template
            reader.MoveToContent();
        }