first commit
This commit is contained in:
39
dashboard/app/Console/Commands/fetchSourceData.php
Normal file
39
dashboard/app/Console/Commands/fetchSourceData.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\DataRetrievalService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class fetchSourceData extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:fetch-source-data';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Retrieve surveillance data from source database';
|
||||
protected $dataRetrievalService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dataRetrievalService = new DataRetrievalService();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->dataRetrievalService->getSurveillanceData();
|
||||
}
|
||||
|
||||
}
|
||||
300
dashboard/app/Http/Controllers/Api/DashboardController.php
Normal file
300
dashboard/app/Http/Controllers/Api/DashboardController.php
Normal file
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Services\DataRetrievalService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\DashboardService;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
protected $service;
|
||||
protected $dataRetrievalService;
|
||||
|
||||
public function __construct(DashboardService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->dataRetrievalService = new DataRetrievalService();
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Helper: Resolve Epiweek Range
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private function getEpiRange(Request $request)
|
||||
{
|
||||
$startYear = (int) $request->query('start_year');
|
||||
$startWeek = (int) $request->query('start_week');
|
||||
$endYear = (int) $request->query('end_year');
|
||||
$endWeek = (int) $request->query('end_week');
|
||||
|
||||
if (!$startYear || !$startWeek || !$endYear || !$endWeek) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'startYear' => $startYear,
|
||||
'startWeek' => $startWeek,
|
||||
'endYear' => $endYear,
|
||||
'endWeek' => $endWeek
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Overview Summary Cards
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function summary()
|
||||
{
|
||||
return response()->json($this->service->summaryCards());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Overview Trend Chart
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function trend(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->aggregateAllPrograms(
|
||||
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Program Dashboard
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function program(Request $request)
|
||||
{
|
||||
$surveillanceId = (int) $request->query('surveillance_id');
|
||||
|
||||
if (!$surveillanceId) {
|
||||
return response()->json(['error' => 'Missing surveillance_id'], 400);
|
||||
}
|
||||
|
||||
$range = $this->getEpiRange($request);
|
||||
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->programDashboardData(
|
||||
$surveillanceId,
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Province Map (Overview)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function provinceCircles(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->provinceCircles(
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Influenza subtype distribution (Overview)
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function influenzaSubtypeDetected(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->influenzaSubtypeDetected(
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function covidDistributedByAgeGroup(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->covidDistributedByAgeGroup(
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function covidLineageRelativeOverTime(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->covidLineageRelativeOverTime(
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function influenzaRelativeOverTime(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->influenzaRelativeOverTime(
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
public function influenzaRelativeOverTimeSequencing(Request $request)
|
||||
{
|
||||
$range = $this->getEpiRange($request);
|
||||
if (!$range) {
|
||||
return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
}
|
||||
|
||||
$data = $this->service->influenzaRelativeOverTimeSequencing(
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
);
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sentinel Map
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// public function sentinelMap(Request $request)
|
||||
|
||||
// {
|
||||
// $range = $this->getEpiRange($request);
|
||||
|
||||
// if (!$range) {
|
||||
// return response()->json(['error' => 'Missing epiweek range'], 400);
|
||||
// }
|
||||
|
||||
// return response()->json($data);
|
||||
// }
|
||||
|
||||
public function fetchSourceData()
|
||||
{
|
||||
try {
|
||||
$this->dataRetrievalService->getSurveillanceData();
|
||||
return response()->json(['message' => 'Data loaded successfully!'], 200);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => 'Data loaded unsuccessfully!'], 400);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Sequencing Dashboard
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public function sequencing(Request $request)
|
||||
{
|
||||
$surveillanceId = (int) $request->query('surveillance_id');
|
||||
$range = $this->getEpiRange($request);
|
||||
|
||||
if (!$surveillanceId || !$range) {
|
||||
return response()->json(['error' => 'Missing parameters'], 400);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'trend' => $this->service->sequencingTrend(
|
||||
$surveillanceId,
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
),'distribution' => $this->service->subtypeDistribution(
|
||||
$surveillanceId,
|
||||
$range['startYear'],
|
||||
$range['startWeek'],
|
||||
$range['endYear'],
|
||||
$range['endWeek']
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
if (!Auth::user()->is_active) {
|
||||
|
||||
Auth::logout();
|
||||
|
||||
return back()->withErrors([
|
||||
'email' => 'Account is disabled.',
|
||||
]);
|
||||
|
||||
}
|
||||
Auth::user()->update([
|
||||
'last_login_at' => now()
|
||||
]);
|
||||
activity_log(
|
||||
'login',
|
||||
'User logged in'
|
||||
);
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
activity_log(
|
||||
'logout',
|
||||
'User logged out'
|
||||
);
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): View
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|View
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(route('dashboard', absolute: false))
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function (User $user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
29
dashboard/app/Http/Controllers/Auth/PasswordController.php
Normal file
29
dashboard/app/Http/Controllers/Auth/PasswordController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validateWithBag('updatePassword', [
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'password-updated');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
}
|
||||
8
dashboard/app/Http/Controllers/Controller.php
Normal file
8
dashboard/app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
20
dashboard/app/Http/Controllers/DashboardController.php
Normal file
20
dashboard/app/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Surveillance;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function overview()
|
||||
{
|
||||
$programs = Surveillance::all();
|
||||
return view('dashboard.overview', compact('programs'));
|
||||
}
|
||||
|
||||
public function detail($code)
|
||||
{
|
||||
$selected = Surveillance::where('code', strtoupper($code))->firstOrFail();
|
||||
return view('dashboard.detail', compact('selected'));
|
||||
}
|
||||
}
|
||||
60
dashboard/app/Http/Controllers/ProfileController.php
Normal file
60
dashboard/app/Http/Controllers/ProfileController.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit')->with('status', 'profile-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validateWithBag('userDeletion', [
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
28
dashboard/app/Http/Middleware/RoleMiddleware.php
Normal file
28
dashboard/app/Http/Middleware/RoleMiddleware.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class RoleMiddleware
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle($request, Closure $next, $role)
|
||||
{
|
||||
if (!auth()->check()) {
|
||||
return redirect('/login');
|
||||
}
|
||||
|
||||
if (auth()->user()->role !== $role) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
86
dashboard/app/Http/Requests/Auth/LoginRequest.php
Normal file
86
dashboard/app/Http/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function authenticate(): void
|
||||
{
|
||||
$this->ensureIsNotRateLimited();
|
||||
|
||||
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.failed'),
|
||||
]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the login request is not rate limited.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited(): void
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event(new Lockout($this));
|
||||
|
||||
$seconds = RateLimiter::availableIn($this->throttleKey());
|
||||
|
||||
throw ValidationException::withMessages([
|
||||
'email' => trans('auth.throttle', [
|
||||
'seconds' => $seconds,
|
||||
'minutes' => ceil($seconds / 60),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rate limiting throttle key for the request.
|
||||
*/
|
||||
public function throttleKey(): string
|
||||
{
|
||||
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
|
||||
}
|
||||
}
|
||||
31
dashboard/app/Http/Requests/ProfileUpdateRequest.php
Normal file
31
dashboard/app/Http/Requests/ProfileUpdateRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class ProfileUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
'lowercase',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique(User::class)->ignore($this->user()->id),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
18
dashboard/app/Models/ActivityLog.php
Normal file
18
dashboard/app/Models/ActivityLog.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ActivityLog extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'action',
|
||||
'description',
|
||||
'ip_address',
|
||||
'user_agent',
|
||||
];
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
19
dashboard/app/Models/CaseLabResult.php
Normal file
19
dashboard/app/Models/CaseLabResult.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CaseLabResult extends Model
|
||||
{
|
||||
protected $table = 'case_lab_results';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'lab_code',
|
||||
'is_positive',
|
||||
'pathogen_name',
|
||||
'subtype',
|
||||
'indicator'
|
||||
];
|
||||
}
|
||||
16
dashboard/app/Models/LastSyncedLog.php
Normal file
16
dashboard/app/Models/LastSyncedLog.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LastSyncedLog extends Model
|
||||
{
|
||||
protected $table = 'last_synced_logs';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'surveillance_id',
|
||||
'last_synced_date'
|
||||
];
|
||||
}
|
||||
24
dashboard/app/Models/Surveillance.php
Normal file
24
dashboard/app/Models/Surveillance.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Surveillance extends Model
|
||||
{
|
||||
protected $table = 'surveillances';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name_en',
|
||||
'name_kh',
|
||||
'start_date',
|
||||
'end_date'
|
||||
];
|
||||
|
||||
public function cases()
|
||||
{
|
||||
return $this->hasMany(SurveillanceCase::class, 'surveillance_id');
|
||||
}
|
||||
}
|
||||
31
dashboard/app/Models/SurveillanceCase.php
Normal file
31
dashboard/app/Models/SurveillanceCase.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SurveillanceCase extends Model
|
||||
{
|
||||
protected $table = 'surveillance_cases';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'lab_code',
|
||||
'case_date',
|
||||
'is_newcase',
|
||||
'sentinel_site_name',
|
||||
'site_province_name',
|
||||
'surveillance_id',
|
||||
'year_data',
|
||||
'week_data',
|
||||
'patient_age_inday',
|
||||
'patient_sex',
|
||||
'is_alive',
|
||||
'patient_privince'
|
||||
];
|
||||
|
||||
public function surveillance()
|
||||
{
|
||||
return $this->belongsTo(Surveillance::class, 'surveillance_id');
|
||||
}
|
||||
}
|
||||
48
dashboard/app/Models/User.php
Normal file
48
dashboard/app/Models/User.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
28
dashboard/app/Providers/AppServiceProvider.php
Normal file
28
dashboard/app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Models\Surveillance;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
View::composer('layouts.app', function ($view) {
|
||||
$view->with('programs', Surveillance::orderBy('id')->get());
|
||||
});
|
||||
}
|
||||
}
|
||||
1456
dashboard/app/Services/DashboardService.php
Normal file
1456
dashboard/app/Services/DashboardService.php
Normal file
File diff suppressed because it is too large
Load Diff
150
dashboard/app/Services/DataRetrievalService.php
Normal file
150
dashboard/app/Services/DataRetrievalService.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DataRetrievalService
|
||||
{
|
||||
|
||||
protected $apiBaseUrl;
|
||||
protected $apiUsername;
|
||||
protected $apiPassword;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->apiBaseUrl = config('services.nphl_api.url');
|
||||
$this->apiUsername = config('services.nphl_api.username');
|
||||
$this->apiPassword = config('services.nphl_api.password');
|
||||
}
|
||||
|
||||
public function get($endpoint)
|
||||
{
|
||||
try {
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $this->apiBaseUrl . $endpoint);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
|
||||
curl_setopt($ch, CURL_HTTP_VERSION_1_1, 0);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->apiUsername . ":" . $this->apiPassword);
|
||||
$resp = curl_exec($ch);
|
||||
$b="";
|
||||
if($e = curl_error($ch)){
|
||||
$b= $e;
|
||||
}else{
|
||||
$b= $resp;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $b;
|
||||
|
||||
} catch (RequestException $e) {
|
||||
return [
|
||||
'error' => true,
|
||||
'message' => $e->getMessage(),
|
||||
'status' => optional($e->response)->status()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getSurveillanceData()
|
||||
{
|
||||
try{
|
||||
$lookbackDays = config('app.lookback_days');
|
||||
$surveillances = DB::connection('mysql')->select("select * from surveillances");
|
||||
foreach ($surveillances as $surveillance){
|
||||
$surveillance_data = $this->get('api/labsurveil.php?surveillance_id='.$surveillance->id.'&start_date='.now()->subDays($lookbackDays[$surveillance->code])->toDateString());
|
||||
$data = json_decode(preg_replace('/^\x{FEFF}+/u', '', $surveillance_data));
|
||||
@$this->insert_surveillance_cases((array)$data->laboratory_cases);
|
||||
@$this->insert_surveillance_case_lab_results((array)$data->laboratory_results);
|
||||
|
||||
}
|
||||
|
||||
Log::channel('jobs')->info(now()->toDateString(). ' Service Reload Data Successfully Ran');
|
||||
return true;
|
||||
}
|
||||
catch (\Exception $e){
|
||||
Log::channel('jobs')->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function insert_surveillance_cases($cases){
|
||||
|
||||
$case_data = [];
|
||||
foreach ($cases as $case) {
|
||||
$case_data[] = [
|
||||
'lab_code' => $case->labcode,
|
||||
'case_date' => $case->patdate,
|
||||
'is_newcase' => $case->isnewcase,
|
||||
'sentinel_site_name' => $case->labname_en,
|
||||
'site_province_name' => $case->labaddress_en,
|
||||
'surveillance_id' => $case->surveillance_id,
|
||||
'year_data' => $case->year_data,
|
||||
'week_data' => $case->week_data,
|
||||
'patient_age_inday' => $case->patage,
|
||||
'patient_sex' => $case->patsex,
|
||||
'is_alive' => $case->is_alive,
|
||||
'patient_province' => $case->proname_en
|
||||
];
|
||||
}
|
||||
|
||||
$case_chunks = array_chunk($case_data, 500);
|
||||
foreach ($case_chunks as $chunk) {
|
||||
DB::connection('mysql')->table('surveillance_cases')->upsert($chunk, [
|
||||
'lab_code',
|
||||
'surveillance_id'
|
||||
], [
|
||||
'case_date',
|
||||
'is_newcase',
|
||||
'sentinel_site_name',
|
||||
'site_province_name',
|
||||
'year_data',
|
||||
'week_data',
|
||||
'patient_age_inday',
|
||||
'patient_sex',
|
||||
'is_alive',
|
||||
'patient_province'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function insert_surveillance_case_lab_results($lab_results){
|
||||
$result_data = [];
|
||||
foreach ($lab_results as $lab_result) {
|
||||
$result_data[] = [
|
||||
'lab_code' => $lab_result->labcode,
|
||||
'surveillance_id' => $lab_result->surveillance_id,
|
||||
'is_positive' => $lab_result->is_positive,
|
||||
'pathogen_name' => $lab_result->pathogen_name,
|
||||
'subtype' => $lab_result->subtype,
|
||||
'indicator' => $lab_result->indicator
|
||||
];
|
||||
}
|
||||
$result_chunks = array_chunk($result_data, 500);
|
||||
foreach ($result_chunks as $chunk) {
|
||||
DB::connection('mysql')->table('case_lab_results')->upsert($chunk,
|
||||
[
|
||||
'lab_code',
|
||||
'surveillance_id',
|
||||
'indicator'
|
||||
],
|
||||
[
|
||||
'is_positive',
|
||||
'pathogen_name',
|
||||
'subtype'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
17
dashboard/app/View/Components/AppLayout.php
Normal file
17
dashboard/app/View/Components/AppLayout.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AppLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.app');
|
||||
}
|
||||
}
|
||||
17
dashboard/app/View/Components/GuestLayout.php
Normal file
17
dashboard/app/View/Components/GuestLayout.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GuestLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.guest');
|
||||
}
|
||||
}
|
||||
18
dashboard/app/helpers.php
Normal file
18
dashboard/app/helpers.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
|
||||
if (!function_exists('activity_log')) {
|
||||
|
||||
function activity_log($action, $description = null)
|
||||
{
|
||||
ActivityLog::create([
|
||||
'user_id' => auth()->id(),
|
||||
'action' => $action,
|
||||
'description' => $description,
|
||||
'ip_address' => request()->ip(),
|
||||
'user_agent' => request()->userAgent(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user