Skip to main content

Crate clinlat

Crate clinlat 

Source
Expand description

§clinlat — Clinical Lattice Types

A Rust substrate for symbolic clinical decision-making based on refinable hypothesis lattices and sound deduction operators.

§Overview

The clinlat crate provides:

  • Hyp: A partially ordered set (poset) of clinical hypotheses, ordered by refinement.
  • Outcome<H, A>: A sum type for operator results (refined hypothesis or abstention).
  • Deduction operators: Sound functions that refine hypotheses using clinical evidence (e.g., sofa::SofaRespOperator for respiratory dysfunction severity).

§Architecture

§Hypotheses and Refinement

A Hyp represents a set of clinical atoms at some level of specificity. Hypotheses are ordered by refinement: h1 ⊑ h2 (h1 refines h2) means h1 is more specific.

let unknown = Hyp::unknown();  // Top element: no information.
let atom = Atom {
    system: OntologySystem::SNOMED,
    code: "67822003".to_string(),
    preferred_term: "Hypoxemia".to_string(),
    version: "2026-01-31".to_string(),
};
let specific = Hyp::new(vec![atom]);  // More specific.
assert!(specific < unknown);  // Refinement ordering.

§Operators

An Operator takes a hypothesis and evidence, producing an Outcome:

impl Operator for MyOperator {
    fn apply(&self, h: &Hyp, e: &Evidence) -> Outcome<Hyp, AbstainReason> {
        // Refine h using evidence e, or abstain with a reason.
    }
}

Operators are sound by construction: they satisfy three properties (DEF-PS-08):

  1. Refinement monotonicity: Hypothesis specificity never decreases.
  2. No spurious refinement: Output never exceeds evidence justification.
  3. Abstention purity: Abstention is structural, not error handling.

§SOFA-3 Respiratory Scoring

The sofa module implements one operator: SOFA-3 respiratory severity (PaO₂/FiO₂ ratio).

let evidence = SofaRespEvidence::new(350.0, 1.0, false);
let ratio = evidence.pao2_fio2_ratio().unwrap();
let score = score_from_ratio(ratio, false);  // Maps to SOFA score.
assert_eq!(score, Some(1));

§v0.2.0-alpha Status

Shipped (Phases 0–3 of the M1 milestone):

  • Atom replaces the v0.1.0 &'static str AtomId; resolved through four OntologyAdapter implementations (SNOMED CT, RxNorm, LOINC, ICD-11).
  • operator::Evidence is a typed struct carrying Observations and a Provenance carrier (DEF-PS-12, DEF-PS-13).
  • Provenance is a typed carrier with origin, timestamp, operator version, metadata, and optional derives_from hashes (DEF-MP-14, OBL-PS-04).
  • sofa::SofaRespOperator enforces the version-respecting derivation chain invariant (INV-PS-05) by abstaining on version mismatch rather than silently producing refined output.
  • Galois connection: operator::abstract_evidence (α_PS) and operator::is_consistent_with (the γ_PS predicate) are property-tested for the adjunction laws, discharging OBL-PS-02.

Deferred to later phases of the v0.2.0 cut:

  • OperatorSet formalization (Phase 4).
  • KDIGO AKI, Wells/PE, CURB-65 operators (Phase 5).
  • SOFA-respiratory property-test tier upgrade (Phase 6).

§References

  • Position: Substrate-First Clinical AI (NOTE.md § 4A–4D).
  • Formalization: SPEC.md § 2 (patient-state substrate).
  • SOFA-3: Vincent et al. (1996), Singer et al. (2016, Sepsis-3).

Re-exports§

pub use abstain::AbstainReason;
pub use curb65::Curb65Operator;
pub use hyp::Hyp;
pub use kdigo_aki::KdigoAkiOperator;
pub use lattice_search::LatticeSearchProposer;
pub use llm_proposer::LlmProposer;
pub use llm_proposer_config::LlmProposerConfig;
pub use llm_proposer_config::LlmProvider;
pub use ontology::Atom;
pub use ontology::CacheMode;
pub use ontology::Icd11Adapter;
pub use ontology::LoincAdapter;
pub use ontology::OntologyAdapter;
pub use ontology::OntologyError;
pub use ontology::OntologySystem;
pub use ontology::RxNormAdapter;
pub use ontology::SNOMEDAdapter;
pub use operator::Evidence;
pub use operator::Observation;
pub use operator::Operator;
pub use operator::abstract_evidence;
pub use operator::is_consistent_with;
pub use operator_set::OperatorMetadata;
pub use operator_set::OperatorSet;
pub use operator_set::SetOutcome;
pub use outcome::Outcome;
pub use proposer::CandidateSet;
pub use proposer::ConstraintError;
pub use proposer::FilterResult;
pub use proposer::ProposerConstraint;
pub use proposer::RefinementProposer;
pub use proposer::VerifyResult;
pub use proposer::propose_and_filter;
pub use proposer::propose_verify;
pub use provenance::Provenance;
pub use provenance::ProvenanceOrigin;
pub use sofa::SofaRespEvidence;
pub use sofa::SofaRespHypothesis;
pub use sofa::SofaRespOperator;
pub use version::Ver;
pub use wells_pe::WellsPeOperator;

Modules§

abstain
Abstention reasons for deduction operators.
curb65
CURB-65 operator for community-acquired pneumonia disposition.
hyp
Clinical hypotheses as a refinable poset.
kdigo_aki
KDIGO AKI staging operator.
lattice_search
Exhaustive lattice-search proposer.
llm_proposer
LLM-based refinement proposer adapter (task 10.2).
llm_proposer_config
Configuration for LLM-based refinement proposer.
ontology
Ontology adapter infrastructure for binding clinical atoms to external ontology systems.
operator
Deduction operators on hypotheses.
operator_set
Composition of multiple deduction operators.
outcome
Operator outcome types: refined hypothesis or abstention.
proposer
Refinement proposers: black-box candidate generators per DEF-PS-14 / DEF-PS-15.
provenance
Provenance carrier for tracking evidence source, timestamp, and version through operator derivations.
sofa
SOFA-3 respiratory component (PaO₂/FiO₂ ratio) deduction operator.
version
Version tuple for tracking operator and build versions in provenance chains.
wells_pe
Wells score operator for pulmonary embolism risk stratification.