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

/// Provenance of a resource is a record that describes entities and processes involved in producing and delivering or otherwise influencing that resource. Provenance provides a critical foundation for assessing authenticity, enabling trust, and allowing reproducibility. Provenance assertions are a form of contextual metadata and can themselves become important records with their own provenance. Provenance statement indicates clinical significance in terms of confidence in authenticity, reliability, and trustworthiness, integrity, and stage in lifecycle (e.g. Document Completion - has the artifact been legally authenticated), all of which may impact security, privacy, and trust policies.
///
/// FHIR path: `Provenance`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Provenance {
    /// `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>,
    /// `target` (1..*): Target Reference(s) (usually version specific)
    pub target: Vec<Reference>,
    /// `occurred[x]` (0..1): When the activity occurred
    pub occurred: Option<ProvenanceOccurred>,
    /// `recorded` (1..1): When the activity was recorded / updated
    pub recorded: Option<Primitive<String>>,
    /// `policy` (0..*): Policy or plan the activity was defined by
    pub policy: Vec<Primitive<String>>,
    /// `location` (0..1): Where the activity occurred, if relevant
    pub location: Option<Reference>,
    /// `reason` (0..*): Reason the activity is occurring
    pub reason: Vec<CodeableConcept>,
    /// `activity` (0..1): Activity that occurred
    pub activity: Option<CodeableConcept>,
    /// `agent` (1..*): Actor involved
    pub agent: Vec<ProvenanceAgent>,
    /// `entity` (0..*): An entity used in this activity
    pub entity: Vec<ProvenanceEntity>,
    /// `signature` (0..*): Signature on target
    pub signature: Vec<Signature>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Provenance");
        let r = Provenance {
            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"),
            target: o.list(d, "target"),
            occurred: o.choice(d, "occurred"),
            recorded: o.prim(d, "recorded", Kind::Instant),
            policy: o.prim_list(d, "policy", Kind::Uri),
            location: o.one(d, "location"),
            reason: o.list(d, "reason"),
            activity: o.one(d, "activity"),
            agent: o.list(d, "agent"),
            entity: o.list(d, "entity"),
            signature: o.list(d, "signature"),
        };
        required_list(d, "target", &r.target, 1);
        required(d, "recorded", &r.recorded);
        required_list(d, "agent", &r.agent, 1);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Provenance".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("target", &self.target);
        w.choice("occurred", &self.occurred);
        w.prim("recorded", &self.recorded);
        w.prim_list("policy", &self.policy);
        w.one("location", &self.location);
        w.list("reason", &self.reason);
        w.one("activity", &self.activity);
        w.list("agent", &self.agent);
        w.list("entity", &self.entity);
        w.list("signature", &self.signature);
        w.finish()
    }
}

/// Actor involved
///
/// FHIR path: `Provenance.agent`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ProvenanceAgent {
    /// `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): How the agent participated
    pub type_: Option<CodeableConcept>,
    /// `role` (0..*): What the agents role was
    pub role: Vec<CodeableConcept>,
    /// `who` (1..1): Who participated
    pub who: Option<Reference>,
    /// `onBehalfOf` (0..1): Who the agent is representing
    pub on_behalf_of: Option<Reference>,
}

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

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

/// An entity used in this activity
///
/// FHIR path: `Provenance.entity`.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ProvenanceEntity {
    /// `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` (1..1): derivation | revision | quotation | source | removal
    pub role: Option<Primitive<String>>,
    /// `what` (1..1): Identity of entity
    pub what: Option<Reference>,
    /// `agent` (0..*): Entity is attributed to this agent
    pub agent: Vec<ProvenanceAgent>,
}

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

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

/// The types `Provenance.occurred[x]` allows.
#[cfg(feature = "foundation")]
#[derive(Debug, Clone, PartialEq)]
pub enum ProvenanceOccurred {
    /// `Period`
    Period(Period),
    /// `dateTime`
    DateTime(Primitive<String>),
}

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

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

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