Skip to content

Commit

Permalink
Adds uuid to the list of primitive types (google#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
bashir2 authored Feb 9, 2024
1 parent c2b76f2 commit 9708fb0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public Schema getDataType() {
.put("markdown", STRING_CONVERTER)
.put("date", DATE_CONVERTER)
.put("instant", DATE_CONVERTER)
.put("datetime", DATE_CONVERTER)
.put("dateTime", DATE_CONVERTER)
.put("time", STRING_CONVERTER)
.put("string", STRING_CONVERTER)
Expand All @@ -127,8 +126,6 @@ public Schema getDataType() {
.put("http://hl7.org/fhirpath/System.Decimal", DOUBLE_CONVERTER)
.put("http://hl7.org/fhirpath/System.DateTime", DATE_CONVERTER)
.put("http://hl7.org/fhirpath/System.Time", STRING_CONVERTER)
// TODO add the following converter; in the standard R4 implementation this seems missing!
// .put("http://hl7.org/fhirpath/System.Quantity", ?)
.put("canonical", STRING_CONVERTER)
.put("url", STRING_CONVERTER)
.put("uuid", STRING_CONVERTER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Provenance;
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.Task;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -45,6 +46,12 @@ public class R4AvroConverterTest {

private static Observation testObservationDecoded;

private static final Task testTask = TestData.newTask();

private static Record avroTask;

private static Task testTaskDecoded;

private static final Observation testObservationNullStatus =
TestData.newObservation().setStatus(Observation.ObservationStatus.NULL);

Expand Down Expand Up @@ -108,6 +115,12 @@ public static void convertTestData() throws IOException {
testObservationDecodedNullStatus =
(Observation) observationConverter.avroToResource(avroObservationNullStatus);

AvroConverter taskConverter = AvroConverter.forResource(FhirContexts.forR4(), "Task");

avroTask = (Record) taskConverter.resourceToAvro(testTask);

testTaskDecoded = (Task) taskConverter.avroToResource(avroTask);

AvroConverter patientConverter =
AvroConverter.forResource(FhirContexts.forR4(), TestData.US_CORE_PATIENT);

Expand Down Expand Up @@ -169,6 +182,19 @@ public void testDecimal() {
originalDecimal.compareTo(((Quantity) testObservationDecoded.getValue()).getValue()), 0);
}

@Test
public void testTaskConversion() {
Assert.assertEquals(testTask.getInput().size(), testTaskDecoded.getInput().size());
Assert.assertEquals(testTask.getInput().size(), 1);
Assert.assertEquals(
testTask.getInput().get(0).getType().getCoding().get(0).getSystem(),
testTaskDecoded.getInput().get(0).getType().getCoding().get(0).getSystem());
Assert.assertEquals(
testTask.getInput().get(0).getValue().primitiveValue(),
testTaskDecoded.getInput().get(0).getValue().primitiveValue());
Assert.assertEquals(testTask.getOutput().size(), testTaskDecoded.getOutput().size());
}

@Test
public void testPrimitiveMultiplicity() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cerner.bunsen.avro.converters;

import com.cerner.bunsen.definitions.StructureDefinitions;
import org.junit.Assert;
import org.junit.Test;

public class DefinitionToAvroVisitorTest {

@Test
public void checkPrimitivesMap() {
Assert.assertEquals(
DefinitionToAvroVisitor.TYPE_TO_CONVERTER.keySet(), StructureDefinitions.PRIMITIVE_TYPES);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.Task;
import org.hl7.fhir.r4.model.Timing;
import org.hl7.fhir.r4.model.Timing.TimingRepeatComponent;
import org.hl7.fhir.utilities.xhtml.NodeType;
Expand Down Expand Up @@ -183,6 +184,24 @@ public static Observation newObservation() {
return observation;
}

public static Task newTask() {
Task task = new Task();

task.setId("my-task");

CodeableConcept taskCode = new CodeableConcept();
taskCode.addCoding().setSystem("test-system");

Task.ParameterComponent input = task.addInput();
input.setType(taskCode);
input.setValue(new IntegerType(12));
Task.TaskOutputComponent output = task.addOutput();
output.setType(taskCode);
output.setValue(new IntegerType(13));

return task;
}

/**
* Returns a new Patient for testing.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Verify;
import com.google.common.collect.ImmutableSet;
import java.lang.reflect.Constructor;
Expand All @@ -21,37 +22,37 @@
public abstract class StructureDefinitions {

// TODO make this FHIR version specific and hide it under an abstract method.
protected static final Set<String> PRIMITIVE_TYPES =
@VisibleForTesting
public static final Set<String> PRIMITIVE_TYPES =
ImmutableSet.<String>builder()
.add("id")
.add("boolean")
.add("code")
.add("markdown")
.add("date")
.add("instant")
.add("datetime")
.add("dateTime")
.add("time")
.add("oid")
.add("string")
.add("oid")
.add("xhtml")
.add("decimal")
.add("integer")
.add("xhtml")
.add("unsignedInt")
.add("positiveInt")
.add("base64Binary")
.add("uri")
// TODO: Figure out why these are added to R4 resource definitions.
.add("http://hl7.org/fhirpath/System.Boolean")
.add("http://hl7.org/fhirpath/System.String")
.add("http://hl7.org/fhirpath/System.Boolean")
.add("http://hl7.org/fhirpath/System.Integer")
.add("http://hl7.org/fhirpath/System.Long")
.add("http://hl7.org/fhirpath/System.Decimal")
.add("http://hl7.org/fhirpath/System.DateTime")
.add("http://hl7.org/fhirpath/System.Time")
.add("http://hl7.org/fhirpath/System.Quantity")
.add("canonical")
.add("url")
.add("uuid")
.build();

private static final String STU3_DEFINITIONS_CLASS =
Expand Down

0 comments on commit 9708fb0

Please sign in to comment.