Search in sources :

Example 11 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupTranslatorImpl_2_1Test method shouldTranslateFHIRGroupMembersToOpenMRSCohortMembers.

@Test
public void shouldTranslateFHIRGroupMembersToOpenMRSCohortMembers() {
    Group group = mock(Group.class);
    CohortMembership cohortMembership = mock(CohortMembership.class);
    GroupMember groupMember = mock(GroupMember.class);
    Group.GroupMemberComponent groupMemberComponent = mock(Group.GroupMemberComponent.class);
    when(group.hasMember()).thenReturn(true);
    when(group.getMember()).thenReturn(Arrays.asList(groupMemberComponent, groupMemberComponent));
    when(groupMemberTranslator21.toOpenmrsType(groupMember)).thenReturn(cohortMembership);
    when(componentTranslator.toOpenmrsType(groupMemberComponent)).thenReturn(groupMember);
    Cohort cohort = groupTranslator.toOpenmrsType(group);
    assertThat(cohort, notNullValue());
    assertThat(cohort.getMemberships().isEmpty(), is(false));
    assertThat(cohort.getMemberships(), hasSize(1));
    assertThat(cohort.getMemberships().iterator().next(), is(cohortMembership));
}
Also used : Group(org.hl7.fhir.r4.model.Group) GroupMember(org.openmrs.module.fhir2.model.GroupMember) Cohort(org.openmrs.Cohort) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 12 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnPaginatedListOfGroupMembersAsJson.

@Test
public void shouldReturnPaginatedListOfGroupMembersAsJson() throws Exception {
    MockHttpServletResponse response = get("/Group/" + GROUP_UUID + "/$members").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle groupMembers = readBundleResponse(response);
    assertThat(groupMembers, notNullValue());
    assertThat(groupMembers.getEntry(), not(empty()));
    assertThat(groupMembers.getTotal(), is(1));
    List<Bundle.BundleEntryComponent> entries = groupMembers.getEntry();
    assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class))));
    assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/"))))));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 13 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnPaginatedListOfGroupMembersWithLargeGroupAsJson.

@Test
public void shouldReturnPaginatedListOfGroupMembersWithLargeGroupAsJson() throws Exception {
    MockHttpServletResponse response = get("/Group/" + GROUP_WITH_MORE_MEMBERS + "/$members").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(BaseFhirIntegrationTest.FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle groupMembers = readBundleResponse(response);
    assertThat(groupMembers, notNullValue());
    assertThat(groupMembers.getEntry(), not(empty()));
    assertThat(groupMembers.getTotal(), is(6));
    List<Bundle.BundleEntryComponent> entries = groupMembers.getEntry();
    assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class))));
    assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/"))))));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 14 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnPaginatedListOfGroupMembersWithLargeGroupAsXml.

@Test
public void shouldReturnPaginatedListOfGroupMembersWithLargeGroupAsXml() throws Exception {
    MockHttpServletResponse response = get("/Group/" + GROUP_WITH_MORE_MEMBERS + "/$members").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle groupMembers = readBundleResponse(response);
    assertThat(groupMembers, notNullValue());
    assertThat(groupMembers.getEntry(), not(empty()));
    assertThat(groupMembers.getTotal(), is(6));
    List<Bundle.BundleEntryComponent> entries = groupMembers.getEntry();
    assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class))));
    assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/"))))));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 15 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnPaginatedListOfGroupMembersAsXml.

@Test
public void shouldReturnPaginatedListOfGroupMembersAsXml() throws Exception {
    MockHttpServletResponse response = get("/Group/" + GROUP_UUID + "/$members").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle groupMembers = readBundleResponse(response);
    assertThat(groupMembers, notNullValue());
    assertThat(groupMembers.getEntry(), not(empty()));
    assertThat(groupMembers.getTotal(), is(1));
    List<Bundle.BundleEntryComponent> entries = groupMembers.getEntry();
    assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/GroupMember/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(GroupMember.class))));
    assertThat(entries, everyItem(hasResource(hasProperty("entity", hasProperty("reference", startsWith("Patient/"))))));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Aggregations

GroupMember (org.openmrs.module.fhir2.model.GroupMember)27 Test (org.junit.Test)23 CohortMembership (org.openmrs.CohortMembership)14 Reference (org.hl7.fhir.r4.model.Reference)13 Patient (org.openmrs.Patient)10 Group (org.hl7.fhir.r4.model.Group)6 Period (org.hl7.fhir.r4.model.Period)6 Cohort (org.openmrs.Cohort)5 Bundle (org.hl7.fhir.r4.model.Bundle)4 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 Resource (org.hl7.fhir.r4.model.Resource)3 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)1 ArrayList (java.util.ArrayList)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)1