use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupTranslatorImpl method toOpenmrsType.
@Override
public Cohort toOpenmrsType(@Nonnull Cohort existingCohort, @Nonnull Group group) {
notNull(group, "group resource object should not be null");
notNull(existingCohort, "ExistingCohort object should not be null");
Cohort finalExistingCohort = super.toOpenmrsType(existingCohort, group);
if (group.hasMember()) {
group.getMember().forEach(member -> finalExistingCohort.addMember(groupMemberTranslator.toOpenmrsType(new GroupMember(member.getEntity()))));
}
return finalExistingCohort;
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImplTest method shouldTranslateCohortMemberToFHIRType.
@Test
public void shouldTranslateCohortMemberToFHIRType() {
Reference patientReference = mock(Reference.class);
Patient patient = mock(Patient.class);
when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
when(patientDao.getPatientById(1)).thenReturn(patient);
GroupMember component = groupMemberTranslator.toFhirResource(1);
assertThat(component, notNullValue());
assertThat(component.getEntity(), notNullValue());
assertThat(component.hasEntity(), is(true));
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupComponentTranslatorImplTest method setup.
@Before
public void setup() {
translator = new GroupComponentTranslatorImpl();
component = new Group.GroupMemberComponent();
member = new GroupMember();
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImpl_2_1Test method shouldUpdateCohortMembershipEndDate.
@Test
public void shouldUpdateCohortMembershipEndDate() {
Period period = mock(Period.class);
GroupMember groupMember = mock(GroupMember.class);
// Existing cohortMembership
CohortMembership cohortMembership = new CohortMembership();
cohortMembership.setEndDate(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.getEnd()).thenReturn(Date.from(Instant.now()));
CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember);
assertThat(membership, notNullValue());
assertThat(membership.getEndDate(), notNullValue());
assertThat(membership.getEndDate(), DateMatchers.sameDay(Date.from(Instant.now())));
}
use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.
the class GroupMemberTranslatorImpl_2_1Test method shouldGroupPeriodToCohortStartAndEndDateOpenMRSType.
@Test
public void shouldGroupPeriodToCohortStartAndEndDateOpenMRSType() {
Period period = mock(Period.class);
GroupMember groupMember = mock(GroupMember.class);
when(groupMember.hasPeriod()).thenReturn(true);
when(groupMember.getPeriod()).thenReturn(period);
when(period.getStart()).thenReturn(Date.from(Instant.now()));
when(period.getEnd()).thenReturn(Date.from(Instant.now()));
CohortMembership membership = groupMemberTranslator.toOpenmrsType(groupMember);
assertThat(membership, notNullValue());
assertThat(membership.getStartDate(), notNullValue());
assertThat(membership.getEndDate(), notNullValue());
assertThat(membership.getStartDate(), DateMatchers.sameDay(Date.from(Instant.now())));
assertThat(membership.getEndDate(), DateMatchers.sameDay(Date.from(Instant.now())));
}
Aggregations