Search in sources :

Example 86 with RelatedPerson

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

the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfPersonWhenPersonCountryMatched.

@Test
public void searchForRelatedPeople_shouldReturnCollectionOfPersonWhenPersonCountryMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(COUNTRY)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.COUNTRY_PROPERTY, stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
    when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = relatedPersonService.searchForRelatedPeople(null, null, null, null, null, null, stringAndListParam, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 87 with RelatedPerson

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

the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonStateMatched.

@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonStateMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(STATE)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.STATE_PROPERTY, stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
    when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = relatedPersonService.searchForRelatedPeople(null, null, null, null, stringAndListParam, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 88 with RelatedPerson

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

the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonBirthDateMatched.

@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonBirthDateMatched() throws ParseException {
    Date birthDate = dateFormatter.parse(PERSON_BIRTH_DATE);
    person.setBirthdate(birthDate);
    DateRangeParam dateRangeParam = new DateRangeParam().setLowerBound(PERSON_BIRTH_DATE).setUpperBound(PERSON_BIRTH_DATE);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, dateRangeParam);
    when(dao.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
    when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = relatedPersonService.searchForRelatedPeople(null, null, dateRangeParam, null, null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Date(java.util.Date) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 89 with RelatedPerson

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

the class FhirRelatedPersonServiceImplTest method setup.

@Before
public void setup() {
    relatedPersonService = new FhirRelatedPersonServiceImpl() {

        @Override
        protected void validateObject(Relationship object) {
        }
    };
    relatedPersonService.setDao(dao);
    relatedPersonService.setTranslator(translator);
    relatedPersonService.setSearchQuery(searchQuery);
    relatedPersonService.setSearchQueryInclude(searchQueryInclude);
    PersonName name = new PersonName();
    name.setUuid(PERSON_NAME_UUID);
    name.setGivenName(GIVEN_NAME);
    name.setFamilyName(FAMILY_NAME);
    PersonAddress address = new PersonAddress();
    address.setCityVillage(CITY);
    address.setStateProvince(STATE);
    address.setPostalCode(POSTAL_CODE);
    address.setCountry(COUNTRY);
    person = new org.openmrs.Person();
    person.setUuid(PERSON_UUID);
    person.setGender("M");
    person.addName(name);
    relationship = new org.openmrs.Relationship();
    relationship.setRelationshipId(1000);
    relationship.setPersonA(person);
    HumanName humanName = new HumanName();
    humanName.addGiven(GIVEN_NAME);
    humanName.setFamily(FAMILY_NAME);
    humanName.setId(PERSON_NAME_UUID);
    Address relatedPersonAddress = new Address();
    relatedPersonAddress.setCity(CITY);
    relatedPersonAddress.setState(STATE);
    relatedPersonAddress.setPostalCode(POSTAL_CODE);
    relatedPersonAddress.setCountry(COUNTRY);
    relatedPerson = new RelatedPerson();
    relatedPerson.addName(humanName);
    relatedPerson.addAddress(relatedPersonAddress);
    relatedPerson.setGender(Enumerations.AdministrativeGender.MALE);
}
Also used : Relationship(org.openmrs.Relationship) HumanName(org.hl7.fhir.r4.model.HumanName) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Address(org.hl7.fhir.r4.model.Address) PersonAddress(org.openmrs.PersonAddress) Relationship(org.openmrs.Relationship) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Before(org.junit.Before)

Example 90 with RelatedPerson

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

the class RelatedPersonSearchQueryTest method shouldReturnCollectionOfRelatedPeopleByMatchingUuidAndLastUpdated.

@Test
public void shouldReturnCollectionOfRelatedPeopleByMatchingUuidAndLastUpdated() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(RELATIONSHIP_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setUpperBound(DATE_CREATED).setLowerBound(DATE_CREATED);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    List<RelatedPerson> resultList = get(results);
    assertThat(resultList, hasSize(equalTo(1)));
    assertThat(resultList.get(0).getIdElement().getIdPart(), equalTo(RELATIONSHIP_UUID));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)87 RelatedPerson (org.hl7.fhir.r4.model.RelatedPerson)54 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)51 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)29 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)24 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)24 StringParam (ca.uhn.fhir.rest.param.StringParam)24 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)24 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)20 RelatedPerson (org.hl7.fhir.dstu3.model.RelatedPerson)17 Test (org.junit.jupiter.api.Test)17 Resource (org.hl7.fhir.r4.model.Resource)14 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)13 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)12 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)12 Patient (org.hl7.fhir.r4.model.Patient)12 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)11 Identifier (org.hl7.fhir.r4.model.Identifier)10 Reference (org.hl7.fhir.r4.model.Reference)9