Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Nov 6, 2024
1 parent d76ed00 commit 37f0975
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ca.uhn.fhir.jpa.search.builder.predicate;

import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.model.entity.ResourceIndexedComboStringUnique;
import ca.uhn.fhir.jpa.search.builder.sql.SearchQueryBuilder;
import ca.uhn.fhir.jpa.util.QueryParameterUtils;
import com.healthmarketscience.sqlbuilder.Condition;
Expand All @@ -35,7 +36,9 @@ public class ComboUniqueSearchParameterPredicateBuilder extends BaseSearchParamP
* Constructor
*/
public ComboUniqueSearchParameterPredicateBuilder(SearchQueryBuilder theSearchSqlBuilder) {
super(theSearchSqlBuilder, theSearchSqlBuilder.addTable("HFJ_IDX_CMP_STRING_UNIQ"));
super(
theSearchSqlBuilder,
theSearchSqlBuilder.addTable(ResourceIndexedComboStringUnique.HFJ_IDX_CMP_STRING_UNIQ));

myColumnString = getTable().addColumn("IDX_STRING");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.gclient.StringClientParam;
import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import jakarta.annotation.Nonnull;
Expand Down Expand Up @@ -106,7 +107,7 @@ void testIndexAndSearch(TestParameters theParameters) {
String expectedErrorMessage = "HAPI-" + theParameters.myExpectedErrorCode + ": Search parameter \"" + sp.getCode() + "\" for resource type \"Patient\" is not active for searching";
assertThat(e.getMessage()).contains(expectedErrorMessage);

String expectedValidParams = "Valid search parameters for this search are: [_id, _lastUpdated, _text, active, address, address-city, address-country, address-postalcode, address-state, address-use, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, part-agree, phone, phonetic, telecom]";
String expectedValidParams = "Valid search parameters for this search are: [_id, _lastUpdated, _profile, _security, _tag, _text, active, address, address-city, address-country, address-postalcode, address-state, address-use, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, part-agree, phone, phonetic, telecom]";
if (theParameters.mySearchParameter.getCode().equals("family")) {
expectedValidParams = expectedErrorMessage.replace(", family", "");
}
Expand Down Expand Up @@ -151,13 +152,13 @@ void testCapabilityStatement(TestParameters theParameters) {
" , false"
})
public void testComboUniqueSearchParameter(Boolean theEnabledForSearching, boolean theUnique) {
myComboSearchParameterTestHelper.createBirthdateAndGenderSps(theUnique, t -> {
myComboSearchParameterTestHelper.createFamilyAndGenderSps(theUnique, t -> {
if (theEnabledForSearching != null) {
t.addExtension(EXT_SEARCHPARAM_ENABLED_FOR_SEARCHING, new BooleanType(theEnabledForSearching));
}
});

createPatient(withId("A"), withBirthdate("2020-01-02"), withGender("male"));
createPatient(withId("A"), withFamily("simpson"), withGender("male"));

logAllDateIndexes();
logAllTokenIndexes();
Expand All @@ -166,7 +167,7 @@ public void testComboUniqueSearchParameter(Boolean theEnabledForSearching, boole
// Test
SearchParameterMap map = SearchParameterMap
.newSynchronous()
.add(Patient.SP_BIRTHDATE, new DateParam("2020-01-02"))
.add(Patient.SP_FAMILY, new StringParam("simpson"))
.add(Patient.SP_GENDER, new TokenParam( "male"));
myCaptureQueriesListener.clear();
IBundleProvider outcome = myPatientDao.search(map, mySrd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,49 @@ public void createBirthdateAndGenderSps(boolean theUnique, ISearchParamCustomize
.setDefinition("SearchParameter/patient-birthdate");
sp.addExtension()
.setUrl(HapiExtensions.EXT_SP_UNIQUE)
.setValue(new BooleanType(true));
.setValue(new BooleanType(theUnique));
for (var next : theSearchParamCustomizer) {
next.accept(sp);
}

mySearchParameterDao.update(fromCanonoical(sp), new SystemRequestDetails());

mySearchParamRegistry.forceRefresh();
}

public void createFamilyAndGenderSps(boolean theUnique, ISearchParamCustomizer... theSearchParamCustomizer) {
SearchParameter sp = new SearchParameter();
sp.setId("SearchParameter/patient-family");
sp.setType(Enumerations.SearchParamType.STRING);
sp.setCode("family");
sp.setExpression("Patient.name.family");
sp.setStatus(Enumerations.PublicationStatus.ACTIVE);
sp.addBase(Enumerations.VersionIndependentResourceTypesAll.PATIENT);
mySearchParameterDao.update(fromCanonoical(sp), new SystemRequestDetails());

sp = new SearchParameter();
sp.setId("SearchParameter/patient-gender");
sp.setType(Enumerations.SearchParamType.TOKEN);
sp.setCode("gender");
sp.setExpression("Patient.gender");
sp.setStatus(Enumerations.PublicationStatus.ACTIVE);
sp.addBase(Enumerations.VersionIndependentResourceTypesAll.PATIENT);
mySearchParameterDao.update(fromCanonoical(sp), new SystemRequestDetails());

sp = new SearchParameter();
sp.setId("SearchParameter/patient-family-gender");
sp.setType(Enumerations.SearchParamType.COMPOSITE);
sp.setStatus(Enumerations.PublicationStatus.ACTIVE);
sp.addBase(Enumerations.VersionIndependentResourceTypesAll.PATIENT);
sp.addComponent()
.setExpression("Patient")
.setDefinition("SearchParameter/patient-family");
sp.addComponent()
.setExpression("Patient")
.setDefinition("SearchParameter/patient-gender");
sp.addExtension()
.setUrl(HapiExtensions.EXT_SP_UNIQUE)
.setValue(new BooleanType(theUnique));
for (var next : theSearchParamCustomizer) {
next.accept(sp);
}
Expand Down

0 comments on commit 37f0975

Please sign in to comment.