Skip to main content

Overview

The Consultation model represents the clinical encounter between a patient and doctor. It records vital signs, clinical findings, diagnoses, and treatment plans. Each consultation can be linked to an appointment and may have associated prescriptions and payments. Model Location: app/Models/Consultation.php Features:
  • Soft deletes enabled
  • Comprehensive vital signs tracking
  • Relationships with patients, doctors, appointments, prescriptions, and payments
  • Clinical documentation support

Database Schema

id
bigint
required
Primary key, auto-incrementing
patient_id
bigint
required
Foreign key to patients table. Cascades on delete.
doctor_id
bigint
required
Foreign key to users table. Cascades on delete.
appointment_id
bigint
Foreign key to appointments table. Sets to null on delete.

Vital Signs

weight
decimal(5,2)
Patient weight in kilograms
height
decimal(5,2)
Patient height in centimeters
temperature
decimal(4,1)
Body temperature in Celsius
bp_systolic
integer
Systolic blood pressure (mmHg)
bp_diastolic
integer
Diastolic blood pressure (mmHg)
heart_rate
integer
Heart rate in beats per minute
respiratory_rate
integer
Respiratory rate in breaths per minute
oxygen_saturation
integer
Oxygen saturation percentage (SpO2)

Clinical Record

reason_for_visit
text
required
Chief complaint or reason for the consultation
clinical_findings
text
Physical examination findings and observations
diagnosis
text
required
Medical diagnosis or diagnoses
treatment_plan
text
Recommended treatment and follow-up plan
created_at
timestamp
Record creation timestamp
updated_at
timestamp
Record last update timestamp
deleted_at
timestamp
Soft delete timestamp (null if not deleted)

Fillable Attributes

The following attributes can be mass-assigned:
patient_id
integer
required
ID of the patient
doctor_id
integer
required
ID of the doctor (User)
appointment_id
integer
ID of the related appointment (optional)
weight
decimal
Weight in kg (e.g., 75.50)
height
decimal
Height in cm (e.g., 175.00)
temperature
decimal
Temperature in Celsius (e.g., 36.5)
bp_systolic
integer
Systolic blood pressure (e.g., 120)
bp_diastolic
integer
Diastolic blood pressure (e.g., 80)
heart_rate
integer
Heart rate in bpm (e.g., 72)
respiratory_rate
integer
Respiratory rate in breaths/min (e.g., 16)
oxygen_saturation
integer
SpO2 percentage (e.g., 98)
reason_for_visit
text
required
Chief complaint or reason for visit
clinical_findings
text
Physical examination findings
diagnosis
text
required
Medical diagnosis
treatment_plan
text
Treatment and follow-up plan

Relationships

Patient

Get the patient associated with this consultation.
$consultation = Consultation::find(1);
$patient = $consultation->patient;

echo $patient->full_name;
echo $patient->allergies;
Relationship Type: belongsTo Related Model: App\Models\Patient Foreign Key: patient_id

Doctor

Get the doctor (User) who conducted this consultation.
$consultation = Consultation::find(1);
$doctor = $consultation->doctor;

echo $doctor->name;
Relationship Type: belongsTo Related Model: App\Models\User Foreign Key: doctor_id

Appointment

Get the appointment associated with this consultation (if any).
$consultation = Consultation::find(1);
$appointment = $consultation->appointment;

if ($appointment) {
    echo $appointment->start_time;
}
Relationship Type: belongsTo Related Model: App\Models\Appointment Foreign Key: appointment_id

Prescription

Get the prescription created for this consultation.
$consultation = Consultation::find(1);
$prescription = $consultation->prescription;

if ($prescription) {
    foreach ($prescription->items as $item) {
        echo $item['medication'];
    }
}
Relationship Type: hasOne Related Model: App\Models\Prescription

Payment

Get the payment associated with this consultation.
$consultation = Consultation::find(1);
$payment = $consultation->payment;

if ($payment) {
    echo "Amount: " . $payment->amount;
    echo "Status: " . $payment->status;
}
Relationship Type: hasOne Related Model: App\Models\Payment

Soft Deletes

The Consultation model uses soft deletes. Deleted records are not permanently removed from the database but marked with a deleted_at timestamp.
// Soft delete a consultation
$consultation->delete();

// Include soft deleted records
$allConsultations = Consultation::withTrashed()->get();

// Get only soft deleted records
$deletedConsultations = Consultation::onlyTrashed()->get();

// Restore a soft deleted consultation
$consultation->restore();

// Permanently delete
$consultation->forceDelete();

