<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class HostAppCodingSysSeeder extends Seeder
{
  public function run()
  {
    $now = date('Y-m-d H:i:s');

    // Clear existing data first (avoid foreign key constraint issues by ordering)
    $this->db->table('hostcompara')->emptyTable();
    $this->db->table('hostapp')->emptyTable();
    $this->db->table('codingsys')->emptyTable();

    // HostApp - Host Applications
    $hostAppData = [
      [
        'HostAppID' => 1,
        'HostAppName' => 'Laboratory Information System Main',
        'SiteID' => 1,
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 2,
        'HostAppName' => 'Laboratory Information System Backup',
        'SiteID' => 1,
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 3,
        'HostAppName' => 'Electronic Medical Record System',
        'SiteID' => 1,
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 4,
        'HostAppName' => 'Picture Archiving System',
        'SiteID' => 1,
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 5,
        'HostAppName' => 'Billing System',
        'SiteID' => 1,
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 6,
        'HostAppName' => 'Insurance System Integration',
        'SiteID' => 1,
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 7,
        'HostAppName' => 'Legacy Laboratory System',
        'SiteID' => 1,
        'CreateDate' => $now,
        'EndDate' => date('Y-m-d H:i:s', strtotime('-1 year'))
      ],
    ];
    $this->db->table('hostapp')->insertBatch($hostAppData);

    // HostComPara - Host Communication Parameters
    $hostComParaData = [
      [
        'HostAppID' => 1,
        'HostIP' => '192.168.1.10',
        'HostPort' => '8080',
        'HostPwd' => 'lis_main_pass_2024',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 2,
        'HostIP' => '192.168.1.11',
        'HostPort' => '8081',
        'HostPwd' => 'lis_backup_pass_2024',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 3,
        'HostIP' => '192.168.1.20',
        'HostPort' => '443',
        'HostPwd' => 'emr_secure_2024',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 4,
        'HostIP' => '192.168.1.30',
        'HostPort' => '8042',
        'HostPwd' => 'pacs_dicom_2024',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 5,
        'HostIP' => '192.168.1.40',
        'HostPort' => '8443',
        'HostPwd' => 'bill_payment_2024',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 6,
        'HostIP' => '192.168.1.50',
        'HostPort' => '443',
        'HostPwd' => 'ins_claim_2024',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'HostAppID' => 7,
        'HostIP' => '192.168.1.99',
        'HostPort' => '8080',
        'HostPwd' => 'old_legacy_pass',
        'CreateDate' => $now,
        'EndDate' => date('Y-m-d H:i:s', strtotime('-1 year'))
      ],
    ];
    $this->db->table('hostcompara')->insertBatch($hostComParaData);

    // CodingSys - Coding Systems
    $codingSysData = [
      [
        'CodingSysAbb' => 'ICD10',
        'FullText' => 'International Classification of Diseases 10th Revision',
        'Description' => 'Medical diagnosis coding system for diseases and health conditions',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'ICD10PCS',
        'FullText' => 'ICD-10 Procedure Coding System',
        'Description' => 'Classification system for inpatient hospital procedures',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'LOINC',
        'FullText' => 'Logical Observation Identifiers Names and Codes',
        'Description' => 'Standard for identifying medical laboratory observations',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'SNOMED',
        'FullText' => 'SNOMED CT',
        'Description' => 'Systematized Nomenclature of Medicine - Clinical Terms',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'CPT',
        'FullText' => 'Current Procedural Terminology',
        'Description' => 'Medical code set for medical procedures and services',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'HCPCS',
        'FullText' => 'Healthcare Common Procedure Coding System',
        'Description' => 'Medical code set for equipment, supplies, and services',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'RXNORM',
        'FullText' => 'RxNorm',
        'Description' => 'Normalized naming system for medications',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'NDC',
        'FullText' => 'National Drug Code',
        'Description' => 'Unique identifier for human drugs in the United States',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'UCUM',
        'FullText' => 'Unified Code for Units of Measure',
        'Description' => 'Standard for units of measurement in clinical and scientific contexts',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'CVX',
        'FullText' => 'Vaccines Administered',
        'Description' => 'Vaccine codes for immunization records',
        'CreateDate' => $now,
        'EndDate' => null
      ],
      [
        'CodingSysAbb' => 'ICD9',
        'FullText' => 'International Classification of Diseases 9th Revision',
        'Description' => 'Legacy medical diagnosis coding system',
        'CreateDate' => $now,
        'EndDate' => date('Y-m-d H:i:s', strtotime('-2 years'))
      ],
      [
        'CodingSysAbb' => 'ICD9CM',
        'FullText' => 'ICD-9-CM',
        'Description' => 'Legacy procedure coding system',
        'CreateDate' => $now,
        'EndDate' => date('Y-m-d H:i:s', strtotime('-2 years'))
      ],
    ];
    $this->db->table('codingsys')->insertBatch($codingSysData);
  }
}
