public void controller(
      FragmentModel model,
      @FragmentParam("patient") Patient patient,
      @FragmentParam("program") Program program,
      @FragmentParam(required = false, value = "registrationFormUuid") String regFormUuid,
      @FragmentParam(required = false, value = "exitFormUuid") String exitFormUuid) {

    ProgramWorkflowService pws = Context.getProgramWorkflowService();
    PatientProgram currentEnrollment = null;
    List<PatientProgram> pastEnrollments = new ArrayList<PatientProgram>();
    for (PatientProgram pp :
        pws.getPatientPrograms(patient, program, null, null, null, null, false)) {
      if (pp.getActive()) {
        currentEnrollment = pp;
      } else {
        pastEnrollments.add(pp);
      }
    }

    model.addAttribute("patient", patient);
    model.addAttribute("program", program);
    model.addAttribute("registrationFormUuid", regFormUuid);
    model.addAttribute("exitFormUuid", exitFormUuid);
    model.addAttribute("currentEnrollment", currentEnrollment);
    model.addAttribute("pastEnrollments", pastEnrollments);
  }
 /**
  * returns active patient program corresponding to valid programId
  *
  * @param ppList
  * @param programIds
  * @return
  */
 private PatientProgram activePatientProgram(
     List<PatientProgram> ppList, Set<Integer> programIds) {
   if (ppList != null) {
     for (PatientProgram pp : ppList) {
       if (pp.getActive() && programIds.contains(pp.getProgram().getProgramId())) return pp;
     }
   }
   return null;
 }