|
|
|
@ -2,11 +2,11 @@ package ca.uhn.fhir.jpa.dao.r4;
|
|
|
|
|
|
|
|
|
|
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
|
|
|
|
|
import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome;
|
|
|
|
|
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
|
|
|
|
|
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
|
|
|
|
import ca.uhn.fhir.jpa.test.BaseJpaR4Test;
|
|
|
|
|
import ca.uhn.fhir.model.primitive.IdDt;
|
|
|
|
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
|
|
|
|
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
|
|
|
|
|
import ca.uhn.fhir.rest.param.TokenParam;
|
|
|
|
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
|
|
|
|
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
|
|
|
@ -18,20 +18,28 @@ import org.hl7.fhir.r4.model.Bundle;
|
|
|
|
|
import org.hl7.fhir.r4.model.Condition;
|
|
|
|
|
import org.hl7.fhir.r4.model.Encounter;
|
|
|
|
|
import org.hl7.fhir.r4.model.ExplanationOfBenefit;
|
|
|
|
|
import org.hl7.fhir.r4.model.Extension;
|
|
|
|
|
import org.hl7.fhir.r4.model.IdType;
|
|
|
|
|
import org.hl7.fhir.r4.model.MessageHeader;
|
|
|
|
|
import org.hl7.fhir.r4.model.Observation;
|
|
|
|
|
import org.hl7.fhir.r4.model.Organization;
|
|
|
|
|
import org.hl7.fhir.r4.model.Patient;
|
|
|
|
|
import org.hl7.fhir.r4.model.Reference;
|
|
|
|
|
import org.hl7.fhir.r4.model.StringType;
|
|
|
|
|
import org.hl7.fhir.r4.model.Task;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.junit.jupiter.api.AfterEach;
|
|
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.DisplayName;
|
|
|
|
|
import org.junit.jupiter.api.Nested;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.platform.commons.annotation.Testable;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -39,6 +47,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static ca.uhn.fhir.util.HapiExtensions.EXTENSION_AUTO_VERSION_REFERENCES_AT_PATH;
|
|
|
|
|
import static org.hamcrest.CoreMatchers.is;
|
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
@ -60,11 +69,60 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths(new JpaStorageSettings().getAutoVersionReferenceAtPaths());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCreateAndUpdateVersionedReferencesInTransaction_VersionedReferenceToUpsertWithNop() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("ExplanationOfBenefit.patient");
|
|
|
|
|
@Nested
|
|
|
|
|
public class AutoVersionReferencesWithSettingAndExtension extends AutoVersionReferencesWithExtension {
|
|
|
|
|
@BeforeEach
|
|
|
|
|
public void before() {
|
|
|
|
|
beforeAutoVersionReferencesWithSetting();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nested
|
|
|
|
|
public class AutoVersionReferencesWithSetting extends AutoVersionReferencesTestCases {
|
|
|
|
|
@BeforeEach
|
|
|
|
|
public void before() {
|
|
|
|
|
beforeAutoVersionReferencesWithSetting();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void beforeAutoVersionReferencesWithSetting() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths(
|
|
|
|
|
"Patient.managingOrganization",
|
|
|
|
|
"ExplanationOfBenefit.patient",
|
|
|
|
|
"Observation.subject",
|
|
|
|
|
"MessageHeader.focus"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nested
|
|
|
|
|
public class AutoVersionReferencesWithExtension extends AutoVersionReferencesTestCases {
|
|
|
|
|
@BeforeEach
|
|
|
|
|
public void before() {
|
|
|
|
|
patientAutoVersionExtension = createAutoVersionReferencesExtensions("managingOrganization");
|
|
|
|
|
observationAutoVersionExtension = createAutoVersionReferencesExtensions("subject");
|
|
|
|
|
explanationOfBenefitAutoVersionExtension = createAutoVersionReferencesExtensions("patient");
|
|
|
|
|
messageHeaderAutoVersionExtension = createAutoVersionReferencesExtensions("focus");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
private List<Extension> createAutoVersionReferencesExtensions(String... thePaths) {
|
|
|
|
|
return Arrays.stream(thePaths)
|
|
|
|
|
.map(path -> new Extension(EXTENSION_AUTO_VERSION_REFERENCES_AT_PATH, new StringType(path)))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Testable
|
|
|
|
|
public abstract class AutoVersionReferencesTestCases {
|
|
|
|
|
|
|
|
|
|
protected List<Extension> patientAutoVersionExtension = Collections.emptyList();
|
|
|
|
|
protected List<Extension> observationAutoVersionExtension = Collections.emptyList();
|
|
|
|
|
protected List<Extension> explanationOfBenefitAutoVersionExtension = Collections.emptyList();
|
|
|
|
|
protected List<Extension> messageHeaderAutoVersionExtension = Collections.emptyList();
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCreateAndUpdateVersionedReferencesInTransaction_VersionedReferenceToUpsertWithNoOp() {
|
|
|
|
|
// We'll submit the same bundle twice. It has an UPSERT (with no changes
|
|
|
|
|
// the second time) on a Patient, and a CREATE on an ExplanationOfBenefit
|
|
|
|
|
// referencing that Patient.
|
|
|
|
@ -77,6 +135,7 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
bb.addTransactionUpdateEntry(patient);
|
|
|
|
|
|
|
|
|
|
ExplanationOfBenefit eob = new ExplanationOfBenefit();
|
|
|
|
|
eob.getMeta().setExtension(explanationOfBenefitAutoVersionExtension);
|
|
|
|
|
eob.setId(IdType.newRandomUuid());
|
|
|
|
|
eob.setPatient(new Reference("Patient/A"));
|
|
|
|
|
bb.addTransactionCreateEntry(eob);
|
|
|
|
@ -104,13 +163,7 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCreateAndUpdateVersionedReferencesInTransaction_VersionedReferenceToVersionedReferenceToUpsertWithNop() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths(
|
|
|
|
|
"Patient.managingOrganization",
|
|
|
|
|
"ExplanationOfBenefit.patient"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
public void testCreateAndUpdateVersionedReferencesInTransaction_VersionedReferenceToVersionedReferenceToUpsertWithNoOp() {
|
|
|
|
|
// We'll submit the same bundle twice. It has an UPSERT (with no changes
|
|
|
|
|
// the second time) on a Patient, and a CREATE on an ExplanationOfBenefit
|
|
|
|
|
// referencing that Patient.
|
|
|
|
@ -123,12 +176,14 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
bb.addTransactionUpdateEntry(organization);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.getMeta().setExtension(patientAutoVersionExtension);
|
|
|
|
|
patient.setId("Patient/A");
|
|
|
|
|
patient.setManagingOrganization(new Reference("Organization/O"));
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
bb.addTransactionUpdateEntry(patient);
|
|
|
|
|
|
|
|
|
|
ExplanationOfBenefit eob = new ExplanationOfBenefit();
|
|
|
|
|
eob.getMeta().setExtension(explanationOfBenefitAutoVersionExtension);
|
|
|
|
|
eob.setId(IdType.newRandomUuid());
|
|
|
|
|
eob.setPatient(new Reference("Patient/A"));
|
|
|
|
|
bb.addTransactionCreateEntry(eob);
|
|
|
|
@ -165,12 +220,6 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testCreateAndUpdateVersionedReferencesInTransaction_VersionedReferenceToVersionedReferenceToUpsertWithChange() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths(
|
|
|
|
|
"Patient.managingOrganization",
|
|
|
|
|
"ExplanationOfBenefit.patient"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
AtomicInteger counter = new AtomicInteger();
|
|
|
|
|
Supplier<Bundle> supplier = () -> {
|
|
|
|
|
BundleBuilder bb = new BundleBuilder(myFhirContext);
|
|
|
|
@ -182,12 +231,14 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
bb.addTransactionUpdateEntry(organization);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.getMeta().setExtension(patientAutoVersionExtension);
|
|
|
|
|
patient.setId("Patient/A");
|
|
|
|
|
patient.setManagingOrganization(new Reference("Organization/O"));
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
bb.addTransactionUpdateEntry(patient);
|
|
|
|
|
|
|
|
|
|
ExplanationOfBenefit eob = new ExplanationOfBenefit();
|
|
|
|
|
eob.getMeta().setExtension(explanationOfBenefitAutoVersionExtension);
|
|
|
|
|
eob.setId(IdType.newRandomUuid());
|
|
|
|
|
eob.setPatient(new Reference("Patient/A"));
|
|
|
|
|
bb.addTransactionCreateEntry(eob);
|
|
|
|
@ -220,6 +271,325 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
assertEquals(patientId, eob2.getPatient().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath() {
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.setActive(true);
|
|
|
|
|
IIdType patientId = myPatientDao.create(p).getId().toUnqualified();
|
|
|
|
|
assertEquals("1", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals(null, patientId.getBaseUrl());
|
|
|
|
|
String patientIdString = patientId.getValue();
|
|
|
|
|
|
|
|
|
|
// Create - put an unversioned reference in the subject
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
observation.getSubject().setReference(patientId.toVersionless().getValue());
|
|
|
|
|
IIdType observationId = myObservationDao.create(observation).getId().toUnqualified();
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientIdString, observation.getSubject().getReference());
|
|
|
|
|
|
|
|
|
|
myCaptureQueriesListener.clear();
|
|
|
|
|
|
|
|
|
|
// Update - put an unversioned reference in the subject
|
|
|
|
|
observation = new Observation();
|
|
|
|
|
observation.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
observation.setId(observationId);
|
|
|
|
|
observation.addIdentifier().setSystem("http://foo").setValue("bar");
|
|
|
|
|
observation.getSubject().setReference(patientId.toVersionless().getValue());
|
|
|
|
|
myObservationDao.update(observation);
|
|
|
|
|
|
|
|
|
|
// Make sure we're not introducing any extra DB operations
|
|
|
|
|
assertEquals(5, myCaptureQueriesListener.logSelectQueries().size());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientIdString, observation.getSubject().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_SourceAndTargetBothCreated() {
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
builder.addTransactionCreateEntry(patient);
|
|
|
|
|
|
|
|
|
|
Encounter encounter = new Encounter();
|
|
|
|
|
encounter.setId(IdType.newRandomUuid());
|
|
|
|
|
encounter.addIdentifier().setSystem("http://baz").setValue("baz");
|
|
|
|
|
builder.addTransactionCreateEntry(encounter);
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
observation.getEncounter().setReference(encounter.getId()); // not versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType encounterId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(2).getResponse().getLocation());
|
|
|
|
|
assertTrue(patientId.hasVersionIdPart());
|
|
|
|
|
assertTrue(encounterId.hasVersionIdPart());
|
|
|
|
|
assertTrue(observationId.hasVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
assertEquals(encounterId.toVersionless().getValue(), observation.getEncounter().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_TargetConditionalCreatedNoOp() {
|
|
|
|
|
{
|
|
|
|
|
// Create patient
|
|
|
|
|
createAndUpdatePatient(IdType.newRandomUuid().getId());
|
|
|
|
|
|
|
|
|
|
// Create encounter
|
|
|
|
|
Encounter encounter = new Encounter();
|
|
|
|
|
encounter.setId(IdType.newRandomUuid());
|
|
|
|
|
encounter.addIdentifier().setSystem("http://baz").setValue("baz");
|
|
|
|
|
myEncounterDao.create(encounter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify Patient Version
|
|
|
|
|
assertEquals("2", myPatientDao.search(SearchParameterMap.newSynchronous("active", new TokenParam("false")))
|
|
|
|
|
.getResources(0, 1).get(0).getIdElement().getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
builder.addTransactionCreateEntry(patient).conditional("Patient?active=false");
|
|
|
|
|
|
|
|
|
|
Encounter encounter = new Encounter();
|
|
|
|
|
encounter.setId(IdType.newRandomUuid());
|
|
|
|
|
encounter.addIdentifier().setSystem("http://baz").setValue("baz");
|
|
|
|
|
builder.addTransactionCreateEntry(encounter).conditional("Encounter?identifier=http://baz|baz");
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
observation.getEncounter().setReference(encounter.getId()); // not versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(1).getResponse().getStatus());
|
|
|
|
|
assertEquals("201 Created", outcome.getEntry().get(2).getResponse().getStatus());
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType encounterId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(2).getResponse().getLocation());
|
|
|
|
|
assertEquals("2", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", encounterId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", observationId.getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
assertEquals("2", observation.getSubject().getReferenceElement().getVersionIdPart());
|
|
|
|
|
assertEquals(encounterId.toVersionless().getValue(), observation.getEncounter().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_TargetUpdate() {
|
|
|
|
|
myStorageSettings.setDeleteEnabled(false);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Create patient
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId("PATIENT");
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
myPatientDao.update(patient).getId();
|
|
|
|
|
|
|
|
|
|
// Update patient to make a second version
|
|
|
|
|
patient.setActive(false);
|
|
|
|
|
myPatientDao.update(patient);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId("Patient/PATIENT");
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
builder.addTransactionUpdateEntry(patient);
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
myCaptureQueriesListener.clear();
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertEquals("201 Created", outcome.getEntry().get(1).getResponse().getStatus());
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
assertEquals("3", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", observationId.getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Make sure we're not introducing any extra DB operations
|
|
|
|
|
assertEquals(3, myCaptureQueriesListener.logSelectQueries().size());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_TargetUpdateConditional() {
|
|
|
|
|
createAndUpdatePatient(IdType.newRandomUuid().getId());
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setDeceased(new BooleanType(true));
|
|
|
|
|
patient.setActive(false);
|
|
|
|
|
builder
|
|
|
|
|
.addTransactionUpdateEntry(patient)
|
|
|
|
|
.conditional("Patient?active=false");
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
myCaptureQueriesListener.clear();
|
|
|
|
|
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertEquals("201 Created", outcome.getEntry().get(1).getResponse().getStatus());
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
assertEquals("3", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", observationId.getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Make sure we're not introducing any extra DB operations
|
|
|
|
|
assertEquals(4, myCaptureQueriesListener.logSelectQueries().size());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("Bundle transaction with AutoVersionReferenceAtPath on and with existing Patient resource should create")
|
|
|
|
|
public void bundleTransaction_autoVersionReferenceAtPathWithPreexistingPatientReference_shouldCreate() {
|
|
|
|
|
String patientId = "Patient/RED";
|
|
|
|
|
IIdType idType = new IdDt(patientId);
|
|
|
|
|
|
|
|
|
|
// create patient ahead of time
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(patientId);
|
|
|
|
|
DaoMethodOutcome outcome = myPatientDao.update(patient);
|
|
|
|
|
assertThat(outcome.getResource().getIdElement().getValue(), is(equalTo(patientId + "/_history/1")));
|
|
|
|
|
|
|
|
|
|
Patient returned = myPatientDao.read(idType);
|
|
|
|
|
Assertions.assertNotNull(returned);
|
|
|
|
|
assertThat(returned.getId(), is(equalTo(patientId + "/_history/1")));
|
|
|
|
|
|
|
|
|
|
// update to change version
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
myPatientDao.update(patient);
|
|
|
|
|
|
|
|
|
|
Observation obs = new Observation();
|
|
|
|
|
obs.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
obs.setId("Observation/DEF");
|
|
|
|
|
Reference patientRef = new Reference(patientId);
|
|
|
|
|
obs.setSubject(patientRef);
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
builder.addTransactionUpdateEntry(obs);
|
|
|
|
|
|
|
|
|
|
Bundle submitted = (Bundle) builder.getBundle();
|
|
|
|
|
|
|
|
|
|
Bundle returnedTr = mySystemDao.transaction(new SystemRequestDetails(), submitted);
|
|
|
|
|
|
|
|
|
|
Assertions.assertNotNull(returnedTr);
|
|
|
|
|
|
|
|
|
|
// some verification
|
|
|
|
|
Observation obRet = myObservationDao.read(obs.getIdElement());
|
|
|
|
|
Assertions.assertNotNull(obRet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("GH-2901 Test no NPE is thrown on autoversioned references")
|
|
|
|
|
public void testNoNpeMinimal() {
|
|
|
|
|
myStorageSettings.setAutoCreatePlaceholderReferenceTargets(true);
|
|
|
|
|
|
|
|
|
|
Observation obs = new Observation();
|
|
|
|
|
obs.getMeta().setExtension(observationAutoVersionExtension);
|
|
|
|
|
obs.setId("Observation/DEF");
|
|
|
|
|
Reference patientRef = new Reference("Patient/RED");
|
|
|
|
|
obs.setSubject(patientRef);
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
builder.addTransactionUpdateEntry(obs);
|
|
|
|
|
|
|
|
|
|
Bundle submitted = (Bundle) builder.getBundle();
|
|
|
|
|
|
|
|
|
|
Bundle returnedTr = mySystemDao.transaction(new SystemRequestDetails(), submitted);
|
|
|
|
|
|
|
|
|
|
Assertions.assertNotNull(returnedTr);
|
|
|
|
|
|
|
|
|
|
// some verification
|
|
|
|
|
Observation obRet = myObservationDao.read(obs.getIdElement());
|
|
|
|
|
Assertions.assertNotNull(obRet);
|
|
|
|
|
Patient returned = myPatientDao.read(patientRef.getReferenceElement());
|
|
|
|
|
Assertions.assertNotNull(returned);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferencesByPath_resourceReferenceNotInTransaction_addsVersionToTheReferences() {
|
|
|
|
|
Patient patient = createAndUpdatePatient(IdType.newRandomUuid().getId());
|
|
|
|
|
|
|
|
|
|
// create MessageHeader
|
|
|
|
|
MessageHeader messageHeader = new MessageHeader();
|
|
|
|
|
messageHeader.getMeta().setExtension(messageHeaderAutoVersionExtension);
|
|
|
|
|
// add reference
|
|
|
|
|
messageHeader.addFocus().setReference(patient.getIdElement().toVersionless().getValue());
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
builder.addTransactionCreateEntry(messageHeader);
|
|
|
|
|
|
|
|
|
|
ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(builder.getBundle()));
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.info(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
assertEquals("201 Created", outcome.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
|
|
|
|
|
IdType messageHeaderId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
assertEquals("2", patient.getIdElement().getVersionIdPart());
|
|
|
|
|
assertEquals("1", messageHeaderId.getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// read back and verify that reference is versioned
|
|
|
|
|
messageHeader = myMessageHeaderDao.read(messageHeaderId);
|
|
|
|
|
assertEquals(patient.getIdElement().getValue(), messageHeader.getFocus().get(0).getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Patient createAndUpdatePatient(String thePatientId) {
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(thePatientId);
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
myPatientDao.create(patient).getId();
|
|
|
|
|
|
|
|
|
|
// update patient to make a second version
|
|
|
|
|
patient.setActive(false);
|
|
|
|
|
myPatientDao.update(patient);
|
|
|
|
|
return patient;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testStoreAndRetrieveVersionedReference() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
@ -264,243 +634,6 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
assertEquals(patientId.withVersion("1").getValue(), observation.getSubject().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("Observation.subject");
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
|
p.setActive(true);
|
|
|
|
|
IIdType patientId = myPatientDao.create(p).getId().toUnqualified();
|
|
|
|
|
assertEquals("1", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals(null, patientId.getBaseUrl());
|
|
|
|
|
String patientIdString = patientId.getValue();
|
|
|
|
|
|
|
|
|
|
// Create - put an unversioned reference in the subject
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getSubject().setReference(patientId.toVersionless().getValue());
|
|
|
|
|
IIdType observationId = myObservationDao.create(observation).getId().toUnqualified();
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientIdString, observation.getSubject().getReference());
|
|
|
|
|
|
|
|
|
|
myCaptureQueriesListener.clear();
|
|
|
|
|
|
|
|
|
|
// Update - put an unversioned reference in the subject
|
|
|
|
|
observation = new Observation();
|
|
|
|
|
observation.setId(observationId);
|
|
|
|
|
observation.addIdentifier().setSystem("http://foo").setValue("bar");
|
|
|
|
|
observation.getSubject().setReference(patientId.toVersionless().getValue());
|
|
|
|
|
myObservationDao.update(observation);
|
|
|
|
|
|
|
|
|
|
// Make sure we're not introducing any extra DB operations
|
|
|
|
|
assertEquals(5, myCaptureQueriesListener.logSelectQueries().size());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientIdString, observation.getSubject().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_SourceAndTargetBothCreated() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("Observation.subject");
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
builder.addTransactionCreateEntry(patient);
|
|
|
|
|
|
|
|
|
|
Encounter encounter = new Encounter();
|
|
|
|
|
encounter.setId(IdType.newRandomUuid());
|
|
|
|
|
encounter.addIdentifier().setSystem("http://baz").setValue("baz");
|
|
|
|
|
builder.addTransactionCreateEntry(encounter);
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
observation.getEncounter().setReference(encounter.getId()); // not versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType encounterId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(2).getResponse().getLocation());
|
|
|
|
|
assertTrue(patientId.hasVersionIdPart());
|
|
|
|
|
assertTrue(encounterId.hasVersionIdPart());
|
|
|
|
|
assertTrue(observationId.hasVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
assertEquals(encounterId.toVersionless().getValue(), observation.getEncounter().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_TargetConditionalCreatedNop() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("Observation.subject");
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Create patient
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
myPatientDao.create(patient).getId();
|
|
|
|
|
|
|
|
|
|
// Update patient to make a second version
|
|
|
|
|
patient.setActive(false);
|
|
|
|
|
myPatientDao.update(patient);
|
|
|
|
|
|
|
|
|
|
// Create encounter
|
|
|
|
|
Encounter encounter = new Encounter();
|
|
|
|
|
encounter.setId(IdType.newRandomUuid());
|
|
|
|
|
encounter.addIdentifier().setSystem("http://baz").setValue("baz");
|
|
|
|
|
myEncounterDao.create(encounter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify Patient Version
|
|
|
|
|
assertEquals("2", myPatientDao.search(SearchParameterMap.newSynchronous("active", new TokenParam("false"))).getResources(0, 1).get(0).getIdElement().getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
builder.addTransactionCreateEntry(patient).conditional("Patient?active=false");
|
|
|
|
|
|
|
|
|
|
Encounter encounter = new Encounter();
|
|
|
|
|
encounter.setId(IdType.newRandomUuid());
|
|
|
|
|
encounter.addIdentifier().setSystem("http://baz").setValue("baz");
|
|
|
|
|
builder.addTransactionCreateEntry(encounter).conditional("Encounter?identifier=http://baz|baz");
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
observation.getEncounter().setReference(encounter.getId()); // not versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(1).getResponse().getStatus());
|
|
|
|
|
assertEquals("201 Created", outcome.getEntry().get(2).getResponse().getStatus());
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType encounterId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(2).getResponse().getLocation());
|
|
|
|
|
assertEquals("2", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", encounterId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", observationId.getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
assertEquals("2", observation.getSubject().getReferenceElement().getVersionIdPart());
|
|
|
|
|
assertEquals(encounterId.toVersionless().getValue(), observation.getEncounter().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_TargetUpdate() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setDeleteEnabled(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("Observation.subject");
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Create patient
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId("PATIENT");
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
myPatientDao.update(patient).getId();
|
|
|
|
|
|
|
|
|
|
// Update patient to make a second version
|
|
|
|
|
patient.setActive(false);
|
|
|
|
|
myPatientDao.update(patient);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId("Patient/PATIENT");
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
builder.addTransactionUpdateEntry(patient);
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
myCaptureQueriesListener.clear();
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertEquals("201 Created", outcome.getEntry().get(1).getResponse().getStatus());
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
assertEquals("3", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", observationId.getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Make sure we're not introducing any extra DB operations
|
|
|
|
|
assertEquals(3, myCaptureQueriesListener.logSelectQueries().size());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testInsertVersionedReferenceAtPath_InTransaction_TargetUpdateConditional() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("Observation.subject");
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Create patient
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
myPatientDao.create(patient).getId();
|
|
|
|
|
|
|
|
|
|
// Update patient to make a second version
|
|
|
|
|
patient.setActive(false);
|
|
|
|
|
myPatientDao.update(patient);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(IdType.newRandomUuid());
|
|
|
|
|
patient.setDeceased(new BooleanType(true));
|
|
|
|
|
patient.setActive(false);
|
|
|
|
|
builder
|
|
|
|
|
.addTransactionUpdateEntry(patient)
|
|
|
|
|
.conditional("Patient?active=false");
|
|
|
|
|
|
|
|
|
|
Observation observation = new Observation();
|
|
|
|
|
observation.getSubject().setReference(patient.getId()); // versioned
|
|
|
|
|
builder.addTransactionCreateEntry(observation);
|
|
|
|
|
|
|
|
|
|
myCaptureQueriesListener.clear();
|
|
|
|
|
|
|
|
|
|
Bundle outcome = mySystemDao.transaction(mySrd, (Bundle) builder.getBundle());
|
|
|
|
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome));
|
|
|
|
|
assertEquals("200 OK", outcome.getEntry().get(0).getResponse().getStatus());
|
|
|
|
|
assertEquals("201 Created", outcome.getEntry().get(1).getResponse().getStatus());
|
|
|
|
|
IdType patientId = new IdType(outcome.getEntry().get(0).getResponse().getLocation());
|
|
|
|
|
IdType observationId = new IdType(outcome.getEntry().get(1).getResponse().getLocation());
|
|
|
|
|
assertEquals("3", patientId.getVersionIdPart());
|
|
|
|
|
assertEquals("1", observationId.getVersionIdPart());
|
|
|
|
|
|
|
|
|
|
// Make sure we're not introducing any extra DB operations
|
|
|
|
|
assertEquals(4, myCaptureQueriesListener.logSelectQueries().size());
|
|
|
|
|
|
|
|
|
|
// Read back and verify that reference is now versioned
|
|
|
|
|
observation = myObservationDao.read(observationId);
|
|
|
|
|
assertEquals(patientId.getValue(), observation.getSubject().getReference());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSearchAndIncludeVersionedReference_Asynchronous() {
|
|
|
|
|
myFhirContext.getParserOptions().setStripVersionsFromReferences(false);
|
|
|
|
@ -866,70 +999,4 @@ public class FhirResourceDaoR4VersionedReferenceTest extends BaseJpaR4Test {
|
|
|
|
|
Observation obs = myObservationDao.read(idType);
|
|
|
|
|
Assertions.assertNotNull(obs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("Bundle transaction with AutoVersionReferenceAtPath on and with existing Patient resource should create")
|
|
|
|
|
public void bundleTransaction_autoreferenceAtPathWithPreexistingPatientReference_shouldCreate() {
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("Observation.subject");
|
|
|
|
|
|
|
|
|
|
String patientId = "Patient/RED";
|
|
|
|
|
IIdType idType = new IdDt(patientId);
|
|
|
|
|
|
|
|
|
|
// create patient ahead of time
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId(patientId);
|
|
|
|
|
DaoMethodOutcome outcome = myPatientDao.update(patient);
|
|
|
|
|
assertThat(outcome.getResource().getIdElement().getValue(), is(equalTo(patientId + "/_history/1")));
|
|
|
|
|
|
|
|
|
|
Patient returned = myPatientDao.read(idType);
|
|
|
|
|
Assertions.assertNotNull(returned);
|
|
|
|
|
assertThat(returned.getId(), is(equalTo(patientId + "/_history/1")));
|
|
|
|
|
|
|
|
|
|
// update to change version
|
|
|
|
|
patient.setActive(true);
|
|
|
|
|
myPatientDao.update(patient);
|
|
|
|
|
|
|
|
|
|
Observation obs = new Observation();
|
|
|
|
|
obs.setId("Observation/DEF");
|
|
|
|
|
Reference patientRef = new Reference(patientId);
|
|
|
|
|
obs.setSubject(patientRef);
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
builder.addTransactionUpdateEntry(obs);
|
|
|
|
|
|
|
|
|
|
Bundle submitted = (Bundle)builder.getBundle();
|
|
|
|
|
|
|
|
|
|
Bundle returnedTr = mySystemDao.transaction(new SystemRequestDetails(), submitted);
|
|
|
|
|
|
|
|
|
|
Assertions.assertNotNull(returnedTr);
|
|
|
|
|
|
|
|
|
|
// some verification
|
|
|
|
|
Observation obRet = myObservationDao.read(obs.getIdElement());
|
|
|
|
|
Assertions.assertNotNull(obRet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("GH-2901 Test no NPE is thrown on autoversioned references")
|
|
|
|
|
public void testNoNpeMinimal() {
|
|
|
|
|
myStorageSettings.setAutoCreatePlaceholderReferenceTargets(true);
|
|
|
|
|
myStorageSettings.setAutoVersionReferenceAtPaths("Observation.subject");
|
|
|
|
|
|
|
|
|
|
Observation obs = new Observation();
|
|
|
|
|
obs.setId("Observation/DEF");
|
|
|
|
|
Reference patientRef = new Reference("Patient/RED");
|
|
|
|
|
obs.setSubject(patientRef);
|
|
|
|
|
BundleBuilder builder = new BundleBuilder(myFhirContext);
|
|
|
|
|
builder.addTransactionUpdateEntry(obs);
|
|
|
|
|
|
|
|
|
|
Bundle submitted = (Bundle)builder.getBundle();
|
|
|
|
|
|
|
|
|
|
Bundle returnedTr = mySystemDao.transaction(new SystemRequestDetails(), submitted);
|
|
|
|
|
|
|
|
|
|
Assertions.assertNotNull(returnedTr);
|
|
|
|
|
|
|
|
|
|
// some verification
|
|
|
|
|
Observation obRet = myObservationDao.read(obs.getIdElement());
|
|
|
|
|
Assertions.assertNotNull(obRet);
|
|
|
|
|
Patient returned = myPatientDao.read(patientRef.getReferenceElement());
|
|
|
|
|
Assertions.assertNotNull(returned);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|