use of org.hl7.fhir.r4b.model.SearchParameter in project kindling by HL7.
the class ResourceParser method parseSearchParameter.
private void parseSearchParameter(ResourceDefn r, SearchParameter src) {
if (!src.hasName()) {
src.setName(src.getCode());
}
src.setVersion(version);
SearchParameterDefn sp = new SearchParameterDefn(src.getCode(), src.getDescription(), type(src.getType()), src.getXpathUsage(), StandardsStatus.fromCode(BuildExtensions.readStringExtension(src, "http://hl7.org/fhir/StructureDefinition/structuredefinition-standards-status")));
r.getSearchParams().put(sp.getCode(), sp);
sp.setExpression(src.getExpression());
sp.setXPath(src.getXpath());
sp.setResource(src);
String s = BuildExtensions.readStringExtension(src, BuildExtensions.EXT_PATH);
if (!Utilities.noString(s)) {
for (String p : s.split("\\,")) {
String v = p.trim();
if (!Utilities.noString(v)) {
sp.getPaths().add(v);
}
}
}
for (SearchParameterComponentComponent comp : src.getComponent()) {
sp.getComposites().add(new CompositeDefinition(comp.getDefinition(), comp.getExpression()));
}
}
use of org.hl7.fhir.r4b.model.SearchParameter in project kindling by HL7.
the class Regenerator method generateSearchParameter.
private CanonicalResource generateSearchParameter(String root, ResourceDefn r, Profile p, SearchParameter sp) throws IOException {
File fn = new File(Utilities.path(root, sp.fhirType().toLowerCase() + "-profile-" + sp.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sp);
fn.setLastModified(r.getTimestamp());
return sp;
}
use of org.hl7.fhir.r4b.model.SearchParameter in project kindling by HL7.
the class ProfileGenerator method makeSearchParam.
public SearchParameter makeSearchParam(StructureDefinition p, String id, String rn, SearchParameterDefn spd, ResourceDefn rd) throws Exception {
boolean shared;
boolean created = true;
SearchParameter sp;
if (definitions.getCommonSearchParameters().containsKey(rn + "::" + spd.getCode())) {
shared = true;
CommonSearchParameter csp = definitions.getCommonSearchParameters().get(rn + "::" + spd.getCode());
if (csp.getDefinition() == null) {
sp = new SearchParameter();
csp.setDefinition(sp);
sp.setId(csp.getId());
} else {
created = false;
sp = csp.getDefinition();
}
} else {
shared = false;
sp = new SearchParameter();
sp.setId(id.replace("[", "").replace("]", ""));
}
spd.setCommonId(sp.getId());
if (created) {
sp.setUrl("http://hl7.org/fhir/SearchParameter/" + sp.getId());
sp.setVersion(version.toCode());
if (context.getSearchParameter(sp.getUrl()) != null)
throw new Exception("Duplicated Search Parameter " + sp.getUrl());
context.cacheResource(sp);
spd.setResource(sp);
definitions.addNs(sp.getUrl(), "Search Parameter: " + sp.getName(), rn.toLowerCase() + ".html#search");
sp.setStatus(spd.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
StandardsStatus sst = ToolingExtensions.getStandardsStatus(sp);
if (sst == null || (spd.getStandardsStatus() == null && spd.getStandardsStatus().isLowerThan(sst)))
ToolingExtensions.setStandardsStatus(sp, spd.getStandardsStatus(), spd.getNormativeVersion());
sp.setExperimental(p.getExperimental());
sp.setName(spd.getCode());
sp.setCode(spd.getCode());
sp.setDate(genDate.getTime());
sp.setPublisher(p.getPublisher());
for (ContactDetail tc : p.getContact()) {
ContactDetail t = sp.addContact();
if (tc.hasNameElement())
t.setNameElement(tc.getNameElement().copy());
for (ContactPoint ts : tc.getTelecom()) t.getTelecom().add(ts.copy());
}
if (!definitions.hasResource(p.getType()) && !p.getType().equals("Resource") && !p.getType().equals("DomainResource"))
throw new Exception("unknown resource type " + p.getType());
sp.setType(getSearchParamType(spd.getType()));
if (sp.getType() == SearchParamType.REFERENCE && spd.isHierarchy()) {
sp.addModifier(SearchParameter.SearchModifierCode.BELOW);
sp.addModifier(SearchParameter.SearchModifierCode.ABOVE);
}
if (shared) {
sp.setDescription("Multiple Resources: \r\n\r\n* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
} else
sp.setDescription(preProcessMarkdown(spd.getDescription(), "Search Description"));
if (!Utilities.noString(spd.getExpression()))
sp.setExpression(spd.getExpression());
// addModifiers(sp);
addComparators(sp);
String xpath = Utilities.noString(spd.getXPath()) ? new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn) : spd.getXPath();
if (xpath != null) {
if (xpath.contains("[x]"))
xpath = convertToXpath(xpath);
sp.setXpath(xpath);
sp.setXpathUsage(spd.getxPathUsage());
}
if (sp.getType() == SearchParamType.COMPOSITE) {
for (CompositeDefinition cs : spd.getComposites()) {
SearchParameterDefn cspd = findSearchParameter(rd, cs.getDefinition());
if (cspd != null)
sp.addComponent().setExpression(cs.getExpression()).setDefinition(cspd.getUrl());
else
sp.addComponent().setExpression(cs.getExpression()).setDefinition("http://hl7.org/fhir/SearchParameter/" + rn + "-" + cs.getDefinition());
}
sp.setMultipleOr(false);
}
sp.addBase(p.getType());
} else {
if (sp.getType() != getSearchParamType(spd.getType()))
throw new FHIRException("Type mismatch on common parameter: expected " + sp.getType().toCode() + " but found " + getSearchParamType(spd.getType()).toCode());
if (!sp.getDescription().contains("[" + rn + "](" + rn.toLowerCase() + ".html)"))
sp.setDescription(sp.getDescription() + "* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
// ext.addExtension("description", new MarkdownType(spd.getDescription()));
if (!Utilities.noString(spd.getExpression()) && !sp.getExpression().contains(spd.getExpression()))
sp.setExpression(sp.getExpression() + " | " + spd.getExpression());
String xpath = new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn);
if (xpath != null) {
if (xpath.contains("[x]"))
xpath = convertToXpath(xpath);
if (sp.getXpath() != null && !sp.getXpath().contains(xpath))
sp.setXpath(sp.getXpath() + " | " + xpath);
if (sp.getXpathUsage() != spd.getxPathUsage())
throw new FHIRException("Usage mismatch on common parameter: expected " + sp.getXpathUsage().toCode() + " but found " + spd.getxPathUsage().toCode());
}
boolean found = false;
for (CodeType ct : sp.getBase()) found = found || p.getType().equals(ct.asStringValue());
if (!found)
sp.addBase(p.getType());
}
spd.setUrl(sp.getUrl());
for (String target : spd.getWorkingTargets()) {
if ("Any".equals(target) == true) {
for (String resourceName : definitions.sortedResourceNames()) {
boolean found = false;
for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(resourceName);
if (!found)
sp.addTarget(resourceName);
}
} else {
boolean found = false;
for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(target);
if (!found)
sp.addTarget(target);
}
}
return sp;
}
use of org.hl7.fhir.r4b.model.SearchParameter 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.r4b.model.SearchParameter in project org.hl7.fhir.core by hapifhir.
the class PackageMaintainer method check.
private void check(String ver) throws IOException {
System.out.println("Check " + ver);
List<String> allIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".examples", "package"));
List<String> coreIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package"));
for (String s : coreIds) {
if (!allIds.contains(s)) {
System.out.println("Core contains " + s + " but allIds doesn't");
}
}
for (String s : allIds) {
if (!coreIds.contains(s)) {
String c = s.substring(0, s.indexOf("-"));
if (Utilities.existsInList(c, "CodeSystem", "ValueSet", "ConceptMap", "StructureDefinition", "StructureMap", "NamingSystem", "SearchParameter", "OperationDefinition", "CapabilityStatement", "Conformance"))
System.out.println("Examples contains " + s + " but core doesn't");
}
}
strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package")));
strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".expansions", "package")));
if (!ver.equals("r2b"))
strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".elements", "package")));
}
Aggregations