Skip to content

Commit

Permalink
Expand ExtractTest#simple and make assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
johngrimes committed Apr 18, 2024
1 parent 2c7e41b commit f401d97
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions fhirpath/src/test/java/au/csiro/pathling/extract/ExtractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import au.csiro.pathling.query.ExpressionWithLabel;
import au.csiro.pathling.terminology.TerminologyServiceFactory;
import au.csiro.pathling.test.SpringBootUnitTest;
import au.csiro.pathling.test.assertions.DatasetAssert;
import au.csiro.pathling.test.builders.DatasetBuilder;
import au.csiro.pathling.test.datasource.ObjectDataSource;
import ca.uhn.fhir.context.FhirContext;
import java.util.Collections;
Expand All @@ -14,6 +16,7 @@
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;
import org.apache.spark.sql.types.DataTypes;
import org.hl7.fhir.r4.model.Enumerations.ResourceType;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test;
Expand All @@ -39,9 +42,12 @@ class ExtractTest {
void simple() {
final Patient patient = new Patient();
patient.setId("1");
patient.addName().setFamily("Smith").addGiven("John");
patient.addName().setFamily("Tyler").addGiven("Mary");
patient.addTelecom().setValue("555-555-5555");
patient.addName().setFamily("Kay").addGiven("Awee");
patient.addName().setFamily("Robert").addGiven("Zosia");
final Patient.ContactComponent contact1 = patient.addContact();
contact1.getName().setFamily("Ravindra").addGiven("Veremund");
final Patient.ContactComponent contact2 = patient.addContact();
contact2.getName().setFamily("Einion").addGiven("Kazuko");
final ObjectDataSource dataSource = new ObjectDataSource(spark, encoders,
List.of(patient));
final ExtractQueryExecutor executor = new ExtractQueryExecutor(
Expand All @@ -52,11 +58,28 @@ void simple() {
List.of(
ExpressionWithLabel.of("id", "id"),
ExpressionWithLabel.of("name.given", "given_name"),
ExpressionWithLabel.of("name.family", "family_name")
ExpressionWithLabel.of("name.family", "family_name"),
ExpressionWithLabel.of("contact.name.given", "contact_given_name"),
ExpressionWithLabel.of("contact.name.family", "contact_family_name")
), Collections.emptyList(), Optional.empty());

final Dataset<Row> result = executor.buildQuery(request);
result.show();

final Dataset<Row> expected = DatasetBuilder.of(spark)
.withColumn("id", DataTypes.StringType)
.withColumn("given_name", DataTypes.StringType)
.withColumn("family_name", DataTypes.StringType)
.withColumn("contact_given_name", DataTypes.StringType)
.withColumn("contact_family_name", DataTypes.StringType)
.withRow("1", "Awee", "Kay", "Veremund", "Ravindra")
.withRow("1", "Awee", "Kay", "Kazuko", "Einion")
.withRow("1", "Zosia", "Robert", "Veremund", "Ravindra")
.withRow("1", "Zosia", "Robert", "Kazuko", "Einion")
.build();

new DatasetAssert(result)
.hasRowsUnordered(expected);
}

}

0 comments on commit f401d97

Please sign in to comment.