Skip to content

Conversation

@halcwb
Copy link
Collaborator

@halcwb halcwb commented Feb 4, 2026

This pull request introduces several enhancements and refactorings to the Order and OrderProcessor modules, focusing on improved constraint handling, dose normalization, and table output formatting. It adds new utility functions for applying and setting calculated constraints, refines how orders are processed when properties change, and streamlines table output for better logging and debugging. Additionally, new script files are included in the project.

Constraint and Dose Handling Improvements:

  • Added applyOnlyMaxConstraints, applyCalculatedConstraints, and setCalculatedConstraints functions to the Order module, enabling more precise application and management of constraints on doses and orders. [1] [2] [3]
  • Introduced hasNormDose and improved setNormDose logic to better handle normalization of doses based on order schedules and components. [1] [2]

Order Property Processing Enhancements:

  • Refactored property change handling in OrderProcessor to use new constraint application functions and to process property changes in a more functional, composable way (e.g., always returning Ok, not using intermediate Result.map). Added orderPropertySetDoseQuantityPerc for setting dose quantity by percentage. [1] [2] [3]
  • Updated command processing to support setting dose quantity by percentage and improved handling of component quantities. [1] [2]

Console Table and Logging Refactor:

  • Refactored table output functions: replaced printTable with toConsoleTable, added toConsoleTableString, and updated logging to use these new functions for clearer, more informative output. [1] [2] [3] [4] [5]

Increment and Calculation Adjustments:

@greptile: review

  • Adjusted increments used for dose calculations and removed unused increment values for better precision. Simplified calcMinMax to remove the increaseIncrement parameter. [1] [2] [3] [4]

Project Structure:

  • Added new script files Constraints.fsx and NormDose.fsx to the project file for improved testing and documentation.

…lation, working on percentage setting of dose quantity
…ated constraints, remove need to recacl min-max
@greptile-apps
Copy link

greptile-apps bot commented Feb 4, 2026

Greptile Overview

Greptile Summary

This PR introduces a calculated constraints tracking system to improve order processing efficiency. The key architectural change is adding a Calculated field to OrderVariable that stores constraint values derived from solving, enabling more efficient recalculation by applying previously calculated constraints instead of recomputing from scratch.

Key Changes:

  • Added calculated constraints tracking: OrderVariable now maintains both Constraints (user/system defined) and Calculated (solver-derived) fields, with applyConstraints preferring calculated values when available
  • Refactored order processing pipeline: CalcMinMax command now separates increment increase and norm dose calculation into distinct pipeline steps, improving modularity
  • Modified property change handlers to return Ok directly rather than binding through solveMinMax, shifting error handling to pipeline steps
  • Enhanced table output to display calculated constraints as a 5th column for better debugging visibility
  • Simplified calcMinMax by removing the increaseIncrement parameter, now handling increment increases through separate pipeline step
  • Improved increaseIncrement logic to only consider increments larger than the current value
  • Added SetDoseQuantityPerc command for percentage-based dose quantity setting
  • Refactored script files by extracting constraint and norm dose testing into separate files

Issues Found:

  • Multiple instances of commented-out code that should be removed (solveMinMax calls, guard conditions)
  • Inconsistent refactoring in orderPropertySetComponentQuantity which still uses the old Result.bind pattern while other property setters have moved to the new Ok-returning approach

Confidence Score: 3/5

  • This PR is safe to merge after addressing the inconsistent refactoring in orderPropertySetComponentQuantity
  • The PR implements a significant architectural improvement with calculated constraints tracking, but has an inconsistent refactoring where orderPropertySetComponentQuantity still uses the old error handling pattern while other property setters have been updated. Additionally, multiple commented-out code blocks should be cleaned up before merge.
  • src/Informedica.GenORDER.Lib/OrderProcessor.fs requires attention for the inconsistent error handling pattern and commented-out code removal

Important Files Changed

