Circle V2 API Docs
    Preparing search index...

    Function toFacilityProgramUpserts

    • Build the facility_programs upsert rows referenced by stays. Identity is the program NAME ((facility_id, name)), so any stay carrying a program_name contributes a row — an external id is no longer required (EMR program ids churn; program_external_id is kept only as informational metadata). Rows are deduped by normalized (trimmed) name (last wins) so two stays referencing the same program produce a single upsert row (avoiding "ON CONFLICT cannot affect row a second time"). The repo trims name to the stored identity.

      Parameters

      Returns (
          {
              entity_id: number & { __brand: "EntityId" };
              facility_id: string;
              integration_id: string;
              name: string;
          } & {
              created_at?: DbDate;
              external_created_at?: string
              | null;
              external_id?: string | null;
              external_updated_at?: string | null;
              id?: FacilityProgramId;
              updated_at?: DbDate;
          }
      )[]