Here’s a simple example of extracting sections from a radiology report:
from radreportparser import RadReportExtractor# Sample brain CT report (note the markdown formatting)report_text ="""EMERGENCY MDCT OF THE BRAIN**HISTORY:** A 25-year-old female presents with headache. Physical examination reveals no focal neurological deficits.TECHNIQUE: Axial helical scan of the brain performed with coronal and sagittal reconstructions.*Comparison:* None.Findings:The brain shows age-appropriate volume with normal parenchymal attenuation and gray-white differentiation. No acute infarction or hemorrhage identified. The ventricles are normal in size without intraventricular hemorrhage. No extra-axial collection, midline shift, or brain herniation. The vascular structures appear normal. The calvarium and skull base show no fracture. Visualized paranasal sinuses, mastoids, and upper cervical spine are unremarkable.=== IMPRESSION ===- No intracranial hemorrhage, acute large territorial infarction, extra-axial collection, midline shift, brain herniation, or skull fracture identified."""# Initialize extractor and parse the reportextractor = RadReportExtractor()report = extractor.extract_all(report_text)report
RadReport(title='EMERGENCY MDCT OF THE BRAIN', history='A 25-year-old female presents with headache. Physical examination reveals no focal neurological deficits.', technique='Axial helical scan of the brain performed with coronal and sagittal reconstructions.', comparison='None.', findings='The brain shows age-appropriate volume with normal parenchymal attenuation and gray-white differentiation. No acute infarction or hemorrhage identified. The ventricles are normal in size without intraventricular hemorrhage. No extra-axial collection, midline shift, or brain herniation. The vascular structures appear normal. The calvarium and skull base show no fracture. Visualized paranasal sinuses, mastoids, and upper cervical spine are unremarkable.', impression='- No intracranial hemorrhage, acute large territorial infarction, extra-axial collection, midline shift, brain herniation, or skull fracture identified.')
Access individual sections:
print(report.history)
A 25-year-old female presents with headache. Physical examination reveals no focal neurological deficits.
Convert to dictionary or JSON
report.to_dict()
{'title': 'EMERGENCY MDCT OF THE BRAIN',
'history': 'A 25-year-old female presents with headache. Physical examination reveals no focal neurological deficits.',
'technique': 'Axial helical scan of the brain performed with coronal and sagittal reconstructions.',
'comparison': 'None.',
'findings': 'The brain shows age-appropriate volume with normal parenchymal attenuation and gray-white differentiation. No acute infarction or hemorrhage identified. The ventricles are normal in size without intraventricular hemorrhage. No extra-axial collection, midline shift, or brain herniation. The vascular structures appear normal. The calvarium and skull base show no fracture. Visualized paranasal sinuses, mastoids, and upper cervical spine are unremarkable.',
'impression': '- No intracranial hemorrhage, acute large territorial infarction, extra-axial collection, midline shift, brain herniation, or skull fracture identified.'}
print(report.to_json(indent =2)) # pretty-printed
{
"title": "EMERGENCY MDCT OF THE BRAIN",
"history": "A 25-year-old female presents with headache. Physical examination reveals no focal neurological deficits.",
"technique": "Axial helical scan of the brain performed with coronal and sagittal reconstructions.",
"comparison": "None.",
"findings": "The brain shows age-appropriate volume with normal parenchymal attenuation and gray-white differentiation. No acute infarction or hemorrhage identified. The ventricles are normal in size without intraventricular hemorrhage. No extra-axial collection, midline shift, or brain herniation. The vascular structures appear normal. The calvarium and skull base show no fracture. Visualized paranasal sinuses, mastoids, and upper cervical spine are unremarkable.",
"impression": "- No intracranial hemorrhage, acute large territorial infarction, extra-axial collection, midline shift, brain herniation, or skull fracture identified."
}
Note
The pattern matching mechanism can extract sections from text with plain text or markdown formatting.