/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $run = Run::where('id', $id)->first(); // query selects batch name, date, charge code, user and project for run having status updated. // smaller return than eloquent query were only small sub set of data required. $batches = DB::table('batches')->join('samples', function ($join) { $join->on('batches.id', '=', 'samples.batch_id'); })->join('sample_runs', function ($join) { $join->on('sample_runs.sample_id', '=', 'samples.id'); })->join('users', function ($join) { $join->on('batches.user_id', '=', 'users.id'); })->join('project_group', function ($join) { $join->on('batches.project_group_id', '=', 'project_group.id'); })->where('sample_runs.run_id', '=', $run->id)->distinct('batches.id')->select('batches.id', 'batch_name', 'batches.created_at', 'batches.charge_code', 'users.name', 'project_group.name as project')->get(); $status_options = Run_status::lists('status', 'id'); return view('runs.edit', ['run' => $run, 'status_options' => $status_options, 'batches' => $batches]); }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $this->middleware('super'); $batch_ids = Session::get('run_batch_ids'); $batches = Batch::whereIn('id', $batch_ids)->get(); $countProjectSamples = array(); // initialise array to count number samples with runs remaining in each project group foreach ($batches as $batch) { $countProjectSamples[$batch->project_group_id] = 0; } // count number samples with runs remaining in each selected batch foreach ($batches as $batch) { $count = 0; foreach ($batch->samples as $sample) { if ($sample->runs_remaining > 0) { $count++; } } $countProjectSamples[$batch->project_group_id] += $count; } // most common project is one with highest count of samples with runs remaining // this will be the automatically selected project to set for the run $mostCommonProject = array_keys($countProjectSamples, max($countProjectSamples)); // create list of dates so run can be scheduled up to 7 days in the future $dates = array('0' => Carbon::now()->format('d-M-Y'), '1' => Carbon::now()->addDays(1)->format('d-M-Y'), '2' => Carbon::now()->addDays(2)->format('d-M-Y'), '3' => Carbon::now()->addDays(3)->format('d-M-Y'), '4' => Carbon::now()->addDays(4)->format('d-M-Y'), '5' => Carbon::now()->addDays(5)->format('d-M-Y'), '6' => Carbon::now()->addDays(6)->format('d-M-Y'), '7' => Carbon::now()->addDays(7)->format('d-M-Y')); // for each database list find which is the default to be set in list $default_chemistry = DB::table('chemistry')->where('default', 1)->first(); $default_adaptor = DB::table('adaptor')->where('default', 1)->first(); $default_iem_file_version = DB::table('iem_file_version')->where('default', 1)->first(); $default_application = DB::table('application')->where('default', 1)->first(); $default_assay = DB::table('assay')->where('default', 1)->first(); $default_work_flow = DB::table('work_flow')->where('default', 1)->first(); $default_run_status = DB::table('run_status')->where('default', 1)->first(); // pass the selected batches and list to view to get the run header fiels to save return view('sampleRuns.createRunDetails', ['batch_ids' => $batch_ids, 'batches' => $batches, 'adaptor' => Adaptor::lists('value', 'id'), 'iem_file_version' => Iem_file_version::lists('file_version', 'id'), 'application' => Application::lists('application', 'id'), 'chemistry' => Chemistry::lists('chemistry', 'id'), 'run_status' => Run_status::lists('status', 'id'), 'instrument' => Instrument::lists('name', 'id'), 'work_flow' => Work_flow::lists('value', 'id'), 'assay' => Assay::lists('name', 'id'), 'run_date' => $dates, 'sampleRun' => SampleRun::lists('run_id', 'sample_id'), 'projectGroup' => ProjectGroup::lists('name', 'id'), 'default_chemistry_id' => $default_chemistry->id, 'default_adaptor_id' => $default_adaptor->id, 'default_iem_file_version_id' => $default_iem_file_version->id, 'default_application_id' => $default_application->id, 'default_assay_id' => $default_assay->id, 'default_work_flow_id' => $default_work_flow->id, 'default_run_status_id' => $default_run_status->id, 'default_project_id' => $mostCommonProject[0]]); }