PatientProgram has the folllowing utility method to transition to a new state (which the REST module delegates to when adding new states):
public void transitionToState(ProgramWorkflowState programWorkflowState, Date onDate)
This method will set the end date of the current “last” state to the “onDate”, and then create a the new state with startDate = onDAte, and endDate = null.
In this case, we want to set the endDate to the dateCompleted if the program is completed.
This functionality has been implemented in the following feature branch:
... but should not be added until
TRUNK-5230 is completed for consistency.
There was talk of backporting these, features, but I think it's fine to just apply them to the latest master at this point... *but note*that this feature branch was made off of 1.10.x, so you may want/need to cherry pick this commit into the master branch.