Usage Examples

Creating a Consultation

use App\Models\Consultation;

$consultation = Consultation::create([
    'patient_id' => 1,
    'doctor_id' => 5,
    'appointment_id' => 10,
    'weight' => 75.5,
    'height' => 175.0,
    'temperature' => 36.5,
    'bp_systolic' => 120,
    'bp_diastolic' => 80,
    'heart_rate' => 72,
    'respiratory_rate' => 16,
    'oxygen_saturation' => 98,
    'reason_for_visit' => 'Dolor de cabeza persistente',
    'clinical_findings' => 'Paciente alerta y orientado. No se observan signos neurológicos focales.',
    'diagnosis' => 'Cefalea tensional',
    'treatment_plan' => 'Analgésicos según necesidad. Control en 2 semanas si persiste.',
]);

Updating a Consultation

$consultation = Consultation::find(1);
$consultation->update([
    'clinical_findings' => 'Actualización de hallazgos clínicos',
    'diagnosis' => 'Diagnóstico actualizado después de pruebas',
]);

Querying Consultations

// Get all consultations for a patient
$patientConsultations = Consultation::where('patient_id', 1)
    ->with(['doctor', 'prescription', 'payment'])
    ->orderBy('created_at', 'desc')
    ->get();

// Get today's consultations for a doctor
$todayConsultations = Consultation::where('doctor_id', 5)
    ->whereDate('created_at', today())
    ->with('patient')
    ->get();

// Get consultations with abnormal vitals
$abnormalVitals = Consultation::where('bp_systolic', '>', 140)
    ->orWhere('bp_diastolic', '>', 90)
    ->orWhere('temperature', '>', 37.5)
    ->with('patient')
    ->get();

Working with Vital Signs

$consultation = Consultation::find(1);

// Calculate BMI
if ($consultation->weight && $consultation->height) {
    $heightInMeters = $consultation->height / 100;
    $bmi = $consultation->weight / ($heightInMeters * $heightInMeters);
    echo "BMI: " . round($bmi, 2);
}

// Check blood pressure status
if ($consultation->bp_systolic >= 140 || $consultation->bp_diastolic >= 90) {
    echo "Hypertensive reading detected";
}

// Format blood pressure
echo "BP: {$consultation->bp_systolic}/{$consultation->bp_diastolic} mmHg";

Creating Complete Consultation Record

// Create consultation with prescription and payment
$consultation = Consultation::create([
    'patient_id' => 1,
    'doctor_id' => 5,
    'appointment_id' => 10,
    'weight' => 68.0,
    'height' => 165.0,
    'temperature' => 38.2,
    'bp_systolic' => 115,
    'bp_diastolic' => 75,
    'heart_rate' => 88,
    'respiratory_rate' => 20,
    'oxygen_saturation' => 97,
    'reason_for_visit' => 'Fiebre y malestar general',
    'clinical_findings' => 'Faringitis aguda observada',
    'diagnosis' => 'Faringitis viral',
    'treatment_plan' => 'Reposo, hidratación, analgésicos',
]);

// Create prescription
$consultation->prescription()->create([
    'patient_id' => 1,
    'doctor_id' => 5,
    'items' => [
        [
            'medication' => 'Paracetamol',
            'dosage' => '500mg',
            'frequency' => 'Cada 6 horas',
            'duration' => '5 días',
        ],
    ],
    'general_instructions' => 'Tomar con alimentos',
]);

// Create payment
$consultation->payment()->create([
    'patient_id' => 1,
    'amount' => 500.00,
    'payment_method' => 'cash',
    'status' => 'paid',
]);

Eager Loading Complete Records

// Load consultation with all related data
$consultation = Consultation::with([
    'patient',
    'doctor',
    'appointment',
    'prescription.doctor',
    'payment'
])->find(1);

// Get patient's consultation history with prescriptions
$history = Consultation::where('patient_id', 1)
    ->with(['doctor', 'prescription'])
    ->orderBy('created_at', 'desc')
    ->get();

Statistics and Reports

// Get average vital signs for a patient
$avgVitals = Consultation::where('patient_id', 1)
    ->selectRaw('AVG(bp_systolic) as avg_systolic')
    ->selectRaw('AVG(bp_diastolic) as avg_diastolic')
    ->selectRaw('AVG(weight) as avg_weight')
    ->first();

// Count consultations by doctor
$consultationCount = Consultation::where('doctor_id', 5)
    ->whereMonth('created_at', now()->month)
    ->count();

Build docs developers (and LLMs) love