feat: add core backend modules, inventory services, and patch scripts for AI Pharmacy API
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
const fs = require('fs');
|
||||
const path = 'C:/Users/CSH12/Desktop/Hospital_Api/all-applications-api/app/Services/PharmacyWebhookController.php';
|
||||
let code = fs.readFileSync(path, 'utf8');
|
||||
|
||||
const target1 = `$dispensingId = $payload['dispensing_id'] ?? null;`;
|
||||
const replace1 = `$dispensingId = $payload['dispensing_id'] ?? null;\n $prescriptionId = $payload['prescription_id'] ?? null;`;
|
||||
code = code.replace(target1, replace1);
|
||||
|
||||
const target2 = `if ($subjectRef) {`;
|
||||
const replace2 = `if ($prescriptionId) {
|
||||
try {
|
||||
$latestPrescription = \\App\\Entities\\PatientHealth::find($prescriptionId);
|
||||
if ($latestPrescription) {
|
||||
$values = is_array($latestPrescription->values) ? $latestPrescription->values : (array)$latestPrescription->values;
|
||||
foreach ($values as &$medicine) {
|
||||
if (is_object($medicine)) {
|
||||
$medicine->dispensing_status = 'dispensed';
|
||||
$medicine->dispensing_id = $dispensingId;
|
||||
$medicine->dispensed_at = $occurredAt;
|
||||
} elseif (is_array($medicine)) {
|
||||
$medicine['dispensing_status'] = 'dispensed';
|
||||
$medicine['dispensing_id'] = $dispensingId;
|
||||
$medicine['dispensed_at'] = $occurredAt;
|
||||
}
|
||||
}
|
||||
$latestPrescription->values = array_values($values);
|
||||
$latestPrescription->save();
|
||||
}
|
||||
} catch (\\Exception $e) {
|
||||
\\Illuminate\\Support\\Facades\\Log::error("[PharmacyWebhook] Error updating prescription by ID: " . $e->getMessage());
|
||||
}
|
||||
} elseif ($subjectRef) {`;
|
||||
code = code.replace(target2, replace2);
|
||||
|
||||
fs.writeFileSync(path, code);
|
||||
console.log("Successfully patched PharmacyWebhookController.php");
|
||||
Reference in New Issue
Block a user