Merge branch 'feature/aso-digital-card' into staging

This commit is contained in:
R
2023-02-17 14:31:02 +07:00
140 changed files with 4497 additions and 736 deletions

View File

@@ -4,7 +4,10 @@ namespace App\Http\Controllers\Api\OLDLMS;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Resources\OLDLMS\MemberResource;
use App\Models\Corporate;
use App\Models\Member;
use App\Rules\NikRule;
use App\Services\ClaimService;
use Illuminate\Http\Request;
@@ -169,4 +172,83 @@ class MembershipController extends Controller
return Helper::responseJson(data: $limits);
}
public function linkingRules(Request $request)
{
$corporates = Corporate::query()
->when($request->search, function ($q, $search) {
$q->where('name', 'LIKE', '%'.$search.'%');
})
->get();
return Helper::responseJson(data: $corporates);
}
public function linkingValidate(Request $request)
{
$request->validate([
'corporate_id' => 'required'
]);
$corporate = Corporate::findOrFail($request->corporate_id);
// Make Validation from Linking Rules
$linkingRulesArr = $corporate->linking_rules->toArray();
$validationRules = [];
foreach ($linkingRulesArr as $field) {
$rules = ['required']; // Default is required if in the linking_rules
if ($field == 'email') {
$rules[] = 'email';
}
if ($field == 'nric') {
$rules[] = new NikRule;
}
$validationRules[$field] = $rules;
}
$request->validate($validationRules);
$member = Member::query()
->when(in_array('nric', $linkingRulesArr), function($q) use ($request) {
$q->where('nric', $request->nric);
})
->when(in_array('member_id', $linkingRulesArr), function($q) use ($request) {
$q->where('member_id', $request->member_id);
})
->when(in_array('name', $linkingRulesArr), function($q) use ($request) {
$q->where('name', $request->name);
})
->when(in_array('dob', $linkingRulesArr), function($q) use ($request) {
$q->where('birth_date', $request->dob);
})
->when(in_array('phone', $linkingRulesArr), function($q) use ($request) {
$q->whereHas('person', function ($person) use ($request) {
$person->where('phone', $request->phone);
});
})
->when(in_array('email', $linkingRulesArr), function($q) use ($request) {
$q->where('email', $request->email);
})
->when(in_array('nik', $linkingRulesArr), function($q) use ($request) {
$q->whereHas('employeds', function ($employed) use ($request) {
$employed->where('corporate_id', $request->corporate_id)
->where('nik', $request->nik);
});
})
->with([
'memberPlans' => function ($memberPlan) {
$memberPlan->latest();
},
])
->first();
if ($member) {
return Helper::responseJson(data: MemberResource::make($member), message: 'Data Member ditemukan!');
}
return Helper::responseJson(data: [], message: 'Member Tidak ditemukan', statusCode: 404, status: 'error');
}
}

View File

@@ -14,6 +14,23 @@ class MemberResource extends JsonResource
*/
public function toArray($request)
{
return parent::toArray($request);
// $data = parent::toArray($request);
$currentMemberPlan = $this->memberPlans?->first();
$currentPlan = $currentMemberPlan ? [
'code' => $currentMemberPlan->plan->code ?? null,
'start' => $currentMemberPlan->start,
'end' => $currentMemberPlan->end
] : null;
$data = [
'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' => $currentPlan
];
return $data;
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -23,7 +24,7 @@ class Corporate extends Model
];
protected $casts = [
'linking_rules' => 'array',
'linking_rules' => AsArrayObject::class,
];
protected $appends = [

View File

@@ -141,7 +141,8 @@ class Member extends Model
public function currentPlan()
{
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id')->latest();
return $this->hasOneThrough(Plan::class, MemberPlan::class, 'member_id', 'id', 'id', 'plan_id')
->latest(); // TODO Fix This
}
public function policies()

View File

@@ -31,4 +31,17 @@ class MemberPlan extends Model
{
return $this->belongsTo(CorporatePlan::class, 'plan_id', 'code');
}
public function plan()
{
return $this->belongsTo(Plan::class, 'plan_id');
}
public function scopeActive($q)
{
return $q
->where('start', '<', now())
->where('end', '>', now())
->latest();
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -14,12 +15,99 @@ class Appointment extends Model
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
public $sStatusNames = [
0 => 'Menunggu Pembayaran',
1 => 'Pembayaran Terkonfirmasi', // Pembayaran Diterima
2 => 'Ditolak',
3 => 'Dibatalkan', // Canceled
4 => 'Expired',
];
public $sPaymentMethodName = [
1 => 'Pribadi',
2 => 'On-Site Payment',
3 => 'OVO',
4 => 'Asuransi',
5 => 'Voucher',
];
public $nIDJenisBookingNames = [
1 => 'Rawat Jalan',
2 => 'Telekonsultasi',
3 => 'Chat Sekarang'
];
protected $connection = 'oldlms';
protected $table = 'tx_appointment';
public function detail()
protected $primaryKey = 'nID';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'nID',
'nIDDokter',
'nIDUser',
'sStatus',
'dCreateOn',
'dUpdateOn',
'dDeleteOn',
];
protected $appends = [
'status_name',
'payment_method',
'type'
];
protected function statusName(): Attribute
{
return $this->hasOne(AppointmentDetail::class, '');
return Attribute::make(
get: function ($value) {
return $this->sStatusNames[$this->sStatus] ?? '-';
},
);
}
protected function paymentMethod(): Attribute
{
return Attribute::make(
get: function ($value) {
return $this->sPaymentMethodName[$this->sPaymentMethod] ?? '-';
},
);
}
protected function type(): Attribute
{
return Attribute::make(
get: function($value) {
return $this->nIDJenisBookingNames[$this->nIDJenisBooking] ?? '-';
}
);
}
public function appointmentDetail()
{
return $this->hasOne(AppointmentDetail::class, 'nIDAppointment', 'nID');
}
public function doctor()
{
return $this->belongsTo(Dokter::class, 'nIDDokter', 'nID');
}
public function user()
{
return $this->belongsTo(User::class, 'nIDUser', 'nID');
}
public function healthCare()
{
return $this->belongsTo(Healthcare::class, 'nIDHealthCare', 'nID');
}
}

