Skip to main content

fhirkit/r4/resources/
media.rs

1// @generated by fhirkit-gen from hl7.fhir.r4.core 4.0.1. Do not edit.
2//! The FHIR R4 `Media` resource.
3
4#![allow(
5    unused_imports,
6    clippy::large_enum_variant,
7    clippy::too_many_lines,
8    clippy::doc_markdown
9)]
10
11use crate::decode::{
12    choice_key, required, required_list, resource_type, Choice, Decoder, FhirJson, Obj, ObjWriter,
13};
14use crate::json::Json;
15use crate::primitive::{Decimal, Kind, Primitive};
16use crate::r4::*;
17
18/// A photo, video, or audio recording acquired or used in healthcare. The actual content may be inline or provided by direct reference.
19///
20/// FHIR path: `Media`.
21#[cfg(feature = "clinical")]
22#[derive(Debug, Clone, PartialEq, Default)]
23pub struct Media {
24    /// `id` (0..1): Logical id of this artifact
25    pub id: Option<String>,
26    /// `meta` (0..1): Metadata about the resource
27    pub meta: Option<Meta>,
28    /// `implicitRules` (0..1): A set of rules under which this content was created
29    pub implicit_rules: Option<Primitive<String>>,
30    /// `language` (0..1): Language of the resource content
31    pub language: Option<Primitive<String>>,
32    /// `text` (0..1): Text summary of the resource, for human interpretation
33    pub text: Option<Narrative>,
34    /// `contained` (0..*): Contained, inline Resources
35    pub contained: Vec<Resource>,
36    /// `extension` (0..*): Additional content defined by implementations
37    pub extension: Vec<Extension>,
38    /// `modifierExtension` (0..*): Extensions that cannot be ignored
39    pub modifier_extension: Vec<Extension>,
40    /// `identifier` (0..*): Identifier(s) for the image
41    pub identifier: Vec<Identifier>,
42    /// `basedOn` (0..*): Procedure that caused this media to be created
43    pub based_on: Vec<Reference>,
44    /// `partOf` (0..*): Part of referenced event
45    pub part_of: Vec<Reference>,
46    /// `status` (1..1): preparation | in-progress | not-done | on-hold | stopped | completed | entered-in-error | unknown
47    pub status: Option<Primitive<String>>,
48    /// `type` (0..1): Classification of media as image, video, or audio
49    pub type_: Option<CodeableConcept>,
50    /// `modality` (0..1): The type of acquisition equipment/process
51    pub modality: Option<CodeableConcept>,
52    /// `view` (0..1): Imaging view, e.g. Lateral or Antero-posterior
53    pub view: Option<CodeableConcept>,
54    /// `subject` (0..1): Who/What this Media is a record of
55    pub subject: Option<Reference>,
56    /// `encounter` (0..1): Encounter associated with media
57    pub encounter: Option<Reference>,
58    /// `created[x]` (0..1): When Media was collected
59    pub created: Option<MediaCreated>,
60    /// `issued` (0..1): Date/Time this version was made available
61    pub issued: Option<Primitive<String>>,
62    /// `operator` (0..1): The person who generated the image
63    pub operator: Option<Reference>,
64    /// `reasonCode` (0..*): Why was event performed?
65    pub reason_code: Vec<CodeableConcept>,
66    /// `bodySite` (0..1): Observed body part
67    pub body_site: Option<CodeableConcept>,
68    /// `deviceName` (0..1): Name of the device/manufacturer
69    pub device_name: Option<Primitive<String>>,
70    /// `device` (0..1): Observing Device
71    pub device: Option<Reference>,
72    /// `height` (0..1): Height of the image in pixels (photo/video)
73    pub height: Option<Primitive<i32>>,
74    /// `width` (0..1): Width of the image in pixels (photo/video)
75    pub width: Option<Primitive<i32>>,
76    /// `frames` (0..1): Number of frames if > 1 (photo)
77    pub frames: Option<Primitive<i32>>,
78    /// `duration` (0..1): Length in seconds (audio / video)
79    pub duration: Option<Primitive<Decimal>>,
80    /// `content` (1..1): Actual Media - reference or data
81    pub content: Option<Attachment>,
82    /// `note` (0..*): Comments made about the media
83    pub note: Vec<Annotation>,
84}
85
86#[cfg(feature = "clinical")]
87impl FhirJson for Media {
88    const TYPE_NAME: &'static str = "Media";
89
90    fn decode(v: &Json, d: &mut Decoder) -> Option<Self> {
91        let mut o = Obj::new(v, d)?;
92        resource_type(&mut o, d, "Media");
93        let r = Media {
94            id: o.string(d, "id"),
95            meta: o.one(d, "meta"),
96            implicit_rules: o.prim(d, "implicitRules", Kind::Uri),
97            language: o.prim(d, "language", Kind::Code),
98            text: o.one(d, "text"),
99            contained: o.list(d, "contained"),
100            extension: o.list(d, "extension"),
101            modifier_extension: o.list(d, "modifierExtension"),
102            identifier: o.list(d, "identifier"),
103            based_on: o.list(d, "basedOn"),
104            part_of: o.list(d, "partOf"),
105            status: o.prim(d, "status", Kind::Code),
106            type_: o.one(d, "type"),
107            modality: o.one(d, "modality"),
108            view: o.one(d, "view"),
109            subject: o.one(d, "subject"),
110            encounter: o.one(d, "encounter"),
111            created: o.choice(d, "created"),
112            issued: o.prim(d, "issued", Kind::Instant),
113            operator: o.one(d, "operator"),
114            reason_code: o.list(d, "reasonCode"),
115            body_site: o.one(d, "bodySite"),
116            device_name: o.prim(d, "deviceName", Kind::String),
117            device: o.one(d, "device"),
118            height: o.prim(d, "height", Kind::PositiveInt),
119            width: o.prim(d, "width", Kind::PositiveInt),
120            frames: o.prim(d, "frames", Kind::PositiveInt),
121            duration: o.prim(d, "duration", Kind::Decimal),
122            content: o.one(d, "content"),
123            note: o.list(d, "note"),
124        };
125        required(d, "status", &r.status);
126        required(d, "content", &r.content);
127        o.finish(d);
128        Some(r)
129    }
130
131    fn encode(&self) -> Json {
132        let mut w = ObjWriter::new();
133        w.raw("resourceType", Json::String("Media".into()));
134        w.string("id", &self.id);
135        w.one("meta", &self.meta);
136        w.prim("implicitRules", &self.implicit_rules);
137        w.prim("language", &self.language);
138        w.one("text", &self.text);
139        w.list("contained", &self.contained);
140        w.list("extension", &self.extension);
141        w.list("modifierExtension", &self.modifier_extension);
142        w.list("identifier", &self.identifier);
143        w.list("basedOn", &self.based_on);
144        w.list("partOf", &self.part_of);
145        w.prim("status", &self.status);
146        w.one("type", &self.type_);
147        w.one("modality", &self.modality);
148        w.one("view", &self.view);
149        w.one("subject", &self.subject);
150        w.one("encounter", &self.encounter);
151        w.choice("created", &self.created);
152        w.prim("issued", &self.issued);
153        w.one("operator", &self.operator);
154        w.list("reasonCode", &self.reason_code);
155        w.one("bodySite", &self.body_site);
156        w.prim("deviceName", &self.device_name);
157        w.one("device", &self.device);
158        w.prim("height", &self.height);
159        w.prim("width", &self.width);
160        w.prim("frames", &self.frames);
161        w.prim("duration", &self.duration);
162        w.one("content", &self.content);
163        w.list("note", &self.note);
164        w.finish()
165    }
166}
167
168/// The types `Media.created[x]` allows.
169#[cfg(feature = "clinical")]
170#[derive(Debug, Clone, PartialEq)]
171pub enum MediaCreated {
172    /// `dateTime`
173    DateTime(Primitive<String>),
174    /// `Period`
175    Period(Period),
176}
177
178#[cfg(feature = "clinical")]
179impl Choice for MediaCreated {
180    const TYPES: &'static [&'static str] = &["dateTime", "Period"];
181
182    fn decode_as(code: &str, key: &str, o: &mut Obj<'_>, d: &mut Decoder) -> Option<Self> {
183        match code {
184            "dateTime" => o.prim(d, key, Kind::DateTime).map(Self::DateTime),
185            "Period" => o.one(d, key).map(Self::Period),
186            _ => None,
187        }
188    }
189
190    fn encode_into(&self, base: &str, w: &mut ObjWriter) {
191        match self {
192            Self::DateTime(v) => w.prim_value(&choice_key(base, "dateTime"), v),
193            Self::Period(v) => w.value(&choice_key(base, "Period"), v),
194        }
195    }
196}