fix(abdm): improve radiology report title resolution and prevent completed task duplication
This commit is contained in:
parent
3358f56e3f
commit
8dd34a9085
|
|
@ -2057,13 +2057,31 @@ class AbdmGateway extends BaseController
|
||||||
|
|
||||||
// -- Load test / charge name --------------------------------------------
|
// -- Load test / charge name --------------------------------------------
|
||||||
$testTitle = '';
|
$testTitle = '';
|
||||||
$chargeId = (int) ($labReq->charge_id ?? 0);
|
$labType = (int) ($labReq->lab_type ?? 0);
|
||||||
if ($chargeId > 0 && $this->db->tableExists('charge_master')) {
|
$isImaging = in_array($labType, [1, 2, 3, 4, 6], true);
|
||||||
$chargeRow = $this->db->table('charge_master')->select('charge_name, charge_type')->where('id', $chargeId)->get(1)->getRowArray() ?? [];
|
|
||||||
$testTitle = trim((string) ($chargeRow['charge_name'] ?? ''));
|
// Check lab_repo first
|
||||||
|
$labRepoId = (int) ($labReq->lab_repo_id ?? 0);
|
||||||
|
if ($labRepoId > 0 && $this->db->tableExists('lab_repo')) {
|
||||||
|
$repoRow = $this->db->table('lab_repo')->select('Repo, RepoName')->where('mstRepoKey', $labRepoId)->get(1)->getRowArray() ?? [];
|
||||||
|
$testTitle = trim((string) ($repoRow['RepoName'] ?? $repoRow['Repo'] ?? ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback: check charge_id in invoice_item or item_master
|
||||||
|
$chargeId = (int) ($labReq->charge_id ?? 0);
|
||||||
|
if ($testTitle === '' && $chargeId > 0) {
|
||||||
|
if ($this->db->tableExists('invoice_item')) {
|
||||||
|
$invItem = $this->db->table('invoice_item')->select('item_name')->where('id', $chargeId)->get(1)->getRowArray() ?? [];
|
||||||
|
$testTitle = trim((string) ($invItem['item_name'] ?? ''));
|
||||||
|
}
|
||||||
|
if ($testTitle === '' && $this->db->tableExists('item_master')) {
|
||||||
|
$itRow = $this->db->table('item_master')->select('item_name')->where('id', $chargeId)->get(1)->getRowArray() ?? [];
|
||||||
|
$testTitle = trim((string) ($itRow['item_name'] ?? ''));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($testTitle === '') {
|
if ($testTitle === '') {
|
||||||
$testTitle = $this->mapLabTypeToTitle((int) ($labReq->lab_type ?? 0));
|
$testTitle = $isImaging ? 'Radiology Report' : $this->mapLabTypeToTitle($labType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Load hospital profile ---------------------------------------------
|
// -- Load hospital profile ---------------------------------------------
|
||||||
|
|
@ -2087,19 +2105,18 @@ class AbdmGateway extends BaseController
|
||||||
|
|
||||||
$diagnosticReport = [
|
$diagnosticReport = [
|
||||||
'id' => (string) $labReqId,
|
'id' => (string) $labReqId,
|
||||||
'title' => $testTitle ?: 'Laboratory Report',
|
'title' => $testTitle ?: ($isImaging ? 'Radiology Report' : 'Laboratory Report'),
|
||||||
'status' => $labReq->status == 1 ? 'final' : 'preliminary',
|
'status' => $labReq->status == 1 ? 'final' : 'preliminary',
|
||||||
'conclusion' => trim((string) ($labReq->report_data_Impression ?? '')),
|
'conclusion' => trim((string) ($labReq->report_data_Impression ?? '')),
|
||||||
'reported_at' => $reportedAt,
|
'reported_at' => $reportedAt,
|
||||||
'report_html' => trim((string) ($labReq->Report_Data ?? '')),
|
'report_html' => trim((string) ($labReq->Report_Data ?? '')),
|
||||||
];
|
];
|
||||||
$isImaging = (int) ($labReq->lab_type ?? 0) === 6;
|
|
||||||
if ($isImaging) {
|
if ($isImaging) {
|
||||||
$diagnosticReport['is_imaging'] = true;
|
$diagnosticReport['is_imaging'] = true;
|
||||||
$diagnosticReport['report_domain'] = 'imaging';
|
$diagnosticReport['report_domain'] = 'imaging';
|
||||||
$diagnosticReport['section_title'] = 'Computed tomography imaging report';
|
$diagnosticReport['section_title'] = 'Diagnostic imaging report';
|
||||||
$diagnosticReport['section_snomed_code'] = '371531008';
|
$diagnosticReport['section_snomed_code'] = '371531008';
|
||||||
$diagnosticReport['section_snomed_display'] = 'Computed tomography imaging report';
|
$diagnosticReport['section_snomed_display'] = 'Diagnostic imaging report';
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Load LOINC code for the panel from lab_repo -----------------------
|
// -- Load LOINC code for the panel from lab_repo -----------------------
|
||||||
|
|
|
||||||
|
|
@ -454,12 +454,29 @@ class AbdmTaskBoard extends BaseController
|
||||||
$labType = (int) ($row['lab_type'] ?? 0);
|
$labType = (int) ($row['lab_type'] ?? 0);
|
||||||
$taskType = in_array($labType, [1, 2, 3, 4, 6], true) ? 'radiology_report_publish' : 'lab_report_publish';
|
$taskType = in_array($labType, [1, 2, 3, 4, 6], true) ? 'radiology_report_publish' : 'lab_report_publish';
|
||||||
|
|
||||||
|
// Skip if already linked in health_records
|
||||||
|
if ($this->db->tableExists('health_records')) {
|
||||||
|
$alreadyLinked = $this->db->table('health_records')
|
||||||
|
->select('id')
|
||||||
|
->where('patient_id', $patientId)
|
||||||
|
->groupStart()
|
||||||
|
->where('entity_id', (string) $labReqId)
|
||||||
|
->orLike('care_context_reference', 'RAD-' . $labReqId . '-', 'after')
|
||||||
|
->orLike('care_context_reference', 'LAB-' . $labReqId . '-', 'after')
|
||||||
|
->groupEnd()
|
||||||
|
->whereIn('push_status', ['linked', 'pushed', 'shared'])
|
||||||
|
->get(1)
|
||||||
|
->getRowArray();
|
||||||
|
if (! empty($alreadyLinked)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$exists = $this->db->table('abdm_work_tasks')
|
$exists = $this->db->table('abdm_work_tasks')
|
||||||
->select('id')
|
->select('id')
|
||||||
->where('task_type', $taskType)
|
->where('task_type', $taskType)
|
||||||
->where('entity_type', 'lab_request')
|
->where('entity_type', 'lab_request')
|
||||||
->where('entity_id', (string) $labReqId)
|
->where('entity_id', (string) $labReqId)
|
||||||
->whereIn('status', ['pending', 'in_progress'])
|
|
||||||
->get(1)
|
->get(1)
|
||||||
->getRowArray();
|
->getRowArray();
|
||||||
if (! empty($exists)) {
|
if (! empty($exists)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user