Search in sources :

Example 1 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class FhirGroupMemberService_2_1Test method shouldSearchForGroupMembersByGroupUuid.

@Test
public void shouldSearchForGroupMembersByGroupUuid() {
    GroupMember groupMember = mock(GroupMember.class);
    CohortMembership cohortMembership = mock(CohortMembership.class);
    List<CohortMembership> memberships = new ArrayList<>();
    memberships.add(cohortMembership);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GROUP_MEMBERS_SEARCH_HANDLER, GROUP_MEMBER_UUID);
    when(dao.getSearchResults(any(), any())).thenReturn(memberships);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(GROUP_MEMBER_UUID));
    when(translator.toFhirResource(cohortMembership)).thenReturn(groupMember);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = groupMemberService.getGroupMembers(GROUP_MEMBER_UUID);
    List<IBaseResource> resultList = get(results);
    assertThat(results, Matchers.notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(1));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) ArrayList(java.util.ArrayList) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) CohortMembership(org.openmrs.CohortMembership) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 2 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupComponentTranslatorImplTest method shouldTranslateEntityToOpenmrsType.

@Test
public void shouldTranslateEntityToOpenmrsType() {
    Reference patientRef = new Reference(PATIENT_REF);
    component.setEntity(patientRef);
    GroupMember result = translator.toOpenmrsType(component);
    assertThat(result.getEntity().getReference(), is(PATIENT_REF));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Reference(org.hl7.fhir.r4.model.Reference) Test(org.junit.Test)

Example 3 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupComponentTranslatorImplTest method shouldTranslateEntityTargetToOpenmrsType.

@Test
public void shouldTranslateEntityTargetToOpenmrsType() {
    Resource resource = Mockito.mock(Resource.class);
    component.setEntityTarget(resource);
    when(resource.getId()).thenReturn(String.valueOf(1));
    GroupMember result = translator.toOpenmrsType(component);
    assertThat(result.getEntityTarget().getId(), is("1"));
}
Also used : GroupMember(org.openmrs.module.fhir2.model.GroupMember) Resource(org.hl7.fhir.r4.model.Resource) Test(org.junit.Test)

Example 4 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupMemberTranslatorImpl_2_1Test method shouldTranslateCohortMemberStartDateToFHIRType.

@Test
public void shouldTranslateCohortMemberStartDateToFHIRType() {
    CohortMembership cohortMembership = mock(CohortMembership.class);
    Patient patient = mock(Patient.class);
    Reference patientReference = mock(Reference.class);
    when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
    when(patientDao.getPatientById(anyInt())).thenReturn(patient);
    when(cohortMembership.getStartDate()).thenReturn(Date.from(Instant.now()));
    GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership);
    assertThat(component, notNullValue());
    assertThat(component.hasPeriod(), is(true));
    assertThat(component.getPeriod().getStart(), notNullValue());
    assertThat(Date.from(Instant.now()), DateMatchers.sameDay(component.getPeriod().getStart()));
}
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 5 with GroupMember

use of org.openmrs.module.fhir2.model.GroupMember in project openmrs-module-fhir2 by openmrs.

the class GroupMemberTranslatorImpl_2_1Test method shouldTranslateCohortMemberEndDateToFHIRType.

@Test
public void shouldTranslateCohortMemberEndDateToFHIRType() {
    CohortMembership cohortMembership = mock(CohortMembership.class);
    Patient patient = mock(Patient.class);
    Reference patientReference = mock(Reference.class);
    when(patientReferenceTranslator.toFhirResource(patient)).thenReturn(patientReference);
    when(patientDao.getPatientById(anyInt())).thenReturn(patient);
    when(cohortMembership.getEndDate()).thenReturn(Date.from(Instant.now()));
    GroupMember component = groupMemberTranslator.toFhirResource(cohortMembership);
    assertThat(component, notNullValue());
    assertThat(component.hasPeriod(), is(true));
    assertThat(component.getPeriod().getEnd(), notNullValue());
    assertThat(Date.from(Instant.now()), DateMatchers.sameDay(component.getPeriod().getEnd()));
}
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)

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