Search in sources :

Example 96 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner in project openmrs-module-fhir2 by openmrs.

the class PractitionerFhirResourceProviderWebTest method shouldVerifyGetPractitionerHistoryByIdUri.

@Test
public void shouldVerifyGetPractitionerHistoryByIdUri() throws Exception {
    Practitioner practitioner = new Practitioner();
    practitioner.setId(PRACTITIONER_UUID);
    when(practitionerService.get(PRACTITIONER_UUID)).thenReturn(practitioner);
    MockHttpServletResponse response = getPractitionerHistoryByIdRequest();
    MatcherAssert.assertThat(response, isOk());
    MatcherAssert.assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 97 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner in project openmrs-module-fhir2 by openmrs.

the class PractitionerFhirResourceProviderWebTest method updatePractitioner_shouldUpdateExistingPractitioner.

@Test
public void updatePractitioner_shouldUpdateExistingPractitioner() throws Exception {
    String jsonPractitioner;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_PRACTITIONER_PATH)) {
        Objects.requireNonNull(is);
        jsonPractitioner = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    org.hl7.fhir.r4.model.Practitioner practitioner = new org.hl7.fhir.r4.model.Practitioner();
    practitioner.setId(PRACTITIONER_UUID);
    when(practitionerService.update(anyString(), any(org.hl7.fhir.r4.model.Practitioner.class))).thenReturn(practitioner);
    MockHttpServletResponse response = put("/Practitioner/" + PRACTITIONER_UUID).jsonContent(jsonPractitioner).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Practitioner(org.hl7.fhir.r4.model.Practitioner) Test(org.junit.Test)

Example 98 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner in project openmrs-module-fhir2 by openmrs.

the class PractitionerNarrativeTest method shouldGeneratePractitionerNarrative.

/**
 * Check that the expected narrative is generated for some example Practitioner resource
 *
 * @throws IOException
 */
@Test
public void shouldGeneratePractitionerNarrative() throws IOException {
    Practitioner given = parser.parseResource(Practitioner.class, getClass().getClassLoader().getResourceAsStream(EXAMPLE_RESOURCE_PATH));
    Practitioner result = parser.parseResource(Practitioner.class, parser.encodeResourceToString(given));
    assertThat(result, notNullValue());
    assertThat(result.getText(), notNullValue());
    assertThat(result.getText().getStatusAsString(), equalTo("generated"));
    assertThat(result.getText().getDivAsString(), equalTo(readNarrativeFile(EXPECTED_NARRATIVE_PATH)));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) Test(org.junit.Test)

Example 99 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner in project openmrs-module-fhir2 by openmrs.

the class PractitionerFhirResourceProviderIntegrationTest method shouldUpdateExistingPractitionerAsXML.

@Test
public void shouldUpdateExistingPractitionerAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.XML).go();
    Practitioner practitioner = readResponse(response);
    // update the existing record
    Date birthDate = DateUtils.truncate(new Date(), Calendar.DATE);
    practitioner.setBirthDate(birthDate);
    // send the update to the server
    response = put("/Practitioner/" + PRACTITIONER_UUID).xmlContent(toXML(practitioner)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    Practitioner updatedPractitioner = readResponse(response);
    assertThat(updatedPractitioner, notNullValue());
    assertThat(updatedPractitioner.getIdElement().getIdPart(), equalTo(PRACTITIONER_UUID));
    assertThat(updatedPractitioner.getBirthDate(), equalTo(birthDate));
    assertThat(practitioner, validResource());
    // double-check the record returned via get
    response = get("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.XML).go();
    Practitioner reReadPractitioner = readResponse(response);
    assertThat(reReadPractitioner.getBirthDate(), equalTo(birthDate));
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 100 with Practitioner

use of org.hl7.fhir.r4.model.Practitioner in project openmrs-module-fhir2 by openmrs.

the class PractitionerFhirResourceProviderIntegrationTest method shouldReturnCountForPractitionerAsJson.

@Test
public void shouldReturnCountForPractitionerAsJson() throws Exception {
    MockHttpServletResponse response = get("/Practitioner?&_summary=count").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle result = readBundleResponse(response);
    assertThat(result, notNullValue());
    assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(result, hasProperty("total", equalTo(6)));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)185 Practitioner (org.hl7.fhir.r4.model.Practitioner)139 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)86 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)81 Test (org.junit.jupiter.api.Test)68 Practitioner (org.hl7.fhir.dstu3.model.Practitioner)62 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)59 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)54 StringParam (ca.uhn.fhir.rest.param.StringParam)54 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)52 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)37 Identifier (org.hl7.fhir.r4.model.Identifier)32 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)30 Resource (org.hl7.fhir.r4.model.Resource)30 ArrayList (java.util.ArrayList)25 Reference (org.hl7.fhir.r4.model.Reference)24 Bundle (org.hl7.fhir.r4.model.Bundle)22 Date (java.util.Date)21 List (java.util.List)21 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)20