-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new txt-1 and txt-2 validation components #181
Merged
mmsmits
merged 4 commits into
develop
from
feature/141-improve-error-report-narrative-validation
Aug 17, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3f7ee89
feature: Added new txt-1 and txt-2 validation components
mmsmits 91e8b56
Merge branch 'develop' into feature/141-improve-error-report-narrativ…
mmsmits d2de453
fix unit tests
mmsmits 8a31e23
throw error when narrative is not of type string
mmsmits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2022, Firely (info@fire.ly) - All Rights Reserved | ||
* Proprietary and confidential. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. | ||
*/ | ||
|
||
using Hl7.Fhir.ElementModel; | ||
using Hl7.Fhir.Model; | ||
using Hl7.Fhir.Support; | ||
using Newtonsoft.Json.Linq; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Firely.Fhir.Validation | ||
{ | ||
/// <summary> | ||
/// Represents the hand-coded version of the equivalent <see cref="FhirPathValidator"/> running invariant "ext-1". | ||
/// </summary> | ||
[DataContract] | ||
public class FhirTxt1Validator : InvariantValidator | ||
{ | ||
/// <inheritdoc/> | ||
public override string Key => "txt-1"; | ||
|
||
/// <inheritdoc/> | ||
public override OperationOutcome.IssueSeverity? Severity => OperationOutcome.IssueSeverity.Error; | ||
|
||
/// <inheritdoc/> | ||
public override bool BestPractice => false; | ||
|
||
/// <inheritdoc/> | ||
public override string? HumanDescription => "The narrative SHALL contain only the basic html formatting elements and attributes described in chapters 7-11 (except section 4 of chapter 9) and 15 of the HTML 4.0 standard, <a> elements (either name or href), images and internally contained style attributes"; | ||
|
||
/// <inheritdoc/> | ||
protected override (bool, ResultReport?) RunInvariant(ITypedElement input, ValidationContext vc, ValidationState _) | ||
{ | ||
// Original expression: "expression": "htmlChecks()" | ||
|
||
if (input.Value is null) return (false, null); | ||
|
||
switch (input.Value) | ||
{ | ||
case string value: | ||
{ | ||
var result = XHtml.IsValidNarrativeXhtml(input.Value.ToString(), out var errors); | ||
|
||
if (result) | ||
{ | ||
return (true, null); | ||
} | ||
else | ||
{ | ||
var issues = errors.Select(e => new IssueAssertion(Issue.XSD_VALIDATION_ERROR, e)); | ||
return (false, new ResultReport(ValidationResult.Failure, issues)); | ||
} | ||
} | ||
default: | ||
return (false, new ResultReport(ValidationResult.Failure, | ||
new IssueAssertion(Issue.CONTENT_ELEMENT_INVALID_PRIMITIVE_VALUE, | ||
$"Narrative should be of type string, but is of type ({input.Value.GetType()})"))); | ||
|
||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override JToken ToJson() => new JProperty("FastInvariant-txt1", new JObject()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2022, Firely (info@fire.ly) - All Rights Reserved | ||
* Proprietary and confidential. Unauthorized copying of this file, | ||
* via any medium is strictly prohibited. | ||
*/ | ||
|
||
using Hl7.Fhir.ElementModel; | ||
using Hl7.Fhir.Model; | ||
using Newtonsoft.Json.Linq; | ||
using System.Runtime.Serialization; | ||
|
||
namespace Firely.Fhir.Validation | ||
{ | ||
/// <summary> | ||
/// Represents the hand-coded version of the equivalent <see cref="FhirPathValidator"/> running invariant "ext-1". | ||
/// </summary> | ||
[DataContract] | ||
public class FhirTxt2Validator : InvariantValidator | ||
{ | ||
/// <inheritdoc/> | ||
public override string Key => "txt-2"; | ||
|
||
/// <inheritdoc/> | ||
public override OperationOutcome.IssueSeverity? Severity => OperationOutcome.IssueSeverity.Error; | ||
|
||
/// <inheritdoc/> | ||
public override bool BestPractice => false; | ||
|
||
/// <inheritdoc/> | ||
public override string? HumanDescription => "The narrative SHALL have some non-whitespace content"; | ||
|
||
/// <inheritdoc/> | ||
protected override (bool, ResultReport?) RunInvariant(ITypedElement input, ValidationContext vc, ValidationState _) | ||
{ | ||
//Check whether the narrative contains non-whitespace content. | ||
return (!string.IsNullOrWhiteSpace(input.Value.ToString()), null); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override JToken ToJson() => new JProperty("FastInvariant-txt2", new JObject()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
test/Firely.Fhir.Validation.Compilation.Tests.Shared/FhirTestCases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be really sure this invariant works, you need to use a forbidden html feature according to the XHTML spec for narrative, e.,g: