Search in sources :

Example 41 with Function

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();
}
Also used : CacheControlDirective(ca.uhn.fhir.rest.api.CacheControlDirective) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) URI(java.net.URI) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) IIdType(org.hl7.fhir.instance.model.api.IIdType) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 42 with Function

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();
}
Also used : CacheControlDirective(ca.uhn.fhir.rest.api.CacheControlDirective) Observation(org.hl7.fhir.r5.model.Observation) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) Subscription(org.hl7.fhir.r5.model.Subscription) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) URI(java.net.URI) SubscriptionTopic(org.hl7.fhir.r5.model.SubscriptionTopic) IIdType(org.hl7.fhir.instance.model.api.IIdType) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 43 with Function

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;
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) BundleEntryRequestComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent) Property(org.hl7.fhir.r4.model.Property)

Example 44 with Function

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;
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.dstu3.model.Identifier) BundleEntryRequestComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent) Property(org.hl7.fhir.dstu3.model.Property)

Example 45 with Function

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());
    }
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) DataType(org.hl7.cql.model.DataType)

Aggregations

Test (org.junit.jupiter.api.Test)17 List (java.util.List)8 FhirPath (au.csiro.pathling.fhirpath.FhirPath)7 Reference (org.hl7.fhir.r4.model.Reference)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 URI (java.net.URI)6 Row (org.apache.spark.sql.Row)6 Session (org.eclipse.jetty.websocket.api.Session)6 ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)6 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)6 IIdType (org.hl7.fhir.instance.model.api.IIdType)6 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)6 FhirReference (org.openmrs.module.fhir2.model.FhirReference)6 FhirTask (org.openmrs.module.fhir2.model.FhirTask)6 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)5 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)5 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)5 ArrayList (java.util.ArrayList)5