


image::https://specifications.openehr.org/images/openEHR_logo_RGB.svg["openEHR logo",align="center"]

# Basic Meta-Model (BMM)





## Acknowledgements

### Primary Author

* Thomas Beale, Ars Semantica; openEHR Foundation Management Board.

### Contributors

This specification has benefited from formal and informal input from the openEHR and wider health informatics community. The openEHR Foundation would like to recognise the following people for their contributions.

* Patrick Langford, NeuronSong LLC, Utah, USA
* Claude Nanjo MA African Studies., M Public Health, Cognitive Medical Systems Inc., California, USA
* Harold Solbrig, Mayo Clinic, Rochester, USA
* Erik Sundvall PhD, Linkoping University, Sweden

### Trademarks

* 'openEHR' is a registered trademark of the openEHR Foundation
* 'Java' is a registered trademark of Oracle Corporation
* 'C#' is a registered trademark of Microsoft Corporation
* 'OMG' and 'UML' are registered trademarks of the Object Management Group
* 'MagicDraw' is a registered trademark of NoMagic Inc
* 'Rational Software Architect' is a registered trademark of IBM Corporation.


ifdef::package_qualifiers[]
endif::[]

# Preface

## Purpose

This document describes the Basic Meta-Model (BMM), a model of object models. It may be considered as an approximate replacement for the UML XMI. It is human-readable and writable, and supports generic types (open and closed), container types, and multiple inheritance.

## Status

This specification is in the STABLE state. The development version of this document can be found at {openehr_bmm}[{openehr_bmm}^].

Known omissions or questions are indicated in the text with a 'to be determined' paragraph, as follows:
*TBD*: (example To Be Determined paragraph)

## Feedback

Feedback may be provided on the https://discourse.openehr.org/c/specifications/bmm-el[openEHR languages specifications forum^].

Issues may be raised on the https://specifications.openehr.org/components/{component}/open_issues[specifications Problem Report tracker^].

To see changes made due to previously reported issues, see the https://specifications.openehr.org/components/{component}/history[{component} component Change Request tracker^].

## History

The Basic Meta-Model originated in the openEHR BASE component, where it was published up to and including {openehr_base_release_104}/bmm.html[BASE Release 1.0.4^]. With the establishment of the openEHR LANG (Generic Languages) component, the BMM specification was migrated to LANG, which is now its normative home. This document describes the stable v2.x form of BMM, i.e. the form implemented by current openEHR tooling such as Archie.

Continued development of the meta-model, extending it with an expression and statement meta-model together with richer feature and signature metadata, is carried out separately and is documented in the {openehr_bmm3}[BMM v3 specification^]. The v2.x form described here remains the normative, tool-implemented version.

The P_BMM persistence model, which defines the serialised schema form of a BMM model together with its {openehr_odin}[ODIN^] syntax, is specified separately in the {openehr_bmm_persistence}[BMM Persistence specification^].


# Overview

## Introduction

One of the key needs in any open computing environment is a computable representation of its own models, for a number of purposes, including reasoning about them, performing validation and consistency checking, building software and generating documentation. This is particularly true of openEHR, where a further need is to be able to validate archetypes and templates with respect to the reference model, and also to validate runtime instance data against operational templates and the reference model.

A number of computable representations of the openEHR published models have been available in the past. Currently models are represented in two computable forms:

* MagicDraw 18.5 or higher UML/XMI;
* Basic Meta-Model (BMM) format, i.e. the format of this specification.

The primary use of the UML expression is for specification publishing. In this role, the internal UML is processed to generate correct signatures for class properties and functions, and can be used computably for other purposes, as long as care is taken with template and qualified attributes.

The BMM provides a standalone alternative to UML/XMI which correctly represents all types, including open and closed template types, and is human-readable. It was originally developed in 2012, when the state of UML tools and particularly XMI was poor, and a reliable format was needed for openEHR modelling tools. 

NOTE: Other than for working with particular tools designed to use BMM, BMM is not a required formalism for implementing openEHR, and other methods of accessing models computably may be used, including UML and software implementations of the openEHR Reference Model.

## Current State of the Art

