ARCHETYPE_TERM[] VisitArchetypeTerms(ARCHETYPE_TERM[] archetypeTerms)
        {
            ARCHETYPE_TERM[] result = null;

            if (archetypeTerms != null)
            {
                SortedDictionary<string, ARCHETYPE_TERM> sortedItems = new SortedDictionary<string, ARCHETYPE_TERM>();

                foreach (ARCHETYPE_TERM termItem in archetypeTerms)
                {
                    ARCHETYPE_TERM canonicalTerm = new ARCHETYPE_TERM();
                    canonicalTerm.code = termItem.code;
                    canonicalTerm.items = VisitStringDictionary(termItem.items);
                    sortedItems.Add(termItem.code, canonicalTerm);
                }

                result = new ARCHETYPE_TERM[sortedItems.Count];
                sortedItems.Values.CopyTo(result, 0);
            }

            return result;
        }
        public void SpecialiseArchetype(string addition_to_concept_name)
        {
            ARCHETYPE_TERM term = new ARCHETYPE_TERM();
            ARCHETYPE_TERM parentTerm = _ontology.TermDefinition(_ontology.PrimaryLanguageCode, _archetype.concept);
            term.code = _ontology.NextSpecialisedTermId(parentTerm.code);
            term.items = new StringDictionaryItem[parentTerm.items.Length];

            for (int i = 0; i < parentTerm.items.Length; i++)
            {
                term.items[i] = new StringDictionaryItem();
                term.items[i].id = parentTerm.items[i].id;
                term.items[i].Value = parentTerm.items[i].Value;
            }

            _ontology.AddTermOrConstraintDefinition(term, false);

            if (_archetype.definition.node_id == _archetype.concept)
                _archetype.definition.node_id = term.code;

            _archetype.concept = term.code;
            _archetype.parent_archetype_id = _archetype.archetype_id;

            //now add the addition to the concept name in the archetype ID
            string[] y = _archetype.archetype_id.value.Split(".".ToCharArray());
            _archetype.archetype_id = new ARCHETYPE_ID();
            _archetype.archetype_id.value = y[0] + "." + y[1] + "-" + addition_to_concept_name;

            for (int i = 2; i < y.Length; i++)
            {
                _archetype.archetype_id.value += "." + y[i];
            }

            //don't overwrite the old archetype
            _file_name = null;
        }
        protected virtual CodeDefinitionSet[] CloneCodeDefinitions(EiffelStructures.table.HASH_TABLE_REFERENCE_REFERENCE o)
        {
            CodeDefinitionSet[] result = null;

            if (o != null)
            {
                result = new CodeDefinitionSet[o.count()];
                o.start();

                for (int i = 1; i <= result.Length; i++)
                {
                    CodeDefinitionSet codeDefinitionSet = new CodeDefinitionSet();
                    codeDefinitionSet.language = o.key_for_iteration().ToString();
                    EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE adlTerms = o.item_for_iteration() as EiffelStructures.table.Impl.HASH_TABLE_REFERENCE_REFERENCE;
                    SortedList<string, ARCHETYPE_TERM> localTerms = new SortedList<string, ARCHETYPE_TERM>();
                    adlTerms.start();

                    for (int j = 1; j <= adlTerms.count(); j++)
                    {
                        openehr.openehr.am.archetype.ontology.Impl.ARCHETYPE_TERM term = adlTerms.item_for_iteration() as openehr.openehr.am.archetype.ontology.Impl.ARCHETYPE_TERM;
                        ARCHETYPE_TERM localTerm = new ARCHETYPE_TERM();
                        localTerm.code = term.code().ToString();
                        localTerm.items = CloneHashTableAny(term.items());
                        localTerms.Add(localTerm.code, localTerm);
                        adlTerms.forth();
                    }

                    codeDefinitionSet.items = new ARCHETYPE_TERM[localTerms.Count];
                    localTerms.Values.CopyTo(codeDefinitionSet.items, 0);
                    CleanUpCodeDefinitionSet(codeDefinitionSet);
                    result[i - 1] = codeDefinitionSet;
                    o.forth();
                }
            }

            return result;
        }
Example #4
0
        protected void AddTermOrConstraintDefinitionForLanguage(CodeDefinitionSet ls, ARCHETYPE_TERM term)
        {
            if (ls.items == null)
                ls.items = new ARCHETYPE_TERM[1];
            else
            {
                ARCHETYPE_TERM[] t = ls.items;
                Array.Resize(ref t, t.Length + 1);
                ls.items = t;
            }

            ls.items[ls.items.Length - 1] = term;
        }
Example #5
0
        public void AddTermOrConstraintDefinition(string language, ARCHETYPE_TERM term, bool isLoading)
        {
            CodeDefinitionSet definition = null;
            CodeDefinitionSet[] definitions = null;
            string code = term.code.ToLowerInvariant();

            if (code.StartsWith("at"))
            {
                definition = GetTermLanguageSet(language);
                definitions = _archetype.ontology.term_definitions;
            }
            else if (code.StartsWith("ac"))
            {
                definition = GetConstraintLanguageSet(language);
                definitions = _archetype.ontology.constraint_definitions;
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "Error in code " + code);
            }

            if (definition != null && definitions != null)
            {
                //Add the term to that language - ensures there is a language set for the language
                AddTermOrConstraintDefinitionForLanguage(definition, term);

                if (!isLoading && definitions != null && definitions.Length > 1) // if there is more than one language then add the term to those
                {
                    foreach (CodeDefinitionSet ls in definitions)
                    {
                        if (ls.language != language)
                        {
                            foreach (StringDictionaryItem di in term.items)
                            {
                                di.Value = string.Format("{0}{1}({2})", "*", di.Value, language);
                            }

                            AddTermOrConstraintDefinitionForLanguage(ls, term);
                        }
                    }
                }
            }
        }
