Jr 20240830 merge references (#6263)
* enhance clone operation * change log
This commit is contained in:
parent
1e2d8b123e
commit
0f2eb08a77
|
@ -194,6 +194,14 @@ public class FhirTerser {
|
|||
+ theTarget.getClass().getName());
|
||||
}
|
||||
|
||||
if (theSource instanceof IBaseReference && theTarget instanceof IBaseReference) {
|
||||
IBaseReference sourceReference = (IBaseReference) theSource;
|
||||
IBaseReference targetReference = (IBaseReference) theTarget;
|
||||
if (sourceReference.getResource() != null) {
|
||||
targetReference.setResource(sourceReference.getResource());
|
||||
}
|
||||
}
|
||||
|
||||
BaseRuntimeElementCompositeDefinition<?> sourceDef =
|
||||
(BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(theSource.getClass());
|
||||
BaseRuntimeElementCompositeDefinition<?> targetDef =
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: add
|
||||
issue: 6263
|
||||
title: "The method `FhirTerser.cloneInto()` has been enhanced to copy the `resource` field of a `Reference`,
|
||||
in addition to the fields that are accessible via the structure definition."
|
|
@ -12,6 +12,7 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
|||
import ca.uhn.fhir.model.dstu2.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Practitioner;
|
||||
import ca.uhn.fhir.model.primitive.BooleanDt;
|
||||
import ca.uhn.fhir.model.primitive.MarkdownDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
|
@ -182,6 +183,19 @@ public class FhirTerserDstu2Test {
|
|||
assertEquals("COMMENTS", obs.getComments());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneIntoReferenceWithResource() {
|
||||
// set up
|
||||
Practitioner practitioner = new Practitioner();
|
||||
ResourceReferenceDt source = new ResourceReferenceDt(practitioner);
|
||||
ResourceReferenceDt target = new ResourceReferenceDt();
|
||||
|
||||
// execute
|
||||
ourCtx.newTerser().cloneInto(source, target, false);
|
||||
|
||||
assertThat(target.getResource()).isSameAs(practitioner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllPopulatedChildElementsOfTypeDescendsIntoContained() {
|
||||
Patient p = new Patient();
|
||||
|
|
|
@ -470,6 +470,19 @@ public class FhirTerserR4Test {
|
|||
assertEquals("BBB", target.getValueStringType().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloneIntoReferenceWithResource() {
|
||||
// set up
|
||||
Practitioner practitioner = new Practitioner();
|
||||
Reference source = new Reference(practitioner);
|
||||
Reference target = new Reference();
|
||||
|
||||
// execute
|
||||
myCtx.newTerser().cloneInto(source, target, false);
|
||||
|
||||
assertThat(target.getResource()).isSameAs(practitioner);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetAllPopulatedChildElementsOfTypeDescendsIntoContained() {
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
|
|||
import org.hl7.fhir.r4.model.Address;
|
||||
import org.hl7.fhir.r4.model.BooleanType;
|
||||
import org.hl7.fhir.r4.model.Claim;
|
||||
import org.hl7.fhir.r4.model.Condition;
|
||||
import org.hl7.fhir.r4.model.DateTimeType;
|
||||
import org.hl7.fhir.r4.model.DateType;
|
||||
import org.hl7.fhir.r4.model.Enumerations;
|
||||
|
@ -15,12 +16,14 @@ import org.hl7.fhir.r4.model.HumanName;
|
|||
import org.hl7.fhir.r4.model.Identifier;
|
||||
import org.hl7.fhir.r4.model.Organization;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.hl7.fhir.r4.model.Practitioner;
|
||||
import org.hl7.fhir.r4.model.PrimitiveType;
|
||||
import org.hl7.fhir.r4.model.Reference;
|
||||
import org.hl7.fhir.r4.model.StringType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
@ -398,6 +401,21 @@ class TerserUtilTest {
|
|||
assertTrue(p2.getAddress().get(1).hasExtension());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMergeWithReference() {
|
||||
Practitioner practitioner = new Practitioner();
|
||||
practitioner.setId(UUID.randomUUID().toString());
|
||||
practitioner.addName().setFamily("Smith").addGiven("Jane");
|
||||
|
||||
Condition c1 = new Condition();
|
||||
c1.setRecorder(new Reference(practitioner));
|
||||
|
||||
Condition c2 = new Condition();
|
||||
|
||||
TerserUtil.mergeField(ourFhirContext, "recorder", c1, c2);
|
||||
|
||||
assertThat(c2.getRecorder().getResource()).isSameAs(practitioner);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCloneWithDuplicateNonPrimitives() {
|
||||
|
|
Loading…
Reference in New Issue