From 5ac91bfb94aad7bcc7e7fb8e6b06baa0b4629271 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 17 May 2017 08:19:11 -0400 Subject: [PATCH] Add a test for custom params --- .../BaseResourceIndexedSearchParam.java | 5 ++- ...ceDaoDstu3SearchCustomSearchParamTest.java | 37 ++++++++++++++++++- .../WEB-INF/templates/tmpl-navbar-left.html | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java index c01fa62e1b4..7eb0c2e2746 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/BaseResourceIndexedSearchParam.java @@ -35,9 +35,10 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable { private static final long serialVersionUID = 1L; + // TODO: make this nullable=false and a primitive (written may 2017) @Field() @Column(name = "SP_MISSING", nullable = true) - private boolean myMissing; + private Boolean myMissing; @Field @Column(name = "SP_NAME", length = MAX_SP_NAME, nullable = false) @@ -83,7 +84,7 @@ public abstract class BaseResourceIndexedSearchParam implements Serializable { } public boolean isMissing() { - return myMissing; + return Boolean.TRUE.equals(myMissing); } public void setMissing(boolean theMissing) { 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 7bd22243258..e483f226d00 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 @@ -12,6 +12,7 @@ import java.util.List; 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.Reference; import org.hl7.fhir.dstu3.model.SearchParameter; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.instance.model.api.IIdType; @@ -167,7 +168,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu } @Test - public void testSearchForExtension() { + public void testSearchForExtensionToken() { SearchParameter eyeColourSp = new SearchParameter(); eyeColourSp.addBase("Patient"); eyeColourSp.setCode("eyecolour"); @@ -199,6 +200,40 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu } + @Test + public void testSearchForExtensionReference() { + + + SearchParameter eyeColourSp = new SearchParameter(); + eyeColourSp.addBase("Patient"); + eyeColourSp.setCode("sibling"); + eyeColourSp.setType(org.hl7.fhir.dstu3.model.Enumerations.SearchParamType.REFERENCE); + eyeColourSp.setTitle("Sibling"); + eyeColourSp.setExpression("Patient.extension('http://acme.org/sibling')"); + eyeColourSp.setXpathUsage(org.hl7.fhir.dstu3.model.SearchParameter.XPathUsageType.NORMAL); + eyeColourSp.setStatus(org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus.ACTIVE); + mySearchParameterDao.create(eyeColourSp, mySrd); + + mySearchParamRegsitry.forceRefresh(); + + Patient p1 = new Patient(); + p1.setActive(true); + IIdType p1id = myPatientDao.create(p1).getId().toUnqualifiedVersionless(); + + Patient p2 = new Patient(); + p2.setActive(true); + p2.addExtension().setUrl("http://acme.org/sibling").setValue(new Reference(p1id)); + IIdType p2id = myPatientDao.create(p2).getId().toUnqualifiedVersionless(); + + // Try with custom gender SP + SearchParameterMap map = new SearchParameterMap(); + map.add("sibling", new ReferenceParam(p1id.getValue())); + IBundleProvider results = myPatientDao.search(map); + List foundResources = toUnqualifiedVersionlessIdValues(results); + assertThat(foundResources, contains(p2id.getValue())); + + } + @Test public void testSearchWithCustomParam() { diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html index 030c25897e6..876eb94d816 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html @@ -115,7 +115,7 @@