use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project kindling by HL7.
the class SpecNPMPackageGenerator method determineVersion.
private FHIRVersion determineVersion(Map<String, byte[]> files) throws FHIRException {
byte[] b = files.get("version.info");
if (b == null)
return FHIRVersion.NULL;
String s = new String(b);
s = Utilities.stripBOM(s).trim();
while (s.charAt(0) != '[') s = s.substring(1);
byte[] bytes = {};
try {
bytes = s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
}
ByteArrayInputStream bs = new ByteArrayInputStream(bytes);
IniFile ini = new IniFile(bs);
String v = ini.getStringProperty("FHIR", "version");
if (v == null)
throw new Error("unable to determine version from " + new String(bytes));
if ("3.0.0".equals(v))
v = "3.0.1";
return FHIRVersion.fromCode(v);
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project kindling by HL7.
the class JsonLDDefinitionsGenerator method generate.
// private String genDate;
// private String version;
// private BuildWorkerContext workerContext;
public void generate(Definitions definitions, IniFile ini, String tmpResDir, String dstDir, String srcDir, FHIRVersion version, String genDate, BuildWorkerContext workerContext) throws Exception {
// this.genDate = genDate;
// this.version = version;
// this.workerContext = workerContext;
JsonObject defn = new JsonObject();
JsonObject context = new JsonObject();
defn.add("@context", context);
defn.addProperty("@id", "http://hl7.org/fhir/");
context.addProperty("fhir", "http://hl7.org/fhir/");
context.addProperty("xsd", "http://www.w3.org/2001/XMLSchema#");
// properties for primitives, helpers, format features
addProperty(context, "value", "fhir:value", "xsd:string");
addProperty(context, "decimal", "fhir:value", "xsd:decimal");
addProperty(context, "integer", "fhir:value", "xsd:integer");
if (!version.isR4B()) {
addProperty(context, "integer64", "fhir:value", "xsd:string");
}
addProperty(context, "boolean", "fhir:value", "xsd:boolean");
addProperty(context, "binary", "fhir:value", "xsd:base64Binary");
addProperty(context, "date", "fhir:value", "xsd:date");
addProperty(context, "dateTime", "fhir:value", "xsd:dateTime");
addProperty(context, "gYearMonth", "fhir:value", "xsd:gYearMonth");
addProperty(context, "gYear", "fhir:value", "xsd:gYear");
addProperty(context, "link", "fhir:link", "@id");
addProperty(context, "concept", "fhir:concept", "@id");
addProperty(context, "index", "fhir:index", "xsd:integer");
addProperty(context, "role", "fhir:nodeRole", "@id");
// elements defined in FHIR:
for (TypeRef tr : definitions.getKnownTypes()) {
if (!definitions.hasPrimitiveType(tr.getName()) && !tr.getName().equals("SimpleQuantity") && !tr.getName().equals("MoneyQuantity")) {
TypeDefn root = definitions.getElementDefn(tr.getName());
new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root, version, genDate);
}
}
List<String> names = new ArrayList<String>();
names.addAll(definitions.getResources().keySet());
names.addAll(definitions.getBaseResources().keySet());
names.add("Parameters");
Collections.sort(names);
for (String name : names) {
ResourceDefn root = definitions.getResourceByName(name);
new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root.getRoot(), version, genDate);
}
save(defn, dstDir + "fhir.jsonld");
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project cqf-ruler by DBCG.
the class ExpressionEvaluation method setupContext.
private Context setupContext(DomainResource instance, String cql, String patientId, Boolean aliasedExpression, RequestDetails theRequest) {
JpaFhirDal jpaFhirDal = jpaFhirDalFactory.create(theRequest);
List<CanonicalType> libraries = getLibraryReferences(instance, theRequest);
String fhirVersion = this.fhirContext.getVersion().getVersion().getFhirVersionString();
// Remove LocalLibrary from cache first...
VersionedIdentifier localLibraryIdentifier = new VersionedIdentifier().withId("LocalLibrary");
globalLibraryCache.remove(localLibraryIdentifier);
// temporary LibraryLoader to resolve library dependencies when building
// includes
LibraryLoader tempLibraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest))));
String source = "";
if (aliasedExpression) {
if (libraries.size() != 1) {
throw new RuntimeException("If an aliased expression is provided, there must be exactly one primary Library");
}
VersionedIdentifier vi = getVersionedIdentifierFromCanonical(libraries.get(0));
// Still not the best way to build include, but at least checks dal for an
// existing library
// Check if id works for LibraryRetrieval
org.cqframework.cql.elm.execution.Library executionLibrary = null;
try {
executionLibrary = tempLibraryLoader.load(vi);
} catch (Exception e) {
// log error
}
if (executionLibrary == null) {
Library library = (Library) jpaFhirDal.read(new IdType("Library", Canonicals.getIdPart(libraries.get(0))));
vi.setId(library.getName());
if (library.getVersion() != null) {
vi.setVersion(library.getVersion());
}
}
source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), vi.getId() + ".\"" + cql + "\"");
} else {
source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), cql);
}
LibraryLoader libraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest), new InMemoryLibraryContentProvider(Arrays.asList(source)))));
// resolve execution context
return setupContext(instance, patientId, libraryLoader, theRequest);
}
use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion 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.r5.model.Enumerations.FHIRVersion in project ab2d by CMSgov.
the class ErrorHandler method generateFHIRError.
private ResponseEntity<JsonNode> generateFHIRError(Exception e, HttpHeaders httpHeaders, HttpServletRequest request) throws IOException {
String msg = getRootCause(e);
HttpStatus httpStatus = getErrorResponse(e.getClass());
FhirVersion version = FhirVersion.fromAB2DUrl(request.getRequestURI());
IBaseResource operationOutcome = version.getErrorOutcome(msg);
String encoded = version.outcomePrettyToJSON(operationOutcome);
// Log so that Splunk can pick this up and alert
log.warn("{} {}", ExceptionUtils.getRootCause(e).getClass(), msg);
eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), null, ErrorHandler.getErrorResponse(e.getClass()), "FHIR Error", msg, (String) request.getAttribute(REQUEST_ID)));
return new ResponseEntity<>(new ObjectMapper().readTree(encoded), httpHeaders, httpStatus);
}
Aggregations