{
  "schema_version": "2026-05-14.leafenterprise.calculation-registry.v1",
  "source_of_truth": true,
  "calculation_families": [
    {
      "id": "report_payload_kpis",
      "label": "Report payload KPIs",
      "implementation": "LeafEnterprise/client_preview.py",
      "source_tables": ["automation.audit_kpidrugs", "automation.audit_groupsrepresented"],
      "scope_required": ["itr_num", "pbm", "tpa", "group_name when selected", "date window"],
      "formulas": [
        "total_drug_spend = SUM(drug_spend)",
        "specialty_drug_spend = SUM(drug_spend WHERE LH_specialty = Y)",
        "specialty_share = specialty_drug_spend / total_drug_spend",
        "total_claims = SUM(num_claims)"
      ],
      "blocked_when": ["scope is ambiguous", "group-specific output lacks exact group", "source rows do not match selected run"]
    },
    {
      "id": "workbook_channel_math",
      "label": "Workbook channel math",
      "implementation": "LeafEnterprise/report_workbook.py",
      "source_tables": ["automation.audit_segmentation"],
      "scope_required": ["itr_num", "group_name when selected"],
      "formulas": [
        "claims = SUM(num_claims)",
        "awp = SUM(AWP)",
        "ingredient_cost = SUM(ingredient_cost)",
        "dispensing_fee = SUM(disp_fee)",
        "discount = AVG(discount) from source segmentation table"
      ],
      "blocked_when": ["source segmentation rows are unavailable", "scope mismatch exists"]
    },
    {
      "id": "contract_guarantee_inputs",
      "label": "Contract guarantee inputs",
      "implementation": "LeafEnterprise/report_workbook.py and LeafEnterprise/contract_guarantees.py",
      "source_tables": ["governed pricing registry", "Graph-promoted contract packets"],
      "scope_required": ["pbm", "tpa", "group_name", "contract year/date window"],
      "formulas": ["contract discount and rebate cells are written only from exact governed pricing lineage"],
      "blocked_when": ["exact contract packet is missing", "pricing lineage is candidate-only", "Domo pricing is the only evidence"]
    },
    {
      "id": "governed_pbm_switch",
      "label": "Governed PBM switch",
      "implementation": "LeafEnterprise/pocket_consultant.py",
      "source_tables": ["governed savings packet alternative_pbm_matrix.ranked_analysis"],
      "scope_required": ["exact governed savings packet match"],
      "formulas": [
        "baseline_net_employer_paid = incumbent Net Employer Paid",
        "target_net_employer_paid = challenger Net Employer Paid",
        "projected_savings = max(baseline_net_employer_paid - target_net_employer_paid, 0)"
      ],
      "blocked_when": ["no exact packet match exists", "required Net Employer Paid rows are missing"]
    },
    {
      "id": "modeled_scenarios",
      "label": "Modeled optimization scenarios",
      "implementation": "LeafEnterprise/pocket_consultant.py",
      "source_tables": ["report payload", "optimization evidence"],
      "scope_required": ["resolved report scope"],
      "formulas": [
        "specialty_rebate_lift = specialty_drug_spend * improvement_pct",
        "top_specialty_cost_reduction = top_specialty_drug_ingredient_cost * improvement_pct",
        "channel_cost_reduction = top_channel_ingredient_cost * improvement_pct"
      ],
      "blocked_when": ["rebate evidence is not safe for rebate-backed recommendations", "model would imply unsupported final savings proof"]
    }
  ]
}
