use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportResourceProviderIntegrationTest method shouldSearchForAllDiagnosticReportsAsJson.
@Test
public void shouldSearchForAllDiagnosticReportsAsJson() throws Exception {
MockHttpServletResponse response = get("/DiagnosticReport").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
List<Bundle.BundleEntryComponent> entries = results.getEntry();
assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/DiagnosticReport/"))));
assertThat(entries, everyItem(hasResource(instanceOf(DiagnosticReport.class))));
assertThat(entries, everyItem(hasResource(validResource())));
}
use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportResourceProviderIntegrationTest method shouldCreateNewDiagnosticReportAsJson.
@Test
public void shouldCreateNewDiagnosticReportAsJson() throws Exception {
String jsonReport;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_DIAGNOSTIC_REPORT_DOCUMENT)) {
Objects.requireNonNull(is);
jsonReport = IOUtils.toString(is, StandardCharsets.UTF_8);
}
MockHttpServletResponse response = post("/DiagnosticReport").accept(FhirMediaTypes.JSON).jsonContent(jsonReport).go();
assertThat(response, isCreated());
assertThat(response.getHeader("Location"), containsString("/DiagnosticReport/"));
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
DiagnosticReport diagnosticReport = readResponse(response);
assertThat(diagnosticReport, notNullValue());
assertThat(diagnosticReport.getIdElement().getIdPart(), notNullValue());
assertThat(diagnosticReport.getStatus(), equalTo(DiagnosticReport.DiagnosticReportStatus.FINAL));
assertThat(diagnosticReport.getCategoryFirstRep().getCodingFirstRep().getCode(), equalTo("LAB"));
assertThat(diagnosticReport.getCode().getCoding(), hasSize(greaterThanOrEqualTo(2)));
assertThat(diagnosticReport.getCode().getCoding().get(0).getSystem(), nullValue());
assertThat(diagnosticReport.getCode().getCoding().get(0).getCode(), equalTo("5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
assertThat(diagnosticReport.getCode().getCoding().get(1).getSystem(), equalTo("https://openconceptlab.org/orgs/CIEL/sources/CIEL"));
assertThat(diagnosticReport.getCode().getCoding().get(1).getCode(), equalTo("5085"));
assertThat(diagnosticReport.getSubject().getReference(), equalTo("Patient/5946f880-b197-400b-9caa-a3c661d23041"));
assertThat(diagnosticReport.getEncounter().getReference(), equalTo("Encounter/6519d653-393b-4118-9c83-a3715b82d4ac"));
assertThat(diagnosticReport.getIssued(), equalTo(Date.from(LocalDateTime.of(2011, 3, 4, 11, 45, 33).atOffset(ZoneOffset.ofHours(11)).toInstant())));
assertThat(diagnosticReport.getResult(), hasSize(2));
assertThat(diagnosticReport.getResult(), hasItem(hasProperty("reference", equalTo("Observation/6f16bb57-12bc-4077-9f49-ceaa9b928669"))));
assertThat(diagnosticReport.getResult(), hasItem(hasProperty("reference", equalTo("Observation/dc386962-1c42-49ea-bed2-97650c66f742"))));
}
use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnNotFoundWhenDiagnosticReportDoesNotExistAsXML.
@Test
public void shouldReturnNotFoundWhenDiagnosticReportDoesNotExistAsXML() throws Exception {
MockHttpServletResponse response = get("/DiagnosticReport/" + WRONG_DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.XML).go();
assertThat(response, isNotFound());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.getIssue(), hasSize(greaterThanOrEqualTo(1)));
assertThat(operationOutcome.getIssue(), hasItem(hasProperty("severity", equalTo(OperationOutcome.IssueSeverity.ERROR))));
}
use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnSortedAndFilteredSearchResultsForPatientsAsJson.
@Test
public void shouldReturnSortedAndFilteredSearchResultsForPatientsAsJson() throws Exception {
MockHttpServletResponse response = get("/DiagnosticReport?patient.given=Collet&_sort=-_lastUpdated").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle results = readBundleResponse(response);
assertThat(results, notNullValue());
assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(results.hasEntry(), is(true));
List<Bundle.BundleEntryComponent> entries = results.getEntry();
assertThat(entries, everyItem(hasResource(hasProperty("subject", hasProperty("reference", equalTo("Patient/5946f880-b197-400b-9caa-a3c661d23041"))))));
assertThat(entries, containsInRelativeOrder(hasResource(hasProperty("meta", hasProperty("lastUpdated", equalTo(Date.from(LocalDateTime.of(2018, 8, 18, 14, 9, 35).atZone(ZoneId.systemDefault()).toInstant()))))), hasResource(hasProperty("meta", hasProperty("lastUpdated", equalTo(Date.from(LocalDateTime.of(2008, 8, 18, 14, 9, 35).atZone(ZoneId.systemDefault()).toInstant())))))));
assertThat(entries, everyItem(hasResource(validResource())));
}
use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchPatientIdAsXML.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchPatientIdAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.XML).go();
DiagnosticReport diagnosticReport = readResponse(response);
// update the existing record
diagnosticReport.setId(WRONG_DIAGNOSTIC_REPORT_UUID);
// send the update to the server
response = put("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).xmlContent(toXML(diagnosticReport)).accept(FhirMediaTypes.XML).go();
assertThat(response, isBadRequest());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
Aggregations