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

/// Invoice containing collected ChargeItems from an Account with calculated individual and total price for Billing purpose.
///
/// FHIR path: `Invoice`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Invoice {
    /// `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..*): Business Identifier for item
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): draft | issued | balanced | cancelled | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `cancelledReason` (0..1): Reason for cancellation of this Invoice
    pub cancelled_reason: Option<Primitive<String>>,
    /// `type` (0..1): Type of Invoice
    pub type_: Option<CodeableConcept>,
    /// `subject` (0..1): Recipient(s) of goods and services
    pub subject: Option<Reference>,
    /// `recipient` (0..1): Recipient of this invoice
    pub recipient: Option<Reference>,
    /// `date` (0..1): Invoice date / posting date
    pub date: Option<Primitive<String>>,
    /// `participant` (0..*): Participant in creation of this Invoice
    pub participant: Vec<InvoiceParticipant>,
    /// `issuer` (0..1): Issuing Organization of Invoice
    pub issuer: Option<Reference>,
    /// `account` (0..1): Account that is being balanced
    pub account: Option<Reference>,
    /// `lineItem` (0..*): Line items of this Invoice
    pub line_item: Vec<InvoiceLineItem>,
    /// `totalPriceComponent` (0..*): Components of Invoice total
    pub total_price_component: Vec<InvoiceLineItemPriceComponent>,
    /// `totalNet` (0..1): Net total of this Invoice
    pub total_net: Option<Money>,
    /// `totalGross` (0..1): Gross total of this Invoice
    pub total_gross: Option<Money>,
    /// `paymentTerms` (0..1): Payment details
    pub payment_terms: Option<Primitive<String>>,
    /// `note` (0..*): Comments made about the invoice
    pub note: Vec<Annotation>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Invoice");
        let r = Invoice {
            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),
            cancelled_reason: o.prim(d, "cancelledReason", Kind::String),
            type_: o.one(d, "type"),
            subject: o.one(d, "subject"),
            recipient: o.one(d, "recipient"),
            date: o.prim(d, "date", Kind::DateTime),
            participant: o.list(d, "participant"),
            issuer: o.one(d, "issuer"),
            account: o.one(d, "account"),
            line_item: o.list(d, "lineItem"),
            total_price_component: o.list(d, "totalPriceComponent"),
            total_net: o.one(d, "totalNet"),
            total_gross: o.one(d, "totalGross"),
            payment_terms: o.prim(d, "paymentTerms", Kind::Markdown),
            note: o.list(d, "note"),
        };
        required(d, "status", &r.status);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Invoice".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.prim("cancelledReason", &self.cancelled_reason);
        w.one("type", &self.type_);
        w.one("subject", &self.subject);
        w.one("recipient", &self.recipient);
        w.prim("date", &self.date);
        w.list("participant", &self.participant);
        w.one("issuer", &self.issuer);
        w.one("account", &self.account);
        w.list("lineItem", &self.line_item);
        w.list("totalPriceComponent", &self.total_price_component);
        w.one("totalNet", &self.total_net);
        w.one("totalGross", &self.total_gross);
        w.prim("paymentTerms", &self.payment_terms);
        w.list("note", &self.note);
        w.finish()
    }
}

/// Participant in creation of this Invoice
///
/// FHIR path: `Invoice.participant`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct InvoiceParticipant {
    /// `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>,
    /// `role` (0..1): Type of involvement in creation of this Invoice
    pub role: Option<CodeableConcept>,
    /// `actor` (1..1): Individual who was involved
    pub actor: Option<Reference>,
}

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

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

/// Line items of this Invoice
///
/// FHIR path: `Invoice.lineItem`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct InvoiceLineItem {
    /// `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>,
    /// `sequence` (0..1): Sequence number of line item
    pub sequence: Option<Primitive<i32>>,
    /// `chargeItem[x]` (1..1): Reference to ChargeItem containing details of this line item or an inline billing code
    pub charge_item: Option<InvoiceLineItemChargeItem>,
    /// `priceComponent` (0..*): Components of total line item price
    pub price_component: Vec<InvoiceLineItemPriceComponent>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = InvoiceLineItem {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            sequence: o.prim(d, "sequence", Kind::PositiveInt),
            charge_item: o.choice(d, "chargeItem"),
            price_component: o.list(d, "priceComponent"),
        };
        required(d, "chargeItem[x]", &r.charge_item);
        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.prim("sequence", &self.sequence);
        w.choice("chargeItem", &self.charge_item);
        w.list("priceComponent", &self.price_component);
        w.finish()
    }
}

/// Components of total line item price
///
/// FHIR path: `Invoice.lineItem.priceComponent`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct InvoiceLineItemPriceComponent {
    /// `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>,
    /// `type` (1..1): base | surcharge | deduction | discount | tax | informational
    pub type_: Option<Primitive<String>>,
    /// `code` (0..1): Code identifying the specific component
    pub code: Option<CodeableConcept>,
    /// `factor` (0..1): Factor used for calculating this component
    pub factor: Option<Primitive<Decimal>>,
    /// `amount` (0..1): Monetary amount associated with this component
    pub amount: Option<Money>,
}

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

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

/// The types `Invoice.lineItem.chargeItem[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum InvoiceLineItemChargeItem {
    /// `Reference`
    Reference(Reference),
    /// `CodeableConcept`
    CodeableConcept(CodeableConcept),
}

#[cfg(feature = "financial")]
impl Choice for InvoiceLineItemChargeItem {
    const TYPES: &'static [&'static str] = &["Reference", "CodeableConcept"];

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "Reference" => o.one(d, key).map(Self::Reference),
            "CodeableConcept" => o.one(d, key).map(Self::CodeableConcept),
            _ => None,
        }
    }

    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
        match self {
            Self::Reference(v) => w.value(&choice_key(base, "Reference"), v),
            Self::CodeableConcept(v) => w.value(&choice_key(base, "CodeableConcept"), v),
        }
    }
}