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());
}
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));
}
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())));
}
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()));
}
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())));
}
Aggregations