diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Quantity.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Quantity.java index fd3912594a..1fe0a11e02 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Quantity.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Quantity.java @@ -1,6 +1,7 @@ package org.hl7.fhir.dstu3.model; import java.math.BigDecimal; +import java.util.ArrayList; /* Copyright (c) 2011+, HL7, Inc. @@ -668,12 +669,16 @@ public String fhirType() { public Quantity copy() { Quantity dst = new Quantity(); copyValues(dst); + return dst; + } + + public void copyValues(Quantity dst) { + super.copyValues(dst); dst.value = value == null ? null : value.copy(); dst.comparator = comparator == null ? null : comparator.copy(); dst.unit = unit == null ? null : unit.copy(); dst.system = system == null ? null : system.copy(); dst.code = code == null ? null : code.copy(); - return dst; } protected Quantity typedCopy() { diff --git a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/MedicationAdministrationCopyTest.java b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/MedicationAdministrationCopyTest.java new file mode 100644 index 0000000000..a1adeb2165 --- /dev/null +++ b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/MedicationAdministrationCopyTest.java @@ -0,0 +1,40 @@ +package org.hl7.fhir.dstu3.model; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.hl7.fhir.dstu3.formats.JsonParser; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class MedicationAdministrationCopyTest { + + @DisplayName("Test MedicationAdministration copy") + @Test + public void test() throws IOException { + MedicationAdministration beforeCopy = createMedAdminWithDosageDurationExtension(); + MedicationAdministration afterCopy = beforeCopy.copy(); + + System.out.println("---- BEFORE COPY (BEGIN)"); + System.out.println(new JsonParser().composeString(beforeCopy)); + System.out.println("---- BEFORE COPY (END)"); + System.out.println(); + System.out.println("---- AFTER COPY (BEGIN)"); + System.out.println(new JsonParser().composeString(afterCopy)); + System.out.println("---- AFTER COPY (END)"); + assertTrue(beforeCopy.equalsDeep(afterCopy)); + } + + private static MedicationAdministration createMedAdminWithDosageDurationExtension() { + MedicationAdministration resource = new MedicationAdministration(); + resource.setId("12345"); + var dosage = new MedicationAdministration.MedicationAdministrationDosageComponent(); + dosage.setDose((SimpleQuantity) new SimpleQuantity().setValue(40)) + .addExtension(new Extension() + .setUrl("http://duration") + .setValue(new Duration().setValue(5340000))); + resource.setDosage(dosage); + return resource; + } +}