diff --git a/.github/stale.yml b/.github/stale.yml
new file mode 100644
index 00000000000..b21223c3726
--- /dev/null
+++ b/.github/stale.yml
@@ -0,0 +1,17 @@
+# Two years until issues go stale
+daysUntilStale: 730
+# Number of days of inactivity before a stale issue is closed
+daysUntilClose: 7
+# Issues with these labels will never be considered stale
+exemptLabels:
+ - pinned
+ - security
+# Label to use when marking an issue as stale
+staleLabel: wontfix
+# Comment to post when marking an issue as stale. Set to `false` to disable
+markComment: >
+ This issue has been automatically marked as stale because it has not had
+ recent activity. It will be closed if no further activity occurs. Thank you
+ for your contributions.
+# Comment to post when closing a stale issue. Set to `false` to disable
+closeComment: false
diff --git a/README.md b/README.md
index 9a7ce3ff074..bf7df70bf1c 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ HAPI FHIR - Java API for HL7 FHIR Clients and Servers
[![Build Status](https://dev.azure.com/jamesagnew214/jamesagnew214/_apis/build/status/jamesagnew.hapi-fhir?branchName=master)](https://dev.azure.com/jamesagnew214/jamesagnew214/_build/latest?definitionId=1&branchName=master)
[![codecov](https://codecov.io/gh/jamesagnew/hapi-fhir/branch/master/graph/badge.svg)](https://codecov.io/gh/jamesagnew/hapi-fhir)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/ca.uhn.hapi.fhir/hapi-fhir-base/badge.svg)](http://search.maven.org/#search|ga|1|ca.uhn.hapi.fhir)
-[![License](https://img.shields.io/badge/license-apache%202.0-60C060.svg)](http://jamesagnew.github.io/hapi-fhir/license.html)
+[![License](https://img.shields.io/badge/license-apache%202.0-60C060.svg)](https://hapifhir.io/hapi-fhir/license.html)
Complete project documentation is available here:
http://hapifhir.io
diff --git a/example-projects/hapi-fhir-jpaserver-cds-example/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html b/example-projects/hapi-fhir-jpaserver-cds-example/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
index dfc4769d6e4..fa0fa5666f6 100644
--- a/example-projects/hapi-fhir-jpaserver-cds-example/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
+++ b/example-projects/hapi-fhir-jpaserver-cds-example/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
@@ -40,10 +40,8 @@
-
-
- This is not a production server!
-
+
+ This is not a production server!
Do not store any information here that contains personal health information
or any other confidential information. This server will be regularly purged
and reloaded with fixed test data.
diff --git a/example-projects/hapi-fhir-jpaserver-dynamic/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html b/example-projects/hapi-fhir-jpaserver-dynamic/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
index dfc4769d6e4..fa0fa5666f6 100644
--- a/example-projects/hapi-fhir-jpaserver-dynamic/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
+++ b/example-projects/hapi-fhir-jpaserver-dynamic/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
@@ -40,10 +40,8 @@
-
-
- This is not a production server!
-
+
+ This is not a production server!
Do not store any information here that contains personal health information
or any other confidential information. This server will be regularly purged
and reloaded with fixed test data.
diff --git a/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html b/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
index dfc4769d6e4..fa0fa5666f6 100644
--- a/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
+++ b/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/webapp/WEB-INF/templates/tmpl-home-welcome.html
@@ -40,10 +40,8 @@
-
-
- This is not a production server!
-
+
+ This is not a production server!
Do not store any information here that contains personal health information
or any other confidential information. This server will be regularly purged
and reloaded with fixed test data.
diff --git a/examples/.gitignore b/examples/.gitignore
deleted file mode 100644
index 2fca895151a..00000000000
--- a/examples/.gitignore
+++ /dev/null
@@ -1,125 +0,0 @@
-/target/
-
-# Created by https://www.gitignore.io
-
-### Java ###
-*.class
-
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.ear
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
-
-
-### Maven ###
-target/
-pom.xml.tag
-pom.xml.releaseBackup
-pom.xml.versionsBackup
-pom.xml.next
-release.properties
-dependency-reduced-pom.xml
-buildNumber.properties
-
-
-### Vim ###
-[._]*.s[a-w][a-z]
-[._]s[a-w][a-z]
-*.un~
-Session.vim
-.netrwhist
-*~
-
-
-### Intellij ###
-# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
-
-*.iml
-
-## Directory-based project format:
-.idea/
-# if you remove the above rule, at least ignore the following:
-
-# User-specific stuff:
-# .idea/workspace.xml
-# .idea/tasks.xml
-# .idea/dictionaries
-
-# Sensitive or high-churn files:
-# .idea/dataSources.ids
-# .idea/dataSources.xml
-# .idea/sqlDataSources.xml
-# .idea/dynamic.xml
-# .idea/uiDesigner.xml
-
-# Gradle:
-# .idea/gradle.xml
-# .idea/libraries
-
-# Mongo Explorer plugin:
-# .idea/mongoSettings.xml
-
-## File-based project format:
-*.ipr
-*.iws
-
-## Plugin-specific files:
-
-# IntelliJ
-/out/
-
-# mpeltonen/sbt-idea plugin
-.idea_modules/
-
-# JIRA plugin
-atlassian-ide-plugin.xml
-
-# Crashlytics plugin (for Android Studio and IntelliJ)
-com_crashlytics_export_strings.xml
-crashlytics.properties
-crashlytics-build.properties
-
-
-
-### Eclipse ###
-*.pydevproject
-.metadata
-.gradle
-bin/
-tmp/
-*.tmp
-*.bak
-*.swp
-*~.nib
-local.properties
-.loadpath
-
-# Eclipse Core
-.project
-
-# External tool builders
-.externalToolBuilders/
-
-# Locally stored "Eclipse launch configurations"
-*.launch
-
-# CDT-specific
-.cproject
-
-# JDT-specific (Eclipse Java Development Tools)
-
-# PDT-specific
-.buildpath
-
-# sbteclipse plugin
-.target
-
-# TeXlipse plugin
-.texlipse
-
diff --git a/examples/pom.xml b/examples/pom.xml
deleted file mode 100644
index 9adf692ef09..00000000000
--- a/examples/pom.xml
+++ /dev/null
@@ -1,133 +0,0 @@
-
- 4.0.0
-
-
- ca.uhn.hapi.fhir
- hapi-fhir
- 4.3.0-SNAPSHOT
- ../pom.xml
-
-
- hapi-fhir-base-examples
- jar
-
- HAPI FHIR - Examples (for site)
-
-
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-bom
- ${project.version}
- import
- pom
-
-
-
-
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-base
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-structures-dstu2
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-structures-dstu2.1
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-structures-dstu3
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-structures-r4
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-structures-hl7org-dstu2
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-validation-resources-dstu2
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-validation
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-converter
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-client-okhttp
-
-
- javax.servlet
- javax.servlet-api
- provided
-
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-jaxrsserver-base
-
-
- javax.ws.rs
- javax.ws.rs-api
- 2.0
- provided
-
-
- javax.ejb
- ejb-api
- 3.0
- provided
-
-
- org.springframework
- spring-web
-
-
- ca.uhn.hapi.fhir
- hapi-fhir-jpaserver-base
-
-
-
- org.slf4j
- slf4j-simple
- ${slf4j_version}
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
-
- true
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-deploy-plugin
-
- true
-
-
-
-
-
-
diff --git a/examples/src/main/java/example/AuthorizationInterceptors.java b/examples/src/main/java/example/AuthorizationInterceptors.java
deleted file mode 100644
index 009b725a11d..00000000000
--- a/examples/src/main/java/example/AuthorizationInterceptors.java
+++ /dev/null
@@ -1,216 +0,0 @@
-package example;
-
-import ca.uhn.fhir.interceptor.api.HookParams;
-import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster;
-import ca.uhn.fhir.interceptor.api.Pointcut;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.ResourceParam;
-import ca.uhn.fhir.rest.annotation.Update;
-import ca.uhn.fhir.rest.api.MethodOutcome;
-import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
-import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
-import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.auth.*;
-import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
-import org.hl7.fhir.dstu3.model.IdType;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-
-import java.util.List;
-
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
-
-@SuppressWarnings("unused")
-public class AuthorizationInterceptors {
-
- public class PatientResourceProvider implements IResourceProvider
- {
-
- @Override
- public Class extends IBaseResource> getResourceType() {
- return Patient.class;
- }
-
- public MethodOutcome create(@ResourceParam Patient thePatient, RequestDetails theRequestDetails) {
-
- return new MethodOutcome(); // populate this
- }
-
- }
-
- //START SNIPPET: patientAndAdmin
- @SuppressWarnings("ConstantConditions")
- public class PatientAndAdminAuthorizationInterceptor extends AuthorizationInterceptor {
-
- @Override
- public List buildRuleList(RequestDetails theRequestDetails) {
-
- // Process authorization header - The following is a fake
- // implementation. Obviously we'd want something more real
- // for a production scenario.
- //
- // In this basic example we have two hardcoded bearer tokens,
- // one which is for a user that has access to one patient, and
- // another that has full access.
- IdDt userIdPatientId = null;
- boolean userIsAdmin = false;
- String authHeader = theRequestDetails.getHeader("Authorization");
- if ("Bearer dfw98h38r".equals(authHeader)) {
- // This user has access only to Patient/1 resources
- userIdPatientId = new IdDt("Patient", 1L);
- } else if ("Bearer 39ff939jgg".equals(authHeader)) {
- // This user has access to everything
- userIsAdmin = true;
- } else {
- // Throw an HTTP 401
- throw new AuthenticationException("Missing or invalid Authorization header value");
- }
-
- // If the user is a specific patient, we create the following rule chain:
- // Allow the user to read anything in their own patient compartment
- // Allow the user to write anything in their own patient compartment
- // If a client request doesn't pass either of the above, deny it
- if (userIdPatientId != null) {
- return new RuleBuilder()
- .allow().read().allResources().inCompartment("Patient", userIdPatientId).andThen()
- .allow().write().allResources().inCompartment("Patient", userIdPatientId).andThen()
- .denyAll()
- .build();
- }
-
- // If the user is an admin, allow everything
- if (userIsAdmin) {
- return new RuleBuilder()
- .allowAll()
- .build();
- }
-
- // By default, deny everything. This should never get hit, but it's
- // good to be defensive
- return new RuleBuilder()
- .denyAll()
- .build();
- }
- }
- //END SNIPPET: patientAndAdmin
-
-
- //START SNIPPET: conditionalUpdate
- @Update()
- public MethodOutcome update(
- @IdParam IdDt theId,
- @ResourceParam Patient theResource,
- @ConditionalUrlParam String theConditionalUrl,
- ServletRequestDetails theRequestDetails,
- IInterceptorBroadcaster theInterceptorBroadcaster) {
-
- // If we're processing a conditional URL...
- if (isNotBlank(theConditionalUrl)) {
-
- // Pretend we've done the conditional processing. Now let's
- // notify the interceptors that an update has been performed
- // and supply the actual ID that's being updated
- IdDt actual = new IdDt("Patient", "1123");
-
- }
-
- // In a real server, perhaps we would process the conditional
- // request differently and follow a separate path. Either way,
- // let's pretend there is some storage code here.
- theResource.setId(theId.withVersion("2"));
-
- // Notify the interceptor framework when we're about to perform an update. This is
- // useful as the authorization interceptor will pick this event up and use it
- // to factor into a decision about whether the operation should be allowed to proceed.
- IBaseResource previousContents = theResource;
- IBaseResource newContents = theResource;
- HookParams params = new HookParams()
- .add(IBaseResource.class, previousContents)
- .add(IBaseResource.class, newContents)
- .add(RequestDetails.class, theRequestDetails)
- .add(ServletRequestDetails.class, theRequestDetails);
- theInterceptorBroadcaster.callHooks(Pointcut.STORAGE_PRESTORAGE_RESOURCE_UPDATED, params);
-
- MethodOutcome retVal = new MethodOutcome();
- retVal.setCreated(true);
- retVal.setResource(theResource);
- return retVal;
- }
- //END SNIPPET: conditionalUpdate
-
- public void authorizeTenantAction() {
- //START SNIPPET: authorizeTenantAction
- new AuthorizationInterceptor(PolicyEnum.DENY) {
- @Override
- public List buildRuleList(RequestDetails theRequestDetails) {
- return new RuleBuilder()
- .allow().read().resourcesOfType(Patient.class).withAnyId().forTenantIds("TENANTA").andThen()
- .build();
- }
- };
- //END SNIPPET: authorizeTenantAction
-
-
- //START SNIPPET: patchAll
- new AuthorizationInterceptor(PolicyEnum.DENY) {
- @Override
- public List buildRuleList(RequestDetails theRequestDetails) {
- return new RuleBuilder()
- // Authorize patch requests
- .allow().patch().allRequests().andThen()
- // Authorize actual writes that patch may perform
- .allow().write().allResources().inCompartment("Patient", new IdType("Patient/123")).andThen()
- .build();
- }
- };
- //END SNIPPET: patchAll
-
- }
-
-
- //START SNIPPET: narrowing
- public class MyPatientSearchNarrowingInterceptor extends SearchNarrowingInterceptor {
-
- /**
- * This method must be overridden to provide the list of compartments
- * and/or resources that the current user should have access to
- */
- @Override
- protected AuthorizedList buildAuthorizedList(RequestDetails theRequestDetails) {
- // Process authorization header - The following is a fake
- // implementation. Obviously we'd want something more real
- // for a production scenario.
- //
- // In this basic example we have two hardcoded bearer tokens,
- // one which is for a user that has access to one patient, and
- // another that has full access.
- String authHeader = theRequestDetails.getHeader("Authorization");
- if ("Bearer dfw98h38r".equals(authHeader)) {
-
- // This user will have access to two compartments
- return new AuthorizedList()
- .addCompartment("Patient/123")
- .addCompartment("Patient/456");
-
- } else if ("Bearer 39ff939jgg".equals(authHeader)) {
-
- // This user has access to everything
- return new AuthorizedList();
-
- } else {
-
- throw new AuthenticationException("Unknown bearer token");
-
- }
-
- }
-
- }
- //END SNIPPET: narrowing
-
-
-}
diff --git a/examples/src/main/java/example/AuthorizingTesterUiClientFactory.java b/examples/src/main/java/example/AuthorizingTesterUiClientFactory.java
deleted file mode 100644
index 78c1d399ba0..00000000000
--- a/examples/src/main/java/example/AuthorizingTesterUiClientFactory.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package example;
-
-import javax.servlet.http.HttpServletRequest;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor;
-import ca.uhn.fhir.rest.server.util.ITestingUiClientFactory;
-
-public class AuthorizingTesterUiClientFactory implements ITestingUiClientFactory {
-
- @Override
- public IGenericClient newClient(FhirContext theFhirContext, HttpServletRequest theRequest, String theServerBaseUrl) {
- // Create a client
- IGenericClient client = theFhirContext.newRestfulGenericClient(theServerBaseUrl);
-
- // Register an interceptor which adds credentials
- client.registerInterceptor(new BasicAuthInterceptor("someusername", "somepassword"));
-
- return client;
- }
-
-}
diff --git a/examples/src/main/java/example/BundleFetcher.java b/examples/src/main/java/example/BundleFetcher.java
deleted file mode 100644
index 9da5300043d..00000000000
--- a/examples/src/main/java/example/BundleFetcher.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package example;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.hl7.fhir.instance.model.api.IBaseBundle;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.resource.Bundle;
-import ca.uhn.fhir.model.dstu2.resource.RelatedPerson;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-
-/**
- * @author Bill de Beaubien on 1/13/2016.
- */
-public class BundleFetcher {
- public static void fetchRestOfBundle(IGenericClient theClient, Bundle theBundle) {
- // we need to keep track of which resources are already in the bundle so that if other resources (e.g. Practitioner) are _included,
- // we don't end up with multiple copies
- Set resourcesAlreadyAdded = new HashSet();
- addInitialUrlsToSet(theBundle, resourcesAlreadyAdded);
- Bundle partialBundle = theBundle;
- for (;;) {
- if (partialBundle.getLink(IBaseBundle.LINK_NEXT) != null) {
- partialBundle = theClient.loadPage().next(partialBundle).execute();
- addAnyResourcesNotAlreadyPresentToBundle(theBundle, partialBundle, resourcesAlreadyAdded);
- } else {
- break;
- }
- }
- // the self and next links for the aggregated bundle aren't really valid anymore, so remove them
- theBundle.getLink().clear();
- }
-
- private static void addInitialUrlsToSet(Bundle theBundle, Set theResourcesAlreadyAdded) {
- for (Bundle.Entry entry : theBundle.getEntry()) {
- theResourcesAlreadyAdded.add(entry.getFullUrl());
- }
- }
-
- private static void addAnyResourcesNotAlreadyPresentToBundle(Bundle theAggregatedBundle, Bundle thePartialBundle, Set theResourcesAlreadyAdded) {
- for (Bundle.Entry entry : thePartialBundle.getEntry()) {
- if (!theResourcesAlreadyAdded.contains(entry.getFullUrl())) {
- theResourcesAlreadyAdded.add(entry.getFullUrl());
- theAggregatedBundle.getEntry().add(entry);
- }
- }
- }
-
- public static void main(String[] args) throws Exception {
- FhirContext ctx = FhirContext.forDstu2();
- String serverBase = "http://fhirtest.uhn.ca/baseDstu2";
- IGenericClient client = ctx.newRestfulGenericClient(serverBase);
- // use RelatedPerson because there aren't that many on the server
- Bundle bundle = client.search().forResource(RelatedPerson.class).returnBundle(Bundle.class).execute();
- BundleFetcher.fetchRestOfBundle(client, bundle);
- if (bundle.getTotal() != bundle.getEntry().size()) {
- System.out.println("Counts didn't match! Expected " + bundle.getTotal() + " but bundle only had " + bundle.getEntry().size() + " entries!");
- }
-
-// IParser parser = ctx.newXmlParser().setPrettyPrint(true);
-// System.out.println(parser.encodeResourceToString(bundle));
-
- }
-}
-
-
diff --git a/examples/src/main/java/example/ClientExamples.java b/examples/src/main/java/example/ClientExamples.java
deleted file mode 100644
index 25a805d8dd8..00000000000
--- a/examples/src/main/java/example/ClientExamples.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package example;
-
-import ca.uhn.fhir.rest.api.CacheControlDirective;
-import org.hl7.fhir.dstu3.model.Bundle;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory;
-import ca.uhn.fhir.rest.api.EncodingEnum;
-import ca.uhn.fhir.rest.client.apache.GZipContentInterceptor;
-import ca.uhn.fhir.rest.client.api.*;
-import ca.uhn.fhir.rest.client.interceptor.*;
-import org.hl7.fhir.r4.model.Patient;
-
-public class ClientExamples {
-
- public interface IPatientClient extends IBasicClient {
- // nothing yet
- }
-
- @SuppressWarnings("unused")
- public void createProxy() {
- // START SNIPPET: proxy
- FhirContext ctx = FhirContext.forDstu2();
-
- // Set connections to access the network via the HTTP proxy at
- // example.com : 8888
- ctx.getRestfulClientFactory().setProxy("example.com", 8888);
-
- // If the proxy requires authentication, use the following as well
- ctx.getRestfulClientFactory().setProxyCredentials("theUsername", "thePassword");
-
- // Create the client
- IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
- // END SNIPPET: proxy
- }
-
- @SuppressWarnings("unused")
- public void processMessage() {
- // START SNIPPET: processMessage
- FhirContext ctx = FhirContext.forDstu3();
-
- // Create the client
- IGenericClient client = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
-
- Bundle bundle = new Bundle();
- // ..populate the bundle..
-
- Bundle response = client
- .operation()
- .processMessage() // New operation for sending messages
- .setMessageBundle(bundle)
- .asynchronous(Bundle.class)
- .execute();
- // END SNIPPET: processMessage
- }
-
- @SuppressWarnings("unused")
- public void cacheControl() {
- FhirContext ctx = FhirContext.forDstu3();
-
- // Create the client
- IGenericClient client = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
-
- Bundle bundle = new Bundle();
- // ..populate the bundle..
-
- // START SNIPPET: cacheControl
- Bundle response = client
- .search()
- .forResource(Patient.class)
- .returnBundle(Bundle.class)
- .cacheControl(new CacheControlDirective().setNoCache(true)) // <-- add a directive
- .execute();
- // END SNIPPET: cacheControl
- }
-
- @SuppressWarnings("unused")
- public void createOkHttp() {
- // START SNIPPET: okhttp
- FhirContext ctx = FhirContext.forDstu3();
-
- // Use OkHttp
- ctx.setRestfulClientFactory(new OkHttpRestfulClientFactory(ctx));
-
- // Create the client
- IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
- // END SNIPPET: okhttp
- }
-
- @SuppressWarnings("unused")
- public void createTimeouts() {
- // START SNIPPET: timeouts
- FhirContext ctx = FhirContext.forDstu2();
-
- // Set how long to try and establish the initial TCP connection (in ms)
- ctx.getRestfulClientFactory().setConnectTimeout(20 * 1000);
-
- // Set how long to block for individual read/write operations (in ms)
- ctx.getRestfulClientFactory().setSocketTimeout(20 * 1000);
-
- // Create the client
- IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
- // END SNIPPET: timeouts
- }
-
- @SuppressWarnings("unused")
- public void createSecurity() {
- // START SNIPPET: security
- // Create a context and get the client factory so it can be configured
- FhirContext ctx = FhirContext.forDstu2();
- IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
-
- // Create an HTTP basic auth interceptor
- String username = "foobar";
- String password = "boobear";
- IClientInterceptor authInterceptor = new BasicAuthInterceptor(username, password);
-
- // If you're usinf an annotation client, use this style to
- // register it
- IPatientClient annotationClient = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/fhir");
- annotationClient.registerInterceptor(authInterceptor);
-
- // If you're using a generic client, use this instead
- IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
- genericClient.registerInterceptor(authInterceptor);
- // END SNIPPET: security
- }
-
- @SuppressWarnings("unused")
- public void createCookie() {
- // START SNIPPET: cookie
- // Create a context and get the client factory so it can be configured
- FhirContext ctx = FhirContext.forDstu2();
- IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
-
- // Create a cookie interceptor. This cookie will have the name "mycookie" and
- // the value "Chips Ahoy"
- CookieInterceptor interceptor = new CookieInterceptor("mycookie=Chips Ahoy");
-
- // Register the interceptor with your client (either style)
- IPatientClient annotationClient = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/fhir");
- annotationClient.registerInterceptor(interceptor);
-
- IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
- annotationClient.registerInterceptor(interceptor);
- // END SNIPPET: cookie
- }
-
- @SuppressWarnings("unused")
- public void gzip() {
- // START SNIPPET: gzip
- // Create a context and get the client factory so it can be configured
- FhirContext ctx = FhirContext.forDstu2();
- IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
-
- // Register the interceptor with your client (either style)
- IPatientClient annotationClient = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/fhir");
- annotationClient.registerInterceptor(new GZipContentInterceptor());
- // END SNIPPET: gzip
- }
-
- @SuppressWarnings("unused")
- public void createSecurityBearer() {
- // START SNIPPET: securityBearer
- // Create a context and get the client factory so it can be configured
- FhirContext ctx = FhirContext.forDstu2();
- IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
-
- // In reality the token would have come from an authorization server
- String token = "3w03fj.r3r3t";
-
- BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(token);
-
- // Register the interceptor with your client (either style)
- IPatientClient annotationClient = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/fhir");
- annotationClient.registerInterceptor(authInterceptor);
-
- IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
- annotationClient.registerInterceptor(authInterceptor);
- // END SNIPPET: securityBearer
- }
-
- @SuppressWarnings("unused")
- public void createLogging() {
- {
- // START SNIPPET: logging
- // Create a context and get the client factory so it can be configured
- FhirContext ctx = FhirContext.forDstu2();
- IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory();
-
- // Create a logging interceptor
- LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
-
- // Optionally you may configure the interceptor (by default only
- // summary info is logged)
- loggingInterceptor.setLogRequestSummary(true);
- loggingInterceptor.setLogRequestBody(true);
-
- // Register the interceptor with your client (either style)
- IPatientClient annotationClient = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/fhir");
- annotationClient.registerInterceptor(loggingInterceptor);
-
- IGenericClient genericClient = ctx.newRestfulGenericClient("http://localhost:9999/fhir");
- genericClient.registerInterceptor(loggingInterceptor);
- // END SNIPPET: logging
- }
-
- /******************************/
- {
- // START SNIPPET: clientConfig
- // Create a client
- FhirContext ctx = FhirContext.forDstu2();
- IPatientClient client = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/");
-
- // Request JSON encoding from the server (_format=json)
- client.setEncoding(EncodingEnum.JSON);
-
- // Request pretty printing from the server (_pretty=true)
- client.setPrettyPrint(true);
- // END SNIPPET: clientConfig
- }
- }
-
-}
diff --git a/examples/src/main/java/example/ClientTransactionExamples.java b/examples/src/main/java/example/ClientTransactionExamples.java
deleted file mode 100644
index 82ffe9f7639..00000000000
--- a/examples/src/main/java/example/ClientTransactionExamples.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
-import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
-import ca.uhn.fhir.model.dstu2.resource.*;
-import ca.uhn.fhir.model.dstu2.valueset.*;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-
-public class ClientTransactionExamples {
-
- public static void main(String[] args) {
- conditionalCreate();
- }
-
- private static void conditionalCreate() {
-
- //START SNIPPET: conditional
- // Create a patient object
- Patient patient = new Patient();
- patient.addIdentifier()
- .setSystem("http://acme.org/mrns")
- .setValue("12345");
- patient.addName()
- .addFamily("Jameson")
- .addGiven("J")
- .addGiven("Jonah");
- patient.setGender(AdministrativeGenderEnum.MALE);
-
- // Give the patient a temporary UUID so that other resources in
- // the transaction can refer to it
- patient.setId(IdDt.newRandomUuid());
-
- // Create an observation object
- Observation observation = new Observation();
- observation.setStatus(ObservationStatusEnum.FINAL);
- observation
- .getCode()
- .addCoding()
- .setSystem("http://loinc.org")
- .setCode("789-8")
- .setDisplay("Erythrocytes [#/volume] in Blood by Automated count");
- observation.setValue(
- new QuantityDt()
- .setValue(4.12)
- .setUnit("10 trillion/L")
- .setSystem("http://unitsofmeasure.org")
- .setCode("10*12/L"));
-
- // The observation refers to the patient using the ID, which is already
- // set to a temporary UUID
- observation.setSubject(new ResourceReferenceDt(patient.getId().getValue()));
-
- // Create a bundle that will be used as a transaction
- Bundle bundle = new Bundle();
- bundle.setType(BundleTypeEnum.TRANSACTION);
-
- // Add the patient as an entry. This entry is a POST with an
- // If-None-Exist header (conditional create) meaning that it
- // will only be created if there isn't already a Patient with
- // the identifier 12345
- bundle.addEntry()
- .setFullUrl(patient.getId().getValue())
- .setResource(patient)
- .getRequest()
- .setUrl("Patient")
- .setIfNoneExist("identifier=http://acme.org/mrns|12345")
- .setMethod(HTTPVerbEnum.POST);
-
- // Add the observation. This entry is a POST with no header
- // (normal create) meaning that it will be created even if
- // a similar resource already exists.
- bundle.addEntry()
- .setResource(observation)
- .getRequest()
- .setUrl("Observation")
- .setMethod(HTTPVerbEnum.POST);
-
- // Log the request
- FhirContext ctx = FhirContext.forDstu2();
- System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle));
-
- // Create a client and post the transaction to the server
- IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
- Bundle resp = client.transaction().withBundle(bundle).execute();
-
- // Log the response
- System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp));
- //END SNIPPET: conditional
-
- }
-
-}
diff --git a/examples/src/main/java/example/CompleteExampleClient.java b/examples/src/main/java/example/CompleteExampleClient.java
deleted file mode 100644
index b58a0b47351..00000000000
--- a/examples/src/main/java/example/CompleteExampleClient.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package example;
-
-//START SNIPPET: client
-import java.io.IOException;
-import java.util.List;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
-import ca.uhn.fhir.model.dstu2.resource.Organization;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.client.api.IRestfulClient;
-
-public class CompleteExampleClient {
-
- /**
- * This is a simple client interface. It can have many methods for various
- * searches but in this case it has only 1.
- */
- public static interface ClientInterface extends IRestfulClient {
-
- /**
- * This is translated into a URL similar to the following:
- * http://fhir.healthintersections.com.au/open/Patient?identifier=urn:oid:1.2.36.146.595.217.0.1%7C12345
- */
- @Search
- List findPatientsForMrn(@RequiredParam(name = Patient.SP_IDENTIFIER) IdentifierDt theIdentifier);
-
- }
-
- /**
- * The main method here will directly call an open FHIR server and retrieve a
- * list of resources matching a given criteria, then load a linked resource.
- */
- public static void main(String[] args) throws IOException {
-
- // Create a client factory
- FhirContext ctx = FhirContext.forDstu2();
-
- // Create the client
- String serverBase = "http://fhir.healthintersections.com.au/open";
- ClientInterface client = ctx.newRestfulClient(ClientInterface.class, serverBase);
-
- // Invoke the client to search for patient
- List patients = client.findPatientsForMrn(new IdentifierDt("urn:oid:1.2.36.146.595.217.0.1", "12345"));
-
- System.out.println("Found " + patients.size() + " patients");
-
- // Print a value from the loaded resource
- Patient patient = patients.get(0);
- System.out.println("Patient Last Name: " + patient.getName().get(0).getFamily().get(0).getValue());
-
- // Load a referenced resource
- ResourceReferenceDt managingRef = patient.getManagingOrganization();
- Organization org = (Organization) managingRef.loadResource(client);
-
- // Print organization name
- System.out.println(org.getName());
-
- }
-
-}
-// END SNIPPET: client
-
diff --git a/examples/src/main/java/example/ConsentInterceptors.java b/examples/src/main/java/example/ConsentInterceptors.java
deleted file mode 100644
index be9ba91ea03..00000000000
--- a/examples/src/main/java/example/ConsentInterceptors.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package example;
-
-import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
-import ca.uhn.fhir.rest.server.interceptor.consent.ConsentOutcome;
-import ca.uhn.fhir.rest.server.interceptor.consent.IConsentContextServices;
-import ca.uhn.fhir.rest.server.interceptor.consent.IConsentService;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-import org.hl7.fhir.r4.model.Observation;
-
-@SuppressWarnings("unused")
-public class ConsentInterceptors {
-
-
- //START SNIPPET: service
- public class MyConsentService implements IConsentService {
-
- /**
- * Invoked once at the start of every request
- */
- @Override
- public ConsentOutcome startOperation(RequestDetails theRequestDetails, IConsentContextServices theContextServices) {
- // This means that all requests should flow through the consent service
- // This has performance implications - If you know that some requests
- // don't need consent checking it is a good idea to return
- // ConsentOutcome.AUTHORIZED instead for those requests.
- return ConsentOutcome.PROCEED;
- }
-
- /**
- * Can a given resource be returned to the user?
- */
- @Override
- public ConsentOutcome canSeeResource(RequestDetails theRequestDetails, IBaseResource theResource, IConsentContextServices theContextServices) {
- // In this basic example, we will filter out lab results so that they
- // are never disclosed to the user. A real interceptor might do something
- // more nuanced.
- if (theResource instanceof Observation) {
- Observation obs = (Observation)theResource;
- if (obs.getCategoryFirstRep().hasCoding("http://hl7.org/fhir/codesystem-observation-category.html", "laboratory")) {
- return ConsentOutcome.REJECT;
- }
- }
-
- // Otherwise, allow the
- return ConsentOutcome.PROCEED;
- }
-
- /**
- * Modify resources that are being shown to the user
- */
- @Override
- public ConsentOutcome willSeeResource(RequestDetails theRequestDetails, IBaseResource theResource, IConsentContextServices theContextServices) {
- // Don't return the subject for Observation resources
- if (theResource instanceof Observation) {
- Observation obs = (Observation)theResource;
- obs.setSubject(null);
- }
- return ConsentOutcome.AUTHORIZED;
- }
-
- @Override
- public void completeOperationSuccess(RequestDetails theRequestDetails, IConsentContextServices theContextServices) {
- // We could write an audit trail entry in here
- }
-
- @Override
- public void completeOperationFailure(RequestDetails theRequestDetails, BaseServerResponseException theException, IConsentContextServices theContextServices) {
- // We could write an audit trail entry in here
- }
- }
- //END SNIPPET: service
-
-
-}
diff --git a/examples/src/main/java/example/ConverterExamples.java b/examples/src/main/java/example/ConverterExamples.java
deleted file mode 100644
index 710e8338485..00000000000
--- a/examples/src/main/java/example/ConverterExamples.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package example;
-
-import org.hl7.fhir.convertors.conv10_30.Observation10_30;
-import org.hl7.fhir.convertors.conv14_30.Questionnaire14_30;
-import org.hl7.fhir.exceptions.FHIRException;
-
-public class ConverterExamples {
-
- @SuppressWarnings("unused")
- public void c1020() throws FHIRException {
- //START SNIPPET: 1020
- // Create an input resource to convert
- org.hl7.fhir.dstu2.model.Observation input = new org.hl7.fhir.dstu2.model.Observation();
- input.setEncounter(new org.hl7.fhir.dstu2.model.Reference("Encounter/123"));
-
- // Convert the resource
- org.hl7.fhir.dstu3.model.Observation output = Observation10_30.convertObservation(input);
- String context = output.getContext().getReference();
- //END SNIPPET: 1020
- }
-
- @SuppressWarnings("unused")
- public void c1420() throws FHIRException {
- //START SNIPPET: 1420
- // Create a resource to convert
- org.hl7.fhir.dstu2016may.model.Questionnaire input = new org.hl7.fhir.dstu2016may.model.Questionnaire();
- input.setTitle("My title");
-
- // Convert the resource
- org.hl7.fhir.dstu3.model.Questionnaire output = Questionnaire14_30.convertQuestionnaire(input);
- String context = output.getTitle();
- //END SNIPPET: 1420
- }
-
-}
diff --git a/examples/src/main/java/example/Copier.java b/examples/src/main/java/example/Copier.java
deleted file mode 100644
index f73c23e1df3..00000000000
--- a/examples/src/main/java/example/Copier.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-import ca.uhn.fhir.util.ResourceReferenceInfo;
-import org.hl7.fhir.dstu3.model.Bundle;
-import org.hl7.fhir.dstu3.model.Resource;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-import org.hl7.fhir.instance.model.api.IIdType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.*;
-
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
-
-@SuppressWarnings("unused")
-public class Copier {
- private static final Logger ourLog = LoggerFactory.getLogger(Copier.class);
-
- public static void main(String[] args) {
- FhirContext ctx = FhirContext.forDstu3();
- IGenericClient source = ctx.newRestfulGenericClient("http://localhost:8080/baseDstu3");
- IGenericClient target = ctx.newRestfulGenericClient("https://try.smilecdr.com:8000");
-
- List resType = Arrays.asList(
- "Patient", "Organization", "Encounter", "Procedure",
- "Observation", "ResearchSubject", "Specimen",
- "ResearchStudy", "Location", "Practitioner"
- );
-
- List queued = new ArrayList<>();
- Set sent = new HashSet<>();
- for (String next : resType) {
- copy(ctx, source, target, next, queued, sent);
- }
-
- while (queued.size() > 0) {
- ourLog.info("Have {} queued resources to deliver", queued.size());
-
- for (IBaseResource nextQueued : new ArrayList<>(queued)) {
-
- String missingRef = null;
- for (ResourceReferenceInfo nextRefInfo : ctx.newTerser().getAllResourceReferences(nextQueued)) {
- String nextRef = nextRefInfo.getResourceReference().getReferenceElement().getValue();
- if (isNotBlank(nextRef) && !sent.contains(nextRef)) {
- missingRef = nextRef;
- }
- }
- if (missingRef != null) {
- ourLog.info("Can't send {} because of missing ref {}", nextQueued.getIdElement().getIdPart(), missingRef);
- continue;
- }
-
- IIdType newId = target
- .update()
- .resource(nextQueued)
- .execute()
- .getId();
-
- ourLog.info("Copied resource {} and got ID {}", nextQueued.getIdElement().getValue(), newId);
- sent.add(nextQueued.getIdElement().toUnqualifiedVersionless().getValue());
- queued.remove(nextQueued);
- }
- }
-
-
- }
-
- private static void copy(FhirContext theCtx, IGenericClient theSource, IGenericClient theTarget, String theResType, List theQueued, Set theSent) {
- Bundle received = theSource
- .search()
- .forResource(theResType)
- .returnBundle(Bundle.class)
- .execute();
- copy(theCtx, theTarget, theResType, theQueued, theSent, received);
-
- while (received.getLink("next") != null) {
- ourLog.info("Fetching next page...");
- received = theSource.loadPage().next(received).execute();
- copy(theCtx, theTarget, theResType, theQueued, theSent, received);
- }
-
- }
-
- private static void copy(FhirContext theCtx, IGenericClient theTarget, String theResType, List theQueued, Set theSent, Bundle theReceived) {
- for (Bundle.BundleEntryComponent nextEntry : theReceived.getEntry()) {
- Resource nextResource = nextEntry.getResource();
- nextResource.setId(theResType + "/" + "CR-" + nextResource.getIdElement().getIdPart());
-
- boolean haveUnsentReference = false;
- for (ResourceReferenceInfo nextRefInfo : theCtx.newTerser().getAllResourceReferences(nextResource)) {
- IIdType nextRef = nextRefInfo.getResourceReference().getReferenceElement();
- if (nextRef.hasIdPart()) {
- String newRef = nextRef.getResourceType() + "/" + "CR-" + nextRef.getIdPart();
- ourLog.info("Changing reference {} to {}", nextRef.getValue(), newRef);
- nextRefInfo.getResourceReference().setReference(newRef);
- if (!theSent.contains(newRef)) {
- haveUnsentReference = true;
- }
- }
- }
-
- if (haveUnsentReference) {
- ourLog.info("Queueing {} for delivery after", nextResource.getId());
- theQueued.add(nextResource);
- continue;
- }
-
- IIdType newId = theTarget
- .update()
- .resource(nextResource)
- .execute()
- .getId();
-
- ourLog.info("Copied resource {} and got ID {}", nextResource.getId(), newId);
- theSent.add(nextResource.getIdElement().toUnqualifiedVersionless().getValue());
- }
- }
-
-}
diff --git a/examples/src/main/java/example/CustomObservation.java b/examples/src/main/java/example/CustomObservation.java
deleted file mode 100644
index 54269735c0e..00000000000
--- a/examples/src/main/java/example/CustomObservation.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package example;
-
-import org.hl7.fhir.dstu3.model.Observation;
-
-public class CustomObservation extends Observation {
-
-}
diff --git a/examples/src/main/java/example/Dstu2Examples.java b/examples/src/main/java/example/Dstu2Examples.java
deleted file mode 100644
index 5456c55a522..00000000000
--- a/examples/src/main/java/example/Dstu2Examples.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package example;
-
-import java.util.Collection;
-
-import javax.servlet.ServletException;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.parser.IParser;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-import ca.uhn.fhir.rest.server.RestfulServer;
-
-@SuppressWarnings("serial")
-public class Dstu2Examples {
- private Collection resourceProviderList;
-
- public static void main(String[] args) {
- new Dstu2Examples().getResourceTags();
- }
-
- @SuppressWarnings("unused")
- public void getResourceTags() {
- // START SNIPPET: context
- // Create a DSTU2 context, which will use DSTU2 semantics
- FhirContext ctx = FhirContext.forDstu2();
-
- // This parser supports DSTU2
- IParser parser = ctx.newJsonParser();
-
- // This client supports DSTU2
- IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
- // END SNIPPET: context
- }
-
-
- // START SNIPPET: server
- public class MyServer extends RestfulServer
- {
-
- @Override
- protected void initialize() throws ServletException {
-
- // In your initialize method, assign a DSTU2 FhirContext. This
- // is all that is required in order to put the server
- // into DSTU2 mode
- setFhirContext(FhirContext.forDstu2());
-
- // Then set resource providers as normal, and do any other
- // configuration you need to do.
- setResourceProviders(resourceProviderList);
-
- }
-
- }
- // END SNIPPET: server
-
-
- public void upgrade() {
- // START SNIPPET: client
- FhirContext ctxDstu2 = FhirContext.forDstu2();
- IGenericClient clientDstu2 = ctxDstu2.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
-
- // END SNIPPET: client
-
- }
-
-}
diff --git a/examples/src/main/java/example/ExampleProviders.java b/examples/src/main/java/example/ExampleProviders.java
deleted file mode 100644
index 8a41d40a469..00000000000
--- a/examples/src/main/java/example/ExampleProviders.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package example;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hl7.fhir.dstu3.model.Bundle;
-
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-
-@SuppressWarnings(value= {"serial"})
-public class ExampleProviders {
-
-
-//START SNIPPET: plainProvider
-public class PlainProvider {
-
- /**
- * This method is a Patient search, but HAPI can not automatically
- * determine the resource type so it must be explicitly stated.
- */
- @Search(type=Patient.class)
- public Bundle searchForPatients(@RequiredParam(name=Patient.SP_NAME) StringDt theName) {
- Bundle retVal = new Bundle();
- // perform search
- return retVal;
- }
-
-}
-//END SNIPPET: plainProvider
-
-
-//START SNIPPET: plainProviderServer
-public class ExampleServlet extends ca.uhn.fhir.rest.server.RestfulServer {
-
- /**
- * Constructor
- */
- public ExampleServlet() {
- /*
- * Plain providers are passed to the server in the same way
- * as resource providers. You may pass both resource providers
- * and and plain providers to the same server if you like.
- */
- List plainProviders=new ArrayList();
- plainProviders.add(new PlainProvider());
- registerProviders(plainProviders);
-
- List resourceProviders = new ArrayList();
- // ...add some resource providers...
- registerProviders(resourceProviders);
- }
-
-}
-//END SNIPPET: plainProviderServer
-
- //START SNIPPET: addressStrategy
- public class MyServlet extends ca.uhn.fhir.rest.server.RestfulServer {
-
- /**
- * Constructor
- */
- public MyServlet() {
-
- String serverBaseUrl = "http://foo.com/fhir";
- setServerAddressStrategy(new HardcodedServerAddressStrategy(serverBaseUrl));
-
- // ...add some resource providers, etc...
- List resourceProviders = new ArrayList();
- setResourceProviders(resourceProviders);
- }
-
- }
-//END SNIPPET: addressStrategy
-
-
-
-}
diff --git a/examples/src/main/java/example/ExampleRestfulClient.java b/examples/src/main/java/example/ExampleRestfulClient.java
deleted file mode 100644
index 16e05c2304e..00000000000
--- a/examples/src/main/java/example/ExampleRestfulClient.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package example;
-
-import java.util.List;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.StringDt;
-
-@SuppressWarnings("unused")
-public class ExampleRestfulClient {
-
-//START SNIPPET: client
-public static void main(String[] args) {
- FhirContext ctx = FhirContext.forDstu2();
- String serverBase = "http://foo.com/fhirServerBase";
-
- // Create the client
- IRestfulClient client = ctx.newRestfulClient(IRestfulClient.class, serverBase);
-
- // Try the client out! This method will invoke the server
- List patients = client.getPatient(new StringDt("SMITH"));
-
-}
-//END SNIPPET: client
-
-}
diff --git a/examples/src/main/java/example/ExampleRestfulServlet.java b/examples/src/main/java/example/ExampleRestfulServlet.java
deleted file mode 100644
index 34bd915a86d..00000000000
--- a/examples/src/main/java/example/ExampleRestfulServlet.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package example;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-
-import ca.uhn.fhir.rest.server.IResourceProvider;
-import ca.uhn.fhir.rest.server.RestfulServer;
-
-//START SNIPPET: servlet
-/**
- * In this example, we are using Servlet 3.0 annotations to define
- * the URL pattern for this servlet, but we could also
- * define this in a web.xml file.
- */
-@WebServlet(urlPatterns= {"/fhir/*"}, displayName="FHIR Server")
-public class ExampleRestfulServlet extends RestfulServer {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * The initialize method is automatically called when the servlet is starting up, so it can
- * be used to configure the servlet to define resource providers, or set up
- * configuration, interceptors, etc.
- */
- @Override
- protected void initialize() throws ServletException {
- /*
- * The servlet defines any number of resource providers, and
- * configures itself to use them by calling
- * setResourceProviders()
- */
- List resourceProviders = new ArrayList();
- resourceProviders.add(new RestfulPatientResourceProvider());
- resourceProviders.add(new RestfulObservationResourceProvider());
- setResourceProviders(resourceProviders);
- }
-
-}
-//END SNIPPET: servlet
-
-
-
diff --git a/examples/src/main/java/example/ExtensionsDstu2.java b/examples/src/main/java/example/ExtensionsDstu2.java
deleted file mode 100644
index fe0a272ce5f..00000000000
--- a/examples/src/main/java/example/ExtensionsDstu2.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package example;
-
-import java.io.IOException;
-import java.util.List;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.api.ExtensionDt;
-import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.resource.Questionnaire;
-import ca.uhn.fhir.model.dstu2.resource.Questionnaire.GroupQuestion;
-import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
-import ca.uhn.fhir.model.primitive.CodeDt;
-import ca.uhn.fhir.model.primitive.DateTimeDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.parser.DataFormatException;
-
-public class ExtensionsDstu2 {
-
-@SuppressWarnings("unused")
-public static void main(String[] args) throws DataFormatException, IOException {
-
- {
- Questionnaire q= new Questionnaire();
- GroupQuestion item = q.getGroup().addQuestion();
- item.setText("Hello");
-
- ExtensionDt extension = new ExtensionDt(false, "http://hl7.org/fhir/StructureDefinition/translation");
- item.getTextElement().addUndeclaredExtension(extension);
-
- extension.addUndeclaredExtension(new ExtensionDt(false, "lang", new CodeDt("es")));
- extension.addUndeclaredExtension(new ExtensionDt(false, "cont", new StringDt("hola")));
-
- System.out.println(FhirContext.forDstu2().newJsonParser().setPrettyPrint(true).encodeResourceToString(q));
- }
-
-
-// START SNIPPET: resourceExtension
-// Create an example patient
-Patient patient = new Patient();
-patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:example").setValue("7000135");
-
-// Create an extension
-ExtensionDt ext = new ExtensionDt();
-ext.setModifier(false);
-ext.setUrl("http://example.com/extensions#someext");
-ext.setValue(new DateTimeDt("2011-01-02T11:13:15"));
-
-// Add the extension to the resource
-patient.addUndeclaredExtension(ext);
-//END SNIPPET: resourceExtension
-
-
-//START SNIPPET: resourceStringExtension
-// Continuing the example from above, we will add a name to the patient, and then
-// add an extension to part of that name
-HumanNameDt name = patient.addName();
-name.addFamily().setValue("Shmoe");
-
-// Add a new "given name", which is of type StringDt
-StringDt given = name.addGiven();
-given.setValue("Joe");
-
-// Create an extension and add it to the StringDt
-ExtensionDt givenExt = new ExtensionDt(false, "http://examples.com#moreext", new StringDt("Hello"));
-given.addUndeclaredExtension(givenExt);
-//END SNIPPET: resourceStringExtension
-
-FhirContext ctx = FhirContext.forDstu2();
-String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
-System.out.println(output);
-
-
-//START SNIPPET: parseExtension
-// Get all extensions (modifier or not) for a given URL
-List resourceExts = patient.getUndeclaredExtensionsByUrl("http://fooextensions.com#exts");
-
-// Get all non-modifier extensions regardless of URL
-List nonModExts = patient.getUndeclaredExtensions();
-
-//Get all non-modifier extensions regardless of URL
-List modExts = patient.getUndeclaredModifierExtensions();
-//END SNIPPET: parseExtension
-
-}
-
-
-public void foo() {
-//START SNIPPET: subExtension
-Patient patient = new Patient();
-
-// Add an extension (initially with no contents) to the resource
-ExtensionDt parent = new ExtensionDt(false, "http://example.com#parent");
-patient.addUndeclaredExtension(parent);
-
-// Add two extensions as children to the parent extension
-ExtensionDt child1 = new ExtensionDt(false, "http://example.com#childOne", new StringDt("value1"));
-parent.addUndeclaredExtension(child1);
-
-ExtensionDt child2 = new ExtensionDt(false, "http://example.com#childTwo", new StringDt("value1"));
-parent.addUndeclaredExtension(child2);
-//END SNIPPET: subExtension
-
-}
-
-}
diff --git a/examples/src/main/java/example/ExtensionsDstu3.java b/examples/src/main/java/example/ExtensionsDstu3.java
deleted file mode 100644
index 0593761c662..00000000000
--- a/examples/src/main/java/example/ExtensionsDstu3.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package example;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.hl7.fhir.dstu3.model.*;
-import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-
-public class ExtensionsDstu3 {
-
- public void customType() {
-
-IGenericClient client = FhirContext.forDstu3().newRestfulGenericClient("http://foo");
-
-//START SNIPPET: customTypeClientSimple
-// Create an example patient
-MyPatient custPatient = new MyPatient();
-custPatient.addName().setFamily("Smith").addGiven("John");
-custPatient.setPetName(new StringType("Rover")); // populate the extension
-
-// Create the resource like normal
-client.create().resource(custPatient).execute();
-
-// You can also read the resource back like normal
-custPatient = client.read().resource(MyPatient.class).withId("123").execute();
-//END SNIPPET: customTypeClientSimple
-
-//START SNIPPET: customTypeClientSearch
-// Perform the search using the custom type
-Bundle bundle = client
- .search()
- .forResource(MyPatient.class)
- .returnBundle(Bundle.class)
- .execute();
-
-// Entries in the return bundle will use the given type
-MyPatient pat0 = (MyPatient) bundle.getEntry().get(0).getResource();
-//END SNIPPET: customTypeClientSearch
-
-//START SNIPPET: customTypeClientSearch2
-//Perform the search using the custom type
-bundle = client
- .history()
- .onInstance(new IdType("Patient/123"))
- .andReturnBundle(Bundle.class)
- .preferResponseType(MyPatient.class)
- .execute();
-
-//Entries in the return bundle will use the given type
-MyPatient historyPatient0 = (MyPatient) bundle.getEntry().get(0).getResource();
-//END SNIPPET: customTypeClientSearch2
-
- }
-
- public void customTypeDeclared() {
-
-
-//START SNIPPET: customTypeClientDeclared
-FhirContext ctx = FhirContext.forDstu3();
-
-// Instruct the context that if it receives a resource which
-// claims to conform to the given profile (by URL), it should
-// use the MyPatient type to parse this resource
-ctx.setDefaultTypeForProfile("http://example.com/StructureDefinition/mypatient", MyPatient.class);
-
-// You can declare as many default types as you like
-ctx.setDefaultTypeForProfile("http://foo.com/anotherProfile", CustomObservation.class);
-
-// Create a client
-IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");
-
-// You can also read the resource back like normal
-Patient patient = client.read().resource(Patient.class).withId("123").execute();
-if (patient instanceof MyPatient) {
- // If the server supplied a resource which declared to conform
- // to the given profile, MyPatient will have been returned so
- // process it differently..
-}
-
-//END SNIPPET: customTypeClientDeclared
-
-
- }
-
-@SuppressWarnings("unused")
-public static void main(String[] args) throws DataFormatException, IOException {
-
-
-// START SNIPPET: resourceExtension
-// Create an example patient
-Patient patient = new Patient();
-patient.addIdentifier().setUse(IdentifierUse.OFFICIAL).setSystem("urn:example").setValue("7000135");
-
-// Create an extension
-Extension ext = new Extension();
-ext.setUrl("http://example.com/extensions#someext");
-ext.setValue(new DateTimeType("2011-01-02T11:13:15"));
-
-// Add the extension to the resource
-patient.addExtension(ext);
-//END SNIPPET: resourceExtension
-
-
-//START SNIPPET: resourceStringExtension
-// Continuing the example from above, we will add a name to the patient, and then
-// add an extension to part of that name
-HumanName name = patient.addName();
-name.setFamily("Shmoe");
-
-// Add a new "given name", which is of type String
-StringType given = name.addGivenElement();
-given.setValue("Joe");
-
-// Create an extension and add it to the String
-Extension givenExt = new Extension("http://examples.com#moreext", new StringType("Hello"));
-given.addExtension(givenExt);
-//END SNIPPET: resourceStringExtension
-
-FhirContext ctx = FhirContext.forDstu3();
-String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
-System.out.println(output);
-
-
-//START SNIPPET: parseExtension
-// Get all extensions (modifier or not) for a given URL
-List resourceExts = patient.getExtensionsByUrl("http://fooextensions.com#exts");
-
-// Get all non-modifier extensions regardless of URL
-List nonModExts = patient.getExtension();
-
-//Get all non-modifier extensions regardless of URL
-List modExts = patient.getModifierExtension();
-//END SNIPPET: parseExtension
-
-}
-
-
-public void foo() {
-//START SNIPPET: subExtension
-Patient patient = new Patient();
-
-// Add an extension (initially with no contents) to the resource
-Extension parent = new Extension("http://example.com#parent");
-patient.addExtension(parent);
-
-// Add two extensions as children to the parent extension
-Extension child1 = new Extension("http://example.com#childOne", new StringType("value1"));
-parent.addExtension(child1);
-
-Extension child2 = new Extension("http://example.com#chilwo", new StringType("value1"));
-parent.addExtension(child2);
-//END SNIPPET: subExtension
-
-}
-
-}
diff --git a/examples/src/main/java/example/FhirContextIntro.java b/examples/src/main/java/example/FhirContextIntro.java
deleted file mode 100644
index 0ee77203a77..00000000000
--- a/examples/src/main/java/example/FhirContextIntro.java
+++ /dev/null
@@ -1,137 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu2.resource.Observation;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.valueset.NameUseEnum;
-import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.parser.IParser;
-
-public class FhirContextIntro {
-
- @SuppressWarnings("unused")
- public static void creatingContext() {
-// START SNIPPET: creatingContext
-// Create a context for DSTU2
-FhirContext ctxDstu2 = FhirContext.forDstu2();
-
-// Alternately, create a context for R4
-FhirContext ctxR4 = FhirContext.forR4();
-// END SNIPPET: creatingContext
-
- }
-
- @SuppressWarnings("unused")
- public static void creatingContextHl7org() {
-// START SNIPPET: creatingContextHl7org
-// Create a context for DSTU3
-FhirContext ctx = FhirContext.forDstu3();
-
-// Working with RI structures is similar to how it works with the HAPI structures
-org.hl7.fhir.dstu3.model.Patient patient = new org.hl7.fhir.dstu3.model.Patient();
-patient.addName().addGiven("John").setFamily("Smith");
-patient.getBirthDateElement().setValueAsString("1998-02-22");
-
-// Parsing and encoding works the same way too
-String encoded = ctx.newJsonParser().encodeResourceToString(patient);
-
-// END SNIPPET: creatingContextHl7org
-
- }
-
- public static void main(String[] args) throws DataFormatException {
-
-new FhirContextIntro().encodeMsg();
-
-
- }
-
- public void encodeMsg() throws DataFormatException {
-FhirContext ctx = new FhirContext(Patient.class, Observation.class);
-//START SNIPPET: encodeMsg
-
-/**
- * FHIR model types in HAPI are simple POJOs. To create a new
- * one, invoke the default constructor and then
- * start populating values.
- */
-Patient patient = new Patient();
-
-// Add an MRN (a patient identifier)
-IdentifierDt id = patient.addIdentifier();
-id.setSystem("http://example.com/fictitious-mrns");
-id.setValue("MRN001");
-
-// Add a name
-HumanNameDt name = patient.addName();
-name.setUse(NameUseEnum.OFFICIAL);
-name.addFamily("Tester");
-name.addGiven("John");
-name.addGiven("Q");
-
-// We can now use a parser to encode this resource into a string.
-String encoded = ctx.newXmlParser().encodeResourceToString(patient);
-System.out.println(encoded);
-//END SNIPPET: encodeMsg
-
-//START SNIPPET: encodeMsgJson
-IParser jsonParser = ctx.newJsonParser();
-jsonParser.setPrettyPrint(true);
-encoded = jsonParser.encodeResourceToString(patient);
-System.out.println(encoded);
-//END SNIPPET: encodeMsgJson
-
-
- }
-
-
-public void fluent() throws DataFormatException {
-FhirContext ctx = new FhirContext(Patient.class, Observation.class);
-String encoded;
-//START SNIPPET: encodeMsgFluent
-Patient patient = new Patient();
-patient.addIdentifier().setSystem("http://example.com/fictitious-mrns").setValue("MRN001");
-patient.addName().setUse(NameUseEnum.OFFICIAL).addFamily("Tester").addGiven("John").addGiven("Q");
-
-encoded = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
-System.out.println(encoded);
-//END SNIPPET: encodeMsgFluent
-
-}
-
-
- public static void parseMsg() {
-FhirContext ctx = FhirContext.forR4();
-
-//START SNIPPET: parseMsg
-// The following is an example Patient resource
-String msgString = ""
- + "John Cardinal
"
- + " "
- + " "
- + "
"
- + " "
- + " ";
-
-// The hapi context object is used to create a new XML parser
-// instance. The parser can then be used to parse (or unmarshall) the
-// string message into a Patient object
-IParser parser = ctx.newXmlParser();
-Patient patient = parser.parseResource(Patient.class, msgString);
-
-// The patient object has accessor methods to retrieve all of the
-// data which has been parsed into the instance.
-String patientId = patient.getIdentifier().get(0).getValue();
-String familyName = patient.getName().get(0).getFamily().get(0).getValue();
-String gender = patient.getGender();
-
-System.out.println(patientId); // PRP1660
-System.out.println(familyName); // Cardinal
-System.out.println(gender); // M
-//END SNIPPET: parseMsg
-
- }
-
-}
diff --git a/examples/src/main/java/example/FhirDataModel.java b/examples/src/main/java/example/FhirDataModel.java
deleted file mode 100644
index d6d521a4586..00000000000
--- a/examples/src/main/java/example/FhirDataModel.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package example;
-
-import java.util.*;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
-import ca.uhn.fhir.model.dstu2.composite.*;
-import ca.uhn.fhir.model.dstu2.resource.Observation;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.valueset.*;
-import ca.uhn.fhir.model.primitive.InstantDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-
-public class FhirDataModel {
-
- public static void datatypes() {
- // START SNIPPET: datatypes
- Observation obs = new Observation();
-
- // These are all equivalent
- obs.setIssued(new InstantDt(new Date()));
- obs.setIssued(new Date(), TemporalPrecisionEnum.MILLI);
- obs.setIssuedWithMillisPrecision(new Date());
-
- // The InstantDt also lets you work with the instant as a Java Date
- // object or as a FHIR String.
- Date date = obs.getIssuedElement().getValue(); // A date object
- String dateString = obs.getIssuedElement().getValueAsString(); // "2014-03-08T12:59:58.068-05:00"
- // END SNIPPET: datatypes
-
- System.out.println(date);
- System.out.println(dateString);
-
- }
-
- @SuppressWarnings("unused")
- public void nonNull() {
- // START SNIPPET: nonNull
- Observation observation = new Observation();
-
- // None of these calls will not return null, but instead create their
- // respective
- // child elements.
- List identifierList = observation.getIdentifier();
- CodeableConceptDt code = observation.getCode();
- StringDt textElement = observation.getCode().getTextElement();
-
- // DateTimeDt is a FHIR primitive however, so the following will return
- // null
- // unless a value has been placed there.
- Date active = observation.addIdentifier().getPeriod().getStartElement().getValue();
- // END SNIPPET: nonNull
-
- }
-
- @SuppressWarnings("unused")
- public static void codes() {
- // START SNIPPET: codes
- Patient patient = new Patient();
-
- // You can set this code using a String if you want. Note that
- // for "closed" valuesets (such as the one used for Patient.gender)
- // you must use one of the strings defined by the FHIR specification.
- // You must not define your own.
- patient.getGenderElement().setValue("male");
-
- // HAPI also provides Java enumerated types which make it easier to
- // deal with coded values. This code achieves the exact same result
- // as the code above.
- patient.setGender(AdministrativeGenderEnum.MALE);
-
- // You can also retrieve coded values the same way
- String genderString = patient.getGenderElement().getValueAsString();
- AdministrativeGenderEnum genderEnum = patient.getGenderElement().getValueAsEnum();
-
- // The following is a shortcut to create
- patient.setMaritalStatus(MaritalStatusCodesEnum.M);
- // END SNIPPET: codes
-
- }
-
-
- @SuppressWarnings("unused")
- public static void codeableConcepts() {
- // START SNIPPET: codeableConcepts
- Patient patient = new Patient();
-
- // Coded types can naturally be set using plain strings
- CodingDt statusCoding = patient.getMaritalStatus().addCoding();
- statusCoding.setSystem("http://hl7.org/fhir/v3/MaritalStatus");
- statusCoding.setCode("M");
- statusCoding.setDisplay("Married");
-
- // You could add a second coding to the field if needed too. This
- // can be useful if you want to convey the concept using different
- // codesystems.
- CodingDt secondStatus = patient.getMaritalStatus().addCoding();
- secondStatus.setCode("H");
- secondStatus.setSystem("http://example.com#maritalStatus");
- secondStatus.setDisplay("Happily Married");
-
- // CodeableConcept also has a text field meant to convey
- // a user readable version of the concepts it conveys.
- patient.getMaritalStatus().setText("Happily Married");
-
- // There are also accessors for retrieving values
- String firstCode = patient.getMaritalStatus().getCoding().get(0).getCode();
- String secondCode = patient.getMaritalStatus().getCoding().get(1).getCode();
- // END SNIPPET: codeableConcepts
-
- }
-
- @SuppressWarnings("unused")
- public static void codeableConceptEnums() {
- // START SNIPPET: codeableConceptEnums
- Patient patient = new Patient();
-
- // Set the CodeableConcept's first coding to use the code
- // and codesystem associated with the M value.
- patient.setMaritalStatus(MaritalStatusCodesEnum.M);
-
- // If you need to set other fields (such as the display name) after
- // using the Enum type, you may still do so.
- patient.getMaritalStatus().getCodingFirstRep().setDisplay("Married");
- patient.getMaritalStatus().getCodingFirstRep().setVersion("1.0");
- patient.getMaritalStatus().getCodingFirstRep().setUserSelected(true);
-
- // You can use accessors to retrieve values from CodeableConcept fields
-
- // Returns "M"
- String code = patient.getMaritalStatus().getCodingFirstRep().getCode();
-
- // Returns "http://hl7.org/fhir/v3/MaritalStatus". This value was also
- // populated via the enum above.
- String codeSystem = patient.getMaritalStatus().getCodingFirstRep().getCode();
-
- // In many cases, Enum types can be used to retrieve values as well. Note that
- // the setter takes a single type, but the getter returns a Set, because the
- // field can technicaly contain more than one code and codesystem. BE CAREFUL
- // when using this method however, as no Enum will be returned in the case
- // that the field contains only a code other than the ones defined by the Enum.
- Set status = patient.getMaritalStatus().getValueAsEnum();
- // END SNIPPET: codeableConceptEnums
-
- }
-
-
- public static void main(String[] args) {
- tmp();
-
-
- datatypes();
-
- // START SNIPPET: observation
- // Create an Observation instance
- Observation observation = new Observation();
-
- // Give the observation a status
- observation.setStatus(ObservationStatusEnum.FINAL);
-
- // Give the observation a code (what kind of observation is this)
- CodingDt coding = observation.getCode().addCoding();
- coding.setCode("29463-7").setSystem("http://loinc.org").setDisplay("Body Weight");
-
- // Create a quantity datatype
- QuantityDt value = new QuantityDt();
- value.setValue(83.9).setSystem("http://unitsofmeasure.org").setCode("kg");
- observation.setValue(value);
-
- // Set the reference range
- SimpleQuantityDt low = new SimpleQuantityDt();
- low.setValue(45).setSystem("http://unitsofmeasure.org").setCode("kg");
- observation.getReferenceRangeFirstRep().setLow(low);
- SimpleQuantityDt high = new SimpleQuantityDt();
- low.setValue(90).setSystem("http://unitsofmeasure.org").setCode("kg");
- observation.getReferenceRangeFirstRep().setHigh(high);
-
- // END SNIPPET: observation
-
-
- }
-
- private static void tmp() {
-// Create a FHIR Context
-FhirContext ctx = FhirContext.forDstu2();
-
-// Create a client
-IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
-
-// Read a patient with the given ID
-Patient patient = client
- .read()
- .resource(Patient.class)
- .withId("952975")
- .execute();
-
-// Print the patient's name
-String string = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
-System.out.println(string);
-
- }
-
- public void namesHard() {
- // START SNIPPET: namesHard
- Patient patient = new Patient();
- HumanNameDt name = patient.addName();
- StringDt family = name.addFamily();
- family.setValue("Smith");
- StringDt firstName = name.addGiven();
- firstName.setValue("Rob");
- StringDt secondName = name.addGiven();
- secondName.setValue("Bruce");
- // END SNIPPET: namesHard
- }
-
- public void namesEasy() {
- // START SNIPPET: namesEasy
- Patient patient = new Patient();
- patient.addName().addFamily("Smith").addGiven("Rob").addGiven("Bruce");
- // END SNIPPET: namesEasy
- }
-
-}
diff --git a/examples/src/main/java/example/GenericClientExample.java b/examples/src/main/java/example/GenericClientExample.java
deleted file mode 100644
index 8366f2c147b..00000000000
--- a/examples/src/main/java/example/GenericClientExample.java
+++ /dev/null
@@ -1,536 +0,0 @@
-package example;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.context.PerformanceOptionsEnum;
-import ca.uhn.fhir.model.api.IResource;
-import ca.uhn.fhir.model.dstu2.resource.*;
-import ca.uhn.fhir.model.dstu2.resource.OperationOutcome.Issue;
-import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
-import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
-import ca.uhn.fhir.model.primitive.*;
-import ca.uhn.fhir.rest.api.*;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
-import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
-import ca.uhn.fhir.rest.param.DateRangeParam;
-import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
-
-public class GenericClientExample {
- public static void deferModelScanning() {
- // START SNIPPET: deferModelScanning
- // Create a context and configure it for deferred child scanning
- FhirContext ctx = FhirContext.forDstu2();
- ctx.setPerformanceOptions(PerformanceOptionsEnum.DEFERRED_MODEL_SCANNING);
-
- // Now create a client and use it
- String serverBase = "http://fhirtest.uhn.ca/baseDstu2";
- IGenericClient client = ctx.newRestfulGenericClient(serverBase);
- // END SNIPPET: deferModelScanning
- }
-
- public static void performance() {
- // START SNIPPET: dontValidate
- // Create a context
- FhirContext ctx = FhirContext.forDstu2();
-
- // Disable server validation (don't pull the server's metadata first)
- ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
-
- // Now create a client and use it
- String serverBase = "http://fhirtest.uhn.ca/baseDstu2";
- IGenericClient client = ctx.newRestfulGenericClient(serverBase);
- // END SNIPPET: dontValidate
- }
-
- public static void simpleExample() {
- // START SNIPPET: simple
- // We're connecting to a DSTU1 compliant server in this example
- FhirContext ctx = FhirContext.forDstu2();
- String serverBase = "http://fhirtest.uhn.ca/baseDstu2";
-
- IGenericClient client = ctx.newRestfulGenericClient(serverBase);
-
- // Perform a search
- Bundle results = client
- .search()
- .forResource(Patient.class)
- .where(Patient.FAMILY.matches().value("duck"))
- .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .execute();
-
- System.out.println("Found " + results.getEntry().size() + " patients named 'duck'");
- // END SNIPPET: simple
- }
-
- @SuppressWarnings("unused")
- public static void fluentSearch() {
- FhirContext ctx = FhirContext.forDstu2();
- IGenericClient client = ctx.newRestfulGenericClient("http://fhir.healthintersections.com.au/open");
- {
- // START SNIPPET: create
- Patient patient = new Patient();
- // ..populate the patient object..
- patient.addIdentifier().setSystem("urn:system").setValue("12345");
- patient.addName().addFamily("Smith").addGiven("John");
-
- // Invoke the server create method (and send pretty-printed JSON
- // encoding to the server
- // instead of the default which is non-pretty printed XML)
- MethodOutcome outcome = client.create()
- .resource(patient)
- .prettyPrint()
- .encodedJson()
- .execute();
-
- // The MethodOutcome object will contain information about the
- // response from the server, including the ID of the created
- // resource, the OperationOutcome response, etc. (assuming that
- // any of these things were provided by the server! They may not
- // always be)
- IdDt id = (IdDt) outcome.getId();
- System.out.println("Got ID: " + id.getValue());
- // END SNIPPET: create
- }
- {
- Patient patient = new Patient();
- // START SNIPPET: createConditional
- // One form
- MethodOutcome outcome = client.create()
- .resource(patient)
- .conditionalByUrl("Patient?identifier=system%7C00001")
- .execute();
-
- // Another form
- MethodOutcome outcome2 = client.create()
- .resource(patient)
- .conditional()
- .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
- .execute();
-
- // This will return Boolean.TRUE if the server responded with an HTTP 201 created,
- // otherwise it will return null.
- Boolean created = outcome.getCreated();
-
- // The ID of the created, or the pre-existing resource
- IdDt id = (IdDt) outcome.getId();
- // END SNIPPET: createConditional
- }
- {
- // START SNIPPET: validate
- Patient patient = new Patient();
- patient.addIdentifier().setSystem("http://hospital.com").setValue("123445");
- patient.addName().addFamily("Smith").addGiven("John");
-
- // Validate the resource
- MethodOutcome outcome = client.validate()
- .resource(patient)
- .execute();
-
- // The returned object will contain an operation outcome resource
- OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
-
- // If the OperationOutcome has any issues with a severity of ERROR or SEVERE,
- // the validation failed.
- for (Issue nextIssue : oo.getIssue()) {
- if (nextIssue.getSeverityElement().getValueAsEnum().ordinal() >= IssueSeverityEnum.ERROR.ordinal()) {
- System.out.println("We failed validation!");
- }
- }
- // END SNIPPET: validate
- }
- {
- // START SNIPPET: update
- Patient patient = new Patient();
- // ..populate the patient object..
- patient.addIdentifier().setSystem("urn:system").setValue("12345");
- patient.addName().addFamily("Smith").addGiven("John");
-
- // To update a resource, it should have an ID set (if the resource
- // object
- // comes from the results of a previous read or search, it will already
- // have one though)
- patient.setId("Patient/123");
-
- // Invoke the server update method
- MethodOutcome outcome = client.update()
- .resource(patient)
- .execute();
-
- // The MethodOutcome object will contain information about the
- // response from the server, including the ID of the created
- // resource, the OperationOutcome response, etc. (assuming that
- // any of these things were provided by the server! They may not
- // always be)
- IdDt id = (IdDt) outcome.getId();
- System.out.println("Got ID: " + id.getValue());
- // END SNIPPET: update
- }
- {
- Patient patient = new Patient();
- // START SNIPPET: updateConditional
- client.update()
- .resource(patient)
- .conditionalByUrl("Patient?identifier=system%7C00001")
- .execute();
-
- client.update()
- .resource(patient)
- .conditional()
- .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
- .execute();
- // END SNIPPET: updateConditional
- }
- {
- // START SNIPPET: etagupdate
- // First, let's retrive the latest version of a resource
- // from the server
- Patient patient = client.read().resource(Patient.class).withId("123").execute();
-
- // If the server is a version aware server, we should now know the latest version
- // of the resource
- System.out.println("Version ID: " + patient.getId().getVersionIdPart());
-
- // Now let's make a change to the resource
- patient.setGender(AdministrativeGenderEnum.FEMALE);
-
- // Invoke the server update method - Because the resource has
- // a version, it will be included in the request sent to
- // the server
- try {
- MethodOutcome outcome = client
- .update()
- .resource(patient)
- .execute();
- } catch (PreconditionFailedException e) {
- // If we get here, the latest version has changed
- // on the server so our update failed.
- }
- // END SNIPPET: etagupdate
- }
- {
- // START SNIPPET: conformance
- // Retrieve the server's conformance statement and print its
- // description
- Conformance conf = client.fetchConformance().ofType(Conformance.class).execute();
- System.out.println(conf.getDescriptionElement().getValue());
- // END SNIPPET: conformance
- }
- {
- // START SNIPPET: delete
- IBaseOperationOutcome resp = client.delete().resourceById(new IdDt("Patient", "1234")).execute();
-
- // outcome may be null if the server didn't return one
- if (resp != null) {
- OperationOutcome outcome = (OperationOutcome) resp;
- System.out.println(outcome.getIssueFirstRep().getDetailsElement().getValue());
- }
- // END SNIPPET: delete
- }
- {
- // START SNIPPET: deleteConditional
- client.delete()
- .resourceConditionalByUrl("Patient?identifier=system%7C00001")
- .execute();
-
- client.delete()
- .resourceConditionalByType("Patient")
- .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
- .execute();
- // END SNIPPET: deleteConditional
- }
- {
- // START SNIPPET: search
- ca.uhn.fhir.model.dstu2.resource.Bundle response = client.search()
- .forResource(Patient.class)
- .where(Patient.BIRTHDATE.beforeOrEquals().day("2011-01-01"))
- .and(Patient.CAREPROVIDER.hasChainedProperty(Organization.NAME.matches().value("Health")))
- .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .execute();
- // END SNIPPET: search
-
- // START SNIPPET: searchOr
- response = client.search()
- .forResource(Patient.class)
- .where(Patient.FAMILY.matches().values("Smith", "Smyth"))
- .returnBundle(Bundle.class)
- .execute();
- // END SNIPPET: searchOr
-
- // START SNIPPET: searchAnd
- response = client.search()
- .forResource(Patient.class)
- .where(Patient.ADDRESS.matches().values("Toronto"))
- .and(Patient.ADDRESS.matches().values("Ontario"))
- .and(Patient.ADDRESS.matches().values("Canada"))
- .returnBundle(Bundle.class)
- .execute();
- // END SNIPPET: searchAnd
-
- // START SNIPPET: searchCompartment
- response = client.search()
- .forResource(Patient.class)
- .withIdAndCompartment("123", "condition")
- .where(Patient.ADDRESS.matches().values("Toronto"))
- .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .execute();
- // END SNIPPET: searchCompartment
-
- // START SNIPPET: searchUrl
- String searchUrl = "http://example.com/base/Patient?identifier=foo";
-
- // Search URL can also be a relative URL in which case the client's base
- // URL will be added to it
- searchUrl = "Patient?identifier=foo";
-
- response = client.search()
- .byUrl(searchUrl)
- .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .execute();
- // END SNIPPET: searchUrl
-
- // START SNIPPET: searchSubsetSummary
- response = client.search()
- .forResource(Patient.class)
- .where(Patient.ADDRESS.matches().values("Toronto"))
- .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .summaryMode(SummaryEnum.TRUE)
- .execute();
- // END SNIPPET: searchSubsetSummary
-
- // START SNIPPET: searchSubsetElements
- response = client.search()
- .forResource(Patient.class)
- .where(Patient.ADDRESS.matches().values("Toronto"))
- .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .elementsSubset("identifier", "name") // only include the identifier and name
- .execute();
- // END SNIPPET: searchSubsetElements
-
- // START SNIPPET: searchAdv
- response = client.search()
- .forResource(Patient.class)
- .encodedJson()
- .where(Patient.BIRTHDATE.beforeOrEquals().day("2012-01-22"))
- .and(Patient.BIRTHDATE.after().day("2011-01-01"))
- .withTag("http://acme.org/codes", "needs-review")
- .include(Patient.INCLUDE_ORGANIZATION.asRecursive())
- .include(Patient.INCLUDE_CAREPROVIDER.asNonRecursive())
- .revInclude(Provenance.INCLUDE_TARGET)
- .lastUpdated(new DateRangeParam("2011-01-01", null))
- .sort().ascending(Patient.BIRTHDATE)
- .sort().descending(Patient.NAME).limitTo(123)
- .returnBundle(Bundle.class)
- .execute();
- // END SNIPPET: searchAdv
-
- // START SNIPPET: searchPost
- response = client.search()
- .forResource("Patient")
- .where(Patient.NAME.matches().value("Tester"))
- .usingStyle(SearchStyleEnum.POST)
- .returnBundle(Bundle.class)
- .execute();
- // END SNIPPET: searchPost
-
- // START SNIPPET: searchComposite
- response = client.search()
- .forResource("Observation")
- .where(Observation.CODE_VALUE_DATE
- .withLeft(Observation.CODE.exactly().code("FOO$BAR"))
- .withRight(Observation.VALUE_DATE.exactly().day("2001-01-01")))
- .returnBundle(Bundle.class)
- .execute();
- // END SNIPPET: searchComposite
- }
- {
- // START SNIPPET: transaction
- List resources = new ArrayList();
- // .. populate this list - note that you can also pass in a populated
- // Bundle if you want to create one manually ..
-
- List response = client.transaction().withResources(resources).execute();
- // END SNIPPET: transaction
- }
-
- {
- // START SNIPPET: read
- // search for patient 123
- Patient patient = client.read()
- .resource(Patient.class)
- .withId("123")
- .execute();
- // END SNIPPET: read
- }
- {
- // START SNIPPET: vread
- // search for patient 123 (specific version 888)
- Patient patient = client.read()
- .resource(Patient.class)
- .withIdAndVersion("123", "888")
- .execute();
- // END SNIPPET: vread
- }
- {
- // START SNIPPET: readabsolute
- // search for patient 123 on example.com
- String url = "http://example.com/fhir/Patient/123";
- Patient patient = client.read()
- .resource(Patient.class)
- .withUrl(url)
- .execute();
- // END SNIPPET: readabsolute
- }
-
- {
- // START SNIPPET: etagread
- // search for patient 123
- Patient patient = client.read()
- .resource(Patient.class)
- .withId("123")
- .ifVersionMatches("001").returnNull()
- .execute();
- if (patient == null) {
- // resource has not changed
- }
- // END SNIPPET: etagread
- }
-
-
-
- }
-
- @SuppressWarnings("unused")
- public static void history() {
- IGenericClient client = FhirContext.forDstu2().newRestfulGenericClient("");
- {
- ca.uhn.fhir.model.dstu2.resource.Bundle response;
- // START SNIPPET: historyDstu2
- response = client
- .history()
- .onServer()
- .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .execute();
- // END SNIPPET: historyDstu2
- }
- {
- ca.uhn.fhir.model.dstu2.resource.Bundle response;
- // START SNIPPET: historyFeatures
- response = client
- .history()
- .onServer()
- .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
- .since(new InstantDt("2012-01-01T12:22:32.038Z"))
- .count(100)
- .execute();
- // END SNIPPET: historyFeatures
- }
- }
-
- public static void main(String[] args) {
- paging();
- }
- private static void paging() {
- {
- // START SNIPPET: searchPaging
- FhirContext ctx = FhirContext.forDstu2();
- IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
-
- // Perform a search
- Bundle resultBundle = client.search()
- .forResource(Patient.class)
- .where(Patient.NAME.matches().value("Smith"))
- .returnBundle(Bundle.class)
- .execute();
-
- if (resultBundle.getLink(Bundle.LINK_NEXT) != null) {
-
- // load next page
- Bundle nextPage = client.loadPage().next(resultBundle).execute();
- }
- // END SNIPPET: searchPaging
- }
- }
-
- @SuppressWarnings("unused")
- private static void operationHttpGet() {
- // START SNIPPET: operationHttpGet
- // Create a client to talk to the HeathIntersections server
- FhirContext ctx = FhirContext.forDstu2();
- IGenericClient client = ctx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open");
- client.registerInterceptor(new LoggingInterceptor(true));
-
- // Create the input parameters to pass to the server
- Parameters inParams = new Parameters();
- inParams.addParameter().setName("start").setValue(new DateDt("2001-01-01"));
- inParams.addParameter().setName("end").setValue(new DateDt("2015-03-01"));
-
- // Invoke $everything on "Patient/1"
- Parameters outParams = client
- .operation()
- .onInstance(new IdDt("Patient", "1"))
- .named("$everything")
- .withParameters(inParams)
- .useHttpGet() // Use HTTP GET instead of POST
- .execute();
- // END SNIPPET: operationHttpGet
- }
-
- @SuppressWarnings("unused")
- private static void operation() {
- // START SNIPPET: operation
- // Create a client to talk to the HeathIntersections server
- FhirContext ctx = FhirContext.forDstu2();
- IGenericClient client = ctx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open");
- client.registerInterceptor(new LoggingInterceptor(true));
-
- // Create the input parameters to pass to the server
- Parameters inParams = new Parameters();
- inParams.addParameter().setName("start").setValue(new DateDt("2001-01-01"));
- inParams.addParameter().setName("end").setValue(new DateDt("2015-03-01"));
-
- // Invoke $everything on "Patient/1"
- Parameters outParams = client
- .operation()
- .onInstance(new IdDt("Patient", "1"))
- .named("$everything")
- .withParameters(inParams)
- .execute();
-
- /*
- * Note that the $everything operation returns a Bundle instead
- * of a Parameters resource. The client operation methods return a
- * Parameters instance however, so HAPI creates a Parameters object
- * with a single parameter containing the value.
- */
- Bundle responseBundle = (Bundle) outParams.getParameter().get(0).getResource();
-
- // Print the response bundle
- System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(responseBundle));
- // END SNIPPET: operation
- }
-
- @SuppressWarnings("unused")
- private static void operationNoIn() {
- // START SNIPPET: operationNoIn
- // Create a client to talk to the HeathIntersections server
- FhirContext ctx = FhirContext.forDstu2();
- IGenericClient client = ctx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open");
- client.registerInterceptor(new LoggingInterceptor(true));
-
- // Invoke $everything on "Patient/1"
- Parameters outParams = client
- .operation()
- .onInstance(new IdDt("Patient", "1"))
- .named("$everything")
- .withNoParameters(Parameters.class) // No input parameters
- .execute();
- // END SNIPPET: operationNoIn
- }
-
-}
diff --git a/examples/src/main/java/example/GenomicsUploader.java b/examples/src/main/java/example/GenomicsUploader.java
deleted file mode 100644
index f7f87823905..00000000000
--- a/examples/src/main/java/example/GenomicsUploader.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
-import org.hl7.fhir.r4.model.Enumerations;
-import org.hl7.fhir.r4.model.SearchParameter;
-
-public class GenomicsUploader {
-
- public static void main(String[] theArgs) {
- FhirContext ctx = FhirContext.forR4();
- IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseR4");
- client.registerInterceptor(new LoggingInterceptor(false));
-
- SearchParameter dnaSequenceVariantName = new SearchParameter();
- dnaSequenceVariantName.setId("SearchParameter/dnaSequenceVariantName");
- dnaSequenceVariantName.setStatus(Enumerations.PublicationStatus.ACTIVE);
- dnaSequenceVariantName.addBase("Observation");
- dnaSequenceVariantName.setCode("dnaSequenceVariantName");
- dnaSequenceVariantName.setType(Enumerations.SearchParamType.TOKEN);
- dnaSequenceVariantName.setTitle("DNASequenceVariantName");
- dnaSequenceVariantName.setExpression("Observation.extension('http://hl7.org/fhir/StructureDefinition/observation-geneticsDNASequenceVariantName')");
- dnaSequenceVariantName.setXpathUsage(SearchParameter.XPathUsageType.NORMAL);
- client.update().resource(dnaSequenceVariantName).execute();
-
- SearchParameter dNAVariantId = new SearchParameter();
- dNAVariantId.setId("SearchParameter/dNAVariantId");
- dNAVariantId.setStatus(Enumerations.PublicationStatus.ACTIVE);
- dNAVariantId.addBase("Observation");
- dNAVariantId.setCode("dnaVariantId");
- dNAVariantId.setType(Enumerations.SearchParamType.TOKEN);
- dNAVariantId.setTitle("DNAVariantId");
- dNAVariantId.setExpression("Observation.extension('http://hl7.org/fhir/StructureDefinition/observation-geneticsDNAVariantId')");
- dNAVariantId.setXpathUsage(SearchParameter.XPathUsageType.NORMAL);
- client.update().resource(dNAVariantId).execute();
-
- SearchParameter gene = new SearchParameter();
- gene.setId("SearchParameter/gene");
- gene.setStatus(Enumerations.PublicationStatus.ACTIVE);
- gene.addBase("Observation");
- gene.setCode("gene");
- gene.setType(Enumerations.SearchParamType.TOKEN);
- gene.setTitle("Gene");
- gene.setExpression("Observation.extension('http://hl7.org/fhir/StructureDefinition/observation-geneticsGene')");
- gene.setXpathUsage(SearchParameter.XPathUsageType.NORMAL);
- client.update().resource(gene).execute();
-
- SearchParameter alleleName = new SearchParameter();
- alleleName.setId("SearchParameter/alleleName");
- alleleName.setStatus(Enumerations.PublicationStatus.ACTIVE);
- alleleName.addBase("Observation");
- alleleName.setCode("alleleName");
- alleleName.setType(Enumerations.SearchParamType.TOKEN);
- alleleName.setTitle("AlleleName");
- alleleName.setExpression("Observation.extension('http://hl7.org/fhir/StructureDefinition/observation-geneticsAlleleName')");
- alleleName.setXpathUsage(SearchParameter.XPathUsageType.NORMAL);
- client.update().resource(alleleName).execute();
- }
-
-}
diff --git a/examples/src/main/java/example/HttpProxy.java b/examples/src/main/java/example/HttpProxy.java
deleted file mode 100644
index 3e26973b7f3..00000000000
--- a/examples/src/main/java/example/HttpProxy.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package example;
-
-import org.apache.http.HttpHost;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.impl.client.*;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-
-public class HttpProxy {
-
- public static void main(String[] args) {
- /*
- * This is out ot date - Just keeping
- * it in case it's helpful...
- */
- final String authUser = "username";
- final String authPassword = "password";
- CredentialsProvider credsProvider = new BasicCredentialsProvider();
- credsProvider.setCredentials(new AuthScope("10.10.10.10", 8080),
- new UsernamePasswordCredentials(authUser, authPassword));
-
- HttpHost myProxy = new HttpHost("10.10.10.10", 8080);
-
-
- HttpClientBuilder clientBuilder = HttpClientBuilder.create();
- clientBuilder
- .setProxy(myProxy)
- .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy())
- .setDefaultCredentialsProvider(credsProvider)
- .disableCookieManagement();
- CloseableHttpClient httpClient = clientBuilder.build();
-
- FhirContext ctx = FhirContext.forDstu2();
- String serverBase = "http://spark.furore.com/fhir/";
- ctx.getRestfulClientFactory().setHttpClient(httpClient);
- IGenericClient client = ctx.newRestfulGenericClient(serverBase);
-
- IdDt id = new IdDt("Patient", "123");
- client.read(Patient.class, id);
-
- }
-
-}
diff --git a/examples/src/main/java/example/IRestfulClient.java b/examples/src/main/java/example/IRestfulClient.java
deleted file mode 100644
index d9963f27d62..00000000000
--- a/examples/src/main/java/example/IRestfulClient.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package example;
-
-import java.util.List;
-
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.client.api.IBasicClient;
-
-//START SNIPPET: provider
-/**
- * All RESTful clients must be an interface which extends IBasicClient
- */
-public interface IRestfulClient extends IBasicClient {
-
- /**
- * The "@Read" annotation indicates that this method supports the
- * read operation. Read operations should return a single resource
- * instance.
- *
- * @param theId
- * The read operation takes one parameter, which must be of type
- * IdDt and must be annotated with the "@Read.IdParam" annotation.
- * @return
- * Returns a resource matching this identifier, or null if none exists.
- */
- @Read()
- public Patient getResourceById(@IdParam IdDt theId);
-
- /**
- * The "@Search" annotation indicates that this method supports the
- * search operation. You may have many different methods annotated with
- * this annotation, to support many different search criteria. This
- * example searches by family name.
- *
- * @param theIdentifier
- * This operation takes one parameter which is the search criteria. It is
- * annotated with the "@Required" annotation. This annotation takes one argument,
- * a string containing the name of the search criteria. The datatype here
- * is StringDt, but there are other possible parameter types depending on the
- * specific search criteria.
- * @return
- * This method returns a list of Patients. This list may contain multiple
- * matching resources, or it may also be empty.
- */
- @Search()
- public List getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringDt theFamilyName);
-
-}
-//END SNIPPET: provider
-
-
diff --git a/examples/src/main/java/example/IncludesExamples.java b/examples/src/main/java/example/IncludesExamples.java
deleted file mode 100644
index 899d095d62d..00000000000
--- a/examples/src/main/java/example/IncludesExamples.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package example;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hl7.fhir.instance.model.api.IBaseResource;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.resource.Organization;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.valueset.BundleTypeEnum;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.server.provider.dstu2.Dstu2BundleFactory;
-
-public class IncludesExamples {
-
- public static void main(String[] args) {
- testSearchForPatients();
- }
-
- private static void testSearchForPatients() {
- List resources = new IncludesExamples().searchForPatients();
-
- // Create a bundle with both
- FhirContext ctx = FhirContext.forDstu2();
-
- Dstu2BundleFactory bf = new Dstu2BundleFactory(ctx);
- bf.addRootPropertiesToBundle(null, null, null, null, null, resources.size(), BundleTypeEnum.SEARCHSET, null);
- bf.addResourcesToBundle(new ArrayList<>(resources), BundleTypeEnum.SEARCHSET, null, null, null);
- IBaseResource b = bf.getResourceBundle();
-
- // Encode the bundle
- String encoded = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
- System.out.println(encoded);
- }
-
- // START SNIPPET: addIncludes
- @Search
- private List searchForPatients() {
- // Create an organization
- Organization org = new Organization();
- org.setId("Organization/65546");
- org.setName("Test Organization");
-
- // Create a patient
- Patient patient = new Patient();
- patient.setId("Patient/1333");
- patient.addIdentifier().setSystem("urn:mrns").setValue("253345");
- patient.getManagingOrganization().setResource(org);
-
- // Here we return only the patient object, which has links to other resources
- List retVal = new ArrayList();
- retVal.add(patient);
- return retVal;
- }
- // END SNIPPET: addIncludes
-
-}
diff --git a/examples/src/main/java/example/JaxRsClient.java b/examples/src/main/java/example/JaxRsClient.java
deleted file mode 100644
index 581b38c4b88..00000000000
--- a/examples/src/main/java/example/JaxRsClient.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.jaxrs.client.JaxRsRestfulClientFactory;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-
-@SuppressWarnings(value= {"serial"})
-public class JaxRsClient {
-
-public static void main(String[] args) {
-//START SNIPPET: createClient
-
- // Create a client
- FhirContext ctx = FhirContext.forDstu2();
-
- // Create an instance of the JAX RS client factory and
- // set it on the context
- JaxRsRestfulClientFactory clientFactory = new JaxRsRestfulClientFactory(ctx);
- ctx.setRestfulClientFactory(clientFactory);
-
- // This client uses JAX-RS!
- IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu2");
-
-//END SNIPPET: createClient
-}
-
-
-}
diff --git a/examples/src/main/java/example/JaxRsConformanceProvider.java b/examples/src/main/java/example/JaxRsConformanceProvider.java
deleted file mode 100644
index 1f1549f07f7..00000000000
--- a/examples/src/main/java/example/JaxRsConformanceProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package example;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.ejb.EJB;
-import javax.ejb.Stateless;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import ca.uhn.fhir.jaxrs.server.AbstractJaxRsConformanceProvider;
-import ca.uhn.fhir.rest.api.Constants;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-
-/**
- * Conformance Rest Service
- *
- * @author Peter Van Houte
- */
- // START SNIPPET: jax-rs-conformance
-@Path("")
-@Stateless
-@Produces({ MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML })
-public class JaxRsConformanceProvider extends AbstractJaxRsConformanceProvider {
-
- @EJB
- private JaxRsPatientRestProvider provider;
-
- public JaxRsConformanceProvider() {
- super("My Server Description", "My Server Name", "My Server Version");
- }
-
- @Override
- protected ConcurrentHashMap, IResourceProvider> getProviders() {
- ConcurrentHashMap, IResourceProvider> map = new ConcurrentHashMap, IResourceProvider>();
- map.put(JaxRsConformanceProvider.class, this);
- map.put(JaxRsPatientRestProvider.class, provider);
- return map;
- }
-}
-// END SNIPPET: jax-rs-conformance
diff --git a/examples/src/main/java/example/JaxRsPatientRestProvider.java b/examples/src/main/java/example/JaxRsPatientRestProvider.java
deleted file mode 100644
index 6c68f1a6a14..00000000000
--- a/examples/src/main/java/example/JaxRsPatientRestProvider.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package example;
-
-import javax.ejb.Local;
-import javax.ejb.Stateless;
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import ca.uhn.fhir.jaxrs.server.AbstractJaxRsResourceProvider;
-import ca.uhn.fhir.model.dstu2.resource.Parameters;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.rest.annotation.*;
-import ca.uhn.fhir.rest.api.*;
-
-/**
- * A demo JaxRs Patient Rest Provider
- */
-@Local
-@Stateless
-// START SNIPPET: jax-rs-provider-construction
-@Path("/Patient")
-@Produces({ MediaType.APPLICATION_JSON, Constants.CT_FHIR_JSON, Constants.CT_FHIR_XML })
-public class JaxRsPatientRestProvider extends AbstractJaxRsResourceProvider {
-
- public JaxRsPatientRestProvider() {
- super(JaxRsPatientRestProvider.class);
- }
-// END SNIPPET: jax-rs-provider-construction
-
- @Override
- public Class getResourceType() {
- return Patient.class;
- }
-
-
- @Create
- public MethodOutcome create(@ResourceParam final Patient patient, @ConditionalUrlParam String theConditional) {
- // create the patient ...
- return new MethodOutcome(new IdDt(1L)).setCreated(true);
- }
-
-// START SNIPPET: jax-rs-provider-operation
- @GET
- @Path("/{id}/$someCustomOperation")
- public Response someCustomOperationUsingGet(@PathParam("id") String id, String resource) throws Exception {
- return customOperation(resource, RequestTypeEnum.GET, id, "$someCustomOperation",
- RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE);
- }
-
- @Operation(name = "someCustomOperation", idempotent = true, returnParameters = {
- @OperationParam(name = "return", type = StringDt.class) })
- public Parameters someCustomOperation(@IdParam IdDt myId, @OperationParam(name = "dummy") StringDt dummyInput) {
- Parameters parameters = new Parameters();
- parameters.addParameter().setName("return").setValue(new StringDt("My Dummy Result"));
- return parameters;
- }
- // END SNIPPET: jax-rs-provider-operation
-
- @POST
- @Path("/{id}/$someCustomOperation")
- public Response someCustomOperationUsingPost(@PathParam("id") String id, String resource) throws Exception {
- return customOperation(resource, RequestTypeEnum.POST, id, "$someCustomOperation",
- RestOperationTypeEnum.EXTENDED_OPERATION_INSTANCE);
- }
-
-}
diff --git a/examples/src/main/java/example/Multitenancy.java b/examples/src/main/java/example/Multitenancy.java
deleted file mode 100644
index 21f840e379e..00000000000
--- a/examples/src/main/java/example/Multitenancy.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package example;
-
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-import ca.uhn.fhir.rest.server.RestfulServer;
-import ca.uhn.fhir.rest.server.tenant.UrlBaseTenantIdentificationStrategy;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-import org.hl7.fhir.r4.model.IdType;
-import org.hl7.fhir.r4.model.Patient;
-
-public class Multitenancy {
-
-//START SNIPPET: enableUrlBaseTenantIdentificationStrategy
- public class MyServer extends RestfulServer {
-
- @Override
- protected void initialize() {
-
- setTenantIdentificationStrategy(new UrlBaseTenantIdentificationStrategy());
-
- // ... do other initialization ...
- }
-}
-//END SNIPPET: enableUrlBaseTenantIdentificationStrategy
-
-//START SNIPPET: resourceProvider
- public class MyPatientResourceProvider implements IResourceProvider {
-
- @Override
- public Class extends IBaseResource> getResourceType() {
- return Patient.class;
- }
-
- @Read
- public Patient read(RequestDetails theRequestDetails, @IdParam IdType theId) {
-
- String tenantId = theRequestDetails.getTenantId();
- String resourceId = theId.getIdPart();
-
- // Use these two values to fetch the patient
-
- return new Patient();
- }
-}
-
-//END SNIPPET: resourceProvider
-
-}
diff --git a/examples/src/main/java/example/MyPatient.java b/examples/src/main/java/example/MyPatient.java
deleted file mode 100644
index 02248f0a81d..00000000000
--- a/examples/src/main/java/example/MyPatient.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package example;
-
-//START SNIPPET: patientDef
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hl7.fhir.dstu3.model.DateTimeType;
-import org.hl7.fhir.dstu3.model.Patient;
-import org.hl7.fhir.dstu3.model.StringType;
-
-import ca.uhn.fhir.model.api.annotation.Child;
-import ca.uhn.fhir.model.api.annotation.Description;
-import ca.uhn.fhir.model.api.annotation.Extension;
-import ca.uhn.fhir.model.api.annotation.ResourceDef;
-import ca.uhn.fhir.util.ElementUtil;
-
-/**
- * Definition class for adding extensions to the built-in
- * Patient resource type.
- *
- * Note the "profile" attribute below, which indicates the URL/ID of the
- * profile implemented by this resource. You are not required to supply this,
- * but if you do it will be automatically populated in the resource meta
- * tag if the resource is returned by a server.
- */
-@ResourceDef(name="Patient", profile="http://example.com/StructureDefinition/mypatient")
-public class MyPatient extends Patient {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Each extension is defined in a field. Any valid HAPI Data Type
- * can be used for the field type. Note that the [name=""] attribute
- * in the @Child annotation needs to match the name for the bean accessor
- * and mutator methods.
- */
- @Child(name="petName")
- @Extension(url="http://example.com/dontuse#petname", definedLocally=false, isModifier=false)
- @Description(shortDefinition="The name of the patient's favourite pet")
- private StringType myPetName;
-
- /**
- * The second example extension uses a List type to provide
- * repeatable values. Note that a [max=] value has been placed in
- * the @Child annotation.
- *
- * Note also that this extension is a modifier extension
- */
- @Child(name="importantDates", max=Child.MAX_UNLIMITED)
- @Extension(url="http://example.com/dontuse#importantDates", definedLocally=false, isModifier=true)
- @Description(shortDefinition="Some dates of note for this patient")
- private List myImportantDates;
-
- /**
- * It is important to override the isEmpty() method, adding a check for any
- * newly added fields.
- */
- @Override
- public boolean isEmpty() {
- return super.isEmpty() && ElementUtil.isEmpty(myPetName, myImportantDates);
- }
-
- /********
- * Accessors and mutators follow
- *
- * IMPORTANT:
- * Each extension is required to have an getter/accessor and a stter/mutator.
- * You are highly recommended to create getters which create instances if they
- * do not already exist, since this is how the rest of the HAPI FHIR API works.
- ********/
-
- /** Getter for important dates */
- public List getImportantDates() {
- if (myImportantDates==null) {
- myImportantDates = new ArrayList();
- }
- return myImportantDates;
- }
-
- /** Getter for pet name */
- public StringType getPetName() {
- if (myPetName == null) {
- myPetName = new StringType();
- }
- return myPetName;
- }
-
- /** Setter for important dates */
- public void setImportantDates(List theImportantDates) {
- myImportantDates = theImportantDates;
- }
-
- /** Setter for pet name */
- public void setPetName(StringType thePetName) {
- myPetName = thePetName;
- }
-
-}
-//END SNIPPET: patientDef
diff --git a/examples/src/main/java/example/MyPatientUse.java b/examples/src/main/java/example/MyPatientUse.java
deleted file mode 100644
index d4068a86c7e..00000000000
--- a/examples/src/main/java/example/MyPatientUse.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package example;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.context.RuntimeResourceDefinition;
-import ca.uhn.fhir.model.api.annotation.Child;
-import ca.uhn.fhir.model.api.annotation.Description;
-import ca.uhn.fhir.model.api.annotation.Extension;
-import ca.uhn.fhir.model.api.annotation.ResourceDef;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.DateTimeDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.parser.IParser;
-
-public class MyPatientUse {
-
- @ResourceDef()
- public static class MyPatient extends Patient {
-
- @Child(name="petName")
- @Extension(url="http://example.com/dontuse#petname", definedLocally=false, isModifier=false)
- @Description(shortDefinition="The name of the patient's favourite pet")
- private StringDt myPetName;
-
- public StringDt getPetName() {
- if(myPetName==null) {
- myPetName = new StringDt();
- }
- return myPetName;
- }
-
- public void setPetName(StringDt thePetName) {
- myPetName = thePetName;
- }
-
- public List getImportantDates() {
- if (myImportantDates==null) {
- myImportantDates=new ArrayList();
- }
- return myImportantDates;
- }
-
- public void setImportantDates(List theImportantDates) {
- myImportantDates = theImportantDates;
- }
-
- @Child(name="importantDates", max=Child.MAX_UNLIMITED)
- @Extension(url="http://example.com/dontuse#importantDates", definedLocally=false, isModifier=true)
- @Description(shortDefinition="Some dates of note for the patient")
- private List myImportantDates;
-
- }
-
-@SuppressWarnings("unused")
-public static void main(String[] args) throws DataFormatException, IOException {
-//START SNIPPET: patientUse
-MyPatient patient = new MyPatient();
-patient.setPetName(new StringDt("Fido"));
-patient.getImportantDates().add(new DateTimeDt("2010-01-02"));
-patient.getImportantDates().add(new DateTimeDt("2014-01-26T11:11:11"));
-
-patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr");
-
-IParser p = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true);
-String messageString = p.encodeResourceToString(patient);
-
-System.out.println(messageString);
-//END SNIPPET: patientUse
-
-//START SNIPPET: patientParse
-IParser parser = FhirContext.forDstu2().newXmlParser();
-MyPatient newPatient = parser.parseResource(MyPatient.class, messageString);
-//END SNIPPET: patientParse
-
-{
- FhirContext ctx2 = FhirContext.forDstu2();
- RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient);
- System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile()));
-}
-}
-
-}
diff --git a/examples/src/main/java/example/Narrative.java b/examples/src/main/java/example/Narrative.java
deleted file mode 100644
index d8c5c9aa4ce..00000000000
--- a/examples/src/main/java/example/Narrative.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.valueset.NarrativeStatusEnum;
-import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
-import ca.uhn.fhir.parser.DataFormatException;
-
-@SuppressWarnings("unused")
-public class Narrative {
-
-public static void main(String[] args) throws DataFormatException {
-
-//START SNIPPET: example1
-Patient patient = new Patient();
-patient.addIdentifier().setSystem("urn:foo").setValue("7000135");
-patient.addName().addFamily("Smith").addGiven("John").addGiven("Edward");
-patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").setState("ZZ");
-
-FhirContext ctx = FhirContext.forDstu2();
-
-// Use the narrative generator
-ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
-
-// Encode the output, including the narrative
-String output = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
-System.out.println(output);
-//END SNIPPET: example1
-
-}
-
-public void simple() {
-//START SNIPPET: simple
-Patient pat = new Patient();
-pat.getText().setStatus(NarrativeStatusEnum.GENERATED);
-pat.getText().setDiv("This is the narrative text this is line 2
");
-//END SNIPPET: simple
-}
-
-}
diff --git a/examples/src/main/java/example/NarrativeGenerator.java b/examples/src/main/java/example/NarrativeGenerator.java
deleted file mode 100644
index daeab7ae4ae..00000000000
--- a/examples/src/main/java/example/NarrativeGenerator.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.narrative.CustomThymeleafNarrativeGenerator;
-
-@SuppressWarnings("unused")
-public class NarrativeGenerator {
-
- public void testGenerator() {
-
-//START SNIPPET: gen
-FhirContext ctx = FhirContext.forDstu2();
-String propFile = "classpath:/com/foo/customnarrative.properties";
-CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator(propFile);
-
-ctx.setNarrativeGenerator(gen);
-//END SNIPPET: gen
-
-
- }
-}
diff --git a/examples/src/main/java/example/NewInterceptors.java b/examples/src/main/java/example/NewInterceptors.java
deleted file mode 100644
index 60da5d43ded..00000000000
--- a/examples/src/main/java/example/NewInterceptors.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package example;
-
-public class NewInterceptors {
-}
diff --git a/examples/src/main/java/example/PagingPatientProvider.java b/examples/src/main/java/example/PagingPatientProvider.java
deleted file mode 100644
index efcfaa7ff46..00000000000
--- a/examples/src/main/java/example/PagingPatientProvider.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package example;
-
-import java.util.List;
-
-import org.hl7.fhir.instance.model.api.IBaseResource;
-
-import ca.uhn.fhir.model.api.IResource;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.InstantDt;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.api.server.IBundleProvider;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-
-import javax.annotation.Nonnull;
-
-@SuppressWarnings("null")
-// START SNIPPET: provider
-public class PagingPatientProvider implements IResourceProvider {
-
- /**
- * Search for Patient resources matching a given family name
- */
- @Search
- public IBundleProvider search(@RequiredParam(name = Patient.SP_FAMILY) StringParam theFamily) {
- final InstantDt searchTime = InstantDt.withCurrentTime();
-
- /**
- * First, we'll search the database for a set of database row IDs that
- * match the given search criteria. That way we can keep just the row IDs
- * around, and load the actual resources on demand later as the client
- * pages through them.
- */
- final List matchingResourceIds = null; // <-- implement this
-
- /**
- * Return a bundle provider which can page through the IDs and return the
- * resources that go with them.
- */
- return new IBundleProvider() {
-
- @Override
- public Integer size() {
- return matchingResourceIds.size();
- }
-
- @Nonnull
- @Override
- public List getResources(int theFromIndex, int theToIndex) {
- int end = Math.max(theToIndex, matchingResourceIds.size() - 1);
- List idsToReturn = matchingResourceIds.subList(theFromIndex, end);
- return loadResourcesByIds(idsToReturn);
- }
-
- @Override
- public InstantDt getPublished() {
- return searchTime;
- }
-
- @Override
- public Integer preferredPageSize() {
- // Typically this method just returns null
- return null;
- }
-
- @Override
- public String getUuid() {
- return null;
- }
- };
- }
-
- /**
- * Load a list of patient resources given their IDs
- */
- private List loadResourcesByIds(List theIdsToReturn) {
- // .. implement this search against the database ..
- return null;
- }
-
- @Override
- public Class extends IResource> getResourceType() {
- return Patient.class;
- }
-
-}
-// END SNIPPET: provider
diff --git a/examples/src/main/java/example/PagingServer.java b/examples/src/main/java/example/PagingServer.java
deleted file mode 100644
index d35ceddd138..00000000000
--- a/examples/src/main/java/example/PagingServer.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package example;
-
-import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
-import ca.uhn.fhir.rest.server.RestfulServer;
-
-@SuppressWarnings({ "serial" })
-//START SNIPPET: provider
-public class PagingServer extends RestfulServer {
-
- public PagingServer() {
-
- /*
- * Set the resource providers as always. Here we are using the paging
- * provider from the example below, but it is not strictly neccesary
- * to use a paging resource provider as well. If a normal resource
- * provider is used (one which returns List> instead of IBundleProvider)
- * then the loaded resources will be stored by the IPagingProvider.
- */
- setResourceProviders(new PagingPatientProvider());
-
- /*
- * Set a paging provider. Here a simple in-memory implementation
- * is used, but you may create your own.
- */
- FifoMemoryPagingProvider pp = new FifoMemoryPagingProvider(10);
- pp.setDefaultPageSize(10);
- pp.setMaximumPageSize(100);
- setPagingProvider(pp);
-
- }
-
-}
-//END SNIPPET: provider
diff --git a/examples/src/main/java/example/Parser.java b/examples/src/main/java/example/Parser.java
deleted file mode 100644
index 7e3802fcb42..00000000000
--- a/examples/src/main/java/example/Parser.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package example;
-
-import java.io.IOException;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.parser.IParser;
-
-public class Parser {
-
-public static void main(String[] args) throws DataFormatException, IOException {
- {
-//START SNIPPET: disableStripVersions
-FhirContext ctx = FhirContext.forDstu2();
-IParser parser = ctx.newJsonParser();
-
-// Disable the automatic stripping of versions from references on the parser
-parser.setStripVersionsFromReferences(false);
-//END SNIPPET: disableStripVersions
-
-//START SNIPPET: disableStripVersionsCtx
-ctx.getParserOptions().setStripVersionsFromReferences(false);
-//END SNIPPET: disableStripVersionsCtx
-
- }
-
- {
-//START SNIPPET: disableStripVersionsField
-FhirContext ctx = FhirContext.forDstu2();
-IParser parser = ctx.newJsonParser();
-
-// Preserve versions only on these two fields (for the given parser)
-parser.setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.reference", "Patient.managingOrganization");
-
-// You can also apply this setting to the context so that it will
-// flow to all parsers
-ctx.getParserOptions().setDontStripVersionsFromReferencesAtPaths("AuditEvent.entity.reference", "Patient.managingOrganization");
-//END SNIPPET: disableStripVersionsField
-
- }
-}
-}
diff --git a/examples/src/main/java/example/PatchExamples.java b/examples/src/main/java/example/PatchExamples.java
deleted file mode 100644
index 43af0984d46..00000000000
--- a/examples/src/main/java/example/PatchExamples.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package example;
-
-import org.hl7.fhir.dstu3.model.IdType;
-import org.hl7.fhir.dstu3.model.OperationOutcome;
-
-import ca.uhn.fhir.rest.annotation.*;
-import ca.uhn.fhir.rest.api.PatchTypeEnum;
-
-
-public class PatchExamples {
-
- //START SNIPPET: patch
- @Patch
- public OperationOutcome patientPatch(@IdParam IdType theId, PatchTypeEnum thePatchType, @ResourceParam String theBody) {
-
- if (thePatchType == PatchTypeEnum.JSON_PATCH) {
- // do something
- }
- if (thePatchType == PatchTypeEnum.XML_PATCH) {
- // do something
- }
-
- OperationOutcome retVal = new OperationOutcome();
- retVal.getText().setDivAsString("OK
");
- return retVal;
- }
- //END SNIPPET: patch
-
-
-}
diff --git a/examples/src/main/java/example/QuickUsage.java b/examples/src/main/java/example/QuickUsage.java
deleted file mode 100644
index fffa88ed80f..00000000000
--- a/examples/src/main/java/example/QuickUsage.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package example;
-
-import java.io.IOException;
-import java.util.List;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
-import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
-import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.rest.annotation.Create;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.ResourceParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.api.MethodOutcome;
-import ca.uhn.fhir.rest.client.api.IRestfulClient;
-
-public class QuickUsage {
-
-@SuppressWarnings("unused")
-public static void main(String[] args) throws DataFormatException, IOException {
-
-Patient patient = new Patient();
-patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135");
-patient.addIdentifier().setUse(IdentifierUseEnum.SECONDARY).setSystem("urn:fake:otherids").setValue("3287486");
-
-patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("Junior");
-
-patient.setGender(AdministrativeGenderEnum.MALE);
-
-
-FhirContext ctx = FhirContext.forDstu2();
-String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient);
-String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient);
-
-MyClientInterface client = ctx.newRestfulClient(MyClientInterface.class, "http://foo/fhir");
-IdentifierDt searchParam = new IdentifierDt("urn:someidentifiers", "7000135");
-List clients = client.findPatientsByIdentifier(searchParam);
-}
-
-public interface MyClientInterface extends IRestfulClient
-{
- /** A FHIR search */
- @Search
- public List findPatientsByIdentifier(@RequiredParam(name="identifier") IdentifierDt theIdentifier);
-
- /** A FHIR create */
- @Create
- public MethodOutcome createPatient(@ResourceParam Patient thePatient);
-
-}
-
-}
diff --git a/examples/src/main/java/example/RequestCounterInterceptor.java b/examples/src/main/java/example/RequestCounterInterceptor.java
deleted file mode 100644
index acf35013d56..00000000000
--- a/examples/src/main/java/example/RequestCounterInterceptor.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package example;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
-
-//START SNIPPET: interceptor
-public class RequestCounterInterceptor extends InterceptorAdapter
-{
-
- private int myRequestCount;
-
- public int getRequestCount() {
- return myRequestCount;
- }
-
- /**
- * Override the incomingRequestPreProcessed method, which is called
- * for each incoming request before any processing is done
- */
- @Override
- public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {
- myRequestCount++;
- return true;
- }
-
-}
-//END SNIPPET: interceptor
diff --git a/examples/src/main/java/example/RequestExceptionInterceptor.java b/examples/src/main/java/example/RequestExceptionInterceptor.java
deleted file mode 100644
index c041250bd77..00000000000
--- a/examples/src/main/java/example/RequestExceptionInterceptor.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package example;
-
-import java.io.IOException;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
-import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
-
-//START SNIPPET: interceptor
-public class RequestExceptionInterceptor extends InterceptorAdapter
-{
-
- @Override
- public boolean handleException(RequestDetails theRequestDetails, BaseServerResponseException theException, HttpServletRequest theServletRequest,
- HttpServletResponse theServletResponse) throws ServletException, IOException {
-
- // HAPI's server exceptions know what the appropriate HTTP status code is
- theServletResponse.setStatus(theException.getStatusCode());
-
- // Provide a response ourself
- theServletResponse.setContentType("text/plain");
- theServletResponse.getWriter().append("Failed to process!");
- theServletResponse.getWriter().close();
-
- // Since we handled this response in the interceptor, we must return false
- // to stop processing immediately
- return false;
- }
-
-
-}
-//END SNIPPET: interceptor
diff --git a/examples/src/main/java/example/ResourceRefs.java b/examples/src/main/java/example/ResourceRefs.java
deleted file mode 100644
index b5d81d41595..00000000000
--- a/examples/src/main/java/example/ResourceRefs.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu2.resource.Organization;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-
-public class ResourceRefs {
-
- private static FhirContext ourCtx = FhirContext.forDstu2();
-
- public static void main(String[] args) {
- manualContained();
- }
-
- public static void manualContained() {
- // START SNIPPET: manualContained
- // Create an organization, and give it a local ID
- Organization org = new Organization();
- org.setId("#localOrganization");
- org.getNameElement().setValue("Contained Test Organization");
-
- // Create a patient
- Patient patient = new Patient();
- patient.setId("Patient/1333");
- patient.addIdentifier().setSystem("urn:mrns").setValue("253345");
-
- // Set the reference, and manually add the contained resource
- patient.getManagingOrganization().setReference("#localOrganization");
- patient.getContained().getContainedResources().add(org);
-
- String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
- System.out.println(encoded);
- // END SNIPPET: manualContained
- }
-
-}
diff --git a/examples/src/main/java/example/RestfulObservationResourceProvider.java b/examples/src/main/java/example/RestfulObservationResourceProvider.java
deleted file mode 100644
index 773d7640c7c..00000000000
--- a/examples/src/main/java/example/RestfulObservationResourceProvider.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package example;
-
-import java.util.Collections;
-import java.util.List;
-
-import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.model.primitive.UriDt;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-
-//START SNIPPET: provider
-/**
- * All resource providers must implement IResourceProvider
- */
-public class RestfulObservationResourceProvider implements IResourceProvider {
-
- /**
- * The getResourceType method comes from IResourceProvider, and must
- * be overridden to indicate what type of resource this provider
- * supplies.
- */
- @Override
- public Class getResourceType() {
- return Patient.class;
- }
-
- /**
- * The "@Read" annotation indicates that this method supports the
- * read operation. It takes one argument, the Resource type being returned.
- *
- * @param theId
- * The read operation takes one parameter, which must be of type
- * IdDt and must be annotated with the "@Read.IdParam" annotation.
- * @return
- * Returns a resource matching this identifier, or null if none exists.
- */
- @Read()
- public Patient getResourceById(@IdParam IdDt theId) {
- Patient patient = new Patient();
- patient.addIdentifier();
- patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
- patient.getIdentifier().get(0).setValue("00002");
- patient.addName().addFamily("Test");
- patient.getName().get(0).addGiven("PatientOne");
- patient.setGender(AdministrativeGenderEnum.FEMALE);
- return patient;
- }
-
- /**
- * The "@Search" annotation indicates that this method supports the
- * search operation. You may have many different methods annotated with
- * this annotation, to support many different search criteria. This
- * example searches by family name.
- *
- * @param theIdentifier
- * This operation takes one parameter which is the search criteria. It is
- * annotated with the "@Required" annotation. This annotation takes one argument,
- * a string containing the name of the search criteria. The datatype here
- * is StringDt, but there are other possible parameter types depending on the
- * specific search criteria.
- * @return
- * This method returns a list of Patients. This list may contain multiple
- * matching resources, or it may also be empty.
- */
- @Search()
- public List getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringDt theFamilyName) {
- Patient patient = new Patient();
- patient.addIdentifier();
- patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
- patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
- patient.getIdentifier().get(0).setValue("00001");
- patient.addName();
- patient.getName().get(0).addFamily("Test");
- patient.getName().get(0).addGiven("PatientOne");
- patient.setGender(AdministrativeGenderEnum.MALE);
- return Collections.singletonList(patient);
- }
-
-}
-//END SNIPPET: provider
diff --git a/examples/src/main/java/example/RestfulPatientResourceProvider.java b/examples/src/main/java/example/RestfulPatientResourceProvider.java
deleted file mode 100644
index 3fe42a9ab39..00000000000
--- a/examples/src/main/java/example/RestfulPatientResourceProvider.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package example;
-
-import java.util.Collections;
-import java.util.List;
-
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
-import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.model.primitive.UriDt;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-
-//START SNIPPET: provider
-/**
- * All resource providers must implement IResourceProvider
- */
-public class RestfulPatientResourceProvider implements IResourceProvider {
-
- /**
- * The getResourceType method comes from IResourceProvider, and must
- * be overridden to indicate what type of resource this provider
- * supplies.
- */
- @Override
- public Class getResourceType() {
- return Patient.class;
- }
-
- /**
- * The "@Read" annotation indicates that this method supports the
- * read operation. Read operations should return a single resource
- * instance.
- *
- * @param theId
- * The read operation takes one parameter, which must be of type
- * IdDt and must be annotated with the "@Read.IdParam" annotation.
- * @return
- * Returns a resource matching this identifier, or null if none exists.
- */
- @Read()
- public Patient getResourceById(@IdParam IdDt theId) {
- Patient patient = new Patient();
- patient.addIdentifier();
- patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
- patient.getIdentifier().get(0).setValue("00002");
- patient.addName().addFamily("Test");
- patient.getName().get(0).addGiven("PatientOne");
- patient.setGender(AdministrativeGenderEnum.FEMALE);
- return patient;
- }
-
- /**
- * The "@Search" annotation indicates that this method supports the
- * search operation. You may have many different methods annotated with
- * this annotation, to support many different search criteria. This
- * example searches by family name.
- *
- * @param theFamilyName
- * This operation takes one parameter which is the search criteria. It is
- * annotated with the "@Required" annotation. This annotation takes one argument,
- * a string containing the name of the search criteria. The datatype here
- * is StringParam, but there are other possible parameter types depending on the
- * specific search criteria.
- * @return
- * This method returns a list of Patients. This list may contain multiple
- * matching resources, or it may also be empty.
- */
- @Search()
- public List getPatient(@RequiredParam(name = Patient.SP_FAMILY) StringParam theFamilyName) {
- Patient patient = new Patient();
- patient.addIdentifier();
- patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
- patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
- patient.getIdentifier().get(0).setValue("00001");
- patient.addName();
- patient.getName().get(0).addFamily(theFamilyName.getValue());
- patient.getName().get(0).addGiven("PatientOne");
- patient.setGender(AdministrativeGenderEnum.MALE);
- return Collections.singletonList(patient);
- }
-
-}
-//END SNIPPET: provider
-
-
diff --git a/examples/src/main/java/example/RestfulPatientResourceProviderMore.java b/examples/src/main/java/example/RestfulPatientResourceProviderMore.java
deleted file mode 100644
index 8bb1c1eed4d..00000000000
--- a/examples/src/main/java/example/RestfulPatientResourceProviderMore.java
+++ /dev/null
@@ -1,1036 +0,0 @@
-package example;
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.*;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.hl7.fhir.dstu3.model.*;
-import org.hl7.fhir.dstu3.model.Bundle;
-import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent;
-import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse;
-import org.hl7.fhir.dstu3.model.OperationOutcome.IssueSeverity;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-import org.hl7.fhir.instance.model.api.IIdType;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.api.*;
-import ca.uhn.fhir.model.api.annotation.Description;
-import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.rest.annotation.*;
-import ca.uhn.fhir.rest.annotation.Count;
-import ca.uhn.fhir.rest.api.*;
-import ca.uhn.fhir.rest.client.api.IBasicClient;
-import ca.uhn.fhir.rest.client.api.IRestfulClient;
-import ca.uhn.fhir.rest.param.*;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-import ca.uhn.fhir.rest.server.exceptions.*;
-
-@SuppressWarnings("unused")
-public abstract class RestfulPatientResourceProviderMore implements IResourceProvider {
-
- public interface ITestClient extends IBasicClient
- {
-
- @Search
- List getPatientByDob(@RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theParam);
-
- }
-
-private boolean detectedVersionConflict;
-private boolean conflictHappened;
-private boolean couldntFindThisId;
-private FhirContext myContext;
-
-//START SNIPPET: searchAll
-@Search
-public List getAllOrganizations() {
- List retVal=new ArrayList(); // populate this
- return retVal;
-}
-//END SNIPPET: searchAll
-
-//START SNIPPET: updateEtag
-@Update
-public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient thePatient) {
- String resourceId = theId.getIdPart();
- String versionId = theId.getVersionIdPart(); // this will contain the ETag
-
- String currentVersion = "1"; // populate this with the current version
-
- if (!versionId.equals(currentVersion)) {
- throw new ResourceVersionConflictException("Expected version " + currentVersion);
- }
-
- // ... perform the update ...
- return new MethodOutcome();
-
-}
-//END SNIPPET: updateEtag
-
-//START SNIPPET: summaryAndElements
-@Search
-public List search(
- SummaryEnum theSummary, // will receive the summary (no annotation required)
- @Elements Set theElements // (requires the @Elements annotation)
- ) {
- return null; // todo: populate
-}
-//END SNIPPET: summaryAndElements
-
-//START SNIPPET: searchCompartment
-public class PatientRp implements IResourceProvider {
-
- @Override
- public Class extends IBaseResource> getResourceType() {
- return Patient.class;
- }
-
- @Search(compartmentName="Condition")
- public List searchCompartment(@IdParam IdType thePatientId) {
- List retVal=new ArrayList();
-
- // populate this with resources of any type that are a part of the
- // "Condition" compartment for the Patient with ID "thePatientId"
-
- return retVal;
- }
-
- // .. also include other Patient operations ..
-}
-//END SNIPPET: searchCompartment
-
-
-//START SNIPPET: sort
-@Search
-public List findPatients(
- @RequiredParam(name=Patient.SP_IDENTIFIER) StringParam theParameter,
- @Sort SortSpec theSort) {
- List retVal=new ArrayList(); // populate this
-
- // theSort is null unless a _sort parameter is actually provided
- if (theSort != null) {
-
- // The name of the param to sort by
- String param = theSort.getParamName();
-
- // The sort order, or null
- SortOrderEnum order = theSort.getOrder();
-
- // This will be populated if a second _sort was specified
- SortSpec subSort = theSort.getChain();
-
- // ...apply the sort...
- }
-
- return retVal;
-}
-//END SNIPPET: sort
-
-//START SNIPPET: underlyingReq
-@Search
-public List findPatients(
- @RequiredParam(name="foo") StringParam theParameter,
- HttpServletRequest theRequest,
- HttpServletResponse theResponse) {
- List retVal=new ArrayList(); // populate this
- return retVal;
-}
-//END SNIPPET: underlyingReq
-
-//START SNIPPET: referenceSimple
-@Search
-public List findDiagnosticReportsWithSubjet(
- @OptionalParam(name=DiagnosticReport.SP_SUBJECT) ReferenceParam theSubject
- ) {
- List retVal=new ArrayList();
-
- // If the parameter passed in includes a resource type (e.g. ?subject:Patient=123)
- // that resource type is available. Here we just check that it is either not provided
- // or set to "Patient"
- if (theSubject.hasResourceType()) {
- String resourceType = theSubject.getResourceType();
- if ("Patient".equals(resourceType) == false) {
- throw new InvalidRequestException("Invalid resource type for parameter 'subject': " + resourceType);
- }
- }
-
- if (theSubject != null) {
- // ReferenceParam extends IdType so all of the resource ID methods are available
- String subjectId = theSubject.getIdPart();
-
- // .. populate retVal with DiagnosticReport resources having
- // subject with id "subjectId" ..
-
- }
-
- return retVal;
-
-}
-//END SNIPPET: referenceSimple
-
-
-//START SNIPPET: referenceWithChain
-@Search
-public List findReportsWithChain(
- @RequiredParam(name=DiagnosticReport.SP_SUBJECT, chainWhitelist= {Patient.SP_FAMILY, Patient.SP_GENDER}) ReferenceParam theSubject
- ) {
- List retVal=new ArrayList();
-
- String chain = theSubject.getChain();
- if (Patient.SP_FAMILY.equals(chain)) {
- String familyName = theSubject.getValue();
- // .. populate with reports matching subject family name ..
- }
- if (Patient.SP_GENDER.equals(chain)) {
- String gender = theSubject.getValue();
- // .. populate with reports matching subject gender ..
- }
-
- return retVal;
-}
-//END SNIPPET: referenceWithChain
-
-
-//START SNIPPET: referenceWithChainCombo
-@Search
-public List findReportsWithChainCombo (
- @RequiredParam(name=DiagnosticReport.SP_SUBJECT, chainWhitelist= {"", Patient.SP_FAMILY}) ReferenceParam theSubject
- ) {
- List retVal=new ArrayList();
-
- String chain = theSubject.getChain();
- if (Patient.SP_FAMILY.equals(chain)) {
- String familyName = theSubject.getValue();
- // .. populate with reports matching subject family name ..
- }
- if ("".equals(chain)) {
- String resourceId = theSubject.getValue();
- // .. populate with reports matching subject with resource ID ..
- }
-
- return retVal;
-}
-//END SNIPPET: referenceWithChainCombo
-
-
-//START SNIPPET: referenceWithStaticChain
-@Search
-public List findObservations(
- @RequiredParam(name=Observation.SP_SUBJECT+'.'+Patient.SP_IDENTIFIER) TokenParam theProvider
- ) {
-
- String system = theProvider.getSystem();
- String identifier = theProvider.getValue();
-
- // ...Do a search for all observations for the given subject...
-
- List retVal=new ArrayList(); // populate this
- return retVal;
-
-}
-//END SNIPPET: referenceWithStaticChain
-
-
-//START SNIPPET: referenceWithDynamicChain
-@Search()
-public List findBySubject(
- @RequiredParam(name=Observation.SP_SUBJECT, chainWhitelist = {"", Patient.SP_IDENTIFIER, Patient.SP_BIRTHDATE}) ReferenceParam subject
- ) {
- List observations = new ArrayList();
-
- String chain = subject.getChain();
- if (Patient.SP_IDENTIFIER.equals(chain)) {
-
- // Because the chained parameter "subject.identifier" is actually of type
- // "token", we convert the value to a token before processing it.
- TokenParam tokenSubject = subject.toTokenParam(myContext);
- String system = tokenSubject.getSystem();
- String identifier = tokenSubject.getValue();
-
- // TODO: populate all the observations for the identifier
-
- } else if (Patient.SP_BIRTHDATE.equals(chain)) {
-
- // Because the chained parameter "subject.birthdate" is actually of type
- // "date", we convert the value to a date before processing it.
- DateParam dateSubject = subject.toDateParam(myContext);
- DateTimeType birthDate = new DateTimeType(dateSubject.getValueAsString());
-
- // TODO: populate all the observations for the birthdate
-
- } else if ("".equals(chain)) {
-
- String resourceId = subject.getValue();
- // TODO: populate all the observations for the resource id
-
- }
-
- return observations;
-}
-//END SNIPPET: referenceWithDynamicChain
-
-
-//START SNIPPET: read
-@Read()
-public Patient getResourceById(@IdParam IdType theId) {
- Patient retVal = new Patient();
-
- // ...populate...
- retVal.addIdentifier().setSystem("urn:mrns").setValue("12345");
- retVal.addName().setFamily("Smith").addGiven("Tester").addGiven("Q");
- // ...etc...
-
- // if you know the version ID of the resource, you should set it and HAPI will
- // include it in a Content-Location header
- retVal.setId(new IdType("Patient", "123", "2"));
-
- return retVal;
-}
-//END SNIPPET: read
-
-//START SNIPPET: delete
-@Delete()
-public void deletePatient(@IdParam IdType theId) {
- // .. Delete the patient ..
- if (couldntFindThisId) {
- throw new ResourceNotFoundException("Unknown version");
- }
- if (conflictHappened) {
- throw new ResourceVersionConflictException("Couldn't delete because [foo]");
- }
- // otherwise, delete was successful
- return; // can also return MethodOutcome
-}
-//END SNIPPET: delete
-
-
-//START SNIPPET: deleteConditional
-@Delete()
-public void deletePatientConditional(@IdParam IdType theId, @ConditionalUrlParam String theConditionalUrl) {
- // Only one of theId or theConditionalUrl will have a value depending
- // on whether the URL receieved was a logical ID, or a conditional
- // search string
- if (theId != null) {
- // do a normal delete
- } else {
- // do a conditional delete
- }
-
- // otherwise, delete was successful
- return; // can also return MethodOutcome
-}
-//END SNIPPET: deleteConditional
-
-//START SNIPPET: history
-@History()
-public List getPatientHistory(
- @IdParam IdType theId,
- @Since InstantType theSince,
- @At DateRangeParam theAt
- ) {
- List retVal = new ArrayList();
-
- Patient patient = new Patient();
- patient.addName().setFamily("Smith");
-
- // Set the ID and version
- patient.setId(theId.withVersion("1"));
-
- // ...populate the rest...
- return retVal;
-}
-//END SNIPPET: history
-
-
-//START SNIPPET: vread
-@Read(version=true)
-public Patient readOrVread(@IdParam IdType theId) {
- Patient retVal = new Patient();
-
- if (theId.hasVersionIdPart()) {
- // this is a vread
- } else {
- // this is a read
- }
-
- // ...populate...
-
- return retVal;
-}
-//END SNIPPET: vread
-
-//START SNIPPET: searchStringParam
-@Search()
-public List searchByLastName(@RequiredParam(name=Patient.SP_FAMILY) StringParam theFamily) {
- String valueToMatch = theFamily.getValue();
-
- if (theFamily.isExact()) {
- // Do an exact match search
- } else {
- // Do a fuzzy search if possible
- }
-
- // ...populate...
- Patient patient = new Patient();
- patient.addIdentifier().setSystem("urn:mrns").setValue("12345");
- patient.addName().setFamily("Smith").addGiven("Tester").addGiven("Q");
- // ...etc...
-
- // Every returned resource must have its logical ID set. If the server
- // supports versioning, that should be set too
- String logicalId = "4325";
- String versionId = "2"; // optional
- patient.setId(new IdType("Patient", logicalId, versionId));
-
- /*
- * This is obviously a fairly contrived example since we are always
- * just returning the same hardcoded patient, but in a real scenario
- * you could return as many resources as you wanted, and they
- * should actually match the given search criteria.
- */
- List retVal = new ArrayList();
- retVal.add(patient);
-
- return retVal;
-}
-//END SNIPPET: searchStringParam
-
-//START SNIPPET: searchNamedQuery
-@Search(queryName="namedQuery1")
-public List searchByNamedQuery(@RequiredParam(name="someparam") StringParam theSomeParam) {
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: searchNamedQuery
-
-//START SNIPPET: searchComposite
-@Search()
-public List searchByComposite(
- @RequiredParam(name=Observation.SP_CODE_VALUE_DATE, compositeTypes= {TokenParam.class, DateParam.class})
- CompositeParam theParam) {
- // Each of the two values in the composite param are accessible separately.
- // In the case of Observation's name-value-date, the left is a string and
- // the right is a date.
- TokenParam observationName = theParam.getLeftValue();
- DateParam observationValue = theParam.getRightValue();
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: searchComposite
-
-
-//START SNIPPET: searchIdentifierParam
-@Search()
-public List searchByIdentifier(@RequiredParam(name=Patient.SP_IDENTIFIER) TokenParam theId) {
- String identifierSystem = theId.getSystem();
- String identifier = theId.getValue();
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: searchIdentifierParam
-
-//START SNIPPET: searchOptionalParam
-@Search()
-public List searchByNames( @RequiredParam(name=Patient.SP_FAMILY) StringParam theFamilyName,
- @OptionalParam(name=Patient.SP_GIVEN) StringParam theGivenName ) {
- String familyName = theFamilyName.getValue();
- String givenName = theGivenName != null ? theGivenName.getValue() : null;
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: searchOptionalParam
-
-//START SNIPPET: searchWithDocs
-@Description(shortDefinition="This search finds all patient resources matching a given name combination")
-@Search()
-public List searchWithDocs(
- @Description(shortDefinition="This is the patient's last name - Supports partial matches")
- @RequiredParam(name=Patient.SP_FAMILY) StringParam theFamilyName,
-
- @Description(shortDefinition="This is the patient's given names")
- @OptionalParam(name=Patient.SP_GIVEN) StringParam theGivenName ) {
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: searchWithDocs
-
-
-//START SNIPPET: searchMultiple
-@Search()
-public List searchByObservationNames(
- @RequiredParam(name=Observation.SP_CODE) TokenOrListParam theCodings ) {
-
- // The list here will contain 0..* codings, and any observations which match any of the
- // given codings should be returned
- List wantedCodings = theCodings.getValuesAsQueryTokens();
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: searchMultiple
-
-
-//START SNIPPET: searchMultipleAnd
-@Search()
-public List searchByPatientAddress(
- @RequiredParam(name=Patient.SP_ADDRESS) StringAndListParam theAddressParts ) {
-
- // StringAndListParam is a container for 0..* StringOrListParam, which is in turn a
- // container for 0..* strings. It is a little bit weird to understand at first, but think of the
- // StringAndListParam to be an AND list with multiple OR lists inside it. So you will need
- // to return results which match at least one string within every OR list.
- List wantedCodings = theAddressParts.getValuesAsQueryTokens();
- for (StringOrListParam nextOrList : wantedCodings) {
- List queryTokens = nextOrList.getValuesAsQueryTokens();
- // Only return results that match at least one of the tokens in the list below
- for (StringParam nextString : queryTokens) {
- // ....check for match...
- }
- }
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: searchMultipleAnd
-
-
-//START SNIPPET: dates
-@Search()
-public List searchByObservationNames( @RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theDate ) {
- ParamPrefixEnum prefix = theDate.getPrefix(); // e.g. gt, le, etc..
- Date date = theDate.getValue(); // e.g. 2011-01-02
- TemporalPrecisionEnum precision = theDate.getPrecision(); // e.g. DAY
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: dates
-
-public void dateClientExample() {
-ITestClient client = provideTc();
-//START SNIPPET: dateClient
-DateParam param = new DateParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, "2011-01-02");
-List response = client.getPatientByDob(param);
-//END SNIPPET: dateClient
-}
-
-//START SNIPPET: dateRange
-@Search()
-public List searchByDateRange(
- @RequiredParam(name=Observation.SP_DATE) DateRangeParam theRange ) {
-
- Date from = theRange.getLowerBoundAsInstant();
- Date to = theRange.getUpperBoundAsInstant();
-
- List retVal = new ArrayList();
- // ...populate...
- return retVal;
-}
-//END SNIPPET: dateRange
-
-
-private ITestClient provideTc() {
- return null;
-}
-@Override
-public Class extends IBaseResource> getResourceType() {
- return null;
-}
-
-
-
-//START SNIPPET: pathSpec
-@Search()
-public List getDiagnosticReport(
- @RequiredParam(name=DiagnosticReport.SP_IDENTIFIER)
- TokenParam theIdentifier,
-
- @IncludeParam(allow= {"DiagnosticReport:subject"})
- Set theIncludes ) {
-
- List retVal = new ArrayList();
-
- // Assume this method exists and loads the report from the DB
- DiagnosticReport report = loadSomeDiagnosticReportFromDatabase(theIdentifier);
-
- // If the client has asked for the subject to be included:
- if (theIncludes.contains(new Include("DiagnosticReport:subject"))) {
-
- // The resource reference should contain the ID of the patient
- IIdType subjectId = report.getSubject().getReferenceElement();
-
- // So load the patient ID and return it
- Patient subject = loadSomePatientFromDatabase(subjectId);
- report.getSubject().setResource(subject);
-
- }
-
- retVal.add(report);
- return retVal;
-}
-//END SNIPPET: pathSpec
-
-//START SNIPPET: revInclude
-@Search()
-public List getDiagnosticReport(
- @RequiredParam(name=DiagnosticReport.SP_IDENTIFIER)
- TokenParam theIdentifier,
-
- @IncludeParam()
- Set theIncludes,
-
- @IncludeParam(reverse=true)
- Set theReverseIncludes
- ) {
-
-return new ArrayList(); // populate this
-}
-//END SNIPPET: revInclude
-
-//START SNIPPET: pathSpecSimple
-@Search()
-public List getDiagnosticReport(
- @RequiredParam(name=DiagnosticReport.SP_IDENTIFIER)
- TokenParam theIdentifier,
-
- @IncludeParam(allow= {"DiagnosticReport:subject"})
- String theInclude ) {
-
- List retVal = new ArrayList();
-
- // Assume this method exists and loads the report from the DB
- DiagnosticReport report = loadSomeDiagnosticReportFromDatabase(theIdentifier);
-
- // If the client has asked for the subject to be included:
- if ("DiagnosticReport:subject".equals(theInclude)) {
-
- // The resource reference should contain the ID of the patient
- IIdType subjectId = report.getSubject().getReferenceElement();
-
- // So load the patient ID and return it
- Patient subject = loadSomePatientFromDatabase(subjectId);
- report.getSubject().setResource(subject);
-
- }
-
- retVal.add(report);
- return retVal;
-}
-//END SNIPPET: pathSpecSimple
-
-//START SNIPPET: quantity
-@Search()
-public List getObservationsByQuantity(
- @RequiredParam(name=Observation.SP_VALUE_QUANTITY) QuantityParam theQuantity) {
-
- List retVal = new ArrayList();
-
- ParamPrefixEnum prefix = theQuantity.getPrefix();
- BigDecimal value = theQuantity.getValue();
- String units = theQuantity.getUnits();
- // .. Apply these parameters ..
-
- // ... populate ...
- return retVal;
-}
-//END SNIPPET: quantity
-
-private DiagnosticReport loadSomeDiagnosticReportFromDatabase(TokenParam theIdentifier) {
- return null;
-}
-
-private Patient loadSomePatientFromDatabase(IIdType theId) {
- return null;
-}
-
-
-//START SNIPPET: create
-@Create
-public MethodOutcome createPatient(@ResourceParam Patient thePatient) {
-
- /*
- * First we might want to do business validation. The UnprocessableEntityException
- * results in an HTTP 422, which is appropriate for business rule failure
- */
- if (thePatient.getIdentifierFirstRep().isEmpty()) {
- /* It is also possible to pass an OperationOutcome resource
- * to the UnprocessableEntityException if you want to return
- * a custom populated OperationOutcome. Otherwise, a simple one
- * is created using the string supplied below.
- */
- throw new UnprocessableEntityException("No identifier supplied");
- }
-
- // Save this patient to the database...
- savePatientToDatabase(thePatient);
-
- // This method returns a MethodOutcome object which contains
- // the ID (composed of the type Patient, the logical ID 3746, and the
- // version ID 1)
- MethodOutcome retVal = new MethodOutcome();
- retVal.setId(new IdType("Patient", "3746", "1"));
-
- // You can also add an OperationOutcome resource to return
- // This part is optional though:
- OperationOutcome outcome = new OperationOutcome();
- outcome.addIssue().setDiagnostics("One minor issue detected");
- retVal.setOperationOutcome(outcome);
-
- return retVal;
-}
-//END SNIPPET: create
-
-
-//START SNIPPET: createConditional
-@Create
-public MethodOutcome createPatientConditional(
- @ResourceParam Patient thePatient,
- @ConditionalUrlParam String theConditionalUrl) {
-
- if (theConditionalUrl != null) {
- // We are doing a conditional create
-
- // populate this with the ID of the existing resource which
- // matches the conditional URL
- return new MethodOutcome();
- } else {
- // We are doing a normal create
-
- // populate this with the ID of the newly created resource
- return new MethodOutcome();
- }
-
-}
-//END SNIPPET: createConditional
-
-
-//START SNIPPET: createClient
-@Create
-public abstract MethodOutcome createNewPatient(@ResourceParam Patient thePatient);
-//END SNIPPET: createClient
-
-//START SNIPPET: updateConditional
-@Update
-public MethodOutcome updatePatientConditional(
- @ResourceParam Patient thePatient,
- @IdParam IdType theId,
- @ConditionalUrlParam String theConditional) {
-
- // Only one of theId or theConditional will have a value and the other will be null,
- // depending on the URL passed into the server.
- if (theConditional != null) {
- // Do a conditional update. theConditional will have a value like "Patient?identifier=system%7C00001"
- } else {
- // Do a normal update. theId will have the identity of the resource to update
- }
-
- return new MethodOutcome(); // populate this
-}
-//END SNIPPET: updateConditional
-
-//START SNIPPET: updatePrefer
-@Update
-public MethodOutcome updatePatientPrefer(
- @ResourceParam Patient thePatient,
- @IdParam IdType theId) {
-
- // Save the patient to the database
-
- // Update the version and last updated time on the resource
- IdType updatedId = theId.withVersion("123");
- thePatient.setId(updatedId);
- InstantType lastUpdated = InstantType.withCurrentTime();
- thePatient.getMeta().setLastUpdatedElement(lastUpdated);
-
- // Add the resource to the outcome, so that it can be returned by the server
- // if the client requests it
- MethodOutcome outcome = new MethodOutcome();
- outcome.setId(updatedId);
- outcome.setResource(thePatient);
- return outcome;
-}
-//END SNIPPET: updatePrefer
-
-//START SNIPPET: updateRaw
-@Update
-public MethodOutcome updatePatientWithRawValue (
- @ResourceParam Patient thePatient,
- @IdParam IdType theId,
- @ResourceParam String theRawBody,
- @ResourceParam EncodingEnum theEncodingEnum) {
-
- // Here, thePatient will have the parsed patient body, but
- // theRawBody will also have the raw text of the resource
- // being created, and theEncodingEnum will tell you which
- // encoding was used
-
- return new MethodOutcome(); // populate this
-}
-//END SNIPPET: updateRaw
-
-//START SNIPPET: update
-@Update
-public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Patient thePatient) {
-
- /*
- * First we might want to do business validation. The UnprocessableEntityException
- * results in an HTTP 422, which is appropriate for business rule failure
- */
- if (thePatient.getIdentifierFirstRep().isEmpty()) {
- /* It is also possible to pass an OperationOutcome resource
- * to the UnprocessableEntityException if you want to return
- * a custom populated OperationOutcome. Otherwise, a simple one
- * is created using the string supplied below.
- */
- throw new UnprocessableEntityException("No identifier supplied");
- }
-
- String versionId = theId.getVersionIdPart();
- if (versionId != null) {
- // If the client passed in a version number in an If-Match header, they are
- // doing a version-aware update. You may wish to throw an exception if the supplied
- // version is not the latest version. Note that as of DSTU2 the FHIR specification uses
- // ETags and If-Match to handle version aware updates, so PreconditionFailedException (HTTP 412)
- // is used instead of ResourceVersionConflictException (HTTP 409)
- if (detectedVersionConflict) {
- throw new PreconditionFailedException("Unexpected version");
- }
- }
-
- // Save this patient to the database...
- savePatientToDatabase(theId, thePatient);
-
- // This method returns a MethodOutcome object which contains
- // the ID and Version ID for the newly saved resource
- MethodOutcome retVal = new MethodOutcome();
- String newVersion = "2"; // may be null if the server is not version aware
- retVal.setId(theId.withVersion(newVersion));
-
- // You can also add an OperationOutcome resource to return
- // This part is optional though:
- OperationOutcome outcome = new OperationOutcome();
- outcome.addIssue().setDiagnostics("One minor issue detected");
- retVal.setOperationOutcome(outcome);
-
- // If your server supports creating resources during an update if they don't already exist
- // (this is not mandatory and may not be desirable anyhow) you can flag in the response
- // that this was a creation as follows:
- // retVal.setCreated(true);
-
- return retVal;
-}
-//END SNIPPET: update
-
-//START SNIPPET: updateClient
-@Update
-public abstract MethodOutcome updateSomePatient(@IdParam IdType theId, @ResourceParam Patient thePatient);
-//END SNIPPET: updateClient
-
-//START SNIPPET: validate
-@Validate
-public MethodOutcome validatePatient(@ResourceParam Patient thePatient,
- @Validate.Mode ValidationModeEnum theMode,
- @Validate.Profile String theProfile) {
-
- // Actually do our validation: The UnprocessableEntityException
- // results in an HTTP 422, which is appropriate for business rule failure
- if (thePatient.getIdentifierFirstRep().isEmpty()) {
- /* It is also possible to pass an OperationOutcome resource
- * to the UnprocessableEntityException if you want to return
- * a custom populated OperationOutcome. Otherwise, a simple one
- * is created using the string supplied below.
- */
- throw new UnprocessableEntityException("No identifier supplied");
- }
-
- // This method returns a MethodOutcome object
- MethodOutcome retVal = new MethodOutcome();
-
- // You may also add an OperationOutcome resource to return
- // This part is optional though:
- OperationOutcome outcome = new OperationOutcome();
- outcome.addIssue().setSeverity(IssueSeverity.WARNING).setDiagnostics("One minor issue detected");
- retVal.setOperationOutcome(outcome);
-
- return retVal;
-}
-//END SNIPPET: validate
-
-
-
-
-public static void main(String[] args) throws DataFormatException, IOException {
-//nothing
-}
-
-
-private void savePatientToDatabase(Patient thePatient) {
- // nothing
-}
-private void savePatientToDatabase(IdType theId, Patient thePatient) {
- // nothing
-}
-
-//START SNIPPET: metadataProvider
-public class CapabilityStatementProvider {
-
- @Metadata
- public CapabilityStatement getServerMetadata() {
- CapabilityStatement retVal = new CapabilityStatement();
- // ..populate..
- return retVal;
- }
-
-}
-//END SNIPPET: metadataProvider
-
-
-
-//START SNIPPET: metadataClient
-public interface MetadataClient extends IRestfulClient {
-
- @Metadata
- CapabilityStatement getServerMetadata();
-
- // ....Other methods can also be added as usual....
-
-}
-//END SNIPPET: metadataClient
-
-//START SNIPPET: historyClient
-public interface HistoryClient extends IBasicClient {
- /** Server level (history of ALL resources) */
- @History
- Bundle getHistoryServer();
-
- /** Type level (history of all resources of a given type) */
- @History(type=Patient.class)
- Bundle getHistoryPatientType();
-
- /** Instance level (history of a specific resource instance by type and ID) */
- @History(type=Patient.class)
- Bundle getHistoryPatientInstance(@IdParam IdType theId);
-
- /**
- * Either (or both) of the "since" and "count" paramaters can
- * also be included in any of the methods above.
- */
- @History
- Bundle getHistoryServerWithCriteria(@Since Date theDate, @Count Integer theCount);
-
-}
-//END SNIPPET: historyClient
-
-
-public void bbbbb() throws DataFormatException, IOException {
-//START SNIPPET: metadataClientUsage
-FhirContext ctx = FhirContext.forDstu2();
-MetadataClient client = ctx.newRestfulClient(MetadataClient.class, "http://spark.furore.com/fhir");
-CapabilityStatement metadata = client.getServerMetadata();
-System.out.println(ctx.newXmlParser().encodeResourceToString(metadata));
-//END SNIPPET: metadataClientUsage
-}
-
-//START SNIPPET: readTags
-@Read()
-public Patient readPatient(@IdParam IdType theId) {
- Patient retVal = new Patient();
-
- // ..populate demographics, contact, or anything else you usually would..
-
- // Populate some tags
- retVal.getMeta().addTag("http://animals", "Dog", "Canine Patient"); // TODO: more realistic example
- retVal.getMeta().addTag("http://personality", "Friendly", "Friendly"); // TODO: more realistic example
-
- return retVal;
-}
-//END SNIPPET: readTags
-
-//START SNIPPET: clientReadInterface
-private interface IPatientClient extends IBasicClient
-{
- /** Read a patient from a server by ID */
- @Read
- Patient readPatient(@IdParam IdType theId);
-
- // Only one method is shown here, but many methods may be
- // added to the same client interface!
-}
-//END SNIPPET: clientReadInterface
-
-public void clientRead() {
-//START SNIPPET: clientReadTags
-IPatientClient client = FhirContext.forDstu2().newRestfulClient(IPatientClient.class, "http://foo/fhir");
-Patient patient = client.readPatient(new IdType("1234"));
-
-// Access the tag list
-List tagList = patient.getMeta().getTag();
-for (Coding next : tagList) {
- // ..process the tags somehow..
-}
-//END SNIPPET: clientReadTags
-
-//START SNIPPET: clientCreateTags
-Patient newPatient = new Patient();
-
-// Populate the resource object
-newPatient.addIdentifier().setUse(IdentifierUse.OFFICIAL).setValue("123");
-newPatient.addName().setFamily("Jones").addGiven("Frank");
-
-// Populate some tags
-newPatient.getMeta().addTag("http://animals", "Dog", "Canine Patient"); // TODO: more realistic example
-newPatient.getMeta().addTag("http://personality", "Friendly", "Friendly"); // TODO: more realistic example
-
-// ...invoke the create method on the client...
-//END SNIPPET: clientCreateTags
-}
-
-//START SNIPPET: createTags
-@Create
-public MethodOutcome createPatientResource(@ResourceParam Patient thePatient) {
-
- // ..save the resouce..
- IdType id = new IdType("123"); // the new databse primary key for this resource
-
- // Get the tag list
- List tags = thePatient.getMeta().getTag();
- for (Coding tag : tags) {
- // process/save each tag somehow
- }
-
- return new MethodOutcome(id);
-}
-//END SNIPPET: createTags
-
-//START SNIPPET: transaction
-@Transaction
-public Bundle transaction(@TransactionParam Bundle theInput) {
- for (BundleEntryComponent nextEntry : theInput.getEntry()) {
- // Process entry
- }
-
- Bundle retVal = new Bundle();
- // Populate return bundle
- return retVal;
-}
-//END SNIPPET: transaction
-
-
-}
-
-
diff --git a/examples/src/main/java/example/SecurityInterceptors.java b/examples/src/main/java/example/SecurityInterceptors.java
deleted file mode 100644
index a2e8851fa56..00000000000
--- a/examples/src/main/java/example/SecurityInterceptors.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package example;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.codec.binary.Base64;
-
-import ca.uhn.fhir.rest.api.server.RequestDetails;
-import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
-import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
-
-public class SecurityInterceptors {
-
-// START SNIPPET: basicAuthInterceptor
-public class BasicSecurityInterceptor extends InterceptorAdapter
-{
-
- /**
- * This interceptor implements HTTP Basic Auth, which specifies that
- * a username and password are provided in a header called Authorization.
- */
- @Override
- public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
- String authHeader = theRequest.getHeader("Authorization");
-
- // The format of the header must be:
- // Authorization: Basic [base64 of username:password]
- if (authHeader == null || authHeader.startsWith("Basic ") == false) {
- throw new AuthenticationException("Missing or invalid Authorization header");
- }
-
- String base64 = authHeader.substring("Basic ".length());
- String base64decoded = new String(Base64.decodeBase64(base64));
- String[] parts = base64decoded.split("\\:");
-
- String username = parts[0];
- String password = parts[1];
-
- /*
- * Here we test for a hardcoded username & password. This is
- * not typically how you would implement this in a production
- * system of course..
- */
- if (!username.equals("someuser") || !password.equals("thepassword")) {
- throw new AuthenticationException("Invalid username or password");
- }
-
- // Return true to allow the request to proceed
- return true;
- }
-
-
-}
-//END SNIPPET: basicAuthInterceptor
-
-
-
- public void basicAuthInterceptorRealm() {
- //START SNIPPET: basicAuthInterceptorRealm
- AuthenticationException ex = new AuthenticationException();
- ex.addAuthenticateHeaderForRealm("myRealm");
- throw ex;
- //END SNIPPET: basicAuthInterceptorRealm
- }
-
-}
diff --git a/examples/src/main/java/example/ServerETagExamples.java b/examples/src/main/java/example/ServerETagExamples.java
deleted file mode 100644
index b85f42c39ad..00000000000
--- a/examples/src/main/java/example/ServerETagExamples.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package example;
-
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-
-import ca.uhn.fhir.rest.server.ETagSupportEnum;
-import ca.uhn.fhir.rest.server.RestfulServer;
-
-@SuppressWarnings("serial")
-public class ServerETagExamples {
-
- // START SNIPPET: disablingETags
- @WebServlet(urlPatterns = { "/fhir/*" }, displayName = "FHIR Server")
- public class RestfulServerWithLogging extends RestfulServer {
-
- @Override
- protected void initialize() throws ServletException {
- // ... define your resource providers here ...
-
- // ETag support is enabled by default
- setETagSupport(ETagSupportEnum.ENABLED);
- }
-
- }
- // END SNIPPET: disablingETags
-
-
-
-}
diff --git a/examples/src/main/java/example/ServerExceptionsExample.java b/examples/src/main/java/example/ServerExceptionsExample.java
deleted file mode 100644
index 7506599da7a..00000000000
--- a/examples/src/main/java/example/ServerExceptionsExample.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package example;
-
-import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
-import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.server.IResourceProvider;
-import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
-
-public abstract class ServerExceptionsExample implements IResourceProvider {
-
-private boolean databaseIsDown;
-
-//START SNIPPET: returnOO
-@Read
-public Patient read(@IdParam IdDt theId) {
- if (databaseIsDown) {
- OperationOutcome oo = new OperationOutcome();
- oo.addIssue().setSeverity(IssueSeverityEnum.FATAL).setDetails("Database is down");
- throw new InternalErrorException("Database is down", oo);
- }
-
- Patient patient = new Patient(); // populate this
- return patient;
-}
-//END SNIPPET: returnOO
-
-
-}
-
-
diff --git a/examples/src/main/java/example/ServerInterceptors.java b/examples/src/main/java/example/ServerInterceptors.java
deleted file mode 100644
index fdfc5311ba4..00000000000
--- a/examples/src/main/java/example/ServerInterceptors.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package example;
-
-import java.io.IOException;
-import java.util.List;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.api.ExtensionDt;
-import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
-import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.model.primitive.DateTimeDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.parser.DataFormatException;
-
-public class ServerInterceptors {
-
-@SuppressWarnings("unused")
-public static void main(String[] args) throws DataFormatException, IOException {
-
-
-// START SNIPPET: resourceExtension
-// Create an example patient
-Patient patient = new Patient();
-patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:example").setValue("7000135");
-
-// Create an extension
-ExtensionDt ext = new ExtensionDt();
-ext.setModifier(false);
-ext.setUrl("http://example.com/extensions#someext");
-ext.setValue(new DateTimeDt("2011-01-02T11:13:15"));
-
-// Add the extension to the resource
-patient.addUndeclaredExtension(ext);
-//END SNIPPET: resourceExtension
-
-
-//START SNIPPET: resourceStringExtension
-HumanNameDt name = patient.addName();
-name.addFamily().setValue("Shmoe");
-StringDt given = name.addGiven();
-given.setValue("Joe");
-ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#moreext", new StringDt("Hello"));
-given.addUndeclaredExtension(ext2);
-//END SNIPPET: resourceStringExtension
-
-String output = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
-System.out.println(output);
-
-
-//START SNIPPET: parseExtension
-// Get all extensions (modifier or not) for a given URL
-List resourceExts = patient.getUndeclaredExtensionsByUrl("http://fooextensions.com#exts");
-
-// Get all non-modifier extensions regardless of URL
-List nonModExts = patient.getUndeclaredExtensions();
-
-//Get all non-modifier extensions regardless of URL
-List modExts = patient.getUndeclaredModifierExtensions();
-//END SNIPPET: parseExtension
-
-}
-
-
-public void foo() {
-//START SNIPPET: subExtension
-Patient patient = new Patient();
-
-ExtensionDt parent = new ExtensionDt(false, "http://example.com#parent");
-patient.addUndeclaredExtension(parent);
-
-ExtensionDt child1 = new ExtensionDt(false, "http://example.com#childOne", new StringDt("value1"));
-parent.addUndeclaredExtension(child1);
-
-ExtensionDt child2 = new ExtensionDt(false, "http://example.com#childTwo", new StringDt("value1"));
-parent.addUndeclaredExtension(child2);
-//END SNIPPET: subExtension
-
-}
-
-}
diff --git a/examples/src/main/java/example/ServerMetadataExamples.java b/examples/src/main/java/example/ServerMetadataExamples.java
deleted file mode 100644
index 20b5e98b838..00000000000
--- a/examples/src/main/java/example/ServerMetadataExamples.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package example;
-
-import ca.uhn.fhir.model.api.Tag;
-import ca.uhn.fhir.rest.annotation.Search;
-import org.hl7.fhir.r4.model.InstantType;
-import org.hl7.fhir.r4.model.Patient;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ServerMetadataExamples {
-
- // START SNIPPET: serverMethod
- @Search
- public List getAllPatients() {
- ArrayList retVal = new ArrayList();
-
- // Create a patient to return
- Patient patient = new Patient();
- retVal.add(patient);
- patient.setId("Patient/123");
- patient.addName().setFamily("Smith").addGiven("John");
-
- // Add tags
- patient.getMeta().addTag()
- .setSystem(Tag.HL7_ORG_FHIR_TAG)
- .setCode("some_tag")
- .setDisplay("Some tag");
- patient.getMeta().addTag()
- .setSystem(Tag.HL7_ORG_FHIR_TAG)
- .setCode("another_tag")
- .setDisplay("Another tag");
-
- // Set the last updated date
- patient.getMeta().setLastUpdatedElement(new InstantType("2011-02-22T11:22:00.0122Z"));
-
- return retVal;
- }
- // END SNIPPET: serverMethod
-
-}
diff --git a/examples/src/main/java/example/ServerOperations.java b/examples/src/main/java/example/ServerOperations.java
deleted file mode 100644
index 5d978867a0a..00000000000
--- a/examples/src/main/java/example/ServerOperations.java
+++ /dev/null
@@ -1,115 +0,0 @@
-package example;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.commons.io.IOUtils;
-import org.hl7.fhir.dstu3.model.Parameters;
-
-import ca.uhn.fhir.model.dstu2.composite.CodingDt;
-import ca.uhn.fhir.model.dstu2.resource.Bundle;
-import ca.uhn.fhir.model.dstu2.resource.ConceptMap;
-import ca.uhn.fhir.model.primitive.DateDt;
-import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.model.primitive.StringDt;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.Operation;
-import ca.uhn.fhir.rest.annotation.OperationParam;
-import ca.uhn.fhir.rest.param.DateParam;
-import ca.uhn.fhir.rest.param.DateRangeParam;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.param.TokenAndListParam;
-import ca.uhn.fhir.rest.param.TokenParam;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-
-public class ServerOperations {
- private static final Logger ourLog = LoggerFactory.getLogger(ServerOperations.class);
-
-
- //START SNIPPET: manualInputAndOutput
- @Operation(name="$manualInputAndOutput", manualResponse=true, manualRequest=true)
- public void manualInputAndOutput(HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws IOException {
- String contentType = theServletRequest.getContentType();
- byte[] bytes = IOUtils.toByteArray(theServletRequest.getInputStream());
- ourLog.info("Received call with content type {} and {} bytes", contentType, bytes.length);
-
- // In a real example we might do something more interesting with the received bytes,
- // here we'll just replace them with hardcoded ones
- bytes = new byte[] { 0, 1, 2, 3 };
-
- theServletResponse.setContentType(contentType);
- theServletResponse.getOutputStream().write(bytes);
- theServletResponse.getOutputStream().close();
- }
- //END SNIPPET: manualInputAndOutput
-
-
- //START SNIPPET: searchParamBasic
- @Operation(name="$find-matches", idempotent=true)
- public Parameters findMatchesBasic(
- @OperationParam(name="date") DateParam theDate,
- @OperationParam(name="code") TokenParam theCode) {
-
- Parameters retVal = new Parameters();
- // Populate bundle with matching resources
- return retVal;
- }
- //END SNIPPET: searchParamBasic
-
- //START SNIPPET: searchParamAdvanced
- @Operation(name="$find-matches", idempotent=true)
- public Parameters findMatchesAdvanced(
- @OperationParam(name="dateRange") DateRangeParam theDate,
- @OperationParam(name="name") List theName,
- @OperationParam(name="code") TokenAndListParam theEnd) {
-
- Parameters retVal = new Parameters();
- // Populate bundle with matching resources
- return retVal;
- }
- //END SNIPPET: searchParamAdvanced
-
- //START SNIPPET: patientTypeOperation
- @Operation(name="$everything", idempotent=true)
- public Bundle patientTypeOperation(
- @OperationParam(name="start") DateDt theStart,
- @OperationParam(name="end") DateDt theEnd) {
-
- Bundle retVal = new Bundle();
- // Populate bundle with matching resources
- return retVal;
- }
- //END SNIPPET: patientTypeOperation
-
- //START SNIPPET: patientInstanceOperation
- @Operation(name="$everything", idempotent=true)
- public Bundle patientInstanceOperation(
- @IdParam IdDt thePatientId,
- @OperationParam(name="start") DateDt theStart,
- @OperationParam(name="end") DateDt theEnd) {
-
- Bundle retVal = new Bundle();
- // Populate bundle with matching resources
- return retVal;
- }
- //END SNIPPET: patientInstanceOperation
-
- //START SNIPPET: serverOperation
- @Operation(name="$closure")
- public ConceptMap closureOperation(
- @OperationParam(name="name") StringDt theStart,
- @OperationParam(name="concept") List theEnd,
- @OperationParam(name="version") IdDt theVersion) {
-
- ConceptMap retVal = new ConceptMap();
- // Populate bundle with matching resources
- return retVal;
- }
- //END SNIPPET: serverOperation
-
-}
diff --git a/examples/src/main/java/example/ServletExamples.java b/examples/src/main/java/example/ServletExamples.java
deleted file mode 100644
index 40fe909ed2f..00000000000
--- a/examples/src/main/java/example/ServletExamples.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package example;
-
-import java.util.Arrays;
-
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-
-import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator;
-import org.springframework.web.cors.CorsConfiguration;
-
-import ca.uhn.fhir.rest.server.RestfulServer;
-import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
-import ca.uhn.fhir.rest.server.interceptor.*;
-import ca.uhn.fhir.validation.ResultSeverityEnum;
-
-@SuppressWarnings("serial")
-public class ServletExamples {
-
- // START SNIPPET: loggingInterceptor
- @WebServlet(urlPatterns = { "/fhir/*" }, displayName = "FHIR Server")
- public class RestfulServerWithLogging extends RestfulServer {
-
- @Override
- protected void initialize() throws ServletException {
-
- // ... define your resource providers here ...
-
- // Now register the logging interceptor
- LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
- registerInterceptor(loggingInterceptor);
-
- // The SLF4j logger "test.accesslog" will receive the logging events
- loggingInterceptor.setLoggerName("test.accesslog");
-
- // This is the format for each line. A number of substitution variables may
- // be used here. See the JavaDoc for LoggingInterceptor for information on
- // what is available.
- loggingInterceptor.setMessageFormat("Source[${remoteAddr}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}]");
-
- }
-
- }
- // END SNIPPET: loggingInterceptor
-
- // START SNIPPET: validatingInterceptor
- @WebServlet(urlPatterns = { "/fhir/*" }, displayName = "FHIR Server")
- public class ValidatingServerWithLogging extends RestfulServer {
-
- @Override
- protected void initialize() throws ServletException {
-
- // ... define your resource providers here ...
-
- // Create an interceptor to validate incoming requests
- RequestValidatingInterceptor requestInterceptor = new RequestValidatingInterceptor();
-
- // Register a validator module (you could also use SchemaBaseValidator and/or SchematronBaseValidator)
- requestInterceptor.addValidatorModule(new FhirInstanceValidator());
-
- requestInterceptor.setFailOnSeverity(ResultSeverityEnum.ERROR);
- requestInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
- requestInterceptor.setResponseHeaderValue("Validation on ${line}: ${message} ${severity}");
- requestInterceptor.setResponseHeaderValueNoIssues("No issues detected");
-
- // Now register the validating interceptor
- registerInterceptor(requestInterceptor);
-
- // Create an interceptor to validate responses
- // This is configured in the same way as above
- ResponseValidatingInterceptor responseInterceptor = new ResponseValidatingInterceptor();
- responseInterceptor.addValidatorModule(new FhirInstanceValidator());
- responseInterceptor.setFailOnSeverity(ResultSeverityEnum.ERROR);
- responseInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
- responseInterceptor.setResponseHeaderValue("Validation on ${line}: ${message} ${severity}");
- responseInterceptor.setResponseHeaderValueNoIssues("No issues detected");
- registerInterceptor(responseInterceptor);
- }
-
- }
- // END SNIPPET: validatingInterceptor
-
- // START SNIPPET: exceptionInterceptor
- @WebServlet(urlPatterns = { "/fhir/*" }, displayName = "FHIR Server")
- public class RestfulServerWithExceptionHandling extends RestfulServer {
-
- @Override
- protected void initialize() throws ServletException {
-
- // ... define your resource providers here ...
-
- // Now register the interceptor
- ExceptionHandlingInterceptor interceptor = new ExceptionHandlingInterceptor();
- registerInterceptor(interceptor);
-
- // Return the stack trace to the client for the following exception types
- interceptor.setReturnStackTracesForExceptionTypes(InternalErrorException.class, NullPointerException.class);
-
- }
-
- }
- // END SNIPPET: exceptionInterceptor
-
- // START SNIPPET: responseHighlighterInterceptor
- @WebServlet(urlPatterns = { "/fhir/*" }, displayName = "FHIR Server")
- public class RestfulServerWithResponseHighlighter extends RestfulServer {
-
- @Override
- protected void initialize() throws ServletException {
-
- // ... define your resource providers here ...
-
- // Now register the interceptor
- ResponseHighlighterInterceptor interceptor = new ResponseHighlighterInterceptor();
- registerInterceptor(interceptor);
-
- }
-
- }
- // END SNIPPET: responseHighlighterInterceptor
-
- // START SNIPPET: corsInterceptor
- @WebServlet(urlPatterns = { "/fhir/*" }, displayName = "FHIR Server")
- public class RestfulServerWithCors extends RestfulServer {
-
- @Override
- protected void initialize() throws ServletException {
-
- // ... define your resource providers here ...
-
- // Define your CORS configuration. This is an example
- // showing a typical setup. You should customize this
- // to your specific needs
- CorsConfiguration config = new CorsConfiguration();
- config.addAllowedHeader("x-fhir-starter");
- config.addAllowedHeader("Origin");
- config.addAllowedHeader("Accept");
- config.addAllowedHeader("X-Requested-With");
- config.addAllowedHeader("Content-Type");
-
- config.addAllowedOrigin("*");
-
- config.addExposedHeader("Location");
- config.addExposedHeader("Content-Location");
- config.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
-
- // Create the interceptor and register it
- CorsInterceptor interceptor = new CorsInterceptor(config);
- registerInterceptor(interceptor);
-
- }
-
- }
- // END SNIPPET: corsInterceptor
-
-}
diff --git a/examples/src/main/java/example/TagsExamples.java b/examples/src/main/java/example/TagsExamples.java
deleted file mode 100644
index 8a6c5a19aa5..00000000000
--- a/examples/src/main/java/example/TagsExamples.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package example;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.api.*;
-import ca.uhn.fhir.model.dstu2.resource.Patient;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-
-public class TagsExamples {
-
- public static void main(String[] args) {
- new TagsExamples().getResourceTags();
- }
-
- @SuppressWarnings("unused")
- public void getResourceTags() {
- // START SNIPPET: getResourceTags
- IGenericClient client = FhirContext.forDstu2().newRestfulGenericClient("http://fhir.healthintersections.com.au/open");
- Patient p = client.read(Patient.class, "1");
-
- // Retrieve the list of tags from the resource metadata
- TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(p);
-
- // tags may be null if no tags were read in
- if (tags == null) {
- System.out.println("No tags!");
- } else {
-
- // You may iterate over all the tags
- for (Tag next : tags) {
- System.out.println(next.getScheme() + " - " + next.getTerm());
- }
-
- // You may also get a list of tags matching a given scheme
- List someTags = tags.getTagsWithScheme("http://hl7.org/fhir/tag");
-
- // Or a specific tag (by scheme and term)
- Tag specificTag = tags.getTag("http://hl7.org/fhir/tag", "http://foo");
-
- }
- // END SNIPPET: getResourceTags
- }
-
- // START SNIPPET: serverMethod
- @Search
- public List getAllPatients() {
- ArrayList retVal = new ArrayList();
-
- // Create a patient to return
- Patient patient = new Patient();
- patient.setId("Patient/123");
- patient.addName().addFamily("Smith").addGiven("John");
-
- // Create a tag list and add it to the resource
- TagList tags = new TagList();
- ResourceMetadataKeyEnum.TAG_LIST.put(patient, tags);
-
- // Add some tags to the list
- tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag1.html", "Some tag");
- tags.addTag(Tag.HL7_ORG_FHIR_TAG, "http://foo/tag2.html", "Another tag");
-
- return retVal;
- }
- // END SNIPPET: serverMethod
-
-}
diff --git a/examples/src/main/java/example/ValidateDirectory.java b/examples/src/main/java/example/ValidateDirectory.java
deleted file mode 100644
index 4c6ea0986ad..00000000000
--- a/examples/src/main/java/example/ValidateDirectory.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package example;
-
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.io.IOUtils;
-import org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport;
-import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator;
-import org.hl7.fhir.dstu3.hapi.validation.PrePopulatedValidationSupport;
-import org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain;
-import org.hl7.fhir.dstu3.model.CodeSystem;
-import org.hl7.fhir.dstu3.model.StructureDefinition;
-import org.hl7.fhir.dstu3.model.ValueSet;
-import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.parser.IParser;
-import ca.uhn.fhir.validation.FhirValidator;
-import ca.uhn.fhir.validation.ValidationResult;
-
-public class ValidateDirectory {
- private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateDirectory.class);
-
- public static void main(String[] args) throws Exception {
- // Load all profiles in this directory
- File profileDirectory = new File("/tmp/directory/with/profiles");
-
- // Validate resources in this directory
- File resourceDirectory = new File("/tmp/directory/with/resources/to/validate");
-
- FhirContext ctx = FhirContext.forDstu3();
- IParser xmlParser = ctx.newXmlParser();
- IParser jsonParser = ctx.newJsonParser();
-
- Map structureDefinitions = new HashMap();
- Map codeSystems = new HashMap();
- Map valueSets = new HashMap();
-
- // Load all profile files
- for (File nextFile : profileDirectory.listFiles()) {
-
- IBaseResource parsedRes = null;
- if (nextFile.getAbsolutePath().toLowerCase().endsWith(".xml")) {
- parsedRes = xmlParser.parseResource(new FileReader(nextFile));
- } else if (nextFile.getAbsolutePath().toLowerCase().endsWith(".json")) {
- parsedRes = jsonParser.parseResource(new FileReader(nextFile));
- } else {
- ourLog.info("Ignoring file: {}", nextFile.getName());
- }
-
- if (parsedRes instanceof StructureDefinition) {
- StructureDefinition res = (StructureDefinition) parsedRes;
- if (isNotBlank(res.getUrl())) {
- structureDefinitions.put(res.getUrl(), res);
- }
- } else if (parsedRes instanceof ValueSet) {
- ValueSet res = (ValueSet) parsedRes;
- if (isNotBlank(res.getUrl())) {
- valueSets.put(res.getUrl(), res);
- }
- } else if (parsedRes instanceof CodeSystem) {
- CodeSystem res = (CodeSystem) parsedRes;
- if (isNotBlank(res.getUrl())) {
- codeSystems.put(res.getUrl(), res);
- }
- }
- }
-
- FhirInstanceValidator instanceValidator = new FhirInstanceValidator();
-
- ValidationSupportChain validationSupportChain = new ValidationSupportChain();
- validationSupportChain.addValidationSupport(new DefaultProfileValidationSupport());
- validationSupportChain.addValidationSupport(new PrePopulatedValidationSupport(structureDefinitions, valueSets, codeSystems));
-
- instanceValidator.setValidationSupport(validationSupportChain);
-
- FhirValidator val = ctx.newValidator();
- val.registerValidatorModule(instanceValidator);
-
- // Loop through the files in the validation directory and validate each one
- for (File nextFile : resourceDirectory.listFiles()) {
-
- if (nextFile.getAbsolutePath().toLowerCase().endsWith(".xml")) {
- ourLog.info("Going to validate: {}", nextFile.getName());
- } else if (nextFile.getAbsolutePath().toLowerCase().endsWith(".json")) {
- ourLog.info("Going to validate: {}", nextFile.getName());
- } else {
- ourLog.info("Ignoring file: {}", nextFile.getName());
- continue;
- }
-
- String input = IOUtils.toString(new FileReader(nextFile));
- ValidationResult result = val.validateWithResult(input);
- IBaseOperationOutcome oo = result.toOperationOutcome();
- ourLog.info("Result:\n{}", xmlParser.setPrettyPrint(true).encodeResourceToString(oo));
- }
-
- }
-
-}
diff --git a/examples/src/main/java/example/ValidateSimple.java b/examples/src/main/java/example/ValidateSimple.java
deleted file mode 100644
index bef1e2b3912..00000000000
--- a/examples/src/main/java/example/ValidateSimple.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package example;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.validation.FhirValidator;
-import ca.uhn.fhir.validation.ValidationResult;
-import org.apache.commons.io.IOUtils;
-import org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport;
-import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator;
-import org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain;
-import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
-
-import java.io.FileReader;
-
-public class ValidateSimple {
- private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateSimple.class);
-
- public static void main(String[] args) throws Exception {
- FhirContext ctx = FhirContext.forR4();
-
- // Create a validator module
- FhirInstanceValidator instanceValidator = new FhirInstanceValidator();
-
- // We'll create a validation chain with only the DefaultProfileValidationupport registered
- ValidationSupportChain validationSupportChain = new ValidationSupportChain();
- validationSupportChain.addValidationSupport(new DefaultProfileValidationSupport());
- instanceValidator.setValidationSupport(validationSupportChain);
-
- // Create a validator and register the InstanceValidator module
- FhirValidator val = ctx.newValidator();
- val.registerValidatorModule(instanceValidator);
-
- // Read in the file and validate it
- String nextFile = args[0];
- try (FileReader fileReader = new FileReader(nextFile)) {
- String input = IOUtils.toString(fileReader);
- ValidationResult result = val.validateWithResult(input);
- IBaseOperationOutcome oo = result.toOperationOutcome();
- ourLog.info("Result:\n{}", ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(oo));
- }
-
- }
-
-}
diff --git a/examples/src/main/java/example/ValidatorExamples.java b/examples/src/main/java/example/ValidatorExamples.java
deleted file mode 100644
index 171b7088095..00000000000
--- a/examples/src/main/java/example/ValidatorExamples.java
+++ /dev/null
@@ -1,331 +0,0 @@
-package example;
-
-import java.io.File;
-import java.io.FileReader;
-import java.util.List;
-
-import javax.servlet.ServletException;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.filefilter.WildcardFileFilter;
-import org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport;
-import org.hl7.fhir.dstu3.hapi.ctx.IValidationSupport;
-import org.hl7.fhir.dstu3.hapi.validation.*;
-import org.hl7.fhir.dstu3.model.*;
-import org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem;
-import org.hl7.fhir.instance.model.api.IBaseResource;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.parser.IParser;
-import ca.uhn.fhir.parser.StrictErrorHandler;
-import ca.uhn.fhir.rest.client.api.IGenericClient;
-import ca.uhn.fhir.rest.server.RestfulServer;
-import ca.uhn.fhir.validation.*;
-import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
-
-@SuppressWarnings("serial")
-public class ValidatorExamples {
-
- public void validationIntro() {
- // START SNIPPET: validationIntro
- FhirContext ctx = FhirContext.forDstu3();
-
- // Ask the context for a validator
- FhirValidator validator = ctx.newValidator();
-
- // Create some modules and register them
- IValidatorModule module1 = new SchemaBaseValidator(ctx);
- validator.registerValidatorModule(module1);
- IValidatorModule module2 = new SchematronBaseValidator(ctx);
- validator.registerValidatorModule(module2);
-
- // Pass a resource in to be validated. The resource can
- // be an IBaseResource instance, or can be a raw String
- // containing a serialized resource as text.
- Patient resource = new Patient();
- ValidationResult result = validator.validateWithResult(resource);
- String resourceText = "";
- ValidationResult result2 = validator.validateWithResult(resourceText);
-
- // The result object now contains the validation results
- for (SingleValidationMessage next : result.getMessages()) {
- System.out.println(next.getLocationString() + " " + next.getMessage());
- }
- // END SNIPPET: validationIntro
- }
-
- // START SNIPPET: serverValidation
- public class MyRestfulServer extends RestfulServer {
-
- @Override
- protected void initialize() throws ServletException {
- // ...Configure resource providers, etc...
-
- // Create a context, set the error handler and instruct
- // the server to use it
- FhirContext ctx = FhirContext.forDstu3();
- ctx.setParserErrorHandler(new StrictErrorHandler());
- setFhirContext(ctx);
- }
-
- }
- // END SNIPPET: serverValidation
-
- @SuppressWarnings("unused")
- public void enableValidation() {
- // START SNIPPET: clientValidation
- FhirContext ctx = FhirContext.forDstu3();
-
- ctx.setParserErrorHandler(new StrictErrorHandler());
-
- // This client will have strict parser validation enabled
- IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");
- // END SNIPPET: clientValidation
-
- }
-
- public void parserValidation() {
- // START SNIPPET: parserValidation
- FhirContext ctx = FhirContext.forDstu3();
-
- // Create a parser and configure it to use the strict error handler
- IParser parser = ctx.newXmlParser();
- parser.setParserErrorHandler(new StrictErrorHandler());
-
- // This example resource is invalid, as Patient.active can not repeat
- String input = " ";
-
- // The following will throw a DataFormatException because of the StrictErrorHandler
- parser.parseResource(Patient.class, input);
- // END SNIPPET: parserValidation
- }
-
- public void validateResource() {
- // START SNIPPET: basicValidation
- // As always, you need a context
- FhirContext ctx = FhirContext.forDstu3();
-
- // Create and populate a new patient object
- Patient p = new Patient();
- p.addName().setFamily("Smith").addGiven("John").addGiven("Q");
- p.addIdentifier().setSystem("urn:foo:identifiers").setValue("12345");
- p.addTelecom().setSystem(ContactPointSystem.PHONE).setValue("416 123-4567");
-
- // Request a validator and apply it
- FhirValidator val = ctx.newValidator();
-
- // Create the Schema/Schematron modules and register them. Note that
- // you might want to consider keeping these modules around as long-term
- // objects: they parse and then store schemas, which can be an expensive
- // operation.
- IValidatorModule module1 = new SchemaBaseValidator(ctx);
- IValidatorModule module2 = new SchematronBaseValidator(ctx);
- val.registerValidatorModule(module1);
- val.registerValidatorModule(module2);
-
- ValidationResult result = val.validateWithResult(p);
- if (result.isSuccessful()) {
-
- System.out.println("Validation passed");
-
- } else {
- // We failed validation!
- System.out.println("Validation failed");
- }
-
- // The result contains a list of "messages"
- List messages = result.getMessages();
- for (SingleValidationMessage next : messages) {
- System.out.println("Message:");
- System.out.println(" * Location: " + next.getLocationString());
- System.out.println(" * Severity: " + next.getSeverity());
- System.out.println(" * Message : " + next.getMessage());
- }
-
- // You can also convert the results into an OperationOutcome resource
- OperationOutcome oo = (OperationOutcome) result.toOperationOutcome();
- String results = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(oo);
- System.out.println(results);
- // END SNIPPET: basicValidation
-
- }
-
- public static void main(String[] args) throws Exception {
- instanceValidator();
-
- }
-
- private static void instanceValidator() throws Exception {
- // START SNIPPET: instanceValidator
- FhirContext ctx = FhirContext.forDstu3();
-
- // Create a FhirInstanceValidator and register it to a validator
- FhirValidator validator = ctx.newValidator();
- FhirInstanceValidator instanceValidator = new FhirInstanceValidator();
- validator.registerValidatorModule(instanceValidator);
-
- /*
- * If you want, you can configure settings on the validator to adjust
- * its behaviour during validation
- */
- instanceValidator.setAnyExtensionsAllowed(true);
-
-
- /*
- * Let's create a resource to validate. This Observation has some fields
- * populated, but it is missing Observation.status, which is mandatory.
- */
- Observation obs = new Observation();
- obs.getCode().addCoding().setSystem("http://loinc.org").setCode("12345-6");
- obs.setValue(new StringType("This is a value"));
-
- // Validate
- ValidationResult result = validator.validateWithResult(obs);
-
- /*
- * Note: You can also explicitly declare a profile to validate against
- * using the block below.
- */
- // ValidationResult result = validator.validateWithResult(obs, new ValidationOptions().addProfile("http://myprofile.com"));
-
- // Do we have any errors or fatal errors?
- System.out.println(result.isSuccessful()); // false
-
- // Show the issues
- for (SingleValidationMessage next : result.getMessages()) {
- System.out.println(" Next issue " + next.getSeverity() + " - " + next.getLocationString() + " - " + next.getMessage());
- }
- // Prints:
- // Next issue ERROR - /f:Observation - Element '/f:Observation.status': minimum required = 1, but only found 0
- // Next issue WARNING - /f:Observation/f:code - Unable to validate code "12345-6" in code system "http://loinc.org"
-
- // You can also convert the result into an operation outcome if you
- // need to return one from a server
- OperationOutcome oo = (OperationOutcome) result.toOperationOutcome();
- // END SNIPPET: instanceValidator
- }
-
- private static void instanceValidatorCustom() throws Exception {
- // START SNIPPET: instanceValidatorCustom
- FhirContext ctx = FhirContext.forDstu3();
-
- // Create a FhirInstanceValidator and register it to a validator
- FhirValidator validator = ctx.newValidator();
- FhirInstanceValidator instanceValidator = new FhirInstanceValidator();
- validator.registerValidatorModule(instanceValidator);
-
- IValidationSupport valSupport = new IValidationSupport() {
-
- @Override
- public org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent expandValueSet(FhirContext theContext, org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent theInclude) {
- // TODO: implement
- return null;
- }
-
- @Override
- public List fetchAllConformanceResources(FhirContext theContext) {
- // TODO: implement
- return null;
- }
-
- @Override
- public List fetchAllStructureDefinitions(FhirContext theContext) {
- // TODO: implement
- return null;
- }
-
- @Override
- public CodeSystem fetchCodeSystem(FhirContext theContext, String theSystem) {
- // TODO: implement
- return null;
- }
-
- @Override
- public ValueSet fetchValueSet(FhirContext theContext, String theSystem) {
- // TODO: implement
- return null;
- }
-
- @Override
- public T fetchResource(FhirContext theContext, Class theClass, String theUri) {
- // TODO: implement
- return null;
- }
-
- @Override
- public StructureDefinition fetchStructureDefinition(FhirContext theCtx, String theUrl) {
- // TODO: implement
- return null;
- }
-
- @Override
- public boolean isCodeSystemSupported(FhirContext theContext, String theSystem) {
- // TODO: implement
- return false;
- }
-
- @Override
- public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay, String theValueSet) {
- // TODO: implement
- return null;
- }
-
- @Override
- public LookupCodeResult lookupCode(FhirContext theContext, String theSystem, String theCode) {
- // TODO: implement
- return null;
- }
-
- @Override
- public StructureDefinition generateSnapshot(StructureDefinition theInput, String theUrl, String theName) {
- // TODO: implement
- return null;
- }
- };
-
- /*
- * ValidationSupportChain strings multiple instances of IValidationSupport together. The
- * code below is useful because it means that when the validator wants to load a
- * StructureDefinition or a ValueSet, it will first use DefaultProfileValidationSupport,
- * which loads the default HL7 versions. Any StructureDefinitions which are not found in
- * the built-in set are delegated to your custom implementation.
- */
- ValidationSupportChain support = new ValidationSupportChain(new DefaultProfileValidationSupport(), valSupport);
- instanceValidator.setValidationSupport(support);
-
- // END SNIPPET: instanceValidatorCustom
- }
-
- @SuppressWarnings("unused")
- private static void validateFiles() throws Exception {
- // START SNIPPET: validateFiles
- FhirContext ctx = FhirContext.forDstu3();
-
- // Create a validator and configure it
- FhirValidator validator = ctx.newValidator();
- validator.setValidateAgainstStandardSchema(true);
- validator.setValidateAgainstStandardSchematron(true);
-
- // Get a list of files in a given directory
- String[] fileList = new File("/home/some/dir").list(new WildcardFileFilter("*.txt"));
- for (String nextFile : fileList) {
-
- // For each file, load the contents into a string
- String nextFileContents = IOUtils.toString(new FileReader(nextFile));
-
- // Parse that string (this example assumes JSON encoding)
- IBaseResource resource = ctx.newJsonParser().parseResource(nextFileContents);
-
- // Apply the validation. This will throw an exception on the first
- // validation failure
- ValidationResult result = validator.validateWithResult(resource);
- if (result.isSuccessful() == false) {
- throw new Exception("We failed!");
- }
-
- }
-
- // END SNIPPET: validateFiles
- }
-
-}
diff --git a/examples/src/main/java/example/ValidatorExamplesDstu3.java b/examples/src/main/java/example/ValidatorExamplesDstu3.java
deleted file mode 100644
index 87a13cbdfbe..00000000000
--- a/examples/src/main/java/example/ValidatorExamplesDstu3.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package example;
-
-import org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport;
-import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator;
-import org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.validation.FhirValidator;
-
-public class ValidatorExamplesDstu3 {
-
- public void validateProfileDstu3() {
- // START SNIPPET: validateFiles
-
- FhirContext ctx = FhirContext.forDstu3();
- FhirValidator validator = ctx.newValidator();
-
- // Typically if you are doing profile validation, you want to disable
- // the schema/schematron validation since the profile will specify
- // all the same rules (and more)
- validator.setValidateAgainstStandardSchema(false);
- validator.setValidateAgainstStandardSchematron(false);
-
- // FhirInstanceValidator is the validation module that handles
- // profile validation. So, create an InstanceValidator module
- // and register it to the validator.
- FhirInstanceValidator instanceVal = new FhirInstanceValidator();
- validator.registerValidatorModule(instanceVal);
-
- // FhirInstanceValidator requires an instance of "IValidationSupport" in
- // order to function. This module is used by the validator to actually obtain
- // all of the resources it needs in order to perform validation. Specifically,
- // the validator uses it to fetch StructureDefinitions, ValueSets, CodeSystems,
- // etc, as well as to perform terminology validation.
- //
- // The implementation used here (ValidationSupportChain) is allows for
- // multiple implementations to be used in a chain, where if a specific resource
- // is needed the whole chain is tried and the first module which is actually
- // able to answer is used. The first entry in the chain that we register is
- // the DefaultProfileValidationSupport, which supplies the "built-in" FHIR
- // StructureDefinitions and ValueSets
- ValidationSupportChain validationSupportChain = new ValidationSupportChain();
- validationSupportChain.addValidationSupport(new DefaultProfileValidationSupport());
- instanceVal.setValidationSupport(validationSupportChain);
-
- // END SNIPPET: validateFiles
- }
-
-}
diff --git a/examples/src/main/java/example/customtype/CustomCompositeExtension.java b/examples/src/main/java/example/customtype/CustomCompositeExtension.java
deleted file mode 100644
index 49a1ce5f5ce..00000000000
--- a/examples/src/main/java/example/customtype/CustomCompositeExtension.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package example.customtype;
-
-import org.hl7.fhir.dstu3.model.BackboneElement;
-import org.hl7.fhir.dstu3.model.Patient;
-import org.hl7.fhir.dstu3.model.StringType;
-
-import ca.uhn.fhir.model.api.annotation.Block;
-import ca.uhn.fhir.model.api.annotation.Child;
-import ca.uhn.fhir.model.api.annotation.Extension;
-import ca.uhn.fhir.model.api.annotation.ResourceDef;
-import ca.uhn.fhir.util.ElementUtil;
-
-//START SNIPPET: resource
-@ResourceDef(name = "Patient")
-public class CustomCompositeExtension extends Patient {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * A custom extension
- */
- @Child(name = "foo")
- @Extension(url="http://acme.org/fooParent", definedLocally = false, isModifier = false)
- protected FooParentExtension fooParentExtension;
-
- public FooParentExtension getFooParentExtension() {
- return fooParentExtension;
- }
-
- @Override
- public boolean isEmpty() {
- return super.isEmpty() && ElementUtil.isEmpty(fooParentExtension);
- }
-
- public void setFooParentExtension(FooParentExtension theFooParentExtension) {
- fooParentExtension = theFooParentExtension;
- }
-
- @Block
- public static class FooParentExtension extends BackboneElement {
-
- private static final long serialVersionUID = 4522090347756045145L;
-
- @Child(name = "childA")
- @Extension(url = "http://acme.org/fooChildA", definedLocally = false, isModifier = false)
- private StringType myChildA;
-
- @Child(name = "childB")
- @Extension(url = "http://acme.org/fooChildB", definedLocally = false, isModifier = false)
- private StringType myChildB;
-
- @Override
- public FooParentExtension copy() {
- FooParentExtension copy = new FooParentExtension();
- copy.myChildA = myChildA;
- copy.myChildB = myChildB;
- return copy;
- }
-
- @Override
- public boolean isEmpty() {
- return super.isEmpty() && ElementUtil.isEmpty(myChildA, myChildB);
- }
-
- public StringType getChildA() {
- return myChildA;
- }
-
- public StringType getChildB() {
- return myChildB;
- }
-
- public void setChildA(StringType theChildA) {
- myChildA = theChildA;
- }
-
- public void setChildB(StringType theChildB) {
- myChildB = theChildB;
- }
-
- }
-
-}
-//END SNIPPET: resource
diff --git a/examples/src/main/java/example/customtype/CustomDatatype.java b/examples/src/main/java/example/customtype/CustomDatatype.java
deleted file mode 100644
index fc3ecbc0720..00000000000
--- a/examples/src/main/java/example/customtype/CustomDatatype.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package example.customtype;
-
-//START SNIPPET: datatype
-import org.hl7.fhir.dstu3.model.DateTimeType;
-import org.hl7.fhir.dstu3.model.StringType;
-import org.hl7.fhir.dstu3.model.Type;
-import org.hl7.fhir.instance.model.api.ICompositeType;
-
-import ca.uhn.fhir.model.api.annotation.Child;
-import ca.uhn.fhir.model.api.annotation.DatatypeDef;
-import ca.uhn.fhir.util.ElementUtil;
-
-/**
- * This is an example of a custom datatype.
- *
- * This is an STU3 example so it extends Type and implements ICompositeType. For
- * DSTU2 it would extend BaseIdentifiableElement and implement ICompositeDatatype.
- */
-@DatatypeDef(name="CustomDatatype")
-public class CustomDatatype extends Type implements ICompositeType {
-
- private static final long serialVersionUID = 1L;
-
- @Child(name = "date", order = 0, min = 1, max = 1)
- private DateTimeType myDate;
-
- @Child(name = "kittens", order = 1, min = 1, max = 1)
- private StringType myKittens;
-
- public DateTimeType getDate() {
- if (myDate == null)
- myDate = new DateTimeType();
- return myDate;
- }
-
- public StringType getKittens() {
- return myKittens;
- }
-
- @Override
- public boolean isEmpty() {
- return ElementUtil.isEmpty(myDate, myKittens);
- }
-
- public CustomDatatype setDate(DateTimeType theValue) {
- myDate = theValue;
- return this;
- }
-
- public CustomDatatype setKittens(StringType theKittens) {
- myKittens = theKittens;
- return this;
- }
-
- @Override
- protected CustomDatatype typedCopy() {
- CustomDatatype retVal = new CustomDatatype();
- super.copyValues(retVal);
- retVal.myDate = myDate;
- return retVal;
- }
-}
-//END SNIPPET: datatype
\ No newline at end of file
diff --git a/examples/src/main/java/example/customtype/CustomResource.java b/examples/src/main/java/example/customtype/CustomResource.java
deleted file mode 100644
index 3e1862c5b4a..00000000000
--- a/examples/src/main/java/example/customtype/CustomResource.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package example.customtype;
-
-// START SNIPPET: resource
-import java.util.ArrayList;
-import java.util.List;
-
-import org.hl7.fhir.dstu3.model.DomainResource;
-import org.hl7.fhir.dstu3.model.ResourceType;
-import org.hl7.fhir.dstu3.model.StringType;
-import org.hl7.fhir.dstu3.model.Type;
-
-import ca.uhn.fhir.context.FhirVersionEnum;
-import ca.uhn.fhir.model.api.annotation.Child;
-import ca.uhn.fhir.model.api.annotation.ResourceDef;
-import ca.uhn.fhir.util.ElementUtil;
-
-/**
- * This is an example of a custom resource that also uses a custom
- * datatype.
- *
- * Note that we are extensing DomainResource for an STU3
- * resource. For DSTU2 it would be BaseResource.
- */
-@ResourceDef(name = "CustomResource", profile = "http://hl7.org/fhir/profiles/custom-resource")
-public class CustomResource extends DomainResource {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * We give the resource a field with name "television". This field has no
- * specific type, so it's a choice[x] field for any type.
- */
- @Child(name="television", min=1, max=Child.MAX_UNLIMITED, order=0)
- private List myTelevision;
-
- /**
- * We'll give it one more field called "dogs"
- */
- @Child(name = "dogs", min=0, max=1, order=1)
- private StringType myDogs;
-
- @Override
- public CustomResource copy() {
- CustomResource retVal = new CustomResource();
- super.copyValues(retVal);
- retVal.myTelevision = myTelevision;
- retVal.myDogs = myDogs;
- return retVal;
- }
-
- public List getTelevision() {
- if (myTelevision == null) {
- myTelevision = new ArrayList();
- }
- return myTelevision;
- }
-
- public StringType getDogs() {
- return myDogs;
- }
-
- @Override
- public ResourceType getResourceType() {
- return null;
- }
-
- @Override
- public FhirVersionEnum getStructureFhirVersionEnum() {
- return FhirVersionEnum.DSTU3;
- }
-
- @Override
- public boolean isEmpty() {
- return ElementUtil.isEmpty(myTelevision, myDogs);
- }
-
- public void setTelevision(List theValue) {
- this.myTelevision = theValue;
- }
-
- public void setDogs(StringType theDogs) {
- myDogs = theDogs;
- }
-
-}
-// END SNIPPET: resource
diff --git a/examples/src/main/java/example/customtype/CustomUsage.java b/examples/src/main/java/example/customtype/CustomUsage.java
deleted file mode 100644
index a823aea607f..00000000000
--- a/examples/src/main/java/example/customtype/CustomUsage.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package example.customtype;
-
-import java.util.Date;
-
-import org.hl7.fhir.dstu3.model.DateTimeType;
-import org.hl7.fhir.dstu3.model.DateType;
-import org.hl7.fhir.dstu3.model.StringType;
-
-import ca.uhn.fhir.context.FhirContext;
-
-public class CustomUsage {
-
- public static void main(String[] args) {
-
- // START SNIPPET: usage
- // Create a context. Note that we declare the custom types we'll be using
- // on the context before actually using them
- FhirContext ctx = FhirContext.forDstu3();
- ctx.registerCustomType(CustomResource.class);
- ctx.registerCustomType(CustomDatatype.class);
-
- // Now let's create an instance of our custom resource type
- // and populate it with some data
- CustomResource res = new CustomResource();
-
- // Add some values, including our custom datatype
- DateType value0 = new DateType("2015-01-01");
- res.getTelevision().add(value0);
-
- CustomDatatype value1 = new CustomDatatype();
- value1.setDate(new DateTimeType(new Date()));
- value1.setKittens(new StringType("FOO"));
- res.getTelevision().add(value1);
-
- res.setDogs(new StringType("Some Dogs"));
-
- // Now let's serialize our instance
- String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(res);
- System.out.println(output);
- // END SNIPPET: usage
-
- }
-
-}
diff --git a/examples/src/main/java/example/interceptor/MyTestInterceptor.java b/examples/src/main/java/example/interceptor/MyTestInterceptor.java
deleted file mode 100644
index bd62ea36b64..00000000000
--- a/examples/src/main/java/example/interceptor/MyTestInterceptor.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package example.interceptor;
-
-import ca.uhn.fhir.interceptor.api.Hook;
-import ca.uhn.fhir.interceptor.api.Interceptor;
-import ca.uhn.fhir.interceptor.api.Pointcut;
-import ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription;
-import ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceDeliveryMessage;
-
-/**
- * Interceptor class
- */
-@Interceptor
-public class MyTestInterceptor {
-
- @Hook(Pointcut.SUBSCRIPTION_BEFORE_REST_HOOK_DELIVERY)
- public boolean beforeRestHookDelivery(ResourceDeliveryMessage theDeliveryMessage, CanonicalSubscription theSubscription) {
-
- String header = "Authorization: Bearer 1234567";
-
- theSubscription.addHeader(header);
-
- return true;
- }
-
-}
diff --git a/examples/src/main/java/logback.xml b/examples/src/main/java/logback.xml
deleted file mode 100644
index 1c8de9da344..00000000000
--- a/examples/src/main/java/logback.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
- INFO
-
-
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] %msg%n
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/hapi-deployable-pom/pom.xml b/hapi-deployable-pom/pom.xml
index cfbbacddefa..599b8fe0ee4 100644
--- a/hapi-deployable-pom/pom.xml
+++ b/hapi-deployable-pom/pom.xml
@@ -4,7 +4,7 @@
ca.uhn.hapi.fhir
hapi-fhir
- 4.3.0-SNAPSHOT
+ 5.0.0-SNAPSHOT
../pom.xml
@@ -181,7 +181,16 @@
- http://jamesagnew.github.io/hapi-fhir/apidocs/
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-base
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-dstu2
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-dstu3
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-r4
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-r5
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-client
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-server
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-jpaserver-base
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-converter
+ https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-validation
https://docs.oracle.com/javaee/7/api/
-Xdoclint:none
diff --git a/hapi-fhir-android/pom.xml b/hapi-fhir-android/pom.xml
index 129477c4a80..363a68022b2 100644
--- a/hapi-fhir-android/pom.xml
+++ b/hapi-fhir-android/pom.xml
@@ -5,7 +5,7 @@
ca.uhn.hapi.fhir
hapi-deployable-pom
- 4.3.0-SNAPSHOT
+ 5.0.0-SNAPSHOT
../hapi-deployable-pom/pom.xml
diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml
index eb562662816..6e01dce40bc 100644
--- a/hapi-fhir-base/pom.xml
+++ b/hapi-fhir-base/pom.xml
@@ -5,7 +5,7 @@
ca.uhn.hapi.fhir
hapi-deployable-pom
- 4.3.0-SNAPSHOT
+ 5.0.0-SNAPSHOT
../hapi-deployable-pom/pom.xml
@@ -20,8 +20,8 @@
- com.google.code.gson
- gson
+ com.fasterxml.jackson.core
+ jackson-databind
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java
index 90e4a50ac91..fbe2fc502dc 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeElementDefinition.java
@@ -22,8 +22,11 @@ package ca.uhn.fhir.context;
import ca.uhn.fhir.util.UrlUtil;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.util.*;
@@ -33,11 +36,11 @@ public abstract class BaseRuntimeElementDefinition {
private final Class extends T> myImplementingClass;
private final String myName;
private final boolean myStandardType;
- private Map, Constructor> myConstructors = Collections.synchronizedMap(new HashMap, Constructor>());
- private List myExtensions = new ArrayList();
- private List myExtensionsModifier = new ArrayList();
- private List myExtensionsNonModifier = new ArrayList();
- private Map myUrlToExtension = new HashMap();
+ private Map, Constructor> myConstructors = Collections.synchronizedMap(new HashMap<>());
+ private List myExtensions = new ArrayList<>();
+ private List myExtensionsModifier = new ArrayList<>();
+ private List myExtensionsNonModifier = new ArrayList<>();
+ private Map myUrlToExtension = new HashMap<>();
private BaseRuntimeElementDefinition> myRootParentDefinition;
public BaseRuntimeElementDefinition(String theName, Class extends T> theImplementingClass, boolean theStandardType) {
@@ -56,19 +59,17 @@ public abstract class BaseRuntimeElementDefinition {
myImplementingClass = theImplementingClass;
}
- public void addExtension(RuntimeChildDeclaredExtensionDefinition theExtension) {
- if (theExtension == null) {
- throw new NullPointerException();
- }
+ public void addExtension(@Nonnull RuntimeChildDeclaredExtensionDefinition theExtension) {
+ Validate.notNull(theExtension, "theExtension must not be null");
myExtensions.add(theExtension);
}
public abstract ChildTypeEnum getChildType();
@SuppressWarnings("unchecked")
- private Constructor getConstructor(Object theArgument) {
+ private Constructor getConstructor(@Nullable Object theArgument) {
- Class extends Object> argumentType;
+ Class> argumentType;
if (theArgument == null) {
argumentType = VOID_CLASS;
} else {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java
index c938e30761c..7458be5edca 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java
@@ -1,15 +1,22 @@
package ca.uhn.fhir.context;
import ca.uhn.fhir.context.api.AddProfileTagEnum;
-import ca.uhn.fhir.context.support.IContextValidationSupport;
-import ca.uhn.fhir.fluentpath.IFluentPath;
+import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
+import ca.uhn.fhir.context.support.IValidationSupport;
+import ca.uhn.fhir.fhirpath.IFhirPath;
import ca.uhn.fhir.i18n.HapiLocalizer;
import ca.uhn.fhir.model.api.IElement;
import ca.uhn.fhir.model.api.IFhirVersion;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.view.ViewGenerator;
import ca.uhn.fhir.narrative.INarrativeGenerator;
-import ca.uhn.fhir.parser.*;
+import ca.uhn.fhir.parser.DataFormatException;
+import ca.uhn.fhir.parser.IParser;
+import ca.uhn.fhir.parser.IParserErrorHandler;
+import ca.uhn.fhir.parser.JsonParser;
+import ca.uhn.fhir.parser.LenientErrorHandler;
+import ca.uhn.fhir.parser.RDFParser;
+import ca.uhn.fhir.parser.XmlParser;
import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
import ca.uhn.fhir.rest.client.api.IBasicClient;
import ca.uhn.fhir.rest.client.api.IGenericClient;
@@ -20,7 +27,6 @@ import ca.uhn.fhir.util.ReflectionUtil;
import ca.uhn.fhir.util.VersionUtil;
import ca.uhn.fhir.validation.FhirValidator;
import org.apache.commons.lang3.Validate;
-import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.jena.riot.Lang;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseBundle;
@@ -97,7 +103,7 @@ public class FhirContext {
private Collection> myResourceTypesToScan;
private volatile IRestfulClientFactory myRestfulClientFactory;
private volatile RuntimeChildUndeclaredExtensionDefinition myRuntimeChildUndeclaredExtensionDefinition;
- private IContextValidationSupport, ?, ?, ?, ?, ?> myValidationSupport;
+ private IValidationSupport myValidationSupport;
private Map>> myVersionToNameToResourceType = Collections.emptyMap();
/**
@@ -371,15 +377,27 @@ public class FhirContext {
}
}
+ /**
+ * Sets the configured performance options
+ *
+ * @see PerformanceOptionsEnum for a list of available options
+ */
+ public void setPerformanceOptions(final PerformanceOptionsEnum... thePerformanceOptions) {
+ Collection asList = null;
+ if (thePerformanceOptions != null) {
+ asList = Arrays.asList(thePerformanceOptions);
+ }
+ setPerformanceOptions(asList);
+ }
+
/**
* Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed
* for extending the core library.
*/
public RuntimeResourceDefinition getResourceDefinition(final Class extends IBaseResource> theResourceType) {
validateInitialized();
- if (theResourceType == null) {
- throw new NullPointerException("theResourceType can not be null");
- }
+ Validate.notNull(theResourceType, "theResourceType can not be null");
+
if (Modifier.isAbstract(theResourceType.getModifiers())) {
throw new IllegalArgumentException("Can not scan abstract or interface class (resource definitions must be concrete classes): " + theResourceType.getName());
}
@@ -544,16 +562,37 @@ public class FhirContext {
/**
* Returns the validation support module configured for this context, creating a default
- * implementation if no module has been passed in via the {@link #setValidationSupport(IContextValidationSupport)}
+ * implementation if no module has been passed in via the {@link #setValidationSupport(IValidationSupport)}
* method
*
- * @see #setValidationSupport(IContextValidationSupport)
+ * @see #setValidationSupport(IValidationSupport)
*/
- public IContextValidationSupport, ?, ?, ?, ?, ?> getValidationSupport() {
- if (myValidationSupport == null) {
- myValidationSupport = myVersion.createValidationSupport();
+ public IValidationSupport getValidationSupport() {
+ IValidationSupport retVal = myValidationSupport;
+ if (retVal == null) {
+ retVal = new DefaultProfileValidationSupport(this);
+
+ /*
+ * If hapi-fhir-validation is on the classpath, we can create a much more robust
+ * validation chain using the classes found in that package
+ */
+ String inMemoryTermSvcType = "org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport";
+ String commonCodeSystemsSupportType = "org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService";
+ if (ReflectionUtil.typeExists(inMemoryTermSvcType)) {
+ IValidationSupport inMemoryTermSvc = ReflectionUtil.newInstanceOrReturnNull(inMemoryTermSvcType, IValidationSupport.class, new Class>[]{FhirContext.class}, new Object[]{this});
+ IValidationSupport commonCodeSystemsSupport = ReflectionUtil.newInstanceOrReturnNull(commonCodeSystemsSupportType, IValidationSupport.class, new Class>[]{FhirContext.class}, new Object[]{this});
+ retVal = ReflectionUtil.newInstanceOrReturnNull("org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain", IValidationSupport.class, new Class>[]{IValidationSupport[].class}, new Object[]{new IValidationSupport[]{
+ retVal,
+ inMemoryTermSvc,
+ commonCodeSystemsSupport
+ }});
+ assert retVal != null : "Failed to instantiate " + "org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain";
+ }
+
+
+ myValidationSupport = retVal;
}
- return myValidationSupport;
+ return retVal;
}
/**
@@ -561,7 +600,7 @@ public class FhirContext {
* is used to supply underlying infrastructure such as conformance resources (StructureDefinition, ValueSet, etc)
* as well as to provide terminology services to modules such as the validator and FluentPath executor
*/
- public void setValidationSupport(IContextValidationSupport, ?, ?, ?, ?, ?> theValidationSupport) {
+ public void setValidationSupport(IValidationSupport theValidationSupport) {
myValidationSupport = theValidationSupport;
}
@@ -586,12 +625,21 @@ public class FhirContext {
}
/**
- * Creates a new FluentPath engine which can be used to exvaluate
+ * @since 2.2
+ * @deprecated Deprecated in HAPI FHIR 5.0.0. Use {@link #newFhirPath()} instead.
+ */
+ @Deprecated
+ public IFhirPath newFluentPath() {
+ return newFhirPath();
+ }
+
+ /**
+ * Creates a new FhirPath engine which can be used to evaluate
* path expressions over FHIR resources. Note that this engine will use the
- * {@link IContextValidationSupport context validation support} module which is
+ * {@link IValidationSupport context validation support} module which is
* configured on the context at the time this method is called.
*
- * In other words, call {@link #setValidationSupport(IContextValidationSupport)} before
+ * In other words, you may wish to call {@link #setValidationSupport(IValidationSupport)} before
* calling {@link #newFluentPath()}
*
*
@@ -601,10 +649,10 @@ public class FhirContext {
* {@link UnsupportedOperationException}
*
*
- * @since 2.2
+ * @since 5.0.0
*/
- public IFluentPath newFluentPath() {
- return myVersion.createFluentPathExecutor(this);
+ public IFhirPath newFhirPath() {
+ return myVersion.createFhirPathExecutor(this);
}
/**
@@ -642,13 +690,12 @@ public class FhirContext {
return new RDFParser(this, myParserErrorHandler, Lang.TURTLE);
}
-
/**
* Instantiates a new client instance. This method requires an interface which is defined specifically for your use
* cases to contain methods for each of the RESTful operations you wish to implement (e.g. "read ImagingStudy",
* "search Patient by identifier", etc.). This interface must extend {@link IRestfulClient} (or commonly its
* sub-interface {@link IBasicClient}). See the RESTful Client documentation for more
+ * href="https://hapifhir.io/hapi-fhir/docs/client/introduction.html">RESTful Client documentation for more
* information on how to define this interface.
*
*
@@ -862,19 +909,6 @@ public class FhirContext {
myParserErrorHandler = theParserErrorHandler;
}
- /**
- * Sets the configured performance options
- *
- * @see PerformanceOptionsEnum for a list of available options
- */
- public void setPerformanceOptions(final PerformanceOptionsEnum... thePerformanceOptions) {
- Collection asList = null;
- if (thePerformanceOptions != null) {
- asList = Arrays.asList(thePerformanceOptions);
- }
- setPerformanceOptions(asList);
- }
-
@SuppressWarnings({"cast"})
private List> toElementList(final Collection> theResourceTypes) {
if (theResourceTypes == null) {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/ConceptValidationOptions.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/ConceptValidationOptions.java
new file mode 100644
index 00000000000..7d1d3f2d135
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/ConceptValidationOptions.java
@@ -0,0 +1,36 @@
+package ca.uhn.fhir.context.support;
+
+/*-
+ * #%L
+ * HAPI FHIR - Core Library
+ * %%
+ * Copyright (C) 2014 - 2020 University Health Network
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+
+public class ConceptValidationOptions {
+
+ public boolean isInferSystem() {
+ return myInferSystem;
+ }
+
+ public ConceptValidationOptions setInferSystem(boolean theInferSystem) {
+ myInferSystem = theInferSystem;
+ return this;
+ }
+
+ private boolean myInferSystem;
+
+}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java
new file mode 100644
index 00000000000..3498ac29df0
--- /dev/null
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/DefaultProfileValidationSupport.java
@@ -0,0 +1,354 @@
+package ca.uhn.fhir.context.support;
+
+/*-
+ * #%L
+ * HAPI FHIR - Core Library
+ * %%
+ * Copyright (C) 2014 - 2020 University Health Network
+ * %%
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * #L%
+ */
+
+import ca.uhn.fhir.context.ConfigurationException;
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.context.RuntimeResourceDefinition;
+import ca.uhn.fhir.rest.api.Constants;
+import ca.uhn.fhir.util.BundleUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.hl7.fhir.instance.model.api.IBase;
+import org.hl7.fhir.instance.model.api.IBaseBundle;
+import org.hl7.fhir.instance.model.api.IBaseResource;
+import org.hl7.fhir.instance.model.api.IPrimitiveType;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+
+import static org.apache.commons.lang3.StringUtils.isNotBlank;
+
+public class DefaultProfileValidationSupport implements IValidationSupport {
+
+ private static final String URL_PREFIX_STRUCTURE_DEFINITION = "http://hl7.org/fhir/StructureDefinition/";
+ private static final String URL_PREFIX_STRUCTURE_DEFINITION_BASE = "http://hl7.org/fhir/";
+ private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultProfileValidationSupport.class);
+ private final FhirContext myCtx;
+
+ private Map myCodeSystems;
+ private Map myStructureDefinitions;
+ private Map myValueSets;
+ private List myTerminologyResources;
+ private List myStructureDefinitionResources;
+
+ /**
+ * Constructor
+ *
+ * @param theFhirContext The context to use
+ */
+ public DefaultProfileValidationSupport(FhirContext theFhirContext) {
+ myCtx = theFhirContext;
+ }
+
+
+ private void initializeResourceLists() {
+
+ if (myTerminologyResources != null && myStructureDefinitionResources != null) {
+ return;
+ }
+
+ List terminologyResources = new ArrayList<>();
+ List structureDefinitionResources = new ArrayList<>();
+ switch (getFhirContext().getVersion().getVersion()) {
+ case DSTU2:
+ case DSTU2_HL7ORG:
+ terminologyResources.add("/org/hl7/fhir/instance/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/instance/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/instance/model/valueset/v3-codesystems.xml");
+ Properties profileNameProperties = new Properties();
+ try {
+ profileNameProperties.load(DefaultProfileValidationSupport.class.getResourceAsStream("/org/hl7/fhir/instance/model/profile/profiles.properties"));
+ for (Object nextKey : profileNameProperties.keySet()) {
+ structureDefinitionResources.add("/org/hl7/fhir/instance/model/profile/" + nextKey);
+ }
+ } catch (IOException e) {
+ throw new ConfigurationException(e);
+ }
+ break;
+ case DSTU2_1:
+ terminologyResources.add("/org/hl7/fhir/dstu2016may/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu2016may/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu2016may/model/valueset/v3-codesystems.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu2016may/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu2016may/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu2016may/model/profile/profiles-others.xml");
+ break;
+ case DSTU3:
+ terminologyResources.add("/org/hl7/fhir/dstu3/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu3/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/dstu3/model/valueset/v3-codesystems.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/profile/profiles-others.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/dstu3/model/extension/extension-definitions.xml");
+ break;
+ case R4:
+ terminologyResources.add("/org/hl7/fhir/r4/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/r4/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/r4/model/valueset/v3-codesystems.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/profile/profiles-others.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r4/model/extension/extension-definitions.xml");
+ break;
+ case R5:
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/profile/profiles-resources.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/profile/profiles-types.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/profile/profiles-others.xml");
+ structureDefinitionResources.add("/org/hl7/fhir/r5/model/extension/extension-definitions.xml");
+ terminologyResources.add("/org/hl7/fhir/r5/model/valueset/valuesets.xml");
+ terminologyResources.add("/org/hl7/fhir/r5/model/valueset/v2-tables.xml");
+ terminologyResources.add("/org/hl7/fhir/r5/model/valueset/v3-codesystems.xml");
+ break;
+ }
+
+ myTerminologyResources = terminologyResources;
+ myStructureDefinitionResources = structureDefinitionResources;
+ }
+
+
+ @Override
+ public List fetchAllConformanceResources() {
+ ArrayList retVal = new ArrayList<>();
+ retVal.addAll(myCodeSystems.values());
+ retVal.addAll(myStructureDefinitions.values());
+ retVal.addAll(myValueSets.values());
+ return retVal;
+ }
+
+ @Override
+ public List fetchAllStructureDefinitions() {
+ return toList(provideStructureDefinitionMap());
+ }
+
+
+ @Override
+ public IBaseResource fetchCodeSystem(String theSystem) {
+ return fetchCodeSystemOrValueSet(theSystem, true);
+ }
+
+ private IBaseResource fetchCodeSystemOrValueSet(String theSystem, boolean codeSystem) {
+ synchronized (this) {
+ Map codeSystems = myCodeSystems;
+ Map valueSets = myValueSets;
+ if (codeSystems == null || valueSets == null) {
+ codeSystems = new HashMap<>();
+ valueSets = new HashMap<>();
+
+ initializeResourceLists();
+ for (String next : myTerminologyResources) {
+ loadCodeSystems(codeSystems, valueSets, next);
+ }
+
+ myCodeSystems = codeSystems;
+ myValueSets = valueSets;
+ }
+
+ // System can take the form "http://url|version"
+ String system = theSystem;
+ if (system.contains("|")) {
+ String version = system.substring(system.indexOf('|') + 1);
+ if (version.matches("^[0-9.]+$")) {
+ system = system.substring(0, system.indexOf('|'));
+ }
+ }
+
+ if (codeSystem) {
+ return codeSystems.get(system);
+ } else {
+ return valueSets.get(system);
+ }
+ }
+ }
+
+ @Override
+ public IBaseResource fetchStructureDefinition(String theUrl) {
+ String url = theUrl;
+ if (url.startsWith(URL_PREFIX_STRUCTURE_DEFINITION)) {
+ // no change
+ } else if (url.indexOf('/') == -1) {
+ url = URL_PREFIX_STRUCTURE_DEFINITION + url;
+ } else if (StringUtils.countMatches(url, '/') == 1) {
+ url = URL_PREFIX_STRUCTURE_DEFINITION_BASE + url;
+ }
+ Map structureDefinitionMap = provideStructureDefinitionMap();
+ IBaseResource retVal = structureDefinitionMap.get(url);
+ return retVal;
+ }
+
+ @Override
+ public IBaseResource fetchValueSet(String theUrl) {
+ IBaseResource retVal = fetchCodeSystemOrValueSet(theUrl, false);
+ return retVal;
+ }
+
+ public void flush() {
+ myCodeSystems = null;
+ myStructureDefinitions = null;
+ }
+
+ @Override
+ public FhirContext getFhirContext() {
+ return myCtx;
+ }
+
+ private Map provideStructureDefinitionMap() {
+ Map structureDefinitions = myStructureDefinitions;
+ if (structureDefinitions == null) {
+ structureDefinitions = new HashMap<>();
+
+ initializeResourceLists();
+ for (String next : myStructureDefinitionResources) {
+ loadStructureDefinitions(structureDefinitions, next);
+ }
+
+ myStructureDefinitions = structureDefinitions;
+ }
+ return structureDefinitions;
+ }
+
+ private void loadCodeSystems(Map theCodeSystems, Map theValueSets, String theClasspath) {
+ ourLog.info("Loading CodeSystem/ValueSet from classpath: {}", theClasspath);
+ InputStream inputStream = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath);
+ InputStreamReader reader = null;
+ if (inputStream != null) {
+ try {
+ reader = new InputStreamReader(inputStream, Constants.CHARSET_UTF8);
+ List resources = parseBundle(reader);
+ for (IBaseResource next : resources) {
+
+ RuntimeResourceDefinition nextDef = getFhirContext().getResourceDefinition(next);
+ Map map = null;
+ switch (nextDef.getName()) {
+ case "CodeSystem":
+ map = theCodeSystems;
+ break;
+ case "ValueSet":
+ map = theValueSets;
+ break;
+ }
+
+ if (map != null) {
+ String urlValueString = getConformanceResourceUrl(next);
+ if (isNotBlank(urlValueString)) {
+ map.put(urlValueString, next);
+ }
+
+ switch (myCtx.getVersion().getVersion()) {
+ case DSTU2:
+ case DSTU2_HL7ORG:
+
+ IPrimitiveType> codeSystem = myCtx.newTerser().getSingleValueOrNull(next, "ValueSet.codeSystem.system", IPrimitiveType.class);
+ if (codeSystem != null && isNotBlank(codeSystem.getValueAsString())) {
+ theCodeSystems.put(codeSystem.getValueAsString(), next);
+ }
+
+ break;
+
+ default:
+ case DSTU2_1:
+ case DSTU3:
+ case R4:
+ case R5:
+ break;
+ }
+ }
+
+
+ }
+ } finally {
+ try {
+ if (reader != null) {
+ reader.close();
+ }
+ inputStream.close();
+ } catch (IOException e) {
+ ourLog.warn("Failure closing stream", e);
+ }
+ }
+ } else {
+ ourLog.warn("Unable to load resource: {}", theClasspath);
+ }
+ }
+
+ private void loadStructureDefinitions(Map theCodeSystems, String theClasspath) {
+ ourLog.info("Loading structure definitions from classpath: {}", theClasspath);
+ try (InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath)) {
+ if (valuesetText != null) {
+ try (InputStreamReader reader = new InputStreamReader(valuesetText, Constants.CHARSET_UTF8)) {
+
+ List resources = parseBundle(reader);
+ for (IBaseResource next : resources) {
+
+ String nextType = getFhirContext().getResourceDefinition(next).getName();
+ if ("StructureDefinition".equals(nextType)) {
+
+ String url = getConformanceResourceUrl(next);
+ if (isNotBlank(url)) {
+ theCodeSystems.put(url, next);
+ }
+
+ }
+
+ }
+ }
+ } else {
+ ourLog.warn("Unable to load resource: {}", theClasspath);
+ }
+ } catch (IOException theE) {
+ ourLog.warn("Unable to load resource: {}", theClasspath);
+ }
+ }
+
+ private String getConformanceResourceUrl(IBaseResource theResource) {
+ String urlValueString = null;
+ Optional urlValue = getFhirContext().getResourceDefinition(theResource).getChildByName("url").getAccessor().getFirstValueOrNull(theResource);
+ if (urlValue.isPresent()) {
+ IPrimitiveType> urlValueType = (IPrimitiveType>) urlValue.get();
+ urlValueString = urlValueType.getValueAsString();
+ }
+ return urlValueString;
+ }
+
+ private List parseBundle(InputStreamReader theReader) {
+ IBaseResource parsedObject = getFhirContext().newXmlParser().parseResource(theReader);
+ if (parsedObject instanceof IBaseBundle) {
+ IBaseBundle bundle = (IBaseBundle) parsedObject;
+ return BundleUtil.toListOfResources(getFhirContext(), bundle);
+ } else {
+ return Collections.singletonList(parsedObject);
+ }
+ }
+
+ static List toList(Map theMap) {
+ ArrayList retVal = new ArrayList<>(theMap.values());
+ return (List) Collections.unmodifiableList(retVal);
+ }
+
+}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IContextValidationSupport.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java
similarity index 50%
rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IContextValidationSupport.java
rename to hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java
index d0fb1bca555..fc5089e2163 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IContextValidationSupport.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/support/IValidationSupport.java
@@ -23,12 +23,14 @@ package ca.uhn.fhir.context.support;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.ParametersUtil;
+import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -42,33 +44,63 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
* various functions that can be provided by validation and terminology
* services.
*
+ * This interface is invoked directly by internal parts of the HAPI FHIR API, including the
+ * Validator and the FHIRPath evaluator. It is used to supply artifacts required for validation
+ * (e.g. StructureDefinition resources, ValueSet resources, etc.) and also to provide
+ * terminology functions such as code validation, ValueSet expansion, etc.
+ *
+ *
* Implementations are not required to implement all of the functions
* in this interface; in fact it is expected that most won't. Any
* methods which are not implemented may simply return null
- * and calling code is expected to be able to handle this.
+ * and calling code is expected to be able to handle this. Generally, a
+ * series of implementations of this interface will be joined together using
+ * the
+ * ValidationSupportChain
+ * class.
*
+ *
+ * See Validation Support Modules
+ * for information on how to assemble and configure implementations of this interface. See also
+ * the org.hl7.fhir.common.hapi.validation.support
+ * package summary
+ * in the hapi-fhir-validation
module for many implementations of this interface.
+ *
+ *
+ * @since 5.0.0
*/
-public interface IContextValidationSupport {
+public interface IValidationSupport {
+ String URL_PREFIX_VALUE_SET = "http://hl7.org/fhir/ValueSet/";
+
/**
* Expands the given portion of a ValueSet
*
- * @param theInclude The portion to include
- * @return The expansion
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theExpansionOptions If provided (may be null
), contains options controlling the expansion
+ * @param theValueSetToExpand The valueset that should be expanded
+ * @return The expansion, or null
*/
- EVS_OUT expandValueSet(FhirContext theContext, EVS_IN theInclude);
+ default ValueSetExpansionOutcome expandValueSet(IValidationSupport theRootValidationSupport, @Nullable ValueSetExpansionOptions theExpansionOptions, @Nonnull IBaseResource theValueSetToExpand) {
+ return null;
+ }
/**
* Load and return all conformance resources associated with this
* validation support module. This method may return null if it doesn't
* make sense for a given module.
*/
- List fetchAllConformanceResources(FhirContext theContext);
+ default List fetchAllConformanceResources() {
+ return null;
+ }
/**
* Load and return all possible structure definitions
*/
- List fetchAllStructureDefinitions(FhirContext theContext);
+ default List fetchAllStructureDefinitions() {
+ return null;
+ }
/**
* Fetch a code system by ID
@@ -76,70 +108,146 @@ public interface IContextValidationSupport
* @param theSystem The code system
* @return The valueset (must not be null, but can be an empty ValueSet)
*/
- CST fetchCodeSystem(FhirContext theContext, String theSystem);
+ default IBaseResource fetchCodeSystem(String theSystem) {
+ return null;
+ }
/**
* Loads a resource needed by the validation (a StructureDefinition, or a
* ValueSet)
*
- * @param theContext The HAPI FHIR Context object current in use by the validator
- * @param theClass The type of the resource to load
- * @param theUri The resource URI
+ * @param theClass The type of the resource to load
+ * @param theUri The resource URI
* @return Returns the resource, or null
if no resource with the
* given URI can be found
*/
- T fetchResource(FhirContext theContext, Class theClass, String theUri);
+ default T fetchResource(Class theClass, String theUri) {
+ Validate.notNull(theClass, "theClass must not be null or blank");
+ Validate.notBlank(theUri, "theUri must not be null or blank");
- SDT fetchStructureDefinition(FhirContext theCtx, String theUrl);
+ switch (getFhirContext().getResourceDefinition(theClass).getName()) {
+ case "StructureDefinition":
+ return theClass.cast(fetchStructureDefinition(theUri));
+ case "ValueSet":
+ return theClass.cast(fetchValueSet(theUri));
+ case "CodeSystem":
+ return theClass.cast(fetchCodeSystem(theUri));
+ }
+
+ if (theUri.startsWith(URL_PREFIX_VALUE_SET)) {
+ return theClass.cast(fetchValueSet(theUri));
+ }
+
+ return null;
+ }
+
+ default IBaseResource fetchStructureDefinition(String theUrl) {
+ return null;
+ }
/**
* Returns true
if codes in the given code system can be expanded
* or validated
*
- * @param theSystem The URI for the code system, e.g. "http://loinc.org"
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theSystem The URI for the code system, e.g. "http://loinc.org"
* @return Returns true
if codes in the given code system can be
* validated
*/
- boolean isCodeSystemSupported(FhirContext theContext, String theSystem);
+ default boolean isCodeSystemSupported(IValidationSupport theRootValidationSupport, String theSystem) {
+ return false;
+ }
/**
* Fetch the given ValueSet by URL
*/
- IBaseResource fetchValueSet(FhirContext theContext, String theValueSetUrl);
+ default IBaseResource fetchValueSet(String theValueSetUrl) {
+ return null;
+ }
/**
* Validates that the given code exists and if possible returns a display
* name. This method is called to check codes which are found in "example"
* binding fields (e.g. Observation.code
in the default profile.
*
- * @param theCodeSystem The code system, e.g. "http://loinc.org
"
- * @param theCode The code, e.g. "1234-5
"
- * @param theDisplay The display name, if it should also be validated
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theOptions Provides options controlling the validation
+ * @param theCodeSystem The code system, e.g. "http://loinc.org
"
+ * @param theCode The code, e.g. "1234-5
"
+ * @param theDisplay The display name, if it should also be validated
* @return Returns a validation result object
*/
- CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl);
+ default CodeValidationResult validateCode(IValidationSupport theRootValidationSupport, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) {
+ return null;
+ }
/**
* Validates that the given code exists and if possible returns a display
* name. This method is called to check codes which are found in "example"
* binding fields (e.g. Observation.code
in the default profile.
*
- * @param theCodeSystem The code system, e.g. "http://loinc.org
"
- * @param theCode The code, e.g. "1234-5
"
- * @param theDisplay The display name, if it should also be validated
- * @param theValueSet The ValueSet to validate against. Must not be null, and must be a ValueSet resource.
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theCodeSystem The code system, e.g. "http://loinc.org
"
+ * @param theCode The code, e.g. "1234-5
"
+ * @param theDisplay The display name, if it should also be validated
+ * @param theValueSet The ValueSet to validate against. Must not be null, and must be a ValueSet resource.
* @return Returns a validation result object, or null
if this validation support module can not handle this kind of request
*/
- default CodeValidationResult validateCodeInValueSet(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay, @Nonnull IBaseResource theValueSet) { return null; }
+ default CodeValidationResult validateCodeInValueSet(IValidationSupport theRootValidationSupport, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, @Nonnull IBaseResource theValueSet) {
+ return null;
+ }
/**
* Look up a code using the system and code value
*
- * @param theContext The FHIR context
- * @param theSystem The CodeSystem URL
- * @param theCode The code
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theSystem The CodeSystem URL
+ * @param theCode The code
*/
- LookupCodeResult lookupCode(FhirContext theContext, String theSystem, String theCode);
+ default LookupCodeResult lookupCode(IValidationSupport theRootValidationSupport, String theSystem, String theCode) {
+ return null;
+ }
+
+ /**
+ * Returns true
if the given valueset can be validated by the given
+ * validation support module
+ *
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @param theValueSetUrl The ValueSet canonical URL
+ */
+ default boolean isValueSetSupported(IValidationSupport theRootValidationSupport, String theValueSetUrl) {
+ return false;
+ }
+
+ /**
+ * Generate a snapshot from the given differential profile.
+ *
+ * @param theRootValidationSupport The validation support module will be passed in to this method. This is convenient in cases where the operation needs to make calls to
+ * other method in the support chain, so that they can be passed through the entire chain. Implementations of this interface may always safely ignore this parameter.
+ * @return Returns null if this module does not know how to handle this request
+ */
+ default IBaseResource generateSnapshot(IValidationSupport theRootValidationSupport, IBaseResource theInput, String theUrl, String theWebUrl, String theProfileName) {
+ return null;
+ }
+
+ /**
+ * Returns the FHIR Context associated with this module
+ */
+ FhirContext getFhirContext();
+
+ /**
+ * This method clears any temporary caches within the validation support. It is mainly intended for unit tests,
+ * but could be used in non-test scenarios as well.
+ */
+ default void invalidateCaches() {
+ // nothing
+ }
+
class ConceptDesignation {
private String myLanguage;
@@ -257,59 +365,83 @@ public interface IContextValidationSupport
}
}
+ enum IssueSeverity {
+ /**
+ * The issue caused the action to fail, and no further checking could be performed.
+ */
+ FATAL,
+ /**
+ * The issue is sufficiently important to cause the action to fail.
+ */
+ ERROR,
+ /**
+ * The issue is not important enough to cause the action to fail, but may cause it to be performed suboptimally or in a way that is not as desired.
+ */
+ WARNING,
+ /**
+ * The issue has no relation to the degree of success of the action.
+ */
+ INFORMATION
+ }
+
class CodeValidationResult {
- private IBase myDefinition;
+ private String myCode;
private String myMessage;
- private Enum mySeverity;
+ private IssueSeverity mySeverity;
private String myCodeSystemName;
private String myCodeSystemVersion;
private List myProperties;
private String myDisplay;
- public CodeValidationResult(IBase theDefinition) {
- this.myDefinition = theDefinition;
- }
-
- public CodeValidationResult(Enum theSeverity, String message) {
- this.mySeverity = theSeverity;
- this.myMessage = message;
- }
-
- public CodeValidationResult(Enum theSeverity, String theMessage, IBase theDefinition, String theDisplay) {
- this.mySeverity = theSeverity;
- this.myMessage = theMessage;
- this.myDefinition = theDefinition;
- this.myDisplay = theDisplay;
+ public CodeValidationResult() {
+ super();
}
public String getDisplay() {
return myDisplay;
}
- public IBase asConceptDefinition() {
- return myDefinition;
+ public CodeValidationResult setDisplay(String theDisplay) {
+ myDisplay = theDisplay;
+ return this;
+ }
+
+ public String getCode() {
+ return myCode;
+ }
+
+ public CodeValidationResult setCode(String theCode) {
+ myCode = theCode;
+ return this;
}
String getCodeSystemName() {
return myCodeSystemName;
}
- public void setCodeSystemName(String theCodeSystemName) {
+ public CodeValidationResult setCodeSystemName(String theCodeSystemName) {
myCodeSystemName = theCodeSystemName;
+ return this;
}
public String getCodeSystemVersion() {
return myCodeSystemVersion;
}
- public void setCodeSystemVersion(String theCodeSystemVersion) {
+ public CodeValidationResult setCodeSystemVersion(String theCodeSystemVersion) {
myCodeSystemVersion = theCodeSystemVersion;
+ return this;
}
public String getMessage() {
return myMessage;
}
+ public CodeValidationResult setMessage(String theMessage) {
+ myMessage = theMessage;
+ return this;
+ }
+
public List getProperties() {
return myProperties;
}
@@ -318,12 +450,17 @@ public interface IContextValidationSupport
myProperties = theProperties;
}
- public Enum getSeverity() {
+ public IssueSeverity getSeverity() {
return mySeverity;
}
+ public CodeValidationResult setSeverity(IssueSeverity theSeverity) {
+ mySeverity = theSeverity;
+ return this;
+ }
+
public boolean isOk() {
- return myDefinition != null;
+ return isNotBlank(myCode);
}
public LookupCodeResult asLookupCodeResult(String theSearchedForSystem, String theSearchedForCode) {
@@ -339,6 +476,49 @@ public interface IContextValidationSupport