mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
MCP `search` and `fetch` link a metric as `/insights?metric=<id>` and a lab value as `/labs?analyte=<name>`. Neither page read its query, so every link opened the overview or the full list. `/insights` now resolves the id server-side, in whichever spelling the result carries (a Coach source key such as `hrv` or `bp`, a signal or metric-status key such as `GRIP_STRENGTH`, a measurement type, or a sub-page slug), and redirects to the metric's page, or to its value list when no page focuses it. An id it cannot place renders the overview as before. `/labs` asks for the newest reading stored under the exact analyte name and opens its marker's page; a name with no reading keeps the list and drops the query.
27 lines
1017 B
TypeScript
27 lines
1017 B
TypeScript
/**
|
|
* Where `/labs?analyte=<name>` goes (MCP deep links).
|
|
*
|
|
* MCP `search` and `fetch` link a lab value as `/labs?analyte=<name>`, the
|
|
* analyte name exactly as stored on the reading. The labs page read nothing
|
|
* from the query, so every such link showed the whole list. The page now asks
|
|
* for the newest reading under that name and opens its marker's page; a name
|
|
* with no reading, or one whose reading carries no marker, keeps the list.
|
|
*/
|
|
|
|
/** The analyte named in the query, or null when there is none to follow. */
|
|
export function analyteFromQuery(
|
|
raw: string | null | undefined,
|
|
): string | null {
|
|
const analyte = raw?.trim() ?? "";
|
|
return analyte.length > 0 && analyte.length <= 120 ? analyte : null;
|
|
}
|
|
|
|
/** The marker page for the newest reading under that name, or null. */
|
|
export function labHrefForAnalyteReading(
|
|
reading: { biomarkerId: string | null } | undefined,
|
|
): string | null {
|
|
return reading?.biomarkerId
|
|
? `/labs/${encodeURIComponent(reading.biomarkerId)}`
|
|
: null;
|
|
}
|