openehr-its 0.0.128

openEHR ITS (Implementation Technology Specifications): canonical JSON + canonical XML serialization of the RM, the generated ITS-REST 1.1.0 API contract, and the OPT 1.4 and AOM2 archetype XML codecs
Documentation
// @generated by openehr-codegen (emit-aom2) — DO NOT EDIT.
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-FileCopyrightText: openEHR Foundation
// SPDX-License-Identifier: Apache-2.0
//! openEHR AOM2 model-form archetype model + canonical-XML codec.
//!
//! Parse a model-form AOM2 archetype with [`from_xml`]; the root element is `<archetype>` (`AUTHORED_ARCHETYPE`).
//!
//! This is the AOM MODEL form — `Archetype.xsd`, whose own header calls it "uses
//! AOM-like types - not space-efficient": the AOM2 classes themselves
//! (`C_COMPLEX_OBJECT`, `C_ATTRIBUTE`, `ARCHETYPE_TERMINOLOGY`,
//! `MultiplicityInterval`), as opposed to the persistent `P_AOM` form in
//! [`crate::aom2`]. Both schemas declare the top-level element `<archetype>`, so
//! a document's ROOT TYPE — not its element name — decides which module reads it.
//!
//! Root type: `Archetype.xsd` declares
//! `<xs:element name="archetype" type="ARCHETYPE"/>`, but `ARCHETYPE` is
//! `abstract="true"` and no complexType in the closure derives from it —
//! `AUTHORED_ARCHETYPE` extends `AUTHORED_RESOURCE` and re-uses the archetype body
//! through `<xs:group ref="ARCHETYPE"/>` instead. `AUTHORED_ARCHETYPE` is
//! therefore the only instantiable archetype root the schema offers, and the entry
//! points here are typed to it; `Archetype` itself is not emitted, because an
//! abstract type with no concrete subtype can never appear on the wire.
//!
//! Corpus ceiling: openEHR publishes NO model-form instance documents. All 8
//! `AOM2/examples/*.xml` are persistent-form, `openEHR/adl-archetypes` publishes
//! ADL text only, and `specifications-ITS-XML` has no further branch to vendor. So
//! this codec is gated by construct → serialize → parse self-consistency
//! (`openehr-its` `tests/it/aom2_model_xml.rs`), not by an upstream corpus. That
//! ceiling is stated rather than implied.

mod impls;
pub mod types;

/// Parse a model-form AOM2 archetype XML document into a [`types::AuthoredArchetype`].
///
/// # Errors
/// Propagates canonical-XML parse errors, and refuses a root element other
/// than `<archetype>`.
pub fn from_xml(xml: &str) -> Result<types::AuthoredArchetype, crate::xml::runtime::XmlError> {
    crate::xml::runtime::from_xml_rooted(xml, "archetype")
}

/// Serialize a [`types::AuthoredArchetype`] back to AOM2 model-form archetype XML (root `<archetype>`,
/// `http://schemas.openehr.org/v1`).
///
/// # Errors
/// Propagates canonical-XML serialization errors.
pub fn to_xml(value: &types::AuthoredArchetype) -> Result<String, crate::xml::runtime::XmlError> {
    crate::xml::runtime::to_xml(value, "archetype", crate::xml::runtime::Namespace::V1)
}