From 930d860c709c27fbb37aae961306eee7c8903938 Mon Sep 17 00:00:00 2001 From: "b.debeaubien" Date: Fri, 31 Oct 2014 09:54:44 -0400 Subject: [PATCH] Updated docs in ResourceDef to indicate what id is used for (potentially it's also used for other things, though I didn't find any) Added a test that demonstrates using ResourceDef.id to set the id for a custom resource's profile --- .../model/api/annotation/ResourceDef.java | 2 +- .../uhn/fhir/context/CustomObservation.java | 30 +++++++++++++++++++ .../RuntimeResourceDefinitionTest.java | 10 +++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/CustomObservation.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java index 817b981b01f..03daf573e32 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/annotation/ResourceDef.java @@ -38,7 +38,7 @@ public @interface ResourceDef { String name() default ""; /** - * Not currently used + * if set, will be used as the id for any profiles generated for this resource */ String id() default ""; diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/CustomObservation.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/CustomObservation.java new file mode 100644 index 00000000000..0ff66e9d594 --- /dev/null +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/CustomObservation.java @@ -0,0 +1,30 @@ +package ca.uhn.fhir.context; + +import ca.uhn.fhir.model.api.annotation.Child; +import ca.uhn.fhir.model.api.annotation.Description; +import ca.uhn.fhir.model.api.annotation.Extension; +import ca.uhn.fhir.model.api.annotation.ResourceDef; +import ca.uhn.fhir.model.dstu.resource.Observation; +import ca.uhn.fhir.model.primitive.StringDt; + +/** + * Created by Bill de Beaubien on 10/31/2014. + */ +@ResourceDef(name="Observation", id="customobservation") +public class CustomObservation extends Observation { + @Child(name = "valueUnits", order = 3) + @Extension(url = "http://hapi.test.com/profile/customobservation#valueUnits", definedLocally = true, isModifier = false) + @Description(shortDefinition = "Units on an observation whose type is of valueString") + private StringDt myValueUnits; + + public StringDt getValueUnits() { + if (myValueUnits == null) { + myValueUnits = new StringDt(); + } + return myValueUnits; + } + + public void setValueUnits(StringDt theValueUnits) { + myValueUnits = theValueUnits; + } +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java index 01981d9b0e5..bf470e20bca 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java @@ -92,4 +92,14 @@ public class RuntimeResourceDefinitionTest { } + @Test + public void testProfileIdIsActualResourceName() { + FhirContext ctx = new FhirContext(CustomObservation.class); + RuntimeResourceDefinition def = ctx.getResourceDefinition(CustomObservation.class); + + Profile profile = (Profile) def.toProfile(); + + assertEquals("customobservation", profile.getId().toString()); + } + }