예제 #1
0
        internal static string AssertionRegExPattern(Assertion assertion)
        {
            Check.Require(assertion != null, "assertion must not be null.");

            string assertionRegex = string.Empty;

            ExprBinaryOperator expression = assertion.Expression as ExprBinaryOperator;
            if (expression != null)
            {
                ExprLeaf rightExpression = expression.RightOperand as ExprLeaf;
                if (rightExpression != null)
                {
                    CString stringConstraint = rightExpression.Item as CString;
                    Check.Assert(stringConstraint != null);
                    Check.Assert(!string.IsNullOrEmpty(stringConstraint.Pattern));
                    Check.Assert(!(stringConstraint.Pattern.StartsWith("/") &&
                        stringConstraint.Pattern.EndsWith("/")), "Regex is enclosed in forward slashes, as with the C_STRING produced by old version of the ADL Parser.");

                    // Cleanse regex of fullstops which are not either preceded by a backslash (\.) or followed by a star (.*)
                    assertionRegex = stringConstraint.Pattern
                        .Replace(".*", " * ")
                        .Replace(@"\.", @" \ ")
                        .Replace(".", @"\.")
                        .Replace(@" \ ", @"\.")
                        .Replace(" * ", ".*");
                }
            }
            return assertionRegex;
        }
예제 #2
0
        protected void Validate(Assertion assertion)
        {
            Invariant(assertion.Tag == null || assertion.Tag != string.Empty,
                string.Format(CommonStrings.IfXIsNotNullMustBeEmpty, "Assertion.Tag"));

            Invariant(assertion.Expression != null, string.Format(CommonStrings.XMustNotBeNull, "Assertion.Expression"));
            Invariant(assertion.Expression.Type.Equals("BOOLEAN",
                StringComparison.CurrentCultureIgnoreCase), CommonStrings.AssertionExpressMustBeBool);

            if (assertion.Variables != null)
            {
                foreach (AssertionVariable var in assertion.Variables)
                    this.Validate(var);
            }
        }
예제 #3
0
        public void ReadArchetype(XmlReader reader, Archetype archetype)
        {
            DesignByContract.Check.Require(reader != null, string.Format(CommonStrings.XMustNotBeNull, "reader"));
            DesignByContract.Check.Require(archetype != null, string.Format(CommonStrings.XMustNotBeNull, "archetype"));

            this.reader = reader;
            this.archetype = archetype;

            if (reader.NodeType == System.Xml.XmlNodeType.None)
                reader.MoveToContent();

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

               ((AuthoredResource)(archetype)).ReadXml(reader);

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

            if (reader.LocalName != "archetype_id")
                throw new InvalidXmlException("archetype_id", reader.LocalName);
            archetype.ArchetypeId = new ArchetypeId();
            archetype.ArchetypeId.ReadXml(reader);

            if (reader.LocalName == "adl_version")
            {
                archetype.AdlVersion = reader.ReadElementContentAsString("adl_version", OpenEhrNamespace);
                reader.MoveToContent();
            }

            if (reader.LocalName != "concept")
                throw new InvalidXmlException("concept", reader.LocalName);
            archetype.Concept = reader.ReadElementContentAsString("concept", OpenEhrNamespace);
            reader.MoveToContent();

            if (reader.LocalName == "parent_archetype_id")
            {
                archetype.ParentArchetypeId = new ArchetypeId();
                archetype.ParentArchetypeId.ReadXml(reader);
            }

            if (reader.LocalName != "definition")
                throw new InvalidXmlException("definition", reader.LocalName);
            archetype.Definition = new CComplexObject();
            this.ReadXml(archetype.Definition);

            if (reader.LocalName == "invariants")
            {
                System.Collections.Generic.List<Assertion> invariantsList =
                    new System.Collections.Generic.List<OpenEhr.AM.Archetype.Assertion.Assertion>();
                do
                {
                    Assertion assertion = new OpenEhr.AM.Archetype.Assertion.Assertion();
                    this.ReadXml(assertion);

                    invariantsList.Add(assertion);
                } while (reader.LocalName == "invariants");

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

                archetype.Invariants = new AssumedTypes.Set<OpenEhr.AM.Archetype.Assertion.Assertion>(invariantsList);
            }

            if (reader.LocalName != "ontology")
                throw new ValidationException(string.Format(CommonStrings.ExpectedLocalNameIsXNotY, "ontology", reader.LocalName));
            archetype.Ontology = new ArchetypeOntology();
            this.ReadXml(archetype.Ontology);
            archetype.Ontology.ParentArchetype = archetype;
            archetype.Ontology.SpecialisationDepth = AM.Archetype.Ontology.ArcheytpeTermCodeTools.SpecialisationDepthFromCode(archetype.Definition.NodeId);

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

            reader.MoveToContent();
        }
