public function setupDoctorsAction(Request $request)
 {
     //TODO: check institution signupStepStatus
     $doctor = new Doctor();
     $doctor->addInstitutionMedicalCenter($this->institutionMedicalCenter);
     $form = $this->createForm(new InstitutionMedicalCenterDoctorFormType(), $doctor);
     $doctors = $this->getDoctrine()->getRepository('DoctorBundle:Doctor')->findByInstitutionMedicalCenter($this->institutionMedicalCenter->getId(), Query::HYDRATE_OBJECT);
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $doctor = $form->getData();
             $doctor->setStatus(Doctor::STATUS_ACTIVE);
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($doctor);
             $em->flush($doctor);
             $data = array('status' => true, 'message' => 'Doctor has been added to your clinic!', 'doctor' => $this->get('services.doctor')->toArrayDoctor($doctor), 'editDoctorUrl' => $this->generateUrl('institution_medicalCenter_ajaxUpdateDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())), 'removeDoctorUrl' => $this->generateUrl('institution_medicalCenter_removeDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())), 'uploadLogoUrl' => $this->generateUrl('institution_doctor_logo_upload', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())));
         } else {
             $data = array('status' => false, 'message' => $form->getErrorsAsString());
         }
         return new Response(json_encode($data), 200, array('Content-Type' => 'application/json'));
     }
     $params = array('doctorForm' => $form->createView(), 'institution' => $this->institution, 'institutionMedicalCenter' => $this->institutionMedicalCenter, 'thumbnailSize' => ImageSizes::DOCTOR_LOGO, 'doctors' => $this->get('services.doctor')->doctorsObjectToArray($doctors));
     $editDoctor = new Doctor();
     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);
     $params['editDoctorForm'] = $editDoctorForm->createView();
     return $this->render('InstitutionBundle:SignUp:setupDoctors.html.twig', $params);
 }
 /**
  * Action page for Institution Profile Page
  *
  * @param Request $request
  */
 public function profileAction(Request $request)
 {
     $medicalProviderGroup = $this->getDoctrine()->getRepository('InstitutionBundle:MedicalProviderGroup')->getActiveMedicalGroups();
     $medicalProviderGroupArr = array();
     foreach ($medicalProviderGroup as $e) {
         $medicalProviderGroupArr[] = array('value' => $e->getName(), 'id' => $e->getId());
     }
     $this->get('services.contact_detail')->initializeContactDetails($this->institution, array(ContactDetailTypes::PHONE), $this->institution->getCountry());
     $form = $this->createForm(new InstitutionProfileFormType(), $this->institution, array(InstitutionProfileFormType::OPTION_BUBBLE_ALL_ERRORS => false));
     $currentGlobalAwards = $this->get('services.institution_property')->getGlobalAwardPropertiesByInstitution($this->institution);
     $editGlobalAwardForm = $this->createForm(new InstitutionGlobalAwardFormType());
     $params = array('institutionForm' => $form->createView(), 'institutionPhotos' => $this->get('services.institution.gallery')->getInstitutionPhotos($this->institution->getId()), 'currentGlobalAwards' => $currentGlobalAwards, 'editGlobalAwardForm' => $editGlobalAwardForm->createView(), 'medicalProvidersJSON' => \json_encode($medicalProviderGroupArr), 'ancillaryServicesData' => $this->get('services.helper.ancillary_service')->getActiveAncillaryServices());
     if ($this->isSingleCenter) {
         $doctor = new Doctor();
         $doctor->addInstitutionMedicalCenter($this->institutionMedicalCenter);
         $doctorForm = $this->createForm(new InstitutionMedicalCenterDoctorFormType(), $doctor);
         $editDoctor = new 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);
         $institutionMedicalCenterForm = $this->createForm(new InstitutionMedicalCenterFormType($this->institution), $this->institutionMedicalCenter, array(InstitutionMedicalCenterFormType::OPTION_BUBBLE_ALL_ERRORS => false));
         $params['editDoctorForm'] = $editDoctorForm->createView();
         $params['institutionMedicalCenter'] = $this->institutionMedicalCenter;
         $params['institutionMedicalCenterForm'] = $institutionMedicalCenterForm->createView();
         $params['commonDeleteForm'] = $this->createForm(new CommonDeleteFormType())->createView();
         $params['specializations'] = $this->getDoctrine()->getRepository('InstitutionBundle:InstitutionSpecialization')->getActiveSpecializationsByInstitutionMedicalCenter($this->institutionMedicalCenter);
         $params['doctors'] = $this->get('services.doctor')->doctorsObjectToArray($this->institutionMedicalCenter->getDoctors());
         $params['doctorForm'] = $doctorForm->createView();
     }
     return $this->render('InstitutionBundle:Institution:profile.html.twig', $params);
 }
 /**
  * Modified for new markup in adding specialist in clinic profile doctors tab
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function addDoctorAction(Request $request)
 {
     $doctor = new Doctor();
     $doctor->addInstitutionMedicalCenter($this->institutionMedicalCenter);
     $form = $this->createForm(new InstitutionMedicalCenterDoctorFormType(), $doctor);
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $doctor = $form->getData();
             $doctor->setStatus(Doctor::STATUS_ACTIVE);
             $em = $this->getDoctrine()->getEntityManager();
             $em->persist($doctor);
             $em->flush($doctor);
             // 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()));
             $data = array('status' => true, 'message' => 'Doctor has been added to your clinic!', 'doctor' => $this->get('services.doctor')->toArrayDoctor($doctor), 'editDoctorUrl' => $this->generateUrl('institution_medicalCenter_ajaxUpdateDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())), 'removeDoctorUrl' => $this->generateUrl('institution_medicalCenter_removeDoctor', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())), 'uploadLogoUrl' => $this->generateUrl('institution_doctor_logo_upload', array('imcId' => $this->institutionMedicalCenter->getId(), 'doctorId' => $doctor->getId())));
         } else {
             $data = array('status' => false, 'message' => $form->getErrorsAsString());
         }
     }
     return new Response(json_encode($data), 200, array('Content-Type' => 'application/json'));
 }