Skip to content

Commit fa90bbf

Browse files
committed
add mapping of lists
1 parent b99b1a6 commit fa90bbf

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/main/java/de/uksh/medic/etl/OpenEhrObds.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,26 @@ public static void walkTree(Set<Entry<String, Object>> xmlSet, int depth, String
376376

377377
switch (entry.getValue()) {
378378
case @SuppressWarnings("rawtypes") Map h -> {
379-
walkTree(h.entrySet(), newDepth, newPath, theMap);
379+
if (Settings.getMapping().getOrDefault(newPath, new ArrayList<>()).size() == 1
380+
&& Settings.getMapping().get(newPath).get(0).isList()) {
381+
Map<String, Object> tmpList = new HashMap<>();
382+
tmpList.put("list", List.of(h));
383+
walkTree(tmpList.entrySet(), newDepth, newPath, theMap);
384+
} else {
385+
walkTree(h.entrySet(), newDepth, newPath, theMap);
386+
}
380387
}
381388
case @SuppressWarnings("rawtypes") List a -> {
382-
for (Object b : a) {
383-
if (b instanceof Map) {
384-
walkTree(((Map<String, Object>) b).entrySet(), newDepth, newPath, theMap);
389+
if (Settings.getMapping().get(newPath).size() == 1
390+
&& Settings.getMapping().get(newPath).get(0).isList()) {
391+
Map<String, Object> tmpList = new HashMap<>();
392+
tmpList.put("list", a);
393+
walkTree(tmpList.entrySet(), newDepth, newPath, theMap);
394+
} else {
395+
for (Object b : a) {
396+
if (b instanceof Map) {
397+
walkTree(((Map<String, Object>) b).entrySet(), newDepth, newPath, theMap);
398+
}
385399
}
386400
}
387401
}

src/main/java/de/uksh/medic/etl/settings/Mapping.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Mapping {
1313
private boolean global;
1414
private String templateId;
1515
private boolean update;
16+
private boolean list;
1617

1718
public String getSource() {
1819
return source;
@@ -77,4 +78,12 @@ public boolean isUpdate() {
7778
public void setUpdate(boolean update) {
7879
this.update = update;
7980
}
81+
82+
public boolean isList() {
83+
return list;
84+
}
85+
86+
public void setList(boolean list) {
87+
this.list = list;
88+
}
8089
}

0 commit comments

Comments
 (0)