update status klinik ruang
This commit is contained in:
@@ -982,9 +982,10 @@ const fetchPatientsFromAPI = async () => {
|
||||
const klinikId = clinic.id;
|
||||
|
||||
// Build API URL with filters - using Nuxt proxy to avoid CORS
|
||||
// CRITICAL: Do NOT use active filter at top level - we need to see all healthcare_services
|
||||
// to filter by healthcare_type_name="KLINIK" with active=true
|
||||
const baseUrl = '/visit-api/visit';
|
||||
const params = new URLSearchParams({
|
||||
active: '1',
|
||||
klinik_id: klinikId.toString(),
|
||||
limit: '500'
|
||||
});
|
||||
@@ -1019,7 +1020,13 @@ const fetchPatientsFromAPI = async () => {
|
||||
|
||||
data.forEach((visit, index) => {
|
||||
// Each visit can have multiple healthcare_services (sub-services/rooms)
|
||||
const healthcareServices = visit.healthcare_services || [];
|
||||
const allHealthcareServices = visit.healthcare_services || [];
|
||||
|
||||
// CRITICAL FIX: Filter for KLINIK healthcare_type_name with active=true
|
||||
// This identifies patients who have been transferred to klinik ruang
|
||||
const healthcareServices = allHealthcareServices.filter(service =>
|
||||
service.healthcare_type_name === 'KLINIK' && service.active === true
|
||||
);
|
||||
|
||||
if (healthcareServices.length > 0) {
|
||||
healthcareServices.forEach(service => {
|
||||
@@ -1381,8 +1388,8 @@ const getAllPatientsForRoom = (ruang) => {
|
||||
p.kodeKlinik === klinikData.value?.kodeKlinik &&
|
||||
p.nomorRuang === ruang.nomorRuang &&
|
||||
p.processStage === 'klinik-ruang' &&
|
||||
// Include semua pasien dengan status yang relevan (including pemeriksaan for API patients)
|
||||
(p.status === 'anjungan' || p.status === 'pemeriksaan' || p.status === 'di-loket' || p.status === 'terlambat' || p.status === 'pending');
|
||||
// CRITICAL: Only show patients with status "pemeriksaan" (from loket to klinik ruang)
|
||||
p.status === 'pemeriksaan';
|
||||
|
||||
if (!matches && p.kodeKlinik === klinikData.value?.kodeKlinik) {
|
||||
console.log('❌ Patient did not match room:', {
|
||||
|
||||
+50
-11
@@ -776,20 +776,48 @@ const buatAntreanKlinikRuang = async (klinikRuang, ruang) => {
|
||||
(patient.pembayaran || '').toUpperCase().includes('GRAND')
|
||||
? 2 : 1;
|
||||
|
||||
// Get idruangan from ruang object, ensure it's a number or null
|
||||
let subHealthcareServiceId = null;
|
||||
if (ruang.kodeRuang) {
|
||||
const parsed = Number(ruang.kodeRuang);
|
||||
subHealthcareServiceId = isNaN(parsed) ? null : parsed;
|
||||
} else if (ruang.idruangan) {
|
||||
const parsed = Number(ruang.idruangan);
|
||||
subHealthcareServiceId = isNaN(parsed) ? null : parsed;
|
||||
}
|
||||
|
||||
// Ensure healthcare_service_id is a number - MUST use actual clinic ID from clinicStore
|
||||
const actualClinic = clinicStore.clinics.find(c => c.kode === klinikRuang.kodeKlinik);
|
||||
const healthcareServiceId = actualClinic ? Number(actualClinic.id) : null;
|
||||
|
||||
// Get idruangan from ruang object, ensure it's a number or null
|
||||
console.log('🔍 Debug ruang object:', ruang);
|
||||
console.log('🔍 ruang.kodeRuang:', ruang.kodeRuang);
|
||||
console.log('🔍 ruang.idruangan:', ruang.idruangan);
|
||||
|
||||
let subHealthcareServiceId = null;
|
||||
if (ruang.kodeRuang) {
|
||||
const parsed = Number(ruang.kodeRuang);
|
||||
|
||||
// CRITICAL FIX: Check if kodeRuang is actually the clinic ID (fallback value)
|
||||
// This happens when clinic doesn't have actual sub_healthcare rooms
|
||||
if (!isNaN(parsed) && parsed === healthcareServiceId) {
|
||||
// kodeRuang equals clinic ID = no sub_healthcare, set to null
|
||||
subHealthcareServiceId = null;
|
||||
console.log('🔍 kodeRuang equals clinic ID (fallback) -> subHealthcareServiceId: null');
|
||||
} else {
|
||||
subHealthcareServiceId = isNaN(parsed) ? null : parsed;
|
||||
console.log('🔍 Parsed kodeRuang:', ruang.kodeRuang, '-> subHealthcareServiceId:', subHealthcareServiceId);
|
||||
}
|
||||
} else if (ruang.idruangan) {
|
||||
const parsed = Number(ruang.idruangan);
|
||||
|
||||
// Same check for idruangan
|
||||
if (!isNaN(parsed) && parsed === healthcareServiceId) {
|
||||
subHealthcareServiceId = null;
|
||||
console.log('🔍 idruangan equals clinic ID (fallback) -> subHealthcareServiceId: null');
|
||||
} else {
|
||||
subHealthcareServiceId = isNaN(parsed) ? null : parsed;
|
||||
console.log('🔍 Parsed idruangan:', ruang.idruangan, '-> subHealthcareServiceId:', subHealthcareServiceId);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🔍 Clinic Info:');
|
||||
console.log(' - klinikRuang.kodeKlinik:', klinikRuang.kodeKlinik);
|
||||
console.log(' - actualClinic:', actualClinic);
|
||||
console.log(' - healthcareServiceId:', healthcareServiceId);
|
||||
console.log(' - subHealthcareServiceId:', subHealthcareServiceId);
|
||||
|
||||
if (!healthcareServiceId) {
|
||||
console.error('❌ Could not find clinic ID for kode:', klinikRuang.kodeKlinik);
|
||||
snackbarText.value = "Gagal membuat antrean ruang: ID klinik tidak ditemukan";
|
||||
@@ -808,7 +836,7 @@ const buatAntreanKlinikRuang = async (klinikRuang, ruang) => {
|
||||
visit_type_id: 1,
|
||||
service_type_id: serviceTypeId,
|
||||
healthcare_type_id: 2
|
||||
};
|
||||
}
|
||||
|
||||
console.log('📤 Sending visit ticket to API:', visitTicketBody);
|
||||
|
||||
@@ -889,6 +917,17 @@ const buatAntreanKlinikRuang = async (klinikRuang, ruang) => {
|
||||
);
|
||||
|
||||
if (result.success && result.patient) {
|
||||
// CRITICAL: Update source patient status to "processed" after klinik ruang creation
|
||||
// This prevents duplicate patients with different statuses in Admin Klinik Ruang
|
||||
const sourcePatientIndex = queueStore.allPatients.findIndex(p => p.no === patient.no);
|
||||
if (sourcePatientIndex !== -1) {
|
||||
queueStore.allPatients[sourcePatientIndex] = {
|
||||
...queueStore.allPatients[sourcePatientIndex],
|
||||
status: "processed"
|
||||
};
|
||||
console.log(`✅ Updated source patient ${patient.noAntrian} status to "processed"`);
|
||||
}
|
||||
|
||||
try {
|
||||
await printTicketFromPatient(result.patient);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1536,7 +1536,7 @@ export const useQueueStore = defineStore('queue', () => {
|
||||
fastTrack: patient ? (patient.fastTrack || "TIDAK") : "TIDAK",
|
||||
pembayaran: patient ? patient.pembayaran : "UMUM",
|
||||
noRM: patient ? patient.noRM : null,
|
||||
status: "anjungan",
|
||||
status: "pemeriksaan", // Patients from loket to klinik ruang start as "pemeriksaan"
|
||||
processStage: "klinik-ruang", // Set ke klinik-ruang langsung
|
||||
createdAt: timestamp.toISOString(),
|
||||
referencePatient: patient ? patient.noAntrian : null,
|
||||
|
||||
Reference in New Issue
Block a user