Skip to content

Commit

Permalink
post-merge updates
Browse files Browse the repository at this point in the history
Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
lmsurpre committed Oct 18, 2021
1 parent ff520bf commit e34f78b
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import static com.ibm.fhir.cql.helpers.ModelHelper.concept;
import static com.ibm.fhir.cql.helpers.ModelHelper.fhirboolean;
import static com.ibm.fhir.cql.helpers.ModelHelper.fhirstring;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -20,12 +18,14 @@
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail;

import javax.ws.rs.core.MultivaluedMap;

import org.testng.annotations.Test;
import org.mockito.MockedStatic;
import org.testng.annotations.Test;

import com.ibm.fhir.cql.Constants;
import com.ibm.fhir.cql.helpers.LibraryHelper;
Expand Down Expand Up @@ -63,8 +63,15 @@ public void testInlineExpression() throws Exception {
String encounterCode = "office-visit";
Coding reason = coding(codesystem, encounterCode);

Encounter encounter =
Encounter.builder().reasonCode(concept(reason)).status(EncounterStatus.FINISHED).clazz(reason).period(Period.builder().start(DateTime.now()).end(DateTime.now()).build()).build();
Encounter encounter = Encounter.builder()
.reasonCode(concept(reason))
.status(EncounterStatus.FINISHED)
.clazz(reason)
.period(Period.builder()
.start(DateTime.now())
.end(DateTime.now())
.build())
.build();

String expression = "[Encounter] e where e.status = 'finished'";

Expand All @@ -85,7 +92,7 @@ public void testInlineExpression() throws Exception {

// when(mockRegistry.getResource(javastring(fhirHelpers.getUrl()), Library.class)).thenReturn(fhirHelpers);

FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext();
FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext(null);
Parameters result = getOperation().doInvoke(ctx, null, null, null, parameters, resourceHelper);
assertNotNull(result);

Expand Down Expand Up @@ -136,7 +143,7 @@ public void testInlineExpressionWithIncludes() throws Exception {
canonical = ModelHelper.canonical(modelInfo.getUrl(), modelInfo.getVersion());
when(mockRegistry.getResource(canonical.getValue(), Library.class)).thenReturn(modelInfo);

FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext();
FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext("cql");
getOperation().doInvoke(ctx, null, null, null, parameters, resourceHelper);
}
}
Expand All @@ -158,7 +165,7 @@ public void testInlineExpressionInvalid() throws Exception {
FHIRRegistry mockRegistry = spy(FHIRRegistry.class);
staticRegistry.when(FHIRRegistry::getInstance).thenReturn(mockRegistry);

FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext();
FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext("cql");
getOperation().doInvoke(ctx, null, null, null, parameters, resourceHelper);
fail("Missing expected Exception");
} catch (FHIROperationException fex) {
Expand Down Expand Up @@ -189,7 +196,7 @@ public void testInlineExpressionWithDebug() throws Exception {
FHIRRegistry mockRegistry = spy(FHIRRegistry.class);
staticRegistry.when(FHIRRegistry::getInstance).thenReturn(mockRegistry);

FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext();
FHIROperationContext ctx = FHIROperationContext.createSystemOperationContext("cql");
Parameters result = getOperation().doInvoke(ctx, null, null, null, parameters, resourceHelper);

assertNotNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import static com.ibm.fhir.cql.helpers.ModelHelper.concept;
import static com.ibm.fhir.cql.helpers.ModelHelper.fhirstring;
import static com.ibm.fhir.cql.helpers.ModelHelper.valueset;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -23,14 +21,16 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertSame;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;

import org.mockito.MockedStatic;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.mockito.MockedStatic;

import com.ibm.fhir.cql.helpers.ParameterMap;
import com.ibm.fhir.model.resource.Bundle;
Expand Down Expand Up @@ -70,8 +70,15 @@ public void testDoEvaluationEXM74() throws Exception {
String codesystem = "http://snomed.ct/info";
String encounterCode = "office-visit";
Coding reason = coding(codesystem, encounterCode);
Encounter encounter =
Encounter.builder().reasonCode(concept(reason)).status(EncounterStatus.FINISHED).clazz(reason).period(Period.builder().start(DateTime.now()).end(DateTime.now()).build()).build();
Encounter encounter = Encounter.builder()
.reasonCode(concept(reason))
.status(EncounterStatus.FINISHED)
.clazz(reason)
.period(Period.builder()
.start(DateTime.now())
.end(DateTime.now())
.build())
.build();

String procedureCode = "fluoride-application";
Coding type = coding(codesystem, procedureCode);
Expand Down Expand Up @@ -116,7 +123,7 @@ public void testDoEvaluationEXM74() throws Exception {
fhirLibraries.stream().forEach(l -> when(mockRegistry.getResource(canonical(l.getUrl(), l.getVersion()).getValue(), Library.class)).thenReturn(l));

Parameters result =
operation.doInvoke(FHIROperationContext.createResourceTypeOperationContext(), Measure.class, null, null, parameters, resourceHelper);
operation.doInvoke(FHIROperationContext.createResourceTypeOperationContext("care-gap"), Measure.class, null, null, parameters, resourceHelper);
assertNotNull(result);

ParameterMap resultMap = new ParameterMap(result);
Expand All @@ -127,7 +134,7 @@ public void testDoEvaluationEXM74() throws Exception {

@SuppressWarnings("unchecked")
protected SingleResourceResult<? extends Resource> asResult(Resource patient) {
SingleResourceResult<Resource> result = (SingleResourceResult<Resource>) mock(SingleResourceResult.class);
SingleResourceResult<Resource> result = mock(SingleResourceResult.class);
when(result.isSuccess()).thenReturn(true);
when(result.getResource()).thenReturn(patient);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import static com.ibm.fhir.cql.helpers.ModelHelper.concept;
import static com.ibm.fhir.cql.helpers.ModelHelper.fhirstring;
import static com.ibm.fhir.cql.helpers.ModelHelper.valueset;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -21,6 +19,8 @@
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

import java.time.LocalDate;
import java.time.LocalTime;
Expand All @@ -31,9 +31,9 @@
import java.util.List;
import java.util.stream.Collectors;

import org.mockito.MockedStatic;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.mockito.MockedStatic;

import com.ibm.fhir.cql.helpers.ParameterMap;
import com.ibm.fhir.model.resource.Encounter;
Expand All @@ -57,86 +57,86 @@
import com.ibm.fhir.server.operation.spi.FHIRResourceHelpers;

public class EvaluateMeasureOperationTest {

private EvaluateMeasureOperation operation;

@BeforeMethod
public void setup() {
operation = new EvaluateMeasureOperation();
}

@Test
public void testDoEvaluationEXM74() throws Exception {
Patient patient = (Patient) TestHelper.getTestResource("Patient.json");

String codesystem = "http://snomed.ct/info";
String encounterCode = "office-visit";
Coding reason = coding(codesystem, encounterCode);
Coding reason = coding(codesystem, encounterCode);
Encounter encounter = Encounter.builder()
.reasonCode(concept(reason))
.status(EncounterStatus.FINISHED)
.clazz(reason)
.period(Period.builder().start(DateTime.now()).end(DateTime.now()).build())
.build();

String procedureCode = "fluoride-application";
Coding type = coding(codesystem, procedureCode);
Procedure procedure = Procedure.builder().subject(Reference.builder().reference(fhirstring("Patient/"
+ patient.getId())).build()).code(concept(type)).status(ProcedureStatus.COMPLETED).performed(DateTime.of("2019-03-14")).build();

List<Measure> measures = TestHelper.getBundleResources("EXM74-10.2.000-request.json", Measure.class);
assertEquals( measures.size(), 1 );
Measure measure = measures.get(0);
String measureURL = canonical(measure.getUrl(), measure.getVersion()).getValue();

List<Library> fhirLibraries = TestHelper.getBundleResources("EXM74-10.2.000-request.json", Library.class);

List<String> names = fhirLibraries.stream().map( l -> l.getName().getValue()).collect(Collectors.toList());
System.out.println(names);

LocalDate periodStart = LocalDate.of(2000, 1, 1);
LocalDate periodEnd = periodStart.plus(1, ChronoUnit.YEARS);

Parameters.Parameter pPeriodStart = Parameters.Parameter.builder().name(fhirstring(EvaluateMeasureOperation.PARAM_IN_PERIOD_START)).value(Date.of(periodStart)).build();
Parameters.Parameter pPeriodEnd = Parameters.Parameter.builder().name(fhirstring(EvaluateMeasureOperation.PARAM_IN_PERIOD_END)).value(Date.of(periodEnd)).build();
Parameters.Parameter pReportType = Parameters.Parameter.builder().name(fhirstring(EvaluateMeasureOperation.PARAM_IN_REPORT_TYPE)).value(MeasureReportType.INDIVIDUAL).build();
Parameters.Parameter pMeasure = Parameters.Parameter.builder().name(fhirstring(EvaluateMeasureOperation.PARAM_IN_MEASURE)).value(fhirstring(measureURL)).build();
Parameters.Parameter pSubject = Parameters.Parameter.builder().name(fhirstring(EvaluateMeasureOperation.PARAM_IN_SUBJECT)).value(fhirstring("Patient/" + patient.getId())).build();

Parameters parameters = Parameters.builder().parameter(pPeriodStart, pPeriodEnd, pReportType, pMeasure, pSubject).build();

FHIRResourceHelpers resourceHelper = mock(FHIRResourceHelpers.class);
when(resourceHelper.doRead(eq("Patient"), eq(patient.getId()), anyBoolean(), anyBoolean(), any())).thenAnswer(x -> TestHelper.asResult(patient));

when(resourceHelper.doSearch(eq("Encounter"), anyString(), anyString(), any(), anyString(), any())).thenReturn( bundle(encounter) );
when(resourceHelper.doSearch(eq("Procedure"), anyString(), anyString(), any(), anyString(), any())).thenReturn( bundle(procedure) );

try (MockedStatic<FHIRRegistry> staticRegistry = mockStatic(FHIRRegistry.class)) {
FHIRRegistry mockRegistry = spy(FHIRRegistry.class);
staticRegistry.when(FHIRRegistry::getInstance).thenReturn(mockRegistry);


when(mockRegistry.getResource("http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.101.12.1001", ValueSet.class)).thenReturn( valueset(codesystem, encounterCode) );
when(mockRegistry.getResource("http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.125.12.1002", ValueSet.class)).thenReturn( valueset(codesystem, procedureCode) );

when(mockRegistry.getResource(measureURL, Measure.class)).thenReturn( measure );
fhirLibraries.stream().forEach( l -> when(mockRegistry.getResource( canonical(l.getUrl(), l.getVersion()).getValue(), Library.class )).thenReturn(l) );
Parameters result = operation.doInvoke(FHIROperationContext.createResourceTypeOperationContext(),

Parameters result = operation.doInvoke(FHIROperationContext.createResourceTypeOperationContext("evaluate-measure"),
Measure.class, null, null, parameters, resourceHelper);
assertNotNull(result);

ParameterMap resultMap = new ParameterMap(result);
MeasureReport report = (MeasureReport) resultMap.getSingletonParameter(EvaluateMeasureOperation.PARAM_OUT_RETURN).getResource();
assertEquals( report.getMeasure().getValue(), measureURL );

ZoneOffset zoneOffset = OffsetDateTime.now().getOffset();
ZonedDateTime expectedStart = OffsetDateTime.of(periodStart, LocalTime.MIN, zoneOffset).toZonedDateTime();
ZonedDateTime expectedEnd= OffsetDateTime.of(periodEnd, LocalTime.MAX, zoneOffset).toZonedDateTime();

Period expectedPeriod = Period.builder().start(DateTime.of(expectedStart)).end(DateTime.of(expectedEnd)).build();
assertEquals( report.getPeriod(), expectedPeriod );

assertEquals( report.getGroup().size(), 1 );
MeasureReport.Group group = report.getGroup().get(0);
assertEquals( group.getPopulation().size(), 3 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
import com.ibm.fhir.server.operation.spi.FHIROperationContext;

public class LibraryDataRequirementsOperationTest extends BaseDataRequirementsOperationTest {

@Test
public void testInstanceLibrary() throws Exception {
runTest( FHIROperationContext.createInstanceOperationContext(), Library.class, primaryLibrary -> primaryLibrary.getId(), primaryLibrary -> null );
runTest( FHIROperationContext.createInstanceOperationContext("data-requirements"), Library.class, primaryLibrary -> primaryLibrary.getId(), primaryLibrary -> null );
}

@Test
public void testSystemLibrary() throws Exception {
runTest( FHIROperationContext.createSystemOperationContext(), null, primaryLibrary -> null, primaryLibrary -> {
runTest( FHIROperationContext.createSystemOperationContext("data-requirements"), null, primaryLibrary -> null, primaryLibrary -> {
return Parameters.builder().parameter( Parameters.Parameter.builder().name(fhirstring("target")).value(fhirstring(primaryLibrary.getId())).build()).build();
});
}


@Override
public AbstractDataRequirementsOperation getOperation() {
return new LibraryDataRequirementsOperation();
}
Expand Down
Loading

0 comments on commit e34f78b

Please sign in to comment.