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 {