Import Key to PDF
Fills the AnnotsJSON field of a PDF record in
<DASHBOARD_URL>/admin/ehealth/medicalpdf/ by analyzing the source PDF with the
icd10-panel-fill skill and writing the enriched annotation JSON back to the
dashboard.
Invocation
import-key-to-pdf <path.pdf> [<dashboard_url>]
<path.pdf>— absolute path to the source lab PDF (same file used in W03).<dashboard_url>— optional; if omitted, ask the user.
When called from import-lab-recform, <PDF_PATH> and <DASHBOARD_URL> are
already set — skip Phase 0 and go straight to Step 1.
Output Language
All user-facing output is in English, regardless of conversation language.
Phase 0 — Validate Inputs (standalone only)
- Check
<path.pdf>was supplied; if missing →❌ No PDF path supplied.STOP. - Validate path exists and ends with
.pdf; if invalid →❌ Invalid path: <path>STOP. - If
<dashboard_url>not supplied, ask:Dashboard base URL? (e.g. https://dev-dashboard.dnainsights.ai) - Ensure Playwright MCP browser is ready and logged in to
<DASHBOARD_URL>/admin/.
Step 1 — Fetch current AnnotsJSON from dashboard
- Navigate to:
<DASHBOARD_URL>/admin/ehealth/medicalpdf/ - Search for the PDF entry that matches the current recform
(search by the flattened filename or Description, e.g.
CGX - Amedix <YEAR>). - Click on the matching entry to open its change page.
- Read the current value of the AnnotsJSON field.
- If the field is empty → report
⚠️ AnnotsJSON is empty. Nothing to fill.and STOP.
- If the field is empty → report
- Save the raw JSON value to
/tmp/annots-<recform-slug>.json. - Report:
✅ Fetched AnnotsJSON (N annotation objects)
Step 2 — Analyze PDF and build ICD10 panel mapping
Goal: produce
{ "<uuid>": "diagnosis_icd10codes_panel_<Panel>__<ICD>" }for every annotation whosecontentslooks likediagnosis_icd10codes__<ICD>.
Read the full PDF with Claude
Readtool (<PDF_PATH>). Do NOT use pypdf. Confirm all pages captured (panels, ICD-10 code lists, panel headers).Load the AnnotsJSON from
/tmp/annots-<recform-slug>.json. Identify annotation objects wherecontentsmatches the patterndiagnosis_icd10codes__<ICD>(short form, no panel prefix).For each such annotation:
- Extract
<ICD>fromcontents. - From the PDF content, determine which panel owns that ICD code
(the panel whose code list contains
<ICD>). - Build the full value:
diagnosis_icd10codes_panel_<Panel>__<ICD>. - Record:
{ "<uuid>": "diagnosis_icd10codes_panel_<Panel>__<ICD>" }.
- Extract
Save the mapping to
/tmp/icd_map.json.If any ICD code cannot be matched to a panel in the PDF:
- List them as unresolved and ask the user to confirm the panel name before continuing.
Show the user a compact confirmation table:
UUID (first 8 chars) | contents (before) | value (after) ───────────────────────────────────────────────────────────────────────────── a1b2c3d4 | diagnosis_icd10codes__C50.0 | diagnosis_icd10codes_panel_Breast Cancer__C50.0 ...Ask: "Apply this mapping? (yes / adjust)" Do NOT proceed to Step 3 until confirmed.
Step 3 — Apply mapping via icd10-panel-fill
Use the icd10-panel-fill skill inline:
- Mapping file:
/tmp/icd_map.json - Target file:
/tmp/annots-<recform-slug>.json
Follow the icd10-panel-fill steps exactly:
- Dry-run check (confirm UUID matches + count changes).
- Backup target file as
/tmp/annots-<recform-slug>.json.bak. - Apply → verify.
- Report:
✅ icd10-panel-fill: N changed, M skipped
Step 4 — Paste updated AnnotsJSON into dashboard and save
- Navigate back to the medicalpdf change page for this PDF
(
<DASHBOARD_URL>/admin/ehealth/medicalpdf/→ search → open entry). - Clear the AnnotsJSON field.
- Paste the full contents of
/tmp/annots-<recform-slug>.jsoninto the field. - Click Save.
- Wait for the success confirmation page.
- Take a screenshot:
<recform-slug>/screenshots/<NN>-annots-json-saved.png. - Report:
✅ import-key-to-pdf done: AnnotsJSON updated and saved.
Final Report Format (standalone)
PDF: CGX rec_Amedix-flatten-pdf.pdf
Dashboard: https://dev-dashboard.dnainsights.ai
Annotations fetched: 42
Panel mappings built: 38 (4 unresolved — listed above)
icd10-panel-fill: 38 changed, 0 skipped
AnnotsJSON saved: ✅