gpt4 book ai didi

hl7-fhir - Hapi Fhir DomainResource,您使用什么 URL?

转载 作者:行者123 更新时间:2023-12-02 16:42:17 27 4
gpt4 key购买 nike

http://hapifhir.io/doc_custom_structures.html

本文讨论 DomainResource。

There are situations however when you might want to create an entirely custom resource type. This feature should be used only if there is no other option, since it means you are creating a resource type that will not be interoperable with other FHIR implementations.

我已经逐字实现了代码。 (我展示了下面的类(为了简洁起见,没有“胆量”)(完整代码位于网址))

/**
* This is an example of a custom resource that also uses a custom
* datatype.
*
* Note that we are extensing DomainResource for an STU3
* resource. For DSTU2 it would be BaseResource.
*/
@ResourceDef(name = "CustomResource", profile = "http://hl7.org/fhir/profiles/custom-resource")
public class CustomResource extends DomainResource {
}

/**
* This is an example of a custom datatype.
*
* This is an STU3 example so it extends Type and implements ICompositeType. For
* DSTU2 it would extend BaseIdentifiableElement and implement ICompositeDatatype.
*/
@DatatypeDef(name="CustomDatatype")
public class CustomDatatype extends Type implements ICompositeType {
}

我已经在我的代码库中“注册了它”:

        if (null != this.fhirContext)
{
this.fhirContext.registerCustomType(CustomResource.class);
this.fhirContext.registerCustomType(CustomDatatype.class);
}

(~尝试按照上面 URL 中的说明进行操作)

// Create a context. Note that we declare the custom types we'll be using
// on the context before actually using them
FhirContext ctx = FhirContext.forDstu3();
ctx.registerCustomType(CustomResource.class);
ctx.registerCustomType(CustomDatatype.class);

// Now let's create an instance of our custom resource type
// and populate it with some data
CustomResource res = new CustomResource();

// Add some values, including our custom datatype
DateType value0 = new DateType("2015-01-01");
res.getTelevision().add(value0);

CustomDatatype value1 = new CustomDatatype();
value1.setDate(new DateTimeType(new Date()));
value1.setKittens(new StringType("FOO"));
res.getTelevision().add(value1);

res.setDogs(new StringType("Some Dogs"));

// Now let's serialize our instance
String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(res);
System.out.println(output);

但这看起来像是两个对象的控制台应用程序使用...而不是如何将其连接到 fhir 服务器。

我已经尝试了 3 个小时来找出要使用的 URL。

我尝试过的一些事情:

http://127.0.0.1:8080/fhir/CustomResource

http://127.0.0.1:8080/fhir/profiles/custom-resource

http://127.0.0.1:8080/fhir/custom-resource

没用...

网址是什么?

如何填充它的值?

最佳答案

好的。

所以 CustomResource 仍然需要它自己的 IResourceProvider。 (感谢丹尼尔斯在原始问题的评论中)

这是一个基本的工作示例。

您将执行我在原始问题中列出的所有操作,并且将为新的自定义资源创建并注册 IResourceProvider。

新的 IResourceProvider

package mystuff.resourceproviders;

import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.IdType;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.server.IResourceProvider;
import mystuff.CustomDatatype;
import mystuff.CustomResource;
import org.hl7.fhir.dstu3.model.DateTimeType;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.instance.model.api.IBaseResource;

import java.util.Date;

public class CustomResourceProvider implements IResourceProvider {


@Override
public Class<? extends IBaseResource> getResourceType() {
return CustomResource.class;
}


/* the IdType (datatype) will be different based on STU2 or STU3. STU3 version below */
@Read()
public CustomResource getResourceById(@IdParam IdType theId) {
// Now let's create an instance of our custom resource type
// and populate it with some data
CustomResource res = new CustomResource();
res.setId(theId);

// Add some values, including our custom datatype
DateType value0 = new DateType("2015-01-01");
res.getTelevision().add(value0);

CustomDatatype value1 = new CustomDatatype();
value1.setDate(new DateTimeType(new Date()));
value1.setKittens(new StringType("FOO"));
res.getTelevision().add(value1);

res.setDogs(new StringType("Some Dogs"));
return res;
}
}

然后您将注册它(如此处所述):

http://hapifhir.io/doc_rest_server.html#_toc_create_a_server

而不是这个:

   @Override
protected void initialize() throws ServletException {
/*
* The servlet defines any number of resource providers, and
* configures itself to use them by calling
* setResourceProviders()
*/
List<IResourceProvider> resourceProviders = new ArrayList<IResourceProvider>();
resourceProviders.add(new RestfulPatientResourceProvider());
resourceProviders.add(new RestfulObservationResourceProvider());
setResourceProviders(resourceProviders);
}

你会得到这样的东西

   @Override
protected void initialize() throws ServletException {
/*
* The servlet defines any number of resource providers, and
* configures itself to use them by calling
* setResourceProviders()
*/
List<IResourceProvider> resourceProviders = new ArrayList<IResourceProvider>();
resourceProviders.add(new CustomResourceProvider());
setResourceProviders(resourceProviders);
}

用于测试此的 URL(最可能的本地开发 URL)

http://127.0.0.1:8080/fhir/CustomResource/12345

您将收到此 JSON 响应。

{
"resourceType": "CustomResource",
"id": "12345",
"meta": {
"profile": [
"http://hl7.org/fhir/profiles/custom-resource"
]
},
"televisionDate": [
"2015-01-01"
],
"televisionCustomDatatype": [
{
"date": "2019-01-14T11:49:44-05:00",
"kittens": "FOO"
}
],
"dogs": "Some Dogs"
}

关于hl7-fhir - Hapi Fhir DomainResource,您使用什么 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54153559/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com