Another test fix

This commit is contained in:
James Agnew 2019-01-04 13:53:24 -05:00
parent 051074d0bc
commit 137d39e80f
3 changed files with 47 additions and 5 deletions

View File

@ -380,7 +380,8 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
} else if (match.size() == 1) { } else if (match.size() == 1) {
Long pid = match.iterator().next(); Long pid = match.iterator().next();
entity = myEntityManager.find(ResourceTable.class, pid); entity = myEntityManager.find(ResourceTable.class, pid);
return toMethodOutcome(entity, null).setCreated(false); IBaseResource resource = toResource(entity, false);
return toMethodOutcome(entity, resource).setCreated(false);
} }
} }
@ -1141,15 +1142,15 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
return retVal; return retVal;
} }
private DaoMethodOutcome toMethodOutcome(@Nonnull final ResourceTable theEntity, @Nullable IBaseResource theResource) { private DaoMethodOutcome toMethodOutcome(@Nonnull final ResourceTable theEntity, @Nonnull IBaseResource theResource) {
DaoMethodOutcome outcome = new DaoMethodOutcome(); DaoMethodOutcome outcome = new DaoMethodOutcome();
IIdType id = null; IIdType id = null;
if (theResource != null) { if (theResource.getIdElement().getValue() != null) {
id = theResource.getIdElement(); id = theResource.getIdElement();
} }
if (id == null) { if (id == null) {
id = ((BaseHasResource) theEntity).getIdDt(); id = theEntity.getIdDt();
if (getContext().getVersion().getVersion().isRi()) { if (getContext().getVersion().getVersion().isRi()) {
id = getContext().getVersion().newIdType().setValue(id.getValue()); id = getContext().getVersion().newIdType().setValue(id.getValue());
} }
@ -1294,7 +1295,8 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
* directly. So we just bail now. * directly. So we just bail now.
*/ */
if (!thePerformIndexing) { if (!thePerformIndexing) {
DaoMethodOutcome outcome = toMethodOutcome(entity, null).setCreated(false); theResource.setId(entity.getIdDt().getValue());
DaoMethodOutcome outcome = toMethodOutcome(entity, theResource).setCreated(false);
outcome.setPreviousResource(oldResource); outcome.setPreviousResource(oldResource);
return outcome; return outcome;
} }

View File

@ -29,6 +29,13 @@ public class DaoMethodOutcome extends MethodOutcome {
private ResourceTable myEntity; private ResourceTable myEntity;
private IBaseResource myPreviousResource; private IBaseResource myPreviousResource;
/**
* Constructor
*/
public DaoMethodOutcome() {
super();
}
public ResourceTable getEntity() { public ResourceTable getEntity() {
return myEntity; return myEntity;
} }

View File

@ -37,6 +37,7 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -403,6 +404,38 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
} }
@Test
public void testCreateConditionalWithPreferRepresentation() {
Patient p = new Patient();
p.setActive(false);
p.addIdentifier().setSystem("foo").setValue("bar");
IIdType id = ourClient.create().resource(p).execute().getId();
p = new Patient();
p.setId(id);
p.setActive(true);
p.addIdentifier().setSystem("foo").setValue("bar");
ourClient.update().resource(p).execute().getId();
// Now conditional create
p = new Patient();
p.setActive(true);
p.setBirthDateElement(new DateType("2011-01-01"));
p.addIdentifier().setSystem("foo").setValue("bar");
MethodOutcome outcome = ourClient
.create()
.resource(p)
.conditionalByUrl("Patient?identifier=foo|bar")
.prefer(PreferReturnEnum.REPRESENTATION)
.execute();
assertEquals(id.getIdPart(), outcome.getId().getIdPart());
assertEquals("2", outcome.getId().getVersionIdPart());
p = (Patient) outcome.getResource();
assertNull(p.getBirthDate());
}
/** /**
* See #438 * See #438
*/ */