Skip to content
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 type coercion between Integer and Integer64 #351

Merged
merged 3 commits into from
Aug 20, 2024
Merged
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
11 changes: 10 additions & 1 deletion src/Firely.Fhir.Validation/Impl/MinMaxValueValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Hl7.Fhir.ElementModel.Types;
using Hl7.Fhir.Support;
using Hl7.Fhir.Utility;
using Hl7.FhirPath.Functions;
using Newtonsoft.Json.Linq;
using System;
using System.ComponentModel;
Expand Down Expand Up @@ -105,7 +106,15 @@ ResultReport IValidatable.Validate(IScopedNode input, ValidationSettings _, Vali

try
{
if ((instanceValue is ICqlOrderable ce ? ce.CompareTo(_minMaxAnyValue) : -1) == _comparisonOutcome)
var (lt, gt) = (EqualityOperators.Compare(instanceValue, _minMaxAnyValue, "<"), EqualityOperators.Compare(instanceValue, _minMaxAnyValue, ">"));
var intResult = (lt, gt) switch
{
(true, _) => -1,
(false, true) => 1,
_ => 0
};

if (intResult == _comparisonOutcome)
{
return new IssueAssertion(_comparisonIssue, $"Value '{input.Value}' is {_comparisonLabel} {Limit.Value})")
.AsResult(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

using FluentAssertions;
using Hl7.Fhir.ElementModel;
using Hl7.Fhir.ElementModel.Types;
using Hl7.Fhir.Model;
using Hl7.Fhir.Support;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using Date = Hl7.Fhir.Model.Date;
using Integer = Hl7.Fhir.Model.Integer;

namespace Firely.Fhir.Validation.Tests
{
Expand Down Expand Up @@ -86,6 +89,12 @@ internal class MinValueValidatorData : BasicValidatorDataAttribute
PrimitiveTypeExtensions.ToTypedElement<Date, string>("1906"),
false, Issue.CONTENT_ELEMENT_PRIMITIVE_VALUE_TOO_LARGE, "PartialGreaterThan"
};
yield return new object?[]
{
_validatableMinValue,
PrimitiveTypeExtensions.ToTypedElement<Integer64, long?>(4),
true, null, "Equals"
};
}
}

Expand Down