1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! Annotation
//!
//! URL: http://hl7.org/fhir/StructureDefinition/Annotation
//!
//! Version: 5.0.0
//!
//! Annotation Type: A text note which also contains information about who made the statement and when.
//!
//! FHIR: <https://build.fhir.org/>
//!
//! UML: <https://build.fhir.org/uml.html>
// Allow unused crate::r5::types as types;
#![allow(unused_imports)]
use crate::r5::types;
use ::serde::{Deserialize, Serialize};
use fhir_derive_macros::{Builder, Validate};
/// A text note that also records information about who made the statement
/// and when it was made. Annotations are used throughout FHIR resources to
/// capture free-text comments, clinical notes, or remarks alongside optional
/// attribution to an author and a timestamp. The author may be identified
/// either by a reference to a resource or by a plain text name.
///
/// # Examples
///
/// ```
/// use fhir::r5::types::annotation::Annotation;
///
/// let value = Annotation::default();
/// let json = ::serde_json::to_value(&value).unwrap();
/// let back: Annotation = ::serde_json::from_value(json).unwrap();
/// assert_eq!(value, back);
/// ```
#[serde_with::skip_serializing_none]
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq, Validate, Builder)]
#[serde(rename_all = "camelCase")]
pub struct Annotation {
/// Unique id for inter-element referencing
pub id: Option<types::String>,
/// Additional content defined by implementations
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub extension: Vec<types::Extension>,
/// The individual responsible for the annotation (`author[x]` choice,
/// 0..1): either a [`Reference`](types::Reference) to a Practitioner,
/// PractitionerRole, Patient, RelatedPerson, or Organization
/// (`authorReference`), or free-text [`String`](types::String)
/// (`authorString`).
#[serde(flatten)]
pub author: Option<AnnotationAuthor>,
/// The date and time this annotation was made. Cardinality 0..1, data
/// type `dateTime`.
///
pub time: Option<types::DateTime>,
/// Primitive extension sibling for [`time`](Self::time) (FHIR `_time`).
#[serde(rename = "_time")]
pub time_ext: Option<types::Element>,
/// The text content of the annotation, which may include markdown
/// formatting. This is the required content of the note itself.
///
pub text: types::Markdown,
/// Primitive extension sibling for [`text`](Self::text) (FHIR `_text`).
#[serde(rename = "_text")]
pub text_ext: Option<types::Element>,
}
/// The `Annotation.author[x]` choice: who made the annotation.
#[derive(Debug, Clone, PartialEq, Eq, fhir_derive_macros::FhirChoice, Validate)]
pub enum AnnotationAuthor {
/// `authorReference` — a reference to the responsible party.
#[fhir("authorReference")]
Reference(Box<types::Reference>),
/// `authorString` — the responsible party as free text.
#[fhir("authorString")]
String(crate::r5::choice::Primitive<types::String>),
}
impl Annotation {
/// The `authorReference` variant, if set.
#[deprecated(note = "match on `author` (the AnnotationAuthor choice enum) instead")]
#[must_use]
pub fn author_reference(&self) -> Option<&types::Reference> {
match &self.author {
Some(AnnotationAuthor::Reference(r)) => Some(r),
_ => None,
}
}
/// The `authorString` variant's value, if set.
#[deprecated(note = "match on `author` (the AnnotationAuthor choice enum) instead")]
#[must_use]
pub fn author_string(&self) -> Option<&types::String> {
match &self.author {
Some(AnnotationAuthor::String(p)) => Some(&p.value),
_ => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
type T = Annotation;
#[test]
fn test_default() {
let actual = T::default();
let expect = T {
author: None,
time: None,
text: types::Markdown::default(),
..Default::default()
};
assert_eq!(actual, expect);
}
mod serde_json {
use super::*;
#[test]
fn test_serde_json_round_trip() {
let value = T::default();
let json = ::serde_json::to_value(&value).expect("to_value");
let back: T = ::serde_json::from_value(json).expect("from_value");
assert_eq!(value, back);
}
}
}