mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-17 02:15:22 +00:00
Make sure we properly scope reference queries on external URLs
This commit is contained in:
parent
e85bec2858
commit
cf7cd40336
@ -450,8 +450,9 @@ public class SearchBuilder implements ISearchBuilder {
|
|||||||
// Resources by fully qualified URL
|
// Resources by fully qualified URL
|
||||||
if (!targetQualifiedUrls.isEmpty()) {
|
if (!targetQualifiedUrls.isEmpty()) {
|
||||||
ourLog.debug("Searching for resource link with target URLs: {}", targetQualifiedUrls);
|
ourLog.debug("Searching for resource link with target URLs: {}", targetQualifiedUrls);
|
||||||
Predicate eq = join.get("myTargetResourceUrl").in(targetQualifiedUrls);
|
Predicate pathPredicate = createResourceLinkPathPredicate(theResourceName, theParamName, join);
|
||||||
codePredicates.add(eq);
|
Predicate pidPredicate = join.get("myTargetResourceUrl").in(targetQualifiedUrls);
|
||||||
|
codePredicates.add(myBuilder.and(pathPredicate, pidPredicate));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codePredicates.size() > 0) {
|
if (codePredicates.size() > 0) {
|
||||||
|
@ -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
|
* See #872
|
||||||
*/
|
*/
|
||||||
|
@ -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
|
@Test
|
||||||
public void testCreateResourceConditional() throws IOException {
|
public void testCreateResourceConditional() throws IOException {
|
||||||
String methodName = "testCreateResourceConditional";
|
String methodName = "testCreateResourceConditional";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user