-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f6a6cc
commit 1799a09
Showing
12 changed files
with
146 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
api/src/main/java/com/lantanagroup/link/api/MeasureDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.lantanagroup.link.api; | ||
|
||
import com.lantanagroup.link.StreamUtils; | ||
import lombok.Getter; | ||
import org.hl7.fhir.instance.model.api.IBaseResource; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
import org.hl7.fhir.r4.model.Measure; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public class MeasureDef { | ||
private final Measure measure; | ||
private final List<IBaseResource> resources; | ||
|
||
public MeasureDef(Bundle bundle) { | ||
measure = bundle.getEntry().stream() | ||
.map(Bundle.BundleEntryComponent::getResource) | ||
.filter(resource -> resource instanceof Measure) | ||
.map(resource -> (Measure) resource) | ||
.reduce(StreamUtils::toOnlyElement) | ||
.orElseThrow(); | ||
|
||
// Ensure all populations have an ID | ||
for (Measure.MeasureGroupComponent group : measure.getGroup()) { | ||
for (Measure.MeasureGroupPopulationComponent population : group.getPopulation()) { | ||
if (!population.hasId()) { | ||
population.setId(population.getCode().getCodingFirstRep().getCode()); | ||
} | ||
} | ||
} | ||
|
||
resources = bundle.getEntry().stream() | ||
.map(Bundle.BundleEntryComponent::getResource) | ||
.filter(resource -> !(resource instanceof Measure)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
api/src/main/java/com/lantanagroup/link/api/MeasureService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.lantanagroup.link.api; | ||
|
||
import com.lantanagroup.link.Constants; | ||
import com.lantanagroup.link.FhirContextProvider; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.hl7.fhir.instance.model.api.IBaseResource; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
import org.hl7.fhir.r4.model.Coding; | ||
import org.hl7.fhir.r4.model.Endpoint; | ||
import org.hl7.fhir.r4.model.MeasureReport; | ||
import org.opencds.cqf.fhir.api.Repository; | ||
import org.opencds.cqf.fhir.cql.EvaluationSettings; | ||
import org.opencds.cqf.fhir.cql.engine.retrieve.RetrieveSettings; | ||
import org.opencds.cqf.fhir.cql.engine.terminology.TerminologySettings; | ||
import org.opencds.cqf.fhir.cr.measure.MeasureEvaluationOptions; | ||
import org.opencds.cqf.fhir.cr.measure.r4.R4MeasureService; | ||
import org.opencds.cqf.fhir.utility.monad.Eithers; | ||
import org.opencds.cqf.fhir.utility.repository.InMemoryFhirRepository; | ||
|
||
public class MeasureService { | ||
private final MeasureDef measureDef; | ||
private final R4MeasureService measureService; | ||
private final Endpoint terminologyEndpoint; | ||
|
||
public MeasureService(Bundle measureDefBundle, String terminologyService) { | ||
measureDef = new MeasureDef(measureDefBundle); | ||
Repository repository = new InMemoryFhirRepository(FhirContextProvider.getFhirContext()); | ||
for (IBaseResource resource : measureDef.getResources()) { | ||
repository.update(resource); | ||
} | ||
MeasureEvaluationOptions options = MeasureEvaluationOptions.defaultOptions(); | ||
EvaluationSettings evaluationSettings = options.getEvaluationSettings(); | ||
evaluationSettings.getTerminologySettings() | ||
.setValuesetPreExpansionMode(TerminologySettings.VALUESET_PRE_EXPANSION_MODE.USE_IF_PRESENT) | ||
.setValuesetExpansionMode(TerminologySettings.VALUESET_EXPANSION_MODE.PERFORM_NAIVE_EXPANSION) | ||
.setValuesetMembershipMode(TerminologySettings.VALUESET_MEMBERSHIP_MODE.USE_EXPANSION) | ||
.setCodeLookupMode(TerminologySettings.CODE_LOOKUP_MODE.USE_CODESYSTEM_URL); | ||
evaluationSettings.getRetrieveSettings() | ||
.setTerminologyParameterMode(RetrieveSettings.TERMINOLOGY_FILTER_MODE.FILTER_IN_MEMORY) | ||
.setSearchParameterMode(RetrieveSettings.SEARCH_FILTER_MODE.FILTER_IN_MEMORY) | ||
.setProfileMode(RetrieveSettings.PROFILE_MODE.DECLARED); | ||
measureService = new R4MeasureService(repository, options); | ||
terminologyEndpoint = getTerminologyEndpoint(terminologyService); | ||
} | ||
|
||
private static Endpoint getTerminologyEndpoint(String terminologyService) { | ||
if (StringUtils.isEmpty(terminologyService)) { | ||
return null; | ||
} | ||
Endpoint endpoint = new Endpoint(); | ||
endpoint.setStatus(Endpoint.EndpointStatus.ACTIVE); | ||
endpoint.setConnectionType(new Coding()); | ||
endpoint.getConnectionType().setSystem(Constants.TerminologyEndpointSystem); | ||
endpoint.getConnectionType().setCode(Constants.TerminologyEndpointCode); | ||
endpoint.setAddress(terminologyService); | ||
return endpoint; | ||
} | ||
|
||
public void preCompile() { | ||
evaluate(null, null, null, null); | ||
} | ||
|
||
public MeasureReport evaluate(String periodStart, String periodEnd, String subject, Bundle additionalData) { | ||
return measureService.evaluate( | ||
Eithers.forRight3(measureDef.getMeasure()), | ||
periodStart, | ||
periodEnd, | ||
null, | ||
subject, | ||
null, | ||
null, | ||
terminologyEndpoint, | ||
null, | ||
additionalData, | ||
null, | ||
null, | ||
null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.