404 lines · 13.9 KB · RustRaw
//! The wire shapes of Cotton Health's screens. Published early so the phone//! lanes draw against them (a `shapes.md` kept beside the work says the same//! in prose). Add-only: a field once shipped keeps its name and meaning; a//! new one is optional.//!//! ```text//! health.people {} → PeopleAnswer//! health.labs {person, q?} → LabsAnswer//! health.parameter {person, parameter? | name?} → ParameterAnswer//! health.reports {person} → ReportsAnswer//! health.report {id} → ReportAnswer//! health.body {person} → BodyAnswer//! health.metric {person, metric, days?} → MetricAnswer//! health.settings {platform, person?} → SettingsAnswer//! health.addReport {path, person? | newPerson?} → AddAnswer//! health.act {act, person?, id?, value?} → ActAnswer//! health.look {} → Look (kits/health/look.json)//! ```//!//! **The core decides; a phone draws.** Every word is the kit's (`health`//! line set), every act names the method and request a tap sends. No answer//! carries advice: a value and its range are said as the lab printed them,//! and a state is the lab's own interval applied to the lab's own value.use serde::{Deserialize, Serialize};use serde_json::Value;pub use crate::keys::app::shapes::{Act, Confirm, Mark, Toast, Tone};/// Tints a person's initials are drawn on (`tint.<n>` in the look).pub const TINTS: u32 = 8;/// Points a row's small trend carries at most.pub const TREND_POINTS: usize = 12;/// Rows "Changed most" holds at most.pub const CHANGED_ROWS: usize = 5;/// A value as drawn: its text, its unit, and whether the mono face draws it.#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]#[serde(rename_all = "camelCase")]pub struct Said { pub text: String, #[serde(default, skip_serializing_if = "String::is_empty")] pub unit: String, #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub mono: bool,}/// One point of a trend: a day and a number (canonical unit for a lab/// parameter, the metric's unit for Apple Health).#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct Point { pub day: String, pub value: f64, #[serde(default, skip_serializing_if = "Option::is_none")] pub min: Option<f64>, #[serde(default, skip_serializing_if = "Option::is_none")] pub max: Option<f64>, /// `apple_health` or `lab`, where both feed one history. #[serde(default, skip_serializing_if = "Option::is_none")] pub source: Option<String>, /// The point's own state, where it has one. #[serde(default, skip_serializing_if = "Option::is_none")] pub tone: Option<Tone>,}/// A screen with nothing on it yet.#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct Empty { pub title: String, pub body: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub act: Option<Act>,}// ── health.people ──────────────────────────────────────────────────────#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct PersonChip { /// The `person` row's id: what `person` means in every other request. pub id: String, pub name: String, pub initials: String, pub tint: u32, pub owner: bool, pub reports: u32, /// `"3 reports"`. pub detail: String, pub current: bool, pub act: Act,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct PeopleAnswer { pub title: String, /// The owner first, then by the order the owner keeps. pub people: Vec<PersonChip>, /// The person shown now (the owner when none is asked). #[serde(default, skip_serializing_if = "Option::is_none")] pub current: Option<String>, pub add: Act,}// ── health.labs ────────────────────────────────────────────────────────/// One parameter on the Labs screen: its latest reading and its trend.#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ParameterRow { /// The canonical parameter's id, or `name:<printed name folded>` for one not yet known. pub id: String, pub name: String, pub latest: Said, /// `"12 Mar 2024"`. pub day: String, pub mark: Mark, /// Oldest first, at most [`TREND_POINTS`]. pub trend: Vec<Point>, pub act: Act,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ChangeRow { pub row: ParameterRow, pub from: Said, pub to: Said, /// `"Up 12 mg/dL since 4 Jan 2024"`. pub change: String,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct Strip { pub out_title: String, pub out: Vec<ParameterRow>, pub changed_title: String, pub changed: Vec<ChangeRow>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct PanelSection { pub id: String, pub name: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub detail: Option<String>, pub rows: Vec<ParameterRow>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct LabsAnswer { pub person: String, pub title: String, pub search: String, pub strip: Strip, /// In the catalogue's medical order; only panels with a reading. pub panels: Vec<PanelSection>, /// Names not yet known, as printed. #[serde(default, skip_serializing_if = "Option::is_none")] pub other: Option<PanelSection>, #[serde(default, skip_serializing_if = "Option::is_none")] pub empty: Option<Empty>,}// ── health.parameter ───────────────────────────────────────────────────#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct Band { #[serde(default, skip_serializing_if = "Option::is_none")] pub low: Option<f64>, #[serde(default, skip_serializing_if = "Option::is_none")] pub high: Option<f64>, /// `"The lab's range: 70 to 100 mg/dL"`. pub said: String,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ReadingRow { pub day: String, pub said: Said, /// `"As printed: 1.9 mmol/L"`, when the printed unit is not the canonical one. #[serde(default, skip_serializing_if = "Option::is_none")] pub original: Option<String>, /// The interval as printed, lines joined. #[serde(default, skip_serializing_if = "String::is_empty")] pub interval: String, pub mark: Mark, #[serde(default, skip_serializing_if = "Option::is_none")] pub lab: Option<String>, #[serde(default, skip_serializing_if = "Option::is_none")] pub method: Option<String>, pub act: Act,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ParameterAnswer { pub id: String, pub title: String, /// What it is, in one plain line (or why it is shown as printed). pub line: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub panel: Option<String>, #[serde(default, skip_serializing_if = "Option::is_none")] pub loinc: Option<String>, #[serde(default, skip_serializing_if = "Option::is_none")] pub attribution: Option<String>, /// The unit `points` are in. pub unit: String, /// The latest reading's own in-range band, in `unit`. #[serde(default, skip_serializing_if = "Option::is_none")] pub band: Option<Band>, /// Oldest first. pub points: Vec<Point>, /// Newest first. pub readings: Vec<ReadingRow>, #[serde(default, skip_serializing_if = "Option::is_none")] pub empty: Option<Empty>,}// ── health.reports / health.report ─────────────────────────────────────#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ReportRow { pub id: String, pub title: String, pub day: String, pub status: Mark, /// `"24 results · 3 out of range"`. pub detail: String, pub act: Act,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ReportsAnswer { pub person: String, pub title: String, /// Newest first. pub rows: Vec<ReportRow>, pub add: Act, #[serde(default, skip_serializing_if = "Option::is_none")] pub empty: Option<Empty>,}#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct Fact { pub label: String, pub value: String,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ResultLine { pub name: String, pub said: Said, #[serde(default, skip_serializing_if = "String::is_empty")] pub range: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub method: Option<String>, pub mark: Mark, /// Opens the parameter's history. pub act: Act,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ReportSection { /// The panel title as printed. pub title: String, pub rows: Vec<ResultLine>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ReportAnswer { pub id: String, pub person: String, pub title: String, pub day: String, pub facts: Vec<Fact>, pub sections: Vec<ReportSection>, #[serde(default, skip_serializing_if = "Option::is_none")] pub pdf: Option<Act>, #[serde(default, skip_serializing_if = "Option::is_none")] pub notice: Option<String>,}// ── health.body / health.metric ────────────────────────────────────────#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct MetricRow { /// A `health_day` metric key, or `lab:<parameter>` for a report's vital. pub metric: String, pub label: String, pub latest: Said, pub day: String, pub trend: Vec<Point>, pub act: Act,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct BodySection { pub id: String, pub title: String, pub rows: Vec<MetricRow>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct BodyAnswer { pub person: String, /// Apple Health is the owner's: only the owner's Body reads it. pub owner: bool, pub title: String, pub sections: Vec<BodySection>, #[serde(default, skip_serializing_if = "Option::is_none")] pub connect: Option<Act>, #[serde(default, skip_serializing_if = "Option::is_none")] pub empty: Option<Empty>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct MetricAnswer { pub person: String, pub metric: String, pub title: String, pub unit: String, /// Oldest first; where a report's reading and Apple Health's meet, both, each with its source. pub points: Vec<Point>, /// Newest first, as said. pub readings: Vec<ReadingRow>,}// ── health.settings ────────────────────────────────────────────────────#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct SettingsRow { pub id: String, pub label: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub detail: Option<String>, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub acts: Vec<Act>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct SettingsSection { pub id: String, pub title: String, pub rows: Vec<SettingsRow>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct SettingsAnswer { pub title: String, pub sections: Vec<SettingsSection>,}// ── health.addReport / health.act ──────────────────────────────────────#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct AddAnswer { /// `added`, `updated`, `seen`, `older`, or a refusal: `no_text`, `locked`, `unreadable`, `no_table`. pub outcome: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub report: Option<String>, pub results: u32, pub matched: u32, /// Test names not yet known. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub unmatched: Vec<String>, pub toast: Toast, /// Opens the report, when one landed. #[serde(default, skip_serializing_if = "Option::is_none")] pub open: Option<Act>,}#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct ActAnswer { pub ok: bool, #[serde(default, skip_serializing_if = "Option::is_none")] pub toast: Option<Toast>, /// What the act hands back (`open_pdf`: `{key, contentType}`). #[serde(default, skip_serializing_if = "Value::is_null")] pub value: Value,}