/** edited for newly markup * Add new CLINIC CENTER * @author Chaztine Blance * @return \Symfony\Component\HttpFoundation\Response */ public function addMedicalCenterAction(Request $request) { if ($request->isMethod('POST')) { if (!$this->institutionMedicalCenter instanceof InstitutionMedicalCenter) { $this->institutionMedicalCenter = new InstitutionMedicalCenter(); $this->institutionMedicalCenter->setInstitution($this->institution); } $formVariables = $request->get(InstitutionMedicalCenterFormType::NAME); unset($formVariables['_token']); $removedFields = \array_diff(InstitutionMedicalCenterFormType::getFieldNames(), array_keys($formVariables)); $this->get('services.contact_detail')->initializeContactDetails($this->institutionMedicalCenter, array(ContactDetailTypes::PHONE), $this->institution->getCountry()); $this->institutionMedicalCenter->setDescription(' '); $this->institutionMedicalCenter->setAddress($this->institution->getAddress1()); $this->institutionMedicalCenter->setAddressHint($this->institution->getAddressHint()); $this->institutionMedicalCenter->setCoordinates($this->institution->getCoordinates()); $form = $this->createForm(new InstitutionMedicalCenterFormType($this->institution), $this->institutionMedicalCenter, array(InstitutionMedicalCenterFormType::OPTION_BUBBLE_ALL_ERRORS => false, InstitutionMedicalCenterFormType::OPTION_REMOVED_FIELDS => $removedFields)); $form->bind($request); if ($form->isValid()) { $this->get('services.contact_detail')->removeInvalidContactDetails($this->institutionMedicalCenter); $this->institutionMedicalCenter = $this->get('services.institutionMedicalCenter')->saveAsDraft($form->getData()); $output = $this->generateUrl('institution_medicalCenter_view', array('imcId' => $this->institutionMedicalCenter->getId())); $this->get('event_dispatcher')->dispatch(MailerBundleEvents::NOTIFICATIONS_CLINIC_CREATED, new GenericEvent($this->institutionMedicalCenter, array('userEmail' => $request->getSession()->get('userEmail')))); $response = new Response(\json_encode(array('redirect' => $output)), 200, array('content-type' => 'application/json')); } else { $errors = array(); $form_errors = $this->get('validator')->validate($form); foreach ($form_errors as $_err) { $errors[] = array('field' => str_replace('data.', '', $_err->getPropertyPath()), 'error' => $_err->getMessage()); } $response = new Response(\json_encode(array('html' => $errors)), 400, array('content-type' => 'application/json')); } } 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)); }
public function completeProfileOfInstitutionWithSingleCenter(Institution $institution, InstitutionMedicalCenter $institutionMedicalCenter) { // save the institution $this->institutionFactory->save($institution); // set medical center name and description to institution.name and institution.description $institutionMedicalCenter->setName($institution->getName()); $institutionMedicalCenter->setDescription($institution->getDescription() ? $institution->getDescription() : '2'); $institutionMedicalCenter->setInstitution($institution); $institutionMedicalCenter->setAddress($institution->getAddress1()); $institutionMedicalCenter->setCoordinates($institution->getCoordinates()); // save institution medical center as draft $this->institutionMedicalCenterService->saveAsDraft($institutionMedicalCenter); }