代码之家  ›  专栏  ›  技术社区  ›  granadaCoder

Hapi Fhir域资源,您使用什么URL?

  •  3
  • granadaCoder  · 技术社区  · 7 年前

    http://hapifhir.io/doc_custom_structures.html

    本文讨论域资源。

    但是,在某些情况下,您可能希望创建一个完全 自定义资源类型。此功能仅在没有 其他选项,因为这意味着您正在创建 将无法与其他FHIR实现互操作。

    我已经实现了verbatum代码。(我在下面展示了这些类(为了简洁起见没有“胆量”)(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);
            }
    

    (~尝试按照上面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

    没有用。。。

    什么是URL?

    我如何填充它的值?

    1 回复  |  直到 7 年前
        1
  •  2
  •   granadaCoder    7 年前

    好啊

    因此CustomResource仍然需要自己的IResourceProvider。(感谢daniels对原始问题的评论)

    下面是一个基本的工作示例。

    您将完成我在原始问题中列出的所有操作,并为新customresource创建并注册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

    {
        "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"
    }
    
    推荐文章