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));
}
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));
}
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"));
}
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()));
}
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()));
}
Aggregations