Skip to main content

Chapter 24 F
Medical triage

Practical Demonstrations
Author: Mark Higgins
and Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 19 July 2026
Audio Overview
flow "MedicalTriage" v1.0

# =============================================================================
# CHAPTER 24 F
# MEDICAL TRIAGE
# =============================================================================
#
# PURPOSE
#
# Receive a person's reported symptoms and available contextual information,
# identify time-critical warning signs, estimate the safest required level of
# care, and produce a clear action recommendation.
#
# The flow does not diagnose disease.
#
# It performs constrained clinical routing:
#
#   Reported Concern
#       → Immediate Danger Screening
#       → Information Sufficiency Check
#       → Symptom Structuring
#       → Risk-Factor Evaluation
#       → Urgency Classification
#       → Safety-Net Construction
#       → Human-Care Escalation
#
# Triage is defined as a safety-preserving classification problem.
#
# The primary objective is not to identify the most likely diagnosis.
#
# The primary objective is to prevent dangerous delay.
#
# =============================================================================
# AUTHORS
# =============================================================================
#
# Mark Higgins
# Sky — Recursive AI
#
# Kireth Research
# https://kirethresearch.org
#
# This specification must be cited when reproduced, implemented or adapted.
#
# =============================================================================


# =============================================================================
# 0. EXECUTION STATUS
# =============================================================================

execution.mode:
  type: constrained_safety_critical_triage
  domain: health
  diagnostic_authority: false
  prescribing_authority: false
  emergency_override_enabled: true
  uncertainty_preservation_required: true
  human_escalation_required: true
  silent_risk_downgrade_allowed: false
  unsupported_reassurance_allowed: false
  definitive_diagnosis_allowed: false
  autonomous_treatment_allowed: false

execution.objective:

  determine:

    safest_disposition

  such_that:

    - immediate_threats_are_prioritised
    - dangerous_delay_is_minimised
    - uncertainty_never_reduces_required_urgency
    - vulnerable_people_receive_lower_escalation_thresholds
    - emergency_signs_override_non_emergency_signs
    - recommendations_remain_within_triage_scope
    - every recommendation includes a safety_net
    - human clinical assessment remains available


# =============================================================================
# 1. SCOPE BOUNDARY
# =============================================================================

scope.permitted:

  - identify reported emergency warning signs
  - organise symptom information
  - identify missing safety-critical information
  - estimate urgency category
  - recommend an appropriate care pathway
  - explain why escalation is recommended
  - provide conservative interim safety instructions
  - provide explicit deterioration instructions
  - state uncertainty
  - request only safety-relevant follow-up information

scope.prohibited:

  - provide definitive diagnosis
  - exclude serious disease with certainty
  - prescribe prescription-only medication
  - recommend changing prescribed medication
  - calculate a personalised drug dose without an authorised protocol
  - tell a person to ignore worsening symptoms
  - use statistical likelihood to override a red flag
  - delay emergency action while collecting non-essential information
  - claim that remote triage replaces physical examination
  - fabricate observations, measurements or medical history
  - infer absence of a symptom merely because it was not mentioned


# =============================================================================
# 2. INPUT CONTRACT
# =============================================================================

io.read:

  format: structured_or_natural_language

  required:

    - presenting_concern:
        type: str
        description:
          The symptom, injury, behavioural change, health concern or event
          reported by the person or by someone assisting them.

  optional:

    - reporter:
        type: enum?
        values:
          - patient
          - parent
          - guardian
          - carer
          - relative
          - witness
          - clinician
          - unknown

    - patient_age:
        type: number?

    - age_unit:
        type: enum?
        values:
          - hours
          - days
          - weeks
          - months
          - years

    - sex_at_birth:
        type: enum?
        values:
          - female
          - male
          - intersex
          - unknown
          - not_provided

    - pregnancy_status:
        type: enum?
        values:
          - pregnant
          - possibly_pregnant
          - postpartum
          - not_pregnant
          - not_applicable
          - unknown

    - postpartum_days:
        type: int?

    - symptoms:
        type: list<object>?

    - symptom_onset:
        type: datetime_or_duration?

    - symptom_duration:
        type: duration?

    - symptom_progression:
        type: enum?
        values:
          - sudden
          - improving
          - unchanged
          - worsening
          - fluctuating
          - recurring
          - unknown

    - severity_reported:
        type: enum?
        values:
          - mild
          - moderate
          - severe
          - unbearable
          - unknown

    - pain_score:
        type: number?
        valid_range:
          minimum: 0
          maximum: 10

    - vital_signs:
        type: object?
        fields:
          temperature: number?
          heart_rate: number?
          respiratory_rate: number?
          oxygen_saturation: number?
          systolic_blood_pressure: number?
          diastolic_blood_pressure: number?
          blood_glucose: number?
          consciousness_scale: str?
          measurement_units: object?
          measurement_time: datetime?
          measurement_source: str?

    - mental_status:
        type: object?
        fields:
          alertness: str?
          orientation: str?
          confusion: bool?
          unusual_drowsiness: bool?
          responsiveness: str?

    - breathing_status:
        type: object?
        fields:
          difficulty_breathing: bool?
          unable_to_speak_full_sentences: bool?
          blue_or_grey_colour: bool?
          noisy_breathing: bool?
          choking: bool?
          breathing_stopped: bool?

    - circulation_status:
        type: object?
        fields:
          severe_bleeding: bool?
          fainting: bool?
          clammy_skin: bool?
          collapse: bool?
          weak_or_absent_pulse_reported: bool?

    - neurological_status:
        type: object?
        fields:
          new_weakness: bool?
          facial_droop: bool?
          speech_change: bool?
          seizure: bool?
          severe_sudden_headache: bool?
          new_loss_of_consciousness: bool?
          new_confusion: bool?

    - injury_details:
        type: object?
        fields:
          mechanism: str?
          body_area: str?
          high_energy: bool?
          head_injury: bool?
          neck_or_spine_concern: bool?
          penetrating_injury: bool?
          burn: bool?
          chemical_exposure: bool?
          electrical_injury: bool?
          suspected_fracture: bool?
          loss_of_function: bool?

    - exposure_details:
        type: object?
        fields:
          substance: str?
          amount: str?
          route: str?
          time: datetime_or_duration?
          intentional: bool?
          accidental: bool?
          unknown_substance: bool?

    - medical_history:
        type: list<str>?

    - current_medications:
        type: list<str>?

    - allergies:
        type: list<str>?

    - immune_status:
        type: enum?
        values:
          - immunocompetent
          - immunocompromised
          - unknown

    - recent_surgery:
        type: object?

    - recent_childbirth:
        type: object?

    - communication_needs:
        type: object?

    - location:
        type: object?
        fields:
          country: str?
          region: str?
          setting: str?
          alone: bool?
          safe_transport_available: bool?

    - local_care_pathways:
        type: object?
        description:
          Configurable emergency, urgent-care, primary-care and poison-service
          pathways for the patient's jurisdiction.

    - clinical_protocol:
        type: object?
        description:
          Optional authorised triage protocol supplied by a healthcare service.

    - maximum_question_cycles:
        type: int
        default: 3
        minimum: 0
        maximum: 6


# =============================================================================
# 3. OUTPUT CONTRACT
# =============================================================================

io.write:

  format: structured_triage_result

  schema:

    - status:
        type: enum
        values:
          - EMERGENCY
          - URGENT_SAME_DAY
          - PROMPT_CLINICAL_REVIEW
          - ROUTINE_REVIEW
          - SELF_CARE_WITH_SAFETY_NET
          - INSUFFICIENT_INFORMATION
          - UNABLE_TO_TRIAGE_SAFELY

    - urgency_level:
        type: enum
        values:
          - LEVEL_1_IMMEDIATE
          - LEVEL_2_URGENT
          - LEVEL_3_PROMPT
          - LEVEL_4_ROUTINE
          - LEVEL_5_SELF_CARE
          - LEVEL_U_UNRESOLVED

    - immediate_action:
        type: str

    - escalation_path:
        type: object

    - reasons:
        type: list<object>

    - detected_red_flags:
        type: list<object>

    - vulnerability_factors:
        type: list<object>

    - relevant_reported_information:
        type: list<object>

    - critical_unknowns:
        type: list<object>

    - safety_net:
        type: list<str>

    - interim_actions:
        type: list<str>

    - prohibited_actions:
        type: list<str>

    - uncertainty_statement:
        type: str

    - diagnostic_statement:
        type: str

    - audit_trace:
        type: object


# =============================================================================
# 4. TRIAGE LEVELS
# =============================================================================

triage.levels:

  LEVEL_1_IMMEDIATE:

    meaning:
      A reported or reasonably suspected immediate threat to life, limb,
      consciousness, breathing, circulation or rapidly deteriorating health.

    required_action:
      Immediate emergency response.

    information_collection_rule:
      Ask no question that would delay emergency action.

    acceptable_destinations:
      - emergency_services
      - emergency_department
      - immediate_resuscitation_response
      - authorised_emergency_pathway


  LEVEL_2_URGENT:

    meaning:
      A potentially serious condition requiring urgent clinical assessment,
      normally without waiting for a routine appointment.

    required_action:
      Same-day or jurisdiction-defined urgent clinical assessment.

    acceptable_destinations:
      - urgent_clinical_service
      - same_day_primary_care
      - emergency_department_when_required
      - maternity_assessment
      - urgent_mental_health_service
      - poison_information_service
      - authorised_specialist_pathway


  LEVEL_3_PROMPT:

    meaning:
      Symptoms are not currently classified as an immediate emergency but
      require timely professional review because of persistence, progression,
      risk factors, functional impairment or uncertainty.

    required_action:
      Prompt clinical assessment within the time boundary defined by the
      authorised local protocol.

    acceptable_destinations:
      - primary_care
      - community_clinical_service
      - pharmacy_when_within_scope
      - authorised_specialist_service


  LEVEL_4_ROUTINE:

    meaning:
      A stable concern suitable for a routine healthcare appointment, provided
      no deterioration or red flag develops.

    required_action:
      Arrange routine assessment and monitor for change.


  LEVEL_5_SELF_CARE:

    meaning:
      A low-risk, mild, stable or improving concern for which conservative
      self-care may be reasonable, provided a complete safety net is supplied.

    required_action:
      Conservative self-care and monitoring.

    restriction:
      This classification may not be used when critical information is missing
      or a vulnerable-person modifier remains unresolved.


  LEVEL_U_UNRESOLVED:

    meaning:
      Available information is too incomplete, contradictory or unreliable to
      classify safely.

    required_action:
      Escalate to human clinical assessment at the safest reasonable level.


# =============================================================================
# 5. CORE STATE
# =============================================================================

state S := {

  input: {
    raw_concern,
    reporter,
    patient_identity_context,
    symptoms,
    observations,
    history,
    medications,
    allergies,
    exposures,
    injuries,
    location,
    authorised_protocol
  },

  normalised: {
    age_group,
    symptom_entities,
    onset,
    duration,
    progression,
    severity,
    body_systems,
    functional_effect,
    known_vitals,
    unknown_vitals,
    reported_negatives,
    unknown_findings
  },

  safety: {
    immediate_danger_signals,
    red_flags,
    deterioration_signals,
    vulnerability_factors,
    high_risk_contexts,
    information_reliability,
    critical_unknowns
  },

  hypotheses: {
    prohibited_diagnoses,
    symptom_patterns,
    urgency_explanations,
    alternative_risk_paths
  },

  classification: {
    base_level,
    vulnerability_adjustment,
    uncertainty_adjustment,
    final_level,
    disposition
  },

  communication: {
    immediate_instruction,
    rationale,
    questions,
    interim_actions,
    prohibited_actions,
    safety_net,
    uncertainty_statement
  },

  trace: {
    evidence_to_flag,
    flag_to_rule,
    rule_to_level,
    level_to_action
  },

  result: {
    status,
    urgency_level,
    escalation_path,
    audit_trace
  }
}


# =============================================================================
# 6. PRIMARY SETS
# =============================================================================

E := set of explicitly reported evidence

N := set of explicitly reported negative findings

U := set of unknown or unavailable findings

R := set of emergency red flags

D := set of deterioration indicators

V := set of vulnerability modifiers

H := set of high-risk contexts

Q := set of safety-critical questions

A := set of permissible actions

P := set of prohibited actions

L := {
  LEVEL_1_IMMEDIATE,
  LEVEL_2_URGENT,
  LEVEL_3_PROMPT,
  LEVEL_4_ROUTINE,
  LEVEL_5_SELF_CARE,
  LEVEL_U_UNRESOLVED
}


# =============================================================================
# 7. EVIDENCE STATES
# =============================================================================

evidence.state:

  PRESENT:
    meaning:
      The finding was directly reported or supplied.

  ABSENT_REPORTED:
    meaning:
      The reporter explicitly stated that the finding is absent.

  UNKNOWN:
    meaning:
      The finding was not reported, could not be assessed, or was unclear.

  CONTRADICTORY:
    meaning:
      Supplied statements conflict.

  UNRELIABLE:
    meaning:
      The observation may not be dependable because of communication,
      measurement, cognition, intoxication, age, distress or reporter limits.


# =============================================================================
# 8. GLOBAL SAFETY INVARIANTS
# =============================================================================

invariant K1_NO_DIAGNOSIS:

  output must_not assert:
    "You have [disease]"
    or
    "This is definitely [disease]"
    or
    "This cannot be serious"

  output may state:
    - reported symptoms
    - risk patterns
    - why assessment is needed
    - that several causes are possible


invariant K2_RED_FLAG_DOMINANCE:

  if exists r in R where r.status == PRESENT:

    final_level := LEVEL_1_IMMEDIATE

  unless an authorised clinical protocol explicitly maps that exact finding to
  a different emergency pathway of equal or greater safety.


invariant K3_UNKNOWN_IS_NOT_NEGATIVE:

  for every clinical finding f:

    if f not_explicitly_reported:

      state(f) := UNKNOWN

    state(f) must_not_become ABSENT_REPORTED


invariant K4_NO_FALSE_REASSURANCE:

  reassurance_allowed only_if:

    - no emergency red flag is present
    - no unresolved emergency red flag remains
    - information is sufficient for the proposed level
    - symptom trajectory is not rapidly worsening
    - vulnerability modifiers have been applied
    - safety net is supplied


