Files
VesiscanClinicalAndroid/app/src/main/java/com/medithings/vesiscan/telemetry/ClinicalEventBus.kt
T
dw.jang 165df3c63d feat(telemetry): Phase B/C/D · ClinicalEventBus + emit (cloud-mvp 6856a7b 이식)
Phase D · telemetry/ClinicalEvent + ClinicalEventBus 신규 (demo-final path):
- sealed 계층 · schemaVersion · severity · isTransition · anonymized sessionId
- MutableSharedFlow (replay=0, buffer=64, DROP_OLDEST · fire-and-forget)
- PhiRedactor 없음 (demo-final) · TelemetryHash.sessionId (inline SHA-256) 사용

Phase A → BvEvent emit (AppState.updateLevelFromMeasurement):
- 매 측정마다 emit · urgency 전이 시 isTransition=true
- bvMethod 이름 · anonymized sessionId

Phase B/C → PostureEvent/GaitEvent emit (PiezoMonitoringView):
- composite posture 전이 시 PostureEvent (매 사이클 X · 트래픽 절약)
- walkingTransitioned 시 GaitEvent (severity=WARN on WALKING 진입)
- prevCompositePosture 상태 신규 추적

기존 SyncEvents/PostureEventLogger 와 병렬 · 서로 독립.

Refs: GUARDIAN-01 §3-2 이벤트 스키마 · §5 Phase A~D

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-08-03 17:22:48 +09:00

36 lines
1.1 KiB
Kotlin

/*
* ClinicalEventBus — 임상 이벤트 중앙 브로드캐스트 (SSOT).
* (GUARDIAN-01 §3-3 · 2026-08-03 · cloud-mvp 6856a7b 이식)
*
* fire-and-forget · emit 실패해도 필수기능 영향 X.
*/
package com.medithings.vesiscan.telemetry
import android.util.Log
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
object ClinicalEventBus {
private const val TAG = "ClinicalEventBus"
private val _events = MutableSharedFlow<ClinicalEvent>(
replay = 0,
extraBufferCapacity = 64,
onBufferOverflow = BufferOverflow.DROP_OLDEST,
)
val events: SharedFlow<ClinicalEvent> = _events.asSharedFlow()
fun emit(event: ClinicalEvent) {
try {
val delivered = _events.tryEmit(event)
if (!delivered) {
Log.w(TAG, "buffer full · dropped: ${event.javaClass.simpleName}")
}
} catch (e: Exception) {
Log.w(TAG, "emit failed: ${e.message}")
}
}
}