/// <summary>
        /// Perform the Invariant based validation for this rule
        /// </summary>
        /// <param name="invariantRule"></param>
        /// <param name="model"></param>
        /// <param name="result">The OperationOutcome that will have the validation results appended</param>
        /// <param name="context">Describes the context in which a validation check is performed.</param>
        /// <returns></returns>
        public static bool ValidateInvariantRule(ValidationContext context, ElementDefinition.ConstraintComponent invariantRule, ITypedElement model, OperationOutcome result)
        {
            string expression = invariantRule.GetStringExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-expression");

            try
            {
                // No FhirPath extension
                if (string.IsNullOrEmpty(expression))
                {
                    result.Issue.Add(new OperationOutcome.IssueComponent()
                    {
                        Code        = OperationOutcome.IssueType.Invariant,
                        Severity    = OperationOutcome.IssueSeverity.Warning,
                        Details     = new CodeableConcept(null, invariantRule.Key, "Unable to validate without a FhirPath expression"),
                        Diagnostics = expression
                    });
                    return(true);
                }

                // Ensure the FHIR extensions are registered
                Hl7.Fhir.FhirPath.ElementNavFhirExtensions.PrepareFhirSymbolTableFunctions();

                if (model.Predicate(expression, new EvaluationContext(model)))
                {
                    return(true);
                }

                result.Issue.Add(new OperationOutcome.IssueComponent()
                {
                    Code        = OperationOutcome.IssueType.Invariant,
                    Severity    = OperationOutcome.IssueSeverity.Error,
                    Details     = new CodeableConcept(null, invariantRule.Key, invariantRule.Human),
                    Diagnostics = expression
                });
                return(false);
            }
            catch (Exception ex)
            {
                result.Issue.Add(new OperationOutcome.IssueComponent()
                {
                    Code        = OperationOutcome.IssueType.Invariant,
                    Severity    = OperationOutcome.IssueSeverity.Fatal,
                    Details     = new CodeableConcept(null, invariantRule.Key, "FATAL: Unable to process the invariant rule: " + invariantRule.Key + " " + expression),
                    Diagnostics = String.Format("FhirPath: {0}\r\nError: {1}", expression, ex.Message)
                });
                return(false);
            }
        }