A registry is the list of patients with a condition that a care team follows: one row per patient, with the facts that matter, such as the latest result.
For each patient's latest A1c, take the value at the most recent collection time. In DuckDB that is arg_max; in any SQL, number the rows with a window and keep the first:
SELECT patient_id, arg_max(result_value, collected_at) AS latest_a1c
FROM hd_labs
WHERE test_code = 'CR-A1C'
GROUP BY patient_id;
The same with a window: ROW_NUMBER() OVER (PARTITION BY patient_id ORDER BY collected_at DESC), then keep row 1.
The pitfalls: MAX(result_value) is the highest A1c, not the latest; a cohort built from diagnosis rows repeats each patient once per row, which multiplies any count joined to it; and a registry counts patients, so check that each patient appears once.
Each patient's latest A1c.