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

# Poll Patient Summary Status Before Retrieve

> Poll Patient Summary job status until COMPLETED before calling retrieve APIs

**Problem:** Retrieve APIs return empty or missing summaries right after you trigger generation.

**Solution:** Poll [Get patient summary generation status for encounter](/patient-summary-api-reference/summary-jobs/encounter-status) until `COMPLETED`, then retrieve. Treat `FAILED` and `ABORTED` as terminal. You can also poll by `patient_summary_id` with [Get patient summary job status](/patient-summary-api-reference/summary-jobs/job-status).

<Note>
  This cookbook assumes you already triggered generation for the encounter, have Partner ID and `sdp_suki_token`, and use the same `fhir_encounter_id` and `fhir_practitioner_id` as generation.
</Note>

<Tabs>
  <Tab title="TypeScript">
    ```typescript theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
    const BASE_URL = "https://sdp.suki.ai";

    async function waitUntilCompleted(
      fhirEncounterId: string,
      fhirPractitionerId: string
    ) {
      for (let i = 0; i < 60; i++) {
        const res = await fetch(
          `${BASE_URL}/api/v1/patient-summary/encounter/${fhirEncounterId}/practitioner/${fhirPractitionerId}/status`,
          {
            headers: {
              sdp_suki_token: sdpSukiToken,
              sdp_provider_id: sdpProviderId,
            },
          }
        );

        if (!res.ok) {
          throw new Error(`Get patient summary status failed: ${res.status}`);
        }

        const { status } = await res.json();
        if (status === "COMPLETED") return "COMPLETED";
        if (status === "FAILED" || status === "ABORTED") return status;

        await new Promise((r) => setTimeout(r, 2000));
      }

      throw new Error("Timed out waiting for patient summary status");
    }

    const outcome = await waitUntilCompleted("enc-123", "pract-456");
    if (outcome === "COMPLETED") {
      // Call retrieve Patient Summary APIs
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={"theme":{"light":"github-dark","dark":"material-theme-darker"}}
    import time
    import requests

    BASE_URL = "https://sdp.suki.ai"

    def wait_until_completed(fhir_encounter_id: str, fhir_practitioner_id: str) -> str:
        for _ in range(60):
            res = requests.get(
                f"{BASE_URL}/api/v1/patient-summary/encounter/{fhir_encounter_id}/practitioner/{fhir_practitioner_id}/status",
                headers={
                    "sdp_suki_token": sdp_suki_token,
                    "sdp_provider_id": sdp_provider_id,
                },
                timeout=30,
            )
            res.raise_for_status()
            status = res.json().get("status")
            if status == "COMPLETED":
                return "COMPLETED"
            if status in ("FAILED", "ABORTED"):
                return status
            time.sleep(2)
        raise TimeoutError("Timed out waiting for patient summary status")

    outcome = wait_until_completed("enc-123", "pract-456")
    if outcome == "COMPLETED":
        # Call retrieve Patient Summary APIs
        pass
    ```
  </Tab>
</Tabs>

## Common mistakes

* Calling retrieve while status is still `READY` or `RUNNING`.
* Stopping only on `COMPLETED` and ignoring `FAILED` / `ABORTED` (those loops never end cleanly).
* Polling with different encounter or practitioner IDs than you used to generate.

## Other cookbooks

<div className="cookbook-hub-wrap">
  <div className="hp-io-method-grid tut-hub-card-grid" data-cookbook-related-grid>
    <a className="hp-io-method-card tut-hub-method-card" href="/documentation/cookbooks/generate-patient-summary-for-encounter">
      <div className="tut-hub-card-media" aria-hidden="true" />

      <div className="hp-io-method-card-body">
        <div className="tut-hub-card-badges">
          <span className="hp-wn-badge hp-wn-badge-new">Patient Summary</span>
          <span className="hp-wn-badge cookbook-hub-badge-surface cookbook-hub-badge-surface--api">API</span>
        </div>

        <h3 className="hp-io-method-card-title">Generate a Patient Summary for One Encounter</h3>

        <p className="hp-io-method-card-desc cookbook-hub-card-desc">
          Trigger generation and save the ID.
        </p>

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

    <a className="hp-io-method-card tut-hub-method-card" href="/documentation/cookbooks/upload-fhir-to-ckg-and-poll">
      <div className="tut-hub-card-media tut-hub-card-media--blue" aria-hidden="true" />

      <div className="hp-io-method-card-body">
        <div className="tut-hub-card-badges">
          <span className="hp-wn-badge hp-wn-badge-new">Patient Summary</span>
          <span className="hp-wn-badge cookbook-hub-badge-surface cookbook-hub-badge-surface--api">API</span>
        </div>

        <h3 className="hp-io-method-card-title">Upload FHIR to CKG and Poll Ingestion</h3>

        <p className="hp-io-method-card-desc cookbook-hub-card-desc">
          Upload FHIR, then wait for COMPLETED.
        </p>

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