Filename Overview
src/Informedica.GenORDER.Lib/Order.fs Added calculated constraints tracking, new constraint application functions (applyOnlyMaxConstraints, applyCalculatedConstraints, setCalculatedConstraints), improved table output with calculated column, refactored calcMinMax to remove increaseIncrement parameter, and enhanced norm dose handling
src/Informedica.GenORDER.Lib/OrderProcessor.fs Refactored property change handlers to always return Ok instead of Result, added percentage-based dose quantity setting, modified pipeline steps to separate increment increase and norm dose calculation, changed guard conditions for calc-values
src/Informedica.GenORDER.Lib/OrderVariable.fs Added Calculated field to OrderVariable type, implemented setCalculatedConstraints and applyCalculatedConstraints functions, modified applyConstraints to check calculated constraints first, added fromValueRange helper, extended DTO serialization
src/Informedica.GenORDER.Lib/Types.fs Added Calculated field to OrderVariable type, added IncreaseIncrements and SetDoseQuantityPerc command types
src/Informedica.GenSOLVER.Lib/Variable.fs Modified increaseIncrement to only use increments larger than original and return original ValueRange when no suitable increments found, improving increment selection logic

Sequence Diagram

sequenceDiagram
    participant Client
    participant OrderProcessor
    participant Order
    participant OrderVariable
    participant Variable

    Note over Client,Variable: Calculated Constraints Flow

    Client->>OrderProcessor: CalcMinMax Command
    OrderProcessor->>Order: applyConstraints()
    Order->>OrderVariable: applyConstraints()
    OrderVariable->>OrderVariable: Check if Calculated is set
    alt Calculated constraints exist
        OrderVariable->>OrderVariable: applyCalculatedConstraints()
    else No calculated constraints
        OrderVariable->>OrderVariable: Apply regular Constraints
    end
    OrderProcessor->>Order: calcMinMax()
    Order->>Variable: solveMinMax()
    Variable-->>Order: Solved order with min/max
    OrderProcessor->>Order: setCalculatedConstraints()
    Order->>OrderVariable: setCalculatedConstraints()
    OrderVariable->>OrderVariable: Store Variable.Values as Calculated
    OrderProcessor->>Order: increaseIncrements()
    Order->>Variable: increaseIncrement()
    Variable->>Variable: Filter increments > current
    Variable-->>Order: Updated increments
    OrderProcessor->>Order: solveNormDose()
    Order->>Order: hasNormDose()
    alt Has norm dose
        Order->>Order: setNormDose()
    end
    Order-->>Client: Result with calculated constraints

    Note over Client,Variable: Property Change Flow

    Client->>OrderProcessor: ChangeProperty Command
    OrderProcessor->>OrderProcessor: processChangeProperty()
    OrderProcessor->>Order: Apply property changes
    Order->>OrderVariable: setPercValue() / setMinValue() / etc
    OrderProcessor->>Order: calcMinMax()
    Order-->>Client: Updated order
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 7 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +69 to +73
// |> solveMinMax "Order Property Set Frequency" printErr logger
// step to a min, median or max value
|> Result.map (OrderPropertyChange.proc [ ScheduleFrequency step ])
// |> Result.map (OrderPropertyChange.proc [ ScheduleFrequency step ])
|> OrderPropertyChange.proc [ ScheduleFrequency step ]
|> Ok
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented-out code should be removed rather than kept in the codebase

Suggested change
// |> solveMinMax "Order Property Set Frequency" printErr logger
// step to a min, median or max value
|> Result.map (OrderPropertyChange.proc [ ScheduleFrequency step ])
// |> Result.map (OrderPropertyChange.proc [ ScheduleFrequency step ])
|> OrderPropertyChange.proc [ ScheduleFrequency step ]
|> Ok
|> OrderPropertyChange.proc [ ScheduleFrequency step ]
|> Ok

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Informedica.GenORDER.Lib/OrderProcessor.fs
Line: 69:73

Comment:
commented-out code should be removed rather than kept in the codebase

