Issue 3563 mdm nickname support (#3565)
* added NicknameMap * added NicknameSvc * create NicknameInterceptor * test interceptor integration * add nickname matcher * test nickname matcher * unit test * documentation * unit test * cleanup * cleanup * Msg.code() * Msg.code() in test * Msg.code() * review feedback
This commit is contained in:
parent
e0f1b913b7
commit
10ebb082d0
|
@ -22,12 +22,7 @@ package ca.uhn.fhir.rest.api;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
|
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_STRING_EXACT = ":exact";
|
||||||
public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";
|
public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";
|
||||||
public static final String PARAMQUALIFIER_MDM = ":mdm";
|
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_OF_TYPE = ":of-type";
|
||||||
public static final String PARAMQUALIFIER_TOKEN_NOT = ":not";
|
public static final String PARAMQUALIFIER_TOKEN_NOT = ":not";
|
||||||
public static final int STATUS_HTTP_200_OK = 200;
|
public static final int STATUS_HTTP_200_OK = 200;
|
||||||
|
|
|
@ -21,9 +21,11 @@ package ca.uhn.fhir.rest.param;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
|
import ca.uhn.fhir.i18n.Msg;
|
||||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||||
import ca.uhn.fhir.model.primitive.StringDt;
|
import ca.uhn.fhir.model.primitive.StringDt;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
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.StringUtils;
|
||||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||||
|
@ -38,7 +40,8 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
private boolean myExact;
|
private boolean myExact;
|
||||||
private String myValue;
|
private String myValue;
|
||||||
|
|
||||||
private Boolean myMdmExpand;
|
private Boolean myNicknameExpand;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -77,12 +80,12 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
return ParameterUtil.escape(myValue);
|
return ParameterUtil.escape(myValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMdmExpand() {
|
public boolean isNicknameExpand() {
|
||||||
return myMdmExpand != null && myMdmExpand;
|
return myNicknameExpand != null && myNicknameExpand;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringParam setMdmExpand(boolean theMdmExpand) {
|
public StringParam setNicknameExpand(boolean theNicknameExpand) {
|
||||||
myMdmExpand = theMdmExpand;
|
myNicknameExpand = theNicknameExpand;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +101,15 @@ public class StringParam extends BaseParam implements IQueryParameterType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void doSetValueAsQueryToken(FhirContext theContext, String theParamName, String theQualifier, String theValue) {
|
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)) {
|
if (Constants.PARAMQUALIFIER_STRING_EXACT.equals(theQualifier)) {
|
||||||
setExact(true);
|
setExact(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -147,4 +147,15 @@ public class SearchParameterUtil {
|
||||||
.map(t -> t.getValueAsString())
|
.map(t -> t.getValueAsString())
|
||||||
.orElse(null);
|
.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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."
|
|
@ -1,5 +1,7 @@
|
||||||
# JPA Server Search
|
# 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:
|
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
|
### Chains within _has
|
||||||
|
|
|
@ -406,6 +406,14 @@ The following algorithms are currently supported:
|
||||||
Match names as strings in any order
|
Match names as strings in any order
|
||||||
</td>
|
</td>
|
||||||
<td>John Henry = John HENRY when exact=false, John Henry != Henry John</td>
|
<td>John Henry = John HENRY when exact=false, John Henry != Henry John</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>NICKNAME</td>
|
||||||
|
<td>matcher</td>
|
||||||
|
<td>
|
||||||
|
True if one name is a nickname of the other
|
||||||
|
</td>
|
||||||
|
<td>Ken = Kenneth, Kenny = Ken. Allen != Allan.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>IDENTIFIER</td>
|
<td>IDENTIFIER</td>
|
||||||
|
|
|
@ -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.search.warm.ICacheWarmingSvc;
|
||||||
import ca.uhn.fhir.jpa.searchparam.config.SearchParamConfig;
|
import ca.uhn.fhir.jpa.searchparam.config.SearchParamConfig;
|
||||||
import ca.uhn.fhir.jpa.searchparam.extractor.IResourceLinkResolver;
|
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.searchparam.registry.ISearchParamProvider;
|
||||||
import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc;
|
import ca.uhn.fhir.jpa.sp.ISearchParamPresenceSvc;
|
||||||
import ca.uhn.fhir.jpa.sp.SearchParamPresenceSvcImpl;
|
import ca.uhn.fhir.jpa.sp.SearchParamPresenceSvcImpl;
|
||||||
|
@ -164,6 +165,7 @@ import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
|
||||||
import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;
|
import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -827,4 +829,10 @@ public class JpaConfig {
|
||||||
public MemberMatcherR4Helper memberMatcherR4Helper(FhirContext theFhirContext) {
|
public MemberMatcherR4Helper memberMatcherR4Helper(FhirContext theFhirContext) {
|
||||||
return new MemberMatcherR4Helper(theFhirContext);
|
return new MemberMatcherR4Helper(theFhirContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
@Bean
|
||||||
|
public NicknameInterceptor nicknameInterceptor() throws IOException {
|
||||||
|
return new NicknameInterceptor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ public class ExtendedLuceneSearchBuilder {
|
||||||
case EMPTY_MODIFIER:
|
case EMPTY_MODIFIER:
|
||||||
return true;
|
return true;
|
||||||
case Constants.PARAMQUALIFIER_MDM:
|
case Constants.PARAMQUALIFIER_MDM:
|
||||||
|
case Constants.PARAMQUALIFIER_NICKNAME:
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,11 @@ import ca.uhn.fhir.mdm.log.Logs;
|
||||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||||
import ca.uhn.fhir.model.primitive.IdDt;
|
import ca.uhn.fhir.model.primitive.IdDt;
|
||||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||||
import ca.uhn.fhir.rest.param.StringParam;
|
|
||||||
import ca.uhn.fhir.rest.param.TokenParam;
|
import ca.uhn.fhir.rest.param.TokenParam;
|
||||||
import org.hl7.fhir.instance.model.api.IIdType;
|
import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -104,8 +102,7 @@ public class MdmSearchExpandingInterceptor {
|
||||||
.forEach(toAdd::add);
|
.forEach(toAdd::add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (theParamName.equalsIgnoreCase("_id")) {
|
||||||
else if (theParamName.equalsIgnoreCase("_id")) {
|
|
||||||
expandIdParameter(iQueryParameterType, toAdd, toRemove);
|
expandIdParameter(iQueryParameterType, toAdd, toRemove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +114,7 @@ public class MdmSearchExpandingInterceptor {
|
||||||
/**
|
/**
|
||||||
* Expands out the provided _id parameter into all the various
|
* Expands out the provided _id parameter into all the various
|
||||||
* ids of linked resources.
|
* ids of linked resources.
|
||||||
|
*
|
||||||
* @param theIdParameter
|
* @param theIdParameter
|
||||||
* @param theAddList
|
* @param theAddList
|
||||||
* @param theRemoveList
|
* @param theRemoveList
|
||||||
|
@ -130,29 +128,21 @@ public class MdmSearchExpandingInterceptor {
|
||||||
IIdType id;
|
IIdType id;
|
||||||
Creator<? extends IQueryParameterType> creator;
|
Creator<? extends IQueryParameterType> creator;
|
||||||
boolean mdmExpand = false;
|
boolean mdmExpand = false;
|
||||||
if (theIdParameter instanceof StringParam) {
|
if (theIdParameter instanceof TokenParam) {
|
||||||
StringParam param = (StringParam) theIdParameter;
|
|
||||||
mdmExpand = param.isMdmExpand();
|
|
||||||
id = new IdDt(param.getValue());
|
|
||||||
creator = StringParam::new;
|
|
||||||
}
|
|
||||||
else if (theIdParameter instanceof TokenParam) {
|
|
||||||
TokenParam param = (TokenParam) theIdParameter;
|
TokenParam param = (TokenParam) theIdParameter;
|
||||||
mdmExpand = param.isMdmExpand();
|
mdmExpand = param.isMdmExpand();
|
||||||
id = new IdDt(param.getValue());
|
id = new IdDt(param.getValue());
|
||||||
creator = TokenParam::new;
|
creator = TokenParam::new;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
creator = null;
|
creator = null;
|
||||||
id = null;
|
id = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == null || creator == null) {
|
if (id == null) {
|
||||||
// in case the _id paramter type is different from the above
|
// 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!",
|
ourLog.warn("_id parameter of incorrect type. Expected StringParam or TokenParam, but got {}. No expansion will be done!",
|
||||||
theIdParameter.getClass().getSimpleName());
|
theIdParameter.getClass().getSimpleName());
|
||||||
}
|
} else if (mdmExpand) {
|
||||||
else if (mdmExpand) {
|
|
||||||
ourLog.debug("_id parameter must be expanded out from: {}", id.getValue());
|
ourLog.debug("_id parameter must be expanded out from: {}", id.getValue());
|
||||||
|
|
||||||
Set<String> expandedResourceIds = myMdmLinkExpandSvc.expandMdmBySourceResourceId(id);
|
Set<String> expandedResourceIds = myMdmLinkExpandSvc.expandMdmBySourceResourceId(id);
|
||||||
|
|
|
@ -31,6 +31,7 @@ import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
|
||||||
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
||||||
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorService;
|
import ca.uhn.fhir.jpa.searchparam.extractor.SearchParamExtractorService;
|
||||||
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
|
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
|
||||||
|
import ca.uhn.fhir.util.SearchParameterUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -61,7 +62,8 @@ public class MdmSearchParamSvc {
|
||||||
|
|
||||||
public List<String> getValueFromResourceForSearchParam(IBaseResource theResource, String theSearchParam) {
|
public List<String> getValueFromResourceForSearchParam(IBaseResource theResource, String theSearchParam) {
|
||||||
String resourceType = myFhirContext.getResourceType(theResource);
|
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);
|
return mySearchParamExtractorService.extractParamValuesAsStrings(activeSearchParam, theResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -161,68 +162,134 @@ public class MdmProviderMatchR4Test extends BaseProviderR4Test {
|
||||||
public void testMatchWithCoarseDateGranularity() throws Exception {
|
public void testMatchWithCoarseDateGranularity() throws Exception {
|
||||||
setMdmRuleJson("mdm/coarse-birthdate-mdm-rules.json");
|
setMdmRuleJson("mdm/coarse-birthdate-mdm-rules.json");
|
||||||
|
|
||||||
String granularPatient = "{\n" +
|
String granularPatient = """
|
||||||
" \"resourceType\": \"Patient\",\n" +
|
{
|
||||||
" \"active\": true,\n" +
|
"resourceType": "Patient",
|
||||||
" \"name\": [\n" +
|
"active": true,
|
||||||
" {\n" +
|
"name": [
|
||||||
" \"family\": \"PETERSON\",\n" +
|
{
|
||||||
" \"given\": [\n" +
|
"family": "PETERSON",
|
||||||
" \"GARY\",\n" +
|
"given": [
|
||||||
" \"D\"\n" +
|
"GARY",
|
||||||
" ]\n" +
|
"D"
|
||||||
" }\n" +
|
]
|
||||||
" ],\n" +
|
}
|
||||||
" \"telecom\": [\n" +
|
],
|
||||||
" {\n" +
|
"telecom": [
|
||||||
" \"system\": \"phone\",\n" +
|
{
|
||||||
" \"value\": \"100100100\",\n" +
|
"system": "phone",
|
||||||
" \"use\": \"home\"\n" +
|
"value": "100100100",
|
||||||
" }\n" +
|
"use": "home"
|
||||||
" ],\n" +
|
}
|
||||||
" \"gender\": \"male\",\n" +
|
],
|
||||||
" \"birthDate\": \"1991-10-10\",\n" +
|
"gender": "male",
|
||||||
" \"address\": [\n" +
|
"birthDate": "1991-10-10",
|
||||||
" {\n" +
|
"address": [
|
||||||
" \"state\": \"NY\",\n" +
|
{
|
||||||
" \"postalCode\": \"12313\"\n" +
|
"state": "NY",
|
||||||
" }\n" +
|
"postalCode": "12313"
|
||||||
" ]\n" +
|
}
|
||||||
"}";
|
]
|
||||||
|
}""";
|
||||||
IBaseResource iBaseResource = myFhirContext.newJsonParser().parseResource(granularPatient);
|
IBaseResource iBaseResource = myFhirContext.newJsonParser().parseResource(granularPatient);
|
||||||
createPatient((Patient) iBaseResource);
|
createPatient((Patient) iBaseResource);
|
||||||
|
|
||||||
String coarsePatient = "{\n" +
|
String coarsePatient = """
|
||||||
" \"resourceType\": \"Patient\",\n" +
|
{
|
||||||
" \"active\": true,\n" +
|
"resourceType": "Patient",
|
||||||
" \"name\": [\n" +
|
"active": true,
|
||||||
" {\n" +
|
"name": [
|
||||||
" \"family\": \"PETERSON\",\n" +
|
{
|
||||||
" \"given\": [\n" +
|
"family": "PETERSON",
|
||||||
" \"GARY\",\n" +
|
"given": [
|
||||||
" \"D\"\n" +
|
"GARY",
|
||||||
" ]\n" +
|
"D"
|
||||||
" }\n" +
|
]
|
||||||
" ],\n" +
|
}
|
||||||
" \"telecom\": [\n" +
|
],
|
||||||
" {\n" +
|
"telecom": [
|
||||||
" \"system\": \"phone\",\n" +
|
{
|
||||||
" \"value\": \"100100100\",\n" +
|
"system": "phone",
|
||||||
" \"use\": \"home\"\n" +
|
"value": "100100100",
|
||||||
" }\n" +
|
"use": "home"
|
||||||
" ],\n" +
|
}
|
||||||
" \"gender\": \"male\",\n" +
|
],
|
||||||
" \"birthDate\": \"1991-10\",\n" +
|
"gender": "male",
|
||||||
" \"address\": [\n" +
|
"birthDate": "1991-10",
|
||||||
" {\n" +
|
"address": [
|
||||||
" \"state\": \"NY\",\n" +
|
{
|
||||||
" \"postalCode\": \"12313\"\n" +
|
"state": "NY",
|
||||||
" }\n" +
|
"postalCode": "12313"
|
||||||
" ]\n" +
|
}
|
||||||
"}";
|
]
|
||||||
|
}""";
|
||||||
|
|
||||||
IBaseResource coarseResource = myFhirContext.newJsonParser().parseResource(coarsePatient);
|
IBaseResource coarseResource = myFhirContext.newJsonParser().parseResource(coarsePatient);
|
||||||
Bundle result = (Bundle) myMdmProvider.match((Patient) coarseResource, new SystemRequestDetails());
|
Bundle result = (Bundle) myMdmProvider.match((Patient) coarseResource, new SystemRequestDetails());
|
||||||
assertEquals(1, result.getEntry().size());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package ca.uhn.fhir.jpa.mdm.svc;
|
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.BaseMdmR4Test;
|
||||||
import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmCandidateSearchCriteriaBuilderSvc;
|
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.HumanName;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
|
@ -4,15 +4,21 @@ import ca.uhn.fhir.interceptor.model.RequestPartitionId;
|
||||||
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
|
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
|
||||||
import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmCandidateSearchSvc;
|
import ca.uhn.fhir.jpa.mdm.svc.candidate.MdmCandidateSearchSvc;
|
||||||
import ca.uhn.fhir.jpa.mdm.svc.candidate.TooManyCandidatesException;
|
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.mdm.rules.config.MdmSettings;
|
||||||
|
import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||||
import org.hl7.fhir.r4.model.Patient;
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.hl7.fhir.r4.model.Practitioner;
|
import org.hl7.fhir.r4.model.Practitioner;
|
||||||
import org.hl7.fhir.r4.model.Reference;
|
import org.hl7.fhir.r4.model.Reference;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -28,10 +34,21 @@ public class MdmCandidateSearchSvcIT extends BaseMdmR4Test {
|
||||||
MdmCandidateSearchSvc myMdmCandidateSearchSvc;
|
MdmCandidateSearchSvc myMdmCandidateSearchSvc;
|
||||||
@Autowired
|
@Autowired
|
||||||
MdmSettings myMdmSettings;
|
MdmSettings myMdmSettings;
|
||||||
|
@Autowired
|
||||||
|
MatchUrlService myMatchUrlService;
|
||||||
|
|
||||||
|
private NicknameInterceptor myNicknameInterceptor;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void before() throws IOException {
|
||||||
|
myNicknameInterceptor = new NicknameInterceptor();
|
||||||
|
myInterceptorRegistry.registerInterceptor(myNicknameInterceptor);
|
||||||
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void resetMdmSettings() {
|
public void resetMdmSettings() {
|
||||||
myMdmSettings.setCandidateSearchLimit(MdmSettings.DEFAULT_CANDIDATE_SEARCH_LIMIT);
|
myMdmSettings.setCandidateSearchLimit(MdmSettings.DEFAULT_CANDIDATE_SEARCH_LIMIT);
|
||||||
|
myInterceptorRegistry.unregisterInterceptor(myNicknameInterceptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -43,6 +60,42 @@ public class MdmCandidateSearchSvcIT extends BaseMdmR4Test {
|
||||||
assertEquals(1, result.size());
|
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<IAnyResource> 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<IAnyResource> result = myMdmCandidateSearchSvc.findCandidates("Practitioner", noMatch, RequestPartitionId.allPartitions());
|
||||||
|
assertEquals(0, result.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findCandidatesMultipleMatchesDoNotCauseDuplicates() {
|
public void findCandidatesMultipleMatchesDoNotCauseDuplicates() {
|
||||||
|
@ -83,9 +136,9 @@ public class MdmCandidateSearchSvcIT extends BaseMdmR4Test {
|
||||||
Patient newJane = buildJanePatient();
|
Patient newJane = buildJanePatient();
|
||||||
|
|
||||||
createActivePatient();
|
createActivePatient();
|
||||||
assertEquals(1, runInTransaction(()->myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size()));
|
assertEquals(1, runInTransaction(() -> myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size()));
|
||||||
createActivePatient();
|
createActivePatient();
|
||||||
assertEquals(2, runInTransaction(()->myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size()));
|
assertEquals(2, runInTransaction(() -> myMdmCandidateSearchSvc.findCandidates("Patient", newJane, RequestPartitionId.allPartitions()).size()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
createActivePatient();
|
createActivePatient();
|
||||||
|
|
|
@ -25,6 +25,13 @@
|
||||||
"searchParams": [
|
"searchParams": [
|
||||||
"general-practitioner"
|
"general-practitioner"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"resourceType": "Practitioner",
|
||||||
|
"searchParams": [
|
||||||
|
"given:nickname",
|
||||||
|
"family"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"candidateFilterSearchParams": [
|
"candidateFilterSearchParams": [
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String, List<List<IQueryParameterType>>> set : theSearchParameterMap.entrySet()) {
|
||||||
|
String paramName = set.getKey();
|
||||||
|
List<List<IQueryParameterType>> andList = set.getValue();
|
||||||
|
for (List<IQueryParameterType> 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<IQueryParameterType> orList) {
|
||||||
|
List<IQueryParameterType> toAdd = new ArrayList<>();
|
||||||
|
List<IQueryParameterType> 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<String> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String, List<String>> myFormalToNick = new HashMap<>();
|
||||||
|
private final Map<String, List<String>> 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<String> values = new ArrayList<>(Arrays.asList(parts).subList(1, parts.length));
|
||||||
|
add(key, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(String theKey, List<String> 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<String> getNicknamesFromFormalNameOrNull(String theName) {
|
||||||
|
return myFormalToNick.get(theName);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> getFormalNamesFromNicknameOrNull(String theNickname) {
|
||||||
|
return myNicknameToFormal.get(theNickname);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String> getEquivalentNames(String theName) {
|
||||||
|
List<String> retval = new ArrayList<>();
|
||||||
|
retval.add(theName);
|
||||||
|
|
||||||
|
List<String> expansions;
|
||||||
|
expansions = getNicknamesFromFormalNameOrNull(theName);
|
||||||
|
if (expansions != null) {
|
||||||
|
retval.addAll(expansions);
|
||||||
|
} else {
|
||||||
|
expansions = getFormalNamesFromNicknameOrNull(theName);
|
||||||
|
if (expansions != null) {
|
||||||
|
retval.addAll(expansions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> getNicknamesFromFormalNameOrNull(String theName) {
|
||||||
|
return myNicknameMap.getNicknamesFromFormalNameOrNull(theName);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> getFormalNamesFromNicknameOrNull(String theNickname) {
|
||||||
|
return myNicknameMap.getFormalNamesFromNicknameOrNull(theNickname);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.
|
|
@ -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
|
||||||
|
<a href="http://www.caagri.org/nicknames.html">genealogy page</a>. 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 <a href="http://www.odu.edu/">Old Dominion University</a> - <a href="http://ws-dl.blogspot.com/">Web Science and Digital Libraries Research Group</a>. More information about the creation of this lookup can be found <a href="https://ws-dl.blogspot.com/2010/08/lookup-for-nicknames-and-diminutive.html">here</a>.
|
|
@ -0,0 +1,2 @@
|
||||||
|
The files in this folder were cloned from https://github.com/carltonnorthern/nickname-and-diminutive-names-lookup
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Patient> resources = BundleUtil.toListOfResourcesOfType(myFhirContext,result, Patient.class);
|
||||||
|
assertThat(resources, hasSize(1));
|
||||||
|
assertEquals("ken", resources.get(0).getNameFirstRep().getGivenAsSingleString());
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,14 +20,14 @@ package ca.uhn.fhir.mdm.rules.config;
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.i18n.Msg;
|
|
||||||
import ca.uhn.fhir.context.ConfigurationException;
|
import ca.uhn.fhir.context.ConfigurationException;
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||||
import ca.uhn.fhir.fhirpath.IFhirPath;
|
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.IMdmRuleValidator;
|
||||||
|
import ca.uhn.fhir.mdm.api.MdmConstants;
|
||||||
import ca.uhn.fhir.mdm.rules.json.MdmFieldMatchJson;
|
import ca.uhn.fhir.mdm.rules.json.MdmFieldMatchJson;
|
||||||
import ca.uhn.fhir.mdm.rules.json.MdmFilterSearchParamJson;
|
import ca.uhn.fhir.mdm.rules.json.MdmFilterSearchParamJson;
|
||||||
import ca.uhn.fhir.mdm.rules.json.MdmResourceSearchParamJson;
|
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.parser.DataFormatException;
|
||||||
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
|
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;
|
||||||
import ca.uhn.fhir.util.FhirTerser;
|
import ca.uhn.fhir.util.FhirTerser;
|
||||||
|
import ca.uhn.fhir.util.SearchParameterUtil;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -150,7 +151,8 @@ public class MdmRuleValidator implements IMdmRuleValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateResourceSearchParam(String theFieldName, String theResourceType, String theSearchParam) {
|
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 + "'");
|
throw new ConfigurationException(Msg.code(1511) + "Error in " + theFieldName + ": " + theResourceType + " does not have a search parameter called '" + theSearchParam + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ public enum MdmMatcherEnum {
|
||||||
NYSIIS(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.NYSIIS))),
|
NYSIIS(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.NYSIIS))),
|
||||||
REFINED_SOUNDEX(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.REFINED_SOUNDEX))),
|
REFINED_SOUNDEX(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.REFINED_SOUNDEX))),
|
||||||
SOUNDEX(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.SOUNDEX))),
|
SOUNDEX(new HapiStringMatcher(new PhoneticEncoderMatcher(PhoneticEncoderEnum.SOUNDEX))),
|
||||||
|
NICKNAME(new HapiStringMatcher(new NicknameMatcher())),
|
||||||
|
|
||||||
STRING(new HapiStringMatcher()),
|
STRING(new HapiStringMatcher()),
|
||||||
SUBSTRING(new HapiStringMatcher(new SubstringStringMatcher())),
|
SUBSTRING(new HapiStringMatcher(new SubstringStringMatcher())),
|
||||||
|
|
|
@ -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<String> leftNames = myNicknameSvc.getEquivalentNames(leftString);
|
||||||
|
return leftNames.contains(rightString);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,11 +48,24 @@ public class RuleTarget {
|
||||||
for (Map.Entry<String, String[]> entry : theParameters.entrySet()) {
|
for (Map.Entry<String, String[]> entry : theParameters.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
String[] value = entry.getValue();
|
String[] value = entry.getValue();
|
||||||
if (key.endsWith(Constants.PARAMQUALIFIER_MDM)) {
|
key = stripMdmQualifier(key);
|
||||||
key = key.split(Constants.PARAMQUALIFIER_MDM)[0];
|
key = stripNicknameQualifier(key);
|
||||||
}
|
|
||||||
retval.put(key, value);
|
retval.put(key, value);
|
||||||
}
|
}
|
||||||
return retval;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,14 @@ package ca.uhn.fhir.rest.param;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
|
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class TokenParamTest {
|
public class TokenParamTest {
|
||||||
private static final FhirContext ourCtx = FhirContext.forR4Cached();
|
private static final FhirContext ourCtx = FhirContext.forR4Cached();
|
||||||
|
@ -48,4 +50,32 @@ public class TokenParamTest {
|
||||||
assertEquals("type-value|identifier-value", param.getValue());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue