> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.emtelligent.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.emtelligent.com/_mcp/server.

# Imagelink Summary

## Synopsis

This query finds all imagelink relations extracted by the NLP API, showing the annotated terms for the image reference and findings.

SQL statements to retrieve filename and patient id are provided but commented out.

## Processing Requirements

This query assumes that at least the following `emtellipro-db-client` processing options were enabled:

* `--feature imagelink-relations`
* `--store-sections-and-sentences`

## Clinical Context

Cross-sectional medical imaging studies such as MRI and CT may contain hundreds to thousands of images, which according to the DICOM standard, are organized into one or more series that contain one or more images. When a radiologist dictates the study, to aid in finding the lesion in question by the reader of the report, they may dictate the **series number** and **image number** of the lesion using varying notation methods. An example of this would be "There is a 5 mm nodule in the right lower lobe (4:3)." to indicate that the nodule is present on `image 3 of series 4`, or they may more explicitly state an image location as "There is a 1.2 cm hemangioma in Segment IVa of the liver on (Series 601, Image 29)".

The NLP API identifies these Imagelink relations between the pathology (or finding) being described and the `series/image` annotation and returns them as a relation. The query below can be used to retrieve the finding and image reference from radiology reports.

## SQL query

#### SQL

```sql
SELECT image_e.document_id             AS doc_id,
    imagelinkrelation.id               AS imagerelation_id,
    -- regexp_replace(d.filename, '.*/', '')                      AS filename,
    -- dm.subject_id                   AS subject_id,
    image_fe.text                     AS image_reference_term,
    STRING_AGG(finding_fe.text, ', ') AS image_finding_terms
FROM imagelinkrelation
-- Joins to retrieve entity text for 'Image FINDING' foundentity
        JOIN imagelinkrelationimagefinding image_finding
            ON image_finding.imagelink_id = imagelinkrelation.id
        JOIN entity finding_e
            ON finding_e.id = image_finding.entity_id
        JOIN foundentity finding_fe
            ON finding_fe.id = finding_e.entity_id AND finding_e.type_ = 'found'
-- Joins to retrieve entity text for 'Image REFERENCE'
        JOIN imagelinkrelationreference image_ref
            ON image_ref.imagelink_id = imagelinkrelation.id
        JOIN entity image_e
            ON image_e.id = image_ref.entity_id
        JOIN foundentity image_fe
            ON image_fe.id = image_e.entity_id AND image_e.type_ = 'found'
-- Joins to retrieve document filename
    -- JOIN document d ON image_fe.document_id = d.id
-- Joins to retrieve subject id from documentmetadata (if populated)
    -- JOIN documentmetadata dm ON d.id = dm.document_id
-- GROUP BY imagelinkrelation.id, regexp_replace(d.filename, '.*/', '') AS filename, dm.subject_id, image_fe.txt
GROUP BY image_e.document_id, imagelinkrelation.id, image_fe.text
ORDER BY imagelinkrelation.id;
```

#### Snowflake

```sql
SELECT image_e.document_id                AS doc_id,
    imagelinkrelation.id               AS imagerelation_id,
    -- regexp_replace(d.filename, '.*/', '')                      AS filename,
    -- dm.subject_id                   AS subject_id,
    image_fe.text                     AS image_reference_term,
    list_agg(finding_fe.text, ', ') AS image_finding_terms
FROM imagelinkrelation
-- Joins to retrieve entity text for 'Image FINDING' foundentity
        JOIN imagelinkrelationimagefinding image_finding
            ON image_finding.imagelink_id = imagelinkrelation.id
        JOIN entity finding_e
            ON finding_e.id = image_finding.entity_id
        JOIN foundentity finding_fe
            ON finding_fe.id = finding_e.entity_id AND finding_e.type_ = 'found'
-- Joins to retrieve entity text for 'Image REFERENCE'
        JOIN imagelinkrelationreference image_ref
            ON image_ref.imagelink_id = imagelinkrelation.id
        JOIN entity image_e
            ON image_e.id = image_ref.entity_id
        JOIN foundentity image_fe
            ON image_fe.id = image_e.entity_id AND image_e.type_ = 'found'
-- Joins to retrieve document filename
    -- JOIN document d ON image_fe.document_id = d.id
-- Joins to retrieve subject id from documentmetadata (if populated)
    -- JOIN documentmetadata dm ON d.id = dm.document_id
-- GROUP BY imagelinkrelation.id, regexp_replace(d.filename, '.*/', '') AS filename, dm.subject_id, image_fe.txt
GROUP BY image_e.document_id, imagelinkrelation.id, image_fe.text
ORDER BY imagelinkrelation.id;
```

| doc_id | imagerelation_id | image_reference_term | image_finding_terms          |
| ------ | ---------------- | -------------------- | ---------------------------- |
| 6      | 1                | series 3, image 53   | umbilical hernia             |
| 6      | 2                | series 3, image 104  | rectal wall thickening       |
| 10     | 3                | series 68 image 29   | lateral cervical nodes       |
| 10     | 4                | series 68 image 29   | 0.6cm                        |
| 10     | 5                | series 68 image 29   | 0.9cm                        |
| 10     | 6                | series 68 image 20   | lateral cervical node        |
| 10     | 7                | series 68 image 20   | 0.7 cm                       |
| 10     | 8                | series 68 image 15   | nodes                        |
| 10     | 9                | series 68 image 15   | lateral cervical nodal chain |
| 10     | 10               | series 68 image 15   | 0.5cm                        |

## Next steps

After previewing the data extracted by imagelink relations, you may want to limit the result set to the imaging results for certain findings only. You can do this in a number of ways:

1. Using SQL pattern-matching operators (i.e. LIKE and ILIKE) to find specific words in the annotated text.
2. Using a concept-based approach where you search for finding entities that are mapped to a specific concept ID e.g. for a specific anatomical feature, or morphological abnormalities. This example shows how to search for specific concepts, see [Sleep Apnea](/nlp/database/cookbook/concept-queries/multi-concept/sleep-apnea).
3. Using a concept hierarchy search. This type of query searches for a parent and all its children concepts using Snomed CT. Examples of this approach, are found [here](/nlp/database/cookbook/concept-queries/concept-hierarchy/overview).
4. For the most general search, you may also choose to search for a specific entity type.

## Related links

* [Imagelink Relations](/nlp/database/schema/relations/imagelink)
* [Entity-level Tables](/nlp/database/schema/core/entity-tables)