/**
  * Save Specializations for Clinics Profile
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function saveSpecializationsAction(Request $request)
 {
     //Multiple centers of an institution with similar specializations are now allowed.
     //$specializations = $this->get('services.institution_specialization')->getNotSelectedSpecializations($this->institution);
     $specializations = $this->get('services.institution_specialization')->getNotSelectedSpecializationsOfInstitutionMedicalCenter($this->institutionMedicalCenter);
     if ($request->isMethod('POST')) {
         $specializationsWithTreatments = $request->get(InstitutionSpecializationFormType::NAME);
         if (\count($specializationsWithTreatments)) {
             $isIds = $this->get('services.institution_medical_center')->addMedicalCenterSpecializationsWithTreatments($this->institutionMedicalCenter, $specializationsWithTreatments);
             if (!empty($isIds)) {
                 foreach ($this->institutionMedicalCenter->getInstitutionSpecializations() as $institutionSpecialization) {
                     if (in_array($institutionSpecialization->getId(), $isIds)) {
                         $html['html'][] = $this->renderView('InstitutionBundle:MedicalCenter:listItem.institutionSpecializationTreatments.html.twig', array('each' => $institutionSpecialization, 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'commonDeleteForm' => $this->createForm(new CommonDeleteFormType())->createView()));
                     }
                 }
                 // Invalidate InstitutionMedicalCenterProfile memcache
                 $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($this->institutionMedicalCenter->getId()));
                 // Invalidate InstitutionProfile memcache
                 $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($this->institutionMedicalCenter->getInstitution()->getId()));
                 $response = new Response(\json_encode($html), 200, array('content-type' => 'application/json'));
             }
         } else {
             $response = new Response('Please select at least one treatment.', 400);
         }
     }
     return $response;
 }
 /**
  * Profile page of a medical center
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function viewAction(Request $request)
 {
     $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));
     $currentGlobalAwards = $this->get('services.institution_medical_center_property')->getGlobalAwardPropertiesByInstitutionMedicalCenter($this->institutionMedicalCenter);
     $editGlobalAwardForm = $this->createForm(new InstitutionGlobalAwardFormType());
     // Doctors
     $editDoctor = $doctor = new Doctor();
     $doctor->addInstitutionMedicalCenter($this->institutionMedicalCenter);
     $doctorForm = $this->createForm(new InstitutionMedicalCenterDoctorFormType(), $doctor);
     $doctors = $this->getDoctrine()->getRepository('DoctorBundle:Doctor')->findByInstitutionMedicalCenter($this->institutionMedicalCenter->getId(), Query::HYDRATE_OBJECT);
     if (!empty($doctors)) {
         $editDoctor = $doctors[0];
     }
     $this->get('services.contact_detail')->initializeContactDetails($editDoctor, array(ContactDetailTypes::PHONE), $this->institution->getCountry());
     $editDoctorForm = $this->createForm(new InstitutionMedicalCenterDoctorFormType('editInstitutionMedicalCenterDoctorForm'), $editDoctor);
     return $this->render('InstitutionBundle:MedicalCenter:view.html.twig', array('institutionMedicalCenterForm' => $form->createView(), 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'medicalCenterPhotos' => $this->get('services.institution.gallery')->getInstitutionMedicalCenterPhotos($this->institutionMedicalCenter->getId()), 'specializations' => $this->institutionMedicalCenter->getInstitutionSpecializations(), 'ancillaryServicesData' => $this->get('services.helper.ancillary_service')->getActiveAncillaryServices(), 'commonDeleteForm' => $this->createForm(new CommonDeleteFormType())->createView(), 'currentGlobalAwards' => $currentGlobalAwards, 'editGlobalAwardForm' => $editGlobalAwardForm->createView(), 'doctors' => $this->get('services.doctor')->doctorsObjectToArray($doctors), 'doctorForm' => $doctorForm->createView(), 'editDoctorForm' => $editDoctorForm->createView()));
 }