devsofttech_hms_ci4/app/Controllers/AbdmBridgeLog.php
DevSoftTech Server 23cca1f9ba feat(abdm): proper FHIR bundles for lab reports and IPD discharge
- FhirR4Builder: rewrite buildLabReportBundle() with DiagnosticReportLab
  profile, structured Observation valueQuantity/valueString, reference
  ranges, interpretation codes, Binary+DocumentReference for HTML report,
  Encounter resource, HFR-based bundle identifier system

- FhirR4Builder: rewrite buildDischargeSummaryBundle() with optional
  Practitioner/Organization params, structured ABDM sections (chief
  complaints 422843007, medical history 1003642006, investigations
  721981007, procedures 1003640003, medications 721912009, follow-up
  736271009), HFR-based bundle identifier system

- AbdmGateway: shareIpdDischargeBundle() now builds a real
  DischargeSummaryRecord FHIR bundle and posts via pushRecord()
  (POST /v3/records/push) instead of the stale shareIpdDischargeBundle()

- AbdmGateway: shareDiagnosisReportBundle() now builds a real
  DiagnosticReportRecord FHIR bundle and posts via pushRecord()
  instead of the stale shareDiagnosisReportBundle()

- AbdmGateway: add getHospitalProfileForFhir() and mapLabTypeToTitle()
  helpers; fix pre-existing undefined \ bug in
  getActiveConsentRecord()

- Add ABDM_FHIR reference package, AbdmBridgeLog controller/view,
  bridge record migration, debug scripts and misc UI/settings updates
2026-05-23 04:41:59 +05:30

102 lines
3.4 KiB
PHP

<?php
namespace App\Controllers;
class AbdmBridgeLog extends BaseController
{
// Route filter (permission:abdm.*) handles auth — no secondary check needed.
public function index()
{
return view('abdm/bridge_log');
}
/**
* AJAX: paginated log rows with filters.
* GET AbdmBridgeLog/list
*/
public function list()
{
$db = \Config\Database::connect();
$builder = $db->table('abdm_api_logs');
$channel = trim((string) $this->request->getGet('channel'));
$status = trim((string) $this->request->getGet('status'));
$search = trim((string) $this->request->getGet('search'));
$dateFrom = trim((string) $this->request->getGet('date_from'));
$dateTo = trim((string) $this->request->getGet('date_to'));
$page = max(1, (int) $this->request->getGet('page'));
$perPage = 50;
if ($channel !== '') {
$builder->where('channel', $channel);
}
if ($status !== '') {
$builder->where('status', $status);
}
if ($search !== '') {
$builder->groupStart()
->like('event_type', $search)
->orLike('entity_id', $search)
->orLike('endpoint', $search)
->groupEnd();
}
if ($dateFrom !== '') {
$builder->where('created_at >=', $dateFrom . ' 00:00:00');
}
if ($dateTo !== '') {
$builder->where('created_at <=', $dateTo . ' 23:59:59');
}
$total = (clone $builder)->countAllResults(false);
$rows = $builder
->select('id, channel, event_type, endpoint, http_method, entity_type, entity_id, response_code, status, error_message, created_at')
->orderBy('id', 'DESC')
->limit($perPage, ($page - 1) * $perPage)
->get()
->getResultArray();
return $this->response->setJSON([
'ok' => 1,
'rows' => $rows,
'total' => $total,
'page' => $page,
'per_page' => $perPage,
'pages' => (int) ceil($total / $perPage),
'csrfName' => csrf_token(),
'csrfHash' => csrf_hash(),
]);
}
/**
* AJAX: full request + response JSON for one log entry.
* GET AbdmBridgeLog/detail/(:num)
*/
public function detail(int $id)
{
$db = \Config\Database::connect();
$row = $db->table('abdm_api_logs')
->select('id, channel, event_type, endpoint, http_method, entity_type, entity_id, request_json, response_code, response_json, status, error_message, created_at')
->where('id', $id)
->get()
->getRowArray();
if ($row === null) {
return $this->response->setStatusCode(404)->setJSON(['ok' => 0, 'error_text' => 'Log entry not found']);
}
// Pretty-print JSON strings for the UI
foreach (['request_json', 'response_json'] as $field) {
if ($row[$field] !== null) {
$decoded = json_decode($row[$field], true);
$row[$field] = is_array($decoded)
? json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
: $row[$field];
}
}
return $this->response->setJSON(['ok' => 1, 'row' => $row]);
}
}