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\""));
}
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());
}
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());
}
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());
}
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);
}
Aggregations