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 94525322afa..74ece7fe5f2 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 @@ -167,6 +167,18 @@ public interface ITestDataBuilder { }; } + default Consumer withOrganization(@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("organization").getMutator().addValue(t, reference); + } + }; + } + /** * Users of this API must implement this method */