Search in sources :

Example 81 with Location

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()));
}
Also used : InputStream(java.io.InputStream) Patient(org.hl7.fhir.dstu3.model.Patient) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 82 with Location

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()));
}
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 83 with Location

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()));
}
Also used : InputStream(java.io.InputStream) Patient(org.hl7.fhir.r4.model.Patient) Matchers.containsString(org.hamcrest.Matchers.containsString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 84 with Location

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()));
}
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 85 with Location

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)));
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)215 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)94 Location (org.hl7.fhir.r4.model.Location)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)71 Location (org.hl7.fhir.dstu3.model.Location)66 InputStream (java.io.InputStream)46 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)39 Matchers.containsString (org.hamcrest.Matchers.containsString)38 Test (org.junit.jupiter.api.Test)38 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)37 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)35 ArrayList (java.util.ArrayList)29 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)29 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)26 Reference (org.hl7.fhir.r4.model.Reference)25 Date (java.util.Date)24 Bundle (org.hl7.fhir.r4.model.Bundle)24 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)24 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23