Mentions légales du service

Skip to content
Snippets Groups Projects
Commit e0464084 authored by Achraf Achkari's avatar Achraf Achkari
Browse files

[GOC-247] Fix cardinality processing and use extended element provided in BBR...

[GOC-247] Fix cardinality processing and use extended element provided in BBR for computation and generalize DataType distinguiser process for all elements with same name.
parent 4b47b23e
No related branches found
No related tags found
3 merge requests!36[GOC-247] Fix cardinality processing and use extended element provided in BBR...,!35[GOC-247] Fix cardinality processing and use extended element provided in BBR...,!33Draft: Develop
Showing
with 73 additions and 36 deletions
......@@ -25,9 +25,6 @@ public abstract class ChoiceDefinitionProcessorImpl implements ChoiceDefinitionP
this.processMinimumMultiplicity(t.getMinimumMultiplicity());
this.processContains(ChoiceDefinitionUtil.getContains(t));
this.processItem(t.getItem());
//Comment next line to disable processing of the unsported HL7 choices specs
//this.processPredicates(ChoiceDefinitionUtil.getElements(t));
}
}
......@@ -72,6 +69,7 @@ public abstract class ChoiceDefinitionProcessorImpl implements ChoiceDefinitionP
}
@Override
@Deprecated(since = "3.1.0", forRemoval = true)
public void processPredicates(List<RuleDefinition> elements) {
// to be overrided if needed to
}
......
......@@ -189,6 +189,7 @@ public class ChoiceDefinitionAnalyzer extends ChoiceDefinitionProcessorImpl {
* NOTICE: this method does not process numbered predicates due to a lack of functional specifications for the CDA
* @param elements elements in the ChoiceDefinition
*/
@Deprecated(since = "3.1.0", forRemoval = true)
@Override
public void processPredicates(List<RuleDefinition> elements){
......@@ -381,7 +382,7 @@ public class ChoiceDefinitionAnalyzer extends ChoiceDefinitionProcessorImpl {
}
public List<List<OwnedRule>> generateSubRuleOfElements(List<RuleDefinition> elements){
private List<List<OwnedRule>> generateSubRuleOfElements(List<RuleDefinition> elements){
List<List<OwnedRule>> rules = new ArrayList<>();
log.info("processing {} element in choices", Integer.valueOf(elements.size()));
for(RuleDefinition element:elements){
......@@ -416,7 +417,7 @@ public class ChoiceDefinitionAnalyzer extends ChoiceDefinitionProcessorImpl {
return rules;
}
public List<OwnedRule> generateRulesOfAssertionElements(RuleDefinition element){
private List<OwnedRule> generateRulesOfAssertionElements(RuleDefinition element){
String test = AssertUtil.extractAssertFromName(element.getName());
if(test == null){
ProblemHandler.handleRuleDefinitionError((RuleDefinition)element.getParentObject(),
......
......@@ -15,7 +15,6 @@ import net.ihe.gazelle.tempmodel.dpath.utils.DPathExtractor;
import net.ihe.gazelle.tempmodel.org.decor.art.behavior.HasItem;
import net.ihe.gazelle.tempmodel.org.decor.art.model.*;
import net.ihe.gazelle.tempmodel.org.decor.art.utils.*;
import org.eclipse.uml2.uml.DataType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -141,19 +140,18 @@ public class RuleDefinitionAnalyzer extends RuleDefinitionProcessorImpl {
AnalyzerEnum.RULE_DEF_GENERAL_PROCESS.getValue());
return;
}
this.currentPackagedElement = (PackagedElement) objects[0];
this.selectedRuleDefinition = ruleDefinition;
Object parentRule = this.selectedRuleDefinition.getParentObject();
if(parentRule instanceof ChoiceDefinition){
this.generateDTDistinguisher = (RuleDefinitionDistinguisherUtil.elementsShouldBeDistinguisedWithDT((ChoiceDefinition) parentRule));
boolean isTemplateId = (this.selectedRuleDefinition.getName().matches(".*:templateId") || this.selectedRuleDefinition.getName().matches("templateId"));
if (this.ignoreTemplateIdRequirements.booleanValue() && this.selectedRuleDefinition.getName() != null && isTemplateId) {
return;
}
this.currentPackagedElement = (PackagedElement) objects[0];
if(!isTemplateId){
this.generateDTDistinguisher = (RuleDefinitionDistinguisherUtil.elementShouldBeDistinguisedByDT(this.selectedRuleDefinition, this.selectedRuleDefinition.getParentObject()));
}
if (objects.length > 1) {
this.ignoreTemplateIdRequirements = (Boolean) objects[1];
}
if (this.ignoreTemplateIdRequirements.booleanValue() && this.selectedRuleDefinition.getName() != null &&
(this.selectedRuleDefinition.getName().matches(".*:templateId") || this.selectedRuleDefinition.getName().matches("templateId"))) {
return;
}
// catch error in numbered predicates
if (!RuleDefinitionProblemUtil.verifyIfRuleDefinitionIsTreatable(this.selectedRuleDefinition)) {
String name = selectedRuleDefinition != null ? selectedRuleDefinition.getName() : null;
......@@ -423,11 +421,6 @@ public class RuleDefinitionAnalyzer extends RuleDefinitionProcessorImpl {
@UsedByArtDecor
@Override
public void processMinimumMultiplicity(Integer minimumMultiplicity) {
// TODO: 23/12/2021 Highly need to be reviewed
// if (this.ignoreMinCardinality()) {
// // this is the case where the RuleDefinition is included in a choice
// return;
// }
if (checkIfConstraintCanBeGeneratedForMinimumMultiplicity(minimumMultiplicity, this.selectedRuleDefinition)) {
if (!(this.selectedRuleDefinition.getParentObject() instanceof TemplateDefinition)) {
fulfillOwnedRuleForConstraintGenerator((new RDMinimumMultiplicityAnalyzer(this.generateDTDistinguisher)), this.currentPackagedElement, OwnedRuleKind.CARDINALITY,
......@@ -536,9 +529,6 @@ public class RuleDefinitionAnalyzer extends RuleDefinitionProcessorImpl {
if (constraintGenerator == null) {
return;
}
// if(this.generateDTDistinguisher && constraintGenerator instanceof RDDatatypeAnalyzer){
// return;
// }
OwnedRule ownedRule = OwnedRuleUtil.initOwnedRule();
ownedRule.setConstrainedElement(pe.getId());
String specification = constraintGenerator.generateOCLConstraint(this.selectedRuleDefinition);
......@@ -579,6 +569,7 @@ public class RuleDefinitionAnalyzer extends RuleDefinitionProcessorImpl {
* @param pe temporary package used to grab all sub elements rules
* @return returns a list of ownedRules for the ruleDefinition itself and sub elements
*/
@Deprecated(since = "3.1.0", forRemoval = true)
public List<OwnedRule> processAndReturn(RuleDefinition ruleDefinition, PackagedElement pe){
if(pe == null){
pe = PackagedElementUtil.initPackagedElement();
......@@ -589,7 +580,7 @@ public class RuleDefinitionAnalyzer extends RuleDefinitionProcessorImpl {
if(pe.getOwnedRule().size() == 0){
return null;
};
}
//Clean TAML
for(OwnedRule or:pe.getOwnedRule()){
......
package net.ihe.gazelle.tempgen.action;
import net.ihe.gazelle.tempmodel.decor.dt.utils.DTUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -24,12 +25,15 @@ public class UMLElementsManager {
* @param indexParam index
* @return int
*/
public int getMaxAttribute(DParent cdaPath, Integer indexParam){
public int getMaxAttribute(DParent cdaPath, Integer indexParam, String parentDatatype){
Integer index = indexParam;
if (index == null){
index = Integer.valueOf(cdaPath.size() - 1);
}
String typeName = (new PathManager()).findPathTypeName(cdaPath, index.intValue() -1);
if(parentDatatype != null && DTUtils.constrainedDTIsAnExtension(parentDatatype, typeName)){
typeName = parentDatatype.replace("_","");
}
if (cdaPath.get(index.intValue()) != null) {
String attrName = cdaPath.get(index.intValue()).getName();
return UMLLoader.getMaxAttribute(typeName, attrName);
......@@ -37,6 +41,10 @@ public class UMLElementsManager {
log.error("The requested index ( {} ) is out of bound regarding the cdaPath", index);
return -1;
}
public int getMaxAttribute(DParent cdaPath, Integer indexParam){
return getMaxAttribute(cdaPath, indexParam, null);
}
public int getMinAttribute(DParent cdaPath, Integer indexParam){
Integer index = indexParam;
......
......@@ -4,11 +4,14 @@ import net.ihe.gazelle.tempgen.action.OCLCleaner;
import net.ihe.gazelle.tempgen.action.OCLGenerator;
import net.ihe.gazelle.tempgen.action.OwnedRuleManager;
import net.ihe.gazelle.tempgen.action.UMLElementsManager;
import net.ihe.gazelle.tempmodel.decor.dt.utils.DTUtils;
import net.ihe.gazelle.tempmodel.dpath.model.DParent;
import net.ihe.gazelle.tempmodel.dpath.utils.DPathExtractor;
import net.ihe.gazelle.tempmodel.org.decor.art.model.RuleDefinition;
import net.ihe.gazelle.tempmodel.org.decor.art.utils.RuleDefinitionUtil;
import javax.xml.namespace.QName;
/**
*
* @author Abderrazek Boufahja
......@@ -50,8 +53,17 @@ public class RDMaximumMultiplicityAnalyzer implements ConstraintGenerator{
}
else {
res = contextRule + "->forAll(";
int max = (new UMLElementsManager()).getMaxAttribute(RuleDefinitionUtil.getDParentOfRuleDefinition(ruleDefinition), null);
if (max == 1){
int max = 0;
UMLElementsManager umlElementsManager = new UMLElementsManager();
if(ruleDefinition.getParentObject() instanceof RuleDefinition &&
((RuleDefinition) ruleDefinition.getParentObject()).getDatatype() != null){
String parentDt = ((RuleDefinition) ruleDefinition.getParentObject()).getDatatype().getLocalPart();
max = umlElementsManager.getMaxAttribute(RuleDefinitionUtil.getDParentOfRuleDefinition(ruleDefinition), null, parentDt);
}
else{
max = umlElementsManager.getMaxAttribute(RuleDefinitionUtil.getDParentOfRuleDefinition(ruleDefinition), null);
}
if (max == 0){
res = res + RuleDefinitionUtil.getRealNameOfRuleDefinition(ruleDefinition) + ".oclIsUndefined())";
}
else{
......
......@@ -12,6 +12,9 @@ import net.ihe.gazelle.svs.ValueSetResponseType;
import net.ihe.gazelle.tempgen.valueset.action.ValueSetConceptProc;
import net.ihe.gazelle.tempmodel.org.decor.art.model.ValueSetConcept;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Abderrazek Boufahja
......@@ -28,10 +31,11 @@ public class ValueSetConceptProcTest extends ValueSetConceptProc {
public void testProcess() {
ValueSetConcept vsc = new ValueSetConcept();
RetrieveValueSetResponseType currentRetrieveValueSetResponseType = new RetrieveValueSetResponseType();
List<CE> conceptList = new ArrayList<>();
currentRetrieveValueSetResponseType.setValueSet(new ValueSetResponseType());
currentRetrieveValueSetResponseType.getValueSet().getConceptList().add(new ConceptListType());
this.process(vsc, new Object[] {currentRetrieveValueSetResponseType});
assertTrue(this.currentRetrieveValueSetResponseType.getValueSet().getConceptList().get(0).getConcept()!= null);
this.process(vsc, new Object[] {currentRetrieveValueSetResponseType, conceptList});
assertTrue(this.conceptList!= null);
}
@Test
......
......@@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import javax.xml.namespace.QName;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
/**
* @author Abderrazek Boufahja
......@@ -121,14 +122,21 @@ public class RuleDefinitionDistinguisherUtil {
return null;
}
public static Boolean elementsShouldBeDistinguisedWithDT(ChoiceDefinition choiceDefinition){
Set<String> names = new HashSet<>();
int count = 0;
for(RuleDefinition rd : ChoiceDefinitionUtil.getElements(choiceDefinition)){
names.add(RuleDefinitionUtil.getRealNameOfRuleDefinition(rd));
count++;
public static Boolean elementShouldBeDistinguisedByDT(RuleDefinition element, Object parent) {
List<RuleDefinition> nameOfElementsInParent = null;
if(parent instanceof RuleDefinition){
nameOfElementsInParent = RuleDefinitionUtil.getAllEffectiveElements((RuleDefinition) parent);
}
return Boolean.valueOf(names.size() != count);
else if(parent instanceof ChoiceDefinition){
nameOfElementsInParent = ChoiceDefinitionUtil.getElements((ChoiceDefinition) parent);
}
else {
return Boolean.FALSE;
}
return Boolean.valueOf(nameOfElementsInParent.stream()
.map(RuleDefinitionUtil::getRealNameOfRuleDefinition)
.filter(name -> name.equals(RuleDefinitionUtil.getRealNameOfRuleDefinition(element)))
.count() > 1);
}
}
......@@ -41,6 +41,20 @@ public class RuleDefinitionUtil {
return elements;
}
/**
* Flatten the rule definition and extract choices, to get all possible elements
* @param ruleDefinition the rule definition to flatten
* @return list of ruledefinitions
*/
public static List<RuleDefinition> getAllEffectiveElements(RuleDefinition ruleDefinition){
List<RuleDefinition> elements = getElements(ruleDefinition);
List<ChoiceDefinition> choices = getChoices(ruleDefinition);
for(ChoiceDefinition choice : choices){
elements.addAll(ChoiceDefinitionUtil.getElements(choice));
}
return elements;
}
public static List<ChoiceDefinition> getChoices(RuleDefinition ruleDefinition) {
List<ChoiceDefinition> elements = new ArrayList<>();
if (ruleDefinition != null) {
......
......@@ -10,11 +10,12 @@ import java.io.IOException;
/**
* All methods in this class are ignore, as they are executed as scripts and not tests
* All methods in this class are ignored, as they are executed as scripts and not tests
*/
public class EHDSITransformers {
@Test
@Ignore
public void transformBBRToFriendly() throws IOException, JAXBException {
String bbrPath = System.getProperty("bbrPath");
String bbrOutput = System.getProperty("bbrOutput");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment