diff --git a/app/Controllers/AbdmGateway.php b/app/Controllers/AbdmGateway.php index b5e650e..63f22af 100644 --- a/app/Controllers/AbdmGateway.php +++ b/app/Controllers/AbdmGateway.php @@ -2190,13 +2190,13 @@ class AbdmGateway extends BaseController foreach ($this->ipdRows('ipd_discharge_1_b', ['short_head', 'rdata'], $ipdId, 'ipd_d_id') as $row) { $label = trim((string) ($row['short_head'] ?? '')); $value = trim((string) ($row['rdata'] ?? '')); - if ($label === '' || $value === '') { + if ($label === '' || ! $this->isMeaningfulClinicalValue($value)) { continue; } $observations[] = [ 'text' => $label, 'value' => $value, - 'category' => 'vital-signs', + 'category' => 'Condition on Admission Time', 'category_code' => 'vital-signs', 'effective_at' => $this->toIsoDateTimeOrNow($admissionRaw), ]; @@ -2204,13 +2204,13 @@ class AbdmGateway extends BaseController foreach ($this->ipdRows('ipd_discharge_1_b_final', ['short_head', 'rdata'], $ipdId, 'ipd_d_id') as $row) { $label = trim((string) ($row['short_head'] ?? '')); $value = trim((string) ($row['rdata'] ?? '')); - if ($label === '' || $value === '') { + if ($label === '' || ! $this->isMeaningfulClinicalValue($value)) { continue; } $observations[] = [ - 'text' => 'Discharge ' . $label, + 'text' => $label, 'value' => $value, - 'category' => 'vital-signs', + 'category' => 'Condition on Discharge Time', 'category_code' => 'vital-signs', 'effective_at' => $this->toIsoDateTimeOrNow($dischargeRaw), ]; @@ -2220,22 +2220,22 @@ class AbdmGateway extends BaseController foreach ($this->ipdRows('ipd_discharge_1_d', ['short_head', 'rdata'], $ipdId, 'ipd_d_id') as $row) { $label = trim((string) ($row['short_head'] ?? '')); $value = trim((string) ($row['rdata'] ?? '')); - if ($label === '') { + if ($label === '' || ! $this->isMeaningfulClinicalValue($value)) { continue; } $investigations[] = [ - 'text' => $value !== '' ? ($label . ': ' . $value) : $label, + 'text' => $label . ': ' . $value, 'authored_on' => $this->toIsoDateTimeOrNow($admissionRaw), ]; } foreach ($this->ipdRows('ipd_discharge_1_e', ['short_head', 'rdata'], $ipdId, 'ipd_d_id') as $row) { $label = trim((string) ($row['short_head'] ?? '')); $value = trim((string) ($row['rdata'] ?? '')); - if ($label === '') { + if ($label === '' || ! $this->isMeaningfulClinicalValue($value)) { continue; } $investigations[] = [ - 'text' => $value !== '' ? ($label . ': ' . $value) : $label, + 'text' => $label . ': ' . $value, 'authored_on' => $this->toIsoDateTimeOrNow($admissionRaw), ]; } @@ -2394,6 +2394,16 @@ class AbdmGateway extends BaseController return is_array($decoded) ? $decoded : []; } + private function isMeaningfulClinicalValue(string $value): bool + { + $normalized = strtolower(trim($value)); + if ($normalized === '') { + return false; + } + + return ! in_array($normalized, ['-', '--', 'na', 'n/a', 'nil', 'none', 'not done'], true); + } + private function normalizeFhirGender(string $gender): string { $value = strtolower(trim($gender)); diff --git a/app/Views/abdm/task_board.php b/app/Views/abdm/task_board.php index 0d5024c..83ca91f 100644 --- a/app/Views/abdm/task_board.php +++ b/app/Views/abdm/task_board.php @@ -1853,6 +1853,21 @@ var loincLabel = { '8867-4':'HR','59408-5':'SpO₂','8480-6':'BP Sys','8462-4':'BP Dia','8310-5':'Temp','9279-1':'RR','8302-2':'Height','29463-7':'Weight' }; var vitalLoincCodes = { '8867-4':1, '59408-5':1, '8480-6':1, '8462-4':1, '8310-5':1, '9279-1':1, '8302-2':1, '29463-7':1 }; + function meaningfulText(v) { + var s = String(v || '').trim().toLowerCase(); + if (!s) return false; + return ['-', '--', 'na', 'n/a', 'nil', 'none', 'not done'].indexOf(s) === -1; + } + + function getObservationCategoryText(o) { + var categories = o.category || []; + for (var i = 0; i < categories.length; i++) { + var t = (categories[i] || {}).text || ''; + if (t && String(t).trim() !== '') return String(t).trim(); + } + return ''; + } + function isVitalObservation(o) { var categories = o.category || []; for (var ci = 0; ci < categories.length; ci++) { @@ -1881,7 +1896,7 @@ if (!items.length) { return; } - html += '
' + hesc(sectionTitle) + '
'; + html += '
' + hesc(sectionTitle) + '
'; items.forEach(function(o) { var loinc = (((o.code || {}).coding) || [])[0] || {}; var label = loincLabel[loinc.code] || (o.code || {}).text || loinc.display || ''; @@ -1890,7 +1905,7 @@ if (val === undefined || val === null) { val = o.valueString || o.valueCodeableConcept && o.valueCodeableConcept.text || ''; } - if (val === undefined || val === null || val === '') { + if (val === undefined || val === null || !meaningfulText(val)) { return; } html += '
'; @@ -1903,9 +1918,21 @@ html += '
'; } - var vitalObservations = observations.filter(isVitalObservation); - var labObservations = observations.filter(function(o) { return !isVitalObservation(o); }); + var admissionObservations = observations.filter(function(o) { + return getObservationCategoryText(o).toLowerCase() === 'condition on admission time'; + }); + var dischargeObservations = observations.filter(function(o) { + return getObservationCategoryText(o).toLowerCase() === 'condition on discharge time'; + }); + var remainingObservations = observations.filter(function(o) { + var cat = getObservationCategoryText(o).toLowerCase(); + return cat !== 'condition on admission time' && cat !== 'condition on discharge time'; + }); + var vitalObservations = remainingObservations.filter(isVitalObservation); + var labObservations = remainingObservations.filter(function(o) { return !isVitalObservation(o); }); + renderObservationCard('Condition on Admission Time', admissionObservations); + renderObservationCard('Condition on Discharge Time', dischargeObservations); renderObservationCard('Vitals', vitalObservations); renderObservationCard('Lab Results', labObservations); } @@ -1947,6 +1974,10 @@ serviceReqs.forEach(function(s) { var text = (s.code || {}).text || ''; var loinc = (((s.code || {}).coding) || [])[0] || {}; + var normalized = String(text || '').trim().toLowerCase(); + if (!normalized || normalized === '-' || normalized === '--' || normalized === 'na' || normalized === 'n/a' || normalized === 'nil' || normalized === 'none' || normalized === 'not done') { + return; + } html += '
  • ' + hesc(text) + ''; if (loinc.code) html += ' LOINC ' + hesc(loinc.code) + ''; html += '
  • ';