ABDM: separate course section and include doctor in discharge FHIR

This commit is contained in:
DevSoftTech Server 2026-07-17 18:40:19 +05:30
parent ca025a088e
commit 629590d9ab
3 changed files with 78 additions and 5 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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 += '</ul></div></div>';
}
// ── Course In Hospital
if (coursePlans.length) {
html += '<div class="card mb-2"><div class="card-header py-1 bg-light"><small class="fw-bold text-uppercase text-secondary">Course In Hospital</small></div><div class="card-body py-2">';
html += '<ul class="mb-0 ps-3">';
coursePlans.forEach(function(cp) {
var title = cp.title || 'Care Plan';
var desc = cp.description || '';
html += '<li class="mb-2"><strong>' + hesc(title) + '</strong>';
if (desc) html += '<div class="text-muted small">' + hesc(desc) + '</div>';
html += '</li>';
});
html += '</ul></div></div>';
}
// ── Discharge Advice / Follow-up
if (carePlans.length) {
if (advicePlans.length) {
html += '<div class="card mb-2"><div class="card-header py-1 bg-light"><small class="fw-bold text-uppercase text-secondary">Discharge Advice & Follow-up</small></div><div class="card-body py-2">';
html += '<ul class="mb-0 ps-3">';
carePlans.forEach(function(cp) {
advicePlans.forEach(function(cp) {
var title = cp.title || 'Care Plan';
var desc = cp.description || '';
html += '<li class="mb-2"><strong>' + hesc(title) + '</strong>';