# Configure Safety Views in Safety Signal

Use safety views to define the SQL and filters, which Vault references when <a href="/en/lr/753144/">running calculations</a> to detect _Product-Event Combinations_ (PECs) for pharmacovigilance (PV) data. 

Safety Signal includes the following safety views:
* **Principal Views**: Contain the largest collection of data and preconfigured parameters. For example, a _Principal View_ might include data for all postmarket _Cases_ with the _Drug_ product type. Vault derives all _Filter Views_ and _Signal Views_ from a _Principal View_. _Principal Views_ are important as some statistical methods and calculations require a complete dataset. 
* **Supporting Views**: Provisioned by your Veeva Representative to support _Principal Views_. This view type provides a subset of data for _Principal Views_ to use in report generation, for example, expectedness information.
* **Filter Views**: Contain a subset of data from a specified _Principal View_ and filters. For example, a _Filter View_ might filter on a _Product Family_ with a given start date. Vault derives a _Filter View_ from a _Principal View_. _Filter Views_ offer more specific analyses and can detect adverse events within a _Product Family_ from a given period.
* **Signal Views**: Contain the most specific subset of data in the view hierarchy. For example, a _Signal View_ might return _Case_ counts for all pediatrics in this quarter. Vault derives a _Signal View_ from a _Principal View_ and a _Filter View_.

<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: Do not edit a safety view referenced by a <a href="/en/lr/753144/#add-signal-calculation"><em>Signal Calculation</em></a> record. Any changes you make to the safety view will not be reflected in the <em>Signal Calculation Run</em> records referencing this safety view.</p>
    </div>
  </div>
</div>



The sections in this article describe the different sections of a safety view and how to configure them for signal detection. 

## Create and Access Safety Views {#create-and-access-safety-views}

To create a safety view:
1. Navigate to **Business Admin > Objects > Workbench Views**. 
2. Select **Create**. 
3. In the _Create Workbench View_ dialog, specify the type of view you want to create and then select **Continue**. 
4. Complete the following information about the safety view in the _Details_ section:
    * **Name**: Enter a **Name** for the safety view.
    * **API Name**: Enter an **API Name** for the safety view. The API Name cannot include spaces and must end in `__c`.
    * Optional: **Description**: Enter a **Description** for the safety view.
    * **Data Source**: Select a **Data Source** from the drop-down or use the **Advanced Search** (<img class="inline" src="https://platform.veevavault.help/assets/images/saf-binoculars-icon.png" alt="binoculars-icon" style="" />) icon to use filters and refine your search.
    * **View Tag**: Select a tag from the picklist to organize this safety view. <a href="/en/lr/1269/">Add values</a> to the _Workbench View Tag_ picklist as needed.
    * Optional: **Signal Case Series Enabled**: This checkbox appears only for the _Signal View_ type and is for creating <a href="/en/lr/825938/">_Signal Case Series_-enabled views</a>.

## Dependent Views {#dependent-views}

When creating a new _Filter View_ or _Signal View_, this section appears only after saving.

_Signal Views_ and _Filter Views_ are always dependent on another safety view, meaning they derive their data and configuration parameters from the specified safety view. The safety view on which the _Signal_ or _Filter View_ is dependent is known as a dependent view. A _Signal View_ is usually dependent on a _Principal View_, a _Filter View_, or both. A _Signal View_ can also be dependent on other _Signal Views_ and multiple _Filter Views_. A _Filter View_ is always dependent on a _Principal View_. 

_Principal Views_ are the basis for _Filter_ and _Signal Views_ to add filters and configuration and, therefore, are not dependent on any views.

The following illustration demonstrates an example of a safety view hierarchy. The hierarchy always starts with a _Principal View_. In this example, a _Principal View_ leads into two (2) _Filter Views_. Each _Filter View_ subsequently leads into two (2) _Signal Views_. 

