From 51da7b068ecd2271b9fa05fc8b00bad69c340d26 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 28 Jul 2026 20:55:01 +0530 Subject: [PATCH] Add diagnostic to probe candidate care-context-link bridge endpoints --- check_care_context_link_endpoint.php | 103 +++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 check_care_context_link_endpoint.php diff --git a/check_care_context_link_endpoint.php b/check_care_context_link_endpoint.php new file mode 100644 index 0000000..ac85edc --- /dev/null +++ b/check_care_context_link_endpoint.php @@ -0,0 +1,103 @@ +connect_errno) { + fwrite(STDERR, "DB connect failed: " . $mysqli->connect_error . "\n"); + exit(1); +} + +$settings = []; +$res = $mysqli->query("SELECT s_name, s_value FROM hospital_setting WHERE s_name IN ('EATRIA_BRIDGE_URL','EATRIA_BRIDGE_TOKEN','ABDM_HFR_ID','H_HFR_ID')"); +while ($row = $res->fetch_assoc()) { + $settings[$row['s_name']] = $row['s_value']; +} + +$baseUrl = rtrim($settings['EATRIA_BRIDGE_URL'] ?? '', '/'); +$token = trim($settings['EATRIA_BRIDGE_TOKEN'] ?? ''); +$hfrId = trim($settings['ABDM_HFR_ID'] ?? ($settings['H_HFR_ID'] ?? '')); + +echo "Base URL: {$baseUrl}\n"; +echo "HFR ID: {$hfrId}\n"; +echo "Token configured: " . ($token !== '' ? 'yes (len=' . strlen($token) . ')' : 'NO') . "\n\n"; + +if ($baseUrl === '' || $token === '') { + fwrite(STDERR, "Missing bridge URL or token in hospital_setting; aborting.\n"); + exit(1); +} + +$paths = [ + '/api/v1/abdm/gateway/care-context/link', + '/api/v3/care-context/link', + '/api/v3/records/care-context/link', +]; + +$payload = json_encode([ + 'hfr_id' => $hfrId, + 'hospital_id' => 1, + 'patient' => [ + 'patient_id' => 'TEST-DIAG-0001', + 'name' => 'Test Diagnostic Patient', + 'mobile' => '9999999999', + 'gender' => 'M', + 'year_of_birth' => 1990, + ], + 'care_contexts' => [ + ['reference_number' => 'TEST-CC-0001', 'display' => 'Diagnostic Test Care Context'], + ], +]); + +foreach ($paths as $path) { + $url = $baseUrl . $path; + $ch = curl_init($url); + curl_setopt_array($ch, [ + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $payload, + CURLOPT_HTTPHEADER => [ + 'Authorization: Bearer ' . $token, + 'Content-Type: application/json', + ], + CURLOPT_TIMEOUT => 15, + ]); + $body = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $err = curl_error($ch); + curl_close($ch); + + echo "=== POST {$url} ===\n"; + echo "HTTP {$httpCode}" . ($err ? " (curl error: {$err})" : '') . "\n"; + echo "Body: " . substr((string) $body, 0, 400) . "\n\n"; +} + +$mysqli->close();