Search in sources :

Example 16 with Period

use of org.hl7.fhir.dstu2016may.model.Period in project cqf-ruler by DBCG.

the class MeasureEvaluateProvider method evaluateMeasure.

/**
 * Implements the <a href=
 * "https://www.hl7.org/fhir/operation-measure-evaluate-measure.html">$evaluate-measure</a>
 * operation found in the
 * <a href="http://www.hl7.org/fhir/clinicalreasoning-module.html">FHIR Clinical
 * Reasoning Module</a>. This implementation aims to be compatible with the CQF
 * IG.
 *
 * @param requestDetails The details (such as tenant) of this request. Usually
 *                       auto-populated HAPI.
 * @param theId          the Id of the Measure to evaluate
 * @param periodStart    The start of the reporting period
 * @param periodEnd      The end of the reporting period
 * @param reportType     The type of MeasureReport to generate
 * @param subject        the subject to use for the evaluation
 * @param practitioner   the practitioner to use for the evaluation
 * @param lastReceivedOn the date the results of this measure were last
 *                       received.
 * @param productLine    the productLine (e.g. Medicare, Medicaid, etc) to use
 *                       for the evaluation. This is a non-standard parameter.
 * @param additionalData the data bundle containing additional data
 * @return the calculated MeasureReport
 */
// warning for greater than 7 parameters
@SuppressWarnings("squid:S00107")
@Description(shortDefinition = "$evaluate-measure", value = "Implements the <a href=\"https://www.hl7.org/fhir/operation-measure-evaluate-measure.html\">$evaluate-measure</a> operation found in the <a href=\"http://www.hl7.org/fhir/clinicalreasoning-module.html\">FHIR Clinical Reasoning Module</a>. This implementation aims to be compatible with the CQF IG.", example = "Measure/example/$evaluate-measure?subject=Patient/123&periodStart=2019&periodEnd=2020")
@Operation(name = "$evaluate-measure", idempotent = true, type = Measure.class)
public MeasureReport evaluateMeasure(RequestDetails requestDetails, @IdParam IdType theId, @OperationParam(name = "periodStart") String periodStart, @OperationParam(name = "periodEnd") String periodEnd, @OperationParam(name = "reportType") String reportType, @OperationParam(name = "subject") String subject, @OperationParam(name = "practitioner") String practitioner, @OperationParam(name = "lastReceivedOn") String lastReceivedOn, @OperationParam(name = "productLine") String productLine, @OperationParam(name = "additionalData") Bundle additionalData) {
    Measure measure = read(theId);
    TerminologyProvider terminologyProvider = this.jpaTerminologyProviderFactory.create(requestDetails);
    DataProvider dataProvider = this.jpaDataProviderFactory.create(requestDetails, terminologyProvider);
    LibraryContentProvider libraryContentProvider = this.libraryContentProviderFactory.create(requestDetails);
    FhirDal fhirDal = this.fhirDalFactory.create(requestDetails);
    org.opencds.cqf.cql.evaluator.measure.r4.R4MeasureProcessor measureProcessor = new org.opencds.cqf.cql.evaluator.measure.r4.R4MeasureProcessor(null, this.dataProviderFactory, null, null, null, terminologyProvider, libraryContentProvider, dataProvider, fhirDal, null, this.globalLibraryCache);
    MeasureReport report = measureProcessor.evaluateMeasure(measure.getUrl(), periodStart, periodEnd, reportType, subject, null, lastReceivedOn, null, null, null, additionalData);
    if (productLine != null) {
        Extension ext = new Extension();
        ext.setUrl("http://hl7.org/fhir/us/cqframework/cqfmeasures/StructureDefinition/cqfm-productLine");
        ext.setValue(new StringType(productLine));
        report.addExtension(ext);
    }
    return report;
}
Also used : LibraryContentProvider(org.opencds.cqf.cql.evaluator.cql2elm.content.LibraryContentProvider) StringType(org.hl7.fhir.r4.model.StringType) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) FhirDal(org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal) DataProvider(org.opencds.cqf.cql.engine.data.DataProvider) Extension(org.hl7.fhir.r4.model.Extension) TerminologyProvider(org.opencds.cqf.cql.engine.terminology.TerminologyProvider) Measure(org.hl7.fhir.r4.model.Measure) Description(ca.uhn.fhir.model.api.annotation.Description) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 17 with Period

use of org.hl7.fhir.dstu2016may.model.Period in project ipf by oehf.

the class Iti67ResourceProvider method documentReferenceSearch.

