diff --git a/TODO.md b/TODO.md index 0249883..9f3d6ac 100644 --- a/TODO.md +++ b/TODO.md @@ -1,11 +1,9 @@ # Project Checklist: Glen RME & Lab Management System -**Last Updated:** 20260204 +**Last Updated:** 20260205 Pending: - Test and fix Reprint label -- Test and fix PDF Generation -- Print Result Audit (Track when result reports are printed/exported, log user and timestamp) Completed: - Update User Role levels (Standardize roles: Superuser, Admin, Lab, Phlebo, CS) @@ -35,4 +33,6 @@ Completed: - Auto generate PDF on second val - Validate delay when loading result - Reprint Label (Add functionality to reprint labels) -- Create Eng Result UI UX on request dashboard \ No newline at end of file +- Create Eng Result UI UX on request dashboard +- Test and fix PDF Generation +- Print Result Audit (Track when result reports are printed/exported, log user and timestamp) \ No newline at end of file diff --git a/app/Controllers/ApiRequestsAuditController.php b/app/Controllers/ApiRequestsAuditController.php index a2cb81b..1622a16 100644 --- a/app/Controllers/ApiRequestsAuditController.php +++ b/app/Controllers/ApiRequestsAuditController.php @@ -13,7 +13,8 @@ class ApiRequestsAuditController extends BaseController { 'accessnumber' => $accessnumber, 'validation' => [], 'sample_collection' => [], - 'tube_received' => [] + 'tube_received' => [], + 'pdf_generation' => [] ]; $sqlAudit = "SELECT EVENT_TYPE, USERID, EVENT_AT, REASON @@ -63,6 +64,21 @@ class ApiRequestsAuditController extends BaseController { ]; } + $sqlRequests = "SELECT STEPTYPE, STEPDATE, STEPSTATUS + FROM GDC_CMOD.dbo.AUDIT_REQUESTS + WHERE ACCESSNUMBER = ? AND STEPTYPE IN ('PRINT', 'GEN_PDF', 'REGEN_PDF') + ORDER BY STEPDATE ASC"; + $requestRows = $db->query($sqlRequests, [$accessnumber])->getResultArray(); + + foreach ($requestRows as $row) { + $result['pdf_generation'][] = [ + 'type' => $row['STEPTYPE'], + 'status' => trim($row['STEPSTATUS']), + 'datetime' => $row['STEPDATE'] ? date('Y-m-d H:i:s', strtotime($row['STEPDATE'])) : null, + 'user' => session()->get('userid') + ]; + } + return $this->respond(['status' => 'success', 'data' => $result]); } } diff --git a/app/Controllers/ReportController.php b/app/Controllers/ReportController.php index 90e08bd..882d641 100644 --- a/app/Controllers/ReportController.php +++ b/app/Controllers/ReportController.php @@ -20,14 +20,16 @@ class ReportController extends BaseController if ($ispdf == 0) { $ispdf = $this->request->getVar('ispdf') ?? 0; } - - if ($eng == 0) { - // Read REPORT_LANG from CM_REQUESTS if not provided + + $engQuery = $this->request->getVar('eng'); + if ($engQuery !== null) { + $eng = (int) $engQuery; + } elseif ($eng == 0) { $sql = "SELECT REPORT_LANG FROM GDC_CMOD.dbo.CM_REQUESTS WHERE ACCESSNUMBER=?"; $row = $this->db->query($sql, [$accessnumber])->getRowArray(); $eng = $row['REPORT_LANG'] ?? 0; } - + return $this->renderReport($accessnumber, $eng, $ispdf, false); } @@ -36,14 +38,16 @@ class ReportController extends BaseController if ($ispdf == 0) { $ispdf = $this->request->getVar('ispdf') ?? 0; } - - if ($eng == 0) { - // Read REPORT_LANG from CM_REQUESTS if not provided + + $engQuery = $this->request->getVar('eng'); + if ($engQuery !== null) { + $eng = (int) $engQuery; + } elseif ($eng == 0) { $sql = "SELECT REPORT_LANG FROM GDC_CMOD.dbo.CM_REQUESTS WHERE ACCESSNUMBER=?"; $row = $this->db->query($sql, [$accessnumber])->getRowArray(); $eng = $row['REPORT_LANG'] ?? 0; } - + return $this->renderReport($accessnumber, $eng, $ispdf, true); } @@ -116,12 +120,25 @@ class ReportController extends BaseController try { $jobId = $this->postToSpooler($html, $filename, $collectionDate); + + $sqlCheck = "SELECT COUNT(*) as cnt FROM GDC_CMOD.dbo.AUDIT_REQUESTS + WHERE ACCESSNUMBER = ? AND STEPTYPE IN ('GEN_PDF', 'REGEN_PDF')"; + $result = $this->db->query($sqlCheck, [$accessnumber])->getRowArray(); + + $stepType = ($result['cnt'] > 0) ? 'REGEN_PDF' : 'GEN_PDF'; + $stepStatus = $eng == 1 ? 'English' : 'Indonesian'; + + $sqlLog = "INSERT INTO GDC_CMOD.dbo.AUDIT_REQUESTS(ACCESSNUMBER, STEPDATE, STEPTYPE, STEPSTATUS) + VALUES (?, GETDATE(), ?, ?)"; + $this->db->query($sqlLog, [$accessnumber, $stepType, $stepStatus]); + return $this->response->setJSON([ 'success' => true, 'jobId' => $jobId, 'message' => 'PDF queued for generation', 'status' => 'queued', - 'lang' => $eng == 1 ? 'English' : 'Indonesian' + 'lang' => $eng == 1 ? 'English' : 'Indonesian', + 'isRegen' => ($stepType === 'REGEN_PDF') ]); } catch (\Exception $e) { log_message('error', "PDF generation failed: " . $e->getMessage()); diff --git a/app/Views/shared/dialog_audit.php b/app/Views/shared/dialog_audit.php index e899c0e..b9a0a0f 100644 --- a/app/Views/shared/dialog_audit.php +++ b/app/Views/shared/dialog_audit.php @@ -26,6 +26,9 @@ +
- Generating PDF... -
-Please wait
-Select language and click Generate PDF
-Indonesian PDF is automatically generated after validation.
-PDF Generation Failed
- -