Initial commit
This commit is contained in:
293
cpone-dashboard/scripts/demo_live.sh
Normal file
293
cpone-dashboard/scripts/demo_live.sh
Normal file
@@ -0,0 +1,293 @@
|
||||
#!/usr/bin/env bash
|
||||
# demo_live.sh — Simulate live ongoing MCU activity for demo
|
||||
#
|
||||
# Usage:
|
||||
# ./demo_live.sh # default: 1 action every 8 seconds
|
||||
# ./demo_live.sh 3 # 1 action every 3 seconds (faster)
|
||||
# ./demo_live.sh 15 # 1 action every 15 seconds (slower)
|
||||
#
|
||||
# What it simulates (cycles through 4 action types):
|
||||
# A — New patient check-in for today (April 30, patients 811–825)
|
||||
# B — Station progress update for today's in-progress patients
|
||||
# C — Doctor validates a yesterday resume (April 29)
|
||||
# D — Publish result PDF (April 29 patient gets a file URL)
|
||||
#
|
||||
# Press Ctrl+C to stop.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
MCU_ID=9999
|
||||
TODAY="2026-04-30"
|
||||
SPEED="${1:-8}"
|
||||
|
||||
DB() { mysql -u admin -p'Sasone!102938' cpone_dashboard -sN -e "$1" 2>/dev/null; }
|
||||
DB_EXEC() { mysql -u admin -p'Sasone!102938' cpone_dashboard -e "$1" 2>/dev/null; }
|
||||
|
||||
PDF_BASE_DIR="/home/one/project/one/dashboard-files/2026/04"
|
||||
PDF_SOURCE="/home/one/project/one/dashboard-files/2024/09/R2409170003_resume_individu.pdf"
|
||||
PDF_DB_PATH="2026/04"
|
||||
|
||||
NOW_TS() { date '+%Y-%m-%d %H:%M:%S'; }
|
||||
LOG() { printf "[%s] %s\n" "$(date '+%H:%M:%S')" "$1"; }
|
||||
|
||||
# ── counters ──────────────────────────────────────────────────────────────────
|
||||
action_cycle=0
|
||||
|
||||
# ── ACTION A: new check-in ────────────────────────────────────────────────────
|
||||
action_checkin() {
|
||||
local patient
|
||||
patient=$(DB "
|
||||
SELECT mp.Mcu_PatientPreregisterID
|
||||
FROM mcu_patient mp
|
||||
WHERE mp.Mcu_PatientMcuID = $MCU_ID
|
||||
AND mp.Mcu_PatientPreregisterID NOT IN (
|
||||
SELECT Mcu_CheckinoutPreregisterID
|
||||
FROM mcu_checkinout
|
||||
WHERE Mcu_CheckinoutMcuID = $MCU_ID
|
||||
AND Mcu_CheckinoutDate = '$TODAY'
|
||||
)
|
||||
AND mp.Mcu_PatientPreregisterID BETWEEN 900811 AND 900825
|
||||
ORDER BY mp.Mcu_PatientPreregisterID
|
||||
LIMIT 1;
|
||||
")
|
||||
|
||||
if [ -z "$patient" ]; then
|
||||
LOG "⏩ Semua pasien hari ini sudah check-in"
|
||||
return
|
||||
fi
|
||||
|
||||
local pid=$patient
|
||||
local oid=$patient
|
||||
local name
|
||||
name=$(DB "SELECT Mcu_PatientName FROM mcu_patient WHERE Mcu_PatientPreregisterID = $pid;")
|
||||
local dept
|
||||
dept=$(DB "SELECT Mcu_PatientDepartment FROM mcu_patient WHERE Mcu_PatientPreregisterID = $pid;")
|
||||
local now_time
|
||||
now_time=$(date '+%H:%M:%S')
|
||||
|
||||
DB_EXEC "
|
||||
INSERT INTO mcu_checkinout
|
||||
(Mcu_CheckinoutMcuID, Mcu_CheckinoutPreregisterID, Mcu_CheckinoutOrderID,
|
||||
Mcu_CheckinoutDate, Mcu_CheckinoutInTime, Mcu_CheckinoutOutTime,
|
||||
Mcu_CheckinoutIsActive, Mcu_CheckinoutSyncedAt)
|
||||
VALUES
|
||||
($MCU_ID, $pid, $oid, '$TODAY', '$now_time', NULL, 'Y', NOW());
|
||||
"
|
||||
LOG "✅ CHECK-IN │ $name │ $dept │ masuk pukul $now_time"
|
||||
}
|
||||
|
||||
# ── ACTION B: station progress update ────────────────────────────────────────
|
||||
action_station() {
|
||||
# Pick a patient checked in today with at least one required station not yet done
|
||||
# Station IDs that are part of the MCU package
|
||||
local ALL_STATIONS="1,31,17,4,5,2,7,33"
|
||||
local patient
|
||||
patient=$(DB "
|
||||
SELECT c.Mcu_CheckinoutPreregisterID
|
||||
FROM mcu_checkinout c
|
||||
WHERE c.Mcu_CheckinoutMcuID = $MCU_ID
|
||||
AND c.Mcu_CheckinoutDate = '$TODAY'
|
||||
AND (
|
||||
SELECT COUNT(DISTINCT sp.Mcu_StationProgressStationID)
|
||||
FROM mcu_station_progress sp
|
||||
WHERE sp.Mcu_StationProgressPreregisterID = c.Mcu_CheckinoutPreregisterID
|
||||
AND sp.Mcu_StationProgressMcuID = $MCU_ID
|
||||
AND sp.Mcu_StationProgressStationID IN ($ALL_STATIONS)
|
||||
) < 8
|
||||
ORDER BY c.Mcu_CheckinoutPreregisterID
|
||||
LIMIT 1;
|
||||
")
|
||||
|
||||
if [ -z "$patient" ]; then
|
||||
LOG "⏩ Semua station sudah diproses untuk pasien hari ini"
|
||||
return
|
||||
fi
|
||||
|
||||
local pid=$patient
|
||||
local oid=$patient
|
||||
local name
|
||||
name=$(DB "SELECT Mcu_PatientName FROM mcu_patient WHERE Mcu_PatientPreregisterID = $pid;")
|
||||
|
||||
# Get next station not yet done (from the 8-station package)
|
||||
local station_row
|
||||
station_row=$(DB "
|
||||
SELECT s.sid, s.sname, s.src
|
||||
FROM (
|
||||
SELECT 1 AS sid, 'Sample Station Phlebotomy' AS sname, 'lab' AS src UNION ALL
|
||||
SELECT 31,'Sample Station Urine','lab' UNION ALL
|
||||
SELECT 17,'Sample Station TB/BB','nonlab' UNION ALL
|
||||
SELECT 4, 'Sample Station Treadmill','nonlab' UNION ALL
|
||||
SELECT 5, 'Sample Station ECG','nonlab' UNION ALL
|
||||
SELECT 2, 'Sample Station Rontgen','nonlab' UNION ALL
|
||||
SELECT 7, 'Sample Station Pemeriksaan Fisik','nonlab' UNION ALL
|
||||
SELECT 33,'Sample Station Visus dan Buta Warna','nonlab'
|
||||
) s
|
||||
WHERE s.sid NOT IN (
|
||||
SELECT Mcu_StationProgressStationID
|
||||
FROM mcu_station_progress
|
||||
WHERE Mcu_StationProgressPreregisterID = $pid
|
||||
AND Mcu_StationProgressMcuID = $MCU_ID
|
||||
)
|
||||
LIMIT 1;
|
||||
")
|
||||
|
||||
if [ -z "$station_row" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local sid sname src
|
||||
sid=$(echo "$station_row" | cut -f1)
|
||||
sname=$(echo "$station_row" | cut -f2)
|
||||
src=$(echo "$station_row" | cut -f3)
|
||||
local now_ts
|
||||
now_ts=$(NOW_TS)
|
||||
|
||||
if [ "$src" = "lab" ]; then
|
||||
DB_EXEC "
|
||||
INSERT INTO mcu_station_progress
|
||||
(Mcu_StationProgressOrderID, Mcu_StationProgressPreregisterID, Mcu_StationProgressMcuID,
|
||||
Mcu_StationProgressStationID, Mcu_StationProgressStationName, Mcu_StationProgressSource,
|
||||
Mcu_StationProgressCheckinDate, Mcu_StationProgressSamplingAt, Mcu_StationProgressReceiveAt,
|
||||
Mcu_StationProgressProcessAt, Mcu_StationProgressDoneAt, Mcu_StationProgressSyncedAt)
|
||||
VALUES
|
||||
($oid, $pid, $MCU_ID, $sid, '$sname', 'lab',
|
||||
'$TODAY',
|
||||
DATE_SUB('$now_ts', INTERVAL 45 MINUTE),
|
||||
DATE_SUB('$now_ts', INTERVAL 30 MINUTE),
|
||||
DATE_SUB('$now_ts', INTERVAL 10 MINUTE),
|
||||
'$now_ts', NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Mcu_StationProgressDoneAt = '$now_ts',
|
||||
Mcu_StationProgressSyncedAt = NOW();
|
||||
"
|
||||
else
|
||||
DB_EXEC "
|
||||
INSERT INTO mcu_station_progress
|
||||
(Mcu_StationProgressOrderID, Mcu_StationProgressPreregisterID, Mcu_StationProgressMcuID,
|
||||
Mcu_StationProgressStationID, Mcu_StationProgressStationName, Mcu_StationProgressSource,
|
||||
Mcu_StationProgressCheckinDate, Mcu_StationProgressSamplingAt, Mcu_StationProgressReceiveAt,
|
||||
Mcu_StationProgressProcessAt, Mcu_StationProgressDoneAt, Mcu_StationProgressSyncedAt)
|
||||
VALUES
|
||||
($oid, $pid, $MCU_ID, $sid, '$sname', 'nonlab',
|
||||
'$TODAY', NULL, NULL,
|
||||
DATE_SUB('$now_ts', INTERVAL 15 MINUTE),
|
||||
'$now_ts', NOW())
|
||||
ON DUPLICATE KEY UPDATE
|
||||
Mcu_StationProgressDoneAt = '$now_ts',
|
||||
Mcu_StationProgressSyncedAt = NOW();
|
||||
"
|
||||
fi
|
||||
LOG "🏥 STATION │ $name │ $sname │ selesai"
|
||||
}
|
||||
|
||||
# ── ACTION C: validate resume ─────────────────────────────────────────────────
|
||||
action_validate() {
|
||||
local patient
|
||||
patient=$(DB "
|
||||
SELECT rs.Mcu_PatientResumeStatusPreregisterID
|
||||
FROM mcu_patient_resume_status rs
|
||||
JOIN mcu_patient mp ON mp.Mcu_PatientPreregisterID = rs.Mcu_PatientResumeStatusPreregisterID
|
||||
WHERE rs.Mcu_PatientResumeStatusMcuID = $MCU_ID
|
||||
AND rs.Mcu_PatientResumeStatusValidated = 'N'
|
||||
AND mp.Mcu_PatientPreregisterID BETWEEN 900676 AND 900750
|
||||
ORDER BY rs.Mcu_PatientResumeStatusPreregisterID
|
||||
LIMIT 1;
|
||||
")
|
||||
|
||||
if [ -z "$patient" ]; then
|
||||
LOG "⏩ Semua resume kemarin sudah divalidasi"
|
||||
return
|
||||
fi
|
||||
|
||||
local name
|
||||
name=$(DB "SELECT Mcu_PatientName FROM mcu_patient WHERE Mcu_PatientPreregisterID = $patient;")
|
||||
|
||||
DB_EXEC "
|
||||
UPDATE mcu_patient_resume_status
|
||||
SET Mcu_PatientResumeStatusValidated = 'Y',
|
||||
Mcu_PatientResumeStatusStatus = 'DONE',
|
||||
Mcu_PatientResumeSyncedAt = NOW()
|
||||
WHERE Mcu_PatientResumeStatusPreregisterID = $patient
|
||||
AND Mcu_PatientResumeStatusMcuID = $MCU_ID;
|
||||
"
|
||||
LOG "✔ VALIDASI │ $name │ resume divalidasi dokter"
|
||||
}
|
||||
|
||||
# ── ACTION D: publish PDF ─────────────────────────────────────────────────────
|
||||
action_publish() {
|
||||
local order_id
|
||||
order_id=$(DB "
|
||||
SELECT rs.Mcu_PatientResumeStatusPreregisterID
|
||||
FROM mcu_patient_resume_status rs
|
||||
WHERE rs.Mcu_PatientResumeStatusMcuID = $MCU_ID
|
||||
AND rs.Mcu_PatientResumeStatusValidated = 'Y'
|
||||
AND rs.Mcu_PatientResumeStatusPublished = 'N'
|
||||
AND rs.Mcu_PatientResumeStatusPreregisterID BETWEEN 900676 AND 900825
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM published_mcu_dashboard_sync p
|
||||
WHERE p.Published_McuDasboardT_OrderHeaderID = rs.Mcu_PatientResumeStatusPreregisterID
|
||||
AND (p.Published_McuDasboardFileUrl IS NULL OR p.Published_McuDasboardFileUrl = '')
|
||||
)
|
||||
ORDER BY rs.Mcu_PatientResumeStatusPreregisterID
|
||||
LIMIT 1;
|
||||
")
|
||||
|
||||
if [ -z "$order_id" ]; then
|
||||
LOG "⏩ Tidak ada resume validated yang bisa dipublish saat ini"
|
||||
return
|
||||
fi
|
||||
|
||||
local name
|
||||
name=$(DB "SELECT Mcu_PatientName FROM mcu_patient WHERE Mcu_PatientPreregisterID = $order_id;")
|
||||
|
||||
# seq number for PDF filename: use order_id offset
|
||||
local seq=$(( order_id - 900000 ))
|
||||
local fname="R2604D${seq}_resume_individu.pdf"
|
||||
local fpath="$PDF_BASE_DIR/$fname"
|
||||
local db_path="$PDF_DB_PATH/$fname"
|
||||
|
||||
# Copy PDF file
|
||||
mkdir -p "$PDF_BASE_DIR"
|
||||
cp "$PDF_SOURCE" "$fpath" 2>/dev/null || true
|
||||
|
||||
# Update database
|
||||
DB_EXEC "
|
||||
UPDATE published_mcu_dashboard_sync
|
||||
SET Published_McuDasboardFileUrl = '$db_path',
|
||||
Published_McuDasboardStatus = 'Y',
|
||||
Published_McuDasboardLastUpdated = NOW()
|
||||
WHERE Published_McuDasboardT_OrderHeaderID = $order_id;
|
||||
|
||||
UPDATE mcu_patient_resume_status
|
||||
SET Mcu_PatientResumeStatusPublished = 'Y',
|
||||
Mcu_PatientResumeSyncedAt = NOW()
|
||||
WHERE Mcu_PatientResumeStatusPreregisterID = $order_id
|
||||
AND Mcu_PatientResumeStatusMcuID = $MCU_ID;
|
||||
"
|
||||
LOG "📄 PUBLISH │ $name │ PDF → $db_path"
|
||||
}
|
||||
|
||||
# ── main loop ─────────────────────────────────────────────────────────────────
|
||||
echo "╔══════════════════════════════════════════════════════════════╗"
|
||||
echo "║ CpOne — DEMO LIVE SIMULATION ║"
|
||||
echo "║ MCU PROJECT DEMO 2026 │ ID: $MCU_ID │ Hari ini: $TODAY ║"
|
||||
echo "╚══════════════════════════════════════════════════════════════╝"
|
||||
echo ""
|
||||
echo " Aksi: A=Check-in B=Station C=Validasi D=Publish PDF"
|
||||
echo " Interval: ${SPEED}s │ Ctrl+C untuk berhenti"
|
||||
echo ""
|
||||
|
||||
actions=(A B C D)
|
||||
idx=0
|
||||
|
||||
while true; do
|
||||
act="${actions[$((idx % 4))]}"
|
||||
case "$act" in
|
||||
A) action_checkin ;;
|
||||
B) action_station ;;
|
||||
C) action_validate ;;
|
||||
D) action_publish ;;
|
||||
esac
|
||||
idx=$(( idx + 1 ))
|
||||
sleep "$SPEED"
|
||||
done
|
||||
Reference in New Issue
Block a user