Unable to validate resources in R4/R4B where Attachement.size is set because CQL types differ #326
Closed
Description
When validating an Attachment element with the size field in R4B (size is mapped to unsignedInt
in R4/R4B and integer64
in R5), The MinMaxValueValidator
fails with an ArgumentException with message:
'Cannot compare 234 (of type Hl7.Fhir.ElementModel.Types.Long) to -2147483648 (of type Hl7.Fhir.ElementModel.Types.Integer), because the types differ.'
Reproduction code:
var r = new DiagnosticReport
{
Code = new CodeableConcept("http://loinc.org", "abc"),
Status = DiagnosticReport.DiagnosticReportStatus.Partial,
PresentedForm = [new Attachment { Size = 234 }],
};
var result = validator.Validate(r);
I believe the fix should be in Hl7.Fhir.ElementModel.Types.Long
to allow comparisons to Integer
which should to be in line with the csharp comparison semantics where int values are automatically converted to long.
public int CompareTo(object? obj)
{
return obj switch
{
null => 1,
Long i => Value.CompareTo(i.Value),
+ Integer i => Value.CompareTo(i.Value),
_ => throw NotSameTypeComparison(this, obj)
};
}
Metadata
Assignees
Labels
No labels