Fix conditional creates updating resource body
This commit is contained in:
parent
c836a8905e
commit
ad781334d8
|
@ -492,7 +492,9 @@ public class FhirSystemDaoDstu2 extends BaseHapiFhirSystemDao<Bundle, MetaDt> {
|
|||
InstantDt deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get(nextResource);
|
||||
Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null;
|
||||
boolean shouldUpdate = !nonUpdatedEntities.contains(nextOutcome.getEntity());
|
||||
updateEntity(nextResource, nextOutcome.getEntity(), deletedTimestampOrNull, true, shouldUpdate, updateTime);
|
||||
if (shouldUpdate) {
|
||||
updateEntity(nextResource, nextOutcome.getEntity(), deletedTimestampOrNull, true, true, updateTime);
|
||||
}
|
||||
}
|
||||
|
||||
myEntityManager.flush();
|
||||
|
|
|
@ -383,7 +383,8 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
|
|||
IFhirResourceDao resourceDao = getDaoOrThrowException(res.getClass());
|
||||
res.setId((String) null);
|
||||
DaoMethodOutcome outcome;
|
||||
outcome = resourceDao.create(res, nextReqEntry.getRequest().getIfNoneExist(), false, theRequestDetails);
|
||||
String matchUrl = nextReqEntry.getRequest().getIfNoneExist();
|
||||
outcome = resourceDao.create(res, matchUrl, false, theRequestDetails);
|
||||
handleTransactionCreateOrUpdateOutcome(idSubstitutions, idToPersistedOutcome, nextResourceId, outcome, nextRespEntry, resourceType, res);
|
||||
entriesToProcess.put(nextRespEntry, outcome.getEntity());
|
||||
if (outcome.getCreated() == false) {
|
||||
|
@ -489,7 +490,9 @@ public class FhirSystemDaoDstu3 extends BaseHapiFhirSystemDao<Bundle, Meta> {
|
|||
IPrimitiveType<Date> deletedInstantOrNull = ResourceMetadataKeyEnum.DELETED_AT.get((IAnyResource) nextResource);
|
||||
Date deletedTimestampOrNull = deletedInstantOrNull != null ? deletedInstantOrNull.getValue() : null;
|
||||
boolean shouldUpdate = !nonUpdatedEntities.contains(nextOutcome.getEntity());
|
||||
updateEntity(nextResource, nextOutcome.getEntity(), deletedTimestampOrNull, shouldUpdate, shouldUpdate, updateTime);
|
||||
if (shouldUpdate) {
|
||||
updateEntity(nextResource, nextOutcome.getEntity(), deletedTimestampOrNull, shouldUpdate, true, updateTime);
|
||||
}
|
||||
}
|
||||
|
||||
myEntityManager.flush();
|
||||
|
|
|
@ -19,10 +19,12 @@ import static org.mockito.Mockito.verify;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.dstu3.model.IdType;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
@ -73,6 +75,43 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest {
|
|||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu2Test.class);
|
||||
|
||||
/**
|
||||
* Per a message on the mailing list
|
||||
*/
|
||||
@Test
|
||||
public void testTransactionWithPostDoesntUpdate() throws Exception {
|
||||
|
||||
// First bundle (name is Joshua)
|
||||
|
||||
String input = IOUtils.toString(getClass().getResource("/dstu3-post1.xml"), StandardCharsets.UTF_8);
|
||||
Bundle request = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
||||
Bundle response = mySystemDao.transaction(mySrd, request);
|
||||
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||
|
||||
assertEquals(1, response.getEntry().size());
|
||||
assertEquals("201 Created", response.getEntry().get(0).getResponse().getStatus());
|
||||
assertEquals("1", response.getEntry().get(0).getResponse().getEtag());
|
||||
String id = response.getEntry().get(0).getResponse().getLocation();
|
||||
|
||||
// Now the second (name is Adam, shouldn't get used)
|
||||
|
||||
input = IOUtils.toString(getClass().getResource("/dstu3-post2.xml"), StandardCharsets.UTF_8);
|
||||
request = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
||||
response = mySystemDao.transaction(mySrd, request);
|
||||
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||
|
||||
assertEquals(1, response.getEntry().size());
|
||||
assertEquals("200 OK", response.getEntry().get(0).getResponse().getStatus());
|
||||
assertEquals("1", response.getEntry().get(0).getResponse().getEtag());
|
||||
String id2 = response.getEntry().get(0).getResponse().getLocation();
|
||||
assertEquals(id, id2);
|
||||
|
||||
Patient patient = myPatientDao.read(new IdType(id), mySrd);
|
||||
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
|
||||
assertEquals("Joshua", patient.getNameFirstRep().getGivenAsSingleString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReindexing() {
|
||||
Patient p = new Patient();
|
||||
|
|
|
@ -382,6 +382,42 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Per a message on the mailing list
|
||||
*/
|
||||
@Test
|
||||
public void testTransactionWithPostDoesntUpdate() throws Exception {
|
||||
|
||||
// First bundle (name is Joshua)
|
||||
|
||||
String input = IOUtils.toString(getClass().getResource("/dstu3-post1.xml"), StandardCharsets.UTF_8);
|
||||
Bundle request = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
||||
Bundle response = mySystemDao.transaction(mySrd, request);
|
||||
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||
|
||||
assertEquals(1, response.getEntry().size());
|
||||
assertEquals("201 Created", response.getEntry().get(0).getResponse().getStatus());
|
||||
assertEquals("1", response.getEntry().get(0).getResponse().getEtag());
|
||||
String id = response.getEntry().get(0).getResponse().getLocation();
|
||||
|
||||
// Now the second (name is Adam, shouldn't get used)
|
||||
|
||||
input = IOUtils.toString(getClass().getResource("/dstu3-post2.xml"), StandardCharsets.UTF_8);
|
||||
request = myFhirCtx.newXmlParser().parseResource(Bundle.class, input);
|
||||
response = mySystemDao.transaction(mySrd, request);
|
||||
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||
|
||||
assertEquals(1, response.getEntry().size());
|
||||
assertEquals("200 OK", response.getEntry().get(0).getResponse().getStatus());
|
||||
assertEquals("1", response.getEntry().get(0).getResponse().getEtag());
|
||||
String id2 = response.getEntry().get(0).getResponse().getLocation();
|
||||
assertEquals(id, id2);
|
||||
|
||||
Patient patient = myPatientDao.read(new IdType(id), mySrd);
|
||||
ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
|
||||
assertEquals("Joshua", patient.getNameFirstRep().getGivenAsSingleString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionCreateInlineMatchUrlWithOneMatch() {
|
||||
String methodName = "testTransactionCreateInlineMatchUrlWithOneMatch";
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bundle xmlns="http://hl7.org/fhir">
|
||||
<type value="transaction"/>
|
||||
<entry>
|
||||
<resource>
|
||||
<Patient>
|
||||
<id value="ID613876"/>
|
||||
<identifier>
|
||||
<value value="ID613876"/>
|
||||
</identifier>
|
||||
<name>
|
||||
<given value="Joshua"/>
|
||||
</name>
|
||||
</Patient>
|
||||
</resource>
|
||||
<request>
|
||||
<method value="POST"/>
|
||||
<url value="Patient/ID613876"/>
|
||||
<ifNoneExist value="identifier=ID613876"/>
|
||||
</request>
|
||||
</entry>
|
||||
</Bundle>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bundle xmlns="http://hl7.org/fhir">
|
||||
<type value="transaction"/>
|
||||
<entry>
|
||||
<resource>
|
||||
<Patient>
|
||||
<id value="ID613876"/>
|
||||
<identifier>
|
||||
<value value="ID613876"/>
|
||||
</identifier>
|
||||
<name>
|
||||
<given value="Adam"/>
|
||||
</name>
|
||||
</Patient>
|
||||
</resource>
|
||||
<request>
|
||||
<method value="POST"/>
|
||||
<url value="Patient/ID613876"/>
|
||||
<ifNoneExist value="identifier=ID613876"/>
|
||||
</request>
|
||||
</entry>
|
||||
</Bundle>
|
|
@ -123,6 +123,13 @@
|
|||
Clean up dependencies and remove Eclipse project files from git. Thanks to
|
||||
@sekaijin for the pull request!
|
||||
</action>
|
||||
<action type="fix">
|
||||
When performing a conditional create in a transaction in JPA server,
|
||||
if a resource already existed matching the conditional expression, the
|
||||
server did not change the version of the resource but did update the body
|
||||
with the passed in body. Thanks to Artem Sopin for reporting and providing a test
|
||||
case for this!
|
||||
</action>
|
||||
</release>
|
||||
<release version="2.2" date="2016-12-20">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue