Skip to content

fix: Dosage Calculator does not display calculation results inline #16

@DeepRatAI

Description

@DeepRatAI

Summary

The Dosage Calculator correctly computes the dosage via the API and stores the formatted result in state, but the result text is never rendered inline in the panel. Users only see a generic artifact card title — the actual dosage values are buried behind a "Ver Más" modal click.

Steps to Reproduce

  1. Navigate to Tools → Dosage Calculator
  2. Enter a drug name, patient weight, and age
  3. Click Calcular
  4. Observe: an artifact card appears with a generic title like "Cálculo de dosificación para Amoxicillin en paciente de 70kg"
  5. Expected: The recommended dose, frequency, max daily dose, and warnings should be visible immediately
  6. Actual: The computed result is only accessible by clicking the artifact card's "Ver Más" button

Root Cause

Component Status
API endpoint (/api/v1/tools/dosage-calculator) ✅ Returns correct fields: recommended_dose, frequency, max_daily_dose, dose_per_kg, warnings
State handler (perform_dosage_calculation) ✅ Calls _format_dosage_result(), stores in dosage_result
Result formatter (_format_dosage_result) ✅ Correctly formats all fields into a readable string
Artifact card creation ✅ Creates card with result as content
Panel rendering (dosage_calculator_panel) No rx.cond(State.dosage_result, ...) block to render the result text inline

The dosage_result state variable is populated correctly but the panel component never renders it directly. The formatted text only flows into the artifact card's content field, which requires a modal interaction to view.

Proposed Fix

Add an inline result display block in dosage_calculator_panel() (in ui/medex_ui/app.py) that renders State.dosage_result when it is non-empty — similar to how other tool panels display their results. Example:

rx.cond(
    State.dosage_result,
    rx.box(
        rx.markdown(State.dosage_result),
        padding="1em",
        border_radius="8px",
        bg="var(--accent-3)",
        margin_top="1em",
    ),
),

Priority

High — the calculation works correctly but users cannot see the result without extra clicks, which defeats the purpose of the tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingui

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions