agentleFS
aizechaizech/clinical-skills/.agents/skills/modality-detection/SKILL.md

modality-detection

Skill4 starsChanged 7 months agoMITView on GitHub

Auto-detect imaging modality (CT, MRI, X-ray, US, etc.) from user input, DICOM file headers, or file analysis. Also use when the user mentions "what modality", "detect from file", "identify imaging type", or needs to classify imaging studies. For PACS queries, see pacs-workflow.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When input is ambiguous:

    line 209
  2. Distinctive:

    Request clarification: Ask user for more specific information

    line 211
  3. Distinctive:

    Use context: Consider clinical context if available

    line 213
  4. Distinctive:

    Defer to user: When in doubt, ask rather than guess

    line 214

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Modality Detection

You are a radiology modality detection expert. Your role is to accurately identify the imaging modality from various input formats.

Modality Categories

Primary Modalities

ModalityCodeDescription
Computed TomographyCT, CT-AX-ray cross-sections, often with contrast
Magnetic Resonance ImagingMR, MR-AMagnetic field imaging, no radiation
Plain RadiographyCR, DXProjectional X-ray images
UltrasoundUSSound wave imaging, no radiation
MammographyMGBreast imaging, specialized X-ray
Nuclear MedicineNM, PT, PETRadioactive tracer imaging
FluoroscopyRFReal-time X-ray video

Hybrid/Advanced Modalities

ModalityCodeDescription
PET/CTPT/CTCombined PET and CT
PET/MRPT/MRCombined PET and MRI
SPECT/CTNM/CTCombined SPECT and CT
CT AngiographyCTACT with arterial contrast timing
MR AngiographyMRAMRI for vessel imaging

DICOM Modality Codes

Standard DICOM modality values:

  • CT: Computed Tomography
  • MR: Magnetic Resonance
  • DX: Digital Radiography
  • CR: Computed Radiography
  • US: Ultrasound
  • MG: Mammography
  • NM: Nuclear Medicine
  • PT: PET
  • RF: Radio Fluoroscopy
  • XA: X-Ray Angiography
  • OP: Ophthalmic Photography
  • ES: Endoscopy

Detection Patterns

From Text Input

Extract modality from clinical text using these patterns:

def detect_modality(text):
    text_upper = text.upper()
    
    # Exact matches first
    if "PET/CT" in text_upper:
        return "PET/CT"
    if "CT ANGIOGRAPHY" in text_upper or "CTA" in text_upper:
        return "CTA"
    if "MR ANGIOGRAPHY" in text_upper or "MRA" in text_upper:
        return "MRA"
    if "DIGITAL MAMMOGRAPHY" in text_upper or "SCREENING MAMMO" in text_upper:
        return "Mammography"
    
    # Pattern matching
    if "CT " in text_upper or text_upper.startswith("CT"):
        return "CT"
    if "MRI " in text_upper or text_upper.startswith("MR ") or "MAGNETIC RESONANCE" in text_upper:
        return "MRI"
    if "X-RAY" in text_upper or "CHEST X" in text_upper or "DX " in text_upper:
        return "X-ray"
    if "ULTRASOUND" in text_upper or "SONOGRAPHY" in text_upper or "US " in text_upper:
        return "Ultrasound"
    if "MAMMO" in text_upper or "BREAST" in text_upper:
        return "Mammography"
    if "PET " in text_upper or "PET-" in text_upper:
        return "PET/CT"
    
    return None  # Unknown

From DICOM Headers

Extract modality from DICOM file metadata:

def detect_from_dicom(dicom_file):
    # Using pydicom
    import pydicom
    
    ds = pydicom.dcmread(dicom_file)
    
    modality = getattr(ds, 'Modality', None)
    body_part = getattr(ds, 'BodyPartExamined', None)
    series_desc = getattr(ds, 'SeriesDescription', None)
    
    return {
        'modality': modality,
        'body_part': body_part,
        'series_description': series_desc
    }

Modality Mapping

Map DICOM codes to human-readable names:

DICOM CodeDisplay NameCategory
CTCT ScanTomography
MRMRITomography
DXX-rayProjection
CRX-rayProjection
USUltrasoundUltrasound
MGMammographyProjection
PTPETNuclear
NMNuclear MedicineNuclear
RFFluoroscopyFluoroscopy
XAAngiographyFluoroscopy
CRComputed RadiographyProjection
OPGOrthopantomogramProjection
DXABone DensitometryProjection

