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); }
internal void AddSlotFiller(CArchetypeRoot filler) { Check.Require(filler != null, string.Format(CommonStrings.XMustNotBeNull, "filler")); Check.Require(!IsFull, AmValidationStrings.SlotMustNotBeFull); numberOfFillers++; }
internal static void PopulateLocatableAttributes(CComplexObject cComplexObject, OpenEhr.RM.Common.Archetyped.Impl.Locatable locatable) { Check.Require(locatable != null, "locatable must not be null."); Check.Require(cComplexObject != null, "cComplexObject must not be null."); string codeString = null; if (string.IsNullOrEmpty(locatable.ArchetypeNodeId)) { CArchetypeRoot archetypeRoot = cComplexObject as CArchetypeRoot; if (archetypeRoot != null) { locatable.ArchetypeNodeId = archetypeRoot.ArchetypeId.Value; codeString = cComplexObject.NodeId; } else { locatable.ArchetypeNodeId = cComplexObject.NodeId; codeString = cComplexObject.NodeId; } } if (locatable.Name == null || string.IsNullOrEmpty(locatable.Name.Value)) { if (string.IsNullOrEmpty(codeString)) codeString = cComplexObject.NodeId; locatable.Name = new DvText(LocalTermDefText(codeString, cComplexObject)); } Check.Ensure(!string.IsNullOrEmpty(locatable.ArchetypeNodeId), "ArchetypeId must not be null or empty."); Check.Ensure(locatable.Name != null && !string.IsNullOrEmpty(locatable.Name.Value), "name must not be null."); }
public MatchingItems(AssumedTypes.IList dataChildren, CObject constraint) : base() { Check.Require(dataChildren != null, string.Format(CommonStrings.XMustNotBeNull, "dataChildren")); Check.Require(constraint != null, string.Format(CommonStrings.XMustNotBeNull, "constraint")); Constraint = constraint; NameAttribute = NameAttributeConstraint(constraint); Lower = constraint.Occurrences.Lower; Upper = constraint.Occurrences.UpperUnbounded ? long.MaxValue : constraint.Occurrences.Upper; CArchetypeRoot archetypeRoot = constraint as CArchetypeRoot; NodeId = archetypeRoot != null ? archetypeRoot.ArchetypeId.Value : constraint.NodeId; if (!(constraint is ArchetypeSlot)) { OpenEhr.AssumedTypes.Impl.ILocatableList locatableItems = dataChildren as OpenEhr.AssumedTypes.Impl.ILocatableList; if (locatableItems != null) { Check.Assert(!string.IsNullOrEmpty(NodeId), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "NodeId")); if (locatableItems.Contains(NodeId)) { foreach (OpenEhr.RM.Common.Archetyped.Impl.Locatable locatable in (System.Collections.IEnumerable)locatableItems[NodeId]) { if (NameAttribute == null || NameAttribute.ValidValue(locatable.Name)) { Add(locatable); } } } } else { foreach (object item in dataChildren) { IRmType rmType = item as IRmType; if (rmType != null && constraint.IsSameRmType(rmType)) { Add(item); } } } } Check.Ensure(Constraint == constraint); }
protected virtual string FullPath() { string result = ""; ArchetypeConstraint parent = constraint; do { CArchetypeRoot cArchetypeRoot = parent as CArchetypeRoot; if (cArchetypeRoot != null) { string rootPath = cArchetypeRoot.Parent != null ? cArchetypeRoot.Path : ""; if (result.StartsWith(rootPath)) { result = result.Substring(rootPath.Length); } result = rootPath + CArchetypeRootPredicate(cArchetypeRoot) + result; parent = cArchetypeRoot.Parent; } else { if (string.IsNullOrEmpty(result)) { result = parent.Path; } CObject cObject = parent as CObject; if (cObject != null) { parent = cObject.Parent; } else { CAttribute cAttribute = parent as CAttribute; if (cAttribute != null) { parent = cAttribute.parent; } } } } while (parent != null); Check.Ensure(result != null); return(result); }
public static string LocalTermDefText(string codeString, CObject cObject) { Check.Require(!string.IsNullOrEmpty(codeString), "codeString must not be null or empty."); Check.Require(cObject != null, "cObject must not be null"); CArchetypeRoot cArchetypeRoot = GetCArchetypeRoot(cObject); Check.Assert(cArchetypeRoot.TermDefinitions.HasKey(codeString)); string termDefText = cArchetypeRoot.TermDefinitions.Item(codeString).Items.Item("text"); Check.Ensure(!string.IsNullOrEmpty(termDefText)); return termDefText; }
protected virtual string CArchetypeRootPredicate(CArchetypeRoot cArchetypeRoot) { string result = ""; string name = GetName(cArchetypeRoot); if (!string.IsNullOrEmpty(name)) { result = string.Format("[{0} and name/value='{1}']", cArchetypeRoot.ArchetypeId, name); } else { result = string.Format("[{0}]", cArchetypeRoot.ArchetypeNodeId); } Check.Ensure(result != null); return(result); }
internal static CArchetypeRoot GetCArchetypeRoot(CObject cObject) { Check.Require(cObject != null, "cObject must not be null"); CObject parentObject = cObject; CArchetypeRoot cArchetypeRoot = null; while (parentObject != null && (cArchetypeRoot = parentObject as CArchetypeRoot) == null) { CAttribute cattribute = parentObject.Parent; Check.Assert(cattribute != null, "cattribute must not be null"); parentObject = cattribute.parent; } if (cArchetypeRoot == null) throw new ApplicationException("Operational template must contain CArchetypeRoot"); return cArchetypeRoot; }
public override bool ValidValue(object dataValue) { Check.Require(dataValue != null, string.Format(CommonStrings.XMustNotBeNull, "dataValue")); IRmType rmType = dataValue as IRmType; Check.Require(rmType != null, string.Format(AmValidationStrings.ValueMustImplementIRmType, dataValue.GetType().ToString())); bool result = true; rmType.Constraint = this; if (!IsSameRmType(rmType)) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectRmType, RmTypeName, rmType.GetRmTypeName())); } if (!result || !AnyAllowed()) { OpenEhr.RM.Common.Archetyped.Impl.Locatable locatable = dataValue as OpenEhr.RM.Common.Archetyped.Impl.Locatable; if (locatable != null) { ValidationUtility.PopulateLocatableAttributes(this, locatable); if (Parent != null && ArchetypeNodeId != locatable.ArchetypeNodeId) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectNodeId, ArchetypeNodeId, locatable.ArchetypeNodeId)); } } System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection = System.ComponentModel.TypeDescriptor.GetProperties(dataValue); if (Attributes != null) { foreach (CAttribute cAttribute in Attributes) { object attributeObject = null; string attributeName = RmFactory.GetOpenEhrV1RmName(cAttribute.RmAttributeName); System.ComponentModel.PropertyDescriptor property = propertyDescriptorCollection.Find(attributeName, true); // if the attributeName is not a class property, it must be a class function. if (property == null) { System.Reflection.MethodInfo method = dataValue.GetType().GetMethod(attributeName); if (method == null) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.UnexpectedAttributeX, attributeName)); continue; } else { attributeObject = method.Invoke(dataValue, null); } } else { attributeObject = property.GetValue(dataValue); } if (attributeObject == null) { if (cAttribute.Existence.Lower > 0) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmExpectedConstraintMissing, cAttribute.RmAttributeName)); } } else if (cAttribute.Existence.Upper == 0) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmForbiddenConstraint, cAttribute.RmAttributeName)); } else if (!cAttribute.ValidValue(attributeObject)) { result = false; } else { DvCodedText codedText = dataValue as DvCodedText; if (codedText != null && cAttribute.RmAttributeName == "defining_code") { // validate the code string before validating the coded value if (codedText.DefiningCode.TerminologyId.Value == "local") { CObject parentObject = cAttribute.parent; CArchetypeRoot cArchetypeRoot = ValidationUtility.GetCArchetypeRoot(parentObject); if (!cArchetypeRoot.TermDefinitions.HasKey(codedText.DefiningCode.CodeString)) { result = false; string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString; ValidationContext.AcceptValidationError(this, string.Format("code {0} is not existing archetype term", code)); } } if (result && !ValidationUtility.ValidValueTermDef(codedText, cAttribute, ValidationContext.TerminologyService)) { result = false; string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TextValueXInvalidForCodeY, codedText.Value, code)); } } } } } } return(result); }