# Build include and exclude rules

## Overview

[Video: Build include and exclude rules](https://www.youtube.com/watch?v=i1ZgRZaJs3M)

This flow describes how to build the include and exclude rules of a facility [valueset](https://docs.ohc.network/concepts/definitions/valueset.md) in Care. The rules decide which codes the valueset contains.

## Pre-requisites

* You are on the **Create ValueSet** page or the **Edit ValueSet** page of a facility valueset. See [Create a valueset](https://docs.ohc.network/flows/definitions/valueset/create-valueset.md) or [Update or retire a valueset](https://docs.ohc.network/flows/definitions/valueset/update-or-retire-valueset.md).
* If you change an existing valueset, it is shared with your department or a sub-department of it.
* You have the permissions listed below.

## Permissions

| Permission | Access |
| - | - |
| Can Create/Update ValueSets | Lets you change the rules and save the valueset. You must hold it in the facility's root organization (**Administration**). Without it there, the rules are read only. By default, the Facility Admin role holds it. |
| Can Read ValueSets | If you change an existing valueset, lets you open it. You must hold it in a department that the valueset is shared with, or in a parent department of one. Holding it in the root organization alone is not enough, unless the valueset is shared with the root organization (**Administration**). By default, the Facility Admin, Administrator, Doctor, Nurse, Staff, Pharmacist and Volunteer roles hold it. |

## Steps

### 1. Find the rules

On the page, find the **Definition** section.

The section has **Include rules** and **Exclude rules**, each with the number of rules in it.

A rule in **Include rules** adds codes to the valueset. A rule in **Exclude rules** removes matching codes from the included codes. If a code matches both, Care leaves it out.

![Step 1, Find the rules: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-1-1c1a8fdc29b7c83e7e03d895dbf59a0f.webp)

### 2. Choose whether to use the parent rules

Do this step only if the valueset has a parent valueset.

Set the **Use parent rules** switch.

If the switch is on, Care combines the rules of the parent valueset with the rules on this page.

If the switch is off, Care uses only the rules on this page and ignores the parent rules.

Note: The **Edit ValueSet** page shows **Use parent rules** also for a valueset with no parent. For such a valueset, the switch has no effect.

![Step 2, Choose whether to use the parent rules: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-2-5111020170ec5ce075b117b8cf2ef4d5.webp)

### 3. Add a rule

Select **Add Rule** next to **Include rules** or **Exclude rules**.

Care adds a rule card, for example "Include rule 1", and opens it.

The card shows a summary line with the terminology system, the number of concepts, and the number of filters.

![Step 3, Add a rule: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-3-a3c464565996da4d57b7602fbf1b9615.webp)

### 4. Select the terminology system

In **System**, select LOINC, SNOMED, or UCUM. A new rule starts with LOINC.

If you need a specific version of the terminology system, enter it in **Version**. This field is optional.

An include rule with no concepts and no filters takes every code in its terminology system. An exclude rule like this removes every code in its terminology system. Care shows a warning on such a rule.

If you change **System** later, Care clears the verified names of the concepts in the rule. Verify the codes again.

![Step 4, Select the terminology system: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-4-1690002bbaa9d1342c3fdb5959ad2f1e.webp)

### 5. Add exact codes

Use concepts or filters in a rule, not both. To use both, add a separate rule.

1. Under **Concepts**, select **Add Concept**. Care adds a row with a **Code** box and a name box that shows **Unverified**.
2. Enter the code in the **Code** box.
3. Select **Verify**.

Care fills in the name of the concept and shows **Code verified successfully**. The button changes to **Code Verified**.

If Care cannot find the code, it shows **We couldn't verify this code. Check the code and terminology system, then try again.**

If you change a code after you verify it, Care clears its name. Verify the code again.

Verify every concept before you save. If a concept is not verified, Care shows **Verify this code before saving.**

![Step 5, Add exact codes: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-5-14008d6e49b006444a297234807a264f.webp)

### 6. Add filters

A filter matches a group of codes by a property of the terminology system.

1. In the rule card, open **Advanced: filter by properties**.
2. Select **Add Filter**. Care adds a row with **Property**, **Operator**, and **Value** boxes.
3. Enter the property.
4. Enter the operator.
5. Enter the value.

All three boxes are required.

Care accepts only these operators: `=`, `is-a`, `descendent-of`, `is-not-a`, `regex`, `in`, `not-in`, `generalizes`, `child-of`, `descendent-leaf`, and `exists`. If you enter another operator, Care does not save the valueset.

![Step 6, Add filters: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-6-9d94e9879f6be6d201093a7528c35451.webp)

### 7. Remove a rule, a concept, or a filter

To remove a rule, select the trash button on its card. Care shows **Rule removed** and an **Undo** button.

To bring back the rule, select **Undo**.

To remove one concept or one filter, select the trash button on its row.

![Step 7, Remove a rule, a concept, or a filter: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-7-4516bb9478814eba23c0b503d9c7fac6.webp)

### 8. Save the valueset

Select **Save**.

If a rule has an error, its card shows **Needs attention**. Care lists the errors under **Review these fields before saving**.

![Step 8, Save the valueset: the screen at this step, with the control for the step outlined](/assets/images/build-include-and-exclude-rules-8-52d0e4777b3fce4e054568f94f28dfa3.webp)

## Expected Outcome

* The valueset contains the include rules and the exclude rules that you built.
* The valueset gives the codes that match an include rule, minus the codes that match an exclude rule.
* If the valueset has a parent and **Use parent rules** is on, Care also uses the parent rules.

## Related

Concepts:

* [Valueset](https://docs.ohc.network/concepts/definitions/valueset.md)

Flows:

* [Create a valueset](https://docs.ohc.network/flows/definitions/valueset/create-valueset.md)
* [Customize a shared valueset](https://docs.ohc.network/flows/definitions/valueset/customize-shared-valueset.md)
* [Preview a valueset](https://docs.ohc.network/flows/definitions/valueset/preview-valueset.md)
* [Update or retire a valueset](https://docs.ohc.network/flows/definitions/valueset/update-or-retire-valueset.md)
