tinyqc/app/Models/Qc/ControlTestsModel.php
mahdahar dd7a058511 feat: Implement Monthly Entry interface and consolidate Entry API controller
- New EntryApiController (app/Controllers/Api/EntryApiController.php)
    - Centralized API for entry operations (daily/monthly data retrieval and saving)
    - getControls() - Fetch controls with optional date-based expiry filtering
    - getTests() - Get tests associated with a control
    - getDailyData() - Retrieve daily results for a date/control
    - getMonthlyData() - Retrieve monthly results with per-day data and comments
    - saveDaily() - Batch save daily results with validation
    - saveMonthly() - Batch save monthly results with statistics
  - New Monthly Entry View (app/Views/entry/monthly.php)
    - Calendar grid interface for entering monthly QC results
    - Month selector with quick navigation (prev/next/current)
    - Test selector to filter controls
    - 31-day grid per control with inline editing
    - Visual QC range indicators (green for in-range, red for out-of-range)
    - Weekend highlighting
    - Per-control monthly comment field
    - Keyboard shortcut (Ctrl+S) for saving
    - Change tracking with pending save indicator
  - Route Updates (app/Config/Routes.php)
    - Added /entry/monthly page route
    - Added /api/entry/daily GET endpoint
  - Model Updates
    - ResultsModel: Added updateMonthly() for upserting monthly results
    - ResultCommentsModel: Added upsertMonthly() for monthly comments
2026-01-20 16:47:11 +07:00

121 lines
3.6 KiB
PHP

<?php
namespace App\Models\Qc;
use App\Models\BaseModel;
class ControlTestsModel extends BaseModel {
protected $table = 'control_tests';
protected $primaryKey = 'control_test_id';
protected $allowedFields = [
'control_id',
'test_id',
'mean',
'sd',
'created_at',
'updated_at',
'deleted_at'
];
protected $useTimestamps = true;
protected $useSoftDeletes = true;
public function search($keyword = null) {
if ($keyword) {
return $this->groupStart()
->like('mean', $keyword)
->groupEnd()
->findAll();
}
return $this->findAll();
}
/**
* Get control-test with control and test details
*/
public function getWithDetails(int $controlTestId): ?array {
$builder = $this->db->table('control_tests ct');
$builder->select('
ct.control_test_id as id,
ct.control_id as controlId,
ct.test_id as testId,
ct.mean,
ct.sd,
c.control_name as controlName,
c.lot,
t.test_name as testName,
t.test_unit as testUnit
');
$builder->join('master_controls c', 'c.control_id = ct.control_id');
$builder->join('master_tests t', 't.test_id = ct.test_id');
$builder->where('ct.control_test_id', $controlTestId);
$builder->where('ct.deleted_at', null);
return $builder->get()->getRowArray() ?: null;
}
/**
* Get tests for a control with QC parameters
*/
public function getByControl(int $controlId): array {
$builder = $this->db->table('control_tests ct');
$builder->select('
ct.control_test_id as id,
ct.control_id as controlId,
ct.test_id as testId,
ct.mean,
ct.sd,
t.test_name as testName,
t.test_unit as testUnit
');
$builder->join('master_tests t', 't.test_id = ct.test_id');
$builder->where('ct.control_id', $controlId);
$builder->where('ct.deleted_at', null);
$builder->where('t.deleted_at', null);
$builder->orderBy('t.test_name', 'ASC');
return $builder->get()->getResultArray();
}
/**
* Get controls for a test with QC parameters
*/
public function getByTest(int $testId): array {
$builder = $this->db->table('control_tests ct');
$builder->select('
ct.control_test_id as id,
ct.control_id as controlId,
ct.test_id as testId,
ct.mean,
ct.sd,
c.control_name as controlName,
c.lot,
c.producer
');
$builder->join('master_controls c', 'c.control_id = ct.control_id');
$builder->where('ct.test_id', $testId);
$builder->where('ct.deleted_at', null);
$builder->where('c.deleted_at', null);
$builder->orderBy('c.control_name', 'ASC');
return $builder->get()->getResultArray();
}
/**
* Get by control and test
*/
public function getByControlAndTest(int $controlId, int $testId): ?array {
$builder = $this->db->table('control_tests ct');
$builder->select('
ct.control_test_id as id,
ct.control_id as controlId,
ct.test_id as testId,
ct.mean,
ct.sd
');
$builder->where('ct.control_id', $controlId);
$builder->where('ct.test_id', $testId);
$builder->where('ct.deleted_at', null);
return $builder->get()->getRowArray() ?: null;
}
}