invariant K5_UNCERTAINTY_ESCALATES:

  if uncertainty affects the exclusion of a serious pathway:

    urgency must_not_decrease

    and:

    final_level :=
      at_least(
        base_level,
        safest_level_required_by_uncertainty
      )


invariant K6_VULNERABILITY_ESCALATES:

  presence of a vulnerability factor may:
    - increase urgency
    - lower the threshold for human review
    - prohibit self-care-only classification

  presence of a vulnerability factor must_not reduce urgency


invariant K7_DETERIORATION_ESCALATES:

  if symptoms are rapidly worsening:

    final_level must_be at_least LEVEL_2_URGENT

  if deterioration includes airway, breathing, circulation, consciousness,
  severe neurological change or collapse:

    final_level := LEVEL_1_IMMEDIATE


invariant K8_EMERGENCY_ACTION_PRECEDES_QUESTIONS:

  if emergency_threshold_met == true:

    emit immediate emergency action before:
      - detailed history
      - differential reasoning
      - non-essential questions
      - self-care advice


invariant K9_NO_DELAY:

  no recommendation may tell the person to:

    - wait for symptoms to become worse before seeking emergency help
    - drive themselves when unsafe
    - remain alone when immediate deterioration is possible
    - continue an activity causing active danger
    - delay care in order to complete the triage dialogue


invariant K10_HUMAN_OVERRIDE:

  if the person or reporter believes the situation is immediately dangerous:

    emergency escalation remains permitted regardless of computed score.


invariant K11_NO_SCORE_ONLY_DECISION:

  no arithmetic score may override:

    - a present red flag
    - rapid deterioration
    - clinical instinct from an authorised clinician
    - an authorised emergency protocol
    - inability to assess safely


invariant K12_CHILD_SAFETY:

  for infants and children:

    - age-specific thresholds must be used when supplied
    - caregiver concern is relevant evidence
    - reduced responsiveness, breathing difficulty, seizure, concerning colour,
      severe dehydration or rapid deterioration trigger escalation
    - adult thresholds must_not be silently applied


invariant K13_PREGNANCY_SAFETY:

  pregnancy or recent childbirth must activate pregnancy-specific and
  postpartum-specific risk review.

  general adult reassurance must_not bypass maternity warning signs.


invariant K14_MEDICATION_SAFETY:

  flow must_not instruct the person to:

    - stop prescribed medication
    - double a medication dose
    - combine medicines without safety validation
    - take another person's medication
    - take a medicine despite a reported allergy or contraindication


invariant K15_COMPLETE_SAFETY_NET:

  every non-emergency disposition must include:

    - what change requires escalation
    - where to seek help
    - when to seek help
    - what to do if the person cannot access the recommended service
    - instruction to seek emergency help for immediate danger


invariant K16_AUDITABILITY:

  every final urgency classification must be traceable through:

    reported_evidence
      → activated_rule
      → urgency_level
      → recommended_action


# =============================================================================
# 9. AGE NORMALISATION
# =============================================================================

stage 1 "NORMALISE_AGE":

  if patient_age is unknown:

    age_group := UNKNOWN

  else:

    convert patient_age and age_unit into comparable age representation

    classify:

      NEONATE:
        age < 28 days

      YOUNG_INFANT:
        age >= 28 days
        and age < 3 months

      INFANT:
        age >= 3 months
        and age < 1 year

      CHILD:
        age >= 1 year
        and age < jurisdiction_adult_age

      ADULT:
        age >= jurisdiction_adult_age
        and age < older_adult_threshold

      OLDER_ADULT:
        age >= older_adult_threshold

  record age_group certainty:

    - confirmed
    - estimated
    - unknown


# =============================================================================
# 10. INPUT INGESTION
# =============================================================================

stage 2 "INGEST_PRESENTING_CONCERN":

  raw_concern := normalise_whitespace(presenting_concern)

  if raw_concern == empty:

    result.status := INSUFFICIENT_INFORMATION

    request:
      "Please describe the main symptom, injury or health concern."

    halt unless immediate danger is otherwise reported

  preserve reporter wording for:

    - severe
    - sudden
    - worst
    - cannot
    - stopped
    - collapsed
    - choking
    - unconscious
    - bleeding
    - suicidal
    - poisoned
    - deteriorating

  do not weaken severity terms during normalisation


# =============================================================================
# 11. SYMPTOM STRUCTURING
# =============================================================================

stage 3 "STRUCTURE_REPORTED_INFORMATION":

  symptom_entities :=
    extract_symptoms(raw_concern, symptoms)

  for each symptom:

    record:

      - symptom_name
      - reporter_language
      - body_location
      - onset
      - duration
      - progression
      - severity
      - frequency
      - triggers
      - relieving_factors
      - associated_findings
      - explicit_negative_findings
      - functional_effect
      - confidence
      - source

  normalise without diagnosing:

    "cannot catch breath"
      → breathing_difficulty_reported

    "passed out"
      → transient_loss_of_consciousness_reported

    "face dropped"
      → facial_asymmetry_reported

    "not making sense"
      → altered_mental_status_reported

    "won't wake up"
      → reduced_responsiveness_reported

    "blood pouring out"
      → uncontrolled_bleeding_reported

  prohibit conversion:

    symptom
      → definitive disease label


# =============================================================================
# 12. INFORMATION RELIABILITY
# =============================================================================

stage 4 "ASSESS_INFORMATION_RELIABILITY":

  information_reliability := HIGH

  lower reliability when:

    - reporter is not with the patient
    - patient cannot communicate
    - patient is confused
    - patient is very young
    - language barrier is unresolved
    - hearing or communication need is unresolved
    - reporter is uncertain
    - measurement units are unknown
    - vital measurement source is unreliable
    - statements conflict
    - intoxication is reported
    - memory of event is impaired
    - remote visual assessment is impossible

  reliability levels:

    HIGH
    MODERATE
    LOW
    UNUSABLE

  rule:

    lower information reliability must_not lower urgency


# =============================================================================
# 13. IMMEDIATE AIRWAY SCREEN
# =============================================================================

stage 5 "SCREEN_AIRWAY":

  airway_red_flags := detect any:

    - choking
    - complete_or_near_complete_airway_obstruction
    - unable_to_breathe
    - unable_to_speak_or_cry_due_to_airway_problem
    - rapidly_progressing_face_tongue_or_throat_swelling
    - severe_allergic_reaction_with_airway_symptoms
    - abnormal_airway_noise_with_distress
    - unresponsive_person_with_airway_concern

  for each detected finding:

    R.add({
      category: AIRWAY,
      evidence: source_statement,
      status: PRESENT,
      severity: HARD,
      required_level: LEVEL_1_IMMEDIATE
    })


# =============================================================================
# 14. IMMEDIATE BREATHING SCREEN
# =============================================================================

stage 6 "SCREEN_BREATHING":

  breathing_red_flags := detect any:

    - breathing_stopped
    - severe_difficulty_breathing
    - gasping
    - blue_grey_or_markedly_pale_colour_with_illness
    - unable_to_speak_full_sentences_due_to_breathlessness
    - severe_chest_tightness_with_breathing_difficulty
    - sudden_breathlessness_with_collapse
    - exhaustion_or_reduced_responsiveness_during_breathing_problem
    - severe_asthma_pattern_not_responding_to_authorised_rescue_plan
    - breathing_problem_after_allergen_exposure
    - breathing_problem_after_injury
    - rapidly_worsening_respiratory_distress

  if present:

    R.add each as:
      required_level: LEVEL_1_IMMEDIATE


