protected virtual ARCHETYPE CloneArchetypeDetails(openehr.openehr.am.archetype.ARCHETYPE archetype)
        {
            ARCHETYPE result = new ARCHETYPE();

            if (archetype.uid() != null)
            {
                HIER_OBJECT_ID uid = new HIER_OBJECT_ID();
                uid.value = archetype.uid().value().ToString();
                result.uid = uid;
            }

            if (archetype.archetype_id() != null)
            {
                ARCHETYPE_ID archetypeId = new ARCHETYPE_ID();
                archetypeId.value = archetype.archetype_id().value().ToString();
                result.archetype_id = archetypeId;
            }

            if (archetype.version() != null)
                result.adl_version = archetype.adl_version().ToString();

            if (archetype.concept() != null)
                result.concept = archetype.concept().ToString();

            result.original_language = CloneCodePhrase(archetype.original_language());
            result.is_controlled = archetype.is_controlled();

            if (archetype.parent_archetype_id() != null)
            {
                ARCHETYPE_ID parentId = new ARCHETYPE_ID();
                parentId.value = archetype.parent_archetype_id().value().ToString();
                result.parent_archetype_id = parentId;
            }

            result.description = CloneDescription(archetype.description());
            result.ontology = CloneOntology(archetype.ontology());

            // 0..1 revision_history REVISION_HISTORY (does not occur in NHS archetypes, do later)
            //if (archetype.revision_history() != null)
            // result.revision_history = CloneAuthoredResource(archetype.revision_history());

            if (archetype.translations() != null && archetype.translations().count() >= 0)
            {
                TRANSLATION_DETAILS[] translations = new TRANSLATION_DETAILS[archetype.translations().count()];
                archetype.translations().start();

                for (int i = 1; i <= archetype.translations().count(); i++)
                {
                    TRANSLATION_DETAILS translation = new TRANSLATION_DETAILS();
                    openehr.openehr.rm.common.resource.TRANSLATION_DETAILS td = archetype.translations().item_for_iteration() as openehr.openehr.rm.common.resource.TRANSLATION_DETAILS;

                    if (td.accreditation() != null)
                        translation.accreditation = td.accreditation().ToString();

                    translation.author = CloneHashTableAny(td.author());
                    translation.language = CloneCodePhrase(td.language());
                    translation.other_details = CloneHashTableAny(td.other_details());
                    translations[i - 1] = translation;

                    archetype.translations().forth();
                }

                result.translations = translations;
            }

            result.invariants = CloneAssertion(archetype.invariants());

            return result;
        }
        /// <summary>
        /// canonicalise translations hash list
        /// </summary>
        TRANSLATION_DETAILS[] VisitTranslations(TRANSLATION_DETAILS[] translations)
        {
            TRANSLATION_DETAILS[] result = null;

            if (translations != null)
            {
                SortedDictionary<string, TRANSLATION_DETAILS> sortedTranslations = new SortedDictionary<string, TRANSLATION_DETAILS>();

                foreach (TRANSLATION_DETAILS translation in translations)
                {
                    if (translation == null)
                        throw new ApplicationException("translations list must not contain null");

                    TRANSLATION_DETAILS canonicalTranslation = new TRANSLATION_DETAILS();
                    canonicalTranslation.accreditation = translation.accreditation;
                    canonicalTranslation.language = translation.language;

                    // sort translations author hash list
                    canonicalTranslation.author = VisitStringDictionary(translation.author);

                    // sort translations other_details hash list
                    canonicalTranslation.other_details = VisitStringDictionary(translation.other_details);
                    sortedTranslations.Add(translation.language.code_string, canonicalTranslation);
                }

                result = new TRANSLATION_DETAILS[sortedTranslations.Count];
                sortedTranslations.Values.CopyTo(result, 0);
            }

            return result;
        }
        public void AddTranslation(CODE_PHRASE a_language)
        {
            TRANSLATION_DETAILS td = new TRANSLATION_DETAILS();
            TRANSLATION_DETAILS[] translationDetails;
            td.language = a_language;

            if (_archetype.translations == null)
            {
                //create an array
                translationDetails = Array.CreateInstance(typeof(TRANSLATION_DETAILS), 1) as TRANSLATION_DETAILS[];
                translationDetails[0] = td;
            }
            else
            {
                //resize the array
                translationDetails = _archetype.translations;
                int i = translationDetails.Length;
                Array.Resize(ref translationDetails, i + 1);
                translationDetails[i] = td;
            }

            _archetype.translations = translationDetails;    
        }