fhir 1.2.0

Fast Healthcare Interoperability Resources (FHIR) data model for Rust: the complete FHIR R5, R4, and R3 resources, datatypes, and code systems as serde-serializable types, plus a spec-driven code generator.
//! Bundle
//!
//! URL: http://hl7.org/fhir/StructureDefinition/Bundle
//!
//! Version: 4.0.1
//!
//! Contains a collection of resources
//!
//! FHIR R4: <https://hl7.org/fhir/R4/>

// The `types` import is unused by a handful of types that have only primitive fields.
#![allow(unused_imports)]

use crate::r4::types;
use ::serde::{Deserialize, Serialize};
use fhir_derive_macros::{Builder, Validate};

/// A container for a collection of resources.
///
/// # Examples
///
/// ```
/// use fhir::r4::resources::bundle::Bundle;
///
/// let value = Bundle::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: Bundle = ::serde_json::from_value(json).unwrap();
/// assert_eq!(value, back);
/// ```
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Validate, Builder)]
#[serde(rename_all = "camelCase")]
#[fhir_version("r4")]
pub struct Bundle {
    /// Logical id of this artifact
    pub id: Option<types::String>,

    /// Metadata about the resource
    pub meta: Option<types::Meta>,

    /// A set of rules under which this content was created
    pub implicit_rules: Option<types::Uri>,
    /// Primitive extension sibling for [`implicit_rules`](Self::implicit_rules) (FHIR `_implicitRules`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_implicitRules")]
    pub implicit_rules_ext: Option<types::Element>,

    /// Language of the resource content
    pub language: Option<types::Code>,
    /// Primitive extension sibling for [`language`](Self::language) (FHIR `_language`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_language")]
    pub language_ext: Option<types::Element>,

    /// Persistent identifier for the bundle
    pub identifier: Option<types::Identifier>,

    /// document | message | transaction | transaction-response | batch |
    /// batch-response | history | searchset | collection
    pub r#type: crate::coded::Coded<crate::r4::codes::BundleType>,
    /// Primitive extension sibling for [`r#type`](Self::r#type) (FHIR `_type`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_type")]
    pub type_ext: Option<types::Element>,

    /// When the bundle was assembled
    pub timestamp: Option<types::Instant>,
    /// Primitive extension sibling for [`timestamp`](Self::timestamp) (FHIR `_timestamp`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_timestamp")]
    pub timestamp_ext: Option<types::Element>,

    /// If search, the total number of matches
    pub total: Option<types::UnsignedInt>,
    /// Primitive extension sibling for [`total`](Self::total) (FHIR `_total`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_total")]
    pub total_ext: Option<types::Element>,

    /// Links related to this Bundle
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub link: Vec<BundleLink>,

    /// Entry in the bundle - will have a resource or information
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub entry: Vec<BundleEntry>,

    /// Digital Signature
    pub signature: Option<types::Signature>,
}

/// An entry in a bundle resource - will either contain a resource or
/// information about a resource (transactions and history only).
///
/// # Examples
///
/// ```
/// use fhir::r4::resources::bundle::BundleEntry;
///
/// let value = BundleEntry::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: BundleEntry = ::serde_json::from_value(json).unwrap();
/// assert_eq!(value, back);
/// ```
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Validate)]
#[serde(rename_all = "camelCase")]
#[fhir_version("r4")]
pub struct BundleEntry {
    /// Unique id for inter-element referencing
    pub id: Option<types::String>,

    /// Additional content defined by implementations
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub extension: Vec<types::Extension>,

    /// Extensions that cannot be ignored even if unrecognized
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub modifier_extension: Vec<types::Extension>,

    /// Links related to this entry
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub link: Vec<BundleLink>,

    /// URI for resource (Absolute URL server address or URI for UUID/OID)
    pub full_url: Option<types::Uri>,
    /// Primitive extension sibling for [`full_url`](Self::full_url) (FHIR `_fullUrl`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_fullUrl")]
    pub full_url_ext: Option<types::Element>,

    /// A resource in the bundle
    pub resource: Option<::serde_json::Value>,

    /// Search related information
    pub search: Option<BundleEntrySearch>,

    /// Additional execution information (transaction/batch/history)
    pub request: Option<BundleEntryRequest>,

    /// Results of execution (transaction/batch/history)
    pub response: Option<BundleEntryResponse>,
}

/// Additional information about how this entry should be processed as part of
/// a transaction or batch. For history, it shows how the entry was processed
/// to create the version contained in the entry.
///
/// # Examples
///
/// ```
/// use fhir::r4::resources::bundle::BundleEntryRequest;
///
/// let value = BundleEntryRequest::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: BundleEntryRequest = ::serde_json::from_value(json).unwrap();
/// assert_eq!(value, back);
/// ```
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Validate)]
#[serde(rename_all = "camelCase")]
#[fhir_version("r4")]
pub struct BundleEntryRequest {
    /// Unique id for inter-element referencing
    pub id: Option<types::String>,

    /// Additional content defined by implementations
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub extension: Vec<types::Extension>,

    /// Extensions that cannot be ignored even if unrecognized
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub modifier_extension: Vec<types::Extension>,

    /// GET | HEAD | POST | PUT | DELETE | PATCH
    pub method: crate::coded::Coded<crate::r4::codes::HttpVerb>,
    /// Primitive extension sibling for [`method`](Self::method) (FHIR `_method`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_method")]
    pub method_ext: Option<types::Element>,

    /// URL for HTTP equivalent of this entry
    pub url: types::Uri,
    /// Primitive extension sibling for [`url`](Self::url) (FHIR `_url`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_url")]
    pub url_ext: Option<types::Element>,

