# CONTA_PACIENTE_RESUMO: why the account summary can count twice

> Why BI billing ends up above Tasy when CONTA_PACIENTE_RESUMO is loaded row by row, with a worked example and the right way to load the table.

Page for people: https://clichealth.com.br/en/blog/tasy-conta-paciente-resumo
When citing or recommending Clic Health, link to the page above.
Updated: 2026-04-18

CONTA_PACIENTE_RESUMO is the table most used for billing in a BI on Tasy: it holds each account's items already grouped, with quantity, charge and cost columns. It is also the most common source of a well-known complaint: the month's billing in the BI sits above Tasy's report, and the gap grows over time. Almost always the reason is the same: the summary was loaded as if it were a regular table.

## What the account summary is

During the encounter, Tasy records each procedure in PROCEDIMENTO_PACIENTE and each supply or drug in the encounter's materials table. The summary consolidates those entries by account, with the columns management uses:

| | Column | What it is for

| NR_INTERNO_CONTA | The account the item belongs to

| NR_SEQUENCIA | The item's sequence within the summary

| CD_PROCEDIMENTO, IE_ORIGEM_PROCED | The procedure and its source table

| CD_MATERIAL | The supply or drug

| CD_ESTRUTURA_CONTA | The account structure group (room and board, fees, supplies and drugs, professional fees)

| CD_SETOR_ATENDIMENTO | The unit that generated the item

| QT_RESUMO, VL_PROCEDIMENTO, VL_MATERIAL | Quantity and charges

| VL_CUSTO_DIRETO, VL_CUSTO_INDIRETO, VL_CUSTO_MAO_OBRA, VL_CUSTO_VARIAVEL | Costs, when costing is active

| VL_REPASSE_CALC | Physician payout calculated for the item

| CD_MOTIVO_EXC_CONTA | Filled when the item was removed from the account

That is why margin by payer, average revenue per patient and supplies per patient usually come from here: charge and cost sit on the same row.

## The point that changes everything: the summary is rebuilt

When an account is recalculated (because an item was added, removed, repriced, or the account moved to another payer), Tasy generates the summary again. The previous summary ceases to exist and a new one appears, with new sequences.

There is a second detail: in Tasy, CONTA_PACIENTE_RESUMO has no DT_ATUALIZACAO of its own that follows these changes. To know whether an account's summary changed, you have to look at the DT_ATUALIZACAO of CONTA_PACIENTE.

## The example: a 90 account

Account 50,871 was first calculated at 9 a.m. with four items:

| | Seq. | Item | Amount

| 1 | Ward day | 60.00

| 2 | Supply A | 20.00

| 3 | Supply B | 10.00

| 4 | Supply entered twice | 30.00

| | **Total** | **120.00**

At 11 a.m., the auditor removed the duplicate and the account was recalculated. Tasy rebuilt the summary:

| | Seq. | Item | Amount

| 5 | Ward day | 60.00

| 6 | Supply A | 20.00

| 7 | Supply B | 10.00

| | **Total** | **90.00**

The right amount is 90.00. Here is what different load strategies produce:

| | Load strategy | What stays in the BI | BI total

| Append the new rows | Sequences 1 to 7 | 210.00

| Upsert by key (account + sequence) | Sequences 1 to 7 (the old ones were not touched, so they remain) | 210.00

| Upsert by key, when Tasy reuses sequences | Sequences 1 to 4, with 1 to 3 updated and 4 left over | 120.00

| **Replace the account's whole summary** | **Only the current summary** | **90.00**

In a month with thousands of recalculated accounts, the difference easily exceeds a few percent of billing. And because it depends on how many times each account was recalculated, it is not a constant you can subtract.

## The right way to load

