Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ private static Environment buildEnvironment(
.getNamespaceManager()
.ensureNamespaceRegistered(new NamespaceInfo("hl7.fhir.us.cql", "http://hl7.org/fhir/us/cql"));

// Register any namespaces added to the settings
settings.getRegisteredNamespaces()
.forEach((name, uri) ->
libraryManager.getNamespaceManager().ensureNamespaceRegistered(new NamespaceInfo(name, uri)));

return new Environment(libraryManager, dataProviders, terminologyProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class EvaluationSettings {
private Map<VersionedIdentifier, CompiledLibrary> libraryCache;
private Map<String, List<Code>> valueSetCache;
private List<LibrarySourceProvider> librarySourceProviders;
private Map<String, String> registeredNamespaces;

private CqlOptions cqlOptions;

Expand All @@ -40,6 +41,7 @@ public static EvaluationSettings getDefault() {
this.retrieveSettings = new RetrieveSettings();
this.terminologySettings = new TerminologySettings();
this.npmProcessor = null;
this.registeredNamespaces = new ConcurrentHashMap<>();
}

/**
Expand All @@ -56,6 +58,7 @@ public EvaluationSettings(EvaluationSettings settings) {
this.librarySourceProviders = new ArrayList<>(settings.librarySourceProviders);
this.npmProcessor =
settings.npmProcessor != null ? new NpmProcessor(settings.npmProcessor.getIgContext()) : null;
this.registeredNamespaces = new ConcurrentHashMap<>(settings.registeredNamespaces);
}

public Map<ModelIdentifier, Model> getModelCache() {
Expand Down Expand Up @@ -161,4 +164,17 @@ public EvaluationSettings withNpmProcessor(NpmProcessor npmProcessor) {
setNpmProcessor(npmProcessor);
return this;
}

public Map<String, String> getRegisteredNamespaces() {
return registeredNamespaces;
}

public void setRegisteredNamespaces(Map<String, String> namespaces) {
this.registeredNamespaces = namespaces;
}

public EvaluationSettings withRegisteredNamespaces(Map<String, String> namespaces) {
setRegisteredNamespaces(namespaces);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.cqframework.cql.cql2elm.StringLibrarySourceProvider;
Expand Down Expand Up @@ -377,6 +378,22 @@ void getCqlFhirParametersConverter() {
assertNotNull(Engines.getCqlFhirParametersConverter(FhirContext.forR4Cached()));
}

@Test
void additionalNamespacesRegistered() {
var name = "com.organization.common";
var uri = "http://com.organization.common";
var namespaces = new ConcurrentHashMap<String, String>();
namespaces.put(name, uri);
var settings = new EvaluationSettings().withRegisteredNamespaces(namespaces);
var engine = getEngine(settings);
assertEquals(
uri,
engine.getEnvironment()
.getLibraryManager()
.getNamespaceManager()
.resolveNamespaceUri(name));
}

/**
* All created resources must have an SP that identifies
* a field that *does not have* a date value between 2000-01-01 and 2000-12-31 eod
Expand Down Expand Up @@ -519,7 +536,7 @@ static List<Arguments> successfulParameters() {

@ParameterizedTest
@MethodSource("successfulParameters")
public void retrieve_withValidDatesInRange_succeeds(IBaseResource resource, String spName) {
void retrieve_withValidDatesInRange_succeeds(IBaseResource resource, String spName) {
// test
var results = retrieveResourcesWithin2000BySPName(resource, spName);

Expand All @@ -532,7 +549,7 @@ public void retrieve_withValidDatesInRange_succeeds(IBaseResource resource, Stri

@ParameterizedTest
@MethodSource("failureParameters")
public void retrieve_withValidDatesOutOfRange_failToRetrieve(IBaseResource resource, String spName) {
void retrieve_withValidDatesOutOfRange_failToRetrieve(IBaseResource resource, String spName) {
// setup
IParser parser = repository.fhirContext().newJsonParser();

Expand Down Expand Up @@ -574,7 +591,7 @@ private Iterable<Object> retrieveResourcesWithin2000BySPName(IBaseResource resou
var dateRange = new Interval(start, true, end, true);

// Retrieve resources with period overlapping 2000
var results = dataProvider.retrieve(
return dataProvider.retrieve(
resourceType, // context
null, // contextPath
"pat1", // contextValue
Expand All @@ -588,12 +605,10 @@ private Iterable<Object> retrieveResourcesWithin2000BySPName(IBaseResource resou
"period.end", // dateHighPath
dateRange // dateRange
);

return results;
}

@Test
public void dateFiltering() {
void dateFiltering() {
// setup
RetrieveSettings retrieveSettings = new RetrieveSettings();
retrieveSettings.setSearchParameterMode(SEARCH_FILTER_MODE.FILTER_IN_MEMORY);
Expand Down
Loading