> 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.

# Follow-up Summary

## Synopsis

This data exploration query returns data about all follow-up relations that were extracted for further analysis or review.

## Processing Requirements

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

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

For this query, Radiology imaging studies were processed with the following document type:

* `--category Radiology`
* `--subcategory CT`

## Clinical Context

Follow-up recommendations are common in medical reports, particularly in diagnostic reports. A common scenario would be in patients receiving CT scans of the thorax, small lung nodules are not infrequently incidentally discovered. While many of these nodules are benign and do not grow, a small number of these nodules will be early malignancies. For this reason, radiologists use clinical guidelines such as the Fleischner Society Guidelines to qualify if and when a patient should have a follow-up examination to re-evaluate the lung nodule in question for interval growth.

An example sentence whereby a radiologist may indicate a follow-up is required would be, "Small pulmonary nodule in the right lower lobe for which a CT scan of the chest should be performed in 6 months". In this case, the NLP API would identify that a follow-up relation exists, and that a `169069000 |Computed tomography of chest (procedure)|` should be performed in `6-months` because of the presence of a `427359005 |Solitary nodule of lung (finding)|`.

The query below identifies these follow-up relations, and returns the **reason**, **timeframe**, and **pathology** for which the follow-up should be performed.

## SQL query

#### PostgreSQL

```sql
WITH reason_terms AS (SELECT DISTINCT followuprelation.id                   AS followup_relation_id,
                                    STRING_AGG(reason_fe.text, ', ')
                                    OVER (PARTITION BY followuprelation.id) AS reason_terms
                    FROM followuprelation
                            -- retrieve reason entity for follow up
                            JOIN followuprelationreason reason
                                    ON followuprelation.id = reason.followup_id
                            JOIN entity reason_e
                                    ON reason_e.id = reason.entity_id
                            JOIN foundentity reason_fe
                                    ON reason_fe.id = reason_e.entity_id  AND reason_e.type_='found'),
    time_expression_terms AS (SELECT followuprelation.id AS followup_relation_id,
                                    time_fe.text        AS time_expression
                            FROM followuprelation
                                        -- retrieve time expression entity for follow up
                                        JOIN entity time_e
                                            ON time_e.id = followuprelation.time_expression_id
                                        JOIN foundentity time_fe
                                            ON time_fe.id = time_e.entity_id AND time_e.type_ = 'found'),
    procedure_terms AS (SELECT DISTINCT followuprelation.id                     AS followup_relation_id,
                                        STRING_AGG(procedure_fe.text, ', ')
                                        OVER (PARTITION BY followuprelation.id) AS procedure_terms,
                                        sl.text                                 AS sentence,
                                        procedure_e.document_id                 AS doc_id
                        FROM followuprelation
                                -- retrieve procedure entity for follow up
                                JOIN followuprelationprocedure procedure
                                    ON followuprelation.id = procedure.followup_id
                                JOIN entity procedure_e
                                    ON procedure_e.id = procedure.entity_id
                                JOIN foundentity procedure_fe
                                    ON procedure_fe.id = procedure_e.entity_id AND procedure_e.type_='found'
                                JOIN foundentitylocation fel on procedure_fe.id = fel.found_entity_id
                                JOIN location l on fel.location_id = l.id AND l.type_ = 'sentence'
                                JOIN sentencelocation sl on l.location_id = sl.id
    )
SELECT fr.id,
    -- if documentmetadata is populated
    -- dm.chartdate
    -- dm.subject_id
    reason_terms.reason_terms AS reasons,
    procedure_terms.procedure_terms AS procedures,
    time_expression_terms.time_expression AS timeline,
    procedure_terms.sentence AS sentence
FROM followuprelation fr
        LEFT JOIN reason_terms -- IMPORTANT: left joins required
                ON reason_terms.followup_relation_id = fr.id
        LEFT JOIN procedure_terms
                ON procedure_terms.followup_relation_id = fr.id
        LEFT JOIN time_expression_terms
                ON time_expression_terms.followup_relation_id = fr.id
        -- if documentmetadata is populated
        JOIN documentmetadata dm ON dm.document_id = procedure_terms.doc_id
ORDER BY procedure_terms.doc_id;
```

