/** * 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())); }
public function render_signup_steps_by_route($route, $isSingleCenter = false) { // $isSingleCenter = true; // $route = 'institution_signup_setup_institutionDoctors'; if ('institution_signUp' == $route) { // we are still in initial sign up, so no specific steps yet $template = $this->twig->render('InstitutionBundle:SignUp/Widgets:steps.initial.html.twig'); } else { if ($isSingleCenter) { $steps = $this->signUpService->getSingleCenterSignUpSteps(); $currentStep = $this->signUpService->getSingleCenterSignUpStepByRoute($route); } else { $steps = $this->signUpService->getMultipleCenterSignUpSteps(); $currentStep = $this->signUpService->getMultipleCenterSignUpStepByRoute($route); } $template = $this->twig->render('InstitutionBundle:SignUp/Widgets:steps.html.twig', array('steps' => $steps, 'currentStep' => $currentStep ? $currentStep : new SignUpStep())); } return $template; }