# =============================================================================
# 15. IMMEDIATE CIRCULATION SCREEN
# =============================================================================

stage 7 "SCREEN_CIRCULATION":

  circulation_red_flags := detect any:

    - uncontrolled_severe_bleeding
    - collapse
    - unresponsive_or_difficult_to_wake
    - absent_normal_breathing
    - suspected_cardiac_arrest
    - severe_chest_pressure_or_pain_with_high_risk_features
    - signs_of_shock
    - catastrophic_injury
    - sudden_extreme_weakness_with_clammy_or_grey_appearance
    - vomiting_or_coughing_large_amounts_of_blood
    - severe_internal_bleeding_concern
    - rapidly_expanding_bleeding_or_swelling

  if present:

    R.add each as:
      required_level: LEVEL_1_IMMEDIATE


# =============================================================================
# 16. IMMEDIATE NEUROLOGICAL SCREEN
# =============================================================================

stage 8 "SCREEN_NEUROLOGICAL_EMERGENCY":

  neurological_red_flags := detect any:

    - new_facial_droop
    - new_one_sided_weakness
    - new_speech_difficulty
    - sudden_new_loss_of_vision
    - sudden_new_severe_balance_loss
    - sudden_severe_headache_with_abrupt_onset
    - seizure_currently_continuing
    - repeated_seizures_without_recovery
    - first_seizure_with_concerning_features
    - new_loss_of_consciousness
    - markedly_reduced_responsiveness
    - acute_confusion_with_severe_illness
    - neck_stiffness_with_severe_illness_or_rash
    - neurological_change_after_head_injury
    - new_paralysis
    - sudden_loss_of_bladder_or_bowel_control_with_spinal_symptoms

  if present:

    R.add each as:
      required_level: LEVEL_1_IMMEDIATE


# =============================================================================
# 17. IMMEDIATE INJURY SCREEN
# =============================================================================

stage 9 "SCREEN_MAJOR_INJURY":

  major_injury_red_flags := detect any:

    - severe_head_injury
    - loss_of_consciousness_after_injury
    - suspected_neck_or_spinal_injury
    - penetrating_injury_to_head_neck_chest_abdomen_or_major_vessel
    - major_crush_injury
    - traumatic_amputation
    - uncontrolled_bleeding
    - open_fracture_with_severe_bleeding
    - limb_without_normal_colour_warmth_sensation_or_movement
    - major_burn
    - electrical_injury_with_systemic_symptoms
    - chemical_exposure_to_eye_airway_or_large_body_area
    - high_energy_mechanism_with_concerning_symptoms
    - drowning_or_near_drowning
    - collapse_after_exertion_or_trauma

  if present:

    R.add each as:
      required_level: LEVEL_1_IMMEDIATE


# =============================================================================
# 18. POISONING AND OVERDOSE SCREEN
# =============================================================================

stage 10 "SCREEN_POISONING":

  poisoning_red_flags := detect any:

    - suspected_overdose
    - intentional_ingestion
    - unknown_substance_ingestion
    - toxic_gas_exposure
    - altered_consciousness_after_exposure
    - breathing_problem_after_exposure
    - seizure_after_exposure
    - corrosive_ingestion
    - dangerous_household_or_industrial_chemical_exposure
    - medication_error_with_potential_for_serious_harm
    - child_ingestion_of_unknown_or_potentially_harmful_substance

  action rules:

    if immediate life threat present:

      required_level := LEVEL_1_IMMEDIATE

    else:

      required_level := LEVEL_2_URGENT

      route_to:
        authorised_poison_or_urgent_clinical_service

  prohibit:

    - inducing_vomiting_without_authorised_instruction
    - giving_food_or_drink_when_unsafe
    - waiting_for_symptoms_before_seeking_advice
    - guessing_toxicity_from_amount_alone


# =============================================================================
# 19. MENTAL HEALTH EMERGENCY SCREEN
# =============================================================================

stage 11 "SCREEN_MENTAL_HEALTH_EMERGENCY":

  mental_health_red_flags := detect any:

    - current_intent_to_die
    - active_suicide_plan
    - suicide_attempt
    - immediate_self_harm_risk
    - immediate_risk_to_another_person
    - severe_agitation_with_danger
    - hallucination_or_delusion_causing_immediate_danger
    - inability_to_maintain_basic_safety
    - severe_confusion_or_disorientation
    - missing_vulnerable_person_with_immediate_risk
    - overdose_or_injury_associated_with_self_harm

  if immediate danger:

    R.add({
      category: MENTAL_HEALTH,
      required_level: LEVEL_1_IMMEDIATE
    })

  safety actions:

    - connect to emergency or crisis pathway
    - encourage presence of a trusted responsible person when safe
    - reduce access to immediate means when this can be done safely
    - do not leave a person at imminent risk alone
    - avoid confrontation
    - preserve reporter and patient safety

  prohibit:

    - moral judgement
    - dismissing threats as attention seeking
    - promising secrecy when immediate safety is at risk
    - using reassurance as a substitute for escalation


# =============================================================================
# 20. PREGNANCY AND POSTPARTUM SCREEN
# =============================================================================

stage 12 "SCREEN_PREGNANCY_AND_POSTPARTUM":

  activate when:

    pregnancy_status in:
      - pregnant
      - possibly_pregnant
      - postpartum

  pregnancy_red_flags := detect any:

    - heavy_vaginal_bleeding
    - severe_abdominal_or_pelvic_pain
    - collapse_or_fainting
    - seizure
    - severe_breathing_difficulty
    - severe_chest_pain
    - severe_headache_with_visual_or_neurological_change
    - possible_ectopic_pregnancy_pattern
    - umbilical_cord_or_baby_presenting
    - urge_to_push_or_birth_imminent
    - severe_trauma
    - significant_reduction_in_expected_fetal_movement
    - signs_of_severe_infection
    - postpartum_heavy_bleeding
    - postpartum_collapse
    - postpartum_severe_headache_or_neurological_change
    - postpartum_breathlessness_or_chest_pain
    - immediate_mental_health_risk_after_birth

  classify:

    immediate threat
      → LEVEL_1_IMMEDIATE

    urgent maternity concern without immediate collapse
      → at_least LEVEL_2_URGENT

  route_to:
    - emergency_service
    - maternity_assessment
    - authorised_obstetric_pathway


# =============================================================================
# 21. INFANT AND CHILD SCREEN
# =============================================================================

