mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-11 22:41:05 +03:30
saeid
This commit is contained in:
@@ -11,6 +11,9 @@ class MedicalCenterController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (!auth('api')->user()->can('list', MedicalCenter::class)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
$MedicalCenters = MedicalCenter::withCount('users')->paginate(10);
|
||||
return \MessageResponse::data($MedicalCenters);
|
||||
}
|
||||
|
||||
@@ -8,24 +8,35 @@ use App\Http\Requests\StoreTestResultRequest;
|
||||
use App\TestResult;
|
||||
use App\InputValue;
|
||||
use App\Input;
|
||||
use App\MedicalCenter;
|
||||
use App\TestType;
|
||||
use App\Gallery;
|
||||
use App\Uploadable;
|
||||
use App\MedicalCenter;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\TestType;
|
||||
use App\User;
|
||||
|
||||
class TestResultController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = auth('api')->user();
|
||||
$TestResult = TestResult::with('test_type', 'user', 'user.medical_center')
|
||||
->when($request->has('verified'), function ($query) use ($request)
|
||||
{
|
||||
return $query->where('verified', $request->verified);
|
||||
})->paginate(10);
|
||||
})
|
||||
->when($user->hasRole('Supervisor') , function($query) {
|
||||
return $query->with(['user' => function($query) use ($user) {
|
||||
$query->where('medical_center_id', $user->medical_center_id);
|
||||
}]);
|
||||
})
|
||||
->when($user->hasRole('User') || ( !$user->hasRole('Admin') && !$user->hasRole('Supervisor')), function($query) {
|
||||
return $query->where('user_id', $user->id);
|
||||
})
|
||||
->paginate(10);
|
||||
|
||||
return \MessageResponse::data($TestResult);
|
||||
|
||||
}
|
||||
|
||||
public function create()
|
||||
@@ -68,25 +79,33 @@ class TestResultController extends Controller
|
||||
///////////////////////////////////////////////////////////////////////////Inputs
|
||||
foreach ($Inputs as $Input) {
|
||||
if ($Input['type'] != 'Form') {
|
||||
$Value = $TestResultInfo[$Input->name];
|
||||
|
||||
$Value = $TestResultInfo[$Input->name.'_'.$Input->id];
|
||||
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' ) {
|
||||
|
||||
foreach ($Value as $Option) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
// foreach ($Value as $Option) {
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
// }
|
||||
foreach ($Input->options as $Option) {//--2
|
||||
if(in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $Input->id, 'value' => $Value]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
foreach ($Input->children as $InputChild) {
|
||||
$Value = $TestResultInfo[$InputChild->name];
|
||||
$Value = $TestResultInfo[$InputChild->name.'_'.$InputChild->id];
|
||||
|
||||
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select') {
|
||||
foreach ($Value as $Option) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'option_id' => $Option]);
|
||||
// foreach ($Value as $Option) {
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'option_id' => $Option]);
|
||||
// }
|
||||
foreach ($InputChild->options as $Option) {//--2
|
||||
if(in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -99,12 +118,9 @@ class TestResultController extends Controller
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////Inputs
|
||||
///////////////////////////////////////////////////////////////////////////Image
|
||||
// if ($request->hasFile('img')) {
|
||||
//
|
||||
// $Image = $request->file('img');
|
||||
|
||||
if ($request->img != null) {
|
||||
|
||||
// $Image = $request->file('img');
|
||||
$Image = $request->img;
|
||||
$InterventionImage = Image::make($Image);
|
||||
$Mime = explode('/', $InterventionImage->mime());
|
||||
@@ -144,7 +160,7 @@ class TestResultController extends Controller
|
||||
$options[] = $input_option->option->title;
|
||||
$input_values[$input->name] = $options;
|
||||
}
|
||||
// dd($input_values);
|
||||
|
||||
$children[$input->parent->name] = $input_values;
|
||||
$TestResult['children'] = $children;
|
||||
}
|
||||
@@ -178,7 +194,6 @@ class TestResultController extends Controller
|
||||
if (count($TestResult->TitleImage)) {
|
||||
$TestResult['imagePath'] = $TestResult->TitleImage[0]->path;
|
||||
}
|
||||
// dd($TestResult);
|
||||
return \MessageResponse::data($TestResult);
|
||||
}
|
||||
|
||||
@@ -188,10 +203,10 @@ class TestResultController extends Controller
|
||||
$input = $value->input;
|
||||
if ($input->type == 'Checkbox' || $input->type == 'Select') {
|
||||
$input_options = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $input->id)->get()->pluck('option_id')->toArray();
|
||||
$TestResult[$input->name] = $input_options;
|
||||
$TestResult[$input->name.'_'.$input->id] = $input_options;
|
||||
}
|
||||
else {
|
||||
$TestResult[$input->name] = $value->value;
|
||||
$TestResult[$input->name.'_'.$input->id] = $value->value;
|
||||
}
|
||||
}
|
||||
if (count($TestResult->TitleImage)) {
|
||||
@@ -225,21 +240,21 @@ class TestResultController extends Controller
|
||||
|
||||
foreach ($Inputs as $Input) {
|
||||
if ($Input['type'] != 'Form') {
|
||||
$Value = $TestResultInfo[$Input->name];
|
||||
$Value = $TestResultInfo[$Input->name.'_'.$Input->id];
|
||||
|
||||
if ($Input['type'] == 'Checkbox' || $Input['type'] == 'Select' ) {
|
||||
|
||||
$InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $Input->id)->get()->each->delete();
|
||||
|
||||
// $option_array = $Input->options->pluck('id')->toArray();
|
||||
foreach ($Value as $Option) {//--1
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
}
|
||||
// foreach ($Input->options as $Option) {//--2
|
||||
// if(in_array($Option->id,$Value)){
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
// }
|
||||
// foreach ($Value as $Option) {//--1
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option]);
|
||||
// }
|
||||
foreach ($Input->options as $Option) {//--2
|
||||
if(in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $Input->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$InputValueObj = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $Input['id'])->update(['value' => $Value]);
|
||||
@@ -248,19 +263,19 @@ class TestResultController extends Controller
|
||||
else {
|
||||
foreach ($Input->children as $InputChild) {
|
||||
|
||||
$Value = $TestResultInfo[$InputChild->name];
|
||||
$Value = $TestResultInfo[$InputChild->name.'_'.$InputChild->id];
|
||||
|
||||
if ($InputChild['type'] == 'Checkbox' || $InputChild['type'] == 'Select') {
|
||||
$InputOptions = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $InputChild->id)->get()->each->delete();
|
||||
|
||||
foreach ($Value as $Option) {
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option]);
|
||||
}
|
||||
// foreach ($InputChild->options as $Option) {//--2
|
||||
// if(in_array($Option->id,$Value)){
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
// }
|
||||
// foreach ($Value as $Option) {
|
||||
// $InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option]);
|
||||
// }
|
||||
foreach ($InputChild->options as $Option) {//--2
|
||||
if(in_array($Option->id,$Value)){
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResult->id, 'input_id' => $InputChild->id, 'option_id' => $Option->id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$InputValueObj = InputValue::where('test_result_id', $TestResult->id)->where('input_id', $InputChild['id'])->update(['value' => $Value]);
|
||||
@@ -272,11 +287,9 @@ class TestResultController extends Controller
|
||||
$image = '';
|
||||
if (count($TestResult->TitleImage))
|
||||
$image = $TestResult->TitleImage[0];
|
||||
// dd($request->img);
|
||||
// if ($request->hasFile('img')) {
|
||||
|
||||
if ($request->img != null) {
|
||||
|
||||
// $Image = $request->file('img');
|
||||
$Image = $request->img;
|
||||
$InterventionImage = Image::make($Image);
|
||||
$Mime = explode('/', $InterventionImage->mime());
|
||||
@@ -322,7 +335,7 @@ class TestResultController extends Controller
|
||||
public function verifyTestResult(TestResult $TestResult)
|
||||
{
|
||||
if (!auth('api')->user()->can('verifyTestResult', $TestResult)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
return \MessageResponse::error(trans('You dont have permission or this test result belongs to another medical center'));
|
||||
}
|
||||
if ($TestResult->verified == 'Verified') {
|
||||
$TestResult->verified = 'NotVerified';
|
||||
@@ -334,14 +347,60 @@ class TestResultController extends Controller
|
||||
return \MessageResponse::success(trans('messages.success'), null, $TestResult);
|
||||
}
|
||||
|
||||
// TODO: Policy And Check Role
|
||||
public function listFilterItems()
|
||||
{
|
||||
$MedicalCenter = MedicalCenter::select('name', 'id')->get()->toArray();
|
||||
$TestType = TestType::select('name', 'id')->get()->toArray();
|
||||
return \MessageResponse::data([
|
||||
'MedicalCenters' => $MedicalCenter,
|
||||
'MedicalCenters' => $MedicalCenter,
|
||||
'TestTypes' => $TestType
|
||||
]);
|
||||
}
|
||||
|
||||
public function chart(Request $request)
|
||||
{
|
||||
$TestResults = TestResult::
|
||||
when($request->has('userId') && $request->userId, function ($query) use ($request)
|
||||
{
|
||||
$query->where('user_id', $request->userId);
|
||||
})
|
||||
->when($request->has('medicalCenterId') && $request->medicalCenterId, function ($query) use ($request)
|
||||
{
|
||||
$query->whereHas('user', function($query) use ($request) {
|
||||
$query->where('medical_center_id', $request->medicalCenterId);
|
||||
});
|
||||
})
|
||||
->when($request->has('testTypeId') && $request->testTypeId, function ($query) use ($request)
|
||||
{
|
||||
$query->where('test_type_id', $request->testTypeId);
|
||||
})
|
||||
->when($request->has('result') && $request->result, function ($query) use ($request)
|
||||
{
|
||||
$query->where('result', $request->result);
|
||||
})
|
||||
->when(($request->has('fromPicker') && $request->fromPicker) || ($request->has('upToPicker') && $request->upToPicker), function ($query) use ($request)
|
||||
{
|
||||
$from = ($request->fromPicker) ? date($request->fromPicker . ' 00:00:00') : date('2010-01-01' . ' 00:00:00');
|
||||
$upTo = ($request->upToPicker) ? date($request->upToPicker . ' 23:59:59') : date('Y-m-d' . ' 23:59:59');
|
||||
return $query->whereBetween('created_at', [$from, $upTo]);
|
||||
})
|
||||
->when($request->has('verify') && $request->verify, function ($query) use ($request)
|
||||
{
|
||||
$query->where('verified', $request->verify);
|
||||
})->get();
|
||||
$AcceptCount = 0;
|
||||
$RejectCount = 0;
|
||||
foreach ($TestResults as $TestResult) {
|
||||
if ($TestResult->result == 'Accept') {
|
||||
$AcceptCount++;
|
||||
}
|
||||
if ($TestResult->result == 'Reject') {
|
||||
$RejectCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// return \MessageResponse::data(['AcceptCount' => $AcceptCount, 'RejectCount' => $RejectCount]);
|
||||
return \MessageResponse::data(['labels' => ['Number Of Accepted Test Results', 'Number Of Rejected Test Results'], 'data' => [$AcceptCount,$RejectCount]]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,19 @@ class TestTypeController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if (!auth('api')->user()->can('list', TestType::class)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
$TestTypes = TestType::withCount('test_results')->with('user','user.medical_center')->paginate(10);
|
||||
return \MessageResponse::data($TestTypes);
|
||||
|
||||
}
|
||||
|
||||
public function generateBarcode(TestType $TestType)
|
||||
{
|
||||
if (!auth('api')->user()->can('generateBarcode', $TestType)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
$Number = $TestType->unique_code;
|
||||
$Barcode = DNS1D::getBarcodePNGUri($Number, "C128");
|
||||
$TestType->update(['bar_code' => $Barcode]);
|
||||
@@ -292,9 +299,9 @@ class TestTypeController extends Controller
|
||||
|
||||
public function update(StoreTestTypeRequest $request, TestType $TestType)
|
||||
{
|
||||
if (count($TestType->test_results) > 0) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
// if (count($TestType->test_results) > 0) {
|
||||
// return \MessageResponse::error(trans('messages.access_denied'));
|
||||
// }
|
||||
$TestTypeData = [
|
||||
'name' => $request['name'],
|
||||
'unique_code' => $request['unique_code'],
|
||||
@@ -382,7 +389,7 @@ class TestTypeController extends Controller
|
||||
public function destroy(TestType $TestType)
|
||||
{
|
||||
if (!auth('api')->user()->can('delete', $TestType)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
return \MessageResponse::error(trans('You dont have permission or this test type has a test result'));
|
||||
}
|
||||
$TestType->delete();
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
|
||||
@@ -20,8 +20,12 @@ class UserController extends Controller
|
||||
␍
|
||||
public function index()␍
|
||||
{␍
|
||||
if (!auth('api')->user()->can('list', User::class)) {␍
|
||||
return \MessageResponse::error(trans('messages.access_denied'));␍
|
||||
}␍
|
||||
$Users = User::with(['medical_center', 'roles'])->paginate(10);␍
|
||||
return \MessageResponse::data($Users);␍
|
||||
␍
|
||||
}␍
|
||||
␍
|
||||
public function store(StoreUserRequest $request)␍
|
||||
@@ -78,6 +82,9 @@ class UserController extends Controller
|
||||
␍
|
||||
public function changeStatus(User $User)␍
|
||||
{␍
|
||||
if (!auth('api')->user()->can('changeStatus', User::class)) {␍
|
||||
return \MessageResponse::error(trans('messages.access_denied'));␍
|
||||
}␍
|
||||
if ($User->status == 'Active') {␍
|
||||
$User->status = 'Suspended';␍
|
||||
} else {␍
|
||||
@@ -89,6 +96,9 @@ class UserController extends Controller
|
||||
␍
|
||||
public function changeRole(User $User, Request $request)␍
|
||||
{␍
|
||||
if (!auth('api')->user()->can('changeRole', User::class)) {␍
|
||||
return \MessageResponse::error(trans('messages.access_denied'));␍
|
||||
}␍
|
||||
$User->syncRoles($request->roles);␍
|
||||
return \MessageResponse::data($User);␍
|
||||
}␍
|
||||
|
||||
Reference in New Issue
Block a user