fix(abdm): support multi-careContext patient array in m2LinkInit
This commit is contained in:
parent
c0196b7e9f
commit
e93ebf7bf6
|
|
@ -6754,32 +6754,67 @@ class AbdmGateway extends BaseController
|
|||
$requestId = trim((string) ($payload['requestId'] ?? $payload['request_id'] ?? $this->request->getHeaderLine('X-Request-Id')));
|
||||
$transactionId = trim((string) ($payload['transactionId'] ?? $payload['transaction_id'] ?? ('tx-' . bin2hex(random_bytes(8)))));
|
||||
|
||||
$rawPatient = $payload['patient'] ?? [];
|
||||
$patientRef = '';
|
||||
$abhaAddress = '';
|
||||
$careContexts = [];
|
||||
|
||||
if (is_array($rawPatient)) {
|
||||
if (isset($rawPatient[0]) && is_array($rawPatient[0])) {
|
||||
foreach ($rawPatient as $pItem) {
|
||||
if (is_array($pItem)) {
|
||||
if ($patientRef === '' && ! empty($pItem['referenceNumber'])) {
|
||||
$patientRef = trim((string) $pItem['referenceNumber']);
|
||||
}
|
||||
if ($abhaAddress === '' && ! empty($pItem['id'])) {
|
||||
$abhaAddress = trim((string) $pItem['id']);
|
||||
}
|
||||
if (! empty($pItem['careContexts']) && is_array($pItem['careContexts'])) {
|
||||
foreach ($pItem['careContexts'] as $cc) {
|
||||
if (is_array($cc) && ! empty($cc['referenceNumber'])) {
|
||||
$careContexts[] = $cc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$patientRef = trim((string) ($rawPatient['referenceNumber'] ?? $rawPatient['id'] ?? ''));
|
||||
$abhaAddress = trim((string) ($rawPatient['id'] ?? $rawPatient['abhaAddress'] ?? $rawPatient['abha_address'] ?? ''));
|
||||
if (! empty($rawPatient['careContexts']) && is_array($rawPatient['careContexts'])) {
|
||||
$careContexts = $rawPatient['careContexts'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($patientRef === '') {
|
||||
$patientRef = trim((string) (
|
||||
$payload['patient']['referenceNumber']
|
||||
?? $payload['patientRef']
|
||||
$payload['patientRef']
|
||||
?? $payload['patient_ref']
|
||||
?? $payload['referenceNumber']
|
||||
?? $payload['patient_id']
|
||||
?? $payload['patient']['patient_id']
|
||||
?? ''
|
||||
));
|
||||
}
|
||||
|
||||
if ($abhaAddress === '') {
|
||||
$abhaAddress = trim((string) (
|
||||
$payload['patient']['id']
|
||||
?? $payload['patient']['abhaAddress']
|
||||
?? $payload['patient']['abha_address']
|
||||
?? $payload['abhaAddress']
|
||||
$payload['abhaAddress']
|
||||
?? $payload['abha_address']
|
||||
?? $payload['abhaId']
|
||||
?? $payload['abha_id']
|
||||
?? ''
|
||||
));
|
||||
}
|
||||
|
||||
$careContexts = $payload['patient']['careContexts']
|
||||
?? $payload['careContexts']
|
||||
if (empty($careContexts)) {
|
||||
$careContexts = $payload['careContexts']
|
||||
?? $payload['care_contexts']
|
||||
?? [];
|
||||
if (! is_array($careContexts)) {
|
||||
$careContexts = [];
|
||||
}
|
||||
}
|
||||
|
||||
if ($patientRef === '') {
|
||||
return $this->response->setStatusCode(400)->setJSON([
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user