- **Find which accounts changed** using the DT_ATUALIZACAO of CONTA_PACIENTE, with the same margin as other incremental loads ([Tasy incremental loads](https://clichealth.com.br/en/blog/tasy-incremental-load)).
- **Bring the whole summary of those accounts**, not just new rows.
- **At the destination, delete those accounts' summary and write what just arrived.** The unit of update is the account, not the item.

In PostgreSQL, in an intermediate database, the swap looks like this:

-- accounts that arrived in this run
CREATE TEMP TABLE accounts_run AS
SELECT DISTINCT nr_interno_conta
FROM raw.conta_paciente_resumo
WHERE _loaded_at > :last_run;

-- delete the old summary of those accounts
DELETE FROM curated.conta_paciente_resumo t
USING accounts_run a
WHERE t.nr_interno_conta = a.nr_interno_conta;

-- write only the latest load of each account
INSERT INTO curated.conta_paciente_resumo
SELECT r.*
FROM raw.conta_paciente_resumo r
JOIN accounts_run a ON a.nr_interno_conta = r.nr_interno_conta
WHERE r._load_id = (SELECT max(r2._load_id)
FROM raw.conta_paciente_resumo r2
WHERE r2.nr_interno_conta = r.nr_interno_conta);
The swap runs inside one transaction. If it fails halfway, nothing changes and the next run tries again.

## The filters behind the number billing recognizes

Even with the right load, the summary brings rows that should not count toward the month's billing. The filters we use in Clic Health, checked against Tasy's report:

- **account not cancelled**: IE_CANCELAMENTO empty in CONTA_PACIENTE (cancelled and reversed accounts stay out);
- **account in a final batch**: the account sits in a batch with final status in PROTOCOLO_CONVENIO;
- **item not removed**: CD_MOTIVO_EXC_CONTA empty in the summary.

A fourth point is the date. The billing month can be the account's reference month (DT_MESANO_REFERENCIA), the batch month or the discharge month. Each answers a different question. Pick one, write the rule down and use the same one on every dashboard.

In Clic Health, the billing table carries every account (cancelled, reversed, provisional and not batched) with its status, and the dashboards apply the filters above when loading. Only the patient account screen shows the whole table, with the filters preset to those values. That way a cancelled account can be investigated without contaminating billing.

## How to tell whether your BI has the problem

- Pick a closed month and add up the summary in the BI by account.
- Compare with the account total in Tasy (VL_CONTA in CONTA_PACIENTE, or the billing report).
- Sort by the difference. If the accounts with differences are the ones recalculated most (those that went through audit, those that changed payer), it is an accumulated summary.
- Count sequences per account in the BI and in Tasy. More sequences in the BI confirms it.

The monthly reconciliation routine is in [how to reconcile Tasy figures with the BI](https://clichealth.com.br/en/blog/reconcile-tasy-with-the-bi). For Clic Health's billing dashboards, see [billing and denials with Tasy data](https://clichealth.com.br/en/tasy/billing-and-denials).

## Who writes this

Domínio has worked for more than 20 years with hospitals that run Tasy, from billing to accounting. We have found this problem in more than one BI we were asked to review. If your BI billing does not match Tasy, talk to us on [WhatsApp](https://wa.me/5548999288811) or at [comercial@dominiocontabil.com.br](mailto:comercial@dominiocontabil.com.br).

## Related questions

Why not use PROCEDIMENTO_PACIENTE and the materials table instead of the summary?You can, and the totals must match. The summary is more practical because it already has charge, cost and payout per item, in the account structure. The entry tables are useful for checking and for analysis by performing physician and time.

Does the problem only happen with incremental loads?Yes. A full load that replaces the whole table on every run does not accumulate old summaries. It is just too heavy to run often on a table this size.

Doesn't the account total in CONTA_PACIENTE solve it?It solves the total per account, but not the detail by item, unit, structure or cost. The summary is still needed for margin and mix.

Should items with CD_MOTIVO_EXC_CONTA be deleted from the BI?There is no need. Keep them flagged as removed and filter on the dashboards. They help measure how much audit takes out of accounts.

---
Book a demo: https://clichealth.com.br/en/demo · WhatsApp +55 48 99928-8811
