Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@
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,11 +41,12 @@
this.retrieveSettings = new RetrieveSettings();
this.terminologySettings = new TerminologySettings();
this.npmProcessor = null;
this.registeredNamespaces = new ConcurrentHashMap<>();
}

/**
* Copy constructor for EvaluationSettings
* @param settings
* @param settings The EvaluationSettings being copied
*/
public EvaluationSettings(EvaluationSettings settings) {
this.modelCache = new ConcurrentHashMap<>(settings.modelCache);
Expand All @@ -56,6 +58,7 @@
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,28 @@
setNpmProcessor(npmProcessor);
return this;
}

/***
* Returns a map of the registered namespaces with the key being the name and the value being the uri of the namespace
* @return The map of registered namespaces
*/
public Map<String, String> getRegisteredNamespaces() {
return registeredNamespaces;
}

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

public EvaluationSettings withRegisteredNamespaces(Map<String, String> namespaces) {
setRegisteredNamespaces(namespaces);
return this;
}

public EvaluationSettings addRegisteredNamespace(String name, String uri) {
if (!registeredNamespaces.containsKey(name)) {

Check warning on line 186 in cqf-fhir-cql/src/main/java/org/opencds/cqf/fhir/cql/EvaluationSettings.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this "Map.containsKey()" with a call to "Map.computeIfAbsent()".

See more on https://sonarcloud.io/project/issues?id=cqframework_clinical-reasoning&issues=AZzi2EJbPBpoWfrDpOnH&open=AZzi2EJbPBpoWfrDpOnH&pullRequest=965
registeredNamespaces.put(name, uri);
}
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,31 @@ 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 name2 = "com.smiledigitalhealth.greatreef";
var uri2 = "http://smile.org/greatreef";
settings.addRegisteredNamespace(name2, uri2);
var engine = getEngine(settings);
assertEquals(
uri,
engine.getEnvironment()
.getLibraryManager()
.getNamespaceManager()
.resolveNamespaceUri(name));
assertEquals(
uri2,
engine.getEnvironment()
.getLibraryManager()
.getNamespaceManager()
.resolveNamespaceUri(name2));
}

/**
* 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 +545,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 +558,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 +600,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 +614,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