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 `MessageHeader` 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::*;

/// The header for a message exchange that is either requesting or responding to an action. The reference(s) that are the subject of the action as well as other information related to the action are typically transmitted in a bundle in which the MessageHeader resource instance is the first resource in the bundle.
///
/// FHIR path: `MessageHeader`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MessageHeader {
    /// `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>,
    /// `event[x]` (1..1): Code for the event this message represents or link to event definition
    pub event: Option<MessageHeaderEvent>,
    /// `destination` (0..*): Message destination application(s)
    pub destination: Vec<MessageHeaderDestination>,
    /// `sender` (0..1): Real world sender of the message
    pub sender: Option<Reference>,
    /// `enterer` (0..1): The source of the data entry
    pub enterer: Option<Reference>,
    /// `author` (0..1): The source of the decision
    pub author: Option<Reference>,
    /// `source` (1..1): Message source application
    pub source: Option<MessageHeaderSource>,
    /// `responsible` (0..1): Final responsibility for event
    pub responsible: Option<Reference>,
    /// `reason` (0..1): Cause of event
    pub reason: Option<CodeableConcept>,
    /// `response` (0..1): If this is a reply to prior message
    pub response: Option<MessageHeaderResponse>,
    /// `focus` (0..*): The actual content of the message
    pub focus: Vec<Reference>,
    /// `definition` (0..1): Link to the definition for this message
    pub definition: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "MessageHeader");
        let r = MessageHeader {
            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"),
            event: o.choice(d, "event"),
            destination: o.list(d, "destination"),
            sender: o.one(d, "sender"),
            enterer: o.one(d, "enterer"),
            author: o.one(d, "author"),
            source: o.one(d, "source"),
            responsible: o.one(d, "responsible"),
            reason: o.one(d, "reason"),
            response: o.one(d, "response"),
            focus: o.list(d, "focus"),
            definition: o.prim(d, "definition", Kind::Canonical),
        };
        required(d, "event[x]", &r.event);
        required(d, "source", &r.source);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("MessageHeader".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.choice("event", &self.event);
        w.list("destination", &self.destination);
        w.one("sender", &self.sender);
        w.one("enterer", &self.enterer);
        w.one("author", &self.author);
        w.one("source", &self.source);
        w.one("responsible", &self.responsible);
        w.one("reason", &self.reason);
        w.one("response", &self.response);
        w.list("focus", &self.focus);
        w.prim("definition", &self.definition);
        w.finish()
    }
}

/// Message destination application(s)
///
/// FHIR path: `MessageHeader.destination`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MessageHeaderDestination {
    /// `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>,
    /// `name` (0..1): Name of system
    pub name: Option<Primitive<String>>,
    /// `target` (0..1): Particular delivery destination within the destination
    pub target: Option<Reference>,
    /// `endpoint` (1..1): Actual destination address or id
    pub endpoint: Option<Primitive<String>>,
    /// `receiver` (0..1): Intended "real-world" recipient for the data
    pub receiver: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MessageHeaderDestination {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            name: o.prim(d, "name", Kind::String),
            target: o.one(d, "target"),
            endpoint: o.prim(d, "endpoint", Kind::Url),
            receiver: o.one(d, "receiver"),
        };
        required(d, "endpoint", &r.endpoint);
        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("name", &self.name);
        w.one("target", &self.target);
        w.prim("endpoint", &self.endpoint);
        w.one("receiver", &self.receiver);
        w.finish()
    }
}

/// Message source application
///
/// FHIR path: `MessageHeader.source`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MessageHeaderSource {
    /// `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>,
    /// `name` (0..1): Name of system
    pub name: Option<Primitive<String>>,
    /// `software` (0..1): Name of software running the system
    pub software: Option<Primitive<String>>,
    /// `version` (0..1): Version of software running
    pub version: Option<Primitive<String>>,
    /// `contact` (0..1): Human contact for problems
    pub contact: Option<ContactPoint>,
    /// `endpoint` (1..1): Actual message source address or id
    pub endpoint: Option<Primitive<String>>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MessageHeaderSource {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            name: o.prim(d, "name", Kind::String),
            software: o.prim(d, "software", Kind::String),
            version: o.prim(d, "version", Kind::String),
            contact: o.one(d, "contact"),
            endpoint: o.prim(d, "endpoint", Kind::Url),
        };
        required(d, "endpoint", &r.endpoint);
        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("name", &self.name);
        w.prim("software", &self.software);
        w.prim("version", &self.version);
        w.one("contact", &self.contact);
        w.prim("endpoint", &self.endpoint);
        w.finish()
    }
}

/// If this is a reply to prior message
///
/// FHIR path: `MessageHeader.response`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct MessageHeaderResponse {
    /// `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>,
    /// `identifier` (1..1): Id of original message
    pub identifier: Option<Primitive<String>>,
    /// `code` (1..1): ok | transient-error | fatal-error
    pub code: Option<Primitive<String>>,
    /// `details` (0..1): Specific list of hints/warnings/errors
    pub details: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = MessageHeaderResponse {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            identifier: o.prim(d, "identifier", Kind::Id),
            code: o.prim(d, "code", Kind::Code),
            details: o.one(d, "details"),
        };
        required(d, "identifier", &r.identifier);
        required(d, "code", &r.code);
        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("identifier", &self.identifier);
        w.prim("code", &self.code);
        w.one("details", &self.details);
        w.finish()
    }
}

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

#[cfg(feature = "foundation")]
impl Choice for MessageHeaderEvent {
    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),
        }
    }
}