From 9f6cb36f006cdaf3ef174ab481daa16d04b1b415 Mon Sep 17 00:00:00 2001 From: jjangddu Date: Tue, 9 Jun 2026 16:32:19 +0900 Subject: [PATCH] =?UTF-8?q?Clinical:=20meta.json/measurement.json=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EB=AA=85=EC=97=90=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=ED=8F=AC=ED=95=A8=20(=EC=8B=9D=EB=B3=84?= =?UTF-8?q?=EC=84=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 회의 피드백: 분석 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) --- .../services/ClinicalSessionStore.kt | 11 +++++++++-- .../services/labdb/LabdbUploader.kt | 9 +++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/example/medilightv2android/services/ClinicalSessionStore.kt b/app/src/main/java/com/example/medilightv2android/services/ClinicalSessionStore.kt index e478dad..de85cd5 100644 --- a/app/src/main/java/com/example/medilightv2android/services/ClinicalSessionStore.kt +++ b/app/src/main/java/com/example/medilightv2android/services/ClinicalSessionStore.kt @@ -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) { // 저장 실패해도 측정 자체는 막지 않음 } diff --git a/app/src/main/java/com/example/medilightv2android/services/labdb/LabdbUploader.kt b/app/src/main/java/com/example/medilightv2android/services/labdb/LabdbUploader.kt index 6e14e2d..5baffe9 100644 --- a/app/src/main/java/com/example/medilightv2android/services/labdb/LabdbUploader.kt +++ b/app/src/main/java/com/example/medilightv2android/services/labdb/LabdbUploader.kt @@ -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_.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)