// let the states decide for uncompleted programs
// (_should_ not be necessary, but that's life,
// partially due
// to ProgramLocation module, or Reopening of old
// programs, or patient merge)
PatientState mostRecentState = mostRecentPatientProgram.getCurrentState(workflow);
PatientState ps = pp.getCurrentState(workflow);
if (mostRecentState == null || ps == null) {
// just do nothing
} else if (mostRecentState.getEndDate() != null && ps.getEndDate() == null) {
mostRecentPatientProgram = pp;
} else if (ps.getStartDate().after(mostRecentState.getStartDate())) {
mostRecentPatientProgram = pp;
}
}
}
}
}
if (mostRecentPatientProgram != null) {
PatientState ps = mostRecentPatientProgram.getCurrentState(workflow);
if (ps != null && ps.getState() != null && ps.getState().getConcept().getName() != null) {
return ps;
}
}
return null;
}