Skip to content

Commit

Permalink
Cleanup ADL14Converter code (#648)
Browse files Browse the repository at this point in the history
* Remove unused setExistingRepository method

* Add documentation to DescriptionConverter

* remove commented code and add to documentation of DefaultMultiplicitiesSetter

* Cleanup ConversionResult

* cleanup DefaultRmStructureRemover

* Rename ArchetypeParsePostProcessor and formatting

* Cleanup ADL14NodeIDConverter

* Update faulty comment about default occurrences

* Set back javadoc comment

* revert removing setExistingRepository method and add comment about it being part of the public API

* change javadoc comment formatting
  • Loading branch information
VeraPrinsen authored Jan 16, 2025
1 parent b7fbc56 commit 2e07d73
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import com.nedap.archie.rminfo.MetaModels;

/**
* Sets the default occurrences with ADL 1.4 rules, if not explicitly set in a given Archetype.
* Sets the default occurrences with ADL 1.4 rules ({1..1}), if not explicitly set in a given Archetype.
* Useful for conversion to ADL 2, where the default values are different, and it is good to start
* with the correct values already present.
*
* <p>
* Cardinality and existence are also specified to have a default value. However, this is not used
* in practice (source, several openEHR community members). Adding that to the conversion would
* lead to problems. So these are left out.
Expand All @@ -31,20 +31,9 @@ public void setDefaults(Archetype archetype) {
}

private void correctItemsMultiplicities(CObject cObject) {
for(CAttribute attribute:cObject.getAttributes()) {
// according to the specification, the following lines must be added.
// however, in practice this is not followed, and adding it would
// lead to more problems
/*
if(attribute.getCardinality() == null) {
attribute.setCardinality(new Cardinality(0, 1));
}
if(attribute.getExistence() == null) {
attribute.setExistence(new MultiplicityInterval(1, 1));
}*/
for(CObject child:attribute.getChildren()) {
if(child.getOccurrences() == null &&
metaModels.isMultiple(cObject.getRmTypeName(), attribute.getRmAttributeName())) {
for (CAttribute attribute : cObject.getAttributes()) {
for (CObject child : attribute.getChildren()) {
if (child.getOccurrences() == null && metaModels.isMultiple(cObject.getRmTypeName(), attribute.getRmAttributeName())) {
child.setOccurrences(new MultiplicityInterval(1, 1));
}
correctItemsMultiplicities(child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import java.util.LinkedHashMap;
import java.util.Map;

/**
* Converts the Description section from ADL1.4 to ADL2
* <a href="https://specifications.openehr.org/releases/AM/latest/ADL1.4.html#_description_section">Specifications ADL1.4</a>
* <a href="https://specifications.openehr.org/releases/AM/Release-2.3.0/ADL2.html#_description_section">Specifications ADL2</a>
*/
public class ADL14DescriptionConverter {

public void convert(Archetype archetype) {
Expand Down Expand Up @@ -44,12 +49,10 @@ public void convert(Archetype archetype) {
}
description.setIpAcknowledgements(acknowledgements);
}

String revision = description.getOtherDetails().remove("revision");
if(revision != null) {
archetype.getArchetypeId().setReleaseVersion(revision);
}

archetype.setGenerated(true);
}
}
271 changes: 140 additions & 131 deletions aom/src/main/java/com/nedap/archie/adl14/ADL14NodeIDConverter.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions aom/src/main/java/com/nedap/archie/adl14/ADL14Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.nedap.archie.antlr.errors.ANTLRParserErrors;
import com.nedap.archie.antlr.errors.ArchieErrorListener;
import com.nedap.archie.aom.Archetype;
import com.nedap.archie.aom.utils.ArchetypeParsePostProcesser;
import com.nedap.archie.aom.utils.ArchetypeParsePostProcessor;
import com.nedap.archie.rminfo.MetaModels;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
Expand Down Expand Up @@ -74,7 +74,7 @@ public Archetype parse(CharStream stream, ADL14ConversionConfiguration conversio
walker = new ParseTreeWalker();
walker.walk(listener, tree);
result = listener.getArchetype();
ArchetypeParsePostProcesser.fixArchetype(result);
ArchetypeParsePostProcessor.fixArchetype(result);
if (metaModels != null) {
metaModels.selectModel(result);
if (metaModels.getSelectedBmmModel() != null) {
Expand Down
38 changes: 10 additions & 28 deletions aom/src/main/java/com/nedap/archie/adl14/ADL2ConversionResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* ADL 2 conversion result. Always has the archetypeId field set.
* Either has archetype and conversionLog non-null in case of a succesful conversion, or
* Either has archetype and conversionLog non-null in case of a successful conversion, or
* exception non-null in case of an unexpected Exception
*/
public class ADL2ConversionResult {
Expand All @@ -18,24 +18,14 @@ public class ADL2ConversionResult {
private MessageLogger log;
private Exception exception;

/**
* empty constructor for JSON parsing. Do not use
*/
/** Empty construction for Jackson parsing, do not use */
public ADL2ConversionResult() {

}

public ADL2ConversionResult(Archetype archetype) {
this.archetypeId = archetype.getArchetypeId().getFullId();
this(archetype.getArchetypeId().getFullId(), null);
this.archetype = archetype;
log = new MessageLogger();
}

public ADL2ConversionResult(Archetype archetype, ADL2ConversionLog conversionLog) {
this.archetypeId = archetype.getArchetypeId().getFullId();
this.archetype = archetype;
this.conversionLog = conversionLog;
log = new MessageLogger();
}

public ADL2ConversionResult(String archetypeId, Exception exception) {
Expand All @@ -44,14 +34,11 @@ public ADL2ConversionResult(String archetypeId, Exception exception) {
log = new MessageLogger();
}

/* GETTERS **/
public String getArchetypeId() {
return archetypeId;
}

public void setArchetypeId(String archetypeId) {
this.archetypeId = archetypeId;
}

public Archetype getArchetype() {
return archetype;
}
Expand All @@ -60,14 +47,6 @@ public ADL2ConversionLog getConversionLog() {
return conversionLog;
}

public void setConversionLog(ADL2ConversionLog conversionLog) {
this.conversionLog = conversionLog;
}

public void setArchetype(Archetype archetype) {
this.archetype = archetype;
}

public MessageLogger getLog() {
return log;
}
Expand All @@ -76,9 +55,12 @@ public Exception getException() {
return exception;
}

public void setException(Exception exception) {
this.exception = exception;
/* SETTERS **/
public void setArchetype(Archetype archetype) {
this.archetype = archetype;
}


public void setConversionLog(ADL2ConversionLog conversionLog) {
this.conversionLog = conversionLog;
}
}
4 changes: 2 additions & 2 deletions aom/src/main/java/com/nedap/archie/adlparser/ADLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.nedap.archie.antlr.errors.ArchieErrorListener;
import com.nedap.archie.antlr.errors.ANTLRParserErrors;
import com.nedap.archie.aom.Archetype;
import com.nedap.archie.aom.utils.ArchetypeParsePostProcesser;
import com.nedap.archie.aom.utils.ArchetypeParsePostProcessor;
import com.nedap.archie.rminfo.MetaModels;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.*;
Expand Down Expand Up @@ -97,7 +97,7 @@ public Archetype parse(CharStream stream) throws ADLParseException {
walker.walk(listener, tree);
result = listener.getArchetype();
//set some values that are not directly in ODIN or ADL
ArchetypeParsePostProcesser.fixArchetype(result);
ArchetypeParsePostProcessor.fixArchetype(result);

if (modelConstraintImposer != null && result.getDefinition() != null) {
modelConstraintImposer.imposeConstraints(result.getDefinition());
Expand Down
4 changes: 2 additions & 2 deletions aom/src/main/java/com/nedap/archie/aom/Archetype.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.nedap.archie.aom.terminology.ArchetypeTerminology;
import com.nedap.archie.aom.terminology.ValueSet;
import com.nedap.archie.aom.utils.AOMUtils;
import com.nedap.archie.aom.utils.ArchetypeParsePostProcesser;
import com.nedap.archie.aom.utils.ArchetypeParsePostProcessor;
import com.nedap.archie.definitions.AdlCodeDefinitions;
import com.nedap.archie.query.AOMPathQuery;
import com.nedap.archie.rminfo.RMProperty;
Expand Down Expand Up @@ -236,7 +236,7 @@ public Archetype clone() {

Archetype result = (Archetype) super.clone();
//fix some things that are not handled automatically
ArchetypeParsePostProcesser.fixArchetype(result);
ArchetypeParsePostProcessor.fixArchetype(result);
return result;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
/**
* Sets some values that are not directly in ADL or ODIN, such as original language in terminology, etc.
*/
public class ArchetypeParsePostProcesser {
public class ArchetypeParsePostProcessor {

public static void fixArchetype(Archetype archetype) {
if(archetype.getTerminology() != null) {
if (archetype.getTerminology() != null) {
ArchetypeTerminology terminology = archetype.getTerminology();
//codes are in model, but do not appear in odin. Set them here
fillArchetypeTermCodes(terminology.getTermDefinitions());
Expand All @@ -37,33 +37,33 @@ public static void fixArchetype(Archetype archetype) {
private static void setParents(Archetype archetype) {
Stack<CObject> workList = new Stack<>();
workList.add(archetype.getDefinition());
while(!workList.empty()) {
while (!workList.empty()) {
CObject cObject = workList.pop();
if(cObject instanceof CPrimitiveObject) {
if (cObject instanceof CPrimitiveObject) {
cObject.setNodeId("id9999");//also in the implementation, but check to be sure
}
for(CAttribute attribute:cObject.getAttributes()) {
for (CAttribute attribute : cObject.getAttributes()) {

attribute.setParent(cObject);
for(CObject child:attribute.getChildren()) {
for (CObject child : attribute.getChildren()) {
child.setParent(attribute);
}
workList.addAll(attribute.getChildren());
}
if(cObject instanceof CComplexObject) {
if (cObject instanceof CComplexObject) {
//TODO: fix tuple so it has proper multiple references to the separate structures, instead of a complete duplication of data in json
CComplexObject cComplexObject = (CComplexObject) cObject;
for(CAttributeTuple tuple: cComplexObject.getAttributeTuples()) {
for(CAttribute attribute:tuple.getMembers()) {
for (CAttributeTuple tuple : cComplexObject.getAttributeTuples()) {
for (CAttribute attribute : tuple.getMembers()) {
attribute.setSocParent(tuple);
attribute.setParent(cObject);
workList.addAll(attribute.getChildren());
cComplexObject.replaceAttribute(attribute);
}
for(CPrimitiveTuple primitiveTuple:tuple.getTuples()) {
for (CPrimitiveTuple primitiveTuple : tuple.getTuples()) {
int index = 0;
for(CPrimitiveObject<?, ?> object:primitiveTuple.getMembers()) {
if(index < tuple.getMembers().size()) {
for (CPrimitiveObject<?, ?> object : primitiveTuple.getMembers()) {
if (index < tuple.getMembers().size()) {
CAttribute attribute = tuple.getMember(index);
object.setSocParent(primitiveTuple);
object.setParent(attribute);
Expand All @@ -79,9 +79,9 @@ private static void setParents(Archetype archetype) {
}

private static void fillArchetypeTermCodes(Map<String, Map<String, ArchetypeTerm>> termSet) {
if(termSet != null) {
for(Map<String, ArchetypeTerm> language:termSet.values()) {
for(String term:language.keySet()) {
if (termSet != null) {
for (Map<String, ArchetypeTerm> language : termSet.values()) {
for (String term : language.keySet()) {
language.get(term).setCode(term);
}
}
Expand Down
Loading

0 comments on commit 2e07d73

Please sign in to comment.