Search in sources :

Example 91 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.r4.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 92 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.r4.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 93 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldSearchForAllPersonsAsJson.

@Test
public void shouldSearchForAllPersonsAsJson() throws Exception {
    MockHttpServletResponse response = get("/Person").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/Person/"))));
    assertThat(entries, everyItem(hasResource(instanceOf(Person.class))));
    assertThat(entries, everyItem(hasResource(validResource())));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) Person(org.hl7.fhir.r4.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 94 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.r4.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 95 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldReturnSortedAndFilteredSearchResultsForPersonsAsJson.

@Test
public void shouldReturnSortedAndFilteredSearchResultsForPersonsAsJson() throws Exception {
    MockHttpServletResponse response = get("/Person?name=voided&_sort=given").accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.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", startsWith("voided"))))));
    assertThat(entries, containsInRelativeOrder(hasResource(hasProperty("nameFirstRep", hasProperty("givenAsSingleString", containsString("I"))))));
    assertThat(entries, everyItem(hasResource(validResource())));
}
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