简体   繁体   English

使用 FHIR nuget package 通过引用查找包中的资源

[英]Finding a resource in a bundle by reference using FHIR nuget package

I'm consuming a FHIR bundle, and trying to resolve references to resources within the bundle, usin the .net FHIR R4 nuget package.我正在使用 FHIR 包,并尝试使用 .net FHIR R4 nuget ZEFE90A8E604A7C840E88D03A67F6B7DZ8 来解析对包中资源的引用。 I'm using this information as a reference.将此信息用作参考。

How to resolve a reference in a Bundle:如何解析 Bundle 中的引用:

  • If the reference is not an absolute reference, convert it to an absolute URL:如果引用不是绝对引用,请将其转换为绝对 URL:
    • if the reference has the format [type]/[id], and如果引用的格式为 [type]/[id],并且
    • if the fullUrl for the bundle entry containing the resource is a RESTful one (see the RESTful URL regex)如果包含资源的包条目的 fullUrl 是 RESTful 的(请参阅 RESTful URL 正则表达式)
      • extract the [root] from the fullUrl, and append the reference (type/id) to it从 fullUrl 中提取 [root],并 append 对它的引用(类型/id)
      • then try to resolve within the bundle as for a RESTful URL reference.然后尝试在捆绑包中解析 RESTful URL 参考。
      • 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查找具有与引用中的 URI 匹配的 fullUrl 的条目
    • if no match is found, and the URI is a URL that can be resolved (eg if an http: URL), try accessing it directly)如果没有找到匹配项,并且 URI 是可以解析的 URL(例如,如果是 http: URL),请尝试直接访问)

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.另外请注意,引用可能是通过标识符,如果是,并且没有 URL,则可以通过扫描包中的 id 来解决。 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.如果引用是特定于版本的(相对或绝对),则在匹配 fullUrl 之前从 URL 中删除版本,然后根据 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.应用程序可能会返回错误或采取一些其他他们认为合适的操作。

The Bundle.FindEntry extension method appears to only work on absolute references such as this... 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> 

...but it throws an exception if the reference is not absolute such as this: ...但是如果引用不是绝对的,则会引发异常,例如:

<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>

Is there any functionality provided that can resolve relative references?是否提供了可以解析相对引用的任何功能? Failing something already provided, How would I write my own?失败的东西已经提供,我将如何编写自己的?

  • How do you convert arelative url to absolute as stated should be done in the spec?您如何按照规范中的说明将相对 url 转换为绝对值?
  • What would be the logic for extracting the root from the EntryComponent's FullUrl to resolve?从 EntryComponent 的 FullUrl 中提取根来解析的逻辑是什么? How do I know what the root is?我怎么知道根是什么?
  • How do I know that a reference is by identifier?我怎么知道引用是通过标识符? it looks just like a relative reference.它看起来就像一个相对参考。

There is functionality for that in the.Net FHIR library already, in the form of extension methods on ResourceReference. .Net FHIR 库中已经有相应的功能,以 ResourceReference 上的扩展方法的形式。 For your example something like this could work:对于您的示例,这样的事情可能会起作用:

    ResourceReference r1 = ((Observation)b.Entry[0].Resource).Subject;
    var abs = r1.GetAbsoluteUriForReference(b.Entry[0].FullUrl);

This takes the (relative) reference from the subject field in the source resource, and uses the source entry's fullUrl to combine the endpoint/root in that with the relative reference.这从源资源中的主题字段获取(相对)引用,并使用源条目的 fullUrl 将端点/根与相对引用结合起来。

The root/base/endpoint will always be the part of the absolute url up to the resource type, but since that is sometimes hard to determine, the library offers you the ResourceIdentity functionality to build references or look at specific parts of them. root/base/endpoint 将始终是绝对 url 的一部分,直到资源类型,但由于有时很难确定,该库为您提供ResourceIdentity功能来构建引用或查看它们的特定部分。 See ResourceIdentity unit tests for many examples on that.有关这方面的许多示例,请参阅ResourceIdentity 单元测试

If a reference is by identifier, the.Identifier of the ResourceReference will be filled in. Or, if it is a conditional reference, the.Query of the ResourceIdentity will be filled.如果引用是标识符,则填写ResourceReference的.Identifier。或者,如果是条件引用,则填写ResourceIdentity的.Query。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM