Skip to content

Commit

Permalink
testing with primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Mar 6, 2024
1 parent 32e75d9 commit 47fc1a9
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -417,7 +417,8 @@ private static Map<String, Object> createFhirPathMapping(List<Map<String, Object
Bundle sourceBundle, Resource sourceResource, Person person,
FlexporterJavascriptContext fjContext) {

Map<String, Object> fhirPathMapping = new HashMap<>();
// linked hashmap to ensure lists are kept in order. could also use something like a treemap
Map<String, Object> fhirPathMapping = new LinkedHashMap<>();

for (Map<String, Object> field : fields) {
String location = (String)field.get("location");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,9 @@ private void handleIndexFunctionNode(ExpressionNode fhirPath) {

nextTier.nodes.add(containedNodes.get(index));
}

} else if (nextTier.nodeDefinition instanceof RuntimePrimitiveDatatypeDefinition) {
// TODO: is this possible or necessary?
// review handlePrimitiveNode()
}
// else if (nextTier.nodeDefinition instanceof RuntimePrimitiveDatatypeDefinition) {
// from testing this seems to not be necessary

// push the created nextTier to the nodeStack
this.nodeStack.push(nextTier);
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/mitre/synthea/export/flexporter/ActionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Claim;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.DateType;
import org.hl7.fhir.r4.model.Encounter;
import org.hl7.fhir.r4.model.Enumeration;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.Immunization;
Expand All @@ -40,6 +42,9 @@
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Period;
import org.hl7.fhir.r4.model.PositiveIntType;
import org.hl7.fhir.r4.model.PractitionerRole;
import org.hl7.fhir.r4.model.PractitionerRole.DaysOfWeek;
import org.hl7.fhir.r4.model.Procedure;
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.Resource;
Expand Down Expand Up @@ -352,6 +357,40 @@ void testSetValues_encounter_common(String actionName) {
assertTrue(seen355);
}

@Test
public void testSetValues_listOfPrimitives() {
Map<String, Object> action = getActionByName("testSetValues_listOfPrimitives");

PractitionerRole pr = new PractitionerRole();
Claim c = new Claim();
Bundle b = new Bundle();
b.addEntry().setResource(pr);
b.addEntry().setResource(c);

Actions.applyAction(b, action, null, null);

assertEquals(1, pr.getAvailableTime().size());

List<Enumeration<DaysOfWeek>> daysOfWeek = pr.getAvailableTimeFirstRep().getDaysOfWeek();
assertEquals(3, daysOfWeek.size());

assertEquals(DaysOfWeek.WED, daysOfWeek.get(0).getValue());
assertEquals(DaysOfWeek.THU, daysOfWeek.get(1).getValue());
assertEquals(DaysOfWeek.FRI, daysOfWeek.get(2).getValue());

assertEquals(1, c.getItem().size());
Claim.ItemComponent item = c.getItemFirstRep();

List<PositiveIntType> diagnosisSequence = item.getDiagnosisSequence();
assertEquals(6, diagnosisSequence.size());
assertEquals(1, diagnosisSequence.get(0).getValue().intValue());
assertEquals(1, diagnosisSequence.get(1).getValue().intValue());
assertEquals(2, diagnosisSequence.get(2).getValue().intValue());
assertEquals(3, diagnosisSequence.get(3).getValue().intValue());
assertEquals(5, diagnosisSequence.get(4).getValue().intValue());
assertEquals(8, diagnosisSequence.get(5).getValue().intValue());
}

@Test
public void testSetValues_deeplyNested() {
Map<String, Object> action = getActionByName("testSetValues_deeplyNested");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.hl7.fhir.r4.model.HumanName.NameUse;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.StringType;
import org.junit.Ignore;
import org.junit.Test;
import org.mitre.synthea.export.FhirR4;

Expand Down Expand Up @@ -70,20 +69,13 @@ public void testArray1() {
assertEquals("Bob", given.get(1).getValueAsString());
}


@Ignore
@Test
public void testArray2() {
Map<String, Object> fhirPathMapping = new HashMap<>();

fhirPathMapping.put("Patient.name[0].given", "Billy");
fhirPathMapping.put("Patient.name[1].given", "Bob");

// TODO: for some reason Patient.name.given[0] and given[1] work as expected (2 name strings in
// the 'given' array)
// but Patient.name[0].given and .name[1].given do not (same result, expected was 2 HumanName
// objects in the name array)

Patient patient = createPatient(fhirPathMapping);

List<HumanName> name = patient.getName();
Expand Down
23 changes: 22 additions & 1 deletion src/test/resources/flexporter/test_mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,28 @@ actions:
- system: http://terminology.hl7.org/CodeSystem/service-type
code: "355"



- name: testSetValues_listOfPrimitives
set_values:
- applicability: PractitionerRole
fields:
- location: PractitionerRole.availableTime.daysOfWeek
value:
- "wed"
- "thu"
- "fri"
- applicability: Claim
fields:
- location: Claim.item.diagnosisSequence
value:
- 1
- 1
- 2
- 3
- 5
- 8


- name: testSetValues_deeplyNested
set_values:
- applicability: Observation
Expand Down

0 comments on commit 47fc1a9

Please sign in to comment.