Don't allow creating resources with references to deleted resources

This commit is contained in:
James Agnew 2017-06-30 22:20:43 -04:00
parent 9270afe410
commit 73a8cf1fca
3 changed files with 28 additions and 0 deletions

View File

@ -353,6 +353,11 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
"Resource contains reference to " + nextId.getValue() + " but resource with ID " + nextId.getIdPart() + " is actually of type " + target.getResourceType());
}
if (target.getDeleted() != null) {
String resName = targetResourceDef.getName();
throw new InvalidRequestException("Resource " + resName + "/" + id + " is deleted, specified in path: " + nextPathsUnsplit);
}
if (nextSpDef.getTargets() != null && !nextSpDef.getTargets().contains(typeString)) {
continue;
}

View File

@ -155,6 +155,24 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
}
}
@Test
public void testCreateReferenceToDeletedResource() {
Organization org = new Organization();
org.setActive(true);
IIdType orgId = myOrganizationDao.create(org).getId().toUnqualifiedVersionless();
myOrganizationDao.delete(orgId);
Patient p = new Patient();
p.getManagingOrganization().setReferenceElement(orgId);
try {
myPatientDao.create(p);
fail();
} catch (InvalidRequestException e) {
assertEquals("Resource Organization/" + orgId.getIdPart() + " is deleted, specified in path: Patient.managingOrganization", e.getMessage());
}
}
@Test
public void testCreateDuplicateTagsDoesNotCauseDuplicates() {
Patient p = new Patient();

View File

@ -111,6 +111,11 @@
if a resource containing multiple tags was updated many times via
transactions.
</action>
<action type="fix">
JPA server should not allow creation of resources that have a reference to
a resource ID that previously existed but is now deleted. Thanks to Artem
Sopin for reporting!
</action>
</release>
<release version="2.5" date="2017-06-08">
<action type="fix">