The enrollInProgram tag enrolls a patient in a specified program on a specified date. If no date is specified by the tag itself, the patient is enrolled on the encounter date.
In order for the enrollInProgram tag to handle this, the FormSubmissionAction responsible for enrolling a patient in a program must have access to the selected encounter date. The FormSubmissionActions are able to pull the encounter off the stack, but ONLY if the encounterDate tag comes before the enrollInProgram tag on the form.
This a symptom of a bigger issue-- and is just one example of an error that may occur any time one tag needs access to data collected by another tag.
One potential solution would be add a new <encounter> tag that wrapped all the underlying encounter-based functionality.