Search in sources :

Example 46 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonFhirResourceProviderIntegrationTest method shouldReturnRelatedPersonAsJson.

@Test
public void shouldReturnRelatedPersonAsJson() throws Exception {
    MockHttpServletResponse response = get("/RelatedPerson/" + RELATIONSHIP_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    RelatedPerson relatedPerson = readResponse(response);
    assertThat(relatedPerson, notNullValue());
    assertThat(relatedPerson.getIdElement().getIdPart(), equalTo(RELATIONSHIP_UUID));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) RelatedPerson(org.hl7.fhir.dstu3.model.RelatedPerson) Test(org.junit.Test)

Example 47 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonFhirResourceProviderIntegrationTest method shouldReturnSortedAndFilterSearchResultsForRelatedPersonAsXML.

@Test
public void shouldReturnSortedAndFilterSearchResultsForRelatedPersonAsXML() throws Exception {
    MockHttpServletResponse response = get("/RelatedPerson?name=John&_sort=-date").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(results.hasEntry(), is(true));
    List<Bundle.BundleEntryComponent> entries = results.getEntry();
    assertThat(entries, everyItem(hasResource(hasProperty("nameFirstRep", hasProperty("family", containsString("Doe"))))));
    assertThat(entries, containsInRelativeOrder(hasResource(hasProperty("nameFirstRep", hasProperty("givenAsSingleString", containsString("F"))))));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 48 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonFhirResourceProviderTest method getRelatedPersonById_shouldReturnMatchingRelatedPerson.

@Test
public void getRelatedPersonById_shouldReturnMatchingRelatedPerson() {
    when(relatedPersonService.get(RELATED_PERSON_UUID)).thenReturn(relatedPerson);
    IdType id = new IdType();
    id.setValue(RELATED_PERSON_UUID);
    RelatedPerson relatedPerson = resourceProvider.getRelatedPersonById(id);
    assertThat(relatedPerson, notNullValue());
    assertThat(relatedPerson.getId(), notNullValue());
    assertThat(relatedPerson.getId(), equalTo(RELATED_PERSON_UUID));
}
Also used : RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 49 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonFhirResourceProviderTest method searchForRelatedPeople_shouldReturnMatchingBundleOfRelatedPeopleByUUID.

@Test
public void searchForRelatedPeople_shouldReturnMatchingBundleOfRelatedPeopleByUUID() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(RELATED_PERSON_UUID));
    when(relatedPersonService.searchForRelatedPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(uuid)), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(relatedPerson), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchRelatedPerson(null, null, null, null, null, null, null, uuid, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, Matchers.notNullValue());
    assertThat(resultList.iterator().next().fhirType(), equalTo(FhirConstants.RELATED_PERSON));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 50 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonFhirResourceProviderTest method initRelatedPerson.

@Before
public void initRelatedPerson() {
    HumanName name = new HumanName();
    name.addGiven(GIVEN_NAME);
    name.setFamily(FAMILY_NAME);
    relatedPerson = new RelatedPerson();
    relatedPerson.setId(RELATED_PERSON_UUID);
    relatedPerson.setGender(Enumerations.AdministrativeGender.MALE);
    relatedPerson.addName(name);
    setProvenanceResources(relatedPerson);
}
Also used : HumanName(org.hl7.fhir.r4.model.HumanName) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)87 RelatedPerson (org.hl7.fhir.r4.model.RelatedPerson)54 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)51 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)29 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)24 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)24 StringParam (ca.uhn.fhir.rest.param.StringParam)24 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)24 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)20 RelatedPerson (org.hl7.fhir.dstu3.model.RelatedPerson)17 Test (org.junit.jupiter.api.Test)17 Resource (org.hl7.fhir.r4.model.Resource)14 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)13 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)12 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)12 Patient (org.hl7.fhir.r4.model.Patient)12 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)11 Identifier (org.hl7.fhir.r4.model.Identifier)10 Reference (org.hl7.fhir.r4.model.Reference)9