Spaces:
Sleeping
Sleeping
feat: dosage options in detect/preview
Browse files- .claude/state/breezing-timeline.jsonl +1 -0
- .claude/state/changed-files.jsonl +2 -0
- api/detect_preview.py +20 -0
- services/dur.py +37 -0
.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 ๊ฒฐ๊ณผ๋ฅผ ์ฌ์ฉ์ ์ฝ ์ฉ๋์ผ๋ก ์ ๋ฐ ํํฐ.
|