Search in sources :

Example 31 with Group

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;
}
Also used : Group(org.hl7.fhir.r4.model.Group)

Example 32 with 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;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Group(org.hl7.fhir.r4.model.Group) StringType(org.hl7.fhir.r4.model.StringType)

Example 33 with 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()));
}
Also used : Group(org.hl7.fhir.dstu3.model.Group) OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 34 with Group

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));
}
Also used : Group(org.hl7.fhir.r4.model.Group) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 35 with Group

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

Aggregations

Test (org.junit.Test)90 Group (org.hl7.fhir.r4.model.Group)74 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)49 Group (org.hl7.fhir.dstu3.model.Group)44 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)40 Cohort (org.openmrs.Cohort)30 InputStream (java.io.InputStream)20 ArrayList (java.util.ArrayList)16 Structure (ca.uhn.hl7v2.model.Structure)13 Test (org.junit.jupiter.api.Test)13 Group (ca.uhn.hl7v2.model.Group)12 UUID (java.util.UUID)12 Reference (org.hl7.fhir.r4.model.Reference)12 HL7Exception (ca.uhn.hl7v2.HL7Exception)11 List (java.util.List)10 IdType (org.hl7.fhir.dstu3.model.IdType)9 Message (ca.uhn.hl7v2.model.Message)7 Patient (org.hl7.fhir.dstu3.model.Patient)7 PatientEntity (gov.cms.dpc.common.entities.PatientEntity)6 ProviderEntity (gov.cms.dpc.common.entities.ProviderEntity)6