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

/// The resource ChargeItem describes the provision of healthcare provider products for a certain patient, therefore referring not only to the product, but containing in addition details of the provision, like date, time, amounts and participating organizations and persons. Main Usage of the ChargeItem is to enable the billing process and internal cost allocation.
///
/// FHIR path: `ChargeItem`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ChargeItem {
    /// `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>,
    /// `definitionUri` (0..*): Defining information about the code of this charge item
    pub definition_uri: Vec<Primitive<String>>,
    /// `definitionCanonical` (0..*): Resource defining the code of this ChargeItem
    pub definition_canonical: Vec<Primitive<String>>,
    /// `status` (1..1): planned | billable | not-billable | aborted | billed | entered-in-error | unknown
    pub status: Option<Primitive<String>>,
    /// `partOf` (0..*): Part of referenced ChargeItem
    pub part_of: Vec<Reference>,
    /// `code` (1..1): A code that identifies the charge, like a billing code
    pub code: Option<CodeableConcept>,
    /// `subject` (1..1): Individual service was done for/to
    pub subject: Option<Reference>,
    /// `context` (0..1): Encounter / Episode associated with event
    pub context: Option<Reference>,
    /// `occurrence[x]` (0..1): When the charged service was applied
    pub occurrence: Option<ChargeItemOccurrence>,
    /// `performer` (0..*): Who performed charged service
    pub performer: Vec<ChargeItemPerformer>,
    /// `performingOrganization` (0..1): Organization providing the charged service
    pub performing_organization: Option<Reference>,
    /// `requestingOrganization` (0..1): Organization requesting the charged service
    pub requesting_organization: Option<Reference>,
    /// `costCenter` (0..1): Organization that has ownership of the (potential, future) revenue
    pub cost_center: Option<Reference>,
    /// `quantity` (0..1): Quantity of which the charge item has been serviced
    pub quantity: Option<Quantity>,
    /// `bodysite` (0..*): Anatomical location, if relevant
    pub bodysite: Vec<CodeableConcept>,
    /// `factorOverride` (0..1): Factor overriding the associated rules
    pub factor_override: Option<Primitive<Decimal>>,
    /// `priceOverride` (0..1): Price overriding the associated rules
    pub price_override: Option<Money>,
    /// `overrideReason` (0..1): Reason for overriding the list price/factor
    pub override_reason: Option<Primitive<String>>,
    /// `enterer` (0..1): Individual who was entering
    pub enterer: Option<Reference>,
    /// `enteredDate` (0..1): Date the charge item was entered
    pub entered_date: Option<Primitive<String>>,
    /// `reason` (0..*): Why was the charged service rendered?
    pub reason: Vec<CodeableConcept>,
    /// `service` (0..*): Which rendered service is being charged?
    pub service: Vec<Reference>,
    /// `product[x]` (0..1): Product charged
    pub product: Option<ChargeItemProduct>,
    /// `account` (0..*): Account to place this charge
    pub account: Vec<Reference>,
    /// `note` (0..*): Comments made about the ChargeItem
    pub note: Vec<Annotation>,
    /// `supportingInformation` (0..*): Further information supporting this charge
    pub supporting_information: Vec<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "ChargeItem");
        let r = ChargeItem {
            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"),
            definition_uri: o.prim_list(d, "definitionUri", Kind::Uri),
            definition_canonical: o.prim_list(d, "definitionCanonical", Kind::Canonical),
            status: o.prim(d, "status", Kind::Code),
            part_of: o.list(d, "partOf"),
            code: o.one(d, "code"),
            subject: o.one(d, "subject"),
            context: o.one(d, "context"),
            occurrence: o.choice(d, "occurrence"),
            performer: o.list(d, "performer"),
            performing_organization: o.one(d, "performingOrganization"),
            requesting_organization: o.one(d, "requestingOrganization"),
            cost_center: o.one(d, "costCenter"),
            quantity: o.one(d, "quantity"),
            bodysite: o.list(d, "bodysite"),
            factor_override: o.prim(d, "factorOverride", Kind::Decimal),
            price_override: o.one(d, "priceOverride"),
            override_reason: o.prim(d, "overrideReason", Kind::String),
            enterer: o.one(d, "enterer"),
            entered_date: o.prim(d, "enteredDate", Kind::DateTime),
            reason: o.list(d, "reason"),
            service: o.list(d, "service"),
            product: o.choice(d, "product"),
            account: o.list(d, "account"),
            note: o.list(d, "note"),
            supporting_information: o.list(d, "supportingInformation"),
        };
        required(d, "status", &r.status);
        required(d, "code", &r.code);
        required(d, "subject", &r.subject);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("ChargeItem".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_list("definitionUri", &self.definition_uri);
        w.prim_list("definitionCanonical", &self.definition_canonical);
        w.prim("status", &self.status);
        w.list("partOf", &self.part_of);
        w.one("code", &self.code);
        w.one("subject", &self.subject);
        w.one("context", &self.context);
        w.choice("occurrence", &self.occurrence);
        w.list("performer", &self.performer);
        w.one("performingOrganization", &self.performing_organization);
        w.one("requestingOrganization", &self.requesting_organization);
        w.one("costCenter", &self.cost_center);
        w.one("quantity", &self.quantity);
        w.list("bodysite", &self.bodysite);
        w.prim("factorOverride", &self.factor_override);
        w.one("priceOverride", &self.price_override);
        w.prim("overrideReason", &self.override_reason);
        w.one("enterer", &self.enterer);
        w.prim("enteredDate", &self.entered_date);
        w.list("reason", &self.reason);
        w.list("service", &self.service);
        w.choice("product", &self.product);
        w.list("account", &self.account);
        w.list("note", &self.note);
        w.list("supportingInformation", &self.supporting_information);
        w.finish()
    }
}

/// Who performed charged service
///
/// FHIR path: `ChargeItem.performer`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ChargeItemPerformer {
    /// `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>,
    /// `function` (0..1): What type of performance was done
    pub function: Option<CodeableConcept>,
    /// `actor` (1..1): Individual who was performing
    pub actor: Option<Reference>,
}

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

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

/// The types `ChargeItem.occurrence[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum ChargeItemOccurrence {
    /// `dateTime`
    DateTime(Primitive<String>),
    /// `Period`
    Period(Period),
    /// `Timing`
    Timing(Timing),
}

#[cfg(feature = "financial")]
impl Choice for ChargeItemOccurrence {
    const TYPES: &'static [&'static str] = &["dateTime", "Period", "Timing"];

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

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

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

#[cfg(feature = "financial")]
impl Choice for ChargeItemProduct {
    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),
        }
    }
}