diff --git a/.gitignore b/.gitignore
new file mode 100755
index 00000000..e1526075
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+.idea/
+*.iml
+target
+dadl-binding/tree_2_slots.dadl
+oet-parser/term_map.txt
+oet-parser/test_paths.txt
+rm-skeleton/hypersensitivity_max.dadl
+rm-skeleton/hypersensitivity_min.dadl
+build.sh
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 00000000..4349456a
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,39 @@
+image: java:8
+
+stages:
+ - build
+ - release
+ - publish
+
+maven-build-snapshot:
+ image: gitlab.cambiocds.com:4567/tools/docker-builder
+ stage: build
+ script:
+ - mvn clean package sonar:sonar -P sonar
+ except:
+ - /^release-.*$/
+ - tags
+
+maven-build-tag:
+ image: gitlab.cambiocds.com:4567/tools/docker-builder
+ stage: build
+ script:
+ - mvn clean deploy sonar:sonar -P sonar
+ only:
+ - tags
+
+release:
+ image: gitlab.cambiocds.com:4567/tools/docker-builder
+ stage: release
+ when: manual
+ script:
+ - git remote set-url origin $(echo $CI_REPOSITORY_URL | sed -e 's/[^@]\+@\([^\/]\+\)\//git@\1\:/')
+ - git checkout -b release-$CURRENT_VERSION
+ - git push -u origin release-$CURRENT_VERSION
+ - mvn versions:set -DnewVersion=$CURRENT_VERSION
+ - git commit -a -m "Changing to version "$CURRENT_VERSION
+ - git tag $CURRENT_VERSION
+ - git push origin $CURRENT_VERSION --tags
+ - git push origin --delete release-$CURRENT_VERSION
+ only:
+ - master
diff --git a/INSTALL.txt b/INSTALL.txt
deleted file mode 100755
index a5e4b9be..00000000
--- a/INSTALL.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-
-INSTALATION INSTRUCTIONS:
-
-INSTALLATION:
-
-java-libs/mvn clean install
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
old mode 100755
new mode 100644
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..98352717
--- /dev/null
+++ b/README.md
@@ -0,0 +1,32 @@
+# java-libs
+Java openEHR Implementation project (ADL 1.4)
+
+## Getting Started
+
+### Requirements
+
+* Java 8 or higher
+* Maven 3.0.4 or higher
+
+### Usage
+
+The java-libs project is available at [Maven Central](http://search.maven.org/).
+
+For example, if you need to use the adl-parser, add into your _pom.xml_:
+
+```xml
+
+ org.openehr.java-libs
+ adl-parser
+ 1.0.71
+
+```
+
+### Installation
+
+To build the whole project, first clone it, and once inside the project's folder (by default _java-libs_), run:
+```bash
+mvn clean install
+```
+This will create binary files in the _target_ directories of each submodule.
+
diff --git a/README.txt b/README.txt
deleted file mode 100755
index 64f89611..00000000
--- a/README.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-Java openEHR Implementation project
------------------------------------
-
-VERSION
- Current version 1.0.5-SNAPSHOT
\ No newline at end of file
diff --git a/adl-parser/docs/changes.txt b/adl-parser/docs/changes.txt
old mode 100755
new mode 100644
diff --git a/adl-parser/pom.xml b/adl-parser/pom.xml
old mode 100755
new mode 100644
index ce1d0a96..ebc5b0f7
--- a/adl-parser/pom.xml
+++ b/adl-parser/pom.xml
@@ -2,9 +2,9 @@
4.0.0
- openehr
- ref_impl_java
- 1.0.5-SNAPSHOT
+ org.openehr.java-libs
+ java-libs
+ 0-SNAPSHOT
adl-parser
jar
@@ -48,14 +48,14 @@
-
+
@@ -91,32 +91,32 @@
- openehr
+ org.openehr.java-libs
openehr-rm-core
${project.version}
- openehr
+ org.openehr.java-libs
openehr-rm-domain
${project.version}
- openehr
+ org.openehr.java-libs
openehr-aom
${project.version}
- openehr
+ org.openehr.java-libs
openehr-ap
${project.version}
- openehr
+ org.openehr.java-libs
measure-serv
${project.version}
- openehr
+ org.openehr.java-libs
mini-termserv
${project.version}
diff --git a/adl-parser/readme.txt b/adl-parser/readme.txt
old mode 100755
new mode 100644
diff --git a/adl-parser/src/main/java/se/acode/openehr/parser/ArchetypeValidator.java b/adl-parser/src/main/java/se/acode/openehr/parser/ArchetypeValidator.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/main/java/se/acode/openehr/parser/AttributeValue.java b/adl-parser/src/main/java/se/acode/openehr/parser/AttributeValue.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/main/java/se/acode/openehr/parser/ContentObject.java b/adl-parser/src/main/java/se/acode/openehr/parser/ContentObject.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/main/java/se/acode/openehr/parser/Invariant.java b/adl-parser/src/main/java/se/acode/openehr/parser/Invariant.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/main/java/se/acode/openehr/parser/Parsed.java b/adl-parser/src/main/java/se/acode/openehr/parser/Parsed.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/main/javacc/adl.jj b/adl-parser/src/main/javacc/adl.jj
index 9ef1ae04..a10c09af 100755
--- a/adl-parser/src/main/javacc/adl.jj
+++ b/adl-parser/src/main/javacc/adl.jj
@@ -339,7 +339,6 @@ PARSER_END(ADLParser)
| < SYM_START_CBLOCK: "{">
| < SYM_END_CBLOCK: "}">
| < SYM_C_DV_QUANTITY: "c_dv_quantity" >: DOMAIN_TYPE_C_QUANTITY
-| < SYM_UNITS: "units">: DOMAIN_TYPE_C_QUANTITY
| < SYM_ASSUMED_VALUE: "assumed_value">
}
@@ -434,7 +433,7 @@ PARSER_END(ADLParser)
|
< V_INTEGER: ()+
| (){1,3}(","(){3})+>
-| < V_REAL: ()+"./"~[".","0"-"9"]
+| < V_REAL: ()+"./"~[".","0"-"9"]
| ()+"."()*["e","E"](["+","-"])?()+
| ()*"."()+(["e","E"](["+","-"])?()+)?
| (){1,3}("_"(){3})+"./"~[".","0"-"9"]
@@ -859,7 +858,7 @@ ResourceDescription arch_description() throws Exception :
String value = null;
List otherContributors = null;
String lifecycleState = null;
- List details = new ArrayList();
+ Map details = new HashMap();
ResourceDescriptionItem item = null;
String resourcePackageURI = null;
Map otherDetails = null;
@@ -880,7 +879,7 @@ ResourceDescription arch_description() throws Exception :
LOOKAHEAD(2)
item = arch_description_item()
{
- details.add(item);
+ details.put(item.getLanguage().getCodeString(),item);
}
)+
">"
@@ -1008,7 +1007,6 @@ CComplexObject arch_definition() :
ArchetypeOntology arch_ontology() :
{
String primaryLanguage = null;
- List languages = null;
List terminologies = null;
List termDefinitionsList = new ArrayList();
List constraintDefinitionsList = new ArrayList();
@@ -1024,17 +1022,17 @@ ArchetypeOntology arch_ontology() :
{
[primaryLanguage = primary_language()]
- [languages = languages_available()]
+ [languages_available()]
[ terminologies = terminologies_available() ]
termDefinitionsList = term_definitions_list()
-
+
[ constraintDefinitionsList = constraint_definitions_list() ]
-
- [ termBindingList = term_binding_list() ]
-
+
+ [ termBindingList = term_binding_list() ]
+
[ constraintBindingList = constraint_binding_list() ]
-
+
(
t = { key = t.image; }
"<" value = dadl_text() ">"
@@ -1045,7 +1043,7 @@ ArchetypeOntology arch_ontology() :
)*
{
- return new ArchetypeOntology(primaryLanguage, languages, terminologies,
+ return new ArchetypeOntology(primaryLanguage, terminologies,
termDefinitionsList, constraintDefinitionsList,
termBindingList, constraintBindingList);
}
@@ -1084,8 +1082,8 @@ List term_definitions_list() :
OntologyDefinitions definitions = null;
}
{
- "<"
- (
+ "<"
+ (
definitions = definitions_body()
{ list.add(definitions); }
)+
@@ -1095,12 +1093,12 @@ List term_definitions_list() :
List constraint_definitions_list() :
{
- List list = new ArrayList();
+ List list = new ArrayList();
OntologyDefinitions definitions = null;
}
{
- "<"
- (
+ "<"
+ (
definitions = definitions_body()
{ list.add(definitions); }
)*
@@ -1140,14 +1138,14 @@ DefinitionItem definition_item() :
}
{
"[" code = local_code_value() "]" "<"
- (
+ (
"<" text = string_value() ">"
[ ";" ]
"<" description = string_value() ">"
|
"<" description = string_value() ">"
[ ";" ]
- "<" text = string_value() ">"
+ "<" text = string_value() ">"
)
">"
{ return new DefinitionItem(code, text, description); }
@@ -1194,13 +1192,13 @@ ArchetypeTerm archetype_term() :
List term_binding_list() :
{
- List list = new ArrayList();
+ List list = new ArrayList();
OntologyBinding binding = null;
}
{
"<"
- (
- binding = ontology_binding_body()
+ (
+ binding = ontology_binding_body()
{ list.add(binding); }
)*
">"
@@ -1209,12 +1207,12 @@ List term_binding_list() :
List constraint_binding_list() :
{
- List list = new ArrayList();
+ List list = new ArrayList();
OntologyBinding binding = null;
}
{
"<"
- (
+ (
binding = ontology_binding_body()
{ list.add(binding); }
)*
@@ -1231,7 +1229,7 @@ OntologyBinding ontology_binding_body() :
}
{
"[" terminology = string_value() "]" "<"
-
+
"<"
(
@@ -1302,7 +1300,7 @@ String local_code_path_value() :
}
{
t =
- {
+ {
String value = t.image;
return value.substring(1, value.length() - 1);
}
@@ -1410,21 +1408,21 @@ Set assertions() :
Assertion assertion() :
{
- String tag = null;
+ String tag = null;
ExpressionItem expression;
- String stringExpression = null;
- List variables = null;
+ String stringExpression = null;
+ List variables = null;
}
{
- [
+ [
LOOKAHEAD(2)
- tag = any_identifier() ":"
- ]
- expression = boolean_expression()
-
+ tag = any_identifier() ":"
+ ]
+ expression = boolean_expression()
+
{
stringExpression = expression.toString();
- return new Assertion(tag, expression, stringExpression, variables);
+ return new Assertion(tag, expression, stringExpression, variables);
}
}
@@ -1447,7 +1445,7 @@ Object basic_object_val() :
|
LOOKAHEAD( term_code() )
value = term_code()
- )
+ )
{ return value; }
}
@@ -1566,10 +1564,10 @@ String string_value() :
{
// remove escape, \" -> "
value = value.replace("\\\"","\"");
-
+
// remove escape, \\ -> \
value = value.replace("\\\\","\\");
-
+
return value.substring(1, value.length() - 1);
}
}
@@ -1582,7 +1580,7 @@ List index_string_list() :{
{
(
index = string_value()
- ( value = string_value())
+ ( value = string_value())
{ list.add(value); }
)*
@@ -1655,38 +1653,38 @@ Interval integer_interval_value() :
{
Interval i = null;
int lower = 0;
- int upper = 0;
+ int upper = 0;
}
{
(
- LOOKAHEAD( 3 )
+ LOOKAHEAD( 3 )
{
boolean lowerInclusive = true;
- boolean upperInclusive = true;
- boolean upperSpecified = false;
+ boolean upperInclusive = true;
+ boolean upperSpecified = false;
}
[
{ lowerInclusive = false; }
]
- lower = integer_value()
+ lower = integer_value()
{ upper = lower; }
- [
-
- [
- { upperInclusive = false; }
- ]
+ [
+
+ [
+ { upperInclusive = false; }
+ ]
upper = integer_value()
- { upperSpecified =true; }
+ { upperSpecified =true; }
]
{
if(!lowerInclusive && !upperSpecified) {
// specical case for |>100|
i = new Interval(new Integer(lower), null, false, false);
} else {
- i = new Interval(new Integer(lower), new Integer(upper), lowerInclusive,
+ i = new Interval(new Integer(lower), new Integer(upper), lowerInclusive,
upperInclusive);
- }
+ }
}
|
upper = integer_value()
@@ -1721,7 +1719,63 @@ double real_value() :
boolean negative = false;
}
{
- [ ( "+" | "-" { negative = true; } ) ] t =
+ (
+ [ ( "+" | "-" { negative = true; } ) ] t =
+ )
+ {
+ try {
+ d = Double.parseDouble(t.image);
+ } catch(NumberFormatException e) {
+ throw new ParseException("Wrong format of double: " + t.image);
+ }
+ if(negative) {
+ d = -d;
+ }
+ return d;
+ }
+}
+
+String realOrInt_valueAsStr() :
+{
+ Token t;
+ double d;
+ boolean negative = false;
+}
+{
+ (
+ LOOKAHEAD( 2 )
+ [ ( "+" | "-" { negative = true; } ) ] t =
+ |
+ LOOKAHEAD( 2 )
+ [ ( "+" | "-" { negative = true; } ) ] t =
+ )
+ {
+ try {
+ d = Double.parseDouble(t.image);
+ } catch(NumberFormatException e) {
+ throw new ParseException("Wrong format of double: " + t.image);
+ }
+ if(negative) {
+ d = -d;
+ }
+ return "" + t.image; //d;
+ }
+}
+
+double realOrInt_value() :
+{
+ Token t;
+ double d;
+ boolean negative = false;
+}
+{
+ (
+ LOOKAHEAD( 2 )
+ [ ( "+" | "-" { negative = true; } ) ] t =
+ |
+ LOOKAHEAD( 2 )
+ [ ( "+" | "-" { negative = true; } ) ] t =
+ )
{
try {
d = Double.parseDouble(t.image);
@@ -1735,6 +1789,7 @@ double real_value() :
}
}
+
List real_list_value() :
{
List list = new ArrayList();
@@ -1761,31 +1816,31 @@ Interval real_interval_value() :
{
(
- LOOKAHEAD( 3 )
+ LOOKAHEAD( 3 )
{
boolean lowerInclusive = true;
- boolean upperInclusive = true;
- boolean upperSpecified = false;
+ boolean upperInclusive = true;
+ boolean upperSpecified = false;
}
[
{ lowerInclusive = false; }
]
- lower = real_value()
+ lower = real_value()
{ upper = lower; }
- [
-
- [
- { upperInclusive = false; }
+ [
+
+ [
+ { upperInclusive = false; }
]
- upper = real_value()
- { upperSpecified = true; }
+ upper = real_value()
+ { upperSpecified = true; }
]
{
if(!lowerInclusive && !upperSpecified) {
// specical case for |>100.0|
i = new Interval(new Double(lower), null, false, false);
- } else {
- i = new Interval(new Double(lower), new Double(upper), lowerInclusive,
+ } else {
+ i = new Interval(new Double(lower), new Double(upper), lowerInclusive,
upperInclusive);
}
}
@@ -1913,7 +1968,7 @@ Interval date_interval_value() :
{
(
- lower = date_value()
+ lower = date_value()
{ upper = lower; }
[ upper = date_value() ]
{
@@ -2085,7 +2140,7 @@ Interval date_time_interval_value() :
{
(
- lower = date_time_value()
+ lower = date_time_value()
{ upper = lower; }
[ upper = date_time_value() ]
{
@@ -2153,14 +2208,34 @@ Interval duration_interval_value() :
{
(
- lower = duration_value()
+
+ LOOKAHEAD( 3 )
+ {
+ boolean lowerInclusive = true;
+ boolean upperInclusive = true;
+ boolean upperSpecified = false;
+ }
+ [
+ { lowerInclusive = false; }
+ ]
+ lower = duration_value()
{ upper = lower; }
- [
- upper = duration_value()
+ [
+
+ [
+ { upperInclusive = false; }
+ ]
+ upper = duration_value()
+ { upperSpecified = true; }
]
{
- i = new Interval(lower, upper, true, true);
- }
+ if(!lowerInclusive && !upperSpecified) {
+ // specical case for |>100| - important to avoid >100..100
+ i = new Interval(lower, null, false, false);
+ } else {
+ i = new Interval(lower, upper, lowerInclusive, upperInclusive);
+ }
+ }
|
upper = duration_value()
{
@@ -2241,10 +2316,10 @@ CComplexObject c_complex_object(String path, CAttribute parent) :
path = "/";
} else {
path += (nodeID == null ? "" : "[" + nodeID + "]");
- }
+ }
}
- attributes = c_complex_object_body(path)
+ attributes = c_complex_object_body(path)
{
return new CComplexObject(path, type, occurrences, nodeID, attributes, parent);
@@ -2279,7 +2354,7 @@ CObject c_object(String path, CAttribute parent) :
}
{
(
- c = c_dv_quantity(path, parent)
+ c = c_dv_quantity(path, parent)
|
c = c_complex_object(path, parent)
|
@@ -2289,8 +2364,11 @@ CObject c_object(String path, CAttribute parent) :
|
c = c_code_phrase(path, parent)
|
+ LOOKAHEAD( (integer_value() "|" code_phrase() ",")* real_value() "|" )
+ c = c_dv_scale(path, parent)
+ |
LOOKAHEAD( 3 )
- c = c_dv_ordinal(path, parent)
+ c = c_dv_ordinal(path, parent)
|
LOOKAHEAD( 3 )
c = c_primitive_object(path, parent)
@@ -2307,7 +2385,7 @@ ConstraintRef constraint_ref_obj(String path, CAttribute parent) :
String reference;
String rmTypeName = "CODE_PHRASE";
Interval occurrences = new Interval(1, 1);
- String nodeId = null;
+ String nodeId = null;
}
{
reference = constraint_ref()
@@ -2322,14 +2400,23 @@ ArchetypeInternalRef archetype_internal_ref(String path, CAttribute parent) :
String type;
Interval occurrences = new Interval(1, 1);
String target;
+ String nodeID = null;
}
{
- type = type_identifier()
- [ occurrences = c_occurrences() ]
- target = absolute_path()
- {
- return new ArchetypeInternalRef(path, type, occurrences, null, parent,
- target);
+ type = type_identifier()
+ [ nodeID = constraint_ref() ]
+ [ occurrences = c_occurrences() ]
+ {
+ if(path == null) {
+ path = "/";
+ } else {
+ path += (nodeID == null ? "" : "[" + nodeID + "]");
+ }
+ }
+ target = absolute_path()
+ {
+ return new ArchetypeInternalRef(path, type, occurrences, nodeID, parent,
+ target);
}
}
@@ -2343,11 +2430,11 @@ ArchetypeSlot archetype_slot(String path, CAttribute parent) :
}
{
type = type_identifier()
-
+
[ nodeID = constraint_ref() ]
-
- [ occurrences = c_occurrences() ]
-
+
+ [ occurrences = c_occurrences() ]
+
[ includes = c_includes() ]
[ excludes = c_excludes() ]
@@ -2357,8 +2444,8 @@ ArchetypeSlot archetype_slot(String path, CAttribute parent) :
path = "/";
} else {
path += (nodeID == null ? "" : "[" + nodeID + "]");
- }
- return new ArchetypeSlot(path, type, occurrences, nodeID, parent, includes,
+ }
+ return new ArchetypeSlot(path, type, occurrences, nodeID, parent, includes,
excludes);
}
}
@@ -2417,7 +2504,7 @@ void c_any() :
CAttribute c_attribute(String path) :
{
String name;
- CAttribute.Existence existence = CAttribute.Existence.REQUIRED;
+ CAttribute.Existence existence = CAttribute.Existence.OPTIONAL; // SG 2019 - to enable archei to impose the constraints, and not always forcing 1..1 unless otherwise stated.
Cardinality cardinality = null; // default to non-container type
List children;
CAttribute attribute;
@@ -2426,8 +2513,8 @@ CAttribute c_attribute(String path) :
{
if( ! path.endsWith("/")) {
path += "/";
- }
- }
+ }
+ }
name = attribute_identifier()
[ existence = c_existence() ]
[ cardinality = c_cardinality() ]
@@ -2436,20 +2523,22 @@ CAttribute c_attribute(String path) :
{
path += name;
-
+
if(cardinality == null) {
attribute = new CSingleAttribute(path, name, existence, children);
} else {
attribute = new CMultipleAttribute(path, name, existence, cardinality,
children);
}
-
+
// Set children parent to the attribute
- for(Iterator it = children.iterator(); it.hasNext();) {
- CObject co = (CObject) it.next();
- co.setParent(attribute);
+ if (children!=null){
+ for(Iterator it = children.iterator(); it.hasNext();) {
+ CObject co = (CObject) it.next();
+ co.setParent(attribute);
+ }
}
-
+
return attribute;
}
}
@@ -2460,7 +2549,7 @@ List c_attr_values(String path, CAttribute parent) :
CObject c = null;
}
{
- (
+ (
LOOKAHEAD(2)
c_any()
|
@@ -2486,15 +2575,15 @@ Set c_invariants() :
/* ----------------------- expressions ----------------------- */
ExpressionItem boolean_expression() :
{
- ExpressionItem item = null;
+ ExpressionItem item = null;
}
-{
- LOOKAHEAD( 2 )
+{
+ LOOKAHEAD( 2 )
item = boolean_leaf()
|
LOOKAHEAD( 2 )
item = boolean_node()
-
+
{ return item; }
}
@@ -2502,18 +2591,18 @@ ExpressionItem boolean_node() :
{
ExpressionItem ret = null;
ExpressionItem item = null;
- ExpressionItem item2 = null;
+ ExpressionItem item2 = null;
OperatorKind op = null;
String path = null;
boolean precedenceOverridden = false; // TODO
- Token t = null;
+ Token t = null;
String attrId = null;
CPrimitive cp = null;
}
{
(
path = absolute_path()
- {
+ {
item = ExpressionLeaf.pathConstant(path);
ret = new ExpressionUnaryOperator(ExpressionItem.BOOLEAN,
OperatorKind.OP_EXISTS, precedenceOverridden, item);
@@ -2523,76 +2612,76 @@ ExpressionItem boolean_node() :
attrId = relative_path()
(
cp = c_primitive()
- { item2 = new ExpressionLeaf("C_"+cp.getType().toUpperCase(), cp, //SG 2013-01-31: Need to add "C_" because it is a C_* constraint pattern here, with the type usually being displayed in upper case
+ { item2 = new ExpressionLeaf("C_"+cp.getType().toUpperCase(), cp, //SG 2013-01-31: Need to add "C_" because it is a C_* constraint pattern here, with the type usually being displayed in upper case
ExpressionLeaf.ReferenceType.CONSTRAINT); } //SG 2013-01-31: instead of CONSTANT, which is not correct, at least not for archetype slots according to spec.
|
t =
{ item2 = ExpressionLeaf.stringConstant(t.image); }
)
- {
+ {
item = new ExpressionLeaf(ExpressionItem.STRING, attrId,
ExpressionLeaf.ReferenceType.ATTRIBUTE); //SG 2013-01-31, needs to be attribute according to spec (not constant), relevant for archetype slots
//item = ExpressionLeaf.stringConstant(attrId);
- ret = new ExpressionBinaryOperator(ExpressionItem.BOOLEAN,
+ ret = new ExpressionBinaryOperator(ExpressionItem.BOOLEAN,
OperatorKind.OP_MATCHES, false, item, item2);
- }
+ }
|
item = boolean_expression()
{
ret = new ExpressionUnaryOperator(ExpressionItem.BOOLEAN,
- OperatorKind.OP_NOT, precedenceOverridden, item);
+ OperatorKind.OP_NOT, precedenceOverridden, item);
}
|
LOOKAHEAD( 3 )
item = arithmetic_expression()
(
- "="
+ "="
{ op = OperatorKind.OP_EQ; }
- |
-
+ |
+
{ op = OperatorKind.OP_NE; }
- |
-
+ |
+
{ op = OperatorKind.OP_LT; }
- |
-
+ |
+
{ op = OperatorKind.OP_GT; }
- |
-
+ |
+
{ op = OperatorKind.OP_LE; }
- |
+ |
{ op = OperatorKind.OP_GE; }
)
- item2 = arithmetic_expression()
- {
+ item2 = arithmetic_expression()
+ {
ret = new ExpressionBinaryOperator(item.getType(), op, false, item, item2);
}
|
- LOOKAHEAD( 3 )
- item = boolean_leaf()
+ LOOKAHEAD( 3 )
+ item = boolean_leaf()
(
(
-
+
{ op = OperatorKind.OP_AND; }
- |
-
+ |
+
{ op = OperatorKind.OP_OR; }
|
-
+
{ op = OperatorKind.OP_XOR; }
- |
-
+ |
+
{ op = OperatorKind.OP_IMPLIES; }
)
item2 = boolean_expression()
)
- {
+ {
if(item2 == null) {
ret = item;
} else {
- ret = new ExpressionBinaryOperator(ExpressionItem.BOOLEAN, op, false,
+ ret = new ExpressionBinaryOperator(ExpressionItem.BOOLEAN, op, false,
item, item2);
}
}
@@ -2605,22 +2694,22 @@ ExpressionItem boolean_leaf() :
ExpressionItem item = null;
}
{
-
+
LOOKAHEAD( 3 )
"(" item = boolean_expression() ")"
|
{ item = ExpressionLeaf.booleanConstant(true); }
-|
+|
{ item = ExpressionLeaf.booleanConstant(false); }
-
- { return item; }
+
+ { return item; }
}
ExpressionItem arithmetic_expression() :
{
- ExpressionItem item = null;
+ ExpressionItem item = null;
}
{
LOOKAHEAD( 3 )
@@ -2639,63 +2728,63 @@ ExpressionItem arithmetic_node() :
OperatorKind op = null;
}
{
- left = arithmetic_leaf()
+ left = arithmetic_leaf()
(
(
- "+"
+ "+"
{ op = OperatorKind.OP_PLUS; }
- |
- "-"
+ |
+ "-"
{ op = OperatorKind.OP_MINUS; }
- |
- "*"
+ |
+ "*"
{ op = OperatorKind.OP_MULTIPLY; }
- |
- "/"
+ |
+ "/"
{ op = OperatorKind.OP_DIVIDE; }
- |
- "^"
- { op = OperatorKind.OP_EXP; }
- )
-
- right = arithmetic_expression()
- )
- {
+ |
+ "^"
+ { op = OperatorKind.OP_EXP; }
+ )
+
+ right = arithmetic_expression()
+ )
+ {
if(right == null) {
item = left;
- } else {
- item = new ExpressionBinaryOperator(right.getType(), op, false, left,
- right);
+ } else {
+ item = new ExpressionBinaryOperator(right.getType(), op, false, left,
+ right);
}
- return item;
+ return item;
}
}
ExpressionItem arithmetic_leaf() :
-{
+{
ExpressionItem item = null;
Token t = null;
String str = null;
}
{
"(" item = arithmetic_expression() ")"
-|
+|
t =
{
int i = Integer.parseInt(t.image);
item = ExpressionLeaf.intConstant(i);
}
-|
+|
t =
{
double d = Double.parseDouble(t.image);
item = ExpressionLeaf.realConstant(d);
}
|
- str = absolute_path()
+ str = absolute_path()
{
item = ExpressionLeaf.stringConstant(str);
- }
+ }
{ return item; }
}
@@ -2805,7 +2894,7 @@ Interval occurrence_spec() :
CDvOrdinal c_dv_ordinal(String path, CAttribute parent) :
{
- Set list = new LinkedHashSet();
+ List list = new ArrayList();
org.openehr.am.openehrprofile.datatypes.quantity.Ordinal o;
Ordinal defaultValue = null;
int assumed = -1;
@@ -2813,7 +2902,6 @@ CDvOrdinal c_dv_ordinal(String path, CAttribute parent) :
Interval occurrences = new Interval(1, 1);
}
{
-
o = ordinal() { list.add(o); }
(
"," o = ordinal()
@@ -2828,15 +2916,15 @@ CDvOrdinal c_dv_ordinal(String path, CAttribute parent) :
assumedValue = ord;
break;
}
- }
- }
+ }
+ }
]
- {
+ {
return new CDvOrdinal(path, occurrences, null, parent, list, defaultValue,
- assumedValue);
+ assumedValue);
}
|
-
+
{
// any allowed
return new CDvOrdinal(path, occurrences, null, parent, null, null, null);
@@ -2851,12 +2939,60 @@ org.openehr.am.openehrprofile.datatypes.quantity.Ordinal ordinal() :
}
{
value = integer_value() "|" code = code_phrase()
- {
+ {
return new org.openehr.am.openehrprofile.datatypes.quantity.Ordinal(
- value, code);
+ value, code);
+ }
+}
+
+CDvScale c_dv_scale(String path, CAttribute parent) :
+{
+ List list = new ArrayList();
+ org.openehr.am.openehrprofile.datatypes.quantity.Scale o;
+ Scale defaultValue = null;
+ double assumed = -1.0;
+ Scale assumedValue = null;
+ Interval occurrences = new Interval(1, 1);
+}
+{
+ o = scale() { list.add(o); }
+ (
+ "," o = scale()
+ { list.add(o); }
+ )*
+ [
+ ";" assumed = realOrInt_value()
+ {
+ for(Iterator it = list.iterator(); it.hasNext();) {
+ Scale scale = (Scale) it.next();
+ if(scale.getValue() == assumed) {
+ assumedValue = scale;
+ break;
+ }
+ }
+ }
+ ]
+ {
+ return new CDvScale(path, occurrences, null, parent, list, defaultValue, assumedValue);
+ }
+}
+
+org.openehr.am.openehrprofile.datatypes.quantity.Scale scale() :
+{
+ Token t;
+ String display; // We must maintain the way it is specified (2 vs 2.0 makes a difference to end users)
+ //double value;
+ CodePhrase code;
+}
+{
+ display = realOrInt_valueAsStr() "|" code = code_phrase()
+ {
+ return new org.openehr.am.openehrprofile.datatypes.quantity.Scale(display, code);
}
}
+
+
CCodePhrase c_code_phrase(String path, CAttribute parent) :
{
Token t;
@@ -2865,55 +3001,55 @@ CCodePhrase c_code_phrase(String path, CAttribute parent) :
List codeList = null;
String assumed = null;
CodePhrase assumedValue = null;
- CodePhrase defaultValue = null; // not used
+ CodePhrase defaultValue = null; // not used
CodePhrase singleValue = null;
Interval occurrences = new Interval(1, 1);
}
{
- (
- t =
- {
+ (
+ t =
+ {
// remove leading "[" and trailing "::"
- terminology = t.image;
+ terminology = t.image;
terminology = terminology.substring(1, terminology.length() - 2);
terminologyId = new TerminologyID(terminology);
}
[
- t =
- {
+ t =
+ {
codeList = new ArrayList();
- codeList.add(t.image);
+ codeList.add(t.image);
}
(
[","] t = { codeList.add(t.image); }
)*
- [
- ";" t =
- {
- assumed = t.image;
+ [
+ ";" t =
+ {
+ assumed = t.image;
assumedValue = new CodePhrase(terminologyId, assumed);
- }
- ]
+ }
+ ]
]
"]"
- {
+ {
// leave lexical state "TERM_CODE"
- token_source.SwitchTo(CADL);
+ token_source.SwitchTo(CADL);
}
- |
+ |
singleValue = code_phrase()
- {
+ {
codeList = new ArrayList();
codeList.add(singleValue.getCodeString());
terminologyId = singleValue.getTerminologyId();
}
)
- {
- return new CCodePhrase(path, occurrences, null, parent, terminologyId,
- codeList, defaultValue, assumedValue);
+ {
+ return new CCodePhrase(path, occurrences, null, parent, terminologyId,
+ codeList, defaultValue, assumedValue);
}
-
-
+
+
}
CDvQuantity c_dv_quantity(String path, CAttribute parent) :
@@ -2922,7 +3058,7 @@ CDvQuantity c_dv_quantity(String path, CAttribute parent) :
String terminology = null;
String code = null;
List list = null;
- CDvQuantityItem item = null;
+ CDvQuantityItem item = null;
Token t = null;
DvQuantity defaultValue = null;
DvQuantity assumedValue = null;
@@ -2931,33 +3067,33 @@ CDvQuantity c_dv_quantity(String path, CAttribute parent) :
{
"<"
(
-
- "<" property = code_phrase() ">"
-
- |
-
+
+ "<" property = code_phrase() ">"
+
+ |
+
{ list = new ArrayList(); }
- "<"
- (
- item = c_dv_quantity_item()
+ "<"
+ (
+ item = c_dv_quantity_item()
{ list.add(item); }
- )+
+ )+
">"
-
- |
-
+
+ |
+
"<"
- assumedValue = dv_quantity()
+ assumedValue = dv_quantity()
">"
-
+
)*
- ">"
- {
+ ">"
+ {
{ token_source.SwitchTo(CADL); }
-
- return new CDvQuantity(path, occurrences, null, parent, list, property,
- defaultValue, assumedValue);
- }
+
+ return new CDvQuantity(path, occurrences, null, parent, list, property,
+ defaultValue, assumedValue);
+ }
}
DvQuantity dv_quantity() :
@@ -2967,46 +3103,46 @@ DvQuantity dv_quantity() :
int precision = 0;
}
{
- (
+ (
"<" units = string_value() ">"
- |
- "<" magnitude = real_value() ">"
- |
- "<" precision = integer_value() ">"
- )*
- {
- return new DvQuantity(units, magnitude, precision, measureServ);
- }
+ |
+ "<" magnitude = real_value() ">"
+ |
+ "<" precision = integer_value() ">"
+ )*
+ {
+ return new DvQuantity(units, magnitude, precision, measureServ);
+ }
}
CDvQuantityItem c_dv_quantity_item() :
{
Interval value = null;
Interval precision = null;
- String units;
+ String units;
}
{
"[" string_value() "]" "<"
-
- (|) "<"
- units = string_value()
+
+ () "<"
+ units = string_value()
">"
-
+
[
- "<"
- value = real_interval_value()
+ "<"
+ value = real_interval_value()
">"
]
-
+
[
- "<"
+ "<"
precision = integer_interval_value()
">"
]
">"
- {
- return new CDvQuantityItem(value, precision, units);
- }
+ {
+ return new CDvQuantityItem(value, precision, units);
+ }
}
List string_list() :
@@ -3016,14 +3152,14 @@ List string_list() :
}
{
(
- string_value()
+ string_value()
value = string_value()
-
- { list.add(value); }
- )*
-
- { return list; }
-}
+
+ { list.add(value); }
+ )*
+
+ { return list; }
+}
CInteger c_integer() :
{
@@ -3046,8 +3182,8 @@ CInteger c_integer() :
LOOKAHEAD( occurrence_spec())
interval = occurrence_spec()
)
- [ ";" assumed = integer_value()
- { assumedValue = new Integer(assumed); }
+ [ ";" assumed = integer_value()
+ { assumedValue = new Integer(assumed); }
]
{
if(interval != null) {
@@ -3081,7 +3217,7 @@ CReal c_real() :
LOOKAHEAD( real_value() )
d = real_value()
)
- [
+ [
";" assumed = real_value()
{ assumedValue = new Double(assumed); }
]
@@ -3116,7 +3252,7 @@ CDate c_date() :
|
interval = date_interval_value()
)
- [
+ [
";" assumed = date_value()
]
{
@@ -3146,7 +3282,7 @@ CTime c_time() :
|
interval = time_interval_value()
)
- [
+ [
";" assumed = time_value()
]
{
@@ -3176,7 +3312,7 @@ CDateTime c_date_time() :
|
interval = date_time_interval_value()
)
- [
+ [
";" assumed = date_time_value()
]
{
@@ -3198,17 +3334,17 @@ CDuration c_duration() :
}
{
(
- pattern = duration_pattern()
+ pattern = duration_pattern()
[
"/" interval = duration_interval_value()
- ]
+ ]
|
interval = duration_interval_value()
|
- value = duration_value()
+ value = duration_value()
)
-
- [
+
+ [
";" assumed = duration_value()
]
{
@@ -3217,9 +3353,11 @@ CDuration c_duration() :
}
String duration_pattern() :
-{
Token t = null;
+{
+ Token t = null;
}
-{
t =
+{
+ t =
{ return t.image; }
}
@@ -3264,7 +3402,7 @@ CBoolean c_boolean() :
{
boolean trueAllowed = false;
boolean falseAllowed = false;
- boolean assumed = false;
+ boolean assumed = false;
boolean hasAssumed = false;
}
{
@@ -3274,9 +3412,9 @@ CBoolean c_boolean() :
| { falseAllowed = true; }
[ "," { trueAllowed = true; } ]
)
- [
- ";"
- ( {assumed = true; } | {assumed = false;} )
+ [
+ ";"
+ ( {assumed = true; } | {assumed = false;} )
{ hasAssumed = true; }
]
{
@@ -3315,10 +3453,10 @@ String type_identifier() :
String type;
}
{
- t =
+ t =
{ type = t.image; }
- [
- "<" t = ">"
+ [
+ "<" t = ">"
{ type += "<" + t.image + ">"; }
]
{ return type; }
@@ -3335,8 +3473,8 @@ String attribute_identifier() :
String absolute_path() :
-{
- String path;
+{
+ String path;
StringBuffer buf;
Token t;
}
@@ -3346,57 +3484,57 @@ String absolute_path() :
}
String relative_path() :
-{
+{
StringBuffer buf;
- String path;
+ String path;
Token t;
}
{
- (
- t =
- |
- t =
+ (
+ t =
+ |
+ t =
)
{ return t.image; }
}
String path_segment() :
-{
- Token t;
+{
+ Token t;
StringBuffer buf = new StringBuffer();
}
{
t =
- { buf.append(t.image); }
+ { buf.append(t.image); }
[
LOOKAHEAD(2)
t =
{ buf.append(t.image); }
- ]
- { return buf.toString(); }
+ ]
+ { return buf.toString(); }
}
/*
* ***** BEGIN LICENSE BLOCK ***** Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
+ *
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the 'License'); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
- *
+ *
* Software distributed under the License is distributed on an 'AS IS' basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
- *
+ *
* The Original Code is ADLParser.java
- *
+ *
* The Initial Developer of the Original Code is Rong Chen. Portions created by
* the Initial Developer are Copyright (C) 2003-2009 the Initial Developer. All
* Rights Reserved.
- *
+ *
* Contributor(s): Sebastian Garde
- *
+ *
* Software distributed under the License is distributed on an 'AS IS' basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
- *
+ *
* ***** END LICENSE BLOCK *****
- */
\ No newline at end of file
+ */
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeDescriptionTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeDescriptionTest.java
old mode 100755
new mode 100644
index f3bff7ca..80db7576
--- a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeDescriptionTest.java
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeDescriptionTest.java
@@ -56,11 +56,11 @@ public void testParseFullArchetypeDescription() throws Exception {
// TODO: parent_resource
- List details = description.getDetails();
+ Map details = description.getDetails();
assertNotNull("details null", details);
assertEquals("details size wrong", 1, details.size());
- ResourceDescriptionItem item = details.get(0);
+ ResourceDescriptionItem item = details.get("en");
assertNotNull("descriptionItem null", item);
CodePhrase language = new CodePhrase("ISO_639-1", "en");
assertEquals("language wrong", language, item.getLanguage());
@@ -90,12 +90,12 @@ public void testParseFullArchetypeDescription() throws Exception {
keywords.add("condition");
assertEquals("keywords wrong", keywords, item.getKeywords());
- map = details.get(0).getOriginalResourceUri();
+ map = details.get("en").getOriginalResourceUri();
assertEquals("http://guidelines.are.us/wherever/fr",
map.get("ligne guide"));
assertEquals("http://some%20medline%20ref", map.get("medline"));
- map = details.get(0).getOtherDetails();
+ map = details.get("en").getOtherDetails();
assertEquals("item details 1", map.get("item other 1"));
assertEquals("item details 2", map.get("item other 2"));
}
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeIdentificationTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeIdentificationTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeInternalRefTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeInternalRefTest.java
index 614c384e..735fa0cd 100755
--- a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeInternalRefTest.java
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeInternalRefTest.java
@@ -6,7 +6,19 @@
import org.openehr.rm.support.basic.Interval;
public class ArchetypeInternalRefTest extends ParserTestBase {
- public void testParseInternalRefWithOverwrittingOccurrences()
+ public void testParseCheckIfNodeIsIsTakenIntoAccount() throws Exception{
+ ADLParser parser = new ADLParser(loadFromClasspath(
+ "adl-test-entry.archetype_internal_ref.test.adl"));
+ Archetype archetype = parser.parse();
+ assertNotNull(archetype);
+
+ assertNotNull(archetype.node("/attribute3"));
+ assertNotNull(archetype.node("/attribute4[at0005]"));
+ assertNotNull(archetype.node("/attribute4[at0006]"));
+ }
+
+
+ public void testParseInternalRefWithOverwrittingOccurrences()
throws Exception {
ADLParser parser = new ADLParser(loadFromClasspath(
"adl-test-entry.archetype_internal_ref.test.adl"));
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeLanguageTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeLanguageTest.java
old mode 100755
new mode 100644
index 34b7c2ed..d0833ead
--- a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeLanguageTest.java
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeLanguageTest.java
@@ -131,4 +131,13 @@ public void testParseTranslationsAuthorLanguage() throws Exception {
Map map = td.getAuthor();
assertNotNull("author null", map);
}
+
+ public void testParseMultipleLanguageTerms() throws Exception {
+ ADLParser parser = new ADLParser(loadFromClasspath(
+ "adl-test-entry.archetype_language.test2.adl"));
+ Archetype archetype = parser.parse();
+ assertNotNull(archetype);
+
+ assertEquals(2, archetype.getOntology().getLanguages().size());
+ }
}
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeOntologyTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeOntologyTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeSlotTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeSlotTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeUncommonTermKeysTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeUncommonTermKeysTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeValidatorTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ArchetypeValidatorTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/BasicGenericTypeTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/BasicGenericTypeTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/BasicTypesTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/BasicTypesTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/CCodePhraseTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/CCodePhraseTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/CDurationTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/CDurationTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/CDvOrdinalTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/CDvOrdinalTest.java
index 3da83dbd..78d0efe3 100755
--- a/adl-parser/src/test/java/se/acode/openehr/parser/CDvOrdinalTest.java
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/CDvOrdinalTest.java
@@ -43,12 +43,27 @@ public void testCDvOrdinalWithoutAssumedValue() throws Exception {
String[] codes = {
"at0003.0", "at0003.1", "at0003.2", "at0003.3", "at0003.4"
};
+ int[] values = { 0, 1, 2, 3, 4 };
String terminology = "local";
assertFalse("unexpected assumed value",
((CDvOrdinal) node).hasAssumedValue());
- assertCDvOrdinal(node, terminology, codes, null);
+ assertCDvOrdinal(node, terminology, codes, values, null);
+ }
+
+ public void testCDvOrdinalWithDuplicatedValues() throws Exception {
+ node = archetype.node("/types[at0001]/items[at10004]/value");
+ String[] codes = {
+ "at0003.0", "at0003.1", "at0003.2", "at0003.3", "at0003.4"
+ };
+ int[] values = { 0, 1, 1, 3, 4 };
+ String terminology = "local";
+
+ assertFalse("unexpected assumed value",
+ ((CDvOrdinal) node).hasAssumedValue());
+
+ assertCDvOrdinal(node, terminology, codes, values, null);
}
public void testCDvOrdinalWithAssumedValue() throws Exception {
@@ -56,13 +71,14 @@ public void testCDvOrdinalWithAssumedValue() throws Exception {
String[] codes = {
"at0003.0", "at0003.1", "at0003.2", "at0003.3", "at0003.4"
};
+ int[] values = { 0, 1, 2, 3, 4 };
String terminology = "local";
Ordinal assumed = new Ordinal(0, new CodePhrase(terminology, codes[0]));
assertTrue("expected to have assumed value",
((CDvOrdinal) node).hasAssumedValue());
- assertCDvOrdinal(node, terminology, codes, assumed);
+ assertCDvOrdinal(node, terminology, codes, values, assumed);
}
public void testEmptyCDvOrdinal() throws Exception {
@@ -73,22 +89,21 @@ public void testEmptyCDvOrdinal() throws Exception {
}
private void assertCDvOrdinal(ArchetypeConstraint node, String terminoloy,
- String[] codes, Ordinal assumedValue) {
-
- assertTrue("CDvOrdinal expected", node instanceof CDvOrdinal);
+ String[] codes, int[] values, Ordinal assumedValue) {
+
+ assertTrue("CDvOrdinal expected", node instanceof CDvOrdinal);
CDvOrdinal cordinal = (CDvOrdinal) node;
-
- List codeList = Arrays.asList(codes);
- Set list = cordinal.getList();
+
+ List list = cordinal.getList();
assertEquals("codes.size", codes.length, list.size());
- for(Ordinal ordinal : list) {
- assertEquals("terminology", "local",
- ordinal.getSymbol().getTerminologyId().getValue());
- assertTrue("code missing",
- codeList.contains(ordinal.getSymbol().getCodeString()));
+ for(int i = 0; i < codes.length; i++) {
+ assertEquals("terminology", terminoloy,
+ list.get(i).getSymbol().getTerminologyId().getValue());
+ assertEquals("code missing", codes[i], list.get(i).getSymbol().getCodeString());
+ assertEquals("value wrong", values[i], list.get(i).getValue());
}
- assertEquals("assumedValue wrong", assumedValue,
- cordinal.getAssumedValue());
+ assertEquals("assumedValue wrong", assumedValue,
+ cordinal.getAssumedValue());
}
private Archetype archetype;
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/CDvQuantityTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/CDvQuantityTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/CDvScaleTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/CDvScaleTest.java
new file mode 100644
index 00000000..c908daf7
--- /dev/null
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/CDvScaleTest.java
@@ -0,0 +1,131 @@
+package se.acode.openehr.parser;
+
+import org.openehr.am.archetype.constraintmodel.ArchetypeConstraint;
+import org.openehr.am.archetype.constraintmodel.CComplexObject;
+import org.openehr.am.archetype.Archetype;
+import org.openehr.am.openehrprofile.datatypes.quantity.CDvScale;
+import org.openehr.am.openehrprofile.datatypes.quantity.Scale;
+import org.openehr.rm.datatypes.text.CodePhrase;
+
+import java.util.*;
+
+/**
+ * Test case tests parsing of domain type constraints extension.
+ *
+ * @author Sebastian Garde
+ * @version 1.0
+ */
+
+public class CDvScaleTest extends ParserTestBase {
+
+ public CDvScaleTest(String test) throws Exception {
+ super(test);
+ }
+
+ /**
+ * The fixture set up called before every test method.
+ */
+ protected void setUp() throws Exception {
+ ADLParser parser = new ADLParser(loadFromClasspath(
+ "adl-test-ENTRY.c_dv_scale.test.adl"));
+ archetype = parser.parse();
+ }
+
+ /**
+ * The fixture clean up called after every test method.
+ */
+ protected void tearDown() throws Exception {
+ archetype = null;
+ node = null;
+ }
+
+ public void testCDvScaleWithoutAssumedValue() throws Exception {
+ node = archetype.node("/types[at0001]/items[at10001]/value");
+ String[] codes = {
+ "at0003.0", "at0003.1", "at0003.2", "at0003.3", "at0003.4"
+ };
+
+ double[] values = { 0.0, 1.0, 2.5, 3.8, 4.4 };
+ String terminology = "local";
+
+ assertFalse("unexpected assumed value",
+ ((CDvScale) node).hasAssumedValue());
+
+ assertCDvScale(node, terminology, codes, values, null);
+ }
+
+ public void testCDvScaleWithAssumedValueAndIntegers() throws Exception {
+ node = archetype.node("/types[at0001]/items[at10002]/value");
+ String[] codes = {
+ "at0003.0", "at0003.1", "at0003.2", "at0003.3", "at0003.4"
+ };
+ double[] values = { 0, 1, 2, 3, 4.1 };
+ String terminology = "local";
+ Scale assumed = new Scale(2, new CodePhrase(terminology, codes[2]));
+
+ assertTrue("expected to have assumed value",
+ ((CDvScale) node).hasAssumedValue());
+
+ assertCDvScale(node, terminology, codes, values, assumed);
+ }
+
+ public void testEmptyDvScale() throws Exception {
+ node = archetype.node("/types[at0001]/items[at10003]/value");
+
+ assertTrue("CComplexObject expected", node instanceof CComplexObject );
+ assertTrue("DV_SCALE RM Type expected", ((CComplexObject) node).getRmTypeName().equals("DV_SCALE"));
+
+ assertTrue("any allowed expected", node.isAnyAllowed());
+ }
+
+ public void testCDvScaleWithDuplicatedValues() throws Exception {
+ node = archetype.node("/types[at0001]/items[at10004]/value");
+ String[] codes = {
+ "at0003.0", "at0003.1", "at0003.2", "at0003.3", "at0003.4"
+ };
+ double[] values = { 0, 1.5, 1.5, 3.5, 4 };
+ String terminology = "local";
+
+ assertFalse("unexpected assumed value",
+ ((CDvScale) node).hasAssumedValue());
+
+ assertCDvScale(node, terminology, codes, values, null);
+ }
+
+ public void testDvScaleNormal() throws Exception {
+ node = archetype.node("/types[at0001]/items[at10005]/value");
+ String[] codes = {
+ "at0003.0", "at0003.2"
+ };
+ double[] values = { 0, 1.5 };
+ String terminology = "local";
+
+ // DV_SCALE tests
+ //assertFalse("unexpected assumed value",
+ // ((DvScale) node).hasAssumedValue());
+
+ //assertCDvScale(node, terminology, codes, values, null);
+ }
+
+ private void assertCDvScale(ArchetypeConstraint node, String terminoloy,
+ String[] codes, double[] values, Scale assumedValue) {
+
+ assertTrue("CDvScale expected", node instanceof CDvScale);
+ CDvScale cordinal = (CDvScale) node;
+
+ List list = cordinal.getList();
+ assertEquals("codes.size", codes.length, list.size());
+ for(int i = 0; i < codes.length; i++) {
+ assertEquals("terminology", terminoloy,
+ list.get(i).getSymbol().getTerminologyId().getValue());
+ assertEquals("code missing", codes[i], list.get(i).getSymbol().getCodeString());
+ assertEquals("value wrong", values[i], list.get(i).getValue());
+ // could also add a test about the exact display here
+ }
+ assertEquals("assumedValue wrong", assumedValue,
+ cordinal.getAssumedValue());
+ }
+
+ private Archetype archetype;
+ private ArchetypeConstraint node;
+}
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ConstraintBindingTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ConstraintBindingTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ConstraintRefTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/ConstraintRefTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/DateTimeTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/DateTimeTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/DvCodedTextTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/DvCodedTextTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/DvDurationIntervalTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/DvDurationIntervalTest.java
new file mode 100644
index 00000000..47f8a4d7
--- /dev/null
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/DvDurationIntervalTest.java
@@ -0,0 +1,32 @@
+package se.acode.openehr.parser;
+
+import org.openehr.am.archetype.Archetype;
+import org.openehr.rm.datatypes.quantity.datetime.DvDuration;
+import org.openehr.rm.support.basic.Interval;
+
+public class DvDurationIntervalTest extends ParserTestBase {
+
+ /**
+ * Create new test case
+ *
+ * @param test
+ * @throws Exception
+ */
+ public DvDurationIntervalTest() throws Exception {
+ ADLParser parser = new ADLParser(
+ loadFromClasspath("openEHR-EHR-CLUSTER.duration_interval_test.v0.adl"));
+ archetype = parser.parse();
+ }
+
+ public void testParse() throws Exception {
+ // This test is mainly to ensure all examples parse ok.
+ // In addition, this is one test to ensure the special case of >X is working in the constraint. (No incorrect upper limit is imposed)
+ Interval interval = new Interval(
+ DvDuration.getInstance("PT0M"), null, false, true);
+
+ assertCDuration(archetype.node("/items[at0003]/value/value"), null, interval);
+
+ }
+
+ private Archetype archetype;
+}
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/EmptyOtherContributorsTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/EmptyOtherContributorsTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/MissingLanguageTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/MissingLanguageTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/MissingPurposeTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/MissingPurposeTest.java
old mode 100755
new mode 100644
index 0c1b6ca0..114ac38b
--- a/adl-parser/src/test/java/se/acode/openehr/parser/MissingPurposeTest.java
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/MissingPurposeTest.java
@@ -13,6 +13,6 @@ public void testMissingLanguageCompatibility() throws Exception {
assertNotNull(archetype);
assertNotNull("purpose null",
- archetype.getDescription().getDetails().get(0).getPurpose());
+ archetype.getDescription().getDetails().get("en").getPurpose());
}
}
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/MixedNodeTypesTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/MixedNodeTypesTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/MostMinimalADLTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/MostMinimalADLTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/MultiLanguageTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/MultiLanguageTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/ParserTestBase.java b/adl-parser/src/test/java/se/acode/openehr/parser/ParserTestBase.java
old mode 100755
new mode 100644
index 30d891c7..0f29f45d
--- a/adl-parser/src/test/java/se/acode/openehr/parser/ParserTestBase.java
+++ b/adl-parser/src/test/java/se/acode/openehr/parser/ParserTestBase.java
@@ -1,283 +1,283 @@
-package se.acode.openehr.parser;
-
-import junit.framework.TestCase;
-
-import java.io.File;
-import java.io.InputStream;
-import java.util.*;
-import java.text.SimpleDateFormat;
-
-import org.openehr.am.archetype.constraintmodel.*;
-import org.openehr.am.archetype.constraintmodel.primitive.*;
-import org.openehr.rm.support.basic.Interval;
-import org.openehr.rm.datatypes.quantity.datetime.*;
-
-/**
- * ADLParser testing config and common logic
- *
- * @author Rong Chen
- * @version 1.0
- */
-public class ParserTestBase extends TestCase {
-
- public ParserTestBase(String test) {
- super(test);
- }
-
- public ParserTestBase(){
- }
-
- protected InputStream loadFromClasspath(String adl) throws Exception {
- return this.getClass().getClassLoader().getResourceAsStream(adl);
- }
-
- // assert CComplexObject object has expected values
- void assertCComplexObject(CComplexObject obj, String rmTypeName,
- String nodeID, Interval occurrences,
- int attributes) throws Exception {
- assertCObject(obj, rmTypeName, nodeID, occurrences);
- assertEquals("attributes.size", attributes, obj.getAttributes().size());
- }
-
- // assert CObject has expected valuess
- void assertCObject(CObject obj, String rmTypeName, String nodeID,
- Interval occurrences) throws Exception {
- assertEquals("rmTypeName", rmTypeName, obj.getRmTypeName());
- assertEquals("nodeID", nodeID, obj.getNodeId());
- assertEquals("occurrences", occurrences, obj.getOccurrences());
- }
-
- // assert CAttribute has expected values
- void assertCAttribute(CAttribute attr, String rmAttributeName,
- CAttribute.Existence existence,
- Cardinality cardinality, int children)
- throws Exception {
- assertEquals("rmAttributeName", rmAttributeName,
- attr.getRmAttributeName());
- assertEquals("existence", existence, attr.getExistence());
- if(attr instanceof CMultipleAttribute) {
- CMultipleAttribute mattr = (CMultipleAttribute) attr;
- assertEquals("cardinality", cardinality, mattr.getCardinality());
- }
- assertEquals("children.size", children, attr.getChildren().size());
- }
-
- // assert CAttribute has expected values
- void assertCAttribute(CAttribute attr, String rmAttributeName,
- int children) throws Exception {
- assertCAttribute(attr, rmAttributeName, CAttribute.Existence.REQUIRED,
- null, children);
- }
-
- // assertion on primitive types
- void assertCBoolean(Object obj, boolean trueValid, boolean falseValid,
- boolean assumed, boolean hasAssumed)
- throws Exception {
- CBoolean b = (CBoolean) fetchFirst(obj);
- assertEquals("trueValid", trueValid, b.isTrueValid());
- assertEquals("falseValid", falseValid, b.isFalseValid());
- assertEquals("assumed value", assumed, b.assumedValue().booleanValue());
- assertEquals("has assumed value", hasAssumed, b.hasAssumedValue());
- }
-
- void assertCInteger(Object obj, Interval interval, int[] values,
- Integer assumed) throws Exception {
- CInteger c = (CInteger) fetchFirst(obj);
- assertEquals("interval", interval, c.getInterval());
- assertEquals("list", intSet(values), c.getList());
- assertEquals("unexpected assumed value", assumed, c.assumedValue());
- }
-
- void assertCReal(Object obj, Interval interval, double[] values,
- Double assumed) throws Exception {
- CReal c = (CReal) fetchFirst(obj);
- assertEquals("interval", interval, c.getInterval());
- assertEquals("list", doubleSet(values), c.getList());
- assertEquals("unexpected assumed value", assumed, c.assumedValue());
- }
-
- void assertCDate(Object obj, String pattern, Interval interval,
- String[] values, String assumed)
- throws Exception {
- CDate c = (CDate) fetchFirst(obj);
- assertEquals("pattern", pattern, c.getPattern());
- assertEquals("interval", interval, c.getInterval());
- assertEquals("list", dateSet(values), c.getList());
- assertEquals("assumed value",
- assumed == null? null :new DvDate(assumed), c.assumedValue());
- }
-
- void assertCDateTime(Object obj, String pattern, Interval interval,
- String[] values, String assumed)
- throws Exception {
- CDateTime c = (CDateTime) fetchFirst(obj);
- assertEquals("pattern", pattern, c.getPattern());
- assertEquals("interval", interval, c.getInterval());
- assertEquals("list", dateTimeSet(values), c.getList());
- assertEquals("assumed value",
- assumed == null? null :new DvDateTime(assumed), c.assumedValue());
- }
-
- // without assumed value
- void assertCDateTime(Object obj, String pattern, Interval interval,
- String[] values) throws Exception {
- assertCDateTime(obj, pattern, interval, values, null);
- }
-
-
- void assertCTime(Object obj, String pattern, Interval interval,
- String[] values, String assumed)
- throws Exception {
- CTime c = (CTime) fetchFirst(obj);
- assertEquals("pattern", pattern, c.getPattern());
- assertEquals("interval", interval, c.getInterval());
- assertEquals("list", timeSet(values), c.getList());
- assertEquals("assumed value",
- assumed == null? null :new DvTime(assumed), c.assumedValue());
- }
-
- // without assumed value
- void assertCTime(Object obj, String pattern, Interval interval,
- String[] values) throws Exception {
- assertCTime(obj, pattern, interval, values, null);
- }
-
- // full assertion with CDuration
- void assertCDuration(Object obj, String value, Interval interval,
- String assumed, String pattern) throws Exception {
- CDuration c = (CDuration) ((CPrimitiveObject) obj).getItem();
- assertEquals("list", value == null ? null : DvDuration.getInstance(value),
- c.getValue());
- assertEquals("interval", interval, c.getInterval());
- assertEquals("assumed value",
- assumed == null? null
- : DvDuration.getInstance(assumed), c.assumedValue());
- assertEquals("pattern wrong", pattern, c.getPattern());
- }
-
- // without pattern
- void assertCDuration(Object obj, String value, Interval interval,
- String assumed) throws Exception {
- assertCDuration(obj, value, interval, assumed, null);
- }
-
- // without assumed value, pattern
- void assertCDuration(Object obj, String value, Interval interval)
- throws Exception {
- assertCDuration(obj, value, interval, null);
- }
-
- // fetch the first CPrimitive from the CAttribute
- CPrimitive fetchFirst(Object obj) {
- return ( (CPrimitiveObject) ( (CAttribute) obj ).getChildren()
- .get(0) ).getItem();
- }
-
- void assertCString(Object obj, String pattern, String[] values,
- String assumedValue) {
- CString c = (CString) ( (CPrimitiveObject) ( (CAttribute) obj ).getChildren()
- .get(0) ).getItem();
- if (pattern == null) {
- assertTrue("pattern null", c.getPattern() == null);
- } else {
- assertEquals("pattern", pattern, c.getPattern());
- }
- assertEquals("list", values == null
- ? null : Arrays.asList(values), c.getList());
- assertEquals("unexpected CString assumed value", assumedValue,
- c.assumedValue());
- }
-
- void assertDateEquals(List set, String[] dates, String pattern)
- throws Exception {
- if (dates == null) {
- assertEquals("set not empty", 0, set.size());
- return;
- }
- List setFromArray = new ArrayList();
- for (int i = 0; i < dates.length; i++) {
- setFromArray.add(new SimpleDateFormat(pattern).parse(dates[ i ]));
- }
- assertTrue("set not equals array, expected: " + setFromArray
- + ", actual: " + set, set.equals(setFromArray));
- }
-
- // methods for coversion of data types
- List intSet(int[] values) {
- if (values == null) {
- return null;
- }
- List set = new ArrayList();
- for (int i = 0; i < values.length; i++) {
- set.add(new Integer(values[ i ]));
- }
- return set;
- }
-
- List doubleSet(double[] values) {
- if (values == null) {
- return null;
- }
- List set = new ArrayList();
- for (int i = 0; i < values.length; i++) {
- set.add(new Double(values[ i ]));
- }
- return set;
- }
-
- // set of DvDate
- List dateSet(String[] values) throws Exception {
- if (values == null) {
- return null;
- }
- List set = new ArrayList();
- for (int i = 0; i < values.length; i++) {
- set.add(date(values[ i ]));
- }
- return set;
- }
-
- // set of DvDateTime
- List dateTimeSet(String[] values) throws Exception {
- if (values == null) {
- return null;
- }
- List set = new ArrayList();
- for (int i = 0; i < values.length; i++) {
- set.add(dateTime(values[ i ]));
- }
- return set;
- }
-
- // set of DvTime
- List timeSet(String[] values) throws Exception {
- if (values == null) {
- return null;
- }
- List set = new ArrayList();
- for (int i = 0; i < values.length; i++) {
- set.add(time(values[ i ]));
- }
- return set;
- }
-
- // convert with default pattern
- DvDateTime dateTime(String value) throws Exception {
- return new DvDateTime(value);
- }
-
- DvTime time(String value) throws Exception {
- return new DvTime(value);
- }
-
- DvDate date(String value) throws Exception {
- return new DvDate(value);
- }
-
- Interval interval(int low, int up) {
- return new Interval(new Integer(low), new Integer(up));
- }
-
- /* fields */
- static protected File dir = new File("res" + File.separator + "test");
-}
+package se.acode.openehr.parser;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.*;
+import java.text.SimpleDateFormat;
+
+import org.openehr.am.archetype.constraintmodel.*;
+import org.openehr.am.archetype.constraintmodel.primitive.*;
+import org.openehr.rm.support.basic.Interval;
+import org.openehr.rm.datatypes.quantity.datetime.*;
+
+/**
+ * ADLParser testing config and common logic
+ *
+ * @author Rong Chen
+ * @version 1.0
+ */
+public class ParserTestBase extends TestCase {
+
+ public ParserTestBase(String test) {
+ super(test);
+ }
+
+ public ParserTestBase(){
+ }
+
+ protected InputStream loadFromClasspath(String adl) throws Exception {
+ return this.getClass().getClassLoader().getResourceAsStream(adl);
+ }
+
+ // assert CComplexObject object has expected values
+ void assertCComplexObject(CComplexObject obj, String rmTypeName,
+ String nodeID, Interval occurrences,
+ int attributes) throws Exception {
+ assertCObject(obj, rmTypeName, nodeID, occurrences);
+ assertEquals("attributes.size", attributes, obj.getAttributes().size());
+ }
+
+ // assert CObject has expected valuess
+ void assertCObject(CObject obj, String rmTypeName, String nodeID,
+ Interval occurrences) throws Exception {
+ assertEquals("rmTypeName", rmTypeName, obj.getRmTypeName());
+ assertEquals("nodeID", nodeID, obj.getNodeId());
+ assertEquals("occurrences", occurrences, obj.getOccurrences());
+ }
+
+ // assert CAttribute has expected values
+ void assertCAttribute(CAttribute attr, String rmAttributeName,
+ CAttribute.Existence existence,
+ Cardinality cardinality, int children)
+ throws Exception {
+ assertEquals("rmAttributeName", rmAttributeName,
+ attr.getRmAttributeName());
+ assertEquals("existence", existence, attr.getExistence());
+ if(attr instanceof CMultipleAttribute) {
+ CMultipleAttribute mattr = (CMultipleAttribute) attr;
+ assertEquals("cardinality", cardinality, mattr.getCardinality());
+ }
+ assertEquals("children.size", children, attr.getChildren().size());
+ }
+
+ // assert CAttribute has expected values
+ void assertCAttribute(CAttribute attr, String rmAttributeName,
+ int children) throws Exception {
+ assertCAttribute(attr, rmAttributeName, CAttribute.Existence.OPTIONAL, /*NB: We changed this to common practice (initially 1.4 logic specified this to be REQUIRED by default.)*/
+ null, children);
+ }
+
+ // assertion on primitive types
+ void assertCBoolean(Object obj, boolean trueValid, boolean falseValid,
+ boolean assumed, boolean hasAssumed)
+ throws Exception {
+ CBoolean b = (CBoolean) fetchFirst(obj);
+ assertEquals("trueValid", trueValid, b.isTrueValid());
+ assertEquals("falseValid", falseValid, b.isFalseValid());
+ assertEquals("assumed value", assumed, b.assumedValue().booleanValue());
+ assertEquals("has assumed value", hasAssumed, b.hasAssumedValue());
+ }
+
+ void assertCInteger(Object obj, Interval interval, int[] values,
+ Integer assumed) throws Exception {
+ CInteger c = (CInteger) fetchFirst(obj);
+ assertEquals("interval", interval, c.getInterval());
+ assertEquals("list", intSet(values), c.getList());
+ assertEquals("unexpected assumed value", assumed, c.assumedValue());
+ }
+
+ void assertCReal(Object obj, Interval interval, double[] values,
+ Double assumed) throws Exception {
+ CReal c = (CReal) fetchFirst(obj);
+ assertEquals("interval", interval, c.getInterval());
+ assertEquals("list", doubleSet(values), c.getList());
+ assertEquals("unexpected assumed value", assumed, c.assumedValue());
+ }
+
+ void assertCDate(Object obj, String pattern, Interval interval,
+ String[] values, String assumed)
+ throws Exception {
+ CDate c = (CDate) fetchFirst(obj);
+ assertEquals("pattern", pattern, c.getPattern());
+ assertEquals("interval", interval, c.getInterval());
+ assertEquals("list", dateSet(values), c.getList());
+ assertEquals("assumed value",
+ assumed == null? null :new DvDate(assumed), c.assumedValue());
+ }
+
+ void assertCDateTime(Object obj, String pattern, Interval interval,
+ String[] values, String assumed)
+ throws Exception {
+ CDateTime c = (CDateTime) fetchFirst(obj);
+ assertEquals("pattern", pattern, c.getPattern());
+ assertEquals("interval", interval, c.getInterval());
+ assertEquals("list", dateTimeSet(values), c.getList());
+ assertEquals("assumed value",
+ assumed == null? null :new DvDateTime(assumed), c.assumedValue());
+ }
+
+ // without assumed value
+ void assertCDateTime(Object obj, String pattern, Interval interval,
+ String[] values) throws Exception {
+ assertCDateTime(obj, pattern, interval, values, null);
+ }
+
+
+ void assertCTime(Object obj, String pattern, Interval interval,
+ String[] values, String assumed)
+ throws Exception {
+ CTime c = (CTime) fetchFirst(obj);
+ assertEquals("pattern", pattern, c.getPattern());
+ assertEquals("interval", interval, c.getInterval());
+ assertEquals("list", timeSet(values), c.getList());
+ assertEquals("assumed value",
+ assumed == null? null :new DvTime(assumed), c.assumedValue());
+ }
+
+ // without assumed value
+ void assertCTime(Object obj, String pattern, Interval interval,
+ String[] values) throws Exception {
+ assertCTime(obj, pattern, interval, values, null);
+ }
+
+ // full assertion with CDuration
+ void assertCDuration(Object obj, String value, Interval interval,
+ String assumed, String pattern) throws Exception {
+ CDuration c = (CDuration) ((CPrimitiveObject) obj).getItem();
+ assertEquals("list", value == null ? null : DvDuration.getInstance(value),
+ c.getValue());
+ assertEquals("interval", interval, c.getInterval());
+ assertEquals("assumed value",
+ assumed == null? null
+ : DvDuration.getInstance(assumed), c.assumedValue());
+ assertEquals("pattern wrong", pattern, c.getPattern());
+ }
+
+ // without pattern
+ void assertCDuration(Object obj, String value, Interval interval,
+ String assumed) throws Exception {
+ assertCDuration(obj, value, interval, assumed, null);
+ }
+
+ // without assumed value, pattern
+ void assertCDuration(Object obj, String value, Interval interval)
+ throws Exception {
+ assertCDuration(obj, value, interval, null);
+ }
+
+ // fetch the first CPrimitive from the CAttribute
+ CPrimitive fetchFirst(Object obj) {
+ return ( (CPrimitiveObject) ( (CAttribute) obj ).getChildren()
+ .get(0) ).getItem();
+ }
+
+ void assertCString(Object obj, String pattern, String[] values,
+ String assumedValue) {
+ CString c = (CString) ( (CPrimitiveObject) ( (CAttribute) obj ).getChildren()
+ .get(0) ).getItem();
+ if (pattern == null) {
+ assertTrue("pattern null", c.getPattern() == null);
+ } else {
+ assertEquals("pattern", pattern, c.getPattern());
+ }
+ assertEquals("list", values == null
+ ? null : Arrays.asList(values), c.getList());
+ assertEquals("unexpected CString assumed value", assumedValue,
+ c.assumedValue());
+ }
+
+ void assertDateEquals(List set, String[] dates, String pattern)
+ throws Exception {
+ if (dates == null) {
+ assertEquals("set not empty", 0, set.size());
+ return;
+ }
+ List setFromArray = new ArrayList();
+ for (int i = 0; i < dates.length; i++) {
+ setFromArray.add(new SimpleDateFormat(pattern).parse(dates[ i ]));
+ }
+ assertTrue("set not equals array, expected: " + setFromArray
+ + ", actual: " + set, set.equals(setFromArray));
+ }
+
+ // methods for coversion of data types
+ List intSet(int[] values) {
+ if (values == null) {
+ return null;
+ }
+ List set = new ArrayList();
+ for (int i = 0; i < values.length; i++) {
+ set.add(new Integer(values[ i ]));
+ }
+ return set;
+ }
+
+ List doubleSet(double[] values) {
+ if (values == null) {
+ return null;
+ }
+ List set = new ArrayList();
+ for (int i = 0; i < values.length; i++) {
+ set.add(new Double(values[ i ]));
+ }
+ return set;
+ }
+
+ // set of DvDate
+ List dateSet(String[] values) throws Exception {
+ if (values == null) {
+ return null;
+ }
+ List set = new ArrayList();
+ for (int i = 0; i < values.length; i++) {
+ set.add(date(values[ i ]));
+ }
+ return set;
+ }
+
+ // set of DvDateTime
+ List dateTimeSet(String[] values) throws Exception {
+ if (values == null) {
+ return null;
+ }
+ List set = new ArrayList();
+ for (int i = 0; i < values.length; i++) {
+ set.add(dateTime(values[ i ]));
+ }
+ return set;
+ }
+
+ // set of DvTime
+ List timeSet(String[] values) throws Exception {
+ if (values == null) {
+ return null;
+ }
+ List set = new ArrayList();
+ for (int i = 0; i < values.length; i++) {
+ set.add(time(values[ i ]));
+ }
+ return set;
+ }
+
+ // convert with default pattern
+ DvDateTime dateTime(String value) throws Exception {
+ return new DvDateTime(value);
+ }
+
+ DvTime time(String value) throws Exception {
+ return new DvTime(value);
+ }
+
+ DvDate date(String value) throws Exception {
+ return new DvDate(value);
+ }
+
+ Interval interval(int low, int up) {
+ return new Interval(new Integer(low), new Integer(up));
+ }
+
+ /* fields */
+ static protected File dir = new File("res" + File.separator + "test");
+}
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/PathTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/PathTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/RegularExpressionTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/RegularExpressionTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/SpecialStringTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/SpecialStringTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/StructureTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/StructureTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/TermBindingTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/TermBindingTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/UnicodeBOMSupportTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/UnicodeBOMSupportTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/java/se/acode/openehr/parser/UnicodeSupportTest.java b/adl-parser/src/test/java/se/acode/openehr/parser/UnicodeSupportTest.java
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-SOME_TYPE.generic_type_basic.draft.adl b/adl-parser/src/test/resources/adl-test-SOME_TYPE.generic_type_basic.draft.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-SOME_TYPE.generic_type_use_node.draft.adl b/adl-parser/src/test/resources/adl-test-SOME_TYPE.generic_type_use_node.draft.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-car.paths.test.adl b/adl-parser/src/test/resources/adl-test-car.paths.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-car.use_node.test.adl b/adl-parser/src/test/resources/adl-test-car.use_node.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-composition.dv_coded_text.test.adl b/adl-parser/src/test/resources/adl-test-composition.dv_coded_text.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_bindings.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_bindings.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_desc_missing_purpose.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_desc_missing_purpose.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_description.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_description.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_description2.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_description2.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_identification.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_identification.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_internal_ref.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_internal_ref.test.adl
old mode 100755
new mode 100644
index da16b430..c7bc6d86
--- a/adl-parser/src/test/resources/adl-test-entry.archetype_internal_ref.test.adl
+++ b/adl-parser/src/test/resources/adl-test-entry.archetype_internal_ref.test.adl
@@ -19,6 +19,10 @@ definition
use_node COMPLEX_OBJECT /items[at0001]
use_node COMPLEX_OBJECT /items[at0002]
}
+ attribute4 matches {
+ use_node SECTION[at0005] /items[at0001]
+ use_node SECTION[at0006] /items[at0002]
+ }
}
ontology
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_internal_ref2.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_internal_ref2.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_language.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_language.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_language.test2.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_language.test2.adl
new file mode 100644
index 00000000..ae6b3e15
--- /dev/null
+++ b/adl-parser/src/test/resources/adl-test-entry.archetype_language.test2.adl
@@ -0,0 +1,55 @@
+archetype
+ adl-test-ENTRY.archetype_language.draft
+
+concept
+ [at0000] -- test
+
+language
+ original_language = <[ISO_639-1::en]>
+ translations = <
+ ["de"] = <
+ language = <[ISO_639-1::de]>
+ author = <
+ ["name"] = <"Harry Potter">
+ ["email"] = <"harry@something.somewhere.co.uk">
+ >
+ accreditation = <"British Medical Translator id 00400595">
+ other_details = <
+ ["review 1"] = <"Ron Weasley">
+ ["review 2"] = <"Rubeus Hagrid">
+ >
+ >
+ ["ru"] = <
+ language = <[ISO_639-1::ru]>
+ author = <
+ ["name"] = <"Vladimir Nabokov">
+ ["email"] = <"vladimir@something.somewhere.ru">
+ >
+ accreditation = <"Russion Translator id 892230A">
+ >
+ >
+definition
+ ENTRY[at0000] matches {*}
+
+ontology
+ primary_language = <"en">
+ languages_available = <"en", ...>
+
+ term_definitions = <
+ ["en"] = <
+ items = <
+ ["at0000"] = <
+ text = <"test">;
+ description = <"test">
+ >
+ >
+ >
+ ["ru"] = <
+ items = <
+ ["at0000"] = <
+ text = <"test">;
+ description = <"test2">
+ >
+ >
+ >
+ >
\ No newline at end of file
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_language_no_accreditation.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_language_no_accreditation.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_language_order_of_translation_details.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_language_order_of_translation_details.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_ontology.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_ontology.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_slot.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_slot.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_slot.test2.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_slot.test2.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.archetype_uncommonkeys.test.adl b/adl-parser/src/test/resources/adl-test-entry.archetype_uncommonkeys.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.basic_types.test.adl b/adl-parser/src/test/resources/adl-test-entry.basic_types.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_code_phrase.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_code_phrase.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_ordinal.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_ordinal.test.adl
index 1c2761fd..8e0abec5 100755
--- a/adl-parser/src/test/resources/adl-test-entry.c_dv_ordinal.test.adl
+++ b/adl-parser/src/test/resources/adl-test-entry.c_dv_ordinal.test.adl
@@ -36,8 +36,16 @@ definition
C_DV_ORDINAL <
>
}
- }
-
+ }
+ ELEMENT[at10004] matches { -- ordinal with two duplicated values
+ value matches {
+ 0|[local::at0003.0], -- capsule
+ 1|[local::at0003.1], -- powder
+ 1|[local::at0003.2], -- tablet
+ 3|[local::at0003.3], -- solution
+ 4|[local::at0003.4] -- suspension
+ }
+ }
}
}
}
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_empty.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_empty.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_full.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_full.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_full2.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_full2.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_full3.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_full3.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_item_units_only.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_item_units_only.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_list.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_list.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_property.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_property.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_reversed.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_quantity_reversed.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.c_dv_scale.test.adl b/adl-parser/src/test/resources/adl-test-entry.c_dv_scale.test.adl
new file mode 100644
index 00000000..f8e8605d
--- /dev/null
+++ b/adl-parser/src/test/resources/adl-test-entry.c_dv_scale.test.adl
@@ -0,0 +1,97 @@
+archetype
+ adl-test-ENTRY.c_dv_scale.test
+
+concept
+ [at0000]
+
+language
+ original_language = <[ISO_639-1::en]>
+
+definition
+ ENTRY[at0000] matches {
+ types matches {
+ LIST[at0001] matches {
+ items cardinality matches {0..*} matches {
+ ELEMENT[at10001] matches { -- scale
+ value matches {
+ 0.0|[local::at0003.0], -- capsule
+ 1.0|[local::at0003.1], -- powder
+ 2.5|[local::at0003.2], -- tablet
+ 3.8|[local::at0003.3], -- solution
+ 4.4|[local::at0003.4] -- suspension
+ }
+ }
+ ELEMENT[at10002] matches { -- scale with assumed value
+ value matches {
+ 0|[local::at0003.0], -- capsule
+ 1|[local::at0003.1], -- powder
+ 2|[local::at0003.2], -- tablet
+ 3|[local::at0003.3], -- solution
+ 4.1|[local::at0003.4]; -- suspension
+ 2 -- assumed value
+ }
+ }
+ ELEMENT[at10003] matches { -- scale, any allowed
+ value matches { -- any allowed
+ DV_SCALE matches { * }
+ }
+ }
+ ELEMENT[at10004] matches { -- scale with two duplicated values
+ value matches {
+ 0|[local::at0003.0], -- capsule
+ 1.5|[local::at0003.1], -- powder
+ 1.5|[local::at0003.2], -- tablet
+ 3.5|[local::at0003.3], -- solution
+ 4|[local::at0003.4] -- suspension
+ }
+ }
+ ELEMENT[at10005] occurrences matches {0..1} matches { -- MyScale NORMAL
+ value matches {
+ DV_SCALE matches {
+ value matches {0}
+ symbol matches {
+ DV_CODED_TEXT matches {
+ defining_code matches {
+ [local::at0003.0]
+ } -- 0scale
+ }
+ }
+ }
+ DV_SCALE matches {
+ value matches {1.5}
+ symbol matches {
+ DV_CODED_TEXT matches {
+ defining_code matches {
+ [local::at0003.2]
+ } -- 1.5scale
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ontology
+ primary_language = <"en">
+ languages_available = <"en", ...>
+ term_definitions = <
+ ["en"] = <
+ items = <
+ ["at0000"] = <
+ text = <"domain types test">
+ description = <"domain types test">
+ >
+ ["at0001"] = <
+ text = <"items">
+ description = <"items">
+ >
+ ["at10001"] = <
+ text = <"c_dv_scale">
+ description = <"c_dv_scale node">
+ >
+ >
+ >
+ >
\ No newline at end of file
diff --git a/adl-parser/src/test/resources/adl-test-entry.constraint_binding.test.adl b/adl-parser/src/test/resources/adl-test-entry.constraint_binding.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.constraint_ref.test.adl b/adl-parser/src/test/resources/adl-test-entry.constraint_ref.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.datetime.test.adl b/adl-parser/src/test/resources/adl-test-entry.datetime.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.domain_types.test.adl b/adl-parser/src/test/resources/adl-test-entry.domain_types.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.durations.test.adl b/adl-parser/src/test/resources/adl-test-entry.durations.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.empty_other_contributors.test.adl b/adl-parser/src/test/resources/adl-test-entry.empty_other_contributors.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.missing_language.test.adl b/adl-parser/src/test/resources/adl-test-entry.missing_language.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.mixed_node_types.draft.adl b/adl-parser/src/test/resources/adl-test-entry.mixed_node_types.draft.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.most_minimal.test.adl b/adl-parser/src/test/resources/adl-test-entry.most_minimal.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.multi_language.test.adl b/adl-parser/src/test/resources/adl-test-entry.multi_language.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.regular_expression.test.adl b/adl-parser/src/test/resources/adl-test-entry.regular_expression.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.special_string.test.adl b/adl-parser/src/test/resources/adl-test-entry.special_string.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.structure_test1.test.adl b/adl-parser/src/test/resources/adl-test-entry.structure_test1.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.structure_test2.test.adl b/adl-parser/src/test/resources/adl-test-entry.structure_test2.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.term_binding.test.adl b/adl-parser/src/test/resources/adl-test-entry.term_binding.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.term_binding2.test.adl b/adl-parser/src/test/resources/adl-test-entry.term_binding2.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.testtranslations.test.adl b/adl-parser/src/test/resources/adl-test-entry.testtranslations.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.translations_author_language.test.adl b/adl-parser/src/test/resources/adl-test-entry.translations_author_language.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.translations_language_author.test.adl b/adl-parser/src/test/resources/adl-test-entry.translations_language_author.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.unicode_BOM_support.test.adl b/adl-parser/src/test/resources/adl-test-entry.unicode_BOM_support.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/adl-test-entry.unicode_support.test.adl b/adl-parser/src/test/resources/adl-test-entry.unicode_support.test.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.auscultation.v1.adl b/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.auscultation.v1.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.duration_interval_test.v0.adl b/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.duration_interval_test.v0.adl
new file mode 100644
index 00000000..9e4e4a1b
--- /dev/null
+++ b/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.duration_interval_test.v0.adl
@@ -0,0 +1,129 @@
+archetype (adl_version=1.4)
+ openEHR-EHR-CLUSTER.duration_interval_test.v0
+
+concept
+ [at0000] -- Duration interval test
+language
+ original_language = <[ISO_639-1::de]>
+description
+ original_author = <
+ ["name"] = <"s">
+ >
+ details = <
+ ["de"] = <
+ language = <[ISO_639-1::de]>
+ purpose = <"test duration constraints">
+ use = <"">
+ misuse = <"">
+ copyright = <"">
+ >
+ >
+ lifecycle_state = <"in_development">
+ other_contributors = <>
+ other_details = <
+ ["MD5-CAM-1.0.1"] = <"56BA0D180BE093539E02771672EF6BA2">
+ >
+
+definition
+ CLUSTER[at0000] matches { -- Duration interval test
+ items cardinality matches {1..*; unordered} matches {
+ ELEMENT[at0001] occurrences matches {0..1} matches { -- D1
+ value matches {
+ DV_DURATION matches {
+ value matches {PD/|>P10D..PT0M..PT0M|}
+ }
+ }
+ }
+ ELEMENT[at0004] occurrences matches {0..1} matches { -- D3
+ value matches {
+ DV_DURATION matches {
+ value matches {PD/|=P10D|}
+ }
+ }
+ }
+ ELEMENT[at0008] occurrences matches {0..1} matches { -- D6
+ value matches {
+ DV_DURATION matches {
+ value matches {|<=PT110M|}
+ }
+ }
+ }
+ }
+ }
+
+ontology
+ term_definitions = <
+ ["de"] = <
+ items = <
+ ["at0000"] = <
+ text = <"Duration interval test">
+ description = <"unknown">
+ >
+ ["at0001"] = <
+ text = <"D1">
+ description = <"*">
+ >
+ ["at0003"] = <
+ text = <"D2">
+ description = <"*">
+ >
+ ["at0004"] = <
+ text = <"D3">
+ description = <"*">
+ >
+ ["at0005"] = <
+ text = <"D4">
+ description = <"*">
+ >
+ ["at0006"] = <
+ text = <"D unconstrained">
+ description = <"*">
+ >
+ ["at0007"] = <
+ text = <"D5">
+ description = <"*">
+ >
+ ["at0008"] = <
+ text = <"D6">
+ description = <"*">
+ >
+ ["at0009"] = <
+ text = <"D1a">
+ description = <"*">
+ >
+ >
+ >
+ >
diff --git a/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.ordinalandscale.v0.adl b/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.ordinalandscale.v0.adl
new file mode 100644
index 00000000..c8cc6689
--- /dev/null
+++ b/adl-parser/src/test/resources/openEHR-EHR-CLUSTER.ordinalandscale.v0.adl
@@ -0,0 +1,178 @@
+archetype (adl_version=1.4; uid=64891061-481c-44ce-aa73-1913ef8dc66d)
+ openEHR-EHR-CLUSTER.ordinalandscale.v0
+
+concept
+ [at0000] -- Ordinalandscale
+language
+ original_language = <[ISO_639-1::de]>
+description
+ original_author = <
+ ["name"] = <"">
+ >
+ details = <
+ ["de"] = <
+ language = <[ISO_639-1::de]>
+ purpose = <"">
+ use = <"">
+ misuse = <"">
+ copyright = <"© openEHR Foundation">
+ >
+ >
+ lifecycle_state = <"in_development">
+ other_contributors = <>
+ other_details = <
+ ["licence"] = <"This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.">
+ ["custodian_organisation"] = <"openEHR Foundation">
+ ["original_namespace"] = <"org.openehr">
+ ["original_publisher"] = <"openEHR Foundation">
+ ["custodian_namespace"] = <"org.openehr">
+ ["MD5-CAM-1.0.1"] = <"60400C49A960FAF443B1EC1DB870040B">
+ ["build_uid"] = <"73064b08-4ae3-46c7-941d-b45e5066e7a3">
+ ["revision"] = <"0.0.1-alpha">
+ >
+
+definition
+ CLUSTER[at0000] matches { -- Ordinalandscale
+ items cardinality matches {1..*; unordered} matches {
+ ELEMENT[at0001] occurrences matches {0..1} matches { -- MYOrdinal
+ value matches {
+ 1|[local::at0002], -- 1ord
+ 2|[local::at0003], -- 2ord
+ 3|[local::at0004] -- 3ord
+ }
+ }
+ ELEMENT[at0005] occurrences matches {0..1} matches { -- MyScale
+ value matches {
+ 1.0|[local::at0006], -- 1.0scale
+ 2.5|[local::at0007], -- 2.5scale
+ 3.0|[local::at0008] -- 3.0scale
+ }
+ }
+ ELEMENT[at0009] occurrences matches {0..1} matches { -- MyScale2
+ value matches {
+ 1.2|[local::at0010], -- 1.2scale
+ 2.5|[local::at0011], -- 2.5scale
+ 3|[local::at00012] -- 3scale
+ }
+ }
+ ELEMENT[at0013] occurrences matches {0..1} matches { -- MyScale3
+ value matches {
+ 1.5|[local::at0014], -- 1.5scale
+ 2|[local::at0015], -- 2scale
+ 3|[local::at00016] -- 3scale
+ }
+ }
+ ELEMENT[at0017] occurrences matches {0..1} matches { -- MyScale NORMAL
+ value matches {
+ DV_SCALE matches {
+ value matches {0}
+ symbol matches {
+ DV_CODED_TEXT matches {
+ defining_code matches {
+ [local::at0018]
+ } -- 0scale
+ }
+ }
+ }
+ DV_SCALE matches {
+ value matches {1.5}
+ symbol matches {
+ DV_CODED_TEXT matches {
+ defining_code matches {
+ [local::at0019]
+ } -- 1.5scale
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ontology
+ term_definitions = <
+ ["de"] = <
+ items = <
+ ["at0000"] = <
+ text = <"Ordinalandscale">
+ description = <"unknown">
+ >
+ ["at0001"] = <
+ text = <"My Ordinal">
+ description = <"*">
+ >
+ ["at0002"] = <
+ text = <"1ord">
+ description = <"*">
+ >
+ ["at0003"] = <
+ text = <"2ord">
+ description = <"*">
+ >
+ ["at0004"] = <
+ text = <"3ord">
+ description = <"*">
+ >
+ ["at0005"] = <
+ text = <"MyScale">
+ description = <"*">
+ >
+ ["at0006"] = <
+ text = <"1scale">
+ description = <"*">
+ >
+ ["at0007"] = <
+ text = <"2.5scale">
+ description = <"*">
+ >
+ ["at0008"] = <
+ text = <"3scale">
+ description = <"*">
+ >
+ ["at0009"] = <
+ text = <"MyScale2">
+ description = <"*">
+ >
+ ["at0010"] = <
+ text = <"1.2scale">
+ description = <"*">
+ >
+ ["at0011"] = <
+ text = <"2.5scale">
+ description = <"*">
+ >
+ ["at0012"] = <
+ text = <"3scale">
+ description = <"*">
+ >
+ ["at0013"] = <
+ text = <"MyScale2">
+ description = <"*">
+ >
+ ["at0014"] = <
+ text = <"1.5scale">
+ description = <"*">
+ >
+ ["at0015"] = <
+ text = <"2scale">
+ description = <"*">
+ >
+ ["at0016"] = <
+ text = <"3scale">
+ description = <"*">
+ >
+ ["at0017"] = <
+ text = <"MyScale NORMAL">
+ description = <"*">
+ >
+ ["at0018"] = <
+ text = <"0scale">
+ description = <"*">
+ >
+ ["at0019"] = <
+ text = <"1.5scale">
+ description = <"*">
+ >
+ >
+ >
+ >
diff --git a/adl-parser/src/test/resources/openEHR-EHR-ELEMENT.uid_test.v1.adl b/adl-parser/src/test/resources/openEHR-EHR-ELEMENT.uid_test.v1.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/openEHR-EHR-ELEMENT.uid_test.v2.adl b/adl-parser/src/test/resources/openEHR-EHR-ELEMENT.uid_test.v2.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/openEHR-EHR-EVALUATION.columna_vertebral.v1.adl b/adl-parser/src/test/resources/openEHR-EHR-EVALUATION.columna_vertebral.v1.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/openEHR-EHR-OBSERVATION.test_internal_ref_binding.v1.adl b/adl-parser/src/test/resources/openEHR-EHR-OBSERVATION.test_internal_ref_binding.v1.adl
old mode 100755
new mode 100644
diff --git a/adl-parser/src/test/resources/openEHR-EHR-OBSERVATION.testassumedvalue.v1.adl b/adl-parser/src/test/resources/openEHR-EHR-OBSERVATION.testassumedvalue.v1.adl
old mode 100755
new mode 100644
diff --git a/adl-serializer/docs/changes.txt b/adl-serializer/docs/changes.txt
old mode 100755
new mode 100644
diff --git a/adl-serializer/pom.xml b/adl-serializer/pom.xml
index 0d39ed21..e6fc1ab7 100755
--- a/adl-serializer/pom.xml
+++ b/adl-serializer/pom.xml
@@ -1,9 +1,9 @@
4.0.0
- openehr
- ref_impl_java
- 1.0.5-SNAPSHOT
+ org.openehr.java-libs
+ java-libs
+ 0-SNAPSHOT
adl-serializer
jar
@@ -27,32 +27,32 @@
- openehr
+ org.openehr.java-libs
openehr-rm-core
${project.version}
- openehr
+ org.openehr.java-libs
openehr-rm-domain
${project.version}
- openehr
+ org.openehr.java-libs
openehr-aom
${project.version}
- openehr
+ org.openehr.java-libs
openehr-ap
${project.version}
- openehr
+ org.openehr.java-libs
mini-termserv
${project.version}
- openehr
+ org.openehr.java-libs
adl-parser
${project.version}
test
diff --git a/adl-serializer/readme.txt b/adl-serializer/readme.txt
old mode 100755
new mode 100644
diff --git a/adl-serializer/src/main/java/org/openehr/am/serialize/ADLSerializer.java b/adl-serializer/src/main/java/org/openehr/am/serialize/ADLSerializer.java
old mode 100755
new mode 100644
index af138e25..27b08494
--- a/adl-serializer/src/main/java/org/openehr/am/serialize/ADLSerializer.java
+++ b/adl-serializer/src/main/java/org/openehr/am/serialize/ADLSerializer.java
@@ -1,1290 +1,1338 @@
-/*
- * component: "openEHR Reference Implementation"
- * description: "Class ADLSerializer"
- * keywords: "archetype"
- *
- * author: "Rong Chen "
- * support: "Acode HB "
- * copyright: "Copyright (c) 2004,2005,2006 Acode HB, Sweden"
- * license: "See notice at bottom of class"
- *
- * file: "$URL: $"
- * revision: "$LastChangedRevision: 41 $"
- * last_change: "$LastChangedDate: 2006-07-12 23:24:42 +0200 (Wed, 12 Jul 2006) $"
- */
-package org.openehr.am.serialize;
-
-import java.io.BufferedOutputStream;
-import java.io.BufferedWriter;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.nio.charset.Charset;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.openehr.am.archetype.Archetype;
-import org.openehr.am.archetype.assertion.Assertion;
-import org.openehr.am.archetype.constraintmodel.ArchetypeInternalRef;
-import org.openehr.am.archetype.constraintmodel.ArchetypeSlot;
-import org.openehr.am.archetype.constraintmodel.CAttribute;
-import org.openehr.am.archetype.constraintmodel.CComplexObject;
-import org.openehr.am.archetype.constraintmodel.CDomainType;
-import org.openehr.am.archetype.constraintmodel.CMultipleAttribute;
-import org.openehr.am.archetype.constraintmodel.CObject;
-import org.openehr.am.archetype.constraintmodel.CPrimitiveObject;
-import org.openehr.am.archetype.constraintmodel.Cardinality;
-import org.openehr.am.archetype.constraintmodel.ConstraintRef;
-import org.openehr.am.archetype.constraintmodel.primitive.CBoolean;
-import org.openehr.am.archetype.constraintmodel.primitive.CDate;
-import org.openehr.am.archetype.constraintmodel.primitive.CDateTime;
-import org.openehr.am.archetype.constraintmodel.primitive.CDuration;
-import org.openehr.am.archetype.constraintmodel.primitive.CInteger;
-import org.openehr.am.archetype.constraintmodel.primitive.CPrimitive;
-import org.openehr.am.archetype.constraintmodel.primitive.CReal;
-import org.openehr.am.archetype.constraintmodel.primitive.CString;
-import org.openehr.am.archetype.constraintmodel.primitive.CTime;
-import org.openehr.am.archetype.ontology.ArchetypeOntology;
-import org.openehr.am.archetype.ontology.ArchetypeTerm;
-import org.openehr.am.archetype.ontology.OntologyBinding;
-import org.openehr.am.archetype.ontology.OntologyDefinitions;
-import org.openehr.am.archetype.ontology.QueryBindingItem;
-import org.openehr.am.archetype.ontology.TermBindingItem;
-import org.openehr.am.openehrprofile.datatypes.quantity.CDvOrdinal;
-import org.openehr.am.openehrprofile.datatypes.quantity.CDvQuantity;
-import org.openehr.am.openehrprofile.datatypes.quantity.CDvQuantityItem;
-import org.openehr.am.openehrprofile.datatypes.quantity.Ordinal;
-import org.openehr.am.openehrprofile.datatypes.text.CCodePhrase;
-import org.openehr.rm.common.resource.AuthoredResource;
-import org.openehr.rm.common.resource.ResourceDescription;
-import org.openehr.rm.common.resource.ResourceDescriptionItem;
-import org.openehr.rm.common.resource.TranslationDetails;
-import org.openehr.rm.datatypes.quantity.DvQuantity;
-import org.openehr.rm.datatypes.text.CodePhrase;
-import org.openehr.rm.support.basic.Interval;
-import org.openehr.rm.support.identification.ArchetypeID;
-import org.openehr.rm.support.identification.ObjectID;
-
-/**
- * ADL serializer for the openEHR Java kernel
- *
- * @author Rong Chen
- * @author Mattias Forss, Johan Hjalmarsson
- * @author Sebastian Garde
- *
- * @version 1.0
- */
-public class ADLSerializer {
-
- /**
- * Create an outputter with default encoding, indent and lineSeparator
- */
- public ADLSerializer() {
- this.encoding = UTF8;
- this.indent = " "; // 4 white space characters
- this.lineSeparator = "\r\n";
- }
-
- /**
- * Output given archetype as string in ADL format
- *
- * @param archetype
- * @return a string in ADL format
- * @throws IOException
- */
- public String output(Archetype archetype) throws IOException {
- StringWriter writer = new StringWriter();
- output(archetype, writer);
- return writer.toString();
- }
-
- /**
- * Output archetype DEFINITION as string in ADL format
- *
- * @param archetype
- * @return a string in ADL format
- * @throws IOException
- */
- public String outputDefinitionOnly(Archetype archetype) throws IOException {
- StringWriter writer = new StringWriter();
-
- printDefinition(archetype.getDefinition(), writer);
-
- return writer.toString();
- }
-
- /**
- * Output given archetype to outputStream
- *
- * @param archetype
- * @param out
- * @throws IOException
- */
- public void output(Archetype archetype, OutputStream out)
- throws IOException {
- Writer writer = new BufferedWriter(new OutputStreamWriter(
- new BufferedOutputStream(out), encoding));
- output(archetype, writer);
- }
-
- /**
- * Output given archetype to writer
- *
- * @param archetype
- * @param out
- * @throws IOException
- */
- public void output(Archetype archetype, Writer out) throws IOException {
- printHeader(archetype.getAdlVersion(), archetype.getArchetypeId(),
- archetype.getParentArchetypeId(), archetype.getUid(), archetype.getConcept(), out);
- newline(out);
-
- printLanguage(archetype, out);
- newline(out);
-
- if(archetype.getDescription() != null) {
- printDescription(archetype.getDescription(), out);
- newline(out);
- }
-
- printDefinition(archetype.getDefinition(), out);
- newline(out);
-
- printOntology(archetype.getOntology(), out);
- out.flush();
- out.close();
- }
-
- protected void printHeader(String adlVersion,
- ArchetypeID id, ArchetypeID parentId, ObjectID uid,
- String conceptCode, Writer out) throws IOException {
-
- out.write("archetype");
- if(StringUtils.isNotEmpty(adlVersion) || (uid != null && StringUtils.isNotEmpty(uid.toString()))) {
- out.write(" (");
- }
-
- if(StringUtils.isNotEmpty(adlVersion)) {
- out.write("adl_version=");
- out.write(adlVersion);
- }
- if(uid != null && StringUtils.isNotEmpty(uid.toString())) {
- out.write("uid=");
- out.write(uid.toString());
- }
- if(StringUtils.isNotEmpty(adlVersion) || (uid!=null &&StringUtils.isNotEmpty(uid.toString()))) {
- out.write(")");
- }
- newline(out);
- indent(1, out);
- out.write(id.toString());
- newline(out);
-
- if (parentId != null) {
- out.write("specialize");
- newline(out);
- indent(1, out);
- out.write(parentId.toString());
- newline(out);
- }
-
- newline(out);
- out.write("concept");
- newline(out);
- indent(1, out);
- out.write("[" + conceptCode + "]");
- newline(out);
- }
-
- protected void printLanguage(AuthoredResource authored,
- Writer out) throws IOException {
-
- out.write("language");
- newline(out);
- indent(1, out);
- out.write("original_language = <");
- out.write("[");
- out.write(authored.getOriginalLanguage().getTerminologyId().getValue());
- out.write("::");
- out.write(authored.getOriginalLanguage().getCodeString());
- out.write("]");
- out.write(">");
- newline(out);
- if(authored.getTranslations() != null) {
- indent(1, out);
- out.write("translations = <");
- newline(out);
- Map translations =
- authored.getTranslations();
- for(String lang : translations.keySet()) {
- TranslationDetails td = translations.get(lang);
-
- indent(2, out);
- out.write("[\"");
- out.write(lang);
- out.write("\"] = <");
- newline(out);
-
- indent(3, out);
- out.write("language = <");
- out.write("[");
- out.write(td.getLanguage().getTerminologyId().getValue());
- out.write("::");
- out.write(td.getLanguage().getCodeString());
- out.write("]");
- out.write(">");
- newline(out);
-
- indent(3, out);
- out.write("author = <");
- newline(out);
- printMap(td.getAuthor(), out, 4);
- indent(3, out);
- out.write(">");
- newline(out);
-
- if(td.getAccreditation() != null) {
- indent(3, out);
- out.write("accreditation = <\"");
- out.write(td.getAccreditation());
- out.write("\">");
- newline(out);
- }
-
- if(td.getOtherDetails() != null) {
- indent(3, out);
- out.write("other_details = <");
- newline(out);
- printMap(td.getOtherDetails(), out, 4);
- indent(3, out);
- out.write(">");
- newline(out);
- }
-
- indent(2, out);
- out.write(">");
- newline(out);
- }
- indent(1, out);
- out.write(">");
- newline(out);
- }
- }
-
- protected void printMap(Map map, Writer out, int indent)
- throws IOException {
- if(map == null || map.size() == 0) {
- return;
- }
- for(String key : map.keySet()) {
- indent(indent, out);
- out.write("[\"");
- out.write(key);
- out.write("\"] = <\"");
- out.write(map.get(key));
- out.write("\">");
- newline(out);
- }
- }
-
- protected void printDescription(ResourceDescription description, Writer out)
- throws IOException {
-
- if (description == null) {
- return;
- }
-
- out.write("description");
- newline(out);
-
- indent(1, out);
- out.write("original_author = <");
- newline(out);
- Map map = description.getOriginalAuthor();
- for (String key : map.keySet()) {
- indent(2, out);
- out.write("[\"" + key + "\"] = <\"" + map.get(key) + "\">");
- newline(out);
- }
- indent(1, out);
- out.write(">");
- newline(out);
-
- indent(1, out);
- out.write("lifecycle_state = <\"");
- out.write(description.getLifecycleState());
- out.write("\">");
- newline(out);
-
- printNonEmptyString("resource_package_uri", description.getResourcePackageUri(), 1, out);
-
- indent(1, out);
- out.write("details = <");
- newline(out);
- for (ResourceDescriptionItem item : description.getDetails()) {
- printDescriptionItem(item, 2, out);
- }
- indent(1, out);
- out.write(">");
- newline(out);
- }
-
- protected void printDescriptionItem(ResourceDescriptionItem item,
- int indent, Writer out) throws IOException {
- indent(indent, out);
- out.write("[\"");
- out.write(item.getLanguage().getCodeString());
- out.write("\"] = <");
- newline(out);
-
- indent(indent + 1, out);
- out.write("language = <");
- out.write("[");
- out.write(item.getLanguage().getTerminologyId().getValue());
- out.write("::");
- out.write(item.getLanguage().getCodeString());
- out.write("]>");
- newline(out);
-
- printNonEmptyString("purpose", item.getPurpose(), indent + 1, out);
- printNonEmptyStringList("keywords", item.getKeywords(), indent + 1,
- out);
- printNonEmptyString("copyright", item.getCopyright(), indent + 1, out);
- printNonEmptyString("use", item.getUse(), indent + 1, out);
- printNonEmptyString("misuse", item.getMisuse(), indent + 1, out);
- printNonEmptyStringMap("original_resource_uri", item.getOriginalResourceUri(), indent + 1, out);
-
- // other details not printed
-
- indent(indent, out);
- out.write(">");
- newline(out);
- }
-
- private void printNonEmptyString(String label, String value, int indent,
- Writer out) throws IOException {
-
- if (StringUtils.isEmpty(value)) {
- return;
- }
- indent(indent, out);
- out.write(label);
- out.write(" = <\"");
- out.write(value);
- out.write("\">");
- newline(out);
- }
-
- private void printNonEmptyStringList(String label, List list,
- int indent, Writer out) throws IOException {
-
- if (list == null || list.isEmpty()) {
- return;
- }
- indent(indent, out);
- out.write(label);
- out.write(" = <");
- for (int i = 0, j = list.size(); i < j; i++) {
- out.write("\"");
- out.write(list.get(i));
- out.write("\"");
- if (i != j - 1) {
- out.write(",");
- }
- }
- out.write(">");
- newline(out);
- }
-
- private void printNonEmptyStringMap(String label, Map map,
- int indent, Writer out) throws IOException {
- if (map == null || map.isEmpty()) {
- return;
- }
-
- indent(indent, out);
- out.write(label);
- out.write(" = <");
- newline(out);
-
- for (String key : map.keySet()) {
- indent(2, out);
- out.write("[\"" + key + "\"] = <\"" + map.get(key) + "\">");
- newline(out);
- }
-
- indent(indent, out);
- out.write(">");
- newline(out);
- }
-
- protected void printDefinition(CComplexObject definition, Writer out)
- throws IOException {
-
- out.write("definition");
- newline(out);
-
- printCComplexObject(definition, 1, out);
- }
-
- protected void printCComplexObject(CComplexObject ccobj, int indent,
- Writer out) throws IOException {
-
- // TODO skip c_obj with [0,0] occurrences
- Interval occurrences = ccobj.getOccurrences();
- if(occurrences != null
- && (Integer.valueOf(0).equals(occurrences.getLower()))
- && (Integer.valueOf(0).equals(occurrences.getUpper()))) {
- return;
- }
-
-
- // print rmTypeName and nodeId
- indent(indent, out);
- out.write(ccobj.getRmTypeName());
- if (StringUtils.isNotEmpty(ccobj.getNodeId())) {
- out.write("[" + ccobj.getNodeId() + "]");
- }
-
- printOccurrences(ccobj.getOccurrences(), out);
-
- out.write(" matches {");
-
- // print all attributes
- if (!ccobj.isAnyAllowed()) {
- for (CAttribute cattribute : ccobj.getAttributes()) {
- printCAttribute(cattribute, indent + 1, out);
- }
- newline(out);
- indent(indent, out);
- } else {
- out.write("*");
- }
- out.write("}");
- newline(out);
- }
-
- protected void printOccurrences(Interval occurrences, Writer out)
- throws IOException {
-
- Interval defaultOccurrences = new Interval(1, 1);
- if(occurrences == null || defaultOccurrences.equals(occurrences)) {
- return;
- }
- if (occurrences != null) {
- out.write(" occurrences matches {");
- if (occurrences.getLower() == null) {
- out.write("*");
- } else {
- out.write(Integer.toString(occurrences.getLower()));
- }
- out.write("..");
- if (occurrences.getUpper() == null) {
- out.write("*");
- } else {
- out.write(Integer.toString(occurrences.getUpper()));
- }
- out.write("}");
- }
- }
-
- protected void printArchetypeInternalRef(ArchetypeInternalRef ref,
- int indent, Writer out) throws IOException {
- indent(indent, out);
- out.write("use_node ");
- out.write(ref.getRmTypeName());
- printOccurrences(ref.getOccurrences(), out);
- out.write(" ");
- out.write(ref.getTargetPath());
- newline(out);
- }
-
- protected void printArchetypeSlot(ArchetypeSlot slot, int indent, Writer out)
- throws IOException {
-
- indent(indent, out);
- out.write("allow_archetype ");
- out.write(slot.getRmTypeName());
- if (StringUtils.isNotEmpty(slot.getNodeId())) {
- out.write("[" + slot.getNodeId() + "]");
- }
-
- printOccurrences(slot.getOccurrences(), out);
- out.write(" matches {");
-
- if (slot.isAnyAllowed()) {
- out.write("*}");
- } else {
- if (slot.getIncludes() != null) {
- printAssertions(slot.getIncludes(), "include", indent, out);
- }
- if (slot.getExcludes() != null) {
- printAssertions(slot.getExcludes(), "exclude", indent, out);
- }
- newline(out);
- indent(indent, out);
- out.write("}");
- }
- newline(out);
- }
-
- private void printAssertions(Set assertions, String purpose,
- int indent, Writer out) throws IOException {
-
- if(assertions == null) {
- return;
- }
-
- newline(out);
- indent(indent + 1, out);
- out.write(purpose);
-
- for (Assertion assertion : assertions) {
-
- if(assertion.getStringExpression() == null) {
- continue;
- }
-
- newline(out);
- indent(indent + 2, out);
-
- // FIXME: The string expression is null when an archetype is parsed, but after the archetype is recreated in the archetype
- // editor, the string expression exists. Please provide a valid string expression from the parser since it's _much_ easier to
- // maintain this line of code instead of adding hundreds of lines just to output some expressions, operators etc.
- // Opening an archetype directly in the ADL format view will show the output of the parsed archetype in this way:
- //
- // include
- // null
- out.write(assertion.getStringExpression());
- }
- }
-
- protected void printCAttribute(CAttribute cattribute, int indent, Writer out)
- throws IOException {
- newline(out);
- indent(indent, out);
- out.write(cattribute.getRmAttributeName());
- if (!CAttribute.Existence.REQUIRED.equals(cattribute.getExistence())) {
- out.write(" ");
- }
- printExistence(cattribute.getExistence(), out);
- if (cattribute instanceof CMultipleAttribute) {
- CMultipleAttribute cma = (CMultipleAttribute) cattribute;
- if(cma.getCardinality() != null) {
- out.write(" ");
- printCardinality(cma.getCardinality(), out);
- }
- }
- List children = cattribute.getChildren();
- out.write(" matches {");
- if(children == null || children.size() == 0) {
- out.write("*");
- } else if (children.size() != 1
- || !(children.get(0) instanceof CPrimitiveObject)) {
- newline(out);
- for (CObject cobject : cattribute.getChildren()) {
- printCObject(cobject, indent + 1, out);
- }
- indent(indent, out);
- } else {
- CObject child = children.get(0);
- printCPrimitiveObject((CPrimitiveObject) child, out);
- }
- out.write("}");
- }
-
- protected void printExistence(CAttribute.Existence existence, Writer out)
- throws IOException {
- if (CAttribute.Existence.REQUIRED.equals(existence)) {
- return;
- }
- out.write("existence matches ");
- if (CAttribute.Existence.OPTIONAL.equals(existence)) {
- out.write("{0..1}");
- } else {
- out.write("{0}");
- }
- }
-
- protected void printCObject(CObject cobj, int indent, Writer out)
- throws IOException {
-
- // print specialised types
- if (cobj instanceof CDomainType) {
- printCDomainType((CDomainType) cobj, indent, out);
- } else if (cobj instanceof CPrimitiveObject) {
- printCPrimitiveObject((CPrimitiveObject) cobj, out);
- } else if (cobj instanceof CComplexObject) {
- printCComplexObject((CComplexObject) cobj, indent, out);
- } else if (cobj instanceof ArchetypeInternalRef) {
- printArchetypeInternalRef((ArchetypeInternalRef) cobj, indent, out);
- } else if (cobj instanceof ArchetypeSlot) {
- printArchetypeSlot((ArchetypeSlot) cobj, indent, out);
- } else if (cobj instanceof ConstraintRef) {
- printConstraintRef((ConstraintRef) cobj, indent, out);
- }
- }
-
- protected void printConstraintRef(ConstraintRef ref, int indent, Writer out) throws IOException {
- indent(indent, out);
- out.write("[");
- out.write(ref.getReference());
- out.write("]");
- newline(out);
- }
-
- protected void printCardinality(Cardinality cardinality, Writer out)
- throws IOException {
- out.write("cardinality matches {");
- Interval interval = cardinality.getInterval();
- if (interval != null) {
- if (interval.isLowerUnbounded()) {
- out.write("*");
- } else {
- out.write(interval.getLower().toString());
- }
- out.write("..");
- if (interval.isUpperUnbounded()) {
- out.write("*");
- } else {
- out.write(interval.getUpper().toString());
- }
- } else {
- out.write("*");
- }
- out.write("; ");
- if (cardinality.isOrdered()) {
- out.write("ordered");
- } else {
- out.write("unordered");
- }
- if (cardinality.isUnique()) {
- out.write("; unique");
- }
- out.write("}");
- }
-
- protected void printCDomainType(CDomainType cdomain, int indent, Writer out)
- throws IOException {
- if (cdomain instanceof CDvOrdinal) {
- printCDvOrdinal((CDvOrdinal) cdomain, indent, out);
- } else if (cdomain instanceof CDvQuantity) {
- printCDvQuantity((CDvQuantity) cdomain, indent, out);
- }
- else if (cdomain instanceof CCodePhrase) {
- printCCodePhrase((CCodePhrase) cdomain, indent, out);
- }
- // unknow CDomainType
- }
-
- protected void printCCodePhrase(CCodePhrase ccoded, int indent, Writer out)
- throws IOException {
-
- indent(indent, out);
-
- if(ccoded.isAnyAllowed()) {
- out.write("C_CODE_PHRASE <");
- newline(out);
- indent(indent, out);
- out.write(">");
- newline(out);
- return;
- }
-
- if (ccoded.getTerminologyId() != null) {
- out.write("[" + ccoded.getTerminologyId().getValue() + "::");
- }
-
- if (ccoded.getCodeList() != null) {
- if (ccoded.getCodeList().size() > 1) {
- newline(out);
-
- for (int i = 0, j = ccoded.getCodeList().size(); i < j; i++) {
- if (j > 1) {
- indent(indent, out);
- }
- out.write(ccoded.getCodeList().get(i));
- if (i != j - 1) {
- out.write(",");
- } else {
- if(ccoded.hasAssumedValue()) {
- out.write(";");
- newline(out);
- indent(indent, out);
- out.write(ccoded.getAssumedValue().getCodeString());
- }
- out.write("]");
- }
- newline(out);
- }
- } else {
- out.write(ccoded.getCodeList().get(0));
- if(ccoded.hasAssumedValue()) {
- out.write(";" + ccoded.getAssumedValue().getCodeString());
- }
- out.write("]");
- newline(out);
- }
- } else {
- out.write("]");
- newline(out);
- }
- }
-
- protected void printCDvOrdinal(CDvOrdinal cordinal, int indent, Writer out)
- throws IOException {
-
- // if the list is null, the CDvOrdinal is not further constrained
- // (other than that it is a CDvOrdinal)
- if (cordinal.isAnyAllowed()) {
- indent(indent, out);
- out.write("C_DV_ORDINAL <");
- newline(out);
- indent(indent, out);
- out.write(">");
- newline(out);
- }
- else {
- for (Iterator it = cordinal.getList().iterator();
- it.hasNext();) {
- Ordinal ordinal = it.next();
- indent(indent, out);
- printOrdinal(ordinal, out);
- if (it.hasNext()) {
- out.write(",");
- } else if(cordinal.hasAssumedValue()) {
- out.write(";");
- }
- newline(out);
- }
- if(cordinal.hasAssumedValue()) {
- printOrdinal(cordinal.getAssumedValue(), out);
- newline(out);
-
- }
- }
- }
-
- protected void printOrdinal(Ordinal ordinal, Writer out)
- throws IOException {
- CodePhrase symbol = ordinal.getSymbol();
- out.write(Integer.toString(ordinal.getValue()));
- out.write("|[");
- out.write(symbol.getTerminologyId().getValue());
- out.write("::");
- out.write(symbol.getCodeString());
- out.write("]");
- }
-
- protected void printCDvQuantity(CDvQuantity cquantity, int indent,
- Writer out) throws IOException {
- indent(indent, out);
- out.write("C_DV_QUANTITY <");
- newline(out);
- indent(indent + 1, out);
- CodePhrase property = cquantity.getProperty();
- if (property != null) {
- out.write("property = <[");
- out.write(property.getTerminologyId().getValue());
- out.write("::");
- out.write(property.getCodeString());
- out.write("]>");
- }
- List list = cquantity.getList();
- if (list != null) {
- newline(out);
- indent(indent + 1, out);
- out.write("list = <");
- newline(out);
- int index = 1;
- for (CDvQuantityItem item : list) {
- indent(indent + 2, out);
- out.write("[\"");
- out.write(Integer.toString(index));
- out.write("\"] = <");
- newline(out);
- indent(indent + 3, out);
- out.write("units = <\"");
- out.write(item.getUnits());
- out.write("\">");
- newline(out);
- Interval value = item.getMagnitude();
- if (value != null) {
- indent(indent + 3, out);
- out.write("magnitude = <");
- printInterval(value, out);
- out.write(">");
- newline(out);
- }
-
- Interval precision = item.getPrecision();
- if (precision != null) {
- indent(indent + 3, out);
- out.write("precision = <");
- printInterval(precision, out);
- out.write(">");
- newline(out);
- }
- index++;
- indent(indent + 2, out);
- out.write(">");
- newline(out);
- }
- indent(indent + 1, out);
- out.write(">");
- newline(out);
- }
-
-
- if(cquantity.getAssumedValue() != null) {
- newline(out);
- indent(indent + 1, out);
- out.write("assumed_value = <");
- newline(out);
- printDvQuantity(cquantity.getAssumedValue(), indent + 1, out);
- indent(indent + 1, out);
- out.write(">");
- newline(out);
- }
-
- indent(indent, out);
- out.write(">");
- newline(out);
- }
-
- protected void printDvQuantity(DvQuantity quantity, int indent, Writer out)
- throws IOException {
-
- indent(indent + 1, out);
- printUnits(quantity.getUnits(), out);
- newline(out);
-
- if(quantity.getMagnitude() != null) {
- indent(indent + 1, out);
- out.write("magnitude = <");
- out.write(quantity.getMagnitude().toString());
- out.write(">");
- newline(out);
- }
- indent(indent + 1, out);
- out.write("precision = <");
- out.write(Integer.toString(quantity.getPrecision()));
- out.write(">");
- newline(out);
- }
-
- protected void printUnits(String units, Writer out) throws IOException {
- out.write("units = <\"");
- out.write(units);
- out.write("\">");
- }
-
- protected void printOntology(ArchetypeOntology ontology, Writer out)
- throws IOException {
-
- out.write("ontology");
- newline(out);
-
- if (ontology.getTerminologies() != null) {
- indent(1, out);
- out.write("terminologies_available = <");
- for (String terminology : ontology.getTerminologies()) {
- out.write("\"");
- out.write(terminology);
- out.write("\", ");
- }
- out.write("...>");
- newline(out);
- }
-
- // *** Term definition section *** (ADL 1.4 spec 8.6.3)
- indent(1, out);
- out.write("term_definitions = <");
- newline(out);
- List termDefinitionsList = ontology.getTermDefinitionsList();
- printDefinitionList(out, termDefinitionsList);
- indent(1, out);
- out.write(">");
- newline(out);
-
- // *** Constraint definition section *** (ADL 1.4 spec 8.6.4)
- List constraintDefinitionsList = ontology.getConstraintDefinitionsList();
- if (constraintDefinitionsList != null) {
- indent(1, out);
- out.write("constraint_definitions = <");
- newline(out);
- printDefinitionList(out, constraintDefinitionsList);
- indent(1, out);
- out.write(">");
- newline(out);
- }
-
- // *** Term binding section *** (ADL 1.4 spec 8.6.5)
- if (ontology.getTermBindingList() != null) {
- indent(1, out);
- out.write("term_binding = <");
- newline(out);
- for (int i = 0; i < ontology.getTermBindingList().size(); i++) {
- OntologyBinding bind = ontology.getTermBindingList().get(i);
- indent(2, out);
- out.write("[\"");
- out.write(bind.getTerminology());
- out.write("\"] = <");
- newline(out);
- indent(3, out);
- out.write("items = <");
- newline(out);
-
- for (int j = 0; j < ontology.getTermBindingList().get(i)
- .getBindingList().size(); j++) {
- TermBindingItem item = (TermBindingItem) ontology
- .getTermBindingList().get(i).getBindingList()
- .get(j);
- indent(4, out);
- out.write("[\"");
- out.write(item.getCode());
- out.write("\"] = <");
- out.write(item.getTerms().get(0));
-
- if (item.getTerms().size() > 1) {
- for (int k = 1; k < item.getTerms().size(); k++) {
- out.write("," + item.getTerms().get(k));
- }
- }
-
- out.write(">");
- newline(out);
- }
- for (int l = 3; l > 1; l--) {
- indent(l, out);
- out.write(">");
- newline(out);
- }
- }
- indent(1, out);
- out.write(">");
- newline(out);
- }
-
- // *** Constraint binding section *** (ADL 1.4 spec 8.6.6)
- if (ontology.getConstraintBindingList() != null) {
- indent(1, out);
- out.write("constraint_binding = <");
- newline(out);
- for (int i = 0; i < ontology.getConstraintBindingList().size(); i++) {
- OntologyBinding bind = ontology.getConstraintBindingList().get(
- i);
- indent(2, out);
- out.write("[\"");
- out.write(bind.getTerminology());
- out.write("\"] = <");
- newline(out);
- indent(3, out);
- out.write("items = <");
- newline(out);
-
- for (int j = 0; j < ontology.getConstraintBindingList().get(i)
- .getBindingList().size(); j++) {
- QueryBindingItem item = (QueryBindingItem) ontology
- .getConstraintBindingList().get(i).getBindingList()
- .get(j);
- indent(4, out);
- out.write("[\"");
- out.write(item.getCode());
- out.write("\"] = <");
- out.write(item.getQuery().getUrl());
- out.write(">");
- newline(out);
- }
- for (int l = 3; l > 1; l--) {
- indent(l, out);
- out.write(">");
- newline(out);
- }
- }
- indent(1, out);
- out.write(">");
- newline(out);
- }
- }
-
- private void printDefinitionList(Writer out,
- List termDefinitionsList) throws IOException {
- for (OntologyDefinitions defs : termDefinitionsList) {
- indent(2, out);
- out.write("[\"");
- out.write(defs.getLanguage());
- out.write("\"] = <");
- newline(out);
- indent(3, out);
- out.write("items = <");
- newline(out);
- for (ArchetypeTerm term : defs.getDefinitions()) {
- indent(4, out);
- out.write("[\"");
- out.write(term.getCode());
- out.write("\"] = <");
- newline(out);
- for (Map.Entry entry : term.getItems().entrySet()) {
- indent(5, out);
- out.write(entry.getKey());
- out.write(" = <\"");
- out.write(entry.getValue());
- out.write("\">");
- newline(out);
- }
- newline(out);
- indent(4, out);
- out.write(">");
- newline(out);
- }
- for (int i = 3; i > 1; i--) {
- indent(i, out);
- out.write(">");
- newline(out);
- }
- }
- }
-
- protected void printCPrimitiveObject(CPrimitiveObject cpo, Writer out)
- throws IOException {
-
- CPrimitive cp = cpo.getItem();
- if (cp instanceof CBoolean) {
- printCBoolean((CBoolean) cp, out);
- } else if (cp instanceof CDate) {
- printCDate((CDate) cp, out);
- } else if (cp instanceof CDateTime) {
- printCDateTime((CDateTime) cp, out);
- } else if (cp instanceof CTime) {
- printCTime((CTime) cp, out);
- } else if (cp instanceof CDuration) {
- printCDuration((CDuration) cp, out);
- } else if (cp instanceof CInteger) {
- printCInteger((CInteger) cp, out);
- } else if (cp instanceof CReal) {
- printCReal((CReal) cp, out);
- } else if (cp instanceof CString) {
- printCString((CString) cp, out);
- }
- // unknow CPrimitive type
- }
-
- protected void printCBoolean(CBoolean cboolean, Writer out)
- throws IOException {
- if (cboolean.isTrueValid()) {
- out.write("true");
- if (cboolean.isFalseValid()) {
- out.write(", false");
- }
- } else {
- out.write("false");
- }
- if(cboolean.hasAssumedValue()) {
- out.write("; ");
- if(cboolean.assumedValue().booleanValue()) {
- out.write("true");
- } else {
- out.write("false");
- }
- }
- }
-
- protected void printCDate(CDate cdate, Writer out) throws IOException {
- if (cdate.getPattern() != null) {
- out.write(cdate.getPattern());
- } else if (cdate.getList() != null) {
- out.write(cdate.getList().get(0).toString());
- } else {
- printInterval(cdate.getInterval(), out);
- }
- if(cdate.hasAssumedValue()) {
- out.write("; ");
- out.write(cdate.assumedValue().toString());
- }
- }
-
- protected void printCDateTime(CDateTime cdatetime, Writer out)
- throws IOException {
- if (cdatetime.getPattern() != null) {
- out.write(cdatetime.getPattern());
- } else if (cdatetime.getList() != null) {
- out.write(cdatetime.getList().get(0).toString());
- } else {
- printInterval(cdatetime.getInterval(), out);
- }
- if(cdatetime.hasAssumedValue()) {
- out.write("; ");
- out.write(cdatetime.assumedValue().toString());
- }
- }
-
- protected void printCTime(CTime ctime, Writer out) throws IOException {
- if (ctime.getPattern() != null) {
- out.write(ctime.getPattern());
- } else if (ctime.getList() != null) {
- out.write(ctime.getList().get(0).toString());
- } else {
- printInterval(ctime.getInterval(), out);
- }
- if(ctime.hasAssumedValue()) {
- out.write("; ");
- out.write(ctime.assumedValue().toString());
- }
- }
-
- protected void printCDuration(CDuration cduration, Writer out)
- throws IOException {
- if (cduration.getValue() != null) {
- out.write(cduration.getValue().toString());
- } else if(cduration.getPattern() != null) {
- out.write(cduration.getPattern());
- } else {
- printInterval(cduration.getInterval(), out);
- }
- if(cduration.assumedValue() != null) {
- out.write("; ");
- out.write(cduration.assumedValue().toString());
- }
- }
-
- protected void printCInteger(CInteger cinteger, Writer out)
- throws IOException {
- if (cinteger.getList() != null) {
- printList(cinteger.getList(), out);
- } else {
- printInterval(cinteger.getInterval(), out);
- }
- if(cinteger.assumedValue() != null) {
- out.write("; ");
- out.write(cinteger.assumedValue().toString());
- }
- }
-
- protected void printCReal(CReal creal, Writer out) throws IOException {
- if (creal.getList() != null) {
- printList(creal.getList(), out);
- } else {
- printInterval(creal.getInterval(), out);
- }
- if(creal.assumedValue() != null) {
- out.write("; ");
- out.write(creal.assumedValue().toString());
- }
- }
-
- protected void printCString(CString cstring, Writer out) throws IOException {
- if (cstring.getPattern() != null) {
- out.write("/" + cstring.getPattern() + "/");
- } else if(cstring.getList() != null){
- printList(cstring.getList(), out, true);
- } else if(cstring.defaultValue() != null) {
- out.write("\"");
- out.write(cstring.defaultValue());
- out.write("\"");
- }
- if(cstring.hasAssumedValue()) {
- out.write("; ");
- out.write("\"" + cstring.assumedValue() + "\"");
- }
- }
-
- protected void printList(List list, Writer out) throws IOException {
- printList(list, out, false);
- }
-
- protected void printList(List list, Writer out, boolean string)
- throws IOException {
- for (int i = 0, j = list.size(); i < j; i++) {
- if (i != 0) {
- out.write(",");
- }
- if (string) {
- out.write("\"");
- }
- out.write(list.get(i).toString());
- if (string) {
- out.write("\"");
- }
- }
- }
-
- protected void printInterval(Interval interval, Writer out)
- throws IOException {
- out.write("|");
- if (interval.getLower() != null && interval.getUpper() != null) {
- if(interval.getLower().equals(interval.getUpper())
- && interval.isLowerIncluded()
- && interval.isUpperIncluded()) {
- out.write(interval.getLower().toString());
- } else {
- out.write(interval.getLower().toString());
- out.write("..");
- out.write(interval.getUpper().toString());
- }
- } else if (interval.getLower() == null) {
- out.write("<");
- if (interval.isUpperIncluded()) {
- out.write("=");
- }
- out.write(interval.getUpper().toString());
- } else {
- out.write(">");
- if (interval.isLowerIncluded()) {
- out.write("=");
- }
- out.write(interval.getLower().toString());
- }
- out.write("|");
- }
-
- private void newline(Writer out) throws IOException {
- out.write(lineSeparator);
- }
-
- private void indent(int level, Writer out) throws IOException {
- for (int i = 0; i < level; i++) {
- out.write(indent);
- }
- }
-
- /* charset encodings */
- public static final Charset UTF8 = Charset.forName("UTF-8");
- public static final Charset LATIN1 = Charset.forName("ISO-8859-1");
-
- /* fields */
- private Charset encoding;
- private String lineSeparator;
- private String indent;
-}
-/*
- * ***** BEGIN LICENSE BLOCK ***** Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the 'License'); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an 'AS IS' basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
- * the specific language governing rights and limitations under the License.
- *
- * The Original Code is ADLSerializer.java
- *
- * The Initial Developer of the Original Code is Rong Chen. Portions created by
- * the Initial Developer are Copyright (C) 2004-2007 the Initial Developer. All
- * Rights Reserved.
- *
- * Contributor(s): Mattias Forss, Johan Hjalmarsson, Erik Sundvall,
- * Sebastian Garde
- *
- * Software distributed under the License is distributed on an 'AS IS' basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
- * the specific language governing rights and limitations under the License.
- *
- * ***** END LICENSE BLOCK *****
- */
+/*
+ * component: "openEHR Reference Implementation"
+ * description: "Class ADLSerializer"
+ * keywords: "archetype"
+ *
+ * author: "Rong Chen "
+ * support: "Acode HB "
+ * copyright: "Copyright (c) 2004,2005,2006 Acode HB, Sweden"
+ * license: "See notice at bottom of class"
+ *
+ * file: "$URL: $"
+ * revision: "$LastChangedRevision: 41 $"
+ * last_change: "$LastChangedDate: 2006-07-12 23:24:42 +0200 (Wed, 12 Jul 2006) $"
+ */
+package org.openehr.am.serialize;
+
+import java.io.BufferedOutputStream;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.openehr.am.archetype.Archetype;
+import org.openehr.am.archetype.assertion.Assertion;
+import org.openehr.am.archetype.constraintmodel.ArchetypeInternalRef;
+import org.openehr.am.archetype.constraintmodel.ArchetypeSlot;
+import org.openehr.am.archetype.constraintmodel.CAttribute;
+import org.openehr.am.archetype.constraintmodel.CComplexObject;
+import org.openehr.am.archetype.constraintmodel.CDomainType;
+import org.openehr.am.archetype.constraintmodel.CMultipleAttribute;
+import org.openehr.am.archetype.constraintmodel.CObject;
+import org.openehr.am.archetype.constraintmodel.CPrimitiveObject;
+import org.openehr.am.archetype.constraintmodel.Cardinality;
+import org.openehr.am.archetype.constraintmodel.ConstraintRef;
+import org.openehr.am.archetype.constraintmodel.primitive.CBoolean;
+import org.openehr.am.archetype.constraintmodel.primitive.CDate;
+import org.openehr.am.archetype.constraintmodel.primitive.CDateTime;
+import org.openehr.am.archetype.constraintmodel.primitive.CDuration;
+import org.openehr.am.archetype.constraintmodel.primitive.CInteger;
+import org.openehr.am.archetype.constraintmodel.primitive.CPrimitive;
+import org.openehr.am.archetype.constraintmodel.primitive.CReal;
+import org.openehr.am.archetype.constraintmodel.primitive.CString;
+import org.openehr.am.archetype.constraintmodel.primitive.CTime;
+import org.openehr.am.archetype.ontology.ArchetypeOntology;
+import org.openehr.am.archetype.ontology.ArchetypeTerm;
+import org.openehr.am.archetype.ontology.OntologyBinding;
+import org.openehr.am.archetype.ontology.OntologyDefinitions;
+import org.openehr.am.archetype.ontology.QueryBindingItem;
+import org.openehr.am.archetype.ontology.TermBindingItem;
+import org.openehr.am.openehrprofile.datatypes.quantity.CDvOrdinal;
+import org.openehr.am.openehrprofile.datatypes.quantity.CDvQuantity;
+import org.openehr.am.openehrprofile.datatypes.quantity.CDvQuantityItem;
+import org.openehr.am.openehrprofile.datatypes.quantity.CDvScale;
+import org.openehr.am.openehrprofile.datatypes.quantity.Ordinal;
+import org.openehr.am.openehrprofile.datatypes.quantity.Scale;
+import org.openehr.am.openehrprofile.datatypes.text.CCodePhrase;
+import org.openehr.rm.common.resource.AuthoredResource;
+import org.openehr.rm.common.resource.ResourceDescription;
+import org.openehr.rm.common.resource.ResourceDescriptionItem;
+import org.openehr.rm.common.resource.TranslationDetails;
+import org.openehr.rm.datatypes.quantity.DvQuantity;
+import org.openehr.rm.datatypes.text.CodePhrase;
+import org.openehr.rm.support.basic.Interval;
+import org.openehr.rm.support.identification.ArchetypeID;
+import org.openehr.rm.support.identification.ObjectID;
+
+/**
+ * ADL serializer for the openEHR Java kernel
+ *
+ * @author Rong Chen
+ * @author Mattias Forss, Johan Hjalmarsson
+ * @author Sebastian Garde
+ *
+ * @version 1.0
+ */
+public class ADLSerializer {
+
+ /**
+ * Create an outputter with default encoding, indent and lineSeparator
+ */
+ public ADLSerializer() {
+ this.encoding = UTF8;
+ this.indent = " "; // 4 white space characters
+ this.lineSeparator = "\r\n";
+ }
+
+ /**
+ * Output given archetype as string in ADL format
+ *
+ * @param archetype
+ * @return a string in ADL format
+ * @throws IOException
+ */
+ public String output(Archetype archetype) throws IOException {
+ StringWriter writer = new StringWriter();
+ output(archetype, writer);
+ return writer.toString();
+ }
+
+ /**
+ * Output archetype DEFINITION as string in ADL format
+ *
+ * @param archetype
+ * @return a string in ADL format
+ * @throws IOException
+ */
+ public String outputDefinitionOnly(Archetype archetype) throws IOException {
+ StringWriter writer = new StringWriter();
+
+ printDefinition(archetype.getDefinition(), writer);
+
+ return writer.toString();
+ }
+
+ /**
+ * Output given archetype to outputStream
+ *
+ * @param archetype
+ * @param out
+ * @throws IOException
+ */
+ public void output(Archetype archetype, OutputStream out)
+ throws IOException {
+ Writer writer = new BufferedWriter(new OutputStreamWriter(
+ new BufferedOutputStream(out), encoding));
+ output(archetype, writer);
+ }
+
+ /**
+ * Output given archetype to writer
+ *
+ * @param archetype
+ * @param out
+ * @throws IOException
+ */
+ public void output(Archetype archetype, Writer out) throws IOException {
+ printHeader(archetype.getAdlVersion(), archetype.getArchetypeId(),
+ archetype.getParentArchetypeId(), archetype.getUid(), archetype.getConcept(), out);
+ newline(out);
+
+ printLanguage(archetype, out);
+ newline(out);
+
+ if(archetype.getDescription() != null) {
+ printDescription(archetype.getDescription(), out);
+ newline(out);
+ }
+
+ printDefinition(archetype.getDefinition(), out);
+ newline(out);
+
+ printOntology(archetype.getOntology(), out);
+ out.flush();
+ out.close();
+ }
+
+ protected void printHeader(String adlVersion,
+ ArchetypeID id, ArchetypeID parentId, ObjectID uid,
+ String conceptCode, Writer out) throws IOException {
+
+ out.write("archetype");
+ if(StringUtils.isNotEmpty(adlVersion) || (uid != null && StringUtils.isNotEmpty(uid.toString()))) {
+ out.write(" (");
+ }
+
+ if(StringUtils.isNotEmpty(adlVersion)) {
+ out.write("adl_version=");
+ out.write(adlVersion);
+ }
+ if(uid != null && StringUtils.isNotEmpty(uid.toString())) {
+ if (StringUtils.isNotEmpty(adlVersion)) {
+ out.write("; ");
+ }
+ out.write("uid=");
+ out.write(uid.toString());
+ }
+ if(StringUtils.isNotEmpty(adlVersion) || (uid!=null &&StringUtils.isNotEmpty(uid.toString()))) {
+ out.write(")");
+ }
+ newline(out);
+ indent(1, out);
+ out.write(id.toString());
+ newline(out);
+
+ if (parentId != null) {
+ out.write("specialize");
+ newline(out);
+ indent(1, out);
+ out.write(parentId.toString());
+ newline(out);
+ }
+
+ newline(out);
+ out.write("concept");
+ newline(out);
+ indent(1, out);
+ out.write("[" + conceptCode + "]");
+ newline(out);
+ }
+
+ protected void printLanguage(AuthoredResource authored,
+ Writer out) throws IOException {
+
+ out.write("language");
+ newline(out);
+ indent(1, out);
+ out.write("original_language = <");
+ out.write("[");
+ out.write(authored.getOriginalLanguage().getTerminologyId().getValue());
+ out.write("::");
+ out.write(authored.getOriginalLanguage().getCodeString());
+ out.write("]");
+ out.write(">");
+ newline(out);
+ if(authored.getTranslations() != null) {
+ indent(1, out);
+ out.write("translations = <");
+ newline(out);
+ Map translations =
+ authored.getTranslations();
+ for(String lang : translations.keySet()) {
+ TranslationDetails td = translations.get(lang);
+
+ indent(2, out);
+ out.write("[");
+ out.write(quoteString(lang));
+ out.write("] = <");
+ newline(out);
+
+ indent(3, out);
+ out.write("language = <");
+ out.write("[");
+ out.write(td.getLanguage().getTerminologyId().getValue());
+ out.write("::");
+ out.write(td.getLanguage().getCodeString());
+ out.write("]");
+ out.write(">");
+ newline(out);
+
+ indent(3, out);
+ out.write("author = <");
+ newline(out);
+ printMap(td.getAuthor(), out, 4);
+ indent(3, out);
+ out.write(">");
+ newline(out);
+
+ if(td.getAccreditation() != null) {
+ indent(3, out);
+ out.write("accreditation = <");
+ out.write(quoteString(td.getAccreditation()));
+ out.write(">");
+ newline(out);
+ }
+
+ if(td.getOtherDetails() != null) {
+ indent(3, out);
+ out.write("other_details = <");
+ newline(out);
+ printMap(td.getOtherDetails(), out, 4);
+ indent(3, out);
+ out.write(">");
+ newline(out);
+ }
+
+ indent(2, out);
+ out.write(">");
+ newline(out);
+ }
+ indent(1, out);
+ out.write(">");
+ newline(out);
+ }
+ }
+
+ protected void printMap(Map map, Writer out, int indent)
+ throws IOException {
+ if(map == null || map.size() == 0) {
+ return;
+ }
+ for(String key : map.keySet()) {
+ indent(indent, out);
+ out.write("[");
+ out.write(quoteString(key));
+ out.write("] = <");
+ out.write(quoteString(map.get(key)));
+ out.write(">");
+ newline(out);
+ }
+ }
+
+ protected void printDescription(ResourceDescription description, Writer out)
+ throws IOException {
+
+ if (description == null) {
+ return;
+ }
+
+ out.write("description");
+ newline(out);
+
+ indent(1, out);
+ out.write("original_author = <");
+ newline(out);
+ Map map = description.getOriginalAuthor();
+ for (String key : map.keySet()) {
+ indent(2, out);
+ out.write("[" + quoteString(key) + "] = <" + quoteString(map.get(key)) + ">");
+ newline(out);
+ }
+ indent(1, out);
+ out.write(">");
+ newline(out);
+
+ indent(1, out);
+ out.write("lifecycle_state = <");
+ out.write(quoteString(description.getLifecycleState()));
+ out.write(">");
+ newline(out);
+
+ printNonEmptyString("resource_package_uri", description.getResourcePackageUri(), 1, out);
+
+ indent(1, out);
+ out.write("details = <");
+ newline(out);
+ for (ResourceDescriptionItem item : description.getDetails().values()) {
+ printDescriptionItem(item, 2, out);
+ }
+ indent(1, out);
+ out.write(">");
+ newline(out);
+ }
+
+ protected void printDescriptionItem(ResourceDescriptionItem item,
+ int indent, Writer out) throws IOException {
+ indent(indent, out);
+ out.write("[");
+ out.write(quoteString(item.getLanguage().getCodeString()));
+ out.write("] = <");
+ newline(out);
+
+ indent(indent + 1, out);
+ out.write("language = <");
+ out.write("[");
+ out.write(item.getLanguage().getTerminologyId().getValue());
+ out.write("::");
+ out.write(item.getLanguage().getCodeString());
+ out.write("]>");
+ newline(out);
+
+ printNonEmptyString("purpose", item.getPurpose(), indent + 1, out);
+ printNonEmptyStringList("keywords", item.getKeywords(), indent + 1,
+ out);
+ printNonEmptyString("copyright", item.getCopyright(), indent + 1, out);
+ printNonEmptyString("use", item.getUse(), indent + 1, out);
+ printNonEmptyString("misuse", item.getMisuse(), indent + 1, out);
+ printNonEmptyStringMap("original_resource_uri", item.getOriginalResourceUri(), indent + 1, out);
+
+ // other details not printed
+
+ indent(indent, out);
+ out.write(">");
+ newline(out);
+ }
+
+ private void printNonEmptyString(String label, String value, int indent,
+ Writer out) throws IOException {
+
+ if (StringUtils.isEmpty(value)) {
+ return;
+ }
+ indent(indent, out);
+ out.write(label);
+ out.write(" = <");
+ out.write(quoteString(value));
+ out.write(">");
+ newline(out);
+ }
+
+ private void printNonEmptyStringList(String label, List list,
+ int indent, Writer out) throws IOException {
+
+ if (list == null || list.isEmpty()) {
+ return;
+ }
+ indent(indent, out);
+ out.write(label);
+ out.write(" = <");
+ for (int i = 0, j = list.size(); i < j; i++) {
+ out.write(quoteString(list.get(i)));
+ if (i != j - 1) {
+ out.write(",");
+ }
+ }
+ out.write(">");
+ newline(out);
+ }
+
+ private void printNonEmptyStringMap(String label, Map map,
+ int indent, Writer out) throws IOException {
+ if (map == null || map.isEmpty()) {
+ return;
+ }
+
+ indent(indent, out);
+ out.write(label);
+ out.write(" = <");
+ newline(out);
+
+ for (String key : map.keySet()) {
+ indent(2, out);
+ out.write("[" + quoteString(key) + "] = <" + quoteString(map.get(key)) + ">");
+ newline(out);
+ }
+
+ indent(indent, out);
+ out.write(">");
+ newline(out);
+ }
+
+ protected void printDefinition(CComplexObject definition, Writer out)
+ throws IOException {
+
+ out.write("definition");
+ newline(out);
+
+ printCComplexObject(definition, 1, out);
+ }
+
+ protected void printCComplexObject(CComplexObject ccobj, int indent,
+ Writer out) throws IOException {
+
+ // TODO skip c_obj with [0,0] occurrences
+ Interval occurrences = ccobj.getOccurrences();
+ if(occurrences != null
+ && (Integer.valueOf(0).equals(occurrences.getLower()))
+ && (Integer.valueOf(0).equals(occurrences.getUpper()))) {
+ return;
+ }
+
+
+ // print rmTypeName and nodeId
+ indent(indent, out);
+ out.write(ccobj.getRmTypeName());
+ if (StringUtils.isNotEmpty(ccobj.getNodeId())) {
+ out.write("[" + ccobj.getNodeId() + "]");
+ }
+
+ printOccurrences(ccobj.getOccurrences(), out);
+
+ out.write(" matches {");
+
+ // print all attributes
+ if (!ccobj.isAnyAllowed()) {
+ for (CAttribute cattribute : ccobj.getAttributes()) {
+ printCAttribute(cattribute, indent + 1, out);
+ }
+ newline(out);
+ indent(indent, out);
+ } else {
+ out.write("*");
+ }
+ out.write("}");
+ newline(out);
+ }
+
+ protected void printOccurrences(Interval occurrences, Writer out)
+ throws IOException {
+
+ Interval defaultOccurrences = new Interval(1, 1);
+ if(occurrences == null || defaultOccurrences.equals(occurrences)) {
+ return;
+ }
+ if (occurrences != null) {
+ out.write(" occurrences matches {");
+ if (occurrences.getLower() == null) {
+ out.write("*");
+ } else {
+ out.write(Integer.toString(occurrences.getLower()));
+ }
+ out.write("..");
+ if (occurrences.getUpper() == null) {
+ out.write("*");
+ } else {
+ out.write(Integer.toString(occurrences.getUpper()));
+ }
+ out.write("}");
+ }
+ }
+
+ protected void printArchetypeInternalRef(ArchetypeInternalRef ref,
+ int indent, Writer out) throws IOException {
+ indent(indent, out);
+ out.write("use_node ");
+ out.write(ref.getRmTypeName());
+ printOccurrences(ref.getOccurrences(), out);
+ out.write(" ");
+ out.write(ref.getTargetPath());
+ newline(out);
+ }
+
+ protected void printArchetypeSlot(ArchetypeSlot slot, int indent, Writer out)
+ throws IOException {
+
+ indent(indent, out);
+ out.write("allow_archetype ");
+ out.write(slot.getRmTypeName());
+ if (StringUtils.isNotEmpty(slot.getNodeId())) {
+ out.write("[" + slot.getNodeId() + "]");
+ }
+
+ printOccurrences(slot.getOccurrences(), out);
+ out.write(" matches {");
+
+ if (slot.isAnyAllowed()) {
+ out.write("*}");
+ } else {
+ if (slot.getIncludes() != null) {
+ printAssertions(slot.getIncludes(), "include", indent, out);
+ }
+ if (slot.getExcludes() != null) {
+ printAssertions(slot.getExcludes(), "exclude", indent, out);
+ }
+ newline(out);
+ indent(indent, out);
+ out.write("}");
+ }
+ newline(out);
+ }
+
+ private void printAssertions(Set assertions, String purpose,
+ int indent, Writer out) throws IOException {
+
+ if(assertions == null) {
+ return;
+ }
+
+ newline(out);
+ indent(indent + 1, out);
+ out.write(purpose);
+
+ for (Assertion assertion : assertions) {
+
+ if(assertion.getStringExpression() == null) {
+ continue;
+ }
+
+ newline(out);
+ indent(indent + 2, out);
+
+ // FIXME: The string expression is null when an archetype is parsed, but after the archetype is recreated in the archetype
+ // editor, the string expression exists. Please provide a valid string expression from the parser since it's _much_ easier to
+ // maintain this line of code instead of adding hundreds of lines just to output some expressions, operators etc.
+ // Opening an archetype directly in the ADL format view will show the output of the parsed archetype in this way:
+ //
+ // include
+ // null
+ out.write(assertion.getStringExpression());
+ }
+ }
+
+ protected void printCAttribute(CAttribute cattribute, int indent, Writer out)
+ throws IOException {
+ newline(out);
+ indent(indent, out);
+ out.write(cattribute.getRmAttributeName());
+ if (!CAttribute.Existence.REQUIRED.equals(cattribute.getExistence())) {
+ out.write(" ");
+ }
+ printExistence(cattribute.getExistence(), out);
+ if (cattribute instanceof CMultipleAttribute) {
+ CMultipleAttribute cma = (CMultipleAttribute) cattribute;
+ if(cma.getCardinality() != null) {
+ out.write(" ");
+ printCardinality(cma.getCardinality(), out);
+ }
+ }
+ List children = cattribute.getChildren();
+ out.write(" matches {");
+ if(children == null || children.size() == 0) {
+ out.write("*");
+ } else if (children.size() != 1
+ || !(children.get(0) instanceof CPrimitiveObject)) {
+ newline(out);
+ for (CObject cobject : cattribute.getChildren()) {
+ printCObject(cobject, indent + 1, out);
+ }
+ indent(indent, out);
+ } else {
+ CObject child = children.get(0);
+ printCPrimitiveObject((CPrimitiveObject) child, out);
+ }
+ out.write("}");
+ }
+
+ protected void printExistence(CAttribute.Existence existence, Writer out)
+ throws IOException {
+ if (CAttribute.Existence.REQUIRED.equals(existence)) {
+ return;
+ }
+ out.write("existence matches ");
+ if (CAttribute.Existence.OPTIONAL.equals(existence)) {
+ out.write("{0..1}");
+ } else {
+ out.write("{0}");
+ }
+ }
+
+ protected void printCObject(CObject cobj, int indent, Writer out)
+ throws IOException {
+
+ // print specialised types
+ if (cobj instanceof CDomainType) {
+ printCDomainType((CDomainType) cobj, indent, out);
+ } else if (cobj instanceof CPrimitiveObject) {
+ printCPrimitiveObject((CPrimitiveObject) cobj, out);
+ } else if (cobj instanceof CComplexObject) {
+ printCComplexObject((CComplexObject) cobj, indent, out);
+ } else if (cobj instanceof ArchetypeInternalRef) {
+ printArchetypeInternalRef((ArchetypeInternalRef) cobj, indent, out);
+ } else if (cobj instanceof ArchetypeSlot) {
+ printArchetypeSlot((ArchetypeSlot) cobj, indent, out);
+ } else if (cobj instanceof ConstraintRef) {
+ printConstraintRef((ConstraintRef) cobj, indent, out);
+ }
+ }
+
+ protected void printConstraintRef(ConstraintRef ref, int indent, Writer out) throws IOException {
+ indent(indent, out);
+ out.write("[");
+ out.write(ref.getReference());
+ out.write("]");
+ newline(out);
+ }
+
+ protected void printCardinality(Cardinality cardinality, Writer out)
+ throws IOException {
+ out.write("cardinality matches {");
+ Interval