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; }
/** * Setting up the profile of the Single Center institution * * TODO: * This has a crappy rule where institution name and description will internally be the name and description of the clinic. * * @author acgvelarde * @return */ private function setupProfileSingleCenter(Request $request) { // Set Current Route $this->currentSignUpStep = $this->signUpService->getSingleCenterSignUpStepByRoute($request->attributes->get('_route')); $institutionMedicalCenter = $this->institutionService->getFirstMedicalCenter($this->institution); if (\is_null($institutionMedicalCenter)) { $institutionMedicalCenter = new InstitutionMedicalCenter(); } $this->get('services.contact_detail')->initializeContactDetails($this->institution, array(ContactDetailTypes::PHONE)); $form = $this->createForm(new InstitutionProfileFormType(), $this->institution, array(InstitutionProfileFormType::OPTION_BUBBLE_ALL_ERRORS => false)); if ($this->request->isMethod('POST')) { $formRequestData = $this->request->get($form->getName()); if (isset($formRequestData['medicalProviderGroups'])) { // we always expect 1 medical provider group // if it is empty remove it from the array if (isset($formRequestData['medicalProviderGroups'][0]) && '' == trim($formRequestData['medicalProviderGroups'][0])) { unset($formRequestData['medicalProviderGroups'][0]); } else { $formRequestData['medicalProviderGroups'][0] = str_replace(array("\\'", '\\"'), array("'", '"'), $formRequestData['medicalProviderGroups'][0]); } } // Check If Custom State if (!$formRequestData['state'] && ($stateName = $request->get('custom_state'))) { $stateData = array('name' => $stateName, 'geoCountry' => $formRequestData['country'], 'institutionId' => $this->institution->getId()); if ($state = $this->get('services.location')->addNewState($stateData)) { $formRequestData['state'] = $state->getId(); } } // Check If Custom City if (!(int) $formRequestData['city'] && ($cityName = $request->get('custom_city'))) { $cityData = array('name' => $cityName, 'geoState' => $formRequestData['state'], 'geoCountry' => $formRequestData['country'], 'institutionId' => $this->institution->getId()); if ($city = $this->get('services.location')->addNewCity($cityData)) { $formRequestData['city'] = $city->getId(); } } $form->bind($formRequestData); if ($form->isValid()) { $this->get('services.contact_detail')->removeInvalidContactDetails($this->institution); // set the sign up status of this single center institution $this->_updateInstitutionSignUpStepStatus($this->currentSignUpStep); $form->getData()->setSignupStepStatus($this->currentSignUpStep->getStepNumber()); // save institution and create an institution medical center $this->signUpService->completeProfileOfInstitutionWithSingleCenter($form->getData(), $institutionMedicalCenter); // get the next step redirect url $redirectUrl = $this->generateUrl($this->signUpService->getSingleCenterSignUpNextStep($this->currentSignUpStep)->getRoute(), array('imcId' => $this->institutionService->getFirstMedicalCenter($this->institution)->getId())); $request->getSession()->setFlash('success', "<b>Congratulations!</b> You have setup your Clinic profile."); //set flash message // TODO: Update this when we have formulated a strategy for our event 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_HOSPITAL_CREATED, new GenericEvent($this->institution)); return $this->redirect($redirectUrl); } else { $formErrors = $this->get('validator')->validate($form); $request->getSession()->setFlash('error', "We need you to correct some of your input. Please check the fields in red."); //set flash message } } return $this->render('InstitutionBundle:SignUp:setupProfile.singleCenter.html.twig', array('form' => $form->createView(), 'institutionMedicalCenter' => $institutionMedicalCenter, 'medicalProvidersJSON' => $this->getMedicalProviderGroupJSON())); }