wellbeinglib/enums/
behaviour_type.rs

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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use std::fmt;
use std::fmt::Formatter;
use std::str;
use std::str::FromStr;

use serde::Deserialize;
use serde::Serialize;

#[cfg(feature = "diesel")]
use {
    diesel::{deserialize, not_none, serialize},
    diesel::{AsExpression, FromSqlRow},
    diesel::backend::Backend,
    diesel::deserialize::FromSql,
    diesel::pg::Pg,
    diesel::serialize::{IsNull, Output, ToSql},
    diesel::types::Varchar,
    std::io::Write,
};

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
feature = "diesel",
derive(AsExpression, FromSqlRow),
sql_type = "Varchar"
)]

pub enum BehavioutType {
    Criminal,
    Aggressive,
    Physical,
    WeaponUse,
    WeaponPosession,
    WeaponImplementation,
    DrugUse,
    DrugPosession,
    DrugSupply,
    CriminalBehaviour,
    ConcerningBehaviour,
    PersistentRiskOthers,
    PropertyDestruction,
    CyberBullying,
    Bullying,
    PsychologicalAbuse,
    VerbalAbuse,
    Racism,
    Discrimination,
    MisuseTechnology,
    Assault,
    Positive,
    Neutral,
    None,

}
impl BehavioutType {
    pub fn to_text(&self)->String {
        match self {
            BehavioutType::Criminal => "Criminal behaviour".to_string(),
            BehavioutType::Positive => "Positive".to_string(),
            BehavioutType::Neutral => "Neutral".to_string(),
            BehavioutType::Aggressive => "Aggressive behaviour".to_string(),
            BehavioutType::Physical => "Physical violence".to_string(),
            BehavioutType::WeaponUse => "Use of a prohibited weapon, firearm or knife".to_string(),
            BehavioutType::WeaponPosession => "Possession of a prohibited weapon, firearm or knife".to_string(),
            BehavioutType::WeaponImplementation => "Use of implement as a weapon".to_string(),
            BehavioutType::DrugUse => "Use of a suspected drug or illegal substance".to_string(),
            BehavioutType::DrugPosession => "Possession of a suspected drug or illegal substance ".to_string(),
            BehavioutType::DrugSupply => "Supply of suspected drug or illegal substance".to_string(),
            BehavioutType::CriminalBehaviour => "Serious criminal behaviour related to the school".to_string(),
            BehavioutType::ConcerningBehaviour => "Serious behaviours of concern - pending expulsion decision".to_string(),
            BehavioutType::PersistentRiskOthers => "Continuing persistent behaviour posing unacceptable risk to anotherperson's learning and/or wellbeing".to_string(),
            BehavioutType::PropertyDestruction => "Destruction of property that poses unacceptable risk to health and safety ".to_string(),
            BehavioutType::CyberBullying => "Cyber-bullying".to_string(),
            BehavioutType::Bullying => "Bullying".to_string(),
            BehavioutType::PsychologicalAbuse => "Psychological abuse".to_string(),
            BehavioutType::VerbalAbuse =>"Verbal abuse".to_string(),
            BehavioutType::Racism => "Racism".to_string(),
            BehavioutType::Discrimination => "Discrimination".to_string(),
            BehavioutType::MisuseTechnology => "Misuse of technology".to_string(),
            BehavioutType::Assault => "Assault".to_string(),
            BehavioutType::None => "None".to_string(),
        }
    }
}
impl fmt::Display for BehavioutType {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}
impl Default for BehavioutType {
    fn default() -> Self {
        BehavioutType::None
    }
}


#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for BehavioutType {
    fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
        match *self {
            BehavioutType::Criminal => out.write_all(b"Criminal")?,
            BehavioutType::Neutral => out.write_all(b"Neutral")?,
            BehavioutType::Positive => out.write_all(b"Positive")?,
            BehavioutType::Aggressive => out.write_all(b"Aggressive")?,
            BehavioutType::Physical => out.write_all(b"Physical")?,
            BehavioutType::WeaponUse => out.write_all(b"WeaponUse")?,
            BehavioutType::WeaponPosession => out.write_all(b"WeaponPosession")?,
            BehavioutType::WeaponImplementation => out.write_all(b"WeaponImplementation")?,
            BehavioutType::DrugUse => out.write_all(b"DrugUse")?,
            BehavioutType::DrugPosession => out.write_all(b"DrugPosession")?,
            BehavioutType::DrugSupply => out.write_all(b"DrugSupply")?,
            BehavioutType::CriminalBehaviour => out.write_all(b"CriminalBehaviour")?,
            BehavioutType::ConcerningBehaviour => out.write_all(b"ConcerningBehaviour")?,
            BehavioutType::PersistentRiskOthers => out.write_all(b"PersistentRiskOthers")?,
            BehavioutType::PropertyDestruction => out.write_all(b"PropertyDestruction")?,
            BehavioutType::CyberBullying => out.write_all(b"CyberBullying")?,
            BehavioutType::Bullying => out.write_all(b"Bullying")?,
            BehavioutType::PsychologicalAbuse => out.write_all(b"PsychologicalAbuse")?,
            BehavioutType::VerbalAbuse => out.write_all(b"VerbalAbuse")?,
            BehavioutType::Racism => out.write_all(b"Racism")?,
            BehavioutType::Discrimination => out.write_all(b"Discrimination")?,
            BehavioutType::MisuseTechnology => out.write_all(b"MisuseTechnology")?,
            BehavioutType::Assault => out.write_all(b"Assault")?,
            BehavioutType::None => out.write_all(b"None")?,

        }
        Ok(IsNull::No)
    }
}


#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for BehavioutType {
    fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
        match not_none!(bytes) {
            b"Criminal" => Ok(BehavioutType::Criminal),
            b"Positive" => Ok(BehavioutType::Positive),
            b"Neutral" => Ok(BehavioutType::Neutral),
            b"Aggressive" => Ok(BehavioutType::Aggressive),
            b"Physical" => Ok(BehavioutType::Physical),
            b"WeaponUse" => Ok(BehavioutType::WeaponUse),
            b"WeaponPosession" => Ok(BehavioutType::WeaponPosession),
            b"WeaponImplementation" => Ok(BehavioutType::WeaponImplementation),
            b"DrugUse" => Ok(BehavioutType::DrugUse),
            b"DrugPosession" => Ok(BehavioutType::DrugPosession),
            b"DrugSupply" => Ok(BehavioutType::DrugSupply),
            b"CriminalBehaviour" => Ok(BehavioutType::CriminalBehaviour),
            b"ConcerningBehaviour" => Ok(BehavioutType::ConcerningBehaviour),
            b"PersistentRiskOthers" => Ok(BehavioutType::PersistentRiskOthers),
            b"PropertyDestruction" => Ok(BehavioutType::PropertyDestruction),
            b"CyberBullying" => Ok(BehavioutType::CyberBullying),
            b"Bullying" => Ok(BehavioutType::Bullying),
            b"PsychologicalAbuse" => Ok(BehavioutType::PsychologicalAbuse),
            b"VerbalAbuse" => Ok(BehavioutType::VerbalAbuse),
            b"Racism" => Ok(BehavioutType::Racism),
            b"Discrimination" => Ok(BehavioutType::Discrimination),
            b"MisuseTechnology" => Ok(BehavioutType::MisuseTechnology),
            b"Assault" => Ok(BehavioutType::Assault),
            b"None" => Ok(BehavioutType::None),
            _ => Err("Unrecognized enum variant".into()),
        }
    }
}