update post api status dan API data pasien ruang
This commit is contained in:
+63
-22
@@ -169,7 +169,7 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
processStage: 'loket',
|
||||
createdAt: apiPatient.tanggal || new Date().toISOString(),
|
||||
registrationType: 'api',
|
||||
visitType: 'SEKARANG',
|
||||
visitType: 'Onsite',
|
||||
visitDate: apiPatient.tanggal ? apiPatient.tanggal.split('T')[0] : new Date().toISOString().substring(0, 10),
|
||||
namaDokter: null,
|
||||
noRM: null,
|
||||
@@ -325,13 +325,21 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
});
|
||||
|
||||
// 4. Remove existing patients that collide with new ones (to be replaced)
|
||||
// AND remove stale 'api' patients for this loket
|
||||
// This ensures API data ALWAYS takes precedence over local/seed data
|
||||
// Remove ANY patient (local, seed, or api) with matching barcode/idtiket
|
||||
allPatients.value = allPatients.value.filter(p => {
|
||||
const key = p.idtiket ? `id-${p.idtiket}` : `bc-${p.barcode}`;
|
||||
|
||||
// Remove if it's being replaced by new batch
|
||||
// Remove if it's being replaced by new API batch (matches by barcode or idtiket)
|
||||
if (newPatientMap.has(key)) return false;
|
||||
|
||||
// Also check if barcode matches any new API patient (for cases where local has no idtiket)
|
||||
// This prevents duplicates like barcode "2602050017" appearing as both BPJS (local) and JKN (API)
|
||||
if (p.barcode) {
|
||||
const barcodeMatches = patientsWithLoketId.some(newP => newP.barcode === p.barcode);
|
||||
if (barcodeMatches) return false;
|
||||
}
|
||||
|
||||
// Remove if it's a stale 'api' patient for this loket (that wasn't in the new batch)
|
||||
if (p.registrationType === 'api' && String(p.loketId) === String(loketId)) return false;
|
||||
|
||||
@@ -1164,6 +1172,32 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
};
|
||||
syncApiPatientStatus(allPatients.value[patientIndex], "di-loket");
|
||||
message = `Pasien ${patientCode} berhasil check in dan masuk ke Tabel Loket Klinik`;
|
||||
|
||||
// POST to external API when patient finishes at loket
|
||||
try {
|
||||
fetch('http://10.10.150.131:8089/api/v1/tiket/selesai', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
idloket: String(patient.loketId || specificId || ""),
|
||||
barcode: patient.barcode || "",
|
||||
statuspasien: "9",
|
||||
idklinikstatus: "2"
|
||||
})
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
console.log(`✅ [queueStore] Successfully posted selesai status for patient ${patient.barcode}`);
|
||||
} else {
|
||||
console.error(`⚠️ [queueStore] Failed to post selesai status for patient ${patient.barcode}:`, response.status);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error(`❌ [queueStore] Error posting selesai status for patient ${patient.barcode}:`, error);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`❌ [queueStore] Error initiating selesai status update for patient ${patient.barcode}:`, error);
|
||||
}
|
||||
}
|
||||
// Jika check-in di klinik, selesai
|
||||
else if (adminType === 'klinik') {
|
||||
@@ -1402,7 +1436,7 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
};
|
||||
};
|
||||
|
||||
const createAntreanKlinikRuang = (klinikRuang, ruang, patient = null, adminType = 'klinik') => {
|
||||
const createAntreanKlinikRuang = (klinikRuang, ruang, patient = null, adminType = 'klinik', apiTicketNumber = null) => {
|
||||
const newNo = allPatients.value.length + 1;
|
||||
const timestamp = new Date();
|
||||
const barcode = patient ? patient.barcode : generateBarcode([], allPatients);
|
||||
@@ -1410,24 +1444,32 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
// Generate nomor antrian baru dengan format: [huruf pertama poli + urutan abjad ruang + nomor antrian ruang]
|
||||
// Contoh: "Anak" ruang 1 = "AA001" (A dari Anak, A dari ruang 1, 001 nomor antrian)
|
||||
|
||||
// 1. Ambil huruf pertama dari nama klinik/poli
|
||||
const firstLetter = klinikRuang.namaKlinik.charAt(0).toUpperCase();
|
||||
let newNoAntrian;
|
||||
|
||||
// 2. Konversi nomor ruang ke abjad (1 = A, 2 = B, 3 = C, dst)
|
||||
const ruangNumber = parseInt(ruang.nomorRuang) || 1;
|
||||
const ruangLetter = String.fromCharCode(64 + ruangNumber); // 64 = '@', 65 = 'A', 66 = 'B', dst
|
||||
|
||||
// 3. Hitung nomor antrian ruang (dimulai dari 1, maksimal 3 digit)
|
||||
const roomQueues = allPatients.value.filter(p =>
|
||||
p.kodeKlinik === klinikRuang.kodeKlinik &&
|
||||
p.nomorRuang === ruang.nomorRuang &&
|
||||
p.processStage === 'klinik-ruang'
|
||||
);
|
||||
const queueNumber = roomQueues.length + 1;
|
||||
const queueNumberStr = String(queueNumber).padStart(3, "0");
|
||||
|
||||
// 4. Format nomor antrian: AA001, AB002, dst
|
||||
const newNoAntrian = `${firstLetter}${ruangLetter}${queueNumberStr}`;
|
||||
// Use API ticket number if available, otherwise generate locally
|
||||
if (apiTicketNumber) {
|
||||
newNoAntrian = apiTicketNumber; // Use ticket from API (e.g., "PK001")
|
||||
console.log('🎫 Using API ticket number:', newNoAntrian);
|
||||
} else {
|
||||
// 1. Ambil huruf pertama dari nama klinik/poli
|
||||
const firstLetter = klinikRuang.namaKlinik.charAt(0).toUpperCase();
|
||||
|
||||
// 2. Konversi nomor ruang ke abjad (1 = A, 2 = B, 3 = C, dst)
|
||||
const ruangNumber = parseInt(ruang.nomorRuang) || 1;
|
||||
const ruangLetter = String.fromCharCode(64 + ruangNumber); // 64 = '@', 65 = 'A', 66 = 'B', dst
|
||||
|
||||
// 3. Hitung nomor antrian ruang (dimulai dari 1, maksimal 3 digit)
|
||||
const roomQueues = allPatients.value.filter(p =>
|
||||
p.kodeKlinik === klinikRuang.kodeKlinik &&
|
||||
p.nomorRuang === ruang.nomorRuang &&
|
||||
p.processStage === 'klinik-ruang'
|
||||
);
|
||||
const queueNumber = roomQueues.length + 1;
|
||||
const queueNumberStr = String(queueNumber).padStart(3, "0");
|
||||
|
||||
// 4. Format nomor antrian: AA001, AB002, dst
|
||||
newNoAntrian = `${firstLetter}${ruangLetter}${queueNumberStr}`;
|
||||
}
|
||||
|
||||
const newPatient = {
|
||||
no: newNo,
|
||||
@@ -1475,7 +1517,6 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
|
||||
// Pindah pasien ke klinik ruang lain dengan nomor antrian tetap
|
||||
const pindahKlinikRuang = (patient, targetKlinikRuang, targetRuang) => {
|
||||
const patientIndex = allPatients.value.findIndex(p => p.no === patient.no);
|
||||
|
||||
if (patientIndex === -1) {
|
||||
return { success: false, message: "Pasien tidak ditemukan" };
|
||||
|
||||
Reference in New Issue
Block a user