1

我有一个自定义 IResourceProvider 服务于 Measure (Measure.class)。

在该代码中,我有以下扩展操作。(来自http://hapifhir.io/doc_rest_operations.html#_toc_extended_operations

@Operation(name = "$humptydumpty")
public org.hl7.fhir.dstu3.model.Bundle acceptHumptyDumpty(HttpServletRequest servletRequest,
                                                                  @IdParam(optional = true) IdType theId,
                                                                  @OperationParam(name = "request") org.hl7.fhir.dstu3.model.Measure item) {
    String fakeMessage;

    if (null == item) {
        fakeMessage = "org.hl7.fhir.dstu3.model.Measure item is null.  Sad face.  :( ";
    } else {
        fakeMessage = "org.hl7.fhir.dstu3.model.Measure item is not null.  Happy face.  :) ";
    }


    Bundle retVal = new Bundle();
    retVal.setId(fakeMessage);
    return retVal;
}

如果我从

http://hl7.org/fhir/STU3/measure-exclusive-breastfeeding.json.html

邮政

http://localhost:8080/fhir/Measure/MyMeasureName123/ $humptydumpty

一切正常。我回来。

{
    "resourceType": "Bundle",
    "id": "org.hl7.fhir.dstu3.model.Measure item is not null.  Happy face.  :) "
}

所以我了解 $myExtendedMethod 如何工作的基础知识。

现在,当我对 .Parameters 尝试相同的操作时......

Java 代码(与上面相同的 MyResourceProvider)

@Operation(name = "$robinhood")
public Bundle acceptRobinHood(HttpServletRequest servletRequest,
                                         @IdParam(optional = true) IdType theId,
                                         @OperationParam(name = "request") org.hl7.fhir.dstu3.model.Parameters item) {

    String fakeMessage;

    if (null == item) {
        fakeMessage = "org.hl7.fhir.dstu3.model.Parameters item is null.  Sad face.  :( ";
    } else {
        fakeMessage = "org.hl7.fhir.dstu3.model.Parameters item is not null.  Happy face.  :) ";
    }


    Bundle retVal = new Bundle();
    retVal.setId(fakeMessage);
    return retVal;
}

邮政

http://localhost:8080/fhir/Measure/MyMeasureName123/ $robinhood

我已经从http://hl7.org/fhir/STU3/parameters-example.json发送了“示例” 。

{
  "resourceType": "Parameters",
  "id": "example",
  "parameter": [
    {
      "name": "start",
      "valueDate": "2010-01-01"
    },
    {
      "name": "end",
      "resource": {
        "resourceType": "Binary",
        "contentType": "text/plain",
        "content": "VGhpcyBpcyBhIHRlc3QgZXhhbXBsZQ=="
      }
    }
  ]
}

如果我发送......最基本的json。

{
  "resourceType": "Parameters",
  "id": "MyParameterId234"
}

我得到了悲伤的脸。:(

我什么都试过了。

“项目”始终为空。啊,我把这个拿回来了。

{
    "resourceType": "Bundle",
    "id": "org.hl7.fhir.dstu3.model.Parameters item is null.  Sad face.  :( "
}

我尝试了很多东西,最后回到“.Measure”只是为了证明我没有疯。

但我不明白为什么一个会填充(.Measure 资源),而另一个(.Parameters)不会。#帮助

我的hapi fhir版本:

<properties>
    <hapi.version>3.6.0</hapi.version>
</properties>

    <!-- FHIR dependencies -->
    <dependency>
        <groupId>ca.uhn.hapi.fhir</groupId>
        <artifactId>hapi-fhir-structures-dstu3</artifactId>
        <version>${hapi.version}</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi.fhir</groupId>
        <artifactId>hapi-fhir-server</artifactId>
        <version>${hapi.version}</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi.fhir</groupId>
        <artifactId>hapi-fhir-base</artifactId>
        <version>${hapi.version}</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi.fhir</groupId>
        <artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
        <version>${hapi.version}</version>
    </dependency>

附加:

我为病人做了一个

@Operation(name = "$teddybear")
public org.hl7.fhir.dstu3.model.Bundle acceptTeddyBear(HttpServletRequest servletRequest,
                                                          @IdParam(optional = true) IdType theId,
                                                          @OperationParam(name = "request") org.hl7.fhir.dstu3.model.Patient item) {
    String fakeMessage;

    if (null == item) {
        fakeMessage = "org.hl7.fhir.dstu3.model.Patient item is null.  Sad face.  :( ";
    } else {
        fakeMessage = "org.hl7.fhir.dstu3.model.Patient item is not null.  Happy face.  :) ";
    }


    Bundle retVal = new Bundle();
    retVal.setId(fakeMessage);
    return retVal;
}

邮政

http://localhost:8080/fhir/Measure/MyMeasureName123/ $ teddybear

http://hl7.org/fhir/STU3/patient-example.json

它工作正常。

{
    "resourceType": "Bundle",
    "id": "org.hl7.fhir.dstu3.model.Patient item is not null.  Happy face.  :) "
}

它唯一伤害我的 .Parameters 资源。

附加

根据 James A 的回答和解决提示,我在下面输入了。

变通代码:(也就是变通答案意义上的“答案”)

@Operation(name = "$robinhood")
public Bundle acceptRobinHood(HttpServletRequest servletRequest,
                              @IdParam(optional = true) IdType theId,
        /*@OperationParam(name = "request") org.hl7.fhir.dstu3.model.Parameters item*/ @ResourceParam String theRawBody) {
    String fakeMessage;

    if (null == theRawBody || StringUtils.isBlank(theRawBody)) {
        fakeMessage = "theRawBody is null or isBlank.  Sad face.  :( ";
    } else {
        fakeMessage = "theRawBody is not null and is not isBlank.  Happy face.  :) ";
    }

    org.hl7.fhir.dstu3.model.Parameters paramsObject = null;
    FhirContext ctx = FhirContext.forDstu3();//  this.getContext();  /* prefer encapsulated over hard coding, but for SOF, put in the hard code */
    IParser parser = ctx.newJsonParser();
    IBaseResource res = parser.parseResource(theRawBody);
    paramsObject = (org.hl7.fhir.dstu3.model.Parameters) res;
    if (null != paramsObject) {
        fakeMessage += " org.hl7.fhir.dstu3.model.Parameters was serialized from theRawBody.  Super Happy face.  :) :)";
    }
    else
    {
        fakeMessage += " org.hl7.fhir.dstu3.model.Parameters was NOT serialized from theRawBody (is null).  Super Sad face.  :( :( ";
    }

    Bundle retVal = new Bundle();
    retVal.setId(fakeMessage);
    return retVal;
}

以及执行代码的响应:

{
    "resourceType": "Bundle",
    "id": "theRawBody is not null and is not isBlank.  Happy face.  :)  org.hl7.fhir.dstu3.model.Parameters was serialized from theRawBody.  Super Happy face.  :) :)"
}
4

1 回答 1

1

老实说,这看起来像是 HAPI FHIR 中的一个错误。如果您想在 GitHub 跟踪器上报告它,那就太好了。

您可能可以通过添加以下参数来解决它:

@ResourceParam 字符串 theRawBody

并使用 HAPI FHIR 的解析器来解析参数资源。这肯定很烦人,但我相信它会起作用。

于 2019-03-07T02:28:27.663 回答