added test to confirm this works properly (#5134)
Co-authored-by: Ken Stevens <ken@smilecdr.com>
This commit is contained in:
parent
85f41d5fc8
commit
dc3a4114ce
|
@ -8,6 +8,7 @@ import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString;
|
||||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||||
import ca.uhn.fhir.jpa.test.BaseJpaDstu3Test;
|
import ca.uhn.fhir.jpa.test.BaseJpaDstu3Test;
|
||||||
import ca.uhn.fhir.jpa.test.config.TestHSearchAddInConfig;
|
import ca.uhn.fhir.jpa.test.config.TestHSearchAddInConfig;
|
||||||
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.param.StringParam;
|
import ca.uhn.fhir.rest.param.StringParam;
|
||||||
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
|
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
|
||||||
import ca.uhn.fhir.util.HapiExtensions;
|
import ca.uhn.fhir.util.HapiExtensions;
|
||||||
|
@ -73,7 +74,15 @@ public class FhirResourceDaoDstu3PhoneticSearchNoFtTest extends BaseJpaDstu3Test
|
||||||
@Test
|
@Test
|
||||||
public void testSoundex() {
|
public void testSoundex() {
|
||||||
Soundex soundex = new Soundex();
|
Soundex soundex = new Soundex();
|
||||||
|
|
||||||
|
// The tests below depend on these assumptions:
|
||||||
assertEquals(soundex.encode(GALE), soundex.encode(GAIL));
|
assertEquals(soundex.encode(GALE), soundex.encode(GAIL));
|
||||||
|
assertNotEquals(soundex.encode(GALE), GALE);
|
||||||
|
assertNotEquals(soundex.encode(GAIL), GALE);
|
||||||
|
assertNotEquals(soundex.encode(GALE), GAIL);
|
||||||
|
assertNotEquals(soundex.encode(GAIL), GAIL);
|
||||||
|
ourLog.info("Encoded Gale: {}", soundex.encode(GALE));
|
||||||
|
ourLog.info("Encoded Gail: {}", soundex.encode(GAIL));
|
||||||
assertNotEquals(soundex.encode(GALE), soundex.encode(BOB));
|
assertNotEquals(soundex.encode(GALE), soundex.encode(BOB));
|
||||||
assertEquals(soundex.encode(ADDRESS), soundex.encode(ADDRESS_CLOSE));
|
assertEquals(soundex.encode(ADDRESS), soundex.encode(ADDRESS_CLOSE));
|
||||||
assertNotEquals(soundex.encode(ADDRESS), soundex.encode(ADDRESS_FAR));
|
assertNotEquals(soundex.encode(ADDRESS), soundex.encode(ADDRESS_FAR));
|
||||||
|
@ -91,9 +100,7 @@ public class FhirResourceDaoDstu3PhoneticSearchNoFtTest extends BaseJpaDstu3Test
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void phoneticMatch() {
|
public void phoneticMatch() {
|
||||||
Patient patient;
|
Patient patient = new Patient();
|
||||||
|
|
||||||
patient = new Patient();
|
|
||||||
patient.addName().addGiven(GALE);
|
patient.addName().addGiven(GALE);
|
||||||
patient.addAddress().addLine(ADDRESS);
|
patient.addAddress().addLine(ADDRESS);
|
||||||
patient.addTelecom().setValue(PHONE);
|
patient.addTelecom().setValue(PHONE);
|
||||||
|
@ -124,6 +131,30 @@ public class FhirResourceDaoDstu3PhoneticSearchNoFtTest extends BaseJpaDstu3Test
|
||||||
assertNoMatch(PHONE_NUMBER_SP, PHONE_FAR);
|
assertNoMatch(PHONE_NUMBER_SP, PHONE_FAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void phoneticSearch() {
|
||||||
|
// setup
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.addName().addGiven(GALE);
|
||||||
|
patient.addAddress().addLine(ADDRESS);
|
||||||
|
patient.addTelecom().setValue(PHONE);
|
||||||
|
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient));
|
||||||
|
|
||||||
|
IIdType patientId = myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless();
|
||||||
|
|
||||||
|
SearchParameterMap map = SearchParameterMap.newSynchronous();
|
||||||
|
// Search for a different name from the original value that has the same soundex value
|
||||||
|
map.add(NAME_SOUNDEX_SP, new StringParam(GAIL));
|
||||||
|
|
||||||
|
// execute
|
||||||
|
IBundleProvider result = myPatientDao.search(map, mySrd);
|
||||||
|
|
||||||
|
// verify
|
||||||
|
List<String> resultIds = result.getAllResourceIds();
|
||||||
|
assertEquals(1, resultIds.size());
|
||||||
|
assertEquals(patientId.getIdPart(), resultIds.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
private void assertSearchMatch(IIdType thePId1, String theSp, String theValue) {
|
private void assertSearchMatch(IIdType thePId1, String theSp, String theValue) {
|
||||||
SearchParameterMap map;
|
SearchParameterMap map;
|
||||||
map = new SearchParameterMap();
|
map = new SearchParameterMap();
|
||||||
|
|
Loading…
Reference in New Issue