Skip to main content

cimstructs/
Status.rs

1/// Current status information relevant to an entity.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct Status {
4    pub id: String,
5    /// Date and time for which status 'value' applies.
6    pub date_time: String,
7    /// Reason code or explanation for why an object went to the current status 'value'.
8    pub reason: String,
9    /// Pertinent information regarding the current 'value', as free form text.
10    pub remark: String,
11    /// Status value at 'dateTime'; prior status changes may have been kept in instances of activity records associated with the object to which this status applies.
12    pub value: String,
13}
14impl crate::base::CimElement for Status {
15    fn mrid(&self) -> &str { &self.id }
16    fn type_name(&self) -> &'static str { "Status" }
17    fn as_any(&self) -> &dyn std::any::Any { self }
18    fn to_json_value(&self) -> serde_json::Value {
19        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
20    }
21    fn to_block(&self) -> crate::base::RdfBlock {
22        let mut block = crate::base::RdfBlock {
23            type_name: "Status".to_string(),
24            mrid: self.id.clone(),
25            fields: std::collections::HashMap::new(),
26            duplicate_fields: std::collections::HashSet::new(),
27        };
28        if !self.date_time.is_empty() {
29            block.fields.insert("Status.dateTime".into(), crate::base::FieldValue::Text(self.date_time.clone()));
30        }
31        if !self.reason.is_empty() {
32            block.fields.insert("Status.reason".into(), crate::base::FieldValue::Text(self.reason.clone()));
33        }
34        if !self.remark.is_empty() {
35            block.fields.insert("Status.remark".into(), crate::base::FieldValue::Text(self.remark.clone()));
36        }
37        if !self.value.is_empty() {
38            block.fields.insert("Status.value".into(), crate::base::FieldValue::Text(self.value.clone()));
39        }
40        block
41    }
42}
43
44impl Status {
45    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
46        let mut obj = Self::default();
47        obj.id.clone_from(&b.mrid);
48        for (key, val) in &b.fields {
49            match key.as_str() {
50                "Status.dateTime" => {
51                    match val {
52                        crate::base::FieldValue::Text(sv) => { obj.date_time = sv.clone(); }
53                        crate::base::FieldValue::TextList(svs) => {
54                            if let Some(sv) = svs.last() { obj.date_time = sv.clone(); }
55                        }
56                        _ => {}
57                    }
58                }
59                "Status.reason" => {
60                    match val {
61                        crate::base::FieldValue::Text(sv) => { obj.reason = sv.clone(); }
62                        crate::base::FieldValue::TextList(svs) => {
63                            if let Some(sv) = svs.last() { obj.reason = sv.clone(); }
64                        }
65                        _ => {}
66                    }
67                }
68                "Status.remark" => {
69                    match val {
70                        crate::base::FieldValue::Text(sv) => { obj.remark = sv.clone(); }
71                        crate::base::FieldValue::TextList(svs) => {
72                            if let Some(sv) = svs.last() { obj.remark = sv.clone(); }
73                        }
74                        _ => {}
75                    }
76                }
77                "Status.value" => {
78                    match val {
79                        crate::base::FieldValue::Text(sv) => { obj.value = sv.clone(); }
80                        crate::base::FieldValue::TextList(svs) => {
81                            if let Some(sv) = svs.last() { obj.value = sv.clone(); }
82                        }
83                        _ => {}
84                    }
85                }
86                _ => {}
87            }
88        }
89        obj
90    }
91}