firely-net-sdk
firely-net-sdk copied to clipboard
Review Primitive value handling for POCO extension methods for FhirPath
Describe the bug
If we look at the extension methods that evaluate FP on POCO's we see that Select
is called, followed by ToFhirValues()
. Looking at the code for ToFhirValues()
, it seems this code once meant to select the .Value
for primitives. Unfortunately, for non FHIR primitives, it would return null. This method, however, was supposed to return the nodes, not the values (how else could you reach out to the extensions on the nodes for primitives?).
Our saving grace here is that the ToFhirValues()
method polls for an interface called IFhirValueProvider
, for which the implementation on any POCO will invoke the FhirValue
method on the PocoElementNode
. This in turn, will always return the node (of type Base
) instead of the value.
The net result is that we -as far as I can see- always return the node, not the value. But then - why keep this while IFhirValueProvider/ToFhirValues() around in the first place?
To Reproduce
Patient p = new Patient
{
Active = true
};
p.ActiveElement.ElementId = "314";
p.ActiveElement.AddExtension("http://something.org", new FhirBoolean(false));
p.ActiveElement.AddExtension("http://something.org", new Integer(314));
var extensions = p.Select("Patient.active[0].extension");
Assert.AreEqual(2, extensions.Count());
var boolValue = p.Select("Patient.active");
Assert.IsTrue(boolValue.All(bv => bv is FhirBoolean));
Expected behavior As the unit test shows, we do not select the value of the FhirBoolean, but the FhirBoolean itself. This is expected behaviour as far as I am concerned. I cannot see what ToFhirValues() and IFhirValueProvider are doing here - I think we can remove them.
Screenshots If applicable, add screenshots to help explain your problem.
Version used:
- FHIR Version: [e.g. STU3, R4, R5]
- Version: [e.g. 1.9.0]
Additional context Add any other context about the problem here.