diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java index c66c2b8296a..17d43e7a57f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/Constants.java @@ -22,12 +22,7 @@ package ca.uhn.fhir.rest.api; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.apache.commons.lang3.StringUtils.defaultIfBlank; @@ -217,6 +212,7 @@ public class Constants { public static final String PARAMQUALIFIER_STRING_EXACT = ":exact"; public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text"; public static final String PARAMQUALIFIER_MDM = ":mdm"; + public static final String PARAMQUALIFIER_NICKNAME = ":nickname"; public static final String PARAMQUALIFIER_TOKEN_OF_TYPE = ":of-type"; public static final String PARAMQUALIFIER_TOKEN_NOT = ":not"; public static final int STATUS_HTTP_200_OK = 200; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java index 3ce8b50bd46..b7b54e3f3cf 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/StringParam.java @@ -21,9 +21,11 @@ package ca.uhn.fhir.rest.param; */ import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -38,7 +40,8 @@ public class StringParam extends BaseParam implements IQueryParameterType { private boolean myExact; private String myValue; - private Boolean myMdmExpand; + private Boolean myNicknameExpand; + /** * Constructor @@ -77,12 +80,12 @@ public class StringParam extends BaseParam implements IQueryParameterType { return ParameterUtil.escape(myValue); } - public boolean isMdmExpand() { - return myMdmExpand != null && myMdmExpand; + public boolean isNicknameExpand() { + return myNicknameExpand != null && myNicknameExpand; } - public StringParam setMdmExpand(boolean theMdmExpand) { - myMdmExpand = theMdmExpand; + public StringParam setNicknameExpand(boolean theNicknameExpand) { + myNicknameExpand = theNicknameExpand; return this; } @@ -98,6 +101,15 @@ public class StringParam extends BaseParam implements IQueryParameterType { @Override void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) { + if (Constants.PARAMQUALIFIER_NICKNAME.equals(theQualifier)) { + if ("name".equals(theParamName) || "given".equals(theParamName)) { + myNicknameExpand = true; + theQualifier = ""; + } else { + throw new InvalidRequestException(Msg.code(2077) + "Modifier " + Constants.PARAMQUALIFIER_NICKNAME + " may only be used with 'name' and 'given' search parameters"); + } + } + if (Constants.PARAMQUALIFIER_STRING_EXACT.equals(theQualifier)) { setExact(true); } else { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/SearchParameterUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/SearchParameterUtil.java index 024e948ae47..64376924446 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/SearchParameterUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/SearchParameterUtil.java @@ -58,8 +58,8 @@ public class SearchParameterUtil { * 1. Attempt to find one called 'patient' * 2. If that fails, find one called 'subject' * 3. If that fails, find find by Patient Compartment. - * 3.1 If that returns >1 result, throw an error - * 3.2 If that returns 1 result, return it + * 3.1 If that returns >1 result, throw an error + * 3.2 If that returns 1 result, return it */ public static Optional getOnlyPatientSearchParamForResourceType(FhirContext theFhirContext, String theResourceType) { RuntimeSearchParam myPatientSearchParam = null; @@ -115,7 +115,7 @@ public class SearchParameterUtil { */ public static boolean isResourceTypeInPatientCompartment(FhirContext theFhirContext, String theResourceType) { RuntimeResourceDefinition runtimeResourceDefinition = theFhirContext.getResourceDefinition(theResourceType); - return getAllPatientCompartmentRuntimeSearchParams(runtimeResourceDefinition).size() > 0; + return getAllPatientCompartmentRuntimeSearchParams(runtimeResourceDefinition).size() > 0; } @@ -147,4 +147,15 @@ public class SearchParameterUtil { .map(t -> t.getValueAsString()) .orElse(null); } + + public static String stripModifier(String theSearchParam) { + String retval; + int colonIndex = theSearchParam.indexOf(":"); + if (colonIndex == -1) { + retval = theSearchParam; + } else { + retval = theSearchParam.substring(0, colonIndex); + } + return retval; + } } diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_0_0/3563-nickname-matching.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_0_0/3563-nickname-matching.yaml new file mode 100644 index 00000000000..8d21b04e4b2 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_0_0/3563-nickname-matching.yaml @@ -0,0 +1,5 @@ +type: add +issue: 3563 +title: "Added search parameter modifier :nickname that can be used with 'name' or 'given' search parameters. +E.g. ?Patient?given:nickname=Kenny will match a patient with the given name Kenneth. Also added MDM matching +algorithm named NICKNAME that matches based this." diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md index 44f8fc19b8f..d06abec758d 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/search.md @@ -1,5 +1,7 @@ # JPA Server Search +## Limitations + The HAPI FHIR JPA Server fully implements most [FHIR search](https://www.hl7.org/fhir/search.html) operations for most versions of FHIR. However, there are some known limitations of the current implementation. Here is a partial list of search functionality that is not currently supported in HAPI FHIR: ### Chains within _has diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_rules.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_rules.md index 5a2b7167ad4..bb328aca0ed 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_rules.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_rules.md @@ -406,6 +406,14 @@ The following algorithms are currently supported: Match names as strings in any order John Henry = John HENRY when exact=false, John Henry != Henry John + + + NICKNAME + matcher + + True if one name is a nickname of the other + + Ken = Kenneth, Kenny = Ken. Allen != Allan. IDENTIFIER diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/JpaConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/JpaConfig.java index b1f5f45caaf..316d3109d18 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/JpaConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/JpaConfig.java @@ -128,6 +128,7 @@ import ca.uhn.fhir.jpa.search.warm.CacheWarmingSvcImpl; import ca.uhn.fhir.jpa.search.warm.ICacheWarmingSvc; import ca.uhn.fhir.jpa.searchparam.config.SearchParamConfig; import ca.uhn.fhir.jpa.searchparam.extractor.IResourceLinkResolver; +import ca.uhn.fhir.jpa.searchparam.nickname.NicknameInterceptor; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamProvider; import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc; import ca.uhn.fhir.jpa.sp.SearchParamPresenceSvcImpl; @@ -164,6 +165,7 @@ import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean; import javax.annotation.Nullable; +import java.io.IOException; import java.util.Date; /* @@ -827,4 +829,10 @@ public class JpaConfig { public MemberMatcherR4Helper memberMatcherR4Helper(FhirContext theFhirContext) { return new MemberMatcherR4Helper(theFhirContext); } + + @Lazy + @Bean + public NicknameInterceptor nicknameInterceptor() throws IOException { + return new NicknameInterceptor(); + } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/ExtendedLuceneSearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/ExtendedLuceneSearchBuilder.java index 243a5c89c18..28e31abd797 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/ExtendedLuceneSearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/search/ExtendedLuceneSearchBuilder.java @@ -102,6 +102,7 @@ public class ExtendedLuceneSearchBuilder { case EMPTY_MODIFIER: return true; case Constants.PARAMQUALIFIER_MDM: + case Constants.PARAMQUALIFIER_NICKNAME: default: return false; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptor.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptor.java index 4c1319a6a43..abb385db66e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptor.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/interceptor/MdmSearchExpandingInterceptor.java @@ -30,13 +30,11 @@ import ca.uhn.fhir.mdm.log.Logs; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.TokenParam; import org.hl7.fhir.instance.model.api.IIdType; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; -import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -92,7 +90,7 @@ public class MdmSearchExpandingInterceptor { // If we failed, attempt to expand as a golden resource if (expandedResourceIds.isEmpty()) { - expandedResourceIds = myMdmLinkExpandSvc.expandMdmByGoldenResourceId(new IdDt(refParam.getValue())); + expandedResourceIds = myMdmLinkExpandSvc.expandMdmByGoldenResourceId(new IdDt(refParam.getValue())); } //Rebuild the search param list. @@ -104,8 +102,7 @@ public class MdmSearchExpandingInterceptor { .forEach(toAdd::add); } } - } - else if (theParamName.equalsIgnoreCase("_id")) { + } else if (theParamName.equalsIgnoreCase("_id")) { expandIdParameter(iQueryParameterType, toAdd, toRemove); } } @@ -117,6 +114,7 @@ public class MdmSearchExpandingInterceptor { /** * Expands out the provided _id parameter into all the various * ids of linked resources. + * * @param theIdParameter * @param theAddList * @param theRemoveList @@ -130,29 +128,21 @@ public class MdmSearchExpandingInterceptor { IIdType id; Creator creator; boolean mdmExpand = false; - if (theIdParameter instanceof StringParam) { - StringParam param = (StringParam) theIdParameter; - mdmExpand = param.isMdmExpand(); - id = new IdDt(param.getValue()); - creator = StringParam::new; - } - else if (theIdParameter instanceof TokenParam) { + if (theIdParameter instanceof TokenParam) { TokenParam param = (TokenParam) theIdParameter; mdmExpand = param.isMdmExpand(); id = new IdDt(param.getValue()); creator = TokenParam::new; - } - else { + } else { creator = null; id = null; } - if (id == null || creator == null) { + if (id == null) { // in case the _id paramter type is different from the above ourLog.warn("_id parameter of incorrect type. Expected StringParam or TokenParam, but got {}. No expansion will be done!", theIdParameter.getClass().getSimpleName()); - } - else if (mdmExpand) { + } else if (mdmExpand) { ourLog.debug("_id parameter must be expanded out from: {}", id.getValue()); Set expandedResourceIds = myMdmLinkExpandSvc.expandMdmBySourceResourceId(id); diff --git a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmSearchParamSvc.java b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmSearchParamSvc.java index 40397dc5297..20d1eae1f20 100644 --- a/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmSearchParamSvc.java +++ b/hapi-fhir-jpaserver-mdm/src/main/java/ca/uhn/fhir/jpa/mdm/svc/MdmSearchParamSvc.java @@ -31,6 +31,7 @@ import ca.uhn.fhir.jpa.searchparam.MatchUrlService; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorService; import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; +import ca.uhn.fhir.util.SearchParameterUtil; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; import org.springframework.beans.factory.annotation.Autowired; @@ -61,7 +62,8 @@ public class MdmSearchParamSvc { public List getValueFromResourceForSearchParam(IBaseResource theResource, String theSearchParam) { String resourceType = myFhirContext.getResourceType(theResource); - RuntimeSearchParam activeSearchParam = mySearchParamRegistry.getActiveSearchParam(resourceType, theSearchParam); + String searchParam = SearchParameterUtil.stripModifier(theSearchParam); + RuntimeSearchParam activeSearchParam = mySearchParamRegistry.getActiveSearchParam(resourceType, searchParam); return mySearchParamExtractorService.extractParamValuesAsStrings(activeSearchParam, theResource); } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMatchR4Test.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMatchR4Test.java index 3551facb44a..4db9cc11573 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMatchR4Test.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/provider/MdmProviderMatchR4Test.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -161,68 +162,134 @@ public class MdmProviderMatchR4Test extends BaseProviderR4Test { public void testMatchWithCoarseDateGranularity() throws Exception { setMdmRuleJson("mdm/coarse-birthdate-mdm-rules.json"); - String granularPatient = "{\n" + - " \"resourceType\": \"Patient\",\n" + - " \"active\": true,\n" + - " \"name\": [\n" + - " {\n" + - " \"family\": \"PETERSON\",\n" + - " \"given\": [\n" + - " \"GARY\",\n" + - " \"D\"\n" + - " ]\n" + - " }\n" + - " ],\n" + - " \"telecom\": [\n" + - " {\n" + - " \"system\": \"phone\",\n" + - " \"value\": \"100100100\",\n" + - " \"use\": \"home\"\n" + - " }\n" + - " ],\n" + - " \"gender\": \"male\",\n" + - " \"birthDate\": \"1991-10-10\",\n" + - " \"address\": [\n" + - " {\n" + - " \"state\": \"NY\",\n" + - " \"postalCode\": \"12313\"\n" + - " }\n" + - " ]\n" + - "}"; + String granularPatient = """ + { + "resourceType": "Patient", + "active": true, + "name": [ + { + "family": "PETERSON", + "given": [ + "GARY", + "D" + ] + } + ], + "telecom": [ + { + "system": "phone", + "value": "100100100", + "use": "home" + } + ], + "gender": "male", + "birthDate": "1991-10-10", + "address": [ + { + "state": "NY", + "postalCode": "12313" + } + ] + }"""; IBaseResource iBaseResource = myFhirContext.newJsonParser().parseResource(granularPatient); createPatient((Patient) iBaseResource); - String coarsePatient = "{\n" + - " \"resourceType\": \"Patient\",\n" + - " \"active\": true,\n" + - " \"name\": [\n" + - " {\n" + - " \"family\": \"PETERSON\",\n" + - " \"given\": [\n" + - " \"GARY\",\n" + - " \"D\"\n" + - " ]\n" + - " }\n" + - " ],\n" + - " \"telecom\": [\n" + - " {\n" + - " \"system\": \"phone\",\n" + - " \"value\": \"100100100\",\n" + - " \"use\": \"home\"\n" + - " }\n" + - " ],\n" + - " \"gender\": \"male\",\n" + - " \"birthDate\": \"1991-10\",\n" + - " \"address\": [\n" + - " {\n" + - " \"state\": \"NY\",\n" + - " \"postalCode\": \"12313\"\n" + - " }\n" + - " ]\n" + - "}"; + String coarsePatient = """ + { + "resourceType": "Patient", + "active": true, + "name": [ + { + "family": "PETERSON", + "given": [ + "GARY", + "D" + ] + } + ], + "telecom": [ + { + "system": "phone", + "value": "100100100", + "use": "home" + } + ], + "gender": "male", + "birthDate": "1991-10", + "address": [ + { + "state": "NY", + "postalCode": "12313" + } + ] + }"""; IBaseResource coarseResource = myFhirContext.newJsonParser().parseResource(coarsePatient); Bundle result = (Bundle) myMdmProvider.match((Patient) coarseResource, new SystemRequestDetails()); assertEquals(1, result.getEntry().size()); } + + @Test + public void testNicknameMatch() throws IOException { + setMdmRuleJson("mdm/nickname-mdm-rules.json"); + + String formalPatientJson = """ + { + "resourceType": "Patient", + "active": true, + "name": [ + { + "family": "PETERSON", + "given": [ + "Gregory" + ] + } + ], + "gender": "male" + }"""; + Patient formalPatient = (Patient) myFhirContext.newJsonParser().parseResource(formalPatientJson); + createPatient(formalPatient); + + String noMatchPatientJson = """ + { + "resourceType": "Patient", + "active": true, + "name": [ + { + "family": "PETERSON", + "given": [ + "Bob" + ] + } + ], + "gender": "male" + }"""; + Patient noMatchPatient = (Patient) myFhirContext.newJsonParser().parseResource(noMatchPatientJson); + createPatient(noMatchPatient); + { + Bundle result = (Bundle) myMdmProvider.match(noMatchPatient, new SystemRequestDetails()); + assertEquals(0, result.getEntry().size()); + } + + String nickPatientJson = """ + { + "resourceType": "Patient", + "active": true, + "name": [ + { + "family": "PETERSON", + "given": [ + "Greg" + ] + } + ], + "gender": "male" + }"""; + + { + Patient nickPatient = (Patient) myFhirContext.newJsonParser().parseResource(nickPatientJson); + Bundle result = (Bundle) myMdmProvider.match(nickPatient, new SystemRequestDetails()); + assertEquals(1, result.getEntry().size()); + } + } } diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchCriteriaBuilderSvcTest.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchCriteriaBuilderSvcTest.java index db439e71cf9..f37ca2a653a 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchCriteriaBuilderSvcTest.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchCriteriaBuilderSvcTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jpa.mdm.svc; -import ca.uhn.fhir.mdm.rules.json.MdmResourceSearchParamJson; import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmCandidateSearchCriteriaBuilderSvc; +import ca.uhn.fhir.mdm.rules.json.MdmResourceSearchParamJson; import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.Patient; import org.junit.jupiter.api.Test; diff --git a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java index da1f30f0bea..f283683458e 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java +++ b/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/svc/MdmCandidateSearchSvcIT.java @@ -4,15 +4,21 @@ import ca.uhn.fhir.interceptor.model.RequestPartitionId; import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmCandidateSearchSvc; import ca.uhn.fhir.jpa.mdm.svc.candidate.TooManyCandidatesException; +import ca.uhn.fhir.jpa.searchparam.MatchUrlService; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.jpa.searchparam.nickname.NicknameInterceptor; import ca.uhn.fhir.mdm.rules.config.MdmSettings; +import ca.uhn.fhir.rest.api.server.IBundleProvider; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Reference; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -28,10 +34,21 @@ public class MdmCandidateSearchSvcIT extends BaseMdmR4Test { MdmCandidateSearchSvc myMdmCandidateSearchSvc; @Autowired MdmSettings myMdmSettings; + @Autowired + MatchUrlService myMatchUrlService; + + private NicknameInterceptor myNicknameInterceptor; + + @BeforeEach + public void before() throws IOException { + myNicknameInterceptor = new NicknameInterceptor(); + myInterceptorRegistry.registerInterceptor(myNicknameInterceptor); + } @AfterEach public void resetMdmSettings() { myMdmSettings.setCandidateSearchLimit(MdmSettings.DEFAULT_CANDIDATE_SEARCH_LIMIT); + myInterceptorRegistry.unregisterInterceptor(myNicknameInterceptor); } @Test @@ -43,6 +60,42 @@ public class MdmCandidateSearchSvcIT extends BaseMdmR4Test { assertEquals(1, result.size()); } + @Test + public void testNickname() { + Practitioner formal = new Practitioner(); + formal.getNameFirstRep().addGiven("William"); + formal.getNameFirstRep().setFamily("Shatner"); + formal.setActive(true); + myPractitionerDao.create(formal); + + { + // First confirm we can search for this practitioner using a nickname search + SearchParameterMap map = myMatchUrlService.getResourceSearch("Practitioner?given:nickname=Bill&family=Shatner").getSearchParameterMap(); + map.setLoadSynchronous(true); + IBundleProvider result = myPractitionerDao.search(map); + assertEquals(1, result.size()); + Practitioner first = (Practitioner) result.getResources(0, 1).get(0); + assertEquals("William", first.getNameFirstRep().getGivenAsSingleString()); + } + + { + // Now achieve the same match via mdm + Practitioner nick = new Practitioner(); + nick.getNameFirstRep().addGiven("Bill"); + nick.getNameFirstRep().setFamily("Shatner"); + Collection result = myMdmCandidateSearchSvc.findCandidates("Practitioner", nick, RequestPartitionId.allPartitions()); + assertEquals(1, result.size()); + } + + { + // Should not match Bob + Practitioner noMatch = new Practitioner(); + noMatch.getNameFirstRep().addGiven("Bob"); + noMatch.getNameFirstRep().setFamily("Shatner"); + Collection result = myMdmCandidateSearchSvc.findCandidates("Practitioner", noMatch, RequestPartitionId.allPartitions()); + assertEquals(0, result.size()); + } + } @Test public void findCandidatesMultipleMatchesDoNotCauseDuplicates() { @@ -83,9 +136,9 @@ public class MdmCandidateSearchSvcIT extends BaseMdmR4Test { Patient newJane = buildJanePatient(); createActivePatient(); - assertEquals(1, runInTransaction(()->myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size())); + assertEquals(1, runInTransaction(() -> myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size())); createActivePatient(); - assertEquals(2, runInTransaction(()->myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size())); + assertEquals(2, runInTransaction(() -> myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size())); try { createActivePatient(); diff --git a/hapi-fhir-jpaserver-mdm/src/test/resources/mdm/mdm-rules.json b/hapi-fhir-jpaserver-mdm/src/test/resources/mdm/mdm-rules.json index 15ffb644d5e..5c0f391828c 100644 --- a/hapi-fhir-jpaserver-mdm/src/test/resources/mdm/mdm-rules.json +++ b/hapi-fhir-jpaserver-mdm/src/test/resources/mdm/mdm-rules.json @@ -25,6 +25,13 @@ "searchParams": [ "general-practitioner" ] + }, + { + "resourceType": "Practitioner", + "searchParams": [ + "given:nickname", + "family" + ] } ], "candidateFilterSearchParams": [ diff --git a/hapi-fhir-jpaserver-mdm/src/test/resources/mdm/nickname-mdm-rules.json b/hapi-fhir-jpaserver-mdm/src/test/resources/mdm/nickname-mdm-rules.json new file mode 100644 index 00000000000..5685dcde02a --- /dev/null +++ b/hapi-fhir-jpaserver-mdm/src/test/resources/mdm/nickname-mdm-rules.json @@ -0,0 +1,44 @@ +{ + "version":"1", + "mdmTypes": ["Patient", "Practitioner"], + "candidateSearchParams":[ + { + "resourceType": "*", + "searchParams": [ + "given:nickname", + "family" + ] + } + ], + "candidateFilterSearchParams":[], + "matchFields":[ + { + "name":"gender", + "resourceType":"Patient", + "resourcePath":"gender", + "matcher":{ + "algorithm":"STRING" + } + }, + { + "name":"nickname", + "resourceType":"*", + "resourcePath":"name.given", + "matcher":{ + "algorithm":"NICKNAME" + } + }, + { + "name":"lastname", + "resourceType":"*", + "resourcePath":"name.family", + "matcher":{ + "algorithm":"STRING", + "exact": true + } + } + ], + "matchResultMap":{ + "nickname,lastname": "MATCH" + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameInterceptor.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameInterceptor.java new file mode 100644 index 00000000000..b118286e856 --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameInterceptor.java @@ -0,0 +1,67 @@ +package ca.uhn.fhir.jpa.searchparam.nickname; + +import ca.uhn.fhir.interceptor.api.Hook; +import ca.uhn.fhir.interceptor.api.Pointcut; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.model.api.IQueryParameterType; +import ca.uhn.fhir.rest.param.StringParam; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +public class NicknameInterceptor { + private static final Logger ourLog = LoggerFactory.getLogger(NicknameInterceptor.class); + + private final NicknameSvc myNicknameSvc; + + public NicknameInterceptor() throws IOException { + myNicknameSvc = new NicknameSvc(); + } + + @Hook(Pointcut.STORAGE_PRESEARCH_REGISTERED) + public void expandNicknames(SearchParameterMap theSearchParameterMap) { + for (Map.Entry>> set : theSearchParameterMap.entrySet()) { + String paramName = set.getKey(); + List> andList = set.getValue(); + for (List orList : andList) { + // here we will know if it's an _id param or not + // from theSearchParameterMap.keySet() + expandAnyNicknameParameters(paramName, orList); + } + } + } + + /** + * If a Parameter is a string parameter, and it has been set to expand Nicknames, perform the expansion. + */ + private void expandAnyNicknameParameters(String theParamName, List orList) { + List toAdd = new ArrayList<>(); + List toRemove = new ArrayList<>(); + for (IQueryParameterType iQueryParameterType : orList) { + if (iQueryParameterType instanceof StringParam) { + StringParam stringParam = (StringParam) iQueryParameterType; + if (stringParam.isNicknameExpand()) { + ourLog.debug("Found a nickname parameter to expand: {} {}", theParamName, stringParam); + toRemove.add(stringParam); + //First, attempt to expand as a formal name + String name = stringParam.getValue().toLowerCase(Locale.ROOT); + List expansions = myNicknameSvc.getEquivalentNames(name); + if (expansions == null) { + continue; + } + ourLog.debug("Parameter has been expanded to: {} {}", theParamName, String.join(", ", expansions)); + expansions.stream() + .map(StringParam::new) + .forEach(toAdd::add); + } + } + } + orList.removeAll(toRemove); + orList.addAll(toAdd); + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameMap.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameMap.java new file mode 100644 index 00000000000..017442ca6b1 --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameMap.java @@ -0,0 +1,47 @@ +package ca.uhn.fhir.jpa.searchparam.nickname; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +class NicknameMap { + private final Map> myFormalToNick = new HashMap<>(); + private final Map> myNicknameToFormal = new HashMap<>(); + + void load(Reader theReader) throws IOException { + try (BufferedReader reader = new BufferedReader(theReader)) { + String line; + while ((line = reader.readLine()) != null) { + String[] parts = line.split(","); + String key = parts[0]; + List values = new ArrayList<>(Arrays.asList(parts).subList(1, parts.length)); + add(key, values); + } + } + } + + private void add(String theKey, List theValues) { + myFormalToNick.put(theKey, theValues); + for (String value : theValues) { + myNicknameToFormal.putIfAbsent(value, new ArrayList<>()); + myNicknameToFormal.get(value).add(theKey); + } + } + + int size() { + return myFormalToNick.size(); + } + + List getNicknamesFromFormalNameOrNull(String theName) { + return myFormalToNick.get(theName); + } + + List getFormalNamesFromNicknameOrNull(String theNickname) { + return myNicknameToFormal.get(theNickname); + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameSvc.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameSvc.java new file mode 100644 index 00000000000..193b42f7fe7 --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameSvc.java @@ -0,0 +1,53 @@ +package ca.uhn.fhir.jpa.searchparam.nickname; + +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; + +public class NicknameSvc { + private final NicknameMap myNicknameMap = new NicknameMap(); + + public NicknameSvc() throws IOException { + Resource nicknameCsvResource = new ClassPathResource("/nickname/names.csv"); + try (InputStream inputStream = nicknameCsvResource.getInputStream()) { + try (Reader reader = new InputStreamReader(inputStream)) { + myNicknameMap.load(reader); + } + } + } + + public int size() { + return myNicknameMap.size(); + } + + public List getEquivalentNames(String theName) { + List retval = new ArrayList<>(); + retval.add(theName); + + List expansions; + expansions = getNicknamesFromFormalNameOrNull(theName); + if (expansions != null) { + retval.addAll(expansions); + } else { + expansions = getFormalNamesFromNicknameOrNull(theName); + if (expansions != null) { + retval.addAll(expansions); + } + } + return retval; + } + + List getNicknamesFromFormalNameOrNull(String theName) { + return myNicknameMap.getNicknamesFromFormalNameOrNull(theName); + } + + List getFormalNamesFromNicknameOrNull(String theNickname) { + return myNicknameMap.getFormalNamesFromNicknameOrNull(theNickname); + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/License.txt b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/License.txt new file mode 100644 index 00000000000..8dada3edaf5 --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/License.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/README.md b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/README.md new file mode 100644 index 00000000000..863d66d776b --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/README.md @@ -0,0 +1,12 @@ +# nickname-and-diminutive-names-lookup + +A simple CSV file containing US given names (first name) and their associated nicknames or diminutive names. + +This lookup file was initially created by mining this +genealogy page. Because the lookup originates from a dataset used for genealogy purposes there are old names that aren't commonly used these days, but there are recent ones as well. Examples are "gregory", "greg", or "geoffrey", "geoff". There was also a significant effort to make it machine readable, i.e. separate it with commas, remove human conventions, like "rickie(y)" would need to be made into two different names "rickie", and "ricky". + +There are Java, Perl, Python, and R parsers provided for convenience. + +This is a relatively large list with roughly 1600 names. Any help from people to clean this list up and add to it is greatly appreciated. + +This project was created by Old Dominion University - Web Science and Digital Libraries Research Group. More information about the creation of this lookup can be found here. diff --git a/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/README.txt b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/README.txt new file mode 100644 index 00000000000..24d522ebdda --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/README.txt @@ -0,0 +1,2 @@ +The files in this folder were cloned from https://github.com/carltonnorthern/nickname-and-diminutive-names-lookup + diff --git a/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/names.csv b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/names.csv new file mode 100644 index 00000000000..76728850a12 --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/main/resources/nickname/names.csv @@ -0,0 +1,1084 @@ +aaron,erin,ronnie,ron +abbigail,nabby,abby,gail,abbi,abbey +abednego,bedney +abel,ebbie,ab,abe,eb +abiel,ab +abigail,nabby,abby,gail +abijah,ab,bige +abner,ab +abraham,ab,abe +abram,ab,abe +absalom,app,ab,abbie +ada,addy +adaline,delia,lena,dell,addy,ada +addison,addie,addy +adela,della +adelaide,heidi,adele,dell,addy,della +adelbert,del,albert,delbert,bert +adele,addy,dell +adeline,delia,lena,dell,addy,ada +adelphia,philly,delphia,adele,dell,addy +adolphus,dolph,ado,adolph +adrian,rian +adriane,riane +adrienne,addie,rienne,enne +agatha,aggy +agnes,inez,aggy,nessa +aileen,lena,allie +alan,al +alanson,al,lanson +alastair,al +alazama,ali +albert,bert,al +alberta,bert,allie,bertie +aldo,al +aldrich,riche,rich +aleksandr,alex,alek +aleva,levy,leve +alex,al +alexander,alex,al,sandy,alec +alexandra,alex,sandy,alla,sandra +alexandria,drina,alexander,alla,sandra +alexis,lexi +alfonse,al +alfred,freddy,al,fred +alfreda,freddy,alfy,freda,frieda +algernon,algy +alice,lisa,elsie,allie +alicia,lisa,elsie,allie +aline,adeline +alison,ali,allie +alixandra,alix +allan,al +allen,al +allisandra,allie +allison,ali,allie +allyson,ally,allie +allyssa,ally,allie +almena,mena,allie +almina,minnie +almira,myra +alonzo,lon,al,lonzo +alphinias,alphus +althea,ally +alverta,virdie,vert +alyssa,lissia,al,ally +alzada,zada +amanda,mandy,manda +ambrose,brose +amelia,amy,mel,millie,emily +amos,moses +anastasia,ana,stacy +anderson,andy +andre,drea +andrea,drea,rea,andrew +andrew,andy,drew +andriane,ada,adri,rienne +angela,angel,angie +angelica,angie,angel +angelina,angel,angie,lina +ann,annie,nan +anna,anne,ann,annie,nan +anne,annie,ann,nan +annette,anna,nettie +annie,ann,anna +anselm,ansel,selma,anse,ance +anthony,ant,tony +antoinette,tony,netta,ann +antonia,tony,netta,ann +antonio,ant,tony +appoline,appy,appie +aquilla,quil,quillie +ara,belle,arry +arabella,ara,bella,arry,belle +arabelle,ara,bella,arry,belle +araminta,armida,middie,ruminta,minty +archibald,archie +archilles,kill,killis +ariadne,arie,ari +arielle,arie +aristotle,telly +arizona,onie,ona +arlene,arly,lena +armanda,mandy +armena,mena,arry +armilda,milly +arminda,mindie +arminta,minite,minnie +arnold,arnie +aron,erin,ronnie,ron +artelepsa,epsey +artemus,art +arthur,art +arthusa,thursa +arzada,zaddi +asahel,asa +asaph,asa +asenath,sene,assene,natty +ashley,ash,leah,lee +aubrey,bree +audrey,dee +august,gus +augusta,tina,aggy,gatsy,gussie +augustina,tina,aggy,gatsy,gussie +augustine,gus,austin,august +augustus,gus,austin,august +aurelia,ree,rilly,orilla,aurilla,ora +avarilla,rilla +azariah,riah,aze +bab,barby +babs,barby,barbara,bab +barbara,barby,babs,bab,bobbie +barbery,barbara +barbie,barbara +barnabas,barney +barney,barnabas +bart,bartholomew +bartholomew,bartel,bat,meus,bart,mees +barticus,bart +bazaleel,basil +bea,beatrice +beatrice,bea,trisha,trixie,trix +becca,beck +beck,becky +bedelia,delia,bridgit +belinda,belle,linda +bella,belle,arabella,isabella +benedict,bennie,ben +benjamin,benjy,jamie,bennie,ben,benny +benjy,benjamin +bernard,barney,bernie,berney +berney,bernie +bert,bertie,bob,bobby +bertha,bert,birdie,bertie +bertram,bert +bess,bessie +beth,betsy,betty,elizabeth +bethena,beth,thaney +beverly,bev +bezaleel,zeely +biddie,biddy +bill,william,billy,robert,willie,fred +billy,william,robert,fred +blanche,bea +bob,rob,robert +bobby,rob,bob +boetius,bo +brad,bradford,ford +bradford,ford,brad +bradley,brad +brady,brody +breanna,bree,bri +breeanna,bree +brenda,brandy +brian,bryan,bryant +brianna,bri +bridget,bridie,biddy,bridgie,biddie +brittany,britt +brittney,britt +broderick,ricky,brody,brady,rick +caitlin,cait,caity +caitlyn,cait,caity +caldonia,calliedona +caleb,cal +california,callie +calista,kissy +calpurnia,cally +calvin,vin,vinny,cal +cameron,ron,cam,ronny +camille,millie,cammie +campbell,cam +candace,candy,dacey +carlotta,lottie +carlton,carl +carmellia,mellia +carmelo,melo +carmon,charm,cammie,carm +carol,lynn,carrie,carolann,cassie,caroline,carole +carolann,carol,carole +caroline,lynn,carol,carrie,cassie,carole +carolyn,lynn,carrie,cassie +carrie,cassie +carthaette,etta,etty +casey,k.c. +casper,jasper +cassandra,sandy,cassie,sandra +cassidy,cassie,cass +caswell,cass +catherine,kathy,katy,lena,kittie,kit,trina,cathy,kay,cassie +cathleen,kathy,katy,lena,kittie,kit,trina,cathy,kay,cassie +cathy,kathy,cathleen,catherine +cecilia,cissy,celia +cedric,ced,rick,ricky +celeste,lessie,celia +celinda,linda,lynn,lindy +charity,chat +charles,charlie,chuck,carl,chick +charlie,charles,chuck +charlotte,char,sherry,lottie,lotta +chauncey,chan +cheryl,cher +chesley,chet +chester,chet +chet,chester +chick,charlotte,caroline,chuck +chloe,clo +chris,christina,christopher,christine +christa,chris +christian,chris,kit +christiana,kris,kristy,ann,tina,christy,chris,crissy +christiano,chris +christina,kris,kristy,tina,christy,chris,crissy +christine,kris,kristy,chrissy,tina,chris,crissy +christoph,chris +christopher,chris,kit +christy,crissy +cicely,cilla +cinderella,arilla,rella,cindy,rilla +cindy,cinderella +claire,clair,clare,clara +clara,clarissa +clare,clara +clarence,clare,clair +clarinda,clara +clarissa,cissy,clara +claudia,claud +cleatus,cleat +clement,clem +clementine,clement,clem +cliff,clifford,cliff +clifford,ford,cliff +clifton,tony,cliff +cole,colie +columbus,clum +con,conny +conrad,conny,con +constance,connie +cordelia,cordy,delia +corey,coco,cordy,ree +corinne,cora,ora +cornelia,nelly,cornie,nelia,corny,nelle +cornelius,conny,niel,corny,con +cory,coco,cordy,ree +courtney,curt,court +crystal,chris,tal,stal,crys +curtis,curt +cynthia,cintha,cindy +cyrenius,swene,cy,serene,renius,cene +cyrus,cy +dahl,dal +dalton,dahl,dal +daniel,dan,danny,dann +danielle,ellie,dani +danny,daniel +daphne,daph,daphie +darlene,lena,darry +david,dave,day,davey +deanne,ann,dee +debbie,deb,debra,deborah,debby +debby,deb +debora,deb,debbie,debby +deborah,deb,debbie,debby +debra,deb,debbie +deidre,deedee +delbert,bert,del +delia,fidelia,cordelia,delius +delilah,lil,lila,dell,della +deliverance,delly,dilly,della +della,adela,delilah,adelaide,dell +delores,lolly,lola,della,dee,dell +delpha,philadelphia +delphine,delphi,del,delf +demaris,dea,maris,mary +demerias,dea,maris,mary +democrates,mock +dennis,denny +dennison,denny +derrick,ricky,eric,rick +deuteronomy,duty +diana,dicey,didi,di +diane,dicey,didi,di +dicey,dicie +dick,rick,richard +dickson,dick +domenic,dom +dominic,dom +dominick,dom +donald,dony,donnie,don,donny +donovan,dony,donnie,don,donny +dorcus,darkey +dorinda,dorothea,dora +doris,dora +dorothea,doda,dora +dorothy,dortha,dolly,dot,dotty +dotha,dotty +dotty,dot +douglas,doug +drusilla,silla +duncan,dunk +earnest,ernestine,ernie +ebbie,eb +ebenezer,ebbie,eben,eb +eddie,ed +eddy,ed +edgar,ed,eddie,eddy +edith,edie,edye +edmond,ed,eddie,eddy +edmund,ed,eddie,ted,eddy,ned +edna,edny +eduardo,ed,eddie,eddy +edward,teddy,ed,ned,ted,eddy,eddie +edwin,ed,eddie,win,eddy,ned +edwina,edwin +edyth,edie,edye +edythe,edie,edye +egbert,bert,burt +eighta,athy +eileen,helen +elaine,lainie,helen +elbert,albert +elbertson,elbert,bert +eleanor,lanna,nora,nelly,ellie,elaine,ellen,lenora +eleazer,lazar +elena,helen +elias,eli,lee,lias +elijah,lige,eli +eliphalel,life +eliphalet,left +elisa,lisa +elisha,lish,eli +eliza,elizabeth +elizabeth,libby,lisa,lib,lizzy,lizzie,eliza,betsy,liza,betty,bessie,bess,beth,liz +ella,ellen +ellen,nellie,nell,helen +ellender,nellie,ellen,helen +ellie,elly +ellswood,elsey +elminie,minnie +elmira,ellie,elly,mira +elnora,nora +eloise,heloise,louise +elouise,louise +elsie,elsey +elswood,elsey +elvira,elvie +elwood,woody +elysia,lisa +elze,elsey +emanuel,manuel,manny +emeline,em,emmy,emma,milly,emily +emil,emily +emily,emmy,millie,emma,mel +emma,emmy +epaphroditius,dite,ditus,eppa,dyche,dyce +ephraim,eph +erasmus,raze,rasmus +eric,rick,ricky +ernest,ernie +ernestine,teeny,ernest,tina,erna +erwin,irwin +eseneth,senie +essy,es +estella,essy,stella +estelle,essy,stella +esther,hester,essie +eudicy,dicey +eudora,dora +eudoris,dossie,dosie +eugene,gene +eunice,nicie +euphemia,effie,effy +eurydice,dicey +eustacia,stacia,stacy +eva,eve +evaline,eva,lena,eve +evangeline,ev,evan,vangie +evelyn,evelina,ev,eve +experience,exie +ezekiel,zeke,ez +ezideen,ez +ezra,ez +faith,fay +felicia,fel,felix,feli +felicity,flick,tick +feltie,felty +ferdinand,freddie,freddy,ferdie,fred +ferdinando,nando,ferdie,fred +fidelia,delia +flo,florence +flora,florence +florence,flossy,flora,flo +floyd,lloyd +fran,frannie +frances,sis,cissy,frankie,franniey,fran,francie,frannie,fanny +francie,francine +francine,franniey,fran,frannie,francie +francis,fran,frankie,frank +frank,franklin +frankie,frank,francis +franklin,fran,frank +franklind,frank +freda,frieda +frederica,frederick,freddy +frederick,freddie,freddy,fritz,fred +fredericka,freddy,ricka,freda,frieda +frieda,freddie,freddy,fred +gabriel,gabe,gabby +gabriella,ella,gabby +gabrielle,ella,gabby +garrick,garri +genevieve,jean,eve,jenny +geoffrey,geoff,jeff +george,georgie +georgiana,georgia +gerald,gerry,jerry +geraldine,gerry,gerrie,jerry,dina +gerhardt,gay +gertie,gertrude,gert +gertrude,gertie,gert,trudy +gilbert,bert,gil,wilber +giovanni,gio +gloria,glory +governor,govie +greenberry,green,berry +greggory,gregg +gregory,greg,gory +gretchen,margaret +griselda,grissel +gum,monty +gus,gussie +gustavus,gus,gussie +gwen,wendy +gwendolyn,gwen,wendy +hamilton,ham +hannah,nan,nanny,anna +harold,hal,harry +harriet,hattie +harry,harold,henry +haseltine,hassie +heather,hetty +helen,lena,ella,ellen,ellie +helena,eileen,lena,nell,nellie,eleanor,elaine,ellen,aileen +helene,lena,ella,ellen,ellie +heloise,lois,eloise,elouise +henrietta,hank,etta,etty,retta,nettie +henry,hank,hal,harry +hephsibah,hipsie +hepsibah,hipsie +herbert,bert,herb +herman,harman,dutch +hermione,hermie +hester,hessy,esther,hetty +hezekiah,hy,hez,kiah +hiram,hy +honora,honey,nora,norry,norah +hopkins,hopp,hop +horace,horry +hortense,harty,tensey +hosea,hosey,hosie +howard,hal,howie +hubert,bert,hugh,hub +ian,john +ignatius,natius,iggy,nate,nace +ignatzio,naz,iggy,nace +immanuel,manuel,emmanuel +india,indie,indy +inez,agnes +iona,onnie +irene,rena +irvin,irving +irving,irv +irwin,erwin +isaac,ike,zeke +isabel,tibbie,bell,nib,belle,bella,nibby,ib,issy +isabella,tibbie,nib,belle,bella,nibby,ib,issy +isabelle,tibbie,nib,belle,bella,nibby,ib,issy +isadora,issy,dora +isaiah,zadie,zay +isidore,izzy +iva,ivy +ivan,john +jackson,jack +jacob,jaap,jake,jay +jacobus,jacob +jacqueline,jackie,jack +jahoda,hody,hodie,hoda +jakob,jake +james,jimmy,jim,jamie,jimmie,jem +jamie,james +jane,janie,jessie,jean,jennie +janet,jan,jessie +janice,jan +jannett,nettie +jasper,jap,casper +jayme,jay +jean,jane,jeannie +jeanette,jessie,jean,janet,nettie +jeanne,jane,jeannie +jebadiah,jeb +jedediah,dyer,jed,diah +jedidiah,dyer,jed,diah +jefferey,jeff +jefferson,sonny,jeff +jeffery,jeff +jeffrey,geoff,jeff +jehiel,hiel +jehu,hugh,gee +jemima,mima +jennet,jessie,jenny,jenn +jennifer,jennie,jenn,jen,jenny +jeremiah,jereme,jerry +jeremy,jezza,jez +jerita,rita +jerry,jereme,geraldine +jessica,jessie +jessie,jane,jess,janet +jim,jimmie +jincy,jane +jinsy,jane +joan,jo,nonie +joann,jo +joanna,hannah,jody,jo,joan +joanne,jo +jody,jo +joe,joey +johanna,jo +johannah,hannah,jody,joan,nonie +johannes,jonathan,john,johnny +john,jack,johnny,jock,ian +jonathan,john,nathan,jon,jonny,jonnie +jonathon,jon,jonny,jonnie +joseph,jody,jos,joe,joey +josephine,fina,jody,jo,josey,joey,josie +josetta,jettie +josey,josophine +joshua,jos,josh +josiah,jos +joyce,joy +juanita,nita,nettie +judah,juder,jude +judith,judie,juda,judy,judi,jude +judson,sonny,jud +judy,judith +julia,julie,jill +julian,jule +julias,jule +julie,julia,jule +june,junius +junior,junie,june,jr +justin,justus,justina +kaitlin,kait,kaitie +kaitlyn,kait,kaitie +kaitlynn,kait,kaitie +kameron,kam +karonhappuck,karon,karen,carrie,happy +kasey,k.c. +katarina,catherine,tina +kate,kay +katelin,kay,kate,kaye +katelyn,kay,kate,kaye +katherine,kathy,katy,lena,kittie,kaye,kit,trina,cathy,kay,kate,cassie +kathleen,kathy,katy,lena,kittie,kit,trina,cathy,kay,cassie +kathryn,kathy,katie +katy,kathy,katie +kayla,kay +kendall,ken,kenny +kendra,kenj,kenji,kay,kenny +kendrick,ken,kenny +kendrik,ken,kenny +kenneth,ken,kenny,kendrick +kenny,ken,kenneth +kent,ken,kenny,kendrick +keziah,kizza,kizzie +kim,kimberly,kimberley +kimberley,kim +kimberly,kim +kingsley,king +kingston,king +kit,kittie +kris,chris +kristel,kris +kristen,chris +kristin,chris +kristine,kris,kristy,tina,christy,chris,crissy +kristopher,chris,kris +kristy,chris +lafayette,laffie,fate +lamont,monty +laodicia,dicy,cenia +larry,laurence,lawrence +lauren,ren,laurie +laurence,lorry,larry,lon,lonny,lorne +laurinda,laura,lawrence +lauryn,laurie +laveda,veda +laverne,vernon,verna +lavina,vina,viney,ina +lavinia,vina,viney,ina +lavonia,vina,vonnie,wyncha,viney +lavonne,von +lawrence,lorry,larry,lon,lonny,lorne +leanne,lea,annie +lecurgus,curg +lemuel,lem +lena,ellen +lenora,nora,lee +leo,leon +leonard,lineau,leo,leon,len,lenny +leonidas,lee,leon +leonora,nora,nell,nellie +leonore,nora,honor,elenor +leroy,roy,lee,l.r. +leslie,les +lester,les +letitia,tish,titia,lettice,lettie +levi,lee +levicy,vicy +levone,von +lib,libby +lidia,lyddy +lil,lilly,lily +lillah,lil,lilly,lily,lolly +lillian,lil,lilly,lolly +lilly,lily,lil +lincoln,link +linda,lindy,lynn +lindy,lynn +lionel,leon +lisa,liz +littleberry,little,berry,l.b. +lizzie,liz +lois,lou,louise +lonzo,lon +lorenzo,loren +loretta,etta,lorrie,retta +lorraine,lorrie +lotta,lottie +lou,louis,lu +louis,lewis,louise,louie,lou +louisa,eliza,lou,lois +louise,eliza,lou,lois +louvinia,vina,vonnie,wyncha,viney +lucas,luke +lucia,lucy,lucius +lucias,luke +lucille,cille,lu,lucy,lou +lucina,sinah +lucinda,lu,lucy,cindy,lou +lucretia,creasey +lucy,lucinda +luella,lula,ella,lu +luke,lucas +lunetta,nettie +lurana,lura +luther,luke +lydia,lyddy +lyndon,lindy,lynn +mabel,mehitabel,amabel +mac,mc +mack,mac,mc +mackenzie,kenzy,mac,mack +maddison,maddie,maddi +maddy,madelyn,madeline,madge +madeline,maggie,lena,magda,maddy,madge +madeline,maddie,maddi +madie,madeline,madelyn +madison,mattie,maddy +maegen,meg +magdalena,maggie,lena +magdelina,lena,magda,madge +mahala,hallie +makayla,kayla +malachi,mally +malcolm,mac,mal,malc +malinda,lindy +manda,mandy +mandie,amanda +mandy,amanda +manerva,minerva,nervie,eve,nerva +manny,manuel +manoah,noah +manola,nonnie +manuel,emanuel,manny +marcus,mark +margaret,maggie,meg,peg,midge,margy,margie,madge,peggy,maggy,marge,daisy,margery,gretta,rita +margaretta,maggie,meg,peg,midge,margie,madge,peggy,marge,daisy,margery,gretta,rita +margarita,maggie,meg,metta,midge,greta,megan,maisie,madge,marge,daisy,peggie,rita,margo +marge,margery,margaret,margaretta +margie,marjorie,margie +marguerite,peggy +mariah,mary,maria +marian,marianna,marion +marie,mae +marietta,mariah,mercy,polly,may,molly,mitzi,minnie,mollie,mae,maureen,marion,marie,mamie,mary,maria +marilyn,mary +marion,mary +marissa,rissa +marjorie,margie +marjorie,margy,margie +marsha,marcie,mary +martha,marty,mattie,mat,patsy,patty +martin,marty +martina,tina +martine,tine +marv,marvin +marvin,marv +mary,mamie,molly,mae,polly,mitzi +masayuki,masa +mat,mattie +mathew,mat,maty +mathilda,tillie,patty +matilda,tilly,maud,matty +matthew,thys,matt,thias,mattie,matty +matthias,thys,matt,thias +maud,middy +maureen,mary +maurice,morey +mavery,mave +mavine,mave +maximillian,max +maxine,max +maxwell,max +may,mae +mckenna,ken,kenna,meaka +medora,dora +megan,meg +meghan,meg +mehitabel,hetty,mitty,mabel,hitty +melanie,mellie +melchizedek,zadock,dick +melinda,linda,mel,lynn,mindy,lindy +melissa,lisa,mel,missy,milly,lissa +mellony,mellia +melody,lodi +melvin,mel +melvina,vina +mercedes,merci,sadie,mercy +merv,mervin +mervyn,merv +micajah,cage +michael,micky,mike,micah,mick,mikey +micheal,mike,miky,mikey +michelle,mickey +mick,micky +mike,micky,mick,michael +mildred,milly +millicent,missy,milly +minerva,minnie +minnie,wilhelmina +miranda,randy,mandy,mira +miriam,mimi,mitzi,mitzie +missy,melissa +mitch,mitchell +mitchell,mitch +mitzi,mary,mittie,mitty +mitzie,mittie,mitty +monet,nettie +monica,monna,monnie +monteleon,monte +montesque,monty +montgomery,monty,gum +monty,lamont +morris,morey +mortimer,mort +moses,amos,mose,moss +muriel,mur +myrtle,myrt,myrti,mert +nadine,nada,deedee +nancy,ann,nan,nanny +naomi,omi +napoleon,nap,nappy,leon +natalie,natty,nettie +natasha,tasha,nat +nathan,nate,nat +nathaniel,than,nathan,nate,nat,natty +nelle,nelly +nelson,nels +newt,newton +nicholas,nick,claes,claas,nic,nicky,nico,nickie +nicodemus,nick,nic,nicky,nico,nickie +nicole,nole,nikki,cole +nikolas,nick,claes,nic,nicky,nico,nickie +nikole,nikki +nora,nonie +norbert,bert,norby +norbusamte,norbu +nowell,noel +obadiah,dyer,obed,obie,diah +obedience,obed,beda,beedy,biddie +obie,obediah +octavia,tave,tavia +odell,odo +olive,nollie,livia,ollie +oliver,ollie +olivia,nollie,livia,ollie +ollie,oliver +onicyphorous,cyphorus,osaforus,syphorous,one,cy,osaforum +orilla,rilly,ora +orlando,roland +orphelia,phelia +ossy,ozzy +oswald,ozzy,waldo,ossy +otis,ode,ote +pamela,pam +pandora,dora +parmelia,amelia,milly,melia +parthenia,teeny,parsuny,pasoonie,phenie +patience,pat,patty +patricia,tricia,pat,patsy,patty,patti +patrick,pate,peter,pat,patsy,paddy +patsy,patty +patty,patricia +paul,polly +paula,polly,lina +paulina,polly,lina +pauline,polly +peggy,peg +pelegrine,perry +penelope,penny +percival,percy +peregrine,perry +permelia,melly,milly,mellie +pernetta,nettie +persephone,seph,sephy +peter,pete,pate +petronella,nellie +pheney,josephine +pheriba,pherbia,ferbie +philadelphia,delphia +philander,fie +philetus,leet,phil +philinda,linda,lynn,lindy +philip,phil +philipina,phoebe,penie +phillip,phil +philly,delphia +philomena,menaalmena +phoebe,fifi +pinckney,pink +pleasant,ples +pocahontas,pokey +posthuma,humey +prescott,scotty,scott,pres +priscilla,prissy,cissy,cilla +providence,provy +prudence,prue,prudy +prudy,prudence +rachel,shelly +rafaela,rafa +ramona,mona +randolph,dolph,randy +raphael,ralph +ray,raymond +raymond,ray +reba,beck,becca +rebecca,beck,becca,reba,becky +reggie,reginald,reg +regina,reggie,gina +reginald,reggie,naldo,reg,renny +relief,leafa +reuben,rube +reynold,reginald +rhoda,rodie +rhodella,della +rhyna,rhynie +ricardo,rick,ricky +rich,dick,rick +richard,dick,dickon,dickie,dicky,rick,rich,ricky,richie +rick,ricky +ricky,dick,rich +robert,hob,hobkin,dob,rob,bobby,dobbin,bob +roberta,robbie,bert,bobbie,birdie,bertie +roderick,rod,erick,rickie,roddy +rodger,roge,bobby,hodge,rod,robby,rupert,robin +rodney,rod +roger,roge,bobby,hodge,rod,robby,rupert,robin +roland,rollo,lanny,orlando,rolly +ron,ronnie,ronny +ronald,naldo,ron,ronny,ronnie +ronny,ronald +rosa,rose +rosabel,belle,roz,rosa,rose +rosabella,belle,roz,rosa,rose +rosalinda,linda,roz,rosa,rose +rosalyn,linda,roz,rosa,rose +roscoe,ross +rose,rosie +roseann,rose,ann,rosie,roz +roseanna,rose,ann,rosie,roz +roseanne,ann +rosina,sina +roxane,rox,roxie +roxanna,roxie,rose,ann +roxanne,roxie,rose,ann +rudolph,dolph,rudy,olph,rolf +rudolphus,dolph,rudy,olph,rolf +russell,russ,rusty +ryan,ry +sabrina,brina +safieel,safie +salome,loomie +salvador,sal +samantha,sammy,sam,mantha +sammy,samuel +sampson,sam +samson,sam +samuel,sammy,sam +samyra,myra +sandra,sandy,cassandra +sandy,sandra +sanford,sandy +sarah,sally,sadie +sarilla,silla +savannah,vannie,anna +scott,scotty,sceeter,squat,scottie +sebastian,sebby,seb +selma,anselm +serena,rena +serilla,rilla +seymour,see,morey +shaina,sha,shay +sharon,sha,shay +sheila,cecilia +sheldon,shelly +shelton,tony,shel,shelly +sheridan,dan,danny,sher +sheryl,sher +shirley,sherry,lee,shirl +sibbilla,sybill,sibbie,sibbell +sidney,syd,sid +sigfired,sid +sigfrid,sid +sigismund,sig +silas,si +silence,liley +silvester,vester,si,sly,vest,syl +simeon,si,sion +simon,si,sion +smith,smitty +socrates,crate +solomon,sal,salmon,sol,solly,saul,zolly +sondra,dre,sonnie +sophia,sophie +sophronia,frona,sophia,fronia +stephan,steve +stephanie,stephen,stephie,annie,steph +stephen,steve,steph +steve,stevie +steven,steve,steph,stevie +stuart,stu +sue,susie,susan +sullivan,sully,van +sully,sullivan +susan,hannah,susie,sue,sukey,suzie +susannah,hannah,susie,sue,sukey +susie,suzie +suzanne,suki,sue,susie +sybill,sibbie +sydney,sid +sylvanus,sly,syl +sylvester,sy,sly,vet,syl,vester,si,vessie +tabby,tabitha +tabitha,tabby +tamarra,tammy +tanafra,tanny +tasha,tash,tashie +ted,teddy +temperance,tempy +terence,terry +teresa,terry +terry,terence +tess,teresa,theresa +tessa,teresa,theresa +thad,thaddeus +thaddeus,thad +theo,theodore +theodora,dora +theodore,theo,ted,teddy +theodosia,theo,dosia,theodosius +theophilus,ophi +theotha,otha +theresa,tessie,thirza,tessa,terry,tracy,tess,thursa +thom,thomas,tommy,tom +thomas,thom,tommy,tom +thomasa,tamzine +tiffany,tiff,tiffy +tilford,tillie +tim,timothy,timmy +timmy,timothy +timothy,tim,timmy +tina,christina +tobias,bias,toby +tom,thomas,tommy +tommy,thomas +tony,anthony +tranquilla,trannie,quilla +trisha,patricia +trix,trixie +trudy,gertrude +tryphena,phena +unice,eunice,nicie +uriah,riah +ursula,sulie,sula +valentina,felty,vallie,val +valentine,felty +valeri,val +valerie,val +vanburen,buren +vandalia,vannie +vanessa,essa,vanna,nessa +vernisee,nicey +veronica,vonnie,ron,ronna,ronie,frony,franky,ronnie +vic,vicki,vicky +vicki,vicky,victoria +vickie,victoria +vicky,victoria +victor,vic,vickie,vicky +victoria,torie,vic,vicki,tory,vicky +vijay,vij +vincent,vic,vince,vinnie,vin,vinny +vincenzo,vic,vinnie,vin,vinny,vince +vinson,vinny,vinnie,vin +viola,ola,vi +violetta,lettie +virginia,jane,jennie,ginny,virgy,ginger +vivian,vi,viv +waldo,ozzy,ossy +wallace,wally +wally,walt +walter,wally,walt +washington,wash +webster,webb +wendy,wen +wesley,wes +westley,west,wes,farmboy +wilber,will,bert +wilbur,willy,willie +wilda,willie +wilfred,will,willie,fred,wil +wilhelm,wil,willie +wilhelmina,mina,wilma,willie,minnie +will,bill,willie,wilbur,fred +william,willy,bell,bela,bill,will,billy,willie,wil +willie,william,fred +willis,willy,bill +wilma,william,billiewilhelm +wilson,will,willy,willie +winfield,field,winny,win +winifred,freddie,winnie,winnet +winnie,winnifred +winnifred,freddie,freddy,winny,winnie,fred +winny,winnifred +winton,wint +woodrow,woody,wood,drew +yeona,onie,ona +yoshihiko,yoshi +yulan,lan,yul +yvonne,vonna +zach,zachariah +zachariah,zachy,zach,zeke,zac,zack,zak,zakk +zachary,zachy,zach,zeke,zac,zack,zak,zakk +zachery,zachy,zach,zeke,zac,zack,zak,zakk +zebedee,zeb +zedediah,dyer,zed,diah +zephaniah,zeph diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameInterceptorTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameInterceptorTest.java new file mode 100644 index 00000000000..d41f1d1569a --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameInterceptorTest.java @@ -0,0 +1,59 @@ +package ca.uhn.fhir.jpa.searchparam.nickname; + +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.rest.param.StringParam; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class NicknameInterceptorTest { + @Test + public void testExpandForward() throws IOException { + // setup + String formalName = "kenneth"; + SearchParameterMap sp = new SearchParameterMap(); + sp.add("name", new StringParam(formalName).setNicknameExpand(true)); + NicknameInterceptor svc = new NicknameInterceptor(); + + // execute + svc.expandNicknames(sp); + + // verify + String newSearch = sp.toNormalizedQueryString(null); + assertEquals("?name=ken,kendrick,kenneth,kenny", newSearch); + } + + @Test + public void testExpandBackward() throws IOException { + // setup + String nickname = "ken"; + SearchParameterMap sp = new SearchParameterMap(); + sp.add("name", new StringParam(nickname).setNicknameExpand(true)); + NicknameInterceptor svc = new NicknameInterceptor(); + + // execute + svc.expandNicknames(sp); + + // verify + String newSearch = sp.toNormalizedQueryString(null); + assertEquals("?name=ken,kendall,kendrick,kendrik,kenneth,kenny,kent,mckenna", newSearch); + } + + @Test + public void testNothingToExpand() throws IOException { + // setup + String unusualName = "X Æ A-12"; + SearchParameterMap sp = new SearchParameterMap(); + sp.add("name", new StringParam(unusualName).setNicknameExpand(true)); + NicknameInterceptor svc = new NicknameInterceptor(); + + // execute + svc.expandNicknames(sp); + + // verify + String newSearch = sp.toNormalizedQueryString(null); + assertEquals("?name=x%20%C3%A6%20a-12", newSearch); + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameMapTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameMapTest.java new file mode 100644 index 00000000000..e57ea8c549a --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameMapTest.java @@ -0,0 +1,30 @@ +package ca.uhn.fhir.jpa.searchparam.nickname; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.StringReader; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; + +class NicknameMapTest { + @Test + public void testLoad() throws IOException { + String testData = """ +kendall,ken,kenny +kendra,kenj,kenji,kay,kenny +kendrick,ken,kenny +kendrik,ken,kenny +kenneth,ken,kenny,kendrick +kenny,ken,kenneth +kent,ken,kenny,kendrick + """; + NicknameMap map = new NicknameMap(); + map.load(new StringReader(testData)); + assertEquals(7, map.size()); + assertThat(map.getNicknamesFromFormalNameOrNull("kenneth"), containsInAnyOrder("ken", "kenny", "kendrick")); + assertThat(map.getFormalNamesFromNicknameOrNull("ken"), containsInAnyOrder("kendall", "kendrick", "kendrik", "kenneth", "kenny", "kent")); + } +} diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameSvcTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameSvcTest.java new file mode 100644 index 00000000000..80d24b88559 --- /dev/null +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/nickname/NicknameSvcTest.java @@ -0,0 +1,15 @@ +package ca.uhn.fhir.jpa.searchparam.nickname; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class NicknameSvcTest { + @Test + public void testReadfile() throws IOException { + NicknameSvc nicknameSvc = new NicknameSvc(); + assertEquals(1082, nicknameSvc.size()); + } +} diff --git a/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/provider/r4/NicknameSearchR4Test.java b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/provider/r4/NicknameSearchR4Test.java new file mode 100644 index 00000000000..6a3054c9e27 --- /dev/null +++ b/hapi-fhir-jpaserver-test-utilities/src/test/java/ca/uhn/fhir/jpa/provider/r4/NicknameSearchR4Test.java @@ -0,0 +1,57 @@ +package ca.uhn.fhir.jpa.provider.r4; + +import ca.uhn.fhir.jpa.searchparam.nickname.NicknameInterceptor; +import ca.uhn.fhir.util.BundleUtil; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class NicknameSearchR4Test extends BaseResourceProviderR4Test { + @Autowired + NicknameInterceptor myNicknameInterceptor; + + @Override + @AfterEach + public void after() throws Exception { + super.after(); + + myInterceptorRegistry.unregisterInterceptor(myNicknameInterceptor); + } + + @BeforeEach + @Override + public void before() throws Exception { + super.before(); + myInterceptorRegistry.registerInterceptor(myNicknameInterceptor); + } + + @Test + public void testExpandNickname() { + Patient patient1 = new Patient(); + patient1.getNameFirstRep().addGiven("ken"); + myClient.create().resource(patient1).execute(); + + Patient patient2 = new Patient(); + patient2.getNameFirstRep().addGiven("bob"); + myClient.create().resource(patient2).execute(); + + Bundle result = myClient + .loadPage() + .byUrl(ourServerBase + "/Patient?name:nickname=kenneth") + .andReturnBundle(Bundle.class) + .execute(); + + List resources = BundleUtil.toListOfResourcesOfType(myFhirContext,result, Patient.class); + assertThat(resources, hasSize(1)); + assertEquals("ken", resources.get(0).getNameFirstRep().getGivenAsSingleString()); + } +} diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/config/MdmRuleValidator.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/config/MdmRuleValidator.java index 75f11d366a3..0e2d2b3d31e 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/config/MdmRuleValidator.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/config/MdmRuleValidator.java @@ -20,14 +20,14 @@ package ca.uhn.fhir.mdm.rules.config; * #L% */ -import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.fhirpath.IFhirPath; -import ca.uhn.fhir.mdm.api.MdmConstants; +import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.mdm.api.IMdmRuleValidator; +import ca.uhn.fhir.mdm.api.MdmConstants; import ca.uhn.fhir.mdm.rules.json.MdmFieldMatchJson; import ca.uhn.fhir.mdm.rules.json.MdmFilterSearchParamJson; import ca.uhn.fhir.mdm.rules.json.MdmResourceSearchParamJson; @@ -36,6 +36,7 @@ import ca.uhn.fhir.mdm.rules.json.MdmSimilarityJson; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.server.util.ISearchParamRegistry; import ca.uhn.fhir.util.FhirTerser; +import ca.uhn.fhir.util.SearchParameterUtil; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -150,7 +151,8 @@ public class MdmRuleValidator implements IMdmRuleValidator { } private void validateResourceSearchParam(String theFieldName, String theResourceType, String theSearchParam) { - if (mySearchParamRetriever.getActiveSearchParam(theResourceType, theSearchParam) == null) { + String searchParam = SearchParameterUtil.stripModifier(theSearchParam); + if (mySearchParamRetriever.getActiveSearchParam(theResourceType, searchParam) == null) { throw new ConfigurationException(Msg.code(1511) + "Error in " + theFieldName + ": " + theResourceType + " does not have a search parameter called '" + theSearchParam + "'"); } } diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/MdmMatcherEnum.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/MdmMatcherEnum.java index da3a06167ed..395b06d7a66 100644 --- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/MdmMatcherEnum.java +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/MdmMatcherEnum.java @@ -40,6 +40,7 @@ public enum MdmMatcherEnum { NYSIIS(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.NYSIIS))), REFINED_SOUNDEX(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.REFINED_SOUNDEX))), SOUNDEX(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.SOUNDEX))), + NICKNAME(new HapiStringMatcher(new NicknameMatcher())), STRING(new HapiStringMatcher()), SUBSTRING(new HapiStringMatcher(new SubstringStringMatcher())), diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/NicknameMatcher.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/NicknameMatcher.java new file mode 100644 index 00000000000..f4a3fe8df57 --- /dev/null +++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/rules/matcher/NicknameMatcher.java @@ -0,0 +1,30 @@ +package ca.uhn.fhir.mdm.rules.matcher; + +import ca.uhn.fhir.context.ConfigurationException; +import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.jpa.searchparam.nickname.NicknameSvc; + +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +public class NicknameMatcher implements IMdmStringMatcher { + private final NicknameSvc myNicknameSvc; + + public NicknameMatcher() { + try { + myNicknameSvc = new NicknameSvc(); + } catch (IOException e) { + throw new ConfigurationException(Msg.code(2078) + "Unable to load nicknames", e); + } + } + + @Override + public boolean matches(String theLeftString, String theRightString) { + String leftString = theLeftString.toLowerCase(Locale.ROOT); + String rightString = theRightString.toLowerCase(Locale.ROOT); + + List leftNames = myNicknameSvc.getEquivalentNames(leftString); + return leftNames.contains(rightString); + } +} diff --git a/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/rules/matcher/NicknameMatcherTest.java b/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/rules/matcher/NicknameMatcherTest.java new file mode 100644 index 00000000000..89513f9e21e --- /dev/null +++ b/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/rules/matcher/NicknameMatcherTest.java @@ -0,0 +1,25 @@ +package ca.uhn.fhir.mdm.rules.matcher; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class NicknameMatcherTest { + IMdmStringMatcher matcher = new NicknameMatcher(); + + @Test + public void testMatches() { + assertTrue(matcher.matches("Ken", "ken")); + assertTrue(matcher.matches("ken", "Ken")); + assertTrue(matcher.matches("Ken", "Ken")); + assertTrue(matcher.matches("Kenneth", "Ken")); + assertTrue(matcher.matches("Kenneth", "Kenny")); + assertTrue(matcher.matches("Ken", "Kenneth")); + assertTrue(matcher.matches("Kenny", "Kenneth")); + + assertFalse(matcher.matches("Ken", "Bob")); + // These aren't nickname matches. If you want matches like these use a phonetic matcher + assertFalse(matcher.matches("Allen", "Allan")); + } +} diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleTarget.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleTarget.java index f44f15be71e..00361b74a9b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleTarget.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleTarget.java @@ -48,11 +48,24 @@ public class RuleTarget { for (Map.Entry entry : theParameters.entrySet()) { String key = entry.getKey(); String[] value = entry.getValue(); - if (key.endsWith(Constants.PARAMQUALIFIER_MDM)) { - key = key.split(Constants.PARAMQUALIFIER_MDM)[0]; - } + key = stripMdmQualifier(key); + key = stripNicknameQualifier(key); retval.put(key, value); } return retval; } + + private String stripMdmQualifier(String theKey) { + if (theKey.endsWith(Constants.PARAMQUALIFIER_MDM)) { + theKey = theKey.split(Constants.PARAMQUALIFIER_MDM)[0]; + } + return theKey; + } + + private String stripNicknameQualifier(String theKey) { + if (theKey.endsWith(Constants.PARAMQUALIFIER_NICKNAME)) { + theKey = theKey.split(Constants.PARAMQUALIFIER_NICKNAME)[0]; + } + return theKey; + } } diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java index 1a3165bad08..4f35e91cfd1 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java @@ -2,12 +2,14 @@ package ca.uhn.fhir.rest.param; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TokenParamTest { private static final FhirContext ourCtx = FhirContext.forR4Cached(); @@ -48,4 +50,32 @@ public class TokenParamTest { assertEquals("type-value|identifier-value", param.getValue()); } + @Test + public void testNameNickname() { + StringParam param = new StringParam(); + assertFalse(param.isNicknameExpand()); + param.setValueAsQueryToken(ourCtx, "name", Constants.PARAMQUALIFIER_NICKNAME, "kenny"); + assertTrue(param.isNicknameExpand()); + } + + @Test + public void testGivenNickname() { + StringParam param = new StringParam(); + assertFalse(param.isNicknameExpand()); + param.setValueAsQueryToken(ourCtx, "given", Constants.PARAMQUALIFIER_NICKNAME, "kenny"); + assertTrue(param.isNicknameExpand()); + } + + @Test + public void testInvalidNickname() { + StringParam param = new StringParam(); + assertFalse(param.isNicknameExpand()); + try { + param.setValueAsQueryToken(ourCtx, "family", Constants.PARAMQUALIFIER_NICKNAME, "kenny"); + fail(); + } catch (InvalidRequestException e) { + assertEquals("HAPI-2077: Modifier :nickname may only be used with 'name' and 'given' search parameters", e.getMessage()); + } + } + }