update status waiting dan update post data pasien

This commit is contained in:
bagus-arie05
2026-02-02 11:04:28 +07:00
parent 7ba1c5b7dd
commit 53a510f23d
14 changed files with 140 additions and 404 deletions

No files matched your search

+96 -39
View File
@@ -59,20 +59,20 @@ export const useQueueStore = defineStore('queue', () => {
/**
* Reference mapping for patient status from API idvisit
* idvisit 1, 2 = menunggu (CT ANJUNGAN, RT ANJUNGAN)
* idvisit 3, 4 = waiting (PG ANJUNGAN, RT CHECK-IN)
* idvisit 3, 4 = anjungan (PG ANJUNGAN, RT CHECK-IN)
* idvisit 5, 6 = di-loket (PS CHECK-IN, TP LOKET)
*/
const PATIENT_STATUS_MAP = {
1: 'menunggu',
2: 'menunggu',
3: 'waiting',
4: 'waiting',
3: 'anjungan',
4: 'anjungan',
5: 'di-loket',
6: 'di-loket',
"1": 'menunggu',
"2": 'menunggu',
"3": 'waiting',
"4": 'waiting',
"3": 'anjungan',
"4": 'anjungan',
"5": 'di-loket',
"6": 'di-loket'
};
@@ -87,7 +87,7 @@ export const useQueueStore = defineStore('queue', () => {
/**
* Map status dari deskripsi API ke status internal
* menunggu (id 1, 2): "Cetak Tiket Antrian" atau "Ruang Tunggu Anjungan"
* waiting (id 3, 4): "Panggilan loket ke Anjungan" atau "Tunggu Pasien Check-In"
* anjungan (id 3, 4): "Panggilan loket ke Anjungan" atau "Tunggu Pasien Check-In"
* di-loket (id 5, 6): "Pasien Sudah Check-In" atau "Tunggu Panggilan Loket"
*/
const mapStatusFromDeskripsi = (deskripsi) => {
@@ -100,9 +100,9 @@ export const useQueueStore = defineStore('queue', () => {
return 'di-loket';
}
// waiting (id 3, 4): PG ANJUNGAN (Panggilan loket ke Anjungan), RT CHECK-IN (Tunggu Pasien Check-In)
// anjungan (id 3, 4): PG ANJUNGAN (Panggilan loket ke Anjungan), RT CHECK-IN (Tunggu Pasien Check-In)
if (desc.includes('PANGGILAN LOKET KE ANJUNGAN') || desc.includes('TUNGGU PASIEN CHECK-IN') || desc.includes('PG ANJUNGAN') || desc.includes('RT CHECK-IN')) {
return 'waiting';
return 'anjungan';
}
// menunggu (id 1, 2): CT ANJUNGAN (Cetak Tiket Antrian), RT ANJUNGAN (Ruang Tunggu Anjungan)
@@ -131,8 +131,8 @@ export const useQueueStore = defineStore('queue', () => {
if (apiPatient.posisi && Array.isArray(apiPatient.posisi) && apiPatient.posisi.length > 0) {
// Find the "best" status among all positions
// Priority: di-loket > waiting > menunggu
const statusPriority = { 'di-loket': 3, 'waiting': 2, 'menunggu': 1 };
// Priority: di-loket > anjungan > menunggu
const statusPriority = { 'di-loket': 3, 'anjungan': 2, 'menunggu': 1 };
let bestPriority = 0;
apiPatient.posisi.forEach(pos => {
@@ -259,8 +259,8 @@ export const useQueueStore = defineStore('queue', () => {
if (!existing) {
deduplicatedMap.set(id, p);
} else {
// Priority: di-loket > waiting > menunggu
const statusPriority = { 'di-loket': 3, 'waiting': 2, 'menunggu': 1 };
// Priority: di-loket > anjungan > menunggu
const statusPriority = { 'di-loket': 3, 'anjungan': 2, 'menunggu': 1 };
const pPrio = statusPriority[p.status] || 0;
const ePrio = statusPriority[existing.status] || 0;
@@ -296,9 +296,9 @@ export const useQueueStore = defineStore('queue', () => {
allPatients.value.forEach(p => {
const key = p.idtiket ? `id-${p.idtiket}` : `bc-${p.barcode}`;
if (newPatientMap.has(key)) {
// If existing patient has more advanced status (waiting/di-loket), preserve it!
// If existing patient has more advanced status (anjungan/di-loket), preserve it!
// This handles cases where we updated status locally ('onsite' or 'api') but API is lagging
const statusPriority = { 'di-loket': 3, 'waiting': 2, 'menunggu': 1 };
const statusPriority = { 'di-loket': 3, 'anjungan': 2, 'menunggu': 1 };
const existingPrio = statusPriority[p.status] || 0;
const newPatient = newPatientMap.get(key);
const newPrio = statusPriority[newPatient.status] || 0;
@@ -577,7 +577,7 @@ export const useQueueStore = defineStore('queue', () => {
// kodeKlinik: "KD",
// fastTrack: "TIDAK",
// pembayaran: "Eksekutif",
// status: "waiting",
// status: "anjungan",
// processStage: "loket",
// createdAt: new Date().toISOString(),
// registrationType: 'online',
@@ -598,7 +598,7 @@ export const useQueueStore = defineStore('queue', () => {
// kodeKlinik: "IP",
// fastTrack: "TIDAK",
// pembayaran: "Eksekutif",
// status: "waiting",
// status: "anjungan",
// processStage: "loket",
// createdAt: new Date().toISOString(),
// registrationType: 'online',
@@ -619,7 +619,7 @@ export const useQueueStore = defineStore('queue', () => {
// kodeKlinik: "SR",
// fastTrack: "YA",
// pembayaran: "Eksekutif",
// status: "waiting",
// status: "anjungan",
// processStage: "loket",
// createdAt: new Date().toISOString(),
// registrationType: 'online',
@@ -640,7 +640,7 @@ export const useQueueStore = defineStore('queue', () => {
// kodeKlinik: "TH",
// fastTrack: "TIDAK",
// pembayaran: "VIP",
// status: "waiting",
// status: "anjungan",
// processStage: "loket",
// createdAt: new Date().toISOString(),
// registrationType: 'online',
@@ -890,7 +890,7 @@ export const useQueueStore = defineStore('queue', () => {
return {
all: patients,
waiting: patients.filter(p => p.status === 'waiting'),
anjungan: patients.filter(p => p.status === 'anjungan'),
menunggu: patients.filter(p => p.status === 'menunggu'),
diLoket: patients.filter(p => p.status === 'di-loket'),
terlambat: patients.filter(p => p.status === 'terlambat'),
@@ -977,20 +977,47 @@ export const useQueueStore = defineStore('queue', () => {
return { success: false, message: "Kuota sudah penuh" };
}
// Update status menjadi 'waiting' (Masuk ke antrean aktif)
// Update status menjadi 'anjungan' (Masuk ke antrean aktif)
const callTimestamp = new Date().toISOString();
const index = allPatients.value.findIndex(p => p.no === nextPatient.no);
if (index !== -1) {
allPatients.value[index] = {
...allPatients.value[index],
status: "waiting",
status: "anjungan",
// Assign to this specific loket if it was unassigned
loketId: (adminType === 'loket' && targetId) ? parseInt(targetId) : allPatients.value[index].loketId,
lastCalledAt: callTimestamp
};
// SYNC to apiPatientsPerLoket if it's an API patient
syncApiPatientStatus(allPatients.value[index], "waiting");
syncApiPatientStatus(allPatients.value[index], "anjungan");
// POST to external API when patient is called
try {
fetch('http://10.10.150.131:8089/api/v1/tiket/update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
idtiket: nextPatient.barcode || "",
statuspasien: "3",
statuspasien2: "4",
idklinikstatus: "1",
idklinikstatus2: "1"
})
}).then(response => {
if (response.ok) {
console.log(`✅ Successfully posted status update for patient ${nextPatient.barcode}`);
} else {
console.error(`⚠️ Failed to post status update for patient ${nextPatient.barcode}:`, response.status);
}
}).catch(error => {
console.error(`❌ Error posting status update for patient ${nextPatient.barcode}:`, error);
});
} catch (error) {
console.error(`❌ Error initiating status update for patient ${nextPatient.barcode}:`, error);
}
}
return {
@@ -1045,10 +1072,10 @@ export const useQueueStore = defineStore('queue', () => {
const patientsToCall = menungguList.slice(0, maxCallable);
const callTimestamp = new Date().toISOString();
patientsToCall.forEach((patient) => {
patientsToCall.forEach(async (patient) => {
const index = allPatients.value.findIndex(p => p.no === patient.no);
if (index !== -1) {
const newStatus = "waiting";
const newStatus = "anjungan";
const newLoketId = (adminType === 'loket' && targetId) ? targetId : allPatients.value[index].loketId;
allPatients.value[index] = {
@@ -1060,6 +1087,31 @@ export const useQueueStore = defineStore('queue', () => {
// SYNC to apiPatientsPerLoket if it's an API patient
syncApiPatientStatus(allPatients.value[index], newStatus);
// POST to external API when patient is called
try {
const response = await fetch('http://10.10.150.131:8089/api/v1/tiket/update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
idtiket: patient.barcode || "",
statuspasien: "3",
statuspasien2: "4",
idklinikstatus: "1",
idklinikstatus2: "1"
})
});
if (response.ok) {
console.log(`✅ Successfully posted status update for patient ${patient.barcode}`);
} else {
console.error(`⚠️ Failed to post status update for patient ${patient.barcode}:`, response.status);
}
} catch (error) {
console.error(`❌ Error posting status update for patient ${patient.barcode}:`, error);
}
}
});
@@ -1375,7 +1427,7 @@ export const useQueueStore = defineStore('queue', () => {
fastTrack: patient ? (patient.fastTrack || "TIDAK") : "TIDAK",
pembayaran: patient ? patient.pembayaran : "UMUM",
noRM: patient ? patient.noRM : null,
status: "waiting",
status: "anjungan",
processStage: "klinik-ruang", // Set ke klinik-ruang langsung
createdAt: timestamp.toISOString(),
referencePatient: patient ? patient.noAntrian : null,
@@ -1517,7 +1569,7 @@ export const useQueueStore = defineStore('queue', () => {
tipeLayanan: tipeLayanan,
fastTrack: sourcePatient.fastTrack || "TIDAK",
pembayaran: sourcePatient.pembayaran || "UMUM",
status: "waiting",
status: "anjungan",
processStage: "klinik-ruang",
createdAt: sourcePatient.createdAt || timestamp.toISOString(), // Gunakan createdAt dari pasien awal
referencePatient: sourcePatient.noAntrian,
@@ -1618,7 +1670,7 @@ export const useQueueStore = defineStore('queue', () => {
tipeLayanan: tipeLayanan,
fastTrack: sourcePatient.fastTrack || "TIDAK",
pembayaran: sourcePatient.pembayaran || "UMUM",
status: "waiting",
status: "anjungan",
processStage: "klinik-ruang",
createdAt: sourcePatient.createdAt || timestamp.toISOString(), // Gunakan createdAt dari pasien awal
referencePatient: sourcePatient.noAntrian,
@@ -1649,7 +1701,7 @@ export const useQueueStore = defineStore('queue', () => {
return {
all: patients,
waiting: patients.filter(p => p.status === 'waiting'),
anjungan: patients.filter(p => p.status === 'anjungan'),
diLoket: patients.filter(p => p.status === 'di-loket'),
terlambat: patients.filter(p => p.status === 'terlambat'),
pending: patients.filter(p => p.status === 'pending'),
@@ -1664,10 +1716,10 @@ export const useQueueStore = defineStore('queue', () => {
p.nomorRuang === nomorRuang &&
p.tipeLayanan === tipeLayanan &&
p.processStage === 'klinik-ruang' &&
(p.status === 'waiting' || (allowMultiple && p.status === 'di-loket'))
(p.status === 'anjungan' || (allowMultiple && p.status === 'di-loket'))
).sort((a, b) => {
// Sort by status priority first: waiting=1, di-loket=2
const statusPriority = { 'waiting': 1, 'di-loket': 2 };
// Sort by status priority first: anjungan=1, di-loket=2
const statusPriority = { 'anjungan': 1, 'di-loket': 2 };
const priorityDiff = (statusPriority[a.status] || 99) - (statusPriority[b.status] || 99);
if (priorityDiff !== 0) return priorityDiff;
@@ -1895,12 +1947,17 @@ export const useQueueStore = defineStore('queue', () => {
const idloket = targetLoket ? String(targetLoket.id) : "2"; // Default fallback to "2" if not found
// 2. Prepare API Body
// 2. Determine idpembayaran based on paymentType
// BPJS (JKN) = "2", UMUM and others = "1"
const idpembayaran = paymentType === "BPJS" ? "2" : "1";
// 3. Prepare API Body
const body = {
idloket: idloket,
dokter: "",
idklinik: String(clinic.id),
namaklinik: clinic.name,
idpembayaran: idpembayaran,
statuspasien: "1",
statuspasien2: "2",
idklinikstatus: "1"
@@ -2046,7 +2103,7 @@ export const useQueueStore = defineStore('queue', () => {
};
// Check-in patient (update status from waiting to di-loket)
// Check-in patient (update status from anjungan to di-loket)
// IMPORTANT: Hanya menggunakan EXACT barcode match untuk menghindari false positive
// Format barcode: YYMMDD + 5 digit (contoh: 26011500001)
// Jangan gunakan fallback ke noAntrian atau no karena bisa menyebabkan false positive
@@ -2096,7 +2153,7 @@ export const useQueueStore = defineStore('queue', () => {
processStage: patient.processStage
});
// Only allow check-in if status is waiting (sudah dipanggil) or pending
// Only allow check-in if status is anjungan (sudah dipanggil) or pending
// Pasien dengan status "menunggu" belum bisa check-in (belum dipanggil)
if (patient.status === 'menunggu') {
console.log('⚠️ Patient status is menunggu (belum dipanggil):', patient.status);
@@ -2115,8 +2172,8 @@ export const useQueueStore = defineStore('queue', () => {
};
}
if (patient.status !== 'waiting' && patient.status !== 'pending') {
console.log('⚠️ Patient status is not waiting/pending:', patient.status);
if (patient.status !== 'anjungan' && patient.status !== 'pending') {
console.log('⚠️ Patient status is not anjungan/pending:', patient.status);
return {
success: false,
message: `Pasien tidak dapat check-in. Status saat ini: ${patient.status}`
@@ -2155,7 +2212,7 @@ export const useQueueStore = defineStore('queue', () => {
console.log(`🚀 [processNextQueue] Processing for ${key} (Stage: ${targetStage})`);
// 2. Find next patient (Status: 'menunggu' -> 'waiting')
// 2. Find next patient (Status: 'menunggu' -> 'anjungan')
// Prioritaskan yang assigned ke loket ini (loketId) jika ada match
let nextPatient = null;
@@ -2177,10 +2234,10 @@ export const useQueueStore = defineStore('queue', () => {
);
}
// Fallback: Check 'waiting' status if needed (though usually 'menunggu' is for calling)
// Fallback: Check 'anjungan' status if needed (though usually 'menunggu' is for calling)
if (!nextPatient) {
nextPatient = allPatients.value.find(p =>
p.status === 'waiting' &&
p.status === 'anjungan' &&
p.processStage === targetStage &&
(adminType !== 'loket' || String(p.loketId) === String(specificId))
);