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 `Media` 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 photo, video, or audio recording acquired or used in healthcare. The actual content may be inline or provided by direct reference.
///
/// FHIR path: `Media`.
#[cfg(feature = "clinical")]
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Media {
    /// `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..*): Identifier(s) for the image
    pub identifier: Vec<Identifier>,
    /// `basedOn` (0..*): Procedure that caused this media to be created
    pub based_on: Vec<Reference>,
    /// `partOf` (0..*): Part of referenced event
    pub part_of: Vec<Reference>,
    /// `status` (1..1): preparation | in-progress | not-done | on-hold | stopped | completed | entered-in-error | unknown
    pub status: Option<Primitive<String>>,
    /// `type` (0..1): Classification of media as image, video, or audio
    pub type_: Option<CodeableConcept>,
    /// `modality` (0..1): The type of acquisition equipment/process
    pub modality: Option<CodeableConcept>,
    /// `view` (0..1): Imaging view, e.g. Lateral or Antero-posterior
    pub view: Option<CodeableConcept>,
    /// `subject` (0..1): Who/What this Media is a record of
    pub subject: Option<Reference>,
    /// `encounter` (0..1): Encounter associated with media
    pub encounter: Option<Reference>,
    /// `created[x]` (0..1): When Media was collected
    pub created: Option<MediaCreated>,
    /// `issued` (0..1): Date/Time this version was made available
    pub issued: Option<Primitive<String>>,
    /// `operator` (0..1): The person who generated the image
    pub operator: Option<Reference>,
    /// `reasonCode` (0..*): Why was event performed?
    pub reason_code: Vec<CodeableConcept>,
    /// `bodySite` (0..1): Observed body part
    pub body_site: Option<CodeableConcept>,
    /// `deviceName` (0..1): Name of the device/manufacturer
    pub device_name: Option<Primitive<String>>,
    /// `device` (0..1): Observing Device
    pub device: Option<Reference>,
    /// `height` (0..1): Height of the image in pixels (photo/video)
    pub height: Option<Primitive<i32>>,
    /// `width` (0..1): Width of the image in pixels (photo/video)
    pub width: Option<Primitive<i32>>,
    /// `frames` (0..1): Number of frames if > 1 (photo)
    pub frames: Option<Primitive<i32>>,
    /// `duration` (0..1): Length in seconds (audio / video)
    pub duration: Option<Primitive<Decimal>>,
    /// `content` (1..1): Actual Media - reference or data
    pub content: Option<Attachment>,
    /// `note` (0..*): Comments made about the media
    pub note: Vec<Annotation>,
}

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

    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
        let mut o = Obj::new(v, d)?;
        resource_type(&mut o, d, "Media");
        let r = Media {
            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"),
            part_of: o.list(d, "partOf"),
            status: o.prim(d, "status", Kind::Code),
            type_: o.one(d, "type"),
            modality: o.one(d, "modality"),
            view: o.one(d, "view"),
            subject: o.one(d, "subject"),
            encounter: o.one(d, "encounter"),
            created: o.choice(d, "created"),
            issued: o.prim(d, "issued", Kind::Instant),
            operator: o.one(d, "operator"),
            reason_code: o.list(d, "reasonCode"),
            body_site: o.one(d, "bodySite"),
            device_name: o.prim(d, "deviceName", Kind::String),
            device: o.one(d, "device"),
            height: o.prim(d, "height", Kind::PositiveInt),
            width: o.prim(d, "width", Kind::PositiveInt),
            frames: o.prim(d, "frames", Kind::PositiveInt),
            duration: o.prim(d, "duration", Kind::Decimal),
            content: o.one(d, "content"),
            note: o.list(d, "note"),
        };
        required(d, "status", &r.status);
        required(d, "content", &r.content);
        o.finish(d);
        Some(r)
    }

    fn encode(&self) -> Json {
        let mut w = ObjWriter::new();
        w.raw("resourceType", Json::String("Media".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.list("partOf", &self.part_of);
        w.prim("status", &self.status);
        w.one("type", &self.type_);
        w.one("modality", &self.modality);
        w.one("view", &self.view);
        w.one("subject", &self.subject);
        w.one("encounter", &self.encounter);
        w.choice("created", &self.created);
        w.prim("issued", &self.issued);
        w.one("operator", &self.operator);
        w.list("reasonCode", &self.reason_code);
        w.one("bodySite", &self.body_site);
        w.prim("deviceName", &self.device_name);
        w.one("device", &self.device);
        w.prim("height", &self.height);
        w.prim("width", &self.width);
        w.prim("frames", &self.frames);
        w.prim("duration", &self.duration);
        w.one("content", &self.content);
        w.list("note", &self.note);
        w.finish()
    }
}

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

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

    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),
            _ => 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),
        }
    }
}