FirelyTeam / firely-net-sdk

The official Firely .NET SDK for HL7 FHIR
Other
830 stars 344 forks source link

Remove the need for adapters to use validation and fhirpath #2893

Open ewoutkramer opened 3 weeks ago

ewoutkramer commented 3 weeks ago

Currently, we need PocoElementNode + ScopedNode to get the full functionality needed for validation, resolution and fhirpath. The main reason is that elements cannot refer back to their parents, so things like resolving resources and looking into the context of an element are impossible. Also, it is hard to figure out a location, without knowing your parent.

This has been solved by stateful wrappers like ScopedNode, but these have a few disadvantages:

To remove the need for adapters, we will have to add the notion of a parent (and maybe some additional data like index in a list) to the pocos. There are three ways to do this:

This last bullet's disadvantages can be alleviated by making this navigation explicit and requiring a caset to IScopedNode.

var isn = p.AsScopedNode();
var namex = isn.AsScopedNode().Select("resolve()").First();

Second, we need a replacement for ITypedElement, or adapt ITypedElement to expose the Parent. One could argue we should adapt ITypedElement, but the kind of changes we want to make are deeply breaking:

PS: We've for now chosen to stick to IScopedNode, a subclass of ITypedElement that exposes a Parent property. Once we got that change into our codebase, we can think about introducing lists (basically moving from the XML world with repeated elements to the Json world with lists as first class citizens). We have already seen that Definition is hardly necessary anymore (at least for our goals), so the POCO's will not implement that part of ITypedElement. If you need that, use the old stack.

brianpos commented 3 weeks ago

I don't want this change to make it so that things like the XmlNode or JsonNode which are the random content parsed able to be used with the fhirpath engine (without a known class model), and potentially the validator (I don't do this at the moment - but would for the randon logical models - which don't use reflection).

But I expect the plan is to use the overflow area right?

ewoutkramer commented 2 weeks ago

But I expect the plan is to use the overflow area right?

That's exactly it. We should be able to turn any random ITypedElement or even ISourceNode into a DynamicResource with overflow, and then use it everywhere we expect a POCO/IScopedNode.

ewoutkramer commented 2 weeks ago

Image