BOWOWEEEEE commited on
Commit
5fb5a44
ยท
verified ยท
1 Parent(s): 0ec3a79

feat: dosage options in detect/preview

Browse files
.claude/state/breezing-timeline.jsonl CHANGED
@@ -1,3 +1,4 @@
1
  {"event":"teammate_idle","teammate":"backend-worker","team":"scan-flow-redesign","agent_id":"","agent_type":"claude-code-harness:worker","timestamp":"2026-06-08T12:24:54Z"}
2
  {"event":"teammate_idle","teammate":"backend-worker","team":"scan-flow-redesign","agent_id":"","agent_type":"claude-code-harness:worker","timestamp":"2026-06-08T12:27:53Z"}
3
  {"event":"teammate_idle","teammate":"backend-worker","team":"scan-flow-redesign","agent_id":"","agent_type":"claude-code-harness:worker","timestamp":"2026-06-08T12:28:16Z"}
 
 
1
  {"event":"teammate_idle","teammate":"backend-worker","team":"scan-flow-redesign","agent_id":"","agent_type":"claude-code-harness:worker","timestamp":"2026-06-08T12:24:54Z"}
2
  {"event":"teammate_idle","teammate":"backend-worker","team":"scan-flow-redesign","agent_id":"","agent_type":"claude-code-harness:worker","timestamp":"2026-06-08T12:27:53Z"}
3
  {"event":"teammate_idle","teammate":"backend-worker","team":"scan-flow-redesign","agent_id":"","agent_type":"claude-code-harness:worker","timestamp":"2026-06-08T12:28:16Z"}
4
+ {"event":"task_completed","teammate":"","task_id":"5","subject":"๋ฐฑ์—”๋“œ: detect/preview์— ์šฉ๋Ÿ‰ ํ›„๋ณด ๋ฐ˜ํ™˜ ์ถ”๊ฐ€","description":"dur.py์— get_dosage_options() ์ถ”๊ฐ€ (e์•ฝ์€์š” ํ’ˆ๋ชฉ๋ช…์—์„œ ์šฉ๋Ÿ‰ ์ถ”์ถœ), detect_preview.py ","timestamp":"2026-06-10T11:45:58Z"}
.claude/state/changed-files.jsonl CHANGED
@@ -3,3 +3,5 @@
3
  {"file":"CLAUDE.md","action":"Edit","timestamp":"2026-06-08T17:33:51Z","important":true}
4
  {"file":"/Users/apple/Documents/GitHub/pill-advisor/web/CLAUDE.md","action":"Edit","timestamp":"2026-06-08T17:34:13Z","important":true}
5
  {"file":"/Users/apple/Documents/GitHub/pill-advisor/CLAUDE.md","action":"Edit","timestamp":"2026-06-08T17:34:26Z","important":true}
 
 
 
3
  {"file":"CLAUDE.md","action":"Edit","timestamp":"2026-06-08T17:33:51Z","important":true}
4
  {"file":"/Users/apple/Documents/GitHub/pill-advisor/web/CLAUDE.md","action":"Edit","timestamp":"2026-06-08T17:34:13Z","important":true}
5
  {"file":"/Users/apple/Documents/GitHub/pill-advisor/CLAUDE.md","action":"Edit","timestamp":"2026-06-08T17:34:26Z","important":true}
6
+ {"file":"/Users/apple/Documents/GitHub/pill-advisor/mobile/lib/api.ts","action":"Edit","timestamp":"2026-06-10T11:46:07Z","important":false}
7
+ {"file":"/Users/apple/Documents/GitHub/pill-advisor/mobile/app/scan-meal.tsx","action":"Edit","timestamp":"2026-06-10T11:46:22Z","important":false}
api/detect_preview.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import io
2
  from typing import Any
3
 
@@ -5,6 +6,7 @@ from fastapi import APIRouter, File, Header, HTTPException, Request, UploadFile
5
  from PIL import Image
6
 
7
  from api.detect import _CLASS_MAPPING, extract_user_id, get_supabase
 
8
 
9
  router = APIRouter()
10
 
@@ -66,6 +68,24 @@ async def detect_preview(
66
  }
67
  )
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  return {"detected_drugs": detected_drugs}
70
  except HTTPException:
71
  raise
 
1
+ import asyncio
2
  import io
3
  from typing import Any
4
 
 
6
  from PIL import Image
7
 
8
  from api.detect import _CLASS_MAPPING, extract_user_id, get_supabase
9
+ from services import dur as dur_service
10
 
11
  router = APIRouter()
12
 
 
68
  }
69
  )
70
 
71
+ # ์•ฝ๋ณ„ ์šฉ๋Ÿ‰ ์ •๋ณด: ํƒ์ง€๋œ ์šฉ๋Ÿ‰(๊ธฐ๋ณธ ์„ ํƒ๊ฐ’) + DUR ๋“ฑ๋ก ์šฉ๋Ÿ‰ ๋ชฉ๋ก(์žฌ์„ ํƒ์šฉ)
72
+ unique_names = list({d["name"] for d in detected_drugs})
73
+ options_list = await asyncio.gather(
74
+ *(dur_service.get_dosage_options(n) for n in unique_names),
75
+ return_exceptions=True,
76
+ )
77
+ options_map = {
78
+ n: (opts if isinstance(opts, list) else [])
79
+ for n, opts in zip(unique_names, options_list)
80
+ }
81
+ for d in detected_drugs:
82
+ detected_label = dur_service.extract_dosage_label(d["name"])
83
+ opts = options_map[d["name"]]
84
+ if detected_label and detected_label not in opts:
85
+ opts = sorted([*opts, detected_label])
86
+ d["dosage_detected"] = detected_label
87
+ d["dosage_options"] = opts
88
+
89
  return {"detected_drugs": detected_drugs}
