Skip to content

Commit 9b8235e

Browse files
committed
multiple mappings per path possible
1 parent 063202a commit 9b8235e

2 files changed

Lines changed: 57 additions & 49 deletions

File tree

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

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ public static void main(String[] args) throws IOException {
108108
mapper = jm;
109109
}
110110

111-
Settings.getMapping().values().forEach(m -> {
112-
initializeAttribute(m, jm);
113-
});
111+
Settings.getMapping().values().forEach(m -> m.forEach(n -> initializeAttribute(n, jm)));
114112

115113
Logger.info("OpenEhrObds started!");
116114

@@ -173,13 +171,13 @@ public static void main(String[] args) throws IOException {
173171

174172
private static void initializeAttribute(Mapping m, ObjectMapper mapper) {
175173
if (m.getTemplateId() != null) {
176-
OPERATIONALTEMPLATE template;
174+
OPERATIONALTEMPLATE template = null;
177175
if (openEhrClient != null) {
178176
Optional<OPERATIONALTEMPLATE> oTemplate = openEhrClient.templateEndpoint()
179177
.findTemplate(m.getTemplateId());
180-
assert oTemplate.isPresent();
181-
template = oTemplate.get();
182-
} else {
178+
template = oTemplate.orElse(null);
179+
}
180+
if (template == null) {
183181
try {
184182
template = OPERATIONALTEMPLATE.Factory
185183
.parse(new File(new File("templates"), m.getTemplateId() + ".opt"));
@@ -227,7 +225,7 @@ private static void initializeAttribute(Mapping m, ObjectMapper mapper) {
227225
}
228226
}
229227

230-
@SuppressWarnings({"unchecked", "IllegalCatch"})
228+
@SuppressWarnings({ "unchecked", "IllegalCatch" })
231229
public static Map<String, Object> localMap(Set<Entry<String, Object>> xmlSet, String templateId, String path) {
232230
Binding b = new Binding();
233231
GroovyShell s = new GroovyShell(b);
@@ -265,52 +263,61 @@ public static void walkTree(Set<Entry<String, Object>> xmlSet, int depth, String
265263
return;
266264
}
267265

268-
boolean split = Settings.getMapping().containsKey(path) && Settings.getMapping().get(path).getSplit();
269-
boolean global = Settings.getMapping().containsKey(path) && Settings.getMapping().get(path).getGlobal();
270-
boolean update = Settings.getMapping().containsKey(path) && Settings.getMapping().get(path).isUpdate();
271-
272266
Map<String, Object> theMap = resMap;
273267

274-
if (Settings.getMapping().containsKey(path) && Settings.getMapping().get(path).getSource() != null) {
275-
Mapping m = Settings.getMapping().get(path);
268+
if (Settings.getMapping().containsKey(path) && Settings.getMapping().get(path) != null
269+
&& !Settings.getMapping().get(path).isEmpty()) {
276270

277-
Map<String, Object> mapped = localMap(xmlSet, m.getTemplateId(), path);
278-
if (mapped == null) {
279-
return;
280-
}
281-
if (Settings.getCxxmdr() != null) {
282-
mapped.putAll(convertMdr(xmlSet, m));
283-
}
284-
mapped.values().removeIf(Objects::isNull);
285-
Utils.listConv(mapped);
286-
if (Settings.getCxxmdr() != null) {
287-
mapped.entrySet().forEach(e -> FhirUtils.queryFhirTs(FHIR_ATTRIBUTES, m, e, fr));
288-
}
289-
mapped.values().removeIf(Objects::isNull);
290-
Map<String, Object> result = Utils.formatMap(mapped);
271+
for (Mapping m : Settings.getMapping().get(path)) {
291272

292-
boolean done = ((List<Boolean>) result.getOrDefault("done", List.of(true))).get(0);
273+
if (m.getSource() == null) {
274+
continue;
275+
}
293276

294-
if (global || !done) {
295-
Generator.deepMergeNoReplace(resMap, result);
296-
theMap = resMap;
297-
} else {
298-
Generator.deepMergeNoReplace(result, resMap);
299-
theMap = result;
300-
}
277+
boolean split = m.getSplit();
278+
boolean global = m.getGlobal();
279+
boolean update = m.isUpdate();
301280

302-
if (update && result.containsKey("delete")
303-
&& Boolean.TRUE.equals(((List<Boolean>) result.get("delete")).getFirst())) {
304-
Logger.info("Found DELETE entry, trying to delete composition...");
305-
OpenEhrUtils.deleteOpenEhrComposition(openEhrClient, AQLS, m.getTemplateId(),
306-
((List<String>) result.get("identifier")).getFirst());
307-
return;
308-
}
281+
Map<String, Object> mapped = localMap(xmlSet, m.getTemplateId(), path);
282+
if (mapped == null) {
283+
return;
284+
}
285+
if (Settings.getCxxmdr() != null) {
286+
mapped.putAll(convertMdr(xmlSet, m));
287+
}
288+
mapped.values().removeIf(Objects::isNull);
289+
Utils.listConv(mapped);
290+
if (Settings.getCxxmdr() != null) {
291+
mapped.entrySet().forEach(e -> FhirUtils.queryFhirTs(FHIR_ATTRIBUTES, m, e, fr));
292+
}
293+
mapped.values().removeIf(Objects::isNull);
294+
Map<String, Object> result = Utils.formatMap(mapped);
295+
296+
boolean done = ((List<Boolean>) result.getOrDefault("done", List.of(true))).get(0);
297+
298+
if (global || !done) {
299+
Generator.deepMergeNoReplace(resMap, result);
300+
theMap = resMap;
301+
} else {
302+
Generator.deepMergeNoReplace(result, resMap);
303+
theMap = result;
304+
}
305+
306+
if (update && result.containsKey("delete")
307+
&& Boolean.TRUE.equals(((List<Boolean>) result.get("delete")).getFirst())) {
308+
Logger.info("Found DELETE entry, trying to delete composition...");
309+
OpenEhrUtils.deleteOpenEhrComposition(openEhrClient, AQLS, m.getTemplateId(),
310+
((List<String>) result.get("identifier")).getFirst());
311+
return;
312+
}
313+
314+
if (split && done) {
315+
Logger.info("Building composition.");
316+
buildOpenEhrComposition(m.getTemplateId(), theMap);
317+
}
309318

310-
if (split && done) {
311-
Logger.info("Building composition.");
312-
buildOpenEhrComposition(m.getTemplateId(), theMap);
313319
}
320+
314321
}
315322

316323
for (Entry<String, Object> entry : xmlSet) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.annotation.JsonProperty;
55
import java.net.URI;
66
import java.net.URL;
7+
import java.util.List;
78
import java.util.Map;
89

910
/**
@@ -20,7 +21,7 @@ public final class Settings {
2021
private static String mode;
2122
private static CxxMdrSettings cxxmdr;
2223
private static KafkaSettings kafka;
23-
private static Map<String, Mapping> mapping;
24+
private static Map<String, List<Mapping>> mapping;
2425
private static int depthLimit;
2526
private static String systemId;
2627
private static boolean dev;
@@ -109,12 +110,12 @@ public void setKafkaSettings(KafkaSettings newKafka) {
109110
kafka = newKafka;
110111
}
111112

112-
public static Map<String, Mapping> getMapping() {
113+
public static Map<String, List<Mapping>> getMapping() {
113114
return mapping;
114115
}
115116

116117
@JsonProperty("mapping")
117-
public void setMapping(Map<String, Mapping> newMapping) {
118+
public void setMapping(Map<String, List<Mapping>> newMapping) {
118119
mapping = newMapping;
119120
}
120121

0 commit comments

Comments
 (0)