# Configuring CoA Matching Rule Variants (QMS)

After <a href="/en/gr/627672/">configuring the required CoA matching rules</a>, you must create CoA matching rule variants to define various alternate terms for each matching rule to improve the accuracy of field value ingestion.

<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>: This feature is currently available only to Early Adopters. Contact your Veeva Representative for more details.</p>
    </div>
  </div>
</div>



## About Matching Rule Variants {#about}

Matching rule variants for _Header Key_, _Header Value_, and _Table Column_ matching rule types have configurable options to ensure the header and table data is ingested accurately. Vault maps matching rule variants using the _Supplier Name_, _Supplier Manufacturing Site Name_, and _Material_ fields to filter and apply against the ingested data. At least one (1) or more of these fields should contain a value for defining matching rule variants specific to each supplier, supplier manufacturer, or material so that Vault can match more accurately to the appropriate data location on the CoA file provided using _Variant Types_.

When a user runs the _Analyze COA_ action, depending on whether the _Inspection_ record's fields (_Supplier Name_, _Supplier Manufacturing Site Name_, and _Material_) have a value or not, Vault matches the variants based on the specified _Variant Type_. For example, if the _Supplier Name_ field is specified but the _Supplier Manufacturing Site Name_ and _Material_ fields are empty, Vault matches using matching rule variants that have the same _Supplier Name_ value and empty _Supplier Manufacturing Site Name_ and _Material_. If no matching rule variant is defined, Vault matches to global variants, which have empty _Supplier Name_, _Supplier Manufacturing Site Name_, and _Material_ fields.

### Matching Rule Variant Types {#variant-types}

The following are the types of matching rule variants you can use to define the logic to use to interpret data:

* **Complex**: Used to load coordinates by mapping to a location where a value may be found in particular CoA files. You can use this type for variants located in consistent areas for the supported fields. You must [provide the coordinates in JSON format][1]. If your Vault supports <a href="/en/gr/69952/#multi-batch">multi-batch CoA files</a>, the _Complex_ variant type will not be available.
* **Exact Match**: Used to map an exact value in a CoA file to a field. _Exact Match_ values are not case-sensitive.
* **Contains**: Used to map to a defined matching rule variant that comprises specific values.
* **Starts With**: Used to map to a defined matching rule variant that begins with specific values.
* **Ends With**: Used to map to a defined matching rule variant that concludes with specific values.
* **Regex**: A regular expression, used to map a pattern of possible matches in a CoA file to a field.

Vault may use global matching rule variants as generic variants for all _Inspection_ records if there aren't specific matching rule variants to better map to a variant text. For example, you can create a _COA Matching Rule Variant_ record with the "Units" _Variant Text_ value for the "UoM" _COA Matching Field_ key with blank fields for _Supplier Name_, _Supplier Manufacturing Site Name_, and _Material_ fields. This record applies to all _Inspection_ records unless a matching rule variant with existing values for the _Supplier Name_, _Supplier Manufacturing Site Name_, or _Material_ fields is available for a comprehensive match.

### Header Key Matching Rule Priorities {#rule-priority}

When a CoA matching rule of type _Header Key_ has matching rule variants, Vault matches rule variants by most specific first. For rules with the same scope, Vault matches rule variants in the following priority:

1. Complex
2. Matching Strategy:
  * Regex
  * Exact Match
  * Starts With
  * Contains
  * Ends With
3. Vicinity Strategy (find value to the right or below the key):
  * Exact Match

### Example CoA Matching Rule Variant Usages {#example-variant}

You can create CoA matching rule variants to define and ensure the best possible CoA file analysis accuracy with the following usages:

* You might create a _Header Key_ <a href="/en/gr/627672/">matching rule</a> with a _Complex_ matching rule variant to specify coordinates for the value of the key field "Best Before Date", so that you can map to the field in Vault called "Supplier Expire Date". The value of the key field is "12/13/2020"; you can locate the _Complex Matching Rule_ coordinates from the applicable [CSV file][1] for configuration in JSON format: `{ "ocr_left": 0.0533, "ocr_top": 0.4812}`.
* You might create a _Header Key_ matching rule with a _Regex_ matching rule variant to cover the possible permutations of the term "lot code", which may appear in a CoA file so that you can map to the field in Vault called "Supplier Manufacturer Lot Code".
* You might create a _Header Key_ matching rule with a _Contains_ matching rule variant to match a specific keyword of "supp", which may appear in the header section of a CoA file intended as the word "Supplier", so that you can map to the field in Vault called "Supplier Name".
* You might create a _Header Key_ matching rule with an _Exact Match_ matching rule variant to match the _Product_ field in a CoA file to a _Supplemental Field_ in Vault. If configured by your Admin, Vault can use this information to locate a relevant _Inspection Plan_ and populate it on the _Inspection_.
* You might create a _Header Value_ matching rule with a _Starts With_ or _Exact Match_ matching rule variant to match an expected material description value without a header key field in a CoA file.
* You might create a _Table Column_ matching rule with an _Exact Match_ matching rule variant to match the table column in the CoA file called "UNITS" to the field called "UoM".
* You might create a _Table Column_ matching rule with a _Starts With_ matching rule variant to match the table column in the CoA file beginning with "Char" to the field called "Characteristic".

