Ejemplo n.º 1
0
        public Archetype(ArchetypeId archetypeId, string concept, CComplexObject definition,
            ArchetypeOntology ontology, CodePhrase originalLanguage, RevisionHistory revisionHistory,
            bool isControlled)
            : base(originalLanguage, revisionHistory, isControlled)
        {
            Check.Require(archetypeId != null, string.Format(CommonStrings.XMustNotBeNull, "archetypeId"));
            Check.Require(!string.IsNullOrEmpty(concept) != null, string.Format(CommonStrings.XMustNotBeNullOrEmpty, "concept"));
            Check.Require(definition != null, string.Format(CommonStrings.XMustNotBeNull, "definition"));
            Check.Require(ontology != null, string.Format(CommonStrings.XMustNotBeNull, "ontology"));

            this.archetypeId = archetypeId;
            this.definition = definition;
            this.ontology = ontology;
        }
Ejemplo n.º 2
0
 protected void Validate(ArchetypeOntology archetypeOntology)
 {
     Invariant(archetypeOntology.TerminologyesAvailable != null, "archetypeOntology.TerminologesAvailable must not be null.");
     Invariant(archetypeOntology.SpecialisationDepth >= 0, "archetypeOntology.SpecialisationDepth must be >=0.");
     Invariant(archetypeOntology.TermCodes != null, "archetypeOntology.TermCodes must not be null.");
     Invariant(archetypeOntology.ConstraintCodes != null, "archetypeOntology.ConstraintCodes must not be null.");
     Invariant(archetypeOntology.TermAttributeNames != null, "archetypeOntology.TermAttributeNames must not be null.");
     Invariant(archetypeOntology.ParentArchetype != null, "archetypeOntology.PaentArchetype must not be null.");
     Invariant(archetypeOntology.TermAttributeNames.Has("text"), "archetypeOntology.TermAttributeNames must have 'text'");
     Invariant(archetypeOntology.TermAttributeNames.Has("description"), "archetypeOntology.TermAttributeNames must have 'description'");
 }
Ejemplo n.º 3
0
        private void ReadXml(ArchetypeOntology archetypeOntology)
        {
            Check.Require(archetypeOntology!= null, "archetypeOntology must not be null.");

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

            if (reader.LocalName == "term_definitions")
            {

                System.Collections.Generic.Dictionary<string, AssumedTypes.Hash<ArchetypeTerm, string>> termDefinitionsDic =
                    new Dictionary<string, OpenEhr.AssumedTypes.Hash<ArchetypeTerm, string>>();
                do
                {
                    string language = reader.GetAttribute("language");

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

                    Dictionary<string, ArchetypeTerm> termDefimitionItemDic = new Dictionary<string, ArchetypeTerm>();

                    while (reader.LocalName == "items")
                    {
                        ArchetypeTerm archetypeTerm = new ArchetypeTerm();
                        this.ReadXml(archetypeTerm);

                        termDefimitionItemDic.Add(archetypeTerm.Code, archetypeTerm);
                    }

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

                    AssumedTypes.Hash<ArchetypeTerm, string> archetypeTermHash = new OpenEhr.AssumedTypes.Hash<ArchetypeTerm, string>(termDefimitionItemDic);

                    termDefinitionsDic.Add(language, archetypeTermHash);

                } while (reader.LocalName == "term_definitions");

                DesignByContract.Check.Assert(termDefinitionsDic.Count > 0, "termDefinitionDic must not be emppty.");

                archetypeOntology.TermDefinitions = new OpenEhr.AssumedTypes.Hash<OpenEhr.AssumedTypes.Hash<ArchetypeTerm, string>, string>(termDefinitionsDic);
            }

            if (reader.LocalName == "constraint_definitions")
            {

                System.Collections.Generic.Dictionary<string, AssumedTypes.Hash<ArchetypeTerm, string>> constraintDefinitionsDic =
                    new Dictionary<string, OpenEhr.AssumedTypes.Hash<ArchetypeTerm, string>>();
                do
                {
                    string language = reader.GetAttribute("language");

                    Dictionary<string, ArchetypeTerm> constraintDefItemDic = new Dictionary<string, ArchetypeTerm>();
                    reader.ReadStartElement();
                    reader.MoveToContent();

                    while (reader.LocalName == "items")
                    {
                        ArchetypeTerm archetypeTerm = new ArchetypeTerm();
                        this.ReadXml(archetypeTerm);

                        constraintDefItemDic.Add(archetypeTerm.Code, archetypeTerm);
                    }

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

                    AssumedTypes.Hash<ArchetypeTerm, string> constraintDefItemHash =
                        new OpenEhr.AssumedTypes.Hash<ArchetypeTerm, string>(constraintDefItemDic);

                    constraintDefinitionsDic.Add(language, constraintDefItemHash);

                } while (reader.LocalName == "constraint_definitions");

                DesignByContract.Check.Assert(constraintDefinitionsDic.Count > 0, "termDefinitionDic must not be emppty.");

                archetypeOntology.ConstraintDefinitions = new OpenEhr.AssumedTypes.Hash<OpenEhr.AssumedTypes.Hash<ArchetypeTerm, string>, string>(constraintDefinitionsDic);
            }

            if (reader.LocalName == "term_bindings")
            {
                if (reader.IsEmptyElement)
                {
                    reader.Skip();
                    reader.MoveToContent();
                }
                else
                {
                    System.Collections.Generic.Dictionary<string, AssumedTypes.Hash<CodePhrase, string>> termBindingDic =
                        new Dictionary<string, OpenEhr.AssumedTypes.Hash<CodePhrase, string>>();
                    do
                    {
                        Dictionary<string, CodePhrase> termBindingItemDic = new 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.");

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

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

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

                    archetypeOntology.TermBindings = new OpenEhr.AssumedTypes.Hash<OpenEhr.AssumedTypes.Hash<CodePhrase, string>, string>(termBindingDic);
                }
            }

            if (reader.LocalName == "constraint_bindings")
            {
                System.Collections.Generic.Dictionary<string, AssumedTypes.Hash<DvUri, string>> constraintBindingDic =
                    new Dictionary<string, OpenEhr.AssumedTypes.Hash<DvUri, string>>();
                do
                {
                    Dictionary<string, DvUri> constraintBindingItemDic = new Dictionary<string, DvUri>();

                    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");
                        DvUri dvUri = new DvUri();
                        dvUri.ReadXml(reader);

                        constraintBindingItemDic.Add(hashId, dvUri);
                    }

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

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

                    AssumedTypes.Hash<DvUri, string> constraintBindingItemHash =
                        new OpenEhr.AssumedTypes.Hash<DvUri, string>(constraintBindingItemDic);

                    constraintBindingDic.Add(terminologyString, constraintBindingItemHash);
                } while (reader.LocalName == "constraint_bindings");

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

                archetypeOntology.ConstraintBindings = new OpenEhr.AssumedTypes.Hash<OpenEhr.AssumedTypes.Hash<DvUri, string>, string>(constraintBindingDic);
            }

            DesignByContract.Check.Assert(reader.NodeType == System.Xml.XmlNodeType.EndElement,
              "Expected endElement");
            reader.ReadEndElement();
            reader.MoveToContent();
        }
