> For the complete documentation index, see [llms.txt](https://docs.snomed.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.snomed.org/snomed-ct-specifications/snomed-ct-compositional-grammar-specification/examples/6.5-expression-with-nested-refinements.md).

# Expression With Nested Refinements

It is also possible to nest expressions, one inside the other. Any valid expression may be enclosed in a pair of brackets, and included as the value of an attribute in another expression. For example, the following expression describes a medication product that has a single dose form, which is both a spray and a suspension:

{% code overflow="wrap" %}

```
373873005 |Pharmaceutical / biologic product| :
411116001 |Has dose form| = ( 421720008 |Spray dose form| + 7946007 |Drug suspension|)
```

{% endcode %}

In the example above, note the use of round brackets (i.e. "( )") to identify a nested expression, as opposed to braces (i.e. "{ }"), which is used to identify attribute groups.

The following examples show how complex expressions may be build up from simple ones, a layer at a time. This first expression describes a left hip structure:

```
24136001 |Hip joint structure| :
272741003 |Laterality| = 7771000 |Left|
```

This next expression uses the "left hip" expression above to describe a procedure to replace it:

```
397956004 |Prosthetic arthroplasty of the hip| :
363704007 |Procedure site| = ( 24136001 |Hip joint structure| :
272741003 |Laterality| = 7771000 |Left| )
```

Applying a further grouped refinement to the above describes a procedure to replace a left hip by inserting a prosthesis. Note that this example mixes an ungrouped qualification and a grouped qualification. Where this is done, the canonical representation of the expression includes all ungrouped attributes before the grouped ones (see Terminology Services Guide for more details). Please also note that in the previous version of this standard a comma was not permitted between the last ungrouped attribute and the first attribute group – however this comma is now optional to avoid unexpected syntax errors.

{% code overflow="wrap" %}

```
397956004 |Prosthetic arthroplasty of the hip| :
405814001 |Procedure site - indirect| = ( 24136001 |Hip joint structure| : 272741003 |Laterality| = 7771000 |Left| ),
{ 363699004 |Direct device| = 304120007 |Total hip replacement prosthesis| ,
260686004 |Method| = 425362007 |Surgical insertion - action| }
```

{% endcode %}

Finally, the above expression may be included within a contextual wrapper, to describe a procedure that has been performed on a patient to replace a left hip by inserting a prosthesis.

```
243796009 |Situation with explicit context| :
{ 408730004 |Procedure context| = 385658003 |Done| ,
408731000 |Temporal context| = 410512000 |Current or specified| ,
408732007 |Subject relationship context| = 410604004 |Subject of record| ,
363589002 |Associated procedure| =
( 397956004 |Prosthetic arthroplasty of the hip| :
405814001 |Procedure site - indirect| = ( 24136001 |Hip joint structure| :
272741003 |Laterality| = 7771000 |Left| )
{ 363699004 |Direct device| = 304120007 |Total hip replacement prosthesis| ,
260686004 |Method| = 425362007 |Surgical insertion - action| } ) }
```

<a href="https://docs.google.com/forms/d/e/1FAIpQLScTmbZIf0UEQwYDkY27EEWBkaiYkHSbR0_9DmFrMLXoQLyL7Q/viewform?usp=pp_url&#x26;entry.1767247133=Compositional-Grammar-Specification&#x26;entry.670899847=Expression%20With%20Nested%20Refinements" class="button primary">Provide Feedback</a>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.snomed.org/snomed-ct-specifications/snomed-ct-compositional-grammar-specification/examples/6.5-expression-with-nested-refinements.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
