Skip to content

Commit

Permalink
#1723 fix R3 Quantity.copyValues()
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Sep 18, 2024
1 parent f3bd5b9 commit 6952514
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hl7.fhir.dstu3.model;

import java.math.BigDecimal;
import java.util.ArrayList;

/*
Copyright (c) 2011+, HL7, Inc.
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 6952514

Please sign in to comment.