use of org.hl7.fhir.r4b.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));
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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();
}
use of org.hl7.fhir.r4b.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();
}
Aggregations