brett hanson
unread,Sep 15, 2025, 3:38:25 PM (4 days ago) Sep 15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to HAPI FHIR
In my Java application which uses Hapi FHIR version 8.4.0, I have created a servlet class for R5 which extends com.rp.vna.fhir.r5.servlet.RestfulServer. Users of this application will issue search requests which will return a Bundle containing a DiagnosticReport and Patient entries.
When creating a org.hl7.fhir.r5.model.DiagnosticReport resource, I am invoking the copy() method. However, the DiagnosticReport.subject:Patient resource is not getting copied and is null. Below is a test class which fails as
diagnosticReport.copy().getSubject().getResource() is null.
```java
import java.util.List;
import org.hl7.fhir.r5.model.DiagnosticReport;
import org.hl7.fhir.r5.model.HumanName;
import org.hl7.fhir.r5.model.Patient;
import org.hl7.fhir.r5.model.Reference;
import org.junit.jupiter.api.Test;
public class R5ReferenceCopyTest {
@Test
public void r5ReferenceTest() {
Patient patient = new Patient();
patient.setId("222");
patient.setName(List.of(new HumanName().setFamily("Doe").addGiven("John")));
Reference reference = new Reference();
reference.setType(Patient.class.getSimpleName());
reference.setResource(patient);
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setSubject(reference);
assert diagnosticReport.copy().getSubject().getResource() != null;
}
}
```
When I test this same code using only R4 resources, the test will succeed as diagnosticReport.copy().getSubject().getResource() is not null. Comparing the class signatures of org.hl7.fhir.r5.model.BaseReference and org.hl7.fhir.r4.model.BaseReference, I see that in R5 BaseReference now extends DataType and not Element (as it did in R4). However, the copyValues() method in org.hl7.fhir.r5.model.BaseReference is taking in a Element parameter and not a DataType. I am wondering if this is intentional or a bug?