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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations