我有一个为Measure提供服务的自定义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;
}
http://hl7.org/fhir/STU3/measure-exclusive-breastfeeding.json.html
http://localhost:8080/fhir/Measure/MyMeasureName123/
{
"resourceType": "Bundle",
"id": "org.hl7.fhir.dstu3.model.Measure item is not null. Happy face. :) "
}
所以我了解$myextended方法的基本原理。
现在,当我尝试同样的参数。。。。
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://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=="
}
}
]
}
{
"resourceType": "Parameters",
"id": "MyParameterId234"
}
我什么都试过了。
“item”始终为空。阿卡,我把这个拿回来。
{
"resourceType": "Bundle",
"id": "org.hl7.fhir.dstu3.model.Parameters item is null. Sad face. :( "
}
我试了很多次,最后还是回到“.Measure”来证明我没疯。
但是我不明白为什么一个会填充(.Measure resource),而另一个(.Parameters)不会。#帮助
<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/测量/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资源。
追加
@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. :) :)"
}