This commit is contained in:
R
2022-09-17 00:51:02 +07:00
parent 300b53942d
commit a9f29cd19d
28 changed files with 1122 additions and 13 deletions

View File

@@ -8,4 +8,28 @@ use Illuminate\Database\Eloquent\Model;
class Address extends Model
{
use HasFactory;
protected $fillable = [
'addressable_type',
'addressable_id',
'use',
'type',
'text',
'line',
'province_id',
'city_id',
'district_id',
'village_id',
'postal_code',
'country',
'lat',
'lng',
'period_start',
'period_end',
];
public function addressable()
{
return $this->morphTo();
}
}

22
app/Models/Meta.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Meta extends Model
{
use HasFactory;
public $fillable = [
'system',
'type',
'value'
];
public function metaable()
{
return $this->morphTo();
}
}

View File

@@ -10,15 +10,55 @@ class Organization extends Model
use HasFactory;
protected $fillable = [
'code',
'name',
'type',
'status',
'description',
'part_of',
'main_address_id',
];
public $with = [
'metas'
];
public $appends = [
'meta'
];
public function getMetaAttribute()
{
$orgMeta = [];
foreach ($this->metas as $meta) {
$orgMeta[$meta->type] = $meta->value;
}
return (object) $orgMeta;
}
public function addresses()
{
return $this->morphMany(Address::class, 'addressable');
}
public function currentAddress()
{
return $this->belongsTo(Address::class, 'main_address_id');
}
public function parent()
{
return $this->belongsTo(Organization::class, 'part_of', 'id');
}
public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
}
public function practitionerRoles()
{
return $this->hasMany(PractitionerRole::class, 'organization_id');
}
}

49
app/Models/Person.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
use HasFactory;
protected $table = 'persons';
protected $fillable = [
'nik',
'name_prefix',
'name',
'name_suffix',
'gender',
'birth_date',
'is_deceased',
'deceased_at',
'marital_status',
];
public function getFullNameAttribute()
{
$arr = [];
if (!empty($this->name_prefix)) {
$arr[] = $this->name_prefix;
}
$arr[] = $this->name;
if (!empty($this->name_suffix)) {
$arr[] = $this->name_suffix;
}
return implode(' ', $arr);
}
public function addresses()
{
return $this->morphMany(Address::class, 'addressable');
}
public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Practitioner extends Model
{
use HasFactory;
protected $fillable = [
'person_id'
];
public $appends = [
'meta'
];
public function getMetaAttribute()
{
$orgMeta = [];
foreach ($this->metas as $meta) {
$orgMeta[$meta->type] = $meta->value;
}
return (object) $orgMeta;
}
public function person()
{
return $this->belongsTo(Person::class, 'person_id');
}
public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PractitionerRole extends Model
{
use HasFactory;
protected $fillable = [
'practitioner_id',
'organization_id',
'speciality_id',
'identifier_id',
'period_start',
'period_end',
'active',
];
public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
}
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
public function practitioner()
{
return $this->belongsTo(Practitioner::class, 'practitioner_id');
}
public function speciality()
{
return $this->belongsTo(Speciality::class, 'speciality_id');
}
}