Search in sources :

Example 96 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldCreateNewPersonAsXML.

@Test
public void shouldCreateNewPersonAsXML() throws Exception {
    // read XML record
    String xmlPerson;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_PERSON)) {
        Objects.requireNonNull(is);
        xmlPerson = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create person
    MockHttpServletResponse response = post("/Person").accept(FhirMediaTypes.XML).xmlContent(xmlPerson).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getHeader("Location"), containsString("/Person/"));
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Person person = readResponse(response);
    assertThat(person, notNullValue());
    assertThat(person.getIdElement().getIdPart(), notNullValue());
    assertThat(person.getName().get(0).getGiven().get(0).toString(), equalToIgnoringCase("Adam"));
    assertThat(person.getName().get(0).getFamily(), equalToIgnoringCase("John"));
    assertThat(person.getGender(), equalTo(Enumerations.AdministrativeGender.MALE));
    Date birthDate = Date.from(LocalDate.of(2004, 8, 12).atStartOfDay(ZoneId.systemDefault()).toInstant());
    assertThat(person.getBirthDate(), equalTo(birthDate));
    assertThat(person.getAddress().get(0).getCity(), equalTo("Kampala"));
    assertThat(person.getAddress().get(0).getState(), equalTo("Mukono"));
    assertThat(person.getAddress().get(0).getCountry(), equalTo("Uganda"));
    assertThat(person, validResource());
    // try to get new person
    response = get("/Person/" + person.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Person newPerson = readResponse(response);
    assertThat(newPerson.getId(), equalTo(person.getId()));
}
Also used : InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Person(org.hl7.fhir.dstu3.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 97 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentPerson.

@Test
public void shouldReturnNotFoundWhenDeletingNonExistentPerson() throws Exception {
    MockHttpServletResponse response = delete("/Person/" + WRONG_PERSON_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 98 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldReturnExistingPersonAsXML.

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

Example 99 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.JSON).go();
    Person person = readResponse(response);
    // update the existing record
    person.setId(WRONG_PERSON_UUID);
    // send the update to the server
    response = put("/Person/" + PERSON_UUID).jsonContent(toJson(person)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isBadRequest());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Person(org.hl7.fhir.r4.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 100 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldReturnCountForPersonAsXml.

@Test
public void shouldReturnCountForPersonAsXml() throws Exception {
    MockHttpServletResponse response = get("/Person?name=voided&_summary=count").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle result = readBundleResponse(response);
    assertThat(result, notNullValue());
    assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(result, hasProperty("total", equalTo(1)));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)181 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)54 Date (java.util.Date)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)48 Person (org.hl7.fhir.r4.model.Person)47 Person (model.Person)44 Person (com.google.api.services.people.v1.model.Person)38 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)37 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)32 Reference (org.hl7.fhir.r4.model.Reference)31 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)30 StringParam (ca.uhn.fhir.rest.param.StringParam)30 VCard (ezvcard.VCard)30 Person (org.openmrs.Person)29 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)23 List (java.util.List)22 Collectors (java.util.stream.Collectors)22 Person (org.hl7.fhir.dstu3.model.Person)22 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)22 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)21