Search in sources :

Example 76 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnExistingDiagnosticReportAsXML.

@Test
public void shouldReturnExistingDiagnosticReportAsXML() throws Exception {
    MockHttpServletResponse response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    DiagnosticReport diagnosticReport = readResponse(response);
    assertThat(diagnosticReport, notNullValue());
    assertThat(diagnosticReport.getIdElement().getIdPart(), equalTo(DIAGNOSTIC_REPORT_UUID));
    assertThat(diagnosticReport.hasCategory(), is(true));
    assertThat(diagnosticReport.getCategory().getCodingFirstRep().getCode(), equalTo("LAB"));
    assertThat(diagnosticReport.hasSubject(), is(true));
    assertThat(diagnosticReport.getSubject().getReference(), equalTo("Patient/5946f880-b197-400b-9caa-a3c661d23041"));
    assertThat(diagnosticReport.hasContext(), is(true));
    assertThat(diagnosticReport.getContext().getReference(), equalTo("Encounter/6519d653-393b-4118-9c83-a3715b82d4ac"));
    assertThat(diagnosticReport.hasCode(), is(true));
    assertThat(diagnosticReport.getCode().getCoding(), hasItem(hasProperty("code", equalTo(DIAGNOSTIC_REPORT_CONCEPT_UUID))));
    assertThat(diagnosticReport.hasIssued(), is(true));
    assertThat(diagnosticReport.getIssued(), equalTo(Date.from(LocalDateTime.of(2008, 7, 1, 0, 0, 0).atZone(ZoneId.systemDefault()).toInstant())));
    assertThat(diagnosticReport.hasResult(), is(true));
    assertThat(diagnosticReport.getResult(), hasSize(2));
    assertThat(diagnosticReport.getResult(), hasItem(hasProperty("reference", equalTo("Observation/6f16bb57-12bc-4077-9f49-ceaa9b928669"))));
    assertThat(diagnosticReport, validResource());
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 77 with DiagnosticReport

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.getCategory().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.getContext().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"))));
}
Also used : InputStream(java.io.InputStream) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 78 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportResourceProviderIntegrationTest method shouldUpdateExistingDiagnosticReportAsJson.

@Test
public void shouldUpdateExistingDiagnosticReportAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    DiagnosticReport diagnosticReport = readResponse(response);
    // verify condition we will change
    assertThat(diagnosticReport.getStatus(), not(is(DiagnosticReport.DiagnosticReportStatus.FINAL)));
    // update the existing record
    diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL);
    // send the update to the server
    response = put("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).jsonContent(toJson(diagnosticReport)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    DiagnosticReport updatedDiagnosticReport = readResponse(response);
    assertThat(updatedDiagnosticReport, notNullValue());
    assertThat(updatedDiagnosticReport.getIdElement().getIdPart(), equalTo(DIAGNOSTIC_REPORT_UUID));
    assertThat(updatedDiagnosticReport.getStatus(), is(DiagnosticReport.DiagnosticReportStatus.FINAL));
    assertThat(diagnosticReport, validResource());
    // double-check the record returned via get
    response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    DiagnosticReport reReadDiagnosticReport = readResponse(response);
    assertThat(reReadDiagnosticReport.getStatus(), is(DiagnosticReport.DiagnosticReportStatus.FINAL));
}
Also used : DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 79 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentPatientAsJson.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentPatientAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/DiagnosticReport/" + DIAGNOSTIC_REPORT_UUID).accept(FhirMediaTypes.JSON).go();
    DiagnosticReport diagnosticReport = readResponse(response);
    // update the existing record
    diagnosticReport.setId(WRONG_DIAGNOSTIC_REPORT_UUID);
    // send the update to the server
    response = put("/DiagnosticReport/" + WRONG_DIAGNOSTIC_REPORT_UUID).jsonContent(toJson(diagnosticReport)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) DiagnosticReport(org.hl7.fhir.dstu3.model.DiagnosticReport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 80 with DiagnosticReport

use of org.hl7.fhir.dstu3.model.DiagnosticReport in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportResourceProviderIntegrationTest method shouldReturnSortedAndFilteredSearchResultsForPatientsAsXML.

@Test
public void shouldReturnSortedAndFilteredSearchResultsForPatientsAsXML() throws Exception {
    MockHttpServletResponse response = get("/DiagnosticReport?patient.given=Collet&_sort=-_lastUpdated").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.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())));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)133 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)115 FhirDiagnosticReport (org.openmrs.module.fhir2.model.FhirDiagnosticReport)65 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)52 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)50 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)42 Test (org.junit.jupiter.api.Test)39 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)39 DiagnosticReport (org.hl7.fhir.dstu3.model.DiagnosticReport)32 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)29 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)28 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)28 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)28 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)19 Reference (org.hl7.fhir.r4.model.Reference)19 Bundle (org.hl7.fhir.r4.model.Bundle)18 Resource (org.hl7.fhir.r4.model.Resource)18 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)16 Include (ca.uhn.fhir.model.api.Include)12 HashSet (java.util.HashSet)12