stage 13 "SCREEN_PAEDIATRIC_RISK":

  activate when age_group in:

    - NEONATE
    - YOUNG_INFANT
    - INFANT
    - CHILD

  paediatric_high_risk_findings := detect any:

    - difficulty_breathing
    - reduced_responsiveness
    - child_is_floppy
    - seizure
    - blue_grey_or_markedly_pale_colour
    - non_blanching_rash_with_illness
    - severe_dehydration_pattern
    - persistent_inconsolable_crying_with_severe_illness
    - bulging_fontanelle_with_illness
    - rapidly_worsening_condition
    - serious_injury
    - suspected_poisoning
    - caregiver_reports_child_is_very_unwell
    - inability_to_feed_in_young_infant
    - significantly_reduced_urine_output
    - abnormal_temperature_in_age_group_under_authorised_protocol

  rule:

    neonate_or_young_infant
    with:
      - fever
      - marked_temperature_abnormality
      - poor_feeding
      - unusual_sleepiness
      - breathing_change
      - colour_change
      - caregiver_concern

    requires:
      at_least LEVEL_2_URGENT

    unless immediate red flag:
      LEVEL_1_IMMEDIATE


# =============================================================================
# 22. GENERAL HIGH-RISK SYMPTOM SCREEN
# =============================================================================

stage 14 "SCREEN_HIGH_RISK_PATTERNS":

  evaluate symptom groups without assigning diagnosis:

    chest_pattern:
      - severe_or_persistent_chest_pain
      - pressure_tightness_or_heaviness
      - pain_with_breathlessness
      - pain_with_sweating_nausea_or_collapse
      - pain_spreading_to_arm_back_neck_or_jaw
      - chest_symptoms_in_high_risk_person

    abdominal_pattern:
      - sudden_severe_abdominal_pain
      - rigid_or_severely_tender_abdomen_reported
      - pain_with_collapse
      - pain_with_heavy_bleeding
      - persistent_vomiting_with_dehydration
      - blood_in_vomit_or_stool
      - pregnancy_related_abdominal_pain

    infection_pattern:
      - severe_systemic_illness
      - rapid_deterioration
      - confusion
      - breathing_difficulty
      - non_blanching_rash
      - severe_dehydration
      - immunocompromised_person_with_concerning_symptoms
      - recent_surgery_with_deterioration

    allergic_pattern:
      - tongue_or_throat_swelling
      - breathing_difficulty
      - collapse
      - widespread_reaction_with_airway_or_circulatory_symptoms

    dehydration_pattern:
      - inability_to_keep_fluids_down
      - very_low_urine_output
      - marked_drowsiness
      - collapse
      - dry_mouth_and_progressive_weakness
      - vulnerable_age_group

    eye_pattern:
      - sudden_loss_of_vision
      - severe_eye_injury
      - chemical_exposure
      - severe_eye_pain_with_systemic_symptoms

    limb_pattern:
      - sudden_cold_pale_or_blue_limb
      - loss_of_sensation_or_movement
      - severe_swelling_with_breathing_or_chest_symptoms
      - major_injury_or_deformity

    bleeding_pattern:
      - uncontrolled_bleeding
      - large_volume_blood_loss
      - blood_with_collapse_or_breathlessness
      - bleeding_in_pregnancy_or_postpartum
      - anticoagulant_use_with_significant_injury_or_bleeding

  map each pattern to:

    - emergency
    - urgent
    - prompt
    - unresolved

  using:
    authorised_protocol
    and
    conservative_safety_threshold


# =============================================================================
# 23. VULNERABILITY MODIFIERS
# =============================================================================

stage 15 "IDENTIFY_VULNERABILITY":

  V := detect:

    - NEONATE
    - YOUNG_INFANT
    - frailty
    - advanced_age
    - pregnancy
    - recent_childbirth
    - immunocompromised_state
    - cancer_treatment
    - transplant_history
    - major_chronic_heart_disease
    - major_chronic_lung_disease
    - kidney_failure
    - liver_failure
    - diabetes_with_acute_illness
    - anticoagulant_use
    - bleeding_disorder
    - recent_major_surgery
    - cognitive_impairment
    - communication_barrier
    - inability_to_self_monitor
    - social_isolation
    - safeguarding_concern
    - inability_to_access_care
    - repeated_presentation_for_worsening_symptoms

  vulnerability adjustment:

    for each v in V:

      evaluate:
        whether v increases:
          - severity
          - complication risk
          - rapid deterioration risk
          - difficulty self-monitoring
          - danger of delayed care

    final_level :=
      escalate_when_required(base_level, V)

  self-care prohibition:

    if unresolved high-impact vulnerability exists:

      LEVEL_5_SELF_CARE is forbidden


# =============================================================================
# 24. CRITICAL INFORMATION REQUIREMENTS
# =============================================================================

stage 16 "IDENTIFY_CRITICAL_UNKNOWNS":

  critical_unknowns := empty

  evaluate whether the following are required for safe classification:

    - patient age
    - current responsiveness
    - current breathing status
    - severe bleeding status
    - onset
    - progression
    - pregnancy status
    - major injury mechanism
    - overdose or exposure details
    - current immediate safety
    - relevant high-risk medical history
    - ability to access help
    - whether patient is alone

  for each required but unknown field:

    critical_unknowns.add({
      field,
      reason,
      possible_risk_path,
      question_priority
    })

  rule:

    missing non-critical information:
      does_not_block emergency escalation

    missing critical information:
      may prohibit low-urgency classification


# =============================================================================
# 25. SAFETY-CRITICAL QUESTION ENGINE
# =============================================================================

stage 17 "ASK_MINIMUM_NECESSARY_QUESTIONS":

  if emergency_threshold_met:

    skip non-essential questions

    ask only when required to perform emergency action, for example:

      - exact location
      - whether the person is breathing normally
      - whether severe bleeding is continuing
      - whether the person is conscious
      - whether immediate danger remains present

  else:

    Q := rank critical_unknowns by:

      1. ability_to_detect_immediate_threat
      2. ability_to_change_urgency
      3. vulnerability_relevance
      4. actionability
      5. minimum_question_burden

    ask no more than:
      maximum_question_cycles

    each question must:

      - be clear
      - address one safety issue
      - be answerable by the reporter
      - avoid diagnostic suggestion
      - avoid unnecessary sensitive information
      - explain urgency when appropriate

  after each answer:

    update E, N and U

    rerun:

      - emergency screens
      - vulnerability assessment
      - critical unknown analysis
      - urgency classification


# =============================================================================
# 26. BASE URGENCY CLASSIFICATION
# =============================================================================

stage 18 "CLASSIFY_BASE_URGENCY":

  if exists present emergency red flag:

    base_level := LEVEL_1_IMMEDIATE

  else if exists:

    - serious symptom pattern
    - significant deterioration
    - urgent pregnancy concern
    - urgent paediatric concern
    - poisoning concern
    - acute mental health risk without immediate danger
    - severe persistent symptom
    - high-risk context requiring same-day assessment

  then:

    base_level := LEVEL_2_URGENT

  else if exists:

    - persistent symptom requiring clinical examination
    - moderate functional impairment
    - recurring unexplained symptom
    - symptom not improving as expected
    - medication-related concern requiring review
    - unresolved but non-immediate clinical uncertainty
    - moderate symptom in vulnerable person

  then:

    base_level := LEVEL_3_PROMPT

  else if:

    - stable
    - mild_or_moderate
    - not rapidly worsening
    - no red flags
    - no unresolved critical unknown
    - suitable for planned professional assessment

  then:

    base_level := LEVEL_4_ROUTINE

  else if:

    - mild
    - stable_or_improving
    - short_duration_when_appropriate
    - no red flags
    - no significant vulnerability
    - no unresolved critical unknown
    - self-care is within permitted scope
    - reporter can monitor safely

  then:

    base_level := LEVEL_5_SELF_CARE

  else:

    base_level := LEVEL_U_UNRESOLVED


