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

MDClarity · task primitive

LoadFeeSchedules

Overview

LoadFeeSchedulesTask generates fee schedules from pricing records stored in the database for specified schedule types. It processes pricing records containing fee amounts with optional modifiers and creates or updates Schedule, FeeScheduleRecord, and ScheduleMap tables to establish effective date ranges for facility/insurance combinations.

Use this task when: You need to create or update fee schedules from uploaded or modified pricing records, converting pricing data into time-based schedules that can be applied to billing and estimation.

Don't use this task when:


Parameters

Parameter Type Required Default Description
ScheduleTypes List<string> Yes Empty list List of schedule type keys to process. Only pricing records matching these schedule types will be converted to schedules. Must contain at least one schedule type.

Execution Flow

flowchart TD
    A[Start LoadFeeSchedulesTask] --> B[Validate ScheduleTypes is not empty]
    B --> C{Valid input?}
    C -->|No| Z1[Throw exception - Schedule type not set]
    C -->|Yes| D[For each ScheduleType in ScheduleTypes]

    D --> E[Get all FeePricingRecords for ScheduleType with InUse=true]
    E --> F[RemoveOutdatedSchedules: Get schedules without pricing records]
    F --> G{Orphaned schedules exist?}
    G -->|Yes| H[Delete orphaned schedules, schedule maps, and schedule records]
    G -->|No| I[Continue]

    H --> I
    I --> J{For each FeePricingRecord}
    J --> K{Schedule exists for this pricing record?}
    K -->|No| L[Create new Schedule with generated key]
    K -->|Yes| M[Use existing Schedule]

    L --> N[Save Schedule]
    M --> N
    N --> O[Delete existing ScheduleMaps for this schedule]
    O --> P[For each Insurance in pricing record]
    P --> Q[For each Facility in pricing record]

    Q --> R[Calculate end date based on next start date]
    R --> S[Create ScheduleMapRecord]
    S --> T{More facilities?}
    T -->|Yes| Q
    T -->|No| U{More insurances?}
    U -->|Yes| P
    U -->|No| V[Save all ScheduleMapRecords]

    V --> W{New schedule?}
    W -->|Yes| X[Create FeeScheduleRecords from FeePricingEntries]
    W -->|No| Y[Skip schedule record creation]

    X --> AA{More pricing records?}
    Y --> AA
    AA -->|Yes| J
    AA -->|No| BB[Log summary]

    BB --> CC{More schedule types?}
    CC -->|Yes| D
    CC -->|No| Z2[End]

    Z1 --> Z2

    style E fill:#e1f5ff
    style L fill:#fff4e1
    style V fill:#e1f5ff
    style X fill:#e1f5ff
    style H fill:#ffe1e1

Processing Algorithm

The task uses the ScheduleUpdateController with generic type parameters <FeePricingRecord, FeeScheduleRecord> to manage schedule generation:

  1. Input Validation: Verify that at least one schedule type is specified
  2. For Each Schedule Type:
    • Retrieve all active fee pricing records (InUse = true) matching the schedule type
    • Remove Outdated Schedules: Find schedules whose PricingRecordKey no longer exists in the pricing records and delete them along with their schedule maps and fee schedule records
  3. For Each Pricing Record:
    • Find or Create Schedule: Look up existing schedule by PricingRecordKey, or create new with generated key
    • Delete Old Schedule Maps: Remove existing schedule map records to rebuild with current data
    • Calculate End Dates: For each facility/insurance combination:
      • Query all start dates for the facility/insurance pair in the schedule type
      • If this is the most recent start date, set end date to 2999-12-31 (arbitrary far future)
      • Otherwise, set end date to one day before the next start date
    • Create Schedule Maps: Generate ScheduleMapRecord for each facility/insurance combination with calculated date ranges
    • Create Fee Schedule Records (new schedules only): For each FeePricingEntry in the pricing record's collection, create a FeeScheduleRecord with Member, Modifier, Amount, Filter, and Priority values
  4. Logging: Track counts of processed schedules and newly created schedules

Example Execution

Given two pricing records for schedule type Fixed-Fees:

Pricing Record 1:

Pricing Record 2:

The task creates:

Schedule 1 (for Pricing Record 1):

Schedule 2 (for Pricing Record 2):


