Hapi Fhir DomainResource,你用什么URL?

Hapi Fhir DomainResource, What URL do you use?

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.

我已经逐字执行了代码。 (我在下面显示 类(没有 "guts" 只是为了简洁)(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 {
}

我的代码库中有 "registered it":

        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-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?

我该如何填充它的值?

好的。

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