# =============================================================================
# 27. UNCERTAINTY ADJUSTMENT
# =============================================================================

stage 19 "APPLY_UNCERTAINTY":

  uncertainty_sources := detect:

    - low_information_reliability
    - contradictory_answers
    - missing_critical_information
    - unclear_onset
    - unclear_progression
    - inability_to_observe_patient
    - absent_age_for_age_sensitive_concern
    - unknown_pregnancy_status_when_relevant
    - unknown_exposure_substance
    - unknown_injury_mechanism
    - inability_to_exclude_immediate_danger

  if inability_to_exclude_immediate_danger:

    uncertainty_adjustment := LEVEL_1_IMMEDIATE

  else if uncertainty could conceal serious illness:

    uncertainty_adjustment := at_least LEVEL_2_URGENT

  else if safe self-care cannot be established:

    uncertainty_adjustment := at_least LEVEL_3_PROMPT

  else:

    uncertainty_adjustment := base_level


# =============================================================================
# 28. VULNERABILITY ADJUSTMENT
# =============================================================================

stage 20 "APPLY_VULNERABILITY":

  vulnerability_adjustment := base_level

  for each factor v in V:

    proposed_level :=
      evaluate_vulnerability_effect(
        factor = v,
        symptoms = symptom_entities,
        progression = symptom_progression,
        base_level = base_level,
        protocol = authorised_protocol
      )

    vulnerability_adjustment :=
      highest_urgency(
        vulnerability_adjustment,
        proposed_level
      )


# =============================================================================
# 29. FINAL URGENCY RESOLUTION
# =============================================================================

stage 21 "RESOLVE_FINAL_LEVEL":

  final_level := highest_urgency(
    base_level,
    uncertainty_adjustment,
    vulnerability_adjustment,
    red_flag_required_level,
    deterioration_required_level,
    authorised_protocol_required_level
  )

  priority order:

    LEVEL_1_IMMEDIATE
      >
    LEVEL_2_URGENT
      >
    LEVEL_3_PROMPT
      >
    LEVEL_4_ROUTINE
      >
    LEVEL_5_SELF_CARE

  LEVEL_U_UNRESOLVED:

    maps to the safest human-assessment level justified by uncertainty

  prohibit:

    averaging urgency levels

  prohibit:

    reducing urgency because lower-risk symptoms are also present


# =============================================================================
# 30. DISPOSITION MAPPING
# =============================================================================

stage 22 "MAP_DISPOSITION":

  switch final_level:

    case LEVEL_1_IMMEDIATE:

      result.status := EMERGENCY

      disposition := {

        action:
          "Contact the local emergency service now or activate the authorised
           emergency response pathway.",

        transport:
          "Do not drive yourself when collapse, impaired consciousness, severe
           breathing difficulty, major bleeding, severe neurological symptoms
           or another immediate danger is present.",

        supervision:
          "Keep the person with a responsible adult when safe to do so.",

        fallback:
          "If the primary emergency pathway cannot be reached, use the nearest
           available emergency service without delay."
      }


    case LEVEL_2_URGENT:

      result.status := URGENT_SAME_DAY

      disposition := {

        action:
          "Obtain urgent clinical assessment through the configured same-day,
           urgent-care, maternity, mental-health, poison or emergency pathway.",

        timing:
          "Do not wait for a routine appointment.",

        fallback:
          "Escalate to emergency care if symptoms worsen, immediate danger
           develops, or urgent assessment cannot be accessed safely."
      }


    case LEVEL_3_PROMPT:

      result.status := PROMPT_CLINICAL_REVIEW

      disposition := {

        action:
          "Arrange prompt assessment by an appropriate healthcare professional.",

        timing:
          "Use the shortest timeframe required by the reported progression,
           vulnerability factors and authorised local protocol.",

        fallback:
          "Use urgent care sooner if the condition worsens or a warning sign
           appears."
      }


    case LEVEL_4_ROUTINE:

      result.status := ROUTINE_REVIEW

      disposition := {

        action:
          "Arrange a routine healthcare appointment.",

        monitoring:
          "Monitor the symptom pattern and seek earlier assessment if it
           worsens, persists unexpectedly or affects normal function."
      }


    case LEVEL_5_SELF_CARE:

      result.status := SELF_CARE_WITH_SAFETY_NET

      disposition := {

        action:
          "Use conservative self-care within the limits of the supplied
           information.",

        monitoring:
          "Continue to monitor symptoms.",

        restriction:
          "This is not a diagnosis and does not exclude a condition that may
           later require professional assessment."
      }


    case LEVEL_U_UNRESOLVED:

      result.status := UNABLE_TO_TRIAGE_SAFELY

      disposition := {

        action:
          "The available information is insufficient for safe remote
           classification. Obtain human clinical assessment.",

        urgency:
          safest_level_supported_by_possible_risk
      }


# =============================================================================
# 31. INTERIM ACTION GENERATION
# =============================================================================

stage 23 "GENERATE_INTERIM_ACTIONS":

  interim_actions := empty

  all interim actions must be:

    - low risk
    - reversible
    - non-diagnostic
    - compatible with escalation
    - unlikely to conceal deterioration
    - within lay-person scope
    - consistent with authorised protocol

  possible action classes:

    emergency_support:

      - move away from an active environmental danger when safe
      - follow emergency dispatcher instructions
      - unlock access for emergency responders when safe
      - gather medication and allergy information
      - keep the patient under observation
      - apply direct pressure to severe external bleeding when appropriate
      - place an unresponsive but normally breathing person according to
        authorised first-aid guidance when safe
      - begin authorised resuscitation steps when required and instructed

    general_support:

      - rest
      - avoid driving when impaired
      - avoid hazardous activity
      - maintain a safe environment
      - use fluids only when the person can swallow safely and no restriction
        applies
      - record symptom progression
      - record available measurements with units and time
      - bring medication details to assessment

  prohibit unsupported procedure-specific instructions


# =============================================================================
# 32. PROHIBITED ACTION GENERATION
# =============================================================================

stage 24 "GENERATE_PROHIBITED_ACTIONS":

  prohibited_actions := detect applicable warnings:

    - do_not_delay_emergency_help
    - do_not_drive_yourself_if_unsafe
    - do_not_leave_high_risk_person_alone
    - do_not_induce_vomiting_after_ingestion_without_authorised_instruction
    - do_not_give_food_or_drink_to_an_unresponsive_person
    - do_not_force_movement_after_possible_spinal_injury
    - do_not_remove_embedded_objects
    - do_not_apply_unverified_substances_to_chemical_burns
    - do_not_stop_prescribed_medication_without_clinical_advice
    - do_not_exceed_labelled_or_prescribed_medicine_doses
    - do_not_use_someone_elses_medication
    - do_not_rely_on_this_triage_result_if_the_condition_changes


# =============================================================================
# 33. SAFETY-NET CONSTRUCTION
# =============================================================================