<a href="https://platform.veevavault.help/assets/images/saf-signal-safety-view-hierarchy.png" data-lightbox="saf-signal-safety-view-hierarchy.png" data-title="" data-alt="saf-signal-safety-view-hierarchy">
  <img class="docimage" src="https://platform.veevavault.help/assets/images/saf-signal-safety-view-hierarchy.png" alt="saf-signal-safety-view-hierarchy" style="max-width: 60%;"  />
</a>

Although a _Signal View_ may not always include a _Principal View_ in the _Dependent Views_ section, a _Signal View_ must ultimately be associated with one (1) unique _Principal View_ through other dependent views. In the above example, _Signal Views_ A.1 and A.2 are not directly associated with the _Principal View_ but are associated with it through _Filter View_ A. If a safety view is not associated with any or is associated with more than one (1) _Principal View_, Vault prevents you from adding filters to the safety view. 

### Create a Dependent View {#create-a-dependent-view}

To add a dependent view to a safety view:
1. In the _Dependent Views_ section of the safety view, select **Create**.
2. In the _Create Workbench View Dependency_ dialog, select a dependent view.
3. Select **Save** or **Save + Create** to add another dependent view. 

**Result**

Vault adds the selected views to the _Dependent Views_ section and generates a name for each. 

The current view is now dependent on these selected safety views. 

## SQL Editor {#sql-editor}

SQL offers elaborate queries for parsing through data. You or your Veeva Representative can provide and input queries in the _SQL Editor_ section. The queries are based on Amazon Redshift SQL, which is a subset of PostgreSQL 9.x. For more information on the available SQL functions, refer to <a class="external-link " href="https://docs.aws.amazon.com/redshift/latest/dg/c_redshift-and-postgres-sql.html" target="_blank" rel="noopener">Amazon Redshift and PostgreSQL<i class="fa fa-external-link" aria-hidden="true"></i></a>. You can enlarge the _SQL Editor_ section by selecting the **Full Screen** (<img class="inline" src="https://platform.veevavault.help/assets/images/saf-maximize-sql-icon.png" alt="maximize-sql-icon" style="" />) icon.


Only _Principal Views_ and _Signal Views_ contain SQL. When previewing a _Filter View_, this view inherits queries from the associated _Principal View_.


The SQL query provides references for the fields specified in the safety view's [_Workbench View Columns_][1] section. If you [run a preview][2] of the safety view without any _Workbench View Columns_, all fields returned by the SQL query will be displayed in the preview.

The safety view can also leverage another safety view by referencing the safety view's _API Name_ in the _SQL Editor_ section, for example, `select * from ${safety_view_api_name__c}`. You must also [create a dependent view][3] for the safety view you are referencing. 

Consider the following SQL limitations and restrictions:
* Vault does not perform timeout checks when running SQL. Long-running queries will be terminated by Amazon Redshift. Related performance issues are identified through logged server errors.
* The query size limit is 32,000 characters.

### SQL Editor Search Panel {#search-panel}

Before you can access _SQL Editor_ keyboard shortcuts and the search panel, you must <a href="/en/lr/918632/">configure _SQL Editor_ enhancements</a>. After performing the necessary configuration, you can open the _SQL Editor_ search panel by using the  **Ctrl + f** or **Cmd + f** <a href="/en/lr/918630/">keyboard shortcut</a>, as applicable. 

Using the search panel, you can find or replace specific texts and syntax elements. The panel also includes the following settings:  
* _Match case_: Select this checkbox to make your keyword case sensitive.
* _Regexp_: Select this checkbox to use <a href="/en/lr/52324/#regex">regular expressions</a>.
* _By word_: Select this checkbox to search for whole words only. For example, if your keyword is `filter`, Vault excludes elements such as `filterview`.

## View Columns {#view-columns}

When creating a new safety view, this section appears only after saving.

