From 2069dd979dad0b9181e1af999d4eba5d380342d3 Mon Sep 17 00:00:00 2001 From: ppazos Date: Mon, 27 Feb 2023 15:15:26 -0300 Subject: [PATCH] fixed rm validation with complete OPT --- gradle.properties | 2 +- .../opt/model/OperationalTemplate.groovy | 26 +++++++++++++------ .../openehr/validation/RmValidator2.groovy | 22 +++++++--------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/gradle.properties b/gradle.properties index 04c3397a..4e9332c1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 1.8.21 +version = 1.8.22 group = com.cabolabs \ No newline at end of file diff --git a/src/main/groovy/com/cabolabs/openehr/opt/model/OperationalTemplate.groovy b/src/main/groovy/com/cabolabs/openehr/opt/model/OperationalTemplate.groovy index 8b66b432..306e36e5 100644 --- a/src/main/groovy/com/cabolabs/openehr/opt/model/OperationalTemplate.groovy +++ b/src/main/groovy/com/cabolabs/openehr/opt/model/OperationalTemplate.groovy @@ -261,19 +261,21 @@ class OperationalTemplate { // attr name -> type Map rm_attrs = rm_attributes_not_in_opt[obn.rmTypeName] + def path_sep, aom_type, atnc, obnc + rm_attrs.each { attr, type -> // avoid if the attr is aready on the OPT // for instance, a null_flavour could be in the OPT if (!obn.attributes.find{ it.rmAttributeName == attr }) { - def aom_type = (type == 'String' ? 'C_PRIMITIVE_OBJECT' : 'C_COMPLEX_OBJECT') + aom_type = (type == 'String' ? 'C_PRIMITIVE_OBJECT' : 'C_COMPLEX_OBJECT') // avoid // on root paths - def path_sep = "/" + path_sep = "/" if (obn.path == "/") path_sep = "" - def atn = new AttributeNode( + atnc = new AttributeNode( rmAttributeName: attr, type: 'C_SINGLE_ATTRIBUTE', parent: obn, @@ -281,7 +283,7 @@ class OperationalTemplate { dataPath: obn.dataPath +path_sep+ attr, templatePath: obn.templatePath +path_sep+ attr, templateDataPath: obn.templateDataPath +path_sep+ attr, - existence: new IntervalInt( + existence: new IntervalInt( // TODO: check the RM to see the RM existence for this attribute upperIncluded: true, lowerIncluded: true, upperUnbounded: false, @@ -291,7 +293,7 @@ class OperationalTemplate { ) ) - def obnc = new ObjectNode( + obnc = new ObjectNode( owner: this, rmTypeName: type, type: aom_type, @@ -299,19 +301,27 @@ class OperationalTemplate { path: obn.path +path_sep+ attr, dataPath: obn.dataPath +path_sep+ attr, templateDataPath: obn.templateDataPath +path_sep+ attr, - parent: atn + parent: atnc, + occurrences: new IntervalInt( // TODO: check the RM to see the default RM occurrences for this object + upperIncluded: true, + lowerIncluded: true, + upperUnbounded: false, + lowerUnbounded: false, + lower: 0, + upper: 1 + ) // TODO: default_values ) obnc.text = obnc.parent.parent.text +'.'+ obnc.parent.rmAttributeName obnc.description = obnc.parent.parent.description +'.'+ obnc.parent.rmAttributeName - atn.children << obnc + atnc.children << obnc // supports many alternative nodes with the same path if (!this.nodes[obnc.templatePath]) this.nodes[obnc.templatePath] = [] this.nodes[obnc.templatePath] << obnc - obn.attributes << atn + obn.attributes << atnc } } diff --git a/src/main/groovy/com/cabolabs/openehr/validation/RmValidator2.groovy b/src/main/groovy/com/cabolabs/openehr/validation/RmValidator2.groovy index 91da15da..d3d4159d 100644 --- a/src/main/groovy/com/cabolabs/openehr/validation/RmValidator2.groovy +++ b/src/main/groovy/com/cabolabs/openehr/validation/RmValidator2.groovy @@ -122,6 +122,9 @@ class RmValidator2 { String template_id = rm_object.archetype_details.template_id.value + // TEST: complete, RM validation fails (fixed) + //this.opt_manager.load(template_id, namespace, true) + def opt = this.opt_manager.getOpt(template_id, namespace) if (!opt) @@ -2207,20 +2210,9 @@ class RmValidator2 { } else // data is null { - - if (!c_attr.existence) - { - println "attr "+ attribute_name +" existence is null???" - println o.attributes*.rmAttributeName - println c_attr.rmAttributeName - println c_attr.type - println c_attr.templatePath - println c_attr.templateDataPath - } - // existence: the only way of violating existence is with 1..1 so // it's checked only if the value is null - if (!c_attr.existence.has(0)) + if (c_attr.existence && !c_attr.existence.has(0)) { report.addError( object.dataPath +'/'+ attribute_name, @@ -2234,7 +2226,11 @@ class RmValidator2 { // because with a null value, the dataPath can't be retrieved to set it on the error report. // With a not null value, any existence will pass and occurrences 0..0 will fail. - if (c_attr.children.size() == 1 && !c_attr.children[0].occurrences.has(0)) + if ( + c_attr.children.size() == 1 && + c_attr.children[0].occurrences && + !c_attr.children[0].occurrences.has(0) + ) { // here we need the parent for the dataPath since the data is nul report.addError(