HAPI FHIR 中的条件引用
Conditional References in HAPI FHIR
HL7 FHIR 第 3 版 (STU) 在事务包中引入了条件引用 的概念:
When constructing the bundle, the client may not know the logical id
of a resource, but it may know identifying information - e.g. an
identifier. This situation arises commonly when building transactions
from v2 messages. The client could resolve that identifier to a
logical id using a search, but that would mean that the resolution to
a logical id does not occur within the same transaction as the commit
(as well as significantly complicating the client). Because of this,
in a transaction (and only in a transaction), references to resources
may be replaced by a search URI that describes how to find the correct
reference:
<Bundle xmlns="http://hl7.org/fhir">
<id value="20160113160203" />
<type value="transaction" />
<entry>
<fullUrl value="urn:uuid:c72aa430-2ddc-456e-7a09-dea8264671d8" />
<resource>
<Observation>
<subject>
<reference value="Patient?identifier=12345" />
</subject>
<!-- rest of resource omitted -->
</Observation>
</resource>
<request>
<method value="POST" />
</request>
</entry>
</Bundle>
The search URI is relative to the server's [base] path, and always
starts with a resource type: [type]:?parameters....
Only filtering
parameters are allowed; none of the parameters that control the return
of resources are relevant.
When processing transactions, servers SHALL:
- check all references for search URIs
- For search URIs, use the search to locate matching resources
- if there are no matches, or multiple matches, the transaction fails, and an error is returned to the user
- if there is a single match, the server replaces the search URI with a reference to the matching resource
...引用自2.21.0.17.2 Transaction Processing Rules
我发现条件引用的概念非常有用,我想在我的 HAPI FHIR client/server 应用程序中使用它。好像不支持。服务器拒绝此类交易包 si,并显示以下错误消息:
客户:
HTTP 400 Bad Request: Invalid resource reference found at path[Observation.subject]
- Does not contain resource type - Patient?identifier=12345
Exception in thread "main" ca.uhn.fhir.rest.server.exceptions.InvalidRequestException: HTTP 400 Bad Request: Invalid resource reference found at path[Observation.subject] - Does not contain resource type - Patient?identifier=12345
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException.newInstance(BaseServerResponseException.java:307)
at ca.uhn.fhir.rest.client.BaseClient.invokeClient(BaseClient.java:290)
at ca.uhn.fhir.rest.client.GenericClient$BaseClientExecutable.invoke(GenericClient.java:637)
at ca.uhn.fhir.rest.client.GenericClient$TransactionExecutable.execute(GenericClient.java:2209)
服务器日志:
WARN c.u.f.r.s.i.ExceptionHandlingInterceptor [ExceptionHandlingInterceptor.java:135] Failure during REST processing: ca.uhn.fhir.rest.server.exceptions.InvalidRequestException: Invalid resource reference found at path[Observation.subject]
- Does not contain resource type - Patient?identifier=12345
所以我的问题是:
是否可以对 HAPI FHIR JPA 服务器使用条件引用?
或者,如果不可能,是否有变通办法?如果引用目标不存在,我可以使用相同的条件操作来解析引用或失败吗?
最后我发现即使使用 HAPI FHIR 版本 2.2
也可以简单地通过向服务器添加以下选项 DaoConfig
:
ca.uhn.fhir.jpa.dao.DaoConfig.setAllowInlineMatchUrlReferences(true)
Should references containing match URLs be resolved and replaced in
create and update operations. For example, if this property is set to
true and a resource is created containing a reference to
Patient?identifier=12345
, this is reference match URL will be
resolved and replaced according to the usual match URL rules.
Default is false
for now, as this is an experimental feature.
在此处查看源代码:github.com/jamesagnew/hapi-fhir
HL7 FHIR 第 3 版 (STU) 在事务包中引入了条件引用 的概念:
When constructing the bundle, the client may not know the logical id of a resource, but it may know identifying information - e.g. an identifier. This situation arises commonly when building transactions from v2 messages. The client could resolve that identifier to a logical id using a search, but that would mean that the resolution to a logical id does not occur within the same transaction as the commit (as well as significantly complicating the client). Because of this, in a transaction (and only in a transaction), references to resources may be replaced by a search URI that describes how to find the correct reference:
<Bundle xmlns="http://hl7.org/fhir">
<id value="20160113160203" />
<type value="transaction" />
<entry>
<fullUrl value="urn:uuid:c72aa430-2ddc-456e-7a09-dea8264671d8" />
<resource>
<Observation>
<subject>
<reference value="Patient?identifier=12345" />
</subject>
<!-- rest of resource omitted -->
</Observation>
</resource>
<request>
<method value="POST" />
</request>
</entry>
</Bundle>
The search URI is relative to the server's [base] path, and always starts with a resource type:
[type]:?parameters....
Only filtering parameters are allowed; none of the parameters that control the return of resources are relevant.When processing transactions, servers SHALL:
- check all references for search URIs
- For search URIs, use the search to locate matching resources
- if there are no matches, or multiple matches, the transaction fails, and an error is returned to the user
- if there is a single match, the server replaces the search URI with a reference to the matching resource
...引用自2.21.0.17.2 Transaction Processing Rules
我发现条件引用的概念非常有用,我想在我的 HAPI FHIR client/server 应用程序中使用它。好像不支持。服务器拒绝此类交易包 si,并显示以下错误消息:
客户:
HTTP 400 Bad Request: Invalid resource reference found at
path[Observation.subject]
- Does not contain resource type -Patient?identifier=12345
Exception in thread "main" ca.uhn.fhir.rest.server.exceptions.InvalidRequestException: HTTP 400 Bad Request: Invalid resource reference found at path[Observation.subject] - Does not contain resource type - Patient?identifier=12345
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException.newInstance(BaseServerResponseException.java:307)
at ca.uhn.fhir.rest.client.BaseClient.invokeClient(BaseClient.java:290)
at ca.uhn.fhir.rest.client.GenericClient$BaseClientExecutable.invoke(GenericClient.java:637)
at ca.uhn.fhir.rest.client.GenericClient$TransactionExecutable.execute(GenericClient.java:2209)
服务器日志:
WARN c.u.f.r.s.i.ExceptionHandlingInterceptor [ExceptionHandlingInterceptor.java:135] Failure during REST processing: ca.uhn.fhir.rest.server.exceptions.InvalidRequestException: Invalid resource reference found at
path[Observation.subject]
- Does not contain resource type -Patient?identifier=12345
所以我的问题是:
是否可以对 HAPI FHIR JPA 服务器使用条件引用?
或者,如果不可能,是否有变通办法?如果引用目标不存在,我可以使用相同的条件操作来解析引用或失败吗?
最后我发现即使使用 HAPI FHIR 版本 2.2
也可以简单地通过向服务器添加以下选项 DaoConfig
:
ca.uhn.fhir.jpa.dao.DaoConfig.setAllowInlineMatchUrlReferences(true)
Should references containing match URLs be resolved and replaced in create and update operations. For example, if this property is set to true and a resource is created containing a reference to
Patient?identifier=12345
, this is reference match URL will be resolved and replaced according to the usual match URL rules.Default is
false
for now, as this is an experimental feature.
在此处查看源代码:github.com/jamesagnew/hapi-fhir