Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Jun 22, 2023
1 parent 1fd3c6c commit d637bec
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
31 changes: 26 additions & 5 deletions src/main/java/org/mitre/synthea/export/flexporter/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public static void createResource(Bundle bundle, List<Map<String, Object>> resou
}

List<String> profiles = (List<String>) newResourceDef.get("profiles");
List<Map<String, Object>> fields = (List<Map<String, Object>>) newResourceDef.get("fields");

List<Base> basedOnResources;
List<Map<String, Object>> writeback;
Expand Down Expand Up @@ -269,13 +270,32 @@ public static void createResource(Bundle bundle, List<Map<String, Object>> resou
basedOnResources.add(dummyEncounter);
}

if (!basedOnResources.isEmpty()) {
// rewrite "State.entered" to "Encounter.period.start", etc
// so that the end user doesn't have to know we used an Encounter

for (Map<String, Object> field : fields) {
Object valueDef = field.get("value");
if (valueDef instanceof String && ((String) valueDef).startsWith("$")) {
String value = (String) valueDef;
if (value.contains("State.")) {
value = value
.replace("State.entered", "Encounter.period.start")
.replace("State.exited", "Encounter.period.end");

field.put("value", value);
}
}
}

}

writeback = null;
} else {
basedOnResources = Collections.singletonList(null);
writeback = null;
}

List<Map<String, Object>> fields = (List<Map<String, Object>>) newResourceDef.get("fields");

for (Base basedOnItem : basedOnResources) {
// IMPORTANT: basedOnItem may be null
Expand Down Expand Up @@ -373,7 +393,8 @@ private static Map<String, Object> createFhirPathMapping(List<Map<String, Object

} else {
// unexpected type here - is it even possible to get anything else?
System.err.println("Unhandled type in createFhirPathMapping: " + valueDef.getClass());
String type = valueDef == null ? "null" : valueDef.getClass().toGenericString();
System.err.println("Unhandled type in createFhirPathMapping: " + type);

Check warning on line 397 in src/main/java/org/mitre/synthea/export/flexporter/Actions.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/mitre/synthea/export/flexporter/Actions.java#L397

Added line #L397 was not covered by tests
}
}

Expand Down Expand Up @@ -405,7 +426,7 @@ private static void populateFhirPathMapping(Map<String, Object> fhirPathMapping,
* @param bundle FHIR Bundle to filter
* @param list List of resource types to retain, all other types not listed will be removed
*/
public static void keepResources(Bundle bundle, List<String> list) {
private static void keepResources(Bundle bundle, List<String> list) {
// TODO: make this FHIRPath instead of just straight resource types

Set<String> resourceTypesToKeep = new HashSet<>(list);
Expand All @@ -430,7 +451,7 @@ public static void keepResources(Bundle bundle, List<String> list) {
}
}

public static void shiftDates(Bundle bundle, String amountString) {
private static void shiftDates(Bundle bundle, String amountString) {
if (amountString == null) {
return;

Check warning on line 456 in src/main/java/org/mitre/synthea/export/flexporter/Actions.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/mitre/synthea/export/flexporter/Actions.java#L456

Added line #L456 was not covered by tests
}
Expand Down Expand Up @@ -463,7 +484,7 @@ public static void shiftDates(Bundle bundle, String amountString) {
}
}

public static void dateFilter(Bundle bundle, String minDateStr, String maxDateStr) {
private static void dateFilter(Bundle bundle, String minDateStr, String maxDateStr) {
if (minDateStr == null && maxDateStr == null) {
return;

Check warning on line 489 in src/main/java/org/mitre/synthea/export/flexporter/Actions.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/mitre/synthea/export/flexporter/Actions.java#L489

Added line #L489 was not covered by tests
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void set(Resource resource, IBase value) {


public static class DateFieldWrapper extends FieldWrapper {

public DateFieldWrapper(String fieldPath) {
super(fieldPath);
}

Check warning on line 92 in src/main/java/org/mitre/synthea/export/flexporter/FieldWrapper.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/mitre/synthea/export/flexporter/FieldWrapper.java#L91-L92

Added lines #L91 - L92 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ public void testCreateResources_createBasedOnState() throws Exception {
# - location: MedicationRequest.medicationCodeableConcept
# value: $getField([Procedure.code])
- location: MedicationRequest.authoredOn
value: $getField([Encounter.period.start])
value: $getField([State.entered])
*/

Resource newResource = entries.get(1).getResource();
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/flexporter/test_mapping.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ actions:
# - location: MedicationRequest.medicationCodeableConcept
# value: $getField([Procedure.code])
- location: MedicationRequest.authoredOn
value: $getField([Encounter.period.start])
value: $getField([State.entered])

- name: testCreateResources_getAttribute
create_resource:
Expand Down

0 comments on commit d637bec

Please sign in to comment.