Search in sources :

Example 21 with GroupMember

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

the class GroupMemberTranslatorImpl_2_1Test method shouldTranslateCohortMemberInactiveToFHIRType.

@Test
public void shouldTranslateCohortMemberInactiveToFHIRType() {
    CohortMembership cohortMembership = mock(CohortMembership.class);
    Patient patient = mock(Patient.class);
    Reference patientReference = mock(Reference.class);
    when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
    when(patientDao.getPatientById(anyInt())).thenReturn(patient);
    when(cohortMembership.isActive()).thenReturn(true);
    GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership);
    assertThat(component, notNullValue());
    assertThat(component.hasInactive(), is(true));
    assertThat(component.getInactive(), is(false));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.openmrs.Patient) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 22 with GroupMember

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

the class GroupMemberTranslatorImpl_2_1Test method shouldTranslateCohortMemberUuidToFHIRType.

@Test
public void shouldTranslateCohortMemberUuidToFHIRType() {
    CohortMembership cohortMembership = mock(CohortMembership.class);
    Patient patient = mock(Patient.class);
    Reference patientReference = mock(Reference.class);
    when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
    when(patientDao.getPatientById(anyInt())).thenReturn(patient);
    when(cohortMembership.getUuid()).thenReturn(COHORT_UUID);
    when(patientReference.getReference()).thenReturn(COHORT_UUID);
    GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership);
    assertThat(component, notNullValue());
    assertThat(component.hasId(), notNullValue());
    assertThat(component.getEntity().getReference(), is(COHORT_UUID));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.openmrs.Patient) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 23 with GroupMember

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

the class GroupMemberTranslatorImpl_2_1Test method shouldTranslateCohortMemberToFHIRGroupEntity.

@Test
public void shouldTranslateCohortMemberToFHIRGroupEntity() {
    CohortMembership cohortMembership = mock(CohortMembership.class);
    Patient patient = mock(Patient.class);
    Reference patientReference = mock(Reference.class);
    when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
    when(patientDao.getPatientById(anyInt())).thenReturn(patient);
    when(cohortMembership.getPatientId()).thenReturn(1);
    GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership);
    assertThat(component, notNullValue());
    assertThat(component.hasEntity(), is(true));
    assertThat(component.getEntity(), is(patientReference));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.openmrs.Patient) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 24 with GroupMember

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

the class GroupMemberTranslatorImpl_2_1Test method shouldUpdatedGroupEntityOrCohortMembersOpenMRSType.

@Test
public void shouldUpdatedGroupEntityOrCohortMembersOpenMRSType() {
    Reference patientReference = mock(Reference.class);
    Patient patient = mock(Patient.class);
    GroupMember groupMember = mock(GroupMember.class);
    when(groupMember.hasEntity()).thenReturn(true);
    when(groupMember.getEntity()).thenReturn(patientReference);
    when(patient.getPatientId()).thenReturn(4);
    when(patientReferenceTranslator.toOpenmrsType(patientReference)).thenReturn(patient);
    // Existing cohortMembership with patient id 3
    CohortMembership cohortMembership = new CohortMembership();
    cohortMembership.setPatientId(3);
    CohortMembership membership = groupMemberTranslator.toOpenmrsType(cohortMembership, groupMember);
    assertThat(membership, notNullValue());
    assertThat(membership.getPatientId(), notNullValue());
    // Updated cohortMembership with patient id 4
    assertThat(membership.getPatientId(), equalTo(4));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.openmrs.Patient) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 25 with GroupMember

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

the class GroupTranslatorImpl_2_1Test method shouldUpdateMemberList.

@Test
public void shouldUpdateMemberList() {
    CohortMembership cohortMembership = mock(CohortMembership.class);
    GroupMember groupMember = mock(GroupMember.class);
    Group.GroupMemberComponent component = new Group.GroupMemberComponent();
    component.setId("12");
    component.setEntity(mock(Reference.class));
    component.setEntityTarget(mock(Resource.class));
    component.setInactive(false);
    component.setPeriod(mock(Period.class));
    Cohort existingCohort = new Cohort();
    existingCohort.setUuid(COHORT_UUID);
    existingCohort.setVoided(false);
    existingCohort.setMemberships(Arrays.asList(cohortMembership, cohortMembership));
    Group group = mock(Group.class);
    when(group.hasMember()).thenReturn(true);
    when(groupMemberTranslator21.toOpenmrsType(groupMember)).thenReturn(cohortMembership);
    when(group.getMember()).thenReturn(Arrays.asList(component, component));
    when(componentTranslator.toOpenmrsType(component)).thenReturn(groupMember);
    Cohort updateCohort = groupTranslator.toOpenmrsType(existingCohort, group);
    assertThat(updateCohort, notNullValue());
    assertThat(updateCohort.getMemberships(), notNullValue());
    assertThat(updateCohort.getMemberships(), hasSize(1));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Group(org.hl7.fhir.r4.model.Group) Cohort(org.openmrs.Cohort) Reference(org.hl7.fhir.r4.model.Reference) Resource(org.hl7.fhir.r4.model.Resource) Period(org.hl7.fhir.r4.model.Period) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

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