public function preExecute()
 {
     $this->repository = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionMedicalCenter');
     $this->service = $this->get('services.institution_medical_center');
     if ($imcId = $this->getRequest()->get('imcId', 0)) {
         $this->institutionMedicalCenter = $this->repository->find($imcId);
         // non-existent medical center group
         if (!$this->institutionMedicalCenter) {
             if ($this->getRequest()->isXmlHttpRequest()) {
                 throw $this->createNotFoundException('Invalid medical center.');
             } else {
                 return $this->_redirectIndexWithFlashMessage('Invalid medical center.', 'error');
             }
         }
         // medical center group does not belong to this institution
         if ($this->institutionMedicalCenter->getInstitution()->getId() != $this->institution->getId()) {
             return $this->_redirectIndexWithFlashMessage('Invalid medical center.', 'error');
         }
     }
 }
 public function preExecute()
 {
     parent::preExecute();
     $this->repository = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionMedicalCenter');
     $this->service = $this->get('services.institution_medical_center');
     // Temporary condition for eagerLoad
     if ($imcId = $this->getRequest()->get('imcId', 0)) {
         if ($this->getRequest()->attributes->get('_route') == 'institution_medicalCenter_view') {
             $this->institutionMedicalCenter = $this->service->findById($imcId, array('logo' => 'a.logo', 'contactDetails' => 'a.contactDetails', 'businessHours' => 'a.businessHours', 'specializations' => 'a.institutionSpecializations'));
             if ($this->institutionMedicalCenter->getInstitution()->getId() != $this->institution->getId()) {
                 return $this->_redirectIndexWithFlashMessage('Invalid medical center.', 'error');
             }
         } else {
             $this->institutionMedicalCenter = $this->repository->find($imcId);
         }
         if (!$this->institutionMedicalCenter) {
             if ($this->getRequest()->isXmlHttpRequest()) {
                 throw $this->createNotFoundException('Invalid medical center.');
             } else {
                 return $this->_redirectIndexWithFlashMessage('Invalid medical center.', 'error');
             }
         }
     }
 }