use of ca.uhn.fhir.rest.param.StringOrListParam in project cqf-ruler by DBCG.
the class CacheValueSetsProvider method cacheValuesets.
/**
* Using basic authentication this {@link Operation Operation} will update
* any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint}
* provided.
* Any Valuesets that require expansion will be expanded.
*
* @param details the {@link RequestDetails RequestDetails}
* @param endpointId the {@link Endpoint Endpoint} id
* @param valuesets the {@link StringAndListParam list} of {@link ValueSet
* Valueset} ids
* @param userName the userName
* @param password the password
* @return the {@link OperationOutcome OperationOutcome} or the resulting
* {@link Bundle Bundle}
*/
@Description(shortDefinition = "$cache-valuesets", value = "Using basic authentication this Operation will update any Valueset listed given the Endpoint provided. Any Valuesets that require expansion will be expanded.", example = "Endpoint/example-id/$cache-valuesets?valuesets=valuesetId1&valuesets=valuesetId2&user=user&password=password")
@Operation(name = "$cache-valuesets", idempotent = true, type = Endpoint.class)
public Resource cacheValuesets(RequestDetails details, @IdParam IdType endpointId, @OperationParam(name = "valuesets") StringAndListParam valuesets, @OperationParam(name = "user") String userName, @OperationParam(name = "pass") String password) {
Endpoint endpoint = null;
try {
endpoint = this.endpointDao.read(endpointId);
if (endpoint == null) {
return createErrorOutcome("Could not find Endpoint/" + endpointId);
}
} catch (Exception e) {
return createErrorOutcome("Could not find Endpoint/" + endpointId + "\n" + e);
}
IGenericClient client = Clients.forEndpoint(ourCtx, endpoint);
if (userName != null || password != null) {
if (userName == null) {
return createErrorOutcome("Password was provided, but not a user name.");
} else if (password == null) {
return createErrorOutcome("User name was provided, but not a password.");
}
BasicAuthInterceptor basicAuth = new BasicAuthInterceptor(userName, password);
client.registerInterceptor(basicAuth);
// TODO - more advanced security like bearer tokens, etc...
}
try {
Bundle bundleToPost = new Bundle();
for (StringOrListParam params : valuesets.getValuesAsQueryTokens()) {
for (StringParam valuesetId : params.getValuesAsQueryTokens()) {
bundleToPost.addEntry().setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.PUT).setUrl("ValueSet/" + valuesetId.getValue())).setResource(resolveValueSet(client, valuesetId.getValue()));
}
}
return (Resource) systemDao.transaction(details, bundleToPost);
} catch (Exception e) {
return createErrorOutcome(e.getMessage());
}
}
use of ca.uhn.fhir.rest.param.StringOrListParam in project cqf-ruler by DBCG.
the class CacheValueSetsProvider method cacheValuesets.
/**
* Using basic authentication this {@link Operation Operation} will update
* any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint}
* provided.
* Any Valuesets that require expansion will be expanded.
*
* @param details the {@link RequestDetails RequestDetails}
* @param endpointId the {@link Endpoint Endpoint} id
* @param valuesets the {@link StringAndListParam list} of {@link ValueSet
* Valueset} ids
* @param userName the userName
* @param password the password
* @return the {@link OperationOutcome OperationOutcome} or the resulting
* {@link Bundle Bundle}
*/
@Description(shortDefinition = "$cache-valuesets", value = "Using basic authentication this Operation will update any Valueset listed given the Endpoint provided. Any Valuesets that require expansion will be expanded.", example = "Endpoint/example-id/$cache-valuesets?valuesets=valuesetId1&valuesets=valuesetId2&user=user&password=password")
@Operation(name = "cache-valuesets", idempotent = true, type = Endpoint.class)
public Resource cacheValuesets(RequestDetails details, @IdParam IdType endpointId, @OperationParam(name = "valuesets") StringAndListParam valuesets, @OperationParam(name = "user") String userName, @OperationParam(name = "pass") String password) {
Endpoint endpoint = null;
try {
endpoint = this.endpointDao.read(endpointId);
if (endpoint == null) {
return createErrorOutcome("Could not find Endpoint/" + endpointId);
}
} catch (Exception e) {
return createErrorOutcome("Could not find Endpoint/" + endpointId + "\n" + e);
}
IGenericClient client = Clients.forEndpoint(ourCtx, endpoint);
if (userName != null || password != null) {
if (userName == null) {
return createErrorOutcome("Password was provided, but not a user name.");
} else if (password == null) {
return createErrorOutcome("User name was provided, but not a password.");
}
BasicAuthInterceptor basicAuth = new BasicAuthInterceptor(userName, password);
client.registerInterceptor(basicAuth);
// TODO - more advanced security like bearer tokens, etc...
}
try {
Bundle bundleToPost = new Bundle();
for (StringOrListParam params : valuesets.getValuesAsQueryTokens()) {
for (StringParam valuesetId : params.getValuesAsQueryTokens()) {
bundleToPost.addEntry().setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.PUT).setUrl("ValueSet/" + valuesetId.getValue())).setResource(resolveValueSet(client, valuesetId.getValue()));
}
}
return (Resource) systemDao.transaction(details, bundleToPost);
} catch (Exception e) {
return createErrorOutcome(e.getMessage());
}
}
use of ca.uhn.fhir.rest.param.StringOrListParam in project openmrs-module-fhir2 by openmrs.
the class FhirPractitionerServiceImplTest method shouldReturnEmptyCollectionByWrongName.
@Test
public void shouldReturnEmptyCollectionByWrongName() {
StringAndListParam name = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(WRONG_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(NAME_SEARCH_HANDLER, NAME_PROPERTY, name);
when(practitionerDao.getSearchResultUuids(any())).thenReturn(Collections.emptyList());
when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, practitionerDao, practitionerTranslator, globalPropertyService, searchQueryInclude));
when(userService.searchForUsers(any())).thenReturn(new SimpleBundleProvider());
IBundleProvider results = practitionerService.searchForPractitioners(null, name, null, null, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, empty());
}
use of ca.uhn.fhir.rest.param.StringOrListParam in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForNameMatched.
@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonForNameMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(GIVEN_NAME)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.NAME_SEARCH_HANDLER, 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(stringAndListParam, null, null, 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)));
}
use of ca.uhn.fhir.rest.param.StringOrListParam in project openmrs-module-fhir2 by openmrs.
the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonCityMatched.
@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonCityMatched() {
StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(CITY)));
SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.CITY_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, stringAndListParam, null, null, null, null, null, null, null);
List<IBaseResource> resultList = get(results);
assertThat(results, notNullValue());
assertThat(resultList, not(empty()));
assertThat(resultList, hasSize(equalTo(1)));
}
Aggregations