/**
  * Ajax handler for adding existing doctor to an InstitutionMedicalCenter
  * Expected parameters:
  *     - imcId institutionMedicalCenterId
  *     - doctorId
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function addExistingDoctorAction(Request $request)
 {
     $result = array('status' => false);
     $doctor = $this->getDoctrine()->getRepository('DoctorBundle:Doctor')->find($request->get('doctorId', 0));
     if (!$doctor) {
         $result['message'] = 'Invalid doctor.';
     }
     try {
         $this->institutionMedicalCenter->addDoctor($doctor);
         $this->service->save($this->institutionMedicalCenter);
         $result['status'] = true;
         $result['doctor'] = $this->get('services.doctor')->toArrayDoctor($doctor);
         $result['editDoctorUrl'] = $this->generateUrl('institution_medicalCenter_ajaxUpdateDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId()));
         $result['removeDoctorUrl'] = $this->generateUrl('institution_medicalCenter_removeDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId()));
         $result['uploadLogoUrl'] = $this->generateUrl('institution_doctor_logo_upload', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId()));
         // 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()));
     } catch (\Exception $e) {
     }
     return new Response(\json_encode($result), 200, array('content-type' => 'application/json'));
 }