/**
  * Converts record array into actual target entity.
  *
  * @param ImportEvent $event
  */
 public function convert(ImportEvent $event)
 {
     $importer = $event->getImporter();
     if (!('sample' == $importer->getSubject() && 'cpd_genetic_results' == $importer->getName())) {
         return;
     }
     $records = $event->getRecords();
     $repo = $event->getTarget()->getRepository();
     $prototype = $this->prototypeProvider->getPrototypeByName('genetic-results');
     $fields['cpd-id'] = $prototype->getFieldByName('genetic-results-cpd-id');
     $fields['gene-id'] = $prototype->getFieldByName('genetic-results-gene-id');
     $fields['gene'] = $prototype->getFieldByName('genetic-results-gene');
     $fields['variant-detected'] = $prototype->getFieldByName('genetic-results-variant-detected');
     $fields['variant-categorization'] = $prototype->getFieldByName('genetic-results-variant-categorization');
     $fields['cdna-change'] = $prototype->getFieldByName('genetic-results-cdna-change');
     $fields['mutation-type-cdna'] = $prototype->getFieldByName('genetic-results-mutation-type-cdna');
     $fields['mutation-type-protein'] = $prototype->getFieldByName('genetic-results-mutation-type-protein');
     $fields['variant-alias'] = $prototype->getFieldByName('genetic-results-variant-alias');
     $fields['genetic-test-version-id'] = $prototype->getFieldByName('genetic-results-genetic-test-version-id');
     $fields['transcript-id'] = $prototype->getFieldByName('genetic-results-transcript-id');
     $fields['position'] = $prototype->getFieldByName('genetic-results-position');
     $fields['genotype'] = $prototype->getFieldByName('genetic-results-genotype');
     $fields['fdp'] = $prototype->getFieldByName('genetic-results-fdp');
     $fields['frd'] = $prototype->getFieldByName('genetic-results-frd');
     $fields['fad'] = $prototype->getFieldByName('genetic-results-fad');
     $fields['faf'] = $prototype->getFieldByName('genetic-results-faf');
     $fields['exon-id'] = $prototype->getFieldByName('genetic-results-exon-id');
     $fields['exon'] = $prototype->getFieldByName('genetic-results-exon');
     $sources = array();
     foreach ($records as $key => $record) {
         $source = new Source();
         $source->setPatient($record['patient']);
         $source->setSourceDate($record['activity_date']);
         $source->setAmount(1);
         $sample = new Sample();
         $sample->setPrototype($prototype);
         $sample->setPatient($record['patient']);
         $source->addSample($sample);
         if (array_key_exists('diagnosis', $record)) {
             $sample->setDiagnosis($record['diagnosis']);
         }
         foreach ($fields as $key => $field) {
             $fieldValue = new FieldValue();
             $fieldValue->setField($field);
             $fieldValue->setValue($record[str_replace('genetic_results_', '', str_replace('-', '_', $field->getName()))]);
             $sample->addField($fieldValue);
         }
         $sources[$record['pk_id']] = $source;
         unset($records[$key]);
     }
     $event->setRecords($sources);
 }
 /**
  * Converts record array into actual target entity.
  *
  * @param ImportEvent $event
  */
 public function convert(ImportEvent $event)
 {
     $importer = $event->getImporter();
     if (!('sample' === $importer->getSubject() && 'hmtb_specimens_collection' === $importer->getName())) {
         return;
     }
     $records = $event->getRecords();
     $repo = $event->getTarget()->getRepository();
     $prototype = $this->prototypeProvider->getPrototypeByName('specimen-collection');
     $fields['sample-type'] = $prototype->getFieldByName('hmtb-sample-type');
     $fields['restricted'] = $prototype->getFieldByName('hmtb-restricted');
     $fields['subtype'] = $prototype->getFieldByName('hmtb-subtype');
     $fields['total-sum-vials-remaining'] = $prototype->getFieldByName('hmtb-total-sum-vials-remaining');
     $fields['blasts'] = $prototype->getFieldByName('hmtb-blasts');
     $fields['ct-cyle'] = $prototype->getFieldByName('hmtb-ct-cycle');
     $fields['ct-study-day'] = $prototype->getFieldByName('hmtb-ct-study-day');
     $fields['ct-peak-through'] = $prototype->getFieldByName('hmtb-ct-peak-through');
     $fields['ct-time-post-drug'] = $prototype->getFieldByName('hmtb-ct-time-post-drug');
     $fields['ct-time-post-drug-unit'] = $prototype->getFieldByName('hmtb-ct-time-post-drug-unit');
     $fields['ct-treatment-relation-time'] = $prototype->getFieldByName('hmtb-ct-treatment-relation-time');
     $fields['when-modified'] = $prototype->getFieldByName('hmtb-when-modified');
     $sources = array();
     foreach ($records as $key => $record) {
         $source = new Source();
         $source->setPatient($record['patient']);
         $source->setSourceDate($record['activity_date']);
         $source->setAmount(1);
         $sample = new Sample();
         $sample->setPrototype($prototype);
         $sample->setAmount(1);
         $sample->setPatient($record['patient']);
         $source->addSample($sample);
         foreach ($fields as $key => $field) {
             if (method_exists($field, 'getName')) {
                 $fieldValue = new FieldValue();
                 $fieldValue->setField($field);
                 $fieldValue->setSample($sample);
                 $fieldValue->setValue($record[str_replace('hmtb_', '', str_replace('-', '_', $field->getName()))]);
                 $sources[$record['identifier'] . $field->getName()] = $fieldValue;
             }
         }
         $sources[$record['identifier']] = $source;
         unset($records[$key]);
     }
     $event->setRecords($sources);
 }