diff --git a/libraries/openehr/src/am/archetype/assertion/assertion.e b/libraries/openehr/src/am/archetype/assertion/assertion.e index fb7801186..139c5d435 100755 --- a/libraries/openehr/src/am/archetype/assertion/assertion.e +++ b/libraries/openehr/src/am/archetype/assertion/assertion.e @@ -12,11 +12,6 @@ class ASSERTION inherit BASIC_DEFINITIONS - OPERATOR_TYPES - export - {NONE} all - end - RULE_STATEMENT create @@ -29,7 +24,7 @@ feature -- Initialisation do expression := an_expr an_expr.set_parent (Current) - type := op_type_boolean + type := {OPERATOR_TYPES}.op_type_boolean end make_with_tag (an_expr: EXPRESSION; a_tag: STRING) @@ -40,7 +35,7 @@ feature -- Initialisation tag := a_tag expression := an_expr an_expr.set_parent (Current) - type := op_type_boolean + type := {OPERATOR_TYPES}.op_type_boolean end feature -- Access diff --git a/libraries/openehr/src/am/archetype/assertion/expr_archetype_id_constraint.e b/libraries/openehr/src/am/archetype/assertion/expr_archetype_id_constraint.e index 8416095c2..79f2b78b1 100644 --- a/libraries/openehr/src/am/archetype/assertion/expr_archetype_id_constraint.e +++ b/libraries/openehr/src/am/archetype/assertion/expr_archetype_id_constraint.e @@ -23,8 +23,7 @@ feature -- Initialisation make (an_item: C_STRING) -- node is a constraint on a primitive type; can only be used with "matches" function do - item := an_item - type := an_item.generator + precursor (an_item) end end diff --git a/libraries/openehr/src/am/archetype/assertion/expr_operator.e b/libraries/openehr/src/am/archetype/assertion/expr_operator.e index 851487c00..b48e36ed6 100755 --- a/libraries/openehr/src/am/archetype/assertion/expr_operator.e +++ b/libraries/openehr/src/am/archetype/assertion/expr_operator.e @@ -23,10 +23,10 @@ feature -- Initialisation do operator := an_op - -- this should be replaced by code that infers typs properly from operands - if boolean_operator (an_op.value) or relational_operator (an_op.value) or set_operator (an_op.value) then + -- this should be replaced by code that infers types properly from operands + if is_boolean_operator (an_op.value) or is_relational_operator (an_op.value) or is_set_operator (an_op.value) then type := op_type_boolean - elseif arithmetic_operator (an_op.value) then + elseif is_arithmetic_operator (an_op.value) then type := op_type_arithmetic end end @@ -54,6 +54,11 @@ feature -- Modification precedence_overridden end + set_operator (an_op: OPERATOR_KIND) + do + operator := an_op + end + end diff --git a/libraries/openehr/src/am/archetype/assertion/operator_types.e b/libraries/openehr/src/am/archetype/assertion/operator_types.e index bf1b052fd..33e6de127 100755 --- a/libraries/openehr/src/am/archetype/assertion/operator_types.e +++ b/libraries/openehr/src/am/archetype/assertion/operator_types.e @@ -92,15 +92,15 @@ feature -- Status Report Result := operator_values.has (an_op_name) end - boolean_operator (an_op: INTEGER): BOOLEAN + is_boolean_operator (an_op: INTEGER): BOOLEAN -- True if an_op can operate on boolean operands require valid_operator (an_op) do - Result := unary_boolean_operator(an_op) or binary_boolean_operator (an_op) + Result := is_unary_boolean_operator(an_op) or is_binary_boolean_operator (an_op) end - unary_boolean_operator (an_op: INTEGER): BOOLEAN + is_unary_boolean_operator (an_op: INTEGER): BOOLEAN -- True if an_op is a unary boolean operator require valid_operator (an_op) @@ -108,7 +108,7 @@ feature -- Status Report Result := an_op = op_not end - binary_boolean_operator (an_op: INTEGER): BOOLEAN + is_binary_boolean_operator (an_op: INTEGER): BOOLEAN -- True if an_op is a binary boolean operator require valid_operator(an_op) @@ -116,7 +116,7 @@ feature -- Status Report Result := an_op >= op_and and an_op <= op_implies end - relational_operator (an_op: INTEGER): BOOLEAN + is_relational_operator (an_op: INTEGER): BOOLEAN -- True if an_op is a binary operator with COMPARABLE arguments returning a boolean require valid_operator(an_op) @@ -124,7 +124,7 @@ feature -- Status Report Result := an_op >= op_eq and an_op <= op_gt end - unary_arithmetic_operator (an_op: INTEGER): BOOLEAN + is_unary_arithmetic_operator (an_op: INTEGER): BOOLEAN -- True if an_op is a unary arithmetic operator require valid_operator (an_op) @@ -132,15 +132,15 @@ feature -- Status Report Result := an_op = op_minus end - arithmetic_operator (an_op: INTEGER): BOOLEAN + is_arithmetic_operator (an_op: INTEGER): BOOLEAN -- True if an_op is a binary operator with numeric arguments returning a numeric require valid_operator (an_op) do - Result := binary_arithmetic_operator(an_op) + Result := is_binary_arithmetic_operator(an_op) end - binary_arithmetic_operator (an_op: INTEGER): BOOLEAN + is_binary_arithmetic_operator (an_op: INTEGER): BOOLEAN -- True if an_op is a binary operator with numeric arguments returning a numeric require valid_operator(an_op) @@ -148,7 +148,7 @@ feature -- Status Report Result := an_op >= op_plus and an_op <= op_exp end - set_operator (an_op: INTEGER): BOOLEAN + is_set_operator (an_op: INTEGER): BOOLEAN -- True if an_op is a unary set operator require valid_operator(an_op) diff --git a/libraries/openehr/src/am/persistence/c_p_factory.e b/libraries/openehr/src/am/persistence/c_p_factory.e new file mode 100644 index 000000000..57debe310 --- /dev/null +++ b/libraries/openehr/src/am/persistence/c_p_factory.e @@ -0,0 +1,166 @@ +note + component: "openEHR ADL Tools" + description: "visitor class to generate P_C_XXX obects from corresponding C_XXX objects" + keywords: "visitor, constraint model" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025- The openEHR Foundation " + license: "Apache 2.0 License " + +class C_P_FACTORY + +inherit + C_VISITOR + redefine + end_c_complex_object, end_c_archetype_root, end_c_attribute, + start_c_terminology_code, start_c_boolean, start_c_integer, start_c_real, start_c_date, start_c_time, start_c_date_time, start_c_duration, start_c_string + end + +create + make + +feature -- Initialisation + + make (an_archetype: ARCHETYPE) + do + create p_c_obj_node_stack.make (0) + create p_c_attr_node_stack.make (0) + initialise (an_archetype) + end + +feature -- Access + + p_c_object: detachable P_C_COMPLEX_OBJECT + +feature -- Visitor + + start_c_complex_object (a_node: C_COMPLEX_OBJECT; depth: INTEGER) + local + p_co: P_C_COMPLEX_OBJECT + do + create p_co.make (a_node) + p_c_obj_node_stack.extend (p_co) + if a_node.is_root then + p_c_object := p_co + else + p_c_attr_node_stack.item.add_child (p_co) + end + end + + end_c_complex_object (a_node: C_COMPLEX_OBJECT; depth: INTEGER) + do + -- deal with attribute tuples + if not a_node.is_prohibited and not a_node.any_allowed then + if attached a_node.attribute_tuples as att_tuples then + across att_tuples as att_tuples_csr loop + p_c_obj_node_stack.item.add_attribute_tuple (create {P_C_ATTRIBUTE_TUPLE}.make (att_tuples_csr.item)) + end + end + end + p_c_obj_node_stack.remove + end + + start_archetype_slot (a_node: ARCHETYPE_SLOT; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_ARCHETYPE_SLOT}.make(a_node)) + end + + start_c_attribute (a_node: C_ATTRIBUTE; depth: INTEGER) + local + p_c_attr: P_C_ATTRIBUTE + do + create p_c_attr.make (a_node) + p_c_attr_node_stack.extend (p_c_attr) + p_c_obj_node_stack.item.add_attribute (p_c_attr) + end + + end_c_attribute (a_node: C_ATTRIBUTE; depth: INTEGER) + do + p_c_attr_node_stack.remove + end + + start_c_leaf_object (a_node: C_LEAF_OBJECT; depth: INTEGER) + do + end + + start_c_archetype_root (a_node: C_ARCHETYPE_ROOT; depth: INTEGER) + local + p_as:P_C_ARCHETYPE_ROOT + do + create p_as.make(a_node) + p_c_attr_node_stack.item.add_child (p_as) + if a_node.has_attributes then + p_c_obj_node_stack.extend (p_as) + end + end + + end_c_archetype_root (a_node: C_ARCHETYPE_ROOT; depth: INTEGER) + do + if a_node.has_attributes then + p_c_obj_node_stack.remove + end + end + + start_c_complex_object_proxy (a_node: C_COMPLEX_OBJECT_PROXY; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_COMPLEX_OBJECT_PROXY}.make(a_node)) + end + + start_c_primitive_object (a_node: C_PRIMITIVE_OBJECT; depth: INTEGER) + do + end + + start_c_boolean (a_node: C_BOOLEAN; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_BOOLEAN}.make(a_node)) + end + + start_c_integer (a_node: C_INTEGER; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_INTEGER}.make(a_node)) + end + + start_c_real (a_node: C_REAL; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_REAL}.make(a_node)) + end + + start_c_date (a_node: C_DATE; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_DATE}.make(a_node)) + end + + start_c_date_time (a_node: C_DATE_TIME; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_DATE_TIME}.make(a_node)) + end + + start_c_time (a_node: C_TIME; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_TIME}.make(a_node)) + end + + start_c_duration (a_node: C_DURATION; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_DURATION}.make(a_node)) + end + + start_c_string (a_node: C_STRING; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_STRING}.make(a_node)) + end + + start_c_terminology_code (a_node: C_TERMINOLOGY_CODE; depth: INTEGER) + do + p_c_attr_node_stack.item.add_child (create {P_C_TERMINOLOGY_CODE}.make(a_node)) + end + +feature {NONE} -- Implementation + + p_c_obj_node_stack: ARRAYED_STACK [P_C_COMPLEX_OBJECT] + + p_c_attr_node_stack: ARRAYED_STACK [P_C_ATTRIBUTE] + +end + + diff --git a/libraries/openehr/src/am/persistence/p_archetype.e b/libraries/openehr/src/am/persistence/p_archetype.e index 9104397a2..06000e32d 100755 --- a/libraries/openehr/src/am/persistence/p_archetype.e +++ b/libraries/openehr/src/am/persistence/p_archetype.e @@ -24,12 +24,26 @@ feature -- Initialisation make (an_archetype: like artefact_class_type) -- basic make routine to guarantee validity on creation + local + a_c_iterator: OG_CONTENT_ITERATOR + c_p_factory: C_P_FACTORY do artefact_type := an_archetype.artefact_type create archetype_id.make (an_archetype.archetype_id) parent_archetype_id := an_archetype.parent_archetype_id - create definition.make (an_archetype.definition) - rules := an_archetype.rules + + create c_p_factory.make (an_archetype) + create a_c_iterator.make (an_archetype.definition.representation, c_p_factory) + a_c_iterator.do_all + definition := c_p_factory.p_c_object + + if attached an_archetype.rules as arch_rules then + create rules.make (0) + across arch_rules as arch_rules_csr loop + rules.extend (create {P_ASSERTION}.make (arch_rules_csr.item)) + end + end + create terminology.make (an_archetype.terminology) is_generated := an_archetype.is_generated is_differential := an_archetype.is_differential @@ -52,7 +66,7 @@ feature -- Access definition: detachable P_C_COMPLEX_OBJECT - rules: detachable ARRAYED_LIST [ASSERTION] + rules: detachable ARRAYED_LIST [P_ASSERTION] terminology: detachable P_ARCHETYPE_TERMINOLOGY @@ -69,23 +83,31 @@ feature -- Factory create_archetype: detachable like artefact_class_type local - o_archetype_id: detachable ARCHETYPE_HRID + o_archetype_id: ARCHETYPE_HRID arch_terminology: ARCHETYPE_TERMINOLOGY + o_rules: ARRAYED_LIST [ASSERTION] do if attached archetype_id as att_aid and attached definition as o_definition and attached terminology as p_terminology then - create o_archetype_id.make_from_string (att_aid.physical_id) + o_archetype_id := att_aid.create_archetype_hrid create arch_terminology.make_differential ((create {TERMINOLOGY_CODE}.default_create).code_string, o_definition.node_id) p_terminology.populate_terminology (arch_terminology) arch_terminology.finalise_dt + if attached rules as att_rules then + create o_rules.make (0) + across att_rules as p_rules_csr loop + o_rules.extend (p_rules_csr.item.create_assertion) + end + end + create Result.make_all ( o_archetype_id, parent_archetype_id, o_definition.create_c_complex_object, - rules, + o_rules, arch_terminology ) diff --git a/libraries/openehr/src/am/persistence/p_archetype_hrid.e b/libraries/openehr/src/am/persistence/p_archetype_hrid.e index a64c790a0..8e3d84cf2 100755 --- a/libraries/openehr/src/am/persistence/p_archetype_hrid.e +++ b/libraries/openehr/src/am/persistence/p_archetype_hrid.e @@ -19,7 +19,6 @@ feature -- Initialisation make (an_id: ARCHETYPE_HRID) do - physical_id := an_id.physical_id if attached an_id.namespace as att_ns then namespace := att_ns.value end @@ -32,16 +31,15 @@ feature -- Initialisation release_version := an_id.release_version - version_status := an_id.version_status + if not an_id.version_status.is_empty then + version_status := an_id.version_status + end build_count := an_id.build_count end feature -- Access - physical_id: STRING - -- full stringified form of id - namespace: detachable STRING -- Reverse domain name namespace identifier. @@ -62,12 +60,19 @@ feature -- Access -- The full numeric version of this archetype consisting of 3 parts, e.g. 1.8.2. The archetype_hrid -- feature includes only the major version. - version_status: STRING + version_status: detachable STRING -- status of version: release candidate, released, build, unstable build_count: STRING -- Build count of this archetype. This is a number that advances from 1 and is reset for -- each new value of release_version. +feature -- Factory + + create_archetype_hrid: ARCHETYPE_HRID + do + create Result.make (rm_publisher, rm_package, rm_class, concept_id, release_version, if attached version_status as v then v else "" end, build_count) + end + end diff --git a/libraries/openehr/src/am/persistence/p_archetype_slot.e b/libraries/openehr/src/am/persistence/p_archetype_slot.e index 183109c22..ffee0b5c7 100755 --- a/libraries/openehr/src/am/persistence/p_archetype_slot.e +++ b/libraries/openehr/src/am/persistence/p_archetype_slot.e @@ -25,19 +25,27 @@ feature -- Initialisation do precursor (an_as) if not an_as.includes.is_empty then - includes := an_as.includes + create includes.make (0) + across an_as.includes as includes_csr loop + includes.extend (create {P_ASSERTION}.make (includes_csr.item)) + end end + if not an_as.excludes.is_empty then - excludes := an_as.excludes + create excludes.make (0) + across an_as.excludes as excludes_csr loop + excludes.extend (create {P_ASSERTION}.make (excludes_csr.item)) + end end + is_closed := an_as.is_closed end feature -- Access - includes: detachable ARRAYED_LIST [ASSERTION] + includes: detachable ARRAYED_LIST [P_ASSERTION] - excludes: detachable ARRAYED_LIST [ASSERTION] + excludes: detachable ARRAYED_LIST [P_ASSERTION] is_closed: BOOLEAN @@ -48,10 +56,14 @@ feature -- Factory create Result.make (rm_type_name, node_id) populate_c_instance (Result) if attached includes as incls then - Result.set_includes (incls) + across incls as p_includes_csr loop + Result.add_include (p_includes_csr.item.create_assertion) + end end if attached excludes as excls then - Result.set_excludes (excls) + across excls as p_excludes_csr loop + Result.add_exclude (p_excludes_csr.item.create_assertion) + end end if is_closed then Result.set_closed diff --git a/libraries/openehr/src/am/persistence/p_assertion.e b/libraries/openehr/src/am/persistence/p_assertion.e new file mode 100644 index 000000000..144114fa9 --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_assertion.e @@ -0,0 +1,59 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of ASSERTION." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +class P_ASSERTION + +inherit + P_DEFINITIONS + export {NONE} + all + end + +create + make + +feature -- Initialisation + + make (an_ass: ASSERTION) + do + tag := an_ass.tag + expression := expression_to_p_expression (an_ass.expression) + type := {OPERATOR_TYPES}.op_type_boolean + end + +feature -- Access + + tag: detachable STRING + -- tag name of assertion + + expression: P_EXPRESSION + attribute + create {P_EXPR_LITERAL} Result + end + + type: STRING + attribute + create Result.make_empty + end + +feature -- Factory + + create_assertion: ASSERTION + do + if attached tag as att_tag then + create Result.make_with_tag (expression.create_expression, att_tag) + else + create Result.make (expression.create_expression) + end + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_authored_archetype.e b/libraries/openehr/src/am/persistence/p_authored_archetype.e index 4278b8fd2..5da8f3317 100755 --- a/libraries/openehr/src/am/persistence/p_authored_archetype.e +++ b/libraries/openehr/src/am/persistence/p_authored_archetype.e @@ -74,16 +74,17 @@ feature -- Factory create_archetype: detachable like artefact_class_type local - o_archetype_id: detachable ARCHETYPE_HRID + o_archetype_id: ARCHETYPE_HRID arch_terminology: ARCHETYPE_TERMINOLOGY o_uid, o_build_uid: detachable HIER_OBJECT_ID + o_rules: ARRAYED_LIST [ASSERTION] do if attached archetype_id as att_aid and attached description as o_description and attached definition as o_definition and attached terminology as p_terminology then - create o_archetype_id.make_from_string (att_aid.physical_id) + o_archetype_id := att_aid.create_archetype_hrid if attached uid as att_uid then create o_uid.make_from_string (att_uid) end @@ -91,6 +92,13 @@ feature -- Factory create o_build_uid.make_from_string (build_uid) end + if attached rules as att_rules then + create o_rules.make (0) + across att_rules as p_rules_csr loop + o_rules.extend (p_rules_csr.item.create_assertion) + end + end + create arch_terminology.make_differential (original_language.code_string, o_definition.node_id) p_terminology.populate_terminology (arch_terminology) @@ -112,7 +120,7 @@ feature -- Factory translations, o_description, o_definition.create_c_complex_object, - rules, + o_rules, arch_terminology, annotations ) diff --git a/libraries/openehr/src/am/persistence/p_c_attribute.e b/libraries/openehr/src/am/persistence/p_c_attribute.e index 35d902dcb..4b07fb1aa 100755 --- a/libraries/openehr/src/am/persistence/p_c_attribute.e +++ b/libraries/openehr/src/am/persistence/p_c_attribute.e @@ -28,43 +28,7 @@ feature -- Initialisation if attached a_ca.existence as att_ex then existence := att_ex.as_string end --- if attached a_ca.cardinality as att_card then --- cardinality := att_card.as_string --- end cardinality := a_ca.cardinality - if attached a_ca.children as att_children then - create p_c_objs.make (0) - children := p_c_objs - across att_children as c_objs_csr loop - if attached {C_ARCHETYPE_ROOT} c_objs_csr.item as c_ar then - p_c_objs.extend (create {P_C_ARCHETYPE_ROOT}.make(c_ar)) - elseif attached {C_COMPLEX_OBJECT} c_objs_csr.item as c_co then - p_c_objs.extend (create {P_C_COMPLEX_OBJECT}.make(c_co)) - elseif attached {ARCHETYPE_SLOT} c_objs_csr.item as a_s then - p_c_objs.extend (create {P_ARCHETYPE_SLOT}.make(a_s)) - elseif attached {C_COMPLEX_OBJECT_PROXY} c_objs_csr.item as a_ir then - p_c_objs.extend (create {P_C_COMPLEX_OBJECT_PROXY}.make(a_ir)) - elseif attached {C_INTEGER} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_INTEGER}.make(c_po)) - elseif attached {C_REAL} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_REAL}.make(c_po)) - elseif attached {C_DATE} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_DATE}.make(c_po)) - elseif attached {C_TIME} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_TIME}.make(c_po)) - elseif attached {C_DATE_TIME} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_DATE_TIME}.make(c_po)) - elseif attached {C_DURATION} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_DURATION}.make(c_po)) - elseif attached {C_BOOLEAN} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_BOOLEAN}.make(c_po)) - elseif attached {C_TERMINOLOGY_CODE} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_TERMINOLOGY_CODE}.make(c_po)) - elseif attached {C_STRING} c_objs_csr.item as c_po then - p_c_objs.extend (create {P_C_STRING}.make(c_po)) - end - end - end end feature -- Access @@ -79,6 +43,21 @@ feature -- Access cardinality: detachable CARDINALITY +feature -- Modification + + add_child (a_p_c_obj: P_C_OBJECT) + local + pcobjs: ARRAYED_LIST [P_C_OBJECT] + do + if attached children as att_children then + pcobjs := att_children + else + create pcobjs.make (0) + children := pcobjs + end + pcobjs.extend (a_p_c_obj) + end + feature -- Status Report is_multiple: BOOLEAN @@ -89,7 +68,6 @@ feature -- Factory -- recreate original C_ATTRIBUTE local ex: detachable MULTIPLICITY_INTERVAL - card: detachable CARDINALITY do if attached existence as att_ex then create ex.make_from_string (att_ex) diff --git a/libraries/openehr/src/am/persistence/p_c_complex_object.e b/libraries/openehr/src/am/persistence/p_c_complex_object.e index 6d5e2d559..383d9a25e 100755 --- a/libraries/openehr/src/am/persistence/p_c_complex_object.e +++ b/libraries/openehr/src/am/persistence/p_c_complex_object.e @@ -12,42 +12,45 @@ class P_C_COMPLEX_OBJECT inherit P_C_DEFINED_OBJECT redefine - make, populate_c_instance + populate_c_instance end create make -feature -- Initialisation +feature -- Access + + attributes: detachable ARRAYED_LIST [P_C_ATTRIBUTE] + + attribute_tuples: detachable ARRAYED_LIST [P_C_ATTRIBUTE_TUPLE] - make (a_cco: C_COMPLEX_OBJECT) +feature -- Modification + + add_attribute_tuple (a_p_c_attr_tuple: P_C_ATTRIBUTE_TUPLE) local - p_c_attr_tuples: ARRAYED_LIST [P_C_ATTRIBUTE_TUPLE] - p_c_attr_list: ARRAYED_LIST [P_C_ATTRIBUTE] + attr_tuples: ARRAYED_LIST [P_C_ATTRIBUTE_TUPLE] do - precursor (a_cco) - if a_cco.has_attributes then - create p_c_attr_list.make (0) - attributes := p_c_attr_list - across a_cco.attributes as ca_csr loop - p_c_attr_list.extend (create {P_C_ATTRIBUTE}.make (ca_csr.item)) - end - - if attached a_cco.attribute_tuples as atpl then - create p_c_attr_tuples.make (0) - across atpl as ca_tuple_csr loop - p_c_attr_tuples.extend (create {P_C_ATTRIBUTE_TUPLE}.make (ca_tuple_csr.item)) - end - attribute_tuples := p_c_attr_tuples - end + if attached attribute_tuples as atpl then + attr_tuples := atpl + else + create attr_tuples.make (0) + attribute_tuples := attr_tuples end + attr_tuples.extend (a_p_c_attr_tuple) end -feature -- Access - - attributes: detachable ARRAYED_LIST [P_C_ATTRIBUTE] - - attribute_tuples: detachable ARRAYED_LIST [P_C_ATTRIBUTE_TUPLE] + add_attribute (a_p_c_attr: P_C_ATTRIBUTE) + local + pcattrs: ARRAYED_LIST [P_C_ATTRIBUTE] + do + if attached attributes as attrs then + pcattrs := attrs + else + create pcattrs.make (0) + attributes := pcattrs + end + pcattrs.extend (a_p_c_attr) + end feature -- Factory diff --git a/libraries/openehr/src/am/persistence/p_c_object.e b/libraries/openehr/src/am/persistence/p_c_object.e index d9a4be831..7d73226c7 100755 --- a/libraries/openehr/src/am/persistence/p_c_object.e +++ b/libraries/openehr/src/am/persistence/p_c_object.e @@ -28,9 +28,6 @@ feature -- Initialisation do rm_type_name := a_co.rm_type_name node_id := a_co.node_id --- if attached a_co.occurrences as att_occ then --- occurrences := att_occ.as_string --- end occurrences := a_co.occurrences sibling_order := a_co.sibling_order is_deprecated := a_co.is_deprecated diff --git a/libraries/openehr/src/am/persistence/p_c_string.e b/libraries/openehr/src/am/persistence/p_c_string.e index 46ecd17e0..d94694774 100755 --- a/libraries/openehr/src/am/persistence/p_c_string.e +++ b/libraries/openehr/src/am/persistence/p_c_string.e @@ -16,7 +16,7 @@ inherit end create - make + make, make_all feature -- Initialisation @@ -28,6 +28,13 @@ feature -- Initialisation end end + make_all (a_cpo: C_STRING) + -- make, including constraint even if it is open + do + make (a_cpo) + constraint := a_cpo.constraint + end + feature -- Access constraint: detachable ARRAYED_LIST [STRING] diff --git a/libraries/openehr/src/am/persistence/p_definitions.e b/libraries/openehr/src/am/persistence/p_definitions.e new file mode 100644 index 000000000..86f4915ac --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_definitions.e @@ -0,0 +1,34 @@ +note + component: "openEHR ADL Tools" + description: "Definitions and utilities for P_XXX classess." + keywords: "archetype, persistence" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2011- Ocean Informatics Pty Ltd " + license: "Apache 2.0 License " + +class P_DEFINITIONS + +feature -- Factory + + expression_to_p_expression (an_expr: EXPRESSION): P_EXPRESSION + do + if attached {EXPR_ARCHETYPE_REF} an_expr as expr then + create {P_EXPR_ARCHETYPE_REF} Result.make (expr) + elseif attached {EXPR_ARCHETYPE_ID_CONSTRAINT} an_expr as expr then + create {P_EXPR_ARCHETYPE_ID_CONSTRAINT} Result.make (expr) + elseif attached {EXPR_CONSTRAINT} an_expr as expr then + create {P_EXPR_CONSTRAINT} Result.make (expr) + elseif attached {EXPR_BINARY_OPERATOR} an_expr as expr then + create {P_EXPR_BINARY_OPERATOR} Result.make (expr) + elseif attached {EXPR_UNARY_OPERATOR} an_expr as expr then + create {P_EXPR_UNARY_OPERATOR} Result.make (expr) + elseif attached {EXPR_LITERAL} an_expr as expr then + create {P_EXPR_LITERAL} Result.make (expr) + else + create {P_EXPR_LITERAL} Result + end + end + +end + diff --git a/libraries/openehr/src/am/persistence/p_expr_archetype_id_constraint.e b/libraries/openehr/src/am/persistence/p_expr_archetype_id_constraint.e new file mode 100644 index 000000000..bc6020c68 --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_archetype_id_constraint.e @@ -0,0 +1,45 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_ARCHETYPE_REF." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +class P_EXPR_ARCHETYPE_ID_CONSTRAINT + +inherit + P_EXPR_CONSTRAINT + redefine + make, item, create_expression + end + +create + make + +feature -- Initialisation + + make (an_as: EXPR_ARCHETYPE_ID_CONSTRAINT) + do + check attached {C_STRING} an_as.item as c_s then + create item.make_all (c_s) + type := c_s.generating_type + end + end + +feature -- Access + + item: P_C_STRING + +feature -- Factory + + create_expression: EXPR_ARCHETYPE_ID_CONSTRAINT + do + create Result.make (item.create_c_primitive_object) + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expr_archetype_ref.e b/libraries/openehr/src/am/persistence/p_expr_archetype_ref.e new file mode 100644 index 000000000..121e118e3 --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_archetype_ref.e @@ -0,0 +1,40 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_ARCHETYPE_REF." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +class P_EXPR_ARCHETYPE_REF + +inherit + P_EXPR_LEAF + +create + make + +feature -- Initialisation + + make (an_as: EXPR_ARCHETYPE_REF) + do + path := an_as.path + type := an_as.type + end + +feature -- Access + + path: STRING + +feature -- Factory + + create_expression: EXPR_ARCHETYPE_REF + do + create Result.make_definition (path) + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expr_binary_operator.e b/libraries/openehr/src/am/persistence/p_expr_binary_operator.e new file mode 100644 index 000000000..a76f66bac --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_binary_operator.e @@ -0,0 +1,49 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_BINARY_OPERATOR." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +class P_EXPR_BINARY_OPERATOR + +inherit + P_EXPR_OPERATOR + + P_DEFINITIONS + export {NONE} + all + end + +create + make + +feature -- Initialisation + + make (an_op: EXPR_BINARY_OPERATOR) + do + make_operator (an_op) + left_operand := expression_to_p_expression (an_op.left_operand) + right_operand := expression_to_p_expression (an_op.right_operand) + end + +feature -- Access + + left_operand: P_EXPRESSION + + right_operand: P_EXPRESSION + +feature -- Factory + + create_expression: EXPR_BINARY_OPERATOR + do + create Result.make (create {OPERATOR_KIND}.make_from_string (operator), left_operand.create_expression, right_operand.create_expression) + populate_operator (Result) + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expr_constraint.e b/libraries/openehr/src/am/persistence/p_expr_constraint.e new file mode 100644 index 000000000..dab9c3a4b --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_constraint.e @@ -0,0 +1,65 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_ARCHETYPE_REF." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +class P_EXPR_CONSTRAINT + +inherit + P_EXPR_LEAF + +create + make + +feature -- Initialisation + + make (an_as: EXPR_CONSTRAINT) + do + if attached {C_STRING} an_as.item as c then + create {P_C_STRING} item.make (c) + + elseif attached {C_BOOLEAN} an_as.item as c then + create {P_C_BOOLEAN} item.make (c) + + elseif attached {C_INTEGER} an_as.item as c then + create {P_C_INTEGER} item.make (c) + elseif attached {C_REAL} an_as.item as c then + create {P_C_REAL} item.make (c) + + elseif attached {C_DATE} an_as.item as c then + create {P_C_DATE} item.make (c) + elseif attached {C_DATE_TIME} an_as.item as c then + create {P_C_DATE_TIME} item.make (c) + elseif attached {C_TIME} an_as.item as c then + create {P_C_TIME} item.make (c) + elseif attached {C_DURATION} an_as.item as c then + create {P_C_DURATION} item.make (c) + + elseif attached {C_TERMINOLOGY_CODE} an_as.item as c then + create {P_C_TERMINOLOGY_CODE} item.make (c) + + end + end + +feature -- Access + + item: P_C_PRIMITIVE_OBJECT + attribute + create {P_C_BOOLEAN} Result.make (create {C_BOOLEAN}.make_false) + end + +feature -- Factory + + create_expression: EXPR_CONSTRAINT + do + create Result.make(item.create_c_primitive_object) + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expr_leaf.e b/libraries/openehr/src/am/persistence/p_expr_leaf.e new file mode 100644 index 000000000..723ccbe33 --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_leaf.e @@ -0,0 +1,20 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_LEAF." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +deferred class P_EXPR_LEAF + +inherit + P_EXPRESSION + +feature -- Access + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expr_literal.e b/libraries/openehr/src/am/persistence/p_expr_literal.e new file mode 100644 index 000000000..141ddbddf --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_literal.e @@ -0,0 +1,60 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_LITERAL." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +class P_EXPR_LITERAL + +inherit + P_EXPR_LEAF + +create + make, default_create + +feature -- Initialisation + + make (a_literal: EXPR_LITERAL) + -- node is a boolean value + do + item := a_literal.item + type := a_literal.type + end + +feature -- Access + + item: ANY + attribute + Result := 0 + end + +feature -- Factory + + create_expression: EXPR_LITERAL + do + if attached {BOOLEAN} item as bool then + create Result.make_boolean (bool) + + elseif attached {REAL} item as r then + create Result.make_real (r) + + elseif attached {INTEGER} item as i then + create Result.make_integer (i) + + elseif attached {STRING} item as s then + create Result.make_string (s) + + elseif attached {CHARACTER} item as c then + create Result.make_character (c) + else + create Result.make_boolean (False) + end + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expr_operator.e b/libraries/openehr/src/am/persistence/p_expr_operator.e new file mode 100644 index 000000000..6555354fa --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_operator.e @@ -0,0 +1,42 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_OPERATOR." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +deferred class P_EXPR_OPERATOR + +inherit + P_EXPRESSION + +feature -- Initialisation + + make_operator (an_op: EXPR_OPERATOR) + do + operator := an_op.operator.as_string_name + precedence_overridden := an_op.precedence_overridden + type := an_op.type + end + +feature -- Access + + operator: STRING + + precedence_overridden: BOOLEAN + +feature -- Factory + + populate_operator (an_op: EXPR_OPERATOR) + do + if precedence_overridden then + an_op.override_precedence + end + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expr_unary_operator.e b/libraries/openehr/src/am/persistence/p_expr_unary_operator.e new file mode 100644 index 000000000..c6a82e111 --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expr_unary_operator.e @@ -0,0 +1,46 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPR_UNARY_OPERATOR." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +class P_EXPR_UNARY_OPERATOR + +inherit + P_EXPR_OPERATOR + + P_DEFINITIONS + export {NONE} + all + end + +create + make + +feature -- Initialisation + + make (an_op: EXPR_UNARY_OPERATOR) + do + make_operator(an_op) + operand := expression_to_p_expression (an_op.operand) + end + +feature -- Access + + operand: P_EXPRESSION + +feature -- Factory + + create_expression: EXPR_UNARY_OPERATOR + do + create Result.make (create {OPERATOR_KIND}.make_from_string (operator), operand.create_expression) + populate_operator (Result) + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_expression.e b/libraries/openehr/src/am/persistence/p_expression.e new file mode 100644 index 000000000..ddf01352d --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_expression.e @@ -0,0 +1,24 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of EXPRESSION." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +deferred class P_EXPRESSION + +inherit + P_RULE_ELEMENT + +feature -- Factory + + create_expression: EXPRESSION + deferred + end + +end + + diff --git a/libraries/openehr/src/am/persistence/p_rule_element.e b/libraries/openehr/src/am/persistence/p_rule_element.e new file mode 100644 index 000000000..acaeadd15 --- /dev/null +++ b/libraries/openehr/src/am/persistence/p_rule_element.e @@ -0,0 +1,22 @@ +note + component: "openEHR ADL Tools" + description: "Persistent form of RULE_ELEMENT." + keywords: "persistence, ADL" + author: "Thomas Beale " + support: "http://www.openehr.org/issues/browse/AWB" + copyright: "Copyright (c) 2025 openEHR International" + license: "Apache 2.0 License " + + +deferred class P_RULE_ELEMENT + +feature -- Access + + type: STRING + attribute + create Result.make_empty + end + +end + +