예제 #4
0
        private void ReadXml(Assertion assertion)
        {
            Check.Require(assertion!=null, "assertion must not be null.");

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

            if (reader.LocalName == "tag")
            {
                assertion.Tag = reader.ReadElementContentAsString("tag", OpenEhrNamespace);
                reader.MoveToContent();
            }

            if (reader.LocalName == "string_expression")
            {
                assertion.StringExpression = reader.ReadElementContentAsString("string_expression", OpenEhrNamespace);
                reader.MoveToContent();

            }

            if (reader.LocalName != "expression")
                throw new InvalidXmlException("expression" + reader.LocalName);
            string expressionType = reader.GetAttribute("type", XsiNamespace);
            ExprItem expression = AmFactory.ExprItem(expressionType);
            this.ReadXml(expression);
            assertion.Expression = expression;

            if (reader.LocalName == "variables")
            {
                assertion.Variables = new OpenEhr.AssumedTypes.List<AssertionVariable>();
                do
                {
                    AssertionVariable variable = new AssertionVariable();
                    this.ReadXml(variable);

                    assertion.Variables.Add(variable);
                } while (reader.LocalName == "variables");

                DesignByContract.Check.Assert(assertion.Variables.Count > 0, "variableList must not be empty.");
            }

            DesignByContract.Check.Assert(reader.NodeType == System.Xml.XmlNodeType.EndElement,
              "Expected endElement of Assertion");
            reader.ReadEndElement();
            reader.MoveToContent();
        }
예제 #5
0
        private void ReadXml(ArchetypeSlot archetypeSlot)
        {
            Check.Require(archetypeSlot != null, string.Format(CommonStrings.XMustNotBeNull, "archetypeSlot"));

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

            this.ReadXmlBase((CObject)archetypeSlot);

            if (reader.LocalName == "includes")
            {
                System.Collections.Generic.List<Assertion> includesList = new System.Collections.Generic.List<Assertion>();
                do
                {
                    Assertion assertion = new OpenEhr.AM.Archetype.Assertion.Assertion();
                    this.ReadXml(assertion);
                    includesList.Add(assertion);

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

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

                archetypeSlot.Includes = new OpenEhr.AssumedTypes.Set<OpenEhr.AM.Archetype.Assertion.Assertion>(includesList);
            }

            if (reader.LocalName == "excludes")
            {
                System.Collections.Generic.List<Assertion> excludesList = new System.Collections.Generic.List<Assertion>();
                do
                {
                    Assertion assertion = new OpenEhr.AM.Archetype.Assertion.Assertion();
                    this.ReadXml(assertion);
                    excludesList.Add(assertion);

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

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

                archetypeSlot.Excludes = new OpenEhr.AssumedTypes.Set<OpenEhr.AM.Archetype.Assertion.Assertion>(excludesList);
            }

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

            reader.MoveToContent();
        }
예제 #6
0
        private void WriteXml(Assertion assertion)
        {
            Check.Require(assertion != null, string.Format(CommonStrings.XMustNotBeNull, "assertion"));
            Check.Require(assertion.Expression != null, string.Format(CommonStrings.XMustNotBeNull, "assertion.Expression"));

            if (!string.IsNullOrEmpty(assertion.Tag))
                writer.WriteElementString(UseOpenEhrPrefix(writer), "tag", OpenEhrNamespace, assertion.Tag);

            if (!string.IsNullOrEmpty(assertion.StringExpression))
                writer.WriteElementString(UseOpenEhrPrefix(writer), "string_expression", OpenEhrNamespace, assertion.StringExpression);

            writer.WriteStartElement(UseOpenEhrPrefix(writer), "expression", OpenEhrNamespace);
            string expressionType = AmType.GetName(assertion.Expression);
            writer.WriteAttributeString(UseXsiPrefix(writer), "type", XsiNamespace, expressionType);
            this.WriteXml(assertion.Expression);
            writer.WriteEndElement();

            if (assertion.Variables != null)
            {
                foreach (AssertionVariable var in assertion.Variables)
                {
                    writer.WriteStartElement(UseOpenEhrPrefix(writer), "variables", OpenEhrNamespace);
                    this.WriteXml(var);
                    writer.WriteEndElement();
                }
            }
        }