Fixes issue #878 where resources in a bundle are updated even when no data changes

This commit is contained in:
darktyco 2018-03-06 12:03:34 -05:00
parent 9fd9d19678
commit b18bb033bf
2 changed files with 57 additions and 1 deletions

View File

@ -129,7 +129,7 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
HashSet<String> excludeElementsInEncoded = new HashSet<String>();
excludeElementsInEncoded.add("id");
excludeElementsInEncoded.add("meta");
excludeElementsInEncoded.add("*.meta");
EXCLUDE_ELEMENTS_IN_ENCODED = Collections.unmodifiableSet(excludeElementsInEncoded);
}

View File

@ -1193,6 +1193,62 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
}
@Test
public void testTransactionUpdateResourceNewVersionCreatedWhenDataChanges() {
Bundle request = new Bundle();
String patientId = "Patient/IShouldUpdate";
Patient p = new Patient();
p.addName().addFamily("Hello");
p.setId(patientId);
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerbEnum.PUT).setUrl(patientId);
Bundle initialBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, initialBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(initialBundleResponse));
Entry initialBundleResponseEntry = initialBundleResponse.getEntry().get(0);
assertEquals("201 Created", initialBundleResponseEntry.getResponse().getStatus());
assertThat(initialBundleResponseEntry.getResponse().getEtag(), is(equalTo("1")));
p.addName().addFamily("AnotherName");
Bundle secondBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, secondBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(secondBundleResponse));
Entry secondBundleResponseEntry = secondBundleResponse.getEntry().get(0);
assertEquals("200 OK", secondBundleResponseEntry.getResponse().getStatus());
assertThat(secondBundleResponseEntry.getResponse().getEtag(), is(equalTo("2")));
}
@Test
public void testTransactionUpdateResourceNewVersionNotCreatedWhenDataNotChanged() {
Bundle request = new Bundle();
String patientId = "Patient/IShouldNotUpdate";
Patient p = new Patient();
p.addName().addFamily("Hello");
p.setId(patientId);
request.addEntry().setResource(p).getRequest().setMethod(HTTPVerbEnum.PUT).setUrl(patientId);
Bundle initialBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, initialBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(initialBundleResponse));
Entry initialBundleResponseEntry = initialBundleResponse.getEntry().get(0);
assertEquals("201 Created", initialBundleResponseEntry.getResponse().getStatus());
assertThat(initialBundleResponseEntry.getResponse().getEtag(), is(equalTo("1")));
Bundle secondBundleResponse = mySystemDao.transaction(mySrd, request);
assertEquals(1, secondBundleResponse.getEntry().size());
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(secondBundleResponse));
Entry secondBundleResponseEntry = secondBundleResponse.getEntry().get(0);
assertEquals("200 OK", secondBundleResponseEntry.getResponse().getStatus());
assertThat(secondBundleResponseEntry.getResponse().getEtag(), is(equalTo("1")));
}
@Test
public void testTransactionUpdateMatchUrlWithTwoMatch() {
String methodName = "testTransactionUpdateMatchUrlWithTwoMatch";