Search in sources :

Example 91 with Practitioner

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

the class PractitionerFhirResourceProviderWebTest method shouldGetPractitionerHistoryById.

@Test
public void shouldGetPractitionerHistoryById() throws IOException, ServletException {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    provenance.setRecorded(new Date());
    provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
    provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(FhirConstants.AUT).setDisplay(FhirConstants.AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
    org.hl7.fhir.r4.model.Practitioner practitioner = new org.hl7.fhir.r4.model.Practitioner();
    practitioner.setId(PRACTITIONER_UUID);
    practitioner.addContained(provenance);
    when(practitionerService.get(PRACTITIONER_UUID)).thenReturn(practitioner);
    MockHttpServletResponse response = getPractitionerHistoryByIdRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), notNullValue());
    assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Bundle(org.hl7.fhir.dstu3.model.Bundle) Date(java.util.Date) IdType(org.hl7.fhir.dstu3.model.IdType) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) Coding(org.hl7.fhir.r4.model.Coding) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 92 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 {
    org.hl7.fhir.r4.model.Practitioner practitioner = new org.hl7.fhir.r4.model.Practitioner();
    practitioner.setId(PRACTITIONER_UUID);
    when(practitionerService.get(PRACTITIONER_UUID)).thenReturn(practitioner);
    MockHttpServletResponse response = getPractitionerHistoryByIdRequest();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 93 with Practitioner

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

the class PractitionerFhirResourceProviderWebTest method createPractitioner_shouldCreatePractitioner.

@Test
public void createPractitioner_shouldCreatePractitioner() throws Exception {
    String jsonPractitioner;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_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.create(any(org.hl7.fhir.r4.model.Practitioner.class))).thenReturn(practitioner);
    MockHttpServletResponse response = post("/Practitioner").jsonContent(jsonPractitioner).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isCreated());
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 94 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.dstu3.model.Practitioner) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 95 with Practitioner

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

the class PractitionerFhirResourceProviderWebTest method getPractitionerById_shouldReturnPractitioner.

@Test
public void getPractitionerById_shouldReturnPractitioner() throws Exception {
    Practitioner practitioner = new Practitioner();
    practitioner.setId(PRACTITIONER_UUID);
    when(practitionerService.get(PRACTITIONER_UUID)).thenReturn(practitioner);
    MockHttpServletResponse response = get("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.JSON).go();
    MatcherAssert.assertThat(response, isOk());
    MatcherAssert.assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    MatcherAssert.assertThat(readResponse(response).getIdElement().getIdPart(), equalTo(PRACTITIONER_UUID));
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) 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