diff --git a/app/Controllers/AbdmGateway.php b/app/Controllers/AbdmGateway.php index 63f22af..99cc52c 100644 --- a/app/Controllers/AbdmGateway.php +++ b/app/Controllers/AbdmGateway.php @@ -2079,13 +2079,30 @@ class AbdmGateway extends BaseController $doctorName = trim((string) ($ipdRow['r_doc_name'] ?? '')); $doctorId = (int) ($ipdRow['r_doc_id'] ?? 0); - if ($doctorName === '' && $doctorId > 0 && $this->db->tableExists('doctor_master')) { + $doctorRegNo = ''; + if ($doctorId > 0 && $this->db->tableExists('doctor_master')) { + $dFields = $this->db->getFieldNames('doctor_master') ?? []; + $dSelect = ['p_fname', 'p_lname']; + foreach (['doctor_reg_no', 'registration_no', 'reg_no'] as $field) { + if (in_array($field, $dFields, true)) { + $dSelect[] = $field; + } + } $dRow = $this->db->table('doctor_master') - ->select('p_fname,p_lname') + ->select(implode(',', array_unique($dSelect))) ->where('id', $doctorId) ->get(1) ->getRowArray() ?? []; - $doctorName = trim(trim((string) ($dRow['p_fname'] ?? '')) . ' ' . trim((string) ($dRow['p_lname'] ?? ''))); + if ($doctorName === '') { + $doctorName = trim(trim((string) ($dRow['p_fname'] ?? '')) . ' ' . trim((string) ($dRow['p_lname'] ?? ''))); + } + foreach (['doctor_reg_no', 'registration_no', 'reg_no'] as $field) { + $candidate = trim((string) ($dRow[$field] ?? '')); + if ($candidate !== '') { + $doctorRegNo = $candidate; + break; + } + } } $rawAbha = trim($preferredAbhaId); @@ -2309,6 +2326,15 @@ class AbdmGateway extends BaseController 'completed_at' => $this->toIsoDateTimeOrNow($dischargeRaw), 'department' => trim((string) ($ipdRow['dept_id'] ?? '')), 'doctor_name' => $doctorName, + 'doctor' => [ + 'id' => $doctorId > 0 ? (string) $doctorId : '', + 'name' => $doctorName, + 'registration_number' => $doctorRegNo, + ], + 'organization' => [ + 'id' => $hfrId, + 'name' => trim((string) ($hospital['name'] ?? '')), + ], 'patient' => [ 'id' => (string) $patientId, 'name' => $patientName, diff --git a/app/Libraries/Abdm/Fhir/Generators/DischargeFhirGenerator.php b/app/Libraries/Abdm/Fhir/Generators/DischargeFhirGenerator.php index 31eec85..7c0a09c 100644 --- a/app/Libraries/Abdm/Fhir/Generators/DischargeFhirGenerator.php +++ b/app/Libraries/Abdm/Fhir/Generators/DischargeFhirGenerator.php @@ -30,6 +30,28 @@ class DischargeFhirGenerator extends \App\Libraries\Abdm\Fhir\Generators\Abstrac $builder->addEncounter($encounter); } + $practitioner = $this->buildPractitioner($source); + if (! is_array($practitioner)) { + $fallbackDoctorName = trim((string) ($source['doctor_name'] ?? '')); + if ($fallbackDoctorName !== '') { + $practitioner = [ + 'resourceType' => 'Practitioner', + 'id' => 'practitioner-' . md5($fallbackDoctorName), + 'name' => [[ + 'text' => $fallbackDoctorName, + ]], + ]; + } + } + if (is_array($practitioner)) { + $builder->addPractitioner($practitioner); + } + + $organization = $this->buildOrganization($source); + if (is_array($organization)) { + $builder->addOrganization($organization); + } + $patientRef = 'urn:uuid:patient-' . $patientId; $encounterRef = is_array($encounter) ? 'urn:uuid:' . (string) ($encounter['id'] ?? '') : null; diff --git a/app/Views/abdm/task_board.php b/app/Views/abdm/task_board.php index 83ca91f..bf3935f 100644 --- a/app/Views/abdm/task_board.php +++ b/app/Views/abdm/task_board.php @@ -1716,6 +1716,17 @@ var allergies = byType('AllergyIntolerance'); var carePlans = byType('CarePlan'); + var coursePlans = []; + var advicePlans = []; + carePlans.forEach(function(cp) { + var title = String(cp.title || '').trim().toLowerCase(); + if (title === 'course in hospital') { + coursePlans.push(cp); + } else { + advicePlans.push(cp); + } + }); + var complaints = allConditions.filter(function(c) { return (c.category || []).some(function(cat) { return (cat.text || '').toLowerCase().includes('complaint'); }); }); @@ -2001,11 +2012,25 @@ html += ''; } + // ── Course In Hospital + if (coursePlans.length) { + html += '
Course In Hospital
'; + html += '
'; + } + // ── Discharge Advice / Follow-up - if (carePlans.length) { + if (advicePlans.length) { html += '
Discharge Advice & Follow-up
'; html += '