Search in sources :

Example 36 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupTranslatorImpl_2_1Test method shouldTranslateFHIRGroupMembersToOpenMRSCohortMembers.

@Test
public void shouldTranslateFHIRGroupMembersToOpenMRSCohortMembers() {
    Group group = mock(Group.class);
    CohortMembership cohortMembership = mock(CohortMembership.class);
    GroupMember groupMember = mock(GroupMember.class);
    Group.GroupMemberComponent groupMemberComponent = mock(Group.GroupMemberComponent.class);
    when(group.hasMember()).thenReturn(true);
    when(group.getMember()).thenReturn(Arrays.asList(groupMemberComponent, groupMemberComponent));
    when(groupMemberTranslator21.toOpenmrsType(groupMember)).thenReturn(cohortMembership);
    when(componentTranslator.toOpenmrsType(groupMemberComponent)).thenReturn(groupMember);
    Cohort cohort = groupTranslator.toOpenmrsType(group);
    assertThat(cohort, notNullValue());
    assertThat(cohort.getMemberships().isEmpty(), is(false));
    assertThat(cohort.getMemberships(), hasSize(1));
    assertThat(cohort.getMemberships().iterator().next(), is(cohortMembership));
}
Also used : Group(org.hl7.fhir.r4.model.Group) GroupMember(org.openmrs.module.fhir2.model.GroupMember) Cohort(org.openmrs.Cohort) CohortMembership(org.openmrs.CohortMembership) Test(org.junit.Test)

Example 37 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupTranslatorImpl_2_1Test method shouldTranslateCreatorToManagingEntityFHIRType.

@Test
public void shouldTranslateCreatorToManagingEntityFHIRType() {
    User user = mock(User.class);
    Cohort cohort = new Cohort();
    cohort.setUuid(COHORT_UUID);
    cohort.setName(COHORT_NAME);
    cohort.setCreator(user);
    Reference practitionerRef = mock(Reference.class);
    when(practitionerReferenceTranslator.toFhirResource(user)).thenReturn(practitionerRef);
    Group result = groupTranslator.toFhirResource(cohort);
    assertThat(result, notNullValue());
    assertThat(result.hasManagingEntity(), is(true));
    assertThat(result.getManagingEntity(), is(practitionerRef));
}
Also used : Group(org.hl7.fhir.r4.model.Group) User(org.openmrs.User) Cohort(org.openmrs.Cohort) Reference(org.hl7.fhir.r4.model.Reference) Test(org.junit.Test)

Example 38 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupTranslatorImpl_2_1Test method shouldTranslateGroupTypeToAlwaysPerson.

@Test
public void shouldTranslateGroupTypeToAlwaysPerson() {
    Cohort cohort = mock(Cohort.class);
    Group group = groupTranslator.toFhirResource(cohort);
    assertThat(group, notNullValue());
    assertThat(group.getType(), is(Group.GroupType.PERSON));
}
Also used : Group(org.hl7.fhir.r4.model.Group) Cohort(org.openmrs.Cohort) Test(org.junit.Test)

Example 39 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldCreateNewGroupAsXML.

@Test
public void shouldCreateNewGroupAsXML() throws Exception {
    // read JSON record
    String xmlGroup;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_GROUP_DOCUMENT)) {
        Objects.requireNonNull(is);
        xmlGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create group
    MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.XML).xmlContent(xmlGroup).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Group group = readResponse(response);
    assertThat(group, notNullValue());
    assertThat(group.getActive(), is(true));
    assertThat(group.hasMember(), is(true));
    assertThat(group.getMember(), notNullValue());
    assertThat(group.getQuantity(), equalTo(1));
    // try to get new group
    response = get(group.getId()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Group newGroup = readResponse(response);
    assertThat(newGroup.getId(), equalTo(group.getId()));
    assertThat(newGroup.getActive(), equalTo(true));
}
Also used : Group(org.hl7.fhir.dstu3.model.Group) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 40 with Group

use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.

the class GroupResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
    Group group = readResponse(response);
    // update the existing record
    group.setId(BAD_COHORT_UUID);
    // send the update to the server
    response = put("/Group/" + BAD_COHORT_UUID).xmlContent(toXML(group)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : Group(org.hl7.fhir.dstu3.model.Group) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

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