Stream: dotnet
Topic: How to get all the resources where one resource is referred?
Muhammad Abubakar Ikram (Mar 27 2019 at 07:27):
How to get all the resources where one resource is referred, using FHIR Net Api? let's say get all the resources where Patient resource exist as the subject for example Observation and Condition?
Is there anything in FHIR Net Api to address this? like we have all the search parameters in modelinfo
if not, then anyone has done any workaround to achieve this kindly share then.
Michele Mottini (Mar 27 2019 at 12:51):
You have to search each resource: .eg ../Observation?patient=xxx gives you all the observation referencing that patient and so on
Michele Mottini (Mar 27 2019 at 12:51):
In the specific case of patients there is the $everything operation that does that in one go
Muhammad Abubakar Ikram (Mar 28 2019 at 07:32):
@Michele Mottini No no, I am asking in the context of C# code, the FHIR Net API. Not in the context of FHIR search.
Ewout Kramer (Apr 01 2019 at 12:24):
How to get all the resources where one resource is referred, using FHIR Net Api? let's say get all the resources where Patient resource exist as the subject for example Observation and Condition?
Is there anything in FHIR Net Api to address this? like we have all the search parameters in modelinfo
if not, then anyone has done any workaround to achieve this kindly share then.
Easiest is to load the structuredefinition of the standard, that contain all the data about the models. Then go over all the elements in the StructureDefinitions and filter where the typeref.code is "Reference". All structuredefinitions are shipped with the .NET Hl7.Fhir.Specification library, so you could load them from there:
[TestMethod] public void bla() { // src gives access to all definitions in the specification.zip var src = ZipSource.CreateValidationSource(); // Retrieve all canonical ids for the structure definitions var allCanonicals = src.ListResourceUris(Model.ResourceType.StructureDefinition); var result = new List<ElementDefinition>(); // For each structuredefinition, find the relevant elements foreach (var canonical in allCanonicals) { var sd = (StructureDefinition)src.ResolveByUri(canonical); if (!sd.HasSnapshot) throw new NotSupportedException("Oops, really need snapshots"); var elems = sd.Snapshot.Element.Where(e => e.Type.Any(t=> t.Code == "Reference")); result.AddRange(elems); } foreach (var el in result) Debug.WriteLine($"{el.Path}"); }
Muhammad Abubakar Ikram (Apr 24 2019 at 11:35):
@Ewout Kramer Thank you so much. I'll surely look into this.
Muhammad Abubakar Ikram (Nov 21 2019 at 12:01):
@Ewout Kramer Can I also get the maturity level of a resource from the specification file?
Brian Postlethwaite (Nov 21 2019 at 22:38):
There is an extension in the SD, don't recall if we strip it out.
Christiaan Knaap (Nov 26 2019 at 11:17):
It is not stripped out, and it is in the root extension element, the extension with url 'http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm'.
Last updated: Apr 12 2022 at 19:14 UTC