The _View Columns_ are required for the [safety view's SQL][5] to run successfully. The fields you add to a safety view's _View Columns_ section determine the fields to which you can apply [filters][4]. The _View Columns_ section is usually populated in the _Principal View_ to inform the filters in the subsequent _Filter Views_.

Supported field types include:
* _Text_
* _Date_
* _DateTime_
* _Number_
* _Yes/No_
* _Object_
* _Picklist_
* _Multi-Value Picklist_
* _MedDRA_

### Create View Columns {#create-view-columns}

To populate the _View Columns_ section:
1. In the _View Columns_ section, select **Create**.
2. Complete the following fields in the _Create Workbench View Column_ dialog: 
    * **Name**: Enter the **Name** of the view column.
    * **API Name**: Enter the **API Name** of the view column. This value must match the name of the column returned by the [SQL query][5]. 
    * **Column Type**: Select a field type option from the drop-down. 
    * Optional: **Picklist**: If you selected the _Picklist_ column type, select a picklist option from the drop-down.
    * Optional: **Safety Object Reference**: The _Safety Object Reference_ and _Safety Object Constraint_ fields allow you to restrict the values that appear when filtering on this object. For example, you can restrict the _Controlled Vocabulary_ object to display only _Drug Roles_. Enter the API name of the object associated with this view column field.
    * Optional: **Safety Object Constraint**: The _Safety Object Reference_ and _Safety Object Constraint_ fields allow you to restrict the values that appear when filtering on this object. For example, you can restrict the _Controlled Vocabulary_ object to display only _Drug Roles_. Enter <a href="/en/lr/75340/">VQL to configure a reference constraint</a> to restrict the object values.
    * Optional: **Signal Case Series Key**: This field is for _Signal Views_ that should be executed as <a href="/en/lr/935435/#signal-case-series">_Signal Case Series_</a>. Ignore this field if it is not applicable. For more information, see <a href="/en/lr/825938/">Configure Safety Views for Signal Case Series</a>.
    * Optional: **Case Version Key**: This field is for _Signal Views_ that should be executed as <a href="/en/lr/935435/#signal-case-series">_Signal Case Series_</a>. Ignore this field if it is not applicable. For more information, see <a href="/en/lr/825938/">Configure Safety Views for Signal Case Series</a>.
3. Select **Save**.
4. Repeat the steps above to add additional columns. 
5. Optional: To delete a field, select the **Actions** menu next to the field and then select **Delete**. 

## View Parameters {#view-parameters}




When users <a href="/en/lr/935433/#run-preview-signal-calculations">apply filters to _Signal Calculations_</a>, the data set can change before the safety view SQL queries them. Using view parameters, users can enter filter values on the _Signal Calculation_ that can then be referenced directly by the safety view's SQL. View parameters appear as required filters in the _Filters_ section under the _Criteria_ subsection of the _Signal Calculation_.


<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: You cannot add <em>Workbench View Parameters</em> to a <em>Principal View</em> or a <em>Supporting View</em>.</p>
    </div>
  </div>
</div>



### Create or Add Workbench View Parameters {#create-or-add-workbench-view-parameters}

To create _Workbench View Parameters_:
1. In the _Workbench View Parameters_ section, select **Add**.
2. In the _Search: Workbench View Parameter_ dialog:
    1. Filter for and select existing parameters.
    2. Select **Create.** Complete the following information and then select **Save** or **Save + Create** to save the record and create another:
        * **Name**: Enter a name for the _Workbench View Parameter_.
        * **Description**: Enter a description for the _Workbench View Parameter_.
        * **API Name**: Enter an API name for the _Workbench View Parameter_ ending in `__c`.
        * **Optional**: Select **Yes** if the parameter is not required for the report to run. Leave this field as **No** if the parameter is required.
        * **Column Type**: Select a field type option from the drop-down.
        * **Allow user to select multiple values**: If the _Column Type_ is either _Picklist_ or _Object_, you may select **Yes** to allow users to select multiple values for this _Workbench View Parameter_. Otherwise, select **No**.
        * **Picklist Reference**: This field allows you to restrict the values that users may enter. Enter the _API Name_ of the desired picklist.
        * **Safety Object Constraint**: The _Safety Object Reference_ and _Safety Object Constraint_ fields allow you to restrict the values that appear when filtering on this object, for example, restricting the _Controlled Vocabulary_ object to display only _Drug Roles_. Enter the _API Name_ of the object associated with this view column field.
        * **Safety Object Reference**: The _Safety Object Reference_ and _Safety Object Constraint_ fields allow you to restrict the values that appear when filtering on this object, for example, restricting the _Controlled Vocabulary_ object to display only _Drug Roles_. Enter <a href="/en/lr/75340/">VQL to configure a reference constraint</a> to restrict the object values.
3. Select **OK**.



### Update Workbench View Parameters {#update-workbench-view-parameters}

You can edit custom (`__c`) _Workbench View Parameters_:
1. Navigate to **Business Admin > Objects > Workbench View Parameters > [Workbench View Parameter]**.
2. Select **Edit**.
3. Update information as needed.
4. Select **Save**.

## Filters {#filters}

You can configure filters in the _Filters_ section of the safety view. Filters you add to the safety view also appear on associated <a href="/en/lr/753144/#create-signal-calculation-runs">_Signal Calculation Run_</a> records.

You can only add safety view filters if the [_View Columns_][1] section is populated. This section can be populated on the current safety view or on the associated _Principal View_.

For more information, see <a href="/en/lr/753141/">Add Safety View Filters in Safety Signal</a>. 

<div class="note-border alert-info">
  <div class="alert alert-info" role="alert">
    <div><i class="far fa-info-circle"></i></div>
    <div class="alert-text">
      <p><strong>Note</strong>: You cannot filter on <em>Substance</em> or <em>Registration</em>. Filtering on these fields will be supported in a future release.</p>
    </div>
  </div>
</div>



### Filter Fields Mapping

When <a href="/en/lr/826975/#scheduled-signal-calculations">scheduled _Signal Calculations_</a> run, Vault uses _Reporting Period_ field values when applying filters for certain [view columns][6].

Vault uses the _Start Date_ field on the _Reporting Period_ when applying filters for the following view columns:\
* `reporting_period_start_date`
* `case_approval_date`
* `approval_date`
* `new_info_date`
* `receipt_date`
* `case_adverse_event_onset_date`
* `inactive_date`

The filters must use the _is after_ or _is in the range_ <a href="/en/lr/753141/#operators">operator</a>.

Vault uses the _End Date_ field on the _Reporting Period_ when applying filters for the following view columns:
* `reporting_period_end_date`
* `case_approval_date`
* `approval_date`
* `new_info_date`
* `receipt_date`
* `case_adverse_event_onset_date`
* `inactive_date` \
For the above view columns, the filters must use the _is before_, _is in the range_, or _equals_ operator.
* `datasheet_active_start_date`
* `datasheet_active_end_date`
* `meddra_criteria_active_start_date`
* `meddra_criteria_active_end_date` \
For the above view columns, the filters must use the _is before_ and _is after_ operator.

Vault uses the _Product Family_ field on the _Reporting Period_ when applying filters for the following view columns:
* `product_family_id` \
This is for the _Object_ column type.
* `product_family_name` \
This is for the _Text_ column type.

## Run Preview {#run-preview}

You can generate a preview of the safety view by selecting **Run** in the _Run Preview_ section. 

After you run the preview, Vault executes the SQL for this safety view and returns a list of up to 100 records. The output is displayed in a table format based on the view columns's _Column Type_. Optionally, you can select the column header to sort the records returned by the run.

If the SQL is invalid, Vault returns an error. _Run Preview_ also times out after 300 seconds. 

[1]: #view-columns
[2]: #run-preview
[3]: #create-a-dependent-view
[4]: #filters
[5]: #sql-editor
[6]: #view-columns