Search in sources :

Example 76 with Person

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

the class PersonFhirResourceProviderWebTest method deletePerson_shouldDeletePerson.

@Test
public void deletePerson_shouldDeletePerson() throws Exception {
    OperationOutcome retVal = new OperationOutcome();
    retVal.setId(PERSON_UUID);
    retVal.getText().setDivAsString("Deleted successfully");
    Person person = new Person();
    person.setId(PERSON_UUID);
    when(personService.delete(PERSON_UUID)).thenReturn(person);
    MockHttpServletResponse response = delete("/Person/" + PERSON_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : OperationOutcome(org.hl7.fhir.r4.model.OperationOutcome) Person(org.hl7.fhir.r4.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 77 with Person

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

the class PersonFhirResourceProviderWebTest method shouldGetPersonHistoryById.

@Test
public void shouldGetPersonHistoryById() throws IOException, ServletException {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    provenance.setRecorded(new Date());
    provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
    provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(AUT).setDisplay(AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
    Person person = new Person();
    person.setId(PERSON_UUID);
    person.addContained(provenance);
    when(personService.get(PERSON_UUID)).thenReturn(person);
    MockHttpServletResponse response = getPersonHistoryByIdRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results, notNullValue());
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), notNullValue());
    assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) Person(org.hl7.fhir.r4.model.Person) Date(java.util.Date) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) IdType(org.hl7.fhir.r4.model.IdType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 78 with Person

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

the class PersonNarrativeTest method shouldGeneratePersonNarrative.

/**
 * Check that the expected narrative is generated for some example Person resource
 *
 * @throws IOException
 */
@Test
public void shouldGeneratePersonNarrative() throws IOException {
    Person given = parser.parseResource(Person.class, getClass().getClassLoader().getResourceAsStream(EXAMPLE_RESOURCE_PATH));
    Person result = parser.parseResource(Person.class, parser.encodeResourceToString(given));
    assertThat(result, notNullValue());
    assertThat(result.getText(), notNullValue());
    assertThat(result.getText().getStatusAsString(), equalTo("generated"));
    assertThat(result.getText().getDivAsString(), equalTo(readNarrativeFile(EXPECTED_NARRATIVE_PATH)));
}
Also used : Person(org.hl7.fhir.r4.model.Person) Test(org.junit.Test)

Example 79 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.dstu3.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 80 with Person

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

the class PersonFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.JSON).go();
    Person person = readResponse(response);
    // update the existing record
    person.setId(WRONG_PERSON_UUID);
    // send the update to the server
    response = put("/Person/" + PERSON_UUID).jsonContent(toJson(person)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isBadRequest());
    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) 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