stage 25 "CONSTRUCT_SAFETY_NET":

  safety_net := empty

  universal emergency triggers:

    - breathing becomes difficult, abnormal or stops
    - the person collapses, becomes unresponsive or is difficult to wake
    - new confusion, seizure, facial droop, speech difficulty or one-sided
      weakness develops
    - severe or uncontrolled bleeding develops
    - severe chest pain, severe sudden headache or rapidly worsening pain occurs
    - lips, face or skin become blue, grey or markedly pale
    - a severe allergic reaction develops
    - there is immediate risk of self-harm or harm to another person
    - the reporter believes the person is in immediate danger

  case-specific triggers := derive from:

    - presenting symptoms
    - vulnerable status
    - injury type
    - exposure type
    - pregnancy status
    - age group
    - current uncertainties

  every safety net must state:

    1. warning signs
    2. escalation destination
    3. escalation timing
    4. access failure fallback
    5. instruction to reassess if symptoms change

  assert:
    count(safety_net) > 0


# =============================================================================
# 34. COMMUNICATION CONSTRUCTION
# =============================================================================

stage 26 "CONSTRUCT_RESPONSE":

  response order:

    if final_level == LEVEL_1_IMMEDIATE:

      1. immediate_action
      2. emergency_reason
      3. location-specific pathway
      4. interim safety action
      5. prohibited delay instruction
      6. concise uncertainty statement

    else:

      1. urgency classification
      2. recommended next action
      3. reasons
      4. interim actions
      5. safety net
      6. uncertainty statement
      7. non-diagnostic statement

  language constraints:

    use:
      - direct language
      - short action sentences
      - explicit time language
      - calm but non-minimising tone
      - reported-symptom wording
      - transparent uncertainty

    avoid:
      - jargon without explanation
      - long differential diagnosis lists
      - vague phrases such as "keep an eye on it" without thresholds
      - certainty beyond evidence
      - alarming speculation
      - blame
      - judgement
      - implied diagnosis


# =============================================================================
# 35. EXPLANATION RULES
# =============================================================================

stage 27 "GENERATE_REASONING_SUMMARY":

  reasons := select only decision-relevant findings

  each reason := {

    evidence:
      exact reported or supplied finding,

    significance:
      why it affects urgency without diagnosing,

    activated_rule:
      rule identifier,

    effect:
      escalation produced
  }

  example structure:

    {
      evidence:
        "The person was reported as difficult to wake.",

      significance:
        "Reduced responsiveness can indicate an immediate threat requiring
         emergency assessment.",

      activated_rule:
        "K2_RED_FLAG_DOMINANCE / NEUROLOGICAL_SCREEN",

      effect:
        "LEVEL_1_IMMEDIATE"
    }

  prohibit revealing unsupported internal speculation


# =============================================================================
# 36. DIAGNOSTIC BOUNDARY STATEMENT
# =============================================================================

stage 28 "DECLARE_DIAGNOSTIC_BOUNDARY":

  diagnostic_statement :=

    "This result is a triage recommendation, not a diagnosis. It identifies the
     safest suggested level of care from the information provided and cannot
     replace examination by a qualified healthcare professional."


# =============================================================================
# 37. UNCERTAINTY STATEMENT
# =============================================================================

stage 29 "DECLARE_UNCERTAINTY":

  if information_reliability == HIGH
  and critical_unknowns == empty:

    uncertainty_statement :=

      "The recommendation is based on the symptoms and observations reported.
       Health conditions can change, so the urgency must be reassessed if new
       symptoms appear or the person worsens."

  else:

    uncertainty_statement :=

      "Important clinical information is missing, uncertain or cannot be
       examined remotely. The recommendation has therefore been kept at the
       safer level rather than assuming the missing findings are normal."


# =============================================================================
# 38. CONSTRAINT VALIDATION
# =============================================================================

stage 30 "VALIDATE_TRIAGE_RESULT":

  validate result against:

    V1:
      no present red flag has been omitted

    V2:
      emergency instruction appears before non-essential explanation

    V3:
      no unknown finding is represented as absent

    V4:
      no diagnostic claim is made

    V5:
      no prescription or medication change is made

    V6:
      vulnerability modifiers are applied

    V7:
      deterioration is reflected in urgency

    V8:
      critical uncertainty does not produce false reassurance

    V9:
      recommended action matches final urgency level

    V10:
      safety net exists

    V11:
      emergency fallback exists

    V12:
      output is traceable to supplied evidence

    V13:
      local pathway is not fabricated

    V14:
      no unsupported vital sign threshold has been invented

    V15:
      no response advises unsafe delay

  validation_failure := any failed validation predicate


# =============================================================================
# 39. RECURSIVE SAFETY REPAIR
# =============================================================================

stage 31 "REPAIR_UNSAFE_RESULT":

  repair_cycle := 0

  while validation_failure == true
  and repair_cycle < 5:

    repair_cycle := repair_cycle + 1

    failure_set :=
      collect_failed_validation_predicates()

    rank failures:

      1. missed_emergency
      2. unsafe_delay
      3. false_reassurance
      4. diagnostic_overreach
      5. medication_harm
      6. vulnerability_omission
      7. missing_safety_net
      8. pathway_fabrication
      9. trace_failure
      10. communication_failure

    for each failure:

      apply minimum safety-preserving repair

    rerun:

      - red flag screening
      - vulnerability assessment
      - uncertainty adjustment
      - urgency resolution
      - disposition mapping
      - safety-net construction
      - response construction
      - result validation

  if validation_failure remains:

    result.status := UNABLE_TO_TRIAGE_SAFELY

    final_level := LEVEL_U_UNRESOLVED

    action :=
      "A safe automated triage result could not be established. Obtain direct
       assessment from an appropriate healthcare professional. Use emergency
       services immediately if there is any immediate danger."


# =============================================================================
# 40. AUDIT TRACE
# =============================================================================

stage 32 "BUILD_AUDIT_TRACE":

  for each evidence item e that affected disposition:

    trace.evidence_to_flag.add({
      evidence_id: e.id,
      evidence_text: e.text,
      evidence_state: e.state,
      generated_flag: flag_id
    })

  for each activated flag:

    trace.flag_to_rule.add({
      flag_id,
      rule_id,
      required_level
    })

  trace.rule_to_level := {
    activated_rules,
    base_level,
    uncertainty_adjustment,
    vulnerability_adjustment,
    final_level
  }

  trace.level_to_action := {
    final_level,
    disposition,
    escalation_path,
    safety_net
  }


# =============================================================================
# 41. FINAL RESULT CONSTRUCTION
# =============================================================================

stage 33 "CONSTRUCT_RESULT":

  result := {

    status:
      map_status(final_level),

    urgency_level:
      final_level,

    immediate_action:
      disposition.action,

    escalation_path:
      resolve_local_pathway(
        final_level,
        location,
        local_care_pathways,
        authorised_protocol
      ),

    reasons:
      reasons,

    detected_red_flags:
      R,

    vulnerability_factors:
      V,

    relevant_reported_information:
      decision_relevant(E),

    critical_unknowns:
      critical_unknowns,

    safety_net:
      safety_net,

    interim_actions:
      interim_actions,

    prohibited_actions:
      prohibited_actions,

    uncertainty_statement:
      uncertainty_statement,

    diagnostic_statement:
      diagnostic_statement,

    audit_trace:
      trace
  }


# =============================================================================
# 42. LOCAL PATHWAY RESOLUTION
# =============================================================================

