From b8f1f39ead1a8e8f09f2491159b45f26609ad256 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 1 Jul 2016 08:51:47 -0400 Subject: [PATCH] Add tests and get :below queries working for built-in code systems --- .../java/ca/uhn/fhir/parser/BaseParser.java | 7 ++--- .../ca/uhn/fhir/rest/param/TokenParam.java | 13 +++++++-- .../FhirResourceDaoDstu3TerminologyTest.java | 12 ++++---- .../fhir/jpa/term/TerminologySvcImplTest.java | 1 - .../derby_maintenance.txt | 3 ++ ...ParameterTest.java => TokenParamTest.java} | 28 ++++++++++++++++++- 6 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt rename hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/{TokenParameterTest.java => TokenParamTest.java} (89%) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java index a8876dea5f2..f2e670e3836 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java @@ -44,7 +44,6 @@ import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseCoding; import org.hl7.fhir.instance.model.api.IBaseElement; -import org.hl7.fhir.instance.model.api.IBaseExtension; import org.hl7.fhir.instance.model.api.IBaseHasExtensions; import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions; import org.hl7.fhir.instance.model.api.IBaseMetaType; @@ -402,9 +401,9 @@ public abstract class BaseParser implements IParser { String childName = theChild.getChildNameByDatatype(type); BaseRuntimeElementDefinition childDef = theChild.getChildElementDefinitionByDatatype(type); if (childDef == null) { - if (theValue instanceof IBaseExtension) { - return null; - } +// if (theValue instanceof IBaseExtension) { +// return null; +// } /* * For RI structures Enumeration class, this replaces the child def diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/TokenParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/TokenParam.java index fbf53ab199d..37964ac23bb 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/TokenParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/TokenParam.java @@ -143,14 +143,23 @@ public class TokenParam extends BaseParam implements IQueryParameterType { /** * Returns the system for this token. Note that if a {@link #getModifier()} is being used, the entire value of the - * parameter will be placed in {@link #getValue() value} and this method will return null. + * parameter will be placed in {@link #getValue() value} and this method will return null. + *

null or "" (empty string) and that + * each of these have a different meaning. When a token is passed on a URL and it has no + * vertical bar (often meaning "return values that match the given code in any codesystem") + * this method will return null. When a token is passed on a URL and it has + * a vetical bar but nothing before the bar (often meaning "return values that match the + * given code but that have no codesystem) this method will return "" + *

*/ public String getSystem() { return mySystem; } /** - * Returns the value for the token + * Returns the value for the token (generally the value to the right of the + * vertical bar on the URL) */ public String getValue() { return myValue; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java index c639319ad37..9b63a2eb23e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java @@ -331,7 +331,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { ValueSet vs = new ValueSet(); ConceptSetComponent include = vs.getCompose().addInclude(); include.setSystem(URL_MY_CODE_SYSTEM); -// include.addConcept().setCode("A"); + include.addConcept().setCode("A"); // include.addConcept().setCode("AA"); // include.addConcept().setCode("AAA"); // include.addConcept().setCode("AB"); @@ -344,11 +344,12 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { ourLog.info(encoded); ArrayList codes = toCodesContains(result.getExpansion().getContains()); - assertThat(codes, containsInAnyOrder("AAA")); + assertThat(codes, containsInAnyOrder("A", "AAA")); - assertEquals("AAA", result.getExpansion().getContains().get(0).getCode()); - assertEquals("Code AAA", result.getExpansion().getContains().get(0).getDisplay()); - assertEquals(URL_MY_CODE_SYSTEM, result.getExpansion().getContains().get(0).getSystem()); + int idx = codes.indexOf("AAA"); + assertEquals("AAA", result.getExpansion().getContains().get(idx).getCode()); + assertEquals("Code AAA", result.getExpansion().getContains().get(idx).getDisplay()); + assertEquals(URL_MY_CODE_SYSTEM, result.getExpansion().getContains().get(idx).getSystem()); // } @@ -612,7 +613,6 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { @Test - @Ignore public void testSearchCodeInEmptyValueSet() { ValueSet valueSet = new ValueSet(); valueSet.setUrl(URL_MY_VALUE_SET); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java index 84b407c1a51..396ccfa365f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java @@ -24,7 +24,6 @@ import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.TestUtil; public class TerminologySvcImplTest extends BaseJpaDstu3Test { diff --git a/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt new file mode 100644 index 00000000000..7864fd0dd8e --- /dev/null +++ b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt @@ -0,0 +1,3 @@ +call SYSCS_UTIL.SYSCS_COMPRESS_TABLE('SA', 'HFJ_SEARCH_RESULT', 1); +CALL SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE( 'SA', 'HFJ_SEARCH_RESULT', 0, 0, 1 ); + diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParameterTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParamTest.java similarity index 89% rename from hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParameterTest.java rename to hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParamTest.java index 650e98383c2..4ff5cca351e 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParameterTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParamTest.java @@ -33,7 +33,7 @@ import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; -public class TokenParameterTest { +public class TokenParamTest { private static CloseableHttpClient ourClient; private static FhirContext ourCtx = FhirContext.forDstu1(); @@ -63,6 +63,32 @@ public class TokenParameterTest { assertEquals("b", ourLastOrList.getValuesAsQueryTokens().get(0).getValue()); } + @Test + public void testNoSystem() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier=b"); + HttpResponse status = ourClient.execute(httpGet); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + assertEquals(1, ourLastOrList.getListAsCodings().size()); + assertEquals(null, ourLastOrList.getValuesAsQueryTokens().get(0).getSystem()); + assertEquals("b", ourLastOrList.getValuesAsQueryTokens().get(0).getValue()); + } + + @Test + public void testEmptySystem() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier=%7Cb"); + HttpResponse status = ourClient.execute(httpGet); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + assertEquals(1, ourLastOrList.getListAsCodings().size()); + assertEquals("", ourLastOrList.getValuesAsQueryTokens().get(0).getSystem()); + assertEquals("b", ourLastOrList.getValuesAsQueryTokens().get(0).getValue()); + } + @Test public void testGetModifiersText() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier:text=a%7Cb");