update api loket admin

This commit is contained in:
Fanrouver
2026-01-26 14:37:05 +07:00
parent 6c0835227d
commit 083fe3e364
4 changed files with 488 additions and 320 deletions

No files matched your search

+67
View File
@@ -201,6 +201,8 @@ const clinicStore = useClinicStore()
const currentTime = ref('')
const currentDate = ref('')
let timeInterval = null
let broadcastChannel = null
const broadcastedPatient = ref(null)
// Get loket ID from route
const loketId = computed(() => {
@@ -665,6 +667,11 @@ const isInTTSWindow = (queue) => {
// Current called queue - tiket yang sedang diproses di admin loket
// Nomor antrian menjadi "dipanggil" jika diproses pada AdminLoket DAN sudah dipanggil oleh admin
const currentCalledQueue = computed(() => {
// Prioritas 0: Broadcasted patient (Real-time from BroadcastChannel)
if (broadcastedPatient.value) {
return broadcastedPatient.value
}
// Prioritas 1: Pasien yang sedang diproses di admin loket (currentProcessingPatient)
// Hanya tampilkan jika sudah dipanggil eksplisit oleh admin (calledByAdmin === true)
if (currentProcessingPatient.value) {
@@ -926,11 +933,71 @@ onMounted(() => {
// Langsung start timer tanpa menunggu fetch
updateTime()
// Init BroadcastChannel
try {
broadcastChannel = new BroadcastChannel('antrian-loket-channel')
broadcastChannel.onmessage = (event) => {
console.log('Anjungan received broadcast:', event.data)
if (event.data && event.data.type === 'CALL_PATIENT') {
const { patient, loketId: senderLoketId } = event.data
// Cek apakah event ini untuk loket ini
// Gunakan loose equality untuk handle string vs number
if (loketId.value) {
if (String(loketId.value) != String(senderLoketId)) {
console.log('Skipping broadcast for different loket:', senderLoketId)
return
}
}
// Update local state untuk prioritas tampilan hero
broadcastedPatient.value = patient
// PENTING: Update Store agar list antrian juga berubah
// 1. Update currentProcessingPatient
if (!queueStore.currentProcessingPatient) {
queueStore.currentProcessingPatient = {}
}
queueStore.currentProcessingPatient.loket = patient
// 2. Update status patient di allPatients list jika ada
if (queueStore.allPatients && Array.isArray(queueStore.allPatients)) {
const idx = queueStore.allPatients.findIndex(p =>
p.no === patient.no ||
p.noAntrian === patient.noAntrian
)
if (idx !== -1) {
// Update existing patient data
// Kita update status menjadi 'di-loket' dan lastCalledAt
const updatedPatient = {
...queueStore.allPatients[idx],
...patient,
status: 'di-loket', // Pastikan status sinkron
lastCalledAt: patient.lastCalledAt || new Date().toISOString()
}
queueStore.allPatients[idx] = updatedPatient
} else {
// Opsional: Jika pasien tidak ditemukan di list (misal data awal kosong), tambahkan?
// Sebaiknya jangan sembarang nambah, tapi untuk robustnes UI boleh saja
// queueStore.allPatients.push(patient)
}
}
console.log('Store updated from broadcast')
}
}
} catch (e) {
console.error('BroadcastChannel error:', e)
}
// Start TTS checker
timeInterval = setInterval(updateTime, 1000)
})
onUnmounted(() => {
if (timeInterval) clearInterval(timeInterval)
if (broadcastChannel) broadcastChannel.close()
})
</script>