Using a custom DomainResource on happy fhir fhir-server


#1

http://hapifhir.io/doc_custom_structures.html

this article discusses a 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.

I’ve implemented the code verbatum. (I show the classes below (with no “guts” just for brevity) (full code at the 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 {
}

and

/**
 * 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 {
}

And I’ve “registered it” in my code base:

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

(~trying to follow the instructions from the URL above)

// 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);

But that looks like a console-app usage of two objects…not how to wire it into the fhir-server.

I’ve been trying for 3 hours now to figure out what URL to use.

some things I’ve tried:

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

to no avail…

What is the URL?

And how do I populate the values for it?