/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { // $caseClosed = CaseClosed::findOrFail($id); $POrecord = $caseClosed->POrecord; $project_id = $POrecord->project->id; $customersJoinQuery = DB::table('customers')->select(DB::raw('id AS c_id'), 'institute', 'department', 'c_name'); $usersJoinQuery = DB::table('users')->select(DB::raw('id AS u_id'), 'name'); $project = DB::table('projects')->leftJoin(DB::raw('(' . $customersJoinQuery->toSql() . ') i'), function ($join) { $join->on('projects.Customer_id', '=', 'i.c_id'); })->leftJoin(DB::raw('(' . $usersJoinQuery->toSql() . ') j'), function ($join) { $join->on('projects.salesman', '=', 'u_id'); })->where('projects.id', $project_id)->first(); $labmans = DB::table('users')->select('id', 'name')->get(); $user = User::find(\Auth::id()); $qualityControl = QualityControl::where('POrecord_id', '=', $POrecord->id)->first(); if ($qualityControl->QCtype == 'DNA') { $qcReportUrl = url('research/ngs/qualityControl/dnareport') . '/' . $qualityControl->id; } elseif ($qualityControl->QCtype == 'RNA') { $qcReportUrl = url('research/ngs/qualityControl/rnareport') . '/' . $qualityControl->id; } $library = Library::where('POrecord_id', '=', $POrecord->id)->first(); $libraryReportUrl = url('research/ngs/library/report') . '/' . $library->id; return view('research.caseClosed.edit')->with('user', $user)->with('project', $project)->with('labmans', $labmans)->with('POrecord', $POrecord)->with('qcReportUrl', $qcReportUrl)->with('libraryReportUrl', $libraryReportUrl)->with('caseClosed', $caseClosed); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { // $rules = ['QCtype' => 'required', 'operatorDate' => 'required|before:tomorrow', 'measureTool' => 'required', 'fragmentSize' => 'required', 'operator' => 'required', 'figure_1_Path' => 'image', 'figure_2_Path' => 'image', 'figure_3_Path' => 'image', 'figure_4_Path' => 'image', 'figure_nanodrop_Path' => 'image']; $validator = Validator::make($request->all(), $rules); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); } $na_flag = 0; foreach ($request->get('measureTool') as &$tool) { if ($tool == 'N/A') { $na_flag = 1; } if (empty($measureTools)) { $measureTools = $tool; } else { $measureTools = $measureTools . "|" . $tool; } } if ($na_flag == 1 && count($request->get('measureTool')) > 1) { return back()->withErrors(['measureTool' => 'measureTool can not choose N/A with other option.'])->withInput(); } if ($request->get('QCtype') == 'DNA') { $qualityControl = new QualityControl(array('QCtype' => $request->get('QCtype'), 'operatorDate' => $request->get('operatorDate'), 'measureTool' => $measureTools, 'fragmentSize' => $request->get('fragmentSize'), 'measureNote' => $request->get('measureNote'), 'reportDescription' => $request->get('reportDescription'), 'note' => $request->get('note'), 'operator' => $request->get('operator'))); } elseif ($request->get('QCtype') == 'RNA') { if (empty($request->get('is_differentMethods'))) { $is_differentMethods = ''; } else { $is_differentMethods = $request->get('is_differentMethods'); } if (empty($request->get('is_interpretation'))) { $is_interpretation = ''; } else { $is_interpretation = $request->get('is_interpretation'); } $qualityControl = new QualityControl(array('QCtype' => $request->get('QCtype'), 'operatorDate' => $request->get('operatorDate'), 'measureTool' => $measureTools, 'fragmentSize' => $request->get('fragmentSize'), 'measureNote' => $request->get('measureNote'), 'rin_28S18S_measure' => $request->get('rin_28S18S_measure'), 'is_differentMethods' => $is_differentMethods, 'is_interpretation' => $is_interpretation, 'reportDescription' => $request->get('reportDescription'), 'note' => $request->get('note'), 'operator' => $request->get('operator'))); } $operator = User::findOrFail($request->get('operator')); $qualityControl->operator()->associate($operator); $POrecord = POcase::findOrFail($request->get('POrecord_id')); $POrecord->status = 'QualityControl'; $POrecord->save(); $qualityControl->POrecord()->associate($POrecord); $qualityControl->save(); if (empty($request->file('figure_1_Path'))) { $figure_1_Path = null; } else { $fileName_1 = $qualityControl->id . '_1.' . $request->file('figure_1_Path')->getClientOriginalExtension(); $request->file('figure_1_Path')->move(base_path() . '/storeFiles/ngs/qualityControl/', $fileName_1); $figure_1_Path = base_path() . '/storeFiles/ngs/qualityControl/' . $fileName_1; } if (empty($request->file('figure_2_Path'))) { $figure_2_Path = null; } else { $fileName_2 = $qualityControl->id . '_2.' . $request->file('figure_2_Path')->getClientOriginalExtension(); $request->file('figure_2_Path')->move(base_path() . '/storeFiles/ngs/qualityControl/', $fileName_2); $figure_2_Path = base_path() . '/storeFiles/ngs/qualityControl/' . $fileName_2; } if (empty($request->file('figure_3_Path'))) { $figure_3_Path = null; } else { $fileName_3 = $qualityControl->id . '_3.' . $request->file('figure_3_Path')->getClientOriginalExtension(); $request->file('figure_3_Path')->move(base_path() . '/storeFiles/ngs/qualityControl/', $fileName_3); $figure_3_Path = base_path() . '/storeFiles/ngs/qualityControl/' . $fileName_3; } if (empty($request->file('figure_4_Path'))) { $figure_4_Path = null; } else { $fileName_4 = $qualityControl->id . '_4.' . $request->file('figure_4_Path')->getClientOriginalExtension(); $request->file('figure_4_Path')->move(base_path() . '/storeFiles/ngs/qualityControl/', $fileName_4); $figure_4_Path = base_path() . '/storeFiles/ngs/qualityControl/' . $fileName_4; } if (empty($request->file('figure_nanodrop_Path'))) { $figure_nanodrop_Path = null; } else { $fileName_nanodrop = $qualityControl->id . '_nanodrop.' . $request->file('figure_nanodrop_Path')->getClientOriginalExtension(); $request->file('figure_nanodrop_Path')->move(base_path() . '/storeFiles/ngs/qualityControl/', $fileName_nanodrop); $figure_nanodrop_Path = base_path() . '/storeFiles/ngs/qualityControl/' . $fileName_nanodrop; } $qualityControl->update(['figure_1_Path' => $figure_1_Path, 'figure_2_Path' => $figure_2_Path, 'figure_3_Path' => $figure_3_Path, 'figure_4_Path' => $figure_4_Path, 'figure_nanodrop_Path' => $figure_nanodrop_Path]); if (!empty($request->get('sampleName'))) { $sampleName = $request->get('sampleName'); $vol_ul = $request->get('vol_ul'); $conc_ng = $request->get('conc_ng'); $qty_ng = $request->get('qty_ng'); $_260_280 = $request->get('260_280'); $_260_230 = $request->get('260_230'); $_28S_18S = $request->get('28S_18S'); $rin = $request->get('rin'); $lane = $request->get('lane'); $comment = $request->get('comment'); $is_buildLibrary = $request->get('is_buildLibrary'); $figure_Path = $request->file('figure_Path'); $max = 0; $indexs = array_keys($sampleName); foreach ($indexs as $index) { if ($index > $max) { $max = $index; } } for ($i = 1; $i <= $max; $i++) { if (!empty($sampleName[$i])) { if ($request->get('QCtype') == 'DNA') { $QC_Samples = new QC_Samples(array('sampleName' => $sampleName[$i], 'vol_ul' => $vol_ul[$i], 'conc_ng' => $conc_ng[$i], 'qty_ng' => $qty_ng[$i], '260_280' => $_260_280[$i], '260_230' => $_260_230[$i], 'lane' => $lane[$i], 'comment' => $comment[$i], 'is_buildLibrary' => $is_buildLibrary[$i], 'operator_id' => $request->get('operator'))); } elseif ($request->get('QCtype') == 'RNA') { $QC_Samples = new QC_Samples(array('sampleName' => $sampleName[$i], 'vol_ul' => $vol_ul[$i], 'conc_ng' => $conc_ng[$i], 'qty_ng' => $qty_ng[$i], '260_280' => $_260_280[$i], '260_230' => $_260_230[$i], '28S_18S' => $_28S_18S[$i], 'rin' => $rin[$i], 'lane' => $lane[$i], 'comment' => $comment[$i], 'is_buildLibrary' => $is_buildLibrary[$i], 'operator_id' => $request->get('operator'))); } $QC_Samples->qualityControl()->associate($qualityControl); $QC_Samples->operator()->associate($operator); $user = \Auth::user(); $QC_Samples->creater()->associate($user); $QC_Samples->save(); $images = glob(base_path() . '/storeFiles/ngs/tmpImage' . \Auth::id() . '/' . $i . '/' . '{*.gif,*.jpg,*.png}', GLOB_BRACE); if (empty($images[0])) { $figure_Path = null; } else { if (preg_match("/\\.(.+)/", $images[0], $matches)) { // Valid match $fileExtesion = $matches[1]; } $fileName = $QC_Samples->id . '.' . $fileExtesion; $flag = \File::move($images[0], base_path() . '/storeFiles/ngs/QC_Samples/' . $fileName); $figure_Path = base_path() . '/storeFiles/ngs/QC_Samples/' . $fileName; } if (!empty($figure_Path)) { $QC_Samples->update(['figure_Path' => $figure_Path]); } } } } return \Redirect::to('research/ngs/projects/show/' . $POrecord->project->id)->with('message', 'Your Quality Control has been created!'); }