Add test and credit for #819
This commit is contained in:
parent
4f519e0528
commit
a3a15ac9d8
|
@ -1,209 +1,64 @@
|
|||
package ca.uhn.fhir.jpa.dao.r4;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.hl7.fhir.r4.model.Bundle.*;
|
||||
import org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem;
|
||||
import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender;
|
||||
import org.hl7.fhir.r4.model.Observation.ObservationStatus;
|
||||
import org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType;
|
||||
import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus;
|
||||
import org.hl7.fhir.instance.model.api.*;
|
||||
import org.junit.*;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.*;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.*;
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap;
|
||||
import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
|
||||
import ca.uhn.fhir.jpa.entity.*;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.parser.StrictErrorHandler;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.SortOrderEnum;
|
||||
import ca.uhn.fhir.rest.api.SortSpec;
|
||||
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
|
||||
import org.hl7.fhir.r4.model.Bundle.BundleType;
|
||||
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
|
||||
import org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem;
|
||||
import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender;
|
||||
import org.hl7.fhir.r4.model.Observation.ObservationStatus;
|
||||
import org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType;
|
||||
import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus;
|
||||
import org.junit.*;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4SearchNoFtTest.class);
|
||||
|
||||
@Before
|
||||
public void beforeDisableCacheReuse() {
|
||||
myDaoConfig.setReuseCachedSearchResultsForMillis(null);
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterResetSearchSize() {
|
||||
myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis());
|
||||
myDaoConfig.setFetchSizeDefaultMaximum(new DaoConfig().getFetchSizeDefaultMaximum());
|
||||
}
|
||||
|
||||
/**
|
||||
* See #744
|
||||
*/
|
||||
@Test
|
||||
public void testSearchWithVeryLongUrlShorter() {
|
||||
myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis());
|
||||
|
||||
Patient p = new Patient();
|
||||
p.addName().setFamily("A1");
|
||||
myPatientDao.create(p);
|
||||
|
||||
assertEquals(0, mySearchEntityDao.count());
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
StringOrListParam or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'A')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'B')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'C')));
|
||||
map.add(Patient.SP_NAME, or);
|
||||
IBundleProvider results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
assertEquals(1, mySearchEntityDao.count());
|
||||
|
||||
map = new SearchParameterMap();
|
||||
or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'A')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'B')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'C')));
|
||||
map.add(Patient.SP_NAME, or);
|
||||
results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
assertEquals(1, mySearchEntityDao.count());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #744
|
||||
*/
|
||||
@Test
|
||||
public void testSearchWithVeryLongUrlLonger() {
|
||||
myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis());
|
||||
|
||||
Patient p = new Patient();
|
||||
p.addName().setFamily("A1");
|
||||
myPatientDao.create(p);
|
||||
|
||||
assertEquals(0, mySearchEntityDao.count());
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
StringOrListParam or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
for (int i = 0; i < 50; i++) {
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, (char)('A' + i))));
|
||||
}
|
||||
map.add(Patient.SP_NAME, or);
|
||||
IBundleProvider results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
assertEquals(1, mySearchEntityDao.count());
|
||||
|
||||
map = new SearchParameterMap();
|
||||
or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
or.addOr(new StringParam("A1"));
|
||||
for (int i = 0; i < 50; i++) {
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, (char)('A' + i))));
|
||||
}
|
||||
map.add(Patient.SP_NAME, or);
|
||||
results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
// We expect a new one because we don't cache the search URL for very long search URLs
|
||||
assertEquals(2, mySearchEntityDao.count());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #441
|
||||
*/
|
||||
@Test
|
||||
public void testChainedMedication() {
|
||||
Medication medication = new Medication();
|
||||
medication.getCode().addCoding().setSystem("SYSTEM").setCode("04823543");
|
||||
IIdType medId = myMedicationDao.create(medication).getId().toUnqualifiedVersionless();
|
||||
|
||||
MedicationAdministration ma = new MedicationAdministration();
|
||||
ma.setMedication(new Reference(medId));
|
||||
IIdType moId = myMedicationAdministrationDao.create(ma).getId().toUnqualified();
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
map.add(MedicationAdministration.SP_MEDICATION, new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("code", "04823543"))));
|
||||
IBundleProvider results = myMedicationAdministrationDao.search(map);
|
||||
List<String> ids = toUnqualifiedIdValues(results);
|
||||
|
||||
assertThat(ids, contains(moId.getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludeLinkedObservations() {
|
||||
|
||||
DiagnosticReport dr = new DiagnosticReport();
|
||||
dr.setId("DiagnosticReport/DR");
|
||||
dr.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL);
|
||||
|
||||
Observation parentObs = new Observation();
|
||||
parentObs.setStatus(ObservationStatus.FINAL);
|
||||
parentObs.setId("Observation/parentObs");
|
||||
|
||||
Observation childObs = new Observation();
|
||||
childObs.setId("Observation/childObs");
|
||||
childObs.setStatus(ObservationStatus.FINAL);
|
||||
|
||||
dr.addResult().setReference("Observation/parentObs").setResource(parentObs);
|
||||
parentObs.addHasMember(new Reference(childObs).setReference("Observation/childObs"));
|
||||
childObs.addDerivedFrom(new Reference(parentObs).setReference("Observation/parentObs"));
|
||||
|
||||
Bundle input = new Bundle();
|
||||
input.setType(BundleType.TRANSACTION);
|
||||
input.addEntry()
|
||||
.setResource(dr)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl(dr.getId());
|
||||
input.addEntry()
|
||||
.setResource(parentObs)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl(parentObs.getId());
|
||||
input.addEntry()
|
||||
.setResource(childObs)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl(childObs.getId());
|
||||
mySystemDao.transaction(mySrd, input);
|
||||
|
||||
SearchParameterMap params = new SearchParameterMap();
|
||||
params.add("_id", new TokenParam(null, "DR"));
|
||||
params.addInclude(new Include("DiagnosticReport:subject").setRecurse(true));
|
||||
params.addInclude(new Include("DiagnosticReport:result").setRecurse(true));
|
||||
params.addInclude(Observation.INCLUDE_HAS_MEMBER.setRecurse(true));
|
||||
|
||||
IBundleProvider result = myDiagnosticReportDao.search(params);
|
||||
List<String> resultIds = toUnqualifiedVersionlessIdValues(result);
|
||||
assertThat(resultIds, containsInAnyOrder("DiagnosticReport/DR", "Observation/parentObs", "Observation/childObs"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyChain() {
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
map.add(Encounter.SP_SUBJECT, new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("subject", "04823543").setChain("identifier"))));
|
||||
IBundleProvider results = myMedicationAdministrationDao.search(map);
|
||||
List<String> ids = toUnqualifiedIdValues(results);
|
||||
|
||||
assertThat(ids, empty());
|
||||
@Before
|
||||
public void beforeDisableCacheReuse() {
|
||||
myDaoConfig.setReuseCachedSearchResultsForMillis(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -256,6 +111,38 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
assertThat(ids, empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* See #441
|
||||
*/
|
||||
@Test
|
||||
public void testChainedMedication() {
|
||||
Medication medication = new Medication();
|
||||
medication.getCode().addCoding().setSystem("SYSTEM").setCode("04823543");
|
||||
IIdType medId = myMedicationDao.create(medication).getId().toUnqualifiedVersionless();
|
||||
|
||||
MedicationAdministration ma = new MedicationAdministration();
|
||||
ma.setMedication(new Reference(medId));
|
||||
IIdType moId = myMedicationAdministrationDao.create(ma).getId().toUnqualified();
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
map.add(MedicationAdministration.SP_MEDICATION, new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("code", "04823543"))));
|
||||
IBundleProvider results = myMedicationAdministrationDao.search(map);
|
||||
List<String> ids = toUnqualifiedIdValues(results);
|
||||
|
||||
assertThat(ids, contains(moId.getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyChain() {
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
map.add(Encounter.SP_SUBJECT, new ReferenceAndListParam().addAnd(new ReferenceOrListParam().add(new ReferenceParam("subject", "04823543").setChain("identifier"))));
|
||||
IBundleProvider results = myMedicationAdministrationDao.search(map);
|
||||
List<String> ids = toUnqualifiedIdValues(results);
|
||||
|
||||
assertThat(ids, empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEverythingTimings() {
|
||||
String methodName = "testEverythingTimings";
|
||||
|
@ -506,6 +393,50 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludeLinkedObservations() {
|
||||
|
||||
DiagnosticReport dr = new DiagnosticReport();
|
||||
dr.setId("DiagnosticReport/DR");
|
||||
dr.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL);
|
||||
|
||||
Observation parentObs = new Observation();
|
||||
parentObs.setStatus(ObservationStatus.FINAL);
|
||||
parentObs.setId("Observation/parentObs");
|
||||
|
||||
Observation childObs = new Observation();
|
||||
childObs.setId("Observation/childObs");
|
||||
childObs.setStatus(ObservationStatus.FINAL);
|
||||
|
||||
dr.addResult().setReference("Observation/parentObs").setResource(parentObs);
|
||||
parentObs.addHasMember(new Reference(childObs).setReference("Observation/childObs"));
|
||||
childObs.addDerivedFrom(new Reference(parentObs).setReference("Observation/parentObs"));
|
||||
|
||||
Bundle input = new Bundle();
|
||||
input.setType(BundleType.TRANSACTION);
|
||||
input.addEntry()
|
||||
.setResource(dr)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl(dr.getId());
|
||||
input.addEntry()
|
||||
.setResource(parentObs)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl(parentObs.getId());
|
||||
input.addEntry()
|
||||
.setResource(childObs)
|
||||
.getRequest().setMethod(HTTPVerb.PUT).setUrl(childObs.getId());
|
||||
mySystemDao.transaction(mySrd, input);
|
||||
|
||||
SearchParameterMap params = new SearchParameterMap();
|
||||
params.add("_id", new TokenParam(null, "DR"));
|
||||
params.addInclude(new Include("DiagnosticReport:subject").setRecurse(true));
|
||||
params.addInclude(new Include("DiagnosticReport:result").setRecurse(true));
|
||||
params.addInclude(Observation.INCLUDE_HAS_MEMBER.setRecurse(true));
|
||||
|
||||
IBundleProvider result = myDiagnosticReportDao.search(params);
|
||||
List<String> resultIds = toUnqualifiedVersionlessIdValues(result);
|
||||
assertThat(resultIds, containsInAnyOrder("DiagnosticReport/DR", "Observation/parentObs", "Observation/childObs"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexNoDuplicatesDate() {
|
||||
Encounter order = new Encounter();
|
||||
|
@ -553,9 +484,9 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
List<ResourceIndexedSearchParamNumber> results = myEntityManager.createQuery("SELECT i FROM " + type.getSimpleName() + " i", type).getResultList();
|
||||
ourLog.info(toStringMultiline(results));
|
||||
assertThat(results, containsInAnyOrder(
|
||||
((ResourceIndexedSearchParamNumber)(new ResourceIndexedSearchParamNumber(ImmunizationRecommendation.SP_DOSE_SEQUENCE, null).setResource(resource).setMissing(true))),
|
||||
((ResourceIndexedSearchParamNumber)(new ResourceIndexedSearchParamNumber(ImmunizationRecommendation.SP_DOSE_NUMBER, new BigDecimal("1.00")).setResource(resource))),
|
||||
((ResourceIndexedSearchParamNumber)(new ResourceIndexedSearchParamNumber(ImmunizationRecommendation.SP_DOSE_NUMBER, new BigDecimal("2.00")).setResource(resource)))
|
||||
((ResourceIndexedSearchParamNumber) (new ResourceIndexedSearchParamNumber(ImmunizationRecommendation.SP_DOSE_SEQUENCE, null).setResource(resource).setMissing(true))),
|
||||
((ResourceIndexedSearchParamNumber) (new ResourceIndexedSearchParamNumber(ImmunizationRecommendation.SP_DOSE_NUMBER, new BigDecimal("1.00")).setResource(resource))),
|
||||
((ResourceIndexedSearchParamNumber) (new ResourceIndexedSearchParamNumber(ImmunizationRecommendation.SP_DOSE_NUMBER, new BigDecimal("2.00")).setResource(resource)))
|
||||
));
|
||||
}
|
||||
});
|
||||
|
@ -681,6 +612,17 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
assertThat(actual, contains(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* #454
|
||||
*/
|
||||
@Test
|
||||
public void testIndexWithUtf8Chars() throws IOException {
|
||||
String input = IOUtils.toString(getClass().getResourceAsStream("/bug454_utf8.json"), StandardCharsets.UTF_8);
|
||||
|
||||
CodeSystem cs = (CodeSystem) myFhirCtx.newJsonParser().parseResource(input);
|
||||
myCodeSystemDao.create(cs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnOnlyCorrectResourceType() {
|
||||
ValueSet vsRes = new ValueSet();
|
||||
|
@ -702,17 +644,6 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
assertThat(actual, contains(csId));
|
||||
}
|
||||
|
||||
/**
|
||||
* #454
|
||||
*/
|
||||
@Test
|
||||
public void testIndexWithUtf8Chars() throws IOException {
|
||||
String input = IOUtils.toString(getClass().getResourceAsStream("/bug454_utf8.json"), StandardCharsets.UTF_8);
|
||||
|
||||
CodeSystem cs = (CodeSystem) myFhirCtx.newJsonParser().parseResource(input);
|
||||
myCodeSystemDao.create(cs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchAll() {
|
||||
{
|
||||
|
@ -1473,6 +1404,43 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See #819
|
||||
*/
|
||||
@Test
|
||||
public void testSearchTokenWithNotModifier() {
|
||||
String male, female;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("001");
|
||||
patient.addName().setFamily("Tester").addGiven("Joe");
|
||||
patient.setGender(AdministrativeGender.MALE);
|
||||
male = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless().getValue();
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("002");
|
||||
patient.addName().setFamily("Tester").addGiven("Jane");
|
||||
patient.setGender(AdministrativeGender.FEMALE);
|
||||
female = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless().getValue();
|
||||
}
|
||||
|
||||
List<String> patients;
|
||||
SearchParameterMap params;
|
||||
|
||||
params = new SearchParameterMap();
|
||||
params.add(Patient.SP_GENDER, new TokenParam(null, "male"));
|
||||
params.setLoadSynchronous(true);
|
||||
patients = toUnqualifiedVersionlessIdValues(myPatientDao.search(params));
|
||||
assertThat(patients, contains(male));
|
||||
|
||||
params = new SearchParameterMap();
|
||||
params.add(Patient.SP_GENDER, new TokenParam(null, "male").setModifier(TokenParamModifier.NOT));
|
||||
params.setLoadSynchronous(true);
|
||||
patients = toUnqualifiedVersionlessIdValues(myPatientDao.search(params));
|
||||
assertThat(patients, contains(female));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchNumberParam() {
|
||||
ImmunizationRecommendation e1 = new ImmunizationRecommendation();
|
||||
|
@ -1860,7 +1828,6 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void testSearchResourceReferenceOnlyCorrectPath() {
|
||||
|
@ -1893,48 +1860,6 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchStringParamDoesntMatchWrongType() {
|
||||
IIdType pid1;
|
||||
IIdType pid2;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addName().setFamily("HELLO");
|
||||
pid1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
{
|
||||
Practitioner patient = new Practitioner();
|
||||
patient.addName().setFamily("HELLO");
|
||||
pid2 = myPractitionerDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
|
||||
SearchParameterMap params;
|
||||
List<IIdType> patients;
|
||||
|
||||
params = new SearchParameterMap();
|
||||
params.add(Patient.SP_FAMILY, new StringParam("HELLO"));
|
||||
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
|
||||
assertThat(patients, containsInAnyOrder(pid1));
|
||||
assertThat(patients, not(containsInAnyOrder(pid2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithFetchSizeDefaultMaximum() {
|
||||
myDaoConfig.setFetchSizeDefaultMaximum(5);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Patient p = new Patient();
|
||||
p.addName().setFamily("PT" + i);
|
||||
myPatientDao.create(p);
|
||||
}
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
map.setLoadSynchronous(true);
|
||||
IBundleProvider values = myPatientDao.search(map);
|
||||
assertEquals(5, values.size().intValue());
|
||||
assertEquals(5, values.getResources(0, 1000).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchStringParam() throws Exception {
|
||||
IIdType pid1;
|
||||
|
@ -1978,6 +1903,31 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchStringParamDoesntMatchWrongType() {
|
||||
IIdType pid1;
|
||||
IIdType pid2;
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.addName().setFamily("HELLO");
|
||||
pid1 = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
{
|
||||
Practitioner patient = new Practitioner();
|
||||
patient.addName().setFamily("HELLO");
|
||||
pid2 = myPractitionerDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
||||
}
|
||||
|
||||
SearchParameterMap params;
|
||||
List<IIdType> patients;
|
||||
|
||||
params = new SearchParameterMap();
|
||||
params.add(Patient.SP_FAMILY, new StringParam("HELLO"));
|
||||
patients = toUnqualifiedVersionlessIds(myPatientDao.search(params));
|
||||
assertThat(patients, containsInAnyOrder(pid1));
|
||||
assertThat(patients, not(containsInAnyOrder(pid2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchStringParamReallyLong() {
|
||||
String methodName = "testSearchStringParamReallyLong";
|
||||
|
@ -2355,6 +2305,22 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithFetchSizeDefaultMaximum() {
|
||||
myDaoConfig.setFetchSizeDefaultMaximum(5);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Patient p = new Patient();
|
||||
p.addName().setFamily("PT" + i);
|
||||
myPatientDao.create(p);
|
||||
}
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
map.setLoadSynchronous(true);
|
||||
IBundleProvider values = myPatientDao.search(map);
|
||||
assertEquals(5, values.size().intValue());
|
||||
assertEquals(5, values.getResources(0, 1000).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithIncludes() {
|
||||
|
@ -2670,7 +2636,6 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchWithNoResults() {
|
||||
Device dev = new Device();
|
||||
|
@ -2887,7 +2852,6 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* https://chat.fhir.org/#narrow/stream/implementers/topic/Understanding.20_include
|
||||
*/
|
||||
|
@ -3004,6 +2968,81 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
|
|||
assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder());
|
||||
}
|
||||
|
||||
/**
|
||||
* See #744
|
||||
*/
|
||||
@Test
|
||||
public void testSearchWithVeryLongUrlLonger() {
|
||||
myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis());
|
||||
|
||||
Patient p = new Patient();
|
||||
p.addName().setFamily("A1");
|
||||
myPatientDao.create(p);
|
||||
|
||||
assertEquals(0, mySearchEntityDao.count());
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
StringOrListParam or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
for (int i = 0; i < 50; i++) {
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, (char) ('A' + i))));
|
||||
}
|
||||
map.add(Patient.SP_NAME, or);
|
||||
IBundleProvider results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
assertEquals(1, mySearchEntityDao.count());
|
||||
|
||||
map = new SearchParameterMap();
|
||||
or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
or.addOr(new StringParam("A1"));
|
||||
for (int i = 0; i < 50; i++) {
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, (char) ('A' + i))));
|
||||
}
|
||||
map.add(Patient.SP_NAME, or);
|
||||
results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
// We expect a new one because we don't cache the search URL for very long search URLs
|
||||
assertEquals(2, mySearchEntityDao.count());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #744
|
||||
*/
|
||||
@Test
|
||||
public void testSearchWithVeryLongUrlShorter() {
|
||||
myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis());
|
||||
|
||||
Patient p = new Patient();
|
||||
p.addName().setFamily("A1");
|
||||
myPatientDao.create(p);
|
||||
|
||||
assertEquals(0, mySearchEntityDao.count());
|
||||
|
||||
SearchParameterMap map = new SearchParameterMap();
|
||||
StringOrListParam or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'A')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'B')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'C')));
|
||||
map.add(Patient.SP_NAME, or);
|
||||
IBundleProvider results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
assertEquals(1, mySearchEntityDao.count());
|
||||
|
||||
map = new SearchParameterMap();
|
||||
or = new StringOrListParam();
|
||||
or.addOr(new StringParam("A1"));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'A')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'B')));
|
||||
or.addOr(new StringParam(StringUtils.leftPad("", 200, 'C')));
|
||||
map.add(Patient.SP_NAME, or);
|
||||
results = myPatientDao.search(map);
|
||||
assertEquals(1, results.getResources(0, 10).size());
|
||||
assertEquals(1, mySearchEntityDao.count());
|
||||
|
||||
}
|
||||
|
||||
private String toStringMultiline(List<?> theResults) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
|
|
@ -267,6 +267,10 @@
|
|||
removed from the build. Thanks to Łukasz Dywicki for the
|
||||
pull request!
|
||||
</action>
|
||||
<action type="add" issue="819">
|
||||
Support has been added to the JPA server for the :not modifier. Thanks
|
||||
to Łukasz Dywicki for the pull request!
|
||||
</action>
|
||||
</release>
|
||||
<release version="3.2.0" date="2018-01-13">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue