首页 > 解决方案 > 如何在 HAPI FHIR 中包含完整对象而不是“包含”

问题描述

我对 hapi FHIR 很陌生,我正在尝试以以下格式对请求进行编码。

   CoverageEligibilityRequest coverageEligibilityRequest =  new CoverageEligibilityRequest();
   Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
   coverageEligibilityRequest.setPatient(new Reference(patient));

上面的代码是用于在 CoverageEligibilityRequest 中填充患者的 java 片段。

{
  "resourceType": "Bundle",
  "type": "batch",
  "entry": [ {
    "resource": {
      "resourceType": "CoverageEligibilityRequest",
      "id": "7890",
      "contained": [ {
        "resourceType": "Patient",
        "id": "1",
        "identifier": [ {
          "type": {
            "coding": [ {
             ...
             ...

}

但我希望请求应采用以下格式

{
  "resourceType": "Bundle",
  "type": "batch",
  "entry": [ {
    "resource": {
      "resourceType": "CoverageEligibilityRequest",
      "id": "7890",
      "patient": {
        "type": "Patient",
        "identifier": {
          "type": {
            "coding": [ {
              ...
              ...

            } ]
          },

我想在哪里contained 省略actual string

标签: javahl7-fhirhapihapi-fhir

解决方案


FHIR 通常不允许您将整个对象图表示为单个资源,因此如果您尝试将Patient资源作为资源的一部分发送CoverageEligibilityRequest,那么您可以做到这一点的唯一方法是将患者设置在contained现场。该CoverageEligibilityResource.patient字段被定义为一种Reference类型,因此只能包含数据类型允许的Reference数据,不能包含任意数据。

看起来您实际上想要做的是向PatientHAPI FHIR 服务器和CoverageEligibilityRequest引用患者的资源添加一个。在 FHIR 中执行此操作的正确方法是构建包含这两种资源的单个batchtransaction捆绑包。基本上,您想要构建一个Bundle看起来像这样的:

{
  "resourceType": "Bundle",
  "type": "batch",
  "entry": [ {
      "resource": {
        "resourceType": "Patient",
        "id": "1",
        "identifier": [ {
          "type": {
            "coding": [ {
             ...
      }
    }, {
      "resource": {
        "resourceType": "CoverageEligibilityRequest",
        "id": "7890",
        "patient": "Patient/1",
        ...

在 HAPI FHIR 中构造类似内容的最简单方法是使用这样的transaction包:

IGenericClient client = ...
CoverageEligibilityRequest coverageEligibilityRequest =  new CoverageEligibilityRequest();
Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
coverageEligibilityRequest.setPatient(new Reference(patient));
client.transaction().withResources(patient, coverageEligibilityRequest);

推荐阅读