From 2bd304ffaea45d6cac2ed83ba668644d8ee0103b Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 11 Sep 2020 11:34:50 -0400 Subject: [PATCH] Add method to test data builder --- .../ca/uhn/fhir/test/utilities/ITestDataBuilder.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java index ee8ecdb58c9..94525322afa 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java @@ -155,6 +155,18 @@ public interface ITestDataBuilder { }; } + default Consumer withObservationHasMember(@Nullable IIdType theHasMember) { + return t -> { + if (theHasMember != null) { + IBaseReference reference = (IBaseReference) getFhirContext().getElementDefinition("Reference").newInstance(); + reference.setReference(theHasMember.getValue()); + + RuntimeResourceDefinition resourceDef = getFhirContext().getResourceDefinition(t.getClass()); + resourceDef.getChildByName("hasMember").getMutator().addValue(t, reference); + } + }; + } + /** * Users of this API must implement this method */