Merge remote-tracking branch 'origin/staging' into origin/production
This commit is contained in:
@@ -24,9 +24,24 @@ class MemberBuilder extends Builder
|
||||
|
||||
public function joinCorporateEmployees(string $value = 'join'): static
|
||||
{
|
||||
// return match ($value) {
|
||||
// 'join' => $this->join('corporate_employees', 'members.id', '=', 'corporate_employees.member_id'),
|
||||
// 'left' => $this->leftJoin('corporate_employees', 'members.id', '=', 'corporate_employees.member_id')
|
||||
// };
|
||||
|
||||
return match ($value) {
|
||||
'join' => $this->join('corporate_employees', 'members.id', '=', 'corporate_employees.member_id'),
|
||||
'left' => $this->leftJoin('corporate_employees', 'members.id', '=', 'corporate_employees.member_id')
|
||||
'join' => $this->join('corporate_employees', function ($join) {
|
||||
$join->on('members.id', '=', 'corporate_employees.member_id')
|
||||
->orWhere('members.principal_id', '=', 'corporate_employees.member_id');
|
||||
}),
|
||||
'left' => $this->leftJoin('corporate_employees', function ($join) {
|
||||
$join->on('members.id', '=', 'corporate_employees.member_id')
|
||||
->orWhere('members.principal_id', '=', 'corporate_employees.member_id');
|
||||
}),
|
||||
'right' => $this->rightJoin('corporate_employees', function ($join) {
|
||||
$join->on('members.id', '=', 'corporate_employees.member_id')
|
||||
->orWhere('members.principal_id', '=', 'corporate_employees.member_id');
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -40,11 +55,31 @@ class MemberBuilder extends Builder
|
||||
|
||||
public function joinClaimRequests(string $value = 'join'): static
|
||||
{
|
||||
// return match ($value) {
|
||||
// 'join' => $this->join('claim_requests', 'members.id', '=', 'claim_requests.member_id'),
|
||||
// 'left' => $this->leftJoin('claim_requests', 'members.id', '=', 'claim_requests.member_id'),
|
||||
// // 'right' => $this->rightJoin('claim_requests', 'members.id', '=', 'claim_requests.member_id')
|
||||
// 'right' => $this->rightJoin('claim_requests', function ($join) {
|
||||
// $join->on('members.id', '=', 'claim_requests.member_id')
|
||||
// ->orWhere('members.principal_id', '=', 'claim_requests.member_id');
|
||||
// })
|
||||
// };
|
||||
|
||||
return match ($value) {
|
||||
'join' => $this->join('claim_requests', 'members.id', '=', 'claim_requests.member_id'),
|
||||
'left' => $this->leftJoin('claim_requests', 'members.id', '=', 'claim_requests.member_id'),
|
||||
'right' => $this->rightJoin('claim_requests', 'members.id', '=', 'claim_requests.member_id')
|
||||
'join' => $this->join('claim_requests', function ($join) {
|
||||
$join->on('members.id', '=', 'claim_requests.member_id')
|
||||
->orWhere('members.principal_id', '=', 'claim_requests.member_id');
|
||||
}),
|
||||
'left' => $this->leftJoin('claim_requests', function ($join) {
|
||||
$join->on('members.id', '=', 'claim_requests.member_id')
|
||||
->orWhere('members.principal_id', '=', 'claim_requests.member_id');
|
||||
}),
|
||||
'right' => $this->rightJoin('claim_requests', function ($join) {
|
||||
$join->on('members.id', '=', 'claim_requests.member_id')
|
||||
->orWhere('members.principal_id', '=', 'claim_requests.member_id');
|
||||
})
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public function joinMemberPlans(string $value = 'join'): static
|
||||
|
||||
@@ -6,24 +6,41 @@ use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Member;
|
||||
use App\Models\Service;
|
||||
|
||||
class Helper
|
||||
{
|
||||
public static function genderNormalization($anyGenderCode)
|
||||
{
|
||||
if ($anyGenderCode == 'M') {
|
||||
return 'male';
|
||||
return 'Male';
|
||||
} else if ($anyGenderCode == 'F') {
|
||||
return 'female';
|
||||
return 'Female';
|
||||
} else if ($anyGenderCode == 'O') {
|
||||
return 'others';
|
||||
return 'Others';
|
||||
} else if ($anyGenderCode == 'U') {
|
||||
return 'unknown';
|
||||
return 'Unknown';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function maritalNormalization($code)
|
||||
{
|
||||
if ($code == 'M') {
|
||||
return 'Married';
|
||||
} else if ($code == 'D') {
|
||||
return 'Divorced';
|
||||
} else if ($code == 'S') {
|
||||
return 'Single';
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
|
||||
public static function genderPerson($anyGenderCode)
|
||||
{
|
||||
if ($anyGenderCode == 'M') {
|
||||
@@ -39,6 +56,44 @@ class Helper
|
||||
}
|
||||
}
|
||||
|
||||
public static function memberType($code){
|
||||
if ($code == 'P') {
|
||||
return 'Principal';
|
||||
} else if ($code == 'D') {
|
||||
return 'Dependent';
|
||||
} else {
|
||||
'-';
|
||||
}
|
||||
}
|
||||
|
||||
public static function relationWithPrincipal($code){
|
||||
if ($code == 'H') {
|
||||
return 'Husbund';
|
||||
}
|
||||
else if ($code == 'W') {
|
||||
return 'Wife';
|
||||
}
|
||||
else if ($code == 'S') {
|
||||
return 'Son';
|
||||
}
|
||||
else if ($code == 'D') {
|
||||
return 'Daughter';
|
||||
}
|
||||
else {
|
||||
'-';
|
||||
}
|
||||
}
|
||||
|
||||
public static function principalName($code){
|
||||
$principalName = Member::where('member_id', $code)->get()->first();
|
||||
return $principalName->name;
|
||||
}
|
||||
|
||||
public static function serviceName($code){
|
||||
$serviceName = Service::where('code', $code)->get()->first();
|
||||
return $serviceName->name;
|
||||
}
|
||||
|
||||
public static function paginateResources($resource)
|
||||
{
|
||||
return [
|
||||
@@ -216,5 +271,80 @@ class Helper
|
||||
return $sPaymentMethod[$id];
|
||||
}
|
||||
|
||||
public static function formatDateDB($date){
|
||||
$convertedDate = Carbon::createFromFormat('d-m-Y', $date)->format('Y-m-d H:i:s');
|
||||
return $convertedDate;
|
||||
}
|
||||
|
||||
|
||||
public static function formatDateOnly($date){
|
||||
// Membuat objek Carbon dengan tanggal asli dan zona waktu UTC
|
||||
$carbonDate = Carbon::createFromFormat('Y-m-d\TH:i:s.u\Z', $date, 'UTC');
|
||||
|
||||
// Mengonversi tanggal ke zona waktu yang diinginkan
|
||||
$carbonDate->setTimezone('Asia/Jakarta');
|
||||
|
||||
$convertedDate = $carbonDate->toDateString();
|
||||
return $convertedDate;
|
||||
}
|
||||
|
||||
public static function formatTimeOnly($date){
|
||||
// Membuat objek Carbon dengan tanggal asli dan zona waktu UTC
|
||||
$carbonDate = Carbon::createFromFormat('Y-m-d\TH:i:s.u\Z', $date, 'UTC');
|
||||
|
||||
// Mengonversi tanggal ke zona waktu yang diinginkan
|
||||
$carbonDate->setTimezone('Asia/Jakarta');
|
||||
|
||||
$convertedDate = $carbonDate->toTimeString();
|
||||
return $convertedDate;
|
||||
}
|
||||
|
||||
public static function insertNotification($data = array())
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
DB::table('notifications')->insert($data);
|
||||
DB::commit();
|
||||
return true;
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static function sendEmail($data = array())
|
||||
{
|
||||
// Buat instance PHPMailer
|
||||
$mail = new PHPMailer(true);
|
||||
|
||||
try {
|
||||
// Server settings
|
||||
$mail->isSMTP();
|
||||
$mail->Host = 'smtp.gmail.com';
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = env('EMAIL');
|
||||
$mail->Password = env('PW_EMAIL');
|
||||
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
$mail->Port = 465;
|
||||
$mail->SMTPSecure = "ssl";
|
||||
|
||||
// Penerima email
|
||||
$mail->setFrom(env('EMAIL'), env('NAME_EMAIL'));
|
||||
$mail->addAddress($data['email'], $data['name']);
|
||||
|
||||
// Konten email
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $data['subject'];
|
||||
$mail->Body = $data['body'];
|
||||
|
||||
// Kirim email
|
||||
$mail->send();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
//var_dump($mail->ErrorInfo);die();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
namespace App\Http\Resources\OLDLMS;
|
||||
|
||||
use App\Services\ClaimService;
|
||||
use App\Models\Corporate;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
|
||||
class MemberResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
@@ -21,28 +23,17 @@ class MemberResource extends JsonResource
|
||||
$limitTelecon = $this->totalUsage >= 6 ? null : $limitTelecon;
|
||||
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'member_name' => $this->full_name,
|
||||
'member_id' => $this->member_id,
|
||||
'birth_date' => $this->birth_date,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->person->phone ?? null,
|
||||
'full_name' => $this->full_name,
|
||||
'nric' => $this->nric,
|
||||
'plan' => $currentMemberPlan ? [
|
||||
'code' => $currentMemberPlan->plan->code ?? null,
|
||||
'start' => $currentMemberPlan->start,
|
||||
'end' => $currentMemberPlan->end,
|
||||
'limit' => $this->currentPlan->limit_rules,
|
||||
'limit_consultation' => 6
|
||||
] : null,
|
||||
'policy_code' => $this->currentPolicy?->code ?? null,
|
||||
'corporate' => [
|
||||
'code' => $this->currentPolicy?->corporate->code ?? null,
|
||||
'name' => $this->currentPolicy?->corporate->name,
|
||||
'welcome_message' => $this->currentPolicy?->corporate->welcome_message,
|
||||
'help_text' => $this->currentPolicy?->corporate?->help_text,
|
||||
'avatar_url' => $this->currentpolicy?->corporate?->avatar_url
|
||||
],
|
||||
'limit_usage' => $this->totalUsage ?? null
|
||||
'policy_holder' => $this->currentPolicy->corporate->name,
|
||||
'policy_number' => $this->currentPolicy->code ?? null,
|
||||
'date_of_birth' => $this->birth_date,
|
||||
'gender' => $this->gender,
|
||||
'start_date' => $this->members_effective_date,
|
||||
'corporate_logo' => $_ENV['LMS_APP_STORAGE'] . $this->corporateLogo,
|
||||
'valid_until' => $this->members_expire_date,
|
||||
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -29,11 +29,19 @@ class Claim extends Model
|
||||
'currency',
|
||||
'plan_id',
|
||||
'benefit_id',
|
||||
'organization_id',
|
||||
'status',
|
||||
'service_code',
|
||||
'benefit_code',
|
||||
'benefit_desc',
|
||||
'amount_incurred',
|
||||
'amount_approved',
|
||||
'amount_not_approved',
|
||||
'excess_paid',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
// 'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
@@ -195,6 +203,11 @@ class Claim extends Model
|
||||
return $this->belongsTo(Member::class, 'member_id');
|
||||
}
|
||||
|
||||
public function organization()
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function encounters()
|
||||
{
|
||||
return $this->belongsToMany(Encounter::class, 'claim_encounter');
|
||||
@@ -251,5 +264,11 @@ class Claim extends Model
|
||||
{
|
||||
return $this->items->sum('nominal_ditagihkan');
|
||||
}
|
||||
|
||||
public function historyHospitalCare()
|
||||
{
|
||||
return $this->hasMany(ClaimHistoryCare::class, 'claim_id');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
12
app/Models/ClaimEncounter.php
Normal file
12
app/Models/ClaimEncounter.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClaimEncounter extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'claim_encounter';
|
||||
}
|
||||
60
app/Models/ClaimHistoryCare.php
Normal file
60
app/Models/ClaimHistoryCare.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClaimHistoryCare extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'service_code',
|
||||
'admission_date',
|
||||
'discharge_date',
|
||||
'claim_id',
|
||||
'organization_id',
|
||||
'practitioner_id',
|
||||
'medical_record_number',
|
||||
'symptoms',
|
||||
'sign',
|
||||
'main_diagnosis_id',
|
||||
'status'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
public function organization()
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function practitioner()
|
||||
{
|
||||
return $this->belongsTo(Practitioner::class, 'practitioner_id');
|
||||
}
|
||||
|
||||
public function icd()
|
||||
{
|
||||
return $this->belongsTo(Icd::class, 'main_diagnosis_id');
|
||||
}
|
||||
|
||||
public function claim()
|
||||
{
|
||||
return $this->hasOne(Claim::class, 'claim_id');
|
||||
}
|
||||
|
||||
public function person()
|
||||
{
|
||||
return $this->belongsTo(Person::class, 'practitioner_id');
|
||||
}
|
||||
|
||||
public function comparativeDiagnosis()
|
||||
{
|
||||
return $this->hasMany(DiagnosisSecondaryClaimHistoryCare::class, 'claim_history_care_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,11 @@ class ClaimItem extends Model
|
||||
return $this->belongsTo(Claim::class, 'claim_id');
|
||||
}
|
||||
|
||||
public function benefit()
|
||||
{
|
||||
return $this->belongsTo(Benefit::class, 'claim_itemable_id');
|
||||
}
|
||||
|
||||
public function claim_itemable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
|
||||
@@ -14,7 +14,8 @@ class ClaimRequest extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, Blameable;
|
||||
|
||||
protected static $code_prefix = 'CRQ';
|
||||
// protected static $code_prefix_hospital = 'CRQ-H';
|
||||
// protected static $code_prefix_client = 'CRQ-R';
|
||||
|
||||
public $fillable = [
|
||||
'uuid',
|
||||
@@ -24,7 +25,10 @@ class ClaimRequest extends Model
|
||||
'service_code',
|
||||
'policy_id',
|
||||
'status',
|
||||
'claim_id'
|
||||
'claim_id',
|
||||
'organization_id',
|
||||
'code',
|
||||
'request_log_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -36,6 +40,73 @@ class ClaimRequest extends Model
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public static $doc_headers_to_field_map = [
|
||||
"PAYOR ID" => "payor_id",
|
||||
"CORPORATE ID" => "corporate_id",
|
||||
"POLICY NUMBER" => "policy_number",
|
||||
"MEMBER ID" => "member_id",
|
||||
"MEMBER NAME" => "member_name",
|
||||
"RECORD TYPE (P/D)" => "record_type",
|
||||
"BENEFIT CODE" => "benefit_code",
|
||||
"BENEFIT DESC" => "benefit_desc",
|
||||
"CLAIM TYPE" => "claim_type",
|
||||
"CLAIM PROCESS STATUS" => "status",
|
||||
"CLIENT CLAIM ID" => "client_claim_id",
|
||||
"REFERENCE NO" => "reference_no",
|
||||
"ADMEDIKA CLAIM ID" => "admika_claim_id",
|
||||
"PROVIDER CODE" => "provider_code",
|
||||
"ADMISSION DATE" => "admission_date",
|
||||
"DISCUTRGE DATE" => "discutrge_date",
|
||||
"DURATION DAYS" => "duration_days",
|
||||
"COVERAGE TYPE" => "coverage_type",
|
||||
"PLAN ID" => "plan_id",
|
||||
"DIAGNOSIS CODE" => "diagnosis_code",
|
||||
"DIAGNOSIS DESC" => "diagnosis_desc",
|
||||
"TOT AMT INCURRED" => "tot_amt_insurred",
|
||||
"TOT AMT APPROVED" => "tot_amt_approved",
|
||||
"TOT AMT NOT APPROVED" => "tot_amt_not_approved",
|
||||
"TOT EXCESS PAID" => "tot_excess_paid",
|
||||
"REMARKS" => "remarks",
|
||||
"SECONDARY DIAGNOSIS CODE" => "secondary_diagnosis",
|
||||
"APPROVED DATE" => "approved_date",
|
||||
"APPROVED BY" => "approved_by",
|
||||
"DATE RECEIVED" => "data_received",
|
||||
"HOSPITAL INVOICE DATE" => "hospital_invoice_date",
|
||||
];
|
||||
|
||||
public static $listing_doc_headers = [
|
||||
"PAYOR ID",
|
||||
"CORPORATE ID",
|
||||
"POLICY NUMBER",
|
||||
"MEMBER ID",
|
||||
"MEMBER NAME",
|
||||
"RECORD TYPE (P/D)",
|
||||
"CLAIM TYPE",
|
||||
"CLAIM PROCESS STATUS",
|
||||
"CLIENT CLAIM ID",
|
||||
"REFERENCE NO",
|
||||
"ADMEDIKA CLAIM ID",
|
||||
"PROVIDER CODE",
|
||||
"ADMISSION DATE",
|
||||
"DISCUTRGE DATE",
|
||||
"DURATION DAYS",
|
||||
"COVERAGE TYPE",
|
||||
"PLAN ID",
|
||||
"DIAGNOSIS CODE",
|
||||
"DIAGNOSIS DESC",
|
||||
"TOT AMT INCURRED",
|
||||
"TOT AMT APPROVED",
|
||||
"TOT AMT NOT APPROVED",
|
||||
"TOT EXCESS PAID",
|
||||
"REMARKS",
|
||||
"SECONDARY DIAGNOSIS CODE",
|
||||
"APPROVED DATE",
|
||||
"APPROVED BY",
|
||||
"DATE RECEIVED",
|
||||
"HOSPITAL INVOICE DATE",
|
||||
];
|
||||
|
||||
|
||||
public static $status = [
|
||||
'draft' => 'Draft',
|
||||
'requested' => 'Requested',
|
||||
@@ -59,7 +130,7 @@ class ClaimRequest extends Model
|
||||
static::creating(function ($model) {
|
||||
try {
|
||||
$model->uuid = (string) Str::orderedUuid(); // generate uuid
|
||||
$model->code = self::getNextCode();
|
||||
// $model->code = self::getNextCode();
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
@@ -112,19 +183,19 @@ class ClaimRequest extends Model
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static function getNextCode()
|
||||
{
|
||||
$last_number = self::withTrashed()->max('code');
|
||||
$next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[1] + 1);
|
||||
|
||||
return self::makeCode($next_number);
|
||||
}
|
||||
// public static function getNextCode()
|
||||
// {
|
||||
// $last_number = self::withTrashed()->max('code');
|
||||
// $next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[1] + 1);
|
||||
|
||||
public static function makeCode($next_number)
|
||||
{
|
||||
return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
|
||||
}
|
||||
// return self::makeCode($next_number);
|
||||
// }
|
||||
|
||||
// public static function makeCode($next_number)
|
||||
// {
|
||||
// return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
|
||||
// }
|
||||
|
||||
public function claim()
|
||||
{
|
||||
@@ -141,6 +212,21 @@ class ClaimRequest extends Model
|
||||
return $this->morphMany(File::class, 'fileable');
|
||||
}
|
||||
|
||||
public function claimResults()
|
||||
{
|
||||
return $this->files()->where('type', 'claim-result')->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
public function claimConditions()
|
||||
{
|
||||
return $this->files()->where('type', 'claim-kondisi')->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
public function claimDiagnosis()
|
||||
{
|
||||
return $this->files()->where('type', 'claim-diagnosis')->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
public function generatedDocuments()
|
||||
{
|
||||
return $this->morphMany(GeneratedDocument::class, 'generated_documentable');
|
||||
@@ -151,6 +237,11 @@ class ClaimRequest extends Model
|
||||
return $this->morphMany(ClaimHistory::class, 'historiable');
|
||||
}
|
||||
|
||||
public function organization()
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function member()
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Altek\Accountant\Contracts\Recordable;
|
||||
|
||||
class CorporateFormularium extends Model
|
||||
{
|
||||
@@ -15,7 +16,8 @@ class CorporateFormularium extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'corporate_id',
|
||||
'formularium_id'
|
||||
'formularium_template_id',
|
||||
'active'
|
||||
];
|
||||
|
||||
public function corporate()
|
||||
@@ -23,8 +25,8 @@ class CorporateFormularium extends Model
|
||||
return $this->belongsTo(Corporate::class);
|
||||
}
|
||||
|
||||
public function formularium()
|
||||
public function formularium_template()
|
||||
{
|
||||
return $this->belongsTo(Formularium::class);
|
||||
return $this->belongsTo(FormulariumTemplate::class);
|
||||
}
|
||||
}
|
||||
|
||||
36
app/Models/CorporateHospital.php
Normal file
36
app/Models/CorporateHospital.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CorporateHospital extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, Blameable;
|
||||
|
||||
protected $fillable = [
|
||||
'corporate_id',
|
||||
'organization_id',
|
||||
'code',
|
||||
'name',
|
||||
'description',
|
||||
'active',
|
||||
];
|
||||
|
||||
public function corporate()
|
||||
{
|
||||
return $this->belongsTo(Corporate::class);
|
||||
}
|
||||
|
||||
public function scopeFilter($query, array $filters)
|
||||
{
|
||||
$query->when($filters['search'] ?? false, function ($query, $search) {
|
||||
return $query
|
||||
->where('code', 'like', "%" . $search . "%")
|
||||
->orWhere('name', 'like', "%" . $search . "%");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,19 @@ class CorporateManager extends Model
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $table = 'corporate_manager';
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'corporate_id'
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
public function corporate()
|
||||
{
|
||||
return $this->hasOne(Corporate::class, 'id', 'corporate_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ class CorporatePlan extends Model
|
||||
'code',
|
||||
'name',
|
||||
'description',
|
||||
'corporate_plan_id',
|
||||
'service_code',
|
||||
'type',
|
||||
'limit_rules',
|
||||
'active',
|
||||
'reason'
|
||||
];
|
||||
|
||||
61
app/Models/DailyMonitoring.php
Normal file
61
app/Models/DailyMonitoring.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DailyMonitoring extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = "claim_daily_monitoring";
|
||||
|
||||
protected $fillable = [
|
||||
'claim_id',
|
||||
'subject',
|
||||
'body_temperature',
|
||||
'respiration_rate',
|
||||
'sistole',
|
||||
'diastole',
|
||||
'analysis',
|
||||
'complaints'
|
||||
];
|
||||
|
||||
protected $appends = ['medical_plan'];
|
||||
|
||||
public function getBodyTemperatureAttribute()
|
||||
{
|
||||
return round($this->attributes['body_temperature'], 0);
|
||||
}
|
||||
|
||||
public function getSistoleAttribute()
|
||||
{
|
||||
return round($this->attributes['sistole'], 0);
|
||||
}
|
||||
|
||||
public function getDiastoleAttribute()
|
||||
{
|
||||
return round($this->attributes['diastole'], 0);
|
||||
}
|
||||
|
||||
public function getRespirationRateAttribute()
|
||||
{
|
||||
return round($this->attributes['respiration_rate'], 0);
|
||||
}
|
||||
|
||||
public function getMedicalPlanAttribute()
|
||||
{
|
||||
$arr_medical_plan = [];
|
||||
$medical_plan = DB::table('medical_plan')->where('claim_daily_monitoring_id','=',$this->attributes['id'])->get();
|
||||
|
||||
foreach ($medical_plan as $row) {
|
||||
$arr_medical_plan[] = [
|
||||
'medical_plan_str' => $row->plan
|
||||
];
|
||||
}
|
||||
|
||||
return $arr_medical_plan;
|
||||
}
|
||||
}
|
||||
28
app/Models/DiagnosisSecondaryClaimHistoryCare.php
Normal file
28
app/Models/DiagnosisSecondaryClaimHistoryCare.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DiagnosisSecondaryClaimHistoryCare extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'diagnosis_secondary_claim_history_care';
|
||||
|
||||
protected $fillable = [
|
||||
'claim_history_care_id',
|
||||
'icd_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
public function icd()
|
||||
{
|
||||
return $this->belongsTo(Icd::class, 'icd_id');
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,8 @@ class Drug extends Model
|
||||
'dosage',
|
||||
'remark',
|
||||
'selling_unit_id',
|
||||
'status'
|
||||
'status',
|
||||
'active',
|
||||
];
|
||||
|
||||
public function categories()
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Altek\Accountant\Contracts\Recordable;
|
||||
|
||||
class Exclusion extends Model
|
||||
{
|
||||
@@ -17,6 +18,8 @@ class Exclusion extends Model
|
||||
'type',
|
||||
'exclusionable_id',
|
||||
'exclusionable_type',
|
||||
'active',
|
||||
'reason'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
||||
24
app/Models/ExclusionImport.php
Normal file
24
app/Models/ExclusionImport.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Altek\Accountant\Contracts\Recordable;
|
||||
|
||||
class ExclusionImport extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'corporate_id',
|
||||
'file_name',
|
||||
'file_path',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Altek\Accountant\Contracts\Recordable;
|
||||
|
||||
class ExclusionRules extends Model
|
||||
{
|
||||
|
||||
@@ -19,6 +19,8 @@ class File extends Model
|
||||
'original_name',
|
||||
'extension',
|
||||
'path',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -43,6 +45,12 @@ class File extends Model
|
||||
'claim-result' => 'claim/',
|
||||
'claim-diagnosis' => 'claim/',
|
||||
'claim-kondisi' => 'claim/',
|
||||
'claim-invoice' => 'claim/',
|
||||
'final-log-result' => 'final-log/',
|
||||
'final-log-diagnosis' => 'final-log/',
|
||||
'final-log-kondisi' => 'final-log/',
|
||||
'docs' => 'docs/',
|
||||
'additional-files' => 'additional-files/',
|
||||
];
|
||||
|
||||
public function fileable()
|
||||
@@ -52,7 +60,7 @@ class File extends Model
|
||||
|
||||
public static function getDirectory($type)
|
||||
{
|
||||
return self::$file_directories[$type] ?? 'any';
|
||||
return self::$file_directories[$type] ?? 'any/';
|
||||
}
|
||||
|
||||
public static function getFileName($type, $id)
|
||||
|
||||
14
app/Models/FilesDoc.php
Normal file
14
app/Models/FilesDoc.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FilesDoc extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'files_doc';
|
||||
protected $primaryKey = 'id';
|
||||
protected $fillable = ['corporate_id', 'original_name', 'path','status_download', 'created_by','updated_by', 'created_at', 'updated_at'];
|
||||
}
|
||||
@@ -17,6 +17,19 @@ class Formularium extends Model
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'description',
|
||||
'manufacturer',
|
||||
'category_name',
|
||||
'kategori_obat',
|
||||
'uom',
|
||||
'general_indication',
|
||||
'composition',
|
||||
'atc_code',
|
||||
'class',
|
||||
'bpom_registration',
|
||||
'classifications',
|
||||
'cat_for',
|
||||
'formularium_template_id'
|
||||
];
|
||||
|
||||
public function setCodeAttribute($value)
|
||||
@@ -24,11 +37,6 @@ class Formularium extends Model
|
||||
$this->attributes['code'] = !empty($value) ? $value : Str::upper(Str::random('6'));
|
||||
}
|
||||
|
||||
public function corporateFormulariums()
|
||||
{
|
||||
return $this->hasMany(CorporateFormularium::class);
|
||||
}
|
||||
|
||||
public function items()
|
||||
{
|
||||
return $this->belongsToMany(Drug::class, 'formularium_items', 'formularium_id', 'item_id');
|
||||
|
||||
32
app/Models/FormulariumTemplate.php
Normal file
32
app/Models/FormulariumTemplate.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Altek\Accountant\Contracts\Recordable;
|
||||
|
||||
class FormulariumTemplate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'active',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
// 'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
// 'deleted_by',
|
||||
];
|
||||
|
||||
// public function corporateFormulariums()
|
||||
// {
|
||||
// return $this->hasMany(CorporateFormularium::class, 'formularium_template_id', 'id');
|
||||
// }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Altek\Accountant\Contracts\Recordable;
|
||||
|
||||
class Icd extends Model
|
||||
{
|
||||
@@ -20,11 +21,13 @@ class Icd extends Model
|
||||
'name',
|
||||
'description',
|
||||
'parent_code',
|
||||
'active',
|
||||
'icd_template_id'
|
||||
];
|
||||
|
||||
public $appends = [
|
||||
'type',
|
||||
'active'
|
||||
// 'active'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -41,10 +44,10 @@ class Icd extends Model
|
||||
return 'ICD-'.$this->rev;
|
||||
}
|
||||
|
||||
public function getActiveAttribute()
|
||||
{
|
||||
return empty($this->deleted_at);
|
||||
}
|
||||
// public function getActiveAttribute()
|
||||
// {
|
||||
// return empty($this->deleted_at);
|
||||
// }
|
||||
|
||||
public function subCategories()
|
||||
{
|
||||
@@ -71,4 +74,14 @@ class Icd extends Model
|
||||
});
|
||||
}
|
||||
|
||||
public function claim_history_care()
|
||||
{
|
||||
return $this->hasMany(CliamHistoryCare::class, 'main_diagnosis_id', 'id');
|
||||
}
|
||||
|
||||
public function diagnosis_secondary_claim_history_care()
|
||||
{
|
||||
return $this->hasMany(DiagnosisSecondaryCliamHistoryCare::class, 'icd_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
32
app/Models/IcdTemplate.php
Normal file
32
app/Models/IcdTemplate.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
// use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Altek\Accountant\Contracts\Recordable;
|
||||
|
||||
class IcdTemplate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'icd_template';
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'description',
|
||||
'active'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
// 'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
// 'deleted_by',
|
||||
];
|
||||
}
|
||||
39
app/Models/LaboratoriumResult.php
Normal file
39
app/Models/LaboratoriumResult.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LaboratoriumResult extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = "laboratorium_result";
|
||||
protected $fillable = [
|
||||
'claim_id',
|
||||
'date',
|
||||
'location',
|
||||
'examination',
|
||||
];
|
||||
|
||||
protected $appends = ['lab_result_file'];
|
||||
protected $path_for_public = 'storage/lab_result';
|
||||
|
||||
public function getLabResultFileAttribute()
|
||||
{
|
||||
$arr_files = [];
|
||||
$files = DB::table('files')->select('name','original_name','path','extension')->where("type","=","laboratorium-result")->where('fileable_id','=',$this->attributes['id'])->get();
|
||||
|
||||
foreach ($files as $row) {
|
||||
$row->path = url($this->path_for_public . "/" . $row->original_name);
|
||||
|
||||
$arr_files[] = [
|
||||
'lab_result_file_obj' => $row
|
||||
];
|
||||
}
|
||||
|
||||
return $arr_files;
|
||||
}
|
||||
}
|
||||
18
app/Models/MedicalPlan.php
Normal file
18
app/Models/MedicalPlan.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MedicalPlan extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = "medical_plan";
|
||||
|
||||
protected $fillable = [
|
||||
'claim_daily_monitoring_id',
|
||||
'plan'
|
||||
];
|
||||
}
|
||||
@@ -63,6 +63,7 @@ class Member extends Model
|
||||
"policy_in_force",
|
||||
"start_no_claim",
|
||||
"end_no_claim",
|
||||
"suspended"
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
@@ -98,6 +99,12 @@ class Member extends Model
|
||||
return $this->hasMany(Claim::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
public function claimRequest()
|
||||
{
|
||||
return $this->hasMany(ClaimRequest::class, 'member_id', 'id')->where('claim_id', '!=', null);
|
||||
}
|
||||
|
||||
|
||||
public function postponedClaims()
|
||||
{
|
||||
return $this->hasMany(Claim::class, 'member_id', 'id')->where('status', 'postpone');
|
||||
@@ -142,12 +149,35 @@ class Member extends Model
|
||||
return $this->hasManyThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id');
|
||||
}
|
||||
|
||||
public function currentPlans()
|
||||
{
|
||||
return $this->hasManyThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id');
|
||||
// ->latest(); // TODO Fix This
|
||||
}
|
||||
|
||||
public function currentPlan()
|
||||
{
|
||||
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id')
|
||||
->latest(); // TODO Fix This
|
||||
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id', )
|
||||
->latest();
|
||||
// ->where('plans.service_code', $this->claimRequest->service_code); // TODO Fix This
|
||||
}
|
||||
|
||||
// public function currentPlan()
|
||||
// {
|
||||
// return $this->hasOneThrough(
|
||||
// Plan::class,
|
||||
// MemberPlan::class,
|
||||
// 'member_id',
|
||||
// 'id',
|
||||
// 'id',
|
||||
// 'plan_id'
|
||||
// )
|
||||
// ->join('claim_requests', 'claim_requests.service_code', '=', 'plans.service_code')
|
||||
// ->latest('claim_requests.created_at') // Atau sesuaikan dengan kolom timestamp yang sesuai
|
||||
// ->select('plans.*');
|
||||
// }
|
||||
|
||||
|
||||
public function currentEmployeds()
|
||||
{
|
||||
return $this->hasOneThrough(CorporateEmployee::class, Person::class, 'nik', 'id', 'id', 'nik')
|
||||
@@ -240,5 +270,20 @@ class Member extends Model
|
||||
get: fn () => $this->person->gender ?? null
|
||||
);
|
||||
}
|
||||
|
||||
protected function corporateLogo(): Attribute
|
||||
{
|
||||
$avatar = File::where(['type' => 'avatar', 'fileable_id' => $this->currentPolicy->corporate->id])->orderBy('id', 'desc')->get()->first();
|
||||
if ($avatar){
|
||||
$path = $_ENV['LMS_APP_STORAGE'] . $avatar->path ? $avatar->path :'';
|
||||
return Attribute::make(
|
||||
get: fn () => $avatar ? $path : null
|
||||
);
|
||||
} else {
|
||||
return Attribute::make(
|
||||
get: fn () => null
|
||||
);
|
||||
}
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
}
|
||||
|
||||
18
app/Models/OLDLMS/PersonalAccessToken.php
Normal file
18
app/Models/OLDLMS/PersonalAccessToken.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\OLDLMS;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laravel\Sanctum\PersonalAccessToken as SanctumPersonalAccessToken;
|
||||
|
||||
|
||||
class PersonalAccessToken extends SanctumPersonalAccessToken
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'personal_access_tokens';
|
||||
protected $connection = 'oldlms';
|
||||
|
||||
|
||||
}
|
||||
@@ -2,14 +2,20 @@
|
||||
|
||||
namespace App\Models\OLDLMS;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Model
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable, Notifiable;
|
||||
|
||||
const CREATED_AT = 'dCreateOn';
|
||||
const UPDATED_AT = 'dUpdateOn';
|
||||
@@ -55,9 +61,14 @@ class User extends Model
|
||||
{
|
||||
return $this->hasOne(UserDetail::class, 'nIDUser', 'nID');
|
||||
}
|
||||
|
||||
|
||||
public function insurances()
|
||||
{
|
||||
return $this->hasMany(UserInsurance::class, 'nIDUser', 'nID');
|
||||
}
|
||||
|
||||
public function notificationTokens()
|
||||
{
|
||||
return $this->morphMany(NotificationToken::class, 'notifiabletoken');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ class UserDetail extends Model
|
||||
'nIDJenisKelamin',
|
||||
'sCreateBy',
|
||||
'sKTP',
|
||||
'sImages',
|
||||
'sWeight',
|
||||
'sHeight',
|
||||
'nIDGolonganDarah',
|
||||
|
||||
];
|
||||
|
||||
|
||||
@@ -26,5 +26,7 @@ class UserInsurance extends Model
|
||||
'dTanggalLahir',
|
||||
'nNoKTP',
|
||||
'sNoPolis',
|
||||
'nIDInsurance',
|
||||
'sLayanan',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -98,4 +98,17 @@ class Organization extends Model
|
||||
{
|
||||
return $this->hasMany(PractitionerRole::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function claims()
|
||||
{
|
||||
return $this->hasMany(Claim::class, 'organization_id', 'id');
|
||||
}
|
||||
public function claim_request()
|
||||
{
|
||||
return $this->hasMany(ClaimRequest::class, 'organization_id', 'id');
|
||||
}
|
||||
public function claim_history_care()
|
||||
{
|
||||
return $this->hasOne(ClaimHistoryCare::class, 'organization_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
20
app/Models/OrganizationUser.php
Normal file
20
app/Models/OrganizationUser.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OrganizationUser extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'organization_user';
|
||||
protected $connection = 'mysql';
|
||||
protected $fillable = [
|
||||
'organization_id',
|
||||
];
|
||||
|
||||
public function organization(){
|
||||
return $this->hasOne(Organization::class, 'id', 'organization_id');
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,9 @@ class Person extends Model
|
||||
|
||||
public function currentAddress()
|
||||
{
|
||||
return $this->belongsTo(Address::class, 'main_address_id');
|
||||
return $this->belongsTo(Address::class, 'main_address_id')->withDefault([
|
||||
'text' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
public function domicileAddress()
|
||||
|
||||
@@ -47,4 +47,11 @@ class Practitioner extends Model
|
||||
{
|
||||
return $this->hasMany(PractitionerRole::class, 'practitioner_id');
|
||||
}
|
||||
|
||||
public function claim_history_care()
|
||||
{
|
||||
return $this->hasMany(ClaimHistoryCare::class, 'practitioner_id');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
220
app/Models/RequestLog.php
Normal file
220
app/Models/RequestLog.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\ClaimReceived;
|
||||
use App\Events\ClaimRequested;
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Str;
|
||||
|
||||
class RequestLog extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, Blameable;
|
||||
|
||||
// protected static $code_prefix_hospital = 'CRQ-H';
|
||||
// protected static $code_prefix_client = 'CRQ-R';
|
||||
|
||||
public $fillable = [
|
||||
'uuid',
|
||||
'submission_date',
|
||||
'member_id',
|
||||
'payment_type',
|
||||
'service_code',
|
||||
'policy_id',
|
||||
'final_log',
|
||||
'status',
|
||||
'status_final_log',
|
||||
'source',
|
||||
'claim_id',
|
||||
'organization_id',
|
||||
'code'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
// 'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public static $doc_headers_to_field_map = [
|
||||
"ID REQUEST LOG" => "id",
|
||||
"STATUS (approved, declined, requested)" => "status",
|
||||
];
|
||||
|
||||
public static $listing_doc_headers = [
|
||||
"ID REQUEST LOG",
|
||||
"STATUS (approved, declined, requested)",
|
||||
];
|
||||
|
||||
public static $listing_data_doc_headers = [
|
||||
"ID REQUEST LOG",
|
||||
"CODE",
|
||||
"NAME",
|
||||
"DATE OF SUBMISSION",
|
||||
"SERVICE TYPE",
|
||||
"CLAIM METHOD",
|
||||
"STATUS",
|
||||
];
|
||||
|
||||
|
||||
public static $status = [
|
||||
'draft' => 'Draft',
|
||||
'requested' => 'Requested',
|
||||
'approved' => 'Approved',
|
||||
'declined' => 'Declined'
|
||||
];
|
||||
|
||||
public static $payment_types = [
|
||||
'cashless' => 'Cashless',
|
||||
'reimbursement' => 'Reimbursement'
|
||||
];
|
||||
|
||||
public $appends = [
|
||||
'payment_type_name'
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
try {
|
||||
$model->uuid = (string) Str::orderedUuid(); // generate uuid
|
||||
// $model->code = self::getNextCode();
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
static::created(function ($model) {
|
||||
// try {
|
||||
// if (!empty($model->status) && $model->status == 'requested') {
|
||||
// $model->histories()->create([
|
||||
// 'title' => 'New Claim Requested',
|
||||
// 'description' => "Claim Requested for Member : {$model->member->member_id} - ({$model->member->full_name})",
|
||||
// 'type' => 'info'
|
||||
// ]);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// abort(500, $e->getMessage());
|
||||
// }
|
||||
});
|
||||
|
||||
static::updated(function ($model) {
|
||||
if ($model->hasChanges(['status'])) {
|
||||
|
||||
// if ($model->status == 'requested') {
|
||||
// $model->histories()->create([
|
||||
// 'title' => 'New Claim Requested',
|
||||
// 'description' => "Claim Requested for Member : {$model->member->member_id} - ({$model->member->full_name})",
|
||||
// 'type' => 'info'
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// if ($model->status == 'received') {
|
||||
// ClaimReceived::dispatch($model);
|
||||
// }
|
||||
|
||||
// if ($model->status == 'approved') {
|
||||
// ClaimApproved::dispatch($model);
|
||||
// }
|
||||
|
||||
// if ($model->status == 'postpone') {
|
||||
// ClaimPostpone::dispatch($model);
|
||||
// }
|
||||
|
||||
// if ($model->status == 'paid') {
|
||||
// ClaimPaid::dispatch($model);
|
||||
// }
|
||||
|
||||
// if ($model->status == 'declined') {
|
||||
// ClaimDeclined::dispatch($model);
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// public static function getNextCode()
|
||||
// {
|
||||
// $last_number = self::withTrashed()->max('code');
|
||||
// $next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[1] + 1);
|
||||
|
||||
// return self::makeCode($next_number);
|
||||
// }
|
||||
|
||||
// public static function makeCode($next_number)
|
||||
// {
|
||||
// return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
|
||||
// }
|
||||
|
||||
public function claim()
|
||||
{
|
||||
return $this->belongsTo(Claim::class, 'claim_id');
|
||||
}
|
||||
|
||||
public function claims()
|
||||
{
|
||||
return $this->hasMany(Claim::class, 'claim_request_id');
|
||||
}
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->morphMany(File::class, 'fileable');
|
||||
}
|
||||
|
||||
public function claimResults()
|
||||
{
|
||||
return $this->files()->where('type', 'claim-result')->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
public function claimConditions()
|
||||
{
|
||||
return $this->files()->where('type', 'claim-kondisi')->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
public function claimDiagnosis()
|
||||
{
|
||||
return $this->files()->where('type', 'claim-diagnosis')->whereNull('deleted_at');
|
||||
}
|
||||
|
||||
public function generatedDocuments()
|
||||
{
|
||||
return $this->morphMany(GeneratedDocument::class, 'generated_documentable');
|
||||
}
|
||||
|
||||
public function histories()
|
||||
{
|
||||
return $this->morphMany(ClaimHistory::class, 'historiable');
|
||||
}
|
||||
|
||||
public function organization()
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function member()
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
public function service()
|
||||
{
|
||||
return $this->belongsTo(Service::class, 'service_code', 'code');
|
||||
}
|
||||
|
||||
public function getPaymentTypeNameAttribute()
|
||||
{
|
||||
return self::$payment_types[$this->payment_type] ?? $this->payment_type;
|
||||
}
|
||||
|
||||
public function getStatusAttribute($value)
|
||||
{
|
||||
return self::$payment_types[$value] ?? $value;
|
||||
}
|
||||
}
|
||||
27
app/Models/RequestLogBenefit.php
Normal file
27
app/Models/RequestLogBenefit.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RequestLogBenefit extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'request_log_benefits';
|
||||
|
||||
public $fillable = [
|
||||
'request_log_id',
|
||||
'benefit_id',
|
||||
'amount_incurred',
|
||||
'amount_approved',
|
||||
'amount_not_approved',
|
||||
'excess_paid',
|
||||
'keterangan',
|
||||
];
|
||||
|
||||
public function benefit(){
|
||||
return $this->belongsTo(Benefit::class, 'benefit_id', 'id');
|
||||
}
|
||||
}
|
||||
30
app/Models/RequestLogMedicine.php
Normal file
30
app/Models/RequestLogMedicine.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RequestLogMedicine extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $fillable = [
|
||||
'request_log_id',
|
||||
'medicine',
|
||||
'price',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function benefit(){
|
||||
return $this->belongsTo(Benefit::class, 'benefit_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ class User extends Authenticatable
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
|
||||
protected $connection = 'mysql';
|
||||
protected $fillable = [
|
||||
'person_id',
|
||||
'name',
|
||||
@@ -103,4 +105,9 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->morphMany(NotificationToken::class, 'notifiabletoken');
|
||||
}
|
||||
|
||||
public function getOrganization()
|
||||
{
|
||||
return $this->hasOne(OrganizationUser::class, 'user_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,23 @@ use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Models\Corporate;
|
||||
use App\Models\CorporateFormularium;
|
||||
use App\Models\CorporateService;
|
||||
use App\Models\CorporatePlan;
|
||||
use App\Models\CorporateBenefit;
|
||||
use App\Models\Member;
|
||||
use App\Models\CorporateHospital;
|
||||
use App\Models\ExclusionRules;
|
||||
use App\Models\ExclusionImport;
|
||||
use App\Models\Icd;
|
||||
use App\Models\IcdTemplate;
|
||||
use App\Models\FormulariumTemplate;
|
||||
use App\Models\AuditTrail;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Models\OLDLMS\PersonalAccessToken;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
use Str;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -35,7 +46,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
public function boot()
|
||||
{
|
||||
Schema::defaultStringLength(191);
|
||||
|
||||
|
||||
Str::macro('initials', fn($value, $sep = ' ', $glue = '') => trim(collect(explode($sep, $value))->map(function ($segment) {
|
||||
return $segment[0] ?? '';
|
||||
})->join($glue)));
|
||||
@@ -46,7 +57,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
// });
|
||||
|
||||
Corporate::updated(function ($model) {
|
||||
|
||||
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
@@ -55,7 +66,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
Member::updated(function ($model) {
|
||||
|
||||
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
@@ -63,10 +74,20 @@ class AppServiceProvider extends ServiceProvider
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
//Hospital
|
||||
CorporateHospital::updated(function ($model) {
|
||||
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
CorporateHospital::deleted(function ($model) {
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
|
||||
// Corporate Service
|
||||
CorporateService::updated(function ($model) {
|
||||
|
||||
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
@@ -76,7 +97,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
// Corporate Plans
|
||||
CorporatePlan::updated(function ($model) {
|
||||
|
||||
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
@@ -86,7 +107,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
// Corporate Benefits
|
||||
CorporateBenefit::updated(function ($model) {
|
||||
|
||||
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
@@ -95,6 +116,60 @@ class AppServiceProvider extends ServiceProvider
|
||||
});
|
||||
|
||||
|
||||
// Corporate Exclusion
|
||||
ExclusionRules::updated(function ($model) {
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
ExclusionRules::deleted(function ($model) {
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
ExclusionImport::updated(function ($model) {
|
||||
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
ExclusionImport::deleted(function ($model) {
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
// ICD or exlusion
|
||||
Icd::updated(function ($model) {
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
|
||||
Icd::deleted(function ($model) {
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
// ICD or exlusion
|
||||
IcdTemplate::updated(function ($model) {
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
IcdTemplate::deleted(function ($model) {
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
// Formualrium Template
|
||||
FormulariumTemplate::updated(function ($model) {
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
FormulariumTemplate::deleted(function ($model) {
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
// Formualrium Template
|
||||
CorporateFormularium::updated(function ($model) {
|
||||
$this->logAuditTrail($model, 'updated');
|
||||
});
|
||||
CorporateFormularium::deleted(function ($model) {
|
||||
$this->logAuditTrail($model, 'deleted');
|
||||
});
|
||||
|
||||
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function logAuditTrail($model, $action)
|
||||
@@ -109,6 +184,21 @@ class AppServiceProvider extends ServiceProvider
|
||||
'user_id' => Auth::id(),
|
||||
]);
|
||||
|
||||
// Simpan jejak audit
|
||||
$auditTrail->save();
|
||||
}
|
||||
private function logAuditTrailExclusion($model, $action)
|
||||
{
|
||||
// Membuat jejak audit baru
|
||||
$auditTrail = new AuditTrail([
|
||||
'model' => get_class($model),
|
||||
'model_id' => $model->corporate_id,
|
||||
'action' => $action,
|
||||
'old_values' => json_encode($model->getOriginal()),
|
||||
'new_values' => json_encode($model->getAttributes()),
|
||||
'user_id' => Auth::id(),
|
||||
]);
|
||||
|
||||
// Simpan jejak audit
|
||||
$auditTrail->save();
|
||||
}
|
||||
|
||||
@@ -6,32 +6,101 @@ use App\Events\ClaimApproved;
|
||||
use App\Events\ClaimRequested;
|
||||
use App\Models\Claim;
|
||||
use App\Models\ClaimRequest;
|
||||
use App\Models\Organization;
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Icd;
|
||||
use App\Models\Member;
|
||||
use Carbon\Carbon;
|
||||
use App\Exceptions\ImportRowException;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
|
||||
|
||||
use DB;
|
||||
use Str;
|
||||
|
||||
class ClaimRequestService{
|
||||
|
||||
public static function storeClaimRequest($member, $paymentType, $serviceCode, $submissionDate = null, $status = 'requested')
|
||||
public static function storeClaimRequest($row = null, $code, $member, $paymentType, $serviceCode, $requestLogID, $submissionDate = null, $status = 'requested', $organization_code = null)
|
||||
{
|
||||
try {
|
||||
// try {
|
||||
$organization = False;
|
||||
if($organization_code){
|
||||
$organization = Organization::where('code', $organization_code)->first();
|
||||
if (!$organization){
|
||||
throw new ImportRowException(__('Code Provider Tidak ditemukan', [
|
||||
'attribute' => 'provider_code',
|
||||
'code' => $row['provider_code']
|
||||
]), 403, null, $row);
|
||||
}
|
||||
};
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$claimRequestData = [
|
||||
'code' => $code,
|
||||
'request_log_id' => $requestLogID,
|
||||
'member_id' => $member->id,
|
||||
'submission_date' => $submissionDate ?? now(),
|
||||
'status' => $status,
|
||||
'payment_type' => $paymentType,
|
||||
'service_code' => $serviceCode,
|
||||
'policy_id' => $member->currentPolicy->id ?? null,
|
||||
'organization_id' => $organization ? $organization->id : 0,
|
||||
];
|
||||
|
||||
|
||||
$claimRequest = ClaimRequest::create($claimRequestData);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $claimRequest;
|
||||
// } catch (\Exception $error) {
|
||||
// DB::rollBack();
|
||||
|
||||
// throw new \Exception($error);
|
||||
// }
|
||||
}
|
||||
|
||||
public static function storeClaimManagement($row, $member, $claim_request_id){
|
||||
try {
|
||||
$organization = 0;
|
||||
if($row['provider_code']){
|
||||
$organization = Organization::where('code', $row['provider_code'])->first();
|
||||
if (!$organization){
|
||||
throw new ImportRowException(__('Provider Tidak ditemukan'), 0, null, $row);
|
||||
}
|
||||
};
|
||||
if(!$member){
|
||||
throw new ImportRowException(__('Member Tidak ditemukan'), 0, null, $row);
|
||||
};
|
||||
DB::beginTransaction();
|
||||
$data = [
|
||||
'member_id' => $member->id,
|
||||
'currency' => 'IDR',
|
||||
'plan_id' => $member->currentPlan->id,
|
||||
'total_claim' => $row['tot_amt_insurred'] ? $row['tot_amt_insurred'] : 0,
|
||||
'benefit_code' => $row['benefit_code'] ? $row['benefit_code'] : '-',
|
||||
'benefit_desc' => $row['benefit_desc'] ? $row['benefit_desc'] : '-',
|
||||
'amount_incurred' => $row['tot_amt_insurred'] ? $row['tot_amt_insurred'] : 0,
|
||||
'amount_approved' => $row['tot_amt_approved'] ? $row['tot_amt_approved'] : 0,
|
||||
'amount_not_approved' => $row['tot_amt_not_approved'] ? $row['tot_amt_not_approved'] :0,
|
||||
'excess_paid' => $row['tot_excess_paid'] ? $row['tot_excess_paid'] : 0,
|
||||
'claim_request_id' => $claim_request_id,
|
||||
'organization_id' => $organization ? $organization->id : NULL,
|
||||
'status' => 'requested'
|
||||
];
|
||||
|
||||
|
||||
$claimManagement = Claim::create($data);
|
||||
|
||||
// update client id di claim request
|
||||
ClaimRequest::where('id', $claim_request_id)->update([
|
||||
'claim_id' => $claimManagement->id,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return $claimManagement;
|
||||
|
||||
|
||||
} catch (\Exception $error) {
|
||||
DB::rollBack();
|
||||
|
||||
@@ -39,4 +108,73 @@ class ClaimRequestService{
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateClaimRequest($organization_id, $claim_request_id){
|
||||
try {
|
||||
$data = [
|
||||
'organization_id' => $organization_id
|
||||
];
|
||||
DB::commit();
|
||||
$update = ClaimRequest::where('id', $claim_request_id)->update($data);
|
||||
return ClaimRequest::find($claim_request_id);
|
||||
|
||||
} catch (\Exception $error) {
|
||||
DB::rollBack();
|
||||
|
||||
throw new \Exception($error);
|
||||
}
|
||||
}
|
||||
|
||||
protected function validatePlanRow($row)
|
||||
{
|
||||
if (empty($row['member_id'])) {
|
||||
throw new ImportRowException(__('Member ID Required'), 0, null, $row);
|
||||
}
|
||||
}
|
||||
|
||||
public function handleClaimRequestRow($row)
|
||||
{
|
||||
try {
|
||||
$member = Member::where('member_id', $row['member_id'])->with(['currentPlan'])->first();
|
||||
if(!$member){
|
||||
throw new ImportRowException(__('Member Tidak ditemukan'), 0, null, $row);
|
||||
};
|
||||
$code = $row['client_claim_id'];
|
||||
$organization_id = $row['provider_code'];
|
||||
$submissionDate = Helper::formatDateDB($row['admission_date']);
|
||||
$paymentType = $row['claim_type'];
|
||||
$status = $row['status'];
|
||||
$serviceCode = $row['coverage_type'];
|
||||
|
||||
$newClaimRequest = $this->storeClaimRequest(
|
||||
row: $row,
|
||||
code: $code,
|
||||
member: $member,
|
||||
paymentType: $paymentType,
|
||||
serviceCode: $serviceCode,
|
||||
submissionDate: $submissionDate,
|
||||
status: $status,
|
||||
organization_code: $organization_id
|
||||
);
|
||||
|
||||
$newlyCreatedID = $newClaimRequest->id;
|
||||
|
||||
$newClaimManangement = $this->storeClaimManagement($row, $member, $newlyCreatedID);
|
||||
ClaimRequested::dispatch($newClaimRequest);
|
||||
// Log History
|
||||
$newClaimRequest->histories()->create([
|
||||
'title' => 'New Claim Requested',
|
||||
'description' => "Claim Requested for Member : {$member->member_id} - ({$member->full_name})",
|
||||
'type' => 'info',
|
||||
'system_origin' => 'import-internal-aso'
|
||||
]);
|
||||
|
||||
$claim_request_data = $row;
|
||||
$this->validatePlanRow($claim_request_data);
|
||||
|
||||
return $newClaimRequest;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Models\Member;
|
||||
use App\Models\Encounter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CorporateMemberService
|
||||
{
|
||||
@@ -34,7 +35,7 @@ class CorporateMemberService
|
||||
'division' => 'corporate_divisions.name',
|
||||
default => ''
|
||||
};
|
||||
if ($request->order){
|
||||
if ($request->order) {
|
||||
$query->getQuery()->orderBy($orderBy, $request->order);
|
||||
}
|
||||
})
|
||||
@@ -44,14 +45,57 @@ class CorporateMemberService
|
||||
}
|
||||
|
||||
public function getAllMemberClaimReports(int $corporateId, Request $request)
|
||||
{
|
||||
$limit = $request->has('per_page') ? $request->input('per_page') : 10;
|
||||
|
||||
$results = DB::table('claim_requests')
|
||||
->leftJoin('claims', 'claim_requests.id', '=', 'claims.claim_request_id')
|
||||
->leftJoin('members', 'claim_requests.member_id', '=', 'members.id')
|
||||
->leftJoin('corporate_employees', 'members.id', '=', 'corporate_employees.member_id')
|
||||
->leftJoin('corporate_divisions', 'corporate_employees.division_id', '=', 'corporate_divisions.id')
|
||||
->where('corporate_employees.corporate_id', '=', $corporateId)
|
||||
->when($request->input('search'), function ($query, $search) {
|
||||
$query->where(function ($query) use ($search) {
|
||||
$query->orWhere('claim_requests.code', 'like', "%" . $search . "%")
|
||||
->orWhere('members.member_id', 'like', "%" . $search . "%")
|
||||
->orWhere('members.name', 'like', "%" . $search . "%")
|
||||
->orWhere('corporate_divisions.name', 'like', "%" . $search . "%")
|
||||
->orWhere('claim_requests.status', 'like', "%" . $search . "%")
|
||||
->orWhere('claim_requests.submission_date', 'like', "%" . $search . "%");
|
||||
});
|
||||
})
|
||||
->when($request->has('orderBy'), function ($query) use ($request) {
|
||||
$orderBy = $request->orderBy;
|
||||
$direction = $request->order ?? 'asc';
|
||||
|
||||
$query->orderBy($orderBy, $direction);
|
||||
})
|
||||
->select('members.id', 'claim_requests.code','members.member_id', 'members.name as full_name', 'corporate_divisions.name AS division_name',
|
||||
DB::raw('
|
||||
CASE
|
||||
WHEN claim_requests.status = "requested" THEN "requested"
|
||||
WHEN claim_requests.status = "approved" AND claims.status = "approved" THEN "approved"
|
||||
WHEN claim_requests.status = "approved" AND claims.status = "declined" THEN "declined"
|
||||
WHEN claim_requests.status = "approved" AND claims.status = "disbrusmented" THEN "disbrusmented"
|
||||
/*WHEN claim_requests.status = "approved" AND claims.status = "received" THEN "pending"*/
|
||||
WHEN claim_requests.status = "approved" AND claims.status = "received" THEN "reviewed"
|
||||
ELSE ""
|
||||
END AS status
|
||||
'),
|
||||
'claim_requests.id AS claim_request_id', 'claim_requests.submission_date')
|
||||
->paginate($limit);
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getAllMemberClaimSubmits(int $corporateId, Request $request)
|
||||
{
|
||||
$limit = $request->has('perPage') ? $request->input('perPage') : 10;
|
||||
|
||||
return Member::query()
|
||||
->joinClaimRequests('right')
|
||||
// ->joinClaimRequests('right')
|
||||
->joinCorporateEmployees('left')
|
||||
->joinCorporateDivisions('left')
|
||||
->with('currentPlan')
|
||||
->with('currentPlans')
|
||||
->withSum('claims', 'total_claim')
|
||||
->whereHas('employeds', function (Builder $corporateEmployee) use ($corporateId) {
|
||||
$corporateEmployee->where('corporate_id', $corporateId);
|
||||
@@ -80,11 +124,62 @@ class CorporateMemberService
|
||||
$query->getQuery()->orderBy('corporate_divisions.name', $request->order);
|
||||
}
|
||||
})
|
||||
->select(['members.id', 'members.person_id', 'members.member_id', 'members.name', 'corporate_divisions.name AS division_name', 'members.active', 'claim_requests.id', 'claim_requests.member_id', 'claim_requests.submission_date'])
|
||||
// ->select(['members.id', 'members.person_id', 'members.member_id', 'members.name', 'corporate_divisions.name AS division_name', 'members.active', 'claim_requests.id', 'claim_requests.member_id', 'claim_requests.submission_date'])
|
||||
->select(['members.id', 'members.person_id', 'members.member_id', 'members.name', 'corporate_divisions.name AS division_name', 'members.active', ])
|
||||
->paginate($limit);
|
||||
}
|
||||
|
||||
public function getAllMemberAlarmCenter(int $corporateId, Request $request)
|
||||
{
|
||||
$limit = $request->has('perPage') ? $request->input('perPage') : 10;
|
||||
$start_date = date('Y-m-d', strtotime($request->input('start_date') . ' +1 day'));
|
||||
$end_date = date('Y-m-d', strtotime($request->input('end_date') . ' +1 day'));
|
||||
|
||||
// dd($request);
|
||||
return Member::query()
|
||||
->joinCorporateEmployees('left')
|
||||
->joinMemberPlans('left')
|
||||
->joinPlans('left')
|
||||
->with(['currentPlan', 'person'])
|
||||
->where('corporate_employees.corporate_id', $corporateId)
|
||||
->when($request->input('search'), function (Builder $query, $search) {
|
||||
$query->where(function (Builder $query) use ($search) {
|
||||
$query->orWhere('members.member_id', 'like', "%" . $search . "%")
|
||||
->orWhere('members.name', 'like', "%" . $search . "%");
|
||||
});
|
||||
})
|
||||
->when($request->input('start_date'), function (Builder $query, $start) {
|
||||
$query->where('member_plans.start', '>=', $start);
|
||||
})
|
||||
->when($request->input('end_date'), function (Builder $query, $end) {
|
||||
$query->where('member_plans.end', '<', $end);
|
||||
})
|
||||
->when($request->input('division'), function (Builder $query, $value) {
|
||||
$query->where('corporate_employees.division_id', $value);
|
||||
})
|
||||
->when($request->input('status'), function (Builder $query, $value) {
|
||||
$query->where('plans.active', $value);
|
||||
})
|
||||
->when($request->has('orderBy'), function (Builder $query) use ($request) {
|
||||
$orderBy = match ($request->input('orderBy')) {
|
||||
'memberId' => 'member_id',
|
||||
'fullName' => 'name',
|
||||
'status' => 'active',
|
||||
'start_date' => 'member_plans.start',
|
||||
'end_date' => 'member_plans.end',
|
||||
'service' => 'plans.service_code',
|
||||
|
||||
default => ''
|
||||
};
|
||||
|
||||
$query->getQuery()->orderBy($orderBy, $request->order);
|
||||
})
|
||||
->select(['members.id', 'members.person_id', 'members.member_id', 'members.name', 'members.members_effective_date AS start_date', 'members.members_expire_date AS end_date', 'plans.active', 'plans.service_code'])
|
||||
->selectRaw("(select sum(`claims`.`total_claim`) from `claims` where `members`.`id` = `claims`.`member_id` AND `claims`.`deleted_at` IS NULL) AS `claims_sum_total_claim`")
|
||||
->paginate($limit);
|
||||
}
|
||||
|
||||
public function getAllMemberEmployeeData(int $corporateId, Request $request)
|
||||
{
|
||||
$limit = $request->has('perPage') ? $request->input('perPage') : 10;
|
||||
|
||||
@@ -122,8 +217,8 @@ class CorporateMemberService
|
||||
->paginate($limit);
|
||||
}
|
||||
|
||||
public function getAllEncounter(int $corporateId){
|
||||
public function getAllEncounter(int $corporateId)
|
||||
{
|
||||
return Encounter::query()->select(['id'])->paginate(10);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
171
app/Services/RequestLogService.php
Normal file
171
app/Services/RequestLogService.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Events\ClaimApproved;
|
||||
use App\Events\ClaimRequested;
|
||||
use App\Models\Claim;
|
||||
use App\Models\RequestLog;
|
||||
use App\Models\Organization;
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Icd;
|
||||
use App\Models\Member;
|
||||
use Carbon\Carbon;
|
||||
use App\Exceptions\ImportRowException;
|
||||
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
|
||||
|
||||
|
||||
use DB;
|
||||
use Str;
|
||||
|
||||
class RequestLogService{
|
||||
|
||||
public static function storeRequestLog(
|
||||
$row = null,
|
||||
$code,
|
||||
$member,
|
||||
$paymentType,
|
||||
$serviceCode,
|
||||
$submissionDate = null,
|
||||
$status, $organization_id = null,
|
||||
$source
|
||||
)
|
||||
{
|
||||
try {
|
||||
$organization = False;
|
||||
if($organization_id){
|
||||
$organization = Organization::where('id', $organization_id)->first();
|
||||
if (!$organization){
|
||||
throw new ImportRowException(__('Code Provider Tidak ditemukan', [
|
||||
'attribute' => 'provider_code',
|
||||
'code' => $row['provider_code']
|
||||
]), 403, null, $row);
|
||||
}
|
||||
};
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$requestLogData = [
|
||||
'code' => $code,
|
||||
'member_id' => $member->id,
|
||||
'submission_date' => $submissionDate ?? now(),
|
||||
'status' => $status,
|
||||
'payment_type' => $paymentType,
|
||||
'service_code' => $serviceCode,
|
||||
'policy_id' => $member->currentPolicy->id ?? null,
|
||||
'organization_id' => $organization ? $organization->id : 0,
|
||||
'source' => $source,
|
||||
];
|
||||
|
||||
$requestLog = RequestLog::create($requestLogData);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $requestLog;
|
||||
} catch (\Exception $error) {
|
||||
DB::rollBack();
|
||||
|
||||
throw new \Exception($error);
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeClaimManagement($row, $member, $claim_request_id){
|
||||
try {
|
||||
$organization = 0;
|
||||
if($row['provider_code']){
|
||||
$organization = Organization::where('code', $row['provider_code'])->first();
|
||||
if (!$organization){
|
||||
throw new ImportRowException(__('Provider Tidak ditemukan'), 0, null, $row);
|
||||
}
|
||||
};
|
||||
if(!$member){
|
||||
throw new ImportRowException(__('Member Tidak ditemukan'), 0, null, $row);
|
||||
};
|
||||
DB::beginTransaction();
|
||||
$data = [
|
||||
'member_id' => $member->id,
|
||||
'currency' => 'IDR',
|
||||
'plan_id' => $member->currentPlan->id,
|
||||
'total_claim' => $row['tot_amt_insurred'] ? $row['tot_amt_insurred'] : 0,
|
||||
'benefit_code' => $row['benefit_code'] ? $row['benefit_code'] : '-',
|
||||
'benefit_desc' => $row['benefit_desc'] ? $row['benefit_desc'] : '-',
|
||||
'amount_incurred' => $row['tot_amt_insurred'] ? $row['tot_amt_insurred'] : 0,
|
||||
'amount_approved' => $row['tot_amt_approved'] ? $row['tot_amt_approved'] : 0,
|
||||
'amount_not_approved' => $row['tot_amt_not_approved'] ? $row['tot_amt_not_approved'] :0,
|
||||
'excess_paid' => $row['tot_excess_paid'] ? $row['tot_excess_paid'] : 0,
|
||||
'claim_request_id' => $claim_request_id,
|
||||
'organization_id' => $organization ? $organization->id : NULL,
|
||||
'status' => 'requested'
|
||||
];
|
||||
|
||||
|
||||
$claimManagement = Claim::create($data);
|
||||
|
||||
// update client id di claim request
|
||||
ClaimRequest::where('id', $claim_request_id)->update([
|
||||
'claim_id' => $claimManagement->id,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return $claimManagement;
|
||||
|
||||
|
||||
} catch (\Exception $error) {
|
||||
DB::rollBack();
|
||||
|
||||
throw new \Exception($error);
|
||||
}
|
||||
}
|
||||
|
||||
public static function updateClaimRequest($organization_id, $claim_request_id){
|
||||
try {
|
||||
$data = [
|
||||
'organization_id' => $organization_id
|
||||
];
|
||||
DB::commit();
|
||||
$update = ClaimRequest::where('id', $claim_request_id)->update($data);
|
||||
return ClaimRequest::find($claim_request_id);
|
||||
|
||||
} catch (\Exception $error) {
|
||||
DB::rollBack();
|
||||
|
||||
throw new \Exception($error);
|
||||
}
|
||||
}
|
||||
|
||||
protected function validatePlanRow($row)
|
||||
{
|
||||
if (empty($row['member_id'])) {
|
||||
throw new ImportRowException(__('Member ID Required'), 0, null, $row);
|
||||
}
|
||||
}
|
||||
|
||||
public function handleRequestLogRow($row)
|
||||
{
|
||||
try {
|
||||
$requestLog = RequestLog::where('id', $row['id'])->first();
|
||||
if(!$requestLog){
|
||||
throw new ImportRowException(__('Request LOG Tidak ditemukan'), 0, null, $row);
|
||||
};
|
||||
$status = RequestLog::$status;
|
||||
|
||||
if (!array_key_exists($row['status'], $status)){
|
||||
throw new ImportRowException(__('Status Request LOG Tidak ditemukan'), 0, null, $row);
|
||||
}
|
||||
|
||||
// Update Request LOG Status & Link with Claim
|
||||
DB::beginTransaction();
|
||||
$requestLog->update([
|
||||
'status' => $row['status']
|
||||
]);
|
||||
$requestLog->save();
|
||||
DB::commit();
|
||||
return $requestLog;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user