Make sure we properly scope reference queries on external URLs

This commit is contained in:
James Agnew 2019-03-27 13:10:24 -04:00
parent e85bec2858
commit cf7cd40336
3 changed files with 70 additions and 2 deletions

View File

@ -450,8 +450,9 @@ public class SearchBuilder implements ISearchBuilder {
// Resources by fully qualified URL
if (!targetQualifiedUrls.isEmpty()) {
ourLog.debug("Searching for resource link with target URLs: {}", targetQualifiedUrls);
Predicate eq = join.get("myTargetResourceUrl").in(targetQualifiedUrls);
codePredicates.add(eq);
Predicate pathPredicate = createResourceLinkPathPredicate(theResourceName, theParamName, join);
Predicate pidPredicate = join.get("myTargetResourceUrl").in(targetQualifiedUrls);
codePredicates.add(myBuilder.and(pathPredicate, pidPredicate));
}
if (codePredicates.size() > 0) {

View File

@ -90,6 +90,38 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
}
@Test
public void testSearchByExternalReference() {
myDaoConfig.setAllowExternalReferences(true);
Patient patient = new Patient();
patient.addName().setFamily("FooName");
IIdType patientId = ourClient.create().resource(patient).execute().getId();
//Reference patientReference = new Reference("Patient/" + patientId.getIdPart()); <--- this works
Reference patientReference = new Reference(patientId); // <--- this is seen as an external reference
Media media = new Media();
Attachment attachment = new Attachment();
attachment.setLanguage("ENG");
media.setContent(attachment);
media.setSubject(patientReference);
media.setType(Media.DigitalMediaType.AUDIO);
IIdType mediaId = ourClient.create().resource(media).execute().getId();
// Act
Bundle returnedBundle = ourClient.search()
.forResource(Observation.class)
.where(Observation.CONTEXT.hasId(patientReference.getReference()))
.returnBundle(Bundle.class)
.execute();
// Assert
assertEquals(0, returnedBundle.getEntry().size());
}
/**
* See #872
*/

View File

@ -703,6 +703,41 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
}
}
@Test
public void testSearchByExternalReference() {
myDaoConfig.setAllowExternalReferences(true);
Patient patient = new Patient();
patient.addName().setFamily("FooName");
IIdType patientId = ourClient.create().resource(patient).execute().getId();
//Reference patientReference = new Reference("Patient/" + patientId.getIdPart()); <--- this works
Reference patientReference = new Reference(patientId); // <--- this is seen as an external reference
Media media = new Media();
Attachment attachment = new Attachment();
attachment.setLanguage("ENG");
media.setContent(attachment);
media.setSubject(patientReference);
IIdType mediaId = ourClient.create().resource(media).execute().getId();
// Search for wrong type
Bundle returnedBundle = ourClient.search()
.forResource(Observation.class)
.where(Observation.ENCOUNTER.hasId(patientReference.getReference()))
.returnBundle(Bundle.class)
.execute();
assertEquals(0, returnedBundle.getEntry().size());
// Search for right type
returnedBundle = ourClient.search()
.forResource(Media.class)
.where(Media.SUBJECT.hasId(patientReference.getReference()))
.returnBundle(Bundle.class)
.execute();
assertEquals(mediaId, returnedBundle.getEntryFirstRep().getResource().getIdElement());
}
@Test
public void testCreateResourceConditional() throws IOException {
String methodName = "testCreateResourceConditional";