Search in sources :

Example 46 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupFhirResourceProviderIntegrationTest method shouldReturnExistingGroupAsXML.

@Test
public void shouldReturnExistingGroupAsXML() throws Exception {
    MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Group group = readResponse(response);
    assertThat(group, notNullValue());
    assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID));
    assertThat(group, validResource());
}
Also used : Group(org.hl7.fhir.dstu3.model.Group) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 47 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnExistingGroupAsXML.

@Test
public void shouldReturnExistingGroupAsXML() throws Exception {
    MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(BaseFhirIntegrationTest.FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Group group = readResponse(response);
    assertThat(group, notNullValue());
    assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID));
    assertThat(group, validResource());
    assertThat(group.getMember(), notNullValue());
    assertThat(group.getQuantity(), equalTo(1));
    assertThat(group.getMember().size(), equalTo(1));
}
Also used : Group(org.hl7.fhir.r4.model.Group) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 48 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldUpdateExistingGroupAsJson.

@Test
@Transactional(readOnly = true)
public void shouldUpdateExistingGroupAsJson() throws Exception {
    // Before update
    MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Group group = readResponse(response);
    Extension descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
    assertThat(group, notNullValue());
    assertThat(group, validResource());
    assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID));
    assertThat(group.getMember(), notNullValue());
    assertThat(group.getQuantity(), equalTo(1));
    assertThat(descExtension.getValue().toString(), equalTo("cohort voided"));
    // Get existing group with updated name
    String jsonGroup;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_GROUP_DOCUMENT)) {
        Objects.requireNonNull(is);
        jsonGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // Update
    response = put("/Group/" + GROUP_UUID).jsonContent(jsonGroup).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read updated record
    group = readResponse(response);
    descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
    assertThat(group, notNullValue());
    assertThat(group.getIdElement().getIdPart(), equalTo(GROUP_UUID));
    assertThat(group.getActive(), is(true));
    assertThat(group.getMember(), notNullValue());
    assertThat(group.getQuantity(), equalTo(1));
    assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter"));
    assertThat(group, validResource());
    // Double-check via get
    response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go();
    Group updatedGroup = readResponse(response);
    descExtension = updatedGroup.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
    assertThat(updatedGroup, validResource());
    assertThat(updatedGroup, notNullValue());
    assertThat(updatedGroup.getActive(), is(true));
    assertThat(group.getMember(), notNullValue());
    assertThat(group.getQuantity(), equalTo(1));
    assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter"));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Group(org.hl7.fhir.r4.model.Group) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsJSON.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsJSON() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.JSON).go();
    Group group = readResponse(response);
    // update the existing record
    group.setId(BAD_GROUP_UUID);
    // send the update to the server
    response = put("/Group/" + GROUP_UUID).jsonContent(toJson(group)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isBadRequest());
    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 : Group(org.hl7.fhir.r4.model.Group) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 50 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsXML.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Group/" + GROUP_UUID).accept(FhirMediaTypes.XML).go();
    Group group = readResponse(response);
    // update the existing record
    group.setId(BAD_GROUP_UUID);
    // send the update to the server
    response = put("/Group/" + GROUP_UUID).xmlContent(toXML(group)).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));
}
Also used : Group(org.hl7.fhir.r4.model.Group) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Aggregations

Test (org.junit.Test)90 Group (org.hl7.fhir.r4.model.Group)74 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)49 Group (org.hl7.fhir.dstu3.model.Group)44 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)40 Cohort (org.openmrs.Cohort)30 InputStream (java.io.InputStream)20 ArrayList (java.util.ArrayList)16 Structure (ca.uhn.hl7v2.model.Structure)13 Test (org.junit.jupiter.api.Test)13 Group (ca.uhn.hl7v2.model.Group)12 UUID (java.util.UUID)12 Reference (org.hl7.fhir.r4.model.Reference)12 HL7Exception (ca.uhn.hl7v2.HL7Exception)11 List (java.util.List)10 IdType (org.hl7.fhir.dstu3.model.IdType)9 Message (ca.uhn.hl7v2.model.Message)7 Patient (org.hl7.fhir.dstu3.model.Patient)7 PatientEntity (gov.cms.dpc.common.entities.PatientEntity)6 ProviderEntity (gov.cms.dpc.common.entities.ProviderEntity)6