Cobranca indevida de retorno em consulta
Overview
Implements the return-consultation rule for improper consultation charges. Agent: C071 The rule detects continuity of care for consultations from the same beneficiary with the same professional, within the window configured by min_days_return and max_days_return. Rule flow --------- 1) load_artifacts: - loads eligible history from the analytical base, constrained by a lookback window (history_lookback_days) and excluding items already submitted by this same agent (agent_id), since they cannot be used as reference for new denials; - stores the result in self.hist (historical DataFrame). 2) prepare_data: - concatenates input with history, validates required columns, and normalizes key fields; - validates professional data quality (state, board, and registration number) with fallback from executor -> requester; - applies scope filters: target events (RETURN_APPOINTMENT_EVENT_DICT / id_evento_predicted), target regime, valid professional data, board matching the predicted event, and paid value above min_paid_value (same threshold as the history query in load_artifacts). Rows already submitted by this agent are excluded from loaded history in SQL, not re-filtered here on the input batch; - creates id_profissional as the professional key in the format uf_conselho_profissional-conselho-numero_conselho_profissional; - creates pk_retorno as the history comparison key in the format partner_id+id_prestador+id_matricula+id_profissional+id_evento_predicted+regime_atendimento; - produces evaluated with initial out-of-scope tracking. 3) rule_assessment: - runs iterative assessment by pk_retorno: sorts consultations chronologically per group, computes dt_atendimento_anterior and dias_desde_ultima, marks flag_glosa_elegivel when the interval falls in [min_days_return, max_days_return], and marks flag_glosa_aprovada only for the first eligible item in sequence; at the end of each round, removes denied items and reprocesses remaining items until no new approvals exist; - enriches output with denial fields, reasons, and metadata; - when evaluated=True, consolidates final assessment reasons for the entire processed universe.
Architecture
| Field | Value |
|---|---|
| Name | Cobranca indevida de retorno em consulta |
| Agent ID | C071 |
| Version | 0.0.0 |
| Nature | adm |
| Layer | — |
Inheritance
ReturnAppointmentCycleRule → BaseAgent → BaseAgent
Core Functionality
- load_artifacts
- prepare_data
- rule_assessment
Business Rules
Conformidade da cobrança
Consultar código-fonte para regras de negócio detalhadas.
Usage
from agents.returnappointmentcyclerule import ReturnAppointmentCycleRule
rule = ReturnAppointmentCycleRule()
violations_df = rule.rule_assessment(claims_df)
Configuration
Sem parâmetros configuráveis identificados.
Input Requirements
Consultar expected_input_columns no código-fonte.
Output Format
Glosa DataFrame Columns
| Column | Description |
|---|---|
agent_id |
C071 |
version |
0.0.0 |
id_arvo |
Original record ID |
vl_glosa_arvo |
Glosa value |
qt_glosa_arvo |
Glosa quantity |
score_arvo |
Confidence score |
motivo_glosa_arvo |
Detailed reason in Portuguese |
motivo_glosa_ANS |
ANS standard code |
data_dict |
JSON metadata with calculation details |
Error Handling
- DataFrames vazios retornam estrutura vazia com colunas obrigatórias.
- Colunas ausentes geram warning mas não causam crash.
- Conversões numéricas usam
errors="coerce"para evitar falhas.