[WIP] Claim Encounters

This commit is contained in:
R
2023-03-24 14:41:02 +07:00
parent 229908e492
commit 7b9a341ccd
23 changed files with 1099 additions and 37 deletions

View File

@@ -149,6 +149,16 @@ class Claim extends Model
return $this->belongsTo(Member::class, 'member_id');
}
public function encounters()
{
return $this->belongsToMany(Encounter::class, 'claim_encounter');
}
public function finalEncounter()
{
return $this->belongsTo(Encounter::class, 'final_encounter_id');
}
public function diagnoses()
{
return $this->hasMany(ClaimDiagnosis::class, 'claim_id');
@@ -185,5 +195,10 @@ class Claim extends Model
->whereIn('status', ['approved', 'paid']);
// ->whereBetween('requested_at', [$startDate, $endDate]);
}
public function getTotalTagihanAttribute()
{
return $this->items->sum('nominal_ditagihkan');
}
}

View File

@@ -28,6 +28,11 @@ class ClaimDiagnosis extends Model
'deleted_by',
];
public $type_enums = [
'primary' => 'Primary',
'secondary' => 'Secondary'
];
public function icd()
{
return $this->belongsTo(Icd::class, 'diagnosis_id', 'id');

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
class Encounter extends Model
{
@@ -15,8 +16,37 @@ class Encounter extends Model
'class',
'type',
'patient_id',
'healthcare_id',
'start',
'end',
'number_of_bed',
'duration_day'
];
public $casts = [
'start' => 'datetime',
'end' => 'datetime'
];
public static $status_enums = [
'completed' => 'Completed',
'planned' => 'Planned',
'in-progress' => 'In Progress',
'on-hold' => 'On Hold',
'discharged' => 'Discharged',
'completed' => 'Completed',
'cancelled' => 'Cancelled',
'discontinued' => 'Discontinued',
'entered-in-error' => 'Entered in Error',
'unknown' => 'Unknown',
];
public $with = [
'metas'
];
public $append = [
'meta'
];
public function participants()
@@ -24,8 +54,55 @@ class Encounter extends Model
return $this->hasMany(EncounterParticipant::class, 'encounter_id');
}
public function doctors()
{
// return $this->hasManyThrough(CorporateService::class, Service::class, 'corporate_id', 'service_code', 'id', 'service_code');
return $this->hasManyThrough(Practitioner::class, EncounterParticipant::class, 'encounter_id', 'id', 'id', 'participantable_id')
->where(
'participantable_type',
array_search(static::class, Relation::morphMap()) ?: Practitioner::class
);
}
public function diagnoses()
{
return $this->hasMany(EncounterDiagnosis::class, 'encounter_id');
}
public function healthcare()
{
return $this->belongsTo(Organization::class, 'healthcare_id');
}
public function metas()
{
return $this->morphMany(Meta::class, 'metaable');
}
public function primaryDiagnoses()
{
return $this->diagnoses()->where('type', 'primary');
}
public function secondaryDiagnoses()
{
return $this->diagnoses()->wher('type', 'primary');
}
public function service()
{
return $this->belongsTo(Service::class, 'class', 'code');
}
public function getMetaAttribute()
{
$orgMeta = [];
foreach ($this->metas as $meta) {
$orgMeta[$meta->type] = $meta->value;
}
return (object) $orgMeta;
}
}

View File

@@ -12,6 +12,7 @@ class EncounterDiagnosis extends Model
public $fillable = [
'encounter_id',
'diagnosis_id',
'type',
'use',
'source',
'description',
@@ -22,8 +23,18 @@ class EncounterDiagnosis extends Model
'final' => 'Final'
];
public static $type_enums = [
'primary' => 'Primary',
'secondary' => 'Secondary'
];
public function encounter()
{
return $this->belongsTo(Encounter::class, 'encounter_id');
}
public function diagnosis()
{
return $this->belongsTo(Icd::class, 'diagnosis_id');
}
}

View File

@@ -12,6 +12,8 @@ class EncounterParticipant extends Model
public $fillable = [
'encounter_id',
'type',
'participantable_type',
'participantable_id'
];