使用 FHIR nuget 包通过引用在包中查找资源
Finding a resource in a bundle by reference using FHIR nuget package
我正在使用 FHIR 包,并尝试使用 .net FHIR R4 nuget 包解析对包内资源的引用。我使用 this 信息作为参考。
如何解析 Bundle 中的引用:
- If the reference is not an absolute reference, convert it to an absolute URL:
- if the reference has the format [type]/[id], and
- if the fullUrl for the bundle entry containing the resource is a RESTful one (see the RESTful URL regex)
- extract the [root] from the fullUrl, and append the reference (type/id) to it
- then try to resolve within the bundle as for a RESTful URL reference.
- If no resolution is possible, then the reference has no defined meaning within this specification
- else no resolution is possible and the reference has no defined meaning within this specification
- else
- Look for an entry with a fullUrl that matches the URI in the reference
- if no match is found, and the URI is a URL that can be resolved (e.g. if an http: URL), try accessing it directly)
Note, in addition, that a reference may be by identifier, and if it
is, and there is no URL, it may be resolved by scanning the ids in the
bundle. Note also that transactions may contain conditional references
that must be resolved by the server before processing the matches.
If the reference is version specific (either relative or absolute),
then remove the version from the URL before matching fullUrl, and then
match the version based on Resource.meta.versionId. Note that the
rules for resolving references in contained resources are the same as
those for resolving resources in the resource that contains the
contained resource.
If multiple matches are found, it is ambiguous which is correct.
Applications MAY return an error or take some other action as they
deem appropriate.
Bundle.FindEntry 扩展方法似乎只适用于绝对引用,例如这个...
<entry>
<fullUrl value="http://example.org/fhir/Observation/124"/>
<resource>
<Observation>
<id value="124"/>
<subject>
<!-- this is reference to the first patient above -->
<reference value="http://example.org/fhir/Patient/23"/>
</subject>
</Observation>
</resource>
</entry>
...但是如果引用不是绝对的,它会抛出异常,例如:
<entry>
<fullUrl value="http://example.org/fhir/Observation/123"/>
<resource>
<Observation>
<id value="123"/>
<subject>
<!-- this is reference to the first patient above -->
<reference value="Patient/23"/>
</subject>
</Observation>
</resource>
</entry>
是否提供了可以解析相对引用的功能?
如果已经提供的东西失败,我将如何编写自己的东西?
- 如何按照规范中的规定将相对 url 转换为绝对?
- 从EntryComponent 的FullUrl 中提取root 来解析的逻辑是什么?我怎么知道根是什么?
- 我如何知道引用是通过标识符进行的?它看起来就像一个相对参考。
.Net FHIR 库中已经提供了相关功能,形式为 ResourceReference 上的扩展方法。对于您的示例,这样的事情可能会起作用:
ResourceReference r1 = ((Observation)b.Entry[0].Resource).Subject;
var abs = r1.GetAbsoluteUriForReference(b.Entry[0].FullUrl);
这从源资源中的主题字段获取(相对)引用,并使用源条目的 fullUrl 将其中的 endpoint/root 与相对引用相结合。
root/base/endpoint 将始终是资源类型的绝对 url 的一部分,但由于有时很难确定,库为您提供了 ResourceIdentity
功能建立参考资料或查看其中的特定部分。有关这方面的许多示例,请参阅 ResourceIdentity unit tests。
如果是标识符引用,则填写ResourceReference的.Identifier。或者,如果是条件引用,则填写ResourceIdentity的.Query。
我正在使用 FHIR 包,并尝试使用 .net FHIR R4 nuget 包解析对包内资源的引用。我使用 this 信息作为参考。
如何解析 Bundle 中的引用:
- If the reference is not an absolute reference, convert it to an absolute URL:
- if the reference has the format [type]/[id], and
- if the fullUrl for the bundle entry containing the resource is a RESTful one (see the RESTful URL regex)
- extract the [root] from the fullUrl, and append the reference (type/id) to it
- then try to resolve within the bundle as for a RESTful URL reference.
- If no resolution is possible, then the reference has no defined meaning within this specification
- else no resolution is possible and the reference has no defined meaning within this specification
- else
- Look for an entry with a fullUrl that matches the URI in the reference
- if no match is found, and the URI is a URL that can be resolved (e.g. if an http: URL), try accessing it directly)
Note, in addition, that a reference may be by identifier, and if it is, and there is no URL, it may be resolved by scanning the ids in the bundle. Note also that transactions may contain conditional references that must be resolved by the server before processing the matches.
If the reference is version specific (either relative or absolute), then remove the version from the URL before matching fullUrl, and then match the version based on Resource.meta.versionId. Note that the rules for resolving references in contained resources are the same as those for resolving resources in the resource that contains the contained resource.
If multiple matches are found, it is ambiguous which is correct. Applications MAY return an error or take some other action as they deem appropriate.
Bundle.FindEntry 扩展方法似乎只适用于绝对引用,例如这个...
<entry>
<fullUrl value="http://example.org/fhir/Observation/124"/>
<resource>
<Observation>
<id value="124"/>
<subject>
<!-- this is reference to the first patient above -->
<reference value="http://example.org/fhir/Patient/23"/>
</subject>
</Observation>
</resource>
</entry>
...但是如果引用不是绝对的,它会抛出异常,例如:
<entry>
<fullUrl value="http://example.org/fhir/Observation/123"/>
<resource>
<Observation>
<id value="123"/>
<subject>
<!-- this is reference to the first patient above -->
<reference value="Patient/23"/>
</subject>
</Observation>
</resource>
</entry>
是否提供了可以解析相对引用的功能? 如果已经提供的东西失败,我将如何编写自己的东西?
- 如何按照规范中的规定将相对 url 转换为绝对?
- 从EntryComponent 的FullUrl 中提取root 来解析的逻辑是什么?我怎么知道根是什么?
- 我如何知道引用是通过标识符进行的?它看起来就像一个相对参考。
.Net FHIR 库中已经提供了相关功能,形式为 ResourceReference 上的扩展方法。对于您的示例,这样的事情可能会起作用:
ResourceReference r1 = ((Observation)b.Entry[0].Resource).Subject;
var abs = r1.GetAbsoluteUriForReference(b.Entry[0].FullUrl);
这从源资源中的主题字段获取(相对)引用,并使用源条目的 fullUrl 将其中的 endpoint/root 与相对引用相结合。
root/base/endpoint 将始终是资源类型的绝对 url 的一部分,但由于有时很难确定,库为您提供了 ResourceIdentity
功能建立参考资料或查看其中的特定部分。有关这方面的许多示例,请参阅 ResourceIdentity unit tests。
如果是标识符引用,则填写ResourceReference的.Identifier。或者,如果是条件引用,则填写ResourceIdentity的.Query。