public function preExecute()
 {
     parent::preExecute();
     $this->repository = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionMedicalCenter');
     $this->institutionService = $this->get('services.institution');
     $this->request = $this->getRequest();
     // NOTE: This code is not necessary anymore and can be remove.
     if ($imcId = $this->getRequest()->get('imcId', 0)) {
         $this->institutionMedicalCenter = $this->repository->find($imcId);
     }
     // End of note
     if ($this->isSingleCenter) {
         $this->institutionMedicalCenter = $this->institutionService->getFirstMedicalCenter($this->institution);
     }
 }
 /**
  * Breadcrumbs will be shown according to insertion order in the $breadcrumbs array
  *
  * @param array $data
  * @return array
  */
 private function doGenerateBreadcrumbs(array $data)
 {
     $breadcrumbs = array();
     if ($data['country']) {
         $breadcrumbs[] = array('label' => $data['country']['name'], 'url' => $this->generateUrl('frontend_search_results_countries', array('country' => $data['country']['slug'])));
     }
     if ($data['city']) {
         $breadcrumbs[] = array('label' => $data['city']['name'], 'url' => $this->generateUrl('frontend_search_results_cities', array('country' => $data['country']['slug'], 'city' => $data['city']['slug'])));
     }
     if ($data['tag']) {
         $breadcrumbs[] = array('label' => $data['tag']);
         return $breadcrumbs;
     }
     if ($data['institution']) {
         $routeName = InstitutionService::getInstitutionRouteName($data['institution']);
         $breadcrumbs[] = array('label' => $data['institution']['name'], 'url' => $this->generateUrl($routeName, array('institutionSlug' => $data['institution']['slug'])));
         if ($data['institutionMedicalCenter']) {
             $breadcrumbs[] = array('label' => $data['institutionMedicalCenter']['name']);
         }
         return $breadcrumbs;
     }
     if ($data['specialization']) {
         $breadcrumbs[] = array('label' => $data['specialization']['name'], 'url' => $this->generateUrl('frontend_search_results_specializations', array('specialization' => $data['specialization']['slug'])));
     }
     if ($data['subSpecialization']) {
         $breadcrumbs[] = array('label' => $data['subSpecialization']['name'], 'url' => $this->generateUrl('frontend_search_results_subSpecializations', array('specialization' => $data['specialization']['slug'], 'subSpecialization' => $data['specialization']['slug'])));
     }
     if ($data['treatment']) {
         $breadcrumbs[] = array('label' => $data['treatment']['name'], 'url' => $this->generateUrl('frontend_search_results_treatments', array('specialization' => $data['specialization']['slug'], 'treatment' => $data['treatment']['slug'])));
     }
     return $breadcrumbs;
 }
 /**
  * Add an ancillary service to institution
  * Required parameters:
  *     - institutionId
  *     - asId ancillary service id
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  * @author alniejacobe
  */
 public function ajaxAddAncillaryServiceAction(Request $request)
 {
     $ancillaryService = $this->getDoctrine()->getRepository('AdminBundle:OfferedService')->find($request->get('id', 0));
     if (!$ancillaryService) {
         throw $this->createNotFoundException('Invalid ancillary service id');
     }
     $propertyService = $this->get('services.institution_property');
     $propertyType = $propertyService->getAvailablePropertyType(InstitutionPropertyType::TYPE_ANCILLIARY_SERVICE);
     // check if this institution already have this property value
     if ($this->institutionService->hasPropertyValue($this->institution, $propertyType, $ancillaryService->getId())) {
         $response = new Response("Property value {$ancillaryService->getId()} already exists.", 500);
     } else {
         $property = $propertyService->createInstitutionPropertyByName($propertyType->getName(), $this->institution);
         $property->setValue($ancillaryService->getId());
         try {
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($property);
             $em->flush();
             // Invalidate InstitutionProfile memcache
             $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institution->getId()));
             $output = array('label' => 'Delete Service', 'href' => $this->generateUrl('institution_ajaxRemoveAncillaryService', array('institutionId' => $this->institution->getId(), 'id' => $property->getId())), '_isSelected' => true);
             $response = new Response(\json_encode($output), 200, array('content-type' => 'application/json'));
         } catch (\Exception $e) {
             $response = new Response($e->getMessage(), 500);
         }
     }
     return $response;
 }
 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;
 }
 /**
  * DEPRECATED ??? - Note added by: Adelbert
  *   
  * Load tabbed contents of an institution
  *   
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function loadMultipleCenterInstitutionTabbedContentsAction()
 {
     $output = array();
     $parameters = array('institution' => $this->institution);
     $content = $this->request->get('content', null);
     switch ($content) {
         case 'services':
             $ancillaryServicesData = array('globalList' => $this->get('services.helper.ancillary_service')->getActiveAncillaryServices(), 'currentAncillaryData' => array(), 'selected' => array());
             foreach ($this->get('services.institution_property')->getInstitutionByPropertyType($this->institution, InstitutionPropertyType::TYPE_ANCILLIARY_SERVICE) as $_selectedService) {
                 $ancillaryServicesData['currentAncillaryData'][] = array('id' => $_selectedService->getId(), 'value' => $_selectedService->getValue());
                 $ancillaryServicesData['selected'][] = $_selectedService->getValue();
             }
             $parameters['services'] = $ancillaryServicesData;
             $output['services'] = array('html' => $this->renderView('InstitutionBundle:Widgets:tabbedContent.institutionServices.html.twig', $parameters));
             break;
         case 'awards':
             $form = $this->createForm(new InstitutionGlobalAwardsSelectorFormType());
             //$currentGlobalAwards = $this->institutionService->getGroupedGlobalAwardsByType($this->institution);
             $currentGlobalAwards = $this->get('services.institution_property')->getGlobalAwardPropertiesByInstitution($this->institution);
             $autocompleteSource = $this->get('services.global_award')->getAutocompleteSource();
             $editGlobalAwardForm = $this->createForm(new InstitutionGlobalAwardFormType());
             $parameters['form'] = $form->createView();
             $parameters['editGlobalAwardForm'] = $editGlobalAwardForm->createView();
             $parameters['isSingleCenter'] = $this->institutionService->isSingleCenter($this->institution);
             $parameters['awardsSourceJSON'] = \json_encode($autocompleteSource['award']);
             $parameters['certificatesSourceJSON'] = \json_encode($autocompleteSource['certificate']);
             $parameters['affiliationsSourceJSON'] = \json_encode($autocompleteSource['affiliation']);
             $parameters['accreditationsSourceJSON'] = \json_encode($autocompleteSource['accreditation']);
             $parameters['currentGlobalAwards'] = $currentGlobalAwards;
             $parameters['institution'] = $this->institution;
             $parameters['commonDeleteForm'] = $this->createForm(new CommonDeleteFormType())->createView();
             $output['awards'] = array('html' => '');
     }
     return new Response(\json_encode($output), 200, array('content-type' => 'application/json'));
 }
 public static function toArray(InstitutionInquiry $institutionInquiry)
 {
     $data = array('id' => $institutionInquiry->getId(), 'inquirerEmail' => $institutionInquiry->getInquirerEmail(), 'inquirerName' => $institutionInquiry->getInquirerName(), 'dateCreated' => $institutionInquiry->getDateCreated(), 'country' => $institutionInquiry->getCountry(), 'institution' => InstitutionService::institutionToArray($institutionInquiry->getInstitution()));
     if ($imc = $institutionInquiry->getInstitutionMedicalCenter()) {
         $data['institutionMedicalCenter'] = InstitutionMedicalCenterService::institutionMedicalCenterToArray($imc);
     }
     return $data;
 }
 /**
  * Generate frontend uri of an institution
  * 
  * @param Mixed <Institution, array> $institution
  * @return string
  */
 public function getInstitutionFrontendUrl($institution)
 {
     if ($institution instanceof Institution) {
         $slug = $institution->getSlug();
     } else {
         $slug = $institution['slug'];
     }
     $routeName = InstitutionService::getInstitutionRouteName($institution);
     $uri = $this->router->generate($routeName, array('institutionSlug' => $slug), true);
     return $uri;
 }
 public function render_incomplete_clinic_profile(Institution $institution)
 {
     $incompleteClinics = array();
     $centers = $this->institutionService->getAllNotExpiredArchivedAndInactiveMedicalCenters($institution);
     foreach ($centers as $each) {
         $emptyFields = $this->institutionMedicalCenterService->getListOfEmptyFieldsOnInstitutionMedicalCenter($each);
         if (!empty($emptyFields)) {
             $incompleteClinics[] = array('id' => $each->getId(), 'name' => $each->getName(), 'fields' => $emptyFields, 'logo' => $each->getLogo());
         }
     }
     return $incompleteClinics;
 }
 /**
  *
  * @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 ajaxProcessInstitutionParametersAction(Request $request)
 {
     $institution = $this->get('services.institution.factory')->findById($request->get('institutionId', 0));
     if (!$institution) {
         throw $this->createNotFoundException('Cannot build metas for invalid institution');
     }
     $institutionMedicalCenter = null;
     if ($imcId = $request->get('imcId', 0)) {
         $institutionMedicalCenter = $this->get('services.institution_medical_center')->findById($imcId);
         if (!$institutionMedicalCenter || $institutionMedicalCenter->getInstitution()->getId() != $institution->getId()) {
             throw $this->createNotFoundException('Cannot build metas for invalid institution medical center');
         }
     }
     $pageMetaService = $this->get('services.helper.page_meta_configuration');
     $builderMethod = 'buildForInstitutionPage';
     $builderParameter = null;
     if ($institutionMedicalCenter) {
         // clinic page
         $url = $this->generateUrl('frontend_institutionMedicalCenter_profile', array('institutionSlug' => $institution->getSlug(), 'imcSlug' => $institutionMedicalCenter->getSlug()));
         $builderMethod = 'buildForInstitutionMedicalCenterPage';
         $builderParameter = $institutionMedicalCenter;
     } else {
         // hospital page
         $url = $this->generateUrl(InstitutionService::getInstitutionRouteName($institution), array('institutionSlug' => $institution->getSlug()));
         $builderMethod = 'buildForInstitutionPage';
         $builderParameter = $institution;
     }
     // replace app_dev.php
     if ('appDevDebugProjectContainer' == get_class($this->get('service_container'))) {
         $url = \preg_replace('/^(\\/app_dev\\.php)/', '', $url);
     }
     // build meta config if no meta config available
     if (!($metaConfig = $pageMetaService->findOneByUrl($url))) {
         $metaConfig = $pageMetaService->{$builderMethod}($builderParameter);
         $metaConfig->setUrl($url);
         $pageMetaService->save($metaConfig);
     }
     $form = $this->createForm(new PageMetaConfigurationFormType(), $metaConfig);
     $html = $this->renderView('AdminBundle:PageMetaConfiguration:form.html.twig', array('form' => $form->createView()));
     return new Response(\json_encode(array('html' => $html)), 200, array('content-type' => 'application/json'));
 }
 public function getData(Event $event)
 {
     $inquiry = $event->getSubject();
     $institution = $inquiry->getInstitution();
     $institutionMedicalCenter = $inquiry->getInstitutionMedicalCenter();
     $router = $this->container->get('router');
     if ($institutionMedicalCenter) {
         $facilityName = $institutionMedicalCenter->getName() . ' at ' . $institution->getName();
         $urlFacility = $router->generate('frontend_institutionMedicalCenter_profile', array('institutionSlug' => $institution->getSlug(), 'imcSlug' => $institutionMedicalCenter->getSlug()), true);
         $to = $institutionMedicalCenter->getContactEmail();
     } else {
         $facilityName = $institution->getName();
         $routeName = InstitutionService::getInstitutionRouteName($institution);
         $urlFacility = $router->generate($routeName, array('institutionSlug' => $institution->getSlug()), true);
     }
     if (empty($to)) {
         if (!($to = $institution->getContactEmail())) {
             $to = $this->container->get('services.institution')->getAccountOwner($institution)->getEmail();
         }
     }
     return array('inquiry' => array('name' => $inquiry->getInquirerName(), 'email' => $inquiry->getInquirerEmail(), 'message' => $inquiry->getMessage()), 'to' => $to, 'facility_name' => $facilityName, 'url' => array('facility' => $urlFacility));
 }
 private function getInstitutionFrontendUrl($institution)
 {
     $slug = $institution instanceof Institution ? $institution->getSlug() : $institution['slug'];
     $routeName = InstitutionService::getInstitutionRouteName($institution);
     return $this->router->generate($routeName, array('institutionSlug' => $slug), true);
 }
 public function reverseTransform($id)
 {
     return $this->institutionService->findById($id);
 }