#### Microsoft SQL Server

```sql
WITH reason_terms AS (SELECT DISTINCT followuprelation.id                   AS followup_relation_id,
                                STRING_AGG(reason_fe.text, ', ')       AS reason_terms
                FROM followuprelation
                        -- retrieve reason entity for follow up
                        JOIN followuprelationreason reason
                                ON followuprelation.id = reason.followup_id
                        JOIN entity reason_e
                                ON reason_e.id = reason.entity_id
                        JOIN foundentity reason_fe
                                ON reason_fe.id = reason_e.entity_id  AND reason_e.type_='found'
                GROUP BY followuprelation.id
),
time_expression_terms AS (SELECT followuprelation.id AS followup_relation_id,
                                time_fe.text        AS time_expression
                        FROM followuprelation
                                        -- retrieve time expression entity for follow up
                                        JOIN entity time_e
                                        ON time_e.id = followuprelation.time_expression_id
                                        JOIN foundentity time_fe
                                        ON time_fe.id = time_e.entity_id AND time_e.type_ = 'found'),
procedure_terms AS (SELECT followuprelation.id                     AS followup_relation_id,
                                sl.text                                 AS sentence,
                                procedure_e.document_id                 AS doc_id,
                                STRING_AGG(procedure_fe.text, ', ')    AS procedure_terms
                        FROM followuprelation
                                -- retrieve procedure entity for follow up
                                JOIN followuprelationprocedure frp
                                ON followuprelation.id = frp.followup_id
                                JOIN entity procedure_e
                                ON procedure_e.id = frp.entity_id
                                JOIN foundentity procedure_fe
                                ON procedure_fe.id = procedure_e.entity_id AND procedure_e.type_='found'
                                JOIN foundentitylocation fel on procedure_fe.id = fel.found_entity_id
                                JOIN location l on fel.location_id = l.id AND l.type_ = 'sentence'
                                JOIN sentencelocation sl on l.location_id = sl.id
                GROUP BY followuprelation.id, sl.text, procedure_e.document_id
)
SELECT fr.id,
-- if documentmetadata is populated
-- dm.chartdate
-- dm.subject_id
reason_terms.reason_terms AS reasons,
procedure_terms.procedure_terms AS procedures,
time_expression_terms.time_expression AS timeline,
procedure_terms.sentence AS sentence
FROM followuprelation fr
        LEFT JOIN reason_terms -- IMPORTANT: left joins required
                ON reason_terms.followup_relation_id = fr.id
        LEFT JOIN procedure_terms
                ON procedure_terms.followup_relation_id = fr.id
        LEFT JOIN time_expression_terms
                ON time_expression_terms.followup_relation_id = fr.id
        -- if documentmetadata is populated
        -- JOIN documentmetadata dm ON dm.document_id = procedure_terms.doc_id
ORDER BY procedure_terms.doc_id;
```

#### Snowflake

