public function ajaxAddMedicalSpecializationTreatmentsAction(Request $request)
 {
     if ($request->isMethod('POST')) {
         $submittedSpecializations = $request->get(InstitutionSpecializationFormType::NAME);
         $em = $this->getDoctrine()->getEntityManager();
         $errors = array();
         $output = array('html' => '');
         if (\count($submittedSpecializations) > 0) {
             foreach ($submittedSpecializations as $_isId => $_data) {
                 // set passed treatments as choices
                 $default_choices = array();
                 if (!empty($_data['treatments'])) {
                     $_treatment_choices = $this->get('services.treatment_bundle')->findTreatmentsByIds($_data['treatments']);
                     foreach ($_treatment_choices as $_t) {
                         $default_choices[$_t->getId()] = $_t->getName();
                         // add the treatment
                         $this->institutionSpecialization->addTreatment($_t);
                     }
                     $form = $this->createForm(new InstitutionSpecializationFormType(), $this->institutionSpecialization, array('default_choices' => $default_choices));
                     $form->bind($_data);
                     if ($form->isValid()) {
                         $em->persist($this->institutionSpecialization);
                         $em->flush();
                         // Invalidate InstitutionMedicalCenter Profile cache
                         $institutionMedicalCenter = $this->institutionSpecialization->getInstitutionMedicalCenter();
                         $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionMedicalCenterProfileKey($institutionMedicalCenter->getId()));
                         // Invalidate Institution Profile cache
                         $this->get('services.memcache')->delete(FrontendMemcacheKeysHelper::generateInsitutionProfileKey($institutionMedicalCenter->getInstitution()->getId()));
                         $output['html'] = $this->renderView('AdminBundle:InstitutionSpecialization:list.institutionTreatments.html.twig', array('institutionSpecialization' => $this->institutionSpecialization, 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'institution' => $this->institution));
                         $response = new Response(\json_encode($output), 200, array('content-type' => 'application/json'));
                     }
                 } else {
                     $response = new Response('Errors: No treatment selected', 400);
                 }
             }
         } else {
             $response = new Response('Errors: No specialization selected', 400);
         }
     } else {
         $form = $this->createForm(new InstitutionSpecializationFormType(), new InstitutionSpecialization());
         $specialization = $this->institutionSpecialization->getSpecialization();
         $availableTreatments = $this->get('services.institution_medical_center')->getAvailableTreatmentsByInstitutionSpecialization($this->institutionSpecialization);
         $html = $this->renderView('AdminBundle:Widgets:modalEditSpecializationForm.html.twig', array('availableTreatments' => $availableTreatments, 'form' => $form->createView(), 'formName' => InstitutionSpecializationFormType::NAME, 'specialization' => $specialization, 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'institutionSpecialization' => $this->institutionSpecialization, 'institution' => $this->institution));
         $response = new Response(\json_encode(array('html' => $html)));
     }
     return $response;
 }