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)