> ## Documentation Index
> Fetch the complete documentation index at: https://docs.azalt.co/llms.txt
> Use this file to discover all available pages before exploring further.

# ImportResult

> Per-site results from import executions with processed data and field mappings

ImportResult stores the outcome of an import execution for a specific site and time period. Each result contains the processed data snapshot and the mappings that created form submissions.

## Core Purpose

* **Result Tracking**: Records what was imported per site/period
* **Data Snapshot**: Preserves the processed output values
* **Mapping Record**: Tracks which form elements received values
* **Auditability**: Enables reviewing what an import actually changed

## Entity Structure

```
ImportResult {
  id: "impres-...",
  importId: "imp-...",           // Parent import execution
  formSiteId: "fs-...",          // Target form-site combination
  year: 2024,                    // Target year
  periodUnit: "MONTHLY",         // YEARLY, MONTHLY, QUARTERLY
  period: 1,                     // Period number (1-12 for monthly, 1-4 for quarterly)
  processedData: {...},          // Output from processor
  mapping: [...],                // Field-to-element mappings
  rowsProcessed: 12              // Number of input rows used
}
```

## Processed Data

The `processedData` field stores the output from the processor code:

**Simple output**:

```json theme={null}
{
  "total_energy": 15420.5,
  "energy_source": "Grid Electricity"
}
```

**Periodic output (stored per result)**:

```json theme={null}
{
  "monthly_consumption": 1250
}
```

This field preserves the exact output types:

* Numbers remain as numbers
* Strings remain as strings
* Booleans remain as booleans

## Mapping Structure

The `mapping` field records how output values were inserted:

```json theme={null}
[
  {
    "outputKey": "total_energy",
    "formElementId": "fe-abc123",
    "valueInserted": 15420.5
  },
  {
    "outputKey": "energy_source",
    "formElementId": "fe-def456",
    "valueInserted": "Grid Electricity"
  }
]
```

Each mapping entry shows:

* `outputKey`: The processor output field
* `formElementId`: The form element that received the value
* `valueInserted`: The actual value that was stored

## Period Handling

ImportResult supports different period granularities:

**Yearly** (periodUnit: "YEARLY", period: 1):

* Single result per year
* Used for annual totals or averages

**Monthly** (periodUnit: "MONTHLY", period: 1-12):

* Separate result for each month
* Period 1 = January, Period 12 = December

**Quarterly** (periodUnit: "QUARTERLY", period: 1-4):

* Separate result for each quarter
* Period 1 = Q1 (Jan-Mar), Period 4 = Q4 (Oct-Dec)

## Multi-Site Results

For grouped imports, each site receives its own ImportResult:

```
Import (imp-123) produces:
├── ImportResult for Site A, 2024, YEARLY
├── ImportResult for Site B, 2024, YEARLY
└── ImportResult for Site C, 2024, YEARLY
```

The `formSiteId` links each result to the specific FormSite combination.

## Rows Processed

The `rowsProcessed` field indicates how many source rows contributed to this result:

* For ungrouped imports: equals the total row count
* For grouped imports: equals rows matching this site's group key

## Access Control

ImportResult access is inherited from the parent Import:

* Users can only see results from imports in their organization
* RLS policies check the parent Import's organizationId

## Querying Results

**Results for a specific import**:

```sql theme={null}
SELECT * FROM "ImportResult"
WHERE "importId" = 'imp-123'
ORDER BY "formSiteId", year, period;
```

**Results for a specific site**:

```sql theme={null}
SELECT ir.*, i."createdAt" as "importedAt"
FROM "ImportResult" ir
JOIN "Import" i ON i.id = ir."importId"
WHERE ir."formSiteId" = 'fs-456'
ORDER BY i."createdAt" DESC;
```

## Data Integrity

ImportResult records provide:

**Traceability**: Know exactly what values came from imports vs manual entry

**Reproducibility**: The processedData snapshot shows what the processor produced

**Debugging**: Mapping records help diagnose incorrect values

## Related Entities

* [Import](/en/concepts/import): The parent execution record
* [ImportDefinition](/en/concepts/import-definition): Defines the transformation rules
* [FormSite](/en/concepts/form-site): The target form-site combination
* [FormElementSubmission](/en/concepts/form-element-submission): The actual stored values
