From 0f31c03f75eaeee60afaecd182830917ae1b50b1 Mon Sep 17 00:00:00 2001 From: Pieter Bos Date: Mon, 4 Jan 2021 12:55:22 +0100 Subject: [PATCH] Add conversion to 2.0 (well, partially, for some reason) --- .../adl14/ADL14DescriptionConverter.java | 3 +++ opt14/build.gradle | 9 ++++---- .../nedap/archie/opt14/Opt14Converter.java | 19 ++++++++++++++-- .../com/nedap/archie/opt14/ConverterTest.java | 5 +++-- .../nedap/archie/adl14/ADL14Converter.java | 22 +++++++++++++++++++ .../diff/TerminologyDifferentiator.java | 2 +- 6 files changed, 51 insertions(+), 9 deletions(-) diff --git a/aom/src/main/java/com/nedap/archie/adl14/ADL14DescriptionConverter.java b/aom/src/main/java/com/nedap/archie/adl14/ADL14DescriptionConverter.java index 11d105214..911e8948a 100644 --- a/aom/src/main/java/com/nedap/archie/adl14/ADL14DescriptionConverter.java +++ b/aom/src/main/java/com/nedap/archie/adl14/ADL14DescriptionConverter.java @@ -10,6 +10,9 @@ public class ADL14DescriptionConverter { public void convert(Archetype archetype) { ResourceDescription description = archetype.getDescription(); + if(description == null) { + return; + } description.setLicence(description.getOtherDetails().remove("licence")); description.setOriginalNamespace(description.getOtherDetails().remove("original_namespace")); description.setOriginalPublisher(description.getOtherDetails().remove("original_publisher")); diff --git a/opt14/build.gradle b/opt14/build.gradle index a53b6148f..2feef2b88 100644 --- a/opt14/build.gradle +++ b/opt14/build.gradle @@ -16,11 +16,12 @@ dependencies { compile project(':path-queries') compile project(':utils') compile project(':tools') - testCompile project(':openehr-rm') - testCompile project(':archie-utils') - testCompile project(':i18n') + compile project(':referencemodels') + compile project(':openehr-rm') + compile project(':archie-utils') + compile project(':i18n') testCompile project(':test-rm') - testCompile project(':referencemodels') + xjc "javax.xml.bind:jaxb-api:$jaxbVersion" diff --git a/opt14/src/main/java/com/nedap/archie/opt14/Opt14Converter.java b/opt14/src/main/java/com/nedap/archie/opt14/Opt14Converter.java index 4ad0f1ab4..923034f88 100644 --- a/opt14/src/main/java/com/nedap/archie/opt14/Opt14Converter.java +++ b/opt14/src/main/java/com/nedap/archie/opt14/Opt14Converter.java @@ -1,11 +1,19 @@ package com.nedap.archie.opt14; +import com.google.common.collect.Lists; +import com.nedap.archie.adl14.ADL14Converter; +import com.nedap.archie.adl14.ADL2ConversionResultList; +import com.nedap.archie.adl14.OpenEHRADL14ConversionConfiguration; import com.nedap.archie.aom.ArchetypeHRID; import com.nedap.archie.aom.Template; +import com.nedap.archie.flattener.InMemoryFullArchetypeRepository; +import org.openehr.referencemodels.BuiltinReferenceModels; + +import java.io.IOException; public class Opt14Converter { - public Template convert(OPERATIONALTEMPLATE opt14) { + public ADL2ConversionResultList convert(OPERATIONALTEMPLATE opt14, InMemoryFullArchetypeRepository adl2Archetypes) { Template template = new Template(); template.setArchetypeId(new ArchetypeHRID("openEHR-EHR-" + opt14.getDefinition().getRmTypeName() + "." + opt14.getTemplateId().getValue() + "v1.0.0")); template.setParentArchetypeId(opt14.getDefinition().getArchetypeId().getValue()); @@ -15,6 +23,13 @@ public Template convert(OPERATIONALTEMPLATE opt14) { DescriptionConverter.convert(template, opt14); new DefinitionConverter().convert(template, opt14); - return template; + try { + ADL14Converter converter = new ADL14Converter(BuiltinReferenceModels.getMetaModels(), OpenEHRADL14ConversionConfiguration.getConfig()); + converter.setExistingRepository(adl2Archetypes); + ADL2ConversionResultList converted = converter.convert(Lists.newArrayList(template)); + return converted; + } catch (IOException e) { + throw new RuntimeException(e); + } } } diff --git a/opt14/src/test/java/com/nedap/archie/opt14/ConverterTest.java b/opt14/src/test/java/com/nedap/archie/opt14/ConverterTest.java index 1c4c0342b..8044751ca 100644 --- a/opt14/src/test/java/com/nedap/archie/opt14/ConverterTest.java +++ b/opt14/src/test/java/com/nedap/archie/opt14/ConverterTest.java @@ -1,5 +1,6 @@ package com.nedap.archie.opt14; +import com.nedap.archie.adl14.ADL2ConversionResultList; import com.nedap.archie.adlparser.ADLParser; import com.nedap.archie.aom.Archetype; import com.nedap.archie.aom.Template; @@ -28,8 +29,8 @@ public void procedureList() throws Exception { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); try(InputStream stream = getClass().getResourceAsStream("/procedure_list.opt")) { OPERATIONALTEMPLATE opt14 = ((JAXBElement) unmarshaller.unmarshal(stream)).getValue(); - Template template = new Opt14Converter().convert(opt14); - System.out.println(ADLArchetypeSerializer.serialize(template)); + ADL2ConversionResultList convert = new Opt14Converter().convert(opt14, repository); + System.out.println(ADLArchetypeSerializer.serialize(convert.getConversionResults().get(0).getArchetype())); } } diff --git a/tools/src/main/java/com/nedap/archie/adl14/ADL14Converter.java b/tools/src/main/java/com/nedap/archie/adl14/ADL14Converter.java index 5f5d3e7b7..10a50910c 100644 --- a/tools/src/main/java/com/nedap/archie/adl14/ADL14Converter.java +++ b/tools/src/main/java/com/nedap/archie/adl14/ADL14Converter.java @@ -19,6 +19,7 @@ import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Optional; public class ADL14Converter { @@ -67,6 +68,8 @@ public ADL2ConversionResultList convert(List archetypes, ADL2Conversi for(TemplateOverlay overlay:t.getTemplateOverlays()) { templateOverlays.add(overlay); overlay.setRmRelease(t.getRmRelease()); + overlay.setOriginalLanguage(t.getOriginalLanguage()); + overlay.setTranslationList(t.getTranslationList()); } } } @@ -109,6 +112,25 @@ public ADL2ConversionResultList convert(List archetypes, ADL2Conversi } } + for(ADL2ConversionResult ar:resultList.getConversionResults()) { + //template overlays have been processed as separate archetypes. So combine them here again + if(ar.getArchetype() != null && ar.getArchetype() instanceof Template) { + Template t = (Template) ar.getArchetype(); + + List newOverlays = new ArrayList<>(); + for(TemplateOverlay overlay:t.getTemplateOverlays()) { + Optional convertedOverlay = resultList.getConversionResults().stream().filter(r -> r.getArchetypeId().startsWith(overlay.getArchetypeId().getFullId())).findFirst(); + if(convertedOverlay.isPresent()) { + newOverlays.add((TemplateOverlay) convertedOverlay.get().getArchetype()); + } else { + newOverlays.add(overlay); + //TODO: add error + } + t.setTemplateOverlays(newOverlays); + } + } + } + return resultList; } diff --git a/tools/src/main/java/com/nedap/archie/diff/TerminologyDifferentiator.java b/tools/src/main/java/com/nedap/archie/diff/TerminologyDifferentiator.java index 7085ebeed..4291ba0c7 100644 --- a/tools/src/main/java/com/nedap/archie/diff/TerminologyDifferentiator.java +++ b/tools/src/main/java/com/nedap/archie/diff/TerminologyDifferentiator.java @@ -32,7 +32,7 @@ private void removeAdditionalTranslations(Archetype result) { // so remove all from the terminology that have not been speciafically defined in the archetype resource description List translationsToRemove = new ArrayList<>(); for(String key: result.getTerminology().getTermDefinitions().keySet()) { - if(!result.getTranslations().containsKey(key) && !result.getTerminology().getOriginalLanguage().equals(key)) { + if(!(result.getTranslations() != null && result.getTranslations().containsKey(key)) && !key.equals(result.getTerminology().getOriginalLanguage())) { translationsToRemove.add(key); } }