Ejemplo n.º 4
0
        private void WriteXml(ArchetypeOntology archetypeOntology)
        {
            Check.Require(archetypeOntology != null, string.Format(CommonStrings.XMustNotBeNull, "archetypeOntology"));

            if (archetypeOntology.TermDefinitions != null && archetypeOntology.TermDefinitions.Count > 0)
            {
                foreach (string language in archetypeOntology.TermDefinitions.Keys)
                {
                    writer.WriteStartElement(UseOpenEhrPrefix(writer), "term_definitions", OpenEhrNamespace);
                    writer.WriteAttributeString("language", language);

                    AssumedTypes.Hash<ArchetypeTerm, string> eachTermDefinitions = archetypeOntology.TermDefinitions.Item(language);
                    foreach (string code in eachTermDefinitions.Keys)
                    {
                        writer.WriteStartElement(UseOpenEhrPrefix(writer), "items", OpenEhrNamespace);
                        this.WriteXml(eachTermDefinitions.Item(code));
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }
            }

            if (archetypeOntology.ConstraintDefinitions != null && archetypeOntology.ConstraintDefinitions.Count > 0)
            {
                foreach (string language in archetypeOntology.ConstraintDefinitions.Keys)
                {
                    writer.WriteStartElement(UseOpenEhrPrefix(writer), "constraint_definitions", OpenEhrNamespace);
                    writer.WriteAttributeString("language", language);

                    AssumedTypes.Hash<ArchetypeTerm, string> eachTermDefinitions = archetypeOntology.ConstraintDefinitions.Item(language);
                    foreach (string code in eachTermDefinitions.Keys)
                    {
                        writer.WriteStartElement(UseOpenEhrPrefix(writer), "items", OpenEhrNamespace);
                        this.WriteXml(eachTermDefinitions.Item(code));
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }
            }

            if (archetypeOntology.TermBindings != null && archetypeOntology.TermBindings.Count > 0)
            {
                foreach (string terminology in archetypeOntology.TermBindings.Keys)
                {
                    writer.WriteStartElement(UseOpenEhrPrefix(writer), "term_bindings", OpenEhrNamespace);
                    writer.WriteAttributeString("terminology", terminology);

                    AssumedTypes.Hash<CodePhrase, string> eachTermBindingItem = archetypeOntology.TermBindings.Item(terminology);
                    foreach (string code in eachTermBindingItem.Keys)
                    {
                        writer.WriteStartElement(UseOpenEhrPrefix(writer), "items", OpenEhrNamespace);
                        writer.WriteAttributeString("code", code);
                        writer.WriteStartElement(UseOpenEhrPrefix(writer), "value", OpenEhrNamespace);
                        eachTermBindingItem.Item(code).WriteXml(writer);
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();

                }
            }

            if (archetypeOntology.ConstraintBindings != null && archetypeOntology.ConstraintBindings.Count > 0)
            {
                foreach (string terminology in archetypeOntology.ConstraintBindings.Keys)
                {
                    writer.WriteStartElement(UseOpenEhrPrefix(writer), "constraint_bindings", OpenEhrNamespace);
                    writer.WriteAttributeString("terminology", terminology);

                    AssumedTypes.Hash<DvUri, string> eachConstraintBindingItem = archetypeOntology.ConstraintBindings.Item(terminology);
                    foreach (string code in eachConstraintBindingItem.Keys)
                    {
                        writer.WriteStartElement(UseOpenEhrPrefix(writer), "items", OpenEhrNamespace);
                        writer.WriteAttributeString("code", code);
                        eachConstraintBindingItem.Item(code).WriteXml(writer);
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();

                }
            }
        }