/**
  * 
  * @param Treatment $currentTreatment
  * @param Treatment $oldTreatment
  */
 public function moveInstitutionTreatmentsToAnotherTreatment(Treatment $currentTreatment, Treatment $oldTreatment)
 {
     $query = "\r\n        INSERT INTO `institution_treatments` (`institution_specialization_id`, `treatment_id`)\r\n        SELECT a.institution_specialization_id, " . $currentTreatment->getId() . "\r\n        FROM  `institution_treatments` a\r\n        LEFT JOIN (SELECT  * FROM `institution_treatments` WHERE `treatment_id` = {$currentTreatment->getId()}  ) as _existing\r\n        ON _existing.`institution_specialization_id` = a.institution_specialization_id\r\n        WHERE a.treatment_id = " . $oldTreatment->getId() . "\r\n        AND _existing.`institution_specialization_id` IS NULL";
     $conn = $this->getEntityManager()->getConnection();
     $conn->executeQuery($query);
     $deleteQuery = "DELETE FROM institution_treatments WHERE treatment_id = " . $oldTreatment->getId();
     return $conn->executeQuery($deleteQuery);
 }
 public function testCreateTreatment()
 {
     $medicalCenter = $this->getDoctrine()->getRepository('TreatmentBundle:Specialization')->find(1);
     try {
         for ($i = 0; $i < 3; $i++) {
             $procedureType = new Treatment();
             $procedureType->setDateCreated(new \DateTime())->setDateModified($procedureType->getDateCreated())->setName('ProcedureTypeTestUnit ' . $i)->setDescription('this is a test description')->setSlug('ProcedureTypeTestUnit')->setStatus(1)->setSpecialization($medicalCenter);
             $procedureType = $this->service->saveTreatment($procedureType);
         }
     } catch (\Exception $e) {
         $this->getDoctrine()->resetEntityManager();
         throw $e;
     }
     $this->assertNotEmpty($procedureType);
 }
 /**
  * 
  * @PreAuthorize("hasAnyRole('SUPER_ADMIN', 'CAN_MANAGE_TREATMENT')")
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function addAction()
 {
     $params = $formActionParams = array();
     $treatment = new Treatment();
     if ($subSpecializationId = $this->getRequest()->get('subSpecializationId', 0)) {
         $subSpecialization = $this->get('services.treatment_bundle')->getSubSpecialization($subSpecializationId);
         if (!$subSpecialization) {
             throw $this->createNotFoundException("Invalid SubSpecialization.");
         }
         $treatment->setSpecialization($subSpecialization->getSpecialization());
         $treatment->addSubSpecialization($subSpecialization);
         $params['isAddFromSpecificType'] = true;
         $formActionParams['subSpecializationId'] = $subSpecializationId;
     }
     $treatmentForm = new TreatmentFormType();
     $treatmentForm->setDoctrine($this->getDoctrine());
     $form = $this->createForm($treatmentForm, $treatment);
     $params['form'] = $form->createView();
     $params['addTagForm'] = $this->createForm(new TermFormType(), new Term())->createView();
     $params['formAction'] = $this->generateUrl('admin_treatment_create', $formActionParams);
     return $this->render('AdminBundle:Treatment:form.html.twig', $params);
 }
 /**
  * 
  * @param Treatment $treatment
  * @return \HealthCareAbroad\TermBundle\Entity\Term
  */
 private function createTermFromTreatment(Treatment $treatment)
 {
     // check first if this term already exists
     $term = $this->termRepository->findOneByName($treatment->getName());
     if (!$term) {
         // term does not exist
         $term = new Term();
         $term->setName($treatment->getName());
     }
     // create new term document
     $termDocument = new TermDocument();
     $termDocument->setDocumentId($treatment->getId());
     $termDocument->setTerm($term);
     $termDocument->setType(TermDocument::TYPE_TREATMENT);
     $term->setInternal(true);
     $term->addTermDocument($termDocument);
     return $term;
 }
 /**
  * Find active search terms by Treatment
  *
  * @param Treatment $treatment
  * @return array SearchTerm
  */
 public function findByTreatment(Treatment $treatment)
 {
     $qb = $this->getQueryBuilderByDocumentIdAndType($treatment->getId(), TermDocument::TYPE_TREATMENT);
     // TODO: integrate pager here or not?
     return $qb->getQuery()->getResult();
 }
 /**
  * Get the internal Term of a Treatment
  * 
  * @param Treatment $treatment
  * @return Term
  */
 public function getTreatmentInternalTerm(Treatment $treatment)
 {
     $qb = $this->doctrine->getManager()->createQueryBuilder();
     $qb->select('t, td')->from('TermBundle:Term', 't')->innerJoin('t.termDocuments', 'td')->where('td.documentId = :treatmentId')->setParameter('treatmentId', $treatment->getId())->andWhere('td.type = :documentType')->setParameter('documentType', TermDocument::TYPE_TREATMENT)->andWhere('t.name = :treatmentName')->setParameter('treatmentName', $treatment->getName())->andWhere('t.internal = 1');
     $term = $qb->getQuery()->getOneOrNullResult();
     return $term;
 }
 /**
  * Merge $fromTreatment to $toTreatment
  * 
  * @param Treatment $fromTreatment
  * @param Treatment $toTreatment
  */
 public function mergeTreatmentToAnotherTreatment(Treatment $fromTreatment, Treatment $toTreatment)
 {
     /***
      * Steps for merge
      * 1. Move all institution_treatments of $fromTreatment to $toTreatment. Considerations:
      *      a. Consider existing institution_treatments.institution_id and institution_treatments.toTreatment combination
      * 2. Delete $fromTreatment
      */
     $connection = $this->doctrine->getConnection();
     $em = $this->doctrine->getManager();
     // step 1
     $sql = "UPDATE IGNORE `institution_treatments` inst_tr \n                SET inst_tr.`treatment_id` = :toTreatmentId\n                WHERE inst_tr.`treatment_id` = :fromTreatmentId";
     $statement = $connection->prepare($sql);
     $statement->bindValue('fromTreatmentId', $fromTreatment->getId());
     $statement->bindValue('toTreatmentId', $toTreatment->getId());
     $statement->execute();
     // remove the remaining institutions $fromTreatment with existing $toTreatment that were left out from the above operation
     $sql = "DELETE FROM `institution_treatments` WHERE `treatment_id` = :fromTreatmentId";
     $statement = $connection->prepare($sql);
     $statement->bindValue('fromTreatmentId', $fromTreatment->getId());
     $statement->execute();
     // step 2
     // remove $fromTreatment
     $em->remove($fromTreatment);
     $em->flush();
 }
 public function get_treatment_url(Treatment $treatment)
 {
     return $this->generator->generate('frontend_search_results_treatments', array('specialization' => $treatment->getSpecialization()->getSlug(), 'treatment' => $treatment->getSlug()), true);
 }