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 `DeviceUseStatement` 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 record of a device being used by a patient where the record is the result of a report from the patient or another clinician.
///
/// FHIR path: `DeviceUseStatement`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct DeviceUseStatement {
    /// `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..*): External identifier for this record
    pub identifier: Vec<Identifier>,
    /// `basedOn` (0..*): Fulfills plan, proposal or order
    pub based_on: Vec<Reference>,
    /// `status` (1..1): active | completed | entered-in-error +
    pub status: Option<Primitive<String>>,
    /// `subject` (1..1): Patient using device
    pub subject: Option<Reference>,
    /// `derivedFrom` (0..*): Supporting information
    pub derived_from: Vec<Reference>,
    /// `timing[x]` (0..1): How often the device was used
    pub timing: Option<DeviceUseStatementTiming>,
    /// `recordedOn` (0..1): When statement was recorded
    pub recorded_on: Option<Primitive<String>>,
    /// `source` (0..1): Who made the statement
    pub source: Option<Reference>,
    /// `device` (1..1): Reference to device used
    pub device: Option<Reference>,
    /// `reasonCode` (0..*): Why device was used
    pub reason_code: Vec<CodeableConcept>,
    /// `reasonReference` (0..*): Why was DeviceUseStatement performed?
    pub reason_reference: Vec<Reference>,
    /// `bodySite` (0..1): Target body site
    pub body_site: Option<CodeableConcept>,
    /// `note` (0..*): Addition details (comments, instructions)
    pub note: Vec<Annotation>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "DeviceUseStatement");
        let r = DeviceUseStatement {
            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"),
            based_on: o.list(d, "basedOn"),
            status: o.prim(d, "status", Kind::Code),
            subject: o.one(d, "subject"),
            derived_from: o.list(d, "derivedFrom"),
            timing: o.choice(d, "timing"),
            recorded_on: o.prim(d, "recordedOn", Kind::DateTime),
            source: o.one(d, "source"),
            device: o.one(d, "device"),
            reason_code: o.list(d, "reasonCode"),
            reason_reference: o.list(d, "reasonReference"),
            body_site: o.one(d, "bodySite"),
            note: o.list(d, "note"),
        };
        required(d, "status", &r.status);
        required(d, "subject", &r.subject);
        required(d, "device", &r.device);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("DeviceUseStatement".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.list("basedOn", &self.based_on);
        w.prim("status", &self.status);
        w.one("subject", &self.subject);
        w.list("derivedFrom", &self.derived_from);
        w.choice("timing", &self.timing);
        w.prim("recordedOn", &self.recorded_on);
        w.one("source", &self.source);
        w.one("device", &self.device);
        w.list("reasonCode", &self.reason_code);
        w.list("reasonReference", &self.reason_reference);
        w.one("bodySite", &self.body_site);
        w.list("note", &self.note);
        w.finish()
    }
}

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

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

    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
        match code {
            "Timing" => o.one(d, key).map(Self::Timing),
            "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::Timing(v) => w.value(&choice_key(base, "Timing"), v),
            Self::Period(v) => w.value(&choice_key(base, "Period"), v),
            Self::DateTime(v) => w.prim_value(&choice_key(base, "dateTime"), v),
        }
    }
}