clqms-be/app/Models/ValueSet/ValueSetDefModel.php
mahdahar a94df3b5f7 **feat: migrate to v2 frontend with Alpine.js pattern**
- Introduce v2 views directory with Alpine.js-based UI components
- Add AuthV2 controller for v2 authentication flow
- Update PagesController for v2 routing
- Refactor ValueSet module with v2 dialogs and nested CRUD views
- Add organization management views (accounts, departments, disciplines, sites, workstations)
- Add specimen management views (containers, preparations)
- Add master views for tests and valuesets
- Migrate patient views to v2 pattern
- Update Routes and Exceptions config for v2 support
- Enhance CORS configuration
- Clean up legacy files (check_db.php, llms.txt, sanity.php, old views)
- Update agent workflow patterns for PHP Alpine.js
2025-12-30 14:30:35 +07:00

43 lines
1.2 KiB
PHP

<?php
namespace App\Models\ValueSet;
use App\Models\BaseModel;
class ValueSetDefModel extends BaseModel {
protected $table = 'valuesetdef';
protected $primaryKey = 'VSetID';
protected $allowedFields = ['SiteID', 'VSName', 'VSDesc', 'CreateDate', 'EndDate'];
protected $useTimestamps = true;
protected $createdField = 'CreateDate';
protected $updatedField = '';
protected $useSoftDeletes = true;
protected $deletedField = 'EndDate';
public function getValueSetDefs($param = null) {
// Get item counts subquery
$itemCounts = $this->db->table('valueset')
->select('VSetID, COUNT(*) as ItemCount')
->where('EndDate IS NULL')
->groupBy('VSetID');
$builder = $this->db->table('valuesetdef vd');
$builder->select('vd.*, COALESCE(ic.ItemCount, 0) as ItemCount');
$builder->join("({$itemCounts->getCompiledSelect()}) ic", 'vd.VSetID = ic.VSetID', 'LEFT');
$builder->where('vd.EndDate IS NULL');
if ($param !== null) {
$builder->groupStart()
->like('vd.VSName', $param, 'both')
->orLike('vd.VSDesc', $param, 'both')
->groupEnd();
}
$rows = $builder->get()->getResultArray();
return $rows;
}
}