use of org.hl7.fhir.utilities.graphql.Operation in project quality-measure-and-cohort-service by Alvearie.
the class MeasureImporter method importFile.
/**
* Import the contents of a single UI export file.
*
* @param inputPath path to the UI export file.
* @param output path to the folder where output will be written
* @return Pair of FHIR resources representing the request bundle and server response (bundle, operation outcome, etc.)
* @throws Exception on any error
*/
public Pair<Bundle, IBaseResource> importFile(String inputPath, String output) throws Exception {
Bundle request;
try (InputStream is = new FileInputStream(inputPath)) {
request = convertToBundle(is);
}
Path outputPath = Paths.get(output);
Path requestPath = outputPath.resolve(FilenameUtils.getBaseName(inputPath) + "-request.json");
Files.write(requestPath, parser.encodeResourceToString(request).getBytes(StandardCharsets.UTF_8));
IBaseResource response = null;
try {
response = client.transaction().withBundle(request).execute();
} catch (BaseServerResponseException ex) {
if (ex.getOperationOutcome() != null) {
response = ex.getOperationOutcome();
} else {
throw ex;
}
}
if (response != null) {
Path responsePath = outputPath.resolve(FilenameUtils.getBaseName(inputPath) + "-response.json");
Files.write(responsePath, parser.encodeResourceToString(response).getBytes(StandardCharsets.UTF_8));
}
return Pair.of(request, response);
}
use of org.hl7.fhir.utilities.graphql.Operation in project Gravity-SDOH-Exchange-RI by FHIR.
the class ProblemService method addGoalsToConditionBundle.
private Bundle addGoalsToConditionBundle(Bundle responseBundle) {
Bundle goals = new GoalQueryFactory().query(ehrClient, SmartOnFhirContext.get().getPatient()).where(Goal.LIFECYCLE_STATUS.exactly().codes(Goal.GoalLifecycleStatus.ACTIVE.toCode(), Goal.GoalLifecycleStatus.COMPLETED.toCode())).returnBundle(Bundle.class).execute();
if (goals.getLink(IBaseBundle.LINK_NEXT) != null) {
throw new RuntimeException("Multi-page Goal results returned for the List Problems operation. Pagination not supported yet. Make sure " + "there is a small amount of goals in your FHIR store.");
}
Bundle merged = FhirUtil.mergeBundles(ehrClient.getFhirContext(), responseBundle, goals);
return merged;
}
use of org.hl7.fhir.utilities.graphql.Operation in project Gravity-SDOH-Exchange-RI by FHIR.
the class GoalService method addTasksAndSRsToGoalBundle.
// TODO refactor. this fragmet ins used in a ProblemService as well.
private Bundle addTasksAndSRsToGoalBundle(Bundle responseBundle) {
Bundle tasksWithServiceRequests = new TaskQueryFactory().query(ehrClient, SmartOnFhirContext.get().getPatient()).include(Task.INCLUDE_FOCUS).returnBundle(Bundle.class).execute();
if (tasksWithServiceRequests.getLink(IBaseBundle.LINK_NEXT) != null) {
throw new RuntimeException("Multi-page Task results returned for the List Problems operation. Pagination not supported yet. Make sure " + "there is a small amount of tasks in your FHIR store.");
}
Bundle merged = FhirUtil.mergeBundles(ehrClient.getFhirContext(), responseBundle, tasksWithServiceRequests);
return merged;
}
use of org.hl7.fhir.utilities.graphql.Operation in project drug-formulary-ri by HL7-DaVinci.
the class JpaRestfulServer method initialize.
@SuppressWarnings("unchecked")
@Override
protected void initialize() throws ServletException {
super.initialize();
/*
* Create a FhirContext object that uses the version of FHIR
* specified in the properties file.
*/
ApplicationContext appCtx = (ApplicationContext) getServletContext().getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
// Customize supported resource types
Set<String> supportedResourceTypes = HapiProperties.getSupportedResourceTypes();
if (!supportedResourceTypes.isEmpty() && !supportedResourceTypes.contains("SearchParameter")) {
supportedResourceTypes.add("SearchParameter");
}
if (!supportedResourceTypes.isEmpty()) {
DaoRegistry daoRegistry = appCtx.getBean(DaoRegistry.class);
daoRegistry.setSupportedResourceTypes(supportedResourceTypes);
}
/*
* ResourceProviders are fetched from the Spring context
*/
FhirVersionEnum fhirVersion = HapiProperties.getFhirVersion();
ResourceProviderFactory resourceProviders;
Object systemProvider;
if (fhirVersion == FhirVersionEnum.DSTU2) {
resourceProviders = appCtx.getBean("myResourceProvidersDstu2", ResourceProviderFactory.class);
systemProvider = appCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);
} else if (fhirVersion == FhirVersionEnum.DSTU3) {
resourceProviders = appCtx.getBean("myResourceProvidersDstu3", ResourceProviderFactory.class);
systemProvider = appCtx.getBean("mySystemProviderDstu3", JpaSystemProviderDstu3.class);
} else if (fhirVersion == FhirVersionEnum.R4) {
resourceProviders = appCtx.getBean("myResourceProvidersR4", ResourceProviderFactory.class);
systemProvider = appCtx.getBean("mySystemProviderR4", JpaSystemProviderR4.class);
} else if (fhirVersion == FhirVersionEnum.R5) {
resourceProviders = appCtx.getBean("myResourceProvidersR5", ResourceProviderFactory.class);
systemProvider = appCtx.getBean("mySystemProviderR5", JpaSystemProviderR5.class);
} else {
throw new IllegalStateException();
}
setFhirContext(appCtx.getBean(FhirContext.class));
registerProviders(resourceProviders.createProviders());
registerProvider(systemProvider);
/*
* The conformance provider exports the supported resources, search parameters,
* etc for
* this server. The JPA version adds resourceProviders counts to the exported
* statement, so it
* is a nice addition.
*
* You can also create your own subclass of the conformance provider if you need
* to
* provide further customization of your server's CapabilityStatement
*/
IFhirSystemDao<org.hl7.fhir.r4.model.Bundle, org.hl7.fhir.r4.model.Meta> systemDao = appCtx.getBean("mySystemDaoR4", IFhirSystemDao.class);
MetadataProvider metadata = new MetadataProvider(this, systemDao, appCtx.getBean(DaoConfig.class));
// JpaConformanceProviderR4 confProvider = new JpaConformanceProviderR4(this,
// systemDao,
// appCtx.getBean(DaoConfig.class));
metadata.setImplementationDescription("Da Vinci Drug Formulary Reference Server");
setServerConformanceProvider(metadata);
/*
* ETag Support
*/
setETagSupport(HapiProperties.getEtagSupport());
/*
* This server tries to dynamically generate narratives
*/
FhirContext ctx = getFhirContext();
ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
/*
* Default to JSON and pretty printing
*/
setDefaultPrettyPrint(HapiProperties.getDefaultPrettyPrint());
/*
* Default encoding
*/
setDefaultResponseEncoding(HapiProperties.getDefaultEncoding());
/*
* This configures the server to page search results to and from
* the database, instead of only paging them to memory. This may mean
* a performance hit when performing searches that return lots of results,
* but makes the server much more scalable.
*/
setPagingProvider(appCtx.getBean(DatabaseBackedPagingProvider.class));
/*
* This interceptor formats the output using nice colourful
* HTML output when the request is detected to come from a
* browser.
*/
ResponseHighlighterInterceptor responseHighlighterInterceptor = new ResponseHighlighterInterceptor();
this.registerInterceptor(responseHighlighterInterceptor);
/*
* Add Read Only Interceptor
*/
ReadOnlyInterceptor readOnlyInterceptor = new ReadOnlyInterceptor();
this.registerInterceptor(readOnlyInterceptor);
/*
* This interceptor handles the $export operation
*/
ExportInterceptor exportInterceptor = new ExportInterceptor();
this.registerInterceptor(exportInterceptor);
/*
* Add some logging for each request
*/
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLoggerName(HapiProperties.getLoggerName());
loggingInterceptor.setMessageFormat(HapiProperties.getLoggerFormat());
loggingInterceptor.setErrorMessageFormat(HapiProperties.getLoggerErrorFormat());
loggingInterceptor.setLogExceptions(HapiProperties.getLoggerLogExceptions());
this.registerInterceptor(loggingInterceptor);
/*
* Add Authorization interceptor
*/
PatientAuthorizationInterceptor authorizationInterceptor = new PatientAuthorizationInterceptor();
this.registerInterceptor(authorizationInterceptor);
/*
* If you are hosting this server at a specific DNS name, the server will try to
* figure out the FHIR base URL based on what the web container tells it, but
* this doesn't always work. If you are setting links in your search bundles
* that
* just refer to "localhost", you might want to use a server address strategy:
*/
String serverAddress = HapiProperties.getServerAddress();
if (serverAddress != null && serverAddress.length() > 0) {
setServerAddressStrategy(new HardcodedServerAddressStrategy(serverAddress));
}
/*
* If you are using DSTU3+, you may want to add a terminology uploader, which
* allows
* uploading of external terminologies such as Snomed CT. Note that this
* uploader
* does not have any security attached (any anonymous user may use it by
* default)
* so it is a potential security vulnerability. Consider using an
* AuthorizationInterceptor
* with this feature.
*/
if (false) {
// <-- DISABLED RIGHT NOW
registerProvider(appCtx.getBean(TerminologyUploaderProvider.class));
}
// manual triggering of a subscription delivery, enable this provider
if (false) {
// <-- DISABLED RIGHT NOW
SubscriptionTriggeringProvider retriggeringProvider = appCtx.getBean(SubscriptionTriggeringProvider.class);
registerProvider(retriggeringProvider);
}
// to your specific needs
if (HapiProperties.getCorsEnabled()) {
CorsConfiguration config = new CorsConfiguration();
config.addAllowedHeader(HttpHeaders.ORIGIN);
config.addAllowedHeader(HttpHeaders.ACCEPT);
config.addAllowedHeader(HttpHeaders.CONTENT_TYPE);
config.addAllowedHeader(HttpHeaders.AUTHORIZATION);
config.addAllowedHeader(HttpHeaders.CACHE_CONTROL);
config.addAllowedHeader("x-fhir-starter");
config.addAllowedHeader("X-Requested-With");
config.addAllowedHeader("Prefer");
String allAllowedCORSOrigins = HapiProperties.getCorsAllowedOrigin();
Arrays.stream(allAllowedCORSOrigins.split(",")).forEach(o -> {
config.addAllowedOrigin(o);
});
config.addAllowedOrigin(HapiProperties.getCorsAllowedOrigin());
config.addExposedHeader("Location");
config.addExposedHeader("Content-Location");
config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "HEAD"));
config.setAllowCredentials(HapiProperties.getCorsAllowedCredentials());
// Create the interceptor and register it
CorsInterceptor interceptor = new CorsInterceptor(config);
registerInterceptor(interceptor);
}
// will activate them and match results against them
if (HapiProperties.getSubscriptionWebsocketEnabled() || HapiProperties.getSubscriptionEmailEnabled() || HapiProperties.getSubscriptionRestHookEnabled()) {
// Loads subscription interceptors (SubscriptionActivatingInterceptor,
// SubscriptionMatcherInterceptor)
// with activation of scheduled subscription
SubscriptionInterceptorLoader subscriptionInterceptorLoader = appCtx.getBean(SubscriptionInterceptorLoader.class);
subscriptionInterceptorLoader.registerInterceptors();
// Subscription debug logging
IInterceptorService interceptorService = appCtx.getBean(IInterceptorService.class);
interceptorService.registerInterceptor(new SubscriptionDebugLogInterceptor());
}
// Cascading deletes
DaoRegistry daoRegistry = appCtx.getBean(DaoRegistry.class);
IInterceptorBroadcaster interceptorBroadcaster = appCtx.getBean(IInterceptorBroadcaster.class);
if (HapiProperties.getAllowCascadingDeletes()) {
CascadingDeleteInterceptor cascadingDeleteInterceptor = new CascadingDeleteInterceptor(daoRegistry, interceptorBroadcaster);
getInterceptorService().registerInterceptor(cascadingDeleteInterceptor);
}
// Binary Storage
if (HapiProperties.isBinaryStorageEnabled()) {
BinaryStorageInterceptor binaryStorageInterceptor = appCtx.getBean(BinaryStorageInterceptor.class);
getInterceptorService().registerInterceptor(binaryStorageInterceptor);
}
// Validation
IValidatorModule validatorModule;
switch(fhirVersion) {
case DSTU2:
validatorModule = appCtx.getBean("myInstanceValidatorDstu2", IValidatorModule.class);
break;
case DSTU3:
validatorModule = appCtx.getBean("myInstanceValidatorDstu3", IValidatorModule.class);
break;
case R4:
validatorModule = appCtx.getBean("myInstanceValidatorR4", IValidatorModule.class);
break;
case R5:
validatorModule = appCtx.getBean("myInstanceValidatorR5", IValidatorModule.class);
break;
// These versions are not supported by HAPI FHIR JPA
case DSTU2_HL7ORG:
case DSTU2_1:
default:
validatorModule = null;
break;
}
if (validatorModule != null) {
if (HapiProperties.getValidateRequestsEnabled()) {
RequestValidatingInterceptor interceptor = new RequestValidatingInterceptor();
interceptor.setFailOnSeverity(ResultSeverityEnum.ERROR);
interceptor.setValidatorModules(Collections.singletonList(validatorModule));
registerInterceptor(interceptor);
}
if (HapiProperties.getValidateResponsesEnabled()) {
ResponseValidatingInterceptor interceptor = new ResponseValidatingInterceptor();
interceptor.setFailOnSeverity(ResultSeverityEnum.ERROR);
interceptor.setValidatorModules(Collections.singletonList(validatorModule));
registerInterceptor(interceptor);
}
}
// GraphQL
if (HapiProperties.getGraphqlEnabled()) {
if (fhirVersion.isEqualOrNewerThan(FhirVersionEnum.DSTU3)) {
registerProvider(appCtx.getBean(GraphQLProvider.class));
}
}
if (!HapiProperties.getAllowedBundleTypes().isEmpty()) {
String allowedBundleTypesString = HapiProperties.getAllowedBundleTypes();
Set<String> allowedBundleTypes = new HashSet<>();
Arrays.stream(allowedBundleTypesString.split(",")).forEach(o -> {
BundleType type = BundleType.valueOf(o);
allowedBundleTypes.add(type.toCode());
});
DaoConfig config = appCtx.getBean(DaoConfig.class);
config.setBundleTypesAllowedForStorage(Collections.unmodifiableSet(new TreeSet<>(allowedBundleTypes)));
}
// Bulk Export
if (HapiProperties.getBulkExportEnabled()) {
registerProvider(appCtx.getBean(BulkDataExportProvider.class));
}
}
use of org.hl7.fhir.utilities.graphql.Operation in project ab2d by CMSgov.
the class CapabilityStatementSTU3 method createOperation.
private static CapabilityStatement.CapabilityStatementRestOperationComponent createOperation(String name, String path) {
CapabilityStatement.CapabilityStatementRestOperationComponent operation = new CapabilityStatement.CapabilityStatementRestOperationComponent();
operation.setName(name);
Reference ref = new Reference();
ref.setReference(path);
operation.setDefinition(ref);
return operation;
}
Aggregations