Legacy Pipeline Atlas worker-1snapshot 2026-07-15

MDClarity · task primitive

ProcessScenarioModel

Overview

ProcessScenarioModelTask processes scenario models that are in Queued status, calculating account estimates for all facility and insurance combinations defined in each model. It uses scenario-specific pricing logic (ScenarioFeeLogic) to generate what-if analysis results for contract modeling and pricing analysis.

Use this task when: You need to execute scenario model calculations after users have configured scenario models and marked them ready for processing (Queued status).

Don't use this task when: Processing regular account data (use BatchProcessAccountDataTask instead), processing individual accounts (use targeted account processing), or when scenario models haven't been properly configured yet.


Parameters

Parameter Type Required Default Description
None - - - This task has no configurable parameters. It automatically processes all scenario models in Queued status.

Execution Flow

NoYesYesNoYesNoYesNoStartProcessScenarioModelGet all scenario modelswith Status=QueuedModels found?Exit - No models to processUpdate all models toStatus=RunningSave model status updatesFor each scenario modelClear existing scenariomodel dataCreate calculation enginefor scenarioLoop through Facilities inmodelLoop through Insurances inmodelGet accounts matchingcriteriaProcess accounts inbatchesCalculate estimates usingscenario fee logicTag estimates withScenarioModelKeyBulk insert estimates todatabaseMore insurances?More facilities?More models?Update modelStatus=CompleteSave all completed modelsEnd

Processing Algorithm

The ProcessScenarioModel task performs scenario-based account estimation with the following workflow:

Scenario Processing Loop

For each scenario model, the task:

  1. Clears Previous Results: Deletes all existing scenario estimate data for the model key
  2. Creates Scenario Engine: Instantiates a calculation engine using the model's ScenarioFeeLogicKey
  3. Iterates Combinations: Processes all facility × insurance combinations defined in the model
  4. Filters Accounts: Selects accounts matching:
    • Facility from model's Facilities list
    • Insurance from model's Insurances list
    • Bill type matching model's BillType (if specified)
    • Service dates within model's StartDate to EndDate range (if specified)
  5. Calculates Estimates: Runs pricing calculation using scenario-specific fee logic
  6. Tags Results: Associates all estimates with the ScenarioModelKey for scenario isolation
  7. Bulk Saves: Inserts estimates in batches of 100,000 rows

Scenario Data Isolation

All scenario results are stored separately from production estimates:

This ensures scenario analysis doesn't interfere with production data.

Example Execution

Given a scenario model configured to analyze Medicare vs Commercial pricing:

ScenarioModel SM-001
  Name: "Medicare vs Commercial Comparison"
  Status: Queued
  ScenarioFeeLogicKey: "SFL-MEDICARE-TEST"
  Facilities: ["FAC-001", "FAC-002"]
  Insurances: ["INS-MEDICARE", "INS-AETNA"]
  BillType: "Inpatient"
  StartDate: 2025-01-01
  EndDate: 2025-12-31

Step 1: Mark model as Running
  SM-001.Status = Running

Step 2: Clear existing scenario data
  DELETE FROM AccountEstimateScenarioModel WHERE ScenarioModelKey = 'SM-001'
  DELETE FROM AccountEstimateChargeScenarioModel WHERE ScenarioModelKey = 'SM-001'
  DELETE FROM AccountEstimateCalculationScenarioModel WHERE ScenarioModelKey = 'SM-001'

Step 3: Process facility × insurance combinations (4 total)
  Combination 1: FAC-001 × INS-MEDICARE
    - Get accounts: FacilityKey='FAC-001', InsuranceKey='INS-MEDICARE', BillType='Inpatient', ServiceDate BETWEEN 2025-01-01 AND 2025-12-31
    - Found 250 accounts
    - Calculate estimates using SFL-MEDICARE-TEST fee logic
    - Tag all results with ScenarioModelKey = 'SM-001'
    - Bulk insert 250 estimates

  Combination 2: FAC-001 × INS-AETNA
    - Get accounts: FacilityKey='FAC-001', InsuranceKey='INS-AETNA', BillType='Inpatient', ServiceDate BETWEEN 2025-01-01 AND 2025-12-31
    - Found 180 accounts
    - Calculate estimates using SFL-MEDICARE-TEST fee logic
    - Tag all results with ScenarioModelKey = 'SM-001'
    - Bulk insert 180 estimates

  Combination 3: FAC-002 × INS-MEDICARE
    - Found 300 accounts
    - Process and bulk insert

  Combination 4: FAC-002 × INS-AETNA
    - Found 220 accounts
    - Process and bulk insert

Step 4: Mark model as Complete
  SM-001.Status = Complete

Total: 950 accounts processed across 4 facility/insurance combinations

Usage Examples

Example 1: Basic task execution (processes all queued models)

var task = new ProcessScenarioModelTask();
// Automatically processes all scenario models with Status = Queued

Example 2: Scheduled job for nightly scenario processing

// Run scenario processing overnight when system load is lower
var job = new Job
{
    Key = "JOB-PROCESS-SCENARIOS",
    DisplayName = "Process Queued Scenario Models",
    Tasks = new List<Task>
    {
        new ProcessScenarioModelTask()
    },
    Schedule = "0 2 * * *"  // Run at 2 AM daily
};

Example 3: Chaining with scenario model creation

// Pattern: Create scenario models via API, then process in batch
// User creates scenario models through UI, sets Status = Queued
// Job picks them up and processes

var job = new Job
{
    DisplayName = "Scenario Processing Pipeline",
    Tasks = new List<Task>
    {
        new ProcessScenarioModelTask()
    }
};

// This task will process:
// - All scenario models where Status = Queued
// - Changes status to Running → Complete
// - Results isolated in scenario-specific tables

Related Tasks Comparison

Task Scope Pricing Logic Data Isolation Use Case
ProcessScenarioModel Scenario models (Status=Queued) ScenarioFeeLogic Separate scenario tables What-if pricing analysis and contract modeling
BatchProcessAccountData Facilities × Insurances × Bill Types Production FeeLogic Production tables Regular account estimate recalculation
ChargeAnalysis All combinations (charges × facilities × insurances × providers) Production FeeLogic Analysis tables Comprehensive pricing matrix generation

Key Differentiators:


Performance Considerations

Database Impact

Optimization Tips

Scenario Recommendation Rationale
Large account volumes Limit date ranges in scenario model configuration Reduces accounts per facility/insurance combination
Multiple scenarios Process during off-peak hours Avoid competing with production estimate calculations
Repeated scenario runs Archive or delete old scenario data periodically Prevents scenario tables from growing unbounded
Slow scenario processing Review ScenarioFeeLogic complexity Complex fee logic increases calculation time per account