Search in sources :

Example 81 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldUpdateExistingPersonAsXML.

@Test
public void shouldUpdateExistingPersonAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.XML).go();
    Person person = readResponse(response);
    // update the existing record
    Date birthDate = DateUtils.truncate(new Date(), Calendar.DATE);
    person.setBirthDate(birthDate);
    // send the update to the server
    response = put("/Person/" + PERSON_UUID).xmlContent(toXML(person)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    Person updatedPerson = readResponse(response);
    assertThat(updatedPerson, notNullValue());
    assertThat(updatedPerson.getIdElement().getIdPart(), equalTo(PERSON_UUID));
    assertThat(updatedPerson.getBirthDate(), equalTo(birthDate));
    assertThat(person, validResource());
    // double-check the record returned via get
    response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.XML).go();
    Person reReadPerson = readResponse(response);
    assertThat(reReadPerson.getBirthDate(), equalTo(birthDate));
}
Also used : 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 82 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldReturnExistingPersonAsJson.

@Test
public void shouldReturnExistingPersonAsJson() throws Exception {
    MockHttpServletResponse response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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 83 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 84 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 85 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)

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