db->tableExists('ipd_master')) { $fields = []; if (! $this->db->fieldExists('admission_type', 'ipd_master')) { $fields['admission_type'] = [ 'type' => 'ENUM', 'constraint' => ['ipd', 'daycare', 'emergency'], 'default' => 'ipd', 'null' => false, 'after' => 'ipd_code', ]; } if (! $this->db->fieldExists('triage_level', 'ipd_master')) { $fields['triage_level'] = [ 'type' => 'TINYINT', 'constraint' => 1, 'null' => true, 'comment' => 'ESI Triage 1: Red, 2: Orange, 3: Yellow, 4: Green, 5: Blue', 'after' => 'admission_type', ]; } if (! $this->db->fieldExists('triage_time', 'ipd_master')) { $fields['triage_time'] = [ 'type' => 'DATETIME', 'null' => true, 'after' => 'triage_level', ]; } if (! $this->db->fieldExists('is_mlc', 'ipd_master')) { $fields['is_mlc'] = [ 'type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'null' => false, 'after' => 'triage_time', ]; } if (! $this->db->fieldExists('mlc_number', 'ipd_master')) { $fields['mlc_number'] = [ 'type' => 'VARCHAR', 'constraint' => 60, 'null' => true, 'after' => 'is_mlc', ]; } if (! $this->db->fieldExists('police_station', 'ipd_master')) { $fields['police_station'] = [ 'type' => 'VARCHAR', 'constraint' => 120, 'null' => true, 'after' => 'mlc_number', ]; } if (! $this->db->fieldExists('police_constable_details', 'ipd_master')) { $fields['police_constable_details'] = [ 'type' => 'VARCHAR', 'constraint' => 150, 'null' => true, 'after' => 'police_station', ]; } if (! $this->db->fieldExists('brought_by', 'ipd_master')) { $fields['brought_by'] = [ 'type' => 'VARCHAR', 'constraint' => 120, 'null' => true, 'after' => 'police_constable_details', ]; } if (! $this->db->fieldExists('daycare_procedure_name', 'ipd_master')) { $fields['daycare_procedure_name'] = [ 'type' => 'VARCHAR', 'constraint' => 255, 'null' => true, 'after' => 'brought_by', ]; } if (! $this->db->fieldExists('converted_from_type', 'ipd_master')) { $fields['converted_from_type'] = [ 'type' => 'VARCHAR', 'constraint' => 20, 'null' => true, 'after' => 'daycare_procedure_name', ]; } if (! $this->db->fieldExists('converted_from_code', 'ipd_master')) { $fields['converted_from_code'] = [ 'type' => 'VARCHAR', 'constraint' => 50, 'null' => true, 'after' => 'converted_from_type', ]; } if (! $this->db->fieldExists('converted_at', 'ipd_master')) { $fields['converted_at'] = [ 'type' => 'DATETIME', 'null' => true, 'after' => 'converted_from_code', ]; } if (! $this->db->fieldExists('conversion_reason', 'ipd_master')) { $fields['conversion_reason'] = [ 'type' => 'TEXT', 'null' => true, 'after' => 'converted_at', ]; } if (! $this->db->fieldExists('converted_by', 'ipd_master')) { $fields['converted_by'] = [ 'type' => 'INT', 'constraint' => 11, 'null' => true, 'after' => 'conversion_reason', ]; } if (! $this->db->fieldExists('sbar_handover', 'ipd_master')) { $fields['sbar_handover'] = [ 'type' => 'TEXT', 'null' => true, 'after' => 'converted_by', ]; } if (! $this->db->fieldExists('discharge_score', 'ipd_master')) { $fields['discharge_score'] = [ 'type' => 'INT', 'constraint' => 11, 'null' => true, 'comment' => 'PADSS or Modified Aldrete Score', 'after' => 'sbar_handover', ]; } if (! empty($fields)) { $this->forge->addColumn('ipd_master', $fields); } } // 2. Modify ward_master.ward_type to support 'Day Care' if ($this->db->tableExists('ward_master')) { $this->db->query(" ALTER TABLE `ward_master` MODIFY COLUMN `ward_type` ENUM( 'General', 'Private', 'Semi-Private', 'Deluxe', 'ICU', 'NICU', 'PICU', 'HDU', 'ICCU', 'CCU', 'Emergency', 'Day Care' ) NOT NULL DEFAULT 'General' "); // Seed default Emergency and Day Care wards if none exist $erWardCount = $this->db->table('ward_master')->where('ward_type', 'Emergency')->countAllResults(); if ($erWardCount === 0) { $this->db->table('ward_master')->insert([ 'ward_code' => 'ER-01', 'ward_name' => 'Casualty & Emergency Ward', 'ward_type' => 'Emergency', 'gender_type' => 'unisex', 'ward_category' => 'adult', 'total_capacity' => 6, 'floor_number' => 0, 'has_oxygen' => 1, 'has_suction' => 1, 'has_monitor' => 1, 'status' => 'active', 'remarks' => 'Default Casualty / Emergency triage and observation unit', 'created_at' => date('Y-m-d H:i:s'), ]); } $dcWardCount = $this->db->table('ward_master')->where('ward_type', 'Day Care')->countAllResults(); if ($dcWardCount === 0) { $this->db->table('ward_master')->insert([ 'ward_code' => 'DC-01', 'ward_name' => 'Day Care Unit', 'ward_type' => 'Day Care', 'gender_type' => 'unisex', 'ward_category' => 'adult', 'total_capacity' => 6, 'floor_number' => 1, 'has_oxygen' => 1, 'has_suction' => 1, 'has_monitor' => 1, 'status' => 'active', 'remarks' => 'Day Care short stay unit for minor surgeries, dialysis, and chemotherapy', 'created_at' => date('Y-m-d H:i:s'), ]); } } // 3. Ensure dedicated item types in ipd_item_type for separate billing headers if ($this->db->tableExists('ipd_item_type')) { $existingEr = $this->db->table('ipd_item_type') ->groupStart() ->like('desc', 'EMERGENCY') ->orLike('group_desc', 'Emergency') ->groupEnd() ->countAllResults(); if ($existingEr === 0) { $this->db->table('ipd_item_type')->insert([ 'desc' => 'EMERGENCY / CASUALTY CHARGES', 'group_desc' => 'Emergency / Casualty Charges', ]); } $existingDc = $this->db->table('ipd_item_type') ->groupStart() ->like('desc', 'DAY CARE') ->orLike('group_desc', 'Day Care') ->groupEnd() ->countAllResults(); if ($existingDc === 0) { $this->db->table('ipd_item_type')->insert([ 'desc' => 'DAY CARE CHARGES', 'group_desc' => 'Day Care Charges', ]); } } // 4. Seed default Day Care Discharge Summary Template if ($this->db->tableExists('ipd_discharge_templates')) { $dcTemplateExists = $this->db->table('ipd_discharge_templates') ->where('template_name', 'Day Care Discharge Summary') ->countAllResults(); if ($dcTemplateExists === 0) { $dcHtml = '{{DAYCARE_HEADER}}' . '
| Patient Name: {{PATIENT_NAME}} | ' . 'UHID: {{UHID}} | ' . 'Day Care No.: {{IPD_CODE}} | ' . '
| Age / Gender: {{AGE_GENDER}} | ' . 'Guardian: {{GUARDIAN_RELATION}}{{GUARDIAN_NAME}} | ' . 'Phone: {{PATIENT_MOBILE}} | ' . '
| Admission: {{ADMIT_DATE}} | ' . 'Discharge: {{DISCHARGE_DATE}} | ' . 'Attending Doctor: {{DOCTOR_NAMES}} | ' . '