Skip to content

Commit

Permalink
issue #1777 - added tests and minor refactor
Browse files Browse the repository at this point in the history
1. added simple unit tests for the new ParametersMap behavior
2. added single e2e test to SearchTest to cover the case where the
compartment inclusion criteria parameter is filtered out in the config

Also, we now add the DO_NOT_STORE extension from SearchUtil instead of
as the parameters are added to the ParametersMap

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Feb 22, 2022
1 parent 21eeb11 commit 20fc22d
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 131 deletions.
21 changes: 17 additions & 4 deletions fhir-model/src/test/java/com/ibm/fhir/model/test/TestUtil.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* (C) Copyright IBM Corp. 2019, 2021
* (C) Copyright IBM Corp. 2019, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.model.test;

import static com.ibm.fhir.model.type.String.string;
import static org.testng.AssertJUnit.fail;

import java.io.File;
Expand Down Expand Up @@ -117,12 +116,26 @@ public static JsonObject getRequestJsonObject(String method, String url) {
* the specified patient via a subject attribute.
*/
public static Observation buildPatientObservation(String patientId, String fileName) throws Exception {
// TODO review Reference id
Observation observation = readLocalResource(fileName);

observation = observation
.toBuilder()
.subject(Reference.builder().reference(string("Patient/" + patientId)).build())
.subject(Reference.builder().reference("Patient/" + patientId).build())
.build();
return observation;
}

/**
* Loads an Observation resource from the specified file, then associates it with
* the specified patient via a subject attribute.
*/
public static Observation buildPatientObservation(String patientId, String practitionerId, String fileName) throws Exception {
Observation observation = readLocalResource(fileName);

observation = observation
.toBuilder()
.subject(Reference.builder().reference("Patient/" + patientId).build())
.performer(Reference.builder().reference("Practitioner/" + practitionerId).build())
.build();
return observation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.ibm.fhir.core.FHIRConstants;
import com.ibm.fhir.model.type.Code;
import com.ibm.fhir.model.type.Coding;
import com.ibm.fhir.model.type.Extension;
import com.ibm.fhir.model.type.Uri;
import com.ibm.fhir.search.exception.SearchExceptionUtil;

Expand Down Expand Up @@ -103,6 +104,10 @@ private SearchConstants() {

public static final String IMPLICIT_SYSTEM_EXT_URL = FHIRConstants.EXT_BASE + "implicit-system";
public static final String DO_NOT_STORE_EXT_URL = FHIRConstants.EXT_BASE + "do-not-store";
public static final Extension DO_NOT_STORE_EXT = Extension.builder()
.url(SearchConstants.DO_NOT_STORE_EXT_URL)
.value(true)
.build();

// Extracted search parameter suffix for :identifier modifier
public static final String IDENTIFIER_MODIFIER_SUFFIX = ":identifier";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.stream.Collectors;

import com.ibm.fhir.model.resource.SearchParameter;
import com.ibm.fhir.model.type.Extension;
import com.ibm.fhir.search.SearchConstants;

/**
* A multi-key map that indexes a set of search parameters by SearchParameter.code and
Expand All @@ -29,11 +27,6 @@ public class ParametersMap {

public static final String MISSING_EXPRESSION_WARNING = "Skipping parameter '%s' with missing expression";

public static final Extension DO_NOT_STORE = Extension.builder()
.url(SearchConstants.DO_NOT_STORE_EXT_URL)
.value(true)
.build();

private final Map<String, SearchParameter> codeMap;
private final Map<String, SearchParameter> canonicalMap;

Expand Down Expand Up @@ -108,10 +101,6 @@ public void insertInclusionParam(String code, SearchParameter parameter) {
SearchParameter previous = inclusionParamMap.get(code);
logParamConflict("inclusion criteria '" + code + "'", parameter, ParametersUtil.getCanonicalUrl(parameter), previous);
}

parameter = parameter.toBuilder()
.extension(DO_NOT_STORE)
.build();
inclusionParamMap.put(code, parameter);
}

Expand Down Expand Up @@ -174,6 +163,14 @@ public Set<Entry<String, SearchParameter>> codeEntries() {
return Collections.unmodifiableSet(codeMap.entrySet());
}

public Collection<SearchParameter> inclusionValues() {
// use List to preserve order
return Collections.unmodifiableList(inclusionParamMap.entrySet().stream()
.filter(e -> !e.getKey().contains("|"))
.map(e -> e.getValue())
.collect(Collectors.toList()));
}

/**
* @implSpec Note that versioned search parameters will be listed twice;
* once with their version and once without
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ public final class ParametersUtil {

// Logging:
public static final String LOG_PARAMETERS = "Parameter is loaded -> %s";
public static final String LOG_HEADER = "BASE:RESOURCE_NAME:SearchParameter";
public static final String LOG_SIZE = "Size: %s";
private static final String LOG_OUTPUT = "%s|%s|%s";
public static final String LOG_HEADER = "ResourceType | SearchParameter.code | SearchParameter.expression\n"
+ "'*' denotes compartment inclusion criteria parameters";
public static final String LOG_SIZE = "Number of resource types: %s";
private static final String LOG_OUTPUT = "%s | %s | %s";

private static final String LEFT = "[";
private static final String RIGHT = "]";
Expand Down Expand Up @@ -370,6 +371,13 @@ private static void print(PrintStream out, Map<String, ParametersMap> searchPara
}
out.println(String.format(LOG_OUTPUT, base, param.getCode().getValue(), expression));
}
for(SearchParameter param : tmp.inclusionValues()) {
String expression = MISSING_EXPRESSION;
if (param.getExpression() != null) {
expression = param.getExpression().getValue();
}
out.println(String.format(LOG_OUTPUT, "*" + base, param.getCode().getValue(), expression));
}
out.println(SearchConstants.LOG_BOUNDARY);
}
out.println(SearchConstants.LOG_BOUNDARY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ public static Map<SearchParameter, List<FHIRPathNode>> extractParameterValues(Re
if (!COMPARTMENT_PARM_DEF.equals(inclusionParamName) && !parameters.containsKey(inclusionParamName)) {
String tenantId = FHIRRequestContext.get().getTenantId();
ParametersMap parametersMap = ParametersUtil.getTenantSPs(tenantId).get(resourceType.getSimpleName());
parameters.put(inclusionParamName, parametersMap.getInclusionParam(inclusionParamName));
SearchParameter inclusionParam = parametersMap.getInclusionParam(inclusionParamName).toBuilder()
.extension(SearchConstants.DO_NOT_STORE_EXT)
.build();
parameters.put(inclusionParamName, inclusionParam);
}
}

Expand Down
Loading

0 comments on commit 20fc22d

Please sign in to comment.