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 `Patient` 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 other administrative information about an individual or animal receiving care or other health-related services.
///
/// FHIR path: `Patient`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Patient {
    /// `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..*): An identifier for this patient
    pub identifier: Vec<Identifier>,
    /// `active` (0..1): Whether this patient's record is in active use
    pub active: Option<Primitive<bool>>,
    /// `name` (0..*): A name associated with the patient
    pub name: Vec<HumanName>,
    /// `telecom` (0..*): A contact detail for the individual
    pub telecom: Vec<ContactPoint>,
    /// `gender` (0..1): male | female | other | unknown
    pub gender: Option<Primitive<String>>,
    /// `birthDate` (0..1): The date of birth for the individual
    pub birth_date: Option<Primitive<String>>,
    /// `deceased[x]` (0..1): Indicates if the individual is deceased or not
    pub deceased: Option<PatientDeceased>,
    /// `address` (0..*): An address for the individual
    pub address: Vec<Address>,
    /// `maritalStatus` (0..1): Marital (civil) status of a patient
    pub marital_status: Option<CodeableConcept>,
    /// `multipleBirth[x]` (0..1): Whether patient is part of a multiple birth
    pub multiple_birth: Option<PatientMultipleBirth>,
    /// `photo` (0..*): Image of the patient
    pub photo: Vec<Attachment>,
    /// `contact` (0..*): A contact party (e.g. guardian, partner, friend) for the patient
    pub contact: Vec<PatientContact>,
    /// `communication` (0..*): A language which may be used to communicate with the patient about his or her health
    pub communication: Vec<PatientCommunication>,
    /// `generalPractitioner` (0..*): Patient's nominated primary care provider
    pub general_practitioner: Vec<Reference>,
    /// `managingOrganization` (0..1): Organization that is the custodian of the patient record
    pub managing_organization: Option<Reference>,
    /// `link` (0..*): Link to another patient resource that concerns the same actual person
    pub link: Vec<PatientLink>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Patient");
        let r = Patient {
            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"),
            active: o.prim(d, "active", Kind::Boolean),
            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),
            deceased: o.choice(d, "deceased"),
            address: o.list(d, "address"),
            marital_status: o.one(d, "maritalStatus"),
            multiple_birth: o.choice(d, "multipleBirth"),
            photo: o.list(d, "photo"),
            contact: o.list(d, "contact"),
            communication: o.list(d, "communication"),
            general_practitioner: o.list(d, "generalPractitioner"),
            managing_organization: o.one(d, "managingOrganization"),
            link: o.list(d, "link"),
        };
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Patient".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.prim("active", &self.active);
        w.list("name", &self.name);
        w.list("telecom", &self.telecom);
        w.prim("gender", &self.gender);
        w.prim("birthDate", &self.birth_date);
        w.choice("deceased", &self.deceased);
        w.list("address", &self.address);
        w.one("maritalStatus", &self.marital_status);
        w.choice("multipleBirth", &self.multiple_birth);
        w.list("photo", &self.photo);
        w.list("contact", &self.contact);
        w.list("communication", &self.communication);
        w.list("generalPractitioner", &self.general_practitioner);
        w.one("managingOrganization", &self.managing_organization);
        w.list("link", &self.link);
        w.finish()
    }
}

/// A contact party (e.g. guardian, partner, friend) for the patient
///
/// FHIR path: `Patient.contact`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct PatientContact {
    /// `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>,
    /// `relationship` (0..*): The kind of relationship
    pub relationship: Vec<CodeableConcept>,
    /// `name` (0..1): A name associated with the contact person
    pub name: Option<HumanName>,
    /// `telecom` (0..*): A contact detail for the person
    pub telecom: Vec<ContactPoint>,
    /// `address` (0..1): Address for the contact person
    pub address: Option<Address>,
    /// `gender` (0..1): male | female | other | unknown
    pub gender: Option<Primitive<String>>,
    /// `organization` (0..1): Organization that is associated with the contact
    pub organization: Option<Reference>,
    /// `period` (0..1): The period during which this contact person or organization is valid to be contacted relating to this patient
    pub period: Option<Period>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = PatientContact {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            relationship: o.list(d, "relationship"),
            name: o.one(d, "name"),
            telecom: o.list(d, "telecom"),
            address: o.one(d, "address"),
            gender: o.prim(d, "gender", Kind::Code),
            organization: o.one(d, "organization"),
            period: o.one(d, "period"),
        };
        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.list("relationship", &self.relationship);
        w.one("name", &self.name);
        w.list("telecom", &self.telecom);
        w.one("address", &self.address);
        w.prim("gender", &self.gender);
        w.one("organization", &self.organization);
        w.one("period", &self.period);
        w.finish()
    }
}

/// A language which may be used to communicate with the patient about his or her health
///
/// FHIR path: `Patient.communication`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct PatientCommunication {
    /// `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>,
    /// `language` (1..1): The language which can be used to communicate with the patient about his or her health
    pub language: Option<CodeableConcept>,
    /// `preferred` (0..1): Language preference indicator
    pub preferred: Option<Primitive<bool>>,
}

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

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

/// Link to another patient resource that concerns the same actual person
///
/// FHIR path: `Patient.link`.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct PatientLink {
    /// `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>,
    /// `other` (1..1): The other patient or related person resource that the link refers to
    pub other: Option<Reference>,
    /// `type` (1..1): replaced-by | replaces | refer | seealso
    pub type_: Option<Primitive<String>>,
}

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

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

/// The types `Patient.deceased[x]` allows.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq)]
pub enum PatientDeceased {
    /// `boolean`
    Boolean(Primitive<bool>),
    /// `dateTime`
    DateTime(Primitive<String>),
}

#[cfg(feature = "base")]
impl Choice for PatientDeceased {
    const TYPES: &'static [&'static str] = &["boolean", "dateTime"];

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Boolean(v) => w.prim_value(&choice_key(base, "boolean"), v),
            Self::DateTime(v) => w.prim_value(&choice_key(base, "dateTime"), v),
        }
    }
}

/// The types `Patient.multipleBirth[x]` allows.
#[cfg(feature = "base")]
#[derive(Debug, Clone, PartialEq)]
pub enum PatientMultipleBirth {
    /// `boolean`
    Boolean(Primitive<bool>),
    /// `integer`
    Integer(Primitive<i32>),
}

#[cfg(feature = "base")]
impl Choice for PatientMultipleBirth {
    const TYPES: &'static [&'static str] = &["boolean", "integer"];

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

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Boolean(v) => w.prim_value(&choice_key(base, "boolean"), v),
            Self::Integer(v) => w.prim_value(&choice_key(base, "integer"), v),
        }
    }
}