Skip to content

Commit

Permalink
enable functions nested
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Oct 29, 2024
1 parent 8f40247 commit 814bdd2
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/main/java/org/mitre/synthea/export/flexporter/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,15 @@ private static Map<String, Object> createFhirPathMapping(List<Map<String, Object
} else if (valueDef instanceof Map<?,?>) {
Map<String,Object> valueMap = (Map<String, Object>) valueDef;

populateFhirPathMapping(fhirPathMapping, location, valueMap);
populateFhirPathMapping(fhirPathMapping, location, valueMap, sourceBundle, sourceResource,
person, fjContext);

} else if (valueDef instanceof List<?>) {
List<Object> valueList = (List<Object>) valueDef;

populateFhirPathMapping(fhirPathMapping, location, valueList);
populateFhirPathMapping(fhirPathMapping, location, valueList, sourceBundle, sourceResource,
person, fjContext);

} else {
// unexpected type here - is it even possible to get anything else?
String type = valueDef == null ? "null" : valueDef.getClass().toGenericString();
Expand All @@ -480,21 +483,32 @@ private static Map<String, Object> createFhirPathMapping(List<Map<String, Object
}

private static void populateFhirPathMapping(Map<String, Object> fhirPathMapping, String basePath,
Map<String, Object> valueMap) {
Map<String, Object> valueMap, Bundle sourceBundle, Resource sourceResource, Person person,
FlexporterJavascriptContext fjContext) {
for (Map.Entry<String,Object> entry : valueMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();

String path = basePath + "." + key;

if (value instanceof String) {
String valueString = (String)value;

if (valueString.startsWith("$")) {
value = getValue(sourceBundle, valueString, sourceResource, person, fjContext);
}
}

if (value instanceof String || value instanceof Base) {
fhirPathMapping.put(path, value);
} else if (value instanceof Number) {
fhirPathMapping.put(path, value.toString());
} else if (value instanceof Map<?,?>) {
populateFhirPathMapping(fhirPathMapping, path, (Map<String, Object>) value);
populateFhirPathMapping(fhirPathMapping, path, (Map<String, Object>) value, sourceBundle,
sourceResource, person, fjContext);
} else if (value instanceof List<?>) {
populateFhirPathMapping(fhirPathMapping, path, (List<Object>) value);
populateFhirPathMapping(fhirPathMapping, path, (List<Object>) value, sourceBundle,
sourceResource, person, fjContext);
} else if (value != null) {
System.err
.println("Unexpected class found in populateFhirPathMapping[map]: " + value.getClass());
Expand All @@ -503,20 +517,23 @@ private static void populateFhirPathMapping(Map<String, Object> fhirPathMapping,
}

private static void populateFhirPathMapping(Map<String, Object> fhirPathMapping, String basePath,
List<Object> valueList) {
List<Object> valueList, Bundle sourceBundle, Resource sourceResource, Person person,
FlexporterJavascriptContext fjContext) {
for (int i = 0; i < valueList.size(); i++) {
Object value = valueList.get(i);

String path = basePath + "[" + i + "]";

if (value instanceof String) {
if (value instanceof String || value instanceof Base) {
fhirPathMapping.put(path, value);
} else if (value instanceof Number) {
fhirPathMapping.put(path, value.toString());
} else if (value instanceof Map<?,?>) {
populateFhirPathMapping(fhirPathMapping, path, (Map<String, Object>) value);
populateFhirPathMapping(fhirPathMapping, path, (Map<String, Object>) value, sourceBundle,
sourceResource, person, fjContext);
} else if (value instanceof List<?>) {
populateFhirPathMapping(fhirPathMapping, path, (List<Object>) value);
populateFhirPathMapping(fhirPathMapping, path, (List<Object>) value, sourceBundle,
sourceResource, person, fjContext);
} else if (value != null) {
System.err
.println("Unexpected class found in populateFhirPathMapping[list]:" + value.getClass());
Expand Down

0 comments on commit 814bdd2

Please sign in to comment.