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

/// A financial tool for tracking value accrued for a particular purpose. In the healthcare field, used to track charges for a patient, cost centers, etc.
///
/// FHIR path: `Account`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Account {
    /// `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..*): Account number
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): active | inactive | entered-in-error | on-hold | unknown
    pub status: Option<Primitive<String>>,
    /// `type` (0..1): E.g. patient, expense, depreciation
    pub type_: Option<CodeableConcept>,
    /// `name` (0..1): Human-readable label
    pub name: Option<Primitive<String>>,
    /// `subject` (0..*): The entity that caused the expenses
    pub subject: Vec<Reference>,
    /// `servicePeriod` (0..1): Transaction window
    pub service_period: Option<Period>,
    /// `coverage` (0..*): The party(s) that are responsible for covering the payment of this account, and what order should they be applied to the account
    pub coverage: Vec<AccountCoverage>,
    /// `owner` (0..1): Entity managing the Account
    pub owner: Option<Reference>,
    /// `description` (0..1): Explanation of purpose/use
    pub description: Option<Primitive<String>>,
    /// `guarantor` (0..*): The parties ultimately responsible for balancing the Account
    pub guarantor: Vec<AccountGuarantor>,
    /// `partOf` (0..1): Reference to a parent Account
    pub part_of: Option<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Account");
        let r = Account {
            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"),
            status: o.prim(d, "status", Kind::Code),
            type_: o.one(d, "type"),
            name: o.prim(d, "name", Kind::String),
            subject: o.list(d, "subject"),
            service_period: o.one(d, "servicePeriod"),
            coverage: o.list(d, "coverage"),
            owner: o.one(d, "owner"),
            description: o.prim(d, "description", Kind::String),
            guarantor: o.list(d, "guarantor"),
            part_of: o.one(d, "partOf"),
        };
        required(d, "status", &r.status);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Account".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("status", &self.status);
        w.one("type", &self.type_);
        w.prim("name", &self.name);
        w.list("subject", &self.subject);
        w.one("servicePeriod", &self.service_period);
        w.list("coverage", &self.coverage);
        w.one("owner", &self.owner);
        w.prim("description", &self.description);
        w.list("guarantor", &self.guarantor);
        w.one("partOf", &self.part_of);
        w.finish()
    }
}

/// The party(s) that are responsible for covering the payment of this account, and what order should they be applied to the account
///
/// FHIR path: `Account.coverage`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AccountCoverage {
    /// `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>,
    /// `coverage` (1..1): The party(s), such as insurances, that may contribute to the payment of this account
    pub coverage: Option<Reference>,
    /// `priority` (0..1): The priority of the coverage in the context of this account
    pub priority: Option<Primitive<i32>>,
}

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

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

/// The parties ultimately responsible for balancing the Account
///
/// FHIR path: `Account.guarantor`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AccountGuarantor {
    /// `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>,
    /// `party` (1..1): Responsible entity
    pub party: Option<Reference>,
    /// `onHold` (0..1): Credit or other hold applied
    pub on_hold: Option<Primitive<bool>>,
    /// `period` (0..1): Guarantee account during
    pub period: Option<Period>,
}

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

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