90
  except HTTPException:
91
  raise
services/dur.py CHANGED
@@ -41,6 +41,43 @@ def _extract_dosage_ko(name: str) -> str | None:
41
  return f"{num}{_UNIT_KO[m.group(2).lower()]}"
42
 
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  def _filter_by_dosage(items: list[dict], dosage_ko: str | None) -> list[dict]:
45
  """
46
  ํ’ˆ๋ชฉ๋ช…์— ์šฉ๋Ÿ‰์ด ํฌํ•จ๋œ DUR ๊ฒฐ๊ณผ๋ฅผ ์‚ฌ์šฉ์ž ์•ฝ ์šฉ๋Ÿ‰์œผ๋กœ ์ •๋ฐ€ ํ•„ํ„ฐ.
 
41
  return f"{num}{_UNIT_KO[m.group(2).lower()]}"
42
 
43
 
44
+ _UNIT_EN = {"๋ฐ€๋ฆฌ๊ทธ๋žจ": "mg", "๊ทธ๋žจ": "g", "๋งˆ์ดํฌ๋กœ๊ทธ๋žจ": "mcg", "๋ฐ€๋ฆฌ๋ฆฌํ„ฐ": "ml"}
45
+ _MG_FACTOR = {"mg": 1.0, "g": 1000.0, "mcg": 0.001, "ml": 1.0}
46
+
47
+
48
+ async def get_dosage_options(drug_name: str) -> list[str]:
49
+ """
50
+ DUR ํ’ˆ๋ชฉ์ •๋ณด์—์„œ ํ•ด๋‹น ์•ฝ์˜ ๋“ฑ๋ก ์šฉ๋Ÿ‰ ๋ชฉ๋ก์„ ์ถ”์ถœํ•œ๋‹ค.
51
+ ์˜ˆ: "์•„๋นŒ๋ฆฌํŒŒ์ด์ • 10mg" โ†’ ["2mg", "5mg", "10mg", "15mg", "300mg"]
52
+ ์šฉ๋Ÿ‰ ํ‘œ๊ธฐ ์—†๋Š” ํ’ˆ๋ชฉ๋งŒ ์žˆ์œผ๋ฉด ๋นˆ ๋ฆฌ์ŠคํŠธ.
53
+ """
54
+ base = _clean_drug_name(drug_name) or drug_name
55
+ async with httpx.AsyncClient() as client:
56
+ items = await _get_items(client, f"{DUR_BASE}/getDurPrdlstInfoList03", _params(base, 50))
57
+ seen: dict[str, float] = {}
58
+ for it in items:
59
+ n = it.get("ITEM_NAME") or ""
60
+ m = re.search(r"(\d+(?:\.\d+)?)(๋ฐ€๋ฆฌ๊ทธ๋žจ|๊ทธ๋žจ|๋งˆ์ดํฌ๋กœ๊ทธ๋žจ|๋ฐ€๋ฆฌ๋ฆฌํ„ฐ)", n)
61
+ if not m:
62
+ continue
63
+ num_s = m.group(1).rstrip("0").rstrip(".") if "." in m.group(1) else m.group(1)
64
+ unit = _UNIT_EN[m.group(2)]
65
+ label = f"{num_s}{unit}"
66
+ if label not in seen:
67
+ seen[label] = float(num_s) * _MG_FACTOR[unit]
68
+ return sorted(seen, key=lambda k: seen[k])
69
+
70
+
71
+ def extract_dosage_label(name: str) -> str | None:
72
+ """YOLO ํด๋ž˜์Šค๋ช…์—์„œ ์šฉ๋Ÿ‰ ๋ผ๋ฒจ ์ถ”์ถœ. '์•„๋นŒ๋ฆฌํŒŒ์ด์ • 10mg' โ†’ '10mg'"""
73
+ m = re.search(r"(\d+(?:\.\d+)?)\s*(mg|mcg|ug|g|ml)", name, flags=re.IGNORECASE)
74
+ if not m:
75
+ return None
76
+ num = m.group(1).rstrip("0").rstrip(".") if "." in m.group(1) else m.group(1)
77
+ unit = m.group(2).lower().replace("ug", "mcg")
78
+ return f"{num}{unit}"
79
+
80
+
81
  def _filter_by_dosage(items: list[dict], dosage_ko: str | None) -> list[dict]:
82
  """
83
  ํ’ˆ๋ชฉ๋ช…์— ์šฉ๋Ÿ‰์ด ํฌํ•จ๋œ DUR ๊ฒฐ๊ณผ๋ฅผ ์‚ฌ์šฉ์ž ์•ฝ ์šฉ๋Ÿ‰์œผ๋กœ ์ •๋ฐ€ ํ•„ํ„ฐ.