One would expect that the ICT industry would have fully computable representations of models and diagramming solved, but it is not yet the case. UML 2.x and its associated serialisation format XMI 2.x should in theory mean that complete, interoperable machine expressions of object models would be available in all tools. It will probably eventually come to pass, but a number of obstacles remain to date:

* the UML 2.x specifications are exceedingly complex (see OMG site for specifications; UML 2.1.2 'superstructure' = 738pp; UML 2.1.2 'infrastructure' = 224pp);
* the XMI 2.x specification is correspondingly complex, which seems to have so far prevented reliable tool interoperability (recognised as a critical issue by OMG in 2015);
* the Design By Contract (DbC) concept is supported via the use of OCL 2.0 constraints in class models, although there are semantic holes, e.g. proper semantics through inheritance;
* for some, XML schema represents a way of expressing object models, but in fact is not semantically suitable for this purpose, primarily due to its different inheritance model. It can be and is used (including in openEHR) as a derivative serialisation representation, but from the point of view of specification, it is deficient in having non-object-oriented inheritance semantics, no generic classes, no representation of non-data members, and only marginal support for design by contract.

Experience with various UML tools (up till 2015) highlighted the following problems:

* poor support for OCL and design by contract in most tools;
* variable support for generic (i.e. template) classes; even those tools that properly implement the UML 2.5 specification are still very hard to use for defining generic classes because of problems in the specification that remain unaddressed;
* problems with qualified attributes, which are used to represent identifier references to objects rather than direct references;
* variable support for XSD generation across tools, where the results are wildly wrong in some tools;
* in some tools, it is impossible to define an abstract formal model - the only option is to select a particular programming language profile such as Java or C# and thus get locked into the limitations of those languages (messy type systems, weak inheritance semantics, language-specific notion of types such as `Array<T>`, `List<T>`, etc.).

Since 2015, the quality of some UML tools has improved, and the XMI generated by some is more reliable. However, XMI generated by different tools is not the same for identical models, and some XMI importers offer numerous switches in order to process the XMI of another tool properly. XMI thus still needs to be processed with care.

Nevertheless, a small number of tools, including MagicDraw (currently used for representing openEHR models for the specifications) and Rational Software Architect (RSA), appear to implement UML 2.5 faithfully. This means that despite the limitations of UML 2.5 (as noted above), models expressed in it can be correctly interpreted and processed for purposes such as code generation.

NOTE: Other tools may well perform as well or better, and in any case, all tools change over time. No endorsement of a particular tool is intended here.

## Design

The Basic Meta-Model supports the representation of object models in the data point of view. It is designed to enable both human authoring and machine extraction (e.g. from a UML tool or programming language classes) of textual schemas. This specification defines a BMM object model, i.e. the in-memory object structure of a BMM, and also an object model for a serialised schema form. The latter enables serialisation of a BMM into a concrete syntax such as ODIN, JSON or XML. In the future an abstract syntax serialisation may be developed in the style of OMG IDL (Interface Definition Language) or similar.

The BMM packages are as follows:

* `rm_access`: the interface to most features including schema load/reload, generally used by an application as a reflection library;
* `core`: the core BMM classes used for in-memory representation of an object model;
* `persistence`: a simplified version of the core classes prefixed with `P_BMM_`, used for persistence and human authoring, which allow file (i.e. schema) inclusion and re-use.

The `P_BMM_*` classes perform two functions. Firstly, they are a modified and simplified version of the `BMM_*` classes that enable for example symbolic referencing via class names, syntactical type names to be used etc, rather than the full explosion of fine-grained objects that would result from a direct serialisation of `BMM_*` classes. This is what enables the P_BMM file format to be easily readable and editable by human users.

The second is that P_BMM files function as schemas that support schema inclusion and therefore re-use, in a similar manner to the XML schema languages. Thus, a single logical BMM model can be expressed as a _number_ of P_BMM schema files which are actually `P_BMM_*` object serialisations. A schema reading component has to resolve the schema inclusions and ultimately `BMM_*` object instantiations to obtain the in-memory form of the model.

We thus talk of the `P_BMM_*` classes as a model of 'BMM schemas' and the `BMM_*` classes as a model of 'BMM models', where the latter is understood as the fully computable in-memory object structure with all name references resolved to object references.

The packages are illustrated below.

.Package Overview
image::UML/diagrams/LANG-bmm-packages.svg[id=package_overview, align="center"]