@SuppressWarnings("unused")
@Search(type = DocumentReference.class)
public IBundleProvider documentReferenceSearch(@RequiredParam(name = DocumentReference.SP_PATIENT, chainWhitelist = { "", Patient.SP_IDENTIFIER }) ReferenceParam patient, @OptionalParam(name = DocumentReference.SP_STATUS) TokenOrListParam status, @OptionalParam(name = DocumentReference.SP_IDENTIFIER) TokenParam identifier, @OptionalParam(name = DocumentReference.SP_DATE) DateRangeParam date, @OptionalParam(name = STU3_INDEXED) DateRangeParam indexed, @OptionalParam(name = DocumentReference.SP_AUTHOR, chainWhitelist = { Practitioner.SP_FAMILY, Practitioner.SP_GIVEN }) ReferenceAndListParam author, @OptionalParam(name = DocumentReference.SP_CATEGORY) TokenOrListParam category, @OptionalParam(name = STU3_CLASS) TokenOrListParam class_, @OptionalParam(name = DocumentReference.SP_TYPE) TokenOrListParam type, @OptionalParam(name = DocumentReference.SP_SETTING) TokenOrListParam setting, @OptionalParam(name = DocumentReference.SP_PERIOD) DateRangeParam period, @OptionalParam(name = DocumentReference.SP_FACILITY) TokenOrListParam facility, @OptionalParam(name = DocumentReference.SP_EVENT) TokenOrListParam event, @OptionalParam(name = DocumentReference.SP_SECURITY_LABEL) TokenOrListParam securityLabel, @OptionalParam(name = STU3_SECURITY_LABEL) TokenOrListParam label, @OptionalParam(name = DocumentReference.SP_FORMAT) TokenOrListParam format, @OptionalParam(name = DocumentReference.SP_RELATED, chainWhitelist = { "", DocumentReference.SP_IDENTIFIER }) ReferenceOrListParam related, // -> related.identifier
@OptionalParam(name = STU3_RELATED_ID) TokenOrListParam relatedId, // -> related
@OptionalParam(name = STU3_RELATED_REF) ReferenceOrListParam relatedRef, // Extension to ITI-67
@OptionalParam(name = IAnyResource.SP_RES_ID) TokenParam resourceId, @Sort SortSpec sortSpec, @IncludeParam Set<Include> includeSpec, RequestDetails requestDetails, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
    // Be graceful and accept STU3 parameters as well
    var dateParam = date != null ? date : indexed;
    var categoryParam = category != null ? category : class_;
    var securityLabelParam = securityLabel != null ? securityLabel : label;
    // Handle "related" parameters
    ReferenceOrListParam relatedParam = new ReferenceOrListParam();
    TokenOrListParam relatedIdParam = new TokenOrListParam();
    if (relatedRef != null) {
        relatedParam = relatedRef;
    } else if (relatedId != null) {
        relatedIdParam = relatedId;
    } else if (related != null) {
        related.getValuesAsQueryTokens().stream().filter(referenceParam -> !DocumentReference.SP_IDENTIFIER.equals(referenceParam.getChain())).forEach(relatedParam::addOr);
        related.getValuesAsQueryTokens().stream().filter(referenceParam -> DocumentReference.SP_IDENTIFIER.equals(referenceParam.getChain())).map(referenceParam -> referenceParam.toTokenParam(getFhirContext())).forEach(relatedIdParam::addOr);
    }
    var searchParameters = Iti67SearchParameters.builder().status(status).identifier(identifier).date(dateParam).category(categoryParam).type(type).setting(setting).period(period).facility(facility).event(event).securityLabel(securityLabelParam).format(format).related(relatedParam).relatedId(relatedIdParam)._id(resourceId).sortSpec(sortSpec).includeSpec(includeSpec).fhirContext(getFhirContext()).build();
    searchParameters.setAuthor(author);
    var patientChain = patient.getChain();
    if (Patient.SP_IDENTIFIER.equals(patientChain)) {
        searchParameters.setPatientIdentifier(patient.toTokenParam(getFhirContext()));
    } else if (patientChain == null || patientChain.isEmpty()) {
        searchParameters.setPatientReference(patient);
    }
    // Run down the route
    return requestBundleProvider(null, searchParameters, ResourceType.DocumentReference.name(), httpServletRequest, httpServletResponse, requestDetails);
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) IncludeParam(ca.uhn.fhir.rest.annotation.IncludeParam) AbstractPlainProvider(org.openehealth.ipf.commons.ihe.fhir.AbstractPlainProvider) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) HttpServletRequest(javax.servlet.http.HttpServletRequest) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Search(ca.uhn.fhir.rest.annotation.Search) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) Patient(org.hl7.fhir.r4.model.Patient) Read(ca.uhn.fhir.rest.annotation.Read) Practitioner(org.hl7.fhir.r4.model.Practitioner) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Sort(ca.uhn.fhir.rest.annotation.Sort) InvalidRequestException(ca.uhn.fhir.rest.server.exceptions.InvalidRequestException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Include(ca.uhn.fhir.model.api.Include) IdType(org.hl7.fhir.r4.model.IdType) TokenParam(ca.uhn.fhir.rest.param.TokenParam) ResourceType(org.hl7.fhir.r4.model.ResourceType) SortSpec(ca.uhn.fhir.rest.api.SortSpec) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Search(ca.uhn.fhir.rest.annotation.Search)

Example 18 with Period

use of org.hl7.fhir.dstu2016may.model.Period in project quality-measure-and-cohort-service by Alvearie.

the class MeasureEvaluatorTest method measure_report_generated___FHIR_measure_parameters_on_measure_report.

@Test
public void measure_report_generated___FHIR_measure_parameters_on_measure_report() throws Exception {
    CapabilityStatement metadata = getCapabilityStatement();
    mockFhirResourceRetrieval("/metadata?_format=json", metadata);
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1970-10-10");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("TestDummyPopulations", DEFAULT_VERSION, "cql/fhir-measure/test-dummy-populations.xml", ELM_MIME_TYPE);
    Measure measure = getCohortMeasure("CohortMeasureName", library, INITIAL_POPULATION);
    Map<String, Type> measureParameters = new HashMap<>();
    measureParameters.put("base64Param", new Base64BinaryType("AAA"));
    measureParameters.put("booleanParam", new BooleanType(false));
    measureParameters.put("dateParam", new DateType("2020-01-01"));
    measureParameters.put("dateTimeParam", new DateTimeType("2020-01-01T12:00:00"));
    measureParameters.put("decimalParam", new DecimalType(12.0));
    measureParameters.put("instantParam", new InstantType("2020-01-01T12:00:00-04:00"));
    measureParameters.put("integerParam", new IntegerType(1));
    measureParameters.put("stringParam", new StringType("str"));
    measureParameters.put("timeParam", new TimeType("05:30:00"));
    measureParameters.put("uriParam", new UriType("abcde"));
    measureParameters.put("codeableConceptParam", new CodeableConcept().setText("display").addCoding(new Coding().setCode("val").setSystem("sys").setDisplay("display")));
    measureParameters.put("codingParam", new Coding().setCode("v").setSystem("s").setDisplay("d"));
    measureParameters.put("periodParam", new Period().setStart(new Date(1)).setEnd(new Date(2)));
    measureParameters.put("quantityParam", new Quantity().setValue(1).setUnit("g"));
    measureParameters.put("rangeParam", new Range().setLow(new Quantity().setUnit("g").setValue(1)).setHigh(new Quantity().setUnit("g").setValue(5)));
    measureParameters.put("ratioParam", new Ratio().setNumerator(new Quantity().setUnit("g").setValue(1)).setDenominator(new Quantity().setUnit("g").setValue(5)));
    List<Extension> parameterExtensions = measureParameters.entrySet().stream().map(x -> createMeasureParameter(x.getKey(), x.getValue())).collect(Collectors.toList());
    measure.setExtension(parameterExtensions);
    mockFhirResourceRetrieval(measure);
    MeasureReport report = evaluator.evaluatePatientMeasure(measure.getId(), patient.getId(), null);
    assertNotNull(report);
    List<String> parameterNames = report.getExtension().stream().filter(x -> x.getUrl().equals(MEASURE_PARAMETER_VALUE_URL)).map(x -> (ParameterDefinition) x.getValue()).map(ParameterDefinition::getName).collect(Collectors.toList());
    // Expected parameters are the ones listed above, plus the special parameters
    // measurement period and product line
    assertEquals(measureParameters.size() + 2, parameterNames.size());
    assertTrue(parameterNames.containsAll(measureParameters.keySet()));
    assertTrue(parameterNames.contains(CDMConstants.MEASUREMENT_PERIOD));
    assertTrue(parameterNames.contains(CDMConstants.PRODUCT_LINE));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_VALUE_URL) Range(org.hl7.fhir.r4.model.Range) StringUtils(org.apache.commons.lang3.StringUtils) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) InvalidOperatorArgument(org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) HumanName(org.hl7.fhir.r4.model.HumanName) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Map(java.util.Map) StringType(org.hl7.fhir.r4.model.StringType) Assert.fail(org.junit.Assert.fail) ParseException(java.text.ParseException) IntegerType(org.hl7.fhir.r4.model.IntegerType) Patient(org.hl7.fhir.r4.model.Patient) DefineReturnOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions.DefineReturnOptions) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) DateType(org.hl7.fhir.r4.model.DateType) TimeZone(java.util.TimeZone) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) Period(org.hl7.fhir.r4.model.Period) MEASURE_PARAMETER_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_URL) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Collectors(java.util.stream.Collectors) PARAMETER_DEFAULT_URL(com.ibm.cohort.engine.cdm.CDMConstants.PARAMETER_DEFAULT_URL) TimeType(org.hl7.fhir.r4.model.TimeType) List(java.util.List) BooleanType(org.hl7.fhir.r4.model.BooleanType) Assert.assertFalse(org.junit.Assert.assertFalse) Coding(org.hl7.fhir.r4.model.Coding) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Extension(org.hl7.fhir.r4.model.Extension) UriType(org.hl7.fhir.r4.model.UriType) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) HashMap(java.util.HashMap) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) Measure(org.hl7.fhir.r4.model.Measure) ArrayList(java.util.ArrayList) Address(org.hl7.fhir.r4.model.Address) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) MEASURE_PARAMETER_VALUE_URL(com.ibm.cohort.engine.cdm.CDMConstants.MEASURE_PARAMETER_VALUE_URL) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Quantity(org.hl7.fhir.r4.model.Quantity) Ratio(org.hl7.fhir.r4.model.Ratio) MeasureSupplementalDataEvaluation(com.ibm.cohort.engine.cqfruler.MeasureSupplementalDataEvaluation) DecimalType(org.hl7.fhir.r4.model.DecimalType) Before(org.junit.Before) MeasureEvidenceOptions(com.ibm.cohort.engine.measure.evidence.MeasureEvidenceOptions) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Assert.assertNotNull(org.junit.Assert.assertNotNull) ListResource(org.hl7.fhir.r4.model.ListResource) Library(org.hl7.fhir.r4.model.Library) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.Test) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) CDMConstants(com.ibm.cohort.engine.cdm.CDMConstants) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) AdministrativeGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) WireMock.urlEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) StringType(org.hl7.fhir.r4.model.StringType) TimeType(org.hl7.fhir.r4.model.TimeType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) UriType(org.hl7.fhir.r4.model.UriType) Coding(org.hl7.fhir.r4.model.Coding) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) Measure(org.hl7.fhir.r4.model.Measure) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Range(org.hl7.fhir.r4.model.Range) Date(java.util.Date) IntegerType(org.hl7.fhir.r4.model.IntegerType) Extension(org.hl7.fhir.r4.model.Extension) StringType(org.hl7.fhir.r4.model.StringType) IntegerType(org.hl7.fhir.r4.model.IntegerType) DateType(org.hl7.fhir.r4.model.DateType) TimeType(org.hl7.fhir.r4.model.TimeType) BooleanType(org.hl7.fhir.r4.model.BooleanType) UriType(org.hl7.fhir.r4.model.UriType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) DecimalType(org.hl7.fhir.r4.model.DecimalType) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) MeasurePopulationType(org.opencds.cqf.common.evaluation.MeasurePopulationType) InstantType(org.hl7.fhir.r4.model.InstantType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalType(org.hl7.fhir.r4.model.DecimalType) Library(org.hl7.fhir.r4.model.Library) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 19 with Period

use of org.hl7.fhir.dstu2016may.model.Period in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testEvaluateMeasureMissingPatient.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluateMeasureMissingPatient() throws Exception {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_MEASURE.getName())).thenReturn(null);
    mockResponseClasses();
    Library library = TestHelper.getTemplateLibrary();
    Measure measure = TestHelper.getTemplateMeasure(library);
    Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    mockNotFound("/Patient/" + patient.getId() + "\\?_format=json");
    FhirServerConfig clientConfig = getFhirServerConfig();
    Map<String, Parameter> parameterOverrides = new HashMap<>();
    parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
    MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
    MeasureEvaluation evaluationRequest = new MeasureEvaluation();
    evaluationRequest.setDataServerConfig(clientConfig);
    evaluationRequest.setPatientId(patient.getId());
    evaluationRequest.setMeasureContext(measureContext);
    // evaluationRequest.setEvidenceOptions(evidenceOptions);
    FhirContext fhirContext = FhirContext.forR4();
    IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    String json = om.writeValueAsString(evaluationRequest);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Create the ZIP part of the request
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TestHelper.createMeasureArtifact(baos, parser, measure, library);
    ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
    IAttachment measurePart = mockAttachment(zipIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
    when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
    Response loadResponse = restHandler.evaluateMeasure(mockRequestContext, VERSION, body);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(400);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) HashMap(java.util.HashMap) MeasureEvaluation(com.ibm.cohort.engine.api.service.model.MeasureEvaluation) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with Period

