Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Firely.Fhir.Validation/Impl/PatternValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ ResultReport IValidatable.Validate(PocoNode input, ValidationSettings _, Validat
if (input.Matches(PatternValue))
return ResultReport.SUCCESS;

var severity = OperationOutcome.IssueSeverity.Error;
// element with no value and extension - might have a special meaning, so let's make it into warning instead
// element with no value and extension is valid per spec
if (input is PrimitiveNode && input.GetValue() is null && (input.Poco as IExtendable)?.HasExtensions() is true)
severity = OperationOutcome.IssueSeverity.Warning;
return ResultReport.SUCCESS;

return new IssueAssertion(Issue.CONTENT_DOES_NOT_MATCH_PATTERN_VALUE.Code, $"Value '{displayValue(input)}' does not match pattern '{displayValue(PatternValue)}'", severity, OperationOutcome.IssueType.Invalid)
return new IssueAssertion(Issue.CONTENT_DOES_NOT_MATCH_PATTERN_VALUE.Code, $"Value '{displayValue(input)}' does not match pattern '{displayValue(PatternValue)}'", OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid)
.AsResult(s, input, nameof(PatternValidator));

static string displayValue(ITypedElement te) =>
Expand Down
9 changes: 4 additions & 5 deletions src/Firely.Fhir.Validation/Impl/RegExValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ internal override ResultReport BasicValidate(PocoNode input, ValidationSettings
if (value is not null && _regex.IsMatch(value))
return ResultReport.SUCCESS;

var severity = OperationOutcome.IssueSeverity.Error;
// element with no value and extension - might have a special meaning, so let's make it into warning instead
// element with no value and extension is valid per spec
if (value is null && (input.Poco as IExtendable)?.HasExtensions() is true)
severity = OperationOutcome.IssueSeverity.Warning;
return ResultReport.SUCCESS;

return new IssueAssertion(Issue.CONTENT_ELEMENT_INVALID_PRIMITIVE_VALUE.Code, $"Value '{value}' does not match regex '{Pattern}'", severity, OperationOutcome.IssueType.Invalid)
.AsResult(s, input, nameof (RegExValidator));
return new IssueAssertion(Issue.CONTENT_ELEMENT_INVALID_PRIMITIVE_VALUE.Code, $"Value '{value}' does not match regex '{Pattern}'", OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid)
.AsResult(s, input, nameof(RegExValidator));
}

private static string? toStringRepresentation(PocoNode vp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ internal class PatternValidatorData : BasicValidatorDataAttribute
new CodeableConcept() { Coding = [new() { CodeElement = new() { Extension = [new("http://test", new FhirString("Test"))]}}]}.ToPocoNode(),
false, Issue.CONTENT_DOES_NOT_MATCH_PATTERN_VALUE, "Complex inputs primitive entry with extension and no value will still generate an error."
};
yield return new object?[]
{
new PatternValidator(new CodeableConcept("test-system", "test-code").ToPocoNode()),
new CodeableConcept() { Extension = [new("http://test", new FhirString("Test"))] }.ToPocoNode(),
false, Issue.CONTENT_DOES_NOT_MATCH_PATTERN_VALUE, "Complex inputs primitive entry with extension and no value will still generate an error."
};
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/Firely.Fhir.Validation.Tests/Impl/RegExValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ internal class RegExValidatorData : BasicValidatorDataAttribute
new RegExValidator(@"^((\+31)|(0031)|0)(\(0\)|)(\d{1,3})(\s|\-|)(\d{8}|\d{4}\s\d{4}|\d{2}\s\d{2}\s\d{2}\s\d{2})$"),
PocoNode.ForPrimitive<FhirString>("+31(0)612345678"), true, null, "result must be true (Dutch phonenumber)"
};

yield return new object?[]
{
new RegExValidator("[0-9]"),
new FhirString { Extension = [new("http://example.org/ext", new FhirString("test"))] }.ToPocoNode(),
true, null, "extension-only primitive (no value) must pass regex validation"
};
}
}

Expand Down
Loading