Add API
This commit is contained in:
@@ -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
22
app/Models/Meta.php
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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
49
app/Models/Person.php
Normal 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');
|
||||
}
|
||||
}
|
||||
39
app/Models/Practitioner.php
Normal file
39
app/Models/Practitioner.php
Normal 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');
|
||||
}
|
||||
}
|
||||
41
app/Models/PractitionerRole.php
Normal file
41
app/Models/PractitionerRole.php
Normal 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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user