Search in sources :

Example 6 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project quality-measure-and-cohort-service by Alvearie.

the class MeasureCLITest method testJsonFormattedOutput.

@Test
public void testJsonFormattedOutput() throws Exception {
    mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
    Patient patient = getPatient("123", AdministrativeGender.MALE, "1592-14-03");
    mockFhirResourceRetrieval(patient);
    Library library = mockLibraryRetrieval("Test", DEFAULT_RESOURCE_VERSION, "cql/basic/Test-1.0.0.cql");
    Measure measure = getCohortMeasure("Test", library, "Male");
    mockFhirResourceRetrieval(measure);
    File tmpFile = new File("target/fhir-stub.json");
    ObjectMapper om = new ObjectMapper();
    try (Writer w = new FileWriter(tmpFile)) {
        w.write(om.writeValueAsString(getFhirServerConfig()));
    }
    File tmpMeasureConfigurationsFile = createTmpConfigurationsFileForSingleMeasure(measure.getId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(baos);
    try {
        MeasureCLI cli = new MeasureCLI();
        cli.runWithArgs(new String[] { "-d", tmpFile.getAbsolutePath(), "-j", tmpMeasureConfigurationsFile.getAbsolutePath(), "-c", patient.getId(), "-f", "JSON" }, out);
    } finally {
        tmpFile.delete();
        tmpMeasureConfigurationsFile.delete();
    }
    String output = new String(baos.toByteArray());
    System.out.println(output);
    assertTrue(output.contains("\"resourceType\": \"MeasureReport\""));
}
Also used : PrintStream(java.io.PrintStream) FileWriter(java.io.FileWriter) Measure(org.hl7.fhir.r4.model.Measure) Patient(org.hl7.fhir.r4.model.Patient) Library(org.hl7.fhir.r4.model.Library) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 7 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method testSetReportMeasureToMeasureId__measureFromBundleWithoutMetaVersion__onlyMeasurePortionWithoutHistoryOnReport.

@Test
public void testSetReportMeasureToMeasureId__measureFromBundleWithoutMetaVersion__onlyMeasurePortionWithoutHistoryOnReport() {
    MeasureReport report = new MeasureReport();
    String bundleInput = "{\"resourceType\":\"Bundle\",\"id\":\"98765\",\"entry\":[{\"fullUrl\":\"https://full-url-to/fhir-server/api/v4/Measure/id1\",\"resource\":{\"resourceType\":\"Measure\",\"id\":\"id1\"}}]}";
    Measure measure = (Measure) fhirParser.parseResource(Bundle.class, bundleInput).getEntryFirstRep().getResource();
    CDMMeasureEvaluation.setReportMeasureToMeasureId(report, measure);
    assertEquals("Measure/id1", report.getMeasure());
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Measure(org.hl7.fhir.r4.model.Measure) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Test(org.junit.Test)

Example 8 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method testSetReportMeasureToMeasureId__noMetaVersion__noHistoryInMeasureOnReport.

@Test
public void testSetReportMeasureToMeasureId__noMetaVersion__noHistoryInMeasureOnReport() {
    MeasureReport report = new MeasureReport();
    String measureInput = "{\"resourceType\":\"Measure\",\"id\":\"id1\"}";
    Measure measure = fhirParser.parseResource(Measure.class, measureInput);
    CDMMeasureEvaluation.setReportMeasureToMeasureId(report, measure);
    assertEquals("Measure/id1", report.getMeasure());
}
Also used : Measure(org.hl7.fhir.r4.model.Measure) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Test(org.junit.Test)

Example 9 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project quality-measure-and-cohort-service by Alvearie.

the class CDMMeasureEvaluationTest method testSetReportMeasureToMeasureId__includesMetaVersion__hasHistoryInMeasureOnReport.

@Test
public void testSetReportMeasureToMeasureId__includesMetaVersion__hasHistoryInMeasureOnReport() {
    MeasureReport report = new MeasureReport();
    String measureInput = "{\"resourceType\":\"Measure\",\"id\":\"id1\",\"meta\":{\"versionId\":\"2\"}}";
    Measure measure = fhirParser.parseResource(Measure.class, measureInput);
    CDMMeasureEvaluation.setReportMeasureToMeasureId(report, measure);
    assertEquals("Measure/id1/_history/2", report.getMeasure());
}
Also used : Measure(org.hl7.fhir.r4.model.Measure) MeasureReport(org.hl7.fhir.r4.model.MeasureReport) Test(org.junit.Test)

Example 10 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project quality-measure-and-cohort-service by Alvearie.

the class CohortServiceExceptionMapperTest method testToResponseResourceNotFoundExceptionHAPIFormat.

@Test
public void testToResponseResourceNotFoundExceptionHAPIFormat() throws Exception {
    OperationOutcome outcome = new OperationOutcome();
    outcome.getText().setStatusAsString("generated");
    outcome.getIssueFirstRep().setSeverity(IssueSeverity.ERROR).setCode(OperationOutcome.IssueType.PROCESSING).setDiagnostics("Resource Patient/something is not found");
    ResourceNotFoundException ex = new ResourceNotFoundException("Error", outcome);
    ex.setResponseBody(parser.encodeResourceToString(outcome));
    Response response = new CohortServiceExceptionMapper().toResponse(ex);
    ServiceErrorList actual = (ServiceErrorList) response.getEntity();
    ServiceErrorList expected = new ServiceErrorList();
    expected.setStatusCode(400);
    expected.getErrors().add(newServiceError(404, "FHIR Resource Not Found: Error", "{\"resourceType\":\"OperationOutcome\",\"text\":{\"status\":\"generated\"},\"issue\":[{\"severity\":\"error\",\"code\":\"processing\",\"diagnostics\":\"Resource Patient/something is not found\"}]}"));
    expected.setErrorSource(ErrorSource.FHIR_SERVER);
    testErrorListEquality(expected, actual);
}
Also used : Response(javax.ws.rs.core.Response) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) ServiceErrorList(com.ibm.cohort.engine.api.service.model.ServiceErrorList) Test(org.junit.Test)

Aggregations

JsonElement (com.google.gson.JsonElement)33 HashSet (java.util.HashSet)26 Bundle (org.hl7.fhir.r4.model.Bundle)24 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)21 Test (org.junit.Test)20 Nonnull (javax.annotation.Nonnull)18 ArrayList (java.util.ArrayList)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)10 FhirContext (ca.uhn.fhir.context.FhirContext)9 File (java.io.File)9 Row (org.apache.spark.sql.Row)9 IdType (org.hl7.fhir.dstu3.model.IdType)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 IOException (java.io.IOException)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Resource (org.hl7.fhir.r4.model.Resource)7