Search in sources :

Example 1 with SparkRowConverter

use of com.cerner.bunsen.spark.SparkRowConverter in project bunsen by cerner.

the class Functions method toBundle.

/**
 * Returns a bundle containing all resources in the dataset. This should be used
 * with caution for large datasets, since the returned bundle will include all data.
 *
 * @param dataset a dataset of FHIR resoruces
 * @param resourceTypeUrl the FHIR resource type
 * @return a bundle containing those resources.
 */
public static Bundle toBundle(Dataset<Row> dataset, String resourceTypeUrl) {
    List<Row> resources = (List<Row>) dataset.collectAsList();
    SparkRowConverter converter = SparkRowConverter.forResource(CONTEXT, resourceTypeUrl);
    Bundle bundle = new Bundle();
    for (Row row : resources) {
        IBaseResource resource = converter.rowToResource(row);
        bundle.addEntry().setResource((Resource) resource);
    }
    return bundle;
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) List(java.util.List) Row(org.apache.spark.sql.Row) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SparkRowConverter(com.cerner.bunsen.spark.SparkRowConverter)

Example 2 with SparkRowConverter

use of com.cerner.bunsen.spark.SparkRowConverter in project bunsen by cerner.

the class BundlesTest method testGetResourcesAndContainedResourcesByClass.

@Test
public void testGetResourcesAndContainedResourcesByClass() {
    List<Class> containedClasses = ImmutableList.of(Provenance.class);
    Dataset<Row> observations = bundles.extractEntry(spark, bundlesWithContainedRdd, Observation.class, containedClasses);
    SparkRowConverter rowConverter = SparkRowConverter.forResource(fhirContext, Observation.class.getSimpleName(), containedClasses.stream().map(c -> c.getSimpleName()).collect(Collectors.toList()));
    Observation observation = (Observation) rowConverter.rowToResource(observations.head());
    Assert.assertEquals(1, observations.count());
    Assert.assertEquals(ResourceType.Provenance, observation.getContained().get(0).getResourceType());
    // internal references prefixed with #
    String expectedId = "#" + "11000100-4";
    Assert.assertEquals(expectedId, observation.getContained().get(0).getId());
}
Also used : Observation(org.hl7.fhir.dstu3.model.Observation) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) Row(org.apache.spark.sql.Row) SparkRowConverter(com.cerner.bunsen.spark.SparkRowConverter) Test(org.junit.Test)

Aggregations

SparkRowConverter (com.cerner.bunsen.spark.SparkRowConverter)2 Row (org.apache.spark.sql.Row)2 List (java.util.List)1 Bundle (org.hl7.fhir.dstu3.model.Bundle)1 Observation (org.hl7.fhir.dstu3.model.Observation)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1