diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java index 7668b1ffae3..36551277b6d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java @@ -89,6 +89,7 @@ import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; +import org.hl7.fhir.r4.model.Task; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -864,6 +865,7 @@ public abstract class BaseTransactionProcessor { matchUrl = parts.getResourceType(); } matchUrl = performIdSubstitutionsInMatchUrl(theIdSubstitutions, matchUrl); + //TODO FIXME GGG This update call comes back with a contained resource. outcome = resourceDao.update(res, matchUrl, false, false, theRequest, theTransactionDetails); if (Boolean.TRUE.equals(outcome.getCreated())) { conditionalRequestUrls.put(matchUrl, res.getClass()); @@ -1095,7 +1097,6 @@ public abstract class BaseTransactionProcessor { } deferredIndexesForAutoVersioning.put(nextOutcome, referencesToAutoVersion); } - } // If we have any resources we'll be auto-versioning, index these next diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java index 7c753d06320..5be6e35474a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.api.config.DaoConfig; +import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao; import ca.uhn.fhir.jpa.model.entity.NormalizedQuantitySearchLevel; import ca.uhn.fhir.jpa.model.entity.ResourceEncodingEnum; @@ -63,6 +64,7 @@ import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Resource; +import org.hl7.fhir.r4.model.Task; import org.hl7.fhir.r4.model.ValueSet; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -1002,23 +1004,41 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { } + @Test + public void testTransactionNoContainedRedux() throws IOException { + //Pre-create the patient, which will cause the ifNoneExist to prevent a new creation during bundle transaction + Patient patient = loadResourceFromClasspath(Patient.class, "/r4/preexisting-patient.json"); + myPatientDao.create(patient); + + //Post the Bundle containing a conditional POST with an identical patient from the above resource. + Bundle request = loadResourceFromClasspath(Bundle.class, "/r4/transaction-no-contained-2.json"); + Bundle outcome = mySystemDao.transaction(mySrd, request); + IdType taskId = new IdType(outcome.getEntry().get(0).getResponse().getLocation()); + Task task = myTaskDao.read(taskId, mySrd); + + assertThat(task.getBasedOn().get(0).getReference(), matchesPattern("Patient/[0-9]+")); + } + @Test public void testTransactionNoContained() throws IOException { // Run once (should create the patient) Bundle request = loadResourceFromClasspath(Bundle.class, "/r4/transaction-no-contained.json"); - mySystemDao.transaction(mySrd, request); - - // Run a second time (no conditional update) - request = loadResourceFromClasspath(Bundle.class, "/r4/transaction-no-contained.json"); Bundle outcome = mySystemDao.transaction(mySrd, request); - - ourLog.info("Outcome: {}", myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome)); - IdType communicationId = new IdType(outcome.getEntry().get(1).getResponse().getLocation()); Communication communication = myCommunicationDao.read(communicationId, mySrd); assertThat(communication.getSubject().getReference(), matchesPattern("Patient/[0-9]+")); + // Run a second time (no conditional update) + request = loadResourceFromClasspath(Bundle.class, "/r4/transaction-no-contained.json"); + outcome = mySystemDao.transaction(mySrd, request); + + ourLog.info("Outcome: {}", myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome)); + +// IdType communicationId = new IdType(outcome.getEntry().get(1).getResponse().getLocation()); +// Communication communication = myCommunicationDao.read(communicationId, mySrd); +// assertThat(communication.getSubject().getReference(), matchesPattern("Patient/[0-9]+")); + ourLog.info("Outcome: {}", myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(communication)); } diff --git a/hapi-fhir-jpaserver-base/src/test/resources/r4/transaction-no-contained-2.json b/hapi-fhir-jpaserver-base/src/test/resources/r4/transaction-no-contained-2.json new file mode 100644 index 00000000000..675ff990be5 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/resources/r4/transaction-no-contained-2.json @@ -0,0 +1,49 @@ +{ + "resourceType": "Bundle", + "type": "transaction", + "entry": [ + { + "fullUrl": "urn:uuid:1f3b9e25-fd45-4342-a82b-7ca5755923bb", + "resource": { + "resourceType": "Task", + "language": "en-US", + "identifier": [ + { + "system": "https://example.org/fhir/taskidentifier", + "value": "101019" + } + ], + "basedOn": [ + { + "reference": "urn:uuid:47c6d106-3441-41c0-8a2c-054ad9897ced" + } + ] + }, + "request": { + "method": "PUT", + "url": "/Task?identifier\u003dhttps%3A%2F%2Fexample.org%2Ffhir%2Ftaskidentifier|101019" + } + }, + { + "fullUrl": "urn:uuid:47c6d106-3441-41c0-8a2c-054ad9897ced", + "resource": { + "resourceType": "Patient", + "identifier": [ + { + "system": "https://example.org/fhir/memberidentifier", + "value": "12345670" + }, + { + "system": "https://example.org/fhir/memberuniqueidentifier", + "value": "12345670TT" + } + ] + }, + "request": { + "method": "POST", + "url": "/Patient", + "ifNoneExist": "Patient?identifier\u003dhttps%3A%2F%2Fexample.org%2Ffhir%2Fmemberuniqueidentifier|12345670TT" + } + } + ] +} diff --git a/hapi-fhir-jpaserver-base/src/test/resources/r4/transaction-no-contained.json b/hapi-fhir-jpaserver-base/src/test/resources/r4/transaction-no-contained.json index 263cca4691e..880327e4cdc 100644 --- a/hapi-fhir-jpaserver-base/src/test/resources/r4/transaction-no-contained.json +++ b/hapi-fhir-jpaserver-base/src/test/resources/r4/transaction-no-contained.json @@ -250,8 +250,8 @@ ] }, "request": { - "method": "POST", - "url": "Communication" + "method": "PUT", + "url": "Communication?identifier=https://example.com|zoop" } } ]