**APPENDIX D-6**

Associate Sample Analytical Results to Sample Schedule

Monitoring Period Assignments and Sampling Point Sub-SSMPAs

This Page is intentionally left blank

**D-6. Associate Sample Analytical Results to Sample Schedule Monitoring
Period Assignments and Sampling Point Sub-SSMPAs (Section 9.2.6)**

Check-Point Restart Issues: This process will be driven by changes to
the TSASAMPL, TSASAR and the SSMPA tables. This process needs to be
split into three subprocesses:

-   *Subprocess A. Associate Sample Analytical Results of New or Changed
    Samples to SSMPAs and Sampling Point Sub-SSMPAs.*

> The driver for this subprocess is the Sample table.
>
> The record key for this subprocess is the composite of CDS trigger
> timestamp and the TSASAMPL_IS_NUMBER columns.
>
> The sort order for this subprocess will be CDS trigger timestamp
> ascending and TSASAMPL_IS_NUMBER ascending.

-   *Subprocess B. Associate New or Changed Sample Analytical Results to
    SSMPAs and Sampling Point Sub-SSMPAs*.

> The driver for this subprocess is the Sample Analytical Result table.
>
> The record key for this subprocess is the composite of CDS trigger
> timestamp and the TSASAR_IS_NUMBER columns.
>
> The sort order for this subprocess will be CDS trigger timestamp
> ascending and TSASAR_IS_NUMBER ascending.

-   *Subprocess C. Associate New SSMPAs and Sampling Point Sub-SSMPAs to
    SARs.*

> The driver for this subprocess is the SSMPA table.
>
> The record key for this subprocess is the composite of CDS trigger
> timestamp and the TMNSASCH_IS_NUMBER and the TMNMPRD_IS_NUMBER
> columns.
>
> The sort order for this subprocess will be CDS trigger timestamp
> ascending and TMNSASCH_IS_NUMBER and TMNMPRD_IS_NUMBER ascending.

*Subprocess A. Associate Sample Analytical Results of New or Changed
Samples to SSMPAs and Sampling Point Sub-SSMPAs.*

36012. Create a log in the CDS Execution Log indicating the process
       start time.

```{=html}
<!-- -->
```
1.  Identify results that meet the following criteria:

    a.  Whose CDS trigger timestamp or whose parent sample=s CDS trigger
        timestamp is greater than the last time the *CDS Setup* program
        was run AND

    b.  Whose Data Quality Code is accepted (A) or validated (V) AND

    c.  Whose parent Sample=s Compliance Purpose Indicator Code is equal
        to "Y" AND

    d.  Whose parent Sample is a Sample Type of routine (RT) or maximum
        residence time (MR) AND

    e.  Whose parent Sample=s Rejection Reason Code is blank AND

    f.  Either whose parent Sample=s Collection End Date or if the
        Result is already associated to a Monitoring Period, its
        Monitoring Period End Date is greater than or equal to the CDS
        History Date.

    g.  If the result is for an analyte whose type code = "MOR", it was
        not taken from a sampling point that is associated to a WSF of
        type = "DS"

2.  Then the process will attempt to assign each result to an SSMPA that
    is for the same analyte as the result:

