Extract structured information from a pathology PDF report using
pdftools::pdf_text() and regex-based section parsing. Complete extracted
pages and text are retained in metadata even when section heuristics match
only part of the report. Database report summaries use that complete text.
This does not perform OCR or validate extraction accuracy against the PDF.
Value
A molpath_parsed object whose data slot is a
tibble with columns section and content
extracted from the report (Patient, Sample, Findings, Interpretation,
Recommendations).
Examples
# Write a small text PDF to a temporary file and parse it.
pdf_file <- tempfile(fileext = ".pdf")
grDevices::pdf(pdf_file)
graphics::plot.new()
graphics::text(0.02, c(0.9, 0.8, 0.7, 0.6), adj = 0, labels = c(
"Patient: P001", "Sample: S001",
"Findings: KRAS G12D detected",
"Interpretation: pathogenic variant"
))
grDevices::dev.off()
#> agg_record_194e5ceff6ad
#> 2
result <- mp_read_pdf_report(pdf_file)
#> ℹ Reading PDF report: file194e19a7de86.pdf (template: generic)
#> ✔ Extracted 3 section(s) from PDF report
result$data
#> # A tibble: 3 × 2
#> section content
#> <chr> <chr>
#> 1 sample_info Sample: S001
#> 2 findings Findings: KRAS G12D detected
#> 3 interpretation Interpretation: pathogenic variant
unlink(pdf_file)