mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 00:51:05 +03:30
150 lines
6.0 KiB
PHP
150 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Http\Requests\StoreTestResultRequest;
|
|
use App\TestResult;
|
|
use App\InputValue;
|
|
use App\Input;
|
|
|
|
class TestResultController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$TestResult = TestResult::with('test_type', 'user', 'user.medical_center')->paginate(10);
|
|
return \MessageResponse::data($TestResult);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
// public function CreateChildFormValue2($Input,$TestResultObj,$TestResultInfo)
|
|
// {
|
|
// if ($Input['type'] != 'Form') {
|
|
// $Value = $TestResultInfo[$Input->name];
|
|
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
|
|
// }
|
|
// else {
|
|
// foreach ($Input->children as $InputChild) {
|
|
// $this->CreateChildFormValue2($InputChild,$TestResultObj,$TestResultInfo[$Input->name]);
|
|
// }
|
|
// }
|
|
//
|
|
// }
|
|
|
|
public function store(StoreTestResultRequest $request)
|
|
{
|
|
try {
|
|
$return_value = \DB::transaction(function () use ($request) {
|
|
|
|
$TestResult = [
|
|
'user_id' => auth('api')->user()->id,
|
|
'autoclave_id' => $request->autoclave_id,
|
|
'test_type_id' => $request->test_type_id,
|
|
'result' => $request->result,
|
|
'verified' => 0,
|
|
];
|
|
$TestResultObj = TestResult::create($TestResult);
|
|
$TestResultInfo = $request->all();
|
|
|
|
$Inputs = Input::with('options','children','children.children')->where('test_type_id',$request->test_type_id)->get();
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////--2
|
|
foreach ($Inputs as $Input) {
|
|
if ($Input['type'] != 'Form') {
|
|
$Value = $TestResultInfo[$Input->name];
|
|
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
|
|
}
|
|
else {
|
|
foreach ($Input->children as $InputChild) {
|
|
$Value = $TestResultInfo[$Input->name][$InputChild->name];
|
|
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild->id , 'value' => $Value]);
|
|
}
|
|
//-------------------------------------------------------
|
|
// $this->CreateChildFormValue2($Input,$TestResultObj,$TestResultInfo);
|
|
// foreach ($Input->children as $InputChild) {
|
|
//
|
|
// if ($InputChild['type'] != 'Form') {
|
|
// $Value = $TestResultInfo[$Input->name][$InputChild->name];
|
|
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild->id , 'value' => $Value]);
|
|
// }
|
|
// else {
|
|
//
|
|
// foreach ($InputChild->children as $InputChild2) {
|
|
//
|
|
// if ($InputChild2['type'] != 'Form') {
|
|
// $Value = $TestResultInfo[$Input->name][$InputChild->name][$InputChild2->name];
|
|
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild2->id , 'value' => $Value]);
|
|
// }
|
|
// else {
|
|
//
|
|
// }
|
|
//
|
|
// }
|
|
// }
|
|
//
|
|
// }
|
|
//---------------------------------------------------------
|
|
|
|
}
|
|
}
|
|
|
|
|
|
});
|
|
} catch (\Exception $e) {
|
|
return response()->json($e->getMessage(), 441);
|
|
}
|
|
return \MessageResponse::success(null,trans('messages.create'));
|
|
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
//Todo:: pass Inputs
|
|
public function edit(TestResult $TestResult)
|
|
{
|
|
return \MessageResponse::data($TestResult);
|
|
}
|
|
|
|
public function update(StoreTestResultRequest $request, TestResult $TestResult)
|
|
{
|
|
$TestResultData = [
|
|
'user_id' => auth('api')->user()->id,
|
|
'autoclave_id' => $request->autoclave_id,
|
|
'test_type_id' => $request->test_type_id,
|
|
'result' => $request->result,
|
|
'verified' => 0,
|
|
];
|
|
$TestResult->update($TestResultData);
|
|
$TestResultInfo = $request->all();
|
|
|
|
$Inputs = Input::with('options','children','children.children')->where('test_type_id',$request->test_type_id)->get();
|
|
|
|
foreach ($Inputs as $Input) {
|
|
if ($Input['type'] != 'Form') {
|
|
$Value = $TestResultInfo[$Input->name];
|
|
$InputValueObj = InputValue::where('test_result_id',$TestResult)->update(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
|
|
}
|
|
else {
|
|
foreach ($Input->children as $InputChild) {
|
|
$Value = $TestResultInfo[$Input->name][$InputChild->name];
|
|
$InputValueObj = InputValue::where('test_result_id',$TestResult)->update(['test_result_id' => $TestResultObj->id , 'input_id' => $InputChild->id , 'value' => $Value]);
|
|
}
|
|
}
|
|
}
|
|
return \MessageResponse::success(null,trans('messages.update'));
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|