org.hl7.fhir.dstu3.model.Parameters资源对象在扩展操作中不会水合/填充

时间:2019-03-07 02:08:34

标签: hl7-fhir hapi-fhir

我有一个自定义的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;
}

如果我从中传入示例JSON

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

我感到悲伤。 :(

我已经尝试了一切。

“ item”始终为null。 aka,我回来了。

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

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

但是我不知道为什么一个填充(.Measure资源),而另一个填充(.Parameters)。 #help

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

APPEND:

我为病人做了一个

@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资源。

APPEND

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

1 个答案:

答案 0 :(得分:1)

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

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

@ResourceParam字符串theRawBody

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