Search in sources :

Example 51 with Function

use of org.hl7.fhir.r5.model.ExpressionNode.Function in project openmrs-module-fhir2 by openmrs.

the class FhirTaskTranslatorImplTest method shouldTranslateReferenceListToOpenmrs.

private void shouldTranslateReferenceListToOpenmrs(Task task, String refType, String refUuid, Consumer<List<Reference>> setFhirReference, Function<FhirTask, Set<FhirReference>> getOpenmrsReference) {
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    setFhirReference.accept(Collections.singletonList(fhirReference));
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setReference(refUuid);
    openmrsReference.setType(refType);
    when(referenceTranslator.toOpenmrsType(any(Reference.class))).thenReturn(openmrsReference);
    FhirTask result = taskTranslator.toOpenmrsType(task);
    Collection<FhirReference> resultReference = getOpenmrsReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference, hasSize(1));
    assertThat(resultReference.iterator().next().getReference(), equalTo(refUuid));
    assertThat(resultReference.iterator().next().getType(), equalTo(refType));
}
Also used : FhirTask(org.openmrs.module.fhir2.model.FhirTask) Reference(org.hl7.fhir.r4.model.Reference) FhirReference(org.openmrs.module.fhir2.model.FhirReference) FhirReference(org.openmrs.module.fhir2.model.FhirReference)

Example 52 with Function

use of org.hl7.fhir.r5.model.ExpressionNode.Function in project openmrs-module-fhir2 by openmrs.

the class FhirTaskTranslatorImplTest method shouldTranslateReferenceToOpenmrs.

private FhirTask shouldTranslateReferenceToOpenmrs(Task task, String refType, String refUuid, Consumer<Reference> setFhirReference, Function<FhirTask, FhirReference> getOpenmrsReference) {
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    setFhirReference.accept(fhirReference);
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setReference(refUuid);
    openmrsReference.setType(refType);
    when(referenceTranslator.toOpenmrsType(any(Reference.class))).thenReturn(openmrsReference);
    FhirTask result = taskTranslator.toOpenmrsType(task);
    FhirReference resultReference = getOpenmrsReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference.getReference(), equalTo(refUuid));
    assertThat(resultReference.getType(), equalTo(refType));
    return result;
}
Also used : FhirTask(org.openmrs.module.fhir2.model.FhirTask) Reference(org.hl7.fhir.r4.model.Reference) FhirReference(org.openmrs.module.fhir2.model.FhirReference) FhirReference(org.openmrs.module.fhir2.model.FhirReference)

Example 53 with Function

use of org.hl7.fhir.r5.model.ExpressionNode.Function in project openmrs-module-fhir2 by openmrs.

the class FhirTaskTranslatorImplTest method shouldUpdateReferenceInOpenmrs.

private FhirTask shouldUpdateReferenceInOpenmrs(Task task, String refType, String refUuid, Consumer<Reference> setFhirReference, Function<FhirTask, FhirReference> getOpenmrsReference) {
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    setFhirReference.accept(fhirReference);
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setReference(refUuid);
    openmrsReference.setType(refType);
    FhirTask openmrsTask = new FhirTask();
    openmrsTask.setUuid(TASK_UUID);
    openmrsTask.setEncounterReference(new FhirReference());
    when(referenceTranslator.toOpenmrsType(any(Reference.class))).thenReturn(openmrsReference);
    FhirTask result = taskTranslator.toOpenmrsType(openmrsTask, task);
    FhirReference resultReference = getOpenmrsReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference.getReference(), equalTo(refUuid));
    assertThat(resultReference.getType(), equalTo(refType));
    return result;
}
Also used : FhirTask(org.openmrs.module.fhir2.model.FhirTask) Reference(org.hl7.fhir.r4.model.Reference) FhirReference(org.openmrs.module.fhir2.model.FhirReference) FhirReference(org.openmrs.module.fhir2.model.FhirReference)

Example 54 with Function

use of org.hl7.fhir.r5.model.ExpressionNode.Function in project drug-formulary-ri by HL7-DaVinci.

the class ExampleServerR4IT 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:" + ourPort + "/hapi-fhir-jpaserver/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) Observation(org.hl7.fhir.r4.model.Observation) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) Subscription(org.hl7.fhir.r4.model.Subscription) IIdType(org.hl7.fhir.instance.model.api.IIdType) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Example 55 with Function

use of org.hl7.fhir.r5.model.ExpressionNode.Function in project drug-formulary-ri by HL7-DaVinci.

the class ExampleServerR5IT method testWebsocketSubscription.

@Test
public void testWebsocketSubscription() throws Exception {
    /*
         * Create topic
         */
    Topic topic = new Topic();
    topic.getResourceTrigger().getQueryCriteria().setCurrent("Observation?status=final");
    /*
         * Create subscription
         */
    Subscription subscription = new Subscription();
    subscription.getTopic().setResource(topic);
    subscription.setReason("Monitor new neonatal function (note, age will be determined by the monitor)");
    subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED);
    Subscription.SubscriptionChannelComponent channel = new Subscription.SubscriptionChannelComponent();
    channel.getType().addCoding().setSystem(SubscriptionChannelType.WEBSOCKET.getSystem()).setCode(SubscriptionChannelType.WEBSOCKET.toCode());
    channel.getPayload().setContentType("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:" + ourPort + "/hapi-fhir-jpaserver/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) Observation(org.hl7.fhir.r5.model.Observation) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) Topic(org.hl7.fhir.r5.model.Topic) Subscription(org.hl7.fhir.r5.model.Subscription) IIdType(org.hl7.fhir.instance.model.api.IIdType) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

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