Skip to content

Commit

Permalink
Merge pull request #2866 from FirelyTeam/fix/contained-resource-cache…
Browse files Browse the repository at this point in the history
…-entry-id

Fixed inconsistency when resolving references to contained resources
  • Loading branch information
ewoutkramer authored Sep 18, 2024
2 parents f5422cc + cc77f1a commit 8c03944
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/Hl7.Fhir.Base/ElementModel/ScopedNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,15 @@ public IEnumerable<ScopedNode> ParentResources()
/// </summary>
public IEnumerable<ScopedNode> ContainedResources()
{
if (_cache.ContainedResources != null) return _cache.ContainedResources.Resources;

if (AtResource)
{
var referenceEntryPairs = from contained in this.Children("contained")
let id = contained.Children("id").FirstOrDefault()?.Value as string
let resource = contained as ScopedNode
select new KeyValuePair<string, ScopedNode?>(id, resource);
_cache.ContainedResources = new ReferencedResourceCache(referenceEntryPairs);
}
else
_cache.ContainedResources = new ReferencedResourceCache([]);

return _cache.ContainedResources.Resources;
return getOrInitContainedCache().Resources;
}

internal ReferencedResourceCache ContainedResourcesWithId()
{
return getOrInitContainedCache();
}

private ReferencedResourceCache getOrInitContainedCache()
{
if (_cache.ContainedResources != null) return _cache.ContainedResources;

Expand Down

0 comments on commit 8c03944

Please sign in to comment.