/**
  * Create all diagnosis fields not already set.
  *
  * @param FormEvent $event
  */
 public function buildForm(FormEvent $event)
 {
     $regimen = $event->getData();
     if ($regimen->getId()) {
         $event->getForm()->remove('patient');
     }
     $config = $event->getForm()->get('activities')->getConfig();
     $type = $config->getType()->getName();
     $options = $config->getOptions();
     $qb = $options['options']['query_builder'] = $this->activityRepository->getQueryBuilder();
     // If no diagnosis is present, look for patient.
     if (null === $regimen || null === $regimen->getDiagnosis()) {
         if (null === $regimen->getPatient()) {
             $qb->andWhere('activity.patient IS NULL');
             $qb->andWhere('activity.diagnosis IS NULL');
         } else {
             $qb->andWhere('activity.patient = :patient');
             $qb->andWhere('activity.diagnosis IS NULL');
             $qb->setParameter(':patient', $regimen->getPatient());
         }
     } else {
         $qb->resetDQLPart('where')->where('activity.diagnosis = :diagnosis')->setParameter(':diagnosis', $regimen->getDiagnosis());
     }
     if (($startDate = $regimen->getStartDate()) instanceof DateTime) {
         $qb->andWhere('activity.activityDate >= :startDate')->setParameter(':startDate', $startDate);
     }
     if (($endDate = $regimen->getEndDate()) instanceof DateTime) {
         $qb->andWhere('activity.activityDate <= :endDate')->setParameter(':endDate', $endDate);
     }
     $event->getForm()->add('activities', $type, $options);
 }
 /**
  * Constructor.
  *
  * @param PatientRepositoryInterface $patientRepository
  * @param DiagnosisRepositoryInterface $diagnosisRepository
  * @param ActivityRepositoryInterface $activityRepository
  */
 public function __construct(PatientRepositoryInterface $patientRepository, DiagnosisRepositoryInterface $diagnosisRepository, ActivityRepositoryInterface $activityRepository)
 {
     $this->patientClass = $patientRepository->getClassName();
     $this->patientRepository = $patientRepository;
     $this->diagnosisClass = $diagnosisRepository->getClassName();
     $this->diagnosisRepository = $diagnosisRepository;
     $this->activityClass = $activityRepository->getClassName();
     $this->activityRepository = $activityRepository;
 }
 /**
  * Constructor.
  *
  * @param ActivityRepositoryInterface $activityRepository
  */
 public function __construct(ActivityRepositoryInterface $activityRepository)
 {
     $this->dataClass = $activityRepository->getClassName();
     $this->activityRepository = $activityRepository;
 }