From f61cb163ae3b277bdbe34b493c723922f4adad90 Mon Sep 17 00:00:00 2001 From: Mike G Date: Mon, 1 Feb 2021 12:11:11 -0500 Subject: [PATCH] refactor and modify for prefix and suffix --- .../dao/r4/SearchParamExtractorR4Test.java | 10 ++++++-- .../extractor/BaseSearchParamExtractor.java | 23 +++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java index d29371959ad..fa5c7a5c567 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java @@ -36,12 +36,14 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.SearchParameter; +import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -88,14 +90,18 @@ public class SearchParamExtractorR4Test { @Test public void testName() { Patient patient = new Patient(); + List suffixStrings = Arrays.asList(new StringType("the Great")); + List prefixStrings = Arrays.asList(new StringType("King")); HumanName humanName = patient.addName(); humanName.addGiven("Jimmy"); humanName.setFamily("Jones"); - humanName.setText("Jimmy Jones"); + humanName.setText("King Jimmy Jones the Great"); + humanName.setSuffix(suffixStrings); + humanName.setPrefix(prefixStrings); SearchParamExtractorR4 extractor = new SearchParamExtractorR4(new ModelConfig(), new PartitionSettings(), ourCtx, mySearchParamRegistry); ISearchParamExtractor.SearchParamSet stringSearchParams = extractor.extractSearchParamStrings(patient); List nameValues = stringSearchParams.stream().filter(param -> "name".equals(param.getParamName())).map(ResourceIndexedSearchParamString::getValueExact).collect(Collectors.toList()); - assertThat(nameValues, containsInAnyOrder("Jimmy", "Jones", "Jimmy Jones")); + assertThat(nameValues, containsInAnyOrder("Jimmy", "Jones", "King Jimmy Jones the Great", "King", "the Great")); } @Test diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java index 10c8bd2ce2d..2a02c54bb16 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java @@ -69,6 +69,7 @@ import javax.measure.unit.NonSI; import javax.measure.unit.Unit; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -133,6 +134,8 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor private BaseRuntimeChildDefinition myHumanNameFamilyValueChild; private BaseRuntimeChildDefinition myHumanNameGivenValueChild; private BaseRuntimeChildDefinition myHumanNameTextValueChild; + private BaseRuntimeChildDefinition myHumanNamePrefixValueChild; + private BaseRuntimeChildDefinition myHumanNameSuffixValueChild; private BaseRuntimeChildDefinition myContactPointValueValueChild; private BaseRuntimeChildDefinition myIdentifierSystemValueChild; private BaseRuntimeChildDefinition myIdentifierValueValueChild; @@ -868,19 +871,13 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor } } - private void addString_HumanName(String theResourceType, Set theParams, RuntimeSearchParam theSearchParam, IBase theValue) { - List families = extractValuesAsStrings(myHumanNameFamilyValueChild, theValue); - for (String next : families) { - createStringIndexIfNotBlank(theResourceType, theParams, theSearchParam, next); - } - List givens = extractValuesAsStrings(myHumanNameGivenValueChild, theValue); - for (String next : givens) { - createStringIndexIfNotBlank(theResourceType, theParams, theSearchParam, next); - } - List texts = extractValuesAsStrings(myHumanNameTextValueChild, theValue); - for (String next : texts) { - createStringIndexIfNotBlank(theResourceType, theParams, theSearchParam, next); + List myHumanNameChildren = Arrays.asList(myHumanNameFamilyValueChild, myHumanNameGivenValueChild, myHumanNameTextValueChild, myHumanNamePrefixValueChild, myHumanNameSuffixValueChild); + for (BaseRuntimeChildDefinition theChild : myHumanNameChildren) { + List indices = extractValuesAsStrings(theChild, theValue); + for (String next : indices) { + createStringIndexIfNotBlank(theResourceType, theParams, theSearchParam, next); + } } } @@ -1144,6 +1141,8 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor myHumanNameFamilyValueChild = humanNameDefinition.getChildByName("family"); myHumanNameGivenValueChild = humanNameDefinition.getChildByName("given"); myHumanNameTextValueChild = humanNameDefinition.getChildByName("text"); + myHumanNamePrefixValueChild = humanNameDefinition.getChildByName("prefix"); + myHumanNameSuffixValueChild = humanNameDefinition.getChildByName("suffix"); BaseRuntimeElementCompositeDefinition contactPointDefinition = (BaseRuntimeElementCompositeDefinition) getContext().getElementDefinition("ContactPoint"); myContactPointValueValueChild = contactPointDefinition.getChildByName("value");