use of org.hl7.fhir.r5.model.ExpressionNode.Function in project hapi-fhir-jpaserver-starter by hapifhir.
the class ExampleServerDstu3IT method testWebsocketSubscription.
@Test
public void testWebsocketSubscription() throws Exception {
/*
* Create subscription
*/
Subscription subscription = new Subscription();
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
subscription.setCriteria("Observation?status=final");
Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
channel.setType(Subscription.SubscriptionChannelType.WEBSOCKET);
channel.setPayload("application/json");
subscription.setChannel(channel);
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
IIdType mySubscriptionId = methodOutcome.getId();
// Wait for the subscription to be activated
waitForSize(1, () -> ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size());
/*
* Attach websocket
*/
WebSocketClient myWebSocketClient = new WebSocketClient();
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
myWebSocketClient.start();
URI echoUri = new URI("ws://localhost:" + port + "/websocket");
ClientUpgradeRequest request = new ClientUpgradeRequest();
ourLog.info("Connecting to : {}", echoUri);
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
Session session = connection.get(2, TimeUnit.SECONDS);
ourLog.info("Connected to WS: {}", session.isOpen());
/*
* Create a matching resource
*/
Observation obs = new Observation();
obs.setStatus(Observation.ObservationStatus.FINAL);
ourClient.create().resource(obs).execute();
// Give some time for the subscription to deliver
Thread.sleep(2000);
/*
* Ensure that we receive a ping on the websocket
*/
waitForSize(1, () -> mySocketImplementation.myPingCount);
/*
* Clean up
*/
ourClient.delete().resourceById(mySubscriptionId).execute();
}
use of org.hl7.fhir.r5.model.ExpressionNode.Function in project hapi-fhir-jpaserver-starter by hapifhir.
the class ExampleServerR5IT method testWebsocketSubscription.
@Test
public void testWebsocketSubscription() throws Exception {
/*
* Create topic (will be contained in subscription)
*/
SubscriptionTopic topic = new SubscriptionTopic();
topic.setId("#1");
topic.getResourceTriggerFirstRep().getQueryCriteria().setCurrent("Observation?status=final");
/*
* Create subscription
*/
Subscription subscription = new Subscription();
subscription.getContained().add(topic);
subscription.setTopic("#1");
subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
subscription.setStatus(Enumerations.SubscriptionState.REQUESTED);
subscription.getChannelType().setSystem("http://terminology.hl7.org/CodeSystem/subscription-channel-type").setCode("websocket");
subscription.setContentType("application/json");
MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute();
IIdType mySubscriptionId = methodOutcome.getId();
// Wait for the subscription to be activated
waitForSize(1, () -> ourClient.search().forResource(Subscription.class).where(Subscription.STATUS.exactly().code("active")).cacheControl(new CacheControlDirective().setNoCache(true)).returnBundle(Bundle.class).execute().getEntry().size());
/*
* Attach websocket
*/
WebSocketClient myWebSocketClient = new WebSocketClient();
SocketImplementation mySocketImplementation = new SocketImplementation(mySubscriptionId.getIdPart(), EncodingEnum.JSON);
myWebSocketClient.start();
URI echoUri = new URI("ws://localhost:" + port + "/websocket");
ClientUpgradeRequest request = new ClientUpgradeRequest();
ourLog.info("Connecting to : {}", echoUri);
Future<Session> connection = myWebSocketClient.connect(mySocketImplementation, echoUri, request);
Session session = connection.get(2, TimeUnit.SECONDS);
ourLog.info("Connected to WS: {}", session.isOpen());
/*
* Create a matching resource
*/
Observation obs = new Observation();
obs.setStatus(Enumerations.ObservationStatus.FINAL);
ourClient.create().resource(obs).execute();
/*
* Ensure that we receive a ping on the websocket
*/
await().until(() -> mySocketImplementation.myPingCount > 0);
/*
* Clean up
*/
ourClient.delete().resourceById(mySubscriptionId).execute();
}
use of org.hl7.fhir.r5.model.ExpressionNode.Function in project synthea by synthetichealth.
the class FhirR4 method newEntry.
/**
* Helper function to create an Entry for the given Resource within the given Bundle. Sets the
* resourceID to a random UUID, sets the entry's fullURL to that resourceID, and adds the entry to
* the bundle.
*
* @param bundle The Bundle to add the Entry to
* @param resource Resource the new Entry should contain
* @param resourceID The Resource ID to assign
* @return the created Entry
*/
private static BundleEntryComponent newEntry(Bundle bundle, Resource resource, String resourceID) {
BundleEntryComponent entry = bundle.addEntry();
resource.setId(resourceID);
entry.setFullUrl(getUrlPrefix(resource.fhirType()) + resourceID);
entry.setResource(resource);
if (TRANSACTION_BUNDLE) {
BundleEntryRequestComponent request = entry.getRequest();
request.setMethod(HTTPVerb.POST);
String resourceType = resource.getResourceType().name();
request.setUrl(resourceType);
if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
Property prop = entry.getResource().getNamedProperty("identifier");
if (prop != null && prop.getValues().size() > 0) {
Identifier identifier = (Identifier) prop.getValues().get(0);
request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
}
}
entry.setRequest(request);
}
return entry;
}
use of org.hl7.fhir.r5.model.ExpressionNode.Function in project synthea by synthetichealth.
the class FhirStu3 method newEntry.
/**
* Helper function to create an Entry for the given Resource within the given Bundle.
* Sets the entry's fullURL to resourceID, and adds the entry to the bundle.
*
* @param bundle The Bundle to add the Entry to
* @param resource Resource the new Entry should contain
* @param resourceID The Resource ID to assign
* @return the created Entry
*/
private static BundleEntryComponent newEntry(Bundle bundle, Resource resource, String resourceID) {
BundleEntryComponent entry = bundle.addEntry();
resource.setId(resourceID);
if (Config.getAsBoolean("exporter.fhir.bulk_data")) {
entry.setFullUrl(resource.fhirType() + "/" + resourceID);
} else {
entry.setFullUrl("urn:uuid:" + resourceID);
}
entry.setResource(resource);
if (TRANSACTION_BUNDLE) {
BundleEntryRequestComponent request = entry.getRequest();
request.setMethod(HTTPVerb.POST);
String resourceType = resource.getResourceType().name();
request.setUrl(resourceType);
if (ExportHelper.UNDUPLICATED_FHIR_RESOURCES.contains(resourceType)) {
Property prop = entry.getResource().getNamedProperty("identifier");
if (prop != null && prop.getValues().size() > 0) {
Identifier identifier = (Identifier) prop.getValues().get(0);
request.setIfNoneExist("identifier=" + identifier.getSystem() + "|" + identifier.getValue());
}
}
entry.setRequest(request);
}
return entry;
}
use of org.hl7.fhir.r5.model.ExpressionNode.Function in project clinical_quality_language by cqframework.
the class ElmRequirementsContext method reportFunctionRef.
public void reportFunctionRef(FunctionRef functionRef) {
CompiledLibrary targetLibrary = prepareLibraryVisit(getCurrentLibraryIdentifier(), functionRef.getLibraryName());
try {
List<DataType> signature;
signature = new ArrayList<DataType>();
for (TypeSpecifier ts : functionRef.getSignature()) {
signature.add(typeResolver.resolveTypeSpecifier(ts));
}
// Signature sizes will only be different in the case that the signature is not present in the ELM, so needs to be constructed
if (signature.size() != functionRef.getOperand().size()) {
for (Expression e : functionRef.getOperand()) {
if (e.getResultType() != null) {
signature.add(e.getResultType());
} else if (e.getResultTypeName() != null) {
signature.add(typeResolver.resolveTypeName(e.getResultTypeName()));
} else if (e.getResultTypeSpecifier() != null) {
signature.add(typeResolver.resolveTypeSpecifier(e.getResultTypeSpecifier()));
} else {
// Signature could not be constructed, fall back to reporting all function defs
signature = null;
break;
}
}
}
Iterable<FunctionDef> fds = targetLibrary.resolveFunctionRef(functionRef.getName(), signature);
for (FunctionDef fd : fds) {
if (!visited.contains(fd)) {
visitor.visitElement(fd, this);
}
}
} finally {
unprepareLibraryVisit(functionRef.getLibraryName());
}
}
Aggregations