Clinical: 잘못 측정한 값 폐기 — Discard(측정 중) + Delete(측정 후 + labdb 서버)
회의 결정: 잘못 측정한 경우를 없앨 방법이 없었음. 두 시점 모두 제공.
ClinicalSessionStore:
- discardAndDeleteFolder(): 측정 중 즉시 폐기. endMeasurement 호출 안 하고
currentSession + cyclesBuffer 비우고 폴더 전체 삭제.
- deleteFinalizedFolder(): lastFinalizedFolder 로컬 삭제 + reset.
LabdbClient.deleteSession(testId):
DELETE /api/v1/sessions/{testId} — Cascade로 모든 records 함께 제거.
204/200/404 모두 성공 처리 (404 = 이미 없음, 멱등).
401 → 자격 clear + Reregister, 403 → PendingApproval, 429 → RateLimit.
LabdbUploader.deleteSessionForFolder(folder):
labdb_upload.json에 sessionId 있으면 그것을, 없으면 sanitizeTestId(폴더명).
미업로드 폴더에 대해서도 안전하게 호출 가능 (404 처리).
ClinicalLiveView:
- 기존 End Session 단일 버튼 → Discard + End Session 두 버튼 (50/50 Row)
- Discard: 빨간 outline. confirm dialog → 폴더 삭제 + ClinicalHome 복귀
- 사이클 진행 중에도 누를 수 있음 (잘못 측정 즉시 인지 시)
ClinicalHomeView:
- Last saved 카드에 Upload 버튼 옆 (또는 단독) Delete 버튼 추가
- confirm dialog → labdb 서버 DELETE 시도 → 로컬 폴더 삭제 → state reset
- 서버 실패해도 로컬은 진행, Toast로 결과 표시
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -248,4 +248,32 @@ object ClinicalSessionStore {
|
||||
fun discardMeasurement() {
|
||||
currentSession = null
|
||||
}
|
||||
|
||||
/**
|
||||
* 측정 중인 세션을 즉시 폐기 + 폴더 완전 삭제 (잘못 측정 인지 시).
|
||||
* endMeasurement()와 달리 meta.json/measurement.json/labdb 업로드 전부 skip.
|
||||
* 반환: 삭제된 폴더 경로 (없으면 null).
|
||||
*/
|
||||
fun discardAndDeleteFolder(): File? {
|
||||
val dir = currentLogDir()
|
||||
currentSession = null
|
||||
cyclesBuffer.clear()
|
||||
if (dir != null && dir.exists()) {
|
||||
dir.deleteRecursively()
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
/**
|
||||
* 이미 finalize된 측정 폴더(lastFinalizedFolder)를 삭제.
|
||||
* labdb 서버 데이터까지 제거하려면 호출자가 LabdbClient.deleteSession()도 별도 호출.
|
||||
*/
|
||||
fun deleteFinalizedFolder(): File? {
|
||||
val dir = lastFinalizedFolder
|
||||
if (dir != null && dir.exists()) {
|
||||
dir.deleteRecursively()
|
||||
}
|
||||
lastFinalizedFolder = null
|
||||
return dir
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -70,6 +70,22 @@ object LabdbUploader {
|
||||
return if (f.exists()) runCatching { JSONObject(f.readText()).optString("message") }.getOrNull() else null
|
||||
}
|
||||
|
||||
/**
|
||||
* 폴더에 해당하는 labdb 서버 세션 삭제.
|
||||
* labdb_upload.json에 sessionId가 있으면 그것을 사용, 없으면 folderName → sanitizeTestId 변환.
|
||||
* 미등록/미업로드 폴더의 testId도 그대로 호출 → labdb가 404로 응답 → 성공 처리.
|
||||
*/
|
||||
suspend fun deleteSessionForFolder(folder: File): Boolean {
|
||||
val uploadMarker = File(folder, "labdb_upload.json")
|
||||
val testId = if (uploadMarker.exists()) {
|
||||
runCatching { JSONObject(uploadMarker.readText()).optString("sessionId") }
|
||||
.getOrNull()?.takeIf { it.isNotBlank() } ?: sanitizeTestId(folder.name)
|
||||
} else {
|
||||
sanitizeTestId(folder.name)
|
||||
}
|
||||
return if (testId.isNotBlank()) LabdbClient.deleteSession(testId) else true
|
||||
}
|
||||
|
||||
/** measurement.json → labdb payload. 각 cycle = 1 record. */
|
||||
private fun buildPayload(folderName: String, measurement: JSONObject): JSONObject {
|
||||
val meta = measurement.optJSONObject("meta") ?: JSONObject()
|
||||
|
||||
+47
@@ -85,6 +85,8 @@ fun ClinicalHomeView(appState: AppState) {
|
||||
}
|
||||
var uploadBusy by remember { mutableStateOf(false) }
|
||||
var showUnpairConfirm by remember { mutableStateOf(false) }
|
||||
var showDeleteSavedConfirm by remember { mutableStateOf(false) }
|
||||
var deleteBusy by remember { mutableStateOf(false) }
|
||||
|
||||
// 진입 시 status 자동 확인 (apiKey 있을 때만)
|
||||
LaunchedEffect(Unit) {
|
||||
@@ -295,6 +297,8 @@ fun ClinicalHomeView(appState: AppState) {
|
||||
}
|
||||
)
|
||||
}
|
||||
Column(horizontalAlignment = Alignment.End,
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
if (!lastUploaded && LabdbCredentials.isRegistered) {
|
||||
Button(
|
||||
onClick = {
|
||||
@@ -319,9 +323,18 @@ fun ClinicalHomeView(appState: AppState) {
|
||||
}
|
||||
},
|
||||
enabled = !uploadBusy,
|
||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 12.dp, vertical = 4.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = MlPrimary)
|
||||
) { Text("Upload", color = Color.White, fontSize = 12.sp) }
|
||||
}
|
||||
// Delete — 잘못 측정 시 폐기 (로컬 + 서버)
|
||||
OutlinedButton(
|
||||
onClick = { showDeleteSavedConfirm = true },
|
||||
enabled = !deleteBusy && !uploadBusy,
|
||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 12.dp, vertical = 4.dp),
|
||||
colors = ButtonDefaults.outlinedButtonColors(contentColor = Color(0xFFE53935))
|
||||
) { Text("Delete", fontSize = 12.sp) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,6 +459,40 @@ fun ClinicalHomeView(appState: AppState) {
|
||||
fontSize = 10.sp, color = MlSecondaryText)
|
||||
}
|
||||
|
||||
// 잘못 측정한 폴더 삭제 confirm — 로컬 + labdb 서버 둘 다 (회의 결정: Yes 서버도)
|
||||
if (showDeleteSavedConfirm && lastFolder != null) {
|
||||
val targetFolder = lastFolder
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDeleteSavedConfirm = false },
|
||||
title = { Text("Delete measurement?") },
|
||||
text = { Text("폴더 + labdb 서버 데이터를 모두 삭제합니다. 복구 불가.\n\n${targetFolder.name}") },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
if (deleteBusy) return@TextButton
|
||||
showDeleteSavedConfirm = false
|
||||
deleteBusy = true
|
||||
scope.launch {
|
||||
// 1) labdb 서버 삭제 시도 (실패해도 로컬은 진행)
|
||||
val serverResult = runCatching {
|
||||
LabdbUploader.deleteSessionForFolder(targetFolder)
|
||||
}
|
||||
// 2) 로컬 폴더 삭제
|
||||
ClinicalSessionStore.deleteFinalizedFolder()
|
||||
lastUploaded = false
|
||||
lastUploadError = null
|
||||
val msg = if (serverResult.isSuccess) "Deleted (local + server)"
|
||||
else "Local deleted, server failed: ${serverResult.exceptionOrNull()?.message}"
|
||||
Toast.makeText(context, msg, Toast.LENGTH_LONG).show()
|
||||
deleteBusy = false
|
||||
}
|
||||
}) { Text("Delete", color = Color.Red) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showDeleteSavedConfirm = false }) { Text("Cancel") }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showUnpairConfirm) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showUnpairConfirm = false },
|
||||
|
||||
+38
-2
@@ -271,7 +271,19 @@ fun ClinicalLiveView(appState: AppState) {
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
// End Session
|
||||
// End Session / Discard 두 버튼 나란히
|
||||
var showDiscardConfirm by remember { mutableStateOf(false) }
|
||||
Row(modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
// Discard — 측정값 폐기 + 폴더 삭제 (저장 안 함)
|
||||
OutlinedButton(
|
||||
onClick = { showDiscardConfirm = true },
|
||||
modifier = Modifier.weight(1f).height(48.dp),
|
||||
colors = ButtonDefaults.outlinedButtonColors(contentColor = Color(0xFFE53935))
|
||||
) {
|
||||
Text("Discard", fontWeight = FontWeight.Bold)
|
||||
}
|
||||
// End Session — 저장 + 자동 업로드
|
||||
Button(
|
||||
onClick = {
|
||||
isMeasuring = false
|
||||
@@ -282,11 +294,35 @@ fun ClinicalLiveView(appState: AppState) {
|
||||
}
|
||||
appState.currentScreen = AppScreen.CLINICAL_HOME
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp).height(48.dp),
|
||||
modifier = Modifier.weight(1f).height(48.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color.Red.copy(alpha = 0.85f))
|
||||
) {
|
||||
Text("End Session", color = Color.White, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
}
|
||||
|
||||
if (showDiscardConfirm) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDiscardConfirm = false },
|
||||
title = { Text("Discard measurement?") },
|
||||
text = { Text("현재 사이클 ${capturedCount}개 + 폴더 전체 삭제. labdb 업로드 안 함. 복구 불가.") },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
showDiscardConfirm = false
|
||||
isMeasuring = false
|
||||
val deleted = ClinicalSessionStore.discardAndDeleteFolder()
|
||||
deleted?.let {
|
||||
Toast.makeText(context, "Discarded: ${it.name}",
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
appState.currentScreen = AppScreen.CLINICAL_HOME
|
||||
}) { Text("Discard", color = Color.Red) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showDiscardConfirm = false }) { Text("Cancel") }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text("Cycle: ~600ms · Captured: $capturedCount · ${ClinicalSessionStore.currentLogDir()?.name ?: ""}",
|
||||
|
||||
Reference in New Issue
Block a user