devorah-ai-2016 commited on
Commit
fb608fc
ยท
verified ยท
1 Parent(s): 70a7984

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +1240 -0
app.py ADDED
@@ -0,0 +1,1240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("๋น ๋ฅธ ๋ฒ„์ „: ํ™”๋ฉด ์ƒ์„ฑ ํ›„, ์—‘์…€์€ ํ•„์š”ํ•  ๋•Œ๋งŒ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค.")