Consolidates the findings of the three audits (admin, medical, financial) for a Colombian medical invoice, deduplicates redundant findings across auditors, prioritizes by severity and disputed amount, computes a global confidence score, assigns Anexo 6 causales (Res. 3047/2008 codes 1-7 with subcausales) to each finding, determines the case zone (green/yellow/red), and applies workflow labels (auto-approve, needs-human-review, auto-denial, needs-fix-review) in the destination software. Use it once the three audits have run and the case must advance to glosa generation or human review.
Unifies the outputs of the three sub-auditors (admin + medical + financial), deduplicates redundant findings, assigns Anexo 6 causales (Res. 3047/2008), and labels the case for the next step. Absorbs what was originally a separate causal-assigner skill.
The question it answers: given what the three audits found, which findings are real, which causal do they belong to, and what is the next step (auto-approve, human review, or auto-denial)?
consolidation.Do not use: if any of the three audits is missing; if the case already has consolidated_findings and a reconsolidation was not requested.
Read the three audits for the case.
GET {DEST_SOFTWARE_BASE_URL}/cases/{case_id}/audits
Validate that all three audit_type values exist: admin, medical, financial. If any is missing, abort and leave a note on the case.
Collect every finding with resultado=fail or conditional.
Ignore pass — they do not produce findings for a glosa.
Deduplicate by "root cause".
Two findings are duplicates when:
invoice_item (CUPS + quantity + date), orWhen merging:
rule_ids = list of every rule_id that detected the same finding (e.g. ["ADMIN.15", "FIN.20"]).severidad = maximum across merged.peso = maximum.valor_objetado = maximum, not sum (do not double-count money).evidencia = formatted concatenation with source attribution.auditores_detectaron = list (["admin", "financial"]).Compute per-finding confidence (0–1).
confidence = 0.4 × evidence_clarity
+ 0.4 × unanimity (auditors that detected it / 3)
+ 0.2 × citation_quality (exact file+page?)
evidence_clarity: 1 if the evidence contains a literal quote, 0.7 for a specific reference, 0.4 if generic.unanimity: if 2+ auditors detected it → very high confidence.citation_quality: 1 if file+page, 0.5 if file only, 0 if neither.Prioritize findings in this order:
critica > mayor > media > baja.valor_objetado descending.confianza descending.Assign an Anexo 6 causal to each finding (Res. 3047 Art. 5):
| Causal | Name | Typical triggers |
|---|---|---|
| 1 | No cobertura contractual | FIN.06 (plan excludes), FIN.22 (pre-existing), ADMIN.07 (wrong modality) |
| 2 | No pertinencia clínica | MED.04-06 (GPC), MED.10-13 (procedures), MED.14-15 (medications) |
| 3 | Documentación incompleta | ADMIN.08-11 (RIPS), ADMIN.17-19 (HC), MED.11 (operative note), MED.16 |
| 4 | Cobro duplicado | FIN.21 (repeated study), FIN.33 (overlap), FIN.38 (unbundling) |
| 5 | Tarifa incorrecta | FIN.07-09 (manual/UVB), FIN.13-16 (liquidation), FIN.23-25 (copays) |
| 6 | Agotamiento de cobertura | FIN.20 (caps), FIN.21 (grace period) |
| 7 | Genérica / devolución | ADMIN.12-14 (DIAN invoice), ADMIN.24 (timeliness), FIN.29-31 (dates/consecutive) |
Rules:
needs-human-review (do not force a causal).3.1 clinical documentation, 3.2 administrative documentation).Compute zone and amounts.
score = Σ peso of deduplicated findings with resultado=fail.zona:
score ≤ ZONA_GREEN_MAX (default 5) and no critical rule fails.score ≤ ZONA_YELLOW_MAX (default 15) without criticals, or criticals with low confidence.score > ZONA_YELLOW_MAX or at least one critical with confidence ≥ CONFIDENCE_THRESHOLD.total_objetado = Σ valor_objetado of failing findings.total_a_pagar = invoice_total - total_objetado.confianza_global = weighted average by peso.Publish the consolidated object.
POST {DEST_SOFTWARE_BASE_URL}/cases/{case_id}/consolidated
{
"consolidated_findings": [
{
"finding_id": "fx-001",
"rule_ids": ["ADMIN.15", "FIN.20"],
"auditores_detectaron": ["admin", "financial"],
"severidad": "critica",
"peso": 3,
"causal": 6,
"subcausal": "6.1",
"valor_objetado": 1200000,
"confianza": 0.92,
"evidencia": "autorizacion.pdf: annual cap $5M already consumed; invoice exceeds by $1.2M",
"justificacion": "Coverage exhaustion per Anexo 6.6.1"
}
],
"case_summary": {
"zona": "roja",
"score": 22,
"confianza_global": 0.88,
"total_facturado": 8500000,
"total_objetado": 3200000,
"total_a_pagar": 5300000
}
}
Apply workflow labels.
POST {DEST_SOFTWARE_BASE_URL}/cases/{case_id}/labels
Decision matrix:
| Zone | Global confidence | Contradictions between auditors | Label |
|---|---|---|---|
| Green | ≥ 0.7 | No | auto-approve |
| Green | < 0.7 | - | needs-human-review |
| Yellow | any | - | needs-human-review |
| Red | ≥ 0.7 | No | auto-denial |
| Red | ≥ 0.7 | Yes (e.g. admin says OK, financial says fraud) | needs-fix-review |
| Red | < 0.7 | - | needs-human-review |
Always add: consolidated.
Update the case status.
PATCH {DEST_SOFTWARE_BASE_URL}/cases/{case_id}
{ "status": "consolidated", "zona": "...", "score": ..., "total_objetado": ... }
valor_objetado exceeds invoice_total. Cause: summing overlapping findings (same item across multiple rules). Fix: when totalling, group by invoice_item and take the maximum disputed amount per item, not the sum.needs-human-review. Cause: threshold too high or evidence clarity miscomputed. Fix: temporarily lower CONFIDENCE_THRESHOLD to 0.6 and review the actual distribution; adjust weights.rule_id, ignoring the merge. Fix: run mapping after dedup on the merged rule_ids set.auto-denial and needs-human-review). Cause: previous label not removed. Fix: before applying, DELETE /cases/{id}/labels/* for mutually exclusive labels.needs-fix-review never fires). Cause: contradiction check compares only fail findings, missing when one says pass and another fail on the same item. Fix: cross by invoice_item as well; if admin passes and financial fails on the same item → contradiction.GET /cases/{case_id}/consolidated returns an object with consolidated_findings[] and case_summary.causal ∈ {1,2,3,4,5,6,7} OR is flagged needs-human-review.evidencia and different finding_id (dedup correct).total_objetado ≤ invoice_total.auto-approve, needs-human-review, auto-denial, needs-fix-review).zona=roja with a high-confidence critical, label is auto-denial or needs-fix-review, never auto-approve.consolidated.