feat(abdm): set autoLinkDelayMinutes to 1, regenerate FHIR bundle on print, map salt composition to reasonCode

This commit is contained in:
DevSoftTech Server 2026-10-16 18:54:29 +05:30
parent ee57959873
commit 6c812236a8
4 changed files with 38 additions and 8 deletions

View File

@ -154,7 +154,7 @@ class AbdmConnector extends BaseConfig
public bool $autoLinkEnabled = true;
/** Default cooling period for OPD, Lab, Radiology, and all other HI types (in minutes). 0 = immediate 1-minute cron linking. */
public int $autoLinkDelayMinutes = 0;
public int $autoLinkDelayMinutes = 1;
/** Cooling period for IPD Discharge Summary (in hours). 0 = immediate 1-minute cron linking. */
public int $autoLinkDelayDischargeHours = 0;

View File

@ -2186,6 +2186,15 @@ class Opd extends BaseController
$data['print_layout_mode'] = $layoutMode;
if ($includeContent) {
try {
$rxCtrl = new \App\Controllers\Opd_prescription();
$rxCtrl->storePrescriptionFhirBundle($opdId, $sessionId);
} catch (\Throwable $e) {
log_message('warning', '[opd_lettre_pdf] storePrescriptionFhirBundle error: ' . $e->getMessage());
}
}
$isComposedTemplate = $templateKey !== '' && str_starts_with($templateKey, 'compose_');
if ($isComposedTemplate) {
$html = $this->renderComposedOpdPrint($data, $templateKey);

View File

@ -13952,6 +13952,12 @@ OPD SNAPSHOT JSON: " . $payload;
$this->createOpdPrescriptionWorkTask($opdId, $opdSessionId);
$this->markOpdVisitedOnConsultCompletion((int) $opdId);
// Regenerate complete FHIR records with latest medications and PDF on print action
try {
$this->storePrescriptionFhirBundle($opdId, $opdSessionId);
} catch (\Throwable $e) {
log_message('warning', '[opd_prescription_print] storePrescriptionFhirBundle error: ' . $e->getMessage());
}
$printConfig = $this->resolvePrescriptionLayoutByDoctorField($opdId, $printType);
$layoutMode = (string) ($printConfig['layout'] ?? 'content_only');

View File

@ -374,12 +374,9 @@ class FhirR4Builder
$drugName = trim((string) ($medication['drug_name'] ?? ''));
$genericName = trim((string) ($medication['generic_name'] ?? ''));
$medType = trim((string) ($medication['med_type'] ?? ''));
$displayText = $drugName;
if ($genericName !== '' && stripos($drugName, $genericName) === false) {
$displayText = trim($drugName . ' (' . $genericName . ')');
}
$displayText = $drugName !== '' ? $drugName : $genericName;
$medicationCodeableConcept = ['text' => $displayText !== '' ? $displayText : $drugName];
$medicationCodeableConcept = ['text' => $displayText !== '' ? $displayText : 'Medication'];
$snomedCode = trim((string) ($medication['snomed_code'] ?? ''));
$atcCode = strtoupper(trim((string) ($medication['atc_code'] ?? '')));
@ -478,6 +475,19 @@ class FhirR4Builder
'authoredOn' => $issuedAt,
'dosageInstruction' => [$dosageInstruction],
];
// Reason / Indication: Map salt composition if available; otherwise fallback to diagnosis or blank space
$saltReasonText = $genericName;
if ($saltReasonText === '') {
$firstCond = $conditions[0]['name'] ?? ($conditions[0]['text'] ?? ($context['diagnosis'] ?? ''));
$saltReasonText = is_string($firstCond) && trim($firstCond) !== '' ? trim($firstCond) : ' ';
}
if ($saltReasonText !== '') {
$medRes['reasonCode'] = [[
'text' => $saltReasonText,
]];
}
if ($timingResult['asNeeded']) {
$medRes['asNeededBoolean'] = true;
}
@ -3399,7 +3409,8 @@ class FhirR4Builder
}
$medicationRefs[] = ['reference' => 'MedicationRequest/' . $medId];
$entries[] = ['resource' => [
$genericName = is_array($med) ? trim((string) ($med['generic_name'] ?? '')) : '';
$dsMedRes = [
'resourceType' => 'MedicationRequest',
'id' => $medId,
'status' => 'active',
@ -3408,7 +3419,11 @@ class FhirR4Builder
'encounter' => ['reference' => $encounterRef],
'medicationCodeableConcept' => $mc,
'dosageInstruction' => [['text' => is_array($med) ? (string) ($med['dosage'] ?? '') : '']],
]];
];
if ($genericName !== '') {
$dsMedRes['reasonCode'] = [['text' => $genericName]];
}
$entries[] = ['resource' => $dsMedRes];
}
if (! empty($medicationRefs)) {
$sections[] = ['title' => 'Medications', 'entry' => $medicationRefs];