1use std::sync::Arc;
2
3use opencv::{
4 Error,
5 core::{Point, Rect2i, Vector},
6};
7use uuid::Uuid;
8
9use crate::debug::{BpmOcrDebugOutputter, NoDebug, TempFolderDebugger};
10
11#[derive(Clone, Debug)]
12pub enum ReadingIdentificationError {
13 InternalError(&'static str),
14 CouldNotIdentifyReadings,
15 CouldNotIdentityLCDCandidate,
16 UnexpectedNumberOfRows,
17 CouldNotProcessSegments,
18}
19
20#[derive(Clone, Debug)]
21pub struct RejectedLcdScreenCandidate {
22 pub contour: Vector<Point>,
23}
24
25#[derive(Clone, Debug)]
26pub struct LcdScreenCandidate {
27 pub coordinates: Vector<Point>,
28 pub area: f64,
29 pub contour: Vector<Point>,
30}
31
32pub enum LcdScreenCandidateResult {
33 Success(LcdScreenCandidate),
34 Failure(RejectedLcdScreenCandidate),
35}
36
37#[derive(Debug)]
38pub enum ProcessingError {
39 ImageDetectionLibraryError(Error),
40 AppError(ReadingIdentificationError),
41}
42
43impl From<Error> for ProcessingError {
44 fn from(error: Error) -> Self {
45 return Self::ImageDetectionLibraryError(error);
46 }
47}
48
49#[derive(Clone, Debug)]
50pub(crate) struct RectangleCoordinates {
51 pub top_left: Point,
52 pub top_right: Point,
53 pub bottom_left: Point,
54 pub bottom_right: Point,
55}
56
57#[derive(Clone, Debug)]
58pub(crate) struct ReadingLocations {
59 pub systolic_region: Vec<Rect2i>,
60 pub diastolic_region: Vec<Rect2i>,
61 pub pulse_region: Vec<Rect2i>,
62}
63
64#[derive(Clone, Debug, PartialEq)]
65pub struct BloodPressureReading {
66 pub systolic: i32,
67 pub diastolic: i32,
68 pub pulse: i32,
69}
70
71pub struct DebuggerTrace<T: BpmOcrDebugOutputter> {
72 pub unique_trace_name: String,
73 pub debugger: Arc<T>,
74}
75
76impl DebuggerTrace<NoDebug> {
77 pub fn no_debug_session() -> Self {
78 DebuggerTrace {
79 debugger: Arc::new(NoDebug {}),
80 unique_trace_name: "".to_owned(),
81 }
82 }
83}
84
85impl DebuggerTrace<TempFolderDebugger> {
86 pub fn temp_folder_session(unique_session_name: &str) -> Self {
87 DebuggerTrace {
88 debugger: Arc::new(TempFolderDebugger::new(true)),
89 unique_trace_name: unique_session_name.to_owned(),
90 }
91 }
92
93 pub fn temp_folder_session_uuid() -> Self {
94 let uuid = Uuid::new_v4();
95 DebuggerTrace {
96 debugger: Arc::new(TempFolderDebugger::new(true)),
97 unique_trace_name: uuid.to_string(),
98 }
99 }
100}