use of org.hl7.fhir.dstu2016may.model.Period in project quality-measure-and-cohort-service by Alvearie.

the class CohortEngineRestHandlerTest method testEvaluatePatientListMeasureMissingPatient.

@PrepareForTest({ Response.class, TenantManager.class, ServiceBaseUtility.class })
@Test
public void testEvaluatePatientListMeasureMissingPatient() throws Exception {
    prepMocks();
    PowerMockito.mockStatic(ServiceBaseUtility.class);
    PowerMockito.when(ServiceBaseUtility.apiSetup(VERSION, logger, MethodNames.EVALUATE_PATIENT_LIST_MEASURE.getName())).thenReturn(null);
    mockResponseClasses();
    Library library = TestHelper.getTemplateLibrary();
    Measure measure = TestHelper.getTemplateMeasure(library);
    Patient patient = getPatient("patientId", AdministrativeGender.MALE, 40);
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    mockNotFound("/Patient/" + patient.getId() + "\\?_format=json");
    FhirServerConfig clientConfig = getFhirServerConfig();
    Map<String, Parameter> parameterOverrides = new HashMap<>();
    parameterOverrides.put("Measurement Period", new IntervalParameter(new DateParameter("2019-07-04"), true, new DateParameter("2020-07-04"), true));
    MeasureContext measureContext = new MeasureContext(measure.getId(), parameterOverrides);
    PatientListMeasureEvaluation request = new PatientListMeasureEvaluation();
    request.setDataServerConfig(clientConfig);
    request.setPatientIds(Collections.singletonList(patient.getId()));
    request.setMeasureContext(measureContext);
    FhirContext fhirContext = FhirContext.forR4();
    IParser parser = fhirContext.newJsonParser().setPrettyPrint(true);
    // Create the metadata part of the request
    ObjectMapper om = new ObjectMapper();
    String json = om.writeValueAsString(request);
    ByteArrayInputStream jsonIs = new ByteArrayInputStream(json.getBytes());
    IAttachment rootPart = mockAttachment(jsonIs);
    // Create the ZIP part of the request
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TestHelper.createMeasureArtifact(baos, parser, measure, library);
    ByteArrayInputStream zipIs = new ByteArrayInputStream(baos.toByteArray());
    IAttachment measurePart = mockAttachment(zipIs);
    // Assemble them together into a reasonable facsimile of the real request
    IMultipartBody body = mock(IMultipartBody.class);
    when(body.getAttachment(CohortEngineRestHandler.REQUEST_DATA_PART)).thenReturn(rootPart);
    when(body.getAttachment(CohortEngineRestHandler.MEASURE_PART)).thenReturn(measurePart);
    Response loadResponse = restHandler.evaluatePatientListMeasure(mockRequestContext, VERSION, body);
    assertNotNull(loadResponse);
    PowerMockito.verifyStatic(Response.class);
    Response.status(400);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) HashMap(java.util.HashMap) Patient(org.hl7.fhir.r4.model.Patient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAttachment(com.ibm.websphere.jaxrs20.multipart.IAttachment) Response(javax.ws.rs.core.Response) PatientListMeasureEvaluation(com.ibm.cohort.engine.api.service.model.PatientListMeasureEvaluation) MeasureContext(com.ibm.cohort.engine.measure.MeasureContext) IMultipartBody(com.ibm.websphere.jaxrs20.multipart.IMultipartBody) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) Measure(org.hl7.fhir.r4.model.Measure) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) Library(org.hl7.fhir.r4.model.Library) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IParser(ca.uhn.fhir.parser.IParser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Period (org.hl7.fhir.r4.model.Period)87 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)44 Date (java.util.Date)42 Test (org.junit.Test)42 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)40 Coding (org.hl7.fhir.r4.model.Coding)34 Test (org.junit.jupiter.api.Test)34 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)32 Period (org.hl7.fhir.dstu3.model.Period)30 ArrayList (java.util.ArrayList)29 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)27 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)20 Encounter (org.hl7.fhir.r4.model.Encounter)20 Reference (org.hl7.fhir.r4.model.Reference)20 Patient (org.hl7.fhir.r4.model.Patient)19 Reference (org.hl7.fhir.dstu3.model.Reference)18 HashMap (java.util.HashMap)17 Identifier (org.hl7.fhir.r4.model.Identifier)17 NotImplementedException (org.apache.commons.lang3.NotImplementedException)15 List (java.util.List)14