> ## 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

> Map FormFillingResult structured_data fields to your EHR or downstream systems by form_template_id, ambient_session_id, and correlation_id

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);
}
```

## Available tutorials

<div className="hp-io-method-grid tut-hub-card-grid">
  <a className="hp-io-method-card tut-hub-method-card" href="/documentation/tutorials/form-filling-sdk-ehr-handoff">
    <div className="tut-hub-card-media" aria-hidden="true" />

    <div className="hp-io-method-card-body">
      <span className="hp-wn-badge hp-wn-badge-new">Form filling</span>
      <h3 className="hp-io-method-card-title">Build a Form Filling Session with EHR Handoff</h3>

      <p className="hp-io-method-card-desc">
        Open a Form filling session and map structured\_data to your EHR using correlation\_id.
      </p>

      <div className="hp-io-method-card-meta tut-hub-card-foot" aria-label="20 min, Intermediate">
        <div className="tut-hub-card-foot-meta">
          <span className="hp-io-method-card-meta-time">20 min</span>
          <span className="tut-hub-level">Intermediate</span>
        </div>
      </div>
    </div>
  </a>
</div>

## 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
