Пример #1
0
 protected void Validate(ArchetypeTerm archetypeTerm)
 {
     Invariant(!string.IsNullOrEmpty(archetypeTerm.Code), "archetypeTerm.Code must not be null or empty.");
     Invariant(archetypeTerm.Keys()!= null, "archeytpeTerm.Keys() must not be null.");
 }
Пример #2
0
        private void ReadXml(ArchetypeTerm archetypeTerm)
        {
            Check.Require(archetypeTerm!= null, "archetypeTerm must not be null.");

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

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

            if (reader.LocalName != "items")
                throw new InvalidXmlException("items", reader.LocalName);

            System.Collections.Generic.Dictionary<string, string> hashTable = new Dictionary<string, string>();
            do
            {
                string hashId = reader.GetAttribute("id");
                string hashValue = reader.ReadElementContentAsString("items", OpenEhrNamespace);
                reader.MoveToContent();
                hashTable.Add(hashId, hashValue);
            } while (reader.LocalName == "items" && reader.NodeType != XmlNodeType.EndElement);

            archetypeTerm.Items = new OpenEhr.AssumedTypes.Hash<string, string>(hashTable);

            DesignByContract.Check.Assert(reader.NodeType == System.Xml.XmlNodeType.EndElement,
              "Expected endElement");
            reader.ReadEndElement();
            reader.MoveToContent();
        }
Пример #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();
        }
Пример #4
0
 public void WriteArchetypeTerm(XmlWriter writer, ArchetypeTerm archetypeTerm)
 {
     this.writer = writer;
     WriteXml(archetypeTerm);
 }
Пример #5
0
        private void WriteXml(ArchetypeTerm archetypTerm)
        {
            Check.Require(archetypTerm != null, string.Format(CommonStrings.XMustNotBeNull, "archetypTerm"));
            Check.Require(!string.IsNullOrEmpty(archetypTerm.Code), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "archetypTerm.Code"));
            Check.Require(archetypTerm.Items != null && archetypTerm.Items.Count > 0, string.Format(CommonStrings.XMustNotBeNullOrEmpty, "archetypTerm.Items"));

            writer.WriteAttributeString("code", archetypTerm.Code);
            foreach (string eachId in archetypTerm.Items.Keys)
            {
                writer.WriteStartElement(UseOpenEhrPrefix(writer), "items", OpenEhrNamespace);
                writer.WriteAttributeString("id", eachId);
                writer.WriteString(archetypTerm.Items.Item(eachId));
                writer.WriteEndElement();
            }
        }
Пример #6
0
 public void ReadArchetypeTerm(XmlReader reader, ArchetypeTerm archetypeTerm)
 {
     this.reader = reader;
     ReadXml(archetypeTerm);
 }