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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 |
+
# BeeCare ํตํฉ์ฐ๋ ์ฌ๋ก๊ด๋ฆฌ ์์ฑ๊ธฐ
|
| 18 |
+
# Client Center + ์๋ด์ผ์ง + ์๊ตฌ์ฌ์ ์ฐ๋ํ
|
| 19 |
+
# =========================================================
|
| 20 |
+
|
| 21 |
+
st.set_page_config(page_title="BeeCare ํตํฉ ์ฌ๋ก๊ด๋ฆฌ", 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>๐ BeeCare ํตํฉ ์ฌ๋ก๊ด๋ฆฌ ์์ฑ๊ธฐ</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 |
+
|
| 96 |
+
# -----------------------------
|
| 97 |
+
# DB
|
| 98 |
+
# -----------------------------
|
| 99 |
+
def get_conn():
|
| 100 |
+
return sqlite3.connect(DB_PATH, check_same_thread=False)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def init_db():
|
| 104 |
+
conn = get_conn()
|
| 105 |
+
cur = conn.cursor()
|
| 106 |
+
|
| 107 |
+
cur.execute("""
|
| 108 |
+
CREATE TABLE IF NOT EXISTS clients (
|
| 109 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 110 |
+
name TEXT NOT NULL,
|
| 111 |
+
masked_name TEXT,
|
| 112 |
+
gender TEXT,
|
| 113 |
+
birth_year TEXT,
|
| 114 |
+
care_grade TEXT,
|
| 115 |
+
institution_type TEXT,
|
| 116 |
+
institution_name TEXT,
|
| 117 |
+
admission_date TEXT,
|
| 118 |
+
main_condition TEXT,
|
| 119 |
+
cognitive_status TEXT,
|
| 120 |
+
mobility_status TEXT,
|
| 121 |
+
diet_status TEXT,
|
| 122 |
+
toileting_status TEXT,
|
| 123 |
+
guardian_name TEXT,
|
| 124 |
+
guardian_phone TEXT,
|
| 125 |
+
notes TEXT,
|
| 126 |
+
status TEXT DEFAULT '์ด์ฉ์ค',
|
| 127 |
+
created_at TEXT,
|
| 128 |
+
updated_at TEXT
|
| 129 |
+
)
|
| 130 |
+
""")
|
| 131 |
+
|
| 132 |
+
cur.execute("""
|
| 133 |
+
CREATE TABLE IF NOT EXISTS counseling_records (
|
| 134 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 135 |
+
client_id INTEGER,
|
| 136 |
+
client_masked_name TEXT,
|
| 137 |
+
institution_type TEXT,
|
| 138 |
+
counseling_type TEXT,
|
| 139 |
+
counseling_date TEXT,
|
| 140 |
+
counselor TEXT,
|
| 141 |
+
counseling_reason TEXT,
|
| 142 |
+
client_status_change TEXT,
|
| 143 |
+
guardian_opinion TEXT,
|
| 144 |
+
counseling_content TEXT,
|
| 145 |
+
action_plan TEXT,
|
| 146 |
+
evaluation_score INTEGER,
|
| 147 |
+
missing_items TEXT,
|
| 148 |
+
compliance_result TEXT,
|
| 149 |
+
next_due_note TEXT,
|
| 150 |
+
created_at TEXT
|
| 151 |
+
)
|
| 152 |
+
""")
|
| 153 |
+
|
| 154 |
+
# ์๊ตฌ์ฌ์ ์์ฑ๊ธฐ๊ฐ ๋์ค์ ์ ์ฅ ๊ธฐ๋ฅ์ ๋ถ์ด๋ฉด ์ด ํ
์ด๋ธ์ ๊ทธ๋๋ก ์ฌ์ฉ ๊ฐ๋ฅ
|
| 155 |
+
cur.execute("""
|
| 156 |
+
CREATE TABLE IF NOT EXISTS needs_assessment_records (
|
| 157 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 158 |
+
client_id INTEGER,
|
| 159 |
+
client_masked_name TEXT,
|
| 160 |
+
assessment_date TEXT,
|
| 161 |
+
total_opinion TEXT,
|
| 162 |
+
result_status TEXT,
|
| 163 |
+
result_plan TEXT,
|
| 164 |
+
fall_risk TEXT,
|
| 165 |
+
bedsore_risk TEXT,
|
| 166 |
+
dementia_status TEXT,
|
| 167 |
+
diaper_use TEXT,
|
| 168 |
+
service_needs TEXT,
|
| 169 |
+
created_at TEXT
|
| 170 |
+
)
|
| 171 |
+
""")
|
| 172 |
+
|
| 173 |
+
cur.execute("""
|
| 174 |
+
CREATE TABLE IF NOT EXISTS case_management_records (
|
| 175 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 176 |
+
client_id INTEGER,
|
| 177 |
+
client_masked_name TEXT,
|
| 178 |
+
institution_type TEXT,
|
| 179 |
+
case_type TEXT,
|
| 180 |
+
first_meeting_date TEXT,
|
| 181 |
+
second_meeting_date TEXT,
|
| 182 |
+
selection_reason TEXT,
|
| 183 |
+
first_plan TEXT,
|
| 184 |
+
implementation_process TEXT,
|
| 185 |
+
second_result TEXT,
|
| 186 |
+
evaluation_score INTEGER,
|
| 187 |
+
missing_items TEXT,
|
| 188 |
+
created_at TEXT
|
| 189 |
+
)
|
| 190 |
+
""")
|
| 191 |
+
|
| 192 |
+
conn.commit()
|
| 193 |
+
conn.close()
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def load_clients():
|
| 197 |
+
conn = get_conn()
|
| 198 |
+
try:
|
| 199 |
+
df = pd.read_sql_query("""
|
| 200 |
+
SELECT * FROM clients ORDER BY id DESC
|
| 201 |
+
""", conn)
|
| 202 |
+
except Exception:
|
| 203 |
+
df = pd.DataFrame()
|
| 204 |
+
conn.close()
|
| 205 |
+
return df
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def load_counseling(client_id):
|
| 209 |
+
conn = get_conn()
|
| 210 |
+
try:
|
| 211 |
+
df = pd.read_sql_query("""
|
| 212 |
+
SELECT * FROM counseling_records
|
| 213 |
+
WHERE client_id = ?
|
| 214 |
+
ORDER BY counseling_date DESC, id DESC
|
| 215 |
+
""", conn, params=(int(client_id),))
|
| 216 |
+
except Exception:
|
| 217 |
+
df = pd.DataFrame()
|
| 218 |
+
conn.close()
|
| 219 |
+
return df
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def load_needs_assessment(client_id):
|
| 223 |
+
conn = get_conn()
|
| 224 |
+
try:
|
| 225 |
+
df = pd.read_sql_query("""
|
| 226 |
+
SELECT * FROM needs_assessment_records
|
| 227 |
+
WHERE client_id = ?
|
| 228 |
+
ORDER BY assessment_date DESC, id DESC
|
| 229 |
+
""", conn, params=(int(client_id),))
|
| 230 |
+
except Exception:
|
| 231 |
+
df = pd.DataFrame()
|
| 232 |
+
conn.close()
|
| 233 |
+
return df
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def save_case_record(data):
|
| 237 |
+
conn = get_conn()
|
| 238 |
+
cur = conn.cursor()
|
| 239 |
+
cur.execute("""
|
| 240 |
+
INSERT INTO case_management_records (
|
| 241 |
+
client_id, client_masked_name, institution_type, case_type,
|
| 242 |
+
first_meeting_date, second_meeting_date, selection_reason,
|
| 243 |
+
first_plan, implementation_process, second_result,
|
| 244 |
+
evaluation_score, missing_items, created_at
|
| 245 |
+
)
|
| 246 |
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 247 |
+
""", (
|
| 248 |
+
data["client_id"], data["client_masked_name"], data["institution_type"], data["case_type"],
|
| 249 |
+
data["first_meeting_date"], data["second_meeting_date"], data["selection_reason"],
|
| 250 |
+
data["first_plan"], data["implementation_process"], data["second_result"],
|
| 251 |
+
data["evaluation_score"], data["missing_items"],
|
| 252 |
+
datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 253 |
+
))
|
| 254 |
+
conn.commit()
|
| 255 |
+
conn.close()
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def safe(row, key, default=""):
|
| 259 |
+
try:
|
| 260 |
+
v = row.get(key, default)
|
| 261 |
+
if pd.isna(v):
|
| 262 |
+
return default
|
| 263 |
+
return str(v)
|
| 264 |
+
except Exception:
|
| 265 |
+
return default
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def mask_name(name):
|
| 269 |
+
name = str(name or "").strip()
|
| 270 |
+
if len(name) >= 3:
|
| 271 |
+
return name[0] + "โ" + name[2:]
|
| 272 |
+
if len(name) == 2:
|
| 273 |
+
return name[0] + "โ"
|
| 274 |
+
return name
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
init_db()
|
| 278 |
+
|
| 279 |
+
|
| 280 |
+
# -----------------------------
|
| 281 |
+
# ์ฌ๋ก ์ ํ
|
| 282 |
+
# -----------------------------
|
| 283 |
+
CASE_TYPES = {
|
| 284 |
+
"๋์ ๊ณ ์ํ ๊ด๋ฆฌ": {
|
| 285 |
+
"reason": "์ด๋ ์ค ๋ถ์์ , ํ์ฅ์ค ์ด๋ ์ํ, ๋ณดํ๋ณด์กฐ ํ์ ๋ฑ ๋์ ์ํ์์ธ์ด ํ์ธ๋์ด ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 286 |
+
"goal": "๋์ ์ฌ๊ณ ๋ฅผ ์๋ฐฉํ๊ณ ์์ ํ ์ด๋๊ณผ ์ํํ๊ฒฝ์ ์ ์งํ๋ค.",
|
| 287 |
+
"keywords": ["๋์์๋ฐฉ", "์ด๋๋ณด์กฐ", "ํ๊ฒฝ์ ๋น", "ํ์ฅ์ค ๋ํ", "๋ณดํ์ํ ๊ด์ฐฐ"],
|
| 288 |
+
},
|
| 289 |
+
"์์ฌ๋ ๊ฐ์ยท์์๊ด๋ฆฌ": {
|
| 290 |
+
"reason": "์์ฌ๋ ๊ฐ์, ์๋ถ์ญ์ทจ ๋ถ์กฑ, ์ฒด์ค์ ํ ์ฐ๋ ค๊ฐ ํ์ธ๋์ด ์์์ํ ๊ด๋ฆฌ๋ฅผ ์ํ ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 291 |
+
"goal": "์์ฌ๋๊ณผ ์๋ถ์ญ์ทจ๋ฅผ ์์ ์ ์ผ๋ก ์ ์งํ๊ณ ์์ ์ ํ ์ํ์ ์๋ฐฉํ๋ค.",
|
| 292 |
+
"keywords": ["์์ฌ๋ณด์กฐ", "์๋ถ์ญ์ทจ", "์ ํธ์์", "์ฐํ์ํ", "์ญ์ทจ๋ ๊ธฐ๋ก"],
|
| 293 |
+
},
|
| 294 |
+
"์ธ์ง์ ํยท์ ์๋ถ์": {
|
| 295 |
+
"reason": "๋ฐ๋ณต์ง๋ฌธ, ์์ฌํํ, ๋ถ์๊ฐ, ์ ์์ ์์ถ ๋ฑ ์ธ์งยท์ ์ ๋ณํ๊ฐ ํ์ธ๋์ด ์ง์ ๊ด์ฐฐ๊ณผ ๊ฐ๋ณ ๋์์ด ํ์ํจ.",
|
| 296 |
+
"goal": "๋ถ์๊ฐ์ ์ํํ๊ณ ์์ ์ ์ธ ์ผ์์ํ๊ณผ ์๋น์ค ์ด์ฉ์ด ์ด๋ฃจ์ด์ง๋๋ก ์ง์ํ๋ค.",
|
| 297 |
+
"keywords": ["์ ์์ง์", "์ธ์งํ๋", "๋ฐ๋ณต์ค๋ช
", "์์ ์ ํ๊ฒฝ", "๋ณดํธ์ ์๋ด"],
|
| 298 |
+
},
|
| 299 |
+
"์์ฐฝยทํผ๋ถ์ํ ๊ด๋ฆฌ": {
|
| 300 |
+
"reason": "๊ธฐ์ ๊ท ์ฐฉ์ฉ, ํ๋๋ ์ ํ, ํผ๋ถ ๋ฐ์ ๋๋ ์์ฐฝ ์ํ์ด ํ์ธ๋์ด ํผ๋ถ์ํ ๊ด์ฐฐ๊ณผ ์๋ฐฉ๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 301 |
+
"goal": "ํผ๋ถ ์ฒญ๊ฒฐ๊ณผ ์์๋ฅผ ์ ์งํ๊ณ ์์ฐฝ ๋ฐ์์ ์๋ฐฉํ๋ค.",
|
| 302 |
+
"keywords": ["ํผ๋ถ๊ด์ฐฐ", "์ฒด์๋ณ๊ฒฝ", "๊ธฐ์ ๊ท์ผ์ด", "๋ณด์ต", "๊ฐํธ๊ด์ฐฐ"],
|
| 303 |
+
},
|
| 304 |
+
"ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ์ ํ": {
|
| 305 |
+
"reason": "ํ๋ก๊ทธ๋จ ์ฐธ์ฌ ๊ฐ์, ๋ฌด๊ธฐ๋ ฅ, ๋ํ ํํผ ๋ฑ ์ฌํ์ ยท์ ์์ ์์ถ์ด ๊ด์ฐฐ๋์ด ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 306 |
+
"goal": "์ ํธ ํ๋ ์ค์ฌ์ผ๋ก ์ฐธ์ฌ๋ฅผ ์ ๋ํ๊ณ ์ฌํ์ ๊ด๊ณ์ ํ๋ ฅ๏ฟฝ๏ฟฝ๏ฟฝ ๋์ธ๋ค.",
|
| 307 |
+
"keywords": ["์ ํธํ๋", "์ฐธ์ฌ๊ฒฉ๋ ค", "์ ์์ง์", "ํ๋ก๊ทธ๋จ ์กฐ์ ", "์ฐธ์ฌ๋ ๊ธฐ๋ก"],
|
| 308 |
+
},
|
| 309 |
+
"๋ณดํธ์ ์์ฒญยท์๋น์ค ์กฐ์ ": {
|
| 310 |
+
"reason": "๋ณดํธ์ ์์ฒญ ๋๋ ์๋น์ค ์กฐ์ ํ์์ฑ์ด ํ์ธ๋์ด ๊ธ์ฌ์ ๊ณต ๋ฐฉํฅ ์ฌ๊ฒํ ์ ์ฌ๋ก๊ด๋ฆฌ๊ฐ ํ์ํจ.",
|
| 311 |
+
"goal": "๋ณดํธ์ ์๊ฒฌ๊ณผ ์๊ธ์ ์ํ๋ฅผ ๋ฐ์ํ์ฌ ์ ์ ํ ์๋น์ค ์ ๊ณต ๋ฐฉํฅ์ ์กฐ์ ํ๋ค.",
|
| 312 |
+
"keywords": ["๋ณดํธ์ ์๋ด", "์๋น์ค ์กฐ์ ", "๊ธ์ฌ๊ณํ ๋ฐ์", "์ข
์ฌ์ ๊ณต์ ", "ํ์์๋ด"],
|
| 313 |
+
},
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
OPENERS = [
|
| 318 |
+
"ํ์ ์ฐธ์์๋ค์ ์ต๊ทผ ์๋ด๊ธฐ๋ก๊ณผ ์๊ตฌ์ฌ์ ๋ด์ฉ์ ํจ๊ป ๊ฒํ ํ์๋ค.",
|
| 319 |
+
"๋ณธ ์ฌ๋กํ์์์๋ ์๊ธ์์ ์ํ ๋ณํ, ๋ณดํธ์ ์๊ฒฌ, ๊ธ์ฌ์ ๊ณต ์ค ๊ด์ฐฐ์ฌํญ์ ์ข
ํฉํ์๋ค.",
|
| 320 |
+
"๊ธ์ผ ํ์์์๋ ๋จ์ ๋ฌธ์ ๊ธฐ๋ก์ด ์๋๋ผ ์ค์ ์๋น์ค ์ ๊ณต ๊ณผ์ ์ ๋ฐ์ํ ๊ฐ์
๋ฐฉํฅ์ ์ค์ฌ์ผ๋ก ๋
ผ์ํ์๋ค.",
|
| 321 |
+
"์๊ธ์์ ์๊ตฌ์ ๊ธฐ๊ด์์ ์ ๊ณต ๊ฐ๋ฅํ ์์์ ์ฐ๊ฒฐํ์ฌ ์ฌ๋ก๊ด๋ฆฌ ํ์์ฑ์ ๊ฒํ ํ์๋ค.",
|
| 322 |
+
]
|
| 323 |
+
|
| 324 |
+
TONES = [
|
| 325 |
+
"๊ฐ ์ง์ข
๋ณ ์ญํ ์ ๋ช
ํํ ํ์ฌ ๋์ผํ ๋ฐฉํฅ์ผ๋ก ์ง์ํ๊ธฐ๋ก ํ์๋ค.",
|
| 326 |
+
"์๋ด๊ธฐ๋ก, ์๊ตฌ์ฌ์ , ๊ธ์ฌ์ ๊ณต๊ธฐ๋ก์ด ์๋ก ์ฐ๊ฒฐ๋๋๋ก ๊ด๋ฆฌํ๊ธฐ๋ก ํ์๋ค.",
|
| 327 |
+
"๋ณดํธ์์๊ฒ๋ ์ฃผ์ ๋ณํ์ ๊ธฐ๊ด์ ์กฐ์น๊ณํ์ ์๋ดํ์ฌ ํ์กฐ๋ฅผ ๊ตฌํ๊ธฐ๋ก ํ์๋ค.",
|
| 328 |
+
"30์ผ ์ด์ ๊ด์ฐฐ ํ ๊ฒฐ๊ณผ๋ฅผ ๋ค์ ํ์ธํ๊ณ ํ์ ์ ๊ธ์ฌ์ ๊ณต๊ณํ์ ์กฐ์ ํ๊ธฐ๋ก ํ์๋ค.",
|
| 329 |
+
]
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
# -----------------------------
|
| 333 |
+
# ์์ฝ ์์ฑ
|
| 334 |
+
# -----------------------------
|
| 335 |
+
def summarize_counseling(df):
|
| 336 |
+
if df.empty:
|
| 337 |
+
return "์ ์ฅ๋ ์๋ด์ผ์ง๊ฐ ์์ด ์๊ธ์ ๊ธฐ๋ณธ์ ๋ณด์ ์ง์ ์
๋ ฅํ ์ํ๋ณํ๋ฅผ ์ค์ฌ์ผ๋ก ์ฌ๋ก๊ด๋ฆฌ ํ์๋ฅผ ์งํํจ."
|
| 338 |
+
lines = []
|
| 339 |
+
for _, r in df.head(5).iterrows():
|
| 340 |
+
lines.append(
|
| 341 |
+
f"- {safe(r,'counseling_date')}: {safe(r,'counseling_type')} / ์ฌ์ : {safe(r,'counseling_reason')} / "
|
| 342 |
+
f"์ํ๋ณํ: {safe(r,'client_status_change') or '๊ธฐ๋ก ์์'} / ๋ณดํธ์ ์๊ฒฌ: {safe(r,'guardian_opinion') or '๊ธฐ๋ก ์์'}"
|
| 343 |
+
)
|
| 344 |
+
return "\n".join(lines)
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def summarize_needs(df, client, manual_needs):
|
| 348 |
+
if not df.empty:
|
| 349 |
+
r = df.iloc[0]
|
| 350 |
+
return (
|
| 351 |
+
f"์ต๊ทผ ์๊ตฌ์ฌ์ ์ผ: {safe(r,'assessment_date')}\n"
|
| 352 |
+
f"์ข
ํฉ์๊ฒฌ: {safe(r,'total_opinion')}\n"
|
| 353 |
+
f"๊ฒฐ๊ณผ/๊ณํ: {safe(r,'result_plan')}\n"
|
| 354 |
+
f"์ํ์์ธ: ๋์ {safe(r,'fall_risk')}, ์์ฐฝ {safe(r,'bedsore_risk')}, ์ธ์ง {safe(r,'dementia_status')}, ๊ธฐ์ ๊ท {safe(r,'diaper_use')}\n"
|
| 355 |
+
f"์๋น์ค ์๊ตฌ: {safe(r,'service_needs')}"
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
base = (
|
| 359 |
+
f"Client Center ๋ฑ๋ก์ ๋ณด ๊ธฐ์ค ์ฃผ์์ํ: {safe(client,'main_condition') or '๊ธฐ๋ก ์์'}, "
|
| 360 |
+
f"์ธ์ง์ํ: {safe(client,'cognitive_status') or '๊ธฐ๋ก ์์'}, "
|
| 361 |
+
f"์ด๋์ํ: {safe(client,'mobility_status') or '๊ธฐ๋ก ์์'}, "
|
| 362 |
+
f"์์ฌ์ํ: {safe(client,'diet_status') or '๊ธฐ๋ก ์์'}, "
|
| 363 |
+
f"๋ฐฐ๋ณ/๋ฐฐ๋จ์ํ: {safe(client,'toileting_status') or '๊ธฐ๋ก ์์'}"
|
| 364 |
+
)
|
| 365 |
+
if manual_needs.strip():
|
| 366 |
+
base += "\n์ง์ ์
๋ ฅ ์๊ตฌ์ฌ์ ์์ฝ: " + manual_needs.strip()
|
| 367 |
+
return base
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
def build_role_text(case_type, custom_roles=""):
|
| 371 |
+
keywords = ", ".join(CASE_TYPES[case_type]["keywords"])
|
| 372 |
+
default = f"""
|
| 373 |
+
์์ค์ฅ: ์ฌ๋ก๊ด๋ฆฌ ๋์ ์ ์ ์ ์ ์ ์ฑ์ ํ์ธํ๊ณ , ๋ฏผ์ยท์์ ยท๊ธ์ฌ์ ๊ณต ๋ฐ์ ์ฌ๋ถ๋ฅผ ์ด๊ด ์ ๊ฒํ๋ค.
|
| 374 |
+
์ฌํ๋ณต์ง์ฌ: ์๋ด๊ธฐ๋ก๊ณผ ์๊ตฌ์ฌ์ ๋ด์ฉ์ ๋ถ์ํ์ฌ ์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ์ ๊ณํ์ ์๋ฆฝํ๊ณ ๋ณดํธ์ ์๋ด ๋ฐ ๊ธ์ฌ์ ๊ณต๊ณํ ๋ฐ์์ ๋ด๋นํ๋ค.
|
| 375 |
+
์์๋ณดํธ์ฌ: ์ผ์ ์๋น์ค ์ ๊ณต ๊ณผ์ ์์ {keywords} ๊ด๋ จ ๊ด์ฐฐ์ฌํญ์ ๊ตฌ์ฒด์ ์ผ๋ก ๊ธฐ๋กํ๊ณ ์ฆ์ ๊ณต์ ํ๋ค.
|
| 376 |
+
๊ฐํธ์กฐ๋ฌด์ฌ: ๊ฑด๊ฐ์ํ, ํ๋ ฅ์งํ, ํผ๋ถ์ํ, ๋ณต์ฝ ๋ฐ ์ด์์งํ๋ฅผ ๊ด์ฐฐํ๊ณ ํ์ ์ ์๋ฃ์ฐ๊ณ ํ์์ฑ์ ๋ณด๊ณ ํ๋ค.
|
| 377 |
+
๋ฌผ๋ฆฌ์น๋ฃ์ฌ: ์ด๋, ์์ธ์ ์ง, ๋ณดํ, ๊ด์ ๊ตฌ์ถ ์๋ฐฉ๊ณผ ๊ด๋ จ๋ ์ ์ฒด๊ธฐ๋ฅ ์ง์ ๋ฐฉํฅ์ ์๋ฌธํ๋ค.
|
| 378 |
+
""".strip()
|
| 379 |
+
return custom_roles.strip() or default
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def build_attendees_text(director, social_worker, caregiver, nurse, therapist, guardian, extra_attendees):
|
| 383 |
+
attendees = []
|
| 384 |
+
if director.strip():
|
| 385 |
+
attendees.append(f"์์ค์ฅ: {director.strip()}")
|
| 386 |
+
else:
|
| 387 |
+
attendees.append("์์ค์ฅ: ์ฐธ์ ๋๋ ๊ฒํ ")
|
| 388 |
+
if social_worker.strip():
|
| 389 |
+
attendees.append(f"์ฌํ๋ณต์ง์ฌ: {social_worker.strip()}")
|
| 390 |
+
else:
|
| 391 |
+
attendees.append("์ฌํ๋ณต์ง์ฌ: ์ฐธ์")
|
| 392 |
+
if caregiver.strip():
|
| 393 |
+
attendees.append(f"์์๋ณดํธ์ฌ: {caregiver.strip()}")
|
| 394 |
+
else:
|
| 395 |
+
attendees.append("์์๋ณดํธ์ฌ: ์ฐธ์")
|
| 396 |
+
if nurse.strip():
|
| 397 |
+
attendees.append(f"๊ฐํธ์กฐ๋ฌด์ฌ: {nurse.strip()}")
|
| 398 |
+
else:
|
| 399 |
+
attendees.append("๊ฐํธ์กฐ๋ฌด์ฌ: ์ฐธ์")
|
| 400 |
+
if therapist.strip():
|
| 401 |
+
attendees.append(f"๋ฌผ๋ฆฌ์น๋ฃ์ฌ: {therapist.strip()}")
|
| 402 |
+
else:
|
| 403 |
+
attendees.append("๋ฌผ๋ฆฌ์น๋ฃ์ฌ: ํด๋น ์ ์๋ฌธ")
|
| 404 |
+
if guardian.strip():
|
| 405 |
+
attendees.append(f"๋ณดํธ์: {guardian.strip()}")
|
| 406 |
+
if extra_attendees.strip():
|
| 407 |
+
attendees.append(f"๊ธฐํ ์ฐธ์์: {extra_attendees.strip()}")
|
| 408 |
+
return "\n".join(attendees)
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def build_case_documents(client, counseling_summary, needs_summary, case_type, custom_selection, custom_status, custom_goal, custom_roles):
|
| 412 |
+
case = CASE_TYPES[case_type]
|
| 413 |
+
opener = random.choice(OPENERS)
|
| 414 |
+
tone = random.choice(TONES)
|
| 415 |
+
masked = safe(client, "masked_name", "์๊ธ์")
|
| 416 |
+
grade = safe(client, "care_grade")
|
| 417 |
+
institution_type = safe(client, "institution_type")
|
| 418 |
+
keywords = ", ".join(case["keywords"])
|
| 419 |
+
|
| 420 |
+
selection = custom_selection.strip() or (
|
| 421 |
+
f"{masked} ์๊ธ์๋ {grade} ๋์์๋ก {case['reason']} "
|
| 422 |
+
f"์๋ด๊ธฐ๋ก๊ณผ ์๊ตฌ์ฌ์ ์์ ํ์ธ๋ ์ํ๋ฅผ ์ข
ํฉํ ๋ {case_type} ์ฌ๋ก๊ด๋ฆฌ ๋์์ผ๋ก ์ ์ ํจ."
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
first_content = f"""
|
| 426 |
+
{opener}
|
| 427 |
+
|
| 428 |
+
[์๊ธ์ ๊ธฐ๋ณธ์ํ]
|
| 429 |
+
- ๊ธฐ๊ด์ ํ: {institution_type}
|
| 430 |
+
- ์ฅ๊ธฐ์์๋ฑ๊ธ: {grade}
|
| 431 |
+
- ์ฃผ์ ์งํ/์ํ: {safe(client,'main_condition') or '๊ธฐ๋ก ์์'}
|
| 432 |
+
- ์ธ์ง์ํ: {safe(client,'cognitive_status') or '๊ธฐ๋ก ์์'}
|
| 433 |
+
- ์ด๋์ํ: {safe(client,'mobility_status') or '๊ธฐ๋ก ์์'}
|
| 434 |
+
- ์์ฌ์ํ: {safe(client,'diet_status') or '๊ธฐ๋ก ์์'}
|
| 435 |
+
- ๋ฐฐ๋ณ/๋ฐฐ๋จ์ํ: {safe(client,'toileting_status') or '๊ธฐ๋ก ์์'}
|
| 436 |
+
|
| 437 |
+
[์๋ด์ผ์ง ์ฐ๋ ์์ฝ]
|
| 438 |
+
{counseling_summary}
|
| 439 |
+
|
| 440 |
+
[์๊ตฌ์ฌ์ ์ฐ๋ ์์ฝ]
|
| 441 |
+
{needs_summary}
|
| 442 |
+
|
| 443 |
+
[์ถ๊ฐ ์ํ๋ณํ]
|
| 444 |
+
{custom_status or '์ถ๊ฐ๋ก ์
๋ ฅ๋ ์ํ๋ณํ๋ ์์ผ๋, ๊ธฐ์กด ๊ธฐ๋ก์ ๋ฐํ์ผ๋ก ์ง์ ๊ด์ฐฐ์ด ํ์ํจ.'}
|
| 445 |
+
|
| 446 |
+
ํ์ ๊ฒฐ๊ณผ {case_type}๊ณผ ๊ด๋ จํ์ฌ {keywords} ํญ๋ชฉ์ ์ค์ฌ์ผ๋ก ๊ฐ์
ํ๊ธฐ๋ก ํ์์ผ๋ฉฐ, {tone}
|
| 447 |
+
""".strip()
|
| 448 |
+
|
| 449 |
+
goal = custom_goal.strip() or case["goal"]
|
| 450 |
+
|
| 451 |
+
plan = f"""
|
| 452 |
+
[1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ]
|
| 453 |
+
{goal}
|
| 454 |
+
|
| 455 |
+
[1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๊ณํ]
|
| 456 |
+
1. ์๋ด์ผ์ง์ ์๊ตฌ์ฌ์ ์์ ํ์ธ๋ ์ํ์์ธ ๋ฐ ์๊ตฌ๋ฅผ ๊ธ์ฌ์ ๊ณต๊ณํ์ ๋ฐ์ํ๋ค.
|
| 457 |
+
2. {keywords} ๊ด๋ จ ๊ด์ฐฐ ํญ๋ชฉ์ ๊ธ์ฌ์ ๊ณต๊ธฐ๋ก์ง์ ๊ตฌ์ฒด์ ์ผ๋ก ๋จ๊ธด๋ค.
|
| 458 |
+
3. ๋ณดํธ์ ์๊ฒฌ ๋๋ ์ํ๋ณํ๊ฐ ํ์ธ๋ ๊ฒฝ์ฐ ์ฆ์ ์ฌํ๋ณต์ง์ฌ์๊ฒ ๊ณต์ ํ๋ค.
|
| 459 |
+
4. ์์ค์ฅ ํ์ธ ํ์ 30์ผ ์ด์ ์ํ๊ณผ์ ์ ์ ๊ฒํ๊ณ 2์ฐจ ๊ฒฐ๊ณผํ์์์ ํจ๊ณผ์ฑ์ ํ๊ฐํ๋ค.
|
| 460 |
+
5. ํ์ ์ ์ถ๊ฐ ์๋ด, ์๊ตฌ์ฌ์ ์ฌ์ ๊ฒ, ๊ธ์ฌ์ ๊ณต๊ณํ ๋ณ๊ฒฝ์ผ๋ก ์ฐ๊ณํ๋ค.
|
| 461 |
+
""".strip()
|
| 462 |
+
|
| 463 |
+
role_division = build_role_text(case_type, custom_roles)
|
| 464 |
+
|
| 465 |
+
implementation = f"""
|
| 466 |
+
[์ญํ ๋ถ๋ด์ ๋ฐ๋ฅธ ์ํ๊ณผ์ ]
|
| 467 |
+
- ์์ค์ฅ: ์ฌ๋ก๊ด๋ฆฌ ์งํ์ํฉ๊ณผ ๊ธฐ๋ก ์ ์ ์ฑ์ ํ์ธํ๊ณ , ๊ธ์ฌ์ ๊ณต๊ณํ ๋ฐ์ ์ฌ๋ถ๋ฅผ ์ ๊ฒํ์๋ค.
|
| 468 |
+
- ์ฌํ๋ณต์ง์ฌ: ์๋ด์ผ์ง์ ์๊ตฌ์ฌ์ ๋ด์ฉ์ ํตํฉ ๊ฒํ ํ์ฌ ๋ณดํธ์ ์๊ฒฌ, ์ํ๋ณํ, ์๋น์ค ์กฐ์ ํ์์ฑ์ ๊ธ์ฌ์ ๊ณต๊ณํ์ ์ฐ๊ฒฐํ์๋ค.
|
| 469 |
+
- ์์๋ณดํธ์ฌ: ์ค์ ๊ธ์ฌ์ ๊ณต ๊ณผ์ ์์ {keywords} ๊ด๋ จ ๊ด์ฐฐ์ฌํญ์ ํ์ธํ๊ณ ์ผ์๊ธฐ๋ก์ ๋ฐ์ํ์๋ค.
|
| 470 |
+
- ๊ฐํธ์กฐ๋ฌด์ฌ: ๊ฑด๊ฐ์ํ, ํผ๋ถ์ํ, ์์ฌยท์๋ถ์ญ์ทจ, ํ๋ ฅ์ํ ๋ฑ ์ํ์์ธ์ ํ์ธํ๊ณ ์ด์์งํ ๋ฐ์ ์ฌ๋ถ๋ฅผ ๊ด์ฐฐํ์๋ค.
|
| 471 |
+
- ๋ฌผ๋ฆฌ์น๋ฃ์ฌ: ์ด๋, ์์ธ, ๊ด์ ๊ตฌ์ถ ์๋ฐฉ, ์ ์ฒดํ๋ ์ง์ ํ์์ฑ์ ๊ฒํ ํ๊ณ ํ์ฅ ์ ์ฉ ๊ฐ๋ฅํ ์ง์ ๋ฐฉํฅ์ ์ ์ํ์๋ค.
|
| 472 |
+
|
| 473 |
+
[๊ณผ์ ์ ๊ฒ]
|
| 474 |
+
์๋ด๊ธฐ๋ก๊ณผ ์๊ตฌ์ฌ์ ์์ ํ์ธ๋ ๋ด์ฉ์ด ์ค์ ์๋น์ค ์ ๊ณต ๊ณผ์ ์์ ๋๋ฝ๋์ง ์๋๋ก ์ข
์ฌ์ ๊ฐ ๊ณต์ ํ์์ผ๋ฉฐ, ์๊ธ์์ ๋ฐ์๊ณผ ๋ณดํธ์ ์๊ฒฌ์ ์ง์ ํ์ธํ์๋ค.
|
| 475 |
+
""".strip()
|
| 476 |
+
|
| 477 |
+
second_result = f"""
|
| 478 |
+
[2์ฐจ ๊ฒฐ๊ณผํ์ ๋ด์ฉ]
|
| 479 |
+
30์ผ ์ด์ ์ํ๊ณผ์ ์ ํ์ธํ ๊ฒฐ๊ณผ, {case_type} ๊ด๋ จ ์ํ์์ธ๊ณผ ์๊ตฌ์ ๋ํด ์ญํ ๋ณ ์ง์์ด ์ด๋ฃจ์ด์ก๋์ง ์ ๊ฒํ์๋ค.
|
| 480 |
+
|
| 481 |
+
[๊ฒฐ๊ณผํ๊ฐ]
|
| 482 |
+
- ์๊ธ์ ์ํ๋ณํ: ์๋ด๊ธฐ๋ก ๋ฐ ๊ด์ฐฐ๊ธฐ๋ก์ ํตํด ๋ณํ ์ฌ๋ถ๋ฅผ ํ์ธํจ.
|
| 483 |
+
- ๋ณดํธ์ ์๊ฒฌ ๋ฐ์: ๋ณดํธ์ ์๊ฒฌ์ด ์๋ ๊ฒฝ์ฐ ๊ธ์ฌ์ ๊ณต ๋ฐฉํฅ๊ณผ ํ์์กฐ์น์ ๋ฐ์ํจ.
|
| 484 |
+
- ๊ธ์ฌ์ ๊ณต ๋ฐ์: 1์ฐจ ๊ณํ์์ ์ ํ {keywords} ํญ๋ชฉ์ ๊ธ์ฌ์ ๊ณต๊ธฐ๋ก๊ณผ ์๋น์ค ์ ๊ณต ๊ณผ์ ์ ๋ฐ์ํจ.
|
| 485 |
+
- ํฅํ๊ณํ: ํ์ฌ ๊ณํ์ ์ ์งํ๋, ์ํ ์
ํ๋ ์๋ก์ด ์๊ตฌ ๋ฐ์ ์ ์๊ตฌ์ฌ์ ์ฌ์ ๊ฒ ๋ฐ ๊ธ์ฌ์ ๊ณต๊ณํ ๋ณ๊ฒฝ์ ๊ฒํ ํจ.
|
| 486 |
+
""".strip()
|
| 487 |
+
|
| 488 |
+
return selection, first_content, goal, plan, role_division, implementation, second_result
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
def evaluate_case(selection, first_content, plan, role_division, implementation, second_result, counseling_summary, needs_summary):
|
| 492 |
+
required = {
|
| 493 |
+
"์ ์ ์ฌ์ ": bool(selection.strip()),
|
| 494 |
+
"์๋ด์ผ์ง ์ฐ๋": "์๋ด" in counseling_summary and "์ ์ฅ๋ ์๋ด์ผ์ง ์์ด" not in counseling_summary,
|
| 495 |
+
"์๊ตฌ์ฌ์ ์ฐ๋": bool(needs_summary.strip()),
|
| 496 |
+
"1์ฐจ ๊ณํ": bool(plan.strip()) and "๋ชฉํ" in plan,
|
| 497 |
+
"์ญํ ๋ถ๋ด": all(word in role_division for word in ["์์ค์ฅ", "์ฌํ๋ณต์ง์ฌ", "์์๋ณดํธ์ฌ", "๊ฐํธ์กฐ๋ฌด์ฌ", "๋ฌผ๋ฆฌ์น๋ฃ์ฌ"]),
|
| 498 |
+
"์ํ๊ณผ์ ": bool(implementation.strip()) and "์ํ๊ณผ์ " in implementation,
|
| 499 |
+
"2์ฐจ ๊ฒฐ๊ณผํ์": bool(second_result.strip()) and "๊ฒฐ๊ณผ" in second_result,
|
| 500 |
+
"๋ณดํธ์ ์๊ฒฌ/์ํ๋ณํ": ("๋ณดํธ์" in first_content or "๋ณดํธ์" in second_result) and ("์ํ๋ณํ" in first_content or "๋ณํ" in second_result),
|
| 501 |
+
"๊ธ์ฌ์ ๊ณต ๋ฐ์": "๊ธ์ฌ์ ๊ณต" in plan and "๊ธ์ฌ์ ๊ณต" in second_result,
|
| 502 |
+
}
|
| 503 |
+
score = int(sum(required.values()) / len(required) * 100)
|
| 504 |
+
missing = [k for k, v in required.items() if not v]
|
| 505 |
+
if score >= 90:
|
| 506 |
+
result = "ํ๊ฐ ์ ํฉ๋๊ฐ ๋์ต๋๋ค. ์ฌ๋ก์ ์ , 1์ฐจ ๊ณํ, ์ญํ ๋ถ๋ด, ์ํ๊ณผ์ , 2์ฐจ ๊ฒฐ๊ณผํ๊ฐ๊ฐ ์ฐ๊ฒฐ๋์ด ์์ต๋๋ค."
|
| 507 |
+
elif score >= 75:
|
| 508 |
+
result = "๋์ฒด๋ก ์ ํฉํ๋ ์ผ๋ถ ๋ณด์์ด ํ์ํฉ๋๋ค. ๋ถ์กฑ ํญ๋ชฉ์ ์ถ๊ฐํ๋ฉด ํ๊ฐ ๋์๋ ฅ์ด ๋์์ง๋๋ค."
|
| 509 |
+
else:
|
| 510 |
+
result = "๋ณด์์ด ํ์ํฉ๋๋ค. ์๋ด์ผ์ง, ์๊ตฌ์ฌ์ , ์ญํ ๋ณ ์ํ๊ณผ์ , 2์ฐจ ๊ฒฐ๊ณผํ๊ฐ๊ฐ ๋ ๊ตฌ์ฒด์ ์ผ๋ก ์ฐ๊ฒฐ๋์ด์ผ ํฉ๋๋ค."
|
| 511 |
+
return score, missing, result
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
# -----------------------------
|
| 515 |
+
# ์์
ํจ์
|
| 516 |
+
# -----------------------------
|
| 517 |
+
def set_cell(ws, cell, value, bold=False, size=11, fill=None, align="center"):
|
| 518 |
+
ws[cell] = value
|
| 519 |
+
ws[cell].font = Font(name="Malgun Gothic", size=size, bold=bold)
|
| 520 |
+
ws[cell].alignment = Alignment(horizontal=align, vertical="center", wrap_text=True)
|
| 521 |
+
if fill:
|
| 522 |
+
ws[cell].fill = fill
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
def style_ws(ws, max_row):
|
| 526 |
+
thin = Side(style="thin", color="777777")
|
| 527 |
+
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
| 528 |
+
for row in ws.iter_rows(min_row=1, max_row=max_row, min_col=1, max_col=9):
|
| 529 |
+
for cell in row:
|
| 530 |
+
if cell.value is not None:
|
| 531 |
+
cell.border = border
|
| 532 |
+
if cell.font.name != "Malgun Gothic":
|
| 533 |
+
cell.font = Font(name="Malgun Gothic", size=11, bold=cell.font.bold)
|
| 534 |
+
ws.page_setup.paperSize = ws.PAPERSIZE_A4
|
| 535 |
+
ws.page_setup.orientation = "portrait"
|
| 536 |
+
ws.page_setup.fitToWidth = 1
|
| 537 |
+
ws.page_setup.fitToHeight = 0
|
| 538 |
+
ws.sheet_properties.pageSetUpPr.fitToPage = True
|
| 539 |
+
ws.page_margins.left = 0.3
|
| 540 |
+
ws.page_margins.right = 0.3
|
| 541 |
+
ws.page_margins.top = 0.4
|
| 542 |
+
ws.page_margins.bottom = 0.4
|
| 543 |
+
ws.sheet_view.showGridLines = False
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
def write_title_with_approval(ws, title, title_fill, header_fill):
|
| 547 |
+
for col in range(1, 10):
|
| 548 |
+
ws.column_dimensions[get_column_letter(col)].width = 15
|
| 549 |
+
|
| 550 |
+
ws.merge_cells(start_row=1, start_column=1, end_row=2, end_column=7)
|
| 551 |
+
ws.cell(1, 1).value = title
|
| 552 |
+
ws.cell(1, 1).font = Font(name="Malgun Gothic", size=24, bold=True)
|
| 553 |
+
ws.cell(1, 1).alignment = Alignment(horizontal="center", vertical="center")
|
| 554 |
+
ws.cell(1, 1).fill = title_fill
|
| 555 |
+
|
| 556 |
+
# ๊ฒฐ์ฌ๋ผ์ธ: H:I ๋ ์นธ๋ง ์ฌ์ฉ, ์ง์ ๋ถํ G์ด/๋น์นธ ์์
|
| 557 |
+
ws.cell(1, 8).value = "๋ด๋น์"
|
| 558 |
+
ws.cell(1, 9).value = "์์ค์ฅ"
|
| 559 |
+
ws.cell(2, 8).value = ""
|
| 560 |
+
ws.cell(2, 9).value = ""
|
| 561 |
+
for rr in [1, 2]:
|
| 562 |
+
for cc in [8, 9]:
|
| 563 |
+
cell = ws.cell(rr, cc)
|
| 564 |
+
cell.font = Font(name="Malgun Gothic", size=11, bold=True if rr == 1 else False)
|
| 565 |
+
cell.alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 566 |
+
if rr == 1:
|
| 567 |
+
cell.fill = header_fill
|
| 568 |
+
ws.row_dimensions[1].height = 28
|
| 569 |
+
ws.row_dimensions[2].height = 42
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
def write_info_row(ws, row, a, b, c, d, e, f, header_fill):
|
| 573 |
+
ws.cell(row, 1).value = a
|
| 574 |
+
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=3)
|
| 575 |
+
ws.cell(row, 2).value = b
|
| 576 |
+
ws.cell(row, 4).value = c
|
| 577 |
+
ws.merge_cells(start_row=row, start_column=5, end_row=row, end_column=6)
|
| 578 |
+
ws.cell(row, 5).value = d
|
| 579 |
+
ws.cell(row, 7).value = e
|
| 580 |
+
ws.merge_cells(start_row=row, start_column=8, end_row=row, end_column=9)
|
| 581 |
+
ws.cell(row, 8).value = f
|
| 582 |
+
|
| 583 |
+
for col in [1, 4, 7]:
|
| 584 |
+
ws.cell(row, col).fill = header_fill
|
| 585 |
+
ws.cell(row, col).font = Font(name="Malgun Gothic", size=11, bold=True)
|
| 586 |
+
ws.cell(row, col).alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 587 |
+
for col in [2, 5, 8]:
|
| 588 |
+
ws.cell(row, col).alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 589 |
+
ws.row_dimensions[row].height = 30
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
def write_section(ws, row, title, content, header_fill, height=90):
|
| 593 |
+
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=9)
|
| 594 |
+
ws.cell(row, 1).value = title
|
| 595 |
+
ws.cell(row, 1).font = Font(name="Malgun Gothic", size=15, bold=True)
|
| 596 |
+
ws.cell(row, 1).alignment = Alignment(horizontal="center", vertical="center")
|
| 597 |
+
ws.cell(row, 1).fill = header_fill
|
| 598 |
+
ws.row_dimensions[row].height = 30
|
| 599 |
+
row += 1
|
| 600 |
+
|
| 601 |
+
ws.merge_cells(start_row=row, start_column=1, end_row=row, end_column=9)
|
| 602 |
+
ws.cell(row, 1).value = content
|
| 603 |
+
ws.cell(row, 1).font = Font(name="Malgun Gothic", size=11)
|
| 604 |
+
ws.cell(row, 1).alignment = Alignment(horizontal="left", vertical="top", wrap_text=True)
|
| 605 |
+
lines = len(str(content)) // 60 + 1 + str(content).count("\n")
|
| 606 |
+
ws.row_dimensions[row].height = max(height, lines * 18)
|
| 607 |
+
return row + 1
|
| 608 |
+
|
| 609 |
+
|
| 610 |
+
def generate_excel(data):
|
| 611 |
+
wb = Workbook()
|
| 612 |
+
title_fill = PatternFill("solid", fgColor="EDE9FE")
|
| 613 |
+
header_fill = PatternFill("solid", fgColor="F3F4F6")
|
| 614 |
+
|
| 615 |
+
ws1 = wb.active
|
| 616 |
+
ws1.title = "1์ฐจ๊ณํํ์๋ก"
|
| 617 |
+
write_title_with_approval(ws1, "์ฌ๋ก๊ด๋ฆฌ 1์ฐจ ๊ณํํ์๋ก", title_fill, header_fill)
|
| 618 |
+
|
| 619 |
+
r = 3
|
| 620 |
+
write_info_row(ws1, r, "๊ธฐ๊ด๋ช
", data["institution_name"], "๊ธฐ๊ด์ ํ", data["institution_type"], "ํ์์ผ์", data["first_meeting_date"], header_fill); r += 1
|
| 621 |
+
write_info_row(ws1, r, "์๊ธ์", data["client_masked_name"], "์ฅ๊ธฐ์์๋ฑ๊ธ", data["grade"], "์ฌ๋ก์ ํ", data["case_type"], header_fill); r += 1
|
| 622 |
+
write_info_row(ws1, r, "ํ์์ฅ์", data["meeting_place"], "์์ฑ์", data["writer"], "2์ฐจ์์ ์ผ", data["second_meeting_date"], header_fill); r += 1
|
| 623 |
+
r = write_section(ws1, r, "์ ์ ์ฌ์ ", data["selection_reason"], header_fill, 80)
|
| 624 |
+
r = write_section(ws1, r, "์๋ด์ผ์ง ์ฐ๋ ์์ฝ", data["counseling_summary"], header_fill, 90)
|
| 625 |
+
r = write_section(ws1, r, "์๊ตฌ์ฌ์ ์ฐ๋ ์์ฝ", data["needs_summary"], header_fill, 90)
|
| 626 |
+
r = write_section(ws1, r, "1์ฐจ ํ์๋ด์ฉ", data["first_content"], header_fill, 150)
|
| 627 |
+
r = write_section(ws1, r, "1์ฐจ ์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ ๋ฐ ๊ณํ", f"[๋ชฉํ]\n{data['goal']}\n\n[๊ณํ]\n{data['first_plan']}", header_fill, 140)
|
| 628 |
+
r = write_section(ws1, r, "์ญํ ๋ถ๋ด", data["role_division"], header_fill, 130)
|
| 629 |
+
r = write_section(ws1, r, "์ฐธ์์ ๋ช
๋จ", data.get("attendees_text", "์์ค์ฅ, ์ฌํ๋ณต์ง์ฌ, ์์๋ณดํธ์ฌ, ๊ฐํธ์กฐ๋ฌด์ฌ ์ฐธ์"), header_fill, 90)
|
| 630 |
+
r = write_section(ws1, r, "ํ๊ฐ ์ ํฉ๋ ์ ๊ฒ", f"{data['evaluation_score']}์ \n๋ถ์กฑ ํญ๋ชฉ: {data['missing_items']}\n{data['compliance_result']}", header_fill, 80)
|
| 631 |
+
|
| 632 |
+
# ์ฌ์ง์ฒจ๋ถ: ์
๋ก๋๋ ์ฌ์ง์ด ์์ ๋๋ง ๊น๋ํ๊ฒ ์ฝ์
|
| 633 |
+
if data.get("photo_paths"):
|
| 634 |
+
ws1.merge_cells(start_row=r, start_column=1, end_row=r, end_column=9)
|
| 635 |
+
ws1.cell(r, 1).value = "์ฌ์ง์ฒจ๋ถ"
|
| 636 |
+
ws1.cell(r, 1).font = Font(name="Malgun Gothic", size=15, bold=True)
|
| 637 |
+
ws1.cell(r, 1).alignment = Alignment(horizontal="center", vertical="center")
|
| 638 |
+
ws1.cell(r, 1).fill = header_fill
|
| 639 |
+
r += 1
|
| 640 |
+
|
| 641 |
+
img_row = r
|
| 642 |
+
anchors = ["A", "D", "G"]
|
| 643 |
+
for idx, photo_path in enumerate(data.get("photo_paths", [])[:3]):
|
| 644 |
+
try:
|
| 645 |
+
img = XLImage(photo_path)
|
| 646 |
+
img.width = 210
|
| 647 |
+
img.height = 150
|
| 648 |
+
ws1.add_image(img, f"{anchors[idx]}{img_row}")
|
| 649 |
+
except Exception:
|
| 650 |
+
pass
|
| 651 |
+
for rr in range(img_row, img_row + 8):
|
| 652 |
+
ws1.row_dimensions[rr].height = 22
|
| 653 |
+
r = img_row + 8
|
| 654 |
+
|
| 655 |
+
style_ws(ws1, r)
|
| 656 |
+
|
| 657 |
+
ws2 = wb.create_sheet("2์ฐจ๊ฒฐ๊ณผํ์๋ก")
|
| 658 |
+
write_title_with_approval(ws2, "์ฌ๋ก๊ด๋ฆฌ 2์ฐจ ๊ฒฐ๊ณผํ์๋ก", title_fill, header_fill)
|
| 659 |
+
|
| 660 |
+
r = 3
|
| 661 |
+
write_info_row(ws2, r, "์๊ธ์", data["client_masked_name"], "1์ฐจํ์์ผ", data["first_meeting_date"], "2์ฐจํ์์ผ", data["second_meeting_date"], header_fill); r += 1
|
| 662 |
+
write_info_row(ws2, r, "๊ด์ฐฐ๊ธฐ๊ฐ", data["observation_period"], "ํ๊ฐ๊ฒฐ๊ณผ", data["result_level"], "์์ฑ์", data["writer"], header_fill); r += 1
|
| 663 |
+
r = write_section(ws2, r, "์ฐธ์์ ๋ช
๋จ", data.get("attendees_text", "์์ค์ฅ, ์ฌํ๋ณต์ง์ฌ, ์์๋ณดํธ์ฌ, ๊ฐํธ์กฐ๋ฌด์ฌ ์ฐธ์"), header_fill, 90)
|
| 664 |
+
r = write_section(ws2, r, "์ญํ ๋ถ๋ด์ ๋ฐ๋ฅธ ์ํ๊ณผ์ ", data["implementation_process"], header_fill, 170)
|
| 665 |
+
r = write_section(ws2, r, "2์ฐจ ๊ฒฐ๊ณผํ์๋ก", data["second_result"], header_fill, 160)
|
| 666 |
+
r = write_section(ws2, r, "ํฅํ ๊ธ์ฌ์ ๊ณต ๋ฐ์๊ณํ", data["next_plan"], header_fill, 110)
|
| 667 |
+
r = write_section(ws2, r, "ํ๊ฐ ์ ํฉ๋ ์ ๊ฒ", f"{data['evaluation_score']}์ \n๋ถ์กฑ ํญ๋ชฉ: {data['missing_items']}\n{data['compliance_result']}", header_fill, 80)
|
| 668 |
+
style_ws(ws2, r)
|
| 669 |
+
|
| 670 |
+
output = BytesIO()
|
| 671 |
+
wb.save(output)
|
| 672 |
+
output.seek(0)
|
| 673 |
+
return output
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
# -----------------------------
|
| 677 |
+
# ํ๋ฉด
|
| 678 |
+
# -----------------------------
|
| 679 |
+
st.sidebar.success("DB ์ฐ๊ฒฐ")
|
| 680 |
+
st.sidebar.caption(DB_PATH)
|
| 681 |
+
|
| 682 |
+
clients_df = load_clients()
|
| 683 |
+
if clients_df.empty:
|
| 684 |
+
st.warning("Client Center ์๊ธ์ DB๊ฐ ๋น์ด ์์ต๋๋ค. ์ง์ ์
๋ ฅ ๋ชจ๋๋ก ์์ ์์ฑํฉ๋๋ค.")
|
| 685 |
+
temp_name = st.text_input("์๊ธ์๋ช
", "ํ๊ธธ๋")
|
| 686 |
+
client = pd.Series({
|
| 687 |
+
"id": 0, "name": temp_name, "masked_name": mask_name(temp_name), "care_grade": "3๋ฑ๊ธ",
|
| 688 |
+
"institution_type": "๋ฐฉ๋ฌธ์์", "institution_name": "", "main_condition": "",
|
| 689 |
+
"cognitive_status": "", "mobility_status": "", "diet_status": "", "toileting_status": ""
|
| 690 |
+
})
|
| 691 |
+
else:
|
| 692 |
+
options = clients_df.apply(lambda x: f"{x['id']}๋ฒ - {x['masked_name']} / {x['care_grade']} / {x['institution_type']} / {x.get('status','')}", axis=1).tolist()
|
| 693 |
+
selected_option = st.selectbox("์๊ธ์ ์ ํ", options)
|
| 694 |
+
selected_id = int(selected_option.split("๋ฒ")[0])
|
| 695 |
+
client = clients_df[clients_df["id"] == selected_id].iloc[0]
|
| 696 |
+
|
| 697 |
+
client_id = int(safe(client, "id", 0) or 0)
|
| 698 |
+
counseling_df = load_counseling(client_id)
|
| 699 |
+
needs_df = load_needs_assessment(client_id)
|
| 700 |
+
|
| 701 |
+
c1, c2, c3, c4 = st.columns(4)
|
| 702 |
+
c1.metric("์๊ธ์", safe(client, "masked_name"))
|
| 703 |
+
c2.metric("๋ฑ๊ธ", safe(client, "care_grade"))
|
| 704 |
+
c3.metric("๊ธฐ๊ด์ ํ", safe(client, "institution_type"))
|
| 705 |
+
c4.metric("์๋ด๊ธฐ๋ก", f"{len(counseling_df)}๊ฑด")
|
| 706 |
+
|
| 707 |
+
st.markdown("### ์ฐ๋ ์๋ฃ ํ์ธ")
|
| 708 |
+
with st.expander("์๋ด์ผ์ง ์ฐ๋ ๋ด์ฉ", expanded=True):
|
| 709 |
+
if counseling_df.empty:
|
| 710 |
+
st.info("์ ์ฅ๋ ์๋ด๊ธฐ๋ก์ด ์์ต๋๋ค. ์๋ด์ผ์ง ์์ฑ๊ธฐ์์ ๋จผ์ ์ ์ฅํ๋ฉด ์๋ ์ฐ๋๋ฉ๋๋ค.")
|
| 711 |
+
else:
|
| 712 |
+
st.dataframe(counseling_df[["counseling_date", "counseling_type", "counseling_reason", "client_status_change", "guardian_opinion"]], use_container_width=True)
|
| 713 |
+
|
| 714 |
+
with st.expander("์๊ตฌ์ฌ์ ์ฐ๋ ๋ด์ฉ", expanded=True):
|
| 715 |
+
if needs_df.empty:
|
| 716 |
+
st.info("์ ์ฅ๋ ์๊ตฌ์ฌ์ ๊ธฐ๋ก์ด ์์ต๋๋ค. ์๋ ์ง์ ์
๋ ฅ ์์ฝ์ ์ฌ์ฉํ๊ฑฐ๋, ์๊ตฌ์ฌ์ ์์ฑ๊ธฐ์ ์ ์ฅ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ฉด ์๋ ์ฐ๋๋ฉ๋๋ค.")
|
| 717 |
+
else:
|
| 718 |
+
st.dataframe(needs_df, use_container_width=True)
|
| 719 |
+
|
| 720 |
+
manual_needs_summary = st.text_area(
|
| 721 |
+
"์๊ตฌ์ฌ์ ์์ฝ ์ง์ ์
๋ ฅ",
|
| 722 |
+
placeholder="์: ๋์์ํ ๋์, ์ธ์ง์ ํ ์์ฌ, ์์ฌ๋ ๊ฐ์, ๋ฐฐ๋ณ๊ด๋ฆฌ ํ์, ์ ์์ง์ ํ์ ๋ฑ",
|
| 723 |
+
height=90,
|
| 724 |
+
)
|
| 725 |
+
|
| 726 |
+
st.markdown("### ์ฌ๋ก๊ด๋ฆฌ ๊ธฐ๋ณธ ์
๋ ฅ")
|
| 727 |
+
col1, col2, col3 = st.columns(3)
|
| 728 |
+
institution_name = col1.text_input("๊ธฐ๊ด๋ช
", value=safe(client, "institution_name"))
|
| 729 |
+
institution_type = col2.selectbox(
|
| 730 |
+
"๊ธฐ๊ด์ ํ",
|
| 731 |
+
["๋ฐฉ๋ฌธ์์", "๋ฐฉ๋ฌธ๋ชฉ์", "๋ฐฉ๋ฌธ๊ฐํธ", "์ฃผ๊ฐ๋ณดํธ", "์์์", "๊ณต๋์ํ๊ฐ์ "],
|
| 732 |
+
index=["๋ฐฉ๋ฌธ์์", "๋ฐฉ๋ฌธ๋ชฉ์", "๋ฐฉ๋ฌธ๊ฐํธ", "์ฃผ๊ฐ๋ณดํธ", "์์์", "๊ณต๋์ํ๊ฐ์ "].index(safe(client, "institution_type")) if safe(client, "institution_type") in ["๋ฐฉ๋ฌธ์์", "๋ฐฉ๋ฌธ๋ชฉ์", "๋ฐฉ๋ฌธ๊ฐํธ", "์ฃผ๊ฐ๋ณดํธ", "์์์", "๊ณต๋์ํ๊ฐ์ "] else 0
|
| 733 |
+
)
|
| 734 |
+
case_type = col3.selectbox("์ฌ๋ก๊ด๋ฆฌ ์ ํ", list(CASE_TYPES.keys()))
|
| 735 |
+
|
| 736 |
+
col4, col5, col6 = st.columns(3)
|
| 737 |
+
first_meeting_date = col4.date_input("1์ฐจ ํ์์ผ", value=date.today())
|
| 738 |
+
second_meeting_date = col5.date_input("2์ฐจ ๊ฒฐ๊ณผํ์์ผ", value=date.today() + timedelta(days=30))
|
| 739 |
+
writer = col6.text_input("์์ฑ์", "์ฌํ๋ณต์ง์ฌ")
|
| 740 |
+
|
| 741 |
+
meeting_place = st.text_input("ํ์์ฅ์", "๊ธฐ๊ด ๋ด ์๋ด์ค")
|
| 742 |
+
observation_period = st.text_input("๊ด์ฐฐ๊ธฐ๊ฐ", f"{first_meeting_date} ~ {second_meeting_date}")
|
| 743 |
+
result_level = st.selectbox("2์ฐจ ํ๊ฐ๊ฒฐ๊ณผ", ["๋ชฉํ๋ฌ์ฑ", "๋ถ๋ถ๋ฌ์ฑ", "์งํ์ค", "๋ฏธ๋ฌ์ฑ", "์ง์๊ด์ฐฐ"])
|
| 744 |
+
|
| 745 |
+
custom_selection = st.text_area("์ ์ ์ฌ์ ๋ณด์ ์
๋ ฅ", height=80)
|
| 746 |
+
custom_status = st.text_area("์ํ๋ณํ / ๋ณดํธ์ ์๊ฒฌ / ์ถ๊ฐ ๊ด์ฐฐ๋ด์ฉ", height=100)
|
| 747 |
+
custom_goal = st.text_area("์ฌ๋ก๊ด๋ฆฌ ๋ชฉํ ์ง์ ์
๋ ฅ", height=70)
|
| 748 |
+
custom_roles = st.text_area("์ญํ ๋ถ๋ด ์ง์ ์์ ", height=120)
|
| 749 |
+
|
| 750 |
+
st.markdown("### ์ฐธ์์ ๋ช
๋จ")
|
| 751 |
+
a1, a2, a3 = st.columns(3)
|
| 752 |
+
director_name = a1.text_input("์์ค์ฅ", "")
|
| 753 |
+
social_worker_name = a2.text_input("์ฌํ๋ณต์ง์ฌ", "")
|
| 754 |
+
caregiver_name = a3.text_input("์์๋ณดํธ์ฌ", "")
|
| 755 |
+
|
| 756 |
+
a4, a5, a6 = st.columns(3)
|
| 757 |
+
nurse_name = a4.text_input("๊ฐํธ์กฐ๋ฌด์ฌ", "")
|
| 758 |
+
therapist_name = a5.text_input("๋ฌผ๋ฆฌ์น๋ฃ์ฌ", "")
|
| 759 |
+
guardian_name = a6.text_input("๋ณดํธ์", "")
|
| 760 |
+
|
| 761 |
+
extra_attendees = st.text_input("๊ธฐํ ์ฐธ์์", "")
|
| 762 |
+
|
| 763 |
+
st.markdown("### ์ฌ์ง์ฒจ๋ถ")
|
| 764 |
+
case_photos = st.file_uploader(
|
| 765 |
+
"์ฌ๋ก๊ด๋ฆฌ ๊ด๋ จ ์ฌ์ง ์ฒจ๋ถ (์ต๋ 3์ฅ, ์ ํ์ฌํญ)",
|
| 766 |
+
type=["png", "jpg", "jpeg"],
|
| 767 |
+
accept_multiple_files=True
|
| 768 |
+
)
|
| 769 |
+
|
| 770 |
+
def save_uploaded_photos(uploaded_files):
|
| 771 |
+
paths = []
|
| 772 |
+
for file in (uploaded_files or [])[:3]:
|
| 773 |
+
suffix = os.path.splitext(file.name)[1].lower() or ".png"
|
| 774 |
+
temp_path = os.path.join(tempfile.gettempdir(), f"case_photo_{datetime.now().strftime('%Y%m%d%H%M%S%f')}{suffix}")
|
| 775 |
+
with open(temp_path, "wb") as f:
|
| 776 |
+
f.write(file.getbuffer())
|
| 777 |
+
paths.append(temp_path)
|
| 778 |
+
return paths
|
| 779 |
+
|
| 780 |
+
if st.button("๐ ์ฌ๋ก๊ด๋ฆฌ 1์ฐจ/2์ฐจ ํ์๋ก ์์ฑ", use_container_width=True):
|
| 781 |
+
counseling_summary = summarize_counseling(counseling_df)
|
| 782 |
+
needs_summary = summarize_needs(needs_df, client, manual_needs_summary)
|
| 783 |
+
|
| 784 |
+
selection, first_content, goal, first_plan, role_division, implementation, second_result = build_case_documents(
|
| 785 |
+
client, counseling_summary, needs_summary, case_type, custom_selection, custom_status, custom_goal, custom_roles
|
| 786 |
+
)
|
| 787 |
+
|
| 788 |
+
score, missing, compliance = evaluate_case(
|
| 789 |
+
selection, first_content, first_plan, role_division, implementation, second_result, counseling_summary, needs_summary
|
| 790 |
+
)
|
| 791 |
+
|
| 792 |
+
next_plan = (
|
| 793 |
+
"์ฌ๋ก๊ด๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๊ธ์ฌ์ ๊ณต๊ณํ์์ ๊ธ์ฌ๏ฟฝ๏ฟฝ๏ฟฝ๊ณต๊ธฐ๋ก์ง์ ๋ฐ์ํ๊ณ , ์ํ ๋ณํ๊ฐ ์ง์๋๊ฑฐ๋ ์๋ก์ด ์๊ตฌ๊ฐ ํ์ธ๋ ๊ฒฝ์ฐ "
|
| 794 |
+
"๋ณดํธ์ ์๋ด ๋ฐ ์๊ตฌ์ฌ์ ์ฌ์ ๊ฒ์ ์ค์ํ๋ค."
|
| 795 |
+
)
|
| 796 |
+
|
| 797 |
+
attendees_text = build_attendees_text(
|
| 798 |
+
director_name, social_worker_name, caregiver_name,
|
| 799 |
+
nurse_name, therapist_name, guardian_name, extra_attendees
|
| 800 |
+
)
|
| 801 |
+
photo_paths = save_uploaded_photos(case_photos)
|
| 802 |
+
|
| 803 |
+
st.session_state["case_data"] = {
|
| 804 |
+
"client_id": client_id,
|
| 805 |
+
"client_masked_name": safe(client, "masked_name"),
|
| 806 |
+
"institution_name": institution_name,
|
| 807 |
+
"institution_type": institution_type,
|
| 808 |
+
"grade": safe(client, "care_grade"),
|
| 809 |
+
"case_type": case_type,
|
| 810 |
+
"first_meeting_date": str(first_meeting_date),
|
| 811 |
+
"second_meeting_date": str(second_meeting_date),
|
| 812 |
+
"meeting_place": meeting_place,
|
| 813 |
+
"writer": writer,
|
| 814 |
+
"observation_period": observation_period,
|
| 815 |
+
"result_level": result_level,
|
| 816 |
+
"selection_reason": selection,
|
| 817 |
+
"counseling_summary": counseling_summary,
|
| 818 |
+
"needs_summary": needs_summary,
|
| 819 |
+
"first_content": first_content,
|
| 820 |
+
"goal": goal,
|
| 821 |
+
"first_plan": first_plan,
|
| 822 |
+
"role_division": role_division,
|
| 823 |
+
"attendees_text": attendees_text,
|
| 824 |
+
"photo_paths": photo_paths,
|
| 825 |
+
"implementation_process": implementation,
|
| 826 |
+
"second_result": second_result,
|
| 827 |
+
"next_plan": next_plan,
|
| 828 |
+
"evaluation_score": score,
|
| 829 |
+
"missing_items": ", ".join(missing) if missing else "๋ถ์กฑ ํญ๋ชฉ ์์",
|
| 830 |
+
"compliance_result": compliance,
|
| 831 |
+
}
|
| 832 |
+
|
| 833 |
+
if "case_data" in st.session_state:
|
| 834 |
+
data = st.session_state["case_data"]
|
| 835 |
+
|
| 836 |
+
st.markdown("---")
|
| 837 |
+
st.subheader("์์ฑ ๊ฒฐ๊ณผ ์์ ")
|
| 838 |
+
|
| 839 |
+
data["selection_reason"] = st.text_area("์ ์ ์ฌ์ ", value=data["selection_reason"], height=90)
|
| 840 |
+
data["first_content"] = st.text_area("1์ฐจ ํ์๋ด์ฉ", value=data["first_content"], height=220)
|
| 841 |
+
data["first_plan"] = st.text_area("1์ฐจ ๊ณํ", value=data["first_plan"], height=150)
|
| 842 |
+
data["role_division"] = st.text_area("์ญํ ๋ถ๋ด", value=data["role_division"], height=160)
|
| 843 |
+
data["attendees_text"] = st.text_area("์ฐธ์์ ๋ช
๋จ", value=data.get("attendees_text", ""), height=110)
|
| 844 |
+
data["implementation_process"] = st.text_area("์ญํ ๋ณ ์ํ๊ณผ์ ", value=data["implementation_process"], height=180)
|
| 845 |
+
data["second_result"] = st.text_area("2์ฐจ ๊ฒฐ๊ณผํ์๋ก", value=data["second_result"], height=180)
|
| 846 |
+
data["next_plan"] = st.text_area("ํฅํ๊ณํ", value=data["next_plan"], height=100)
|
| 847 |
+
|
| 848 |
+
score, missing, compliance = evaluate_case(
|
| 849 |
+
data["selection_reason"],
|
| 850 |
+
data["first_content"],
|
| 851 |
+
data["first_plan"],
|
| 852 |
+
data["role_division"],
|
| 853 |
+
data["implementation_process"],
|
| 854 |
+
data["second_result"],
|
| 855 |
+
data["counseling_summary"],
|
| 856 |
+
data["needs_summary"],
|
| 857 |
+
)
|
| 858 |
+
data["evaluation_score"] = score
|
| 859 |
+
data["missing_items"] = ", ".join(missing) if missing else "๋ถ์กฑ ํญ๋ชฉ ์์"
|
| 860 |
+
data["compliance_result"] = compliance
|
| 861 |
+
|
| 862 |
+
st.subheader("ํ๊ฐ ์ ํฉ๋ ์ ๊ฒ")
|
| 863 |
+
a, b, c = st.columns(3)
|
| 864 |
+
a.metric("ํ๊ฐ ์ ํฉ๋", f"{score}์ ")
|
| 865 |
+
b.metric("๋ถ์กฑ ํญ๋ชฉ", data["missing_items"])
|
| 866 |
+
c.metric("์ฐ๋์ํ", "์๋ด+์๊ตฌ์ฌ์ ๋ฐ์")
|
| 867 |
+
|
| 868 |
+
if score >= 90:
|
| 869 |
+
st.markdown(f'<div class="okbox">{compliance}</div>', unsafe_allow_html=True)
|
| 870 |
+
else:
|
| 871 |
+
st.markdown(f'<div class="warnbox">{compliance}</div>', unsafe_allow_html=True)
|
| 872 |
+
|
| 873 |
+
if st.button("๐พ ์ฌ๋ก๊ด๋ฆฌ ๊ธฐ๋ก DB ์ ์ฅ", use_container_width=True):
|
| 874 |
+
save_case_record(data)
|
| 875 |
+
st.success("์ฌ๋ก๊ด๋ฆฌ ๊ธฐ๋ก์ด ์ ์ฅ๋์์ต๋๋ค.")
|
| 876 |
+
|
| 877 |
+
filename = f"์ฌ๋ก๊ด๋ฆฌ_{data['client_masked_name']}_{datetime.now().strftime('%Y%m%d')}.xlsx"
|
| 878 |
+
st.download_button(
|
| 879 |
+
"๐ฅ ์ฌ๋ก๊ด๋ฆฌ 1์ฐจ/2์ฐจ ํ์๋ก ์์
๋ค์ด๋ก๋",
|
| 880 |
+
data=generate_excel(data),
|
| 881 |
+
file_name=filename,
|
| 882 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 883 |
+
use_container_width=True,
|
| 884 |
+
)
|
| 885 |
+
|
| 886 |
+
st.caption("BeeCare Client Center + ์๋ด์ผ์ง + ์๊ตฌ์ฌ์ ํตํฉ์ฐ๋ ์ฌ๋ก๊ด๋ฆฌ ์์ฑ๊ธฐ")
|