Stream: dotnet
Topic: Rewriting refs
Josh Mandel (Jun 22 2018 at 18:14):
I'm interested in walking a resource and rewriting references throughout; is there example code that would help with this kind of "dynamic" task (walking the tree of elements, re-mapping based on type)?
Brian Postlethwaite (Jun 22 2018 at 18:27):
you could use the fhirpath engine, that's what @Angus Millar did (which gets all the extensions and contained resources) I just did the modelinfo approach, which misses those extras, but is quick with the core props
Brian Postlethwaite (Jun 22 2018 at 18:27):
Happy to share code for either/both (just not now)
Josh Mandel (Jun 22 2018 at 18:30):
Thanks -- ModelInfo
looks like a great lead.
Josh Mandel (Jun 22 2018 at 18:36):
I think https://github.com/ewoutkramer/fhir-net-api/blob/9c5f262cbab8200f0e82fffe3f0949a6e7120bc8/src/Hl7.Fhir.Support/ElementModel/ElementNode.cs#L23 may also be what I need (this is my first time looking at the library; the tests are super helpful as documentation!)
Josh Mandel (Jun 22 2018 at 20:42):
Okay, so digging into IElementNavigator
, I'm having trouble figuring out:
1) How to determine whether a given child is an array or single element
2) How to serialize a given node and its descendants
Should I not have these kinds of expectations?
Angus Millar (Jun 23 2018 at 05:17):
you could use the fhirpath engine, that's what @Angus Millar did (which gets all the extensions and contained resources) I just did the modelinfo approach, which misses those extras, but is quick with the core props
Here is a link to that code: https://github.com/angusmillar/Pyro/blob/master/Pyro.Common/Extentions/ResourceExtentions.cs
Ewout Kramer (Jul 02 2018 at 11:49):
Okay, so digging into
IElementNavigator
, I'm having trouble figuring out:1) How to determine whether a given child is an array or single element
2) How to serialize a given node and its descendantsShould I not have these kinds of expectations?
Hi Josh - you're getting into .NET I see ;-)
This IElementNavigator
is absolutely the way to do it - it allows you to do this dynamic behaviour without having to deal with POCOs and thus saving the time of parsing data into POCO's - which is quite some cycles.
The IElementNavigator in the current version does not have a lot of type information (like whether something repeats, whether it's a cointained resource, etc), so that's also why serialization functionality is limited. I am working on a greatly expanded set of implementations of this interface that do carry this information, including serializers that would do exactly what you need. See here for where the action is happening: https://github.com/ewoutkramer/fhir-net-api/tree/feature/nav-based-serialization.
I hope to pull this into the main branch this month - but I am happy to discuss it with you in more detail if you need.
Last updated: Apr 12 2022 at 19:14 UTC