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

/// Financial instrument which may be used to reimburse or pay for health care products and services. Includes both insurance and self-payment.
///
/// FHIR path: `Coverage`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Coverage {
    /// `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 the coverage
    pub identifier: Vec<Identifier>,
    /// `status` (1..1): active | cancelled | draft | entered-in-error
    pub status: Option<Primitive<String>>,
    /// `type` (0..1): Coverage category such as medical or accident
    pub type_: Option<CodeableConcept>,
    /// `policyHolder` (0..1): Owner of the policy
    pub policy_holder: Option<Reference>,
    /// `subscriber` (0..1): Subscriber to the policy
    pub subscriber: Option<Reference>,
    /// `subscriberId` (0..1): ID assigned to the subscriber
    pub subscriber_id: Option<Primitive<String>>,
    /// `beneficiary` (1..1): Plan beneficiary
    pub beneficiary: Option<Reference>,
    /// `dependent` (0..1): Dependent number
    pub dependent: Option<Primitive<String>>,
    /// `relationship` (0..1): Beneficiary relationship to the subscriber
    pub relationship: Option<CodeableConcept>,
    /// `period` (0..1): Coverage start and end dates
    pub period: Option<Period>,
    /// `payor` (1..*): Issuer of the policy
    pub payor: Vec<Reference>,
    /// `class` (0..*): Additional coverage classifications
    pub class: Vec<CoverageClass>,
    /// `order` (0..1): Relative order of the coverage
    pub order: Option<Primitive<i32>>,
    /// `network` (0..1): Insurer network
    pub network: Option<Primitive<String>>,
    /// `costToBeneficiary` (0..*): Patient payments for services/products
    pub cost_to_beneficiary: Vec<CoverageCostToBeneficiary>,
    /// `subrogation` (0..1): Reimbursement to insurer
    pub subrogation: Option<Primitive<bool>>,
    /// `contract` (0..*): Contract details
    pub contract: Vec<Reference>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Coverage");
        let r = Coverage {
            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"),
            policy_holder: o.one(d, "policyHolder"),
            subscriber: o.one(d, "subscriber"),
            subscriber_id: o.prim(d, "subscriberId", Kind::String),
            beneficiary: o.one(d, "beneficiary"),
            dependent: o.prim(d, "dependent", Kind::String),
            relationship: o.one(d, "relationship"),
            period: o.one(d, "period"),
            payor: o.list(d, "payor"),
            class: o.list(d, "class"),
            order: o.prim(d, "order", Kind::PositiveInt),
            network: o.prim(d, "network", Kind::String),
            cost_to_beneficiary: o.list(d, "costToBeneficiary"),
            subrogation: o.prim(d, "subrogation", Kind::Boolean),
            contract: o.list(d, "contract"),
        };
        required(d, "status", &r.status);
        required(d, "beneficiary", &r.beneficiary);
        required_list(d, "payor", &r.payor, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Coverage".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.one("policyHolder", &self.policy_holder);
        w.one("subscriber", &self.subscriber);
        w.prim("subscriberId", &self.subscriber_id);
        w.one("beneficiary", &self.beneficiary);
        w.prim("dependent", &self.dependent);
        w.one("relationship", &self.relationship);
        w.one("period", &self.period);
        w.list("payor", &self.payor);
        w.list("class", &self.class);
        w.prim("order", &self.order);
        w.prim("network", &self.network);
        w.list("costToBeneficiary", &self.cost_to_beneficiary);
        w.prim("subrogation", &self.subrogation);
        w.list("contract", &self.contract);
        w.finish()
    }
}

/// Additional coverage classifications
///
/// FHIR path: `Coverage.class`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageClass {
    /// `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): Type of class such as 'group' or 'plan'
    pub type_: Option<CodeableConcept>,
    /// `value` (1..1): Value associated with the type
    pub value: Option<Primitive<String>>,
    /// `name` (0..1): Human readable description of the type and value
    pub name: Option<Primitive<String>>,
}

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

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

/// Patient payments for services/products
///
/// FHIR path: `Coverage.costToBeneficiary`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageCostToBeneficiary {
    /// `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` (0..1): Cost category
    pub type_: Option<CodeableConcept>,
    /// `value[x]` (1..1): The amount or percentage due from the beneficiary
    pub value: Option<CoverageCostToBeneficiaryValue>,
    /// `exception` (0..*): Exceptions for patient payments
    pub exception: Vec<CoverageCostToBeneficiaryException>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        let r = CoverageCostToBeneficiary {
            id: o.string(d, "id"),
            extension: o.list(d, "extension"),
            modifier_extension: o.list(d, "modifierExtension"),
            type_: o.one(d, "type"),
            value: o.choice(d, "value"),
            exception: o.list(d, "exception"),
        };
        required(d, "value[x]", &r.value);
        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("type", &self.type_);
        w.choice("value", &self.value);
        w.list("exception", &self.exception);
        w.finish()
    }
}

/// Exceptions for patient payments
///
/// FHIR path: `Coverage.costToBeneficiary.exception`.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct CoverageCostToBeneficiaryException {
    /// `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): Exception category
    pub type_: Option<CodeableConcept>,
    /// `period` (0..1): The effective period of the exception
    pub period: Option<Period>,
}

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

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

/// The types `Coverage.costToBeneficiary.value[x]` allows.
#[cfg(feature = "financial")]
#[derive(Debug, Clone, PartialEq)]
pub enum CoverageCostToBeneficiaryValue {
    /// `Quantity`
    Quantity(Quantity),
    /// `Money`
    Money(Money),
}

#[cfg(feature = "financial")]
impl Choice for CoverageCostToBeneficiaryValue {
    const TYPES: &'static [&'static str] = &["Quantity", "Money"];

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

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