The normal use of BMM is as follows:

* create a P_BMM schema in the form of one or more files, using the `P_BMM_` form of the model. This is easy to understand by copying existing examples;
* locate these files in a suitable place for use with a tool such as the {openehr_awb}[openEHR ADL Workbench] and {linkehr}[LinkEHR].

## Schema Format

BMM models are normally expressed as schema text files that support inclusion and re-use. The default file format has historically been {openehr_odin}[openEHR ODIN syntax], and BMM tools to date support this format. However any common format that can express typed object models may be used, including JSON (with type markers), YAML, and XML. The examples shown in this specification are primarily in ODIN, but a tool implementing BMM may choose to serialise in and out of another preferred format.

## A Note on Language

The elements of meta-models are sometimes named confusingly in the literature and within various programming language technologies. In this specification, we have used the following terms:

feature (of a class):: any stored or computed element of a class, including constants, attributes (properties) and routines (methods);
property:: a stored class feature; also known as 'attribute';
routine:: a computed class feature that may be either value-returning (a function) or work-performing (a procedure);
function:: a routine that computes and returns a value; typically causes no side-effects in the object;
procedure:: a routine that performs a computation; typically has side-effects;
generic (class or type):: a kind of class or type that has parameters of other types; known as 'template' type in some programming languages.

# BMM in Use

BMM schemas as used in the openEHR ADL Workbench (AWB) provide an illustration of their use and visualisation. The following screenshot shows the BMM schema configuration dialog in the AWB, including some meta-data, validation status etc, and also the schema nesting structure.

.BMM schema configuration
image::{doc_name}/images/awb_schemas_config.png[id=awb_schemas_config, align="center", width="60%"]

The screenshot below shows a number of BMMs loaded into the AWB, including some of the packages and classes for the 'openehr_ehr_extract_1.1.0' model.

.BMM schemas loaded
image::{doc_name}/images/awb_loaded_bmm_schemas.png[id=awb_loaded_bmm_schemas, align="center", width="40%"]

The following shows a single class in the inheritance-flattened properties view, otherwise known as the 'flat view'. The structure of the class as properties, types, multiplicities, inheritance etc are all provided by the in-memory BMM classes.

.BMM class - properties view
image::{doc_name}/images/awb_class_properties.png[id=awb_class_properties, align="center", width="50%"]

The following shows a class in a 'closure' view, which is a computed reachability graph of a fully inheritance-flattened class and all properties, including recursive references.

.BMM class - closure view
image::{doc_name}/images/awb_class_closure.png[id=awb_class_closure, align="center", width="60%"]

One of the main uses of the BMM in the ADL Workbench and other similar tools is to provide a computable form of the information model ('reference model' in openEHR) for use with archetypes. The following shows an archetype for which each node has its RM class shown (in colour), and additionally, the inclusion of non-archetyped attributes from the classes of the archetype nodes.

.ADL archetype with BMM class properties
image::{doc_name}/images/archetype_rm.png[id=archetype_rm, align="center"]



# RM Access Package

## Overview

The `rm_access` package provides an interface for the application to load and access BMM schemas, and is shown below.

.bmm.rm_access Package
image::UML/diagrams/LANG-bmm.rm_access.svg[id=rm_access_package, align="center"]


## Class Definitions



# Core Package

## Overview

The `core` package, shown below, defines the main BMM model.

.bmm.core Package
image::UML/diagrams/LANG-bmm.core.svg[id=core_package, align="center"]

## Semantics

### Basics

Three top-level classes define basic abstract semantics for all other entities in the BMM: `BMM_MODEL_ELEMENT`, `BMM_CLASSIFIER` and `BMM_TYPE`. The first of these introduces features common to all elements of any BMM, such as `_documentation_`. The class `BMM_CLASSIFIER` is the abstract parent of anything that functions as the type of a property (viz: classes, types and generic parameters), while its descendant `BMM_TYPE` defines the semantics of types of instances, described below.

The `BMM_CLASSIFIER` class has a small number of important features that establish formally the meaning of various kinds of class names, type names etc, as follows:

