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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sqlite3
|
| 3 |
+
import random
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
from datetime import date, datetime, timedelta
|
| 6 |
+
import tempfile
|
| 7 |
+
|
| 8 |
+
import pandas as pd
|
| 9 |
+
import streamlit as st
|
| 10 |
+
from openpyxl import Workbook
|
| 11 |
+
from openpyxl.styles import Font, Alignment, Border, Side, PatternFill
|
| 12 |
+
from openpyxl.utils import get_column_letter
|
| 13 |
+
from openpyxl.drawing.image import Image as XLImage
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# =========================================================
|
| 17 |
+
# ํตํฉ์ฐ๋ ์ฌ๋ก๊ด๋ฆฌ ์์ฑ๊ธฐ
|
| 18 |
+
# Client Center + ์๋ด์ผ์ง + ์๊ตฌ์ฌ์ ์ฐ๋ํ
|
| 19 |
+
# =========================================================
|
| 20 |
+
|
| 21 |
+
st.set_page_config(page_title="ํตํฉ ์ฌ๋ก๊ด๋ฆฌ", page_icon="๐", layout="wide")
|
| 22 |
+
|
| 23 |
+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 24 |
+
|
| 25 |
+
DB_CANDIDATES = [
|
| 26 |
+
os.path.join(CURRENT_DIR, "data", "clients.db"),
|
| 27 |
+
os.path.join(CURRENT_DIR, "..", "Client Center", "data", "clients.db"),
|
| 28 |
+
os.path.join(CURRENT_DIR, "..", "ClientCenter", "data", "clients.db"),
|
| 29 |
+
os.path.join(CURRENT_DIR, "..", "Client_Center", "data", "clients.db"),
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
DB_PATH = None
|
| 33 |
+
for p in DB_CANDIDATES:
|
| 34 |
+
if os.path.exists(p):
|
| 35 |
+
DB_PATH = p
|
| 36 |
+
break
|
| 37 |
+
|
| 38 |
+
if DB_PATH is None:
|
| 39 |
+
os.makedirs(os.path.join(CURRENT_DIR, "data"), exist_ok=True)
|
| 40 |
+
DB_PATH = os.path.join(CURRENT_DIR, "data", "clients.db")
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# -----------------------------
|
| 44 |
+
# UI ๋์์ธ
|
| 45 |
+
# -----------------------------
|
| 46 |
+
st.markdown("""
|
| 47 |
+
<style>
|
| 48 |
+
.block-container { padding-top: 2rem; }
|
| 49 |
+
.hero {
|
| 50 |
+
background: linear-gradient(135deg, #6D28D9, #9333EA);
|
| 51 |
+
padding: 30px;
|
| 52 |
+
border-radius: 22px;
|
| 53 |
+
text-align: center;
|
| 54 |
+
margin-bottom: 22px;
|
| 55 |
+
}
|
| 56 |
+
.hero h1 { color: white; margin: 0; font-size: 36px; }
|
| 57 |
+
.hero p { color: white; margin-top: 10px; font-size: 18px; }
|
| 58 |
+
.notice {
|
| 59 |
+
background: #fff8e1;
|
| 60 |
+
border-left: 7px solid #f9a825;
|
| 61 |
+
padding: 15px;
|
| 62 |
+
border-radius: 12px;
|
| 63 |
+
margin-bottom: 18px;
|
| 64 |
+
}
|
| 65 |
+
.okbox {
|
| 66 |
+
background: #e8f5e9;
|
| 67 |
+
border-left: 7px solid #43a047;
|
| 68 |
+
padding: 14px;
|
| 69 |
+
border-radius: 12px;
|
| 70 |
+
margin-bottom: 14px;
|
| 71 |
+
}
|
| 72 |
+
.warnbox {
|
| 73 |
+
background: #fff3e0;
|
| 74 |
+
border-left: 7px solid #fb8c00;
|
| 75 |
+
padding: 14px;
|
| 76 |
+
border-radius: 12px;
|
| 77 |
+
margin-bottom: 14px;
|
| 78 |
+
}
|
| 79 |
+
</style>
|
| 80 |
+
""", unsafe_allow_html=True)
|
| 81 |
+
|
| 82 |
+
st.markdown("""
|
| 83 |
+
<div class="hero">
|
| 84 |
+
<h1>๐ ํตํฉ ์ฌ๋ก๊ด๋ฆฌ ์์ฑ๊ธฐ</h1>
|
| 85 |
+
<p>์๊ธ์ ์ ๋ณด, ์๋ด์ผ์ง, ์๊ตฌ์ฌ์ ๋ด์ฉ์ ์ฐ๊ฒฐํ์ฌ 1์ฐจ ๊ณํํ์๋ก๊ณผ 2์ฐจ ๊ฒฐ๊ณผํ์๋ก์ ์์ฑํฉ๋๋ค.</p>
|
| 86 |
+
</div>
|
| 87 |
+
""", unsafe_allow_html=True)
|
| 88 |
+
|
| 89 |
+
st.markdown("""
|
| 90 |
+
<div class="notice">
|
| 91 |
+
<strong>์ฐ๋ ๊ตฌ์กฐ:</strong> Client Center ์๊ธ์ DB โ ์๋ด๊ธฐ๋ก โ ์๊ตฌ์ฌ์ ์์ฝ โ ์ฌ๋ก๊ด๋ฆฌ 1์ฐจ ๊ณํ โ ์ญํ ๋ณ ์ํ๊ณผ์ โ 2์ฐจ ๊ฒฐ๊ณผํ๊ฐ
|
| 92 |
+
</div>
|
| 93 |
+
""", unsafe_allow_html=True)
|
| 94 |
+
|
| 95 |
+
st.markdown("""
|
| 96 |
+
<div class="notice">
|
| 97 |
+
โป ์์ฑ๋ ๋ฌธ์๋ ๊ทธ๋๋ก ์ฌ์ฉํ์
๋ ๋๋ฉฐ, ๊ธฐ๊ด์ ์ด์๋ฐฉ์นจ, ์๊ธ์ ์ํ, ๋ณดํธ์ ์๊ฒฌ ๋ฐ ํ๊ฐ๊ธฐ์ค์ ๋ฐ๋ผ ์ถ๊ฐ ๋ณด์์ฌํญ์ ์ผ๋ง๋ ์ง ์์ ๊ฐ๋ฅํฉ๋๋ค. ๊ธฐ๊ด์ ์ํฉ์ ๋ง๊ฒ ํ์ฉํ์๊ธฐ ๋ฐ๋๋๋ค.
|
| 98 |
+
</div>
|
| 99 |
+
""", unsafe_allow_html=True)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
# -----------------------------
|
| 103 |
+
# DB
|
| 104 |
+
# -----------------------------
|
| 105 |
+
def get_conn():
|
| 106 |
+
return sqlite3.connect(DB_PATH, check_same_thread=False)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def init_db():
|
| 110 |
+
conn = get_conn()
|
| 111 |
+
cur = conn.cursor()
|
| 112 |
+
|
| 113 |
+
cur.execute("""
|
| 114 |
+
CREATE TABLE IF NOT EXISTS clients (
|
| 115 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 116 |
+
name TEXT NOT NULL,
|
| 117 |
+
masked_name TEXT,
|
| 118 |
+
gender TEXT,
|
| 119 |
+
birth_year TEXT,
|
| 120 |
+
care_grade TEXT,
|
| 121 |
+
institution_type TEXT,
|
| 122 |
+
institution_name TEXT,
|
| 123 |
+
admission_date TEXT,
|
| 124 |
+
main_condition TEXT,
|
| 125 |
+
cognitive_status TEXT,
|
| 126 |
+
mobility_status TEXT,
|
| 127 |
+
diet_status TEXT,
|
| 128 |
+
toileting_status TEXT,
|
| 129 |
+
guardian_name TEXT,
|
| 130 |
+
guardian_phone TEXT,
|
| 131 |
+
notes TEXT,
|
| 132 |
+
status TEXT DEFAULT '์ด์ฉ์ค',
|
| 133 |
+
created_at TEXT,
|
| 134 |
+
updated_at TEXT
|
| 135 |
+
)
|
| 136 |
+
""")
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
new_client_columns = {
|
| 140 |
+
"recognition_number": "TEXT",
|
| 141 |
+
"recognition_start_date": "TEXT",
|
| 142 |
+
"recognition_end_date": "TEXT",
|
| 143 |
+
"previous_care_grade": "TEXT",
|
| 144 |
+
"plan_change_required": "TEXT DEFAULT '์๋์ค'",
|
| 145 |
+
"plan_change_type": "TEXT",
|
| 146 |
+
"plan_change_reason": "TEXT",
|
| 147 |
+
"plan_change_date": "TEXT",
|
| 148 |
+
"plan_rewrite_status": "TEXT DEFAULT 'ํด๋น์์'",
|
| 149 |
+
"linked_document": "TEXT",
|
| 150 |
+
}
|
| 151 |
+
cur.execute("PRAGMA table_info(clients)")
|
| 152 |
+
existing_client_cols = [row[1] for row in cur.fetchall()]
|
| 153 |
+
for col, col_type in new_client_columns.items():
|
| 154 |
+
if col not in existing_client_cols:
|
| 155 |
+
cur.execute(f"ALTER TABLE clients ADD COLUMN {col} {col_type}")
|
| 156 |
+
|
| 157 |
+
cur.execute("""
|
| 158 |
+
CREATE TABLE IF NOT EXISTS counseling_records (
|
| 159 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 160 |
+
client_id INTEGER,
|
| 161 |
+
client_masked_name TEXT,
|
| 162 |
+
institution_type TEXT,
|
| 163 |
+
counseling_type TEXT,
|
| 164 |
+
counseling_date TEXT,
|
| 165 |
+
counselor TEXT,
|
| 166 |
+
counseling_reason TEXT,
|
| 167 |
+
client_status_change TEXT,
|
| 168 |
+
guardian_opinion TEXT,
|
| 169 |
+
counseling_content TEXT,
|
| 170 |
+
action_plan TEXT,
|
| 171 |
+
evaluation_score INTEGER,
|
| 172 |
+
missing_items TEXT,
|
| 173 |
+
compliance_result TEXT,
|
| 174 |
+
next_due_note TEXT,
|
| 175 |
+
created_at TEXT
|
| 176 |
+
)
|
| 177 |
+
""")
|
| 178 |
+
|
| 179 |
+
cur.execute("""
|
| 180 |
+
CREATE TABLE IF NOT EXISTS needs_assessment_records (
|
| 181 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 182 |
+
client_id INTEGER,
|
| 183 |
+
client_masked_name TEXT,
|
| 184 |
+
assessment_date TEXT,
|
| 185 |
+
total_opinion TEXT,
|
| 186 |
+
result_status TEXT,
|
| 187 |
+
result_plan TEXT,
|
| 188 |
+
fall_risk TEXT,
|
| 189 |
+
bedsore_risk TEXT,
|
| 190 |
+
dementia_status TEXT,
|
| 191 |
+
diaper_use TEXT,
|
| 192 |
+
service_needs TEXT,
|
| 193 |
+
created_at TEXT
|
| 194 |
+
)
|
| 195 |
+
""")
|
| 196 |
+
|
| 197 |
+
cur.execute("""
|
| 198 |
+
CREATE TABLE IF NOT EXISTS case_management_records (
|
| 199 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 200 |
+
client_id INTEGER,
|
| 201 |
+
client_masked_name TEXT,
|
| 202 |
+
institution_type TEXT,
|
| 203 |
+
case_type TEXT,
|
| 204 |
+
first_meeting_date TEXT,
|
| 205 |
+
second_meeting_date TEXT,
|
| 206 |
+
selection_reason TEXT,
|
| 207 |
+
first_plan TEXT,
|
| 208 |
+
implementation_process TEXT,
|
| 209 |
+
second_result TEXT,
|
| 210 |
+
evaluation_score INTEGER,
|
| 211 |
+
missing_items TEXT,
|
| 212 |
+
created_at TEXT
|
| 213 |
+
)
|
| 214 |
+
""")
|
| 215 |
+
|
| 216 |
+
conn.commit()
|
| 217 |
+
conn.close()
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def load_clients():
|
| 221 |
+
conn = get_conn()
|
| 222 |
+
try:
|
| 223 |
+
df = pd.read_sql_query("""
|
| 224 |
+
SELECT * FROM clients ORDER BY id DESC LIMIT 300
|
| 225 |
+
""", conn)
|
| 226 |
+
except Exception:
|
| 227 |
+
df = pd.DataFrame()
|
| 228 |
+
conn.close()
|
| 229 |
+
return df
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def load_counseling(client_id):
|
| 233 |
+
conn = get_conn()
|
| 234 |
+
try:
|
| 235 |
+
df = pd.read_sql_query("""
|
| 236 |
+
SELECT * FROM counseling_records
|
| 237 |
+
WHERE client_id = ?
|
| 238 |
+
ORDER BY counseling_date DESC, id DESC
|
| 239 |
+
""", conn, params=(int(client_id),))
|
| 240 |
+
except Exception:
|
| 241 |
+
df = pd.DataFrame()
|
| 242 |
+
conn.close()
|
| 243 |
+
return df
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def load_needs_assessment(client_id):
|
| 247 |
+
conn = get_conn()
|
| 248 |
+
try:
|
| 249 |
+
df = pd.read_sql_query("""
|
| 250 |
+
SELECT * FROM needs_assessment_records
|
| 251 |
+
WHERE client_id = ?
|
| 252 |
+
ORDER BY assessment_date DESC, id DESC
|
| 253 |
+
""", conn, params=(int(client_id),))
|
| 254 |
+
except Exception:
|
| 255 |
+
df = pd.DataFrame()
|
| 256 |
+
conn.close()
|
| 257 |
+
return df
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def save_case_record(data):
|
| 261 |
+
conn = get_conn()
|
| 262 |
+
cur = conn.cursor()
|
| 263 |
+
cur.execute("""
|
| 264 |
+
INSERT INTO case_management_records (
|
| 265 |
+
client_id, client_masked_name, institution_type, case_type,
|
| 266 |
+
first_meeting_date, second_meeting_date, selection_reason,
|
| 267 |
+
first_plan, implementation_process, second_result,
|
| 268 |
+
evaluation_score, missing_items, created_at
|
| 269 |
+
)
|
| 270 |
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 271 |
+
""", (
|
| 272 |
+
data["client_id"], data["client_masked_name"], data["institution_type"], data["case_type"],
|
| 273 |
+
data["first_meeting_date"], data["second_meeting_date"], data["selection_reason"],
|
| 274 |
+
data["first_plan"], data["implementation_process"], data["second_result"],
|
| 275 |
+
data["evaluation_score"], data["missing_items"],
|
| 276 |
+
datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 277 |
+
))
|
| 278 |
+
conn.commit()
|
| 279 |
+
conn.close()
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def normalize_date_text(value):
|
| 285 |
+
"""Client Center ๋ ์ง ํ์์ YYYY-MM-DD๋ก ์์ ํ๊ฒ ๋ง์ถฅ๋๋ค."""
|
| 286 |
+
v = str(value or "").strip()
|
| 287 |
+
if not v or v.lower() == "nan":
|
| 288 |
+
return ""
|
| 289 |
+
try:
|
| 290 |
+
return pd.to_datetime(v, errors="raise").strftime("%Y-%m-%d")
|
| 291 |
+
except Exception:
|
| 292 |
+
return v
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def days_until(date_text):
|
| 296 |
+
v = normalize_date_text(date_text)
|
| 297 |
+
if not v:
|
| 298 |
+
return None
|
| 299 |
+
try:
|
| 300 |
+
return (datetime.strptime(v, "%Y-%m-%d").date() - date.today()).days
|
| 301 |
+
except Exception:
|
| 302 |
+
return None
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def recognition_alert_text(end_date_text):
|
| 306 |
+
days = days_until(end_date_text)
|
| 307 |
+
if days is None:
|
| 308 |
+
return "์ธ์ ๊ธฐ๊ฐ ์ข
๋ฃ์ผ ๋ฏธ์
๋ ฅ"
|
| 309 |
+
if days < 0:
|
| 310 |
+
return f"์ธ์ ๊ธฐ๊ฐ ๋ง๋ฃ {abs(days)}์ผ ๊ฒฝ๊ณผ"
|
| 311 |
+
if days <= 30:
|
| 312 |
+
return f"๋ง๋ฃ {days}์ผ ์ : ๊ธ์ฌ๊ณํ ์ฌ๊ฒํ ํ์"
|
| 313 |
+
if days <= 90:
|
| 314 |
+
return f"๋ง๋ฃ {days}์ผ ์ : ๊ฐฑ์ /๊ณํ ํ์ธ"
|
| 315 |
+
return f"๋ง๋ฃ {days}์ผ ์ "
|
| 316 |
+
|
| 317 |
+
def safe(row, key, default=""):
|
| 318 |
+
try:
|
| 319 |
+
v = row.get(key, default)
|
| 320 |
+
if pd.isna(v):
|
| 321 |
+
return default
|
| 322 |
+
return str(v)
|
| 323 |
+
except Exception:
|
| 324 |
+
return default
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
def mask_name(name):
|
| 328 |
+
name = str(name or "").strip()
|
| 329 |
+
if len(name) >= 3:
|
| 330 |
+
return name[0] + "โ" + name[2:]
|
| 331 |
+
if len(name) == 2:
|
| 332 |
+
return name[0] + "โ"
|
| 333 |
+
return name
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
init_db()
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
# -----------------------------
|
| 340 |
+
# ์ฌ๋ก ์ ํ
|
| 341 |
+
# -----------------------------
|
| 342 |
+
CASE_TYPES = {
|
| 343 |
+
"๋์ ๊ณ ์ํ ๊ด๋ฆฌ": {
|
| 344 |
+
"reason": "์ด๋ ์ค ๋ถ์์ , ํ์ฅ์ค ์ด๋ ์ํ, ๋ณดํ๋ณด์กฐ ํ์ ๋ฑ ๋์ ์ํ์์ธ์ด ํ์ธ๋์ด ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 345 |
+
"goal": "๋์ ์ฌ๊ณ ๋ฅผ ์๋ฐฉํ๊ณ ์์ ํ ์ด๋๊ณผ ์ํํ๊ฒฝ์ ์ ์งํ๋ค.",
|
| 346 |
+
"keywords": ["๋์์๋ฐฉ", "์ด๋๋ณด์กฐ", "ํ๊ฒฝ์ ๋น", "ํ์ฅ์ค ๋ํ", "๋ณดํ์ํ ๊ด์ฐฐ"],
|
| 347 |
+
},
|
| 348 |
+
"์์ฌ๋ ๊ฐ์ยท์์๊ด๋ฆฌ": {
|
| 349 |
+
"reason": "์์ฌ๋ ๊ฐ์, ์๋ถ์ญ์ทจ ๋ถ์กฑ, ์ฒด์ค์ ํ ์ฐ๋ ค๊ฐ ํ์ธ๋์ด ์์์ํ ๊ด๋ฆฌ๋ฅผ ์ํ ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 350 |
+
"goal": "์์ฌ๋๊ณผ ์๋ถ์ญ์ทจ๋ฅผ ์์ ์ ์ผ๋ก ์ ์งํ๊ณ ์์ ์ ํ ์ํ์ ์๋ฐฉํ๋ค.",
|
| 351 |
+
"keywords": ["์์ฌ๋ณด์กฐ", "์๋ถ์ญ์ทจ", "์ ํธ์์", "์ฐํ์ํ", "์ญ์ทจ๋ ๊ธฐ๋ก"],
|
| 352 |
+
},
|
| 353 |
+
"์ธ์ง์ ํยท์ ์๋ถ์": {
|
| 354 |
+
"reason": "๋ฐ๋ณต์ง๋ฌธ, ์์ฌํํ, ๋ถ์๊ฐ, ์ ์์ ์์ถ ๋ฑ ์ธ์งยท์ ์ ๋ณํ๊ฐ ํ์ธ๋์ด ์ง์ ๊ด์ฐฐ๊ณผ ๊ฐ๋ณ ๋์์ด ํ์ํจ.",
|
| 355 |
+
"goal": "๋ถ์๊ฐ์ ์ํํ๊ณ ์์ ์ ์ธ ์ผ์์ํ๊ณผ ์๋น์ค ์ด์ฉ์ด ์ด๋ฃจ์ด์ง๋๋ก ์ง์ํ๋ค.",
|
| 356 |
+
"keywords": ["์ ์์ง์", "์ธ์งํ๋", "๋ฐ๋ณต์ค๋ช
", "์์ ์ ํ๊ฒฝ", "๋ณดํธ์ ์๋ด"],
|
| 357 |
+
},
|
| 358 |
+
"์์ฐฝยทํผ๋ถ์ํ ๊ด๋ฆฌ": {
|
| 359 |
+
"reason": "๊ธฐ์ ๊ท ์ฐฉ์ฉ, ํ๋๋ ์ ํ, ํผ๋ถ ๋ฐ์ ๋๋ ์์ฐฝ ์ํ์ด ํ์ธ๋์ด ํผ๋ถ์ํ ๊ด์ฐฐ๊ณผ ์๋ฐฉ๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 360 |
+
"goal": "ํผ๋ถ ์ฒญ๊ฒฐ๊ณผ ์์๋ฅผ ์ ์งํ๊ณ ์์ฐฝ ๋ฐ์์ ์๋ฐฉํ๋ค.",
|
| 361 |
+
"keywords": ["ํผ๋ถ๊ด์ฐฐ", "์ฒด์๋ณ๊ฒฝ", "๊ธฐ์ ๊ท์ผ์ด", "๋ณด์ต", "๊ฐํธ๊ด์ฐฐ"],
|
| 362 |
+
},
|
| 363 |
+
"ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ์ ํ": {
|
| 364 |
+
"reason": "ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ๊ฐ์, ๋ฌด๊ธฐ๋ ฅ, ๋ํ ํํผ ๋ฑ ์ฌํ์ ยท์ ์์ ์์ถ์ด ๊ด์ฐฐ๋์ด ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 365 |
+
"goal": "์ ํธ ํ๋ ์ค์ฌ์ผ๋ก ์ฐธ์ฌ๋ฅผ ์ ๋ํ๊ณ ์ฌํ์ ๊ด๊ณ์ ํ๋ ฅ์ ๋์ธ๋ค.",
|
| 366 |
+
"keywords": ["์ ํธํ๋", "์ฐธ์ฌ๊ฒฉ๋ ค", "์ ์์ง์", "ํ๋ก๊ทธ๋จ ์กฐ์ ", "์ฐธ์ฌ๋ ๊ธฐ๋ก"],
|
| 367 |
+
},
|
| 368 |
+
"๋ณดํธ์ ์์ฒญยท์๋น์ค ์กฐ์ ": {
|
| 369 |
+
"reason": "๋ณดํธ์ ์์ฒญ ๋๋ ์๋น์ค ์กฐ์ ํ์์ฑ์ด ํ์ธ๋์ด ๊ธ์ฌ์ ๊ณต ๋ฐฉํฅ ์ฌ๊ฒํ ์ ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 370 |
+
"goal": "๋ณดํธ์ ์๊ฒฌ๊ณผ ์๊ธ์ ์ํ๋ฅผ ๋ฐ์ํ์ฌ ์ ์ ํ ์๋น์ค ์ ๊ณต ๋ฐฉํฅ์ ์กฐ์ ํ๋ค.",
|
| 371 |
+
"keywords": ["๋ณดํธ์ ์๋ด", "์๋น์ค ์กฐ์ ", "๊ธ์ฌ๊ณํ ๋ฐ์", "์ข
์ฌ์ ๊ณต์ ", "ํ์์๋ด"],
|
| 372 |
+
},
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
# -----------------------------
|
| 376 |
+
# ๊ฐ์ธ๋ณ์ด์ฉ๊ณํ ์ง์๋ฐฉ๋ฒ ๋ฐ์ดํฐ๋ฒ ์ด์ค
|
| 377 |
+
# -----------------------------
|
| 378 |
+
CASE_DETAILS = {
|
| 379 |
+
"๋์ ๊ณ ์ํ ๊ด๋ฆฌ": {
|
| 380 |
+
"domains": ["๊ฑด๊ฐ/์ ์ฒด", "ํ๊ฒฝ", "๋ณต์ฝ"],
|
| 381 |
+
"goal": "๋์ ์ฌ๊ณ ๋ฅผ ์๋ฐฉํ๊ณ ์์ ํ ์ด๋๊ณผ ์ํํ๊ฒฝ์ ์ ์งํจ.",
|
| 382 |
+
"subjective": "์๊ธ์ ๋ฐ ๋ณดํธ์๋ ์ต๊ทผ ๋ณดํ ์ ๋ค๋ฆฌ์ ํ์ด ํ๋ฆฌ๊ฑฐ๋ ์ด์ง๋ผ์ฆ์ด ์์ฃผ ๋ฐ์ํ์ฌ ์ด๋ ์ ๋ถ์๊ฐ์ด ๋งค์ฐ ํฌ๋ค๊ณ ํธ์ํจ. ํนํ ํ์ฅ์ค ์ด๋ ์ ๋ฏธ๋๋ฌ์ง๊น ๊ฑฑ์ ๋๋ค๊ณ ์ ํจ.",
|
| 383 |
+
"objective": "๋ณดํ๋ณด์กฐ๊ธฐ๋ฅผ ์ฌ์ฉํ๋๋ผ๋ ๊ฑธ์๊ฑธ์ด๊ฐ ๋งค์ฐ ๋ถ์์ ํ๊ณ ์ด์ง๋ผ์ฆ์ ์ข
์ข
๊ด์ฐฐํจ. ์ํ์ค ๋ฐ๋ฅ์ ์ ์ ์ด๋ ๋ฌธํฑ์ด ์์ด ๋์ ์ํ์์๋ก ์์ฉํ๋ ๊ฒ์ ํ์ธํ๊ณ ๊ด์ฐฐํจ.",
|
| 384 |
+
"assessment": "์๊ธ์์ ํ์ง ๊ทผ๋ ฅ ์ ํ์ ์ธ์ง ์ ํ ์ํ๋ฅผ ๊ณ ๋ คํ ๋ ๋์ ์ํ๋๊ฐ ๋์ ์ํ๋ก ์ฌ์ ๋จ. ๋ค๋ฆฌ์ ํ์ด ๋น ์ง๊ฑฐ๋ ์ด์ง๋ฌ์ ํธ์ ์ ์ฆ์ ๋ถ์ถํ๊ณ ์์ ํ ๋ณดํ์ ์ํ ๊ฐ๋ณ ์ง์๋ฐฉ๋ฒ์ ์กฐ์ํ ์ฐ๊ณ ๋ฐ ๊ณํํจ.",
|
| 385 |
+
"plan": [
|
| 386 |
+
"๋ณดํ ์ ๋ถ์ถ์ ์ ๊ณตํจ.",
|
| 387 |
+
"๋ฏธ๋๋ผ ๋ฐฉ์ง ํ๊ฒฝ์ ์ ๊ฒํจ.",
|
| 388 |
+
"์นจ์ ๋๊ฐ ์ํ๋ฅผ ํ์ธํจ.",
|
| 389 |
+
"์ผ๊ฐ ์ด๋ ์ ์์ ๊ด์ฐฐ์ ์ค์ํจ.",
|
| 390 |
+
"์ด๋ ์ ์ด์ง๋ผ ์ฌ๋ถ๋ฅผ ํ์ธํจ.",
|
| 391 |
+
"๋ณดํ๋ณด์กฐ๊ธฐ ์ฌ์ฉ์ ์๋ดํจ.",
|
| 392 |
+
"์ค๋ด ์ ๋ฆฌ์ ๋ ์ํ๋ฅผ ์ ๊ฒํจ.",
|
| 393 |
+
"ํ์ฅ์ค ์ด๋ ์ ๋ํ ๋ฐ ์์ ๊ด์ฐฐ์ ์ค์ํจ."
|
| 394 |
+
],
|
| 395 |
+
"resource": "๋ณด๊ฑด์ ๋์์๋ฐฉ ํ๋ก๊ทธ๋จ ์๋ด ๋ฐ ๋ฐฉ๋ฌธ๊ฐํธ ์๋น์ค ์ฐ๊ณ๋ฅผ ๊ฒํ ํจ."
|
| 396 |
+
},
|
| 397 |
+
"์์ฌ๋ ๊ฐ์ยท์์๊ด๋ฆฌ": {
|
| 398 |
+
"domains": ["๊ฑด๊ฐ/์ ์ฒด", "๊ฐ์กฑ๋ถ๋ด"],
|
| 399 |
+
"goal": "์์ฌ๋๊ณผ ์๋ถ์ญ์ทจ๋ฅผ ์์ ์ ์ผ๋ก ์ ์งํ๊ณ ์์ ์ ํ ์ํ์ ์๋ฐฉํจ.",
|
| 400 |
+
"subjective": "์๊ธ์๋ ์
๋ง์ด ์ ํ ์๋ค๊ณ ํธ์ํ๋ฉฐ ์์ฌ๋ฅผ ๊ฑฐ๋ถํ๊ฑฐ๋ ๋ฐ ๊ณต๊ธฐ๋ ์ฑ ๋จน์ง ๋ชปํ๋ค๊ณ ํํํจ. ๋ณดํธ์๋ ์ฒด์ค ์ ํ์ ์ ์ ์ ์ฝ ์ฐ๋ ค๋ก ์์ ๊ด๋ฆฌ์ ๋ํด ๊น์ ์ผ๋ ค๋ฅผ ํํจ.",
|
| 401 |
+
"objective": "์ต๊ทผ ์์ฌ๋์ด ๋์ ๋๊ฒ ๊ฐ์ํ์ฌ ํ๊ท ์ญ์ทจ๋์ด ๊ธฐ์กด ๋๋น 50% ๋ฏธ๋ง์ผ๋ก ํ์ธ๋จ. ์ฐํ๊ณค๋์ด๋ ๊ตฌ๊ฐ ๊ฑด์กฐ๊ฐ ๊ด์ฐฐ๋๋ฉฐ ์ฒด์ค์ด ์ํญ ๊ฐ์ํ ๊ฒ์ด ํ์ธ๋จ.",
|
| 402 |
+
"assessment": "๋ถ์์ ํ ์ญ์ทจ ์ง์ ์ ๋ง์ฑ์ ์ธ ์์๊ฒฐํ ๋ฐ ๋ฉด์ญ ์ ํ ์ํ์ด ๋งค์ฐ ํฐ ์ํ๋ก ํ๋จ๋จ. ์๊ธ์์ ์ ํธ ์์ ๋ฐ์ ๋ฐ ์๋ถ ์ญ์ทจ ์ ๋ ๋ฑ ๊ตฌ์ฒด์ ์ธ ์์ ๋ณด์ถฉ ์ง์์ ๊ณํํจ.",
|
| 403 |
+
"plan": [
|
| 404 |
+
"์ ํธ ์์์ ํ์ธํจ.",
|
| 405 |
+
"๊ธฐํธ์์ ๋ฐ์ํจ.",
|
| 406 |
+
"์๋ถ์ญ์ทจ๋ฅผ ๋
๋ คํจ.",
|
| 407 |
+
"์์์ํ๋ฅผ ๊ด์ฐฐํจ.",
|
| 408 |
+
"์ฒด์ค๋ณํ๋ฅผ ํ์ธํจ.",
|
| 409 |
+
"์์๋ณด์ถฉ์ ์ง์ํจ."
|
| 410 |
+
],
|
| 411 |
+
"resource": "์ง์ญ ๋ณด๊ฑด์ ์์ ๋ณด์ถฉ ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ๋ฐ ํ์ ์ ์์ ์์ก ์ฒ๋ฐฉ์ ์ํ ๋ณ์ ์ฐ๊ณ๋ฅผ ๊ฒํ ํจ."
|
| 412 |
+
},
|
| 413 |
+
"์ธ์ง์ ํยท์ ์๋ถ์": {
|
| 414 |
+
"domains": ["์ธ์ง/์น๋งค", "์ ์/์ฌ๋ฆฌ", "์ธ๊ถ"],
|
| 415 |
+
"goal": "๋ถ์๊ฐ์ ์ํํ๊ณ ์์ ์ ์ธ ์ผ์์ํ๊ณผ ์๋น์ค ์ด์ฉ์ด ์ด๋ฃจ์ด์ง๋๋ก ์ง์ํจ.",
|
| 416 |
+
"subjective": "์๊ธ์๋ ๋ณธ์ธ์ ๋ฌผ๊ฑด์ ๋จ์ด ๊ฐ์ ธ๊ฐ๋ค๊ณ ์์ฃผ ์ฃผ์ฅํ๋ฉฐ ๋ฐ๋ณตํ์ฌ ์ง๋ฌธํ๊ณ ์์ฌ์ ํํจ. ๋ถ์๊ฐ์ผ๋ก ์ธํด ๋ค๋ฅธ ์ฌ๋๋ค๊ณผ ๋ํํ์ง ์๊ฒ ๋ค๊ณ ๊ทน๋์ ์คํธ๋ ์ค๋ฅผ ํธ์ํจ.",
|
| 417 |
+
"objective": "์๊ฐ, ์ฅ์, ์ฌ๋์ ๋ํ ์ธ์ง ์ง๋จ๋ ฅ ์ ํ๊ฐ ๊ด์ฐฐ๋จ. ์ฃผ๋ณ ์๊ทน์ด ์์ ๋ ๋ฐฉ์ด์ ์ผ๋ก ํฅ๋ถํ๊ฑฐ๋ ๋์ผํ ์ง๋ฌธ์ ๋ฐ๋ณต์ ์ผ๋ก ์ํํ๊ณ ๋ฐฐํํ๋ ๊ฒฝํฅ์ด ๊ด์ฐฐ๋จ.",
|
| 418 |
+
"assessment": "์น๋งค ์ฆ์ ์งํ์ ๋ฐ๋ฅธ ์ผ์์ ๋ง์ ๋ฐ ๋ฐฐํ ํ๋์ผ๋ก ์ฌ์ ๋จ. ์ ๋ฉด ๋ฐ๋ฐ์ ํผํ๊ณ ์์ ๊ฐ์ ์ฃผ๋ ๋ง๋ฒ ์ง์๊ณผ ์ต์ํ ํ๊ฒฝ ์ ์ง๋ฅผ ๋ณํํ์ฌ ์ฌ๋ฆฌ์ ์์ ์ ๋๋ชจํด์ผ ํ๋ค๊ณ ํ๋จ๋จ.",
|
| 419 |
+
"plan": [
|
| 420 |
+
"๋ ์ง์ ์ฅ์๋ฅผ ๋ฐ๋ณต ์๋ดํจ.",
|
| 421 |
+
"ํ์๋ํ๋ฅผ ์ค์ํจ.",
|
| 422 |
+
"์ต์ํ ํ๊ฒฝ์ ์ ์งํ๋๋ก ์ง์ํจ.",
|
| 423 |
+
"์ธ์ง์๊ทน ํ๋์ ์ ๊ณตํจ.",
|
| 424 |
+
"๋์ผ ์ง๋ฌธ์ ์์ ์ ์ผ๋ก ์๋ํจ.",
|
| 425 |
+
"๋ง์ ์ ์ ๋ฉด ๋ฐ๋ฐ์ ์ง์ํจ.",
|
| 426 |
+
"๊ฐ์ ์ ๊ณต๊ฐํจ.",
|
| 427 |
+
"ํ์ ๋ฅผ ์ ํํจ."
|
| 428 |
+
],
|
| 429 |
+
"resource": "์น๋งค์์ฌ์ผํฐ ์น๋งค๊ฐ์กฑ ์ง์ ์๋น์ค ๋ฐ ์ธ์ง ์๊ทน ํ๋ก๊ทธ๋จ ์ฐ๊ณ๋ฅผ ๊ฒํ ํจ."
|
| 430 |
+
},
|
| 431 |
+
"์์ฐฝยทํผ๋ถ์ํ ๊ด๋ฆฌ": {
|
| 432 |
+
"domains": ["๊ฑด๊ฐ/์ ์ฒด", "๋ณต์ฝ"],
|
| 433 |
+
"goal": "ํผ๋ถ ์ฒญ๊ฒฐ๊ณผ ์์๋ฅผ ์ ์งํ๊ณ ์์ฐฝ ๋ฐ์์ ์๋ฐฉํจ.",
|
| 434 |
+
"subjective": "์๊ธ์๋ ํ๋ฃจ ์ข
์ผ ๊ผฌ๋ฆฌ๋ผ์ ์๋ฉ์ด ๋ถ์๊ฐ ๋ป๊ทผํ๊ณ ๊ฐ๋ ต๋ค๊ณ ํธ์ํจ. ๊ธฐ์ ๊ท ์ฐฉ์ฉ์ผ๋ก ๋์ด ์ฐจ์ ํผ๋ถ๊ฐ ๋ฐ๊ฐ๋ค๊ณ ๋ถ๋ง์ ํํํจ.",
|
| 435 |
+
"objective": "์์ ์ํ๋ก ํ๋๋์ด ๊ฑฐ์ ์์ผ๋ฉฐ ๋ฏธ๊ณจ ๋ถ์์ ๊ฐ๋ฒผ์ด ๋ฐ์ ์ด ๊ด์ฐฐ๋จ. ๊ธฐ์ ๊ท ๊ต์ฒด๊ฐ ๋น๋ฒํ๊ณ ํผ๋ถ๊ฐ ์ต์คํ ์ํ๊ฐ ์ง์์ ์ผ๋ก ํ์ธ๋จ.",
|
| 436 |
+
"assessment": "ํ์ก์ํ ์ ํ ๋ฐ ์ต์ค ํ๊ฒฝ์ผ๋ก ์ธํ ์ด๊ธฐ ์์ฐฝ ์งํ ๋จ๊ณ๋ก ํ๋จ๋จ. ์ ๊ธฐ์ ์ธ ์ฒด์๋ณ๊ฒฝ๊ณผ ์๊ฒฉํ ํผ๋ถ ์ฒญ๊ฒฐ ๊ด๋ฆฌ๊ฐ ์๊ธํ๋ฉฐ ๋จ๋ฐฑ์ง ์์ ๋ณด์ถฉ์ด ํ์ํ๋ค๊ณ ์ฌ์ ๋จ.",
|
| 437 |
+
"plan": [
|
| 438 |
+
"์ ๊ธฐ์ ์ฒด์๋ณ๊ฒฝ์ ์ค์ํจ.",
|
| 439 |
+
"ํผ๋ถ์ํ๋ฅผ ํ์ธํจ.",
|
| 440 |
+
"์์ฐฝ ๋ฐ์ ์ฌ๋ถ๋ฅผ ๊ด์ฐฐํจ.",
|
| 441 |
+
"์์์ํ๋ฅผ ํ์ธํจ.",
|
| 442 |
+
"์ฅ์๊ฐ ๋์ผ ์์ธ๋ฅผ ์๋ฐฉํจ.",
|
| 443 |
+
"ํผ๋ถ ์ฒญ๊ฒฐ์ ์ ์งํจ."
|
| 444 |
+
],
|
| 445 |
+
"resource": "์์ฐฝ ๋๋ ์ฑ ๋ฐ ํผ๋ถ ์๋
์ ์ํ ๋ฐฉ๋ฌธ๊ฐํธ ์๋น์ค ์ฐ๊ณ๋ฅผ ๊ฒํ ํจ."
|
| 446 |
+
},
|
| 447 |
+
"ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ์ ํ": {
|
| 448 |
+
"domains": ["์ ์/์ฌ๋ฆฌ", "์ฌํ๊ณ ๋ฆฝ"],
|
| 449 |
+
"goal": "์ ํธ ํ๋ ์ค์ฌ์ผ๋ก ์ฐธ์ฌ๋ฅผ ์ ๋ํ๊ณ ์ฌํ์ ๊ด๊ณ์ ํ๋ ฅ์ ๋์.",
|
| 450 |
+
"subjective": "์๊ธ์๋ ๋จ์ฒด ํ๋ก๊ทธ๋จ์ ์ฐธ์ฌํ๋ ๊ฒ์ด ๊ท์ฐฎ๊ณ ํผ๊ณคํ๋ค๊ณ ํธ์ํจ. ๋ค๋ฅธ ์๊ธ์๋ค๊ณผ ์ด์ธ๋ฆฌ์ง ์๊ณ ์ํ์ค์ ํผ์ ๋จ์ ์๊ธฐ๋ฅผ ๊ณ ์งํ๋ฉฐ ์ธ๋ก์์ ๊ฐ์ ์ ์ผ๋ก ํธ์ํจ.",
|
| 451 |
+
"objective": "์ต๊ทผ 2์ฃผ๊ฐ ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ๊ธฐ๋ก์ด ํ์ ํ ์ ์ ํจ. ์ฌ๋๋ค๊ณผ์ ์์ ๋ง์ฃผ์นจ์ ํผํ๊ณ ํ๋ฃจ ๋๋ถ๋ถ์ ์๊ฐ์ ์นจ์์ด๋ ํ ์ฒด์ด์ ๋ฌด๊ธฐ๋ ฅํ๊ฒ ์์ ์๋ ์ํ๋ก ํ์ธ๋จ.",
|
| 452 |
+
"assessment": "์ ์์ ์์ถ๊ณผ ์ฐ์ธ์ฆ์์ผ๋ก ์ธํ ์ฌํ์ ๊ณ ๋ฆฝ ์ํ๋ก ํ๋จ๋จ. ์ต์ง๋ก ํ๋ก๊ทธ๋จ ์ฐธ์ฌ๋ฅผ ๊ฐ์ํ๊ธฐ๋ณด๋ค๋ ์ ํธ๋๊ฐ ๋์ ์๊ท๋ชจ ํ๋ ๋ฐ ์ผ๋์ผ ๋ง๋ฒ ์ง์์ ํตํด ๋์ธ๊ด๊ณ ๋ฐ ํ๋ ฅ์ ์ด์งํ๋๋ก ๊ณํํจ.",
|
| 453 |
+
"plan": [
|
| 454 |
+
"์ง๋จ ํ๋ก๊ทธ๋จ ์ฐธ์ฌ๋ฅผ ์ง์ํจ.",
|
| 455 |
+
"๋๋ ๊ด๊ณ ํ์ฑ์ ์ง์ํจ.",
|
| 456 |
+
"๋ํ ๊ธฐํ๋ฅผ ์ ๊ณตํจ.",
|
| 457 |
+
"๊ณต๋ํ๋ ์ฐธ์ฌ๋ฅผ ์ ๋ํจ.",
|
| 458 |
+
"๋ง๋ฒ ์๋น์ค๋ฅผ ์ ๊ณตํจ.",
|
| 459 |
+
"์ทจ๋ฏธํ๋ ์ฐธ์ฌ๋ฅผ ์ง์ํจ.",
|
| 460 |
+
"์ฑ์ทจ๊ฐ์ ๊ฒฝํํ๋๋ก ์ง์ํจ."
|
| 461 |
+
],
|
| 462 |
+
"resource": "์ง์ญ ๋ณต์ง๊ด ํ๋ก๊ทธ๋จ ๋ฐ ์ ์ ์ง์ ๋ฉํ ๋ง ์ฐ๊ณ๋ฅผ ๊ฒํ ํจ."
|
| 463 |
+
},
|
| 464 |
+
"๋ณดํธ์ ์์ฒญยท์๋น์ค ์กฐ์ ": {
|
| 465 |
+
"domains": ["๊ฐ๋ฑ", "๊ฐ์กฑ๋ถ๋ด", "์ง์ญ์์"],
|
| 466 |
+
"goal": "๋ณดํธ์ ์๊ฒฌ๊ณผ ์๊ธ์ ์ํ๋ฅผ ๋ฐ์ํ์ฌ ์ ์ ํ ์๋น๏ฟฝ๏ฟฝ๏ฟฝ ์ ๊ณต ๋ฐฉํฅ์ ์กฐ์ ํจ.",
|
| 467 |
+
"subjective": "๋ณดํธ์๋ ์๊ธ์์ ๊ฐ์์ค๋ฌ์ด ์ํ ์
ํ๋ก ์ธํ ์ง์ ๋ด ๋๋ด ์คํธ๋ ์ค์ ๊ณ ์ถฉ์ ํธ์ํจ. ์๋น์ค ์ด์ฉ ์์ผ ๋ฐ ์๊ฐ์ ์ถ๊ฐํ๊ฑฐ๋ ๋ณ๊ฒฝํด ์ค ๊ฒ์ ๊ฐ๋ ฅํ๊ฒ ์์ฒญํจ.",
|
| 468 |
+
"objective": "์๊ธ์์ ์ธ์ง/์ ์ฒด ์ ํ ์๋๊ฐ ๋นจ๋ผ์ ธ ๊ธฐ์กด ๊ธ์ฌ์ ๊ณต๊ณํ์์ ์๊ฐ ์กฐ์จ์ด ๋ง์ง ์์์ ๊ด์ฐฐํจ. ๊ฐ์กฑ ๊ฐ ๋๋ด ์ญํ ๋ถ๋ด ๊ฐ๋ฑ์ด ํ๋ฉดํ๋ ๊ฒ์ ์๋ด๊ธฐ๋ก์ผ๋ก ํ์ธํจ.",
|
| 469 |
+
"assessment": "๋ณดํธ์์ ๋๋ด ๋ถ๋ด ์ํ๋ฅผ ์ํด ๊ธ์ฌ์๊ฐ ์ ์ฐํ์ ์ธ๋ถ ๋ณต์ง ์๋น์ค ํ์ฉ ๋ฐฉ์์ด ์๊ธํ๊ฒ ์๊ตฌ๋๋ ์ํฉ์ผ๋ก ํ๋จ๋จ. ๋ณดํธ์ ์๋ด์ ํตํ ์๊ฒฌ ์กฐ์ ๋ฐ ๊ธ์ฌ์ ๊ณต๊ณํ ๋ณ๊ฒฝ์ ๊ฒํ ํจ.",
|
| 470 |
+
"plan": [
|
| 471 |
+
"๋ณดํธ์ ์๋ด์ ์ค์ํจ.",
|
| 472 |
+
"๋๋ด ๋ถ๋ด์ ๊ฒฝ์ฒญํจ.",
|
| 473 |
+
"์ง์ญ์์ ์ฐ๊ณ๋ฅผ ์๋ดํจ.",
|
| 474 |
+
"๊ฐ์กฑ ์๊ฒฌ์ ์กฐ์ ํจ.",
|
| 475 |
+
"์์ฌ์ํต์ ์ง์ํจ."
|
| 476 |
+
],
|
| 477 |
+
"resource": "ํ์ ๋ณต์ง์ผํฐ ๊ธด๊ธ ๋๋ด ์๋น์ค ๋ฐ ์น๋งค๊ฐ์กฑ ์๋ด ์์ ์ฐ๊ณ๋ฅผ ๊ฒํ ํจ."
|
| 478 |
+
}
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
OPENERS = [
|
| 482 |
+
"ํ์ ์ฐธ์์๋ค์ ์ต๊ทผ ์๋ด๊ธฐ๋ก๊ณผ ์๊ตฌ์ฌ์ ๋ด์ฉ์ ํจ๊ป ๊ฒํ ํจ.",
|
| 483 |
+
"๋ณธ ์ฌ๋กํ์์์๋ ์๊ธ์์ ์ํ ๋ณํ, ๋ณดํธ์ ์๊ฒฌ, ๊ธ์ฌ์ ๊ณต ์ค ๊ด์ฐฐ์ฌํญ์ ์ข
ํฉํจ.",
|
| 484 |
+
"๊ธ์ผ ํ์์์๋ ๋จ์ ๋ฌธ์ ๊ธฐ๋ก์ด ์๋๋ผ ์ค์ ์๋น์ค ์ ๊ณต ๊ณผ์ ์ ๋ฐ์ํ ๊ฐ์
๋ฐฉํฅ์ ์ค์ฌ์ผ๋ก ๋
ผ์ํจ.",
|
| 485 |
+
"์๊ธ์์ ์๊ตฌ์ ๊ธฐ๊ด์์ ์ ๊ณต ๊ฐ๋ฅํ ์์์ ์ฐ๊ฒฐํ์ฌ ์ฌ๋ก๊ด๋ฆฌ ํ์์ฑ์ ๊ฒํ ํจ.",
|
| 486 |
+
]
|
| 487 |
+
|
| 488 |
+
TONES = [
|
| 489 |
+
"๊ฐ ์ง์ข
๋ณ ์ญํ ์ ๋ช
ํํ ํ์ฌ ๋์ผํ ๋ฐฉํฅ์ผ๋ก ์ง์ํ๊ธฐ๋ก ๊ฒฐ์ ํจ.",
|
| 490 |
+
"์๋ด๊ธฐ๋ก, ์๊ตฌ์ฌ์ , ๊ธ์ฌ์ ๊ณต๊ธฐ๋ก์ด ์๋ก ์ฐ๊ฒฐ๋๋๋ก ๊ด๋ฆฌํ๊ธฐ๋ก ๊ณํํจ.",
|
| 491 |
+
"๋ณดํธ์์๊ฒ๋ ์ฃผ์ ๋ณํ์ ๊ธฐ๊ด์ ์กฐ์น๊ณํ์ ์๋ดํ์ฌ ํ์กฐ๋ฅผ ๊ตฌํ๊ธฐ๋ก ํจ.",
|
| 492 |
+
"30์ผ ์ด์ ๊ด์ฐฐ ํ ๊ฒฐ๊ณผ๋ฅผ ๋ค์ ํ์ธํ๊ณ ํ์ ์ ๊ธ์ฌ์ ๊ณต๊ณํ์ ์กฐ์ ํ๊ธฐ๋ก ํ์ธํจ.",
|
| 493 |
+
]
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
# -----------------------------
|
| 497 |
+
# ์์ฝ ์์ฑ
|
| 498 |
+
# -----------------------------
|
| 499 |
+
def summarize_counseling(df):
|
| 500 |
+
if df.empty:
|
| 501 |
+
return "์ ์ฅ๋ ์๋ด์ผ์ง๊ฐ ์์ด ์๊ธ์ ๊ธฐ๋ณธ์ ๋ณด์ ์ง์ ์
๋ ฅํ ์ํ๋ณํ๋ฅผ ์ค์ฌ์ผ๋ก ์ฌ๋ก๊ด๋ฆฌ ํ์๋ฅผ ์งํํจ."
|
| 502 |
+
lines = []
|
| 503 |
+
for _, r in df.head(5).iterrows():
|
| 504 |
+
lines.append(
|
| 505 |
+
f"- {safe(r,'counseling_date')}: {safe(r,'counseling_type')} / ์ฌ์ : {safe(r,'counseling_reason')} / "
|
| 506 |
+
f"์ํ๋ณํ: {safe(r,'client_status_change') or '๊ธฐ๋ก ์์'} / ๋ณดํธ์ ์๊ฒฌ: {safe(r,'guardian_opinion') or '๊ธฐ๋ก ์์'}"
|
| 507 |
+
)
|
| 508 |
+
return "\n".join(lines)
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
def summarize_needs(df, client, manual_needs):
|
| 512 |
+
if not df.empty:
|
| 513 |
+
r = df.iloc[0]
|
| 514 |
+
return (
|
| 515 |
+
f"์ต๊ทผ ์๊ตฌ์ฌ์ ์ผ: {safe(r,'assessment_date')}\n"
|
| 516 |
+
f"์ข
ํฉ์๊ฒฌ: {safe(r,'total_opinion')}\n"
|
| 517 |
+
f"๊ฒฐ๊ณผ/๊ณํ: {safe(r,'result_plan')}\n"
|
| 518 |
+
f"์ํ์์ธ: ๋์ {safe(r,'fall_risk')}, ์์ฐฝ {safe(r,'bedsore_risk')}, ์ธ์ง {safe(r,'dementia_status')}, ๊ธฐ์ ๊ท {safe(r,'diaper_use')}\n"
|
| 519 |
+
f"์๋น์ค ์๊ตฌ: {safe(r,'service_needs')}"
|
| 520 |
+
)
|
| 521 |
+
|
| 522 |
+
base = (
|
| 523 |
+
f"Client Center ๋ฑ๋ก์ ๋ณด ๊ธฐ์ค ์ธ์ ๋ฒํธ: {safe(client,'recognition_number') or '๋ฏธ์
๋ ฅ'}, ์ธ์ ๊ธฐ๊ฐ: {safe(client,'recognition_start_date') or '๋ฏธ์
๋ ฅ'} ~ {safe(client,'recognition_end_date') or '๋ฏธ์
๋ ฅ'}, ์ฃผ์์ํ: {safe(client,'main_condition') or '๊ธฐ๋ก ์์'}, "
|
| 524 |
+
f"์ธ์ง์ํ: {safe(client,'cognitive_status') or '๊ธฐ๋ก ์์'}, "
|
| 525 |
+
f"์ด๋์ํ: {safe(client,'mobility_status') or '๊ธฐ๋ก ์์'}, "
|
| 526 |
+
f"์์ฌ์ํ: {safe(client,'diet_status') or '๊ธฐ๋ก ์์'}, "
|
| 527 |
+
f"๋ฐฐ๋ณ/๋ฐฐ๋จ์ํ: {safe(client,'toileting_status') or '๊ธฐ๋ก ์์'}"
|
| 528 |
+
)
|
| 529 |
+
if manual_needs.strip():
|
| 530 |
+
base += "\n์ง์ ์
๋ ฅ ์๊ตฌ์ฌ์ ์์ฝ: " + manual_needs.strip()
|
| 531 |
+
return base
|
| 532 |
+
|
| 533 |
+
|
| 534 |
+
# -----------------------------
|
| 535 |
+
# ์ฌ๋ก์ ํ ์๋์ถ์ฒ ๋ฐ ๋ฆฌ์คํฌ ๋ถ์
|
| 536 |
+
# -----------------------------
|
| 537 |
+
def recommend_case_type(counseling_summary, needs_summary, main_condition):
|
| 538 |
+
text = f"{counseling_summary} {needs_summary} {main_condition}".lower()
|
| 539 |
+
scores = {
|
| 540 |
+
"๋์ ๊ณ ์ํ ๊ด๋ฆฌ": 0,
|
| 541 |
+
"์์ฌ๋ ๊ฐ์ยท์์๊ด๋ฆฌ": 0,
|
| 542 |
+
"์ธ์ง์ ํยท์ ์๋ถ์": 0,
|
| 543 |
+
"์์ฐฝยทํผ๋ถ์ํ ๊ด๋ฆฌ": 0,
|
| 544 |
+
"ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ์ ํ": 0,
|
| 545 |
+
"๋ณดํธ์ ์์ฒญยท์๋น์ค ์กฐ์ ": 0
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
keywords = {
|
| 549 |
+
"๋์ ๊ณ ์ํ ๊ด๋ฆฌ": ["๋์", "์ด์ง๋ฌ", "๋์ด์ง", "์ด์ง๋ผ", "๋ณดํ", "ํ ์ฒด์ด", "์ด๋", "๋ณด์กฐ๊ธฐ", "์์ "],
|
| 550 |
+
"์์ฌ๋ ๊ฐ์ยท์์๊ด๋ฆฌ": ["์์ฌ", "์์ฌ๋", "์์", "์ฒด์ค", "์ํ", "์ญ์ทจ", "์์", "๊ฑฐ๋ถ", "์๋จ"],
|
| 551 |
+
"์ธ์ง์ ํยท์ ์๋ถ์": ["์ธ์ง", "์น๋งค", "์น๋งค์์ฌ", "์์ฌ", "ํ์ณ", "๋ง์", "๋ฐ๋ณต", "BPSD", "์ง๋จ๋ ฅ", "๋ถ์", "๋ฐฐํ"],
|
| 552 |
+
"์์ฐฝยทํผ๋ถ์ํ ๊ด๋ฆฌ": ["์์ฐฝ", "ํผ๋ถ", "๋ฐ์ ", "๊ธฐ์ ๊ท", "์ฒด์", "์ต์ค", "์์", "๋ณด์ต"],
|
| 553 |
+
"ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ์ ํ": ["ํ๋ก๊ทธ๋จ", "์ฐธ์ฌ", "๋ฌด๊ธฐ๋ ฅ", "์ฐ์ธ", "์์ถ", "๋ง๋ฒ", "ํํผ", "ํ๋"],
|
| 554 |
+
"๋ณดํธ์ ์์ฒญยท์๋น์ค ์กฐ์ ": ["๋ณดํธ์", "์์ฒญ", "์กฐ์ ", "๊ฐ๋ฑ", "๋ถ๋ด", "๊ฐ์กฑ", "์๋ด", "๊ณ ์ถฉ"]
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
for c_type, kw_list in keywords.items():
|
| 558 |
+
for kw in kw_list:
|
| 559 |
+
if kw in text:
|
| 560 |
+
scores[c_type] += 1
|
| 561 |
+
|
| 562 |
+
recommended = max(scores, key=scores.get)
|
| 563 |
+
if scores[recommended] == 0:
|
| 564 |
+
return "๋์ ๊ณ ์ํ ๊ด๋ฆฌ"
|
| 565 |
+
return recommended
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
def analyze_risk_domains(case_type, needs_summary, counseling_summary):
|
| 569 |
+
domains = []
|
| 570 |
+
if "๋์" in case_type or "์์ฐฝ" in case_type or "์์ฌ" in case_type:
|
| 571 |
+
domains.append("๊ฑด๊ฐ/์ ์ฒด")
|
| 572 |
+
if "๋์" in case_type:
|
| 573 |
+
domains.append("ํ๊ฒฝ")
|
| 574 |
+
if "์์ฌ" in case_type:
|
| 575 |
+
domains.append("๊ฑด๊ฐ/์ ์ฒด")
|
| 576 |
+
if "์ธ์ง์ ํ" in case_type or "์น๋งค" in case_type:
|
| 577 |
+
domains.append("์ธ์ง/์น๋งค")
|
| 578 |
+
domains.append("์ ์/์ฌ๋ฆฌ")
|
| 579 |
+
if "ํ๋ก๊ทธ๋จ" in case_type:
|
| 580 |
+
domains.append("์ ์/์ฌ๋ฆฌ")
|
| 581 |
+
domains.append("์ฌํ๊ณ ๋ฆฝ")
|
| 582 |
+
if "๋ณดํธ์" in case_type:
|
| 583 |
+
domains.append("๊ฐ๋ฑ")
|
| 584 |
+
domains.append("๊ฐ์กฑ๋ถ๋ด")
|
| 585 |
+
|
| 586 |
+
text = (needs_summary + " " + counseling_summary).lower()
|
| 587 |
+
if "์ฝ" in text or "๋ณต์ฝ" in text or "์ฝ๋ฌผ" in text:
|
| 588 |
+
domains.append("๋ณต์ฝ")
|
| 589 |
+
if "๋ณด๊ฑด์" in text or "์์ฌ์ผํฐ" in text or "๋ณต์ง๊ด" in text:
|
| 590 |
+
domains.append("์ง์ญ์์")
|
| 591 |
+
if "ํ๋" in text or "๋ฐฉ์" in text or "์ธ๊ถ" in text:
|
| 592 |
+
domains.append("์ธ๊ถ")
|
| 593 |
+
|
| 594 |
+
domains = list(dict.fromkeys(domains))
|
| 595 |
+
if not domains:
|
| 596 |
+
domains = ["๊ฑด๊ฐ/์ ์ฒด"]
|
| 597 |
+
return domains
|
| 598 |
+
|
| 599 |
+
|
| 600 |
+
def build_role_text(case_type, custom_roles=""):
|
| 601 |
+
details = CASE_DETAILS.get(case_type, CASE_DETAILS["๋์ ๊ณ ์ํ ๊ด๋ฆฌ"])
|
| 602 |
+
selected_methods = details["plan"][:3]
|
| 603 |
+
methods_bullet = ", ".join(selected_methods).replace("ํจ.", "ํจ")
|
| 604 |
+
|
| 605 |
+
default = f"""
|
| 606 |
+
์์ค์ฅ: ์ฌ๋ก๊ด๋ฆฌ ๋์ ์ ์ ์ ์ ์ ์ฑ์ ํ์ธํ๊ณ , ๊ธ์ฌ์ ๊ณต ๊ณํ ๋ณ๊ฒฝ ๋ฐ ์์ ์ฐ๊ณ ํ๋น์ฑ์ ์ ๊ฒํจ.
|
| 607 |
+
์ฌํ๋ณต์ง์ฌ: ์๋ด๊ธฐ๋ก๊ณผ ์๊ตฌ์ฌ์ ์ ํ ๋๋ก ์ฌ๋ก๊ฐ์
๋ฐฉํฅ์ ์ค์ ํ๊ณ , {methods_bullet} ๋ฑ ๊ตฌ์ฒด์ ์ธ ์ด์ฉ๊ณํ์ ์๋ฆฝํ์ฌ ์ ๊ณตํจ.
|
| 608 |
+
์์๋ณดํธ์ฌ: ์๋น์ค ์ ๊ณต ์ค ์๊ธ์ ์ํ ๋ณํ๋ฅผ ๊ด์ฐฐํ๊ณ , {methods_bullet} ์กฐ์น ์ฌํญ์ ์คํํ์ฌ ๊ธ์ฌ์ ๊ณต๊ธฐ๋ก์ง์ ์์ธ ๊ธฐ๋กํจ.
|
| 609 |
+
๊ฐํธ์กฐ๋ฌด์ฌ: ํ๋ ฅ์งํ ๋ฐ ์๊ธ์์ ์ ๋ฐ์ ์ธ ๊ฑด๊ฐ, ํผ๋ถ ์ํ๋ฅผ ์ ๊ฒํ๋ฉฐ, ์ด์ ์ฆ์ ๋ฐ์ ์ ์์ค์ฅ์๊ฒ ๋ณด๊ณ ํจ.
|
| 610 |
+
๋ฌผ๋ฆฌ์น๋ฃ์ฌ: ์ ์ฒด ์์กด ๊ธฐ๋ฅ ์ ์ง๋ฅผ ์ํด ์ ํฉํ ์ด๋ ๋ฐ ์์ธ ์ ์ด ์ด๋ ๋ฐฉ๋ฒ ๋ฑ์ ์กฐ์ธํจ.
|
| 611 |
+
""".strip()
|
| 612 |
+
return custom_roles.strip() or default
|
| 613 |
+
|
| 614 |
+
|
| 615 |
+
def build_attendees_text(director, social_worker, caregiver, nurse, therapist, guardian, extra_attendees):
|
| 616 |
+
attendees = []
|
| 617 |
+
if director.strip():
|
| 618 |
+
attendees.append(f"์์ค์ฅ: {director.strip()}")
|
| 619 |
+
else:
|
| 620 |
+
attendees.append("์์ค์ฅ: ์ฐธ์ ๋๋ ๊ฒํ ")
|
| 621 |
+
if social_worker.strip():
|
| 622 |
+
attendees.append(f"์ฌํ๋ณต์ง์ฌ: {social_worker.strip()}")
|
| 623 |
+
else:
|
| 624 |
+
attendees.append("์ฌํ๋ณต์ง์ฌ: ์ฐธ์")
|
| 625 |
+
if caregiver.strip():
|
| 626 |
+
attendees.append(f"์์๋ณดํธ์ฌ: {caregiver.strip()}")
|
| 627 |
+
else:
|
| 628 |
+
attendees.append("์์๋ณดํธ์ฌ: ์ฐธ์")
|
| 629 |
+
if nurse.strip():
|
| 630 |
+
attendees.append(f"๊ฐํธ์กฐ๋ฌด์ฌ: {nurse.strip()}")
|
| 631 |
+
else:
|
| 632 |
+
attendees.append("๊ฐํธ์กฐ๋ฌด์ฌ: ์ฐธ์")
|
| 633 |
+
if therapist.strip():
|
| 634 |
+
attendees.append(f"๋ฌผ๋ฆฌ์น๋ฃ์ฌ: {therapist.strip()}")
|
| 635 |
+
else:
|
| 636 |
+
attendees.append("๋ฌผ๋ฆฌ์น๋ฃ์ฌ: ํด๋น ์ ์๋ฌธ")
|
| 637 |
+
if guardian.strip():
|
| 638 |
+
attendees.append(f"๋ณดํธ์: {guardian.strip()}")
|
| 639 |
+
if extra_attendees.strip():
|
| 640 |
+
attendees.append(f"๊ธฐํ ์ฐธ์์: {extra_attendees.strip()}")
|
| 641 |
+
return "\n".join(attendees)
|
| 642 |
+
|
| 643 |
+
|
| 644 |
+
def build_case_documents(client, counseling_summary, needs_summary, case_type, custom_selection, custom_status, custom_goal, custom_roles):
|
| 645 |
+
case = CASE_TYPES[case_type]
|
| 646 |
+
details = CASE_DETAILS.get(case_type, CASE_DETAILS["๋์ ๊ณ ์ํ ๊ด๋ฆฌ"])
|
| 647 |
+
opener = random.choice(OPENERS)
|
| 648 |
+
tone = random.choice(TONES)
|
| 649 |
+
masked = safe(client, "masked_name", "์๊ธ์")
|
| 650 |
+
grade = safe(client, "care_grade")
|
| 651 |
+
institution_type = safe(client, "institution_type")
|
| 652 |
+
keywords = ", ".join(case["keywords"])
|
| 653 |
+
|
| 654 |
+
domains = analyze_risk_domains(case_type, needs_summary, counseling_summary)
|
| 655 |
+
domains_str = ", ".join(domains)
|
| 656 |
+
|
| 657 |
+
selection = custom_selection.strip() or (
|
| 658 |
+
f"{masked} ์๊ธ์๋ {grade} ๋์์๋ก {case['reason'].replace('ํ์ํจ.', 'ํ์ํจ')} "
|
| 659 |
+
f"์๋ด๊ธฐ๋ก๊ณผ ์๊ตฌ์ฌ์ ์์ ํ์ธ๋ ์ํ๋ฅผ ์ข
ํฉํ ๋ {case_type} ์ฌ๋ก๊ด๋ฆฌ ๋์์ผ๋ก ์ ์ ํจ."
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
first_content = f"""
|
| 663 |
+
{opener}
|
| 664 |
+
|
| 665 |
+
[10๋ ๋ฆฌ์คํฌ ๋๋ฉ์ธ ์๋๋ถ์]
|
| 666 |
+
- ๋ถ์ ๊ฒฐ๊ณผ ๋ถ๋ฅ๋ ํต์ฌ ๋ฆฌ์คํฌ ์์ญ: {domains_str}
|
| 667 |
+
|
| 668 |
+
[SOAP ๊ตฌ์กฐํ ๊ธฐ๋ก]
|
| 669 |
+
[S ์ฃผ๊ด์ ํธ์]
|
| 670 |
+
- {details['subjective']}
|
| 671 |
+
|
| 672 |
+
[O ๊ฐ๊ด์ ๊ด์ฐฐ]
|
| 673 |
+
- {details['objective']}
|
| 674 |
+
|
| 675 |
+
[A ์ ๋ฌธ์ ํ๋จ]
|
| 676 |
+
- {details['assessment']}
|
| 677 |
+
|
| 678 |
+
[P ์กฐ์น๊ณํ]
|
| 679 |
+
- {details['resource']}
|
| 680 |
+
|
| 681 |
+
[์๊ธ์ ๊ธฐ๋ณธ์ํ]
|
| 682 |
+
- ๊ธฐ๊ด์ ํ: {institution_type}
|
| 683 |
+
- ์ฅ๊ธฐ์์๋ฑ๊ธ: {grade}
|
| 684 |
+
- ์ธ์ ๋ฒํธ: {safe(client,'recognition_number') or '๋ฏธ์
๋ ฅ'}
|
| 685 |
+
- ์ธ์ ๊ธฐ๊ฐ: {safe(client,'recognition_start_date') or '๋ฏธ์
๋ ฅ'} ~ {safe(client,'recognition_end_date') or '๋ฏธ์
๋ ฅ'}
|
| 686 |
+
- ์ธ์ ๊ธฐ๊ฐ ์๋ฆผ: {recognition_alert_text(safe(client,'recognition_end_date'))}
|
| 687 |
+
- ์ฃผ์ ์งํ/์ํ: {safe(client,'main_condition') or '๊ธฐ๋ก ์์'}
|
| 688 |
+
- ์ธ์ง์ํ: {safe(client,'cognitive_status') or '๊ธฐ๋ก ์์'}
|
| 689 |
+
- ์ด๋์ํ: {safe(client,'mobility_status') or '๊ธฐ๋ก ์์'}
|
| 690 |
+
- ์์ฌ์ํ: {safe(client,'diet_status') or '๊ธฐ๋ก ์์'}
|
| 691 |
+
- ๋ฐฐ๋ณ/๋ฐฐ๋จ์ํ: {safe(client,'toileting_status') or '๊ธฐ๋ก ์์'}
|
| 692 |
+
|
| 693 |
+
[์๋ด์ผ์ง ์ฐ๋ ์์ฝ]
|
| 694 |
+
{counseling_summary}
|
| 695 |
+
|
| 696 |
+
[์๊ตฌ์ฌ์ ์ฐ๋ ์์ฝ]
|
| 697 |
+
{needs_summary}
|
| 698 |
+
|
| 699 |
+
[์ถ๊ฐ ์ํ๋ณํ]
|
| 700 |
+
{custom_status or '์ถ๊ฐ๋ก ์
๋ ฅ๋ ์ํ๋ณํ๋ ์์ผ๋, ๊ธฐ์กด ๊ธฐ๋ก์ ๋ฐํ์ผ๋ก ์ง์ ๊ด์ฐฐ์ด ํ์ํจ.'}
|
| 701 |
+
|
| 702 |
+
ํ์ ๊ฒฐ๊ณผ {case_type}๊ณผ ๊ด๋ จํ์ฌ {keywords} ํญ๋ชฉ์ ์ค์ฌ์ผ๋ก ๊ฐ์
ํ๊ธฐ๋ก ํ์์ผ๋ฉฐ, {tone}
|
| 703 |
+
""".strip()
|
| 704 |
+
|
| 705 |
+
goal = custom_goal.strip() or details["goal"]
|
| 706 |
+
|
| 707 |
+
selected_methods = details["plan"][:4]
|
| 708 |
+
methods_str = "\n".join(f"- {method}" for method in selected_methods)
|
| 709 |
+
|
| 710 |
+
plan = f"""
|
| 711 |
+
[1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ]
|
| 712 |
+
{goal}
|
| 713 |
+
|
| 714 |
+
[1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๊ณํ ๋ฐ ๊ตฌ์ฒด์ ์ง์๋ฐฉ๋ฒ]
|
| 715 |
+
{methods_str}
|
| 716 |
+
|
| 717 |
+
[์ธ๋ถ์์ ์ฐ๊ณ ๋ฐฉ์]
|
| 718 |
+
- {details['resource']}
|
| 719 |
+
|
| 720 |
+
[๊ธ์ฌ์ ๊ณต๊ณํ ๋ฐ์ ์ฌ๋ถ ์ ๊ฒ]
|
| 721 |
+
โ ๊ธ์ฌ์ ๊ณต๊ณํ ๋ณ๊ฒฝ ํ์
|
| 722 |
+
โ ์๊ตฌ์ฌ์ ์ฌ์ ๊ฒ ํ์
|
| 723 |
+
โ ๋ณดํธ์ ์๋ด ํ์
|
| 724 |
+
โ ์ํ๋ณํ๊ธฐ๋ก ์ฐ๊ณ ํ์
|
| 725 |
+
""".strip()
|
| 726 |
+
|
| 727 |
+
role_division = build_role_text(case_type, custom_roles)
|
| 728 |
+
|
| 729 |
+
implementation = f"""
|
| 730 |
+
[์ญํ ๋ถ๋ด์ ๋ฐ๋ฅธ ์ํ๊ณผ์ ๋ฐ ๊ตฌ์ฒด์ ์ง์๋ฐฉ๋ฒ ์ํ]
|
| 731 |
+
- ์์ค์ฅ: ์ฌ๋ก๊ด๋ฆฌ์ ๋ฐ๋ฅธ ์์ฐ ํธ์ฑ ๋ฐ ๊ธ์ฌ์ ๊ณต ๊ณํ ๋ฐ์ ํ๋ก์ธ์ค๊ฐ ์ ์ ํ๊ฒ ์ด๋ฃจ์ด์ง๋์ง ๊ฒ์ฆํจ.
|
| 732 |
+
- ์ฌํ๋ณต์ง์ฌ: ๋ณดํธ์์ ์ ์ ๋ฐ ๋ฐฉ๋ฌธ์๋ด์ ํตํด ์๋น์ค ์กฐ์ ์ ์ดํํ์์ผ๋ฉฐ, ๊ฐ๋ณ์ด์ฉ๊ณํ ์ง์๋ฐฉ๋ฒ์ ๋ง์ถฐ ๊ณํ์ ์๋ฆฝํจ.
|
| 733 |
+
- ์์๋ณดํธ์ฌ: ์ผ์ ๋๋ด ์๋น์ค ์ ๊ณต ์ค ์๊ธฐ ์ง์๋ฐฉ๋ฒ ์ง์นจ์ ์ดํํ๊ณ , ์๊ธ์์ ํน์ด ๋ฐ์์ ์ผ์๊ธฐ๋ก์ง์ ์ฆ์ ๋ณด๊ณ ๋ฐ ์์ฑํจ.
|
| 734 |
+
- ๊ฐํธ์กฐ๋ฌด์ฌ: ๊ธฐ์ ๊ท ์ผ์ด, ๋ณต์ฝ ์ฒดํฌ, ์์ฌ/์๋ถ ์ญ์ทจ ๋น์ค์ ์ ๊ฒํ๊ณ , ๋ณด๊ฑด์ ๋ฐ ๋ฐฉ๋ฌธ๊ฐํธ ์๋น์ค ์ฐ๊ณ ํ์์ฑ์ ์ง์ ํ๋จํจ.
|
| 735 |
+
- ๋ฌผ๋ฆฌ์น๋ฃ์ฌ: ์ค๋ด ๋ณดํ ์ํ์ ์ด์ง๋ผ ์ฌ๋ถ๋ฅผ ๊ด์ฐฐํ๊ณ , ๋ณดํ๋ณด์กฐ๊ธฐ ์ ๋น ๋ฐ ์ค๋ด ๋์ ์์ ์ ์ํด ์๋ฌธํจ.
|
| 736 |
+
|
| 737 |
+
[๊ณผ์ ์ ๊ฒ ๊ฒฐ๊ณผ]
|
| 738 |
+
- ๊ณํ ์๋ฆฝ ์ดํ 30์ผ๊ฐ ์๊ธ์ ๋ฐ์ฐฉ ์ผ์ด์ ๊ด์ฐฐ์ด ์ด๋ฃจ์ด์ก์ผ๋ฉฐ, ๋ณดํธ์์ ํผ๋๋ฐฑ์ ์๋ ดํ์ฌ ๊ฐ์ ์์ ์ํํจ.
|
| 739 |
+
""".strip()
|
| 740 |
+
|
| 741 |
+
second_result = f"""
|
| 742 |
+
[2์ฐจ ๊ฒฐ๊ณผํ์ ๋ด์ฉ]
|
| 743 |
+
- 1์ฐจ ๊ณํ ์๋ฆฝ ์ดํ 30์ผ๊ฐ์ ๊ฐ๋ณ์ด์ฉ๊ณํ ์ง์์ฌํญ ๋ฐ ์คํ๊ณผ์ ์ ๊ฒ์ฆํจ.
|
| 744 |
+
|
| 745 |
+
[์ํ๊ณผ์ ์ ๊ฒ]
|
| 746 |
+
- ์์๋ณดํธ์ฌ ๋ฐ ๊ฐํธ์กฐ๋ฌด์ฌ์ ์ผ์ ๋ฐ ๊ฑด๊ฐ ๊ด์ฐฐ๊ธฐ๋ก์ ๊ฒํ ํ์์ผ๋ฉฐ, ๋ณดํธ์ ๋ฉด๋ด ๊ฒฐ๊ณผ๋ฅผ ํตํฉํจ.
|
| 747 |
+
|
| 748 |
+
[๋ชฉํ๋ฌ์ฑ ์ฌ๋ถ ํ๊ฐ]
|
| 749 |
+
- ํ๊ฐ ๊ฒฐ๊ณผ: ๋ถ๋ถ๋ฌ์ฑ ๋ฐ ์ง์ ๊ด์ฐฐ ํ์
|
| 750 |
+
- ๋ฏธ๋ฌ์ฑ ์ฌ์ : ์๊ธ์์ ์ธ์ง ๋
ธํ ์งํ ์๋ ๋ฐ ์ ์ฒด ๊ฐ์ง์ผ๋ก ์ธํด ๋ณดํ ์๋ฆฝ๋๊ฐ ์์ ํ ๊ฐ์ ๋์ง๋ ๋ชปํจ.
|
| 751 |
+
- ํ์๊ณํ: ์ธ๋ถ์์({details['resource']}) ์ฐ๊ณ๋ฅผ ๊ฐํํ๊ณ , ๊ธ์ฌ์ ๊ณต๊ณํ์ ์ฌ์กฐ์ ํ์ฌ ์์ ๋ํ์ ์ง์ํจ.
|
| 752 |
+
|
| 753 |
+
[๊ธ์ฌ์ ๊ณต ๋ฐ์ ๊ฒฐ๊ณผ]
|
| 754 |
+
- ์๊ธ์์ ๊ฐ๋ณ ์ง์ ํ๋์ง์นจ์ด ๊ธ์ฌ์ ๊ณต๊ธฐ๋ก์ง ๋ฐ ๊ธ์ฌ์ ๊ณต๊ณํ์์ ์ ํฉ์ฑ ์๊ฒ ์์ฑ ์๋ฃ๋์์์ ํ์ธํจ.
|
| 755 |
+
""".strip()
|
| 756 |
+
|
| 757 |
+
return selection, first_content, goal, plan, role_division, implementation, second_result
|
| 758 |
+
|
| 759 |
+
|
| 760 |
+
|
| 761 |
+
def evaluate_case(selection, first_content, plan, role_division, implementation, second_result, counseling_summary, needs_summary):
|
| 762 |
+
required = {
|
| 763 |
+
"์ ์ ์ฌ์ ": bool(selection.strip()),
|
| 764 |
+
"์๋ด์ผ์ง ์ฐ๋": "์๋ด" in counseling_summary and "์ ์ฅ๋ ์๋ด์ผ์ง ์์ด" not in counseling_summary,
|
| 765 |
+
"์๊ตฌ์ฌ์ ์ฐ๋": bool(needs_summary.strip()),
|
| 766 |
+
"1์ฐจ ๊ณํ": bool(plan.strip()) and "๋ชฉํ" in plan,
|
| 767 |
+
"์ญํ ๋ถ๋ด": all(word in role_division for word in ["์์ค์ฅ", "์ฌํ๋ณต์ง์ฌ", "์์๋ณดํธ์ฌ", "๊ฐํธ์กฐ๋ฌด์ฌ", "๋ฌผ๋ฆฌ์น๋ฃ์ฌ"]),
|
| 768 |
+
"์ํ๊ณผ์ ": bool(implementation.strip()) and "์ํ๊ณผ์ " in implementation,
|
| 769 |
+
"2์ฐจ ๊ฒฐ๊ณผํ์": bool(second_result.strip()) and "๊ฒฐ๊ณผ" in second_result,
|
| 770 |
+
"๋ณดํธ์ ์๊ฒฌ/์ํ๋ณํ": ("๋ณดํธ์" in first_content or "๋ณดํธ์" in second_result) and ("์ํ๋ณํ" in first_content or "๋ณํ" in second_result),
|
| 771 |
+
"๊ธ์ฌ์ ๊ณต ๋ฐ์": "๊ธ์ฌ์ ๊ณต" in plan and "๊ธ์ฌ์ ๊ณต" in second_result,
|
| 772 |
+
}
|
| 773 |
+
score = int(sum(required.values()) / len(required) * 100)
|
| 774 |
+
missing = [k for k, v in required.items() if not v]
|
| 775 |
+
if score >= 90:
|
| 776 |
+
result = "ํ๊ฐ ์ ํฉ๋๊ฐ ๋์ต๋๋ค. ์ฌ๋ก์ ์ , 1์ฐจ ๊ณํ, ์ญํ ๋ถ๋ด, ์ํ๊ณผ์ , 2์ฐจ ๊ฒฐ๊ณผํ๊ฐ๊ฐ ์ฐ๊ฒฐ๋์ด ์์ต๋๋ค."
|
| 777 |
+
elif score >= 75:
|
| 778 |
+
result = "๋์ฒด๋ก ์ ํฉํ๋ ์ผ๋ถ ๋ณด์์ด ํ์ํฉ๋๋ค. ๋ถ์กฑ ํญ๋ชฉ์ ์ถ๊ฐํ๋ฉด ํ๊ฐ ๋์๋ ฅ์ด ๋์์ง๋๋ค."
|
| 779 |
+
else:
|
| 780 |
+
result = "๋ณด์์ด ํ์ํฉ๋๋ค. ์๋ด์ผ์ง, ์๊ตฌ์ฌ์ , ์ญํ ๋ณ ์ํ๊ณผ์ , 2์ฐจ ๊ฒฐ๊ณผํ๊ฐ๊ฐ ๋ ๊ตฌ์ฒด์ ์ผ๋ก ์ฐ๊ฒฐ๋์ด์ผ ํฉ๋๋ค."
|
| 781 |
+
return score, missing, result
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
# -----------------------------
|
| 785 |
+
# ์์
ํจ์ (์ ์๋ฆผ ๋ฌธ์ ๋ฐ ์์ ๊ฐ์ ์ ์ฉ)
|
| 786 |
+
# -----------------------------
|
| 787 |
+
def set_page_style(ws):
|
| 788 |
+
ws.page_setup.paperSize = ws.PAPERSIZE_A4
|
| 789 |
+
ws.page_setup.orientation = "portrait"
|
| 790 |
+
ws.page_setup.fitToWidth = 1
|
| 791 |
+
ws.page_setup.fitToHeight = 0
|
| 792 |
+
ws.sheet_properties.pageSetUpPr.fitToPage = True
|
| 793 |
+
ws.page_margins.left = 0.3
|
| 794 |
+
ws.page_margins.right = 0.3
|
| 795 |
+
ws.page_margins.top = 0.4
|
| 796 |
+
ws.page_margins.bottom = 0.4
|
| 797 |
+
ws.sheet_view.showGridLines = False
|
| 798 |
+
|
| 799 |
+
def style_range(ws, cell_range, border_on=True, fill=None, font=None, alignment=None):
|
| 800 |
+
"""๋ณํฉ ์
ํฌํจ ๋ฒ์ ์ ์ฒด์ ์คํ์ผ ์ ์ฉ (๊ฒ์ ์ ํ
๋๋ฆฌ๋ก ๊ฐ์์ฑ ํ๋ณด)"""
|
| 801 |
+
# ์ ์์์ ์ ๋ช
ํ ๊ฒ์ (000000)์ผ๋ก ๋ณ๊ฒฝํ์ฌ ๋ ๋๋ง ๋๋ฝ ๋ฐฉ์ง
|
| 802 |
+
thin = Side(style="thin", color="000000")
|
| 803 |
+
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
| 804 |
+
|
| 805 |
+
cells = ws[cell_range]
|
| 806 |
+
if not isinstance(cells, tuple):
|
| 807 |
+
cells = ((cells,),)
|
| 808 |
+
|
| 809 |
+
for row in cells:
|
| 810 |
+
for cell in row:
|
| 811 |
+
if border_on:
|
| 812 |
+
cell.border = border
|
| 813 |
+
if fill:
|
| 814 |
+
cell.fill = fill
|
| 815 |
+
if font:
|
| 816 |
+
cell.font = font
|
| 817 |
+
if alignment:
|
| 818 |
+
cell.alignment = alignment
|
| 819 |
+
|
| 820 |
+
def write_title_with_approval(ws, title, title_fill, header_fill):
|
| 821 |
+
for col in range(1, 10):
|
| 822 |
+
ws.column_dimensions[get_column_letter(col)].width = 13
|
| 823 |
+
|
| 824 |
+
ws.merge_cells("A1:G2")
|
| 825 |
+
c = ws["A1"]
|
| 826 |
+
c.value = title
|
| 827 |
+
c.font = Font(name="Malgun Gothic", size=24, bold=True)
|
| 828 |
+
c.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 829 |
+
style_range(ws, "A1:G2", fill=title_fill)
|
| 830 |
+
|
| 831 |
+
headers = ["๋ด๋น์", "์์ค์ฅ"]
|
| 832 |
+
for idx, col in enumerate(range(8, 10)):
|
| 833 |
+
c1 = ws.cell(1, col)
|
| 834 |
+
c2 = ws.cell(2, col)
|
| 835 |
+
c1.value = headers[idx]
|
| 836 |
+
c2.value = ""
|
| 837 |
+
c1.font = Font(name="Malgun Gothic", size=12, bold=True)
|
| 838 |
+
c2.font = Font(name="Malgun Gothic", size=11)
|
| 839 |
+
c1.alignment = Alignment(horizontal="center", vertical="center")
|
| 840 |
+
c2.alignment = Alignment(horizontal="center", vertical="center")
|
| 841 |
+
c1.fill = header_fill
|
| 842 |
+
style_range(ws, f"{get_column_letter(col)}1:{get_column_letter(col)}2")
|
| 843 |
+
|
| 844 |
+
ws.row_dimensions[1].height = 28
|
| 845 |
+
ws.row_dimensions[2].height = 42
|
| 846 |
+
|
| 847 |
+
def write_info_row(ws, row, a, b, c, d, e, f, header_fill):
|
| 848 |
+
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=3)
|
| 849 |
+
ws.merge_cells(start_row=row, start_column=5, end_row=row, end_column=6)
|
| 850 |
+
ws.merge_cells(start_row=row, start_column=8, end_row=row, end_column=9)
|
| 851 |
+
|
| 852 |
+
pairs = [(1, a), (2, b), (4, c), (5, d), (7, e), (8, f)]
|
| 853 |
+
for col, val in pairs:
|
| 854 |
+
is_label = col in [1, 4, 7]
|
| 855 |
+
cell = ws.cell(row, col)
|
| 856 |
+
cell.value = val
|
| 857 |
+
cell.font = Font(name="Malgun Gothic", size=11, bold=is_label)
|
| 858 |
+
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 859 |
+
if is_label:
|
| 860 |
+
cell.fill = header_fill
|
| 861 |
+
|
| 862 |
+
style_range(ws, f"A{row}:I{row}")
|
| 863 |
+
ws.row_dimensions[row].height = 30
|
| 864 |
+
|
| 865 |
+
def write_section(ws, row, title, content, header_fill, min_height=90):
|
| 866 |
+
# ์ ๋ชฉ ํ
|
| 867 |
+
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=9)
|
| 868 |
+
cell = ws.cell(row, 1)
|
| 869 |
+
cell.value = title
|
| 870 |
+
cell.font = Font(name="Malgun Gothic", size=15, bold=True)
|
| 871 |
+
cell.alignment = Alignment(horizontal="center", vertical="center")
|
| 872 |
+
cell.fill = header_fill
|
| 873 |
+
style_range(ws, f"A{row}:I{row}")
|
| 874 |
+
ws.row_dimensions[row].height = 30
|
| 875 |
+
row += 1
|
| 876 |
+
|
| 877 |
+
# ๋ด์ฉ ํ
|
| 878 |
+
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=9)
|
| 879 |
+
cell2 = ws.cell(row, 1)
|
| 880 |
+
cell2.value = content
|
| 881 |
+
cell2.font = Font(name="Malgun Gothic", size=11)
|
| 882 |
+
cell2.alignment = Alignment(horizontal="left", vertical="top", wrap_text=True)
|
| 883 |
+
style_range(ws, f"A{row}:I{row}")
|
| 884 |
+
|
| 885 |
+
# ํ
์คํธ ์๋ฆผ ๋ฐ ์๋ ํ
๋๋ฆฌ ๋ฎ์ ํ์์ ๋ฐฉ์งํ๊ธฐ ์ํ ํ ๋์ด ์ ๋ฐ ๊ณ์ฐ
|
| 886 |
+
content_str = str(content)
|
| 887 |
+
lines = 0
|
| 888 |
+
for line in content_str.split("\n"):
|
| 889 |
+
# ํ ์ค๋น ์ฝ 40์ ๊ธฐ์ค์ผ๋ก ์ค๋ฐ๊ฟ ๋ฐ์์ ์์ธกํ์ฌ ๊ณ์ฐ (์ฌ์ ์๊ฒ 40์ผ๋ก ์ค์ )
|
| 890 |
+
lines += (len(line) // 40) + 1
|
| 891 |
+
|
| 892 |
+
# ๊ฐ ์ค๋น ๋์ด๋ฅผ 24 ํฝ์
๋ก ๋๋ํ๊ฒ ์ก๊ณ , ์ํ ์ฌ๋ฐฑ 15๋ฅผ ์ถ๊ฐ
|
| 893 |
+
calculated_height = lines * 24 + 15
|
| 894 |
+
ws.row_dimensions[row].height = max(min_height, calculated_height)
|
| 895 |
+
|
| 896 |
+
return row + 1
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
def generate_excel(data):
|
| 900 |
+
wb = Workbook()
|
| 901 |
+
title_fill = PatternFill("solid", fgColor="EDE9FE")
|
| 902 |
+
header_fill = PatternFill("solid", fgColor="F3F4F6")
|
| 903 |
+
|
| 904 |
+
# 1์ฐจ ๊ณํํ์๋ก ์ํธ
|
| 905 |
+
ws1 = wb.active
|
| 906 |
+
ws1.title = "1์ฐจ๊ณํํ์๋ก"
|
| 907 |
+
set_page_style(ws1)
|
| 908 |
+
write_title_with_approval(ws1, "์ฌ๋ก๊ด๋ฆฌ 1์ฐจ ๊ณํํ์๋ก", title_fill, header_fill)
|
| 909 |
+
|
| 910 |
+
r = 3
|
| 911 |
+
write_info_row(ws1, r, "๊ธฐ๊ด๋ช
", data["institution_name"], "๊ธฐ๊ด์ ํ", data["institution_type"], "ํ์์ผ์", data["first_meeting_date"], header_fill); r += 1
|
| 912 |
+
write_info_row(ws1, r, "์๊ธ์", data["client_masked_name"], "์ฅ๊ธฐ์์๋ฑ๊ธ", data["grade"], "์ฌ๋ก์ ํ", data["case_type"], header_fill); r += 1
|
| 913 |
+
write_info_row(ws1, r, "์ธ์ ๋ฒํธ", data.get("recognition_number", ""), "์ธ์ ๊ธฐ๊ฐ", f"{data.get('recognition_start_date','')} ~ {data.get('recognition_end_date','')}", "๊ธฐํ์๋ฆผ", data.get("recognition_alert", ""), header_fill); r += 1
|
| 914 |
+
write_info_row(ws1, r, "ํ์์ฅ์", data["meeting_place"], "์์ฑ์", data["writer"], "2์ฐจ์์ ์ผ", data["second_meeting_date"], header_fill); r += 1
|
| 915 |
+
|
| 916 |
+
r = write_section(ws1, r, "์ ์ ์ฌ์ ", data["selection_reason"], header_fill, 80)
|
| 917 |
+
r = write_section(ws1, r, "์๋ด์ผ์ง ์ฐ๋ ์์ฝ", data["counseling_summary"], header_fill, 90)
|
| 918 |
+
r = write_section(ws1, r, "์๊ตฌ์ฌ์ ์ฐ๋ ์์ฝ", data["needs_summary"], header_fill, 90)
|
| 919 |
+
r = write_section(ws1, r, "1์ฐจ ํ์๋ด์ฉ", data["first_content"], header_fill, 150)
|
| 920 |
+
r = write_section(ws1, r, "1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ ๋ฐ ๊ณํ", f"[๋ชฉํ]\n{data['goal']}\n\n[๊ณํ]\n{data['first_plan']}", header_fill, 140)
|
| 921 |
+
r = write_section(ws1, r, "์ญํ ๋ถ๋ด", data["role_division"], header_fill, 130)
|
| 922 |
+
r = write_section(ws1, r, "์ฐธ์์ ๋ช
๋จ", data.get("attendees_text", "์์ค์ฅ, ์ฌํ๋ณต์ง์ฌ, ์์๋ณดํธ์ฌ, ๊ฐํธ์กฐ๋ฌด์ฌ ์ฐธ์"), header_fill, 90)
|
| 923 |
+
r = write_section(ws1, r, "ํ๊ฐ ์ ํฉ๋ ์ ๊ฒ", f"{data['evaluation_score']}์ \n๋ถ์กฑ ํญ๋ชฉ: {data['missing_items']}\n{data['compliance_result']}", header_fill, 80)
|
| 924 |
+
|
| 925 |
+
# ์ฌ์ง์ฒจ๋ถ
|
| 926 |
+
if data.get("photo_paths"):
|
| 927 |
+
ws1.merge_cells(start_row=r, start_column=1, end_row=r, end_column=9)
|
| 928 |
+
ws1.cell(r, 1).value = "์ฌ์ง์ฒจ๋ถ"
|
| 929 |
+
ws1.cell(r, 1).font = Font(name="Malgun Gothic", size=15, bold=True)
|
| 930 |
+
ws1.cell(r, 1).alignment = Alignment(horizontal="center", vertical="center")
|
| 931 |
+
ws1.cell(r, 1).fill = header_fill
|
| 932 |
+
r += 1
|
| 933 |
+
|
| 934 |
+
anchors = ["A", "D", "G"]
|
| 935 |
+
img_row = r
|
| 936 |
+
for idx, photo_path in enumerate(data.get("photo_paths", [])[:3]):
|
| 937 |
+
try:
|
| 938 |
+
img = XLImage(photo_path)
|
| 939 |
+
img.width = 210
|
| 940 |
+
img.height = 150
|
| 941 |
+
ws1.add_image(img, f"{anchors[idx]}{img_row}")
|
| 942 |
+
except Exception:
|
| 943 |
+
pass
|
| 944 |
+
|
| 945 |
+
for rr in range(img_row, img_row + 8):
|
| 946 |
+
ws1.row_dimensions[rr].height = 22
|
| 947 |
+
r = img_row + 8
|
| 948 |
+
|
| 949 |
+
# ๊ณตํต ์๋ด๋ฌธ๊ตฌ ์ถ๊ฐ
|
| 950 |
+
ws1.merge_cells(start_row=r, start_column=1, end_row=r, end_column=9)
|
| 951 |
+
ws1.cell(r, 1).value = "โป ์์ฑ๋ ๋ฌธ์๋ ๊ทธ๋๋ก ์ฌ์ฉํ์
๋ ๋๋ฉฐ, ๊ธฐ๊ด์ ์ด์๋ฐฉ์นจ, ์๊ธ์ ์ํ, ๋ณดํธ์ ์๊ฒฌ ๋ฐ ํ๊ฐ๊ธฐ์ค์ ๋ฐ๋ผ ์ถ๊ฐ ๋ณด์์ฌํญ์ ์ผ๋ง๋ ์ง ์์ ๊ฐ๋ฅํฉ๋๋ค. ๊ธฐ๊ด์ ์ํฉ์ ๋ง๊ฒ ํ์ฉํ์๊ธฐ ๋ฐ๋๋๋ค."
|
| 952 |
+
ws1.cell(r, 1).font = Font(name="Malgun Gothic", size=8.5, color="595959", italic=True)
|
| 953 |
+
ws1.cell(r, 1).alignment = Alignment(horizontal="left", vertical="center", wrap_text=True)
|
| 954 |
+
style_range(ws1, f"A{r}:I{r}")
|
| 955 |
+
ws1.row_dimensions[r].height = 36
|
| 956 |
+
r += 1
|
| 957 |
+
|
| 958 |
+
# ํ
๋๋ฆฌ ์คํ์ผ ์ผ๊ด ์ ์ฉ
|
| 959 |
+
thin = Side(style="thin", color="000000")
|
| 960 |
+
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
| 961 |
+
for row in range(1, r):
|
| 962 |
+
for col in range(1, 10):
|
| 963 |
+
cell = ws1.cell(row, col)
|
| 964 |
+
cell.border = border
|
| 965 |
+
if not cell.font.name:
|
| 966 |
+
cell.font = Font(name="Malgun Gothic", size=11)
|
| 967 |
+
|
| 968 |
+
# 2์ฐจ ๊ฒฐ๊ณผํ์๋ก ์ํธ ์์ฑ
|
| 969 |
+
ws2 = wb.create_sheet("2์ฐจ๊ฒฐ๊ณผํ์๋ก")
|
| 970 |
+
set_page_style(ws2)
|
| 971 |
+
write_title_with_approval(ws2, "์ฌ๋ก๊ด๋ฆฌ 2์ฐจ ๊ฒฐ๊ณผํ์๋ก", title_fill, header_fill)
|
| 972 |
+
|
| 973 |
+
r2 = 3
|
| 974 |
+
write_info_row(ws2, r2, "๊ธฐ๊ด๋ช
", data["institution_name"], "๊ธฐ๊ด์ ํ", data["institution_type"], "ํ์์ผ์", data["second_meeting_date"], header_fill); r2 += 1
|
| 975 |
+
write_info_row(ws2, r2, "์๊ธ์", data["client_masked_name"], "์ฅ๊ธฐ์์๋ฑ๊ธ", data["grade"], "์ฌ๋ก์ ํ", data["case_type"], header_fill); r2 += 1
|
| 976 |
+
write_info_row(ws2, r2, "์ธ๏ฟฝ๏ฟฝ๏ฟฝ๋ฒํธ", data.get("recognition_number", ""), "์ธ์ ๊ธฐ๊ฐ", f"{data.get('recognition_start_date','')} ~ {data.get('recognition_end_date','')}", "๊ธฐํ์๋ฆผ", data.get("recognition_alert", ""), header_fill); r2 += 1
|
| 977 |
+
write_info_row(ws2, r2, "ํ์์ฅ์", data["meeting_place"], "์์ฑ์", data["writer"], "1์ฐจํ์์ผ", data["first_meeting_date"], header_fill); r2 += 1
|
| 978 |
+
|
| 979 |
+
r2 = write_section(ws2, r2, "์ ์ ์ฌ์ ", data["selection_reason"], header_fill, 80)
|
| 980 |
+
r2 = write_section(ws2, r2, "1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ ๋ฐ ๊ณํ", f"[๋ชฉํ]\n{data['goal']}\n\n[๊ณํ]\n{data['first_plan']}", header_fill, 130)
|
| 981 |
+
r2 = write_section(ws2, r2, "์ญํ ๋ณ ์ํ๊ณผ์ ", data["implementation_process"], header_fill, 150)
|
| 982 |
+
r2 = write_section(ws2, r2, "2์ฐจ ํ์๊ฒฐ๊ณผ ๋ฐ ํ๊ฐ", data["second_result"], header_fill, 150)
|
| 983 |
+
r2 = write_section(ws2, r2, "์ฐธ์์ ๋ช
๋จ", data.get("attendees_text", "์์ค์ฅ, ์ฌํ๋ณต์ง์ฌ, ์์๋ณดํธ์ฌ, ๊ฐํธ์กฐ๋ฌด์ฌ ์ฐธ์"), header_fill, 90)
|
| 984 |
+
|
| 985 |
+
# ๊ณตํต ์๋ด๋ฌธ๊ตฌ ์ถ๊ฐ
|
| 986 |
+
ws2.merge_cells(start_row=r2, start_column=1, end_row=r2, end_column=9)
|
| 987 |
+
ws2.cell(r2, 1).value = "โป ์์ฑ๋ ๋ฌธ์๋ ๊ทธ๋๋ก ์ฌ์ฉํ์
๋ ๋๋ฉฐ, ๊ธฐ๊ด์ ์ด์๋ฐฉ์นจ, ์๊ธ์ ์ํ, ๋ณดํธ์ ์๊ฒฌ ๋ฐ ํ๊ฐ๊ธฐ์ค์ ๋ฐ๋ผ ์ถ๊ฐ ๋ณด์์ฌํญ์ ์ผ๋ง๋ ์ง ์์ ๊ฐ๋ฅํฉ๋๋ค. ๊ธฐ๊ด์ ์ํฉ์ ๋ง๊ฒ ํ์ฉํ์๊ธฐ ๋ฐ๋๋๋ค."
|
| 988 |
+
ws2.cell(r2, 1).font = Font(name="Malgun Gothic", size=8.5, color="595959", italic=True)
|
| 989 |
+
ws2.cell(r2, 1).alignment = Alignment(horizontal="left", vertical="center", wrap_text=True)
|
| 990 |
+
style_range(ws2, f"A{r2}:I{r2}")
|
| 991 |
+
ws2.row_dimensions[r2].height = 36
|
| 992 |
+
r2 += 1
|
| 993 |
+
|
| 994 |
+
for row in range(1, r2):
|
| 995 |
+
for col in range(1, 10):
|
| 996 |
+
cell = ws2.cell(row, col)
|
| 997 |
+
cell.border = border
|
| 998 |
+
if not cell.font.name:
|
| 999 |
+
cell.font = Font(name="Malgun Gothic", size=11)
|
| 1000 |
+
|
| 1001 |
+
output = BytesIO()
|
| 1002 |
+
wb.save(output)
|
| 1003 |
+
output.seek(0)
|
| 1004 |
+
return output
|
| 1005 |
+
|
| 1006 |
+
|
| 1007 |
+
def save_uploaded_photos(uploaded_files):
|
| 1008 |
+
paths = []
|
| 1009 |
+
for file in (uploaded_files or []):
|
| 1010 |
+
suffix = os.path.splitext(file.name)[1].lower() or ".png"
|
| 1011 |
+
temp_path = os.path.join(tempfile.gettempdir(), f"case_photo_{datetime.now().strftime('%Y%m%d%H%M%S%f')}{suffix}")
|
| 1012 |
+
with open(temp_path, "wb") as f:
|
| 1013 |
+
f.write(file.getbuffer())
|
| 1014 |
+
paths.append(temp_path)
|
| 1015 |
+
return paths
|
| 1016 |
+
|
| 1017 |
+
|
| 1018 |
+
def get_client_history(db_path: str, client_id: int):
|
| 1019 |
+
conn = sqlite3.connect(db_path)
|
| 1020 |
+
try:
|
| 1021 |
+
counsel_df = pd.read_sql_query(
|
| 1022 |
+
"SELECT counseling_date, counseling_type, counseling_reason, client_status_change, guardian_opinion FROM counseling_records WHERE client_id = ? ORDER BY counseling_date DESC, id DESC LIMIT 5",
|
| 1023 |
+
conn, params=(int(client_id),)
|
| 1024 |
+
)
|
| 1025 |
+
except Exception:
|
| 1026 |
+
counsel_df = pd.DataFrame()
|
| 1027 |
+
try:
|
| 1028 |
+
status_df = pd.read_sql_query(
|
| 1029 |
+
"SELECT record_date, change_category, body_status, cognitive_status, staff_observation, guardian_opinion FROM status_change_records WHERE client_id = ? ORDER BY record_date DESC, id DESC LIMIT 5",
|
| 1030 |
+
conn, params=(int(client_id),)
|
| 1031 |
+
)
|
| 1032 |
+
except Exception:
|
| 1033 |
+
status_df = pd.DataFrame()
|
| 1034 |
+
conn.close()
|
| 1035 |
+
return counsel_df, status_df
|
| 1036 |
+
|
| 1037 |
+
|
| 1038 |
+
# -----------------------------
|
| 1039 |
+
# Streamlit ํ๋ฉด ๊ตฌ์ฑ (๋ชจ๋ ๋ ๋ฒจ ์คํ)
|
| 1040 |
+
# -----------------------------
|
| 1041 |
+
menu = st.sidebar.radio("๋ฉ๋ด", ["์ฌ๋ก๊ด๋ฆฌ ์์ฑ", "์ ์ฅ๊ธฐ๋ก ๋ณด๊ธฐ"])
|
| 1042 |
+
|
| 1043 |
+
st.sidebar.success("DB ์ฐ๊ฒฐ")
|
| 1044 |
+
st.sidebar.caption(DB_PATH)
|
| 1045 |
+
|
| 1046 |
+
clients_df = load_clients()
|
| 1047 |
+
|
| 1048 |
+
if menu == "์ ์ฅ๊ธฐ๋ก ๋ณด๊ธฐ":
|
| 1049 |
+
st.subheader("๐ ์ ์ฅ๋ ์ฌ๋ก๊ด๋ฆฌ ๊ธฐ๋ก")
|
| 1050 |
+
conn = get_conn()
|
| 1051 |
+
try:
|
| 1052 |
+
records_df = pd.read_sql_query("SELECT * FROM case_management_records ORDER BY id DESC LIMIT 20", conn)
|
| 1053 |
+
if records_df.empty:
|
| 1054 |
+
st.info("์ ์ฅ๋ ์ฌ๋ก๊ด๋ฆฌ ๊ธฐ๋ก์ด ์์ต๋๋ค.")
|
| 1055 |
+
else:
|
| 1056 |
+
st.dataframe(records_df, use_container_width=True)
|
| 1057 |
+
except Exception as e:
|
| 1058 |
+
st.error(f"๊ธฐ๋ก ์กฐํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}")
|
| 1059 |
+
conn.close()
|
| 1060 |
+
|
| 1061 |
+
elif menu == "์ฌ๋ก๊ด๋ฆฌ ์์ฑ":
|
| 1062 |
+
if clients_df.empty:
|
| 1063 |
+
st.warning("Client Center ์๊ธ์ DB๊ฐ ๋น์ด ์์ต๋๋ค. ๋จผ์ ์๊ธ์๋ฅผ ๋ฑ๋กํ์ธ์.")
|
| 1064 |
+
st.stop()
|
| 1065 |
+
|
| 1066 |
+
options = clients_df.apply(
|
| 1067 |
+
lambda x: f"{x['id']}๋ฒ - {x['masked_name']} / {x['care_grade']} / {x['institution_type']} / {x.get('status','')}",
|
| 1068 |
+
axis=1
|
| 1069 |
+
).tolist()
|
| 1070 |
+
|
| 1071 |
+
selected_option = st.selectbox("์๊ธ์ ์ ํ", options)
|
| 1072 |
+
selected_id = int(selected_option.split("๋ฒ")[0])
|
| 1073 |
+
client = clients_df[clients_df["id"] == selected_id].iloc[0]
|
| 1074 |
+
|
| 1075 |
+
client_id = int(safe(client, "id", 0) or 0)
|
| 1076 |
+
institution_type = safe(client, "institution_type", "๋ฐฉ๋ฌธ์์")
|
| 1077 |
+
institution_name = safe(client, "institution_name", "BeeCare ์ฅ๊ธฐ์์๊ธฐ๊ด")
|
| 1078 |
+
|
| 1079 |
+
m1, m2, m3, m4 = st.columns(4)
|
| 1080 |
+
m1.metric("์๊ธ์", safe(client, "masked_name"))
|
| 1081 |
+
m2.metric("๋ฑ๊ธ", safe(client, "care_grade"))
|
| 1082 |
+
m3.metric("๊ธฐ๊ด์ ํ", institution_type)
|
| 1083 |
+
m4.metric("์ธ์ ๊ธฐ๊ฐ ์๋ฆผ", recognition_alert_text(safe(client, "recognition_end_date")))
|
| 1084 |
+
|
| 1085 |
+
# RAG ๋ฐ์ดํฐ ์ฐ๋ ์กฐํ ๋ฐ ์ฌ๋ก์ ํ ์ถ์ฒ์ ๋จผ์ ์ํ
|
| 1086 |
+
counseling_df, _ = get_client_history(DB_PATH, client_id)
|
| 1087 |
+
counseling_summary = summarize_counseling(counseling_df)
|
| 1088 |
+
|
| 1089 |
+
needs_df = load_needs_assessment(client_id)
|
| 1090 |
+
needs_summary = summarize_needs(needs_df, client, "")
|
| 1091 |
+
|
| 1092 |
+
recommended_type = recommend_case_type(counseling_summary, needs_summary, safe(client, "main_condition"))
|
| 1093 |
+
|
| 1094 |
+
with st.expander("๐ ์ธ์ ์ ๋ณด ํ์ธ", expanded=False):
|
| 1095 |
+
st.write(f"์ธ์ ๋ฒํธ: {safe(client, 'recognition_number') or '๋ฏธ์
๋ ฅ'}")
|
| 1096 |
+
st.write(f"์ธ์ ๊ธฐ๊ฐ: {safe(client, 'recognition_start_date') or '๋ฏธ์
๋ ฅ'} ~ {safe(client, 'recognition_end_date') or '๋ฏธ์
๋ ฅ'}")
|
| 1097 |
+
st.info(recognition_alert_text(safe(client, 'recognition_end_date')))
|
| 1098 |
+
|
| 1099 |
+
st.markdown("### ํ์ ๊ธฐ๋ณธ์ ๋ณด")
|
| 1100 |
+
col1, col2, col3 = st.columns(3)
|
| 1101 |
+
|
| 1102 |
+
case_types_list = list(CASE_TYPES.keys())
|
| 1103 |
+
try:
|
| 1104 |
+
rec_index = case_types_list.index(recommended_type)
|
| 1105 |
+
except ValueError:
|
| 1106 |
+
rec_index = 0
|
| 1107 |
+
|
| 1108 |
+
case_type = col1.selectbox("์ฌ๋ก์ ํ", case_types_list, index=rec_index)
|
| 1109 |
+
col1.info(f"๐ก ์์คํ
์ถ์ฒ ์ฌ๋ก์ ํ: **{recommended_type}**")
|
| 1110 |
+
|
| 1111 |
+
first_meeting_date = col2.date_input("1์ฐจ ํ์์ผ์", value=date.today())
|
| 1112 |
+
second_meeting_date = col3.date_input("2์ฐจ ๊ฒฐ๊ณผํ์์ผ์ (๋ณดํต 30์ผ ํ)", value=date.today() + timedelta(days=30))
|
| 1113 |
+
|
| 1114 |
+
col4, col5 = st.columns(2)
|
| 1115 |
+
meeting_place = col4.text_input("ํ์์ฅ์", "๊ธฐ๊ด ์ฌ๋ฌด์ค ๋ฐ ํ์์ค")
|
| 1116 |
+
writer = col5.text_input("์์ฑ์", "์ฌํ๋ณต์ง์ฌ")
|
| 1117 |
+
|
| 1118 |
+
st.markdown("### ์ฐธ์์")
|
| 1119 |
+
c1, c2, c3, c4 = st.columns(4)
|
| 1120 |
+
director_attendee = c1.text_input("์์ค์ฅ", "์์ค์ฅ")
|
| 1121 |
+
sw_attendee = c2.text_input("์ฌํ๋ณต์ง์ฌ", "์ฌํ๋ณต์ง์ฌ")
|
| 1122 |
+
cg_attendee = c3.text_input("์์๋ณดํธ์ฌ", "์์๋ณดํธ์ฌ")
|
| 1123 |
+
nurse_attendee = c4.text_input("๊ฐํธ(์กฐ๋ฌด)์ฌ", "๊ฐํธ์กฐ๋ฌด์ฌ")
|
| 1124 |
+
|
| 1125 |
+
c5, c6 = st.columns(2)
|
| 1126 |
+
therapist_attendee = c5.text_input("๋ฌผ๋ฆฌ/์์
์น๋ฃ์ฌ (์ ํ)", "")
|
| 1127 |
+
guardian_attendee = c6.text_input("๋ณดํธ์ (์ ํ)", "")
|
| 1128 |
+
extra_attendees = st.text_input("๊ธฐํ ์ฐธ์์ (์ ํ)", "")
|
| 1129 |
+
|
| 1130 |
+
attendees_text = build_attendees_text(
|
| 1131 |
+
director_attendee, sw_attendee, cg_attendee, nurse_attendee,
|
| 1132 |
+
therapist_attendee, guardian_attendee, extra_attendees
|
| 1133 |
+
)
|
| 1134 |
+
|
| 1135 |
+
st.markdown("### ์๋ ์ถ๊ฐ/์กฐ์ ์
๋ ฅ (์ ํ์ฌํญ)")
|
| 1136 |
+
custom_selection = st.text_area("์ ์ ์ฌ์ ์๋ ์
๋ ฅ", placeholder="๋น์๋ ์ ์๋์ผ๋ก ์์ฑํฉ๋๋ค.", height=70)
|
| 1137 |
+
custom_status = st.text_area("์ถ๊ฐ ์ํ๋ณํ ๊ธฐ๋ก", placeholder="๋น์๋ ์ ๊ธฐ๋ณธ ์ํ๋ฅผ ํ ๋๋ก ์์ฑํฉ๋๋ค.", height=70)
|
| 1138 |
+
custom_goal = st.text_area("1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ ์๋ ์
๋ ฅ", placeholder="๋น์๋ ์ ๊ธฐ๋ณธ ๋ชฉํ๋ฅผ ์์ฑํฉ๋๋ค.", height=70)
|
| 1139 |
+
custom_roles = st.text_area("์ญํ ๋ถ๋ด ์๋ ์
๋ ฅ", placeholder="๋น์๋ ์ ๊ธฐ๋ณธ ์ง์ข
๋ณ ์ญํ ๋ถ๋ด์ ์์ฑํฉ๋๋ค.", height=70)
|
| 1140 |
+
|
| 1141 |
+
photos = st.file_uploader("์ฌ์ง์ฒจ๋ถ (์ต๋ 3์ฅ, ์ ํ์ฌํญ)", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
| 1142 |
+
|
| 1143 |
+
if st.button("๐ ์ฌ๋ก๊ด๋ฆฌ ํตํฉ ํ์๋ก ์์ฑ", use_container_width=True):
|
| 1144 |
+
selection, first_content, goal, plan, role_division, implementation, second_result = build_case_documents(
|
| 1145 |
+
client, counseling_summary, needs_summary, case_type,
|
| 1146 |
+
custom_selection, custom_status, custom_goal, custom_roles
|
| 1147 |
+
)
|
| 1148 |
+
|
| 1149 |
+
score, missing, compliance = evaluate_case(
|
| 1150 |
+
selection, first_content, plan, role_division, implementation, second_result,
|
| 1151 |
+
counseling_summary, needs_summary
|
| 1152 |
+
)
|
| 1153 |
+
|
| 1154 |
+
photo_paths = save_uploaded_photos(photos)
|
| 1155 |
+
|
| 1156 |
+
st.session_state["case_data"] = {
|
| 1157 |
+
"client_id": client_id,
|
| 1158 |
+
"client_masked_name": safe(client, "masked_name"),
|
| 1159 |
+
"institution_name": institution_name,
|
| 1160 |
+
"institution_type": institution_type,
|
| 1161 |
+
"grade": safe(client, "care_grade"),
|
| 1162 |
+
"recognition_number": safe(client, "recognition_number"),
|
| 1163 |
+
"recognition_start_date": safe(client, "recognition_start_date"),
|
| 1164 |
+
"recognition_end_date": safe(client, "recognition_end_date"),
|
| 1165 |
+
"recognition_alert": recognition_alert_text(safe(client, "recognition_end_date")),
|
| 1166 |
+
"case_type": case_type,
|
| 1167 |
+
"first_meeting_date": str(first_meeting_date),
|
| 1168 |
+
"second_meeting_date": str(second_meeting_date),
|
| 1169 |
+
"meeting_place": meeting_place,
|
| 1170 |
+
"writer": writer,
|
| 1171 |
+
"attendees_text": attendees_text,
|
| 1172 |
+
"selection_reason": selection,
|
| 1173 |
+
"first_content": first_content,
|
| 1174 |
+
"goal": goal,
|
| 1175 |
+
"first_plan": plan,
|
| 1176 |
+
"role_division": role_division,
|
| 1177 |
+
"implementation_process": implementation,
|
| 1178 |
+
"second_result": second_result,
|
| 1179 |
+
"counseling_summary": counseling_summary,
|
| 1180 |
+
"needs_summary": needs_summary,
|
| 1181 |
+
"evaluation_score": score,
|
| 1182 |
+
"missing_items": ", ".join(missing) if missing else "๋ถ์กฑ ํญ๋ชฉ ์์",
|
| 1183 |
+
"compliance_result": compliance,
|
| 1184 |
+
"photo_paths": photo_paths
|
| 1185 |
+
}
|
| 1186 |
+
|
| 1187 |
+
if "case_data" in st.session_state:
|
| 1188 |
+
data = st.session_state["case_data"]
|
| 1189 |
+
|
| 1190 |
+
st.markdown("---")
|
| 1191 |
+
st.subheader("์์ฑ๋ ์ฌ๋ก๊ด๋ฆฌ ํ์๋ก (์์ ๊ฐ๋ฅ)")
|
| 1192 |
+
|
| 1193 |
+
data["selection_reason"] = st.text_area("์ ์ ์ฌ์ ", value=data["selection_reason"], height=100)
|
| 1194 |
+
data["first_content"] = st.text_area("1์ฐจ ํ์๋ด์ฉ", value=data["first_content"], height=200)
|
| 1195 |
+
data["goal"] = st.text_area("๋ชฉํ", value=data["goal"], height=80)
|
| 1196 |
+
data["first_plan"] = st.text_area("1์ฐจ ๊ณํ", value=data["first_plan"], height=150)
|
| 1197 |
+
data["role_division"] = st.text_area("์ญํ ๋ถ๋ด", value=data["role_division"], height=150)
|
| 1198 |
+
data["implementation_process"] = st.text_area("์ํ๊ณผ์ ", value=data["implementation_process"], height=150)
|
| 1199 |
+
data["second_result"] = st.text_area("2์ฐจ ๊ฒฐ๊ณผํ๊ฐ", value=data["second_result"], height=200)
|
| 1200 |
+
|
| 1201 |
+
# ํ๊ฐ์ ํฉ๋ ์ฌ์กฐ์
|
| 1202 |
+
score, missing, compliance = evaluate_case(
|
| 1203 |
+
data["selection_reason"], data["first_content"], data["first_plan"],
|
| 1204 |
+
data["role_division"], data["implementation_process"], data["second_result"],
|
| 1205 |
+
data["counseling_summary"], data["needs_summary"]
|
| 1206 |
+
)
|
| 1207 |
+
data["evaluation_score"] = score
|
| 1208 |
+
data["missing_items"] = ", ".join(missing) if missing else "๋ถ์กฑ ํญ๋ชฉ ์์"
|
| 1209 |
+
data["compliance_result"] = compliance
|
| 1210 |
+
|
| 1211 |
+
st.subheader("ํ๊ฐ ์ ํฉ๋ ์ ๊ฒ")
|
| 1212 |
+
e1, e2 = st.columns(2)
|
| 1213 |
+
e1.metric("ํ๊ฐ ์ ํฉ๋", f"{score}์ ")
|
| 1214 |
+
e2.metric("๋ถ์กฑ ํญ๋ชฉ", data["missing_items"])
|
| 1215 |
+
|
| 1216 |
+
if score >= 90:
|
| 1217 |
+
st.success(compliance)
|
| 1218 |
+
else:
|
| 1219 |
+
st.warning(compliance)
|
| 1220 |
+
|
| 1221 |
+
if st.button("๐พ ์ฌ๋ก๊ด๋ฆฌ ๊ธฐ๋ก DB ์ ์ฅ", use_container_width=True):
|
| 1222 |
+
save_case_record(data)
|
| 1223 |
+
st.success("์ฌ๋ก๊ด๋ฆฌ ๊ธฐ๋ก์ด DB์ ์ฑ๊ณต์ ์ผ๋ก ์ ์ฅ๋์์ต๋๋ค.")
|
| 1224 |
+
|
| 1225 |
+
filename = f"์ฌ๋ก๊ด๋ฆฌ์ผ์ง_{data['client_masked_name']}_{data['first_meeting_date']}.xlsx"
|
| 1226 |
+
if st.button("๐ฆ ์์
ํ์ผ ์ค๋นํ๊ธฐ", use_container_width=True, key="prepare_case_excel_fast"):
|
| 1227 |
+
st.session_state["case_excel_fast"] = generate_excel(data)
|
| 1228 |
+
st.success("์์
ํ์ผ ์ค๋น๊ฐ ์๋ฃ๋์์ต๋๋ค. ์๋ ๋ค์ด๋ก๋ ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์.")
|
| 1229 |
+
|
| 1230 |
+
if "case_excel_fast" in st.session_state:
|
| 1231 |
+
st.download_button(
|
| 1232 |
+
"๐ฅ ์ฌ๋ก๊ด๋ฆฌ ํ์๋ก ์์
๋ค์ด๋ก๋",
|
| 1233 |
+
data=st.session_state["case_excel_fast"],
|
| 1234 |
+
file_name=filename,
|
| 1235 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 1236 |
+
use_container_width=True,
|
| 1237 |
+
key="download_case_excel_fast",
|
| 1238 |
+
)
|
| 1239 |
+
|
| 1240 |
+
st.caption("๋น ๋ฅธ ๋ฒ์ : ํ๋ฉด ์์ฑ ํ, ์์
์ ํ์ํ ๋๋ง ์ค๋นํฉ๋๋ค.")
|