Files
web-antrean/refactor.py
T

55 lines
1.6 KiB
Python

import re
import sys
path = r'e:\antrean operasi\web-antrean\stores\queueStore.ts'
try:
with open(path, 'r', encoding='utf-8') as f:
content = f.read()
# 1. Add import for useQueueSync at the top
if 'useQueueSync' not in content:
content = content.replace("import { useQueueAPI } from '@/composables/useQueueAPI';", "import { useQueueAPI } from '@/composables/useQueueAPI';\nimport { useQueueSync } from '@/composables/useQueueSync';")
# 2. Remove the WEBSOCKET INTEGRATION block
ws_pattern = re.compile(r' // WEBSOCKET INTEGRATION \(CENTRALIZED\).*? const disconnectWebSocket = \(\) => \{\n disconnect\(\);\n \};', re.DOTALL)
content = ws_pattern.sub(' // WS and AutoSync logic extracted to composables/useQueueSync.ts', content)
# 3. Add the initialization right before return
init_code = """
// Initialize Queue Sync
const queueSync = useQueueSync({
allPatients,
currentProcessingPatient,
activeLoketInterest,
activeClinicInterest,
globalInterestCount,
fetchPatientsForLoket,
fetchPatientsForClinic,
fetchAllPatients
});
const {
isWsConnected,
wsClientId,
lastGlobalCall,
lastKlinikCall,
initWebSocket,
disconnectWebSocket,
sendViaPost,
startAutoSync,
stopAutoSync
} = queueSync;
return {
"""
content = content.replace(" return {\n // State\n allPatients,", init_code + " // State\n allPatients,")
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
print("Success")
except Exception as e:
print("Error:", e)
sys.exit(1)