devsofttech_hms_ci4/app/Libraries/Abdm/DirectAbdmConnector.php
DevSoftTech Server 0628f8f813 feat: ABDM OPD Queue + ABHA Register flow + patient ABHA search fix
ABDM OPD Queue (today):
- New EAtriaBridgeConnector: opdQueueFetch/opdTokenCreate/opdTokenUpdateStatus + patch() helper
- New AbdmOpdQueue controller: index/list/fetchQueue/createToken/updateTokenStatus/processScannedToken
  - fetchQueue syncs gateway tokens into abdm_opd_tokens (local DB) and enriches with HMS patient data
  - processScannedToken auto-finds/creates patient_master record from ABHA scan data, marks token CALLED
- New migration: abdm_opd_tokens table (gateway_token_id, source, status, patient_id, opd_id, processed_at)
- New view: abdm/opd_queue.php - reception screen with auto-refresh 30s, HMS Patient column (green row when OPD registered)
- Sidebar: ABDM OPD Queue nav link added
- Routes: AbdmOpdQueue with abdmPermFilter

ABHA Register tab (earlier this session):
- New Abha controller: initiate/verifyOtp/communication/verifyCommOtp/validateAbha/card + autoCreateOrFindPatient
- New views: abha/card.php, partials/abha_create_panel.php, partials/abha_otp_modal.php
- Patient_V.php: ABHA Register tab with 4-method wizard (ABHA number, QR scan, facility QR, mobile OTP)

Patient ABHA search fix:
- Patient::search() now detects ABHA column (abha_id/abha_no/abha/abha_address) and searches by it

ABDM Bridge infrastructure:
- EAtriaBridgeConnector: new connector for e-atria.in ABDM bridge gateway
- AbdmConnectorFactory/Interface updated
- AbdmGatewaySettings controller + view
- SNOMED/CSNOTK terminology service skeleton
- Finance payout OPD consult views
- Migration: AddAbdmPushFieldsToOpdAndPatient, CreateSnomedCoreTables
- Docs: abdm/ API specs, architecture, gateway guides
2026-05-16 04:21:31 +05:30

192 lines
7.0 KiB
PHP

