private ComparisonConstraintResult CompareConstraint(IGSettingsManager igSettings, IConstraint oldConstraint, IConstraint newConstraint) { var oldFc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, oldConstraint, null); var newFc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, newConstraint, null); var newNarrative = newFc.GetPlainText(); var oldNarrative = oldFc.GetPlainText(); var cResult = new ComparisonConstraintResult { ParentNumber = newConstraint.Parent != null ? string.Format("{0}-{1}", newConstraint.Parent.Template.OwningImplementationGuideId, newConstraint.Parent.Number) : null, Number = string.Format("{0}-{1}", newConstraint.Template.OwningImplementationGuideId, newConstraint.Number.Value), Order = newConstraint.Order, NewNarrative = newNarrative, OldNarrative = oldNarrative }; // If all that changed was the CONF number, then treat as unchanged. if (newNarrative.IndexOf("(CONF") >= 0 && oldNarrative.IndexOf("(CONF") >= 0) { var newNarrativeCompare = newNarrative.Substring(0, newNarrative.IndexOf("(CONF")); var oldNarrativeCompare = oldNarrative.Substring(0, oldNarrative.IndexOf("(CONF")); cResult.Type = newNarrativeCompare != oldNarrativeCompare ? CompareStatuses.Modified : CompareStatuses.Unchanged; } else { cResult.Type = newNarrative != oldNarrative ? CompareStatuses.Modified : CompareStatuses.Unchanged; } if (!oldConstraint.IsPrimitive && cResult.Type != CompareStatuses.Unchanged) { CheckField(cResult, "Description", oldConstraint.Description, newConstraint.Description); CheckField(cResult, "Label", oldConstraint.Label, newConstraint.Label); CheckField(cResult, "Conformance", oldConstraint.Conformance, newConstraint.Conformance); CheckField(cResult, "Cardinality", oldConstraint.Cardinality, newConstraint.Cardinality); CheckField(cResult, "DataType", oldConstraint.DataType, newConstraint.DataType); CheckField(cResult, "Value", oldConstraint.Value, newConstraint.Value); CheckField(cResult, "Display Name", oldConstraint.ValueDisplayName, newConstraint.ValueDisplayName); CheckField(cResult, "ValueSet Date", oldConstraint.ValueSetDate, newConstraint.ValueSetDate); CheckField(cResult, "ValueSet", GetValueSetDisplay(oldConstraint), GetValueSetDisplay(newConstraint)); CheckField(cResult, "Code System", GetCodeSystemDisplay(oldConstraint), GetCodeSystemDisplay(newConstraint)); CheckField(cResult, "Contained Template", GetContainedTemplateDisplay(oldConstraint), GetContainedTemplateDisplay(newConstraint)); } return(cResult); }
/// <summary> /// Compares the previous template to the new template in two stages; first the fields of the templates and then the constraints of the templates. /// The comparison between constraints are based on the IConstraint.Number field for matching the constraints together. /// </summary> /// <remarks> /// Template fields: Name, Oid, Description, Is Open, Implied Template /// Constraint fields: Description, Label, Conformance, Cardinality, DataType, Value, Display Name, ValueSet Date, Value Set, Code System, Contained Template /// </remarks> /// <returns>A ComparisonResult instance which contains the differences between the old and new templates fields /// and a list of ComparisonConstraintResult instances that represents each modified constraint.</returns> public ComparisonResult Compare(ITemplate previousTemplate, ITemplate newTemplate) { this.result = new ComparisonResult(); this.CompareTemplate(previousTemplate, newTemplate); if (newTemplate.Status != PublishStatus.RETIRED_STATUS) { // Added constraints foreach (var cConstraint in newTemplate.Constraints.Where(b => !previousTemplate.Constraints.Exists(a => a.Number == b.Number))) { IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, cConstraint, null); ComparisonConstraintResult cResult = new ComparisonConstraintResult() { ParentNumber = cConstraint.Parent != null? string.Format("{0}-{1}", cConstraint.Template.OwningImplementationGuideId, cConstraint.Parent.Number) : null, Number = string.Format("{0}-{1}", cConstraint.Template.OwningImplementationGuideId, cConstraint.Number.Value), Order = cConstraint.Order, Type = CompareStatuses.Added, NewNarrative = fc.GetPlainText() }; this.result.ChangedConstraints.Add(cResult); } // Deleted constraints foreach (var cConstraint in previousTemplate.Constraints.Where(a => !newTemplate.Constraints.Exists(b => b.Number == a.Number))) { IFormattedConstraint fc = FormattedConstraintFactory.NewFormattedConstraint(this.tdb, this.igSettings, this.igTypePlugin, cConstraint, null); ComparisonConstraintResult cResult = new ComparisonConstraintResult() { ParentNumber = cConstraint.Parent != null? string.Format("{0}-{1}", cConstraint.Parent.Template.OwningImplementationGuideId, cConstraint.Parent.Number) : null, Number = string.Format("{0}-{1}", cConstraint.Template.OwningImplementationGuideId, cConstraint.Number), Order = cConstraint.Order, Type = CompareStatuses.Removed, OldNarrative = fc.GetPlainText() }; this.result.ChangedConstraints.Add(cResult); } // Modified constraints foreach (var oldConstraint in previousTemplate.Constraints.Where(a => newTemplate.Constraints.Exists(b => b.Number == a.Number))) { var newConstraint = newTemplate.Constraints.Single(b => b.Number == oldConstraint.Number); ComparisonConstraintResult compareResult = this.CompareConstraint(this.igSettings, oldConstraint, newConstraint); if (compareResult != null) { result.ChangedConstraints.Add(compareResult); } } } return(this.result); }