init project
This commit is contained in:
18
.editorconfig
Normal file
18
.editorconfig
Normal file
@@ -0,0 +1,18 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[compose.yaml]
|
||||
indent_size = 4
|
||||
65
.env.example
Normal file
65
.env.example
Normal file
@@ -0,0 +1,65 @@
|
||||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
APP_LOCALE=en
|
||||
APP_FALLBACK_LOCALE=en
|
||||
APP_FAKER_LOCALE=en_US
|
||||
|
||||
APP_MAINTENANCE_DRIVER=file
|
||||
# APP_MAINTENANCE_STORE=database
|
||||
|
||||
# PHP_CLI_SERVER_WORKERS=4
|
||||
|
||||
BCRYPT_ROUNDS=12
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_STACK=single
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=vechsa_lis
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
SESSION_DRIVER=database
|
||||
SESSION_LIFETIME=120
|
||||
SESSION_ENCRYPT=false
|
||||
SESSION_PATH=/
|
||||
SESSION_DOMAIN=null
|
||||
|
||||
BROADCAST_CONNECTION=log
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=database
|
||||
|
||||
CACHE_STORE=database
|
||||
# CACHE_PREFIX=
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_CLIENT=phpredis
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=log
|
||||
MAIL_SCHEME=null
|
||||
MAIL_HOST=127.0.0.1
|
||||
MAIL_PORT=2525
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
11
.gitattributes
vendored
Normal file
11
.gitattributes
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
*.log
|
||||
.DS_Store
|
||||
.env
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpactor.json
|
||||
.phpunit.result.cache
|
||||
/.fleet
|
||||
/.idea
|
||||
/.nova
|
||||
/.phpunit.cache
|
||||
/.vscode
|
||||
/.zed
|
||||
/auth.json
|
||||
/node_modules
|
||||
/public/build
|
||||
/public/hot
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/storage/pail
|
||||
/vendor
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
Thumbs.db
|
||||
59
README.md
Normal file
59
README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
|
||||
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
|
||||
</p>
|
||||
|
||||
## About Laravel
|
||||
|
||||
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
|
||||
|
||||
- [Simple, fast routing engine](https://laravel.com/docs/routing).
|
||||
- [Powerful dependency injection container](https://laravel.com/docs/container).
|
||||
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
|
||||
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
|
||||
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
|
||||
- [Robust background job processing](https://laravel.com/docs/queues).
|
||||
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
|
||||
|
||||
Laravel is accessible, powerful, and provides tools required for large, robust applications.
|
||||
|
||||
## Learning Laravel
|
||||
|
||||
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. You can also check out [Laravel Learn](https://laravel.com/learn), where you will be guided through building a modern Laravel application.
|
||||
|
||||
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
|
||||
|
||||
## Laravel Sponsors
|
||||
|
||||
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
|
||||
|
||||
### Premium Partners
|
||||
|
||||
- **[Vehikl](https://vehikl.com)**
|
||||
- **[Tighten Co.](https://tighten.co)**
|
||||
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
|
||||
- **[64 Robots](https://64robots.com)**
|
||||
- **[Curotec](https://www.curotec.com/services/technologies/laravel)**
|
||||
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
|
||||
- **[Redberry](https://redberry.international/laravel-development)**
|
||||
- **[Active Logic](https://activelogic.com)**
|
||||
|
||||
## Contributing
|
||||
|
||||
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
|
||||
|
||||
## Security Vulnerabilities
|
||||
|
||||
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
|
||||
|
||||
## License
|
||||
|
||||
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
||||
52
app/Console/Commands/DisableLabAccess.php
Normal file
52
app/Console/Commands/DisableLabAccess.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Laboratory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DisableLabAccess extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'laboratory:disable';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try{
|
||||
$labs = Laboratory::query()->where('record_status_id', 1)
|
||||
->whereRaw("DATEDIFF(end_date, CURDATE())<=-7")
|
||||
->update(['record_status_id' => 0]);
|
||||
Log::channel('jobs')->info($labs);
|
||||
} catch (\Exception $e){
|
||||
Log::channel('jobs')->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
77
app/Console/Commands/NotifyExpireLab.php
Normal file
77
app/Console/Commands/NotifyExpireLab.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Laboratory;
|
||||
use App\Models\Publication;
|
||||
use App\Models\PublicationReceiver;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NotifyExpireLab extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'notify:send';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
try{
|
||||
$labs = Laboratory::query()->where('record_status_id', 1)
|
||||
->whereNotNull('end_date')
|
||||
->whereRaw("DATEDIFF(end_date, CURDATE())=7")->get();
|
||||
|
||||
Log::channel('jobs')->info($labs);
|
||||
|
||||
foreach ($labs as $lab){
|
||||
|
||||
$date= date_create(date('Y-m-d', strtotime($lab->end_date)));
|
||||
date_add($date,date_interval_create_from_date_string("7 days"));
|
||||
$_disable_date = date_format($date,"d-M-Y");
|
||||
|
||||
$publication = Publication::query()->create([
|
||||
'title_en' => "License Expiry Alert",
|
||||
'title_kh' => "សេចក្តីជូនដំណឹងអំពីការផុតសុំពលភាពនៃការប្រើប្រាស់ប្រព័ន្ធ Labonak",
|
||||
'start_date' => date('Y-m-d'),
|
||||
'end_date' => date('Y-m-d', strtotime($lab->end_date)),
|
||||
'description' => "គណនីប្រើប្រាស់ប្រព័ន្ធរបស់លោកអ្នកនឹងផ្អាកប្រើប្រាស់ជាបណ្ណោះអាសន្ននៅថ្ងៃ " . $_disable_date . " សូមទំនាក់ទំនងទៅកាន់ System Administrator ដើម្បីបន្តសុពលភាព។ សូមអរគុណ!"
|
||||
]);
|
||||
|
||||
PublicationReceiver::query()->create([
|
||||
'publication_id' => $publication->id,
|
||||
'lab_id' => $lab->id,
|
||||
'created_by' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (\Exception $e){
|
||||
Log::channel('jobs')->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
41
app/Console/Kernel.php
Normal file
41
app/Console/Kernel.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
29
app/Enums/DateFormatEnum.php
Normal file
29
app/Enums/DateFormatEnum.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
|
||||
/**
|
||||
* @method static static OptionOne()
|
||||
* @method static static OptionTwo()
|
||||
* @method static static OptionThree()
|
||||
*/
|
||||
final class DateFormatEnum extends Enum
|
||||
{
|
||||
const Ymd = 'Y-m-d';
|
||||
const YmdHi = 'Y-m-d H:i';
|
||||
const dMY = 'd M Y';
|
||||
const dmY = 'd m Y';
|
||||
const d_M_Y = 'd-M-Y';
|
||||
const d_M_Y_His = 'd-M-Y H:i:s';
|
||||
const MY = 'M-Y';
|
||||
const mY = 'm-Y';
|
||||
const dMYHi = 'd-M-Y H:i';
|
||||
const YmdHis= 'Y-m-d H:i:s';
|
||||
const _YmdHis= 'Y_m_d_His';
|
||||
const _Ymd= 'Y_m_d';
|
||||
const _Ym= 'Y_m';
|
||||
const Y = 'Y';
|
||||
|
||||
}
|
||||
260
app/Enums/ExcelDesignEnum.php
Normal file
260
app/Enums/ExcelDesignEnum.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
|
||||
final class ExcelDesignEnum extends Enum
|
||||
{
|
||||
const NO_FORMAT = [
|
||||
];
|
||||
|
||||
const DEFAULT_TITLE = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 14,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
];
|
||||
const DEFAULT = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
const DEFAULT_HEADER = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
],
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => '0c54a4',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
'color' => ['rgb' => 'FFFFFF'],
|
||||
],
|
||||
];
|
||||
|
||||
const SUB_HEADER = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
],
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => '2672c7',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
'color' => ['rgb' => 'FFFFFF'],
|
||||
],
|
||||
];
|
||||
|
||||
const DEFAULT_TOTAL = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'c74126',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
'color' => ['rgb' => 'FFFFFF'],
|
||||
],
|
||||
];
|
||||
|
||||
const KHR_CURRENCY = '#,##0';
|
||||
|
||||
const GENERAL_CURRENCY = '_(* #,##0_);_(* (#,##0);_(* "-"??_);_(@_)';
|
||||
|
||||
const GENERAL_CURRENCY_ = '_(* #,##0_);_(* (#,##0);_(* "0"??_);_(@_)';
|
||||
|
||||
const TITLE = array(
|
||||
'alignment' => array(
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER
|
||||
),
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'f3f3f3',
|
||||
]
|
||||
],
|
||||
);
|
||||
|
||||
const BORDER = array(
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
const HEADER = array(
|
||||
'font' => array('size' => 14),
|
||||
'alignment' => array(
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER
|
||||
)
|
||||
);
|
||||
|
||||
const SECTION = array(
|
||||
'alignment' => array(
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER
|
||||
),
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 12,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
);
|
||||
|
||||
const LIGHT_SECTION = array(
|
||||
'alignment' => array(
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER
|
||||
),
|
||||
'font' => [
|
||||
'size' => 12,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
);
|
||||
|
||||
const SECTION_BORDER = array(
|
||||
'alignment' => array(
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
'vertical' => Alignment::VERTICAL_CENTER
|
||||
),
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 12,
|
||||
],
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
const HIGHLIGHT = array(
|
||||
'font' => array('bold' => true),
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'E8F0FF',
|
||||
]
|
||||
],
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
'alignment' => array(
|
||||
'vertical' => Alignment::VERTICAL_CENTER
|
||||
)
|
||||
);
|
||||
|
||||
const GRAY_HEADER = array(
|
||||
'font' => array('bold' => true),
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'DDDDDD',
|
||||
]
|
||||
],
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => 'AAAAAA'],
|
||||
],
|
||||
],
|
||||
'alignment' => array(
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
)
|
||||
);
|
||||
|
||||
const FOOTER = array(
|
||||
'font' => array('bold' => true)
|
||||
);
|
||||
|
||||
CONST FONT_KHMER = array(
|
||||
'font' => array(
|
||||
'name' => 'Khmer OS'
|
||||
)
|
||||
);
|
||||
|
||||
CONST ALIGNMENT = [
|
||||
'alignment' => array(
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
'horizontal' => Alignment::HORIZONTAL_CENTER,
|
||||
)
|
||||
];
|
||||
|
||||
const BOLD_BORDER = array(
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
const TEXT_BOLD = array(
|
||||
'font' => array('bold' => true)
|
||||
);
|
||||
|
||||
const YELLOW_BACKGROUND = array(
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'FAFAD2',
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
CONST VERTICAL_ALIGNMENT = [
|
||||
'alignment' => array(
|
||||
'vertical' => Alignment::VERTICAL_CENTER,
|
||||
)
|
||||
];
|
||||
|
||||
CONST FONT_KH_OS_SIEMREAP = 'Khmer OS Siemreap';
|
||||
|
||||
CONST FONT_SIZE = 11;
|
||||
}
|
||||
16
app/Enums/RecordStatusEnum.php
Normal file
16
app/Enums/RecordStatusEnum.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
|
||||
/**
|
||||
* @method static static OptionOne()
|
||||
* @method static static OptionTwo()
|
||||
* @method static static OptionThree()
|
||||
*/
|
||||
final class RecordStatusEnum extends Enum
|
||||
{
|
||||
const ACTIVE = 1;
|
||||
const DELETE = 0;
|
||||
}
|
||||
17
app/Enums/SexEnum.php
Normal file
17
app/Enums/SexEnum.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
|
||||
/**
|
||||
* @method static static OptionOne()
|
||||
* @method static static OptionTwo()
|
||||
* @method static static OptionThree()
|
||||
*/
|
||||
final class SexEnum extends Enum
|
||||
{
|
||||
const M = 'Male';
|
||||
const F = 'Female';
|
||||
const B = 'Both Male & Female';
|
||||
}
|
||||
33
app/Enums/UtilEnum.php
Normal file
33
app/Enums/UtilEnum.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use BenSampo\Enum\Enum;
|
||||
|
||||
/**
|
||||
* @method static static OptionOne()
|
||||
* @method static static OptionTwo()
|
||||
* @method static static OptionThree()
|
||||
*/
|
||||
final class UtilEnum extends Enum
|
||||
{
|
||||
|
||||
const ADMINISTRATOR_ROLE = 1;
|
||||
const ADMINISTRATOR_USER = 1;
|
||||
|
||||
const PHYSICIAN_ROLE = 6;
|
||||
|
||||
const LBD = 'Days';
|
||||
const LBM = 'Months';
|
||||
const LBY = 'Years';
|
||||
|
||||
const Y = 'Yes';
|
||||
const N = 'No';
|
||||
|
||||
const FIELD_TYPE_HEADING = 0;
|
||||
const FIELD_TYPE_NUMERIC = 1;
|
||||
const FIELD_TYPE_SINGLE = 2;
|
||||
const FIELD_TYPE_MULTIPLE = 3;
|
||||
const FIELD_TYPE_CALCULATE = 4;
|
||||
|
||||
}
|
||||
147
app/Exports/DoctorPhysicianExport.php
Normal file
147
app/Exports/DoctorPhysicianExport.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class DoctorPhysicianExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Doctor-Report';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
146
app/Exports/DoctorRawExport.php
Normal file
146
app/Exports/DoctorRawExport.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class DoctorRawExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Doctor-Report';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
145
app/Exports/DoctorSampleSourceExport.php
Normal file
145
app/Exports/DoctorSampleSourceExport.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class DoctorSampleSourceExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Doctor-Report';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
158
app/Exports/FinancialReportExport.php
Normal file
158
app/Exports/FinancialReportExport.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use App\Helpers\Helpers;
|
||||
|
||||
class FinancialReportExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Fianancial-Report';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A".($rows+1).":G".($rows+1))->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A".($rows+1).":G".($rows+1));
|
||||
$sheet->setCellValue('A'.($rows+1), 'Total');
|
||||
$sheet->setCellValue('H'.($rows+1), '=SUM(H3:H'.($rows).')');
|
||||
$sheet->setCellValue('I'.($rows+1), '=SUM(I3:I'.($rows).')');
|
||||
$sheet->setCellValue('J'.($rows+1), '=SUM(J3:J'.($rows).')');
|
||||
$sheet->setCellValue('K'.($rows+1), '=SUM(K3:K'.($rows).')');
|
||||
$sheet->setCellValue('L'.($rows+1), '=SUM(L3:L'.($rows).')');
|
||||
$sheet->setCellValue('M'.($rows+1), '=SUM(M3:M'.($rows).')');
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
147
app/Exports/InventoryOnHandExport.php
Normal file
147
app/Exports/InventoryOnHandExport.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class InventoryOnHandExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Inventory On hand';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
147
app/Exports/ItemExpiredExport.php
Normal file
147
app/Exports/ItemExpiredExport.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class ItemExpiredExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Expired items';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
147
app/Exports/StockinExport.php
Normal file
147
app/Exports/StockinExport.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class StockinExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Stock In Report';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
147
app/Exports/StockoutExport.php
Normal file
147
app/Exports/StockoutExport.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class StockoutExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'Stock In Report';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
147
app/Exports/SummaryReportExport.php
Normal file
147
app/Exports/SummaryReportExport.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Enums\ExcelDesignEnum;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\WithCustomStartCell;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
|
||||
class SummaryReportExport implements FromArray, WithTitle, WithCustomStartCell,WithEvents
|
||||
{
|
||||
use Exportable;
|
||||
protected array $data;
|
||||
protected array $headingTitle;
|
||||
protected string $sheet;
|
||||
protected string $title;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return 'summary_report';
|
||||
}
|
||||
|
||||
public function startCell(): string
|
||||
{
|
||||
return 'A3';
|
||||
}
|
||||
|
||||
public function setTitleHeadingTable($data): array
|
||||
{
|
||||
return $this->headingTitle = $data;
|
||||
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$sheet = $event->sheet->getDelegate();
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setName(ExcelDesignEnum::FONT_KH_OS_SIEMREAP);
|
||||
$sheet->getParent()->getDefaultStyle()->getFont()->setSize(ExcelDesignEnum::FONT_SIZE);
|
||||
|
||||
$bgGrandTotal = [
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'color' => [
|
||||
'rgb' => 'd9d9d9',
|
||||
]
|
||||
],
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentCenter = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'center'
|
||||
]
|
||||
];
|
||||
|
||||
$alignmentLeft = [
|
||||
'alignment' => [
|
||||
'horizontal' => 'left',
|
||||
]
|
||||
];
|
||||
|
||||
$borderAll = [
|
||||
'borders' => [
|
||||
'allBorders' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$outBorder = [
|
||||
'borders' => [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||
'color' => ['rgb' => '000000'],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$textBold = [
|
||||
'font' => [
|
||||
'bold' => true,
|
||||
'size' => 11,
|
||||
],
|
||||
];
|
||||
|
||||
$title = $this->title;
|
||||
$columns = count($this->headingTitle);
|
||||
$rows = count($this->data) + 2;
|
||||
|
||||
$lastColumnString = Coordinate::stringFromColumnIndex($columns);
|
||||
|
||||
for($i = 1; $i<=$columns; $i++){
|
||||
$nameCell = Coordinate::stringFromColumnIndex($i);
|
||||
$sheet->getColumnDimension($nameCell)->setAutoSize(true);
|
||||
//setWidth(21);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->mergeCells("A1:$lastColumnString".'1');
|
||||
$sheet->setCellValue('A1',$title);
|
||||
|
||||
foreach ($this->headingTitle as $key => $value){
|
||||
$cellColumn = $key + 1;
|
||||
$cellColumnName = Coordinate::stringFromColumnIndex($cellColumn);
|
||||
$sheet->setCellValue($cellColumnName.'2', $value);
|
||||
}
|
||||
|
||||
$sheet->getStyle("A1")->applyFromArray($alignmentCenter);
|
||||
$sheet->getRowDimension(1)->setRowHeight(28);
|
||||
$sheet->getStyle("A1")->applyFromArray($textBold);
|
||||
$sheet->getRowDimension(2)->setRowHeight(25);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($alignmentCenter);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($borderAll);
|
||||
$sheet->getStyle("A2:".$lastColumnString."2")->applyFromArray($bgGrandTotal);
|
||||
$sheet->getStyle("A3:A$rows")->applyFromArray($alignmentLeft);
|
||||
$sheet->getStyle("A3:".$lastColumnString.$rows)->applyFromArray($outBorder);
|
||||
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
162
app/Helpers/Helpers.php
Normal file
162
app/Helpers/Helpers.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mruongyutthy
|
||||
* Date: 1/5/20
|
||||
* Time: 22:05
|
||||
*/
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
|
||||
use DateTime;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\Sample;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
||||
class Helpers
|
||||
{
|
||||
public static function lang()
|
||||
{
|
||||
return App::getLocale();
|
||||
}
|
||||
|
||||
public static function numberFormat($value, $decimal = null)
|
||||
{
|
||||
if (empty($value) && $value != 0) {
|
||||
return '';
|
||||
}
|
||||
if ($decimal > 0) {
|
||||
return number_format($value, $decimal);
|
||||
}
|
||||
|
||||
return number_format($value, fmod($value, 1) == 0 ? 0 : 2);
|
||||
}
|
||||
|
||||
public static function isDateValid($date)
|
||||
{
|
||||
if(!is_null($date) && $date != '' && !empty($date) && $date !== "0000-00-00") {
|
||||
return ((strtotime($date) < 0) || (strtotime($date) == false)) ? false : true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public static function generateUuId($prefixClass){
|
||||
$hexTimestamp = strtoupper(dechex(round((1000000*gettimeofday()['sec']) + (gettimeofday()['usec']))));
|
||||
return
|
||||
$prefixClass .
|
||||
'-'.
|
||||
str_pad(substr($hexTimestamp, 8, 3),3,'0',STR_PAD_RIGHT).
|
||||
str_pad(substr($hexTimestamp, 11, 3),3,'0',STR_PAD_LEFT).
|
||||
str_pad(mt_rand(1,99),2,'0',STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public static function generateUuIdForManual($prefixClass, $manual_code){
|
||||
return $prefixClass . '-'.date('ymd').'-'.$manual_code;
|
||||
}
|
||||
|
||||
public static function split_name($name) {
|
||||
return explode(" ",$name,2);
|
||||
}
|
||||
|
||||
public static function getAge($startDate, $endDate) {
|
||||
$today = new DateTime($endDate);
|
||||
$diff = $today->diff(new DateTime($startDate));
|
||||
$years = $diff->y;
|
||||
$months = $diff->m;
|
||||
$days = $diff->d;
|
||||
|
||||
/*if($years>0) return "$years ".__('sample.year') .($months > 0 ? ' '. $months .__('sample.month') : '') . ($days>0? ' ' . $days . __('sample.day'): '');
|
||||
return ($months > 0 ? ' '. $months .__('sample.month') : ''). ($days>0? ' ' . $days . __('sample.day'): '');*/
|
||||
|
||||
if($years ==0 && $months == 0) return $days . __('sample.day');
|
||||
elseif($years == 0 && $months > 0) return $months .__('sample.month');
|
||||
else return "$years ".__('sample.year');
|
||||
|
||||
/*if($years>0) return "$years ".__('sample.year') .($months > 0 ? ' '. $months .__('sample.month') : '');
|
||||
return $months .__('sample.month') .', '. $days . __('sample.day');*/
|
||||
}
|
||||
|
||||
public static function getGender($sex){
|
||||
if($sex == 1) return __('sample.sex_m');
|
||||
return __('sample.sex_f');
|
||||
}
|
||||
|
||||
public static function getGenderfull($sex){
|
||||
if($sex == 1) return __('sample.sex_male');
|
||||
return __('sample.sex_female');
|
||||
}
|
||||
|
||||
public static function knum($string){
|
||||
$string = str_replace(array('1','2','3','4','5','6','7','8','9','0','.'),
|
||||
array('១','២','៣','៤','៥','៦','៧','៨','៩','០',','), $string);
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function getPatientAddress($patientObject){
|
||||
$address = '';
|
||||
if(App::getLocale()=='en'){
|
||||
if(isset($patientObject->province->name_en)) $address.= $patientObject->province->name_en;
|
||||
if(isset($patientObject->district->name_en)) $address.= ', '. $patientObject->district->name_en;
|
||||
if(isset($patientObject->commune->name_en)) $address.= ', '. $patientObject->commune->name_en;
|
||||
if(isset($patientObject->viilage->name_en)) $address.= ', '. $patientObject->viilage->name_en;
|
||||
}else{
|
||||
if(isset($patientObject->province->name_kh)) $address.= $patientObject->province->name_kh;
|
||||
if(isset($patientObject->district->name_kh)) $address.= ', '. $patientObject->district->name_kh;
|
||||
if(isset($patientObject->commune->name_kh)) $address.= ', '. $patientObject->commune->name_kh;
|
||||
if(isset($patientObject->viilage->name_kh)) $address.= ', '. $patientObject->viilage->name_kh;
|
||||
}
|
||||
return $address;
|
||||
}
|
||||
|
||||
public static function getPrinterSignature($sampleId){
|
||||
$sample = Sample::query()->find( $sampleId);
|
||||
if($sample->is_printed == 1){
|
||||
return User::query()->find($sample->printed_by)->signature;
|
||||
}else{
|
||||
return @Auth::user()->signature;
|
||||
}
|
||||
}
|
||||
|
||||
public static function setExcelSheetCell($sheet, $cellStart, $cellEnd, $value, $format = []){
|
||||
if($cellStart != $cellEnd){
|
||||
$sheet->mergeCells($cellStart.":".$cellEnd);
|
||||
}
|
||||
foreach(range(Str::substr($cellStart,0,1),Str::substr($cellEnd,0,1)) as $columnID) {
|
||||
$sheet->getColumnDimension($columnID)->setAutoSize(true);
|
||||
}
|
||||
$sheet->setCellValue($cellStart, $value);
|
||||
if(!is_null($format) || !empty($format)){
|
||||
$sheet->getStyle($cellStart.":".$cellEnd)->applyFromArray($format);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getNotify(){
|
||||
$publication = DB::select("
|
||||
SELECT
|
||||
p.*
|
||||
FROM publications p
|
||||
INNER JOIN publication_receivers pr
|
||||
ON pr.publication_id = p.id
|
||||
WHERE DATE(NOW()) BETWEEN start_date AND end_date AND p.record_status_id = 1
|
||||
AND pr.lab_id = " . Session::get('base_lab_id'));
|
||||
return $publication;
|
||||
}
|
||||
|
||||
public static function generatePatientBotLink($individual_type = 'patient',$labId, $patientId)
|
||||
{
|
||||
$botUsername = env('TELEGRAM_BOT_NAME'); // e.g. "MyLabBot"
|
||||
if ($individual_type == 'sample_source'){
|
||||
// if $individual_type is sample_source, patientId is sample source id
|
||||
return "https://t.me/{$botUsername}?start=samplesource_{$patientId}";
|
||||
}
|
||||
return "https://t.me/{$botUsername}?start={$patientId}";
|
||||
}
|
||||
|
||||
}
|
||||
20
app/Helpers/SessionHelper.php
Normal file
20
app/Helpers/SessionHelper.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
|
||||
class SessionHelper
|
||||
{
|
||||
|
||||
private static function sessionGetter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static function sessionSetter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
74
app/Http/Controllers/ActivityLogsController.php
Normal file
74
app/Http/Controllers/ActivityLogsController.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use App\Models\User;
|
||||
|
||||
class ActivityLogsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$users = User::select('id','name')->get();
|
||||
return view('audit-logs.index',compact('users'));
|
||||
}
|
||||
|
||||
public function data(Request $request)
|
||||
{
|
||||
|
||||
$query = Activity::with('causer')->orderBy('created_at','desc');
|
||||
|
||||
if($request->event){
|
||||
$query->where('description',$request->event);
|
||||
}
|
||||
|
||||
if($request->user_id){
|
||||
$query->where('causer_id',$request->user_id);
|
||||
}
|
||||
|
||||
if($request->date_from){
|
||||
$query->whereDate('created_at','>=',$request->date_from);
|
||||
}
|
||||
|
||||
if($request->date_to){
|
||||
$query->whereDate('created_at','<=',$request->date_to);
|
||||
}
|
||||
|
||||
return DataTables::of($query)
|
||||
|
||||
->addColumn('module', function ($log) {
|
||||
return class_basename($log->subject_type);
|
||||
})
|
||||
|
||||
->addColumn('user', function ($log) {
|
||||
return $log->causer->name ?? 'System';
|
||||
})
|
||||
|
||||
->editColumn('created_at', function ($log) {
|
||||
return '<span title="'.$log->created_at.'">
|
||||
'.$log->created_at->diffForHumans().'
|
||||
</span>';
|
||||
})
|
||||
|
||||
->addColumn('action', function ($log) {
|
||||
|
||||
return '<button class="btn btn-sm btn-inverse-info rounded-25 view-log"
|
||||
data-description="'.$log->description.'"
|
||||
data-user="'.($log->causer->name ?? 'System').'"
|
||||
data-time="'.$log->created_at.'"
|
||||
data-module="'.class_basename($log->subject_type).'"
|
||||
data-log=\''.json_encode($log->properties).'\'>
|
||||
<span class="fa fa-file-text-o"></span>
|
||||
</button>';
|
||||
|
||||
})
|
||||
|
||||
->rawColumns(['created_at','action'])
|
||||
|
||||
->make(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
101
app/Http/Controllers/AntibioticController.php
Normal file
101
app/Http/Controllers/AntibioticController.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\TestSampleCreateRequest;
|
||||
use App\Http\Resources\AntibioticResource;
|
||||
use App\Models\Antibiotic;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Organism;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\SampleType;
|
||||
use App\Models\Test;
|
||||
use App\Models\TestNormalValue;
|
||||
use App\Models\TestSample;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class AntibioticController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
protected $departments;
|
||||
|
||||
public function __construct(Antibiotic $antibioticModel){
|
||||
$this->model = $antibioticModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_antibiotic'])) return redirect(url('my-profile'));
|
||||
$antibiotics = $this->model::with(['lab'])->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(!empty($request->kword), function ($antibiotics) use($request){
|
||||
$antibiotics->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('antibiotic', ['antibiotics' => AntibioticResource::collection($antibiotics)]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_antibiotic'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('antibiotic.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$antibiotic = $this->model::query()->create([ 'name_en' => $request->name_en, 'weight' => $request->weight]);
|
||||
return response()->json(['success' => true, 'message' => __('antibiotic.create_success'), 'data' => [$antibiotic]]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('antibiotic.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_antibiotic'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('antibiotic.update_fail'), 'errors' => $e->getMessage()]);
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'weight' => $request->weight
|
||||
);
|
||||
$this->model::query()->where('id', $request->uid)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('antibiotic.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('antibiotic.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$antibiotic = $this->model::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('antibiotic.get_success'), 'data' => new AntibioticResource($antibiotic)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('antibiotic.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_antibiotic'])) return false;
|
||||
$this->model::query()->where('id', $request->uid)->update(array('record_status_id'=> RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('antibiotic.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('antibiotic.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array('record_status_id'=> RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('antibiotic.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('antibiotic.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
37
app/Http/Controllers/Api/AuthController.php
Normal file
37
app/Http/Controllers/Api/AuthController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login(Request $request)
|
||||
{
|
||||
$credentials = $request->only('email', 'password'); // or 'username' if you use that
|
||||
|
||||
//if($request->client_id != env('ANALYZER_CLIENT_ID') || $request->client_secret != env('ANALYZER_CLIENT_SECRET')){
|
||||
// return response()->json(['error' => 'Invalid credentials'], 401);
|
||||
//}
|
||||
|
||||
if (!Auth::attempt($credentials)) {
|
||||
return response()->json(['error' => 'Invalid credentials'], 401);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
$token = $user->createToken('api-token')->accessToken;
|
||||
return response()->json([
|
||||
'token_type' => 'Bearer',
|
||||
'expires_in' => 1800,
|
||||
'access_token' => $token,
|
||||
]);
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$request->user()->token()->delete();
|
||||
return response()->json(['message' => 'Logged out successfully']);
|
||||
}
|
||||
}
|
||||
64
app/Http/Controllers/Api/SampleResultController.php
Normal file
64
app/Http/Controllers/Api/SampleResultController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Sample;
|
||||
use App\Models\TestResult;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SampleResultController extends Controller
|
||||
{
|
||||
//
|
||||
protected $sampleModel;
|
||||
protected $testResultModel;
|
||||
public function __construct(){
|
||||
$this->sampleModel = new Sample();
|
||||
$this->testResultModel = new TestResult();
|
||||
}
|
||||
|
||||
public function pushLabResult(Request $request){
|
||||
try{
|
||||
$validator = \Validator::make($request->all(), ['message.pid' => 'required', 'message.result' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('Some variables are requires'), 'errors' => $validator->errors()->all()]);
|
||||
$testSamples = collect($this->getSampleTest($request->message['pid']));
|
||||
|
||||
if(!empty($testSamples)) {
|
||||
foreach ($request->message['result'] as $row) {
|
||||
if (!empty($row['code']) && !empty($row['value'])) {
|
||||
$resultRecord = $testSamples->filter(function ($val, $key) use ($row) {
|
||||
return $val->code == $row['code'];
|
||||
})->first();
|
||||
if(!empty($resultRecord)){
|
||||
$data = array(
|
||||
'test_result' => $row['value'],
|
||||
'test_date' => date('Y-m-d'),
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
);
|
||||
$this->testResultModel::query()->where(['id' => $resultRecord->result_id])->update($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json(['success' => true, 'message' => __('Laboratory result already pushed!')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('Failed while pushing laboratory result!'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getSampleTest( $sampleNumber){
|
||||
return DB::select("SELECT
|
||||
s.id,
|
||||
tr.id as result_id,
|
||||
tr.test_sample_id,
|
||||
tr.test_result,
|
||||
ts.code,
|
||||
ts.`unit_sign`
|
||||
FROM samples s
|
||||
INNER JOIN test_results tr ON tr.`sample_id` = s.`id` AND tr.`record_status_id` = 1
|
||||
INNER JOIN test_samples ts ON ts.`id` = tr.`test_sample_id`
|
||||
WHERE s.`sample_number` = '".$sampleNumber."'");
|
||||
}
|
||||
|
||||
}
|
||||
117
app/Http/Controllers/AppointmentController.php
Normal file
117
app/Http/Controllers/AppointmentController.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\ConceptCode;
|
||||
use App\Models\Patient;
|
||||
use App\Models\Physician;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class AppointmentController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $patientModel;
|
||||
protected $baseLabId;
|
||||
|
||||
protected $physicianModel;
|
||||
|
||||
public function __construct(){
|
||||
$this->model = new Appointment();
|
||||
$this->patientModel = new Patient();
|
||||
$this->physicianModel = new Physician();
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_appointment'])) return redirect(url('my-profile'));
|
||||
$conceptCodes = $this->model::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->groupBy('appointment_type')->get('appointment_type');
|
||||
$patients = $this->patientModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => BaseModel::RECORD_STATUS_ACTIVE])->limit(20)->get();
|
||||
$physicians = $this->physicianModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->orderBy('name_en', 'ASC')->get();
|
||||
$appointments = $this->model::with(['patient', 'doctor'])->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->appointment_type), function ($query) use($request){
|
||||
$query->where('appointment_type', $request->appointment_type);
|
||||
})->when(!empty($request->appointment_date), function ($query) use($request) {
|
||||
$query->whereDate('appointment_date', date('Y-m-d', strtotime($request->appointment_date)));
|
||||
})->orderBy('appointment_date','desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('appointment', ['appointments' => $appointments, 'conceptCodes' => $conceptCodes, 'patients' => $patients, 'patient_id' => 0, 'physicians' => $physicians]);
|
||||
}
|
||||
|
||||
public function store(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_appointment'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['patient_id' => 'required', 'appointment_date' => 'required', 'appointment_type' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('appointment.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
|
||||
$app=new Appointment();
|
||||
$app->patient_id=$request->patient_id;
|
||||
$app->appointment_date=date('Y-m-d H:i:s', strtotime($request->appointment_date));
|
||||
$app->appointment_type=$request->appointment_type;
|
||||
$app->description=$request->description;
|
||||
$app->doctor_id=$request->doctor_id;
|
||||
$app->lab_id=$this->baseLabId;
|
||||
$app->save();
|
||||
return response()->json(['success' => true, 'message' => __('appointment.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('appointment.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try {
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_appointment'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['patient_id' => 'required', 'appointment_date' => 'required', 'appointment_type' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('appointment.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$app=Appointment::find($request->uid);
|
||||
$app->appointment_date=date('Y-m-d H:i:s', strtotime($request->appointment_date));
|
||||
$app->appointment_type=$request->appointment_type;
|
||||
$app->description=$request->description;
|
||||
$app->doctor_id=$request->doctor_id;
|
||||
$app->lab_id=$this->baseLabId;
|
||||
$app->save();
|
||||
return response()->json(['success' => true, 'message' => __('appointment.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('appointment.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$test = $this->model::query()->where(['lab_id' => $this->baseLabId, 'id' => $request->uid])->get()->first();
|
||||
return response()->json(['success' => true, 'message' => __('appointment.get_success'), 'data' => $test]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('appointment.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_appointment'])) return false;
|
||||
$this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('appointment.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('appointment.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAlertNofication(){
|
||||
try{
|
||||
$appointments = $this->model::with(['patient:id,name_en,phone_number', 'doctor:id,name_en'])->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->whereBetween('appointment_date', [Carbon::today(), Carbon::today()->addDays(2)])->orderBy('appointment_date','desc')->get();
|
||||
$count = $appointments->count();
|
||||
return response()->json(['success' => true, 'message' => __('appointment.get_success'), 'data' => $appointments, 'count' => $count]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('appointment.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
48
app/Http/Controllers/Auth/AuthController.php
Normal file
48
app/Http/Controllers/Auth/AuthController.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Session;
|
||||
use Hash;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Write code on Method
|
||||
*
|
||||
* @return response()
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required',
|
||||
'password' => 'required',
|
||||
]);
|
||||
|
||||
$credentials = $request->only('UserName', 'Password');
|
||||
dd('sda');
|
||||
|
||||
if (auth()->attempt($credentials)) {
|
||||
return redirect()->route('homepage');
|
||||
|
||||
}else{
|
||||
session()->flash('error', 'Invalid credentials');
|
||||
return redirect()->route('login');
|
||||
|
||||
}
|
||||
|
||||
|
||||
//return redirect("login")->withSuccess('Oppes! You have entered invalid credentials');
|
||||
}
|
||||
|
||||
/**
|
||||
* Write code on Method
|
||||
*
|
||||
* @return response()
|
||||
*/
|
||||
|
||||
}
|
||||
72
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Normal file
72
app/Http/Controllers/Auth/AuthenticatedSessionController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//return view('auth.login');
|
||||
return view('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*
|
||||
* @param \App\Http\Requests\Auth\LoginRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(LoginRequest $request)
|
||||
{
|
||||
$request->authenticate();
|
||||
activity()
|
||||
->causedBy(Auth::user())
|
||||
->withProperties([
|
||||
'ip' => request()->ip(),
|
||||
'browser' => request()->userAgent()
|
||||
])
|
||||
->log('User Login');
|
||||
|
||||
$request->session()->regenerate();
|
||||
if (!$request->session()->has('base_lab_id')) {
|
||||
return redirect()->route('base');
|
||||
}
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
activity()
|
||||
->causedBy(Auth::user())
|
||||
->withProperties([
|
||||
'ip' => request()->ip(),
|
||||
'browser' => request()->userAgent()
|
||||
])
|
||||
->log('User Logout');
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
44
app/Http/Controllers/Auth/ConfirmablePasswordController.php
Normal file
44
app/Http/Controllers/Auth/ConfirmablePasswordController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
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(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME);
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(RouteServiceProvider::HOME)
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
65
app/Http/Controllers/Auth/NewPasswordController.php
Normal file
65
app/Http/Controllers/Auth/NewPasswordController.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$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) 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)]);
|
||||
}
|
||||
}
|
||||
47
app/Http/Controllers/Auth/PasswordResetLinkController.php
Normal file
47
app/Http/Controllers/Auth/PasswordResetLinkController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$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)]);
|
||||
}
|
||||
}
|
||||
54
app/Http/Controllers/Auth/RegisteredUserController.php
Normal file
54
app/Http/Controllers/Auth/RegisteredUserController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'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(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
30
app/Http/Controllers/Auth/VerifyEmailController.php
Normal file
30
app/Http/Controllers/Auth/VerifyEmailController.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Auth\EmailVerificationRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request)
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
|
||||
}
|
||||
}
|
||||
73
app/Http/Controllers/BaseController.php
Normal file
73
app/Http/Controllers/BaseController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Enums\UtilEnum;
|
||||
use App\Models\AgeGroup;
|
||||
use App\Models\Department;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Models\UserLabCover;
|
||||
use App\Models\WardTransaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Laboratory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class BaseController extends Controller
|
||||
{
|
||||
|
||||
function getLabs(){
|
||||
return parent::getAccessAbleLabs();
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
$labs = Laboratory::query()->where('record_status_id', RecordStatusEnum::ACTIVE)
|
||||
->whereIn('id', $this->getLabs()->pluck('id')->toArray())
|
||||
->orderBy('created_at','desc')->get();
|
||||
|
||||
$request->session()->put('base_lab_coverages', $labs->pluck('name_en')->toArray());
|
||||
|
||||
// check it only one base default assign base session, else redirect to base view
|
||||
if(count($labs)==1){
|
||||
$request->session()->put('base_lab_id', $labs->first()->id);
|
||||
$request->session()->put('base_lab_name', $labs->first()->name_en);
|
||||
$request->session()->put('base_lab', $labs[0]->toArray());
|
||||
if ($request->session()->has('base_lab_id')) {
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
}
|
||||
return view('base', ['labs' => $labs]);
|
||||
}
|
||||
|
||||
public function forget(Request $request){
|
||||
if ($request->session()->has('base_lab_id')) {
|
||||
$request->session()->forget('base_lab_id');
|
||||
$request->session()->forget('base_lab_name');
|
||||
$request->session()->forget('base_lab');
|
||||
$request->session()->forget('base_lab');
|
||||
$request->session()->forget('base_lab_coverages');
|
||||
return redirect()->route('base');
|
||||
}
|
||||
}
|
||||
|
||||
public function store(Request $request){
|
||||
$validator = \Validator::make($request->all(), [ 'lab_id' => 'required']);
|
||||
if ($validator->fails())
|
||||
{
|
||||
session()->flash('error', 'Invalid credentials');
|
||||
return redirect()->route('base');
|
||||
}
|
||||
$lab = Laboratory::query()->find($request->lab_id);
|
||||
$request->session()->put('base_lab_id', $request->lab_id);
|
||||
$request->session()->put('base_lab_name', $lab->name_en);
|
||||
$request->session()->put('base_lab', $lab->toArray());
|
||||
if (!$request->session()->has('base_lab_id')) {
|
||||
return redirect()->route('base');
|
||||
}
|
||||
return redirect('/dashboard');
|
||||
}
|
||||
}
|
||||
112
app/Http/Controllers/CommentController.php
Normal file
112
app/Http/Controllers/CommentController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\TestSampleCreateRequest;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Department;
|
||||
use App\Models\Organism;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\Quantity;
|
||||
use App\Models\SampleType;
|
||||
use App\Models\Test;
|
||||
use App\Models\TestNormalValue;
|
||||
use App\Models\TestSample;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
protected $department;
|
||||
|
||||
public function __construct(Comment $comment, Department $department){
|
||||
$this->model = $comment;
|
||||
$this->department = $department;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_comment'])) return redirect(url('my-profile'));
|
||||
$departments = $this->department::query()->where(['lab_id' => Session::get('base_lab_id'), BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->orderBy('name_en','asc')->get();
|
||||
$recordStatusCondition = Auth::id()==1 ? [RecordStatusEnum::DELETE, RecordStatusEnum::ACTIVE] : [RecordStatusEnum::ACTIVE];
|
||||
$comments = $this->model::with(['sample_type','sample_type.department'])->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusCondition)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->kword), function ($comments) use($request){
|
||||
$comments->whereRaw("replace(comment_desc, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('comment', ['comments' => $comments, 'departments' => $departments]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_comment'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['comment_desc' => 'required', 'sample_type_id' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('comment.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
foreach ($request->sample_type_id as $sample_type) {
|
||||
$comment = $this->model::query()->create([
|
||||
'comment_desc' => $request->comment_desc,
|
||||
'sample_type_id' => $sample_type,
|
||||
'lab_id' => $this->baseLabId
|
||||
]);
|
||||
}
|
||||
return response()->json(['success' => true, 'message' => __('comment.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try {
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_comment'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['comment_desc' => 'required', 'sample_type_id' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('comment.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'comment_desc' => $request->comment_desc,
|
||||
'sample_type_id' => $request->sample_type_id
|
||||
);
|
||||
$this->model::query()->where('id', $request->uid)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('comment.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$test = $this->model::with('sample_type')->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('comment.get_success'), 'data' => $test]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_comment'])) return false;
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('comment.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('comment.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
93
app/Http/Controllers/Controller.php
Normal file
93
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Commune;
|
||||
use App\Models\District;
|
||||
use App\Models\Laboratory;
|
||||
use App\Models\Province;
|
||||
use App\Models\UserLabCover;
|
||||
use App\Models\Village;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
function getAccessAbleLabs(){
|
||||
$recordStatusCondition = Auth::id()==1 ? [RecordStatusEnum::DELETE, RecordStatusEnum::ACTIVE] : [RecordStatusEnum::ACTIVE];
|
||||
$labs = Laboratory::query()->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusCondition)->get();
|
||||
if(Auth::id()!=1){
|
||||
$labIds = UserLabCover::query()->where('user_id', Auth::id())->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)->pluck('lab_id')->toArray();
|
||||
$labs = $labs->whereIn('id', $labIds);
|
||||
}
|
||||
return $labs;
|
||||
}
|
||||
|
||||
function province(){
|
||||
return Province::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)->get(['id','name_en','name_kh']);
|
||||
}
|
||||
|
||||
function district($province_id = null){
|
||||
return District::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(! is_null($province_id), function ($district) use($province_id){
|
||||
$district->where('province_id', $province_id);
|
||||
})->orderBy('name_en','asc')->get(['id','name_en','name_kh']);
|
||||
}
|
||||
|
||||
function commune($district_id = null){
|
||||
return Commune::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(!is_null($district_id), function ($commune) use($district_id){
|
||||
$commune->where('district_id', $district_id);
|
||||
})->orderBy('name_en','asc')->get(['id','name_en','name_kh']);
|
||||
}
|
||||
|
||||
function village($commune_id = null){
|
||||
return Village::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(!is_null($commune_id), function ($village) use($commune_id){
|
||||
$village->where('commune_id', $commune_id);
|
||||
})->orderBy('name_en','asc')->get(['id','name_en','name_kh']);
|
||||
}
|
||||
|
||||
public function location(){
|
||||
// discount_type = [1 => '%', 2 => 'USD']
|
||||
return Laboratory::query()->find(Session::get('base_lab_id'))->only([
|
||||
'name_en',
|
||||
'name_kh',
|
||||
'short_name',
|
||||
'sample_number',
|
||||
'patient_code',
|
||||
'verify_label',
|
||||
'technician_label',
|
||||
'discount_type',
|
||||
'logo',
|
||||
'address_kh',
|
||||
'address_en',
|
||||
'phone_number',
|
||||
'email',
|
||||
'shareable_lab_result',
|
||||
'result_header_id',
|
||||
'show_result_footer',
|
||||
'abnormal_result_font_weight',
|
||||
'abnormal_text_color',
|
||||
'exchange_rate',
|
||||
'lab_category_id',
|
||||
'currency',
|
||||
'is_hide_inv_discount',
|
||||
'is_hide_comission_percentage',
|
||||
'invoice_template_id',
|
||||
'alternative_logo'
|
||||
]);
|
||||
}
|
||||
|
||||
// public function switchLanguage($locale)
|
||||
// {
|
||||
// if (array_key_exists($locale, config('app.available_locales'))) {
|
||||
// session(['locale' => $locale]);
|
||||
// }
|
||||
// return redirect()->back();
|
||||
// }
|
||||
|
||||
}
|
||||
630
app/Http/Controllers/DashboardController.php
Normal file
630
app/Http/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,630 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Sample;
|
||||
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
protected $sampleModel;
|
||||
protected $invoiceModel;
|
||||
private $baseLabId;
|
||||
protected $base;
|
||||
|
||||
public function __construct(Sample $sampleModel, Invoice $invoiceModel){
|
||||
$this->sampleModel = $sampleModel;
|
||||
$this->invoiceModel = $invoiceModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
|
||||
}
|
||||
|
||||
function index(Request $q){
|
||||
return redirect(url('my-profile'));
|
||||
$growthSample = 0;
|
||||
$displaySample = '';
|
||||
$displaySampleResult = 0;
|
||||
$growthIncome = 0;
|
||||
$displayIncome = '';
|
||||
$displayIncomeResult = 0;
|
||||
$growthPatient = 0;
|
||||
$displayPatient = '';
|
||||
$displayPatientResult = 0;
|
||||
$totalRejectedSample = $this->getTotalRejectedSampleCount();
|
||||
|
||||
$growthRejectedSample = 0;
|
||||
|
||||
$todaySamples = $this->getTodaySamples();
|
||||
$yesterdaySample = $this->getYesterdaySampleCount();
|
||||
if($yesterdaySample>0){
|
||||
$growthIncome = (($todaySamples->count() - $yesterdaySample) / $yesterdaySample) * 100;
|
||||
}
|
||||
$displaySample=__('general.chart_filter_today');
|
||||
$displaySampleResult = $todaySamples->count();
|
||||
|
||||
//income
|
||||
$todayIncome = $this->getTodayIncome();
|
||||
$todayIncome+=$this->getDailyReportV2(date('Y-m-d'), date('Y-m-d'));
|
||||
$yesterdayIncome = $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDate('invoice_date', date('Y-m-d', strtotime('-1 day')))->sum('gross_total');
|
||||
$yesterdayIncome+=$this->getDailyReportV2(date('Y-m-d', strtotime('-1 day')), date('Y-m-d', strtotime('-1 day')));
|
||||
if($yesterdayIncome>0){
|
||||
$growthIncome = (($todayIncome - $yesterdayIncome) / $yesterdayIncome) * 100;
|
||||
}
|
||||
$displayIncome=__('general.chart_filter_today');
|
||||
$displayIncomeResult = number_format($todayIncome);
|
||||
|
||||
//disaplay patient
|
||||
$todayPatient = $this->getTodayPatient();
|
||||
$yesterdayPatient = $this->getYesterdayPatient();
|
||||
if($yesterdayPatient>0){
|
||||
$growthPatient = (($todayPatient - $yesterdayPatient) / $yesterdayPatient) * 100;
|
||||
}
|
||||
$displayPatient=__('general.chart_filter_today');
|
||||
$displayPatientResult = $todayPatient;
|
||||
|
||||
$todayRejectedSample = $this->getTodayRejectedSamples()->count();
|
||||
$yesterdayRejectedSample = $this->getYesterdayRejectedSamples()->count();
|
||||
if($yesterdayRejectedSample>0){
|
||||
$growthRejectedSample = (($todayRejectedSample - $yesterdayRejectedSample) / $yesterdayRejectedSample) * 100;
|
||||
}
|
||||
$displayRejectedSample=__('general.chart_filter_today');
|
||||
$displayRejectedSampleResult = $todayRejectedSample;
|
||||
|
||||
return view('dashboard',[
|
||||
'growthSample' => number_format($growthSample, 2),
|
||||
'totalSample' => $displaySampleResult,
|
||||
'displaySample' => $displaySample,
|
||||
'displaySampleResult' => $displaySampleResult,
|
||||
'growthIncome' => number_format($growthIncome, 2),
|
||||
'displayIncome' => $displayIncome,
|
||||
'displayIncomeResult' => $displayIncomeResult,
|
||||
'totalIncome' => $displayIncomeResult,
|
||||
'totalPatient' => $displayPatientResult,
|
||||
'growthPatient' => number_format($growthPatient, 2),
|
||||
'displayPatient' => $displayPatient,
|
||||
'displayPatientResult' => $displayPatientResult,
|
||||
'totalRejectedSample' => $totalRejectedSample,
|
||||
'growthRejectedSample' => number_format($growthRejectedSample, 2),
|
||||
'displayRejectedSample' => $displayRejectedSample,
|
||||
'displayRejectedSampleResult' => $displayRejectedSampleResult,
|
||||
|
||||
'labSettings' => (object) $this->base
|
||||
]);
|
||||
}
|
||||
|
||||
function filter_sample(Request $q)
|
||||
{
|
||||
$growthSample = 0;
|
||||
if ($q->dt == 'this_month'){
|
||||
$monlthlySample= $this->getThisMonthSamples()->count();
|
||||
$last_monthSample = $this->getPreviousMonthSamples()->count();
|
||||
if($last_monthSample>0){
|
||||
$growthSample = (($monlthlySample - $last_monthSample) / $last_monthSample) * 100;
|
||||
}
|
||||
$displaySample=__('general.chart_filter_this_month');
|
||||
$displaySampleResult = $monlthlySample;
|
||||
|
||||
} elseif ($q->dt == 'this_year'){
|
||||
$yearSamples = $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereYear('admission_date', date('Y'))->count();
|
||||
$last_yearSample = $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereYear('admission_date', (date('Y')-1))->count();
|
||||
if($last_yearSample>0){
|
||||
$growthSample = (($yearSamples - $last_yearSample) / $last_yearSample);
|
||||
}
|
||||
$displaySample=__('general.chart_filter_this_year');
|
||||
$displaySampleResult = $yearSamples;
|
||||
}
|
||||
else{
|
||||
$todaySamples = $this->getTodaySamples();
|
||||
$yesterdaySample = $this->getYesterdaySampleCount();
|
||||
if($yesterdaySample>0){
|
||||
$growthSample = (($todaySamples->count() - $yesterdaySample) / $yesterdaySample) * 100;
|
||||
}
|
||||
$displaySample=__('general.chart_filter_today');
|
||||
$displaySampleResult = $todaySamples->count();
|
||||
}
|
||||
return response()->json([
|
||||
'growthSample' => number_format($growthSample, 2),
|
||||
'displaySample' => $displaySample,
|
||||
'displaySampleResult' => $displaySampleResult
|
||||
]);
|
||||
}
|
||||
|
||||
function filter_income(Request $q){
|
||||
$growthIncome = 0;
|
||||
if ($q->dt == 'this_month'){
|
||||
$monlthlyIncome= $this->getThisMonthIncome();
|
||||
$monlthlyIncome+=$this->getDailyReportV2(date('Y-m-01'), date('Y-m-t'));
|
||||
$last_monthIncome = $this->getPreviousMonthIncome();
|
||||
$last_monthIncome+=$this->getDailyReportV2(date("Y-m-d", mktime(0, 0, 0, date("m")-1, 1)), date("Y-m-d", mktime(0, 0, 0, date("m"), 0)));
|
||||
if($last_monthIncome>0){
|
||||
$growthIncome = (($monlthlyIncome - $last_monthIncome) / $last_monthIncome) * 100;
|
||||
}
|
||||
$displayIncome=__('general.chart_filter_this_month');
|
||||
$displayIncomeResult = number_format($monlthlyIncome);
|
||||
|
||||
} elseif ($q->dt == 'this_year'){
|
||||
$yearIncome = $this->getLastYearIncome();
|
||||
$yearIncome+=$this->getDailyReportV2(date("Y-m-d",strtotime("last year January 1st")), date("Y-m-d",strtotime("last year December 31st")));
|
||||
$last_yearIncome = $this->getLastYearIncome();
|
||||
$last_yearIncome+=$this->getDailyReportV2(date("Y-m-d",strtotime("-2 year January 1st")), date("Y-m-d",strtotime("-2 year December 31st")));
|
||||
if($last_yearIncome>0){
|
||||
$growthIncome = (($yearIncome - $last_yearIncome) / $last_yearIncome) * 100;
|
||||
}
|
||||
$displayIncome=__('general.chart_filter_this_year');
|
||||
$displayIncomeResult = number_format($yearIncome);
|
||||
}
|
||||
else{
|
||||
$todayIncome = $this->getTodayIncome();
|
||||
$todayIncome+=$this->getDailyReportV2(date('Y-m-d'), date('Y-m-d'));
|
||||
$yesterdayIncome = $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDate('invoice_date', date('Y-m-d', strtotime('-1 day')))->sum('gross_total');
|
||||
$yesterdayIncome+=$this->getDailyReportV2(date('Y-m-d', strtotime('-1 day')), date('Y-m-d', strtotime('-1 day')));
|
||||
if($yesterdayIncome>0){
|
||||
$growthIncome = (($todayIncome - $yesterdayIncome) / $yesterdayIncome) * 100;
|
||||
}
|
||||
$displayIncome=__('general.chart_filter_today');
|
||||
$displayIncomeResult = number_format($todayIncome);
|
||||
}
|
||||
return response()->json([
|
||||
'growthIncome' => number_format($growthIncome, 2),
|
||||
'displayIncome' => $displayIncome,
|
||||
'displayIncomeResult' => $displayIncomeResult
|
||||
]);
|
||||
}
|
||||
|
||||
function filter_patient(Request $q)
|
||||
{
|
||||
$growthPatient = 0;
|
||||
if ($q->dt == 'this_month'){
|
||||
$monthlyPatient= $this->getThisMonthPatient();
|
||||
$last_monthPatient = $this->getPreviousMonthPatient();
|
||||
if($last_monthPatient>0){
|
||||
$growthPatient = (($monthlyPatient - $last_monthPatient) / $last_monthPatient) * 100;
|
||||
}
|
||||
$displayPatient=__('general.chart_filter_this_month');
|
||||
$displayPatientResult = $monthlyPatient;
|
||||
|
||||
} elseif ($q->dt == 'this_year'){
|
||||
$yearPatient = $this->getThisYearPatient();
|
||||
$last_yearPatient = $this->getLastYearPatient();
|
||||
if($last_yearPatient>0){
|
||||
$growthPatient = (($yearPatient - $last_yearPatient) / $last_yearPatient) * 100;
|
||||
}
|
||||
$displayPatient=__('general.chart_filter_this_year');
|
||||
$displayPatientResult = $yearPatient;
|
||||
}
|
||||
else{
|
||||
$todayPatient = $this->getTodayPatient();
|
||||
$yesterdayPatient = $this->getYesterdayPatient();
|
||||
if($yesterdayPatient>0){
|
||||
$growthPatient = (($todayPatient - $yesterdayPatient) / $yesterdayPatient) * 100;
|
||||
}
|
||||
$displayPatient=__('general.chart_filter_today');
|
||||
$displayPatientResult = $todayPatient;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'growthPatient' => number_format($growthPatient, 2),
|
||||
'displayPatient' => $displayPatient,
|
||||
'displayPatientResult' => $displayPatientResult
|
||||
]);
|
||||
}
|
||||
|
||||
function filter_rejected_sample(Request $q)
|
||||
{
|
||||
$growthRejectedSample = 0;
|
||||
if ($q->dt == 'this_month'){
|
||||
$monthlyRejectedSample= $this->getThisMonthRejectedSamples()->count();
|
||||
$last_monthRejectedSample = $this->getPreviousMonthRejectedSamples()->count();
|
||||
if($last_monthRejectedSample>0){
|
||||
$growthRejectedSample = (($monthlyRejectedSample - $last_monthRejectedSample) / $last_monthRejectedSample) * 100;
|
||||
}
|
||||
$displayRejectedSample=__('general.chart_filter_this_month');
|
||||
$displayRejectedSampleResult = $monthlyRejectedSample;
|
||||
|
||||
} elseif ($q->dt == 'this_year'){
|
||||
$yearRejectedSample = $this->getThisYearRejectedSamples()->count();
|
||||
$last_yearRejectedSample = $this->getLastYearRejectedSamples()->count();
|
||||
if($last_yearRejectedSample>0){
|
||||
$growthRejectedSample = (($yearRejectedSample - $last_yearRejectedSample) / $last_yearRejectedSample) * 100;
|
||||
}
|
||||
$displayRejectedSample=__('general.chart_filter_this_year');
|
||||
$displayRejectedSampleResult = $yearRejectedSample;
|
||||
}
|
||||
else{
|
||||
$todayRejectedSample = $this->getTodayRejectedSamples()->count();
|
||||
$yesterdayRejectedSample = $this->getYesterdayRejectedSamples()->count();
|
||||
if($yesterdayRejectedSample>0){
|
||||
$growthRejectedSample = (($todayRejectedSample - $yesterdayRejectedSample) / $yesterdayRejectedSample) * 100;
|
||||
}
|
||||
$displayRejectedSample=__('general.chart_filter_today');
|
||||
$displayRejectedSampleResult = $todayRejectedSample;
|
||||
}
|
||||
return response()->json([
|
||||
'growthRejectedSample' => number_format($growthRejectedSample, 2),
|
||||
'displayRejectedSample' => $displayRejectedSample,
|
||||
'displayRejectedSampleResult' => $displayRejectedSampleResult
|
||||
]);
|
||||
}
|
||||
|
||||
//get total sample count for dashboard by lab id
|
||||
|
||||
function getTotalRejectedSampleCount(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('sample_condition', 0)->count();
|
||||
}
|
||||
|
||||
function getTodayRejectedSamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('sample_condition', 0)
|
||||
->whereDate('admission_date', date('Y-m-d'))->get();
|
||||
}
|
||||
|
||||
function getYesterdayRejectedSamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('sample_condition', 0)
|
||||
->whereDate('admission_date', date('Y-m-d', strtotime('-1 day')))->get();
|
||||
}
|
||||
|
||||
function getThisMonthRejectedSamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('sample_condition', 0)
|
||||
->whereBetween('admission_date', [date('Y-m-01 00:00:00'), date('Y-m-t 23:59:59')])->get();
|
||||
}
|
||||
|
||||
function getPreviousMonthRejectedSamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('sample_condition', 0)
|
||||
->whereBetween('admission_date', [date("Y-m-d 00:00:00", strtotime("first day of previous month")), date("Y-m-d 23:59:59", strtotime("last day of previous month"))])->get();
|
||||
}
|
||||
|
||||
function getThisYearRejectedSamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('sample_condition', 0)
|
||||
->whereYear('admission_date', date('Y'))->get();
|
||||
}
|
||||
|
||||
function getLastYearRejectedSamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('sample_condition', 0)
|
||||
->whereYear('admission_date', (date('Y')-1))->get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function getTotalSampleCount(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->count();
|
||||
}
|
||||
|
||||
//get yesterday sample count for dashboard by lab id
|
||||
|
||||
function getYesterdaySampleCount(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDate('admission_date', date('Y-m-d', strtotime('-1 day')))->count();
|
||||
}
|
||||
|
||||
function getTodaySamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDate('admission_date', date('Y-m-d'))->get();
|
||||
}
|
||||
|
||||
function getThisMonthSamples(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('admission_date', [date('Y-m-01 00:00:00'), date('Y-m-t 23:59:59')])->get();
|
||||
}
|
||||
|
||||
function getPreviousMonthSamples(){
|
||||
return $this->sampleModel::with(['patient'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('admission_date', [date("Y-m-d 00:00:00", strtotime("first day of previous month")), date("Y-m-d 23:59:59", strtotime("last day of previous month"))])->get();
|
||||
}
|
||||
|
||||
function getLastYearAverage(){
|
||||
return $this->sampleModel::with(['patient'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('admission_date', [date('Y-01-01 00:00:00', strtotime('-1 year')), date('Y-12-31 23:59:59', strtotime('-1 year'))])->count();
|
||||
}
|
||||
|
||||
function getTodayIncome(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDate('invoice_date', date('Y-m-d'))->sum('gross_total');
|
||||
}
|
||||
|
||||
function getThisMonthIncome(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('invoice_date', [date('Y-m-01 00:00:00'), date('Y-m-t 23:59:59')])->sum('gross_total');
|
||||
}
|
||||
|
||||
function getPreviousMonthIncome(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('invoice_date', [date("Y-m-d 00:00:00", strtotime("first day of previous month")), date("Y-m-d 23:59:59", strtotime("last day of previous month"))])->sum('gross_total');
|
||||
}
|
||||
|
||||
function getLastYearIncome(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('invoice_date', [date('Y-01-01 00:00:00', strtotime('-1 year')), date('Y-12-31 23:59:59', strtotime('-1 year'))])->sum('gross_total');
|
||||
}
|
||||
|
||||
function getTotalIncome(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->sum('gross_total');
|
||||
}
|
||||
|
||||
function getTotalPatient(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->distinct('patient_id')->count('patient_id');
|
||||
}
|
||||
|
||||
function getTodayPatient(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDate('admission_date', date('Y-m-d'))->distinct('patient_id')->count('patient_id');
|
||||
}
|
||||
|
||||
function getYesterdayPatient(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDate('admission_date', date('Y-m-d', strtotime('-1 day')))->distinct('patient_id')->count('patient_id');
|
||||
}
|
||||
|
||||
function getThisMonthPatient(){
|
||||
return $this->sampleModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('admission_date', [date('Y-m-01 00:00:00'), date('Y-m-t 23:59:59')])->distinct('patient_id')->count('patient_id');
|
||||
}
|
||||
|
||||
function getPreviousMonthPatient(){
|
||||
return $this->sampleModel::with(['patient'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('admission_date', [date("Y-m-d 00:00:00", strtotime("first day of previous month")), date("Y-m-d 23:59:59", strtotime("last day of previous month"))])->distinct('patient_id')->count('patient_id');
|
||||
}
|
||||
|
||||
function getLastYearPatient(){
|
||||
return $this->sampleModel::with(['patient'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('admission_date', [date('Y-01-01 00:00:00', strtotime('-1 year')), date('Y-12-31 23:59:59', strtotime('-1 year'))])->distinct('patient_id')->count('patient_id');
|
||||
}
|
||||
|
||||
function getThisYearPatient(){
|
||||
return $this->sampleModel::with(['patient'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereBetween('admission_date', [date('Y-01-01 00:00:00'), date('Y-12-31 23:59:59')])->distinct('patient_id')->count('patient_id');
|
||||
}
|
||||
|
||||
function getTotalInvoice(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->count();
|
||||
}
|
||||
|
||||
function getTotalPaidInvoice(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('balance', 0)->count();
|
||||
}
|
||||
|
||||
function getTotalUnpaidInvoice(){
|
||||
return $this->invoiceModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->where('balance', '>', 0)->count();
|
||||
}
|
||||
|
||||
|
||||
function getSampleSourceChart($period = 2){
|
||||
$samplePeriodCondition = " and s.lab_id = ".$this->baseLabId;
|
||||
if($period == 1) $samplePeriodCondition.= " and date(s.admission_date)='".date('Y-m-d')."'"; // today
|
||||
if($period == 2) $samplePeriodCondition.= " and s.admission_date BETWEEN '".date('Y-m-01 00:00:00')."' AND '".date('Y-m-t 23:59:59')."'"; // this month
|
||||
if($period == 3) $samplePeriodCondition.= " and s.admission_date BETWEEN '".date('Y-01-01 23:59:59')."' AND '".date('Y-12-31 23:59:59')."'"; // this year
|
||||
$sampleSourceData = DB::select("
|
||||
SELECT
|
||||
ss.`name_en` as sample_source,
|
||||
".$period." as period_type,
|
||||
ifnull(sample.total_samples, 0) as total_samples
|
||||
FROM `sample_sources` ss
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
s.`sample_source_id`,
|
||||
SUM(1) AS total_samples
|
||||
FROM samples s
|
||||
WHERE s.`record_status_id` = 1
|
||||
" . $samplePeriodCondition . "
|
||||
GROUP BY s.`sample_source_id`
|
||||
) sample
|
||||
ON sample.sample_source_id = ss.`id`
|
||||
WHERE ss.`record_status_id` = 1
|
||||
AND ss.`lab_id` = ".$this->baseLabId."
|
||||
");
|
||||
$sampleSourceDataArray = [];
|
||||
foreach ($sampleSourceData as $data){
|
||||
$sampleSourceDataArray['sample_source'][] = $data->sample_source;
|
||||
$sampleSourceDataArray['period_type'][] = ($data->period_type==1 ? date('d-m-Y') : ($data->period_type==3 ? date('Y') : date('M-Y')));
|
||||
$sampleSourceDataArray['total_samples'][] = $data->total_samples;
|
||||
}
|
||||
return $sampleSourceDataArray;
|
||||
}
|
||||
|
||||
function getSampleByYearChart(){
|
||||
$yearSamples = $this->getAggregationSampleByYear((date('Y')-1), date('Y'));
|
||||
$yearData = array();
|
||||
for ($year = date('Y'); $year>=(date('Y')-1); $year--){
|
||||
for($month = 12; $month>0; $month--){
|
||||
$yearData[$year]['month'][$month] = date('M', strtotime($year.'-'. $month.'-01'));
|
||||
$yearData[$year]['data'][$month] = 0;
|
||||
$yearData[$year]['year'][$month] = $year;
|
||||
}
|
||||
}
|
||||
foreach ($yearSamples as $data){
|
||||
$yearData[$data->year_sample]['data'][$data->month_sample] = $data->total_samples;
|
||||
}
|
||||
return $yearData;
|
||||
}
|
||||
|
||||
function getAggregationSampleByYear($fromYear, $toYear)
|
||||
{
|
||||
$sampleByYear = DB::select("SELECT
|
||||
MONTH(s.`admission_date`) AS month_sample,
|
||||
YEAR(s.`admission_date`) AS year_sample,
|
||||
SUM(1) AS total_samples
|
||||
FROM samples s
|
||||
WHERE YEAR(s.`admission_date`) between ".$fromYear." and ".$toYear."
|
||||
AND s.`record_status_id` = 1
|
||||
AND s.`lab_id` = ".$this->baseLabId."
|
||||
GROUP BY MONTH(s.`admission_date`), YEAR(s.`admission_date`) ");
|
||||
return $sampleByYear;
|
||||
}
|
||||
|
||||
|
||||
public function getDailyReportV2($startDate, $endDate){
|
||||
try{
|
||||
$rawTestByPhysician = DB::select("
|
||||
select
|
||||
r.repayment_date as `invoice_date`,
|
||||
ss.`name_en` as sample_source,
|
||||
p.`name_en` AS patient,
|
||||
s.`sample_number`,
|
||||
'' as test_name,
|
||||
r.exchange_rate,
|
||||
ps.`name_en` AS physician_name,
|
||||
sum(r.cash_repayment_amount + r.bank_repayment_amount) AS total_amount,
|
||||
0 AS total_net_amount,
|
||||
0 as discount,
|
||||
sum(r.cash_repayment_amount) as total_paid,
|
||||
sum(r.bank_repayment_amount) as total_bank_paid,
|
||||
0 as total_owe
|
||||
from repayments r
|
||||
inner join invoices inv on inv.id = r.invoice_id and r.lab_id = inv.lab_id and inv.record_status_id = 1
|
||||
inner join samples s on s.`id` = inv.`sample_id` and s.`lab_id` = inv.`lab_id` and s.`record_status_id` = 1
|
||||
inner join patients p on p.`id` = s.`patient_id` and p.`lab_id` = s.`lab_id`
|
||||
INNER JOIN sample_sources ss ON ss.id = s.`sample_source_id` AND ss.`lab_id` = s.`lab_id`
|
||||
INNER JOIN physicians ps ON ps.`id` = s.`physician_id`
|
||||
where r.`record_status_id` = 1
|
||||
AND DATE(r.repayment_date) BETWEEN '".date('Y-m-d', strtotime($startDate))."' AND '".date('Y-m-d', strtotime($endDate))."'
|
||||
and r.lab_id= ".$this->baseLabId."
|
||||
group by r.`repayment_date`,
|
||||
ss.`name_en`,
|
||||
p.`name_en`,
|
||||
s.`sample_number`,
|
||||
ps.`name_en`,
|
||||
r.exchange_rate
|
||||
order by sample_number asc
|
||||
");
|
||||
|
||||
//return $rawTestByPhysician;
|
||||
$total = collect($rawTestByPhysician)->sum('total_paid') + collect($rawTestByPhysician)->sum('total_bank_paid');
|
||||
return $total;
|
||||
} catch (\Exception $e){
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function samplesYearComparison()
|
||||
{
|
||||
$thisYear = now()->year;
|
||||
$lastYear = now()->subYear()->year;
|
||||
|
||||
$current = DB::table('samples')
|
||||
->selectRaw('MONTH(admission_date) as month, COUNT(*) as total')
|
||||
->whereYear('admission_date', $thisYear)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->groupBy('month')
|
||||
->pluck('total', 'month');
|
||||
|
||||
$previous = DB::table('samples')
|
||||
->selectRaw('MONTH(admission_date) as month, COUNT(*) as total')
|
||||
->whereYear('admission_date', $lastYear)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->groupBy('month')
|
||||
->pluck('total', 'month');
|
||||
|
||||
$trend = [];
|
||||
|
||||
for ($m = 1; $m <= 12; $m++) {
|
||||
$trend[] = [
|
||||
'month' => date('M', mktime(0, 0, 0, $m, 1)),
|
||||
'this_year' => $current[$m] ?? 0,
|
||||
'last_year' => $previous[$m] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($trend);
|
||||
}
|
||||
|
||||
public function revenueYearComparison()
|
||||
{
|
||||
$thisYear = now()->year;
|
||||
$lastYear = now()->subYear()->year;
|
||||
|
||||
$current = DB::table('invoices')
|
||||
->selectRaw('MONTH(invoice_date) as month, SUM(gross_total) as total')
|
||||
->whereYear('invoice_date', $thisYear)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->groupBy('month')
|
||||
->pluck('total', 'month');
|
||||
|
||||
$previous = DB::table('invoices')
|
||||
->selectRaw('MONTH(invoice_date) as month, SUM(gross_total) as total')
|
||||
->whereYear('invoice_date', $lastYear)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->groupBy('month')
|
||||
->pluck('total', 'month');
|
||||
|
||||
$trend = [];
|
||||
|
||||
for ($m = 1; $m <= 12; $m++) {
|
||||
$trend[] = [
|
||||
'month' => date('M', mktime(0, 0, 0, $m, 1)),
|
||||
'this_year' => $current[$m] ?? 0,
|
||||
'last_year' => $previous[$m] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
return response()->json($trend);
|
||||
}
|
||||
|
||||
function getSampleSourceByDistributor(){
|
||||
$thisYear = now()->year;
|
||||
$sampleSourceData = DB::select("
|
||||
SELECT
|
||||
ss.`name_en` as sample_source,
|
||||
ifnull(sample.total_samples, 0) as total_samples
|
||||
FROM `sample_sources` ss
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
s.`sample_source_id`,
|
||||
SUM(1) AS total_samples
|
||||
FROM samples s
|
||||
WHERE s.`record_status_id` = 1
|
||||
and year(s.admission_date) = ".$thisYear."
|
||||
AND s.lab_id = ".$this->baseLabId."
|
||||
GROUP BY s.`sample_source_id`
|
||||
|
||||
) sample
|
||||
ON sample.sample_source_id = ss.`id`
|
||||
WHERE ss.`record_status_id` = 1
|
||||
AND ss.`lab_id` = ".$this->baseLabId."
|
||||
ORDER BY total_samples DESC
|
||||
LIMIT 10
|
||||
");
|
||||
return response()->json($sampleSourceData);
|
||||
}
|
||||
|
||||
function getPanelDistributor(){
|
||||
$thisYear = now()->year;
|
||||
$samplePanelData = DB::select("SELECT
|
||||
d.`name_en` AS panel,
|
||||
IFNULL(sample.total_samples, 0) AS total_samples
|
||||
FROM `departments` d
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
st.department_id,
|
||||
SUM(1) AS total_samples
|
||||
FROM samples s
|
||||
INNER JOIN test_results tr ON tr.`sample_id` = s.`id` AND tr.`record_status_id`= 1
|
||||
INNER JOIN test_samples ts ON ts.id = tr.`test_sample_id`
|
||||
INNER JOIN sample_types st ON st.id = ts.`sample_type_id`
|
||||
INNER JOIN departments sd ON sd.id = st.`department_id`
|
||||
WHERE s.`record_status_id` = 1
|
||||
and year(s.admission_date) = ".$thisYear."
|
||||
AND s.lab_id = ".$this->baseLabId."
|
||||
GROUP BY st.`department_id`
|
||||
|
||||
) sample
|
||||
ON sample.department_id = d.`id`
|
||||
WHERE d.`record_status_id` = 1
|
||||
AND d.`lab_id` = ".$this->baseLabId."
|
||||
ORDER BY d.`name_en`
|
||||
");
|
||||
return response()->json($samplePanelData);
|
||||
}
|
||||
|
||||
}
|
||||
108
app/Http/Controllers/DepartmentController.php
Normal file
108
app/Http/Controllers/DepartmentController.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Department;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class DepartmentController extends Controller
|
||||
{
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
|
||||
public function __construct(Department $department){
|
||||
$this->model = $department;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_department'])) return redirect(url('my-profile'));
|
||||
$standardDepartments = $this->model::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'is_standard' => 1])->get(['id','name_en'])->unique('name_en');
|
||||
$recordStatusCondition = Auth::id()==1 ? [RecordStatusEnum::DELETE, RecordStatusEnum::ACTIVE] : [RecordStatusEnum::ACTIVE];
|
||||
$departments = $this->model::query()->with(['samples'])->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusCondition)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->kword), function ($departments) use($request){
|
||||
$departments->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy('weight','asc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('department', ['departments' => $departments, 'labs' => $this->labs, 'standardDepartments' => $standardDepartments]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_department'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()){
|
||||
return response()->json(['success' => false, 'message' => __('department.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
}
|
||||
|
||||
$new = $this->model::query()->firstOrNew(['name_en' => $request->name_en, 'lab_id' => $this->baseLabId]);
|
||||
$new->name_en = $request->name_en;
|
||||
$new->weight = $request->weight;
|
||||
$new->lab_id = $this->baseLabId;
|
||||
$new->created_at = date('Y-m-d H:i:s');
|
||||
$new->created_by = Auth::user()->id;
|
||||
$new->record_status_id = RecordStatusEnum::ACTIVE;
|
||||
$new->save();
|
||||
|
||||
return response()->json(['success' => true, 'message' => __('department.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('department.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_department'])) return false;
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'name_en' => 'required',
|
||||
'weight' => 'nullable'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('department.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->model::query()->where('id', $request->uid)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('department.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('department.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$department = $this->model::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('department.get_success'), 'data' => $department]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('department.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_department'])) return false;
|
||||
$this->model::query()->where('id', $request->uid)->update(array('record_status_id'=> RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('department.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('department.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array('record_status_id'=> RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('department.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('department.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
28
app/Http/Controllers/Helper/GlobalController.php
Normal file
28
app/Http/Controllers/Helper/GlobalController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Helper;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GlobalController extends Controller
|
||||
{
|
||||
public static function user_can($role, array $modules) {
|
||||
try{
|
||||
if(Auth::user()->name == 'administrator' && Auth::id()==1) return true;
|
||||
$user_can = DB::table('sys_permissions')
|
||||
->join('sys_role_has_permissions','sys_role_has_permissions.permission_id','sys_permissions.id')
|
||||
->whereIn('sys_permissions.code',$modules)
|
||||
->where('sys_role_has_permissions.role_id', $role)
|
||||
->exists();
|
||||
return $user_can;
|
||||
}
|
||||
catch (\Exception $e){
|
||||
Log::error($e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
327
app/Http/Controllers/InvoiceController.php
Normal file
327
app/Http/Controllers/InvoiceController.php
Normal file
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\SampleCreateRequest;
|
||||
use App\Http\Requests\UpdateRequests\SampleUpdateRequest;
|
||||
use App\Http\Resources\SampleResource;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceDetail;
|
||||
use App\Models\Patient;
|
||||
use App\Models\Sample;
|
||||
use App\Models\LabConfigure;
|
||||
use App\Models\Physician;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
protected $model;
|
||||
protected $sampleModel;
|
||||
protected $patientModel;
|
||||
protected $invoiceDetailModel;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
protected $base;
|
||||
protected $laboratoryConfigures;
|
||||
protected $physicianModel;
|
||||
|
||||
|
||||
public function __construct(Invoice $invoiceModel, InvoiceDetail $invoiceDetailModel, Sample $sampleModel, Patient $patientModel, Physician $physicianModel){
|
||||
$this->model = $invoiceModel;
|
||||
$this->sampleModel = $sampleModel;
|
||||
$this->invoiceDetailModel = $invoiceDetailModel;
|
||||
$this->patientModel = $patientModel;
|
||||
$this->laboratoryConfigures = new LabConfigure();
|
||||
$this->physicianModel = $physicianModel;
|
||||
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
$this->labs = parent::getAccessAbleLabs();
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_invoice'])) return redirect(url('my-profile'));
|
||||
$recordStatusConditions = Auth::id()==1 ? [RecordStatusEnum::ACTIVE , RecordStatusEnum::DELETE] : [RecordStatusEnum::ACTIVE];
|
||||
|
||||
$oweInvoices = $this->model::with(['sample.patient'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->where('balance','>', 0)->get();
|
||||
$physicians = $this->physicianModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get();
|
||||
|
||||
$invoices = $this->model::with(['sample','repayments'])
|
||||
->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusConditions)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->from_date) && !empty($request->to_date), function ($inv) use ($request){
|
||||
$inv->whereBetween('invoice_date',[date('Y-m-d',strtotime($request->from_date)), date('Y-m-d',strtotime($request->to_date))]);
|
||||
})
|
||||
->when(isset($request->physician) && !empty($request->physician), function($inv) use ($request){
|
||||
$inv->whereIn('sample_id', $this->sampleModel::query()->where('physician_id', $request->physician)->pluck('id'));
|
||||
})
|
||||
->when(!empty(trim($request->kword)), function ($inv) use($request, $recordStatusConditions){
|
||||
$inv->whereRaw("replace(invoice_code, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhereIn('sample_id', $this->sampleModel::query()
|
||||
->whereIn('patient_id', $this->patientModel::query()
|
||||
->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhereRaw("replace(phone_number, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhere('patient_uuid','like','%'.$request->kword.'%')->pluck('id')->toArray()
|
||||
)->orwhereRaw("replace(sample_number, ' ','') like '%".str_replace(" ","",$request->kword)."%'")->pluck('id')->toArray()
|
||||
)->where('lab_id', $this->baseLabId)->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusConditions);
|
||||
})->orderBy('invoice_code','desc')->paginate(20);
|
||||
if(Auth::id()==1){
|
||||
//dd($invoices->pluck('repayments'));
|
||||
}
|
||||
return view('v_invoice.invoice', ['invoices' => $invoices, 'labSettings' => (object) $this->location(), 'oweInvoices' => $oweInvoices, 'physicians' => $physicians]);
|
||||
}
|
||||
|
||||
public function create($sample_id = null){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_invoice'])) return redirect(url('my-profile'));
|
||||
$samples = $this->sampleModel::query()->with('invoice')
|
||||
->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereDoesntHave('invoice')->get();
|
||||
return view('v_invoice.new_invoice', [
|
||||
'samples' => $samples,
|
||||
'sample_id' => $sample_id
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_invoice'])) return redirect(url('my-profile'));
|
||||
$invoiceNumber = $this->generateAutoId($request->invoice_date);
|
||||
$is_hide_discount = isset($request->is_hide_discount) ? 1: 0;
|
||||
$requests = collect($request)->merge(['lab_id'=>$this->baseLabId, 'invoice_code' => $invoiceNumber, 'is_hide_discount' => $is_hide_discount, 'exchange_rate' => ((object) $this->location())->exchange_rate])->except(['first_paid_date']);
|
||||
$invoice = $this->model::query()->create($requests->all());
|
||||
$invoiceDetailRequest = collect($request->test_sample_id);
|
||||
$items = $invoiceDetailRequest->map(function ($row, $key) use($request, $invoice) {
|
||||
$invoiceDetailRow = $this->invoiceDetailModel::query()->create([
|
||||
'invoice_id' => $invoice->id,
|
||||
'test_sample_id' => $request->test_sample_id[$key],
|
||||
'discount_type' => $request->item_discount_type[$key],
|
||||
'discount' => $request->item_discount[$key],
|
||||
'test_name' => $request->test_name[$key],
|
||||
'qty' => 1,
|
||||
'unit_price' => $request->unit_price[$key],
|
||||
]);
|
||||
return [];
|
||||
});
|
||||
DB::commit();
|
||||
$request->session()->flash('message','invoice-success');
|
||||
if(isset($request->save_print_invoice) && $request->save_print_invoice=='save_preview_invoice'){
|
||||
return redirect('invoice/edit/'.$invoice->id.'?print');
|
||||
}
|
||||
return redirect()->back();
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
$request->session()->flash('message','invoice-error');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_invoice', 'update_invoice'])) return redirect(url('my-profile'));
|
||||
$invoice = $this->model::query()->with('invoiceDetail.testSample.sample.department','creator','modifier')->where(['lab_id' => $this->baseLabId, 'id' => $id])->first();
|
||||
|
||||
$samples = $this->sampleModel::query()->where('id', $invoice->sample_id)->first();
|
||||
|
||||
$refreshItemItem = $this->refreshItemItem($invoice->sample_id);
|
||||
|
||||
|
||||
$labConfigures = $this->laboratoryConfigures::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get()->toArray();
|
||||
|
||||
return view('v_invoice.edit_invoice', [
|
||||
'samples' => [$samples],
|
||||
'invoice' => $invoice,
|
||||
'invoice_id' => $id,
|
||||
'sample_id' => $invoice->sample_id,
|
||||
'labSettings' => (object) $this->location(),
|
||||
'refreshItemItem' => $refreshItemItem,
|
||||
'labConfigures' => $labConfigures,
|
||||
'is_need_refresh_invoice' => (count($refreshItemItem) == count($invoice->invoiceDetail)) ? 0 : 1
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $invoiceUpdateRequest){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_invoice'])) return redirect(url('my-profile'));
|
||||
$is_hide_discount = isset($invoiceUpdateRequest->is_hide_discount) ? 1: 0;
|
||||
$requests = collect($invoiceUpdateRequest)->only(['invoice_note','total','discount','gross_total','deposit' ,'bank_deposit', 'balance','invoice_date','exchange_rate'])->merge(['is_hide_discount' => $is_hide_discount, 'updated_by' => Auth::id(), 'updated_at' => date('Y-m-d H:i:s')]);
|
||||
$invoice = $this->model::query()->where(['id' => $invoiceUpdateRequest->uid, 'lab_id' => $this->baseLabId])->update($requests->all());
|
||||
$invoiceDetailRequest = collect($invoiceUpdateRequest->test_sample_id);
|
||||
$items = $invoiceDetailRequest->map(function ($row, $key) use($invoiceUpdateRequest) {
|
||||
$invDetail = $this->invoiceDetailModel::query()->where(['invoice_id' => $invoiceUpdateRequest->uid, 'test_sample_id' => $invoiceUpdateRequest->test_sample_id[$key]])->first();
|
||||
if (empty($invDetail)) {
|
||||
$invoiceDetailRow = $this->invoiceDetailModel::query()->create([
|
||||
'invoice_id' => $invoiceUpdateRequest->uid,
|
||||
'test_sample_id' => $invoiceUpdateRequest->test_sample_id[$key],
|
||||
'discount_type' => $invoiceUpdateRequest->item_discount_type[$key],
|
||||
'discount' => $invoiceUpdateRequest->item_discount[$key],
|
||||
'test_name' => $invoiceUpdateRequest->test_name[$key],
|
||||
'weight' => $invoiceUpdateRequest->weight[$key],
|
||||
'qty' => 1,
|
||||
'unit_price' => $invoiceUpdateRequest->unit_price[$key],
|
||||
]);
|
||||
}
|
||||
else{
|
||||
$invoiceDetailRow = $this->invoiceDetailModel::query()->where([
|
||||
'invoice_id' => $invoiceUpdateRequest->uid,
|
||||
'test_sample_id' => $invoiceUpdateRequest->test_sample_id[$key]
|
||||
])->update([
|
||||
'weight' => $invoiceUpdateRequest->weight[$key]
|
||||
]);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
$this->invoiceDetailModel::query()->where('invoice_id', $invoiceUpdateRequest->uid)
|
||||
->whereNotIn('test_sample_id', $invoiceUpdateRequest->test_sample_id)->delete();
|
||||
DB::commit();
|
||||
$invoiceUpdateRequest->session()->flash('message','invoice-success');
|
||||
return redirect()->back();
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
$invoiceUpdateRequest->session()->flash('message','invoice-error');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
/** Perform by ajax function
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_invoice'])) return false;
|
||||
$invoice = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->first();
|
||||
$invoice->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('invoice.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('invoice.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('invoice.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('invoice.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSampleTest($sampleId){
|
||||
try{
|
||||
$patientTypes = $this->sampleModel::query()->with([])->where([
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
||||
'lab_id' => $this->baseLabId
|
||||
])->get();
|
||||
return response()->json(['success'=> true , 'data' => $patientTypes]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateAutoId($invoiceDate){
|
||||
$prefix = date('y',strtotime($invoiceDate));
|
||||
$invoiceCount = $this->model::query()->where('lab_id', $this->baseLabId)->whereRaw('year(invoice_date) ="'. date('Y',strtotime($invoiceDate)).'"')->count();
|
||||
return 'I-'.$this->base['short_name'].'-'.$prefix.'-'.(str_pad(($invoiceCount+1),5,'0',STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
public function paid($id){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$invoice = $this->model::query()->find($id);
|
||||
$invoice->balance = 0;
|
||||
$invoice->deposit = $invoice->gross_total;
|
||||
$invoice->first_paid_date = date('Y-m-d');
|
||||
$invoice->save();
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('This invoice already paid')]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('Failed while trying to paid on invoice'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function refreshItemItem($sampleId){
|
||||
try{
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
d.`id` AS department_id,
|
||||
d.`name_en` AS department_name,
|
||||
d.weight as dweight,
|
||||
st.`id` AS sample_type_id,
|
||||
st.weight as sweight,
|
||||
st.`name_en` AS sample_type,
|
||||
ts.`id` AS test_sample_id,
|
||||
ts.`heading_id` AS parent_id,
|
||||
ts.`field_type`,
|
||||
ts.`usd_price`,
|
||||
ts.group_result,
|
||||
ts.description,
|
||||
t.`id` AS test_id,
|
||||
t.`name_en` AS test_name,
|
||||
tr.id as test_result_id,
|
||||
pct.`commission_type`,
|
||||
ifnull(pct.`commission_rate`, 0.00) as commission_rate,
|
||||
ifnull(pct.`partner_price`, 0.00) as partner_price,
|
||||
ts.weight
|
||||
FROM samples s
|
||||
INNER JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
AND s.`lab_id` = tr.`lab_id`
|
||||
INNER JOIN test_samples ts
|
||||
ON ts.id = tr.`test_sample_id`
|
||||
and ts.lab_id = tr.lab_id
|
||||
INNER JOIN tests t
|
||||
ON t.`id` = ts.`test_id`
|
||||
INNER JOIN sample_types st
|
||||
ON st.`id` = ts.`sample_type_id`
|
||||
INNER JOIN departments d
|
||||
ON d.`id` = st.`department_id`
|
||||
LEFT JOIN `physician_commisssion` AS pct
|
||||
ON pct.`test_sample_id` = ts.`id`
|
||||
AND pct.`physician_id` = s.`physician_id`
|
||||
WHERE s.`id` = '.$sampleId.'
|
||||
AND s.`lab_id`= '.$this->baseLabId.'
|
||||
AND tr.`record_status_id` = '.BaseModel::RECORD_STATUS_ACTIVE.'
|
||||
AND LENGTH(ts.group_result)>0
|
||||
AND ts.usd_price>0
|
||||
ORDER BY
|
||||
d.`weight`,
|
||||
st.`weight`,
|
||||
ts.`weight`');
|
||||
$departmentArray = array();
|
||||
foreach ($resultItems as $row){
|
||||
$net_amount = number_format((((!empty($row->commission_type) ? $row->commission_type : ((object) $this->location())->discount_type)) ==2 ? (($row->usd_price - $row->partner_price) - $row->commission_rate) :
|
||||
(($row->usd_price - $row->partner_price) * (1-$row->commission_rate/100))),2);
|
||||
$testItemArray = array(
|
||||
'test_sample_id' => (string)$row->test_sample_id,
|
||||
'test_id' => $row->test_id,
|
||||
'test_name' => $row->test_name,
|
||||
'closed_parent_id' => (string) (int)$row->parent_id,
|
||||
'field_type' => (string) $row->field_type,
|
||||
'usd_price' => $row->usd_price,
|
||||
'group_result' => (string) $row->group_result,
|
||||
'item_discount_type' => (!empty($row->commission_type) ? $row->commission_type : ((object) $this->location())->discount_type),
|
||||
'item_discount_rate' => $row->commission_rate,
|
||||
'item_discount' => $net_amount,
|
||||
'discount_price' => ($row->usd_price - $net_amount)
|
||||
);
|
||||
$departmentArray[] = $testItemArray;
|
||||
}
|
||||
return $departmentArray;
|
||||
} catch (\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
486
app/Http/Controllers/LabController.php
Normal file
486
app/Http/Controllers/LabController.php
Normal file
@@ -0,0 +1,486 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Department;
|
||||
use App\Models\SampleType;
|
||||
use App\Models\TestNormalValue;
|
||||
use App\Models\TestSample;
|
||||
use App\Models\TestSampleOrganism;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Laboratory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use App\Models\LabConfigure;
|
||||
|
||||
|
||||
class LabController extends Controller
|
||||
{
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $testSampleModel;
|
||||
protected $labs;
|
||||
|
||||
public function __construct(Laboratory $model, TestSample $testSampleModel){
|
||||
$this->model = $model;
|
||||
$this->testSampleModel = $testSampleModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['system_settings'])) return redirect(url('my-profile'));
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
return view('laboratory', ['info' => $lab]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try {
|
||||
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'lab_name_en' => 'required',
|
||||
'lab_code' => 'required|max:5',
|
||||
'sample_number' => 'required',
|
||||
'patient_code' => 'required',
|
||||
'start_date' => 'required',
|
||||
'end_date' => 'nullable'
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['success' => false, 'message' => __('laboratory.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
}
|
||||
$data = array(
|
||||
'name_en' => $request->lab_name_en,
|
||||
'name_kh' => $request->lab_name_kh,
|
||||
'short_name' => $request->lab_code,
|
||||
'sample_number' => $request->sample_number,
|
||||
'patient_code' => $request->patient_code,
|
||||
'phone_number' => $request->phone_number,
|
||||
'lab_category_id' => $request->lab_category_id,
|
||||
'is_auto_make_invoice' => $request->is_auto_make_invoice,
|
||||
'email' => $request->email,
|
||||
'shareable_lab_result' => isset($request->shareable_lab_result) ? 1 : 0,
|
||||
'allow_external_request' => isset($request->allow_external_request) ? 1 : 0,
|
||||
'is_hide_comission_percentage' => isset($request->is_hide_comission_percentage) ? $request->is_hide_comission_percentage : 0,
|
||||
'is_hide_inv_discount' => 0,
|
||||
'address_en' => $request->address_en,
|
||||
'address_kh' => $request->address_kh,
|
||||
'start_date' => ($request->start_date ? date('Y-m-d H:i:s', strtotime($request->start_date)) : null),
|
||||
'end_date' => ($request->end_date ? date('Y-m-d H:i:s', strtotime($request->end_date)) : null),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => Auth::id()
|
||||
);
|
||||
$this->model::query()->insert($data);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.create_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('laboratory.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateInfo(Request $request){
|
||||
try {
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'name_en' => 'required',
|
||||
'name_kh' => 'required',
|
||||
'short_name' => 'required|max:3'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'name_kh' => $request->name_kh,
|
||||
'short_name' => $request->short_name,
|
||||
'email' => $request->email,
|
||||
'phone_number' => $request->phone_number,
|
||||
'address_en' => $request->address_en,
|
||||
'address_kh' => $request->address_kh,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->model::query()->where('id', $this->baseLabId)->update($data);
|
||||
return redirect()->back();
|
||||
//return response()->json(['success' => true, 'message' => __('laboratory.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
dd($e);
|
||||
//return redirect()->back();
|
||||
return response()->json(['success' => false, 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try {
|
||||
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'lab_name_en' => 'required',
|
||||
'lab_code' => 'required|max:5',
|
||||
'sample_number' => 'required',
|
||||
'patient_code' => 'required',
|
||||
'start_date' => 'required',
|
||||
'end_date' => 'nullable'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name_en' => $request->lab_name_en,
|
||||
'name_kh' => $request->lab_name_kh,
|
||||
'short_name' => $request->lab_code,
|
||||
'sample_number' => $request->sample_number,
|
||||
'patient_code' => $request->patient_code,
|
||||
'phone_number' => $request->phone_number,
|
||||
'lab_category_id' => $request->lab_category_id,
|
||||
'is_auto_make_invoice' => $request->is_auto_make_invoice,
|
||||
'email' => $request->email,
|
||||
'shareable_lab_result' => isset($request->shareable_lab_result) ? 1 : 0,
|
||||
'allow_external_request' => isset($request->allow_external_request) ? 1 : 0,
|
||||
'is_hide_comission_percentage' => isset($request->is_hide_comission_percentage) ? $request->is_hide_comission_percentage : 0,
|
||||
'address_en' => $request->address_en,
|
||||
'address_kh' => $request->address_kh,
|
||||
'start_date' => ($request->start_date ? date('Y-m-d H:i:s', strtotime($request->start_date)) : null),
|
||||
'end_date' => ($request->end_date ? date('Y-m-d H:i:s', strtotime($request->end_date)) : null),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->model::query()->where('id', $request->lab_id)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$lab_id = $request->lab_id;
|
||||
$lab = $this->model::query()->where('id', $lab_id)->get()->first();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.get_success'), 'data' => $lab]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('laboratory.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->lab_id)->update(array(BaseModel::RECORD_STATUS_FIELD=> RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.delete_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('laboratory.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->lab_id)->update(array(BaseModel::RECORD_STATUS_FIELD=> RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.restore_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('laboratory.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function profile(){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_laboratory_information'])) return redirect(url('my-profile'));
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
return view('lab_profile', ['info' => $lab]);
|
||||
}
|
||||
|
||||
public function labSettingSetters(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['system_settings'])) return redirect(url('my-profile'));
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'sample_number' => 'required|integer',
|
||||
'patient_code' => 'required|integer',
|
||||
'technician_label' => 'nullable',
|
||||
'discount_type' => 'required|integer'
|
||||
]);
|
||||
if ($validator->fails()){ return response()->json(['errors'=>$validator->errors()->all()]);}
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array(
|
||||
'sample_number' => $request->sample_number,
|
||||
'currency' => $request->currency,
|
||||
'patient_code' => $request->patient_code,
|
||||
'technician_label' => $request->technician_label,
|
||||
'discount_type' => $request->discount_type,
|
||||
'phone_number' => $request->phone_number,
|
||||
'email' => $request->email,
|
||||
'exchange_rate' => $request->exchange_rate,
|
||||
//'is_hide_inv_discount' => $request->is_hide_inv_discount,
|
||||
'abnormal_text_color' => $request->abnormal_text_color,
|
||||
'show_result_footer' => $request->show_result_footer,
|
||||
'abnormal_result_font_weight' => $request->abnormal_result_font_weight,
|
||||
'result_header_id' => $request->result_header_id,
|
||||
'is_auto_make_invoice' => $request->is_auto_make_invoice,
|
||||
'invoice_template_id' => $request->invoice_template_id
|
||||
));
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function uploadImage(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = 'avatar_'.$this->baseLabId.'.' . $image->getClientOriginalExtension();
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array('logo' => $imageName));
|
||||
$image->move(public_path('storage/images/avatars/labs'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeLabLogo(Request $request){
|
||||
try {
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
if(!empty($lab->logo)) {
|
||||
if (file_exists(public_path('storage/images/avatars/labs/' . $lab->logo))) {
|
||||
unlink(public_path('storage/images/avatars/labs/' . $lab->logo));
|
||||
$lab->logo = null;
|
||||
}
|
||||
}
|
||||
$lab->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function saveLabConfigure(Request $request){
|
||||
try{
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'attribute_code' => 'required|string',
|
||||
'attribute_value' => 'required|string'
|
||||
]);
|
||||
if ($validator->fails()){ return response()->json(['errors'=>$validator->errors()->all()]);}
|
||||
$labSetting = $this->labConfigureModel::query()->firstOrNew(['atrribute_code' => $request->attribute_code, 'lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD=> RecordStatusEnum::ACTIVE]);
|
||||
$labSetting->assigned_attribute_value = $request->attribute_value;
|
||||
$labSetting->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $labSetting]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function initLabData(){
|
||||
return view('clone_lab',['labs' => $this->labs]);
|
||||
}
|
||||
|
||||
function getLabData($labId){
|
||||
try{
|
||||
$department = Department::query()->with([
|
||||
'samples',
|
||||
'samples.testSamples',
|
||||
'samples.testSamples.testValues',
|
||||
'samples.testSamples.organisms',
|
||||
'samples.testSamples.organisms.antibiotics'
|
||||
])->where(['lab_id' => $labId, BaseModel::RECORD_STATUS_FIELD => 1])->get()->toArray();
|
||||
return response()->json(['success' => true, 'data' => $department]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => 'Error while retrieving lab data.']);
|
||||
}
|
||||
}
|
||||
|
||||
/** Verify Image */
|
||||
|
||||
public function uploadVerifyImage(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = 'verify_label_'.$this->baseLabId.'.' . $image->getClientOriginalExtension();
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array('verify_label' => $imageName));
|
||||
$image->move(public_path('storage/images/avatars/labs'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeVerifyImage(Request $request){
|
||||
try {
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
if(!empty($lab->verify_label)) {
|
||||
if (file_exists(public_path('storage/images/avatars/labs/' . $lab->verify_label))) {
|
||||
unlink(public_path('storage/images/avatars/labs/' . $lab->verify_label));
|
||||
$lab->verify_label = null;
|
||||
}
|
||||
}
|
||||
$lab->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function updateHeading(){
|
||||
$targetLabTestSample = TestSample::query()->where(['lab_id' => 18,'sample_type_id'=>397, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->where('heading_id','>',0)->get();
|
||||
foreach ($targetLabTestSample as $targetTestSample){
|
||||
dd($targetTestSample);
|
||||
$source = TestSample::query()->where(['id' => $targetTestSample->heading_id, 'lab_id' => 29])->get();//->first();
|
||||
dd($source);
|
||||
$target = TestSample::query()->where(['lab_id' => 18, 'test_id' => $source->test_id , 'sample_type_id' => $targetTestSample->sample_type_id ])->get()->first();
|
||||
|
||||
//TestSample::query()->where(['id' => $targetTestSample->id])->update([ 'heading_id' => $target->id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function uploadAlternativeLogo(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = 'alternative_logo_'.$this->baseLabId.'.' . $image->getClientOriginalExtension();
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array('alternative_logo' => $imageName));
|
||||
$image->move(public_path('storage/images/avatars/labs/alternative_logo'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAlternativeLogo(Request $request){
|
||||
try {
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
if(!empty($lab->alternative_logo)) {
|
||||
if (file_exists(public_path('storage/images/avatars/labs/alternative_logo/' . $lab->alternative_logo))) {
|
||||
unlink(public_path('storage/images/avatars/labs/alternative_logo/' . $lab->alternative_logo));
|
||||
$lab->alternative_logo = null;
|
||||
}
|
||||
}
|
||||
$lab->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Alternative Verify Signature
|
||||
public function uploadAlterVerifySignature(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = 'alter_verify_sign_'.$this->baseLabId.'.' . $image->getClientOriginalExtension();
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array('alter_verify_sign' => $imageName));
|
||||
$image->move(public_path('storage/images/avatars/labs'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAlterVerifySignature(Request $request){
|
||||
try {
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
if(!empty($lab->alter_verify_sign)) {
|
||||
if (file_exists(public_path('storage/images/avatars/labs/' . $lab->alter_verify_sign))) {
|
||||
unlink(public_path('storage/images/avatars/labs/' . $lab->alter_verify_sign));
|
||||
$lab->alter_verify_sign = null;
|
||||
}
|
||||
}
|
||||
$lab->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
// Alternative Labtech Signature
|
||||
public function uploadAlterLabtechSignature(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = 'alter_labtech_sign_'.$this->baseLabId.'.' . $image->getClientOriginalExtension();
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array('alter_labtech_sign' => $imageName));
|
||||
$image->move(public_path('storage/images/avatars/labs'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAlterLabtechSignature(Request $request){
|
||||
try {
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
if(!empty($lab->alter_labtech_sign)) {
|
||||
if (file_exists(public_path('storage/images/avatars/labs/' . $lab->alter_labtech_sign))) {
|
||||
unlink(public_path('storage/images/avatars/labs/' . $lab->alter_labtech_sign));
|
||||
$lab->alter_labtech_sign = null;
|
||||
}
|
||||
}
|
||||
$lab->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/** default footer */
|
||||
public function uploadDefaultFooter(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = 'default_footer_'.$this->baseLabId.'.' . $image->getClientOriginalExtension();
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array('footer' => $imageName));
|
||||
$image->move(public_path('storage/images/avatars/labs/default_footer'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeDefaultFooter(Request $request){
|
||||
try {
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
if(!empty($lab->footer)) {
|
||||
if (file_exists(public_path('storage/images/avatars/labs/default_footer/' . $lab->footer))) {
|
||||
unlink(public_path('storage/images/avatars/labs/default_footer/' . $lab->footer));
|
||||
$lab->footer = null;
|
||||
}
|
||||
}
|
||||
$lab->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
/* default footer end */
|
||||
|
||||
/** alternative footer */
|
||||
public function uploadAlternativeFooter(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = 'alternative_footer_'.$this->baseLabId.'.' . $image->getClientOriginalExtension();
|
||||
$lab = $this->model::query()->where('id', $this->baseLabId)->first();
|
||||
$lab->update(array('alternative_footer' => $imageName));
|
||||
$image->move(public_path('storage/images/avatars/labs/alternative_footer'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeAlternativeFooter(Request $request){
|
||||
try {
|
||||
$lab = $this->model::query()->find($this->baseLabId);
|
||||
if(!empty($lab->alternative_footer)) {
|
||||
if (file_exists(public_path('storage/images/avatars/labs/alternative_footer/' . $lab->alternative_footer))) {
|
||||
unlink(public_path('storage/images/avatars/labs/alternative_footer/' . $lab->alternative_footer));
|
||||
$lab->alternative_footer = null;
|
||||
}
|
||||
}
|
||||
$lab->save();
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => $lab]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
/* alternative footer end */
|
||||
|
||||
}
|
||||
110
app/Http/Controllers/OrganismController.php
Normal file
110
app/Http/Controllers/OrganismController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\TestSampleCreateRequest;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Organism;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\SampleType;
|
||||
use App\Models\Test;
|
||||
use App\Models\TestNormalValue;
|
||||
use App\Models\TestSample;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class OrganismController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
|
||||
public function __construct(Organism $organism){
|
||||
$this->model = $organism;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_organism'])) return redirect(url('my-profile'));
|
||||
$organisms = $this->model::with(['lab'])->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
//->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->kword), function ($organisms) use($request){
|
||||
$organisms->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('organism', ['organisms' => $organisms]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_organism'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('organism.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$new = $this->model::query()->firstOrNew(['name_en' => $request->name_en]);
|
||||
$new->name_en = $request->name_en;
|
||||
$new->weight = $request->weight;
|
||||
$new->is_bold = $request->is_bold;
|
||||
$new->lab_id = $this->baseLabId;
|
||||
$new->created_at = date('Y-m-d H:i:s');
|
||||
$new->created_by = Auth::id();
|
||||
$new->record_status_id = RecordStatusEnum::ACTIVE;
|
||||
$new->save();
|
||||
return response()->json(['success' => true, 'message' => __('organism.create_success'), 'data' => [$new]]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('organism.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_organism'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('organism.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'name_kh' => $request->name_kh,
|
||||
'is_bold' => $request->is_bold,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->model::query()->where('id', $request->uid)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('organism.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('organism.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$organism = $this->model::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('organism.get_success'), 'data' => $organism]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('organism.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_organism'])) return false;
|
||||
$this->model::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('organism.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('organism.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('organism.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('organism.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
239
app/Http/Controllers/PatientController.php
Normal file
239
app/Http/Controllers/PatientController.php
Normal file
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Helpers\Helpers;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\PatientCreateRequest;
|
||||
use App\Http\Requests\PatientUpdateRequest;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Laboratory;
|
||||
use App\Models\Patient;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class PatientController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $base;
|
||||
protected $departments;
|
||||
|
||||
public function __construct(Patient $patientModel){
|
||||
$this->model = $patientModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
|
||||
}
|
||||
|
||||
function province(){
|
||||
return parent::province();
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_patient'])) return redirect(url('my-profile'));
|
||||
$provinces = $this->province();
|
||||
$patients = $this->model::with(['samples'])->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty(trim($request->kword)), function ($patients) use($request){
|
||||
$patients->whereRaw(
|
||||
"(replace(name_en, ' ', '') LIKE ? OR replace(phone_number, ' ', '') LIKE ? OR replace(patient_uuid, ' ', '') LIKE ? OR replace(khid_number, ' ', '') LIKE ?) and lab_id = ?",
|
||||
[
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
$this->baseLabId
|
||||
]
|
||||
);
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('patient', ['provinces' => $provinces, 'patients' => $patients, 'labSettings' => (object) $this->base]);
|
||||
}
|
||||
|
||||
public function save(PatientCreateRequest $patientCreateRequest){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_patient'])) return false;
|
||||
$dob = $patientCreateRequest->dob;
|
||||
$datePart = explode("-",$dob);
|
||||
if($datePart[1]>12){
|
||||
$dob = $datePart[1].'-'.$datePart[0].'-'.$datePart[2];
|
||||
}
|
||||
$requests = collect($patientCreateRequest)->merge([
|
||||
'lab_id' => $this->baseLabId,
|
||||
BaseModel::CREATED_AT_FIELD => date('Y-m-d H:i:s'),
|
||||
BaseModel::CREATED_BY_FIELD => Auth::id(),
|
||||
BaseModel::UPDATED_AT_FIELD => NULL,
|
||||
BaseModel::UPDATED_BY_FIELD => NULL,
|
||||
BaseModel::RECORD_STATUS_FIELD => BaseModel::RECORD_STATUS_ACTIVE
|
||||
])->replace(
|
||||
[
|
||||
'dob' => date('Y-m-d', strtotime($dob)),
|
||||
'phone_number' => $patientCreateRequest->phone_number // preg_replace('/ /i', '', trim($patientCreateRequest->phone_number))
|
||||
]);
|
||||
|
||||
if(empty($patientCreateRequest->patient_uuid)) {
|
||||
$patientNumber = $this->generateAutoId(date('Y-m-d'));
|
||||
$requests = $requests->merge(['patient_uuid' => $patientNumber]);
|
||||
}
|
||||
|
||||
$patient = $this->model::query()->create($requests->all());
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'message' => __('patient.create_success') , 'data' => $patient]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
Log::error($e);
|
||||
return response()->json(['success'=> false , 'message' => __('patient.create_fail') , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(PatientUpdateRequest $patientUpdateRequest){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_patient'])) return false;
|
||||
$dob = $patientUpdateRequest->dob;
|
||||
$datePart = explode("-",$dob);
|
||||
if($datePart[1]>12){
|
||||
$dob = $datePart[1].'-'.$datePart[0].'-'.$datePart[2];
|
||||
}
|
||||
|
||||
$requests = collect($patientUpdateRequest)->merge([
|
||||
BaseModel::UPDATED_AT_FIELD => date('Y-m-d H:i:s'),
|
||||
BaseModel::UPDATED_BY_FIELD => Auth::id()
|
||||
])->replace([
|
||||
'dob' => date('Y-m-d', strtotime($dob)),
|
||||
'phone_number' => $patientUpdateRequest->phone_number // preg_replace('/ /i', '', trim($patientUpdateRequest->phone_number))
|
||||
])->except(['patient_uuid','uid']);
|
||||
$patient = $this->model::query()->find($patientUpdateRequest->uid)->update($requests->all());
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'message' => __('patient.update_success'), 'data' => array('id' => $patientUpdateRequest->uid) ]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
Log::error($e);
|
||||
return response()->json(['success'=> false , 'message' => __('patient.update_fail'), 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$patient = $this->model::query()->find($request->uid);
|
||||
return response()->json(['success'=> true , 'message' => __('patient.get_success') , 'data' => $patient]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false , __('patient.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_patient'])) return false;
|
||||
$patient = $this->model::query()->find($request->uid);
|
||||
$patient->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success'=> true, 'message' => __('patient.delete_success'), 'data' => $patient]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false, 'message' => __('patient.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$patient = $this->model::query()->find($request->uid);
|
||||
$patient->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success'=> true, 'message' => __('patient.restore_success'), 'data' => $patient]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false, 'message' => __('patient.restore_success'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
try{
|
||||
$patients = $this->model::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->when($request->kword!='', function($patients) use ($request) {
|
||||
$patients->whereRaw(
|
||||
"(replace(name_en, ' ', '') LIKE ? OR replace(phone_number, ' ', '') LIKE ? OR replace(patient_uuid, ' ', '') LIKE ? OR replace(khid_number, ' ', '') LIKE ?) and lab_id = ?",
|
||||
[
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
$this->baseLabId
|
||||
]
|
||||
);
|
||||
})->orderBy('name_en','asc')->limit(config('labis.pagination.perpage', 10))->get();
|
||||
return response()->json(['success'=> true, __('patient.get_success'), 'data' => $patients]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false, __('patient.get_fail'), 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function patientSearchAjax(Request $request)
|
||||
{
|
||||
try{
|
||||
$provinces = $this->province();
|
||||
$patients = $this->model::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->when($request->kword!='', function($patients) use ($request) {
|
||||
$patients->whereRaw(
|
||||
"(replace(name_en, ' ', '') LIKE ? OR replace(phone_number, ' ', '') LIKE ? OR replace(patient_uuid, ' ', '') LIKE ? OR replace(khid_number, ' ', '') LIKE ?) and lab_id = ?",
|
||||
[
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
'%' . str_replace(' ', '', $request->kword) . '%',
|
||||
$this->baseLabId
|
||||
]
|
||||
);
|
||||
})->orderBy('name_en','asc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('partials.patient_list', ['provinces' => $provinces, 'patients' => $patients, 'labSettings' => (object) $this->base]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false, __('patient.get_fail'), 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateAutoId($admissionDate){
|
||||
$prefix = date('y',strtotime($admissionDate));
|
||||
$patientCount = $this->model::query()->where('lab_id', $this->baseLabId)->whereRaw('year(created_at) ="'. date('Y',strtotime($admissionDate)).'"')->count();
|
||||
if($this->baseLabId==34) $patientCount = $patientCount+5; // solve problem when delete patient
|
||||
return 'P-'.$this->base['short_name'].'-'.$prefix.'-'.(str_pad(($patientCount+1),5,'0',STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
|
||||
public function searchPatientToSelect2(Request $request){
|
||||
$patients = [];
|
||||
if(!empty(trim($request->term))){
|
||||
$patients = $this->model::query()
|
||||
->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->when(!empty(trim($request->term)), function ($patients) use($request){
|
||||
$patients->whereRaw(
|
||||
"(replace(name_en, ' ', '') LIKE ? OR replace(phone_number, ' ', '') LIKE ? OR replace(patient_uuid, ' ', '') LIKE ? OR replace(khid_number, ' ', '') LIKE ?) and lab_id = ?",
|
||||
[
|
||||
'%' . str_replace(' ', '', $request->term) . '%',
|
||||
'%' . str_replace(' ', '', $request->term) . '%',
|
||||
'%' . str_replace(' ', '', $request->term) . '%',
|
||||
'%' . str_replace(' ', '', $request->term) . '%',
|
||||
$this->baseLabId
|
||||
]
|
||||
);
|
||||
})->limit(20)->orderBy('name_en', 'asc')->get();
|
||||
}
|
||||
$items = [];
|
||||
if(!empty($patients)){
|
||||
$items = $patients->map(function ($item){
|
||||
return array('id'=>$item->id, 'text' => $item->patient_uuid . ' - '.$item->name_en . ((!empty($item->phone_number) ? ' - '.$item->phone_number: '')));
|
||||
});
|
||||
}
|
||||
return response()->json(['results' => $items]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
115
app/Http/Controllers/PatientTypeController.php
Normal file
115
app/Http/Controllers/PatientTypeController.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\PatientTypeCreateRequest;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\PatientType;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class PatientTypeController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
|
||||
public function __construct(PatientType $patientType){
|
||||
$this->model = $patientType;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_patient_type'])) return redirect(url('my-profile'));
|
||||
$standardPatientTypes = $this->model::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'is_standard' => 1])->get(['id','name_en'])->unique('name_en');
|
||||
$patientTypes = $this->model::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
//->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->kword), function ($patientTypes) use ($request){
|
||||
$patientTypes->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('patient-type', ['patientTypes' => $patientTypes, 'standardPatientTypes' => $standardPatientTypes]);
|
||||
}
|
||||
|
||||
public function save(PatientTypeCreateRequest $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_patient_type'])) return false;
|
||||
$new = $this->model::query()->firstOrNew(['name_en' => $request->name_en, 'gender' => $request->gender]);
|
||||
$new->name_en = $request->name_en;
|
||||
$new->gender = $request->gender;
|
||||
$new->range_start = $request->age_from;
|
||||
$new->range_start_unit = $request->age_from_unit;
|
||||
$new->range_start_sign = $request->age_from_sign;
|
||||
$new->range_end = $request->age_to;
|
||||
$new->range_end_unit = $request->age_to_unit;
|
||||
$new->range_end_sign = $request->age_to_sign;
|
||||
//$new->lab_id = $this->baseLabId;
|
||||
$new->save();
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('patient_type.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('patient_type.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update(PatientTypeCreateRequest $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_patient_type'])) return false;
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'range_start' => $request->age_from,
|
||||
'range_start_unit' => $request->age_from_unit,
|
||||
'gender' => $request->gender,
|
||||
'range_end' => $request->age_to,
|
||||
'range_end_unit' => $request->age_to_unit,
|
||||
//'lab_id' => $this->baseLabId,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->model::query()->where('id', $request->uid)->update($data);
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('patient_type.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('patient_type.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$patientType = $this->model::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('patient_type.get_success'), 'data' => $patientType]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('patient_type.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_patient_type'])) return false;
|
||||
$this->model::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('patient_type.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('patient_type.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('patient_type.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('patient_type.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
170
app/Http/Controllers/PhysicianController.php
Normal file
170
app/Http/Controllers/PhysicianController.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;;
|
||||
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Physician;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class PhysicianController extends Controller
|
||||
{
|
||||
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
private $physician;
|
||||
|
||||
public function __construct(Physician $physician){
|
||||
$this->physician = $physician;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_physician'])) return redirect(url('my-profile'));
|
||||
$physicians = $this->physician::with(['lab'])->where('record_status_id', RecordStatusEnum::ACTIVE)
|
||||
->where('lab_id', Session::get('base_lab_id'))
|
||||
->when(!empty($request->kword), function ($physicians) use ($request){
|
||||
$physicians->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})
|
||||
->orderBy(BaseModel::CREATED_AT,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('physician', ['physicians' => $physicians, 'labs' => parent::getAccessAbleLabs()]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_physician'])) return redirect(url('my-profile'));
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['errors'=>$validator->errors()->all()]);
|
||||
$imageName = NULL;
|
||||
$footerName = NULL;
|
||||
if($request->image)
|
||||
{
|
||||
request()->validate(['image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048']);
|
||||
$imageName = time().'.'.request()->image->getClientOriginalExtension();
|
||||
request()->image->move(public_path('storage/images/physician'), $imageName);
|
||||
}
|
||||
if($request->imageFooter)
|
||||
{
|
||||
request()->validate(['imageFooter' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048']);
|
||||
$footerName = time().'_footer.'.request()->imageFooter->getClientOriginalExtension();
|
||||
request()->imageFooter->move(public_path('storage/images/physician'), $footerName);
|
||||
}
|
||||
|
||||
$new = $this->physician::query()->firstOrNew(['name_en' => $request->name_en, 'lab_id' => $this->baseLabId]);
|
||||
$new->name_en = $request->name_en;
|
||||
$new->phone = $request->phone;
|
||||
$new->lab_id = $this->baseLabId;
|
||||
$new->logo = $imageName;
|
||||
$new->footer = $footerName;
|
||||
$new->is_default = isset($request->is_default) ? 1 : 0;
|
||||
$new->created_at = date('Y-m-d H:i:s');
|
||||
$new->created_by = Auth::user()->id;
|
||||
$new->record_status_id = RecordStatusEnum::ACTIVE;
|
||||
$new->save();
|
||||
|
||||
$request->session()->flash('msg','Physician has been inserted!');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_physician'])) return redirect(url('my-profile'));
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'name_en' => 'required'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['errors'=>$validator->errors()->all()]);
|
||||
$imageName = NULL;
|
||||
$footerName = NULL;
|
||||
if($request->image)
|
||||
{
|
||||
request()->validate(['image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048']);
|
||||
$imageName = time().'.'.request()->image->getClientOriginalExtension();
|
||||
request()->image->move(public_path('storage/images/physician'), $imageName);
|
||||
}
|
||||
if($request->imageFooter)
|
||||
{
|
||||
request()->validate(['imageFooter' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048']);
|
||||
$footerName = time().'_footer.'.request()->imageFooter->getClientOriginalExtension();
|
||||
request()->imageFooter->move(public_path('storage/images/physician'), $footerName);
|
||||
}
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'name_kh' => $request->name_kh,
|
||||
'phone' => $request->phone,
|
||||
'is_default' => isset($request->is_default) ? 1: 0,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
if(!empty($imageName)){$data = array_merge($data, ['logo' => $imageName]);}
|
||||
if(!empty($footerName)){$data = array_merge($data, ['footer' => $footerName]);}
|
||||
$status = $this->physician::query()->where('id', $request->uid)->update($data);
|
||||
$request->session()->flash('msg','Physician has been updated!');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function deletePhysicianLogo(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_physician'])) return false;
|
||||
$physician = $this->physician::query()->find($request->uid);
|
||||
if(file_exists(public_path('storage/images/physician/'.$physician->logo))){
|
||||
unlink(public_path('storage/images/physician/'.$physician->logo));
|
||||
$physician->logo = null;
|
||||
}
|
||||
$physician->save();
|
||||
return response()->json(['success'=> true , 'message' => __('physician.delete_photo_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('physician.delete_photo_failed')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function deletePhysicianFooter(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_physician'])) return false;
|
||||
$physician = $this->physician::query()->find($request->uid);
|
||||
if(file_exists(public_path('storage/images/physician/'.$physician->footer))){
|
||||
unlink(public_path('storage/images/physician/'.$physician->footer));
|
||||
$physician->footer = null;
|
||||
}
|
||||
$physician->save();
|
||||
return response()->json(['success'=> true , 'message' => __('physician.delete_photo_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('physician.delete_photo_failed')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try {
|
||||
$physician = $this->physician::query()->find($request->uid);
|
||||
return response()->json(['success'=> true , 'message' => __('physician.get_success'), 'data' => $physician]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('physician.get_fail')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_physician'])) return false;
|
||||
$this->physician::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success'=> true , 'message' => __('physician.delete_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('physician.delete_fail')]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try {
|
||||
$this->physician::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('physician.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('physician.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
121
app/Http/Controllers/PublicationController.php
Normal file
121
app/Http/Controllers/PublicationController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Publication;
|
||||
use App\Models\PublicationReceiver;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class PublicationController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $labs;
|
||||
protected $publicationReceiverModel;
|
||||
|
||||
public function __construct(Publication $publication){
|
||||
$this->model = $publication;
|
||||
$this->publicationReceiverModel = new PublicationReceiver();
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
$publications = $this->model::query()->whereIn(BaseModel::RECORD_STATUS_FIELD, [RecordStatusEnum::ACTIVE, RecordStatusEnum::DELETE])
|
||||
->when(!empty($request->kword), function ($publications) use($request){
|
||||
$publications->whereRaw("replace(title_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhereRaw("replace(title_kh, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('publication', ['publications' => $publications, 'labs' => $this->labs]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
$validator = \Validator::make($request->all(), ['start_date' => 'required', 'title_en' => 'required','lab_ids' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('comment.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
|
||||
$publication = $this->model::query()->create([
|
||||
'title_en' => $request->title_en,
|
||||
'title_kh' => $request->title_kh,
|
||||
'start_date' => date('Y-m-d', strtotime($request->start_date)),
|
||||
'end_date' => date('Y-m-d', strtotime($request->end_date)),
|
||||
'description' => $request->description
|
||||
]);
|
||||
|
||||
foreach ($request->lab_ids as $lab_id){
|
||||
$this->publicationReceiverModel::query()->create([
|
||||
'publication_id' => $publication->id,
|
||||
'lab_id' => $lab_id,
|
||||
'created_by' => Auth::id()
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json(['success' => true, 'message' => __('comment.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try {
|
||||
$validator = \Validator::make($request->all(), ['start_date' => 'required', 'title_en' => 'required', 'lab_ids' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('comment.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'title_en' => $request->title_en,
|
||||
'title_kh' => $request->title_kh,
|
||||
'start_date' => date('Y-m-d', strtotime($request->start_date)),
|
||||
'end_date' => date('Y-m-d', strtotime($request->end_date)),
|
||||
'description' => $request->description
|
||||
);
|
||||
$this->model::query()->where('id', $request->uid)->update($data);
|
||||
$this->publicationReceiverModel::query()->where('publication_id', $request->uid)->delete();
|
||||
foreach ($request->lab_ids as $lab_id){
|
||||
$this->publicationReceiverModel::query()->create([
|
||||
'publication_id' => $request->uid,
|
||||
'lab_id' => $lab_id,
|
||||
'created_by' => Auth::id()
|
||||
]);
|
||||
}
|
||||
return response()->json(['success' => true, 'message' => __('comment.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$test = $this->model::with(['receivers'])->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('comment.get_success'), 'data' => $test]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('comment.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('comment.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('comment.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function read($id){
|
||||
$publications = $this->model::query()->whereIn(BaseModel::RECORD_STATUS_FIELD, [RecordStatusEnum::ACTIVE, RecordStatusEnum::DELETE])->where('id', $id)->get()->first();
|
||||
return view('read_message', ['publications' => $publications]);
|
||||
}
|
||||
|
||||
}
|
||||
100
app/Http/Controllers/QuantityController.php
Normal file
100
app/Http/Controllers/QuantityController.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\TestSampleCreateRequest;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Organism;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\Quantity;
|
||||
use App\Models\SampleType;
|
||||
use App\Models\Test;
|
||||
use App\Models\TestNormalValue;
|
||||
use App\Models\TestSample;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class QuantityController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
protected $departments;
|
||||
|
||||
public function __construct(Quantity $quantity){
|
||||
$this->model = $quantity;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_quantity'])) return redirect(url('my-profile'));
|
||||
$quantities = $this->model::with(['lab'])->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->kword), function ($quantities) use($request){
|
||||
$quantities->whereRaw("replace(quantity_name, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('quantity', ['quantities' => $quantities]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_quantity'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['quantity_name' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('organism.create_fail'), 'errors' =>$validator->errors()->all()]);
|
||||
$new = $this->model::query()->firstOrNew(['quantity_name' => $request->quantity_name]);
|
||||
$new->quantity_name = $request->quantity_name;
|
||||
//$new->lab_id = $this->baseLabId;
|
||||
$new->save();
|
||||
return response()->json(['success' => true, 'message' => __('quantity.create_success'), 'data' => [$new]]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('quantity.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_quantity'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['quantity_name' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('organism.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$this->model::query()->where('id', $request->uid)->update(array('quantity_name' => $request->quantity_name));
|
||||
return response()->json(['success' => true, 'message' => __('quantity.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('quantity.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$quantity = $this->model::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('quantity.get_success'), 'data' => $quantity]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('quantity.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_quantity'])) return false;
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('quantity.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('quantity.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('quantity.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('quantity.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
165
app/Http/Controllers/RepaymentController.php
Normal file
165
app/Http/Controllers/RepaymentController.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Repayment;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class RepaymentController extends Controller
|
||||
{
|
||||
protected $model;
|
||||
protected $baseLabId;
|
||||
protected $base;
|
||||
protected $invoiceModel;
|
||||
|
||||
|
||||
public function __construct(){
|
||||
$this->model = new Repayment();
|
||||
$this->invoiceModel = new Invoice();
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_repayment'])) return redirect(url('my-profile'));
|
||||
$recordStatusConditions = Auth::id()==1 ? [RecordStatusEnum::ACTIVE , RecordStatusEnum::DELETE] : [RecordStatusEnum::ACTIVE];
|
||||
$invoices = $this->invoiceModel::with(['sample.patient'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->where('balance','>', 0)->get();
|
||||
$repayments = $this->model::query()
|
||||
->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->from_date) && !empty($request->to_date), function ($inv) use ($request){
|
||||
$inv->whereBetween('repayment_date',[date('Y-m-d',strtotime($request->from_date)), date('Y-m-d',strtotime($request->to_date))]);
|
||||
})->when(!empty(trim($request->kword)), function ($inv) use($request, $recordStatusConditions){
|
||||
$inv->whereIn('invoice_id', $this->invoiceModel::query()
|
||||
->whereRaw("replace(invoice_code, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhere('patient_uuid','like','%'.$request->kword.'%')->pluck('id')->toArray()
|
||||
)->where('lab_id', $this->baseLabId)->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusConditions);
|
||||
})->orderBy('repayment_date','desc')->paginate(20);
|
||||
return view('repayment', ['oweInvoices' => $invoices, 'repayments' => $repayments, 'labSettings' => (object) $this->location()]);
|
||||
}
|
||||
|
||||
public function store(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_repayment'])) return false;
|
||||
$data = array(
|
||||
'invoice_id' => $request->invoice_id,
|
||||
'amount_to_pay' => $request->amount_to_pay,
|
||||
'discount' => $request->discount,
|
||||
'amount_after_discount' => $request->amount_after_discount,
|
||||
'discount_type' => $request->discount_type,
|
||||
'cash_repayment_amount' => $request->cash_repayment_amount,
|
||||
'bank_repayment_amount' => $request->bank_repayment_amount,
|
||||
'repayment_date' => date('Y-m-d', strtotime($request->repayment_date)),
|
||||
'payment_method' => $request->payment_method,
|
||||
'bank_name' => $request->bank_name,
|
||||
'transaction_ref' => $request->transaction_ref,
|
||||
'exchange_rate' => $request->exchange_rate,
|
||||
'lab_id' => $this->baseLabId,
|
||||
BaseModel::CREATED_AT => date('Y-m-d H:i:s'),
|
||||
BaseModel::CREATED_BY_FIELD => Auth::id()
|
||||
);
|
||||
$repayment = $this->model::query()->create($data);
|
||||
if($repayment){
|
||||
$invoice = $this->invoiceModel::query()->find($request->invoice_id);
|
||||
$totalRepayment = ($invoice->balance - ($request->cash_repayment_amount + $request->bank_repayment_amount));
|
||||
$invoice->deposit = ($invoice->deposit + $request->cash_repayment_amount);
|
||||
$invoice->bank_deposit = ($invoice->bank_deposit+$request->bank_repayment_amount);
|
||||
$invoice->balance = ($totalRepayment);
|
||||
$invoice->discount = $request->discount;
|
||||
$invoice->save();
|
||||
}
|
||||
else DB::rollBack();
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('invoice.create_success'), 'data' => $repayment]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => $e]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_repayment'])) return false;
|
||||
$data = array(
|
||||
'cash_repayment_amount' => $request->cash_repayment_amount,
|
||||
'bank_repayment_amount' => $request->bank_repayment_amount,
|
||||
'repayment_date' => date('Y-m-d', strtotime($request->repayment_date)),
|
||||
'payment_method' => $request->payment_method,
|
||||
'bank_name' => $request->bank_name,
|
||||
'transaction_ref' => $request->transaction_ref,
|
||||
'exchange_rate' => $request->exchange_rate
|
||||
);
|
||||
|
||||
$prevRepayment = $this->model::query()->find($request->uid);
|
||||
|
||||
$repayment = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->update($data);
|
||||
if($repayment){
|
||||
|
||||
$reviseInvoice = $this->invoiceModel::query()->find($request->invoice_id);
|
||||
$totalRepayment = ($reviseInvoice->balance + $prevRepayment->cash_repayment_amount + $prevRepayment->bank_repayment_amount);
|
||||
$reviseInvoice->deposit = (($reviseInvoice->deposit + $prevRepayment->cash_repayment_amount) - $request->cash_repayment_amount);
|
||||
$reviseInvoice->bank_deposit = (($reviseInvoice->bank_deposit + $prevRepayment->bank_repayment_amount) - $request->bank_repayment_amount);
|
||||
$reviseInvoice->balance = $totalRepayment - ($request->cash_repayment_amount + $request->bank_repayment_amount);
|
||||
$reviseInvoice->save();
|
||||
}
|
||||
else DB::rollBack();
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('invoice.create_success'), 'data' => $repayment]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Perform by ajax function
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_repayment'])) return redirect(url('my-profile'));
|
||||
$repayment = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->get()->first();
|
||||
$reviseInvoice = $this->invoiceModel::query()->find($repayment->invoice_id);
|
||||
$totalRepayment = ($reviseInvoice->balance + $repayment->cash_repayment_amount + $repayment->bank_repayment_amount);
|
||||
$reviseInvoice->deposit = ($reviseInvoice->deposit - $repayment->cash_repayment_amount);
|
||||
$reviseInvoice->bank_deposit = ($reviseInvoice->bank_deposit - $repayment->bank_repayment_amount);
|
||||
$reviseInvoice->balance = $totalRepayment;
|
||||
$reviseInvoice->save();
|
||||
$repayment->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('invoice.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('invoice.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$data = $this->model::with(['invoice.sample.patient'])->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('invoice.get_success'), 'data' => $data]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('invoice.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getInvoice(Request $request){
|
||||
try{
|
||||
$data = $this->invoiceModel::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('invoice.get_success'), 'data' => $data]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('invoice.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1168
app/Http/Controllers/ReportController.php
Normal file
1168
app/Http/Controllers/ReportController.php
Normal file
File diff suppressed because it is too large
Load Diff
193
app/Http/Controllers/RoleController.php
Normal file
193
app/Http/Controllers/RoleController.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Enums\UtilEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Role;
|
||||
use App\Models\RoleHasPermission;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
|
||||
protected $roleModel;
|
||||
protected $roleHasPermission;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
|
||||
public function __construct(RoleHasPermission $roleHasPermission, Role $roleModel){
|
||||
$this->roleModel = $roleModel;
|
||||
$this->roleHasPermission = $roleHasPermission;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_user_role'])) return redirect(url('my-profile'));
|
||||
$recordStatusCondition = Auth::id()==1 ? [RecordStatusEnum::DELETE, RecordStatusEnum::ACTIVE] : [RecordStatusEnum::ACTIVE];
|
||||
$roles = $this->roleModel::with('lab')->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusCondition)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->whereNotIn('id', [UtilEnum::ADMINISTRATOR_ROLE])
|
||||
->when(!empty($request->kword), function ($roles) use($request){
|
||||
$roles->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('role', ['roles' => $roles]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_user_role'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('system_role.create_fail'), 'errors'=>$validator->errors()->all()]);
|
||||
$new = $this->roleModel::query()->create(['name_en' => $request->name_en, 'lab_id' => $this->baseLabId]);
|
||||
return response()->json(['success' => true, 'message' => __('system_role.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('system_role.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_user_role'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('system_role.update_fail'), 'errors'=>$validator->errors()->all()]);
|
||||
$this->roleModel::query()->where('id', $request->uid)->update(array('name_en' => $request->name_en));
|
||||
return response()->json(['success' => true, 'message' => __('system_role.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('system_role.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$role = $this->roleModel::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('system_role.get_success'), 'data' => $role]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('system_role.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_user_role'])) return false;
|
||||
$this->roleModel::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD=> RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('system_role.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('system_role.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->roleModel::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD=> RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('system_role.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('system_role.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function storeRolePermission(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['assign_permission'])) return false;
|
||||
if(isset($request->permission_id)){
|
||||
foreach ($request->permission_id as $module_id){
|
||||
$this->roleHasPermission::query()->updateOrCreate([
|
||||
'role_id' => $request->uid,
|
||||
'permission_id' => $module_id,
|
||||
],[
|
||||
'role_id' => $request->uid,
|
||||
'permission_id' => $module_id
|
||||
]);
|
||||
}
|
||||
$this->roleHasPermission::query()->where('role_id', $request->uid)
|
||||
->whereNotIn('permission_id', $request->permission_id)
|
||||
->delete();
|
||||
}
|
||||
else{
|
||||
$this->roleHasPermission::query()->where('role_id', $request->uid)->delete();
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function viewPermissionByRoleId($roleId){
|
||||
try {
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['assign_permission','create_user_role','update_user_role'])) return false;
|
||||
$items = DB::select('SELECT
|
||||
pg.id,
|
||||
pg.weight,
|
||||
' . (App::getLocale() == 'en' ? 'pg.name_en' : 'pg.name_kh') . ' as permission_group,
|
||||
pg.`parent_id`,
|
||||
sp.id AS permission_id,
|
||||
' . (App::getLocale() == 'en' ? 'sp.name_en' : 'sp.name_kh') . ' as permission_name,
|
||||
IF(prm.permission_id IS NULL, 0, 1) AS is_can
|
||||
FROM `sys_permission_groups` pg
|
||||
INNER JOIN `sys_permissions` sp
|
||||
ON sp.`permission_group_id` = pg.`id`
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
*
|
||||
FROM `sys_role_has_permissions`
|
||||
WHERE role_id = ' . $roleId . '
|
||||
) prm
|
||||
ON prm.permission_id = sp.`id`
|
||||
where sp.record_status_id =1
|
||||
and pg.record_status_id=1
|
||||
');
|
||||
|
||||
$data = $this->arrayToTree($items); // $this->permissionGroup_::with(['subGroup.permission_','permission_'])->get();
|
||||
$arr_permission = array();
|
||||
foreach ($data as $item) {
|
||||
$arr_permission[$item->weight]['name'] = $item->permission_group;
|
||||
$arr = array(
|
||||
'id' => $item->permission_id,
|
||||
'name' => $item->permission_name,
|
||||
'is_can' => $item->is_can
|
||||
);
|
||||
$arr_child = array();
|
||||
if (@$item->children) {
|
||||
foreach ($item->children as $v) {
|
||||
$arr_child[$v->weight]['name'] = $v->permission_group;
|
||||
$arrc = array(
|
||||
'id' => $v->permission_id,
|
||||
'name' => $v->permission_name,
|
||||
'is_can' => $v->is_can
|
||||
);
|
||||
$arr_child[$v->weight]['permissions'][] = $arrc;
|
||||
}
|
||||
}
|
||||
$arr_permission[$item->weight]['permissions'][] = array_merge($arr, $arr_child);
|
||||
}
|
||||
return response()->json(['success' => true, 'message' => __('system_role.get_permission_success'), 'data' => $arr_permission]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('system_role.get_permission_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function arrayToTree(array $items, $parentId = 0) {
|
||||
$tree = [];
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->parent_id == $parentId) {
|
||||
$children = $this->arrayToTree($items, $item->id);
|
||||
if ($children) {
|
||||
$item->children = $children;
|
||||
}
|
||||
$tree[] = $item;
|
||||
}
|
||||
}
|
||||
return $tree;
|
||||
}
|
||||
|
||||
}
|
||||
876
app/Http/Controllers/SampleController.php
Normal file
876
app/Http/Controllers/SampleController.php
Normal file
@@ -0,0 +1,876 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Helpers\Helpers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Enums\UtilEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\SampleCreateRequest;
|
||||
use App\Http\Requests\SampleDetailCreateRequest;
|
||||
use App\Http\Requests\UpdateRequests\SampleUpdateRequest;
|
||||
use App\Http\Resources\SampleResource;
|
||||
use App\Models\AntibioticResult;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\OrganismResult;
|
||||
use App\Models\Patient;
|
||||
use App\Models\Physician;
|
||||
use App\Models\RejectComment;
|
||||
use App\Models\Sample;
|
||||
use App\Models\SampleDetail;
|
||||
use App\Models\SampleSource;
|
||||
use App\Models\TestGroup;
|
||||
use App\Models\TestResult;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Telegram\Bot\Api;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceDetail;
|
||||
|
||||
use App\Models\LabConfigure;
|
||||
|
||||
class SampleController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $physicianModel;
|
||||
protected $sampleSourceModel;
|
||||
protected $patientModel;
|
||||
protected $rejectCommentModel;
|
||||
protected $sampleDetailModel;
|
||||
protected $testResultModel;
|
||||
protected $testGroupModel;
|
||||
protected $organismResultModel;
|
||||
protected $antibioticResultModel;
|
||||
|
||||
protected $baseLabId;
|
||||
protected $base;
|
||||
|
||||
protected $invoiceModel;
|
||||
protected $invoiceDetailModel;
|
||||
protected $laboratoryConfigures;
|
||||
|
||||
public function __construct(Sample $sampleModel, Physician $physicianModel, RejectComment $rejectCommentModel, TestGroup $testGroupModel,
|
||||
SampleSource $sampleSourceModel, Patient $patientModel, SampleDetail $sampleDetailModel, TestResult $testResultModel,
|
||||
OrganismResult $organismResultModel, AntibioticResult $antibioticResultModel, Invoice $invoiceModel, InvoiceDetail $invoiceDetailModel, LabConfigure $laboratoryConfigures
|
||||
){
|
||||
$this->model = $sampleModel;
|
||||
$this->physicianModel = $physicianModel;
|
||||
$this->sampleSourceModel = $sampleSourceModel;
|
||||
$this->patientModel = $patientModel;
|
||||
$this->rejectCommentModel = $rejectCommentModel;
|
||||
$this->sampleDetailModel = $sampleDetailModel;
|
||||
$this->testResultModel = $testResultModel;
|
||||
$this->testGroupModel = $testGroupModel;
|
||||
$this->organismResultModel = $organismResultModel;
|
||||
$this->antibioticResultModel = $antibioticResultModel;
|
||||
|
||||
$this->invoiceModel = $invoiceModel;
|
||||
$this->invoiceDetailModel = $invoiceDetailModel;
|
||||
$this->laboratoryConfigures = $laboratoryConfigures;
|
||||
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_sample'])) return redirect(url('my-profile'));
|
||||
$recordStatusConditions = Auth::id()==1 ? [RecordStatusEnum::ACTIVE, RecordStatusEnum::DELETE] : [RecordStatusEnum::ACTIVE];
|
||||
$samples = $this->model::with(['patient','sample_source'])
|
||||
->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusConditions)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(Auth::user()->role_id == UtilEnum::PHYSICIAN_ROLE, function($sample){
|
||||
$sample->where('sample_source_id', Auth::user()->sample_source_id);
|
||||
})->when(!empty(trim($request->kword)), function ($samples) use($request, $recordStatusConditions){
|
||||
$samples->whereRaw("replace(sample_number, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhereIn('patient_id', $this->patientModel::query()
|
||||
->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhereRaw("replace(phone_number, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhere('patient_uuid','like','%'.$request->kword.'%')->pluck('id')->toArray()
|
||||
)->where('lab_id', $this->baseLabId)->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusConditions);
|
||||
})->when(!empty(trim($request->sample_status)), function ($samples) use($request){
|
||||
$samples->whereIn('id', $this->filterSampleStatus($request->sample_status));
|
||||
})->when(!empty($request->sample_date) && empty($request->kword) , function ($samples) use($request){
|
||||
$samples->whereDate('admission_date', date('Y-m-d',strtotime($request->sample_date)));
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('sample', ['samples' => $samples]);
|
||||
}
|
||||
|
||||
function filterSampleStatus($statusId){
|
||||
if($statusId == 5){ // rejected
|
||||
$wheres = " and sample.`sample_condition` = 0 ";
|
||||
}elseif ($statusId == 4){ // printed
|
||||
$wheres = " and (sample.`sample_condition` <>0 and sample.`is_printed` = 1) ";
|
||||
}elseif ($statusId == 1){ // pending, not request test, no result input
|
||||
$wheres = " and (sample.`sample_condition` <>0 and sample.`is_printed` = 0 and (non_heading_tests=0 or (done_numeric_tests+done_org_test)=0)) ";
|
||||
}elseif ($statusId == 3){
|
||||
$wheres = " and (sample.`sample_condition` <>0 and sample.`is_printed` = 0 and non_heading_tests>0 and non_heading_tests = (done_numeric_tests+done_org_test))";
|
||||
}elseif ($statusId ==2 ){
|
||||
$wheres = " and (sample.`sample_condition` <>0 and sample.`is_printed` = 0 and (done_numeric_tests+done_org_test)>0 and non_heading_tests > (done_numeric_tests+done_org_test))";
|
||||
} else{
|
||||
$wheres = "";
|
||||
}
|
||||
|
||||
$resultItemsData = DB::select('SELECT
|
||||
*
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
s.id,
|
||||
s.`sample_number`,
|
||||
IFNULL(sample_condition,1) AS sample_condition,
|
||||
is_printed,
|
||||
SUM(IF(ts.`field_type`>0, 1,0)) AS non_heading_tests,
|
||||
SUM(IF(ts.`field_type` IN(1,4) AND tr.test_result IS NOT NULL, 1, 0)) AS done_numeric_tests,
|
||||
SUM(IF(ts.`field_type` IN(2,3) AND org_result.total_org_result>0, 1, 0)) AS done_org_test
|
||||
FROM samples s
|
||||
LEFT JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
AND s.`lab_id` = tr.`lab_id`
|
||||
LEFT JOIN test_samples ts
|
||||
ON ts.id = tr.`test_sample_id`
|
||||
AND ts.lab_id = tr.lab_id
|
||||
LEFT JOIN sample_types st
|
||||
ON st.id = ts.`sample_type_id`
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
tr.`id`,
|
||||
COUNT(*) AS total_org_result
|
||||
FROM samples s
|
||||
INNER JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
AND s.`lab_id` = tr.`lab_id`
|
||||
INNER JOIN organism_results orgr
|
||||
ON orgr.`test_result_id` = tr.`id`
|
||||
WHERE s.lab_id = '.$this->baseLabId.'
|
||||
AND tr.`record_status_id` = 1
|
||||
AND orgr.`record_status_id` = 1
|
||||
GROUP BY tr.id
|
||||
) AS org_result
|
||||
ON org_result.id = tr.`id`
|
||||
WHERE s.`lab_id` = '.$this->baseLabId.'
|
||||
AND s.`record_status_id` = 1
|
||||
AND (tr.`record_status_id` = 1 OR tr.`record_status_id` IS NULL)
|
||||
AND (st.`record_status_id` = 1 OR st.`record_status_id` IS NULL)
|
||||
GROUP BY s.id, s.`sample_number`, s.sample_condition, s.is_printed
|
||||
) sample
|
||||
WHERE 1 '.$wheres.'
|
||||
|
||||
');
|
||||
$arr = [];
|
||||
foreach ($resultItemsData as $row){
|
||||
$arr[] = $row->id;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function create($patient_id = null){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_sample'])) return redirect(url('my-profile'));
|
||||
$rejectComments = $this->rejectCommentModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->orderBy('reject_comment', 'ASC')->get();
|
||||
$physicians = $this->physicianModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->orderBy('name_en', 'ASC')->get();
|
||||
$sampleSources = $this->sampleSourceModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->orderBy('name_en','ASC')->get();
|
||||
$patients = $this->patientModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->when(!empty($patient_id), function ($patients) use ($patient_id){
|
||||
$patients->where(['id' => $patient_id, 'lab_id' => $this->baseLabId ]);
|
||||
})->orderBy(BaseModel::CREATED_AT_FIELD, 'DESC')->limit(30)->get();
|
||||
$testGroups = $this->testGroupModel::with(['testGroupDetails'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->orderBy('created_at')->get();
|
||||
return view('new_sample', [
|
||||
'labSettings' => (object) $this->base,
|
||||
'physicians' => $physicians,
|
||||
'sampleSources' => $sampleSources,
|
||||
'patients' => $patients,
|
||||
'rejectComments' => $rejectComments,
|
||||
'provinces' => $this->province(),
|
||||
'patient_id' => $patient_id,
|
||||
'testGroups' => $testGroups
|
||||
]);
|
||||
}
|
||||
|
||||
public function generateAutoId($admissionDate){
|
||||
$prefix = date('ymd',strtotime($admissionDate));
|
||||
$sample = Sample::query();
|
||||
$sampleCount = $sample->where('lab_id', $this->baseLabId)->whereRaw('date(admission_date) ="'. date('Y-m-d',strtotime($admissionDate)).'"')->count();
|
||||
return 'S-'.$this->base['short_name'].'-'.$prefix.'-'.(str_pad(($sampleCount+1),3,'0',STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
public function store(SampleCreateRequest $sampleCreateRequest){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_sample'])) return false;
|
||||
$request = collect($sampleCreateRequest)->merge(['lab_id'=>$this->baseLabId]);
|
||||
if(empty($sampleCreateRequest->sample_number)) {
|
||||
$sampleNumber = $this->generateAutoId($sampleCreateRequest->admission_date);
|
||||
$request = $request->merge(['sample_number' => $sampleNumber]);
|
||||
}
|
||||
|
||||
$sample = $this->model::query()->where(['sample_number' => $request['sample_number']])->get()->first();
|
||||
if(!empty($sample)){
|
||||
if($sample->patient_id !=$request['patient_id']){
|
||||
if(empty($sampleCreateRequest->sample_number)) {
|
||||
sleep(50);
|
||||
$sampleNumber = $this->generateAutoId($sampleCreateRequest->admission_date);
|
||||
$request = $request->merge(['sample_number' => $sampleNumber]);
|
||||
}
|
||||
else{
|
||||
return response()->json(['success' => false, 'message' => __('comment.create_fail'), 'errors' => ['Duplicate Sample Number']]);
|
||||
}
|
||||
$patientSample = $this->model::query()->create($request->all());
|
||||
$patientSample = $this->model::with(['patient','sample_source'])->find($patientSample->id);
|
||||
}
|
||||
else{
|
||||
$patientSample = $this->model::with(['patient','sample_source'])->find($sample->id);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$patientSample = $this->model::query()->create($request->all());
|
||||
$patientSample = $this->model::with(['patient','sample_source','physician'])->find($patientSample->id);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('sample.create_success'), 'data' => new SampleResource($patientSample)]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('comment.create_fail'), 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function store1(SampleCreateRequest $sampleCreateRequest){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$request = collect($sampleCreateRequest)->merge(['lab_id'=>$this->baseLabId]);
|
||||
if(empty($sampleCreateRequest->sample_number)) {
|
||||
$sampleNumber = $this->generateAutoId($sampleCreateRequest->admission_date);
|
||||
$request = $request->merge(['sample_number' => $sampleNumber]);
|
||||
}
|
||||
$patientSample = $this->model::query()->create($request->all());
|
||||
$patientSample = $this->model::with(['patient','sample_source'])->find($patientSample->id);
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('sample.create_success'), 'data' => new SampleResource($patientSample)]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('comment.create_fail'), 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(Request $request, $id){ // url: base_url/sample/edit/[sample-id]
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_sample'])) return redirect(url('my-profile'));
|
||||
$sample = $this->model::with(['patient'/*'patient.telegramChatId'*/,'invoice'])->where(['lab_id' => $this->baseLabId,'id' => $id])->first();
|
||||
$rejectComments = $this->rejectCommentModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->orderBy('reject_comment', 'ASC')->get();
|
||||
$physicians = $this->physicianModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->orderBy('name_en', 'ASC')->get();
|
||||
$samplePhysician = $this->physicianModel::query()->where('id', $sample->physician_id)->first();
|
||||
$sampleSources = $this->sampleSourceModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->orderBy('name_en','ASC')->get();
|
||||
$testGroups = $this->testGroupModel::with(['testGroupDetails'])->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->orderBy('created_at')->get();
|
||||
|
||||
$now = strtotime($sample->admission_date); // or your date as well
|
||||
$your_date = strtotime($sample->patient->dob);
|
||||
$datediff = $now - $your_date;
|
||||
|
||||
$form = $sample->sample_tests->pluck('testSample')->pluck('sample')->unique()->first();
|
||||
|
||||
$enter_form_id = $form->enter_form_id ?? ($this->base['lab_category_id']==0? 1:2);
|
||||
$preview_form_id = $form->preview_form_id ?? ($this->base['lab_category_id']==0? 1:2);
|
||||
|
||||
$prevSample = [];
|
||||
if(isset($_GET['previous_sample'])){
|
||||
$prevSample = $this->model::with(['patient','invoice'])->where(['lab_id' => $this->baseLabId, 'id' => $_GET['previous_sample']])->get();
|
||||
}
|
||||
|
||||
$labConfigures = $this->laboratoryConfigures::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get()->toArray();
|
||||
|
||||
$resultTemplateId = (collect($labConfigures)->where('atrribute_code', 'RESULT_TEMPLATE')->pluck('assigned_attribute_value')->first());
|
||||
if(!empty($resultTemplateId)){
|
||||
$preview_form_id = $resultTemplateId;
|
||||
}
|
||||
|
||||
if($sample->result_template_id > 0){
|
||||
$preview_form_id = $sample->result_template_id;
|
||||
}
|
||||
|
||||
return view('sample_edition', [
|
||||
'sample' => $sample,
|
||||
'labSettings' => (object) $this->base,
|
||||
'physicians' => $physicians,
|
||||
'sampleSources' => $sampleSources,
|
||||
'rejectComments' => $rejectComments,
|
||||
'testGroups' => $testGroups,
|
||||
'samplePhysician' => $samplePhysician,
|
||||
'agedy' => number_format((round($datediff / (60 * 60 * 24))/360),2),
|
||||
'enter_form_id' => $enter_form_id, // $form->enter_form_id ?? 1,
|
||||
'preview_form_id' => $preview_form_id . (isset($request->previous_sample) ? '_previous_sample':''),
|
||||
'previous_samples' => $this->getPreviousSample($sample->patient_id, $id),
|
||||
'labConfigures' => $labConfigures,
|
||||
'prevSample' => $prevSample,
|
||||
'firstPrvSampleId' => (int)@$this->getPreviousSample($sample->patient_id, $id)->first()->id,
|
||||
'firstPrvSampleDate' => (string) !empty($this->getPreviousSample($sample->patient_id, $id)->first()) ? date('d-m-Y', strtotime($this->getPreviousSample($sample->patient_id, $id)->first()->admission_date)) : '',
|
||||
'selected_pre_sample_date' => isset($request->previous_sample) ? date('d-m-Y', strtotime($this->getPreviousSample($sample->patient_id, $id)->where('id', $request->previous_sample)->first()->admission_date)) : ''
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getPreviousSample($patientId, $curSampleId){
|
||||
return $this->model::query()->where(['patient_id' => $patientId, 'lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->where('id','<', $curSampleId)->orderBy('id', 'desc')->get(['id','admission_date', 'sample_number']);
|
||||
}
|
||||
|
||||
/** Update Sample Only
|
||||
* @param SampleUpdateRequest $sampleUpdateRequest
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
|
||||
public function update(SampleUpdateRequest $sampleUpdateRequest){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_sample'])) return redirect(url('my-profile'));
|
||||
$request = collect($sampleUpdateRequest)->except(['id','sample_number','patient_id','_token']);
|
||||
$patientSample = $this->model::query()->where(['id' => $sampleUpdateRequest->id, 'lab_id' => $this->baseLabId])->first();
|
||||
$patientSample->update($request->all());
|
||||
DB::commit();
|
||||
$sampleUpdateRequest->session()->flash('message','Update success.');
|
||||
return redirect()->back();
|
||||
} catch (\Exception $e){
|
||||
if(Auth::id()==1){
|
||||
dd($e);
|
||||
}
|
||||
DB::rollBack();
|
||||
$sampleUpdateRequest->session()->flash('message','Update failed.');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
/** Perform by ajax function */
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_sample'])) return false;
|
||||
$patientSample = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->first();
|
||||
$patientSample->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('sample.delete_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$patientSample = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->first();
|
||||
$patientSample->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('sample.restore_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function approve(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['approve_result'])) return false;
|
||||
$patientSample = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->first();
|
||||
$patientSample->update(array('approved_by' => Auth::id(), 'approved_date' => date('Y-m-d H:i:s')));
|
||||
return response()->json(['success' => true, 'message' => __('sample.approve_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample.approve_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sample Detail / Assign Test */
|
||||
|
||||
public function storeSampleDetail(SampleDetailCreateRequest $sampleCreateRequest){
|
||||
set_time_limit(6000);
|
||||
ini_set('memory_limit', '10240M');
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_sample', 'update_sample'])) return false;
|
||||
$this->sampleDetailModel::query()->where(['sample_id' => $sampleCreateRequest->sample_id, 'lab_id' => $this->baseLabId])->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
$sampleDetails = collect($sampleCreateRequest->sample_details);
|
||||
$sampleDetails->map(function ($item){
|
||||
if(!empty($item['sample_description'])){
|
||||
$sampleDetail = $this->sampleDetailModel::query()->create([
|
||||
'sample_id' => $item['sample_id'],
|
||||
'sample_type_id' => $item['sample_type_id'],
|
||||
'test_date' => date('Y-m-d'),
|
||||
'lab_technician_id' => Auth::id(),
|
||||
'sample_descr' => $item['sample_description'],
|
||||
'lab_id' => $this->baseLabId
|
||||
]);
|
||||
}
|
||||
});
|
||||
//dd($sampleCreateRequest->sample_tests);
|
||||
if(!empty($sampleCreateRequest->sample_tests)){
|
||||
$this->testResultModel::query()->where(['sample_id' => $sampleCreateRequest->sample_id, 'lab_id' => $this->baseLabId])
|
||||
->whereNotIn('test_sample_id', $sampleCreateRequest->sample_tests)
|
||||
->delete();
|
||||
foreach ($sampleCreateRequest->sample_tests as $test){
|
||||
$existingTestResult = $this->testResultModel::query()->where([
|
||||
'test_sample_id' => $test,
|
||||
'lab_id' => $this->baseLabId,
|
||||
'sample_id' => $sampleCreateRequest->sample_id
|
||||
])->get()->toArray();
|
||||
if(empty($existingTestResult)) {
|
||||
$testResult = $this->testResultModel::query()->create([
|
||||
'sample_id' => $sampleCreateRequest->sample_id,
|
||||
'test_sample_id' => $test,
|
||||
'lab_id' => $this->baseLabId
|
||||
]);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$this->testResultModel::query()->where(['sample_id' => $sampleCreateRequest->sample_id, 'lab_id' => $this->baseLabId])->delete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create or Update Invoice in case invoice generation mode is auto start
|
||||
*/
|
||||
|
||||
$labSettings = (object) $this->base;
|
||||
if($labSettings->is_auto_make_invoice == 1) {
|
||||
$sample = $this->model::with('invoice')->find($sampleCreateRequest->sample_id);
|
||||
$invoiceDetail = $this->makeInvoice($sample->id);
|
||||
|
||||
$request = new Request($invoiceDetail);
|
||||
$summary = collect($request);
|
||||
|
||||
$total = $summary->sum('usd_price');
|
||||
$grossTotal = $summary->sum('item_discount'); // total price after discount
|
||||
$discount = $total - $grossTotal;
|
||||
$invoiceId = 0;
|
||||
$discounts = $summary->sum('discount_price');
|
||||
if (empty($sample->invoice)) {
|
||||
// create new
|
||||
$invoiceRequest = collect($request)->merge([
|
||||
'invoice_code' => $this->generateInvoiceId(date('Y-m-d', strtotime($sample->admission_date))),// 'I-'.Helpers::generateUuId($labSettings->short_name),
|
||||
'sample_id' => $sample->id,
|
||||
'total' => $total * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1),
|
||||
'discount' => $discounts * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1),
|
||||
'discount_type' => $labSettings->discount_type,
|
||||
'gross_total' => number_format($grossTotal * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1),2, '.', ''),
|
||||
'deposit' => 0,
|
||||
'bank_deposit' => 0,
|
||||
'balance' => number_format($grossTotal * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1),2, '.', ''),
|
||||
'invoice_date' => date('Y-m-d', strtotime($sample->admission_date)),
|
||||
'lab_id'=>$this->baseLabId,
|
||||
'exchange_rate' => $labSettings->exchange_rate
|
||||
]);
|
||||
$invoice = $this->invoiceModel::query()->create($invoiceRequest->all());
|
||||
$invoiceId = $invoice->id;
|
||||
}
|
||||
else {
|
||||
$invoiceId = $sample->invoice->id;
|
||||
$editInvoice = $this->invoiceModel::query()->find($sample->invoice->id);
|
||||
$deposit = $editInvoice->deposit;
|
||||
$bank_deposit = $editInvoice->bank_deposit;
|
||||
$editInvoice->total = $total * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1);
|
||||
$editInvoice->discount = $discounts * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1);
|
||||
$editInvoice->gross_total = number_format($grossTotal * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1),2, '.', '');
|
||||
$editInvoice->balance = number_format(($grossTotal-($deposit+$bank_deposit)),2, '.', '');
|
||||
$editInvoice->save();
|
||||
$this->invoiceDetailModel::query()->where('invoice_id', $sample->invoice->id)->delete();
|
||||
}
|
||||
// Refresh Invoice Detail
|
||||
$invoiceDetailRequest = collect($invoiceDetail);
|
||||
$items = $invoiceDetailRequest->map(function ($row) use($invoiceId, $labSettings) {
|
||||
$invoiceDetailRow = $this->invoiceDetailModel::query()->create([
|
||||
'invoice_id' => $invoiceId,
|
||||
'test_sample_id' => $row['test_sample_id'],
|
||||
'discount_type' => $row['item_discount_type'],
|
||||
'discount' => $row['item_discount'],
|
||||
'test_name' => $row['group_result'],
|
||||
'qty' => 1,
|
||||
'unit_price' => $row['usd_price'] * ($labSettings->currency==1 ? $labSettings->exchange_rate : 1),
|
||||
]);
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or Update Invoice in case invoice generation mode is auto end
|
||||
*/
|
||||
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('sample.assign_tests_success')]);
|
||||
} catch (\Exception $e){
|
||||
Log::error($e);
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function storeSampleTestResult(Request $request){
|
||||
set_time_limit(6000);
|
||||
ini_set('memory_limit', '10240M');
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['add_result', 'update_result', 'delete_result'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['sample_id' => 'required', 'ref_test_sample_id' => 'nullable', 'ref_test_sample_id_value' => 'nullable', 'test_samples_to_hide' => 'nullable', 'ref_test_sample_performer' => 'nullable']);
|
||||
if ($validator->fails()) {return response()->json(['errors'=>$validator->errors()->all()]);}
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$sample = $this->model::query()->find($request->sample_id);
|
||||
$sample->update([
|
||||
BaseModel::UPDATED_AT_FIELD => date('Y-m-d H:i:s'),
|
||||
BaseModel::UPDATED_BY_FIELD => Auth::id()
|
||||
]);
|
||||
// add test result
|
||||
if(isset($request->ref_test_sample_id)){
|
||||
$data = collect($request->ref_test_sample_id);
|
||||
$ref_test_sample_id_value = collect($request->ref_test_sample_id_value);
|
||||
$ref_test_date = collect($request->ref_test_sample_test_date);
|
||||
$ref_performed_by = collect($request->ref_test_sample_performer);
|
||||
$ref_test_sample_comment = collect($request->ref_test_sample_comment);
|
||||
$vars = $data->map(function ($val, $key) use($request, $ref_test_sample_id_value, $ref_test_date, $ref_performed_by, $ref_test_sample_comment){
|
||||
$this->testResultModel::query()->where(['lab_id' => $this->baseLabId, 'sample_id' => $request->sample_id, 'test_sample_id' => $val])->update([
|
||||
'test_result' => @$ref_test_sample_id_value[$key],
|
||||
'test_date' => @$ref_test_date[$key],
|
||||
'performed_by' => @$ref_performed_by[$key],
|
||||
'comment' => $ref_test_sample_comment[$key],
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if(isset($request->ref_test_sample_id___)){
|
||||
$datas = collect($request->ref_test_sample_id___);
|
||||
//$ref_test_date = collect($request->ref_test_sample_test_date);
|
||||
//$ref_performed_by = collect($request->ref_test_sample_performer);
|
||||
$ref_test_sample_comment_ = collect($request->ref_test_sample_comment___);
|
||||
$vars = $datas->map(function ($val_, $key_) use($request, $ref_test_sample_comment_){
|
||||
$this->testResultModel::query()->where(['lab_id' => $this->baseLabId, 'sample_id' => $request->sample_id, 'test_sample_id' => $val_])->update([
|
||||
//'test_date' => @$ref_test_date[$key],
|
||||
//'performed_by' => @$ref_performed_by[$key],
|
||||
'comment' => $ref_test_sample_comment_[$key_],
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
// set hide test
|
||||
|
||||
if(isset($request->test_samples_to_hide)){
|
||||
$this->testResultModel::query()->where(['lab_id' => $this->baseLabId, 'sample_id' => $request->sample_id])
|
||||
->whereNotIn('test_sample_id', $request->test_samples_to_hide)->update(['is_show' => 1]);
|
||||
|
||||
foreach ($request->test_samples_to_hide as $val){
|
||||
$this->testResultModel::query()->where(['lab_id' => $this->baseLabId, 'sample_id' => $request->sample_id, 'test_sample_id' => $val])->update([
|
||||
'is_show' => 0
|
||||
]);
|
||||
}
|
||||
} else{
|
||||
$this->testResultModel::query()->where(['lab_id' => $this->baseLabId, 'sample_id' => $request->sample_id])->update(['is_show' => 1]);
|
||||
}
|
||||
|
||||
// organism result
|
||||
if(isset($request->possible_result)){
|
||||
$possible_results = collect(json_decode($request->possible_result))->flatten(1);
|
||||
//$organismIds = $possible_results->pluck('organism_id')->toArray();
|
||||
foreach ($possible_results as $k=>$org){
|
||||
|
||||
$organismIds = $possible_results->filter(function($item) use($org){
|
||||
return $item->test_sample_id == $org->test_sample_id;
|
||||
})->pluck('organism_id')->toArray();
|
||||
|
||||
// change on 08/Sep/2023 to fixed issue save result success but no data affect
|
||||
//$testResult = $this->testResultModel::query()->where(['test_sample_id' => $org->test_sample_id, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->orderByDesc('id')->limit(1)->first();
|
||||
$testResult = $this->testResultModel::query()->where(['test_sample_id' => $org->test_sample_id, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId, 'sample_id' => $request->sample_id])->orderByDesc('id')->limit(1)->first();
|
||||
|
||||
if(count($organismIds)>0){
|
||||
$this->organismResultModel::query()->where(['test_result_id' => $testResult->id, 'lab_id' => $this->baseLabId])->whereNotIn('organism_id', $organismIds)->update(['record_status_id' => 0]);
|
||||
}
|
||||
|
||||
$organismResult = $this->organismResultModel::query()->where(['test_result_id' => $testResult->id, 'organism_id' => $org->organism_id, BaseModel::RECORD_STATUS_FIELD =>RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->first();
|
||||
//$organismResultId = 0;
|
||||
|
||||
if(!empty($organismResult)){
|
||||
$organismResultId = $organismResult->id;
|
||||
$this->organismResultModel::query()->find($organismResult->id)->update([
|
||||
'quantity_id' => (int)$org->quantity_id,
|
||||
'contaminant' => $org->contaminant
|
||||
]);
|
||||
}
|
||||
else{
|
||||
$savedOrg = $this->organismResultModel::query()->create([
|
||||
'test_result_id' => $testResult->id,
|
||||
'organism_id' => $org->organism_id,
|
||||
'quantity_id' => (int)$org->quantity_id,
|
||||
'contaminant' => $org->contaminant,
|
||||
'lab_id' => $this->baseLabId,
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
||||
BaseModel::CREATED_AT => date('Y-m-d H:i:s')
|
||||
]);
|
||||
$organismResultId = $savedOrg->id;
|
||||
}
|
||||
|
||||
|
||||
if(isset($request->anti_result)){
|
||||
$anti_result = collect(json_decode($request->anti_result))->flatten(1);
|
||||
if(in_array($org->test_organism_id, $anti_result->pluck('test_organism_id')->unique()->flatten(1)->toArray())){
|
||||
$this->antibioticResultModel::query()->where('organism_result_id', $organismResultId)->delete();
|
||||
}
|
||||
foreach ($anti_result as $j=>$anti){
|
||||
if($anti->test_organism_id == $org->test_organism_id && $anti->sensitive !="") {
|
||||
$this->antibioticResultModel::query()->updateOrCreate([
|
||||
'organism_result_id' => $organismResultId,
|
||||
'antibiotic_id' => $anti->antibiotic_id
|
||||
], [
|
||||
'organism_result_id' => $organismResultId,
|
||||
'antibiotic_id' => $anti->antibiotic_id,
|
||||
'disk_diffusion' => $anti->disk_diffusion,
|
||||
'mic' => $anti->mic,
|
||||
'sensitive' => $anti->sensitive,
|
||||
'is_hide' => $anti->is_hide,
|
||||
BaseModel::CREATED_AT_FIELD => date('Y-m-d H:i:s'),
|
||||
BaseModel::CREATED_BY_FIELD => Auth::id(),
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'message' => 'Sample result already saved.']);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
Log::error($e);
|
||||
return response()->json(['success'=> false , 'error' => 'Failed while update sample result.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSampleTest($sample_id){
|
||||
try{
|
||||
$sample = $this->model::with(['patient','sample_source','sample_details','sample_tests', 'physician'])->find($sample_id);
|
||||
return response()->json(['success'=> true , 'data' => new SampleResource($sample)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function makeInvoice($sampleId){
|
||||
try{
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
d.`id` AS department_id,
|
||||
d.`name_en` AS department_name,
|
||||
d.weight as dweight,
|
||||
st.`id` AS sample_type_id,
|
||||
st.weight as sweight,
|
||||
st.`name_en` AS sample_type,
|
||||
ts.`id` AS test_sample_id,
|
||||
ts.`heading_id` AS parent_id,
|
||||
ts.`field_type`,
|
||||
ts.`usd_price`,
|
||||
ts.group_result,
|
||||
ts.description,
|
||||
t.`id` AS test_id,
|
||||
t.`name_en` AS test_name,
|
||||
tr.id as test_result_id,
|
||||
pct.`commission_type`,
|
||||
ifnull(pct.`commission_rate`, 0.00) as commission_rate,
|
||||
ifnull(pct.`partner_price`, 0.00) as partner_price,
|
||||
ts.weight
|
||||
FROM samples s
|
||||
INNER JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
AND s.`lab_id` = tr.`lab_id`
|
||||
INNER JOIN test_samples ts
|
||||
ON ts.id = tr.`test_sample_id`
|
||||
and ts.lab_id = tr.lab_id
|
||||
INNER JOIN tests t
|
||||
ON t.`id` = ts.`test_id`
|
||||
INNER JOIN sample_types st
|
||||
ON st.`id` = ts.`sample_type_id`
|
||||
INNER JOIN departments d
|
||||
ON d.`id` = st.`department_id`
|
||||
LEFT JOIN `physician_commisssion` AS pct
|
||||
ON pct.`test_sample_id` = ts.`id`
|
||||
AND pct.`physician_id` = s.`physician_id`
|
||||
WHERE s.`id` = '.$sampleId.'
|
||||
AND s.`lab_id`= '.$this->baseLabId.'
|
||||
AND tr.`record_status_id` = '.BaseModel::RECORD_STATUS_ACTIVE.'
|
||||
AND LENGTH(ts.group_result)>0
|
||||
AND ts.usd_price>0
|
||||
ORDER BY
|
||||
d.`weight`,
|
||||
st.`weight`,
|
||||
ts.`weight`');
|
||||
$departmentArray = array();
|
||||
foreach ($resultItems as $row){
|
||||
$net_amount = number_format((((!empty($row->commission_type) ? $row->commission_type : ((object) $this->location())->discount_type)) ==2 ? (($row->usd_price - $row->partner_price) - $row->commission_rate) :
|
||||
(($row->usd_price - $row->partner_price) * (1-$row->commission_rate/100))),3);
|
||||
$testItemArray = array(
|
||||
'test_sample_id' => (string)$row->test_sample_id,
|
||||
'test_id' => $row->test_id,
|
||||
'test_name' => $row->test_name,
|
||||
'closed_parent_id' => (string) (int)$row->parent_id,
|
||||
'field_type' => (string) $row->field_type,
|
||||
'usd_price' => $row->usd_price,
|
||||
'group_result' => (string) $row->group_result,
|
||||
'item_discount_type' => (!empty($row->commission_type) ? $row->commission_type : ((object) $this->location())->discount_type),
|
||||
'item_discount_rate' => $row->commission_rate,
|
||||
'item_discount' => $net_amount,
|
||||
'discount_price' => ($row->usd_price - $net_amount)
|
||||
);
|
||||
$departmentArray[] = $testItemArray;
|
||||
}
|
||||
return $departmentArray;
|
||||
} catch (\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
function printRecorder(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$patientSample = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->first();
|
||||
if($patientSample->is_printed==0) {
|
||||
$patientSample->update(
|
||||
[
|
||||
'is_printed' => 1,
|
||||
'printed_at' => date('Y-m-d H:i:s'),
|
||||
'printed_by' => Auth::id()
|
||||
]
|
||||
);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'data' => $patientSample]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateInvoiceId($invoiceDate){
|
||||
$prefix = date('y',strtotime($invoiceDate));
|
||||
$invoiceCount = $this->invoiceModel::query()->where('lab_id', $this->baseLabId)->whereRaw('year(invoice_date) ="'. date('Y',strtotime($invoiceDate)).'"')->count();
|
||||
return 'I-'.$this->base['short_name'].'-'.$prefix.'-'.(str_pad(($invoiceCount+1),5,'0',STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function temporarySaveOrganismResult($sampleId, $testSampleId, $organismId){
|
||||
// if(Auth::user()->id==1){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$testResult = $this->testResultModel::query()->where(['test_sample_id' => $testSampleId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId, 'sample_id' => $sampleId])->orderByDesc('id')->limit(1)->first();
|
||||
$organismResult = $this->organismResultModel::query()->where(['test_result_id' => $testResult->id, 'organism_id' => $organismId, BaseModel::RECORD_STATUS_FIELD =>RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->first();
|
||||
if(empty($organismResult)){
|
||||
|
||||
$savedOrg = $this->organismResultModel::query()->create([
|
||||
'test_result_id' => $testResult->id,
|
||||
'organism_id' => $organismId,
|
||||
'quantity_id' => 0,
|
||||
'contaminant' => 0,
|
||||
'lab_id' => $this->baseLabId,
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
||||
BaseModel::CREATED_AT => date('Y-m-d H:i:s')
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'message' => 'organisam_result_saved']);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
function temporarySaveOrganismResultQuantity($sampleId, $testSampleId, $organismId, $qtyId){
|
||||
//if(Auth::user()->id==1){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$testResult = $this->testResultModel::query()->where(['test_sample_id' => $testSampleId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId, 'sample_id' => $sampleId])->orderByDesc('id')->limit(1)->first();
|
||||
$organismResult = $this->organismResultModel::query()->where(['test_result_id' => $testResult->id, 'organism_id' => $organismId, BaseModel::RECORD_STATUS_FIELD =>RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->first();
|
||||
if(!empty($organismResult)){
|
||||
$savedOrg = $this->organismResultModel::query()->where(['test_result_id' => $testResult->id, 'organism_id' => $organismId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->update([
|
||||
'quantity_id' => $qtyId
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'message' => 'organisam_result_saved_by_addmin']);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
public function uploadAttachmentResult(Request $request){
|
||||
try {
|
||||
$image = $request->file('image');
|
||||
$imageName = Str::uuid()->toString().'.' . $image->getClientOriginalExtension();
|
||||
$image->move(public_path('storage/images/attachment_lab_result'), $imageName);
|
||||
return response()->json(['success' => true, 'message' => __('laboratory.update_success'), 'data' => array('result' =>$imageName)]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function sendLabResultLink(Request $request, $patientId, $sampleId)
|
||||
{
|
||||
try {
|
||||
$telegram = new Api(env('TELEGRAM_BOT_TOKEN'));
|
||||
|
||||
$sample = $this->model::with(['patient','sample_source','lab'])->where(['id' => $sampleId])->first();
|
||||
|
||||
$text_message = "🧪 ".$sample->lab->name_en." Labo Result\n"
|
||||
."------------------------------------------------\n"
|
||||
."Patient Name:".$sample->patient->name_en."\n"
|
||||
."Age: ".Helpers::getAge($sample->patient->dob, $sample->admission_date)." (".Helpers::getGenderFull($sample->patient->gender).")\n"
|
||||
."Patients ID: ".$sample->patient->patient_uuid."\n"
|
||||
."Sample Source: ".$sample->sample_source->name_en."\n"
|
||||
."👉 <a href='https://vechsa.com/shared/lab-result/{$sampleId}'>Click To View Result</a>\n"
|
||||
."------------------------------------------------\n"
|
||||
."Date: ".date("D d/m/Y H:i");
|
||||
|
||||
if($request->target_receiver=='patient'){
|
||||
$chat = DB::table('patient_telegram')->where('patient_id', $patientId)->first();
|
||||
if ($chat) {
|
||||
$telegram->sendMessage([
|
||||
'chat_id' => $chat->chat_id,
|
||||
'text' => $text_message,
|
||||
'parse_mode' => 'HTML',
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$sample = $this->model::with(['sample_source.telegramChatId'])->find($sampleId);
|
||||
if(isset($sample->sample_source->telegramChatId) && !empty($sample->sample_source->telegramChatId)){
|
||||
$telegram->sendMessage([
|
||||
'chat_id' => $sample->sample_source->telegramChatId->chat_id,
|
||||
'text' => $text_message,
|
||||
'parse_mode' => 'HTML',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['success'=> true , 'message' => 'Laboroatory results have been sent!']);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => 'Laboroatory results sent failed!']);
|
||||
//return response()->json(['success'=> false , 'message' => __('laboratory.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateSampleResultTemplate(Request $request){
|
||||
try{
|
||||
$patientSample = $this->model::query()->where(['id' => $request->uid, 'lab_id' => $this->baseLabId])->first();
|
||||
$patientSample->update(['result_template_id' => $request->result_template_id]);
|
||||
return response()->json(['success'=> true , 'message' => 'Sample result template already saved!']);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => 'Failed while saving sample result template']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
106
app/Http/Controllers/SampleSourceController.php
Normal file
106
app/Http/Controllers/SampleSourceController.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\SampleSource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class SampleSourceController extends Controller
|
||||
{
|
||||
|
||||
protected $sampleSourceModel;
|
||||
protected $baseLabId;
|
||||
protected $base;
|
||||
public function __construct(SampleSource $sampleSourceModel){
|
||||
$this->sampleSourceModel = $sampleSourceModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_sample_source'])) return redirect(url('my-profile'));
|
||||
$sampleSources = $this->sampleSourceModel::with(['lab'])->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->kword), function ($sampleSources) use($request){
|
||||
$sampleSources->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('sample_source', ['sampleSources' => $sampleSources, 'labs' => parent::getAccessAbleLabs()]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try {
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_sample_source'])) return false;
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'name_en' => 'required',
|
||||
'name_kh' => 'nullable'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('sample_source.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
|
||||
$new = $this->sampleSourceModel::query()->firstOrNew(['name_en' => $request->name_en, 'lab_id' => $this->baseLabId]);
|
||||
$new->name_en = $request->name_en;
|
||||
$new->is_default = $request->is_default;
|
||||
$new->lab_id = $this->baseLabId;
|
||||
$new->created_at = date('Y-m-d H:i:s');
|
||||
$new->created_by = Auth::id();
|
||||
$new->record_status_id = RecordStatusEnum::ACTIVE;
|
||||
$new->save();
|
||||
|
||||
return response()->json(['success' => true, 'message' => __('sample_source.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_source.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_sample_source'])) return false;
|
||||
$validator = \Validator::make($request->all(), [ 'name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('sample_source.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'name_kh' => $request->name_kh,
|
||||
'is_default' =>$request->is_default,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->sampleSourceModel::query()->where('id', $request->uid)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('sample_source.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_source.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$sampleSource = $this->sampleSourceModel::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('sample_source.get_success'), 'data' => $sampleSource]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_source.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_sample_source'])) return false;
|
||||
$this->sampleSourceModel::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('sample_source.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_source.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->sampleSourceModel::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('sample_source.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_source.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
133
app/Http/Controllers/SampleTypeController.php
Normal file
133
app/Http/Controllers/SampleTypeController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Department;
|
||||
use App\Models\SampleType;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class SampleTypeController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $departmentModel;
|
||||
protected $sampleTypeModel;
|
||||
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
|
||||
public function __construct(Department $departmentModel,SampleType $sampleTypeModel){
|
||||
$this->departmentModel = $departmentModel;
|
||||
$this->sampleTypeModel = $sampleTypeModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_sample_type'])) return redirect(url('my-profile'));
|
||||
$standardSampleTypes = $this->sampleTypeModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'is_standard' => 1])->get(['id','name_en'])->unique('name_en');
|
||||
$departments = $this->departmentModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)->where('lab_id', $this->baseLabId)->get();
|
||||
$recordStatusCondition = Auth::id()==1 ? [RecordStatusEnum::DELETE, RecordStatusEnum::ACTIVE] : [RecordStatusEnum::ACTIVE];
|
||||
$sampleTypes = $this->sampleTypeModel::with(['department'=>function($query) {return $query->orderBy('id','ASC');}])->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusCondition)
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->when(!empty($request->kword), function ($sampleTypes) use($request, $recordStatusCondition){
|
||||
$sampleTypes->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhereIn('department_id', $this->departmentModel::query()
|
||||
->where('lab_id', $this->baseLabId)
|
||||
->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->kword)."%'")->pluck('id')->toArray()
|
||||
)->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusCondition);;
|
||||
})->orderBy('weight','ASC')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('sample-type', ['sampleTypes' => $sampleTypes, 'departments' => $departments, 'standardSampleTypes' => $standardSampleTypes]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try {
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_sample_type'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required', 'department_id' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('sample_type.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$new = $this->sampleTypeModel::query()->firstOrNew(['name_en' => $request->name_en, 'department_id' => $request->department_id]);
|
||||
$new->name_en = $request->name_en;
|
||||
$new->weight = $request->weight;
|
||||
$new->tube = $request->tube;
|
||||
$new->bg_color = $request->bg_color;
|
||||
$new->color = $request->color;
|
||||
$new->lab_id = $this->baseLabId;
|
||||
$new->department_id = $request->department_id;
|
||||
$new->enter_form_id = $request->enter_form_id;
|
||||
$new->preview_form_id = $request->preview_form_id;
|
||||
$new->description = is_array($request->description) ? json_encode($request->description) : NULL;
|
||||
$new->save();
|
||||
|
||||
return response()->json(['success' => true, 'message' => __('sample_type.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_type.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_sample_type'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['uid' => 'required', 'name_en' => 'required' /*,'department_ids' => 'required'*/]);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('sample_type.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name_en' => $request->name_en,
|
||||
'weight' => $request->weight,
|
||||
'tube' => $request->tube,
|
||||
'bg_color' => $request->bg_color,
|
||||
'color' => $request->color,
|
||||
'department_id' =>$request->department_id,
|
||||
'enter_form_id' => $request->enter_form_id,
|
||||
'preview_form_id' => $request->preview_form_id,
|
||||
'description' => is_array($request->description) ? json_encode($request->description) : NULL
|
||||
);
|
||||
$this->sampleTypeModel::query()->where('id', $request->uid)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('sample_type.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_type.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$sampleType = $this->sampleTypeModel::query()->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('sample_type.get_success'), 'data' => $sampleType]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_type.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_sample_type'])) return false;
|
||||
$this->sampleTypeModel::query()->where('id', $request->uid)->update(array('record_status_id'=> RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('sample_type.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_type.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->sampleTypeModel::query()->where('id', $request->uid)->update(array('record_status_id'=> RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('sample_type.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_type.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getById($id){
|
||||
try{
|
||||
$sampleType = $this->sampleTypeModel::query()->find($id);
|
||||
return response()->json(['success' => true, 'message' => __('sample_type.get_success'), 'data' => $sampleType]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('sample_type.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
710
app/Http/Controllers/ShareController.php
Normal file
710
app/Http/Controllers/ShareController.php
Normal file
@@ -0,0 +1,710 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Resources\SampleTestResource;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Department;
|
||||
use App\Models\LabConfigure;
|
||||
use App\Models\Laboratory;
|
||||
use App\Models\Patient;
|
||||
use App\Models\Physician;
|
||||
use App\Models\SampleSource;
|
||||
use App\Models\Sample;
|
||||
use App\Models\SampleDetail;
|
||||
use App\Models\TestGroup;
|
||||
use App\Models\TestGroupDetail;
|
||||
use App\Models\TestResult;
|
||||
use App\Models\Province;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ShareController extends Controller
|
||||
{
|
||||
protected $patientModel;
|
||||
protected $base;
|
||||
protected $physicianModel;
|
||||
protected $sampleModel;
|
||||
protected $laboratoryConfigures;
|
||||
protected $testResultModel;
|
||||
protected $testGroupModel;
|
||||
protected $departmentModel;
|
||||
protected $sampleDetailModel;
|
||||
protected $testGroupDetailModel;
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->patientModel = new Patient();
|
||||
$this->physicianModel = new Physician();
|
||||
$this->sampleModel = new Sample();
|
||||
$this->testResultModel = new TestResult();
|
||||
$this->laboratoryConfigures = new LabConfigure();
|
||||
$this->testGroupModel = new TestGroup();
|
||||
$this->departmentModel = new Department();
|
||||
$this->sampleDetailModel = new SampleDetail();
|
||||
$this->testGroupDetailModel = new TestGroupDetail();
|
||||
}
|
||||
|
||||
public function index($id){
|
||||
$sample = Sample::with(['patient','invoice'])->where(['id' => $id])->first();
|
||||
$labSettings = Laboratory::query()->find($sample->lab_id);
|
||||
$samplePhysician = Physician::query()->where('id', $sample->physician_id)->first();
|
||||
$labConfigures = $this->laboratoryConfigures::query()->where(['lab_id' => $sample->lab_id, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get()->toArray();
|
||||
|
||||
|
||||
$preview_form_id = ($labSettings->lab_category_id==0? 1:2);
|
||||
|
||||
$resultTemplateId = (collect($labConfigures)->where('atrribute_code', 'RESULT_TEMPLATE')->pluck('assigned_attribute_value')->first());
|
||||
if(!empty($resultTemplateId)){
|
||||
$preview_form_id = $resultTemplateId;
|
||||
}
|
||||
|
||||
if($sample->result_template_id > 0){
|
||||
$preview_form_id = $sample->result_template_id;
|
||||
}
|
||||
|
||||
return view('shared.test_result', [
|
||||
'sample' => $sample,
|
||||
'preview_result_id' => $preview_form_id,
|
||||
'labSettings' =>$labSettings,
|
||||
'samplePhysician' => $samplePhysician,
|
||||
'labConfigures' => $labConfigures,
|
||||
'firstPrvSampleId' => (int)@$this->getPreviousSample($sample->patient_id, $id)->first()->id,
|
||||
'firstPrvSampleDate' => (string) !empty($this->getPreviousSample($sample->patient_id, $id)->first()) ? date('d-m-Y', strtotime($this->getPreviousSample($sample->patient_id, $id)->first()->admission_date)) : '',
|
||||
]);
|
||||
}
|
||||
|
||||
function getTestItemBySampleId($sampleId, $previousId = 0){
|
||||
try{
|
||||
$data = Sample::with(['entryBy','modifiedBy','sample_tests', 'physician'])->where(['id' => $sampleId])->get()->first();
|
||||
$arrData = array();
|
||||
$arrData['result_comment'] = [];
|
||||
$arrData['sample'] = array(
|
||||
'sample_number' => $data->sample_number,
|
||||
'collected_date' => date('d-M-Y H:i', strtotime($data->collected_date)),
|
||||
'received_date' => date('d-M-Y H:i', strtotime($data->received_date)),
|
||||
'requested_by' => $data->physician
|
||||
);
|
||||
$arrData['sample_users'] = array('creator' => $data->entryBy->name, 'modifier' => @$data->modifiedBy->name);
|
||||
$arrData['result_users'] = [];
|
||||
$arrData['performers'] = [];//UserResource::collection($this->getLabUsers()->pluck('user'));
|
||||
$arrData['antibiotic_results'] = $this->getOrgAntibioticResult($sampleId);
|
||||
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
p.gender,
|
||||
p.dob,
|
||||
d.`id` AS department_id,
|
||||
d.`name_en` AS department_name,
|
||||
d.weight as dweight,
|
||||
st.`id` AS sample_type_id,
|
||||
st.`name_en` AS sample_type,
|
||||
ts.`id` AS test_sample_id,
|
||||
ts.`heading_id` AS parent_id,
|
||||
ts.`field_type`,
|
||||
ts.formula,
|
||||
ts.format,
|
||||
ts.`usd_price`,
|
||||
ts.group_result,
|
||||
ts.description,
|
||||
t.`id` AS test_id,
|
||||
t.`name_en` AS test_name,
|
||||
-- IF(ts.`field_type` = 2, \'Signle\', IF(ts.`field_type`=3,\'Multiple\', ts.unit_sign)) AS unit_sign,
|
||||
ts.unit_sign AS unit_sign,
|
||||
-- tnv.`minimum` as minimum,
|
||||
-- tnv.`maximum` as maximum,
|
||||
ifnull(tr.test_result,"") as test_result,
|
||||
ifnull(prev_r.test_result,"") as prev_result,
|
||||
tr.is_show,
|
||||
tr.performed_by,
|
||||
tr.id as test_result_id,
|
||||
pct.`commission_type`,
|
||||
ifnull(pct.`commission_rate`, 0.00) as commission_rate,
|
||||
ifnull(pct.`partner_price`, 0.00) as partner_price,
|
||||
ts.weight,
|
||||
ts.is_bold,
|
||||
ts.lab_id,
|
||||
tr.test_date,
|
||||
tr.comment,
|
||||
sd.sample_descr
|
||||
|
||||
FROM samples s
|
||||
INNER JOIN patients p
|
||||
ON p.id = s.patient_id AND p.lab_id = s.lab_id
|
||||
INNER JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
AND s.`lab_id` = tr.`lab_id`
|
||||
INNER JOIN test_samples ts
|
||||
ON ts.id = tr.`test_sample_id`
|
||||
and ts.lab_id = tr.lab_id
|
||||
INNER JOIN tests t
|
||||
ON t.`id` = ts.`test_id`
|
||||
/*AND t.`lab_id` = ts.`lab_id`*/
|
||||
INNER JOIN sample_types st
|
||||
ON st.`id` = ts.`sample_type_id`
|
||||
INNER JOIN departments d
|
||||
ON d.`id` = st.`department_id`
|
||||
|
||||
LEFT JOIN `physician_commisssion` AS pct
|
||||
ON pct.`test_sample_id` = ts.`id`
|
||||
AND pct.`physician_id` = s.`physician_id`
|
||||
|
||||
LEFT JOIN sample_details sd ON sd.sample_id = s.id AND sd.sample_type_id = st.id
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
tr.`test_sample_id`,
|
||||
tr.`test_result`
|
||||
FROM samples s
|
||||
INNER JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
WHERE s.id = '.$previousId.'
|
||||
AND tr.record_status_id = 1
|
||||
) prev_r
|
||||
ON prev_r.test_sample_id = tr.`test_sample_id`
|
||||
|
||||
WHERE s.`id` = '.$sampleId.'
|
||||
AND tr.`record_status_id` = '.BaseModel::RECORD_STATUS_ACTIVE.'
|
||||
|
||||
ORDER BY
|
||||
d.`weight`,
|
||||
st.`weight`,
|
||||
ts.`weight`');
|
||||
$departmentArray = array();
|
||||
|
||||
$sampleTypeIds = collect($resultItems)->pluck('sample_type_id')->unique()->values();
|
||||
$refComment = collect($this->getRefCommentV2($sampleTypeIds));
|
||||
|
||||
foreach ($resultItems as $row){
|
||||
$departmentArray[$row->dweight]['department_id'] = $row->department_id;
|
||||
$departmentArray[$row->dweight]['department_name'] = $row->department_name;
|
||||
$departmentArray[$row->dweight]['samples'][$row->sample_type_id]['sample_type_id'] = $row->sample_type_id;
|
||||
$departmentArray[$row->dweight]['samples'][$row->sample_type_id]['sample_type_name'] = $row->sample_type;
|
||||
$departmentArray[$row->dweight]['samples'][$row->sample_type_id]['sample_descr'] = (string)$row->sample_descr !=''? '('.$row->sample_descr.')' : '';
|
||||
|
||||
|
||||
$departmentArray[$row->dweight]['samples'][$row->sample_type_id]['comments'] = $refComment->where('sample_type_id', $row->sample_type_id)->values();
|
||||
|
||||
$organismResult = [];
|
||||
if(in_array($row->field_type, [2,3])) {
|
||||
$organismResult = $this->getOrganismResult($row->test_result_id);
|
||||
}
|
||||
|
||||
|
||||
$refRanges = (object) $this->mapReferenceRange($row->test_sample_id, $row->gender, $row->dob);
|
||||
|
||||
$testItemArray = array(
|
||||
'id' => (string)$row->test_sample_id,
|
||||
'test_id' => $row->test_id,
|
||||
'test_name' => $row->test_name,
|
||||
'closed_parent_id' => (string) (int)$row->parent_id,
|
||||
'field_type' => (string) $row->field_type,
|
||||
'unit_sign' => (string) $row->unit_sign,
|
||||
'usd_price' => $row->usd_price,
|
||||
'min_ref_val' => isset($refRanges->minimum) ? $refRanges->minimum :'',
|
||||
'max_ref_val' => isset($refRanges->maximum) ? $refRanges->maximum: '',
|
||||
'ref_range' => (isset($refRanges->minimum) /*&& !empty($refRanges->minimum)*/) ? in_array($refRanges->sign, ['<','<=','Neg <', 'Neg<']) ? $refRanges->sign.' '.$refRanges->maximum : (in_array($refRanges->sign, ['>','>=']) ? $refRanges->sign. ' '.$refRanges->minimum : ((isset($refRanges->minimum) /*&& !empty($refRanges->minimum)*/) ? $refRanges->minimum .' '. $refRanges->sign .' '. $refRanges->maximum : '')) : '',
|
||||
//'ref_range' => ((isset($refRanges->minimum) && !empty($refRanges->minimum)) ? $refRanges->minimum .' '. $refRanges->sign .' '. $refRanges->maximum : ''),
|
||||
'test_result' => !is_null($row->format) && is_numeric($row->test_result) ? number_format($row->test_result,$row->format) : $row->test_result,
|
||||
'prev_result' => (string)!is_null($row->format) && is_numeric($row->prev_result) ? number_format($row->prev_result,$row->format) : $row->prev_result,
|
||||
'sign' => isset($refRanges->sign) ? $refRanges->sign: '',
|
||||
'is_show' => $row->is_show,
|
||||
'performed_by' => $row->performed_by,
|
||||
'org_results' => $organismResult,
|
||||
'group_result' => (string) $row->group_result,
|
||||
'commission_type' => NULL,
|
||||
'commission_rate' => $row->commission_rate,
|
||||
'partner_price' => $row->partner_price,
|
||||
'description' => (string) nl2br($row->description),
|
||||
'formula' => (string) $row->formula,
|
||||
'order' => (int) $row->weight,
|
||||
'test_date' => (string) $row->test_date,
|
||||
'comment' => (string) nl2br($row->comment),
|
||||
'str_comment' => (string) $row->comment,
|
||||
'is_bold' => (int) $row->is_bold,
|
||||
'ts' => $row->test_result,
|
||||
'lab_id' => $row->lab_id,
|
||||
'format' => (int)$row->format
|
||||
);
|
||||
//dd($testItemArray);
|
||||
$departmentArray[$row->dweight]['samples'][$row->sample_type_id]['tests'][] = $testItemArray;
|
||||
}
|
||||
|
||||
$arrData['sample_tests'] = $departmentArray;
|
||||
|
||||
|
||||
return response()->json(['success'=> true , 'data' => $arrData]);
|
||||
} catch (\Exception $e){
|
||||
Log::error($e);
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function getRefCommentV2($sampleTypeIds){
|
||||
return Comment::query()->select('sample_type_id', 'comment_desc as name')->where(
|
||||
[
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE
|
||||
])->whereIn('sample_type_id', $sampleTypeIds)->get()->toArray();
|
||||
}
|
||||
|
||||
function getOrgAntibioticResult($sampleId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
ogr.test_result_id,
|
||||
tsr.id AS test_organism_id,
|
||||
ogr.organism_id,
|
||||
att.antibiotic_id,
|
||||
agr.disk_diffusion,
|
||||
agr.mic,
|
||||
agr.sensitive,
|
||||
agr.is_hide,
|
||||
att.name_en
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN `antibiogram_results` agr
|
||||
ON agr.`organism_result_id` = ogr.`id`
|
||||
INNER JOIN `antibiotics` att
|
||||
ON att.id = agr.antibiotic_id
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
WHERE trs.`sample_id` = '.$sampleId.'
|
||||
AND agr.`record_status_id` = 1
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1
|
||||
order by agr.sensitive desc');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function getOrganismResult($testResultId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
ogr.test_result_id,
|
||||
tsr.id AS test_organism_id,
|
||||
ogr.organism_id,
|
||||
ogr.quantity_id,
|
||||
ogr.contaminant,
|
||||
o.`name_en` AS organism_name,
|
||||
o.is_bold,
|
||||
qt.`quantity_name`,
|
||||
ogr.id
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
INNER JOIN organisms o
|
||||
ON o.id = ogr.`organism_id`
|
||||
LEFT JOIN `quantities` qt
|
||||
ON qt.id = ogr.`quantity_id`
|
||||
WHERE ogr.`test_result_id` = '.$testResultId. '
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function mapReferenceRange($testSampleId, $genderId, $patientDob){
|
||||
|
||||
$referenceRanges = DB::select('
|
||||
SELECT
|
||||
(IF(pt.range_start=0, 1, pt.range_start) * pt.range_start_unit) + IF(pt.range_start_unit=\'>\', 1, 0) AS start_range_in_day,
|
||||
(IF(pt.range_end=0, 1, pt.range_end) * pt.range_end_unit) + IF(pt.range_end_sign=\'<=\', 1, 0) AS end_range_in_day,
|
||||
pt.gender,
|
||||
pt.range_start,
|
||||
pt.range_start_unit,
|
||||
pt.range_start_sign,
|
||||
pt.range_end,
|
||||
pt.range_end_unit,
|
||||
pt.range_end_sign,
|
||||
tnv.test_sample_id,
|
||||
tnv.sign,
|
||||
ts.format,
|
||||
tnv.`minimum` AS minimum,
|
||||
tnv.`maximum` AS maximum
|
||||
FROM test_normal_values tnv
|
||||
INNER JOIN patient_types pt
|
||||
ON pt.id = tnv.patient_type_id
|
||||
INNER JOIN test_samples ts
|
||||
ON ts.id = tnv.test_sample_id
|
||||
WHERE tnv.record_status_id = 1
|
||||
AND test_sample_id = '.$testSampleId.'
|
||||
');
|
||||
|
||||
$now = time(); // or your date as well
|
||||
$your_date = strtotime($patientDob);
|
||||
$patientAgeInDay = round(($now - $your_date)/ (60 * 60 * 24));
|
||||
$referenceRangeArray = array();
|
||||
foreach ($referenceRanges as $referenceRange){
|
||||
if((int)$patientAgeInDay >= (int)$referenceRange->start_range_in_day && (int)$patientAgeInDay <= (int)$referenceRange->end_range_in_day){
|
||||
// Log::info($patientAgeInDay . ' - '.$genderId);
|
||||
if($referenceRange->gender == $genderId){
|
||||
// Log::info('geneder=gender');
|
||||
$referenceRangeArray = array(
|
||||
'sign' => $referenceRange->sign,
|
||||
'minimum' => !is_null($referenceRange->format) ? number_format($referenceRange->minimum,$referenceRange->format) : (fmod($referenceRange->minimum,1) == 0 ? number_format($referenceRange->minimum,0):number_format($referenceRange->minimum,2)),
|
||||
'maximum' => !is_null($referenceRange->format) ? number_format($referenceRange->maximum,$referenceRange->format) : (fmod($referenceRange->maximum,1) == 0 ? number_format($referenceRange->maximum,0):number_format($referenceRange->maximum,2)),
|
||||
); break;
|
||||
}
|
||||
else{
|
||||
if($referenceRange->gender==3) {
|
||||
$referenceRangeArray = array(
|
||||
'sign' => $referenceRange->sign,
|
||||
'minimum' => !is_null($referenceRange->format) ? number_format($referenceRange->minimum,$referenceRange->format) : (fmod($referenceRange->minimum,1) == 0 ? number_format($referenceRange->minimum,0):number_format($referenceRange->minimum,2)),
|
||||
'maximum' => !is_null($referenceRange->format) ? number_format($referenceRange->maximum,$referenceRange->format) : (fmod($referenceRange->maximum,1) == 0 ? number_format($referenceRange->maximum,0):number_format($referenceRange->maximum,2)),
|
||||
); break;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
return $referenceRangeArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* New Implementation for Patient Profile
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
|
||||
public function startAnonymousSession($hashLabId){
|
||||
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->where('allow_external_request', 1)
|
||||
->whereRaw('MD5(id)="'.$hashLabId.'"')->first();
|
||||
$provinces = Province::where('id','<>', 25)->orderBy('name_kh')->get();
|
||||
if(empty($this->base)) return view('errors.404');
|
||||
return view('shared.anonymous_login', ['labSettings' => (object) $this->base, 'provinces' => $provinces ]);
|
||||
}
|
||||
|
||||
public function searchPatientToSelect2(Request $request, $labId){
|
||||
$patients = [];
|
||||
if(!empty(trim($request->term))){
|
||||
$patients = $this->patientModel::query()
|
||||
->where(['record_status_id' => 1, 'lab_id' => $labId])
|
||||
//->whereRaw('MD5(lab_id)="'.$hashLabId.'"')
|
||||
->when(!empty(trim($request->term)), function ($patients) use($request){
|
||||
$patients->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->term)."%'");
|
||||
//->orWhereRaw("replace(phone_number, ' ','') like '%".str_replace(" ","",$request->term)."%'");
|
||||
})->limit(3)->orderBy('name_en', 'asc')->get();
|
||||
}
|
||||
$items = $patients->map(function ($item){
|
||||
return array('id'=>$item->id, 'text' => $item->name_en . ' : '.$item->phone_number . ', '.($item->gender==1 ? 'M' : 'F').', '.(date('Y') - date('Y',strtotime($item->dob))));
|
||||
});
|
||||
return response()->json(['results' => $items]);
|
||||
}
|
||||
|
||||
public function searchPatientPhoneToSelect2(Request $request, $labId){
|
||||
$patients = [];
|
||||
if(!empty(trim($request->term))){
|
||||
$patients = $this->patientModel::query()
|
||||
->where(['record_status_id' => 1, 'lab_id' => $labId])
|
||||
->when(!empty(trim($request->term)), function ($patients) use($request){
|
||||
$patients->whereRaw("replace(phone_number, ' ','') like '%".str_replace(" ","",$request->term)."%'");
|
||||
})->limit(3)->orderBy('phone_number', 'asc')->get();
|
||||
}
|
||||
$items = [];
|
||||
if(count($patients)>0) {
|
||||
$items = $patients->map(function ($item){
|
||||
return array('id'=>$item->phone_number, 'text' => $item->name_en . ' : '.$item->phone_number . ', '.($item->gender==1 ? 'M' : 'F').', '.(date('Y') - date('Y',strtotime($item->dob))));
|
||||
});
|
||||
}
|
||||
return response()->json(['results' => $items]);
|
||||
}
|
||||
|
||||
public function anonymousRegister(Request $request, $hashLabId){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$dob = $request->dob;
|
||||
$patient_name=strtoupper($request->name_en);
|
||||
$datePart = explode("-",$dob);
|
||||
$phoneNumber = $request->phone_number;// preg_replace('/ /i', '', trim($request->phone_number));
|
||||
if($datePart[1]>12){
|
||||
$dob = $datePart[1].'-'.$datePart[0].'-'.$datePart[2];
|
||||
}
|
||||
$requests = collect($request)->merge([
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => '1',
|
||||
'record_status_id' => 1
|
||||
])->replace([
|
||||
'dob' => date('Y-m-d', strtotime($dob)),
|
||||
'phone_number' => $phoneNumber,
|
||||
'name_en'=> $patient_name
|
||||
]);
|
||||
|
||||
$patientNumber = $this->generateAutoId(date('Y-m-d'), $request->short_name, $request->lab_id);
|
||||
$requests = $requests->merge(['patient_uuid' => $patientNumber]);
|
||||
$patient = $this->patientModel::query()->create($requests->all());
|
||||
DB::commit();
|
||||
|
||||
$request->session()->put('anonymous_id', $patient->id);
|
||||
$request->session()->put('base_lab_id', $patient->lab_id);
|
||||
if ($request->session()->has('anonymous_id')) {
|
||||
return redirect(url('customer/'.$hashLabId.'?request-test'));
|
||||
}
|
||||
|
||||
} catch (\Exception $e){
|
||||
dd($e);
|
||||
DB::rollBack();
|
||||
Log::error($e);
|
||||
return response()->json(['success'=> false , 'message' => __('patient.create_fail') , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateAutoId($admissionDate, $labShortName, $labId){
|
||||
$prefix = date('y',strtotime($admissionDate));
|
||||
$patientCount = $this->patientModel::query()->where('lab_id', $labId)->whereRaw('year(created_at) ="'. date('Y',strtotime($admissionDate)).'"')->count();
|
||||
if($labId==34) $patientCount = $patientCount+5; // solve problem when delete patient
|
||||
return 'P-'.$labShortName.'-'.$prefix.'-'.(str_pad(($patientCount+1),5,'0',STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
public function anonymousLogin(Request $request, $hashLabId){
|
||||
if(empty($request->patient_id) && empty($request->phone_number)) {
|
||||
session()->flash('message', 'មិនមានលេខនេះនៅក្នុងប្រព័ន្ធយើងខ្ញុំទេ');
|
||||
return redirect()->back();
|
||||
}
|
||||
$pattern = '/ /i';
|
||||
$phoneNumber = $request->phone_number;// preg_replace($pattern, '', trim($request->phone_number));
|
||||
$patient = $this->patientModel::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')
|
||||
->when(!empty($request->phone_number) && empty($request->patient_id), function($patient) use($request){
|
||||
$patient->whereRaw("replace(phone_number, ' ','') = '".str_replace(" ","",$request->phone_number)."'");
|
||||
})->when(!empty($request->patient_id), function($patient) use($request){
|
||||
$patient->where('id', $request->patient_id);
|
||||
})->first();
|
||||
//->where('phone_number', $phoneNumber)->first();
|
||||
if(empty($patient)){
|
||||
session()->flash('message', 'មិនមានលេខនេះនៅក្នុងប្រព័ន្ធយើងខ្ញុំទេ');
|
||||
return redirect()->back();
|
||||
}
|
||||
else{
|
||||
$request->session()->put('anonymous_id', $patient->id);
|
||||
$request->session()->put('base_lab_id', $patient->lab_id);
|
||||
if ($request->session()->has('anonymous_id')) {
|
||||
return redirect(url('customer/'.$hashLabId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function anonymousLogOut(Request $request, $hashLabId){
|
||||
if ($request->session()->has('anonymous_id')) {
|
||||
$request->session()->forget('anonymous_id');
|
||||
$request->session()->forget('base_lab_id');
|
||||
return redirect(url('anonymous/'.$hashLabId));
|
||||
}
|
||||
}
|
||||
|
||||
public function profile(Request $request, $hashLabId)
|
||||
{
|
||||
if (!$request->session()->has('anonymous_id')) {
|
||||
return redirect(url('anonymous/'.$hashLabId));
|
||||
}
|
||||
$patient = $this->patientModel::query()
|
||||
->where(['id' => $request->session()->get('anonymous_id'), BaseModel::RECORD_STATUS_FIELD => BaseModel::RECORD_STATUS_ACTIVE])
|
||||
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->first();
|
||||
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->whereRaw('MD5(id)="'.$hashLabId.'"')->first();
|
||||
$samples = $this->sampleModel::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->where('patient_id', $request->session()->get('anonymous_id'))
|
||||
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->orderBy(BaseModel::CREATED_AT_FIELD,'desc')->paginate(5);
|
||||
$testGroups = $this->testGroupModel::with(['testGroupDetails'])->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->orderBy('created_at')->get();
|
||||
$physicians = $this->physicianModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereRaw('MD5(lab_id)="'.$hashLabId.'"')->orderBy('name_en')->get();
|
||||
return view('shared.patient_profile',
|
||||
[
|
||||
'patient' => $patient,
|
||||
'samples' => $samples,
|
||||
'labSettings' => (object) $this->base,
|
||||
'testGroups' => $testGroups,
|
||||
'physicians' => $physicians
|
||||
]);
|
||||
}
|
||||
|
||||
function getPreviousSample($patientId, $curSampleId){
|
||||
return $this->sampleModel::query()->where(['patient_id' => $patientId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->where('id','<', $curSampleId)->orderBy('id', 'desc')->get(['id','admission_date']);
|
||||
}
|
||||
|
||||
public function viewLabResult(Request $request, $hashLabId, $hashSampleId){
|
||||
if (!$request->session()->has('anonymous_id')) {
|
||||
return redirect(url('anonymous/'.$hashLabId));
|
||||
}
|
||||
$sample = $this->sampleModel::with(['patient','invoice'])->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->whereRaw('MD5(lab_id)="'.$hashLabId.'" AND MD5(id)="'.$hashSampleId.'"')->first();
|
||||
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->whereRaw('MD5(id)="'.$hashLabId.'"')->first();
|
||||
$labConfigures = $this->laboratoryConfigures::query()
|
||||
->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->whereRaw('MD5(id)="'.$hashLabId.'"')
|
||||
->get()->toArray();
|
||||
$samplePhysician = $this->physicianModel::query()->where('id', $sample->physician_id)->first();
|
||||
|
||||
|
||||
return view('shared.preview_result',
|
||||
[
|
||||
'sample' => $sample,
|
||||
'sample_id' => $sample->id,
|
||||
'labSettings' => (object) $this->base,
|
||||
'labConfigures' => $labConfigures,
|
||||
'samplePhysician' => $samplePhysician
|
||||
]);
|
||||
}
|
||||
|
||||
public function cloneRequestedLabServices(Request $request, $hashLabId, $hashSampleId){
|
||||
if (!$request->session()->has('anonymous_id')) {
|
||||
return redirect(url('anonymous/'.$hashLabId));
|
||||
}
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$sample = $this->sampleModel::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->whereRaw('MD5(lab_id)="'.$hashLabId.'" AND MD5(id)="'.$hashSampleId.'"')->first();
|
||||
|
||||
$requestedSample = [];
|
||||
if(!empty($sample)){
|
||||
$reSampleArray = array(
|
||||
'patient_id' => $sample->patient_id,
|
||||
'sample_number' => $this->generateSampleNumber($sample->lab_id, date('Y-m-d H:i:s')),
|
||||
'admission_date' => date('Y-m-d H:i:s'),
|
||||
'sample_source_id' => $sample->sample_source_id,
|
||||
'physician_id' => $sample->physician_id,
|
||||
'requested_date' => date('Y-m-d H:i:s'),
|
||||
'collected_date' => date('Y-m-d H:i:s'),
|
||||
'is_accept_request' => 0,
|
||||
'lab_id' => $sample->lab_id,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => $sample->patient_id,
|
||||
);
|
||||
|
||||
$requestedSample = $this->sampleModel::query()->create($reSampleArray);
|
||||
$previousTests = $this->testResultModel::query()->where([
|
||||
BaseModel::RECORD_STATUS_FIELD => BaseModel::RECORD_STATUS_ACTIVE,
|
||||
'sample_id' => $sample->id,
|
||||
'lab_id' => $sample->lab_id
|
||||
])->get();
|
||||
if(!empty($requestedSample) && !empty($previousTests)){
|
||||
$items = [];
|
||||
foreach ($previousTests as $previousItem){
|
||||
$items[] = array(
|
||||
'sample_id' => $requestedSample->id,
|
||||
'test_sample_id' => $previousItem->test_sample_id,
|
||||
'test_result' => NULL,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => $sample->patient_id,
|
||||
'lab_id' => $previousItem->lab_id
|
||||
);
|
||||
}
|
||||
$this->testResultModel::query()->insert($items);
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'message' => __('ប្រតិបត្តិការបានសម្រេច'), 'data' => $requestedSample]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'message' => __('ប្រតិបត្តិការមិនបានសម្រេច'), 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateSampleNumber($labId, $admissionDate){
|
||||
$this->base = Laboratory::query()->where(BaseModel::RECORD_STATUS_FIELD, BaseModel::RECORD_STATUS_ACTIVE)
|
||||
->where('id', $labId)->first();
|
||||
$prefix = date('ymd',strtotime($admissionDate));
|
||||
$sample = Sample::query();
|
||||
$sampleCount = $sample->where('lab_id', $labId)->whereRaw('date(admission_date) ="'. date('Y-m-d',strtotime($admissionDate)).'"')->count();
|
||||
return 'S-'.$this->base['short_name'].'-'.$prefix.'-'.(str_pad(($sampleCount+1),3,'0',STR_PAD_LEFT));
|
||||
}
|
||||
|
||||
|
||||
function getTestItem(Request $request){
|
||||
try{
|
||||
$departments = $this->departmentModel::with(['samples','samples.testSamples.test','samples.testSamples.childTest'])
|
||||
->where(['lab_id' => $request->session()->get('base_lab_id'), BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->orderBy('weight', 'asc')->get();
|
||||
return response()->json(['success'=> true , 'data' => SampleTestResource::collection($departments)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Request Test */
|
||||
|
||||
public function storeSampleDetail(Request $sampleCreateRequest){
|
||||
|
||||
set_time_limit(6000);
|
||||
ini_set('memory_limit', '10240M');
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
|
||||
$labId = $sampleCreateRequest->session()->get('base_lab_id');
|
||||
$patientId = $sampleCreateRequest->session()->get('anonymous_id');
|
||||
|
||||
$sampleSourceId = SampleSource::where(['lab_id' => $labId, 'is_default' => 1, 'record_status_id' => 1])->get()->first();
|
||||
//$physicianId = Physician::where(['lab_id' => $labId, 'is_default' => 1, 'record_status_id' => 1])->get()->first();
|
||||
|
||||
// create sample first
|
||||
$sampleRequest = array(
|
||||
'patient_id' => $patientId,
|
||||
'sample_number' => $this->generateSampleNumber($labId, date('Y-m-d H:i:s')),
|
||||
'admission_date' => date('Y-m-d H:i:s'),
|
||||
'sample_source_id' => @$sampleSourceId->id, // cannot null
|
||||
'physician_id' => $sampleCreateRequest->physician_id, // @$physicianId->id, // cannot null
|
||||
'requested_date' => date('Y-m-d H:i:s'),
|
||||
'received_date' => date('Y-m-d H:i:s'),
|
||||
'collected_date' => date('Y-m-d H:i:s'),
|
||||
'is_accept_request' => 0,
|
||||
'lab_id' => $labId,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => $patientId,
|
||||
);
|
||||
|
||||
$requestedSample = $this->sampleModel::query()->create($sampleRequest);
|
||||
|
||||
//$this->sampleDetailModel::query()->where(['sample_id' => $requestedSample->id, 'lab_id' => $labId])->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
if(!empty($requestedSample)) {
|
||||
if (!empty($sampleCreateRequest->sample_tests)) {
|
||||
/*$this->testResultModel::query()->where(['sample_id' => $requestedSample->id, 'lab_id' => $labId])
|
||||
->whereNotIn('test_sample_id', $sampleCreateRequest->sample_tests)
|
||||
->delete();*/
|
||||
foreach ($sampleCreateRequest->sample_tests as $test) {
|
||||
$testResult = $this->testResultModel::query()->create([
|
||||
'sample_id' => $requestedSample->id,
|
||||
'test_sample_id' => $test,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => $patientId,
|
||||
'lab_id' => $labId,
|
||||
]);
|
||||
}
|
||||
}
|
||||
/*else {
|
||||
$this->testResultModel::query()->where(['sample_id' => $sampleCreateRequest->sample_id, 'lab_id' => $this->baseLabId])->delete();
|
||||
}*/
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('sample.assign_tests_success')]);
|
||||
} catch (\Exception $e){
|
||||
Log::error($e);
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTestGroup($id, $labId){
|
||||
try{
|
||||
$testGroupItems = $this->testGroupDetailModel::query()->where(['test_group_id' => $id, 'lab_id' => $labId, 'record_status_id'=> 1])->get()->pluck('test_sample_id')->toArray();
|
||||
return response()->json(['success' => true, 'data' => $testGroupItems]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
88
app/Http/Controllers/TelegramController.php
Normal file
88
app/Http/Controllers/TelegramController.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Telegram\Bot\Api;
|
||||
use Telegram\Bot\Laravel\Facades\Telegram;
|
||||
|
||||
class TelegramController extends Controller
|
||||
{
|
||||
|
||||
public function handle(Request $request)
|
||||
{
|
||||
try{
|
||||
$telegram = new Api(env('TELEGRAM_BOT_TOKEN'));
|
||||
$update = $telegram->getWebhookUpdate();
|
||||
|
||||
if ($update->getMessage()) {
|
||||
$chatId = $update->getMessage()->getChat()->getId();
|
||||
$text = $update->getMessage()->getText();
|
||||
$patientId = null;
|
||||
$sampleSourceId = null;
|
||||
if ($text && str_starts_with($text, "/start")) {
|
||||
$parts = explode(" ", $text);
|
||||
$individualType = 'patient';
|
||||
if (count($parts) > 1) {
|
||||
$fullText = explode("_", $parts[1]);
|
||||
if(count($fullText) > 1){
|
||||
$sampleSourceId = trim($fullText[1]);
|
||||
}
|
||||
else{
|
||||
$patientId = trim($parts[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($patientId) {
|
||||
// Check if patient already registered
|
||||
$exists = DB::table('patient_telegram')
|
||||
->where('patient_id', $patientId)
|
||||
->exists();
|
||||
|
||||
if (!$exists) {
|
||||
DB::table('patient_telegram')->updateOrInsert(
|
||||
['patient_id' => $patientId],
|
||||
['chat_id' => $chatId]
|
||||
);
|
||||
|
||||
$telegram->sendMessage([
|
||||
'chat_id' => $chatId,
|
||||
'text' => "✅ Thank you for joining our bot. You will receive future laboratory results here."
|
||||
]);
|
||||
}
|
||||
}
|
||||
// for sample source
|
||||
if ($sampleSourceId)
|
||||
{
|
||||
// Check if patient already registered
|
||||
$exist_sample_source = DB::table('sample_source_telegram')
|
||||
->where('sample_source_id', $sampleSourceId)
|
||||
->exists();
|
||||
|
||||
if (!$exist_sample_source) {
|
||||
DB::table('sample_source_telegram')->updateOrInsert(
|
||||
['sample_source_id' => $sampleSourceId],
|
||||
['chat_id' => $chatId]
|
||||
);
|
||||
|
||||
$telegram->sendMessage([
|
||||
'chat_id' => $chatId,
|
||||
'text' => "✅ Thank you for joining our bot. You will receive future laboratory results here."
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'ok'], 200);
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
487
app/Http/Controllers/TestController.php
Normal file
487
app/Http/Controllers/TestController.php
Normal file
@@ -0,0 +1,487 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Http\Requests\TestSampleCreateRequest;
|
||||
use App\Http\Requests\UpdateRequests\TestSampleUpdateRequest;
|
||||
use App\Http\Resources\TestSampleResource;
|
||||
use App\Models\Antibiotic;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Department;
|
||||
use App\Models\Organism;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\Physician;
|
||||
use App\Models\PhysicianCommission;
|
||||
use App\Models\SampleType;
|
||||
use App\Models\Test;
|
||||
use App\Models\TestCategory;
|
||||
use App\Models\TestNormalValue;
|
||||
use App\Models\TestSample;
|
||||
use App\Models\TestSampleOrganism;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
use App\Models\Laboratory;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $departmentModel;
|
||||
protected $sampleTypeModel;
|
||||
protected $patientTypeModel;
|
||||
protected $testModel;
|
||||
protected $organismModel;
|
||||
protected $antibioticModel;
|
||||
protected $testSampleOrganismModel;
|
||||
protected $testSampleOrganismAntibioticModel;
|
||||
protected $testNormalValueModel;
|
||||
protected $physicianModel;
|
||||
protected $physicianCommissionModel;
|
||||
protected $labModel;
|
||||
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
protected $base;
|
||||
protected $testCategoryModel;
|
||||
|
||||
public function __construct(TestSample $testSample, Department $departmentModel, PhysicianCommission $physicianCommissionModel,
|
||||
TestSampleOrganism $testSampleOrganismModel,SampleType $sampleTypeModel,
|
||||
PatientType $patientTypeModel,Test $testModel, Organism $organismModel,
|
||||
Antibiotic $antibioticModel,
|
||||
TestNormalValue $testNormalValueModel, Physician $physicianModel, Laboratory $labModel
|
||||
){
|
||||
$this->model = $testSample;
|
||||
$this->departmentModel = $departmentModel;
|
||||
$this->sampleTypeModel = $sampleTypeModel;
|
||||
$this->patientTypeModel = $patientTypeModel;
|
||||
$this->testModel = $testModel;
|
||||
$this->organismModel = $organismModel;
|
||||
$this->antibioticModel = $antibioticModel;
|
||||
$this->testSampleOrganismModel = $testSampleOrganismModel;
|
||||
$this->testNormalValueModel = $testNormalValueModel;
|
||||
$this->physicianModel = $physicianModel;
|
||||
$this->physicianCommissionModel = $physicianCommissionModel;
|
||||
$this->labModel = $labModel;
|
||||
$this->testCategoryModel = new TestCategory();
|
||||
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()){ return response()->json(['errors'=>$validator->errors()->all()]);}
|
||||
$test = $this->testModel::query()->create([
|
||||
'name_en' => $request->name_en,
|
||||
'lab_id' => $this->baseLabId,
|
||||
]);
|
||||
return response()->json(['success'=> true , 'data' => [$test]]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
$validator = \Validator::make($request->all(), ['uid' => 'required', 'name_en' => 'required']);
|
||||
if ($validator->fails()){ return response()->json(['errors'=>$validator->errors()->all()]);}
|
||||
$test = $this->testModel::query()->where(['id' => $request->uid])->first();
|
||||
$test->update(array('name_en' => $request->name_en));
|
||||
return response()->json(['success'=> true , 'data' => [$test]]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$test = Test::query()->find($request->uid);
|
||||
return response()->json(['data' => $test]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
$status = $this->testModel::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['status'=> $status , 'msg' => 'Delete successful']);
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
$status = $this->testModel::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['status'=> $status , 'msg' => 'Activate successful']);
|
||||
}
|
||||
|
||||
/** TEST SAMPLES
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
|
||||
public function testSamples(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_test_sample'])) return redirect(url('my-profile'));
|
||||
$physicians = $this->physicianModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get();
|
||||
$department = $this->departmentModel::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->orderBy('weight','asc')->get();
|
||||
$patientTypes = $this->patientTypeModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)->get();
|
||||
$testItems = $this->testModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)->get();
|
||||
$testSampleTable = $this->model::getTableNameByScheme();
|
||||
$sampleTypeTable = $this->sampleTypeModel::getTableNameByScheme();
|
||||
$departmentTable = $this->departmentModel::getTableNameByScheme();
|
||||
$testTable = $this->testModel::getTableNameByScheme();
|
||||
$testSamples = $this->model::query()->select([
|
||||
$departmentTable.'.name_en as department_name',
|
||||
$sampleTypeTable.'.name_en as sample_type_name',
|
||||
$testTable.'.name_en as test_name',
|
||||
$testSampleTable.'.*'
|
||||
])
|
||||
->join($sampleTypeTable, $testSampleTable.'.sample_type_id', '=', $sampleTypeTable.'.id')
|
||||
->join($departmentTable, $sampleTypeTable.'.department_id', '=', $departmentTable.'.id')
|
||||
->join($testTable, $testSampleTable.'.test_id', '=', $testTable.'.id')
|
||||
->where($testSampleTable.'.'.BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->where($testSampleTable.'.lab_id', $this->baseLabId)
|
||||
->where($sampleTypeTable.'.'.BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(!empty($request->sample_type), function ($query) use($sampleTypeTable, $request){
|
||||
$query->where($sampleTypeTable.'.id', $request->sample_type);
|
||||
})->when(!empty($request->department), function ($query) use($departmentTable, $request) {
|
||||
$query->where($departmentTable.'.id', $request->department);
|
||||
})->when(!empty($request->kword), function ($query) use($testTable, $testSampleTable, $request){
|
||||
$query->whereRaw( $testTable.".name_en like '%".addslashes($request->kword)."%'")
|
||||
->orWhereRaw($testSampleTable.".code like '%".addslashes($request->kword)."%'");
|
||||
})->when(Auth::id()==1, function ($query) use ($testSampleTable){
|
||||
$query->whereIn($testSampleTable.'.'.BaseModel::RECORD_STATUS_FIELD , [RecordStatusEnum::DELETE, RecordStatusEnum::ACTIVE]);
|
||||
})->orderBy($departmentTable.'.weight')
|
||||
->orderBy($sampleTypeTable.'.weight')
|
||||
->orderBy($testSampleTable.'.weight')
|
||||
->paginate(20);
|
||||
return view('test', ['testSamples' => $testSamples, 'departments' => $department,
|
||||
'testItems' => $testItems, 'patientTypes' => $patientTypes, 'labSetting' => (object) $this->base,
|
||||
'physicians' => $physicians
|
||||
]);
|
||||
}
|
||||
|
||||
public function saveTestSample(TestSampleCreateRequest $request){
|
||||
set_time_limit(6000);
|
||||
ini_set('memory_limit', '10240M');
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_test_sample'])) return false;
|
||||
$testSample = $this->model::query()->create([
|
||||
'sample_type_id' => $request->sample_type_id,
|
||||
'test_id' => $request->test_id,
|
||||
'group_result' => $request->group_result,
|
||||
'category' => NULL,
|
||||
'unit_sign' => $request->unit_sign,
|
||||
'code' => $request->code,
|
||||
'heading_id' => $request->heading_id,
|
||||
'usd_price' => $request->usd_price,
|
||||
'weight' => $request->weight,
|
||||
'field_type' => $request->filed_type_id,
|
||||
'formula' => $request->formula,
|
||||
'format' => $request->format_value,
|
||||
'description' => $request->description,
|
||||
'lab_id' => $this->baseLabId,
|
||||
'is_bold' => $request->is_bold,
|
||||
'autocomplete_bind' => $request->autocomplete_bind
|
||||
]);
|
||||
// reference range
|
||||
if(in_array($request->filed_type_id,[1,4,6])){
|
||||
$data = collect($request->patient_type_ids);
|
||||
$items = $data->map(function ($row, $key) use ($request, $testSample) {
|
||||
if(!empty($request->patient_type_ids[$key]['value'])) {
|
||||
$testNormalValue = $this->testNormalValueModel::query()->create([
|
||||
'test_sample_id' => $testSample->id,
|
||||
'patient_type_id' => $request->patient_type_ids[$key]['value'],
|
||||
'sign' => $request->signs[$key]['value'],
|
||||
'minimum' => is_numeric($request->min_values[$key]['value']) ? $request->min_values[$key]['value'] : null,
|
||||
'maximum' => is_numeric($request->max_values[$key]['value']) ? $request->max_values[$key]['value'] : null,
|
||||
]);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
}
|
||||
// organism and antibiotics
|
||||
if(in_array($request->filed_type_id,[2,3]) ){
|
||||
$organismsCollection = collect($request->organisms);
|
||||
foreach ($organismsCollection as $org){
|
||||
$this->testSampleOrganismModel::query()->create([
|
||||
'test_sample_id' => $testSample->id,
|
||||
'is_default' => $org['is_default'],
|
||||
'organism_id' => $org['id'],
|
||||
'lab_id' => $this->baseLabId
|
||||
]);
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('test_sample.create_success'), 'data' => [$testSample]]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false, 'message' => __('test_sample.create_fail'), 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTestSample(Request $request){
|
||||
$testSample = $this->model::with([
|
||||
'sample',
|
||||
'organisms.organism',
|
||||
'testValues'
|
||||
])->find($request->uid);
|
||||
return response()->json(['success'=> true , 'message' => __('test_sample.get_success'), 'data' => new TestSampleResource($testSample)]);
|
||||
}
|
||||
|
||||
public function updateTestSample(TestSampleUpdateRequest $request){
|
||||
|
||||
set_time_limit(6000);
|
||||
ini_set('memory_limit', '10240M');
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_test_sample'])) return false;
|
||||
$testSample = $this->model::query()->where('id',$request->uid)->first();
|
||||
$testSample->update([
|
||||
'sample_type_id' => $request->sample_type_id,
|
||||
'test_id' => $request->test_id,
|
||||
'group_result' => $request->group_result,
|
||||
'category' => @$request->category,
|
||||
'unit_sign' => $request->unit_sign,
|
||||
'code' => $request->code,
|
||||
'heading_id' => $request->heading_id,
|
||||
'usd_price' => $request->usd_price,
|
||||
'weight' => $request->weight,
|
||||
'field_type' => $request->filed_type_id,
|
||||
'formula' => $request->formula,
|
||||
'format' => $request->format_value,
|
||||
'description' => $request->description,
|
||||
'is_bold' => $request->is_bold,
|
||||
'autocomplete_bind' => $request->autocomplete_bind
|
||||
]);
|
||||
|
||||
$this->testNormalValueModel::query()->where('test_sample_id', $testSample->id)->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE]);
|
||||
$this->testSampleOrganismModel::query()->where('test_sample_id', $testSample->id)->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE]);
|
||||
|
||||
// reference range
|
||||
if(in_array($request->filed_type_id,[1,4,6])){
|
||||
$data = collect($request->patient_type_ids);
|
||||
$items = $data->map(function ($row, $key) use ($request, $testSample) {
|
||||
if(!empty($request->patient_type_ids[$key]['value'])) {
|
||||
$testNormalValue = $this->testNormalValueModel::query()->create([
|
||||
'test_sample_id' => $testSample->id,
|
||||
'patient_type_id' => $request->patient_type_ids[$key]['value'],
|
||||
'sign' => $request->signs[$key]['value'],
|
||||
'minimum' => is_numeric($request->min_values[$key]['value']) ? $request->min_values[$key]['value'] : null,
|
||||
'maximum' => is_numeric($request->max_values[$key]['value']) ? $request->max_values[$key]['value'] : null,
|
||||
]);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
}
|
||||
// organism and antibiotics
|
||||
if(in_array($request->filed_type_id,[2,3]) ){
|
||||
$organismsCollection = collect($request->organisms);
|
||||
$organisms = $organismsCollection->pluck('id')->unique()->toArray();
|
||||
$this->testSampleOrganismModel::query()->where(['test_sample_id' => $testSample->id])
|
||||
->whereNotIn('organism_id', $organisms)
|
||||
->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE]);
|
||||
|
||||
foreach ($organismsCollection as $org){
|
||||
$testSampleOrganism = $this->testSampleOrganismModel::query()->create([
|
||||
'test_sample_id' => $testSample->id,
|
||||
'is_default' => $org['is_default'],
|
||||
'organism_id' => $org['id'],
|
||||
'lab_id' => $this->baseLabId
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('test_sample.update_success'), 'data' => [$testSample]]);
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('test_sample.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function editTestSampleOrder(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_test_sample'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['id' => 'required', 'order_number' => 'required']);
|
||||
if ($validator->fails()){ return response()->json(['errors'=>$validator->errors()->all()]);}
|
||||
|
||||
$testSample = $this->model::query()->where([
|
||||
'id' => $request->id,
|
||||
'lab_id' => $this->baseLabId
|
||||
])->first();
|
||||
$testSample->update(['weight' => $request->order_number]);
|
||||
$batchUpdates = $this->model::query()->where([
|
||||
'sample_type_id' => $testSample->sample_type_id,
|
||||
'lab_id' => $this->baseLabId,
|
||||
])->where('weight','>=', $request->order_number)->where('id','<>', $request->id)->update([
|
||||
'weight' => DB::raw('weight + 1')
|
||||
]);
|
||||
DB::commit();
|
||||
return redirect()->back();
|
||||
} catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteTestSample(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_test_sample'])) return false;
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
$this->testNormalValueModel::query()->where('test_sample_id', $request->uid)->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE]);
|
||||
$this->testSampleOrganismModel::query()->where('test_sample_id', $request->uid)->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE]);
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('test_sample.delete_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('test_sample.delete_fail')]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function restoreTestSample(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$this->model::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE));
|
||||
$this->testNormalValueModel::query()->where('test_sample_id', $request->uid)->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE]);
|
||||
$this->testSampleOrganismModel::query()->where('test_sample_id', $request->uid)->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE]);
|
||||
DB::commit();
|
||||
return response()->json(['success' => true, 'message' => __('test_sample.restore_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success' => false, 'message' => __('test_sample.restore_fail')]);
|
||||
}
|
||||
}
|
||||
|
||||
public function storePhysicianCommission(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
foreach ($request->physician as $k=>$val){
|
||||
$this->physicianCommissionModel::query()->updateOrCreate([
|
||||
'physician_id' => $request->physician[$k],
|
||||
'test_sample_id' => $request->test_sample_id
|
||||
],[
|
||||
'physician_id' => $request->physician[$k],
|
||||
'test_sample_id' => $request->test_sample_id,
|
||||
'commission_rate' => $request->commission_rate[$k],
|
||||
'partner_price' => $request->pc_price[$k],
|
||||
'commission_type' => $request->commission_type[$k],
|
||||
'lab_id' => $this->baseLabId,
|
||||
BaseModel::CREATED_AT_FIELD => date('Y-m-d H:i:s'),
|
||||
BaseModel::CREATED_BY_FIELD => Auth::id(),
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
return redirect()->back();
|
||||
}
|
||||
catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
public function setCommissionToAllTest(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
$testSamples = $this->model::query()->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get();
|
||||
foreach ($testSamples as $testSample){
|
||||
$this->physicianCommissionModel::query()->updateOrCreate([
|
||||
'physician_id' => $request->physician_id,
|
||||
'test_sample_id' => $testSample->id
|
||||
],[
|
||||
'physician_id' => $request->physician_id,
|
||||
'test_sample_id' => $testSample->id,
|
||||
'commission_rate' => $request->commission_rate,
|
||||
'commission_type' => $request->commission_type,
|
||||
'lab_id' => $this->baseLabId,
|
||||
BaseModel::CREATED_AT_FIELD => date('Y-m-d H:i:s'),
|
||||
BaseModel::CREATED_BY_FIELD => Auth::id(),
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'message' => __('test_sample.add_commission_success')]);
|
||||
}
|
||||
catch (\Exception $e){
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'message' => __('test_sample.add_commission_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*public function cloneTestSampleProperties(Request $request){
|
||||
try {
|
||||
|
||||
$test_sample_id = $request->test_sample_id;
|
||||
$target_lab_id = $request->target_lab_id;
|
||||
$target_sample_type_id = $request->target_sample_type_id;
|
||||
$target_test_sample_id = $request->target_test_sample_id;
|
||||
|
||||
$testSamples = $this->model::with(['testValues','organisms','organisms.antibiotics'])->where('id', $test_sample_id)->get();
|
||||
|
||||
$this->testNormalValueModel::query()->where(['test_sample_id' => $target_test_sample_id])->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE]);
|
||||
$this->testSampleOrganismModel::query()->where(['test_sample_id' => $target_test_sample_id, 'lab_id' => $target_lab_id])->update([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE]);
|
||||
|
||||
foreach ($testSamples as $testSample) {
|
||||
$testValues = isset($testSample->testValues) ? $testSample->testValues : [];
|
||||
|
||||
foreach ($testValues as $testValue) {
|
||||
$testValueData = [
|
||||
'test_sample_id' => $target_test_sample_id,
|
||||
'patient_type_id' => $testValue->patient_type_id,
|
||||
'sign' => $testValue->sign,
|
||||
'minimum' => $testValue->minimum,
|
||||
'maximum' => $testValue->maximum,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => 1
|
||||
];
|
||||
$insertTestValue = $this->testNormalValueModel::query()->create($testValueData);
|
||||
}
|
||||
$testOrganisms = isset($testSample->organisms) ? $testSample->organisms : [];
|
||||
foreach ($testOrganisms as $testOrganism) {
|
||||
$testOrganismData = [
|
||||
'test_sample_id' => $target_test_sample_id,
|
||||
'organism_id' => $testOrganism->organism_id,
|
||||
'lab_id' => $target_lab_id,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => 1
|
||||
];
|
||||
$insertTestSampleOrganism = $this->testSampleOrganismModel::query()->create($testOrganismData);
|
||||
$antibiotics = isset($testOrganism->antibiotics) ? $testOrganism->antibiotics : [];
|
||||
foreach ($antibiotics as $antibiotic) {
|
||||
$testOrganismAntibioticData = [
|
||||
'test_sample_organism_id' => $insertTestSampleOrganism->id,
|
||||
'antibiotic_id' => $antibiotic->antibiotic_id,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => 1
|
||||
];
|
||||
$insertTestOrganismAntibiotic = $this->testSampleOrganismAntibioticModel::query()->create($testOrganismAntibioticData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Exception $e){
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
return redirect()->back();
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
81
app/Http/Controllers/TestGroupController.php
Normal file
81
app/Http/Controllers/TestGroupController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\TestGroup;
|
||||
use App\Models\TestGroupDetail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class TestGroupController extends Controller
|
||||
{
|
||||
|
||||
protected $model;
|
||||
protected $testGroupDetailModel;
|
||||
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
protected $base;
|
||||
|
||||
public function __construct(TestGroup $model, TestGroupDetail $testGroupDetailModel)
|
||||
{
|
||||
$this->model = $model;
|
||||
$this->testGroupDetailModel = $testGroupDetailModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
DB::beginTransaction();
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_test_group'])) return false;
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required','test_sample_ids' => 'required']);
|
||||
if ($validator->fails()){ return response()->json(['errors'=>$validator->errors()->all()]);}
|
||||
$testGroup = $this->model::query()->create(['group_name' => $request->name_en, 'lab_id' => $this->baseLabId]);
|
||||
foreach ($request->test_sample_ids as $v){
|
||||
$this->testGroupDetailModel::query()->create([
|
||||
'test_group_id' => $testGroup->id,
|
||||
'test_sample_id' => $v,
|
||||
'lab_id' => $this->baseLabId
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
return response()->json(['success'=> true , 'data' => [$testGroup]]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
DB::rollBack();
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get($id){
|
||||
try{
|
||||
$testGroupItems = $this->testGroupDetailModel::query()->where(['test_group_id' => $id, 'lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD=>RecordStatusEnum::ACTIVE])->get()->pluck('test_sample_id')->toArray();
|
||||
return response()->json(['success' => true, 'data' => $testGroupItems]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_test_group'])) return false;
|
||||
$this->model::query()->where(['id' => $request->id, 'lab_id' => $this->baseLabId])->update([BaseModel::RECORD_STATUS_FIELD=>RecordStatusEnum::DELETE]);
|
||||
return response()->json(['success' => true, 'message' => 'Test group successfully deleted']);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'message' => 'Failed while deleting test group. Please try again.', 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
321
app/Http/Controllers/UserController.php
Normal file
321
app/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Enums\UtilEnum;
|
||||
use App\Http\Controllers\Helper\GlobalController;
|
||||
use App\Models\AgeGroup;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Department;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\Role;
|
||||
use App\Models\SampleSource;
|
||||
use App\Models\User;
|
||||
use App\Models\UserLabCover;
|
||||
use App\Models\WardTransaction;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Laboratory;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
protected $userModel;
|
||||
protected $roleModel;
|
||||
protected $userLabCover;
|
||||
protected $sampleSourceModel;
|
||||
protected $baseLabId;
|
||||
protected $labs;
|
||||
protected $base;
|
||||
|
||||
public function __construct(User $userModel, Role $roleModel, UserLabCover $userLabCover, SampleSource $sampleSourceModel){
|
||||
$this->userModel = $userModel;
|
||||
$this->roleModel = $roleModel;
|
||||
$this->userLabCover = $userLabCover;
|
||||
$this->sampleSourceModel = $sampleSourceModel;
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
public function index(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_user_account'])) return redirect(url('my-profile'));
|
||||
$this->labs = parent::getAccessAbleLabs();
|
||||
$recordStatusCondition = Auth::id()==1 ? [RecordStatusEnum::DELETE, RecordStatusEnum::ACTIVE] : [RecordStatusEnum::ACTIVE];
|
||||
$roles = $this->roleModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(Auth::user()->role_id != UtilEnum::ADMINISTRATOR_ROLE , function ($roles){
|
||||
$roles->whereNotIn('id', [UtilEnum::ADMINISTRATOR_ROLE]);
|
||||
})->get();
|
||||
|
||||
$sample_sources = $this->sampleSourceModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(Auth::user()->role_id != UtilEnum::PHYSICIAN_ROLE && Auth::id()!=1 , function ($sampleSource){
|
||||
$sampleSource->where('lab_id', Session::get('base_lab_id'));
|
||||
})->get();
|
||||
|
||||
$users = $this->userModel::with(['role','lab_covers'])->whereIn(BaseModel::RECORD_STATUS_FIELD, $recordStatusCondition)
|
||||
->when(Auth::id()!=1, function ($users){
|
||||
$users->whereNotIn('id', [UtilEnum::ADMINISTRATOR_USER])
|
||||
->whereIn('id', $this->labs->pluck('userLabCovers')->flatten()->pluck('user_id')->toArray());
|
||||
})->when(!empty($request->kword), function($users) use ($request) {
|
||||
$keyword = '%' . str_replace(' ', '', $request->kword) . '%';
|
||||
$users->where(function ($q) use ($keyword) {
|
||||
$q->whereRaw("REPLACE(name,' ','') LIKE ?", [$keyword])
|
||||
->orWhereRaw("REPLACE(email,' ','') LIKE ?", [$keyword]);
|
||||
})->where('id', '!=', UtilEnum::ADMINISTRATOR_USER);
|
||||
})
|
||||
->orderBy(BaseModel::CREATED_AT,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('user_account', ['users' => $users, 'roles' => $roles, 'labs' => $this->labs, 'sample_sources' => $sample_sources]);
|
||||
}
|
||||
|
||||
public function labUsers(Request $request){
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['view_user_account'])) return redirect(url('my-profile'));
|
||||
$this->labs = parent::getAccessAbleLabs();
|
||||
$roles = $this->roleModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->whereNotIn('id', [UtilEnum::ADMINISTRATOR_ROLE])->get();
|
||||
$sample_sources = $this->sampleSourceModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->where('lab_id', Session::get('base_lab_id'))->get();
|
||||
|
||||
$users = $this->userModel::with(['role','lab_covers'])->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->whereIn('id', $this->labs->pluck('labUsers')->flatten()->pluck('user_id')->toArray())
|
||||
->whereNotIn('role_id', [UtilEnum::ADMINISTRATOR_ROLE])
|
||||
->when(!empty($request->kword), function($users) use ($request) {
|
||||
$users->whereRaw("replace(name, ' ','') like '%".str_replace(" ","",$request->kword)."%'")
|
||||
->orWhereRaw("replace(email, ' ','') like '%".str_replace(" ","",$request->kword)."%'");
|
||||
})->orderBy(BaseModel::CREATED_AT,'desc')->paginate(config('labis.pagination.perpage', 10));
|
||||
return view('user_account', ['users' => $users, 'roles' => $roles, 'labs' => $this->labs, 'sample_sources' => $sample_sources]);
|
||||
}
|
||||
|
||||
public function save(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['create_user_account'])) return false;
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|unique:users',
|
||||
'password' => 'required',
|
||||
'role_id' => 'required',
|
||||
'sample_source_id' => 'nullable'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('user_account.create_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
'is_manager' => ($request->role_id==3 ? 1: 0),
|
||||
'sample_source_id' => $request->sample_source_id,
|
||||
'role_id' => $request->role_id,
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => Auth::id(),
|
||||
);
|
||||
$user = $this->userModel::query()->create($data);
|
||||
Log::channel('account_creation')->info(array('action' => 'create', 'raw' => $request->all(), 'prepared' => $data));
|
||||
$requests = new Request(array('uid' => $user->id, 'lab_ids' => [Session::get('base_lab_id')]));
|
||||
$this->assignLabs($requests);
|
||||
return response()->json(['success' => true, 'message' => __('user_account.create_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('user_account.create_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_user_account'])) return false;
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'email' => 'required|email|unique:users,email, ' . $request->uid . ',id',
|
||||
'password' => 'required',
|
||||
'role_id' => 'required'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('user_account.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'role_id' => $request->role_id,
|
||||
'is_manager' => ($request->role_id==3 ? 1: 0),
|
||||
'sample_source_id' => $request->sample_source_id,
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->userModel::query()->where('id', $request->uid)->update($data);
|
||||
Log::channel('account_creation')->info(array('action' => 'update', 'raw' => $request->all(), 'prepared' => $data));
|
||||
return response()->json(['success' => true, 'message' => __('user_account.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('user_account.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function resetPassword(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['update_user_account'])) return false;
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'uid' => 'required',
|
||||
'password' => 'required'
|
||||
]);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('user_account.update_fail'), 'errors' => $validator->errors()->all()]);
|
||||
$data = array(
|
||||
'password' => Hash::make($request->password),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'updated_by' => Auth::id()
|
||||
);
|
||||
$this->userModel::query()->find($request->uid)->update($data);
|
||||
return response()->json(['success' => true, 'message' => __('user_account.update_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('user_account.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get(Request $request){
|
||||
try{
|
||||
$user = $this->userModel::with(['lab_covers'])->find($request->uid);
|
||||
return response()->json(['success' => true, 'message' => __('user_account.get_success'), 'data' => $user]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('user_account.get_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['delete_user_account'])) return false;
|
||||
$this->userModel::query()->where('id', $request->uid)->update(array( BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE));
|
||||
return response()->json(['success' => true, 'message' => __('user_account.delete_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('user_account.delete_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(Request $request){
|
||||
try{
|
||||
$this->userModel::query()->where('id', $request->uid)->update(array(BaseModel::RECORD_STATUS_FIELD=> RecordStatusEnum::ACTIVE));
|
||||
return response()->json(['success' => true, 'message' => __('user_account.restore_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('user_account.restore_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function assignLabs(Request $request){
|
||||
try{
|
||||
if(!GlobalController::user_can(Auth::user()->role_id, ['assign_lab'])) return false;
|
||||
$validator = \Validator::make($request->all(), [ 'uid' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['success' => false, 'message' => __('user_account.assign_lab_fail'), 'errors'=>$validator->errors()->all()]);
|
||||
$this->userLabCover::query()->where('user_id', $request->uid)
|
||||
->update(['end_date' => date('Y-m-d'), BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::DELETE, BaseModel::UPDATED_AT_FIELD => date('Y-m-d H:i:s'), BaseModel::UPDATED_BY_FIELD =>Auth::id()]);
|
||||
$data = array();
|
||||
foreach ($request->lab_ids as $lab_id){
|
||||
$data[] = array(
|
||||
'user_id' => $request->uid,
|
||||
'lab_id' => $lab_id,
|
||||
'start_date' => date('Y-m-d'),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'created_by' => Auth::id()
|
||||
);
|
||||
}
|
||||
$this->userLabCover::query()->insert($data);
|
||||
return response()->json(['success' => true, 'message' => __('user_account.assign_lab_success')]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success' => false, 'message' => __('user_account.assign_lab_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function uploadSignature(Request $request){
|
||||
try {
|
||||
$image = $request->file('signature');
|
||||
$imageName = 'signature_'.Auth::id().date('YmdHis').'.' . $image->getClientOriginalExtension();
|
||||
$user = User::find(Auth::id());
|
||||
$user->update(array('signature' => $imageName));
|
||||
$image->move(public_path('storage/images/signature'), $imageName);
|
||||
return back()->with(['success' => true, 'message' => __('singnature updated'), 'data' => 'signature']);
|
||||
}catch (\Exception $e){
|
||||
Log::error($e);
|
||||
return response()->json(['success'=> false , 'message' => __('user_account.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeSignature(Request $request){
|
||||
try {
|
||||
$user = $this->userModel::query()->find(Auth::id());
|
||||
if(!empty($user->signature)) {
|
||||
if (file_exists(public_path('storage/images/signature/' . $user->signature))) {
|
||||
unlink(public_path('storage/images/signature/' . $user->signature));
|
||||
$user->signature = null;
|
||||
}
|
||||
}
|
||||
$user->save();
|
||||
return response()->json(['success' => true, 'message' => __('user_account.update_success'), 'data' => $user]);
|
||||
}catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'message' => __('user_account.update_fail'), 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function changePassword(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$request->validate([
|
||||
'current_password' => 'required|string',
|
||||
'new_password' => 'required|confirmed|min:8|string'
|
||||
]);
|
||||
|
||||
$auth = Auth::user();
|
||||
|
||||
// Check current password
|
||||
if (!Hash::check($request->current_password, $auth->password)) {
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => __('user_account.invalid_current_password')
|
||||
// ]);
|
||||
return redirect()->back()->withErrors(['current_password' => __('user_account.invalid_current_password')]);
|
||||
}
|
||||
|
||||
// Check new password not same as old
|
||||
if ($request->current_password === $request->new_password) {
|
||||
return redirect()->back()->withErrors(['new_password' => __('user_account.new_password_same_old_password')]);
|
||||
}
|
||||
|
||||
// Update password
|
||||
$user = User::where('id', $auth->id)->update([
|
||||
'password' => Hash::make($request->new_password)
|
||||
]);
|
||||
|
||||
Log::channel('account_creation')->info([
|
||||
'action' => 'change-password',
|
||||
'user_id' => $auth->id
|
||||
]);
|
||||
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => __('user_account.change_password_success')
|
||||
// //'data' => $user
|
||||
// ]);
|
||||
return redirect()->back()->with('success', __('user_account.change_password_success'));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => __('user_account.change_password_fail'),
|
||||
// 'errors' => $e->getMessage()
|
||||
// ]);
|
||||
return redirect()->back()->withErrors(['error' => __('user_account.change_password_fail') . ': ' . $e->getMessage()]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function my_profile()
|
||||
{
|
||||
$user = $this->userModel::query()->with(['role','lab_covers'])->find(Auth::id());
|
||||
//return response()->json(['success' => true, 'message' => __('user_account.get_success'), 'data' => $user]);
|
||||
return view('my_profiles',[
|
||||
// 'labSettings' => (object) $this->base,
|
||||
'users' => $user
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
913
app/Http/Controllers/UtilController.php
Normal file
913
app/Http/Controllers/UtilController.php
Normal file
@@ -0,0 +1,913 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
use App\Enums\RecordStatusEnum;
|
||||
use App\Enums\UtilEnum;
|
||||
use App\Helpers\Helpers;
|
||||
use App\Http\Resources\HeadingItemResource;
|
||||
use App\Http\Resources\SampleTestResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Models\Antibiotic;
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Department;
|
||||
use App\Models\District;
|
||||
use App\Models\Organism;
|
||||
use App\Models\PatientType;
|
||||
use App\Models\Quantity;
|
||||
use App\Models\RejectComment;
|
||||
use App\Models\Sample;
|
||||
use App\Models\SampleType;
|
||||
use App\Models\TestSample;
|
||||
use App\Models\TestSampleOrganism;
|
||||
use App\Models\UserLabCover;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use function Illuminate\Auth\user;
|
||||
|
||||
class UtilController extends Controller
|
||||
{
|
||||
protected $organismModel;
|
||||
protected $antibioticModel;
|
||||
protected $sampleTypeModel;
|
||||
protected $departmentModel;
|
||||
protected $rejectCommentModel;
|
||||
protected $testSampleModel;
|
||||
protected $sampleModel;
|
||||
protected $labUserModel;
|
||||
protected $patientTypeModel;
|
||||
|
||||
protected $testSampleOrganismModel;
|
||||
|
||||
private $baseLabId;
|
||||
protected $base;
|
||||
|
||||
public function __construct(
|
||||
Organism $organismModel, Antibiotic $antibioticModel, RejectComment $rejectCommentModel, UserLabCover $labUserModel,
|
||||
SampleType $sampleTypeModel, Department $departmentModel, TestSample $testSampleModel, Sample $sampleModel,
|
||||
PatientType $patientTypeModel, TestSampleOrganism $testSampleOrganism
|
||||
){
|
||||
$this->organismModel = $organismModel;
|
||||
$this->antibioticModel = $antibioticModel;
|
||||
$this->sampleTypeModel = $sampleTypeModel;
|
||||
$this->departmentModel = $departmentModel;
|
||||
$this->rejectCommentModel = $rejectCommentModel;
|
||||
$this->testSampleModel = $testSampleModel;
|
||||
$this->sampleModel = $sampleModel;
|
||||
$this->labUserModel = $labUserModel;
|
||||
$this->patientTypeModel = $patientTypeModel;
|
||||
|
||||
$this->testSampleOrganismModel = $testSampleOrganism;
|
||||
|
||||
$this->baseLabId = Session::get('base_lab_id');
|
||||
$this->base = Session::get('base_lab');
|
||||
}
|
||||
|
||||
function province($responseType = 'object')
|
||||
{
|
||||
$provinces = parent::province();
|
||||
return $responseType == 'object' ? $provinces : json_encode($provinces); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
|
||||
|
||||
function district($responseType = 'object' ,$province_id = null)
|
||||
{
|
||||
$districts = parent::district($province_id);
|
||||
return $responseType == 'object' ? $districts : response()->json($districts); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function commune($responseType = 'object', $district_id = null)
|
||||
{
|
||||
$communes = parent::commune($district_id);
|
||||
return $responseType == 'object' ? $communes : json_encode($communes); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function village($responseType = 'object', $commune_id = null)
|
||||
{
|
||||
$villages = parent::village($commune_id);
|
||||
return $responseType == 'object' ? $villages : json_encode($villages); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function location()
|
||||
{
|
||||
return parent::location(); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
public function generatePatientUuId($responseType = 'object'){
|
||||
try{
|
||||
$location = (object) $this->location();
|
||||
$uuid = Helpers::generateUuId($location->short_name);
|
||||
return response()->json(['success'=> true , 'data' => array('uuid' => $uuid)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateUuIdForManual($responseType, $manual_code){
|
||||
try{
|
||||
$location = (object) $this->location();
|
||||
$uuid = Helpers::generateUuIdForManual($location->short_name, $manual_code);
|
||||
return response()->json(['success'=> true , 'data' => array('uuid' => $uuid)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDepartment(){
|
||||
try{
|
||||
$department = $this->departmentModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])->orderBy('weight','asc')->get();
|
||||
return response()->json(['success'=> true , 'data' => $department]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDepartmentByLabId($labId){
|
||||
try{
|
||||
$department = $this->departmentModel::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $labId])->orderBy('weight','asc')->get();
|
||||
return response()->json(['success'=> true , 'data' => $department]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSampleTypeByDepartment($departmentId=0){
|
||||
try{
|
||||
if($departmentId == 0) return response()->json(['success'=> true , 'data' => []]);
|
||||
$sampleType = $this->sampleTypeModel::query()->where('record_status_id', RecordStatusEnum::ACTIVE)->where('department_id', $departmentId)->get();
|
||||
return response()->json(['success'=> true , 'data' => $sampleType]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAntibiotic(Request $request, $responseType = 'object')
|
||||
{
|
||||
$antibiotics = $this->antibioticModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(isset($request->name) && $request->name !='', function ($organisms) use($request) {
|
||||
$organisms->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->name)."%'");
|
||||
})->orderBy('name_en', 'asc')->get();
|
||||
return $responseType == 'object' ? $antibiotics : json_encode($antibiotics);
|
||||
}
|
||||
|
||||
public function getOrganisms($responseType = 'object', Request $request)
|
||||
{
|
||||
$organisms = $this->organismModel::query()->where(BaseModel::RECORD_STATUS_FIELD, RecordStatusEnum::ACTIVE)
|
||||
->when(isset($request->name) && $request->name !='', function ($organisms) use($request) {
|
||||
$organisms->whereRaw("replace(name_en, ' ','') like '".str_replace(" ","",$request->name)."%'");
|
||||
})->orderBy('name_en', 'asc')->limit(40)->get();
|
||||
return $responseType == 'object' ? $organisms : json_encode($organisms);
|
||||
}
|
||||
|
||||
public function storeRejectComment(Request $request){
|
||||
try{
|
||||
$validator = \Validator::make($request->all(), ['name_en' => 'required']);
|
||||
if ($validator->fails()) return response()->json(['errors'=>$validator->errors()->all()]);
|
||||
$rejectComment = $this->rejectCommentModel::query()->create([
|
||||
'sample_condition_id' => 3,
|
||||
'reject_comment' => $request->name_en,
|
||||
'lab_id' => $this->baseLabId
|
||||
]);
|
||||
return response()->json(['success'=> true , 'data' => [$rejectComment]]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => [$e->getMessage()]]);
|
||||
}
|
||||
}
|
||||
|
||||
function getTestItem(){
|
||||
try{
|
||||
$departments = $this->departmentModel::with(['samples','samples.testSamples.test','samples.testSamples.childTest'])
|
||||
->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])
|
||||
->orderBy('weight', 'asc')->get();
|
||||
return response()->json(['success'=> true , 'data' => SampleTestResource::collection($departments)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function getLabUsers(){
|
||||
return $this->labUserModel::with('user')->where(['lab_id' => $this->baseLabId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get();
|
||||
}
|
||||
|
||||
|
||||
function getTestItemBySampleId($sampleId, $previousId = 0){
|
||||
try{
|
||||
$data = $this->sampleModel::with(['entryBy','modifiedBy','sample_tests', 'physician', 'patient','sample_source'])->where(['id' => $sampleId, 'lab_id' => $this->baseLabId])->get()->first();
|
||||
$arrData = array();
|
||||
$arrData['result_comment'] = [];
|
||||
$arrData['sample'] = array(
|
||||
'sample_number' => $data->sample_number,
|
||||
'requested_by' => $data->physician,
|
||||
'patient_name' => $data->patient->name_en,
|
||||
'patient_uuid' => $data->patient->patient_uuid,
|
||||
'sample_source' => $data->sample_source->name_en,
|
||||
'sample_id' => $data->id
|
||||
);
|
||||
|
||||
$arrData['sample_users'] = array('creator' => $data->entryBy->name, 'modifier' => @$data->modifiedBy->name);
|
||||
$arrData['result_users'] = [];
|
||||
$arrData['performers'] = UserResource::collection($this->getLabUsers()->pluck('user'));
|
||||
|
||||
$arrData['antibiotic_results'] = $this->getOrgAntibioticResult($sampleId);
|
||||
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
p.gender,
|
||||
p.dob,
|
||||
d.`id` AS department_id,
|
||||
d.`name_en` AS department_name,
|
||||
d.weight as dweight,
|
||||
st.`id` AS sample_type_id,
|
||||
st.weight as sweight,
|
||||
st.`name_en` AS sample_type,
|
||||
ts.`id` AS test_sample_id,
|
||||
ts.`heading_id` AS parent_id,
|
||||
ts.`field_type`,
|
||||
ts.formula,
|
||||
ts.format,
|
||||
ts.`usd_price`,
|
||||
ts.group_result,
|
||||
ts.description,
|
||||
t.`id` AS test_id,
|
||||
t.`name_en` AS test_name,
|
||||
ts.unit_sign AS unit_sign,
|
||||
ifnull(tr.test_result,"") as test_result,
|
||||
tr.is_show,
|
||||
tr.performed_by,
|
||||
tr.id as test_result_id,
|
||||
pct.`commission_type`,
|
||||
ifnull(pct.`commission_rate`, 0.00) as commission_rate,
|
||||
ifnull(pct.`partner_price`, 0.00) as partner_price,
|
||||
ts.weight,
|
||||
tr.test_date,
|
||||
tr.comment,
|
||||
ifnull(prev_r.test_result,"") as prev_result,
|
||||
ts.is_bold,
|
||||
ts.autocomplete_bind,
|
||||
ts.lab_id,
|
||||
sd.sample_descr
|
||||
FROM samples s
|
||||
INNER JOIN patients p
|
||||
ON p.id = s.patient_id AND p.lab_id = s.lab_id
|
||||
INNER JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
AND s.`lab_id` = tr.`lab_id`
|
||||
INNER JOIN test_samples ts
|
||||
ON ts.id = tr.`test_sample_id`
|
||||
and ts.lab_id = tr.lab_id
|
||||
INNER JOIN tests t
|
||||
ON t.`id` = ts.`test_id`
|
||||
INNER JOIN sample_types st
|
||||
ON st.`id` = ts.`sample_type_id`
|
||||
INNER JOIN departments d
|
||||
ON d.`id` = st.`department_id`
|
||||
LEFT JOIN `physician_commisssion` AS pct
|
||||
ON pct.`test_sample_id` = ts.`id`
|
||||
AND pct.`physician_id` = s.`physician_id`
|
||||
|
||||
LEFT JOIN sample_details sd ON sd.sample_id = s.id AND sd.sample_type_id = st.id
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
tr.`test_sample_id`,
|
||||
tr.`test_result`
|
||||
FROM samples s
|
||||
INNER JOIN test_results tr
|
||||
ON tr.`sample_id` = s.`id`
|
||||
WHERE s.id = '.$previousId.'
|
||||
AND s.`lab_id` = '.$this->baseLabId.'
|
||||
AND tr.record_status_id = 1
|
||||
) prev_r
|
||||
ON prev_r.test_sample_id = tr.`test_sample_id`
|
||||
|
||||
WHERE s.`id` = '.$sampleId.'
|
||||
AND s.`lab_id`= '.$this->baseLabId.'
|
||||
and ts.lab_id = '.$this->baseLabId.'
|
||||
AND tr.`record_status_id` = '.BaseModel::RECORD_STATUS_ACTIVE.'
|
||||
|
||||
ORDER BY
|
||||
d.`weight`,
|
||||
st.`weight`,
|
||||
ts.`weight`');
|
||||
$departmentArray = array();
|
||||
|
||||
|
||||
|
||||
$sampleTypeIds = collect($resultItems)->pluck('sample_type_id')->unique()->values();
|
||||
|
||||
$allTestSampleIds = collect($resultItems)->pluck('test_sample_id')->unique()->toArray();
|
||||
|
||||
if(count($sampleTypeIds)>0) {
|
||||
$refComment = collect($this->getRefCommentV2($sampleTypeIds));
|
||||
$testSampleIds = collect($resultItems)->whereIn('field_type', [2, 3])->pluck('test_sample_id')->unique()->toArray();
|
||||
if(count($testSampleIds)>0){
|
||||
$suggestedOrgResults = collect($this->getTestSampleOrganismV2($testSampleIds));
|
||||
}
|
||||
$testResultIds = collect($resultItems)->whereIn('field_type', [2, 3])->pluck('test_result_id')->unique()->toArray();
|
||||
if(count($testResultIds)>0){
|
||||
$organismResults = collect($this->getOrganismResultV2($testResultIds));
|
||||
$previousOrganismResults = collect($this->getPreviousOrganismResult($previousId));
|
||||
}
|
||||
$refCollection = collect($this->mapReferenceRangeV2($allTestSampleIds));
|
||||
}
|
||||
|
||||
|
||||
|
||||
$discount_type = ((object) $this->location())->discount_type;
|
||||
|
||||
foreach ($resultItems as $row){
|
||||
$departmentArray[$row->dweight]['department_id'] = $row->department_id;
|
||||
$departmentArray[$row->dweight]['department_name'] = $row->department_name;
|
||||
$departmentArray[$row->dweight]['samples'][$row->sweight]['sample_type_id'] = $row->sample_type_id;
|
||||
$departmentArray[$row->dweight]['samples'][$row->sweight]['sample_type_name'] = $row->sample_type;
|
||||
$departmentArray[$row->dweight]['samples'][$row->sweight]['sample_descr'] = (string)$row->sample_descr !=''? '('.$row->sample_descr.')' : '';
|
||||
|
||||
$departmentArray[$row->dweight]['samples'][$row->sweight]['comments'] = $refComment->where('sample_type_id', $row->sample_type_id)->values();// (object) $this->getRefComment($row->sample_type_id);
|
||||
|
||||
$organismResult = [];
|
||||
$suggestedOrgResult = [];
|
||||
|
||||
$previousOrganismResult = [];
|
||||
|
||||
if(in_array($row->field_type, [2,3])) {
|
||||
$organismResult = $organismResults->where('test_result_id', $row->test_result_id)->values();// $this->getOrganismResult($row->test_result_id);
|
||||
$suggestedOrgResult = $suggestedOrgResults->where('test_sample_id', $row->test_sample_id)->values();// $this->getTestSampleOrganism($row->test_sample_id);
|
||||
$previousOrganismResult = $previousOrganismResults->where('test_sample_id', $row->test_sample_id)->values();
|
||||
}
|
||||
|
||||
$refRanges =(object) $this->evaluateRefRanges( $refCollection->where('test_sample_id',$row->test_sample_id)->values()->toArray(), $row->gender, $row->dob); // (object) $this->mapReferenceRange($row->test_sample_id, $row->gender, $row->dob);
|
||||
|
||||
|
||||
|
||||
$testItemArray = array(
|
||||
'id' => (string)$row->test_sample_id,
|
||||
'test_id' => $row->test_id,
|
||||
'test_name' => $row->test_name,
|
||||
'closed_parent_id' => (string) (int)$row->parent_id,
|
||||
'field_type' => (string) $row->field_type,
|
||||
'unit_sign' => (string) $row->unit_sign,
|
||||
'usd_price' => $row->usd_price,
|
||||
'min_ref_val' => isset($refRanges->minimum) ? $refRanges->minimum :'',
|
||||
'max_ref_val' => isset($refRanges->maximum) ? $refRanges->maximum: '',
|
||||
'org_ref_range' => $refRanges,
|
||||
'ref_range' =>(isset($refRanges->sign) && in_array($refRanges->sign,["0.00","0.0","0"]) && isset($refRanges->minimum) && $refRanges->minimum==0 && isset($refRanges->maximum) && $refRanges->maximum==0) ? $refRanges->minimum . ' - ' . $refRanges->maximum : ((isset($refRanges->minimum)) ? in_array($refRanges->sign, ['<','<=','Neg <', 'Neg<','≤']) ? $refRanges->sign.' '.$refRanges->maximum : (in_array($refRanges->sign, ['>','>=','≥']) ? $refRanges->sign. ' '. (($refRanges->minimum == 0)? $refRanges->maximum:$refRanges->minimum) : ((isset($refRanges->minimum)) ? ($refRanges->minimum==0 && $refRanges->maximum==0 ? '' : $refRanges->minimum) .' '. $refRanges->sign .' '. ($refRanges->maximum==0? '':$refRanges->maximum) : '')) : ''),
|
||||
//'ref_range' =>(isset($refRanges->sign) && in_array($refRanges->sign,["0.00","0.0","0"]) && isset($refRanges->minimum) && $refRanges->minimum==0 && isset($refRanges->maximum) && $refRanges->maximum==0) ? $refRanges->minimum . ' - ' . $refRanges->maximum : ((isset($refRanges->minimum)) ? in_array($refRanges->sign, ['<','<=','Neg <', 'Neg<','≤']) ? $refRanges->sign.' '.$refRanges->maximum : (in_array($refRanges->sign, ['>','>=']) ? $refRanges->sign. ' '.$refRanges->minimum : ((isset($refRanges->minimum)) ? ($refRanges->minimum==0 && $refRanges->maximum==0 ? '' : $refRanges->minimum) .' '. $refRanges->sign .' '. ($refRanges->maximum==0? '':$refRanges->maximum) : '')) : ''),
|
||||
//'ref_range' => ((isset($refRanges->minimum)) ? in_array($refRanges->sign, ['<','<=','Neg <', 'Neg<','≤']) ? $refRanges->sign.' '.$refRanges->maximum : (in_array($refRanges->sign, ['>','>=']) ? $refRanges->sign. ' '.$refRanges->minimum : ((isset($refRanges->minimum)) ? ($refRanges->minimum==0 && $refRanges->maximum==0 ? '' : $refRanges->minimum) .' '. $refRanges->sign .' '. ($refRanges->maximum==0? '':$refRanges->maximum) : '')) : ''),
|
||||
'test_result' => !is_null($row->format) && $row->format>=0 && is_numeric($row->test_result) ? number_format($row->test_result,$row->format,'.','') : $row->test_result,
|
||||
'prev_result' => (string)!is_null($row->format) && is_numeric($row->prev_result) ? number_format($row->prev_result,$row->format) : $row->prev_result,
|
||||
'sign' => isset($refRanges->sign) ? $refRanges->sign: '',
|
||||
'is_show' => $row->is_show,
|
||||
'performed_by' => $row->performed_by,
|
||||
'org_results' => $organismResult,
|
||||
'prev_org_results' => $previousOrganismResult,
|
||||
'org_suggested_results' => $suggestedOrgResult,
|
||||
'group_result' => (string) $row->group_result,
|
||||
'commission_type' => (!empty($row->commission_type) ? $row->commission_type : $discount_type),
|
||||
'commission_rate' => $row->commission_rate,
|
||||
'partner_price' => $row->partner_price,
|
||||
'description' => (string) nl2br($row->description),
|
||||
'formula' => (string) $row->formula,
|
||||
'order' => (int) $row->weight,
|
||||
'test_date' => (string) $row->test_date,
|
||||
'comment' => (string) nl2br($row->comment),
|
||||
'str_comment' => (string) $row->comment,
|
||||
'is_bold' => (int) $row->is_bold,
|
||||
'autocomplete_bind' => (int) $row->autocomplete_bind,
|
||||
'ts' => $row->test_result,
|
||||
'lab_id' => $row->lab_id,
|
||||
'format' => (int)$row->format
|
||||
);
|
||||
$departmentArray[$row->dweight]['samples'][$row->sweight]['tests'][] = $testItemArray;
|
||||
}
|
||||
|
||||
|
||||
$arrData['sample_tests'] = $departmentArray;
|
||||
return response()->json(['success'=> true , 'data' => $arrData]);
|
||||
} catch (\Exception $e){
|
||||
Log::error($e);
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function getRefCommentV2($sampleTypeIds){
|
||||
return Comment::query()->select('sample_type_id', 'comment_desc as name')->where(
|
||||
[
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
||||
'lab_id' => $this->baseLabId
|
||||
])->whereIn('sample_type_id', $sampleTypeIds)->get()->toArray();
|
||||
}
|
||||
|
||||
function getTestSampleOrganismV2($testSampleIds){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
ts.id as test_sample_id,
|
||||
tsr.id AS test_organism_id,
|
||||
o.id as organism_id,
|
||||
o.`name_en` AS organism_name,
|
||||
o.is_bold,
|
||||
tsr.is_default
|
||||
FROM `test_samples` AS ts
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = ts.id
|
||||
INNER JOIN organisms o
|
||||
ON o.id = tsr.`organism_id`
|
||||
WHERE ts.`id` in('. implode(',',$testSampleIds) . ')
|
||||
AND tsr.record_status_id = 1
|
||||
AND ts.record_status_id = 1 and tsr.is_default=1');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function getOrganismResultV2($testResultIds){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
ogr.test_result_id,
|
||||
tsr.id AS test_organism_id,
|
||||
ogr.organism_id,
|
||||
ogr.quantity_id,
|
||||
ogr.contaminant,
|
||||
o.`name_en` AS organism_name,
|
||||
o.is_bold,
|
||||
qt.`quantity_name`,
|
||||
ogr.id
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id and ogr.lab_id = trs.lab_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
INNER JOIN organisms o
|
||||
ON o.id = ogr.`organism_id`
|
||||
LEFT JOIN `quantities` qt
|
||||
ON qt.id = ogr.`quantity_id`
|
||||
WHERE ogr.`test_result_id` in('.implode(',', $testResultIds). ')
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function getPreviousOrganismResult($previousSampleId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
trs.test_sample_id,
|
||||
ogr.test_result_id,
|
||||
tsr.id AS test_organism_id,
|
||||
ogr.organism_id,
|
||||
ogr.quantity_id,
|
||||
ogr.contaminant,
|
||||
o.`name_en` AS organism_name,
|
||||
o.is_bold,
|
||||
qt.`quantity_name`,
|
||||
ogr.id
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id and ogr.lab_id = trs.lab_id
|
||||
INNER JOIN samples s
|
||||
ON s.id = trs.sample_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
INNER JOIN organisms o
|
||||
ON o.id = ogr.`organism_id`
|
||||
LEFT JOIN `quantities` qt
|
||||
ON qt.id = ogr.`quantity_id`
|
||||
WHERE s.id = '.$previousSampleId.'
|
||||
AND s.`lab_id` = '.$this->baseLabId.'
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function getRefComment($sampleTypeId ){
|
||||
return Comment::query()->select('comment_desc as name')->where(
|
||||
[
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
||||
'lab_id' => $this->baseLabId,
|
||||
'sample_type_id' => $sampleTypeId
|
||||
])->get();
|
||||
}
|
||||
|
||||
function mapReferenceRange($testSampleId, $genderId, $patientDob){
|
||||
|
||||
$referenceRanges = DB::select('
|
||||
SELECT
|
||||
(IF(pt.range_start=0, 1, pt.range_start) * pt.range_start_unit) + IF(pt.range_start_unit=\'>\', 1, 0) AS start_range_in_day,
|
||||
(IF(pt.range_end=0, 1, pt.range_end) * pt.range_end_unit) + IF(pt.range_end_sign=\'<=\', 1, 0) AS end_range_in_day,
|
||||
pt.gender,
|
||||
pt.range_start,
|
||||
pt.range_start_unit,
|
||||
pt.range_start_sign,
|
||||
pt.range_end,
|
||||
pt.range_end_unit,
|
||||
pt.range_end_sign,
|
||||
tnv.test_sample_id,
|
||||
tnv.sign,
|
||||
ts.format,
|
||||
tnv.`minimum` AS minimum,
|
||||
tnv.`maximum` AS maximum
|
||||
FROM test_normal_values tnv
|
||||
INNER JOIN patient_types pt
|
||||
ON pt.id = tnv.patient_type_id
|
||||
INNER JOIN test_samples ts
|
||||
ON ts.id = tnv.test_sample_id
|
||||
WHERE tnv.record_status_id = 1
|
||||
AND test_sample_id = '.$testSampleId.'
|
||||
');
|
||||
|
||||
$now = time(); // or your date as well
|
||||
$your_date = strtotime($patientDob);
|
||||
$patientAgeInDay = round(($now - $your_date)/ (60 * 60 * 24));
|
||||
$referenceRangeArray = array();
|
||||
foreach ($referenceRanges as $referenceRange){
|
||||
if((int)$patientAgeInDay >= (int)$referenceRange->start_range_in_day && (int)$patientAgeInDay <= (int)$referenceRange->end_range_in_day){
|
||||
// Log::info($patientAgeInDay . ' - '.$genderId);
|
||||
if($referenceRange->gender == $genderId){
|
||||
// Log::info('geneder=gender');
|
||||
$referenceRangeArray = array(
|
||||
'sign' => $referenceRange->sign,
|
||||
'minimum' => !is_null($referenceRange->format) ? number_format($referenceRange->minimum,$referenceRange->format) : (fmod($referenceRange->minimum,1) == 0 ? number_format($referenceRange->minimum,0):number_format($referenceRange->minimum,2)),
|
||||
'maximum' => !is_null($referenceRange->format) ? number_format($referenceRange->maximum,$referenceRange->format) : (fmod($referenceRange->maximum,1) == 0 ? number_format($referenceRange->maximum,0):number_format($referenceRange->maximum,2)),
|
||||
); break;
|
||||
}
|
||||
else{
|
||||
if($referenceRange->gender==3) {
|
||||
$referenceRangeArray = array(
|
||||
'sign' => $referenceRange->sign,
|
||||
'minimum' => !is_null($referenceRange->format) ? number_format($referenceRange->minimum,$referenceRange->format) : (fmod($referenceRange->minimum,1) == 0 ? number_format($referenceRange->minimum,0):number_format($referenceRange->minimum,2)),
|
||||
'maximum' => !is_null($referenceRange->format) ? number_format($referenceRange->maximum,$referenceRange->format) : (fmod($referenceRange->maximum,1) == 0 ? number_format($referenceRange->maximum,0):number_format($referenceRange->maximum,2)),
|
||||
); break;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
return $referenceRangeArray;
|
||||
}
|
||||
|
||||
function getTestSampleOrganism($testSampleId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
ts.id as test_sample_id,
|
||||
tsr.id AS test_organism_id,
|
||||
o.id as organism_id,
|
||||
o.`name_en` AS organism_name,
|
||||
o.is_bold,
|
||||
tsr.is_default
|
||||
FROM `test_samples` AS ts
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = ts.id
|
||||
INNER JOIN organisms o
|
||||
ON o.id = tsr.`organism_id`
|
||||
WHERE ts.`id` = '.$testSampleId. '
|
||||
AND tsr.record_status_id = 1
|
||||
AND ts.record_status_id = 1');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function getOrganismResult($testResultId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
ogr.test_result_id,
|
||||
tsr.id AS test_organism_id,
|
||||
ogr.organism_id,
|
||||
ogr.quantity_id,
|
||||
ogr.contaminant,
|
||||
o.`name_en` AS organism_name,
|
||||
o.is_bold,
|
||||
qt.`quantity_name`,
|
||||
ogr.id
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id and ogr.lab_id = trs.lab_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
INNER JOIN organisms o
|
||||
ON o.id = ogr.`organism_id`
|
||||
LEFT JOIN `quantities` qt
|
||||
ON qt.id = ogr.`quantity_id`
|
||||
WHERE ogr.`test_result_id` = '.$testResultId. '
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function getOrgAntibioticResult($sampleId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
ogr.test_result_id,
|
||||
tsr.id AS test_organism_id,
|
||||
ogr.organism_id,
|
||||
agr.antibiotic_id,
|
||||
agr.disk_diffusion,
|
||||
agr.mic,
|
||||
agr.sensitive,
|
||||
agr.is_hide,
|
||||
att.name_en
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN `antibiogram_results` agr
|
||||
ON agr.`organism_result_id` = ogr.`id`
|
||||
INNER JOIN `antibiotics` att
|
||||
ON att.id = agr.antibiotic_id
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
WHERE trs.`sample_id` = '.$sampleId.'
|
||||
AND agr.`record_status_id` = 1
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1
|
||||
order by agr.sensitive desc');
|
||||
return $resultItems;
|
||||
}
|
||||
|
||||
function getTestSampleItems($sampleTypeId = null, $fieldType=""){
|
||||
|
||||
try{
|
||||
$headingItems = $this->testSampleModel::with(['test'])
|
||||
->where([
|
||||
'lab_id' => $this->baseLabId,
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE
|
||||
])->when(!empty($sampleTypeId), function ($headingItems) use($sampleTypeId) {
|
||||
$headingItems->where('sample_type_id', $sampleTypeId);
|
||||
})->when($fieldType !="", function ($query) use($fieldType){
|
||||
$query->where('field_type', $fieldType);
|
||||
})->get();
|
||||
return response()->json(['success'=> true , 'data' => HeadingItemResource::collection($headingItems)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
function getTestSampleBySampleType($sampleTypeId){
|
||||
try{
|
||||
$headingItems = $this->testSampleModel::with(['test'])
|
||||
->where([
|
||||
BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE,
|
||||
'sample_type_id' => $sampleTypeId
|
||||
])->get();
|
||||
return response()->json(['success'=> true , 'data' => HeadingItemResource::collection($headingItems)]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPatientTypes(){
|
||||
try{
|
||||
$patientTypes = $this->patientTypeModel::query()->where([ BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->get();
|
||||
return response()->json(['success'=> true , 'data' => $patientTypes]);
|
||||
} catch (\Exception $e)
|
||||
{
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPhysicianCommission($testSampleId){
|
||||
try {
|
||||
$test = $this->testSampleModel::with(['test'])->find($testSampleId);
|
||||
$testCommissions = DB::select('
|
||||
SELECT
|
||||
p.id,
|
||||
p.name_en,
|
||||
ifnull(comm.commission_type, '.((object)$this->location())->discount_type.') as commission_type,
|
||||
ifnull(comm.commission_rate, 0.00) as commission_rate,
|
||||
ifnull(comm.partner_price, 0.00) as partner_price
|
||||
FROM physicians p
|
||||
LEFT JOIN(
|
||||
SELECT
|
||||
pc.`physician_id`,
|
||||
pc.`commission_type`,
|
||||
pc.`commission_rate`,
|
||||
pc.partner_price,
|
||||
pc.`test_sample_id`
|
||||
FROM `physician_commisssion` pc
|
||||
INNER JOIN physicians p
|
||||
ON p.`id` = pc.`physician_id`
|
||||
WHERE p.`lab_id` = '.$this->baseLabId.'
|
||||
AND p.`record_status_id` = 1
|
||||
AND pc.test_sample_id = '.$testSampleId.'
|
||||
AND pc.`record_status_id` = 1
|
||||
) comm
|
||||
ON comm.physician_id = p.`id`
|
||||
WHERE p.`lab_id` = '.$this->baseLabId.'
|
||||
AND p.`record_status_id` = 1
|
||||
');
|
||||
$data = array('test_name' => $test->test->name_en, 'physicians' => $testCommissions);
|
||||
return response()->json(['success'=> true , 'data' => $data]);
|
||||
} catch (\Exception $e){
|
||||
return response()->json(['success'=> false , 'errors' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/****** */
|
||||
|
||||
|
||||
|
||||
function mapReferenceRangeV2($testSampleIds)
|
||||
{
|
||||
try{
|
||||
$referenceRanges = DB::select('
|
||||
SELECT
|
||||
ts.id as test_sample_id,
|
||||
(IF(pt.range_start=0, 1, pt.range_start) * pt.range_start_unit) + IF(pt.range_start_unit=\'>\', 1, 0) AS start_range_in_day,
|
||||
(IF(pt.range_end=0, 1, pt.range_end) * pt.range_end_unit) + IF(pt.range_end_sign=\'<=\', 1, 0) AS end_range_in_day,
|
||||
pt.gender,
|
||||
pt.range_start,
|
||||
pt.range_start_unit,
|
||||
pt.range_start_sign,
|
||||
pt.range_end,
|
||||
pt.range_end_unit,
|
||||
pt.range_end_sign,
|
||||
tnv.test_sample_id,
|
||||
tnv.sign,
|
||||
ts.format,
|
||||
tnv.`minimum` AS minimum,
|
||||
tnv.`maximum` AS maximum
|
||||
FROM test_normal_values tnv
|
||||
INNER JOIN patient_types pt
|
||||
ON pt.id = tnv.patient_type_id
|
||||
INNER JOIN test_samples ts
|
||||
ON ts.id = tnv.test_sample_id
|
||||
WHERE tnv.record_status_id = 1
|
||||
AND test_sample_id in('. implode(',',$testSampleIds) . ')
|
||||
');
|
||||
return $referenceRanges;
|
||||
} catch(\Exception $e)
|
||||
{
|
||||
dd($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function evaluateRefRanges($referenceRanges, $genderId, $patientDob){
|
||||
$now = time();
|
||||
$your_date = strtotime($patientDob);
|
||||
$patientAgeInDay = round(($now - $your_date)/ (60 * 60 * 24));
|
||||
$referenceRangeArray = array();
|
||||
foreach ($referenceRanges as $referenceRange){
|
||||
if((int)$patientAgeInDay >= (int)$referenceRange->start_range_in_day && (int)$patientAgeInDay <= (int)$referenceRange->end_range_in_day){
|
||||
if($referenceRange->gender == $genderId){
|
||||
$referenceRangeArray = array(
|
||||
'sign' => $referenceRange->sign,
|
||||
'minimum' => !is_null($referenceRange->format) ? number_format($referenceRange->minimum,$referenceRange->format) : (fmod($referenceRange->minimum,1) == 0 ? number_format($referenceRange->minimum,0):number_format($referenceRange->minimum,2)),
|
||||
'maximum' => !is_null($referenceRange->format) ? number_format($referenceRange->maximum,$referenceRange->format) : (fmod($referenceRange->maximum,1) == 0 ? number_format($referenceRange->maximum,0):number_format($referenceRange->maximum,2)),
|
||||
); break;
|
||||
}
|
||||
else{
|
||||
if($referenceRange->gender==3) {
|
||||
$referenceRangeArray = array(
|
||||
'sign' => $referenceRange->sign,
|
||||
'minimum' => !is_null($referenceRange->format) ? number_format($referenceRange->minimum,$referenceRange->format) : (fmod($referenceRange->minimum,1) == 0 ? number_format($referenceRange->minimum,0):number_format($referenceRange->minimum,2)),
|
||||
'maximum' => !is_null($referenceRange->format) ? number_format($referenceRange->maximum,$referenceRange->format) : (fmod($referenceRange->maximum,1) == 0 ? number_format($referenceRange->maximum,0):number_format($referenceRange->maximum,2)),
|
||||
); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $referenceRangeArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getTestSampleOrganisms($testSampleId, $sampleId){
|
||||
|
||||
|
||||
$test = $this->testSampleModel::with('test')->find($testSampleId);
|
||||
$defVal = count($this->getSelectedOrganismResult($sampleId, $testSampleId)) ==0 ? [-1] : $this->getSelectedOrganismResult($sampleId, $testSampleId);
|
||||
$testSampleOrganisms = $this->testSampleOrganismModel::with(['organism'])
|
||||
->where(['test_sample_id' => $testSampleId, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->limit(10)->get()->map(function ($data) use ($defVal) {
|
||||
$data['selected'] = in_array($data['id'], $defVal) ? 1: 0;
|
||||
return $data;
|
||||
})->toArray();
|
||||
|
||||
$qualities = Quantity::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->select(['id','quantity_name as name'])->get()->toArray();
|
||||
$antibiotics = collect(Antibiotic::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->select(['id','name_en'])->get()->toArray());
|
||||
$resultKeyed = collect($this->getOrgAntibioticResult($sampleId))->groupBy('organism_id');
|
||||
|
||||
$testSampleOrganisms = collect($testSampleOrganisms)->map(function ($item) use ($resultKeyed, $antibiotics) {
|
||||
$match = $resultKeyed->get($item['organism_id']);
|
||||
return [
|
||||
'id' => $item['id'],
|
||||
'test_sample_id' => $item['test_sample_id'],
|
||||
'organism_id' => $item['organism_id'],
|
||||
'lab_id' => $item['lab_id'],
|
||||
'record_status_id' => $item['record_status_id'],
|
||||
'selected' => $item['selected'],
|
||||
'organism' => $item['organism'],
|
||||
'antibiotics' => collect($antibiotics)->map(function ($item_) use ($match) {
|
||||
$match = $match?->groupBy('antibiotic_id')->get($item_['id'])?->first();
|
||||
return [
|
||||
'id' => $item_['id'],
|
||||
'name_en' => $item_['name_en'],
|
||||
'antibiotic_item' => $item_,
|
||||
'antibiotic_result' => $match ? [
|
||||
'sensitive' => $match?->sensitive,
|
||||
'mic' => $match?->mic,
|
||||
'disk_diffusion' => $match?->disk_diffusion,
|
||||
'is_hide' => $match?->is_hide,
|
||||
'organism_id' => $match?->organism_id,
|
||||
'test_organism_id' => $match?->test_organism_id,
|
||||
'test_result_id' => $match?->test_result_id
|
||||
] : null
|
||||
];
|
||||
})
|
||||
];
|
||||
})->toArray();
|
||||
|
||||
return response()->json(['success'=> true , 'test' =>$test, 'data' => array_unique($testSampleOrganisms, SORT_REGULAR),'qualities' => $qualities]);
|
||||
}
|
||||
|
||||
|
||||
public function getTestSampleOrganismsByName(Request $request){
|
||||
$test = $this->testSampleModel::with('test')->find($request->test_sample_id);
|
||||
$defVal = count($this->getSelectedOrganismResult($request->sample_id, $request->test_sample_id)) ==0 ? [-1] : $this->getSelectedOrganismResult($request->sample_id, $request->test_sample_id);
|
||||
$selectedOrganisms = $this->testSampleOrganismModel::with(['organism','antibiotics.antibioticResult','antibiotics.antibioticItem'])
|
||||
->where(['test_sample_id' => $request->test_sample_id, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->whereIn('id', $defVal)->get()->map(function ($data) {
|
||||
$data['selected'] = 1;
|
||||
return $data;
|
||||
})->toArray();
|
||||
|
||||
$testSampleOrganisms = $this->testSampleOrganismModel::with(['organism','antibiotics.antibioticResult','antibiotics.antibioticItem'])
|
||||
->where(['test_sample_id' => $request->test_sample_id, BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE, 'lab_id' => $this->baseLabId])
|
||||
->when(!empty(trim($request->name)), function ($testSampleOrganisms) use($request){
|
||||
$testSampleOrganisms->whereIn('organism_id', $this->organismModel::query()->whereRaw("replace(name_en, ' ','') like '%".str_replace(" ","",$request->name)."%'")->pluck('id')->toArray());
|
||||
})->whereNotIn('id', $defVal)
|
||||
->limit(10)->get()->map(function ($data) {
|
||||
$data['selected'] = 0;
|
||||
return $data;
|
||||
})->toArray();
|
||||
$qualities = Quantity::query()->where([BaseModel::RECORD_STATUS_FIELD => RecordStatusEnum::ACTIVE])->select(['id','quantity_name as name'])->get()->toArray();
|
||||
return response()->json(['success'=> true , 'test' =>$test, 'data' => array_unique(array_merge($selectedOrganisms, $testSampleOrganisms), SORT_REGULAR), 'qualities' => $qualities, 'selected_org' => $this->getSelectedOrganismResultQty($request->sample_id, $request->test_sample_id)]);
|
||||
}
|
||||
|
||||
|
||||
function getSelectedOrganismResult($sampleId, $testSampleId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
tsr.id AS test_organism_id
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
INNER JOIN organisms o
|
||||
ON o.id = ogr.`organism_id`
|
||||
LEFT JOIN `quantities` qt
|
||||
ON qt.id = ogr.`quantity_id`
|
||||
WHERE trs.sample_id = '.$sampleId.'
|
||||
and trs.test_sample_id ='.$testSampleId.'
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1');
|
||||
$data = collect($resultItems)->pluck('test_organism_id')->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
function getSelectedOrganismResultQty($sampleId, $testSampleId){
|
||||
$resultItems = DB::select('
|
||||
SELECT
|
||||
tsr.id AS test_organism_id,
|
||||
ogr.quantity_id
|
||||
FROM `organism_results` AS ogr
|
||||
INNER JOIN test_results trs
|
||||
ON trs.id = ogr.test_result_id
|
||||
INNER JOIN `test_sample_organisms` tsr
|
||||
ON tsr.test_sample_id = trs.test_sample_id
|
||||
AND tsr.`organism_id` = ogr.`organism_id`
|
||||
INNER JOIN organisms o
|
||||
ON o.id = ogr.`organism_id`
|
||||
LEFT JOIN `quantities` qt
|
||||
ON qt.id = ogr.`quantity_id`
|
||||
WHERE trs.sample_id = '.$sampleId.'
|
||||
and trs.test_sample_id ='.$testSampleId.'
|
||||
AND ogr.record_status_id = 1
|
||||
AND trs.record_status_id = 1
|
||||
AND tsr.record_status_id = 1');
|
||||
$data = collect($resultItems)->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
21
app/Http/Middleware/Authenticate.php
Normal file
21
app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
31
app/Http/Middleware/Cors.php
Normal file
31
app/Http/Middleware/Cors.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class Cors
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
/* return $next($request)
|
||||
->header('Access-Control-Allow-Origin', '*')
|
||||
->header('Access-Control-Allow-Methods', 'OPTIONS, GET, POST, PUT, DELETE')
|
||||
->header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, X-Token-Auth, Authorization');*/
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
$response->headers->set('Access-Control-Allow-Origin' , '*');
|
||||
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE');
|
||||
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application');
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
26
app/Http/Middleware/Localization.php
Normal file
26
app/Http/Middleware/Localization.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Localization
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (Session::has('locale')) {
|
||||
App::setLocale(Session::get('locale'));
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
17
app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
31
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
31
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string[]|null ...$guards
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
24
app/Http/Middleware/SetLocale.php
Normal file
24
app/Http/Middleware/SetLocale.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SetLocale
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
if (session()->has('locale')) {
|
||||
App::setLocale(session('locale'));
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
18
app/Http/Middleware/TrimStrings.php
Normal file
18
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
20
app/Http/Middleware/TrustHosts.php
Normal file
20
app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
23
app/Http/Middleware/TrustProxies.php
Normal file
23
app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
||||
}
|
||||
34
app/Http/Middleware/VerifyBaseLab.php
Normal file
34
app/Http/Middleware/VerifyBaseLab.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
//use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class VerifyBaseLab
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Closure $next
|
||||
* @return string|null
|
||||
*/
|
||||
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
try{
|
||||
if (!$request->session()->exists('base_lab_id')) {
|
||||
return redirect('/base');
|
||||
}
|
||||
} catch (\Exception $e){
|
||||
|
||||
Log::error($e);
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
19
app/Http/Middleware/VerifyCsrfToken.php
Normal file
19
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
'login',
|
||||
'telegram/webhook'
|
||||
];
|
||||
}
|
||||
92
app/Http/Requests/Auth/LoginRequest.php
Normal file
92
app/Http/Requests/Auth/LoginRequest.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use Illuminate\Auth\Events\Lockout;
|
||||
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.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'email' => ['required', 'string', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to authenticate the request's credentials.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$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.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function ensureIsNotRateLimited()
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function throttleKey()
|
||||
{
|
||||
return Str::lower($this->input('email')).'|'.$this->ip();
|
||||
}
|
||||
}
|
||||
43
app/Http/Requests/PatientCreateRequest.php
Normal file
43
app/Http/Requests/PatientCreateRequest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
class PatientCreateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
//Log::info($this->request->all());
|
||||
return [
|
||||
'name_en' => 'required|string',
|
||||
'patient_uuid' => 'nullable|string',
|
||||
'dob' => 'required|date',
|
||||
'gender' => 'required|integer',
|
||||
'phone_number' => 'nullable',
|
||||
'khid_number' => 'nullable',
|
||||
'house_number' => 'nullable',
|
||||
'street_number' => 'nullable',
|
||||
'province_id' => 'nullable',
|
||||
'district_id' => 'nullable',
|
||||
'commune_id' => 'nullable',
|
||||
'village_id' => 'nullable'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
42
app/Http/Requests/PatientTypeCreateRequest.php
Normal file
42
app/Http/Requests/PatientTypeCreateRequest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PatientTypeCreateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name_en' => 'required',
|
||||
'gender' => 'required',
|
||||
'age_from' => 'required|min:0',
|
||||
'age_from_unit' => 'required|min:0',
|
||||
'age_to' => 'required|min:0',
|
||||
'age_to_unit' => 'required|min:0'
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
43
app/Http/Requests/PatientUpdateRequest.php
Normal file
43
app/Http/Requests/PatientUpdateRequest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PatientUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'uid' => 'required|integer|min:1',
|
||||
'name_en' => 'required|string',
|
||||
'patient_uuid' => 'nullable|string',
|
||||
'dob' => 'required',
|
||||
'gender' => 'required|integer',
|
||||
'phone_number' => 'nullable',
|
||||
'khid_number' => 'nullable',
|
||||
'house_number' => 'nullable',
|
||||
'street_number' => 'nullable',
|
||||
'province_id' => 'nullable',
|
||||
'district_id' => 'nullable',
|
||||
'commune_id' => 'nullable',
|
||||
'village_id' => 'nullable'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
106
app/Http/Requests/SampleCreateRequest.php
Normal file
106
app/Http/Requests/SampleCreateRequest.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
|
||||
|
||||
use App\Models\Sample;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
use Illuminate\Validation\Rules\Unique;
|
||||
|
||||
|
||||
|
||||
class SampleCreateRequest extends FormRequest
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
* Determine if the user is authorized to make this request.
|
||||
|
||||
*
|
||||
|
||||
* @return bool
|
||||
|
||||
*/
|
||||
|
||||
public function authorize()
|
||||
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Get the validation rules that apply to the request.
|
||||
|
||||
*
|
||||
|
||||
* @return array
|
||||
|
||||
*/
|
||||
|
||||
public function rules()
|
||||
|
||||
{
|
||||
|
||||
return [
|
||||
|
||||
'patient_id' => 'required|integer|min:1',
|
||||
|
||||
/*'sample_number' => [
|
||||
|
||||
'required',
|
||||
|
||||
Rule::unique(Sample::getTableNameByConnection(), 'sample_number')
|
||||
|
||||
],*/
|
||||
|
||||
'physician_id' => 'required|integer',
|
||||
'sample_source_id' => 'required|integer',
|
||||
'sample_condition' => 'nullable',
|
||||
|
||||
'reject_comment_id' => 'nullable',
|
||||
|
||||
'collected_date' => 'required|date',
|
||||
|
||||
'received_date' => 'required|date',
|
||||
|
||||
'admission_date' => 'required|date',
|
||||
|
||||
'diagnosis' => 'nullable',
|
||||
|
||||
'is_urgent' => 'required|integer'
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function messages()
|
||||
|
||||
{
|
||||
|
||||
return [
|
||||
|
||||
//'reject_comment_id.required_if' => 'Reject reason is required.'
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
33
app/Http/Requests/SampleDetailCreateRequest.php
Normal file
33
app/Http/Requests/SampleDetailCreateRequest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SampleDetailCreateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'sample_id' => 'required|integer|min:1',
|
||||
'sample_tests' => 'required|array',
|
||||
'sample_details' => 'required|array'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
41
app/Http/Requests/TestSampleCreateRequest.php
Normal file
41
app/Http/Requests/TestSampleCreateRequest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TestSampleCreateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'test_id' => 'required|integer|min:1',
|
||||
'sample_type_id' => 'required|integer|min:1',
|
||||
'group_result' => 'nullable|string',
|
||||
'unit_sign' => 'nullable|string',
|
||||
'heading_id' => 'nullable',
|
||||
'usd_price' => 'nullable',
|
||||
'code' => 'nullable',
|
||||
'wight' => 'nullable',
|
||||
'filed_type_id' => 'required|integer|min:0',
|
||||
//'patient_type_ids' => 'required_if:filed_type_id,1',
|
||||
//'organisms' => 'required_if:filed_type_id,2,3'
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
91
app/Http/Requests/UpdateRequests/SampleUpdateRequest.php
Normal file
91
app/Http/Requests/UpdateRequests/SampleUpdateRequest.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
namespace App\Http\Requests\UpdateRequests;
|
||||
|
||||
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
|
||||
class SampleUpdateRequest extends FormRequest
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
* Determine if the user is authorized to make this request.
|
||||
|
||||
*
|
||||
|
||||
* @return bool
|
||||
|
||||
*/
|
||||
|
||||
public function authorize()
|
||||
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Get the validation rules that apply to the request.
|
||||
|
||||
*
|
||||
|
||||
* @return array
|
||||
|
||||
*/
|
||||
|
||||
public function rules()
|
||||
|
||||
{
|
||||
|
||||
return [
|
||||
|
||||
'physician_id' => 'required|integer',
|
||||
'sample_source_id' => 'required|integer',
|
||||
|
||||
//'sample_condition' => 'nullable',
|
||||
|
||||
//'reject_comment_id' => 'nullable',
|
||||
|
||||
'collected_date' => 'required|date',
|
||||
|
||||
'received_date' => 'required|date',
|
||||
|
||||
'admission_date' => 'required|date',
|
||||
|
||||
//'diagnosis' => 'nullable',
|
||||
|
||||
//'is_urgent' => 'accepted'
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function messages()
|
||||
|
||||
{
|
||||
|
||||
return [
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
39
app/Http/Requests/UpdateRequests/TestSampleUpdateRequest.php
Normal file
39
app/Http/Requests/UpdateRequests/TestSampleUpdateRequest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\UpdateRequests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TestSampleUpdateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'uid' => 'required',
|
||||
'test_id' => 'required|integer|min:1',
|
||||
'sample_type_id' => 'required|integer|min:1',
|
||||
'group_result' => 'nullable|string',
|
||||
'heading_id' => 'nullable',
|
||||
'unit_sign' => 'nullable|string',
|
||||
'usd_price' => 'nullable',
|
||||
'wight' => 'nullable',
|
||||
'filed_type_id' => 'required|integer|min:0',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
26
app/Http/Resources/AntibioticResource.php
Normal file
26
app/Http/Resources/AntibioticResource.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AntibioticResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name_en' => $this->name_en,
|
||||
'weight' => $this->weight,
|
||||
'lab_id' => $this->lab_id,
|
||||
// 'lab' => LaboratoryResource::collection($this->lab),
|
||||
'record_status_id' => $this->record_status_id
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Http/Resources/HeadingItemResource.php
Normal file
27
app/Http/Resources/HeadingItemResource.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class HeadingItemResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'sample_id' => $this->id,
|
||||
'sample_type_id' => $this->sample_type_id,
|
||||
'group_result' => $this->group_result,
|
||||
'id' => $this->test_id,
|
||||
'name_en' => $this->whenLoaded('test', function (){
|
||||
return $this->test->name_en;
|
||||
})
|
||||
];
|
||||
}
|
||||
}
|
||||
24
app/Http/Resources/LaboratoryResource.php
Normal file
24
app/Http/Resources/LaboratoryResource.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class LaboratoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name_en' => $this->name_en,
|
||||
'name_kh' => $this->name_kh,
|
||||
'record_status_id' => $this->record_status_id
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Http/Resources/OrganismResource.php
Normal file
19
app/Http/Resources/OrganismResource.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OrganismResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
19
app/Http/Resources/PatientSampleResource.php
Normal file
19
app/Http/Resources/PatientSampleResource.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PatientSampleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
43
app/Http/Resources/SampleResource.php
Normal file
43
app/Http/Resources/SampleResource.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SampleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'sample_number' => $this->sample_number,
|
||||
'patient' => $this->whenLoaded('patient', function (){
|
||||
return [
|
||||
'id' => $this->patient->id,
|
||||
'uuid' => $this->patient->patient_uuid,
|
||||
'name' => $this->patient->name_en
|
||||
];
|
||||
}),
|
||||
'sample_source' => $this->whenLoaded('sample_source',function (){
|
||||
return [
|
||||
'id' => $this->sample_source->id,
|
||||
'name' => $this->sample_source->name_en
|
||||
];
|
||||
}),
|
||||
'physician' => $this->whenLoaded('physician',function (){
|
||||
return [
|
||||
'id' => $this->physician->id,
|
||||
'name' => $this->physician->name_en
|
||||
];
|
||||
}),
|
||||
'sample_details' => $this->whenLoaded('sample_details'),
|
||||
'sample_tests' => $this->whenLoaded('sample_tests')
|
||||
];
|
||||
}
|
||||
}
|
||||
23
app/Http/Resources/SampleTestResource.php
Normal file
23
app/Http/Resources/SampleTestResource.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SampleTestResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'department_id' => $this->id,
|
||||
'department_name' => $this->name_en,
|
||||
'samples' => SampleTypeResource::collection($this->whenLoaded('samples')),
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Resources/SampleTypeResource.php
Normal file
31
app/Http/Resources/SampleTypeResource.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SampleTypeResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
$data = TestResource::collection($this->whenLoaded('testSamples'));
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'department_id' => $this->department_id,
|
||||
'name_en' => $this->name_en,
|
||||
'tube' => (string)$this->tube,
|
||||
'descriptions' => json_decode($this->description),
|
||||
'bg_color' => $this->bg_color,
|
||||
'color' => $this->color,
|
||||
'testSamples' => TestResource::collection($this->whenLoaded('testSamples')),
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Resources/TestResource.php
Normal file
31
app/Http/Resources/TestResource.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TestResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => (string) $this->id,
|
||||
'group_result' => $this->group_result,
|
||||
'closed_parent_id' => (string) ($this->heading_id > 0 ? $this->heading_id : 0),
|
||||
'code' => $this->code,
|
||||
'test_name' => $this->whenLoaded('test', function (){
|
||||
return $this->test->name_en;
|
||||
}),
|
||||
'children' => null,
|
||||
'price' => (string)$this->usd_price,
|
||||
'test_heading' => $this->field_type== 0 ? 'test-heading' : ''
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
59
app/Http/Resources/TestSampleResource.php
Normal file
59
app/Http/Resources/TestSampleResource.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TestSampleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'sample_type' => new SampleTypeResource($this->whenLoaded('sample')),
|
||||
'selected_organisms' => $this->whenLoaded('organisms', function() {
|
||||
return $this->organisms->map(function ($item){
|
||||
return array(
|
||||
'id' => $item->id,
|
||||
'is_default' => $item->is_default,
|
||||
'organism_id' => $item->organism_id,
|
||||
'test_sample_id' => $item->test_sample_id,
|
||||
'organism' => $item->organism,
|
||||
);
|
||||
});
|
||||
}),
|
||||
'test_values' => $this->whenLoaded('testValues', function (){
|
||||
return $this->testValues->map(function ($item){
|
||||
return array(
|
||||
'id' => $item->id,
|
||||
'patient_type_id' => $item->patient_type_id,
|
||||
'sign' => $item->sign,
|
||||
'maximum' => $item->maximum,
|
||||
'minimum' => $item->minimum
|
||||
);
|
||||
});
|
||||
}),
|
||||
'test_id' => $this->test_id,
|
||||
'heading_id' => $this->heading_id,
|
||||
'usd_price' => $this->usd_price,
|
||||
'group_result' => $this->group_result,
|
||||
'category' => $this->category,
|
||||
'unit_sign' => $this->unit_sign,
|
||||
'weight' => $this->weight,
|
||||
'field_type' => $this->field_type,
|
||||
'format' => $this->format,
|
||||
'formula' => $this->formula,
|
||||
'description' => $this->description,
|
||||
'lab_id' => $this->lab_id,
|
||||
'code' => $this->code,
|
||||
'is_bold' => (int) $this->is_bold,
|
||||
'autocomplete_bind' => (int) $this->autocomplete_bind
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Resources/UserResource.php
Normal file
31
app/Http/Resources/UserResource.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
try{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'is_manager' => $this->is_manager,
|
||||
'role_id' => $this->role_id
|
||||
];
|
||||
}
|
||||
catch(\Exception $e){
|
||||
return [];
|
||||
//dd($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
app/Listeners/LogUserLogin.php
Normal file
32
app/Listeners/LogUserLogin.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class LogUserLogin
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(object $event): void
|
||||
{
|
||||
activity()
|
||||
->causedBy($event->user)
|
||||
->withProperties([
|
||||
'ip' => request()->ip(),
|
||||
'browser' => request()->userAgent(),
|
||||
'url' => request()->fullUrl()
|
||||
])
|
||||
->log('User Login');
|
||||
}
|
||||
}
|
||||
31
app/Listeners/LogUserLogout.php
Normal file
31
app/Listeners/LogUserLogout.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
|
||||
class LogUserLogout
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(object $event): void
|
||||
{
|
||||
activity()
|
||||
->causedBy($event->user)
|
||||
->withProperties([
|
||||
'ip' => request()->ip(),
|
||||
'browser' => request()->userAgent()
|
||||
])
|
||||
->log('User Logout');
|
||||
}
|
||||
}
|
||||
29
app/Models/Antibiotic.php
Normal file
29
app/Models/Antibiotic.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use App\Traits\AuditLogTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Antibiotic extends BaseModel
|
||||
{
|
||||
public $timestamps = false;
|
||||
use HasFactory, AuditLogTrait;
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fillable = ['name_en','weight', 'lab_id'];
|
||||
|
||||
protected $hidden = ['created_at', 'created_by', 'updated_at', 'updated_by', 'record_status_id'];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
public function lab(){
|
||||
return $this->belongsTo('App\Models\Laboratory', 'lab_id','id');
|
||||
}
|
||||
|
||||
}
|
||||
25
app/Models/AntibioticResult.php
Normal file
25
app/Models/AntibioticResult.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use App\Traits\AuditLogTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class AntibioticResult extends BaseModel
|
||||
{
|
||||
protected $table = "antibiogram_results";
|
||||
public $timestamps = false;
|
||||
use HasFactory, AuditLogTrait;
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $fillable = ['organism_result_id','antibiotic_id','disk_diffusion','mic','sensitive','is_hide','created_at','created_by','updated_at','updated_by','record_status_id'];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user