Current patient state being returned is wrong

Whenever I use the method getCurrentState for a Patient Program, it returns the wrong state. It doesn’t return my current state which is the state that has the latest start_date.

How do I get the latest state based on the latest date in the start_date column?

Also whenever I get all the current states for a patient program, it sometimes does not return all current states.

Are you passing the ProgramWorkflow instance to the getCurrentState(ProgramWorkflow) method? Or are you calling the method that takes no arguments?

Yes. But it returns the wrong current/latest state based on start_date.