Clinical: meta.json/measurement.json 파일명에 폴더 정보 포함 (식별성)

회의 피드백: 분석 PC로 파일만 옮기면 어떤 측정인지 식별 불가.
폴더명에는 SUBJECT_TYPE/device/posture/step/datetime이 다 있는데
파일은 generic 이름이라 폴더에서 빼면 어디 측정인지 모름.

수정:
  - meta.json        → meta_{folderName}.json
  - measurement.json → measurement_{folderName}.json
  예: measurement_PHANTOM_VBT26050202_SUPINE_ALIGN_0CM_2026-06-09_15-30-00.json

ClinicalSessionStore에 metaJsonFile / measurementJsonFile 헬퍼 추가.
writeMeta / writeMeasurementJson 둘 다 헬퍼 사용.

LabdbUploader.uploadBlocking 파일 탐색 순서:
  1. measurement_{folderName}.json  (신규)
  2. measurement.json               (구 버전 호환)
  3. measurement_*.json 패턴 매칭   (폴더명 다를 때 fallback)
  → 셋 다 못 찾으면 IllegalStateException

기존 폴더(구 파일명)는 그대로 업로드 가능. 새 폴더부터 새 형식 적용.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-09 16:32:19 +09:00
parent fd9078f9a1
commit 9f6cb36f00
2 changed files with 14 additions and 6 deletions
@@ -102,6 +102,13 @@ object ClinicalSessionStore {
/** clinical_label 컬럼/필드용. 비활성 시 "" */
fun currentLabel(): String = currentSession?.label ?: ""
/**
* 폴더명 정보를 파일명에 포함시켜 분석 PC로 옮긴 후에도 식별 가능하게.
* 예: meta_PHANTOM_VBT26050202_SUPINE_ALIGN_0CM_2026-06-09_15-30-00.json
*/
private fun metaJsonFile(dir: File): File = File(dir, "meta_${dir.name}.json")
private fun measurementJsonFile(dir: File): File = File(dir, "measurement_${dir.name}.json")
fun writeMeta(context: Context) {
val s = currentSession ?: return
val dir = currentLogDir() ?: return
@@ -149,7 +156,7 @@ object ClinicalSessionStore {
if (hw.isNotEmpty()) put("hardware_version", hw)
if (sn.isNotEmpty()) put("serial_number", sn)
}
File(dir, "meta.json").writeText(meta.toString(2))
metaJsonFile(dir).writeText(meta.toString(2))
}
/** 측정 종료: endedAt → meta.json 갱신 → measurement.json 통합 생성 →
@@ -245,7 +252,7 @@ object ClinicalSessionStore {
}
root.put("cycles", cyclesArr)
File(dir, "measurement.json").writeText(root.toString(2))
measurementJsonFile(dir).writeText(root.toString(2))
} catch (_: Exception) {
// 저장 실패해도 측정 자체는 막지 않음
}
@@ -53,10 +53,11 @@ object LabdbUploader {
/** 동기 업로드 — 재시도 버튼/자동 호출 양쪽 사용. */
suspend fun uploadBlocking(folder: File): UploadResult {
val measurementFile = File(folder, "measurement.json")
if (!measurementFile.exists()) {
throw IllegalStateException("measurement.json not found in ${folder.name}")
}
// 새 파일명 (measurement_<folderName>.json) 우선, 구 버전 (measurement.json) fallback
val measurementFile = File(folder, "measurement_${folder.name}.json").takeIf { it.exists() }
?: File(folder, "measurement.json").takeIf { it.exists() }
?: folder.listFiles()?.firstOrNull { it.name.startsWith("measurement_") && it.name.endsWith(".json") }
?: throw IllegalStateException("measurement json not found in ${folder.name}")
val measurement = JSONObject(measurementFile.readText())
val payload = buildPayload(folder.name, measurement)
val result = LabdbClient.uploadJson(payload)