private bool MatchedWithSlot(ILocatable dataItem, out bool isValid)
        {
            isValid = true;

            foreach (CObject child in Children)
            {
                ArchetypeSlot slot = child as ArchetypeSlot;

                if (slot != null && slot.CanFillWith(dataItem.ArchetypeNodeId) && !slot.IsFull)
                {
                    CArchetypeRoot cArchetypeRoot = ValidationContext.FetchOperationalObject(this, new ArchetypeId(dataItem.ArchetypeNodeId));

                    if (cArchetypeRoot == null)
                    {
                        isValid = false;
                        ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.ArchetypeXLoadFailed, dataItem.ArchetypeNodeId));
                    }
                    else
                    {
                        slot.AddSlotFiller(cArchetypeRoot);
                        cArchetypeRoot.SetValidationContext(ValidationContext);
                        isValid = cArchetypeRoot.ValidValue(dataItem);
                    }

                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        internal static CObject CObject(string typeName)
        {
            DesignByContract.Check.Require(!string.IsNullOrEmpty(typeName), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "typeName"));

            CObject cObject = null;
            switch (typeName)
            {
                case "C_COMPLEX_OBJECT":
                    cObject = new CComplexObject();
                    break;
                case "C_PRIMITIVE_OBJECT":
                    cObject = new CPrimitiveObject();
                    break;
                case "ARCHETYPE_INTERNAL_REF":
                    cObject = new ArchetypeInternalRef();
                    break;
                case "CONSTRAINT_REF":
                    cObject = new ConstraintRef();
                    break;
                case "ARCHETYPE_SLOT":
                    cObject = new ArchetypeSlot();
                    break;
                case "C_CODE_PHRASE":
                    cObject = new CCodePhrase();
                    break;
                case "C_DV_STATE":
                    cObject = new CDvState();
                    break;
                case "C_DV_ORDINAL":
                    cObject = new CDvOrdinal();
                    break;
                case "C_DV_QUANTITY":
                    cObject = new CDvQuantity();
                    break;
                default:
                    throw new NotSupportedException("type not supported: " + typeName);
            }

            DesignByContract.Check.Ensure(cObject != null, "cObject must not be null.");

            return cObject;
        }
Example #3
0
        protected void Validate(ArchetypeSlot archetypeSlot)
        {
            this.ValidateBase((CObject)archetypeSlot);

            Invariant(archetypeSlot.Includes == null || !archetypeSlot.Includes.IsEmpty(),
                string.Format(CommonStrings.IfXIsNotNullMustBeEmpty, "ArchetypeSlot.Includes"));

            Invariant(archetypeSlot.Excludes == null || !archetypeSlot.Excludes.IsEmpty(),
                string.Format(CommonStrings.IfXIsNotNullMustBeEmpty, "ArchetypeSlot.Excludes"));

            // TODO: validity: any_allowed xor (includes /= Void or excludes /= Void)

            if (archetypeSlot.Includes != null)
            {
                foreach (Assertion assertion in archetypeSlot.Includes)
                    this.Validate(assertion);
            }

            if (archetypeSlot.Excludes != null)
            {
                foreach (Assertion assertion in archetypeSlot.Excludes)
                    this.Validate(assertion);
            }
        }
Example #4
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();
        }
Example #5
0
        private void WriteXml(ArchetypeSlot archetypeSlot)
        {
            Check.Require(archetypeSlot != null, string.Format(CommonStrings.XMustNotBeNull, "archetypeSlot"));

            this.WriteXmlBase((CObject)archetypeSlot);

            if (archetypeSlot.Includes != null)
            {
                foreach (Assertion assertion in archetypeSlot.Includes)
                {
                    writer.WriteStartElement(UseOpenEhrPrefix(writer), "includes", OpenEhrNamespace);
                    this.WriteXml(assertion);
                    writer.WriteEndElement();
                }
            }

            if (archetypeSlot.Excludes != null)
            {
                foreach (Assertion assertion in archetypeSlot.Excludes)
                {
                    writer.WriteStartElement(UseOpenEhrPrefix(writer), "excludes", OpenEhrNamespace);
                    this.WriteXml(assertion);
                    writer.WriteEndElement();
                }
            }
        }