How to modify nodes selected by FHIRPath "Select" function #1817
-
Hi, We have a question about After parsing the input FHIR resource to var provider = new PocoStructureDefinitionSummaryProvider();
var rootNode = FhirJsonNode.Parse(inputFileContent).ToTypedElement(provider); we could select the target node by FHIRPath using above function: var matchNode = rootNode.Select("Patient.identifier").FirstOrDefault(); Matched node with instance type If we want to modify this node using Can we achieve this by converting the input to // Convert to ElementNode
var rootNode = ElementNode.FromElement(FhirJsonNode.Parse(inputFileContent).ToTypedElement(provider));
var matchNode = rootNode.Select("Patient.identifier").FirstOrDefault();
if (matchNode != null)
{
// Will this always work?
var elementNode = (ElementNode)((ScopedNode)matchNode).Current;
} Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes, that is the approach I would take as well. Navigating a ScopedNode using FhirPath will generally just call public IEnumerable<ITypedElement> Children(string? name = null) =>
Current.Children(name).Select(c => new ScopedNode(this, ParentResource, c, _fullUrl)); This fragment shows that while navigating down the tree using FhirPath, new So this should work! |
Beta Was this translation helpful? Give feedback.
Yes, that is the approach I would take as well. Navigating a ScopedNode using FhirPath will generally just call
Children()
on the ScopedNode, which will do this:This fragment shows that while navigating down the tree using FhirPath, new
ScopedNode
s are created using a private constructor, which just wraps theElementNode
children (c
) of the currentElementNode
, and they will be exposed throughCurrent
in the child nodes.So this should work!