Skip to content

Commit

Permalink
Merge branch 'master' into draft-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TahaAttari authored Dec 19, 2024
2 parents 4b86c08 + b48b7fe commit e2ee08f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.utility.Canonicals;
import org.opencds.cqf.fhir.utility.Constants;
import org.opencds.cqf.fhir.utility.Parameters;
import org.opencds.cqf.fhir.utility.ValueSets;
import org.opencds.cqf.fhir.utility.adapter.IEndpointAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.IValueSetAdapter;
import org.opencds.cqf.fhir.utility.client.TerminologyServerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExpandHelper {

private static final Logger myLogger = LoggerFactory.getLogger(ExpandHelper.class);
private final Repository repository;
private final TerminologyServerClient terminologyServerClient;
public static final List<String> unsupportedParametersToRemove =
Expand Down Expand Up @@ -152,9 +155,8 @@ private IBaseBackboneElement expandIncludes(
var expansion = valueSet.newExpansion();
valueSet.getValueSetIncludes().forEach(reference -> {
// Grab the ValueSet
var split = reference.split("\\|");
var url = split.length == 1 ? reference : split[0];
var version = split.length == 1 ? null : split[1];
var url = Canonicals.getUrl(reference);
var version = Canonicals.getVersion(reference);
var includedVS =
getIncludedValueSet(valueSet, terminologyEndpoint, valueSets, repository, reference, url, version);
if (includedVS != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
import org.opencds.cqf.fhir.utility.adapter.IParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.IValueSetAdapter;
import org.opencds.cqf.fhir.utility.client.TerminologyServerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PackageVisitor extends BaseKnowledgeArtifactVisitor {
private static final Logger myLogger = LoggerFactory.getLogger(PackageVisitor.class);
private static final String CANONICAL_TYPE = "canonical";
private static final String CONFORMANCE_TYPE = "conformance";
private static final String KNOWLEDGE_ARTIFACT_TYPE = "knowledge";
Expand Down Expand Up @@ -195,29 +198,36 @@ protected void handleValueSets(IBaseBundle packagedBundle, Optional<IBaseResourc
var expansionCache = getExpansionCache();
var expansionParamsHash = expansionCache.map(
e -> e.getExpansionParametersHash(rootSpecificationLibrary).orElse(null));
var missingInCache = new ArrayList<>(valueSets);
if (expansionCache.isPresent()) {
var startCache = (new Date()).getTime();
valueSets.forEach(v -> {
var cachedExpansion = expansionCache
.get()
.getExpansionForCanonical(v.getCanonical(), expansionParamsHash.orElse(null));
if (cachedExpansion != null) {
v.setExpansion(cachedExpansion.getExpansion());
expandedList.add(v.getUrl());
missingInCache.remove(v);
}
});
var elapsed = String.valueOf(((new Date()).getTime() - startCache) / 1000);
myLogger.info("retrieved cached ValueSet Expansions in: {}s", elapsed);
}
valueSets.forEach(valueSet -> {
if (!expandedList.contains(valueSet.getUrl())) {
expandHelper.expandValueSet(
valueSet,
params,
terminologyEndpoint.map(e -> (IEndpointAdapter) createAdapterForResource(e)),
valueSets,
expandedList,
new Date());
if (expansionCache.isPresent()) {
expansionCache.get().addToCache(valueSet, expansionParamsHash.orElse(null));
}
missingInCache.forEach(valueSet -> {
var url = valueSet.getUrl();
var expansionStartTime = new Date().getTime();
expandHelper.expandValueSet(
valueSet,
params,
terminologyEndpoint.map(e -> (IEndpointAdapter) createAdapterForResource(e)),
valueSets,
expandedList,
new Date());
var elapsed = String.valueOf(((new Date()).getTime() - expansionStartTime) / 1000);
myLogger.info("Expanded {} in {}s", url, elapsed);
if (expansionCache.isPresent()) {
expansionCache.get().addToCache(valueSet, expansionParamsHash.orElse(null));
}
});
}
Expand Down

0 comments on commit e2ee08f

Please sign in to comment.