* _type_name_: the effective type of an entity; for simple classes, this will just be the class name (`BMM_CLASS._name_`); for generic and container classes it will be generic name such as `List<T>`, `Interval<T>` etc; for feature types it will be the declared type, i.e. a simple name, an open type name (e.g. `T`) or a generic type name (e.g. `Interval<Time>`);
* _type_signature_: a form of the type name that can be used as a fully-defined type signature, which for generic classes includes generic constrainer types, giving a signature such as `Interval<T:Ordered>`;
* _conformance_type_name_: a reduced form of the type useful in some circumstances that is either a simple class name, the _contained_ type for a container type (e.g. `ELEMENT` from the type `List<ELEMENT>`), and the _root_ type from a generic type (e.g. `Interval` from `Interval<T>`).

In addition, concrete classes such as `BMM_CLASS` and `BMM_PROPERTY` have a simple `_name_` property, corresponding to the literal names of these entities.

### Classes and Types

One of the foundational concepts in the BMM is a distinction between _class_ and _type_, in common with the type systems of the modern forms of most object-oriented languages. Classes are definitional entities, while 'type' has two meanings: as the static (design time) type of a class feature (property or function result) and as the dynamic (run-time) type of the object referred to by or computed by that feature. At design time, the type of a property in a BMM model can be one of the following:

* a `BMM_SIMPLE_TYPE` - corresponds to a simple class;
* a `BMM_OPEN_TYPE` - corresponds to a generic parameter type from the class type definition, e.g. `T`, `U` etc;
* a `BMM_GENERIC_TYPE` - a type generated by the use of a generic type with filled type parameters, e.g. `Interval<Time>`;
* a `BMM_CONTAINER_TYPE` - a type generated by the use of a linear container type such as `List<T>`, `Hash<T,U>` with actual generic parameters.

In object-oriented type theory, the last two are really the same thing, but the BMM treats them slightly differently for reasons of clarity: a `BMM_CONTAINER_TYPE` can be thought of as a 1:N counterpart to a `BMM_SIMPLE_TYPE`, whereas `BMM_GENERIC_TYPE` is typically used for objects considered to be singular, but whose types are a product of a special container and one or more parameter types.

### Inheritance

The BMM supports single and multiple inheritance, although it does not distinguish between different types of inheritance relation as some programming languages do. The evaluation of inheritance relations defined in a BMM schema results in an acyclic graph such that ancestors and descendants can be visualised for any class. The following screen shot shows the ancestors view of a class `OBSERVATION`.

.BMM class - ancestors view
image::{doc_name}/images/awb_class_ancestors.png[id=awb_class_ancestors, align="center", width="40%"]

The next screenshot shows the descendants view of one of the ancestor classes of the same class.

.BMM class - descendants view
image::{doc_name}/images/awb_class_descendants.png[id=awb_class_descendants, align="center", width="40%"]

Multiple inheritance is typically used in the definition of classes that have a Liskov substitution inheritance relation as well as an implementation inheritance relation. The following shows a class `DV_INTERVAL<T>` multiply inheriting from `Interval<T>` and `DATA_VALUE`.

.BMM class - descendants view
image::{doc_name}/images/awb_multiple_inheritance.png[id=awb_class_inheritance, align="center", width="40%"]

### Classes and Properties

Class properties are defined using the generic class `BMM_PROPERTY <T: BMM_TYPE>`. This approach provides a direct way of expressing the semantics of property meta-types as listed above. The properties of a class can be understood in two forms. In an original model definition, each class definition states the features it introduces with respect to its inheritance parents. We can think of this list of properties as a _differential_ set. In contrast, the _effective_ set of properties for a class is the result of evaluating these lists of properties down the inheritance hierarchy to obtain the _flat_ set of properties. The features _properties_ and _flat_properties_ defined on `BMM_CLASS` provide access to these two lists for any class.

## Class Definitions



# Persistence

The `persistence` package defines a simplified form of the core BMM model, expressed as the `P_BMM_*` classes, suitable for serialising and human authoring of BMM schemas. Such a schema is typically saved as a `.bmm` file in the {openehr_odin}[ODIN^] syntax, and supports file inclusion and re-use, so that a single logical model may be expressed as a number of schema files.

The `P_BMM_*` model, its class definitions and its serialised syntax are specified separately. See the {openehr_bmm_persistence}[BMM Persistence specification^] for full details.



:sectnums!:
## References

bibliography::[]
