fhirkit 0.1.0

FHIR R4 for Rust: typed models for every resource and datatype generated from the official specification, lossless JSON with path-precise validation, typed search queries, FHIRPath
Documentation
// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
//! The FHIR R4 `MessageDefinition` resource.

#![allow(
    unused_imports,
    clippy::large_enum_variant,
    clippy::too_many_lines,
    clippy::doc_markdown
)]

use crate::decode::{
    choice_key, required, required_list, resource_type, Choice, Decoder, FhirJson, Obj, ObjWriter,
};
use crate::json::Json;
use crate::primitive::{Decimal, Kind, Primitive};
use crate::r4::*;

/// Defines the characteristics of a message that can be shared between systems, including the type of event that initiates the message, the content to be transmitted and what response(s), if any, are permitted.
///
/// FHIR path: `MessageDefinition`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MessageDefinition {
    /// `id` (0..1): Logical id of this artifact
    pub id: Option<String>,
    /// `meta` (0..1): Metadata about the resource
    pub meta: Option<Meta>,
    /// `implicitRules` (0..1): A set of rules under which this content was created
    pub implicit_rules: Option<Primitive<String>>,
    /// `language` (0..1): Language of the resource content
    pub language: Option<Primitive<String>>,
    /// `text` (0..1): Text summary of the resource, for human interpretation
    pub text: Option<Narrative>,
    /// `contained` (0..*): Contained, inline Resources
    pub contained: Vec<Resource>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored
    pub modifier_extension: Vec<Extension>,
    /// `url` (0..1): Business Identifier for a given MessageDefinition
    pub url: Option<Primitive<String>>,
    /// `identifier` (0..*): Primary key for the message definition on a given server
    pub identifier: Vec<Identifier>,
    /// `version` (0..1): Business version of the message definition
    pub version: Option<Primitive<String>>,
    /// `name` (0..1): Name for this message definition (computer friendly)
    pub name: Option<Primitive<String>>,
    /// `title` (0..1): Name for this message definition (human friendly)
    pub title: Option<Primitive<String>>,
    /// `replaces` (0..*): Takes the place of
    pub replaces: Vec<Primitive<String>>,
    /// `status` (1..1): draft | active | retired | unknown
    pub status: Option<Primitive<String>>,
    /// `experimental` (0..1): For testing purposes, not real usage
    pub experimental: Option<Primitive<bool>>,
    /// `date` (1..1): Date last changed
    pub date: Option<Primitive<String>>,
    /// `publisher` (0..1): Name of the publisher (organization or individual)
    pub publisher: Option<Primitive<String>>,
    /// `contact` (0..*): Contact details for the publisher
    pub contact: Vec<ContactDetail>,
    /// `description` (0..1): Natural language description of the message definition
    pub description: Option<Primitive<String>>,
    /// `useContext` (0..*): The context that the content is intended to support
    pub use_context: Vec<UsageContext>,
    /// `jurisdiction` (0..*): Intended jurisdiction for message definition (if applicable)
    pub jurisdiction: Vec<CodeableConcept>,
    /// `purpose` (0..1): Why this message definition is defined
    pub purpose: Option<Primitive<String>>,
    /// `copyright` (0..1): Use and/or publishing restrictions
    pub copyright: Option<Primitive<String>>,
    /// `base` (0..1): Definition this one is based on
    pub base: Option<Primitive<String>>,
    /// `parent` (0..*): Protocol/workflow this is part of
    pub parent: Vec<Primitive<String>>,
    /// `event[x]` (1..1): Event code or link to the EventDefinition
    pub event: Option<MessageDefinitionEvent>,
    /// `category` (0..1): consequence | currency | notification
    pub category: Option<Primitive<String>>,
    /// `focus` (0..*): Resource(s) that are the subject of the event
    pub focus: Vec<MessageDefinitionFocus>,
    /// `responseRequired` (0..1): always | on-error | never | on-success
    pub response_required: Option<Primitive<String>>,
    /// `allowedResponse` (0..*): Responses to this message
    pub allowed_response: Vec<MessageDefinitionAllowedResponse>,
    /// `graph` (0..*): Canonical reference to a GraphDefinition
    pub graph: Vec<Primitive<String>>,
}