> \[*Developer Note: The following action block, "Associate SSMPAs and
> Sampling Point Sub-SSMPAs to SARs," is reused below.*\]

a.  For each result, do the following:

    i.  If the Result is associated to a Monitoring Period that does not
        correlate with the Result=s collection end date, determine
        SSMPAs where:

        1.  the Sample Schedule referenced by the SSMPA references a
            Monitoring Requirement for the same analyte as the Result
            and

        2.  the SSMPA references a Sample Schedule for the same Water
            System Facility as the Result=s parent Sample AND

        3.  the Result=s Monitoring Period is the same Monitoring Period
            associated to the SSMPA

    ii. If the Result is not associated to a Monitoring Period or is
        associated to a Monitoring Period that correlates with the
        Result=s collection end date,

        1.  If Result is a replacement sample (parent Sample's
            Replacement Ind Cd is equal to 'Y') and is associated to an
            original Sample:

            a.  If a Monitoring Period is associated to the Result for
                the same Analyte in the original Sample, determine
                SSMPAs where:

                i.  the Sample Schedule referenced by the SSMPA
                    references a Monitoring Requirement for the same
                    analyte as the Result AND

                ii. the Monitoring Period associated to the Result for
                    the same Analyte in the original Sample is the same
                    Monitoring Period associated to the SSMPA

                    Otherwise, determine SSMPAs where:

        ```{=html}
        <!-- -->
        ```
        1.  the Sample Schedule referenced by the SSMPA references a
            Monitoring Requirement for the same analyte as the Result
            AND

        2.  the parent sample or if the sample is a replacement sample
            and is associated to an original sample, the original sample
            was collected during the applicable period for the SSMPA
            (Collection End Date between SSMPA Applicable Period Begin
            Date and Applicable Period End Date) AND

        3.  the parent Sample or if the sample is a replacement sample
            and is associated to an original sample, the original sample
            was collected during the season indicated by the Sample
            Schedule=s Seasonal Period

> \[*Developer Note: This is similar to an action block that runs during
> the Assign Sample Schedules to Monitoring Periods. It is necessary to
> also run it here to ensure that, for schedules calling for greater
> than annual periodicity but having a seasonal collection period, only
> sample collected during the seasonal collection period are associated
> to the SSMPA or* *Sampling Point Sub-SSMPAs. This really is only
> needed for Sample Schedule=s whose periodicity is greater than annual
> but it does not hurt to run it for all.*\]
>
> The detailed specifications are as follows:

a.  if the Seasonal Period Begin Month and Day are before the Seasonal
    Period End Month and Day for the Sample Schedule, then:

> the Month and Day of the Sample Collection End Date is greater than or
> equal to the Seasonal Period Begin Month and Day and less than or
> equal to the Seasonal Period End Month and Day

b.  if the Seasonal Period Begin Month and Day are after the Seasonal
    Period End Month and Day for the Sample Schedule, then either the
    Month and Day of the parent Sample=s Collection End Date:

    i.  is greater than or equal to the Seasonal Period Begin Month and
        Day and less than or equal to December 31 OR

    ii. is greater than or equal to January 1 and less than or equal to
        the Seasonal Period End Month and Day.

```{=html}
<!-- -->
```
i.  In either case, the parent=s Sample Type Code is equal to the
    Schedule=s Monitoring Requirement Sample Type Code or if the
    parent=s Sample Type Code is equal to \>RT= one of the following
    combinations exists:

+---------------+--------------------------+--------------------------+
| **TSASAMPL**  |                          | **TMNMNR**               |
+===============+==========================+==========================+
| TYPE\_        | LD_COP\_                 | SAMPLE\_                 |
|               |                          |                          |
| CODE          | SAMP_TYP_CD              | TYPE_CODE                |
+---------------+--------------------------+--------------------------+
| RT            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| MR            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | AT                       | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | FSD                      | RT                       |
+---------------+--------------------------+--------------------------+

a.  Link the Result to the SSMPA by creating an SSMPA SAR Association
    record:

> \[*Developer Note: The following action block, ACalculate Compliance
> Value@ is reused below.*\]

?.  If analyte for the result is 3100 OR if the Monitoring Requirement
    is associated to a Violation Type and the Violation Type Code is not
    equal to the following: A04\", A11\", A23\", A24\", A25\", A26\",
    A27\" (and analyte code = A0999\", A1006\", A1008\" or A1009\"),
    A29\", A31\", A36\", A38\", A49\", A51\", A52\", A53\" or A56\", use
    the following logic to populate the Compliance Value and Compliance
    Value UOM code fields for the new/updated SSMPA SAR Association
    record. Otherwise, do not calculate the Compliance Value (skip the
    following but go ahead and create the SSMPA SAR Association record
    and proceed to 3.b.ii).

    39228. If Result=s Concentration Measure is greater than 0 and Less
           Than Ind is not equal to \>Y=, then set the Compliance Value
           to the Result=s Concentration Measure. Otherwise, set to 0.

    ```{=html}
    <!-- -->
    ```
    1.  Set the Compliance Value UOM to the Result=s Concentration UOM
        or if the Result=s Less Than Ind is equal to \>Y=, then set
        Compliance Value UOM to Detection Limit UOM.

```{=html}
<!-- -->
```
i.  If analyte for the result is 3014, read MAR (Microbial Analytical
    Result) associated to result

    1.  If MAR Count UOM Code = "100ML" AND MAR Count Type = "CFU" or
        "COLONIES" or "MPN", set the Compliance Value to the MAR Count
        Qty.

    2.  Set the Compliance Value UOM to "CFU/100ML"

    3.  IF MAR Count UOM Code is not equal to "100ML" OR MAR Count Type
        is not either of "CFU" or "COLONIES" or "MPN", create an
        advisory referencing message number 59 and record the water
        system number, name, tinwsys_is_number, and tinwsys_st_code of
        the water system record; the state_asgn_id and name of the water
        system facility record; the ID and Description of the sampling
        point, and the analyte for the result and the sample laboratory
        number (TSASAMPL.LAB_ASGND_ID_NUM) and collection date for the
        associated sample.

ii. If analyte for the result is 3015, read MAR associated to result

    1.  If MAR Count UOM Code = "LITER" AND MAR Count Type = "OCYSTSO"
        or "OCYSTSC", set the Compliance Value to the MAR Count Qty.

    2.  Set the Compliance Value UOM to "LITER"

    3.  IF MAR Count UOM Code is not equal to "LITER" OR MAR Count Type
        is not either of "OCYSTSO" or "OCYSTSC", create an advisory
        referencing message number 58 and record the water system
        number, name, tinwsys_is_number, and tinwsys_st_code of the
        water system record; the state_asgn_id and name of the water
        system facility record; the ID and Description of the sampling
        point, and the analyte for the result and the sample laboratory
        number (TSASAMPL.LAB_ASGND_ID_NUM) and collection date for the
        associated sample.

iii. Associate SSMPA SAR Association to Result.

iv. Associate SSMPA SAR Association to SSMPA.

```{=html}
<!-- -->
```
a.  If the result has Confirmation Results associated to it, use the
    same logic above to link the Confirmation Result to the SSMPA
    (3.b.i-iii)

b.  In addition to associating the Result to the SSMPA,

    ?.  set the CDS trigger timestamp for the SSMPA and the Sampling
        Point Sub-SSMPA to the current date and time (whether the link
        previously existed or not) AND

    ```{=html}
    <!-- -->
    ```
    i.  link the Result, if not already linked to a Monitoring Period,
        directly to the Monitoring Period referenced by the SSMPA AND

    ii. determine if the next appropriate monitoring period exists for
        the Sample Schedule (using logic described above under
        **Associate Monitoring Periods to Sample Schedules**)

        348. If it exists, go on to the next result (note that the
             **Associate CDS Setup-Created Monitoring Periods to Sample
             Schedules** process will link the Sample Schedule to the
             next monitoring period)

        ```{=html}
        <!-- -->
        ```
        1.  If it does not exist,

            l.  then create the next appropriate monitoring period as
                follows (for SS2.0 add logic to include periodicities of
                2W and 2M):

                mcdlxviii. Begin Date = End Date of current monitoring
                           period plus 1 day

                ```{=html}
                <!-- -->
                ```
                i.  End Date = Begin Date from above plus periodicity of
                    Sample Schedule (TMNMNR-Sample Count Unit Code)
                    minus 1 day

                ii. Duration (Type Code) = code for the periodicity of
                    the Sample Schedule

                iii. Name = name created by action block used in
                     Violation maintenance when creating a new
                     monitoring period

                iv. User ID = "CDSSETUP"

> \[*Developer Note: The following action block, "Determine and Create
> SAR association to SubSSMPA," is reused below.\]*

iii. identify the Subschedule SSMPA associated to the same sampling
     point as the Result=s parent Sample. If found:

     1872. Identify a Sampling Plan and associated Sampling Plan
           Sampling Point Asgmt) where:

           z.  the Sampling Plan Sample Point Ind Code is \>Y= - Use for
               compliance AND

           ```{=html}
           <!-- -->
           ```
           a.  the Sampling Plan Begin Date is equal or less than the
               SSMPA Applicable Period Begin Date AND

           b.  the Sampling Plan End Date is null or is equal or greater
               than the SSMPA Applicable Period Begin Date AND

           c.  the Sampling Plan Sampling Point Asgmt Begin Date is
               equal or less than the SSMPA Applicable Period Begin Date
               AND

           d.  the Sampling Plan Sampling Point Asgmt End Date is equal
               or greater than the SSMPA Applicable Period Begin Date
               AND

           e.  the Sampling Plan is associated to the same Analyte
               referenced by the SSMPA through the Schedule or if the
               Sampling Plan is associated to an Analyte Group, the
               Analyte referenced by the SSMPA through the Schedule is
               part of the Analyte Group.

     ```{=html}
     <!-- -->
     ```
     1.  If a Sampling Plan was found, retrieve the Sampling Plan Dates
         associated to the Sampling Plan Sampling Point Asgmt. For each
         Sampling Plan Date retrieved, determine if the Result=s
         Collection End Date falls between the Sampling Plan Date plus
         or minus the Tolerance (in days). If a Sampling Plan Date is
         found that satisfies the above criteria, associate the Result
         to the Subschedule SSMPA by creating a SPUBA SAR Association
         and associating it to the Result and Subschedule SSMPA.

     2.  Otherwise, if a Sampling Plan was not found, associate the
         Result to the Subschedule SSMPA by creating a SPUBA SAR
         Association and associating it to the Result and Subschedule
         SSMPA

iv. If Sample Schedule=s Substitute Indicator = \>O= (substitute only if
    there is no matching result), disassociate substitute results
    already associated to the SSMPA.

    2904. Identify SSMPA SAR Associations (and associated Results) where
          the analyte referenced by the Result is not equal to the
          SSMPA=s (via the referenced Monitoring Requirement referenced
          by the Sample Schedule referenced by the SSMPA)

    ```{=html}
    <!-- -->
    ```
    1.  For each substitute result identified above, disassociate
        substitute result from the SSMPA by deleting the SSMPA SAR
        Association.

v.  Determine if preliminary or validated violations are already
    associated to the result being processed.

    3420. Identify Violations where:

          n.  the Violation Status Type Code is P - Preliminary or V -
              Validated AND

          ```{=html}
          <!-- -->
          ```
          a.  the Violation is associated the Result via the Violation
              Sample Result Asgmt AND

          b.  the Violation is associated to the same Monitoring Period
              as the Result AND

          c.  the Violation is for the same Water System as the Result
              AND

          d.  if the Violation is associated to a Water System Facility,
              it is for the same Water System Facility as the Result

    ```{=html}
    <!-- -->
    ```
    1.  For each Violation identified, CDS Setup will create an advisory
        record (Message \# 45) and will record the water system number,
        name, tinwsys_is_number, and tinwsys_st_code of the water system
        record; the state_asgn_id and name of the water system facility
        record; Violation Year, FedRep ID (if the violation is hidden,
        the ID from the Group Violation record will be recorded),
        status, analyte or analyte group code (if the violation is
        hidden, the analyte group code of the Group Violation will be
        recorded), otherwise the analyte code will be recorded),
        violation type, State Violation Period Begin and End Dates of
        the violation.

```{=html}
<!-- -->
```
a.  Next, the process will attempt to assign the result as a substitute
    to Schedules that allow substitutes to be assigned (Substitute
    Indicator is either \>A= - always allow substitution or \>O= -
    optionally allow substitution:

    ?.  If the Result=s analyte is not listed in the SAR Analyte column
        of the substitute crosswalk table, processing for this result is
        finished and move on to the next result.

    ```{=html}
    <!-- -->
    ```
    i.  Otherwise, for each corresponding Schedule Analyte in the
        crosswalk table together with which the SAR Analyte is listed,
        do the following:

        4968. If the Result is associated to a Monitoring Period that
              does not correlate with the Result=s collection end date,
              determine SSMPAs where:

              b.  the Sample Schedule referenced by the SSMPA references
                  a Monitoring Requirement for the Schedule Analyte AND

              ```{=html}
              <!-- -->
              ```
              a.  the SSMPA references a Sample Schedule for the same
                  Water System Facility as the Result=s parent Sample

              b.  the Result=s Monitoring Period is the same Monitoring
                  Period associated to the SSMPA

        ```{=html}
        <!-- -->
        ```
        1.  If the Result is not associated to a Monitoring Period or is
            associated to a Monitoring Period that correlates with the
            Result=s collection end date, determine SSMPAs where:

            a.  the Sample Schedule referenced by the SSMPA references a
                Monitoring Requirement for the Schedule Analyte AND

            b.  the SSMPA references a Sample Schedule for the same
                Water System Facility as:

                i.  the Result=s parent Sample or

                ii. If the sample is a replacement and is associated to
                    an original, the original's Sample

                    AND

            c.  the sample was collected during the applicable period
                for the SSMPA (Collection End Date between SSMPA
                Applicable Period Begin Date and Applicable Period End
                Date) AND

            d.  the parent Sample or if the sample is a replacement
                sample and is associated to an original sample, the
                original sample was collected during the season
                indicated by the Sample Schedule=s Seasonal Period

> \[*Developer Note: This is similar to an action block that runs during
> the Assign Sample Schedules to Monitoring Periods. It is necessary to
> also run it here to ensure that, for schedules calling for greater
> than annual periodicity but having a seasonal collection period, only
> sample collected during the seasonal collection period are associated
> to the SSMPA or* *Sampling Point Sub-SSMPAs. This really is only
> needed for Sample Schedule=s whose periodicity is greater than annual
> but it does not hurt to run it for all.*\]
>
> The detailed specifications are as follows:

?.  if the Seasonal Period Begin Month and Day are before the Seasonal
    Period End Month and Day for the Sample Schedule, then:

> the Month and Day of the Sample Collection End Date is greater than or
> equal to the Seasonal Period Begin Month and Day and less than or
> equal to the Seasonal Period End Month and Day

i.  if the Seasonal Period Begin Month and Day are after the Seasonal
    Period End Month and Day for the Sample Schedule, then either the
    Month and Day of the parent Sample=s Collection End Date:

    1.  is greater than or equal to the Seasonal Period Begin Month and
        Day and less than or equal to December 31 OR

    2.  is greater than or equal to January 1 and less than or equal to
        the Seasonal Period End Month and Day.

```{=html}
<!-- -->
```
2.  In either case, the parent=s Sample Type Code is equal to the
    Schedule=s Monitoring Requirement Sample Type Code or if the
    parent=s Sample Type Code is equal to \>RT= one of the following
    combinations exists:

+---------------+--------------------------+--------------------------+
| **TSASAMPL**  |                          | **TMNMNR**               |
+===============+==========================+==========================+
| TYPE\_        | LD_COP\_                 | SAMPLE\_                 |
|               |                          |                          |
| CODE          | SAMP_TYP_CD              | TYPE_CODE                |
+---------------+--------------------------+--------------------------+
| RT            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| MR            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | AT                       | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | FSD                      | RT                       |
+---------------+--------------------------+--------------------------+

3.  For each SSMPA identified:

    f.  If associated Sample Schedule=s Substitute Indicator is equal to
        N - Never use substitutes, processing for SSMPA is finished and
        move on to the next SSMPA.

    ```{=html}
    <!-- -->
    ```
    a.  If associated Sample Schedule=s Substitute Indicator is equal to
        O - Optionally substitute:

        ?.  Identify SSMPA SAR Associations (and associated Results)
            where the analyte referenced by the Result is equal to the
            SSMPA=s (via the referenced Monitoring Requirement
            refererenced by the Sample Schedule referenced by the SSMPA)

        ```{=html}
        <!-- -->
        ```
        i.  If one or more Results are found that satisfy the above
            criteria, processing for this SSMPA is finished. Move on to
            the next qualifying SSMPA.

        ii. Otherwise, proceed with substitutions

    b.  Otherwise (allow substitutions), if the SSMPA satisfies the
        substitution criteria as specified in the substitute crosswalk
        table, link the Result to the SSMPA by creating an SSMPA SAR
        Association record and use the same logic described above under
        *Calculate Compliance Value*. Use the appropriate Concentration
        Measure as indicated in the Calculated Substitute Compliance
        Value column of the substitute crosswalk table.

    c.  Use the same logic described above under *Determine and Create
        SAR association to SubSSMPA* to assign the Result to an
        applicable Sampling Point Sub-SSMPA.

    d.  Determine if preliminary or validated violations are already
        associated to the result being associated.

        ?.  Identify Violations where:

            20768. the Violation Status Type Code is P - Preliminary or
                   V - Validated AND

            ```{=html}
            <!-- -->
            ```
            1.  the Violation is associated the Result via the Violation
                Sample Result Asgmt AND

            2.  the Violation is associated to the same Monitoring
                Period as the Result AND

            3.  the Violation is for the same Water System as the Result
                AND

            4.  if the Violation is associated to a Water System
                Facility, it is for the same Water System Facility as
                the Result

        ```{=html}
        <!-- -->
        ```
        i.  For each Violation identified, CDS Setup will create an
            advisory record (Message \# 45) and will record the water
            system number, name, tinwsys_is_number, and tinwsys_st_code
            of the water system record; the state_asgn_id and name of
            the water system facility record; Violation Year, FedRep ID
            (if the violation is hidden, the ID from the Group Violation
            record will be recorded), status, analyte or analyte group
            code (if the violation is hidden, the analyte group code of
            the Group Violation will be recorded), otherwise the analyte
            code will be recorded), violation type, State Violation
            Period Begin and End Dates of the violation.

```{=html}
<!-- -->
```
3.  If no more SSMPAs meet the above specifications, then stop
    processing for that result and go to the next result (users may want
    to develop an Ms Access report that lists all routine results that
    are not associated to a SSMPA so that they can investigate whether
    they have a missing Sample Schedule or Monitoring Period or both).

*Subprocess B. Associate Sample Analytical Results of New or Changed
Samples to SSMPAs and Sampling Point Sub-SSMPAs.*

20948. Create a log in the CDS Execution Log indicating the process
       start time.

```{=html}
<!-- -->
```
4.  Identify Samples whose CDS trigger timestamp is greater than the
    last time the CDS Setup program was run.

5.  For each identified Sample, use logic described above under
    *Associate New or Changed Sample Analytical Results SSMPAs and
    Sampling Point Sub-SSMPA* to assign the associated Sample Analytical
    Results to the appropriate SSMPA and Sampling Point Sub-SSMPA.

*Subprocess C. Associate New SSMPAs and Sampling Point Sub-SSMPAs to
Results.*

21812. Create a log in the CDS Execution Log indicating the process
       start time.

```{=html}
<!-- -->
```
1.  Identify SSMPAs whose CDS trigger timestamp is greater than the last
    time the CDS Setup program was run.

2.  For each identified SSMPA, associate (or re-associate) results
    (SARs) to the SSMPA where:

    p.  The Result=s Analyte code is equal to the Analyte code
        referenced by the Sample Schedule, AND

    ```{=html}
    <!-- -->
    ```
    a.  The Result=s Data Quality Code is accepted (A) or validated (V);
        AND

    b.  The Result=s parent Sample=s Compliance Purpose Indicator Code
        is equal to "Y", AND

    c.  The Result=s parent Sample is a Sample Type of routine (RT) or
        maximum residence time (MR); AND

    d.  The Result=s parent Sample=s Rejection Reason Code is blank; AND

    e.  If the Result is already associated to a Monitoring Period

        i.  Either the Result=s parent Sample=s Collection End Date or
            its Monitoring Period End Date is greater than or equal to
            the CDS History Date, AND

        ii. The SSMPA is associated to the same Monitoring Period

    f.  Otherwise, if the Result is not associated to a Monitoring
        Period

        i.  If the Result is a replacement sample and is associated to
            an original sample, the Monitoring Period's End Date
            associated to the Result for the same Analyte in the
            original Sample, if any, is greater than or equal to the CDS
            History Date, AND

        ii. The Result=s parent Sample=s Collection End Date or if the
            Result is a replacement sample and is associated to an
            original sample whose Result for the same Analyte is not
            associated to a Monitoring Period, the original Sample's
            Collection End Date is greater than or equal to the CDS
            History Date, AND

        iii. The Result=s parent sample or if the Result is a
             replacement sample and is associated to an original sample
             whose Result for the same Analyte is not associated to a
             Monitoring Period, the original Sample was collected during
             the applicable period for the SSMPA (Collection End Date
             between SSMPA Applicable Period Begin Date and Applicable
             Period End Date), AND

        iv. The Result=s parent sample or if the Result is a replacement
            sample and is associated to an original sample whose Result
            for the same Analyte is not associated to a Monitoring
            Period, the original Sample was collected during the season
            indicated by the Sample Schedule=s Seasonal Period

> \[*Developer Note: This is similar to an action block that runs during
> the Assign Sample Schedules to Monitoring Periods. It is necessary to
> also run it here to ensure that, for schedules calling for greater
> than annual periodicity but having a seasonal collection period, only
> the results of a sample collected during the seasonal collection
> period are associated to the SSMPA or* *Sampling Point Sub-SSMPAs .
> This really is only needed for Sample Schedule=s whose periodicity is
> greater than annual but it does not hurt to run it for all.\]*
>
> The detailed specifications are as follows:

v.  if the Seasonal Period Begin Month and Day are before the Seasonal
    Period End Month and Day for the Sample Schedule, then the Month and
    Day of the Sample Collection End Date is greater than or equal to
    the Seasonal Period Begin Month and Day and less than or equal to
    the Seasonal Period End Month and Day

vi. if the Seasonal Period Begin Month and Day are after the Seasonal
    Period End Month and Day for the Sample Schedule, then either the
    Month and Day of the parent Sample=s Collection End Date:

    1.  is greater than or equal to the Seasonal Period Begin Month and
        Day and less than or equal to December 31 OR

    2.  is greater than or equal to January 1 and less than or equal to
        the Seasonal Period End Month and Day

        AND

```{=html}
<!-- -->
```
a.  In either case, the parent=s Sample Type Code is equal to the
    Schedule=s Monitoring Requirement Sample Type Code or if the
    parent=s Sample Type Code is equal to \>RT= one of the following
    combinations exists:

+---------------+--------------------------+--------------------------+
| **TSASAMPL**  |                          | **TMNMNR**               |
+===============+==========================+==========================+
| TYPE\_        | LD_COP\_                 | SAMPLE\_                 |
|               |                          |                          |
| CODE          | SAMP_TYP_CD              | TYPE_CODE                |
+---------------+--------------------------+--------------------------+
| RT            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| MR            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | AT                       | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | FSD                      | RT                       |
+---------------+--------------------------+--------------------------+

b.  Link the Result to the SSMPA by creating an SSMPA SAR Association
    record:

    ?.  If analyte for the result is 3100 OR if the Monitoring
        Requirement is associated to a Violation Type and the Violation
        Type Code is not equal to the following: A04\", A11\", A23\",
        A24\", A25\", A26\", A27\" (and analyte code = A0999\", A1006\",
        A1008\" or A1009\"), A29\", A31\", A36\", A38\", A49\", A51\",
        A52\", A53\" or A56\", use the following logic to populate the
        Compliance Value and Compliance Value UOM code fields for the
        new/updated SSMPA SAR Association record. Otherwise, do not
        calculate the Compliance Value (skip the following but go ahead
        and create the SSMPA SAR Association record and proceed to
        3.b.ii).

        19732. If Result=s Concentration Measure is greater than 0 and
               Less Than Ind is not equal to \>Y=, then set the
               Compliance Value to the Result=s Concentration Measure.
               Otherwise, set to 0.

        ```{=html}
        <!-- -->
        ```
        1.  Set the Compliance Value UOM to the Result=s Concentration
            UOM or if the Result=s Less Than Ind is equal to \>Y=, then
            set Compliance Value UOM to Detection Limit UOM.

    ```{=html}
    <!-- -->
    ```
    ccxvi. Associate SSMPA SAR Association to Result.

    ```{=html}
    <!-- -->
    ```
    i.  Associate SSMPA SAR Association to SSMPA.

```{=html}
<!-- -->
```
a.  In addition to associating the Result to the SSMPA:

    ?.  set the CDS trigger timestamp for the SSMPA and the Sampling
        Point Sub-SSMPA to the current date and time (whether the link
        previously existed or not) AND

    ```{=html}
    <!-- -->
    ```
    i.  link the Result, if not already linked to a Monitoring Period,
        directly to the Monitoring Period referenced by the SSMPA AND

    ii. determine if the next appropriate monitoring period exists for
        the Sample Schedule (using logic described above under
        **Associate Monitoring Periods to Sample Schedules**)

        252. If it exists, go on to the next result (note that the
             **Associate CDS Setup-Created Monitoring Periods to Sample
             Schedules** process will link the Sample Schedule to the
             next monitoring period)

        ```{=html}
        <!-- -->
        ```
        1.  If it does not exist,

            r.  then create the next appropriate monitoring period as
                follows:

                mcccxcvi. Begin Date = End Date of current monitoring
                          period plus 1 day.

                ```{=html}
                <!-- -->
                ```
                i.  End Date = Begin Date from above plus periodicity of
                    Sample Schedule (TMNMNR-Sample Count Unit Code)
                    minus 1 day.

                ii. Duration (Type Code) = code for the periodicity of
                    the Sample Schedule.

                iii. Name = name created by action block used in
                     Violation maintenance when creating a new
                     monitoring period.

                iv. User ID = "CDSSETUP."

> \[*Developer Note: The following action block, "Determine and Create
> SAR association to SubSSMPA," is reused below.\]*

iii. identify the Subschedule SSMPA associated to the same sampling
     point as the Result=s parent Sample. If found:

     1800. Identify a Sampling Plan and associated Sampling Plan
           Sampling Point Asgmt) where:

           f.  the Sampling Plan Sample Point Ind Code is \>Y= - Use for
               compliance AND

           ```{=html}
           <!-- -->
           ```
           a.  the Sampling Plan Begin Date is equal or less than the
               SSMPA Applicable Period Begin Date AND

           b.  the Sampling Plan End Date is null or is equal or greater
               than the SSMPA Applicable Period Begin Date AND

           c.  the Sampling Plan Sampling Point Asgmt Begin Date is
               equal or less than the SSMPA Applicable Period Begin Date
               AND

           d.  the Sampling Plan Sampling Point Asgmt End Date is equal
               or greater than the SSMPA Applicable Period Begin Date
               AND

           e.  the Sampling Plan is associated to the same Analyte
               referenced by the SSMPA through the Schedule or if the
               Sampling Plan is associated to an Analyte Group, the
               Analyte referenced by the SSMPA through the Schedule is
               part of the Analyte Group.

     ```{=html}
     <!-- -->
     ```
     1.  If a Sampling Plan was found, retrieve the Sampling Plan Dates
         associated to the Sampling Plan Sampling Point Asgmt. For each
         Sampling Plan Date retrieved, determine if the Result=s
         Collection End Date falls between the Sampling Plan Date plus
         or minus the Tolerance (in days). If a Sampling Plan Date is
         found that satisfies the above criteria, associate the Result
         to the Subschedule SSMPA by creating a SPUBA SAR Association
         and associating it to the Result and Subschedule SSMPA.

     2.  Otherwise, if a Sampling Plan was not found, associate the
         Result to the Subschedule SSMPA by creating a SPUBA SAR
         Association and associating it to the Result and Subschedule
         SSMPA

```{=html}
<!-- -->
```
b.  For each result that is being associated, determine if preliminary
    or validated violations are already associated.

    mmdcclxxvi. Identify Violations where:

                1.  the Violation Status Type Code is P - Preliminary or
                    V - Validated AND

                2.  the Violation is associated the Result via the
                    Violation Sample Result Asgmt AND

                3.  the Violation is associated to the same Monitoring
                    Period as SSMPA AND

                4.  the Violation is for the same Water System as the
                    Result AND

                5.  if the Violation is associated to a Water System
                    Facility, it is for the same Water System Facility
                    as the Result

    ```{=html}
    <!-- -->
    ```
    i.  For each Violation identified, CDS Setup will create an advisory
        record (Message \# 45) and will record the water system number,
        name, tinwsys_is_number, and tinwsys_st_code of the water system
        record; the state_asgn_id and name of the water system facility
        record; Violation Year, FedRep ID (if the violation is hidden,
        the ID from the Group Violation record will be recorded),
        status, analyte or analyte group code (if the violation is
        hidden, the analyte group code of the Group Violation will be
        recorded), otherwise the analyte code will be recorded),
        violation type, State Violation Period Begin and End Dates of
        the violation.

c.  If Sample Schedule=s Substitute Indicator is equal to N - Never use
    substitutes, processing for SSMPA is finished and move on to the
    next SSMPA.

d.  Otherwise, the process will attempt to assign substitute results to
    the SSMPA:

    mmmdcccviii. If the SSMPA=s analyte (via the Monitoring Requirement
                 referenced by the Sample Schedule referenced by the
                 SSMPA) is not listed in the Schedule Analyte column of
                 the substitute crosswalk table, processing for this
                 SSMPA is finished and move on to the next SSMPA.

    ```{=html}
    <!-- -->
    ```
    i.  If associated Sample Schedule=s Substitute Indicator is equal to
        O - Optionally substitute:

        a.  Identify SSMPA SAR Associations (and associated Results)
            where the analyte referenced by the Result is equal to the
            SSMPA=s (via the referenced Monitoring Requirement
            referenced by the Sample Schedule referenced by the SSMPA)

        b.  If one or more Results are found that satisfy the above
            criteria, processing for this SSMPA is finished. Move on to
            the next SSMPA.

        c.  Otherwise, proceed with substitutions

    ii. Otherwise (allow substitutions), for each corresponding SAR
        Analyte in the crosswalk table together with which the Schedule
        Analyte is listed, do the following:

        4896. identify results where:

              h.  the Result is for the SAR Analyte AND

              ```{=html}
              <!-- -->
              ```
              a.  the Data Quality Code is accepted (A) or validated (V)
                  AND

              b.  its parent Sample=s Compliance Purpose Indicator Code
                  is equal to "Y"

              c.  its parent Sample=s Sample Type is routine (RT) or
                  maximum residence time (MR) AND

              d.  its parent Sample=s Rejected Reason Code is blank AND

              e.  if the Averages Basis (from the Monitoring Requirement
                  referenced by the Sample Schedule referenced by the
                  SSMPA) is not DO NOT CALC, the source of the
                  Averages_Basis (UOM) matches that of the Result=s UOM
                  AND

              f.  its parent Sample is taken from the same Water System
                  Facility as the SSMPA

              g.  its Monitoring Period is the same Monitoring Period
                  associated to the SSMPA OR

              h.  its parent sample or if the parent sample is a
                  replacement sample and is associated to an original
                  sample, the original sample was collected during the
                  applicable period for the SSMPA (Collection End Date
                  between SSMPA Applicable Period Begin Date and
                  Applicable Period End Date) AND

              i.  its parent Sample or if the parent sample is a
                  replacement sample and is associated to an original
                  sample, the original sample was collected during the
                  season indicated by the Sample Schedule=s Seasonal
                  Period

> \[*Developer Note: This is similar to an action block that runs during
> the Assign Sample Schedules to Monitoring Periods. It is necessary to
> also run it here to ensure that, for schedules calling for greater
> than annual periodicity but having a seasonal collection period, only
> sample collected during the seasonal collection period are associated
> to the SSMPA or* *Sampling Point Sub-SSMPAs. This really is only
> needed for Sample Schedule=s whose periodicity is greater than annual
> but it does not hurt to run it for all.*\]
>
> The detailed specifications are as follows:

?.  if the Seasonal Period Begin Month and Day are before the Seasonal
    Period End Month and Day for the Sample Schedule, then:

> the Month and Day of the Sample Collection End Date is greater than or
> equal to the Seasonal Period Begin Month and Day and less than or
> equal to the Seasonal Period End Month and Day

i.  if the Seasonal Period Begin Month and Day are after the Seasonal
    Period End Month and Day for the Sample Schedule, then either the
    Month and Day of the parent Sample=s Collection End Date:

    1.  is greater than or equal to the Seasonal Period Begin Month and
        Day and less than or equal to December 31 OR

    2.  is greater than or equal to January 1 and less than or equal to
        the Seasonal Period End Month and Day.

```{=html}
<!-- -->
```
j.  One of the following combinations exists:

+---------------+--------------------------+--------------------------+
| **TSASAMPL**  |                          | **TMNMNR**               |
+===============+==========================+==========================+
| TYPE\_        | LD_COP\_                 | SAMPLE\_                 |
|               |                          |                          |
| CODE          | SAMP_TYP_CD              | TYPE_CODE                |
+---------------+--------------------------+--------------------------+
| RT            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| MR            | Null/Blank               | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | AT                       | RT                       |
+---------------+--------------------------+--------------------------+
| RT            | FSD                      | RT                       |
+---------------+--------------------------+--------------------------+

1.  If the result satisfies the substitution criteria as specified in
    the substitute crosswalk table, link the Result to the SSMPA by
    creating an SSMPA SAR Association record and use the same logic
    described above under *Calculate Compliance Value*. Use the
    appropriate Concentration Measure as indicated in the Calculated
    Substitute Compliance Value column of the substitute crosswalk
    table.

2.  Use the same logic described above under *Determine and Create SAR
    association to SubSSMPA* to assign the Result to an applicable
    Sampling Point Sub-SSMPA.

3.  For each result that is being associated, determine if preliminary
    or validated violations are already associated.

    v.  Identify Violations where:

        i.  the Violation Status Type Code is P - Preliminary or V -
            Validated AND

        ii. the Violation is associated the Result via the Violation
            Sample Result Asgmt AND

        iii. the Violation is associated to the same Monitoring Period
             as SSMPA AND

        iv. the Violation is for the same Water System as the Result AND

        v.  if the Violation is associated to a Water System Facility,
            it is for the same Water System Facility as the Result

    ```{=html}
    <!-- -->
    ```
    a.  For each Violation identified, CDS Setup will create an advisory
        record (Message \# 45) and will record the water system number,
        name, tinwsys_is_number, and tinwsys_st_code of the water system
        record; the state_asgn_id and name of the water system facility
        record; Violation Year, FedRep ID (if the violation is hidden,
        the ID from the Group Violation record will be recorded),
        status, analyte or analyte group code (if the violation is
        hidden, the analyte group code of the Group Violation will be
        recorded), otherwise the analyte code will be recorded),
        violation type, State Violation Period Begin and End Dates of
        the violation.

```{=html}
<!-- -->
```
1.  If there are no more results that satisfy the substitute condition
    for the SAR Analyte, move on to the next applicable SAR Analyte
    listed for the Schedule Analyte on the substitute crosswalk table.

```{=html}
<!-- -->
```
i.  Processing for this SSMPA is finished. Move on to the next SSMPA