<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddVitalsSoapToVcAppointments extends Migration
{
    public function up()
    {
        Schema::table('vc_appointments', function (Blueprint $table) {
            if (!Schema::hasColumn('vc_appointments', 'temperature'))
                $table->decimal('temperature', 4, 1)->nullable()->after('weight_kg');
            if (!Schema::hasColumn('vc_appointments', 'heart_rate'))
                $table->unsignedSmallInteger('heart_rate')->nullable()->after('temperature');
            if (!Schema::hasColumn('vc_appointments', 'respiratory_rate'))
                $table->unsignedSmallInteger('respiratory_rate')->nullable()->after('heart_rate');
            if (!Schema::hasColumn('vc_appointments', 'soap_subjective'))
                $table->text('soap_subjective')->nullable()->after('respiratory_rate');
            if (!Schema::hasColumn('vc_appointments', 'soap_objective'))
                $table->text('soap_objective')->nullable()->after('soap_subjective');
            if (!Schema::hasColumn('vc_appointments', 'soap_assessment'))
                $table->text('soap_assessment')->nullable()->after('soap_objective');
            if (!Schema::hasColumn('vc_appointments', 'soap_plan'))
                $table->text('soap_plan')->nullable()->after('soap_assessment');
        });
    }

    public function down()
    {
        Schema::table('vc_appointments', function (Blueprint $table) {
            $table->dropColumn(['temperature', 'heart_rate', 'respiratory_rate',
                                'soap_subjective', 'soap_objective', 'soap_assessment', 'soap_plan']);
        });
    }
}
