org.hl7.fhir.dstu3.model.Parameters 资源对象不会 hydrate/populate 扩展操作

org.hl7.fhir.dstu3.model.Parameters resource object will not hydrate/populate on extended operation

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

在该代码中,我有以下扩展操作。 (来自 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;
}

如果我从

传入示例JSON

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

POST

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

POST

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

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

{
  "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"
}

我看到了那张悲伤的脸。 :(

我什么都试过了。

"item" 始终为空。 Aka,我把这个拿回来了。

{
    "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;
}

POST

http://localhost:8080/fhir/Measure/MyMeasureName123/$泰迪熊

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 的回答和变通提示,我在下面输入了内容。

变通代码:(又名,"ANSWER" 在变通答案的意义上)

@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.  :) :)"
}

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

您可能可以通过添加如下参数来解决此问题:

@ResourceParam String theRawBody

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