<?php
namespace App\Libraries\Abdm;
/**
* DirectAbdmConnector
*
* Future adapter — calls ABDM / NHA APIs directly without any middleware.
* All methods currently throw RuntimeException with TODO notes.
*
* To activate: set env abdm.connector = direct_abdm and implement each method.
*
* Required env / Config\AbdmConnector keys:
* directAbdmBaseUrl e.g. 'https://dev.abdm.gov.in/api/v3'
* directAbdmClientId ABDM M3 client ID
* directAbdmClientSecret ABDM M3 client secret
* directAbdmTimeoutSec HTTP timeout in seconds (default 30)
*
* Reference ABDM IG: https://nrces.in/ndhm/fhir/r4/index.html
*/
class DirectAbdmConnector implements AbdmConnectorInterface
{
private string $baseUrl;
private string $clientId;
private string $clientSecret;
private int $timeoutSec;
public function __construct()
{
$config = config('AbdmConnector');
$this->baseUrl = rtrim((string) ($config->directAbdmBaseUrl ?? ''), '/');
$this->clientId = (string) ($config->directAbdmClientId ?? '');
$this->clientSecret = (string) ($config->directAbdmClientSecret ?? '');
$this->timeoutSec = (int) ($config->directAbdmTimeoutSec ?? 30);
}
public function getConnectorName(): string
{
return 'direct_abdm';
}
// -------------------------------------------------------------------------
// ABHA
// -------------------------------------------------------------------------
public function validateAbha(string $abhaId, array $fullPayload = []): array
{
// TODO: Obtain M3 access token, then call:
// POST {baseUrl}/v1/search/existsByHealthId
// Body: { "healthId": $abhaId }
// Reference: ABDM M3 ABHA search API
throw new \RuntimeException(
'DirectAbdmConnector::validateAbha() not implemented. '
. 'TODO: POST /v1/search/existsByHealthId with ABHA ID.'
);
}
// -------------------------------------------------------------------------
// Consent
// -------------------------------------------------------------------------
public function requestConsent(
int $patientId,
string $abhaId,
string $purposeCode,
string $expiresAt,
string $consentHandle,
array $rawPayload = []
): array {
// TODO: Obtain M3 access token, then call:
// POST {baseUrl}/v0.5/consent-requests/init
// Body: ConsentRequest FHIR resource per ABDM IG
throw new \RuntimeException(
'DirectAbdmConnector::requestConsent() not implemented. '
. 'TODO: POST /v0.5/consent-requests/init.'
);
}
// -------------------------------------------------------------------------
// Health Record Sharing
// -------------------------------------------------------------------------
public function sharePrescriptionBundle(array $payload, string $entityId = ''): array
{
// TODO: Encrypt FHIR bundle using HIP public key, then call:
// POST {baseUrl}/v0.5/health-information/hip/on-request
// Reference: ABDM IG — HIP-initiated record push
throw new \RuntimeException(
'DirectAbdmConnector::sharePrescriptionBundle() not implemented. '
. 'TODO: Encrypt bundle and POST /v0.5/health-information/hip/on-request.'
);
}
public function shareIpdDischargeBundle(array $payload, string $entityId = ''): array
{
// TODO: Same flow as sharePrescriptionBundle but bundle_type = DischargeSummaryBundle
throw new \RuntimeException(
'DirectAbdmConnector::shareIpdDischargeBundle() not implemented. '
. 'TODO: Encrypt bundle and POST /v0.5/health-information/hip/on-request.'
);
}
public function shareDiagnosisReportBundle(array $payload, string $entityId = ''): array
{
// TODO: Same flow as sharePrescriptionBundle but bundle_type = DiagnosticReportBundle
throw new \RuntimeException(
'DirectAbdmConnector::shareDiagnosisReportBundle() not implemented. '
. 'TODO: Encrypt bundle and POST /v0.5/health-information/hip/on-request.'
);
}
// -------------------------------------------------------------------------
// M1 ABHA OTP Flows
// -------------------------------------------------------------------------
public function abhaAadhaarGenerateOtp(array $payload): array
{
throw new \RuntimeException(
'DirectAbdmConnector::abhaAadhaarGenerateOtp() not implemented. '
. 'Use EAtriaBridgeConnector (eatria_bridge) for M1 OTP flows.'
);
}
public function abhaAadhaarVerifyOtp(array $payload): array
{
throw new \RuntimeException(
'DirectAbdmConnector::abhaAadhaarVerifyOtp() not implemented.'
);
}
public function abhaMobileGenerateOtp(array $payload): array
{
throw new \RuntimeException(
'DirectAbdmConnector::abhaMobileGenerateOtp() not implemented.'
);
}
public function abhaMobileVerifyOtp(array $payload): array
{
throw new \RuntimeException(
'DirectAbdmConnector::abhaMobileVerifyOtp() not implemented.'
);
}
// -------------------------------------------------------------------------
// Scan & Share
// -------------------------------------------------------------------------
public function scanShareLookup(string $qrPayload, string $abhaIdHint = '', array $fullPayload = []): array
{
// TODO: Decode QR token, then call:
// POST {baseUrl}/v1.0/hip/patient/scan-share/profile
// Body: { "token": $qrPayload }
throw new \RuntimeException(
'DirectAbdmConnector::scanShareLookup() not implemented. '
. 'TODO: POST /v1.0/hip/patient/scan-share/profile with decoded QR token.'
);
}
// -------------------------------------------------------------------------
// NHCX Claims
// -------------------------------------------------------------------------
public function nhcxClaimCreate(
array $bundle,
int $documentId,
int $patientId,
int $encounterId
): array {
// TODO: Obtain NHCX access token (separate from ABDM), then call:
// POST {nhcxBaseUrl}/v0.5/nhcx/claim
// Body: FHIR Claim bundle
throw new \RuntimeException(
'DirectAbdmConnector::nhcxClaimCreate() not implemented. '
. 'TODO: POST NHCX /v0.5/nhcx/claim with FHIR Claim bundle.'
);
}
public function nhcxClaimStatusRequest(
int $documentId,
string $externalRef,
string $currentStatus,
array $fullPayload = []
): array {
// TODO: POST {nhcxBaseUrl}/v0.5/nhcx/claim/status with external_ref
throw new \RuntimeException(
'DirectAbdmConnector::nhcxClaimStatusRequest() not implemented. '
. 'TODO: POST NHCX /v0.5/nhcx/claim/status.'
);
}
}