【发布时间】:2019-01-11 20:23:20
【问题描述】:
http://hapifhir.io/doc_custom_structures.html
本文讨论了域资源。
但在某些情况下,您可能想要完全创建一个 自定义资源类型。只有在没有 其他选项,因为这意味着您正在创建一个资源类型 将无法与其他 FHIR 实现互操作。
我已经逐字实现了代码。 (我展示了下面的类(为了简洁,没有“胆量”)(完整代码在 url))
/**
* 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);
}
(~尝试按照上面网址中的说明进行操作)
// 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-server。
我已经尝试了 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
无济于事...
网址是什么?
我如何填充它的值?
【问题讨论】:
-
创建资源默认不会创建 URL。您是否设置并配置了 RESTful 服务器?如果是这样,您可以在此处添加对自定义资源和类型 hapifhir.io/doc_rest_server.html 的访问权限。
-
是的,我让我的 fhir 服务器使用默认资源,例如 Patient 等
-
fhirContext 是“我的”代码...我在其中注册项目...因此我认为 URL 应该可以工作
-
要将资源注册到 REST 服务器,您需要为您的自定义资源创建 ResourceProvider 类,并将该 ResourceProvider 注册到服务器,如我提供的初始链接中所述,如果您使用的是示例 JPA 服务器,则此处hapifhir.io/doc_jpa.html 概述的默认资源已完成工作,但您仍需要为自己的自定义资源添加。
-
谢谢丹尼尔斯。现在我懂了”。我仍然需要为新的自定义资源创建一个 IResourceProvider ......并在那里添加一些方法。所以这是一个“呃”的时刻。我希望文档只是添加了一点点。有时你在树上那么远,看不到森林。我很快就会发布我的基本工作示例。