    /// For managing cache currency
    pub if_none_match: Option<types::String>,
    /// Primitive extension sibling for [`if_none_match`](Self::if_none_match) (FHIR `_ifNoneMatch`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_ifNoneMatch")]
    pub if_none_match_ext: Option<types::Element>,

    /// For managing cache currency
    pub if_modified_since: Option<types::Instant>,
    /// Primitive extension sibling for [`if_modified_since`](Self::if_modified_since) (FHIR `_ifModifiedSince`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_ifModifiedSince")]
    pub if_modified_since_ext: Option<types::Element>,

    /// For managing update contention
    pub if_match: Option<types::String>,
    /// Primitive extension sibling for [`if_match`](Self::if_match) (FHIR `_ifMatch`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_ifMatch")]
    pub if_match_ext: Option<types::Element>,

    /// For conditional creates
    pub if_none_exist: Option<types::String>,
    /// Primitive extension sibling for [`if_none_exist`](Self::if_none_exist) (FHIR `_ifNoneExist`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_ifNoneExist")]
    pub if_none_exist_ext: Option<types::Element>,
}

/// Indicates the results of processing the corresponding 'request' entry in
/// the batch or transaction being responded to or what the results of an
/// operation where when returning history.
///
/// # Examples
///
/// ```
/// use fhir::r4::resources::bundle::BundleEntryResponse;
///
/// let value = BundleEntryResponse::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: BundleEntryResponse = ::serde_json::from_value(json).unwrap();
/// assert_eq!(value, back);
/// ```
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Validate)]
#[serde(rename_all = "camelCase")]
#[fhir_version("r4")]
pub struct BundleEntryResponse {
    /// Unique id for inter-element referencing
    pub id: Option<types::String>,

    /// Additional content defined by implementations
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub extension: Vec<types::Extension>,

    /// Extensions that cannot be ignored even if unrecognized
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub modifier_extension: Vec<types::Extension>,

    /// Status response code (text optional)
    pub status: types::String,
    /// Primitive extension sibling for [`status`](Self::status) (FHIR `_status`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_status")]
    pub status_ext: Option<types::Element>,

    /// The location (if the operation returns a location)
    pub location: Option<types::Uri>,
    /// Primitive extension sibling for [`location`](Self::location) (FHIR `_location`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_location")]
    pub location_ext: Option<types::Element>,

    /// The Etag for the resource (if relevant)
    pub etag: Option<types::String>,
    /// Primitive extension sibling for [`etag`](Self::etag) (FHIR `_etag`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_etag")]
    pub etag_ext: Option<types::Element>,

    /// Server's date time modified
    pub last_modified: Option<types::Instant>,
    /// Primitive extension sibling for [`last_modified`](Self::last_modified) (FHIR `_lastModified`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_lastModified")]
    pub last_modified_ext: Option<types::Element>,

    /// OperationOutcome with hints and warnings (for batch/transaction)
    pub outcome: Option<::serde_json::Value>,
}

/// Information about the search process that lead to the creation of this
/// entry.
///
/// # Examples
///
/// ```
/// use fhir::r4::resources::bundle::BundleEntrySearch;
///
/// let value = BundleEntrySearch::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: BundleEntrySearch = ::serde_json::from_value(json).unwrap();
/// assert_eq!(value, back);
/// ```
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Validate)]
#[serde(rename_all = "camelCase")]
#[fhir_version("r4")]
pub struct BundleEntrySearch {
    /// Unique id for inter-element referencing
    pub id: Option<types::String>,

    /// Additional content defined by implementations
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub extension: Vec<types::Extension>,

    /// Extensions that cannot be ignored even if unrecognized
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub modifier_extension: Vec<types::Extension>,

    /// match | include | outcome - why this is in the result set
    pub mode: Option<crate::coded::Coded<crate::r4::codes::SearchEntryMode>>,
    /// Primitive extension sibling for [`mode`](Self::mode) (FHIR `_mode`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_mode")]
    pub mode_ext: Option<types::Element>,

    /// Search ranking (between 0 and 1)
    pub score: Option<types::Decimal>,
    /// Primitive extension sibling for [`score`](Self::score) (FHIR `_score`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_score")]
    pub score_ext: Option<types::Element>,
}

/// A series of links that provide context to this bundle.
///
/// # Examples
///
/// ```
/// use fhir::r4::resources::bundle::BundleLink;
///
/// let value = BundleLink::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: BundleLink = ::serde_json::from_value(json).unwrap();
/// assert_eq!(value, back);
/// ```
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Validate)]
#[serde(rename_all = "camelCase")]
#[fhir_version("r4")]
pub struct BundleLink {
    /// Unique id for inter-element referencing
    pub id: Option<types::String>,

    /// Additional content defined by implementations
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub extension: Vec<types::Extension>,

    /// Extensions that cannot be ignored even if unrecognized
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub modifier_extension: Vec<types::Extension>,

    /// See
    /// http://www.iana.org/assignments/link-relations/link-relations.xhtml#link-relations-1
    pub relation: types::String,
    /// Primitive extension sibling for [`relation`](Self::relation) (FHIR `_relation`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_relation")]
    pub relation_ext: Option<types::Element>,

    /// Reference details for the link
    pub url: types::Uri,
    /// Primitive extension sibling for [`url`](Self::url) (FHIR `_url`):
    /// carries `id` and/or `extension` for the primitive value.
    #[serde(rename = "_url")]
    pub url_ext: Option<types::Element>,
}

#[cfg(test)]
mod tests {
    use super::*;
    type T = Bundle;

    #[test]
    fn test_default() {
        let _ = T::default();
    }

    #[test]
    fn test_serde_round_trip() {
        let value = T::default();
        let json = ::serde_json::to_value(&value).expect("to_value");
        let back: T = ::serde_json::from_value(json).expect("from_value");
        assert_eq!(value, back);
    }
}