Usage Examples

Example 1: Load schedules for a single schedule type

var task = new LoadFeeSchedulesTask
{
    ScheduleTypes = new List<string> { "Fixed-Fees" }
};
// Processes all FeePricingRecords with ScheduleType = "Fixed-Fees" and InUse = true
// Creates or updates schedules for all facilities/insurances in the pricing records

Example 2: Load schedules for multiple schedule types

var task = new LoadFeeSchedulesTask
{
    ScheduleTypes = new List<string> { "Fixed-Fees", "Profee-Clinic", "Surgery-Fees" }
};
// Processes all pricing records for all three schedule types
// Useful for bulk schedule updates across multiple fee types

Example 3: Rebuild schedules after uploading new pricing data

// Step 1: Upload pricing records using UpdateFeePricingRecordsTask or similar
var uploadTask = new UpdateFeePricingRecordsTask { ... };

// Step 2: Generate schedules from the new pricing records
var loadSchedulesTask = new LoadFeeSchedulesTask
{
    ScheduleTypes = new List<string> { "Fixed-Fees" }
};
// Creates new schedules with proper effective date ranges
// Automatically handles date range calculations to prevent overlaps or gaps

Example 4: Updating schedules for specific facility types

// The task respects facility filters in the pricing records
// If pricing records were created for only "Hospital" facilities,
// only those facilities will have schedule maps created
var task = new LoadFeeSchedulesTask
{
    ScheduleTypes = new List<string> { "Hospital-Fees" }
};
// Schedule maps are created only for facilities specified in the pricing records

Related Tasks Comparison

Task Direction Input Output Use Case
LoadFeeSchedulesTask Pricing → Schedules FeePricingRecord + FeePricingEntry Schedule + FeeScheduleRecord + ScheduleMap Create/update time-based fee schedules from pricing data
BuildFeePricingFromSchedulesTask Schedules → Pricing Schedule + FeeScheduleRecord + ScheduleMap FeePricingRecord + FeePricingEntry Extract pricing records from existing schedules for updates or migration
LoadCodeSchedulesTask Pricing → Schedules CodePricingRecord + CodePricingEntry Schedule + CodeScheduleRecord + ScheduleMap Create/update code schedules (uses same controller but different record types)
UpdateFeePricingRecordsTask Upload → Pricing External data file FeePricingRecord + FeePricingEntry Import pricing data before schedule generation

Key Differentiators:


Performance Considerations

Database Impact

Optimization Tips

Scenario Recommendation Rationale
Many pricing records Process by schedule type separately Reduces memory footprint and allows incremental progress tracking
Frequent schedule updates Ensure pricing records have unique start dates per facility/insurance Simplifies end date calculations and reduces schedule map churn
Initial schedule load Run during off-hours Creates many new records; schedule maps always deleted and recreated
Schedule map updates Existing schedules only recreate maps, not records Schedule records are immutable once created for a schedule key

Important Performance Notes:


Error Handling

The task uses fail-fast error handling at the input validation stage:

if (scheduleTypes?.FirstOrDefault() == null)
{
    throw new Exception("Schedule type not set.");
}

Important:


Common Pitfalls

Issue Problem Solution
No schedules created ScheduleTypes list is empty Verify that at least one schedule type is specified in the ScheduleTypes parameter
Pricing records ignored Records have InUse = false Only pricing records with InUse = true are processed; set InUse = true for records that should be converted to schedules
Schedule maps have wrong end dates Multiple schedules with same start date for facility/insurance Ensure each pricing record has a unique start date per facility/insurance combination
Modifier entries missing Modifiers not properly specified in pricing entries Verify that pricing entries with modifiers have the modifier field populated; task will create Filter = %+MODIFIER% and Priority > 1
Schedules not updated Existing schedule records not refreshed Schedule records are immutable once created; only schedule maps are updated for existing schedules. To update fee amounts, create a new pricing record with a different start date.
Orphaned schedules remain Schedules exist for deleted pricing records Task automatically removes orphaned schedules if the schedule type is in ScheduleTypes; run the task to clean up
Facilities excluded unexpectedly Schedule type filter excludes facilities Verify that pricing records include all desired facilities in their Facilities list; task only creates schedule maps for facilities specified in pricing records

Code References