```sql
WITH reason_terms AS (SELECT DISTINCT followuprelation.id                   AS followup_relation_id,
                                    list_agg(reason_fe.text, ', ')
                                    OVER (PARTITION BY followuprelation.id) AS reason_terms
                    FROM followuprelation
                            -- retrieve reason entity for follow up
                            JOIN followuprelationreason reason
                                    ON followuprelation.id = reason.followup_id
                            JOIN entity reason_e
                                    ON reason_e.id = reason.entity_id
                            JOIN foundentity reason_fe
                                    ON reason_fe.id = reason_e.entity_id  AND reason_e.type_='found'),
    time_expression_terms AS (SELECT followuprelation.id AS followup_relation_id,
                                    time_fe.text        AS time_expression
                            FROM followuprelation
                                        -- retrieve time expression entity for follow up
                                        JOIN entity time_e
                                            ON time_e.id = followuprelation.time_expression_id
                                        JOIN foundentity time_fe
                                            ON time_fe.id = time_e.entity_id AND time_e.type_ = 'found'),
    procedure_terms AS (SELECT DISTINCT followuprelation.id                     AS followup_relation_id,
                                        list_agg(procedure_fe.text, ', ')
                                        OVER (PARTITION BY followuprelation.id) AS procedure_terms,
                                        sl.text                                 AS sentence,
                                        procedure_e.document_id                 AS doc_id
                        FROM followuprelation
                                -- retrieve procedure entity for follow up
                                JOIN followuprelationprocedure procedure
                                    ON followuprelation.id = procedure.followup_id
                                JOIN entity procedure_e
                                    ON procedure_e.id = procedure.entity_id
                                JOIN foundentity procedure_fe
                                    ON procedure_fe.id = procedure_e.entity_id AND procedure_e.type_='found'
                                JOIN foundentitylocation fel on procedure_fe.id = fel.found_entity_id
                                JOIN location l on fel.location_id = l.id AND l.type_ = 'sentence'
                                JOIN sentencelocation sl on l.location_id = sl.id
    )
SELECT fr.id,
    -- if documentmetadata is populated
    -- dm.chartdate
    -- dm.subject_id
    reason_terms.reason_terms AS reasons,
    procedure_terms.procedure_terms AS procedures,
    time_expression_terms.time_expression AS timeline,
    procedure_terms.sentence AS sentence
FROM followuprelation fr
        LEFT JOIN reason_terms -- IMPORTANT: left joins required
                ON reason_terms.followup_relation_id = fr.id
        LEFT JOIN procedure_terms
                ON procedure_terms.followup_relation_id = fr.id
        LEFT JOIN time_expression_terms
                ON time_expression_terms.followup_relation_id = fr.id
        -- if documentmetadata is populated
        JOIN documentmetadata dm ON dm.document_id = procedure_terms.doc_id
ORDER BY procedure_terms.doc_id;
```

| id | reasons                                 | procedures                            | timeline                | sentence                                                                                                                                                               |
| -- | --------------------------------------- | ------------------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1  | Barrett's                               | endoscopy                             | 3 years                 | Follow up surveillance endoscopy for Barrett's in 3 years (if pathology confirms this diagnosis).                                                                      |
| 2  | malignancy                              | DRE, FIT testing, followup, endoscopy | —                       | DRE, FIT testing, and a followup endoscopy should be performed to reevaluate for malignancy.                                                                           |
| 3  | pleomorphic adenoma, solid mass lesions | histologic evaluation                 | —                       | Primary consideration is of a pleomorphic adenoma, however, other solid mass lesions cannot be excluded, for which histologic evaluation is necessary for specificity. |
| 4  | lung nodules                            | Follow up                             | —                       | Follow up with respirology was arranged as an outpatient to follow up on the non specific lung nodules.                                                                |
| 5  | —                                       | seen by the ID service                | 6 weeks                 | He was also seen by the ID service who recommended 6 weeks of antimicrobial therapy.                                                                                   |
| 6  | bleeding                                | colonoscopy                           | —                       | If there is further bleeding, a full colonoscopy is recommended.                                                                                                       |
| 7  | lung nodules                            | follow-up, chest CT                   | within 2 months further | Numerous subcentimeter lung nodules, for which a follow-up chest CT should be performed within 2 months further characterization.                                      |
| 8  | metastases                              | Follow-up imaging, MRI                | —                       | Follow-up imaging with MRI to evaluate for additional metastases is advised.                                                                                           |
| 9  | —                                       | transthoracic echocardiogram          | two to three years      | Reevaluation in two to three years with transthoracic echocardiogram will be recommended.                                                                              |
| 10 | weight loss                             | followup                              | —                       | She is here for a followup on her weight loss on phentermine.                                                                                                          |

## Next steps

You may want to assess the frequency distribution of reasons provided or procedures recommended. For more query examples, see [Query: Frequency of reasons for follow-up recommendations](/nlp/database/schema/relations/followup#query-frequency-of-reasons-for-follow-up-recommendations). You can also limit the follow-up relations that are returned to only those found in a specific section; for example, from Radiology reports, you may only need to review follow-up recommendations from the `IMPRESSIONS` section.

## Related links

* [Follow-up Relations](/nlp/database/schema/relations/followup)
* [Entity-level Tables](/nlp/database/schema/core/entity-tables)