<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('resultraw', function (Blueprint $table) {
            // Header Record
            $table->id();
            $table->string('sender_name')->nullable();
            $table->string('version_number')->nullable();
            $table->timestamp('message_datetime')->nullable();
            
            // Patient Record
            $table->string('patient_id')->nullable();
            $table->string('patient_name_last')->nullable();
            $table->string('patient_name_first')->nullable();
            $table->string('patient_name_middle')->nullable();
            $table->string('patient_name_suffix')->nullable();
            $table->string('patient_name_title')->nullable();
            $table->timestamp('patient_dob')->nullable();
            $table->string('patient_sex')->nullable();
            $table->string('address_street')->nullable();
            $table->string('address_city')->nullable();
            $table->string('address_state')->nullable();
            $table->string('address_zip')->nullable();
            $table->string('address_country')->nullable();
            $table->string('patient_phone')->nullable();
            $table->string('admitting_physician')->nullable();
            $table->text('patient_diagnosis')->nullable();
            $table->json('patient_therapy')->nullable(); // For patient therapies
            $table->timestamp('admit_datetime')->nullable();
            $table->string('room_number')->nullable();
            $table->string('hospital_service')->nullable();
            $table->string('hospital_client')->nullable();

            // Order Record
            $table->string('accession_number')->nullable();
            $table->string('isolate_number')->nullable();
            $table->string('organism')->nullable();
            $table->string('specimen_type')->nullable();
            $table->string('body_site')->nullable();
            $table->boolean('exclude_isolate_from_statistics')->nullable();
            $table->string('test_id')->nullable();

            // Result Record
            $table->string('result_type_code')->nullable();
            $table->string('antibiotic')->nullable();
            $table->string('antibiotic_concentration')->nullable();
            $table->string('antibiotic_concentration_units')->nullable();
            $table->string('test_status')->nullable();
            $table->text('result_data')->nullable();
            $table->string('preliminary_final_status')->nullable();
            $table->timestamp('test_start_datetime')->nullable();
            $table->timestamp('result_status_datetime')->nullable();
            $table->timestamp('test_complete_datetime')->nullable();
            $table->timestamp('media_setup_datetime')->nullable();
            $table->string('instrument_type')->nullable();
            $table->string('media_assay_type')->nullable();
            $table->string('protocol_length')->nullable();
            $table->string('instrument_number')->nullable();
            $table->string('instrument_location')->nullable();
            $table->string('protocol_name')->nullable();
            $table->json('additional_result')->nullable(); // To handle multiple results (1-5)

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('resultraw');
    }
};
