Start work

This commit is contained in:
jamesagnew 2020-06-17 18:32:17 -04:00
parent f74eba5397
commit 64a9eaa4de
5 changed files with 77 additions and 24 deletions

View File

@ -7,13 +7,14 @@ import ca.uhn.fhir.jpa.subscription.channel.impl.LinkedBlockingChannel;
import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionMatcherInterceptor; import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionMatcherInterceptor;
import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Transaction;
import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.util.BundleUtil;
import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.test.utilities.JettyUtil;
import ca.uhn.fhir.util.BundleUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.ttddyy.dsproxy.QueryCount; import net.ttddyy.dsproxy.QueryCount;
import net.ttddyy.dsproxy.listener.SingleQueryCountHolder; import net.ttddyy.dsproxy.listener.SingleQueryCountHolder;
@ -22,9 +23,19 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.Bundle;
import org.junit.*; import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Subscription;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -36,28 +47,23 @@ import java.util.List;
@Ignore @Ignore
public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test { public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSubscriptionsR4Test.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSubscriptionsR4Test.class);
protected static int ourListenerPort;
private static Server ourListenerServer;
protected static int ourListenerPort;
protected static List<String> ourContentTypes = Collections.synchronizedList(new ArrayList<>()); protected static List<String> ourContentTypes = Collections.synchronizedList(new ArrayList<>());
protected static List<String> ourHeaders = Collections.synchronizedList(new ArrayList<>()); protected static List<String> ourHeaders = Collections.synchronizedList(new ArrayList<>());
protected static List<Bundle> ourTransactions = Collections.synchronizedList(Lists.newArrayList());
protected static List<Observation> ourCreatedObservations = Collections.synchronizedList(Lists.newArrayList());
protected static List<Observation> ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList());
private static Server ourListenerServer;
private static SingleQueryCountHolder ourCountHolder; private static SingleQueryCountHolder ourCountHolder;
private static String ourListenerServerBase;
@Autowired
private SingleQueryCountHolder myCountHolder;
@Autowired @Autowired
protected SubscriptionTestUtil mySubscriptionTestUtil; protected SubscriptionTestUtil mySubscriptionTestUtil;
@Autowired @Autowired
protected SubscriptionMatcherInterceptor mySubscriptionMatcherInterceptor; protected SubscriptionMatcherInterceptor mySubscriptionMatcherInterceptor;
protected CountingInterceptor myCountingInterceptor; protected CountingInterceptor myCountingInterceptor;
protected static List<Observation> ourCreatedObservations = Collections.synchronizedList(Lists.newArrayList());
protected static List<Observation> ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList());
private static String ourListenerServerBase;
protected List<IIdType> mySubscriptionIds = Collections.synchronizedList(new ArrayList<>()); protected List<IIdType> mySubscriptionIds = Collections.synchronizedList(new ArrayList<>());
@Autowired
private SingleQueryCountHolder myCountHolder;
@After @After
public void afterUnregisterRestHookListener() { public void afterUnregisterRestHookListener() {
@ -87,6 +93,7 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test
public void beforeReset() throws Exception { public void beforeReset() throws Exception {
ourCreatedObservations.clear(); ourCreatedObservations.clear();
ourUpdatedObservations.clear(); ourUpdatedObservations.clear();
ourTransactions.clear();
ourContentTypes.clear(); ourContentTypes.clear();
ourHeaders.clear(); ourHeaders.clear();
@ -162,8 +169,7 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test
} }
public static class ObservationResourceProvider implements IResourceProvider {
public static class ObservationListener implements IResourceProvider {
@Create @Create
public MethodOutcome create(@ResourceParam Observation theObservation, HttpServletRequest theRequest) { public MethodOutcome create(@ResourceParam Observation theObservation, HttpServletRequest theRequest) {
@ -202,6 +208,16 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test
} }
public static class PlainProvider {
@Transaction
public Bundle transaction(@RequestParam Bundle theInput) {
ourTransactions.add(theInput);
return theInput;
}
}
@AfterClass @AfterClass
public static void reportTotalSelects() { public static void reportTotalSelects() {
ourLog.info("Total database select queries: {}", getQueryCount().getSelect()); ourLog.info("Total database select queries: {}", getQueryCount().getSelect());
@ -214,9 +230,9 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test
@BeforeClass @BeforeClass
public static void startListenerServer() throws Exception { public static void startListenerServer() throws Exception {
RestfulServer ourListenerRestServer = new RestfulServer(FhirContext.forR4()); RestfulServer ourListenerRestServer = new RestfulServer(FhirContext.forR4());
ObservationListener obsListener = new ObservationListener(); ObservationResourceProvider observationResourceProvider = new ObservationResourceProvider();
ourListenerRestServer.setResourceProviders(obsListener); ourListenerRestServer.setResourceProviders(observationResourceProvider);
ourListenerServer = new Server(0); ourListenerServer = new Server(0);
@ -229,8 +245,8 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test
ourListenerServer.setHandler(proxyHandler); ourListenerServer.setHandler(proxyHandler);
JettyUtil.startServer(ourListenerServer); JettyUtil.startServer(ourListenerServer);
ourListenerPort = JettyUtil.getPortForStartedServer(ourListenerServer); ourListenerPort = JettyUtil.getPortForStartedServer(ourListenerServer);
ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context";
} }
@AfterClass @AfterClass

View File

@ -1013,4 +1013,30 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test {
} }
@Test
public void testDeliverSearchSet() throws Exception {
{
Subscription subscription = newSubscription("Observation?", "application/json");
subscription.addExtension(JpaConstants.EXT_SUBSCRIPTION_DELIVER_BUNDLE_SEARCH_RESULT, new StringType("Observation?_id=${resource_id}&_include=*"));
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
mySubscriptionIds.add(methodOutcome.getId());
waitForActivatedSubscriptionCount(1);
}
{
Patient patient = new Patient();
patient.setActive(true);
IIdType patientId = ourClient.create().resource(patient).execute().getId();
Observation observation = new Observation();
observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("Catheter"));
observation.getSubject().setReferenceElement(patientId);
MethodOutcome methodOutcome = ourClient.create().resource(observation).execute();
assertEquals(true, methodOutcome.getCreated());
waitForQueueToDrain();
waitForSize(1, ourTransactions);
}
}
} }

View File

@ -214,6 +214,10 @@ public class JpaConstants {
* Extension ID for external binary references * Extension ID for external binary references
*/ */
public static final String EXT_EXTERNALIZED_BINARY_ID = "http://hapifhir.io/fhir/StructureDefinition/externalized-binary-id"; public static final String EXT_EXTERNALIZED_BINARY_ID = "http://hapifhir.io/fhir/StructureDefinition/externalized-binary-id";
/**
* For subscription, deliver a bundle containinf a search result instead of just a single resource
*/
public static final String EXT_SUBSCRIPTION_DELIVER_BUNDLE_SEARCH_RESULT = "http://hapifhir.io/fhir/StructureDefinition/subscription-deliver-bundle-search-result";
/** /**
* Placed in system-generated extensions * Placed in system-generated extensions
*/ */

View File

@ -261,6 +261,7 @@ public class SubscriptionCanonicalizer {
retVal.setChannelExtensions(extractExtension(subscription)); retVal.setChannelExtensions(extractExtension(subscription));
retVal.setIdElement(subscription.getIdElement()); retVal.setIdElement(subscription.getIdElement());
retVal.setPayloadString(subscription.getContentType()); retVal.setPayloadString(subscription.getContentType());
retVal.setDeliverBundleSearchResult(getExtensionString(subscription, JpaConstants.EXT_SUBSCRIPTION_DELIVER_BUNDLE_SEARCH_RESULT));
if (retVal.getChannelType() == CanonicalSubscriptionChannelType.EMAIL) { if (retVal.getChannelType() == CanonicalSubscriptionChannelType.EMAIL) {
String from; String from;

View File

@ -64,6 +64,8 @@ public class CanonicalSubscription implements Serializable, Cloneable, IModelJso
private RestHookDetails myRestHookDetails; private RestHookDetails myRestHookDetails;
@JsonProperty("extensions") @JsonProperty("extensions")
private Map<String, List<String>> myChannelExtensions; private Map<String, List<String>> myChannelExtensions;
@JsonProperty("deliverBundleSearchResult")
private String myDeliverBundleSearchResult;
/** /**
* Constructor * Constructor
@ -276,7 +278,11 @@ public class CanonicalSubscription implements Serializable, Cloneable, IModelJso
} }
} }
public static class EmailDetails implements IModelJson { public void setDeliverBundleSearchResult(String theDeliverBundleSearchResult) {
myDeliverBundleSearchResult = theDeliverBundleSearchResult;
}
public static class EmailDetails implements IModelJson {
@JsonProperty("from") @JsonProperty("from")
private String myFrom; private String myFrom;