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);
}
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());
}
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));
}
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;
}
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));
}
Aggregations