Search in sources :

Example 26 with GroupMember

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

Example 27 with GroupMember

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

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