Fix QuestionnaireResponse reference search on canonical urls (#3502)
This commit is contained in:
parent
179c970144
commit
f88d2d63bd
|
@ -29,6 +29,7 @@ import ca.uhn.fhir.jpa.searchparam.extractor.ISearchParamExtractor;
|
||||||
import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams;
|
import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams;
|
||||||
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
|
||||||
import ca.uhn.fhir.rest.server.util.ResourceSearchParams;
|
import ca.uhn.fhir.rest.server.util.ResourceSearchParams;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import org.hl7.fhir.instance.model.api.IBase;
|
import org.hl7.fhir.instance.model.api.IBase;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
import org.hl7.fhir.instance.model.api.IBaseCoding;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
@ -40,6 +41,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract search params for advanced lucene indexing.
|
* Extract search params for advanced lucene indexing.
|
||||||
|
@ -104,7 +106,15 @@ public class ExtendedLuceneIndexExtractor {
|
||||||
String insensitivePath = nextLink.getSourcePath().toLowerCase(Locale.ROOT);
|
String insensitivePath = nextLink.getSourcePath().toLowerCase(Locale.ROOT);
|
||||||
List<String> paramNames = linkPathToParamName.getOrDefault(insensitivePath, Collections.emptyList());
|
List<String> paramNames = linkPathToParamName.getOrDefault(insensitivePath, Collections.emptyList());
|
||||||
for (String nextParamName : paramNames) {
|
for (String nextParamName : paramNames) {
|
||||||
String qualifiedTargetResourceId = nextLink.getTargetResourceType() + "/" + nextLink.getTargetResourceId();
|
String qualifiedTargetResourceId = "";
|
||||||
|
// Consider 2 cases for references
|
||||||
|
// Case 1: Resource Type and Resource ID is known
|
||||||
|
// Case 2: Resource is unknown and referred by canonical url reference
|
||||||
|
if(!Strings.isNullOrEmpty(nextLink.getTargetResourceId())) {
|
||||||
|
qualifiedTargetResourceId = nextLink.getTargetResourceType() + "/" + nextLink.getTargetResourceId();
|
||||||
|
} else if(!Strings.isNullOrEmpty(nextLink.getTargetResourceUrl())) {
|
||||||
|
qualifiedTargetResourceId = nextLink.getTargetResourceUrl();
|
||||||
|
}
|
||||||
retVal.addResourceLinkIndexData(nextParamName, qualifiedTargetResourceId);
|
retVal.addResourceLinkIndexData(nextParamName, qualifiedTargetResourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
|
||||||
import ca.uhn.fhir.jpa.term.api.ITermReadSvcR4;
|
import ca.uhn.fhir.jpa.term.api.ITermReadSvcR4;
|
||||||
import ca.uhn.fhir.parser.IParser;
|
import ca.uhn.fhir.parser.IParser;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
|
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
|
||||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||||
import ca.uhn.fhir.rest.param.StringOrListParam;
|
import ca.uhn.fhir.rest.param.StringOrListParam;
|
||||||
|
@ -56,6 +57,8 @@ import org.hl7.fhir.r4.model.Narrative;
|
||||||
import org.hl7.fhir.r4.model.Observation;
|
import org.hl7.fhir.r4.model.Observation;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.hl7.fhir.r4.model.Quantity;
|
import org.hl7.fhir.r4.model.Quantity;
|
||||||
|
import org.hl7.fhir.r4.model.Questionnaire;
|
||||||
|
import org.hl7.fhir.r4.model.QuestionnaireResponse;
|
||||||
import org.hl7.fhir.r4.model.Reference;
|
import org.hl7.fhir.r4.model.Reference;
|
||||||
import org.hl7.fhir.r4.model.StringType;
|
import org.hl7.fhir.r4.model.StringType;
|
||||||
import org.hl7.fhir.r4.model.ValueSet;
|
import org.hl7.fhir.r4.model.ValueSet;
|
||||||
|
@ -147,6 +150,12 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
|
||||||
ITestDataBuilder myTestDataBuilder;
|
ITestDataBuilder myTestDataBuilder;
|
||||||
@Autowired
|
@Autowired
|
||||||
TestDaoSearch myTestDaoSearch;
|
TestDaoSearch myTestDaoSearch;
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("myQuestionnaireDaoR4")
|
||||||
|
private IFhirResourceDao<Questionnaire> myQuestionnaireDao;
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("myQuestionnaireResponseDaoR4")
|
||||||
|
private IFhirResourceDao<QuestionnaireResponse> myQuestionnaireResponseDao;
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
@ -445,6 +454,31 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResourceReferenceSearchForCanonicalReferences() {
|
||||||
|
String questionnaireCanonicalUrl = "https://test.fhir.org/R4/Questionnaire/xl-5000-q";
|
||||||
|
|
||||||
|
Questionnaire questionnaire = new Questionnaire();
|
||||||
|
questionnaire.setId("xl-5000-q");
|
||||||
|
questionnaire.setUrl(questionnaireCanonicalUrl);
|
||||||
|
IIdType questionnaireId = myQuestionnaireDao.update(questionnaire).getId();
|
||||||
|
|
||||||
|
QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
|
||||||
|
questionnaireResponse.setId("xl-5000-qr");
|
||||||
|
questionnaireResponse.setQuestionnaire(questionnaireCanonicalUrl);
|
||||||
|
IIdType questionnaireResponseId = myQuestionnaireResponseDao.update(questionnaireResponse).getId();
|
||||||
|
|
||||||
|
// Search Questionnaire Response using questionnaire canonical url
|
||||||
|
SearchParameterMap map = new SearchParameterMap()
|
||||||
|
.setLoadSynchronous(true)
|
||||||
|
.add(QuestionnaireResponse.SP_QUESTIONNAIRE, new ReferenceParam(questionnaireCanonicalUrl));
|
||||||
|
|
||||||
|
IBundleProvider bundle = myQuestionnaireResponseDao.search(map);
|
||||||
|
List<IBaseResource> result = bundle.getResources(0, bundle.sizeOrThrowNpe());
|
||||||
|
assertEquals(1, result.size());
|
||||||
|
assertEquals(questionnaireResponseId, result.get(0).getIdElement());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStringSearch() {
|
public void testStringSearch() {
|
||||||
IIdType id1, id2, id3, id4, id5, id6;
|
IIdType id1, id2, id3, id4, id5, id6;
|
||||||
|
@ -906,7 +940,6 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
|
||||||
// assertThat(newMeta.getTag(), hasSize(2));
|
// assertThat(newMeta.getTag(), hasSize(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue