Search in sources :

Example 36 with Person

use of org.hl7.fhir.r4.model.Person in project elexis-server by elexis.

the class PersonResourceProvider method search.

@Search
public List<Person> search(@OptionalParam(name = Person.SP_NAME) StringParam name, @OptionalParam(name = ca.uhn.fhir.rest.api.Constants.PARAM_FILTER) StringAndListParam theFtFilter) {
    IQuery<IPerson> query = modelService.getQuery(IPerson.class);
    if (name != null) {
        QueryUtil.andContactNameCriterion(query, name);
    }
    if (theFtFilter != null) {
        new IContactSearchFilterQueryAdapter().adapt(query, theFtFilter);
    }
    List<IPerson> persons = query.execute();
    List<Person> _persons = persons.parallelStream().map(org -> getTransformer().getFhirObject(org)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    return _persons;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) IFhirTransformerRegistry(ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry) IFhirTransformer(ch.elexis.core.findings.util.fhir.IFhirTransformer) LoggerFactory(org.slf4j.LoggerFactory) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Update(ca.uhn.fhir.rest.annotation.Update) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IModelService(ch.elexis.core.services.IModelService) Component(org.osgi.service.component.annotations.Component) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Search(ca.uhn.fhir.rest.annotation.Search) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) Delete(ca.uhn.fhir.rest.annotation.Delete) Activate(org.osgi.service.component.annotations.Activate) Person(org.hl7.fhir.r4.model.Person) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Read(ca.uhn.fhir.rest.annotation.Read) Logger(org.slf4j.Logger) Create(ca.uhn.fhir.rest.annotation.Create) IPerson(ch.elexis.core.model.IPerson) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) IQuery(ch.elexis.core.services.IQuery) List(java.util.List) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) QueryUtil(es.fhir.rest.core.resources.util.QueryUtil) StringParam(ca.uhn.fhir.rest.param.StringParam) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Reference(org.osgi.service.component.annotations.Reference) IPerson(ch.elexis.core.model.IPerson) Optional(java.util.Optional) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) Person(org.hl7.fhir.r4.model.Person) IPerson(ch.elexis.core.model.IPerson) Search(ca.uhn.fhir.rest.annotation.Search)

Example 37 with Person

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

the class PersonFhirResourceProviderTest method createPerson_shouldCreateNewPerson.

@Test
public void createPerson_shouldCreateNewPerson() {
    when(fhirPersonService.create(any(org.hl7.fhir.r4.model.Person.class))).thenReturn(person);
    MethodOutcome result = resourceProvider.createPerson(Person30_40.convertPerson(person));
    assertThat(result, notNullValue());
    assertThat(result.getCreated(), is(true));
    assertThat(result.getResource(), notNullValue());
    assertThat(result.getResource().getIdElement().getIdPart(), equalTo(PERSON_UUID));
}
Also used : Person(org.hl7.fhir.dstu3.model.Person) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Test(org.junit.Test)

Example 38 with Person

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

the class PersonFhirResourceProviderTest method searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode.

@Test
public void searchForPeople_shouldReturnMatchingBundleOfPeopleByPostalCode() {
    StringAndListParam postalCodeParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(POSTAL_CODE)));
    when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(postalCodeParam)), isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, postalCodeParam, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList.iterator().next().fhirType(), is(FhirConstants.PERSON));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) MockIBundleProvider(org.openmrs.module.fhir2.providers.r4.MockIBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) Test(org.junit.Test)

Example 39 with Person

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

the class PersonFhirResourceProviderTest method searchForPeople_shouldAddRelatedResourcesWhenIncluded.

@Test
public void searchForPeople_shouldAddRelatedResourcesWhenIncluded() {
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("Person:patient"));
    when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(includes)))).thenReturn(new MockIBundleProvider<>(Arrays.asList(person, new Patient()), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, null, null, null, null, includes);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList.get(0).fhirType(), is(FhirConstants.PERSON));
    assertThat(resultList.get(1).fhirType(), is(FhirConstants.PATIENT));
    assertThat(resultList.size(), equalTo(2));
}
Also used : Include(ca.uhn.fhir.model.api.Include) Patient(org.hl7.fhir.r4.model.Patient) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) MockIBundleProvider(org.openmrs.module.fhir2.providers.r4.MockIBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with Person

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

the class PersonFhirResourceProviderTest method searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry.

@Test
public void searchForPeople_shouldReturnMatchingBundleOfPeopleByCountry() {
    StringAndListParam countryParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(COUNTRY)));
    when(fhirPersonService.searchForPeople(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), argThat(is(countryParam)), isNull(), isNull(), isNull(), isNull())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(person), PREFERRED_PAGE_SIZE, COUNT));
    IBundleProvider results = resourceProvider.searchPeople(null, null, null, null, null, null, countryParam, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList.iterator().next().fhirType(), is(FhirConstants.PERSON));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) MockIBundleProvider(org.openmrs.module.fhir2.providers.r4.MockIBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) 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