Track daily phosphorus (ฟอสฟอรัส) and potassium (โพแทสเซียม) intake from food for kidney disease management. Use this skill whenever the user mentions food they ate, wants to log meals, check daily/monthly intake, or asks for nutrient reports. Trigger on: "กินข้าว", "กิน...มื้อเช้า/เที่ยง/เย็น", "บันทึกอาหาร", "สรุปวันนี้", "สรุปเดือน", "รายงานอาหาร", "ฟอสฟอรัส", "โพแทสเซียม", "log food", "food tracker", "what did I eat", any Thai or English food name followed by a meal context, or when the user sends a photo/image of food. Also trigger when the user asks which foods contributed most to their mineral intake.
ติดตามฟอสฟอรัสและโพแทสเซียมจากอาหาร สำหรับผู้ที่ต้องควบคุมแร่ธาตุ (เช่น ผู้ป่วยโรคไต)
For state management, read and follow the protocol in skills/state-db/SKILL.md
skill_name: food-tracker
| key1 | key2 | key3 | purpose | data fields |
|---|---|---|---|---|
| entry | date (YYYY-MM-DD) | meal_period | individual food log | {food_name, meal_time, phosphorus_mg, potassium_mg, serving_size, source, notes} |
2026-03-14) — enables daily/monthly queries via indexเช้า / กลางวัน / เย็น / ก่อนนอน) — enables per-meal filtering via indexEach food item the user eats becomes one entry row. Reports are generated by querying entries and aggregating in-memory.
| Field | Type | Example | Note |
|---|---|---|---|
| food_name | string | "ข้าวมันไก่" | required |
| meal_time | string | "2026-03-14T12:00:00" | ISO datetime, Asia/Bangkok |
| phosphorus_mg | number | 250 | required |
| potassium_mg | number | 300 | required |
| serving_size | string | "1 จาน" | optional |
| source | string | "web" | "web" or "ai_estimate" |
| notes | string | null | optional |
curl -s -X POST "$DB_URL" "${DB_AUTH[@]}" "${DB_JSON[@]}" "${DB_RETURN[@]}" \
-d '{
"skill_name": "food-tracker",
"key1": "entry",
"key2": "2026-03-14",
"key3": "กลางวัน",
"data": {
"food_name": "ข้าวมันไก่",
"meal_time": "2026-03-14T12:00:00",
"phosphorus_mg": 280,
"potassium_mg": 350,
"serving_size": "1 จาน",
"source": "web",
"notes": null
}
}'
Use ilike to search food names:
curl -s "$DB_URL?skill_name=eq.food-tracker&key1=eq.entry&data->>food_name=ilike.*ข้าวมัน*&order=key2.desc&limit=5" \
"${DB_AUTH[@]}"
curl -s "$DB_URL?skill_name=eq.food-tracker&key1=eq.entry&key2=eq.2026-03-14&order=created_at.asc" \
"${DB_AUTH[@]}"
Use like to match year-month prefix in key2:
curl -s "$DB_URL?skill_name=eq.food-tracker&key1=eq.entry&key2=like.2026-03*&order=created_at.asc" \
"${DB_AUTH[@]}"
curl -s -X DELETE "$DB_URL?id=eq.42" "${DB_AUTH[@]}" "${DB_RETURN[@]}"
curl -s "$DB_URL?skill_name=eq.food-tracker&key1=eq.entry&key2=eq.2026-03-14&select=id,key2,key3,data,created_at&order=created_at.asc" \
"${DB_AUTH[@]}"
When the user mentions food they ate (e.g. "กินข้าวมันไก่ มื้อเที่ยง") or sends a food photo:
If the user sends an image/photo:
If the user sends text:
Extract from the user's message:
For each food item, use WebSearch:
Search: "{food_name} phosphorus potassium mg per serving nutrition facts"
Also try: "{food_name} ฟอสฟอรัส โพแทสเซียม ต่อหน่วย"
Extract phosphorus_mg and potassium_mg per serving. Prefer Thai food databases or credible sources (USDA, Thai nutrition databases).
If WebSearch returns no usable data, read references/nutrients.md for common Thai food values. If still not found, estimate using AI knowledge and mark source as ai_estimate.
Before inserting, search for similar food names using the search operation above. If a match is found with different nutrient values, inform the user but still proceed with the new entry.
Insert using the log operation above. Set key2 to date (YYYY-MM-DD), key3 to meal_period, and meal_time in data to full ISO datetime, all in Asia/Bangkok timezone.
Query today's entries using the daily query operation. Sum up phosphorus_mg and potassium_mg from all entries' data field, then calculate percentages against daily limits.
Confirm what was logged and show today's running totals using the daily report format below.
phosphorus_mg and potassium_mg across all entries## รายงานประจำวัน - {date}
| # | อาหาร | มื้อ | ฟอสฟอรัส | โพแทสเซียม | ปริมาณ |
|---|-------|------|----------|-----------|--------|
| 1 | ข้าวสวย | เช้า | 68 mg | 55 mg | 1 ถ้วย |
### สรุปรวม
| แร่ธาตุ | รับไปแล้ว | เกณฑ์/วัน | สถานะ |
|---------|----------|----------|-------|
| ฟอสฟอรัส | 310 mg | 1,000 mg | 31% ✅ |
| โพแทสเซียม | 737 mg | 3,000 mg | 25% ✅ |
## รายงานประจำเดือน - {month}
### ภาพรวม
| แร่ธาตุ | รวมทั้งเดือน | เฉลี่ย/วัน | วันที่บันทึก |
|---------|------------|----------|------------|
| ฟอสฟอรัส | 8,432 mg | 843 mg | 10 วัน |
| โพแทสเซียม | 19,540 mg | 1,954 mg | 10 วัน |
### อาหารที่เป็นแหล่งฟอสฟอรัสสูงสุด
| อันดับ | อาหาร | รวม | ทานกี่ครั้ง | เฉลี่ย/ครั้ง |
|-------|-------|-----|----------|------------|
| 1 | นมวัว | 1,220 mg | 5 ครั้ง | 244 mg |
### อาหารที่เป็นแหล่งโพแทสเซียมสูงสุด
(same format)
### วันที่กินเกินเกณฑ์ต่อวัน
| วันที่ | ฟอสฟอรัส | สถานะ | โพแทสเซียม | สถานะ |
|-------|----------|-------|-----------|-------|
| 6 มี.ค. | 1,050 mg | 🔴 เกิน | 2,200 mg | ✅ |
(ถ้าไม่มีวันที่เกินเกณฑ์ แสดง "ไม่มีวันที่เกินเกณฑ์ในเดือนนี้ ✅")
### เมนูที่ควรหลีกเลี่ยง
อาหารที่ค่าต่อครั้งสูงกว่า 20% ของเกณฑ์ต่อวัน (P >200mg หรือ K >600mg):
| อาหาร | ค่าเฉลี่ย/ครั้ง | ทานกี่ครั้ง | รวมทั้งเดือน | ควรเลี่ยงเพราะ |
|-------|---------------|----------|------------|--------------|
| ไก่ทอด Bonchon | P: 300 mg | 3 ครั้ง | 900 mg | ฟอสฟอรัสสูง |
From the raw entries array, compute:
key2 (date), sum data.phosphorus_mg and data.potassium_mg per day, count entries per daydata.food_name, sum phosphorus_mg, count frequency, calculate avg = total / frequency| Mineral | Daily Limit |
|---|---|
| Phosphorus (ฟอสฟอรัส) | 800-1,000 mg |
| Potassium (โพแทสเซียม) | 2,000-3,000 mg |
These are general reference values. Always defer to the user's doctor.