use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.
the class PatientFhirResourceProviderIntegrationTest method shouldCreateNewPatientAsJson.
@Test
public void shouldCreateNewPatientAsJson() throws Exception {
// read JSON record
String jsonPatient;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_PATIENT_DOCUMENT)) {
Objects.requireNonNull(is);
jsonPatient = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create patient
MockHttpServletResponse response = post("/Patient").accept(FhirMediaTypes.JSON).jsonContent(jsonPatient).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getHeader("Location"), containsString("/Patient/"));
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Patient patient = readResponse(response);
assertThat(patient, notNullValue());
assertThat(patient.getIdElement().getIdPart(), notNullValue());
assertThat(patient.getName().get(0).getGiven().get(0).toString(), equalToIgnoringCase("Adam"));
assertThat(patient.getName().get(0).getFamily(), equalToIgnoringCase("John"));
assertThat(patient.getGender(), equalTo(Enumerations.AdministrativeGender.MALE));
Date birthDate = Date.from(LocalDate.of(2004, 8, 12).atStartOfDay(ZoneId.systemDefault()).toInstant());
assertThat(patient.getBirthDate(), equalTo(birthDate));
assertThat(patient.getAddress().get(0).getCity(), equalTo("Kampala"));
assertThat(patient.getAddress().get(0).getState(), equalTo("Mukono"));
assertThat(patient.getAddress().get(0).getCountry(), equalTo("Uganda"));
assertThat(patient, validResource());
// try to get new patient
response = get("/Patient/" + patient.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Patient newPatient = readResponse(response);
assertThat(newPatient.getId(), equalTo(patient.getId()));
}
use of org.hl7.fhir.r4.model.Location 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.Location in project openmrs-module-fhir2 by openmrs.
the class PatientFhirResourceProviderIntegrationTest method shouldCreateNewPatientAsXML.
@Test
public void shouldCreateNewPatientAsXML() throws Exception {
// read XML record
String xmlPatient;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_PATIENT_DOCUMENT)) {
Objects.requireNonNull(is);
xmlPatient = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create patient
MockHttpServletResponse response = post("/Patient").accept(FhirMediaTypes.XML).xmlContent(xmlPatient).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getHeader("Location"), containsString("/Patient/"));
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Patient patient = readResponse(response);
assertThat(patient, notNullValue());
assertThat(patient.getIdElement().getIdPart(), notNullValue());
assertThat(patient.getName().get(0).getGiven().get(0).toString(), equalToIgnoringCase("Adam"));
assertThat(patient.getName().get(0).getFamily(), equalToIgnoringCase("John"));
assertThat(patient.getGender(), equalTo(Enumerations.AdministrativeGender.MALE));
Date birthDate = Date.from(LocalDate.of(2004, 8, 12).atStartOfDay(ZoneId.systemDefault()).toInstant());
assertThat(patient.getBirthDate(), equalTo(birthDate));
assertThat(patient.getAddress().get(0).getCity(), equalTo("Kampala"));
assertThat(patient.getAddress().get(0).getState(), equalTo("Mukono"));
assertThat(patient.getAddress().get(0).getCountry(), equalTo("Uganda"));
assertThat(patient, validResource());
// try to get new patient
response = get("/Patient/" + patient.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
Patient newPatient = readResponse(response);
assertThat(newPatient.getId(), equalTo(patient.getId()));
}
use of org.hl7.fhir.r4.model.Location 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.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldReturnCountForLocationAsJson.
@Test
public void shouldReturnCountForLocationAsJson() throws Exception {
MockHttpServletResponse response = get("/Location?_summary=count").accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Bundle result = readBundleResponse(response);
assertThat(result, notNullValue());
assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
assertThat(result, hasProperty("total", equalTo(8)));
}
Aggregations