use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImpl_2_1Test method shouldGroupEntityToCohortPatientIdOpenMRSType.
@Test
public void shouldGroupEntityToCohortPatientIdOpenMRSType() {
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(1);
when(patientReferenceTranslator.toOpenmrsType(patientReference)).thenReturn(patient);
CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember);
assertThat(membership, notNullValue());
assertThat(membership.getPatientId(), notNullValue());
assertThat(membership.getPatientId(), equalTo(1));
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImpl_2_1Test method shouldUpdateCohortMembershipStartDate.
@Test
public void shouldUpdateCohortMembershipStartDate() {
Period period = mock(Period.class);
GroupMember groupMember = mock(GroupMember.class);
// Existing cohortMembership
CohortMembership cohortMembership = new CohortMembership();
cohortMembership.setStartDate(Date.from(Instant.parse("2020-12-04T08:07:00Z")));
when(groupMember.hasPeriod()).thenReturn(true);
when(groupMember.getPeriod()).thenReturn(period);
// Mocked updated date is today
when(period.getStart()).thenReturn(Date.from(Instant.now()));
CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember);
assertThat(membership, notNullValue());
assertThat(membership.getStartDate(), notNullValue());
assertThat(membership.getStartDate(), DateMatchers.sameDay(Date.from(Instant.now())));
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupComponentTranslatorImpl method toOpenmrsType.
@Override
public GroupMember toOpenmrsType(@Nonnull Group.GroupMemberComponent component) {
GroupMember member = new GroupMember();
member.setId(component.getId());
member.setEntity(component.getEntity());
member.setEntityTarget(component.getEntityTarget());
member.setInactive(component.getInactive());
member.setPeriod(component.getPeriod());
return member;
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImplTest method shouldTranslateGroupMemberComponentToOpenMRSType.
@Test
public void shouldTranslateGroupMemberComponentToOpenMRSType() {
Reference patientReference = mock(Reference.class);
Patient patient = mock(Patient.class);
when(patient.getPatientId()).thenReturn(1);
when(patientReferenceTranslator.toOpenmrsType(patientReference)).thenReturn(patient);
Group.GroupMemberComponent component = new Group.GroupMemberComponent();
component.setEntity(patientReference);
Integer patientId = groupMemberTranslator.toOpenmrsType(new GroupMember(component.getEntity()));
assertThat(patientId, notNullValue());
assertThat(patientId, is(1));
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupTranslatorImplTest method shouldTranslateFHIRGroupMembersToOpenMRSCohortMembers.
@Test
@Ignore
public void shouldTranslateFHIRGroupMembersToOpenMRSCohortMembers() {
Group group = mock(Group.class);
GroupMember groupMember = mock(GroupMember.class);
Reference memberRef = mock(Reference.class);
Group.GroupMemberComponent groupMemberComponent = mock(Group.GroupMemberComponent.class);
when(group.hasMember()).thenReturn(true);
when(group.getMember()).thenReturn(Arrays.asList(groupMemberComponent, groupMemberComponent));
when(groupMember.hasEntity()).thenReturn(true);
when(groupMember.getEntity()).thenReturn(memberRef);
// when(memberRef.getReference()).thenReturn("ref-xxx");
when(groupMemberTranslator.toOpenmrsType(groupMember)).thenReturn(1);
Cohort cohort = groupTranslator.toOpenmrsType(group);
assertThat(cohort, notNullValue());
assertThat(cohort.getMemberIds().isEmpty(), is(false));
assertThat(cohort.getMemberIds(), hasSize(1));
assertThat(cohort.getMemberIds().iterator().next(), is(1));
}
Aggregations