Skip to main content

wellfare_core/
lib.rs

1pub mod anatomy;
2pub mod assessment;
3pub mod asset_aspects;
4pub mod authority_attestation;
5pub mod clinical;
6pub mod companion_pairing;
7pub mod companion_sync;
8pub mod conditions;
9pub mod credentials;
10pub mod guardianship;
11pub mod life_records;
12pub mod live_share;
13pub mod medication;
14pub mod mental_wellbeing;
15pub mod models;
16pub mod n3_rules;
17pub mod parser;
18pub mod personal_records;
19pub mod qualia_bindings;
20pub mod rdf;
21pub mod shapes;
22pub mod sleep_analytics;
23pub mod store;
24#[cfg(target_arch = "wasm32")]
25pub mod wasm;
26pub mod webizen;
27pub mod welfare_support;
28
29/// Single source of truth for record envelopes, double-entry finance, and cooperative projects.
30pub use qualia_cooperative_core::{finance, projects, record};
31
32/// Re-export the T71 bridge types so consumers can use them without
33/// qualifying through `record::`.
34pub use record::{DurationBridge, InstantBridge};
35
36/// Legacy coarse Unix timestamp (T71). To be replaced with
37/// `vibe::value::Instant` in a future migration. Until then,
38/// this is the bridge type. Do not add new uses — use Instant
39/// where possible.
40pub type AssertedTime = u32;
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    use chrono::Timelike;
47    use parser::*;
48    use rdf::*;
49
50    #[test]
51    fn asserted_time_type_alias_exists() {
52        // T71: AssertedTime is a type alias for u32, bridging to Instant.
53        let t: AssertedTime = 1700000000;
54        assert_eq!(t, 1700000000u32);
55        // Verify it's the same size as u32.
56        assert_eq!(
57            std::mem::size_of::<AssertedTime>(),
58            std::mem::size_of::<u32>()
59        );
60    }
61
62    #[test]
63    fn test_parse_time_offset_minutes() {
64        assert_eq!(parse_time_offset_minutes("60"), 60);
65        assert_eq!(parse_time_offset_minutes("UTC+1000"), 600);
66        assert_eq!(parse_time_offset_minutes("UTC-0500"), -300);
67        assert_eq!(parse_time_offset_minutes(""), 0);
68    }
69
70    #[test]
71    fn test_parse_samsung_datetime() {
72        let dt = parse_samsung_datetime("1777632000000", 60).unwrap();
73        assert_eq!(dt.timezone().local_minus_utc(), 3600);
74
75        let dt2 = parse_samsung_datetime("2026-05-25 12:00:00", 60).unwrap();
76        assert_eq!(dt2.timezone().local_minus_utc(), 3600);
77        assert_eq!(dt2.hour(), 12);
78    }
79
80    #[test]
81    fn test_parse_weight_csv() {
82        let csv_data = "uuid,start_time,end_time,time_offset,weight,body_fat,muscle_mass,body_water,skeletal_muscle,bmi\n\
83                        a1000001-0000-4000-8000-000000000001,1777632000000,1777632060000,60,72.0,18.5,32.1,55.2,30.5,23.1\n";
84        let records = parse_weight_csv(csv_data).unwrap();
85        assert_eq!(records.len(), 1);
86        assert_eq!(records[0].weight, 72.0);
87        assert_eq!(records[0].bmi, 23.1);
88
89        let rdf = weight_to_turtle(&records);
90        assert!(rdf.contains("fhir:Observation.valueQuantity 72"));
91        assert!(rdf.contains("health:bodyFatPercentage 18.5"));
92    }
93
94    #[test]
95    fn test_parse_sleep_csv() {
96        let csv_data = "uuid,start_time,end_time,time_offset,sleep_duration,efficiency,deep_sleep,rem_sleep,light_sleep,wake_up_count\n\
97                        b2000001-0000-4000-8000-000000000001,1777681200000,1777707600000,60,440,78,90,110,240,0\n";
98        let records = parse_sleep_csv(csv_data).unwrap();
99        assert_eq!(records.len(), 1);
100        assert_eq!(records[0].sleep_duration, 440.0);
101        assert_eq!(records[0].efficiency, 78.0);
102
103        let rdf = sleep_to_turtle(&records);
104        assert!(rdf.contains("health:sleepEfficiency 78"));
105    }
106
107    #[test]
108    fn test_parse_heart_rate_csv() {
109        let csv_data = "uuid,start_time,time_offset,heart_rate,min,max,heart_rate_zone,binning_data\n\
110                        c3000001-0000-4000-8000-000000000001,1777668000000,60,68,58,120,rest,hr_bin_0.json\n";
111        let records = parse_heart_rate_csv(csv_data).unwrap();
112        assert_eq!(records.len(), 1);
113        assert_eq!(records[0].heart_rate, 68);
114
115        let rdf = heart_rate_to_turtle(&records);
116        assert!(rdf.contains("fhir:Observation.valueQuantity 68"));
117    }
118
119    #[test]
120    fn test_parse_steps_csv() {
121        let csv_data = "uuid,start_time,end_time,time_offset,count,calorie,distance\n\
122                        e5000001-0000-4000-8000-000000000001,1777632000000,1777718340000,60,6500,210,4800\n";
123        let records = parse_steps_csv(csv_data).unwrap();
124        assert_eq!(records.len(), 1);
125        assert_eq!(records[0].count, 6500);
126
127        let rdf = steps_to_turtle(&records);
128        assert!(rdf.contains("fhir:Observation.valueQuantity 6500"));
129        assert!(rdf.contains("health:caloriesBurned 210"));
130    }
131}