use of org.hl7.fhir.r4b.model.IdType 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 org.hl7.fhir.r4b.model.IdType 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 org.hl7.fhir.r4b.model.IdType in project cqf-ruler by DBCG.
the class CacheValueSetsProviderIT method testCacheValueSetsEndpointDNE.
@Test
public void testCacheValueSetsEndpointDNE() throws Exception {
Endpoint endpoint = new Endpoint();
endpoint.setId(new IdType("localhost"));
StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json");
RequestDetails details = Mockito.mock(RequestDetails.class);
Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null);
String detailMessage = "Could not find Endpoint/" + endpoint.getIdElement().getIdPart();
validateOutcome(outcomeResource, detailMessage);
}
use of org.hl7.fhir.r4b.model.IdType in project cqf-ruler by DBCG.
the class DataOperationProviderIT method testR4MeasureDataRequirementsOperation.
@Test
public void testR4MeasureDataRequirementsOperation() throws IOException {
String bundleAsText = stringFromResource("Exm104FhirR4MeasureBundle.json");
Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText);
getClient().transaction().withBundle(bundle).execute();
Parameters params = new Parameters();
params.addParameter().setName("startPeriod").setValue(new StringType("2019-01-01"));
params.addParameter().setName("endPeriod").setValue(new StringType("2020-01-01"));
Library returnLibrary = getClient().operation().onInstance(new IdType("Measure", "measure-EXM104-8.2.000")).named("$data-requirements").withParameters(params).returnResourceType(Library.class).execute();
assertNotNull(returnLibrary);
}
use of org.hl7.fhir.r4b.model.IdType in project cqf-ruler by DBCG.
the class DataOperationProviderIT method testR4LibraryDataRequirementsOperation.
@Test
public void testR4LibraryDataRequirementsOperation() throws IOException {
String bundleAsText = stringFromResource("DataReqLibraryTransactionBundle.json");
Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText);
getClient().transaction().withBundle(bundle).execute();
Parameters params = new Parameters();
params.addParameter().setName("target").setValue(new StringType("dummy"));
Library returnLibrary = getClient().operation().onInstance(new IdType("Library", "LibraryEvaluationTest")).named("$data-requirements").withParameters(params).returnResourceType(Library.class).execute();
assertNotNull(returnLibrary);
}
Aggregations