feat(interop): Health Post diarrhea cluster -> raise Fair Share water floor

First cross-mini-app interop for breadth: when the community symptom tally shows a diarrhea cluster (dispatch priority elevated/urgent, a waterborne-outbreak signal), the clinician gets a one-click action to raise the Fair Share water floor (postFairshareFloor water) so every resident is guaranteed enough water for oral rehydration. Real clinician decision, shared key = the water resource, no fabricated data; links Health Post + Fair Share + the water theme.
This commit is contained in:
OmO Orchestrator committed 2026-11-20 03:56:37 -05:00
1 parent 27e29caed6
commit e496fc27ac
2 files changed
+90

No files matched your search

@@ -5,6 +5,7 @@ import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { db } from "../../lib/db.ts";
import { init } from "../../lib/identity.ts";
import { readAll } from "../../lib/eventlog.ts";
import { postSymptomReport } from "./healthpostEvents.ts";
import { SymptomTallyDashboard } from "./SymptomTallyDashboard.tsx";
@@ -64,3 +65,37 @@ describe("SymptomTallyDashboard (QA happy path - seeded reports)", () => {
expect(screen.getByTestId("healthpost-tally-caveat")).toBeInTheDocument();
});
});
describe("SymptomTallyDashboard - waterborne interop (Health -> Fair Share)", () => {
it("offers raising the Fair Share water floor when diarrhea reports cluster, and appends a signed fairshare.floor", async () => {
const user = userEvent.setup();
for (let i = 0; i < 5; i += 1) await postSymptomReport("diarrhea");
render(<SymptomTallyDashboard />);
await waitFor(() =>
expect(screen.getByTestId("healthpost-waterborne-interop")).toBeInTheDocument(),
);
await user.click(screen.getByTestId("healthpost-raise-water-floor"));
await waitFor(() =>
expect(screen.getByTestId("healthpost-water-floor-status")).toHaveTextContent(
/water floor raised/i,
),
);
const floors = (await readAll()).filter(
(e) => (e.payload as { type?: string }).type === "fairshare.floor",
);
expect(floors).toHaveLength(1);
expect((floors[0]!.payload as { resource: string }).resource).toBe("water");
});
it("does not offer the water-floor action below the diarrhea cluster threshold", async () => {
await postSymptomReport("diarrhea");
render(<SymptomTallyDashboard />);
await waitFor(() =>
expect(screen.getByTestId("healthpost-symptom-count-diarrhea")).toHaveTextContent("1"),
);
expect(screen.queryByTestId("healthpost-waterborne-interop")).not.toBeInTheDocument();
});
});
@@ -6,9 +6,15 @@ import {
type SymptomCategory,
} from "../../lib/healthpostTally.ts";
import { useEventLogEntries } from "../../shell/useEventLogEntries.ts";
import { postFairshareFloor } from "../../lib/fairshare.ts";
import { extractSymptomReports, postSymptomReport } from "./healthpostEvents.ts";
import styles from "./SymptomTallyDashboard.module.css";
/** Protective per-resident water floor a clinician can set when diarrhea reports
* cluster (a waterborne-outbreak signal), guaranteeing enough water for oral
* rehydration. A fixed policy default, never a modeled/forecast value. */
const OUTBREAK_WATER_FLOOR_PER_AGENT = 25;
const SYMPTOM_LABEL: Record<SymptomCategory, string> = {
fever: "Fever",
cough: "Cough",
@@ -38,6 +44,24 @@ export function SymptomTallyDashboard() {
const [selectedSymptom, setSelectedSymptom] = useState<SymptomCategory>("fever");
const [submitting, setSubmitting] = useState(false);
const [floorSubmitting, setFloorSubmitting] = useState(false);
const [floorStatus, setFloorStatus] = useState<string>();
const diarrheaRow = tally.bySymptom.find((row) => row.symptom === "diarrhea");
async function handleRaiseWaterFloor() {
setFloorSubmitting(true);
try {
await postFairshareFloor("water", OUTBREAK_WATER_FLOOR_PER_AGENT);
setFloorStatus(
`Fair Share water floor raised to ${OUTBREAK_WATER_FLOOR_PER_AGENT} per resident.`,
);
} catch (err) {
setFloorStatus(err instanceof Error ? err.message : String(err));
} finally {
setFloorSubmitting(false);
}
}
async function handleSubmitReport() {
setSubmitting(true);
@@ -90,6 +114,37 @@ export function SymptomTallyDashboard() {
</li>
))}
</ul>
{diarrheaRow && diarrheaRow.dispatchPriority !== "routine" && (
<div
data-testid="healthpost-waterborne-interop"
style={{ marginTop: 12, padding: 12, borderRadius: 10, background: "#eff6ff", border: "1px solid #bfdbfe" }}
>
<p style={{ margin: "0 0 8px", fontSize: 13 }}>
{diarrheaRow.count} diarrhea reports can signal a waterborne problem. Raising the Fair
Share water floor guarantees every resident enough water for oral rehydration.
</p>
<button
type="button"
data-testid="healthpost-raise-water-floor"
onClick={() => void handleRaiseWaterFloor()}
disabled={floorSubmitting}
>
{floorSubmitting
? "Raising\u2026"
: `Raise Fair Share water floor to ${OUTBREAK_WATER_FLOOR_PER_AGENT}/person`}
</button>
{floorStatus && (
<p
data-testid="healthpost-water-floor-status"
role="status"
style={{ fontSize: 13, margin: "8px 0 0" }}
>
{floorStatus}
</p>
)}
</div>
)}
</>
)}