Search in sources :

Example 16 with GroupMember

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;
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Cohort(org.openmrs.Cohort)

Example 17 with GroupMember

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));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.openmrs.Patient) Test(org.junit.Test)

Example 18 with GroupMember

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();
}
Also used : Group(org.hl7.fhir.r4.model.Group) GroupMember(org.openmrs.module.fhir2.model.GroupMember) Before(org.junit.Before)

Example 19 with 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())));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Period(org.hl7.fhir.r4.model.Period) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 20 with GroupMember

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())));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) 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