```suggestion
        |> OrderPropertyChange.proc [ ScheduleFrequency step ]
        |> Ok
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 112 to +117
// re-calc the min max
|> solveMinMax "Order Property Set Dose Rate" printErr logger
// |> solveMinMax "Order Property Set Dose Rate" printErr logger
// step to a min, median or max rate
|> Result.map (OrderPropertyChange.proc [ OrderableDose step ])

// |> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented-out code should be removed

Suggested change
// re-calc the min max
|> solveMinMax "Order Property Set Dose Rate" printErr logger
// |> solveMinMax "Order Property Set Dose Rate" printErr logger
// step to a min, median or max rate
|> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
// |> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Informedica.GenORDER.Lib/OrderProcessor.fs
Line: 112:117

Comment:
commented-out code should be removed

```suggestion
        |> OrderPropertyChange.proc [ OrderableDose step ]
        |> Ok
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 169 to +176
OrderableDoseCount OrderVariable.Count.applyConstraints
]
// re-calc min max
|> solveMinMax "Order Property Set Dose Quantity" printErr logger
// |> solveMinMax "Order Property Set Dose Quantity" printErr logger
// step to a min, median or max dose quantity
|> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
// |> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented-out code should be removed

Suggested change
OrderableDoseCount OrderVariable.Count.applyConstraints
]
// re-calc min max
|> solveMinMax "Order Property Set Dose Quantity" printErr logger
// |> solveMinMax "Order Property Set Dose Quantity" printErr logger
// step to a min, median or max dose quantity
|> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
// |> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Informedica.GenORDER.Lib/OrderProcessor.fs
Line: 169:176

Comment:
commented-out code should be removed

```suggestion
        |> OrderPropertyChange.proc [ OrderableDose step ]
        |> Ok
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +198 to +204
]
// re-calc min max
// |> solveMinMax "Order Property Set Dose Quantity" printErr logger
// step to a min, median or max dose quantity
// |> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented-out code should be removed

Suggested change
]
// re-calc min max
// |> solveMinMax "Order Property Set Dose Quantity" printErr logger
// step to a min, median or max dose quantity
// |> Result.map (OrderPropertyChange.proc [ OrderableDose step ])
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok
|> OrderPropertyChange.proc [ OrderableDose step ]
|> Ok

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Informedica.GenORDER.Lib/OrderProcessor.fs
Line: 198:204

Comment:
commented-out code should be removed

```suggestion
        |> OrderPropertyChange.proc [ OrderableDose step ]
        |> Ok
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +724 to +725
os.OrderIsSolved |> not //&&
//os.HasValues |> not
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented-out condition should be removed or documented

Suggested change
os.OrderIsSolved |> not //&&
//os.HasValues |> not
os.OrderIsSolved |> not
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Informedica.GenORDER.Lib/OrderProcessor.fs
Line: 724:725

Comment:
commented-out condition should be removed or documented

```suggestion
                os.OrderIsSolved |> not
```

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 329 to +331
|> Result.map (OrderPropertyChange.proc [ ComponentOrderableQuantity (cmp, step) ])
// |> OrderPropertyChange.proc [ ComponentOrderableQuantity (cmp, step) ]
// |> Ok
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented-out code should be removed

Suggested change
|> Result.map (OrderPropertyChange.proc [ ComponentOrderableQuantity (cmp, step) ])
// |> OrderPropertyChange.proc [ ComponentOrderableQuantity (cmp, step) ]
// |> Ok
|> Result.map (OrderPropertyChange.proc [ ComponentOrderableQuantity (cmp, step) ])

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Informedica.GenORDER.Lib/OrderProcessor.fs
Line: 329:331

Comment:
commented-out code should be removed

```suggestion
        |> Result.map (OrderPropertyChange.proc [ ComponentOrderableQuantity (cmp, step) ])
```

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@greptile-apps
Copy link

greptile-apps bot commented Feb 4, 2026

Additional Comments (1)

src/Informedica.GenORDER.Lib/OrderProcessor.fs
inconsistent error handling approach - other property setter functions (orderPropertySetFrequency, orderPropertySetDoseRate, orderPropertySetDoseQuantity) now return Ok directly without calling solveMinMax, but this function still uses Result.bind pattern. Consider aligning with the new pattern or documenting why this needs different handling

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Informedica.GenORDER.Lib/OrderProcessor.fs
Line: 282:331

Comment:
inconsistent error handling approach - other property setter functions (`orderPropertySetFrequency`, `orderPropertySetDoseRate`, `orderPropertySetDoseQuantity`) now return `Ok` directly without calling `solveMinMax`, but this function still uses `Result.bind` pattern. Consider aligning with the new pattern or documenting why this needs different handling

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@halcwb halcwb merged commit 99cff72 into informedica:master Feb 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant