public EnrollInProgramElement(FormEntryContext context, Map<String, String> parameters) {
try {
program = HtmlFormEntryUtil.getProgram(parameters.get("programId"));
if (program == null)
throw new FormEntryException("");
}
catch (Exception ex) {
throw new IllegalArgumentException("Couldn't find program in: " + parameters);
}
if ("true".equalsIgnoreCase(parameters.get("showDate"))) {
dateWidget = new DateWidget();
dateErrorWidget = new ErrorWidget();
context.registerWidget(dateWidget);
context.registerErrorWidget(dateWidget, dateErrorWidget);
}
String stateIdsStr = parameters.get("stateIds");
if (StringUtils.isNotBlank(stateIdsStr)) {
states = new ArrayList<ProgramWorkflowState>();
String[] stateIdsUuidsOrPrefNames = stateIdsStr.split(",");
//set to store unique work flow state combinations so as to determine multiple states in same work flow
Set<String> workflowsAndStates = new HashSet<String>();
for (String value : stateIdsUuidsOrPrefNames) {
value = value.trim();
ProgramWorkflowState state = HtmlFormEntryUtil.getState(value, program);
if (state == null) {
String errorMsgPart = "with an id or uuid";
if (value.indexOf(":") > -1)
errorMsgPart = "associated to a concept with a concept mapping";
throw new FormEntryException("Cannot find a program work flow state " + errorMsgPart + " that matches '"
+ value + "'");
} else if (!state.getInitial()) {
throw new FormEntryException("The program work flow state that matches '" + value
+ "' is not marked as initial");
} else if (!workflowsAndStates.add(state.getProgramWorkflow().getUuid())) {
throw new FormEntryException("A patient cannot be in multiple states in the same workflow");
}
if (!states.contains(state))
states.add(state);
}