fhir 0.1.0

Fast Healthcare Interoperability Resources (FHIR) API is a standardized, RESTful interface for exchanging electronic health records.
Documentation
//! Address
//!
//! URL: http://hl7.org/fhir/StructureDefinition/Address
//!
//! Version: 5.0.0
//!
//! Address Type: An address expressed using postal conventions (as opposed to GPS or other location definition formats).  This data type may be used to convey addresses for use in delivering mail as well as for visiting locations which might not be valid for mail delivery.  There are a variety of postal address formats defined around the world. The ISO21090-codedString may be used to provide a coded representation of the contents of strings in an Address.
//!
//! FHIR: <https://build.fhir.org/>
//!
//! UML: <https://build.fhir.org/uml.html>
//!
//! This module defines the `Address` complex data type used to represent postal addresses.

// Allow unused crate::r5::types as types;
#![allow(unused_imports)]

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

/// An address expressed using postal conventions (as opposed to GPS or other
/// location definition formats). This data type may be used to convey addresses
/// for use in delivering mail as well as for visiting locations which might not
/// be valid for mail delivery. There are a variety of postal address formats
/// defined around the world, so the individual line elements are flexible.
///
/// # Examples
///
/// ```
/// use fhir::r5::types::address::Address;
///
/// let value = Address::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: Address = ::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")]
pub struct Address {
    /// The purpose of this address (home, work, temp, old, billing).
    #[serde(rename = "use")]
    pub use1: Option<types::Code>, // « AddressUse! »

    /// Distinguishes between a postal address (physical/mailing) and a physical
    /// address (visiting location).
    #[serde(rename = "type")]
    pub r#type: Option<types::Code>, // « AddressType! »

    /// A full text representation of the address, useful when it is not
    /// possible or desired to break the address into its component parts.
    pub text: Option<types::String>,

    /// The street address lines, in the order in which they appear on labels
    /// (e.g. street name, number, direction, or post office box).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub line: Vec<types::String>,

    /// The name of the city, town, suburb, village, or other community or
    /// delivery center.
    pub city: Option<types::String>,

    /// The name of the administrative area, such as a county, that is a
    /// subdivision of the state and is not usually included in postal addresses.
    pub district: Option<types::String>,

    /// The sub-unit of the country, such as a state, province, or county.
    pub state: Option<types::String>,

    /// A postal code designating the region, used for mail sorting.
    pub postal_code: Option<types::String>,

    /// The name of the country, using ISO 3166 codes or the full name where
    /// there is no known code.
    pub country: Option<types::String>,

    /// The time period during which this address was, or is, in use.
    pub period: Option<types::Period>,
}

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

    #[test]
    fn test_default() {
        let actual = T::default();
        let expect = T {
            use1: None,
            r#type: None,
            text: None,
            line: vec![],
            city: None,
            district: None,
            state: None,
            postal_code: None,
            country: None,
            period: None,
        };
        assert_eq!(actual, expect);
    }

    mod serde_json {
        use super::*;
        use ::serde_json::json;

        #[test]
        fn test_serde_json_from_value() {
            let json = json!(
                {
                    "line": []
                }
            );
            let actual: T = ::serde_json::from_value(json).expect("from_value");
            let expect: T = T::default();
            assert_eq!(actual, expect);
        }

        #[test]
        fn test_serde_json_to_value() {
            let actual: ::serde_json::Value =
                ::serde_json::to_value(T::default()).expect("to_value");
            let expect: ::serde_json::Value = json!({});
            assert_eq!(actual, expect);
        }
    }
}