Skip to main content

wellfare_core/anatomy/
mod.rs

1//! 3D Anatomy Qapp — **factor / body-system model** (the domain core both audience lenses build on).
2//!
3//! A [`Factor`] — any of {pathology finding, condition, medication, food, herb, tea, nutrient,
4//! supplement, lifestyle, environmental} — maps onto one or more **body systems** with an [`Effect`]
5//! (adverse / supportive / modulating), an [`EvidenceTier`], and a magnitude. From a person's active
6//! factors, [`accumulate`] rolls per-system burden, [`interactions`] finds compounding / opposing /
7//! herb–drug pairs, and [`systemic_implications`] emits **proposals** — never diagnoses.
8//!
9//! The `temporal` layer turns static factors into time-stamped [`FactorEvent`]s with **kinetics**
10//! (onset → clearance), [`EnvironmentModulator`]s, and per-system recovery trajectories — so the view
11//! can show that *different subsystems recover on different clocks and respond to different
12//! interventions* (the hot-week / beer / water example).
13//!
14//! **Honesty boundaries baked in:** every emitted [`SystemicImplication`] carries
15//! `EpistemicStatus::Hypothesis()` and the dominant evidence tier of its contributors; community /
16//! anecdotal claims sit at the lowest tier; temporal projection is coarse ([`RecoveryBand`] "hours vs
17//! days", never a BAC or a fitness-to-operate claim); no advice. The 17 systems mirror
18//! `bundled/qapps/Anatomy/Knowledge/system-map.json` so the native 3D view and this engine agree on
19//! identity.
20
21mod accumulate;
22mod birth;
23mod bridge;
24mod constitution;
25mod coverage;
26mod densitometry;
27mod dyad;
28mod factor;
29mod knowledge;
30mod knowledge_context;
31mod lens;
32mod measurements;
33mod model;
34mod observations;
35mod pathway;
36mod physiology;
37mod registry;
38mod scorecard;
39mod systems;
40mod temporal;
41
42pub use accumulate::{
43    Interaction, InteractionKind, SystemBurden, SystemicImplication, accumulate, interactions,
44    systemic_implications,
45};
46pub use birth::{
47    AgencyStage, BiometricClass, BirthRecordInvalid, CredentialRef, DigitalBirthRecord,
48    Guardianship, GuardianshipCredential, Steward, StewardBasis, StewardRole,
49};
50pub use bridge::{
51    BridgeResult, RecordRef, build_view_from_records, knowledge_key_candidates, records_to_factors,
52    records_to_timeline,
53};
54pub use constitution::{
55    AGE_MONTHS_RANGE, AbsenceReason, AbsentPart, AnatomicalCalibrationInput,
56    AnatomicalCalibrationResult, BodyAttributes, BodyCharacteristics, BodyConstitution, BodyFit,
57    BodyMeasurements, BoneAffineCorrection, BoneScaleLoading, BoneScaleTensor,
58    CalibrationObservation, DominantSide, OrganCavityTransfer, REF_INSEAM_RATIO,
59    REF_SITTING_RATIO, ReferenceGirths, SSDM_FEATURE_COUNT, SsdmBasis, SsdmDensityMode,
60    SsdmShapeMode, VH_FEMALE_STATURE_MM, VH_MALE_STATURE_MM, derive_anatomical_calibration,
61    harmonic_tps_organ_transfer,
62};
63pub use coverage::{SystemCoverage, seed_system_coverage, seed_system_coverage_markdown};
64pub use dyad::{
65    ConsiderationKind, DyadConsideration, DyadInvalid, EmergingChild, InterfaceKind, MaternalBody,
66    MaternalFetalDyad, Parentage, PrincipalRef, Progenitor, RightsStage, SocialRightsThreshold,
67};
68pub use factor::{Effect, EvidenceTier, Factor, FactorKind, FactorTarget};
69pub use knowledge::{
70    FactorKnowledge, ImportResult, KnowledgeBase, KnowledgeSource, KnowledgeTarget, Provenance,
71    import_condition_map, import_entries, seed_knowledge_base,
72};
73pub use knowledge_context::{
74    AncestryInvalid, AncestryRecord, ContextEdgeKind, EthnicityAffiliation, KnowledgeConsideration,
75    KnowledgeContextEdge, SubjectKnowledgeContext, affiliations_from_observations,
76    considerations_for_context, illustrative_context_pack,
77};
78pub use lens::{AnatomyView, Lens, SystemView, WellbeingLevel, build_view, burden_to_sigma};
79pub use measurements::{
80    CIRC_MM_RANGE, MEASUREMENT_CATALOG, MeasurementGroup, MeasurementInputUnit, MeasurementSpec,
81    MeasurementUse, STATURE_MM_RANGE, WEIGHT_G_RANGE, measurement_catalog_json,
82};
83pub use model::{
84    AnatomyModel, Karyotype, SystemRepresentation, body_system_for_organ, normalize_organ_key,
85    overlay_host_systems, system_memberships_for_organ, system_representation,
86};
87pub use densitometry::{
88    CallusHealingPhase, FractureCallusState, MobilityAndFractureRiskReport, MobilityTaskInput,
89    MuscleQualityProfile, MyologicalQualityProfile, PhysealFusionStatus,
90    SkeletalDensitometryProfile, SkeletalDensityProfile, SpeciesDensitometryPreset,
91    WhoDensityCategory, evaluate_mobility_and_fracture_risk,
92};
93pub use observations::{
94    AnatomicalObservationRecord, BodyObservation, InstrumentKind, KNOWN_OBSERVATION_CODES,
95    KnownObservationCode, RepresentationBind, bind_for_code, is_known_code,
96};
97pub use pathway::{
98    Hypothesis, InvestigativePathway, InvestigativeStep, RankedStep, StepKind,
99    hypotheses_from_implications, investigative_pathway, value_of_information,
100};
101pub use physiology::{
102    AgeOntogenyProfile, CyclePhase, EndocrineOsteoState, EngagementLevel, Handedness,
103    LateralityProfile, LimbDominance, OntogeneticStage, PhysiologicalModifierSummary,
104    PhysiologicalState, ReproductiveEndocrinePhase, ReproductiveState, SitusClassification,
105    StateModulator, SystemEngagement, Trimester, apply_physiological_modifiers_to_density,
106    state_modulator, whole_body_profile,
107};
108pub use registry::{
109    NEUTRAL_SYSTEM_RGBA, SystemDef, SystemProvenance, SystemRegistry, SystemRelation,
110    SystemRelationKind, SystemTier, default_registry,
111};
112pub use scorecard::{
113    Aspect, AspectScore, Contribution, ContributionKind, ForumClass, ScoreBand, ScoreCard,
114    SystemAspectWeight, WeightModel, score_card, seed_weight_model,
115};
116pub use systems::{BODY_SYSTEMS, BodySystem, body_system, body_system_by_label};
117pub use temporal::{
118    EnvironmentModulator, FactorEvent, Kinetics, RecoveryBand, Timeline, TrajectoryPoint,
119    recovery_band,
120};
121
122/// Canonical key for a system id (trims surrounding whitespace; identity otherwise). Shared so the
123/// accumulation and temporal layers group systems identically.
124pub(crate) fn system_key(id: &str) -> &str {
125    id.trim()
126}
127
128/// Push `id` into `v` iff absent (preserves first-seen order without a set allocation).
129pub(crate) fn push_unique(v: &mut Vec<String>, id: &str) {
130    if !v.iter().any(|x| x == id) {
131        v.push(id.to_string());
132    }
133}
134
135/// Lower-kebab a human label for use in a knowledge key (`"Type 2 Diabetes"` → `"type-2-diabetes"`).
136/// Shared by the knowledge importer, ethnicity tokens, and the record→factor bridge so keys line up.
137pub fn slugify(s: &str) -> String {
138    let mut out = String::with_capacity(s.len());
139    let mut prev_dash = false;
140    for c in s.chars() {
141        if c.is_ascii_alphanumeric() {
142            out.push(c.to_ascii_lowercase());
143            prev_dash = false;
144        } else if !prev_dash && !out.is_empty() {
145            out.push('-');
146            prev_dash = true;
147        }
148    }
149    out.trim_end_matches('-').to_string()
150}