Writes a read subtree onto the eval branch as a sequence of SHORT statements (parent → child, so
any partial write is a referentially-consistent prefix), then episode-stamps the cloned charts.
Deliberately NOT one big transaction: the branch connects through the transaction-mode pooler,
which is hostile to long transactions, and a re-run only inserts missing rows (facilities aside),
so it resumes idempotently — it fills in whatever a failed run didn't reach.
Out-of-subtree FKs are nulled and secrets scrubbed on the way in; jsonb columns are wrapped so
postgres.js parses them as JSON rather than typing a bare scalar (see toJsonb). A patient's own
rows stay a frozen snapshot. The exception is the entity's facilities: every clone refreshes their
timezone and admission source, which also changes how already-cloned patients of that entity
render (see insertFacilitiesRefreshingConfig). Owns the branch connection (destroy in
finally).
Writes a read subtree onto the eval branch as a sequence of SHORT statements (parent → child, so any partial write is a referentially-consistent prefix), then episode-stamps the cloned charts. Deliberately NOT one big transaction: the branch connects through the transaction-mode pooler, which is hostile to long transactions, and a re-run only inserts missing rows (facilities aside), so it resumes idempotently — it fills in whatever a failed run didn't reach. Out-of-subtree FKs are nulled and secrets scrubbed on the way in; jsonb columns are wrapped so postgres.js parses them as JSON rather than typing a bare scalar (see
toJsonb). A patient's own rows stay a frozen snapshot. The exception is the entity's facilities: every clone refreshes their timezone and admission source, which also changes how already-cloned patients of that entity render (see insertFacilitiesRefreshingConfig). Owns the branch connection (destroyinfinally).