Skip to content

Commit

Permalink
issue #1052 - ignore non-return parameter "general parameters" in search
Browse files Browse the repository at this point in the history
move "general parameter" parameter names to FHIRConstants in `fhir-core`
and update SearchUtil

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed May 8, 2020
1 parent 9ecbbcf commit 6de4860
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 105 deletions.
23 changes: 22 additions & 1 deletion fhir-core/src/main/java/com/ibm/fhir/core/FHIRConstants.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
/*
* (C) Copyright IBM Corp. 2016,2019
* (C) Copyright IBM Corp. 2016, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.core;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* This class contains constants that are used through the fhir-* projects.
*/
public class FHIRConstants {
public static final String FHIR_LOGGING_GROUP = "FHIRServer";

public static final int FHIR_CONDITIONAL_DELETE_MAX_NUMBER_DEFAULT = 10;

public static final String FORMAT = "_format";

public static final String PRETTY = "_pretty";

public static final String SUMMARY = "_summary";

public static final String ELEMENTS = "_elements";

/**
* General parameter names that can be used with any FHIR interaction.
*
* @see <a href="https://www.hl7.org/fhir/r4/http.html#parameters">https://www.hl7.org/fhir/r4/http.html#parameters</a>
*/
public static final List<String> GENERAL_PARAMETER_NAMES =
Collections.unmodifiableList(Arrays.asList(FORMAT, PRETTY, SUMMARY, ELEMENTS));
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,75 @@
/*
* (C) Copyright IBM Corp. 2016,2019
* (C) Copyright IBM Corp. 2016, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.core.context;

/**
* The paging context for given request
*/
public interface FHIRPagingContext {
/**
* @return the last page number
*/
int getLastPageNumber();

/**
* @return the current page number
*/
int getPageNumber();

/**
* @return the number of resources in a single page
* @see <a href="https://www.hl7.org/fhir/r4/search.html#count">https://www.hl7.org/fhir/r4/search.html#count</a>
* @implSpec this number only applies to resources with {@code entry.search.mode = search}
* and does not include included resources or operation outcomes
*/
int getPageSize();

/**
* @return the total number of matching resources for the corresponding query
* @see <a href="https://www.hl7.org/fhir/r4/search.html#count">https://www.hl7.org/fhir/r4/search.html#count</a>
* @implSpec this number only includes the total number of matching resources; it does not count extra resources
* such as OperationOutcome or included resources that may also be returned
*/
int getTotalCount();

/**
* @param lastPageNumber the last page of results that can be requested for the corresponding query
*/
void setLastPageNumber(int lastPageNumber);

/**
* @param pageNumber the current page number
*/
void setPageNumber(int pageNumber);

/**
* @param pageSize the number of resources to include in a single page
* @see <a href="https://www.hl7.org/fhir/r4/search.html#count">https://www.hl7.org/fhir/r4/search.html#count</a>
* @implSpec this number only applies to resources with {@code entry.search.mode = search}
* and does not include included resources or operation outcomes
*
*/
void setPageSize(int pageSize);

/**
* @param totalCount the total number of matching resources for the corresponding query
* @see <a href="https://www.hl7.org/fhir/r4/search.html#count">https://www.hl7.org/fhir/r4/search.html#count</a>
* @implSpec this number only includes the total number of matching resources; it does not count extra resources
* such as OperationOutcome or included resources that may also be returned
*/
void setTotalCount(int totalCount);

/**
* @return whether the request should be handled with leniency
*/
boolean isLenient();

/**
* @param lenient whether the request should be handled with leniency
*/
void setLenient(boolean lenient);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016,2019
* (C) Copyright IBM Corp. 2016, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -12,19 +12,27 @@ public class FHIRPagingContextImpl implements FHIRPagingContext {
protected static final int DEFAULT_PAGE_SIZE = 10;
protected static final int DEFAULT_PAGE_NUMBER = 1;
protected static final int DEFAULT_LAST_PAGE_NUMBER = Integer.MAX_VALUE;

protected int lastPageNumber;
protected int pageNumber;
protected int pageSize;
protected int totalCount;
protected boolean lenient = true;


/**
* Create a FHIRPagingContextImpl with the default values:
* <pre>
* page number: 1
* page size: 10
* last page: 214748364
* </pre>
*/
public FHIRPagingContextImpl() {
this.pageNumber = DEFAULT_PAGE_NUMBER;
this.pageSize = DEFAULT_PAGE_SIZE;
this.lastPageNumber = DEFAULT_LAST_PAGE_NUMBER;
}

@Override
public int getLastPageNumber() {
return lastPageNumber;
Expand All @@ -39,7 +47,7 @@ public int getPageNumber() {
public int getPageSize() {
return pageSize;
}

@Override
public int getTotalCount() {
return totalCount;
Expand All @@ -64,7 +72,7 @@ public void setPageSize(int pageSize) {
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}

@Override
public boolean isLenient() {
return lenient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016,2019
* (C) Copyright IBM Corp. 2016, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -56,7 +56,7 @@ public abstract class AbstractPersistenceTest {

// A hook for subclasses to override and provide specific test database setup functionality if required.
protected void bootstrapDatabase() throws Exception {}

// A hook for subclasses to override and provide specific test database shutdown functionality if required.
protected void shutdownDatabase() throws Exception {}

Expand Down Expand Up @@ -101,7 +101,7 @@ public void commitTrx() throws Exception{
persistence.getTransaction().commit();
}
}

@AfterSuite(alwaysRun = true)
public void tearDown() throws Exception {
shutdownDatabase();
Expand Down Expand Up @@ -137,10 +137,10 @@ protected MultiResourceResult<Resource> runQueryTest(FHIRSearchContext searchCon
for (String key : queryParms.keySet()) {

expectedCount++;
if (!SearchUtil.isSearchResultParameter(key)) {
if (!SearchUtil.isSearchResultParameter(key) && !SearchUtil.isGeneralParameter(key)) {
String paramName = key;
if (SearchUtil.isChainedParameter(key)) {
// ignore the chained part and just very the reference param is there
// ignore the chained part and just verify the reference param is there
paramName = key.split("\\.")[0];
}
// strip any modifiers
Expand Down
82 changes: 38 additions & 44 deletions fhir-search/src/main/java/com/ibm/fhir/search/SearchConstants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2019
* (C) Copyright IBM Corp. 2019, 2020
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -27,7 +27,7 @@ public class SearchConstants {
private SearchConstants() {
// No Op
}

private static final String SUBSETTED_TAG_SYSTEM = "http://terminology.hl7.org/CodeSystem/v3-ObservationValue";
private static final String SUBSETTED_TAG_CODE = "SUBSETTED";
private static final String SUBSETTED_TAG_DISPLAY = "subsetted";
Expand All @@ -38,7 +38,7 @@ private SearchConstants() {
.build();

public static final String LOG_BOUNDARY = "---------------------------------------------------------";

// XML Processing.
public static final String DTM_MANAGER = "com.sun.org.apache.xml.internal.dtm.DTMManager";

Expand All @@ -52,8 +52,8 @@ private SearchConstants() {
public static final String BACKSLASH_NEGATIVE_LOOKBEHIND = "(?<!\\\\)";

public static final String COMPARTMENTS_JSON = "compartments.json";
// Value Types Regex.

// Value Types Regex.
public static final String PARAMETER_DELIMITER_REGEX = "\\|";
public static final String COMPONENT_PATH_REGEX = "\\.";
public static final char START_WHERE = '(';
Expand All @@ -63,9 +63,6 @@ private SearchConstants() {
// In the future, we might want to make this value configurable.
public static final int MAX_PAGE_SIZE = 1000;

// _format
public static final String FORMAT = "_format";

// _sort
public static final String SORT = "_sort";

Expand All @@ -83,20 +80,17 @@ private SearchConstants() {

// _count
public static final String COUNT = "_count";

// _summary
public static final String SUMMARY = "_summary";

// _pretty
public static final String PRETTY = "_pretty";


// _type
public static final String RESOURCE_TYPE = "_type";

// set as unmodifiable
public static final List<String> SEARCH_RESULT_PARAMETER_NAMES =
Collections.unmodifiableList(Arrays.asList(SORT, COUNT, PAGE, INCLUDE, REVINCLUDE, ELEMENTS, SUMMARY));

// set as unmodifiable
public static final List<String> SYSTEM_LEVEL_SORT_PARAMETER_NAMES = Collections.unmodifiableList(Arrays.asList("_id", "_lastUpdated"));

Expand All @@ -109,29 +103,29 @@ private SearchConstants() {
public static final String CHAINED_PARAMETER_CHARACTER = ".";

public static final String PARAMETER_DELIMITER = "|";

public static final char COLON_DELIMITER = ':';

public static final String COLON_DELIMITER_STR = ":";

public static final String WILDCARD = "*";

public static final char AND_CHAR = '&';

public static final char EQUALS_CHAR = '=';

public static final String JOIN_STR = ",";

public static final String AND_CHAR_STR = "&";

// Filter
public static final String WILDCARD_FILTER = "*";
// Resource Constants to reflect a hierarchy:

// Resource Constants to reflect a hierarchy:
// RESOURCE -> DOMAIN_RESOURCE -> Instance (e.g. Claim);
public static final String RESOURCE_RESOURCE = "Resource";
public static final String DOMAIN_RESOURCE_RESOURCE = "DomainResource";

// The resourceTypeModifierMap is set one time on startup and is a final value.
// Set as unmodifiable.
public static final Map<Type, List<Modifier>> RESOURCE_TYPE_MODIFIER_MAP =
Expand All @@ -143,7 +137,7 @@ private SearchConstants() {
put(SearchConstants.Type.STRING, Arrays.asList(Modifier.EXACT, Modifier.CONTAINS, Modifier.MISSING));
put(SearchConstants.Type.REFERENCE, Arrays.asList(Modifier.TYPE, Modifier.IDENTIFIER, Modifier.MISSING));
put(SearchConstants.Type.URI, Arrays.asList(Modifier.BELOW, Modifier.ABOVE, Modifier.MISSING));
put(SearchConstants.Type.TOKEN, Arrays.asList(Modifier.TEXT, Modifier.NOT,
put(SearchConstants.Type.TOKEN, Arrays.asList(Modifier.TEXT, Modifier.NOT,
Modifier.ABOVE, Modifier.BELOW, Modifier.IN, Modifier.NOT_IN, Modifier.OF_TYPE, Modifier.MISSING));
put(SearchConstants.Type.NUMBER, Arrays.asList(Modifier.MISSING));
put(SearchConstants.Type.DATE, Arrays.asList(Modifier.MISSING));
Expand All @@ -157,14 +151,14 @@ private SearchConstants() {
* Prefixes for Search parameters
*/
public enum Prefix {
EQ("eq"),
NE("ne"),
GT("gt"),
LT("lt"),
GE("ge"),
LE("le"),
SA("sa"),
EB("eb"),
EQ("eq"),
NE("ne"),
GT("gt"),
LT("lt"),
GE("ge"),
LE("le"),
SA("sa"),
EB("eb"),
AP("ap");

private String value = null;
Expand All @@ -189,19 +183,19 @@ public static Prefix fromValue(String value) {

/**
* Types
*
*
* @author markd
*
*/
public enum Type {
NUMBER("number"),
DATE("date"),
STRING("string"),
TOKEN("token"),
REFERENCE("reference"),
COMPOSITE("composite"),
QUANTITY("quantity"),
URI("uri"),
NUMBER("number"),
DATE("date"),
STRING("string"),
TOKEN("token"),
REFERENCE("reference"),
COMPOSITE("composite"),
QUANTITY("quantity"),
URI("uri"),
SPECIAL("special");

private String value = null;
Expand Down Expand Up @@ -237,8 +231,8 @@ public enum Modifier {
ABOVE("above"),
NOT("not"),
NOT_IN("not-in"),
TYPE("[type]"),
OF_TYPE("of-type"),
TYPE("[type]"),
OF_TYPE("of-type"),
IDENTIFIER("identifier");

private String value = null;
Expand Down
Loading

0 comments on commit 6de4860

Please sign in to comment.