-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from FirelyTeam/feature/141-improve-error-rep…
…ort-narrative-validation Added new txt-1 and txt-2 validation components
- Loading branch information
Showing
6 changed files
with
150 additions
and
3 deletions.
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