feat: Implement comprehensive patient queue management system with Pinia store, API integration, and dedicated admin counter page.
This commit is contained in:
No files matched your search
+61
-11
@@ -2709,23 +2709,73 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
const patientIndex = allPatients.value.findIndex(p => p.no === patient.no);
|
||||
if (patientIndex === -1) return { success: false, message: "Pasien tidak ditemukan" };
|
||||
|
||||
allPatients.value[patientIndex] = {
|
||||
...allPatients.value[patientIndex],
|
||||
const oldPatient = allPatients.value[patientIndex];
|
||||
const oldLoketId = oldPatient.loketId;
|
||||
|
||||
// Find appropriate loket for the new clinic from loketStore
|
||||
let targetLoketId = oldLoketId;
|
||||
let targetLoketName = oldPatient.loket;
|
||||
|
||||
if (newKlinik.kode) {
|
||||
const allLokets = loketStore.lokets || [];
|
||||
const foundLoket = allLokets.find(l =>
|
||||
l.pelayanan && Array.isArray(l.pelayanan) && l.pelayanan.includes(newKlinik.kode)
|
||||
);
|
||||
|
||||
if (foundLoket) {
|
||||
targetLoketId = foundLoket.id;
|
||||
targetLoketName = foundLoket.namaLoket;
|
||||
console.log(`📡 [queueStore] changeKlinik: Re-assigning to Loket ${targetLoketId} (${targetLoketName})`);
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if we need to reset status from 'diproses' to 'di-loket' if moved to different loket
|
||||
const isMovedToDifferentLoket = String(oldLoketId) !== String(targetLoketId);
|
||||
let newStatus = oldPatient.status;
|
||||
|
||||
// Check if patient is currently being processed at the old loket
|
||||
const oldKey = specificId ? `${adminType}-${specificId}` : adminType;
|
||||
const isCurrentlyProcessingAtOld = currentProcessingPatient.value[oldKey]?.no === patient.no;
|
||||
|
||||
if (isMovedToDifferentLoket && isCurrentlyProcessingAtOld) {
|
||||
// If moved, they should be back to waiting list ('di-loket') at the new target
|
||||
newStatus = 'di-loket';
|
||||
// Clear from old processing slot
|
||||
currentProcessingPatient.value[oldKey] = null;
|
||||
console.log(`📡 [queueStore] changeKlinik: Cleared processing at ${oldKey} and set status to 'di-loket'`);
|
||||
}
|
||||
|
||||
// Update the patient in allPatients
|
||||
const updatedPatient = {
|
||||
...oldPatient,
|
||||
klinik: newKlinik.name,
|
||||
kodeKlinik: newKlinik.kode
|
||||
kodeKlinik: newKlinik.kode,
|
||||
loketId: targetLoketId,
|
||||
loket: targetLoketName,
|
||||
status: newStatus
|
||||
};
|
||||
|
||||
const key = specificId ? `${adminType}-${specificId}` : adminType;
|
||||
if (currentProcessingPatient.value[key]?.no === patient.no) {
|
||||
currentProcessingPatient.value[key] = {
|
||||
...currentProcessingPatient.value[key],
|
||||
klinik: newKlinik.name,
|
||||
kodeKlinik: newKlinik.kode
|
||||
};
|
||||
allPatients.value[patientIndex] = updatedPatient;
|
||||
|
||||
// If they AREN'T moved but were processing, update their clinic info in the current slot
|
||||
if (!isMovedToDifferentLoket && isCurrentlyProcessingAtOld) {
|
||||
currentProcessingPatient.value[oldKey] = updatedPatient;
|
||||
}
|
||||
return { success: true, message: `Klinik berhasil diubah ke ${newKlinik.name}` };
|
||||
|
||||
let successMessage = `Klinik berhasil diubah ke ${newKlinik.name}`;
|
||||
if (isMovedToDifferentLoket) {
|
||||
successMessage += `. Antrean dipindah ke ${targetLoketName}.`;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: successMessage,
|
||||
patient: updatedPatient,
|
||||
moved: isMovedToDifferentLoket
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const getCurrentProcessing = (adminType, id = null) => {
|
||||
const key = id ? `${adminType}-${id}` : adminType;
|
||||
return computed(() => currentProcessingPatient.value[key] || null);
|
||||
|
||||
Reference in New Issue
Block a user