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

# Map Form Filling Results to EHR

> Learn how to map FormFillingResult structured_data to your EHR or downstream systems using the Form filling SDK

This example shows how to map Form filling results to your EHR. When a session completes, `onSubmit` delivers a `FormFillingResult` with filled forms in `structured_data.generated_values`.

The example routes each form by `form_template_id` and maps the `data` object to your EHR fields. Use `ambient_session_id` to avoid duplicate saves and `correlation_id` to match results to your encounter. For production, run this mapping in your [Webhook handler](/form-filling-sdk/examples/webhook-handler). Use SDK callbacks for in-app preview only.

```typescript TypeScript  theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
import type { FormFillingResult } from "@suki-sdk/form-filling";

type EhrFormPayload = {
  encounterId: string;
  sessionId: string;
  templateId: string;
  fields: Record<string, unknown>;
};

function mapResultToEhr(result: FormFillingResult): EhrFormPayload[] {
  const encounterId = result.correlation_id ?? "";
  const sessionId = result.ambient_session_id;

  return result.structured_data.generated_values.map((instance) => ({
    encounterId,
    sessionId,
    templateId: instance.form_template_id,
    fields: instance.data as Record<string, unknown>,
  }));
}

async function saveToEhr(result: FormFillingResult) {
  const payloads = mapResultToEhr(result);

  for (const payload of payloads) {
    await fetch("/api/ehr/forms", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(payload),
    });
  }
}
```

Templates with no output appear in `non_generated_values`. Log or skip them in your handler:

```typescript TypeScript theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
const missing = result.structured_data.non_generated_values.map((v) => v.form_template_id);
if (missing.length > 0) {
  console.warn("No output for templates:", missing);
}
```

## Next steps

<Icon icon="file-lines" iconType="solid" /> Refer to [Webhook handler](/form-filling-sdk/examples/webhook-handler) for server-side persistence

<Icon icon="file-lines" iconType="solid" /> Refer to [Get Form filling structured data](/form-filling-api-reference/form-filling-sessions/structured-data) when your webhook payload does not include full output

<Icon icon="file-lines" iconType="solid" /> Refer to [Callbacks](/form-filling-sdk/guides/callbacks) for `FormFillingResult` field details
