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

# Cancer Staging

## Synopsis

This example shows how to use qualifier relations to extract staged cancer mentions from patient reports.

## Processing Requirements

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

* `--feature qualifier-relations, umlsnci-ontology, snomed-ontology`
* `--store-sections-and-sentences`

## Clinical Context

Medicine has many staging systems and grading systems for different pathologies, and one of the most common is the stage grouping used in cancer diagnosis and treatment. For example, a patient with lung cancer where the disease had spread to distant parts of the body would be described as 'Stage IV lung cancer'. Other diseases can use grading systems where the grade of a disease state is written as the word 'Grade' followed by a numerical value such as 'Grade 1'.

The NLP API can identify stage and grade qualifier relations between a disease subject being qualified (not limited to just cancer), and a stage or grade qualifier value. Due to how SNOMED has been constructed, there are several disease states that use unitary concepts to describe the stage of the disorder (e.g. `431856006 |Chronic kidney disease stage 2 (disorder)|`) while in other cases, there are not. In the cases where there is no unitary concept for the disease stage in SNOMED (e.g. `stage 2 COPD`), if a stage/grade qualifier value describes a disease state, the NLP API will link the stage qualifier value and the disease mention in a qualifier relation.

The query below combines a filter on a UMLS semantic type (in this case `Neoplastic process`) with a filter on a SNOMED concept ID for the stage qualifier itself. The example uses `1229978004 |American Joint Committee on Cancer staging system|`, which matches TNM values such as 'N2'. Substitute a different qualifier concept to target a different staging vocabulary — for instance `258228008 |Stage 4 (qualifier value)|` to find malignancies described as 'Stage 4' or 'Stage IV'.

## SQL query

#### SQL

```sql
SELECT qualifies_fet.type_name AS qualifies_entity_type,
    qualifies_c.concept_id AS qualifies_concept_id,
    qualifies_c.description AS qualifies_concept,
    qualifies_fe.text AS qualifies_term,
    qualifier_fe.text AS qualifier_term,
    qualifier_c.description AS qualifier_concept,
    sl.text AS sentence
FROM qualifierrelation
    -- joins to retrieve annotated term for the SUBJECT
        JOIN entity qualifies_e
        ON qualifies_e.id = qualifierrelation.qualifies_id -- JOIN on qualifie(s)_id column
        JOIN foundentity qualifies_fe
        ON qualifies_fe.id = qualifies_e.entity_id AND qualifies_e.type_='found'
    -- joins to retrieve the concept for the SUBJECT
        JOIN foundentityconcept qualifies_fec
        ON qualifies_fec.found_entity_id = qualifies_fe.id
        JOIN concept qualifies_c
        ON qualifies_c.concept_id = qualifies_fec.concept_id AND
            qualifies_c.ontology = qualifies_fec.concept_ontology
    -- joins to retrieve the entity_type for SUBJECT
        JOIN foundentitytype qualifies_fet
        ON qualifies_fet.found_entity_id = qualifies_fe.id
    -- joins to retrieve the annotated term for the QUALIFIER VALUE
        JOIN entity qualifier_e
        ON qualifier_e.id = qualifierrelation.qualifier_id -- JOIN on qualifie(r)_id column
        JOIN foundentity qualifier_fe
        ON qualifier_fe.id = qualifier_e.entity_id AND qualifier_e.type_ = 'found'
    -- joins to retrieve the concept for the  QUALIFIER VALUE
        JOIN foundentityconcept qualifier_fec
        ON qualifier_fec.found_entity_id = qualifier_fe.id
        JOIN concept qualifier_c
        ON qualifier_c.concept_id = qualifier_fec.concept_id AND
            qualifier_c.ontology = qualifier_fec.concept_ontology
    -- joins to retrieve sentence by joining with location and document tables
        JOIN foundentitylocation qualifies_fel
        ON qualifies_fe.id = qualifies_fel.found_entity_id
        JOIN location l
        ON qualifies_fel.location_id = l.id
        JOIN document d
        ON l.document_id = d.id AND l.type_ = 'sentence' -- IMPORTANT: l.type constraint is required
        JOIN sentencelocation sl
        ON sl.id = l.location_id
WHERE qualifierrelation.qualifier_type = 'stage/grade'
AND qualifies_c.ontology = 'snomed'
-- Limit to cancers using UMLS classification
AND qualifies_fet.ontology = 'umls' AND qualifies_fet.type_name = 'Neoplastic Process'
-- Limit to AJCC-staged cancers using snomed concept
AND qualifier_c.ontology = 'snomed' AND qualifier_c.concept_id = '1229978004' -- AJCC staging (Stage4 is 258228008)
ORDER BY d.id;
```

| qualifies_entity_type | qualifies_concept_id | qualifies_concept                       | qualifies_term       | qualifier_term | qualifier_concept                                        | sentence                                                                           |
| --------------------- | -------------------- | --------------------------------------- | -------------------- | -------------- | -------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| Neoplastic Process    | 422375001            | Carcinoma of colon, stage III (finding) | Stage 3 Colon Cancer | N2             | American Joint Committee on Cancer cN2 (qualifier value) | Stage 3 Colon Cancer (T3N2) - treated with surgery, declined adjuvant chemotherapy |

## Next steps

The `stage/grade` qualifier is one of several qualifier types recognized by the NLP API. The NLP API many useful qualifier types such as `status`, `size/severity`, `location`, and `duration/time`. For more information, see [Qualifier Relations](/nlp/database/schema/relations/qualifier) in the Database Schema section.

## Related links

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