Search in sources :

Example 11 with Function

use of org.hl7.fhir.dstu2.model.ExpressionNode.Function in project cqf-ruler by DBCG.

the class ReflectionsTest method testGetUrl.

@Test
public void testGetUrl() {
    Library library = new Library().setUrl("http://test.com");
    Function<Library, String> getVersion = Reflections.getUrlFunction(library.getClass());
    String version = getVersion.apply(library);
    assertEquals("http://test.com", version);
}
Also used : Library(org.hl7.fhir.dstu3.model.Library) Test(org.junit.jupiter.api.Test)

Example 12 with Function

use of org.hl7.fhir.dstu2.model.ExpressionNode.Function in project cqf-ruler by DBCG.

the class VersionsTest method testSelectFromList.

@Test
public void testSelectFromList() {
    List<Library> libraries = Arrays.asList(new Library().setVersion("1.0.0"), new Library().setVersion("0.0.1"), new Library());
    Function<Library, String> getVersion = l -> l.getVersion();
    // Gets matching version
    Library lib = Versions.selectByVersion(libraries, "1.0.0", getVersion);
    assertEquals("1.0.0", lib.getVersion());
    // Gets max version (null version on library is considered max version)
    lib = Versions.selectByVersion(libraries, "2.0.0", getVersion);
    assertNull(lib.getVersion());
    // Null version max version (null input gets max version)
    lib = Versions.selectByVersion(libraries, null, getVersion);
    assertNull(lib.getVersion());
}
Also used : Test(org.junit.jupiter.api.Test) Arrays(java.util.Arrays) List(java.util.List) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Library(org.hl7.fhir.dstu3.model.Library) Function(java.util.function.Function) Library(org.hl7.fhir.dstu3.model.Library) Test(org.junit.jupiter.api.Test)

Example 13 with Function

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

the class FhirTaskTranslatorImplTest method shouldTranslateReferenceListToFhir.

private void shouldTranslateReferenceListToFhir(FhirTask task, String refType, String refUuid, Consumer<Set<FhirReference>> setOpenmrsReference, Function<Task, List<Reference>> getFhirReference) {
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setType(refType);
    openmrsReference.setReference(refUuid);
    setOpenmrsReference.accept(Collections.singleton(openmrsReference));
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    when(referenceTranslator.toFhirResource(any(FhirReference.class))).thenReturn(fhirReference);
    Task result = taskTranslator.toFhirResource(task);
    Collection<Reference> resultReference = getFhirReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference, hasSize(1));
    assertThat(resultReference.iterator().next(), notNullValue());
    assertThat(resultReference.iterator().next().getType(), equalTo(refType));
    assertThat(resultReference.iterator().next().getReference(), equalTo(refUuid));
}
Also used : Task(org.hl7.fhir.r4.model.Task) 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 14 with Function

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

the class FhirTaskTranslatorImplTest method shouldTranslateReferenceToFhir.

/**
 * Helpers for reference associations
 */
private Task shouldTranslateReferenceToFhir(FhirTask task, String refType, String refUuid, Consumer<FhirReference> setOpenmrsReference, Function<Task, Reference> getFhirReference) {
    FhirReference openmrsReference = new FhirReference();
    openmrsReference.setType(refType);
    openmrsReference.setReference(refUuid);
    setOpenmrsReference.accept(openmrsReference);
    Reference fhirReference = new Reference().setReference(refUuid).setType(refType);
    when(referenceTranslator.toFhirResource(any(FhirReference.class))).thenReturn(fhirReference);
    Task result = taskTranslator.toFhirResource(task);
    Reference resultReference = getFhirReference.apply(result);
    assertThat(resultReference, notNullValue());
    assertThat(resultReference.getType(), equalTo(refType));
    assertThat(resultReference.getReference(), equalTo(refUuid));
    return result;
}
Also used : Task(org.hl7.fhir.r4.model.Task) 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 15 with Function

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

the class FhirTaskTranslatorImplTest method shouldUpdateReferenceListInOpenmrs.

private void shouldUpdateReferenceListInOpenmrs(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);
    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);
    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)

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