<?php

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

/** Rheumatology 1:1 patient extension on the shared ClinicCore patient. */
class CreateRheumatologyPatientProfilesTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('rheumatology_patient_profiles')) return;
        if (! Schema::hasTable('clc_patients')) return;

        Schema::create('rheumatology_patient_profiles', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('clc_patient_id');
            $table->integer('tender_joints')->nullable();
            $table->integer('swollen_joints')->nullable();
            $table->decimal('das28', 8, 2)->nullable();
            $table->string('rf_status', 40)->nullable();
            $table->timestamps();
            $table->unique('clc_patient_id');
            $table->foreign('clc_patient_id')->references('id')->on('clc_patients')->onDelete('cascade');
        });
    }

    public function down() { Schema::dropIfExists('rheumatology_patient_profiles'); }
}
