Skip to content

Commit

Permalink
Introduce SubjectProviderOptions and associate it with MeasureEvaluat…
Browse files Browse the repository at this point in the history
…ionOptions. Use conditional logic in R4RepositorySubjectProvider to choose whether to perform a chained partOf query.
  • Loading branch information
lukedegruchy committed Nov 18, 2024
1 parent eeaa0e0 commit e7deda8
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,43 @@ public static MeasureEvaluationOptions defaultOptions() {

private boolean isValidationEnabled = false;
private Map<String, ValidationProfile> validationProfiles = new HashMap<>();
private SubjectProviderOptions subjectProviderOptions;

private EvaluationSettings evaluationSettings = null;

public boolean isValidationEnabled() {
return this.isValidationEnabled;
}

public void setValidationEnabled(boolean enableValidation) {
public MeasureEvaluationOptions setValidationEnabled(boolean enableValidation) {
this.isValidationEnabled = enableValidation;
return this;
}

public Map<String, ValidationProfile> getValidationProfiles() {
return validationProfiles;
}

public void setValidationProfiles(Map<String, ValidationProfile> validationProfiles) {
public MeasureEvaluationOptions setValidationProfiles(Map<String, ValidationProfile> validationProfiles) {
this.validationProfiles = validationProfiles;
return this;
}

public void setEvaluationSettings(EvaluationSettings evaluationSettings) {
public MeasureEvaluationOptions setEvaluationSettings(EvaluationSettings evaluationSettings) {
this.evaluationSettings = evaluationSettings;
return this;
}

public EvaluationSettings getEvaluationSettings() {
return this.evaluationSettings;
}

public SubjectProviderOptions getSubjectProviderOptions() {
return subjectProviderOptions;
}

public MeasureEvaluationOptions setSubjectProviderOptions(SubjectProviderOptions theSubjectProviderOptions) {
this.subjectProviderOptions = theSubjectProviderOptions;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.opencds.cqf.fhir.cr.measure;

// LUKETODO: javadoc
public class SubjectProviderOptions {

private boolean isPartOfEnabled;

public boolean isPartOfEnabled() {
return isPartOfEnabled;
}

public SubjectProviderOptions setPartOfEnabled(boolean thePartOfEnabled) {
isPartOfEnabled = thePartOfEnabled;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class R4CareGapsProcessor {
private final Map<String, Resource> configuredResources = new HashMap<>();
private final R4MeasureServiceUtils r4MeasureServiceUtils;
private final R4CareGapsBundleBuilder r4CareGapsBundleBuilder;
private final R4RepositorySubjectProvider subjectProvider;

public R4CareGapsProcessor(
CareGapsProperties careGapsProperties,
Expand All @@ -59,6 +60,7 @@ public R4CareGapsProcessor(
serverBase,
configuredResources,
measurePeriodValidator);
subjectProvider = new R4RepositorySubjectProvider(measureEvaluationOptions.getSubjectProviderOptions());
}

public Parameters getCareGapsReport(
Expand Down Expand Up @@ -125,7 +127,6 @@ protected List<Measure> resolveMeasure(List<Either3<IdType, String, CanonicalTyp
}

protected List<String> getSubjects(String subject) {
R4RepositorySubjectProvider subjectProvider = new R4RepositorySubjectProvider();
var subjects = subjectProvider.getSubjects(repository, null, subject).collect(Collectors.toList());
if (!subjects.isEmpty()) {
ourLog.info(String.format("care-gaps report requested for: %s subjects.", subjects.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
public class R4CollectDataService {
private final Repository repository;
private final MeasureEvaluationOptions measureEvaluationOptions;
private final R4RepositorySubjectProvider subjectProvider;

public R4CollectDataService(Repository repository, MeasureEvaluationOptions measureEvaluationOptions) {
this.repository = repository;
this.measureEvaluationOptions = measureEvaluationOptions;
subjectProvider = new R4RepositorySubjectProvider(
measureEvaluationOptions.getSubjectProviderOptions());
}

/**
Expand Down Expand Up @@ -57,7 +60,6 @@ public Parameters collectData(
String practitioner) {

Parameters parameters = new Parameters();
var subjectProvider = new R4RepositorySubjectProvider();
var processor = new R4MeasureProcessor(this.repository, this.measureEvaluationOptions, subjectProvider);

// getSubjects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class R4MeasureService implements R4MeasureEvaluatorSingle {
private final Repository repository;
private final MeasureEvaluationOptions measureEvaluationOptions;
private final MeasurePeriodValidator measurePeriodValidator;
private R4RepositorySubjectProvider subjectProvider;

public R4MeasureService(
Repository repository,
Expand All @@ -30,6 +31,8 @@ public R4MeasureService(
this.repository = repository;
this.measureEvaluationOptions = measureEvaluationOptions;
this.measurePeriodValidator = measurePeriodValidator;
this.subjectProvider = new R4RepositorySubjectProvider(
measureEvaluationOptions.getSubjectProviderOptions());
}

@Override
Expand All @@ -51,7 +54,7 @@ public MeasureReport evaluate(
measurePeriodValidator.validatePeriodStartAndEnd(periodStart, periodEnd);

var repo = Repositories.proxy(repository, true, dataEndpoint, contentEndpoint, terminologyEndpoint);
var processor = new R4MeasureProcessor(repo, this.measureEvaluationOptions, new R4RepositorySubjectProvider());
var processor = new R4MeasureProcessor(repo, this.measureEvaluationOptions, subjectProvider);

R4MeasureServiceUtils r4MeasureServiceUtils = new R4MeasureServiceUtils(repository);
r4MeasureServiceUtils.ensureSupplementalDataElementSearchParameter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public R4MultiMeasureService(
this.measurePeriodValidator = measurePeriodValidator;
this.serverBase = serverBase;

subjectProvider = new R4RepositorySubjectProvider();
subjectProvider = new R4RepositorySubjectProvider(measureEvaluationOptions.getSubjectProviderOptions());

r4Processor = new R4MeasureProcessor(repository, this.measureEvaluationOptions, subjectProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jakarta.annotation.Nullable;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Group;
import org.hl7.fhir.r4.model.Group.GroupMemberComponent;
import org.hl7.fhir.r4.model.Group.GroupType;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.ResourceType;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.cr.measure.SubjectProviderOptions;
import org.opencds.cqf.fhir.cr.measure.common.MeasureEvalType;
import org.opencds.cqf.fhir.cr.measure.common.MeasureEvaluator;
import org.opencds.cqf.fhir.cr.measure.common.SubjectProvider;
Expand All @@ -32,14 +36,15 @@ public class R4RepositorySubjectProvider implements SubjectProvider {

private static final Logger logger = LoggerFactory.getLogger(MeasureEvaluator.class);

private enum OrganizationMode {
NONE,
PART_OF
private final SubjectProviderOptions subjectProviderOptions;

public R4RepositorySubjectProvider(SubjectProviderOptions subjectProviderOptions) {
this.subjectProviderOptions = subjectProviderOptions;
}

@Override
public Stream<String> getSubjects(Repository repository, MeasureEvalType measureEvalType, String subjectId) {
return getSubjects(repository, measureEvalType, List.of(subjectId));
public Stream<String> getSubjects(Repository repository, MeasureEvalType measureEvalType, @Nullable String subjectId) {
return getSubjects(repository, measureEvalType, Collections.singletonList(subjectId));
}

@Override
Expand Down Expand Up @@ -165,7 +170,7 @@ private List<String> getOrganizationSubjectIds(
return Stream.concat(
getManagingOrganizationSubjectIds(organization, repository),
getPartOfSubjectIds(organization, repository)
).toList();
).collect(Collectors.toUnmodifiableList());
}

private Stream<String> getManagingOrganizationSubjectIds(String organization, Repository repository) {
Expand All @@ -189,6 +194,10 @@ private Stream<String> getManagingOrganizationSubjectIds(String organization, Re

private Stream<String> getPartOfSubjectIds(String organization, Repository repository) {

if (! subjectProviderOptions.isPartOfEnabled()) {
return Stream.empty();
}

final Map<String, List<IQueryParameterType>> searchParam = new HashMap<>();

searchParam.put(
Expand All @@ -207,6 +216,6 @@ private Stream<String> getPartOfSubjectIds(String organization, Repository repos
// TODO: JM, address next link if populated in future interation of feature.
// if results expand beyond paging limit of a bundle, a warning will pop to the user.
// This is unlikely to ever be an issue in a real deployment, but should be addressed at some point.
.map(Patient::getIdPart);
.map(idElement -> String.format("%s/%s", ResourceType.Patient, idElement.getIdPart()));
}
}

0 comments on commit e7deda8

Please sign in to comment.