View File

@@ -8,4 +8,19 @@ use Illuminate\Database\Eloquent\Model;
class AppointmentDetail extends Model
{
use HasFactory;
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
protected $connection = 'oldlms';
protected $table = 'tx_appointment_detail';
protected $casts = [
'sPaymentDetails' => 'array',
];
public function appointment()
{
return $this->belongsTo(Appointment::class, 'nIDAppointment', 'nID');
}
}

View File

@@ -24,4 +24,14 @@ class Dokter extends Model
{
return $this->hasMany(JadwalDokter::class, 'nIDDokter', 'nID');
}
public function user()
{
return $this->belongsTo(User::class, 'nIDUser', 'nID');
}
public function speciality()
{
return $this->belongsTo(Speciality::class, 'nIDSpesialis', 'nID');
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class Livechat extends Model
{
use HasFactory;
public $sStatusNames = [
0 => 'Menunggu Konfirmasi',
1 => 'Diterima',
2 => 'Ditolak',
3 => 'Selesai',
4 => 'Expired',
];
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
protected $connection = 'oldlms';
protected $table = 'tx_livechat';
protected $appends = [
'status_name',
];
protected function statusName(): Attribute
{
return Attribute::make(
get: function ($value) {
return $this->sStatusNames[$this->sStatus] ?? '-';
},
);
}
public function user()
{
return $this->belongsTo(User::class, 'nIDUser', 'nID');
}
public function doctor()
{
return $this->belongsTo(Dokter::class, 'nIDDokter', 'nID');
}
public function appointment()
{
return $this->belongsTo(Appointment::class, 'nIDAppointment', 'nID');
}
public function healthCare()
{
return $this->belongsTo(Healthcare::class, 'nIDHealthCare', 'nID');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Speciality extends Model
{
use HasFactory;
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
protected $connection = 'oldlms';
protected $table = 'tm_spesialis';
protected $primaryKey = 'nID';
public function dokter()
{
return $this->hasMany(Dokter::class, 'nIDSpesialis', 'nID');
}
}

View File

@@ -2,10 +2,46 @@
namespace App\Models\OLDLMS;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model
{
use HasFactory;
use HasFactory, SoftDeletes;
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
protected $connection = 'oldlms';
protected $table = 'tm_users';
protected $appends = [
'full_name',
];
protected function fullName(): Attribute
{
return Attribute::make(
get: function ($value) {
$names = [];
if (!empty($this->sFirstName)) {
array_push($names, $this->sFirstName);
}
if (!empty($this->sLastName)) {
array_push($names, $this->sLastName);
}
return implode(' ', $names);
}
);
}
public function detail()
{
return $this->hasOne(UserDetail::class, 'nIDUser', 'nID');
}
}

View File

@@ -8,4 +8,13 @@ use Illuminate\Database\Eloquent\Model;
class UserDetail extends Model
{
use HasFactory;
const CREATED_AT = 'dCreateOn';
const UPDATED_AT = 'dUpdateOn';
const DELETED_AT = 'dDeleteOn';
protected $connection = 'oldlms';
protected $table = 'tm_users_detail';
}

View File

@@ -114,6 +114,11 @@ class Person extends Model
return $this->hasOne(User::class, 'person_id');
}
public function practitioner()
{
return $this->hasOne(Practitioner::class, 'person_id');
}
public function appointmentParticipantables()
{
return $this->morphMany(AppointmentParticipant::class, 'participantable');

View File

@@ -2,7 +2,9 @@
namespace App\Providers;
use App\Rules\NikRule;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Str;

66
app/Rules/NikRule.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class NikRule implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
// The NIK is a 16-digit number
if (!preg_match('/^[0-9]{16}$/', $value)) {
return false;
}
// // The first 6 digits represent the person's birth date in the format of YYMMDD
// $year = substr($value, 6, 2);
// $month = substr($value, 8, 2);
// $day = substr($value, 10, 2);
// // dd($year, $month, $day);
// // dd(checkdate($month, $day, "19{$year}"));
// if (!checkdate($month, $day, "19{$year}")) {
// return false;
// }
// // The next 2 digits represent the place of birth (province/city code)
// $provinceCode = substr($value, 6, 2);
// // The next 2 digits represent the person's gender (odd for male, even for female)
// $genderCode = substr($value, 14, 1);
// // The last 4 digits represent the sequence number of the person's birth in that day
// $sequenceNumber = substr($value, 12, 4);
return true;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return ':attribute bukan valid NIK Indonesia.';
}
}