Fix invalid ABDM HIType codes (HealthDocument->HealthDocumentRecord, Wellness->WellnessRecord) causing consent_request 400; fix extractErrorText for array-shaped bridge error responses

This commit is contained in:
DevSoftTech Server 2026-07-28 22:16:22 +05:30
parent 2525916c08
commit 1439ce0fcc
5 changed files with 27 additions and 19 deletions

View File

@ -1285,7 +1285,7 @@ class Patient extends BaseController
$payload = [
'patient_id' => $pno,
'abha_address' => $abhaContext['abha_address'],
'hiTypes' => ['OPConsultation', 'Prescription', 'DiagnosticReport', 'HealthDocument'],
'hiTypes' => ['OPConsultation', 'Prescription', 'DiagnosticReport', 'HealthDocumentRecord'],
];
try {
@ -1584,7 +1584,7 @@ class Patient extends BaseController
$consentPayload = [
'patient_id' => $pno,
'abha_address' => $abhaContext['abha_address'],
'hiTypes' => ['OPConsultation', 'Prescription', 'DiagnosticReport', 'HealthDocument'],
'hiTypes' => ['OPConsultation', 'Prescription', 'DiagnosticReport', 'HealthDocumentRecord'],
];
try {

View File

@ -516,14 +516,22 @@ class M3HiuGatewayClient
return 'HTTP ' . $httpCode . ' non-JSON response';
}
$code = trim((string) (
$decoded['data']['error']['code']
?? $decoded['error']['code']
?? ''
));
// Some bridge error responses wrap the error object in a list, e.g.
// {"data": [{"error": {"code": "...", "message": "..."}}]}, instead of
// a single {"data": {"error": {...}}} object. Normalize both shapes.
$errorNode = $decoded['data']['error'] ?? $decoded['error'] ?? null;
if (! is_array($errorNode) && isset($decoded['data']) && is_array($decoded['data'])) {
foreach ($decoded['data'] as $item) {
if (is_array($item) && isset($item['error']) && is_array($item['error'])) {
$errorNode = $item['error'];
break;
}
}
}
$code = trim((string) ($errorNode['code'] ?? ''));
$message = trim((string) (
$decoded['data']['error']['message']
?? $decoded['error']['message']
$errorNode['message']
?? $decoded['message']
?? $decoded['error_text']
?? (is_string($decoded['error'] ?? null) ? $decoded['error'] : '')

View File

@ -1042,12 +1042,12 @@ class M3HiuWorkflowService
'prescription' => 'Prescription',
'dischargesummaryrecord' => 'DischargeSummary',
'dischargesummary' => 'DischargeSummary',
'healthdocumentrecord' => 'HealthDocument',
'healthdocument' => 'HealthDocument',
'healthdocumentrecord' => 'HealthDocumentRecord',
'healthdocument' => 'HealthDocumentRecord',
'immunization' => 'ImmunizationRecord',
'immunizationrecord' => 'ImmunizationRecord',
'wellness' => 'Wellness',
'wellnessrecord' => 'Wellness',
'wellness' => 'WellnessRecord',
'wellnessrecord' => 'WellnessRecord',
'invoice' => 'Invoice',
'invoicerecord' => 'Invoice',
];

View File

@ -1199,12 +1199,12 @@
dischargesummary: 'DischargeSummary',
invoice: 'Invoice',
invoicerecord: 'Invoice',
healthdocumentrecord: 'HealthDocument',
healthdocument: 'HealthDocument',
healthdocumentrecord: 'HealthDocumentRecord',
healthdocument: 'HealthDocumentRecord',
immunization: 'ImmunizationRecord',
immunizationrecord: 'ImmunizationRecord',
wellness: 'Wellness',
wellnessrecord: 'Wellness'
wellness: 'WellnessRecord',
wellnessrecord: 'WellnessRecord'
};
var out = [];

View File

@ -480,7 +480,7 @@ if ($patientPhotoPath === '') {
</div>
<div class="col">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="HealthDocument" id="hiHealthDocument">
<input class="form-check-input" type="checkbox" value="HealthDocumentRecord" id="hiHealthDocument">
<label class="form-check-label" for="hiHealthDocument">Health Document</label>
</div>
</div>
@ -492,7 +492,7 @@ if ($patientPhotoPath === '') {
</div>
<div class="col">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="Wellness" id="hiWellness">
<input class="form-check-input" type="checkbox" value="WellnessRecord" id="hiWellness">
<label class="form-check-label" for="hiWellness">Wellness</label>
</div>
</div>