Example #6
0
 public void AddTermOrConstraintDefinition(ARCHETYPE_TERM a_term, bool isLoading)
 {
     AddTermOrConstraintDefinition(languageCode, a_term, isLoading);
 }
Example #7
0
        public void AddLanguage(string language)
        {
            if (!string.IsNullOrEmpty(language) && !_languages_available.Contains(language))
            {
                _languages_available.Add(language);

                if (_languages_available.Count > 1)
                {
                    //populate a translation set from the original language
                    CodeDefinitionSet ls = TermDefinitions(_archetype.original_language.code_string);
                    CodeDefinitionSet new_ls = GetTermLanguageSet(language);
                    ARCHETYPE_TERM[] new_terms = Array.CreateInstance(typeof(ARCHETYPE_TERM), ls.items.Length) as ARCHETYPE_TERM[];

                    for(int i = 0; i < ls.items.Length; i++)
                    {
                        ARCHETYPE_TERM at = ls.items[i];
                        ARCHETYPE_TERM new_at = new ARCHETYPE_TERM();
                        new_at.code = at.code;
                        StringDictionaryItem[] new_items = Array.CreateInstance(typeof(StringDictionaryItem), at.items.Length) as StringDictionaryItem[];

                        for (int j = 0; j < at.items.Length; j++)
                        {
                            StringDictionaryItem di = at.items[j];
                            StringDictionaryItem new_di = new StringDictionaryItem();
                            new_di.id = di.id;
                            new_di.Value = string.Format("{0}{1}({2})", "*", di.Value, _archetype.original_language.code_string);
                            new_items[j] = new_di;
                        }

                        new_at.items = new_items;
                        new_terms[i] = new_at;
                    }

                    new_ls.items = new_terms;

                    //now get a translation set for constraint definitions
                    ls = ConstraintDefinitions(_archetype.original_language.code_string);

                    if (ls != null)  //May not be any Constraint definitions
                    {
                        new_ls = GetConstraintLanguageSet(language);
                        new_terms = Array.CreateInstance(typeof(ARCHETYPE_TERM), ls.items.Length) as ARCHETYPE_TERM[];

                        for (int i = 0; i < ls.items.Length; i++)
                        {
                            ARCHETYPE_TERM ac = ls.items[i];
                            ARCHETYPE_TERM new_ac = new ARCHETYPE_TERM();
                            new_ac.code = ac.code;
                            StringDictionaryItem[] new_items = Array.CreateInstance(typeof(StringDictionaryItem), ac.items.Length) as StringDictionaryItem[];

                            for (int j = 0; j < ac.items.Length; j++)
                            {
                                StringDictionaryItem di = ac.items[j];
                                StringDictionaryItem new_di = new StringDictionaryItem();
                                new_di.id = di.id;
                                new_di.Value = string.Format("{0}{1}({2})", "*", di.Value, _archetype.original_language.code_string);
                                new_items[j] = new_di;
                            }

                            new_ac.items = new_items;
                            new_terms[i] = new_ac;
                        }

                        new_ls.items = new_terms;
                    }
                }

                //populate a new description by raising an event
                LanguageAdded(this, language, _archetype.original_language.terminology_id.value);                
            }
        }
Example #8
0
        public void ReplaceTermDefinition(string languageCode, ARCHETYPE_TERM term, bool replaceTranslations)
        {
            string code = term.code.ToLowerInvariant();
            System.Diagnostics.Debug.Assert(HasTermCode(code), "Does not have code " + code);
            CodeDefinitionSet[] definitions;

            if (code.StartsWith("at"))
                definitions = _archetype.ontology.term_definitions;
            else
                definitions = _archetype.ontology.constraint_definitions;

            if (definitions != null)
            {
                ARCHETYPE_TERM termForTranslations = null;

                if (replaceTranslations && languageCode == PrimaryLanguageCode)
                {
                    termForTranslations = new ARCHETYPE_TERM
                    {
                        code = code,
                        items = new StringDictionaryItem[term.items.Length]
                    };

                    for (int i = 0; i < term.items.Length; i++)
                    {
                        termForTranslations.items[i] = new StringDictionaryItem
                        {
                            id = term.items[i].id,
                            Value = "*" + term.items[i].Value + "(" + languageCode + ")"
                        };
                    }
                }

                foreach (CodeDefinitionSet ls in definitions)
                {
                    ARCHETYPE_TERM replacement = ls.language == languageCode ? term : termForTranslations;

                    if (replacement != null)
                    {
                        ARCHETYPE_TERM[] terms = ls.items;

                        for (int i = 0; i < terms.Length; i++)
                        {
                            if (terms[i].code.ToLowerInvariant() == code)
                                terms[i] = replacement;
                        }
                    }
                }
            }
        }