#[cfg(feature = "foundation")]
impl FhirJson for MessageDefinition {
    const TYPE_NAME: &'static str = "MessageDefinition";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MessageDefinition");
        let r = MessageDefinition {
            id: o.string(d, "id"),
            meta: o.one(d, "meta"),
            implicit_rules: o.prim(d, "implicitRules", Kind::Uri),
            language: o.prim(d, "language", Kind::Code),
            text: o.one(d, "text"),
            contained: o.list(d, "contained"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            url: o.prim(d, "url", Kind::Uri),
            identifier: o.list(d, "identifier"),
            version: o.prim(d, "version", Kind::String),
            name: o.prim(d, "name", Kind::String),
            title: o.prim(d, "title", Kind::String),
            replaces: o.prim_list(d, "replaces", Kind::Canonical),
            status: o.prim(d, "status", Kind::Code),
            experimental: o.prim(d, "experimental", Kind::Boolean),
            date: o.prim(d, "date", Kind::DateTime),
            publisher: o.prim(d, "publisher", Kind::String),
            contact: o.list(d, "contact"),
            description: o.prim(d, "description", Kind::Markdown),
            use_context: o.list(d, "useContext"),
            jurisdiction: o.list(d, "jurisdiction"),
            purpose: o.prim(d, "purpose", Kind::Markdown),
            copyright: o.prim(d, "copyright", Kind::Markdown),
            base: o.prim(d, "base", Kind::Canonical),
            parent: o.prim_list(d, "parent", Kind::Canonical),
            event: o.choice(d, "event"),
            category: o.prim(d, "category", Kind::Code),
            focus: o.list(d, "focus"),
            response_required: o.prim(d, "responseRequired", Kind::Code),
            allowed_response: o.list(d, "allowedResponse"),
            graph: o.prim_list(d, "graph", Kind::Canonical),
        };
        required(d, "status", &r.status);
        required(d, "date", &r.date);
        required(d, "event[x]", &r.event);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("MessageDefinition".into()));
        w.string("id", &self.id);
        w.one("meta", &self.meta);
        w.prim("implicitRules", &self.implicit_rules);
        w.prim("language", &self.language);
        w.one("text", &self.text);
        w.list("contained", &self.contained);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("url", &self.url);
        w.list("identifier", &self.identifier);
        w.prim("version", &self.version);
        w.prim("name", &self.name);
        w.prim("title", &self.title);
        w.prim_list("replaces", &self.replaces);
        w.prim("status", &self.status);
        w.prim("experimental", &self.experimental);
        w.prim("date", &self.date);
        w.prim("publisher", &self.publisher);
        w.list("contact", &self.contact);
        w.prim("description", &self.description);
        w.list("useContext", &self.use_context);
        w.list("jurisdiction", &self.jurisdiction);
        w.prim("purpose", &self.purpose);
        w.prim("copyright", &self.copyright);
        w.prim("base", &self.base);
        w.prim_list("parent", &self.parent);
        w.choice("event", &self.event);
        w.prim("category", &self.category);
        w.list("focus", &self.focus);
        w.prim("responseRequired", &self.response_required);
        w.list("allowedResponse", &self.allowed_response);
        w.prim_list("graph", &self.graph);
        w.finish()
    }
}

/// Resource(s) that are the subject of the event
///
/// FHIR path: `MessageDefinition.focus`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MessageDefinitionFocus {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `code` (1..1): Type of resource
    pub code: Option<Primitive<String>>,
    /// `profile` (0..1): Profile that must be adhered to by focus
    pub profile: Option<Primitive<String>>,
    /// `min` (1..1): Minimum number of focuses of this type
    pub min: Option<Primitive<i32>>,
    /// `max` (0..1): Maximum number of focuses of this type
    pub max: Option<Primitive<String>>,
}

#[cfg(feature = "foundation")]
impl FhirJson for MessageDefinitionFocus {
    const TYPE_NAME: &'static str = "MessageDefinitionFocus";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MessageDefinitionFocus {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            code: o.prim(d, "code", Kind::Code),
            profile: o.prim(d, "profile", Kind::Canonical),
            min: o.prim(d, "min", Kind::UnsignedInt),
            max: o.prim(d, "max", Kind::String),
        };
        required(d, "code", &r.code);
        required(d, "min", &r.min);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("code", &self.code);
        w.prim("profile", &self.profile);
        w.prim("min", &self.min);
        w.prim("max", &self.max);
        w.finish()
    }
}

/// Responses to this message
///
/// FHIR path: `MessageDefinition.allowedResponse`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MessageDefinitionAllowedResponse {
    /// `id` (0..1): Unique id for inter-element referencing
    pub id: Option<String>,
    /// `extension` (0..*): Additional content defined by implementations
    pub extension: Vec<Extension>,
    /// `modifierExtension` (0..*): Extensions that cannot be ignored even if unrecognized
    pub modifier_extension: Vec<Extension>,
    /// `message` (1..1): Reference to allowed message definition response
    pub message: Option<Primitive<String>>,
    /// `situation` (0..1): When should this response be used
    pub situation: Option<Primitive<String>>,
}

#[cfg(feature = "foundation")]
impl FhirJson for MessageDefinitionAllowedResponse {
    const TYPE_NAME: &'static str = "MessageDefinitionAllowedResponse";

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MessageDefinitionAllowedResponse {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            message: o.prim(d, "message", Kind::Canonical),
            situation: o.prim(d, "situation", Kind::Markdown),
        };
        required(d, "message", &r.message);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.string("id", &self.id);
        w.list("extension", &self.extension);
        w.list("modifierExtension", &self.modifier_extension);
        w.prim("message", &self.message);
        w.prim("situation", &self.situation);
        w.finish()
    }
}

/// The types `MessageDefinition.event[x]` allows.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq)]
pub enum MessageDefinitionEvent {
    /// `Coding`
    Coding(Coding),
    /// `uri`
    Uri(Primitive<String>),
}

#[cfg(feature = "foundation")]
impl Choice for MessageDefinitionEvent {
    const TYPES: &'static [&'static str] = &["Coding", "uri"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "Coding" => o.one(d, key).map(Self::Coding),
            "uri" => o.prim(d, key, Kind::Uri).map(Self::Uri),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Coding(v) => w.value(&choice_key(base, "Coding"), v),
            Self::Uri(v) => w.prim_value(&choice_key(base, "uri"), v),
        }
    }
}