use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupTranslatorImpl method toFhirResource.
@Override
public Group toFhirResource(@Nonnull Cohort cohort) {
notNull(cohort, "Cohort object should not be null");
Group group = super.toFhirResource(cohort);
Set<Integer> memberIds = cohort.getMemberIds();
log.info("Number of members {} ", memberIds.size());
group.setQuantity(cohort.size());
memberIds.forEach(id -> {
Group.GroupMemberComponent groupMemberComponent = new Group.GroupMemberComponent();
groupMemberComponent.setEntity(groupMemberTranslator.toFhirResource(id).getEntity());
group.addMember(groupMemberComponent);
});
return group;
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class BaseGroupTranslator method toFhirResource.
public Group toFhirResource(@Nonnull Cohort cohort) {
notNull(cohort, "Cohort object should not be null");
Group group = new Group();
group.setId(cohort.getUuid());
group.setActive(!cohort.getVoided());
/*
* Apparently, cohort.description is a required field
*/
group.addExtension(new Extension().setUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION).setValue(new StringType(cohort.getDescription())));
// Not sure about this, It's either actual or descriptive
// I will set actual - true temporarily as it required - valid resource.
group.setActual(true);
// Set to always person for now
group.setType(Group.GroupType.PERSON);
group.setName(cohort.getName());
group.setManagingEntity(practitionerReferenceTranslator.toFhirResource(cohort.getCreator()));
return group;
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderWebTest method deleteGroup_shouldDeleteGroup.
@Test
public void deleteGroup_shouldDeleteGroup() throws Exception {
OperationOutcome retVal = new OperationOutcome();
retVal.setId(COHORT_UUID);
retVal.getText().setDivAsString("Deleted Successfully");
org.hl7.fhir.r4.model.Group group = new org.hl7.fhir.r4.model.Group();
group.setId(COHORT_UUID);
when(groupService.delete(COHORT_UUID)).thenReturn(group);
MockHttpServletResponse response = delete("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderWebTest method shouldGetGroupByUuid.
@Test
public void shouldGetGroupByUuid() throws Exception {
Group group = new Group();
group.setId(COHORT_UUID);
when(groupService.get(COHORT_UUID)).thenReturn(group);
MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
Group resource = readResponse(response);
assertThat(resource.getIdElement().getIdPart(), equalTo(COHORT_UUID));
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupTranslatorImpl_2_1Test method shouldTranslateActiveFHIRTypeToIsVoidedOpenMRSType.
@Test
public void shouldTranslateActiveFHIRTypeToIsVoidedOpenMRSType() {
Group group = mock(Group.class);
when(group.hasActive()).thenReturn(true);
when(group.getActive()).thenReturn(true);
Cohort cohort = groupTranslator.toOpenmrsType(group);
assertThat(cohort, notNullValue());
assertThat(cohort.getVoided(), is(false));
}
Aggregations