use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupTranslatorImpl_2_1Test method shouldTranslateCohortMembersToFHIRGroupMembers.
@Test
public void shouldTranslateCohortMembersToFHIRGroupMembers() {
Cohort cohort = mock(Cohort.class);
CohortMembership cohortMembership = mock(CohortMembership.class);
Reference patientReference = mock(Reference.class);
GroupMember member = new GroupMember();
member.setId("12");
member.setEntity(mock(Reference.class));
member.setEntityTarget(mock(Resource.class));
member.setInactive(false);
member.setPeriod(mock(Period.class));
Group.GroupMemberComponent component = mock(Group.GroupMemberComponent.class);
component.setId("12");
component.setEntity(mock(Reference.class));
component.setEntityTarget(mock(Resource.class));
component.setInactive(false);
component.setPeriod(mock(Period.class));
when(cohort.getMemberships()).thenReturn(Arrays.asList(cohortMembership, cohortMembership));
when(groupMemberTranslator21.toFhirResource(cohortMembership)).thenReturn(member);
when(componentTranslator.toFhirResource(member)).thenReturn(component);
when(component.getEntity()).thenReturn(patientReference);
Group group = groupTranslator.toFhirResource(cohort);
assertThat(group, notNullValue());
assertThat(group.hasMember(), is(true));
List<Group.GroupMemberComponent> members = group.getMember();
assertThat(members, hasSize(2));
assertThat(members, everyItem(hasProperty("entity", is(patientReference))));
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImpl_2_1 method toFhirResource.
@Override
public GroupMember toFhirResource(@Nonnull CohortMembership cohortMember) {
notNull(cohortMember, "CohortMember object should not be null");
GroupMember groupMember = new GroupMember();
groupMember.setId(cohortMember.getUuid());
groupMember.setInactive(!cohortMember.isActive());
Patient patient = patientDao.getPatientById(cohortMember.getPatientId());
if (patient != null) {
groupMember.setEntity(patientReferenceTranslator.toFhirResource(patient));
}
Period period = new Period();
period.setStart(cohortMember.getStartDate());
period.setEnd(cohortMember.getEndDate());
groupMember.setPeriod(period);
return groupMember;
}
Aggregations