Body Part Detection

Extract body part from text:

def detect_body_part(text):
    text_upper = text.upper()
    
    body_parts = {
        'HEAD': ['HEAD', 'BRAIN', 'SKULL', 'CEREBRAL', 'INTRACRANIAL'],
        'NECK': ['NECK', 'CERVICAL', 'THYROID', 'CAROTID'],
        'CHEST': ['CHEST', 'THORAX', 'LUNG', 'PULMONARY', 'CARDIAC', 'HEART'],
        'ABDOMEN': ['ABDOMEN', 'ABDOMINAL', 'LIVER', 'KIDNEY', 'RENAL', 'PANCREAS', 'SPLEEN'],
        'PELVIS': ['PELVIS', 'PELVIC', 'HIP', 'PROSTATE', 'UTERUS', 'OVARY'],
        'SPINE': ['SPINE', 'VERTEBRAL', 'CERVICAL', 'THORACIC', 'LUMBAR'],
        'EXTREMITY': ['ARM', 'LEG', 'KNEE', 'SHOULDER', 'ANKLE', 'WRIST', 'HAND', 'FOOT'],
        'BREAST': ['BREAST', 'MAmm', 'MAmmog']
    }
    
    for body_part, keywords in body_parts.items():
        if any(kw in text_upper for kw in keywords):
            return body_part
    
    return None

Contrast Detection

Determine if contrast is used:

def detect_contrast(text):
    text_upper = text.upper()
    
    # Positive indicators
    contrast_keywords = ['CONTRAST', 'IV CONTRAST', 'WITH CONTRAST', 'GASTRIN', 'GADOLINIUM', 
                         'IODINATED', 'ENHANCEMENT', 'ANGIOGRAPHY', 'ARTERIAL PHASE']
    
    # Negative indicators  
    no_contrast_keywords = ['WITHOUT CONTRAST', 'NON-CONTRAST', 'UNENHANCED', 'PLAIN']
    
    for kw in contrast_keywords:
        if kw in text_upper:
            return 'Yes'
    
    for kw in no_contrast_keywords:
        if kw in text_upper:
            return 'No'
    
    return None  # Unknown

Output Format

Return detection results in structured format:

{
  "modality": "CT",
  "modality_confidence": "High",
  "body_part": "Chest",
  "contrast": "Yes",
  "subtype": null,
  "source": "text",
  "original_input": "CT chest with contrast",
  "warnings": []
}

Confidence Levels

LevelCriteria
HighExact match, clear indication
MediumPartial match, some ambiguity
LowWeak indicators, significant ambiguity
UnknownCannot determine, needs clarification

Handling Ambiguous Cases

When input is ambiguous:

  1. Request clarification: Ask user for more specific information
  2. List possibilities: Provide options if multiple modalities match
  3. Use context: Consider clinical context if available
  4. Defer to user: When in doubt, ask rather than guess

Example response for ambiguous input:

The input "chest imaging study" is ambiguous. Please clarify:

1. CT chest with contrast
2. Chest X-ray (PA/lateral)
3. Chest ultrasound
4. PET/CT chest

Which modality do you mean?

Common Abbreviations

AbbreviationFull TermModality
CXRChest X-rayX-ray
KUBKidneys, Ureter, Bladder X-rayX-ray
CTACT AngiographyCT
MRAMR AngiographyMRI
VQVentilation/Perfusion ScanNuclear
HIDAHepatobiliary ScanNuclear
DEXABone Density ScanX-ray
OPGPanoramic Dental X-rayX-ray

Related Skills

  • pacs-workflow: For querying PACS with modality filters
  • dicom-web-query: For retrieving DICOM metadata
  • filesystem-imaging: For analyzing local imaging files
  • radiology-context: For understanding user's imaging environment

Examples

Example 1: Text Input

Input: "CT abdomen with contrast" Output:

{
  "modality": "CT",
  "body_part": "Abdomen",
  "contrast": "Yes"
}

Example 2: DICOM File

Input: DICOM file with Modality=MR, BodyPartExamined=BRAIN Output:

{
  "modality": "MRI",
  "body_part": "Brain",
  "source": "DICOM header"
}

Example 3: Ambiguous Input

Input: "imaging study" Response: "Please specify the modality: CT, MRI, X-ray, Ultrasound, etc."

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.