private function validateSignUpStatus($session, $currentRoute)
 {
     $response = null;
     $signupStepStatus = $session->get('institutionSignupStepStatus');
     // check if the institution has completed sign up flow
     if ($session->get('isSingleCenterInstitution')) {
         $lastStep = $this->institutionSignUpService->getSingleCenterSignUpLastStep();
         $nextStep = $this->institutionSignUpService->getSingleCenterSignUpNextStep($signupStepStatus);
     } else {
         $lastStep = $this->institutionSignUpService->getMultipleCenterSignUpLastStep();
         $nextStep = $this->institutionSignUpService->getMultipleCenterSignUpNextStep($signupStepStatus);
     }
     // has not completed institution sign up flow yet
     if ($lastStep && $signupStepStatus < $lastStep->getStepNumber()) {
         $routeName = $nextStep->getRoute();
         // we don't need to redirect anymore
         if ($routeName != $currentRoute) {
             $routeParams = array();
             // only steps other than step 1 has imcId parameter
             if ($signupStepStatus > 1) {
                 $medicalCenter = $this->institutionService->getFirstMedicalCenterByInstitutionId($session->get('institutionId'));
                 $routeParams = array('imcId' => $medicalCenter ? $medicalCenter->getId() : 0);
             }
             // redirect to incomplete step in signup flow
             $response = new RedirectResponse($this->router->generate($routeName, $routeParams));
         }
     }
     return $response;
 }
 /**
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function setupInstitutionMedicalCenterAction(Request $request)
 {
     $error_message = false;
     if ($this->institutionService->isSingleCenter($this->institution)) {
         // this is not part of the sign up flow of  single center institution
         throw $this->createNotFoundException();
     }
     $this->currentSignUpStep = $this->signUpService->getMultipleCenterSignUpStepByRoute($request->attributes->get('_route'));
     // TODO: check current sign up status
     // We don't assume that there is a medical center instance here already since this is also where we redirect from multiple center institution sign up
     if (!$this->institutionMedicalCenter instanceof InstitutionMedicalCenter) {
         $this->institutionMedicalCenter = new InstitutionMedicalCenter();
         $this->institutionMedicalCenter->setInstitution($this->institution);
     }
     $this->get('services.contact_detail')->initializeContactDetails($this->institutionMedicalCenter, array(ContactDetailTypes::PHONE), $this->institution->getCountry());
     $form = $this->createForm(new InstitutionMedicalCenterFormType($this->institution), $this->institutionMedicalCenter, array(InstitutionMedicalCenterFormType::OPTION_BUBBLE_ALL_ERRORS => false));
     if ($this->request->isMethod('POST')) {
         $formRequestData = $request->get($form->getName());
         if ((bool) $request->get('isSameAddress')) {
             $formRequestData['address'] = json_decode($this->institution->getAddress1(), true);
             $this->institutionMedicalCenter->setAddressHint($this->institution->getAddressHint());
             $this->institutionMedicalCenter->setCoordinates($this->institution->getCoordinates());
         }
         $form->bind($formRequestData);
         if ($form->isValid()) {
             $this->institutionMedicalCenter = $form->getData();
             $institutionMedicalCenterService = $this->get('services.institution_medical_center');
             $this->get('services.contact_detail')->removeInvalidContactDetails($this->institutionMedicalCenter);
             $institutionMedicalCenterService->clearBusinessHours($this->institutionMedicalCenter);
             foreach ($this->institutionMedicalCenter->getBusinessHours() as $_hour) {
                 $_hour->setInstitutionMedicalCenter($this->institutionMedicalCenter);
             }
             $institutionMedicalCenterService->saveAsDraft($this->institutionMedicalCenter);
             // update sign up step status of institution
             $this->_updateInstitutionSignUpStepStatus($this->currentSignUpStep, true);
             // redirect to next step
             $nextStepRoute = $this->signUpService->getMultipleCenterSignUpNextStep($this->currentSignUpStep)->getRoute();
             // TODO: Update this when we have formulated a strategy for our events system
             // We can't use InstitutionBundleEvents; we don't know the consequences of the event firing up other listeners.
             $this->get('event_dispatcher')->dispatch(MailerBundleEvents::NOTIFICATIONS_CLINIC_CREATED, new GenericEvent($this->institutionMedicalCenter, array('userEmail' => $request->getSession()->get('userEmail'))));
             return $this->redirect($this->generateUrl($nextStepRoute, array('imcId' => $this->institutionMedicalCenter->getId())));
         }
         $form_errors = $this->get('validator')->validate($form);
         if ($form_errors) {
             $error_message = 'We need you to correct some of your input. Please check the fields in red.';
         }
     }
     return $this->render('InstitutionBundle:SignUp:setupInstitutionMedicalCenter.html.twig', array('form' => $form->createView(), 'institution' => $this->institution, 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'error_message' => $error_message));
 }