From ba40f44d2701062eb32483640718dfe9fa77cb74 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 26 May 2017 06:39:13 -0400 Subject: [PATCH] Properly index decimal datatype --- .../dao/dstu3/SearchParamExtractorDstu3.java | 9 ++++ ...ceDaoDstu3SearchCustomSearchParamTest.java | 44 ++++++++++++++++--- src/changes/changes.xml | 4 ++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java index 6bee6ba6190..182b4ef752d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3.java @@ -261,6 +261,15 @@ public class SearchParamExtractorDstu3 extends BaseSearchParamExtractor implemen ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, new BigDecimal(nextValue.getValue())); nextEntity.setResource(theEntity); retVal.add(nextEntity); + } else if (nextObject instanceof DecimalType) { + DecimalType nextValue = (DecimalType) nextObject; + if (nextValue.getValue() == null) { + continue; + } + + ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue()); + nextEntity.setResource(theEntity); + retVal.add(nextEntity); } else { if (!multiType) { throw new ConfigurationException("Search param " + resourceName + " is of unexpected datatype: " + nextObject.getClass()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java index a4950b4b2a2..1bb84170b6f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java @@ -10,14 +10,7 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.util.List; -import org.hl7.fhir.dstu3.model.Appointment; -import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; -import org.hl7.fhir.dstu3.model.Patient; -import org.hl7.fhir.dstu3.model.Practitioner; -import org.hl7.fhir.dstu3.model.Reference; -import org.hl7.fhir.dstu3.model.SearchParameter; -import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; @@ -488,6 +481,43 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu assertThat(foundResources, contains(p2id.getValue())); } + @Test + public void testSearchForExtensionTwoDeepDecimal() { + SearchParameter siblingSp = new SearchParameter(); + siblingSp.addBase("Patient"); + siblingSp.setCode("foobar"); + siblingSp.setType(org.hl7.fhir.dstu3.model.Enumerations.SearchParamType.NUMBER); + siblingSp.setTitle("FooBar"); + siblingSp.setExpression("Patient.extension('http://acme.org/foo').extension('http://acme.org/bar')"); + siblingSp.setXpathUsage(org.hl7.fhir.dstu3.model.SearchParameter.XPathUsageType.NORMAL); + siblingSp.setStatus(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.ACTIVE); + mySearchParameterDao.create(siblingSp, mySrd); + + mySearchParamRegsitry.forceRefresh(); + + Patient patient = new Patient(); + patient.addName().setFamily("P2"); + Extension extParent = patient + .addExtension() + .setUrl("http://acme.org/foo"); + extParent + .addExtension() + .setUrl("http://acme.org/bar") + .setValue(new DecimalType("2.1")); + + IIdType p2id = myPatientDao.create(patient).getId().toUnqualifiedVersionless(); + + SearchParameterMap map; + IBundleProvider results; + List foundResources; + + map = new SearchParameterMap(); + map.add("foobar", new NumberParam("2.1")); + results = myPatientDao.search(map); + foundResources = toUnqualifiedVersionlessIdValues(results); + assertThat(foundResources, contains(p2id.getValue())); + } + @Test public void testSearchForExtensionTwoDeepString() { SearchParameter siblingSp = new SearchParameter(); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8fc728ccdaa..7de5b4da4fd 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -142,6 +142,10 @@ preventing this library from being used on Android because Android includes an older version of commons-codec. + + JPA server failed to index search parameters on paths containing a decimal + data type +