mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-16 18:05:19 +00:00
Merge pull request #725 from InfiniteLoop90/issue-724-copy-domain-resource-id
Fixes #724 - Resource IDs are now copied when copying instances of subclasses of DomainResource for DSTU2 and DSTU2.1.
This commit is contained in:
commit
c5b7fea01d
@ -159,6 +159,7 @@ public abstract class BackboneElement extends Element implements IBaseBackboneEl
|
||||
public abstract BackboneElement copy();
|
||||
|
||||
public void copyValues(BackboneElement dst) {
|
||||
super.copyValues(dst);
|
||||
if (modifierExtension != null) {
|
||||
dst.modifierExtension = new ArrayList<Extension>();
|
||||
for (Extension i : modifierExtension)
|
||||
|
@ -340,6 +340,7 @@ public abstract class DomainResource extends Resource implements IBaseHasExtensi
|
||||
public abstract DomainResource copy();
|
||||
|
||||
public void copyValues(DomainResource dst) {
|
||||
super.copyValues(dst);
|
||||
dst.text = text == null ? null : text.copy();
|
||||
if (contained != null) {
|
||||
dst.contained = new ArrayList<Resource>();
|
||||
|
@ -0,0 +1,26 @@
|
||||
package ca.uhn.fhir.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hl7.fhir.dstu2016may.model.BackboneElement;
|
||||
import org.hl7.fhir.dstu2016may.model.Patient.PatientCommunicationComponent;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BackboneElementDstu2_1Test {
|
||||
/**
|
||||
* Ensuring that IDs of subtypes of BackboneElement get copied when
|
||||
* the {@link org.hl7.fhir.dstu2016may.model.BackboneElement#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCommunicationComponentIdCopy() {
|
||||
PatientCommunicationComponent pcc1 = new PatientCommunicationComponent();
|
||||
pcc1.setId("1001");
|
||||
|
||||
PatientCommunicationComponent copiedPcc = pcc1.copy();
|
||||
String copiedPccID = copiedPcc.getIdElement().getIdPart();
|
||||
|
||||
assertTrue(copiedPcc instanceof BackboneElement); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPccID);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package ca.uhn.fhir.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hl7.fhir.dstu2016may.model.DomainResource;
|
||||
import org.hl7.fhir.dstu2016may.model.Narrative;
|
||||
import org.hl7.fhir.dstu2016may.model.Patient;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DomainResourceDstu2_1Test {
|
||||
/**
|
||||
* Ensuring that Ensuring that fields defined in {@link org.hl7.fhir.dstu2016may.model.DomainResource} and {@link org.hl7.fhir.dstu2016may.model.Resource}
|
||||
* get copied when the {@link org.hl7.fhir.dstu2016may.model.DomainResource#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCopy() {
|
||||
Patient p1 = new Patient();
|
||||
p1.setId("1001");
|
||||
p1.setText(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL));
|
||||
|
||||
Patient copiedPatient = p1.copy();
|
||||
String copiedPatientID = copiedPatient.getIdElement().getIdPart();
|
||||
Narrative.NarrativeStatus copiedPatientTextStatus = copiedPatient.getText().getStatus();
|
||||
|
||||
assertTrue(copiedPatient instanceof DomainResource); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPatientID);
|
||||
assertEquals(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL).getStatus(), copiedPatientTextStatus);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package org.hl7.fhir.dstu3.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hl7.fhir.dstu3.model.Patient.PatientCommunicationComponent;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BackboneElementDstu3Test {
|
||||
/**
|
||||
* Ensuring that IDs of subtypes of BackboneElement get copied when
|
||||
* the {@link BackboneElement#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCommunicationComponentCopy() {
|
||||
PatientCommunicationComponent pcc1 = new PatientCommunicationComponent();
|
||||
pcc1.setId("1001");
|
||||
|
||||
PatientCommunicationComponent copiedPcc = pcc1.copy();
|
||||
String copiedPccID = copiedPcc.getId();
|
||||
|
||||
assertTrue(copiedPcc instanceof BackboneElement); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPccID);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package org.hl7.fhir.dstu3.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class DomainResourceDstu3Test {
|
||||
/**
|
||||
* Ensuring that fields defined in {@link DomainResource} and {@link Resource}
|
||||
* get copied when the {@link DomainResource#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCopy() {
|
||||
Patient p1 = new Patient();
|
||||
p1.setId("1001");
|
||||
p1.setText(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL));
|
||||
|
||||
Patient copiedPatient = p1.copy();
|
||||
String copiedPatientID = copiedPatient.getIdElement().getIdPart();
|
||||
Narrative.NarrativeStatus copiedPatientTextStatus = copiedPatient.getText().getStatus();
|
||||
|
||||
assertTrue(copiedPatient instanceof DomainResource); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPatientID);
|
||||
assertEquals(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL).getStatus(), copiedPatientTextStatus);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package org.hl7.fhir.dstu3.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MetadataResourceDstu3Test {
|
||||
/**
|
||||
* Ensuring that fields defined in {@link MetadataResource}, {@link DomainResource}, and {@link Resource}
|
||||
* get copied when the {@link MetadataResource#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testCodeSystemCopy() {
|
||||
CodeSystem codeSystem1 = new CodeSystem();
|
||||
codeSystem1.setId("1001");
|
||||
codeSystem1.setName("Name123");
|
||||
codeSystem1.setText(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL));
|
||||
|
||||
CodeSystem copiedCodeSystem = codeSystem1.copy();
|
||||
String copiedCodeSystemID = copiedCodeSystem.getId();
|
||||
String copiedCodeSystemName = copiedCodeSystem.getName();
|
||||
Narrative.NarrativeStatus copiedCodeSystemTextStatus = copiedCodeSystem.getText().getStatus();
|
||||
|
||||
assertTrue(copiedCodeSystem instanceof MetadataResource); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedCodeSystemID);
|
||||
assertEquals("Name123", copiedCodeSystemName);
|
||||
assertEquals(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL).getStatus(), copiedCodeSystemTextStatus);
|
||||
}
|
||||
}
|
@ -128,6 +128,7 @@ public abstract class BackboneElement extends Element implements IBaseBackboneEl
|
||||
public abstract BackboneElement copy();
|
||||
|
||||
public void copyValues(BackboneElement dst) {
|
||||
super.copyValues(dst);
|
||||
if (modifierExtension != null) {
|
||||
dst.modifierExtension = new ArrayList<Extension>();
|
||||
for (Extension i : modifierExtension)
|
||||
|
@ -265,6 +265,7 @@ public abstract class DomainResource extends Resource implements IBaseHasExtensi
|
||||
public abstract DomainResource copy();
|
||||
|
||||
public void copyValues(DomainResource dst) {
|
||||
super.copyValues(dst);
|
||||
dst.text = text == null ? null : text.copy();
|
||||
if (contained != null) {
|
||||
dst.contained = new ArrayList<Resource>();
|
||||
|
@ -0,0 +1,26 @@
|
||||
package ca.uhn.fhir.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hl7.fhir.instance.model.BackboneElement;
|
||||
import org.hl7.fhir.instance.model.Patient.PatientCommunicationComponent;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BackboneElementHL7_Dstu2Test {
|
||||
/**
|
||||
* Ensuring that IDs of subtypes of BackboneElement get copied when
|
||||
* the {@link org.hl7.fhir.instance.model.BackboneElement#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCommunicationComponentIdCopy() {
|
||||
PatientCommunicationComponent pcc1 = new PatientCommunicationComponent();
|
||||
pcc1.setId("1001");
|
||||
|
||||
PatientCommunicationComponent copiedPcc = pcc1.copy();
|
||||
String copiedPccID = copiedPcc.getIdElement().getIdPart();
|
||||
|
||||
assertTrue(copiedPcc instanceof BackboneElement); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPccID);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package ca.uhn.fhir.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hl7.fhir.instance.model.DomainResource;
|
||||
import org.hl7.fhir.instance.model.Narrative;
|
||||
import org.hl7.fhir.instance.model.Patient;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DomainResourceHL7_Dstu2Test {
|
||||
/**
|
||||
* Ensuring that fields defined in {@link org.hl7.fhir.instance.model.DomainResource} and {@link org.hl7.fhir.instance.model.Resource}
|
||||
* the {@link org.hl7.fhir.instance.model.DomainResource#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCopy() {
|
||||
Patient p1 = new Patient();
|
||||
p1.setId("1001");
|
||||
p1.setText(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL));
|
||||
|
||||
Patient copiedPatient = p1.copy();
|
||||
String copiedPatientID = copiedPatient.getIdElement().getIdPart();
|
||||
Narrative.NarrativeStatus copiedPatientTextStatus = copiedPatient.getText().getStatus();
|
||||
|
||||
assertTrue(copiedPatient instanceof DomainResource); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPatientID);
|
||||
assertEquals(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL).getStatus(), copiedPatientTextStatus);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package org.hl7.fhir.r4.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BackboneElementR4Test {
|
||||
/**
|
||||
* Ensuring that IDs of subtypes of BackboneElement get copied when
|
||||
* the {@link BackboneElement#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCommunicationComponentCopy() {
|
||||
PatientCommunicationComponent pcc1 = new PatientCommunicationComponent();
|
||||
pcc1.setId("1001");
|
||||
|
||||
PatientCommunicationComponent copiedPcc = pcc1.copy();
|
||||
String copiedPccID = copiedPcc.getId();
|
||||
|
||||
assertTrue(copiedPcc instanceof BackboneElement); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPccID);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package org.hl7.fhir.r4.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DomainResourceR4Test {
|
||||
/**
|
||||
* Ensuring that fields defined in {@link DomainResource} and {@link Resource}
|
||||
* get copied when the {@link DomainResource#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testPatientCopy() {
|
||||
Patient p1 = new Patient();
|
||||
p1.setId("1001");
|
||||
p1.setText(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL));
|
||||
|
||||
Patient copiedPatient = p1.copy();
|
||||
String copiedPatientID = copiedPatient.getIdElement().getIdPart();
|
||||
Narrative.NarrativeStatus copiedPatientTextStatus = copiedPatient.getText().getStatus();
|
||||
|
||||
assertTrue(copiedPatient instanceof DomainResource); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedPatientID);
|
||||
assertEquals(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL).getStatus(), copiedPatientTextStatus);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package org.hl7.fhir.r4.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MetadataResourceR4Test {
|
||||
/**
|
||||
* Ensuring that fields defined in {@link MetadataResource}, {@link DomainResource}, and {@link Resource}
|
||||
* get copied when the {@link MetadataResource#copy()} method is called
|
||||
*/
|
||||
@Test
|
||||
public void testCodeSystemCopy() {
|
||||
CodeSystem codeSystem1 = new CodeSystem();
|
||||
codeSystem1.setId("1001");
|
||||
codeSystem1.setName("Name123");
|
||||
codeSystem1.setText(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL));
|
||||
|
||||
CodeSystem copiedCodeSystem = codeSystem1.copy();
|
||||
String copiedCodeSystemID = copiedCodeSystem.getId();
|
||||
String copiedCodeSystemName = copiedCodeSystem.getName();
|
||||
Narrative.NarrativeStatus copiedCodeSystemTextStatus = copiedCodeSystem.getText().getStatus();
|
||||
|
||||
assertTrue(copiedCodeSystem instanceof MetadataResource); // Just making sure this assumption still holds up, otherwise this test isn't very useful
|
||||
assertEquals("1001", copiedCodeSystemID);
|
||||
assertEquals("Name123", copiedCodeSystemName);
|
||||
assertEquals(new Narrative().setStatus(Narrative.NarrativeStatus.ADDITIONAL).getStatus(), copiedCodeSystemTextStatus);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user