From d639a2a86ddb6c6617bdb8cc3de5151dbc8478f3 Mon Sep 17 00:00:00 2001 From: Nathan Doef Date: Thu, 8 Dec 2022 23:26:49 -0500 Subject: [PATCH] meta.versionId Incremented After Update Operation With No Changes (DSTU 3) (#4349) * Tests for R4 (passing) and DSTU3 (failing) * Fix Co-authored-by: nathaniel.doef --- ...-versionid-incremented-incorrectly-dstu3.yaml | 6 ++++++ .../ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 5 ++++- .../dstu3/ResourceProviderDstu3Test.java | 16 ++++++++++++++++ .../jpa/provider/r4/ResourceProviderR4Test.java | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4348-meta-versionid-incremented-incorrectly-dstu3.yaml diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4348-meta-versionid-incremented-incorrectly-dstu3.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4348-meta-versionid-incremented-incorrectly-dstu3.yaml new file mode 100644 index 00000000000..d4f5f23fc40 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/4348-meta-versionid-incremented-incorrectly-dstu3.yaml @@ -0,0 +1,6 @@ +--- +type: fix +issue: 4348 +jira: SMILE-5651 +title: "Previously, if a DSTU3 Resource was updated and no changes were made, the `meta.versionId` value was +incremented incorrectly. This has been fixed." diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 48198ed12c3..e6288c8dc20 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -705,7 +705,10 @@ public abstract class BaseHapiFhirDao extends BaseStora } } } - + boolean allExtensionsRemoved = extensions.isEmpty(); + if(allExtensionsRemoved){ + hasExtensions = false; + } } } diff --git a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 7b07c15b765..f3b827a2ab1 100644 --- a/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-test-dstu3/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -4576,6 +4576,22 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } } + @Test + public void testUpdateResourceAfterReadOperationAndNoChangesShouldNotChangeVersion(){ + // Create Patient + Patient patient = new Patient(); + patient = (Patient) myClient.create().resource(patient).execute().getResource(); + assertEquals(1, patient.getIdElement().getVersionIdPartAsLong()); + + // Read Patient + patient = (Patient) myClient.read().resource("Patient").withId(patient.getIdElement()).execute(); + assertEquals(1, patient.getIdElement().getVersionIdPartAsLong()); + + // Update Patient with no changes + patient = (Patient) myClient.update().resource(patient).execute().getResource(); + assertEquals(1, patient.getIdElement().getVersionIdPartAsLong()); + } + @Test public void testValidateBadInputViaGet() throws IOException { diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index 2490ed2825d..f8fa65efae8 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -762,6 +762,22 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } + @Test + public void testUpdateResourceAfterReadOperationAndNoChangesShouldNotChangeVersion(){ + // Create Patient + Patient patient = new Patient(); + patient = (Patient) myClient.create().resource(patient).execute().getResource(); + assertEquals(1, patient.getIdElement().getVersionIdPartAsLong()); + + // Read Patient + patient = (Patient) myClient.read().resource("Patient").withId(patient.getIdElement()).execute(); + assertEquals(1, patient.getIdElement().getVersionIdPartAsLong()); + + // Update Patient with no changes + patient = (Patient) myClient.update().resource(patient).execute().getResource(); + assertEquals(1, patient.getIdElement().getVersionIdPartAsLong()); + } + @Test public void testCreateWithNoBody() throws IOException {