Search in sources :

Example 6 with GroupMember

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

Example 7 with GroupMember

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())));
}
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 8 with GroupMember

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

Example 9 with GroupMember

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

Example 10 with GroupMember

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