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

/// Demographics and administrative information about a person independent of a specific health-related context.
///
/// FHIR path: `Person`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Person {
    /// `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>,
    /// `identifier` (0..*): A human identifier for this person
    pub identifier: Vec<Identifier>,
    /// `name` (0..*): A name associated with the person
    pub name: Vec<HumanName>,
    /// `telecom` (0..*): A contact detail for the person
    pub telecom: Vec<ContactPoint>,
    /// `gender` (0..1): male | female | other | unknown
    pub gender: Option<Primitive<String>>,
    /// `birthDate` (0..1): The date on which the person was born
    pub birth_date: Option<Primitive<String>>,
    /// `address` (0..*): One or more addresses for the person
    pub address: Vec<Address>,
    /// `photo` (0..1): Image of the person
    pub photo: Option<Attachment>,
    /// `managingOrganization` (0..1): The organization that is the custodian of the person record
    pub managing_organization: Option<Reference>,
    /// `active` (0..1): This person's record is in active use
    pub active: Option<Primitive<bool>>,
    /// `link` (0..*): Link to a resource that concerns the same actual person
    pub link: Vec<PersonLink>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Person");
        let r = Person {
            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"),
            identifier: o.list(d, "identifier"),
            name: o.list(d, "name"),
            telecom: o.list(d, "telecom"),
            gender: o.prim(d, "gender", Kind::Code),
            birth_date: o.prim(d, "birthDate", Kind::Date),
            address: o.list(d, "address"),
            photo: o.one(d, "photo"),
            managing_organization: o.one(d, "managingOrganization"),
            active: o.prim(d, "active", Kind::Boolean),
            link: o.list(d, "link"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Person".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.list("identifier", &self.identifier);
        w.list("name", &self.name);
        w.list("telecom", &self.telecom);
        w.prim("gender", &self.gender);
        w.prim("birthDate", &self.birth_date);
        w.list("address", &self.address);
        w.one("photo", &self.photo);
        w.one("managingOrganization", &self.managing_organization);
        w.prim("active", &self.active);
        w.list("link", &self.link);
        w.finish()
    }
}

/// Link to a resource that concerns the same actual person
///
/// FHIR path: `Person.link`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct PersonLink {
    /// `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>,
    /// `target` (1..1): The resource to which this actual person is associated
    pub target: Option<Reference>,
    /// `assurance` (0..1): level1 | level2 | level3 | level4
    pub assurance: Option<Primitive<String>>,
}

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

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