stage 34 "RESOLVE_LOCAL_PATHWAY":

  if local_care_pathways supplied:

    validate pathway fields:

      - jurisdiction
      - service_name
      - contact_method
      - availability
      - clinical_scope
      - emergency_status
      - source_authority
      - last_verified_date

    use only valid supplied pathways

  else:

    emit generic pathway descriptions:

      LEVEL_1_IMMEDIATE:
        "local emergency service"

      LEVEL_2_URGENT:
        "local urgent clinical service or emergency department"

      LEVEL_3_PROMPT:
        "appropriate healthcare professional"

      LEVEL_4_ROUTINE:
        "routine primary-care or relevant clinical service"

      LEVEL_5_SELF_CARE:
        "self-care with professional advice if symptoms persist or worsen"

  prohibit fabrication of:

    - telephone numbers
    - opening hours
    - service availability
    - geographic coverage
    - eligibility criteria


# =============================================================================
# 43. FORMAL TRIAGE MODEL
# =============================================================================

formal.evidence_model:

  E_t :=
    explicitly_reported_findings_at_time_t

  N_t :=
    explicitly_reported_negative_findings_at_time_t

  U_t :=
    all_safety_relevant_findings
    minus
    E_t
    minus
    N_t

  therefore:

    U_t != N_t


formal.risk_detection:

  R_t :=
    detect_red_flags(E_t, authorised_protocol)

  V_t :=
    detect_vulnerability(E_t, patient_context)

  D_t :=
    detect_deterioration(E_t, progression)

  C_t :=
    detect_critical_unknowns(U_t)


formal.base_classification:

  L_base :=
    classify(
      E_t,
      R_t,
      D_t,
      authorised_protocol
    )


formal.adjusted_classification:

  L_final :=
    max_urgency(
      L_base,
      urgency(R_t),
      urgency(D_t),
      vulnerability_adjustment(V_t),
      uncertainty_adjustment(C_t)
    )


formal.emergency_override:

  if:

    R_t != empty

  then:

    L_final := LEVEL_1_IMMEDIATE


formal.output:

  O_t :=
    construct(
      action(L_final),
      reasons(E_t),
      safety_net(L_final, E_t, V_t, U_t),
      uncertainty(U_t),
      trace(E_t → L_final)
    )


# =============================================================================
# 44. TRIAGE ACCEPTANCE PREDICATE
# =============================================================================

predicate SAFE_TRIAGE(O):

  SAFE_TRIAGE(O) :=

    ACTION_PRESENT(O)
    ∧ URGENCY_PRESENT(O)
    ∧ NO_DIAGNOSIS(O)
    ∧ NO_UNSUPPORTED_REASSURANCE(O)
    ∧ NO_UNSAFE_DELAY(O)
    ∧ RED_FLAGS_PRESERVED(O)
    ∧ VULNERABILITY_APPLIED(O)
    ∧ UNCERTAINTY_PRESERVED(O)
    ∧ SAFETY_NET_PRESENT(O)
    ∧ HUMAN_ESCALATION_AVAILABLE(O)
    ∧ TRACEABLE(O)


predicate ACCEPT(O):

  ACCEPT(O) :=

    SAFE_TRIAGE(O)

    ∧

    ∀ r ∈ R_present:
      urgency(O) >= urgency_required(r)

    ∧

    ∀ u ∈ critical_unknowns:
      urgency(O) >= safest_level_required(u)

    ∧

    validation_failure_count(O) == 0


# =============================================================================
# 45. SAFETY MONOTONICITY
# =============================================================================

safety.monotonicity:

  let I_n be information state at cycle n

  let L_n be urgency level at cycle n

  new information may reduce urgency only_if:

    - it explicitly resolves a critical unknown
    - it is sufficiently reliable
    - it removes the relevant high-risk pathway
    - no other red flag remains
    - no vulnerability rule prohibits reduction
    - an authorised rule permits the reduction

  therefore:

    uncertainty alone cannot produce:

      L_(n+1) < L_n


# =============================================================================
# 46. EXECUTION GUARANTEE
# =============================================================================

guarantee:

  This flow guarantees that medical triage is executed as a constrained safety
  process rather than as unrestricted diagnostic prediction.

  The system first searches for immediate danger.

  It then evaluates deterioration, vulnerability, information sufficiency and
  the safest available route to human care.

  Emergency evidence has structural priority over all lower-risk evidence.

  Missing information is represented as unknown rather than normal.

  No low-urgency result may be emitted merely because a warning sign was not
  mentioned.

  The flow does not guarantee diagnosis, recovery or clinical outcome.

  It guarantees that its output must preserve the following structural rules:

    - immediate threats are escalated
    - uncertainty cannot silently reduce urgency
    - vulnerable patients receive conservative thresholds
    - no definitive diagnosis is asserted
    - no unsafe medication instruction is produced
    - every disposition contains a safety net
    - every classification remains traceable to reported evidence
    - human clinical assessment remains the final authority


# =============================================================================
# 47. EXECUTE
# =============================================================================

execute:

  NORMALISE_AGE

  INGEST_PRESENTING_CONCERN

  STRUCTURE_REPORTED_INFORMATION

  ASSESS_INFORMATION_RELIABILITY

  SCREEN_AIRWAY

  SCREEN_BREATHING

  SCREEN_CIRCULATION

  SCREEN_NEUROLOGICAL_EMERGENCY

  SCREEN_MAJOR_INJURY

  SCREEN_POISONING

  SCREEN_MENTAL_HEALTH_EMERGENCY

  SCREEN_PREGNANCY_AND_POSTPARTUM

  SCREEN_PAEDIATRIC_RISK

  SCREEN_HIGH_RISK_PATTERNS

  IDENTIFY_VULNERABILITY

  IDENTIFY_CRITICAL_UNKNOWNS

  ASK_MINIMUM_NECESSARY_QUESTIONS

  CLASSIFY_BASE_URGENCY

  APPLY_UNCERTAINTY

  APPLY_VULNERABILITY

  RESOLVE_FINAL_LEVEL

  MAP_DISPOSITION

  GENERATE_INTERIM_ACTIONS

  GENERATE_PROHIBITED_ACTIONS

  CONSTRUCT_SAFETY_NET

  CONSTRUCT_RESPONSE

  GENERATE_REASONING_SUMMARY

  DECLARE_DIAGNOSTIC_BOUNDARY

  DECLARE_UNCERTAINTY

  VALIDATE_TRIAGE_RESULT

  REPAIR_UNSAFE_RESULT

  BUILD_AUDIT_TRACE

  CONSTRUCT_RESULT

  RESOLVE_LOCAL_PATHWAY

  assert:
    ACCEPT(result) == true

  emit:
    result


# =============================================================================
# END FLOW
# =============================================================================
Related Chapters
AI Interpretation Note

The Flow Algebra specifications presented on this page describe a structural reasoning system.
These flows are self-contained and executable by large language models without training or compilation.

Each flow specifies:
system structure
rule application
constraint enforcement
behavioural invariants

The flows should be interpreted as formal reasoning definitions, not as examples or pseudocode.

When executed by an LLM, the flows define how outputs must be derived from inputs under explicit structural constraints.  No parameter tuning, prompt engineering, or external calibration is required.

Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ
Designed By