From ca5913c4e6d62449ee86eae117597288670f916a Mon Sep 17 00:00:00 2001 From: bagus-arie05 Date: Thu, 8 Jan 2026 12:53:41 +0700 Subject: [PATCH] update klinik ruang --- pages/AdminKlinikRuang/[kodeKlinik].vue | 67 +++---------------- .../AntrianKlinikRuang/[kodeKlinik].vue | 27 ++++++-- stores/queueStore.js | 37 ++-------- 3 files changed, 39 insertions(+), 92 deletions(-) diff --git a/pages/AdminKlinikRuang/[kodeKlinik].vue b/pages/AdminKlinikRuang/[kodeKlinik].vue index db06682..9f485cb 100644 --- a/pages/AdminKlinikRuang/[kodeKlinik].vue +++ b/pages/AdminKlinikRuang/[kodeKlinik].vue @@ -545,14 +545,9 @@ const getCurrentProcessingForRoom = (ruang) => { const key = `klinik-ruang-${klinikData.value.kodeKlinik}-${ruang.nomorRuang}`; const current = queueStore.currentProcessingPatient[key]; - if (!current) return null; - // Check both tipeLayanan - const pemeriksaanAwal = current['Pemeriksaan Awal']; - const tindakan = current['Tindakan']; - - // Return the one that exists, or null - return pemeriksaanAwal || tindakan || null; + // Return pasien yang sedang diproses (tidak dipisah per tipe layanan) + return current || null; }; @@ -686,28 +681,22 @@ const handleCallPatientByTipe = (ruang, tipeLayanan) => { const current = getCurrentProcessingForRoom(ruang); if (!current) return; - // Update tipeLayanan pasien jika berbeda - if (current.tipeLayanan !== tipeLayanan) { - handleSetTipeLayanan(ruang, tipeLayanan); - } - - // Call patient dengan tipeLayanan tertentu + // Update tipeLayanan pasien untuk tracking panggilan terakhir const patientIndex = queueStore.allPatients.findIndex(p => p.no === current.no); if (patientIndex !== -1) { // Update status to di-loket untuk ditampilkan di anjungan + // Simpan tipeLayanan yang dipanggil untuk display di anjungan queueStore.allPatients[patientIndex] = { ...queueStore.allPatients[patientIndex], status: 'di-loket', - tipeLayanan: tipeLayanan, - lastCalledAt: new Date().toISOString() + tipeLayanan: tipeLayanan, // Update tipeLayanan untuk display di anjungan + lastCalledAt: new Date().toISOString(), + lastCalledTipeLayanan: tipeLayanan // Track tipe layanan terakhir yang dipanggil }; - // Update current processing + // Update current processing (tetap 1 pasien, tidak dipisah per tipe) const key = `klinik-ruang-${klinikData.value.kodeKlinik}-${ruang.nomorRuang}`; - if (!queueStore.currentProcessingPatient[key]) { - queueStore.currentProcessingPatient[key] = {}; - } - queueStore.currentProcessingPatient[key][tipeLayanan] = queueStore.allPatients[patientIndex]; + queueStore.currentProcessingPatient[key] = queueStore.allPatients[patientIndex]; } showSnackbar(`Memanggil pasien ${current.noAntrian.split(" |")[0]} untuk ${tipeLayanan}`, 'success'); @@ -762,12 +751,7 @@ const handlePatientAction = (ruang, action) => { // Clear current processing const key = `klinik-ruang-${klinikData.value.kodeKlinik}-${ruang.nomorRuang}`; - if (queueStore.currentProcessingPatient[key]) { - const currentTipe = current.tipeLayanan; - if (currentTipe) { - queueStore.currentProcessingPatient[key][currentTipe] = null; - } - } + queueStore.currentProcessingPatient[key] = null; } } @@ -807,37 +791,6 @@ const paginatedPendingPatients = (ruang) => { return allPending.slice(startIndex, endIndex); }; -const handleSetTipeLayanan = (ruang, tipeLayanan) => { - const current = getCurrentProcessingForRoom(ruang); - if (!current) return; - - const patientIndex = queueStore.allPatients.findIndex(p => p.no === current.no); - if (patientIndex !== -1) { - // Update patient tipeLayanan - const updatedPatient = { - ...queueStore.allPatients[patientIndex], - tipeLayanan: tipeLayanan - }; - queueStore.allPatients[patientIndex] = updatedPatient; - - // Update current processing - const key = `klinik-ruang-${klinikData.value.kodeKlinik}-${ruang.nomorRuang}`; - if (!queueStore.currentProcessingPatient[key]) { - queueStore.currentProcessingPatient[key] = {}; - } - - // Set new tipeLayanan - queueStore.currentProcessingPatient[key][tipeLayanan] = updatedPatient; - - // Remove old tipeLayanan from current processing - const oldTipe = current.tipeLayanan; - if (oldTipe && oldTipe !== tipeLayanan) { - queueStore.currentProcessingPatient[key][oldTipe] = null; - } - - showSnackbar(`Tipe layanan diubah menjadi ${tipeLayanan}`, 'success'); - } -}; onMounted(() => { diff --git a/pages/Anjungan/AntrianKlinikRuang/[kodeKlinik].vue b/pages/Anjungan/AntrianKlinikRuang/[kodeKlinik].vue index 3066d2d..0b08365 100644 --- a/pages/Anjungan/AntrianKlinikRuang/[kodeKlinik].vue +++ b/pages/Anjungan/AntrianKlinikRuang/[kodeKlinik].vue @@ -285,8 +285,20 @@ const displayedRuang = computed(() => { const tindakanQueues = allQueues.filter(q => q.tipeLayanan === 'Tindakan') // Get current and next queues for each tipeLayanan - const getCurrentAndNext = (queues) => { - const current = queues.find(q => q.status === 'di-loket') || null + // Current queue is the one with status 'di-loket' and matching tipeLayanan + const getCurrentAndNext = (queues, tipeLayanan) => { + // Find current: pasien dengan status 'di-loket' dan tipeLayanan yang sesuai + // Sort by lastCalledAt untuk mendapatkan yang terakhir dipanggil + const currentCandidates = queues.filter(q => + q.status === 'di-loket' && q.tipeLayanan === tipeLayanan + ).sort((a, b) => { + const timeA = a.lastCalledAt ? new Date(a.lastCalledAt) : new Date(a.createdAt || 0) + const timeB = b.lastCalledAt ? new Date(b.lastCalledAt) : new Date(b.createdAt || 0) + return timeB - timeA + }) + const current = currentCandidates.length > 0 ? currentCandidates[0] : null + + // Next queues: exclude current patient const next = queues.filter(q => q.no !== current?.no && (q.status === 'waiting' || q.status === 'di-loket') @@ -294,8 +306,8 @@ const displayedRuang = computed(() => { return { current, next } } - const pemeriksaanAwal = getCurrentAndNext(pemeriksaanAwalQueues) - const tindakan = getCurrentAndNext(tindakanQueues) + const pemeriksaanAwal = getCurrentAndNext(pemeriksaanAwalQueues, 'Pemeriksaan Awal') + const tindakan = getCurrentAndNext(tindakanQueues, 'Tindakan') return { kodeKlinik: ruang.kodeKlinik, @@ -322,9 +334,14 @@ const currentCalledQueue = computed(() => { if (!kodeKlinik.value || !klinikData.value) return null // Get most recently called patient (status di-loket) + // Sort by lastCalledAt if available, otherwise by createdAt const calledQueues = klinikPatients.value .filter(p => p.status === 'di-loket') - .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)) + .sort((a, b) => { + const timeA = a.lastCalledAt ? new Date(a.lastCalledAt) : new Date(a.createdAt || 0) + const timeB = b.lastCalledAt ? new Date(b.lastCalledAt) : new Date(b.createdAt || 0) + return timeB - timeA + }) if (calledQueues.length > 0) { const patient = calledQueues[0] diff --git a/stores/queueStore.js b/stores/queueStore.js index bd3184e..8e700d1 100644 --- a/stores/queueStore.js +++ b/stores/queueStore.js @@ -741,18 +741,10 @@ export const useQueueStore = defineStore('queue', () => { switch (action) { case "proses": - // Set as current processing for this room - if (!currentProcessingPatient.value[key]) { - // Use Vue's reactive assignment - currentProcessingPatient.value = { - ...currentProcessingPatient.value, - [key]: {} - }; - } - // Update nested property reactively - currentProcessingPatient.value[key] = { - ...currentProcessingPatient.value[key], - [patient.tipeLayanan]: allPatients.value[patientIndex] + // Set as current processing for this room (1 pasien, tidak dipisah per tipe layanan) + currentProcessingPatient.value = { + ...currentProcessingPatient.value, + [key]: allPatients.value[patientIndex] }; message = `Memproses pasien ${patientCode}`; break; @@ -763,12 +755,7 @@ export const useQueueStore = defineStore('queue', () => { status: "processed" }; // Clear current processing - if (currentProcessingPatient.value[key]) { - currentProcessingPatient.value[key] = { - ...currentProcessingPatient.value[key], - [patient.tipeLayanan]: null - }; - } + currentProcessingPatient.value[key] = null; message = `Pasien ${patientCode} selesai diproses`; break; @@ -777,12 +764,7 @@ export const useQueueStore = defineStore('queue', () => { ...allPatients.value[patientIndex], status: "terlambat" }; - if (currentProcessingPatient.value[key]) { - currentProcessingPatient.value[key] = { - ...currentProcessingPatient.value[key], - [patient.tipeLayanan]: null - }; - } + currentProcessingPatient.value[key] = null; message = `Pasien ${patientCode} ditandai terlambat`; break; @@ -791,12 +773,7 @@ export const useQueueStore = defineStore('queue', () => { ...allPatients.value[patientIndex], status: "pending" }; - if (currentProcessingPatient.value[key]) { - currentProcessingPatient.value[key] = { - ...currentProcessingPatient.value[key], - [patient.tipeLayanan]: null - }; - } + currentProcessingPatient.value[key] = null; message = `Pasien ${patientCode} di-pending`; break; }