@@ -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 ) {
0 commit comments