Co-authored-by: Ken Stevens <ken@smilecdr.com>
This commit is contained in:
Ken Stevens 2023-05-13 22:35:18 -04:00 committed by GitHub
parent 4313dc9958
commit a308f60e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 5 deletions

View File

@ -257,7 +257,11 @@ public class HashMapResourceProvider<T extends IBaseResource> implements IResour
}
@Read(version = true)
public synchronized T read(@IdParam IIdType theId, RequestDetails theRequestDetails) {
public T read(@IdParam IIdType theId, RequestDetails theRequestDetails) {
return read(theId, theRequestDetails, false);
}
public synchronized T read(IIdType theId, RequestDetails theRequestDetails, boolean theDeletedOk) {
TreeMap<Long, T> versions = myIdToVersionToResourceMap.get(theId.getIdPart());
if (versions == null || versions.isEmpty()) {
throw new ResourceNotFoundException(Msg.code(2247) + theId);
@ -276,7 +280,9 @@ public class HashMapResourceProvider<T extends IBaseResource> implements IResour
}
if (retVal == null || retVal.isDeleted()) {
throw new ResourceGoneException(Msg.code(2244) + theId);
if (!theDeletedOk) {
throw new ResourceGoneException(Msg.code(2244) + theId);
}
}
myReadCount.incrementAndGet();

View File

@ -3,15 +3,13 @@ package ca.uhn.fhir.rest.server.provider;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.api.IAnonymousInterceptor;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.rest.api.server.SystemRequestDetails;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
import ca.uhn.fhir.test.utilities.server.HashMapResourceProviderExtension;
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
@ -350,6 +348,29 @@ public class HashMapResourceProviderTest {
}
}
@Test
void testReadDeletedOk() {
Patient patient = new Patient();
patient.setActive(true);
SystemRequestDetails srd = new SystemRequestDetails();
IIdType patientId = myPatientResourceProvider.create(patient, srd).getId().toVersionless();
Patient readPatient = myPatientResourceProvider.read(patientId, srd, true);
assertFalse(readPatient.isDeleted());
}
@Test
void testReadDeletedDeletedOk() {
Patient patient = new Patient();
patient.setActive(true);
SystemRequestDetails srd = new SystemRequestDetails();
IIdType patientId = myPatientResourceProvider.create(patient, srd).getId().toVersionless();
myPatientResourceProvider.delete(patientId, srd);
Patient readPatient = myPatientResourceProvider.read(patientId, srd, true);
assertTrue(readPatient.isDeleted());
}
@AfterAll
public static void afterClassClearContext() throws Exception {
TestUtil.randomizeLocaleAndTimezone();