Skip to content

Commit

Permalink
Add conversion to 2.0 (well, partially, for some reason)
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterbos committed Jan 4, 2021
1 parent be673b1 commit 0f31c03
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
9 changes: 5 additions & 4 deletions opt14/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 17 additions & 2 deletions opt14/src/main/java/com/nedap/archie/opt14/Opt14Converter.java
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -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);
}
}
}
5 changes: 3 additions & 2 deletions opt14/src/test/java/com/nedap/archie/opt14/ConverterTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -28,8 +29,8 @@ public void procedureList() throws Exception {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
try(InputStream stream = getClass().getResourceAsStream("/procedure_list.opt")) {
OPERATIONALTEMPLATE opt14 = ((JAXBElement<OPERATIONALTEMPLATE>) 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()));
}
}

Expand Down
22 changes: 22 additions & 0 deletions tools/src/main/java/com/nedap/archie/adl14/ADL14Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Optional;

public class ADL14Converter {

Expand Down Expand Up @@ -67,6 +68,8 @@ public ADL2ConversionResultList convert(List<Archetype> archetypes, ADL2Conversi
for(TemplateOverlay overlay:t.getTemplateOverlays()) {
templateOverlays.add(overlay);
overlay.setRmRelease(t.getRmRelease());
overlay.setOriginalLanguage(t.getOriginalLanguage());
overlay.setTranslationList(t.getTranslationList());
}
}
}
Expand Down Expand Up @@ -109,6 +112,25 @@ public ADL2ConversionResultList convert(List<Archetype> 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<TemplateOverlay> newOverlays = new ArrayList<>();
for(TemplateOverlay overlay:t.getTemplateOverlays()) {
Optional<ADL2ConversionResult> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
}
}
Expand Down

0 comments on commit 0f31c03

Please sign in to comment.