## Configuring CoA Matching Rule Variants {#config-variant}


<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>: As an alternative to manually creating variant records, we recommend using the <a href="/en/gr/824752/"><em>COA Ingestion Setup</em> panel</a> to guide you through the CoA variant setup process all in a single page.</p>
    </div>
  </div>
</div>



To configure CoA matching rule variants:

1. Navigate to the appropriate _COA Matching Rule_.
2. In the _COA Matching Rule Variants_ section, click **Create**.
3. Enter the **Variant Text**. 
   * This is the text which, depending on the **Variant Type** value, is either matched exactly, mapped to a JSON coordinate, or checked for variant matches.
   * If you expect a key field in a CoA file to contain a colon, there is no need to add it to the variant text. Vault does not ingest values for matching fields if the relevant variant text is followed by a colon.
4. Select a **Variant Type**.
5. Optional: Select a **Supplier Manufacturing Site Name**.
6. Optional: Select a **Supplier Name**.
7. Optional: Select a **Material**.
8. Optional: Enter the **Expected Value Format**. 
   * The value must follow the <a class="external-link " href="https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html" target="_blank" rel="noopener">SimpleDateFormat<i class="fa fa-external-link" aria-hidden="true"></i></a> as outlined by Oracle for _Date_ data type or by using Regex for _Text_ data type. 
   * If the variant is for a _Header Value_ type matching rule, leave this field blank.
9.  Optional: Select a **Language**.
10. Click **Save**. To create another matching rule variant, click **Save + Create**.

Complex CoA matching rule variants cannot be saved successfully if both _Supplier Manufacturing Site Name_ and _Supplier Name_ fields do not have values. If the _Language_ field does not have a value set, the default value is set to English and CoA file content is matched only to English (default) variants.

## Downloading CoA OCR Data Files {#download-file}

When you need to find the JSON coordinates for [_Complex_ matching rules][2], you can run the _Download COA OCR Data_ action to export the CSV file. The _Download COA OCR Data_ action is only available for selection when the _COA Inspection_ record has been <a href="/en/gr/515322/#how_to_analyze_a_coa">analyzed</a> within the last 30 days - you will need to re-run the _Analyze COA_ action again if more than 30 days have elapsed. You first need to <a href="/en/gr/69952/#config-coa-actions">configure the user action</a> to run _Download COA OCR Data_.

To download an OCR data file for CoA inspection:

1. Navigate to the appropriate _COA Inspection_.
2. Select **Download COA OCR Data** from the **All Actions** menu. Once complete, a Vault notification will provide a link to download the CSV file.

Once you have downloaded the CSV file, locate the _Complex Matching Rule_ coordinates for the _OCR Text_ required for configuring _Complex_ matching rule variants. For example, if you require the value for "Best Before Date", which is "12/13/2020", locate the _Complex Matching Rule_ coordinates for the "12/13/2020" _OCR Text_ to use for configuration. Here is an example of how your CSV file may display:

<table>
  <tr>
    <th><strong>OCR Text</strong></th>
    <th><strong>Complex Matching Rule</strong></th>
  </tr>
  <tr>
    <td>…</td>
    <td>…</td>
  </tr>
  <tr>
    <td>Best Before Date</td>
    <td><code>{ "ocr_left": 0.0526, "ocr_top": 0.3512}</code></td>
  </tr>
  <tr>
    <td>12/13/2020</td>
    <td><code>{ "ocr_left": 0.0533, "ocr_top": 0.4812}</code></td>
  </tr>
  <tr>
    <td>…</td>
    <td>…</td>
  </tr>
</table>

## Limitations

The following limitations apply to CoA matching rule variants:

* You can create up to ten _COA Matching Rule Variants_ for _Header Value_ type _COA Matching Rules_.
* The _Complex_ variant type is not available for variants of _Table Column_ and _Header Value_ type _COA Matching Rules_.
* The _Regex_ variant type is not available for variants of _Header Value_ type _COA Matching Rules_.
* Entering an _Expected Value Format_ on _COA Matching Rule Variant_ records is not supported for _Header Value_ type _COA Matching Rules_.

[1]: #download-file
[2]: #variant-types