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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sqlite3
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
from datetime import date, datetime
|
| 5 |
+
|
| 6 |
+
import pandas as pd
|
| 7 |
+
import streamlit as st
|
| 8 |
+
from openpyxl import Workbook
|
| 9 |
+
from openpyxl.styles import Font, Alignment, Border, Side, PatternFill
|
| 10 |
+
from openpyxl.utils import get_column_letter
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
st.set_page_config(page_title="์ํ๋ณํ๊ธฐ๋ก์ง", page_icon="๐", layout="wide")
|
| 14 |
+
|
| 15 |
+
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 16 |
+
DB_CANDIDATES = [
|
| 17 |
+
os.path.join(CURRENT_DIR, "data", "clients.db"),
|
| 18 |
+
os.path.join(CURRENT_DIR, "..", "Client Center", "data", "clients.db"),
|
| 19 |
+
os.path.join(CURRENT_DIR, "..", "ClientCenter", "data", "clients.db"),
|
| 20 |
+
os.path.join(CURRENT_DIR, "..", "Client_Center", "data", "clients.db"),
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
DB_PATH = None
|
| 24 |
+
for candidate in DB_CANDIDATES:
|
| 25 |
+
if os.path.exists(candidate):
|
| 26 |
+
DB_PATH = candidate
|
| 27 |
+
break
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
st.markdown(
|
| 31 |
+
"""
|
| 32 |
+
<style>
|
| 33 |
+
.block-container { padding-top: 1.6rem; max-width: 1160px; }
|
| 34 |
+
.hero { background: linear-gradient(135deg,#2563EB,#60A5FA); padding:32px; border-radius:24px; text-align:center; margin-bottom:20px; }
|
| 35 |
+
.hero h1 { color:white; margin:0; font-size:42px; font-weight:800; }
|
| 36 |
+
.hero p { color:white; margin:14px 0 0 0; font-size:19px; line-height:1.55; }
|
| 37 |
+
.notice { background:#FFF8E1; border-left:7px solid #F59E0B; padding:15px 18px; border-radius:14px; margin:16px 0; line-height:1.7; }
|
| 38 |
+
.okbox { background:#E8F5E9; border-left:7px solid #43A047; padding:14px; border-radius:12px; margin:10px 0; }
|
| 39 |
+
.warnbox { background:#FFF3E0; border-left:7px solid #FB8C00; padding:14px; border-radius:12px; margin:10px 0; }
|
| 40 |
+
</style>
|
| 41 |
+
""",
|
| 42 |
+
unsafe_allow_html=True,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
st.markdown(
|
| 46 |
+
"""
|
| 47 |
+
<div class="hero">
|
| 48 |
+
<h1>๐ ์ํ๋ณํ๊ธฐ๋ก์ง ์์ฑ๊ธฐ</h1>
|
| 49 |
+
<p>Client Center ์ ๋ณด์ ์ง์ ์
๋ ฅ ๋ฉ๋ชจ๋ฅผ ๋ฐํ์ผ๋ก 5๋ ์์ญ, SOAP, ์ํํ์ , ์ฐ๊ณ๊ณํ์ ์๋ ์์ฑํฉ๋๋ค.</p>
|
| 50 |
+
</div>
|
| 51 |
+
""",
|
| 52 |
+
unsafe_allow_html=True,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
st.markdown(
|
| 56 |
+
"""
|
| 57 |
+
<div class="notice">
|
| 58 |
+
<strong>์์ฑ ์์น:</strong> ์ํ๋ณํ๊ฐ ์๋ค๋ ๋ฐ๋ณต ๋ฌธ๊ตฌ๋ฅผ ํผํ๊ณ , ์ ์ฒดยท์ธ์งยท๊ฐ์ ยท๊ด๊ณยท์ง์ญ์์์ฐ๊ณ ์์ญ์ ๊ธฐ์ค์ผ๋ก ํ๊ฐ ์ ํฉ ๋ฌธ์ฒด๋ก ๊ธฐ๋กํฉ๋๋ค.
|
| 59 |
+
</div>
|
| 60 |
+
""",
|
| 61 |
+
unsafe_allow_html=True,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
st.markdown(
|
| 65 |
+
"""
|
| 66 |
+
<div class="notice">
|
| 67 |
+
โป ์์ฑ๋ ๋ฌธ์๋ ๊ทธ๋๋ก ์ฌ์ฉํ์
๋ ๋๋ฉฐ, ๊ธฐ๊ด์ ์ด์๋ฐฉ์นจ, ์๊ธ์ ์ํ, ๋ณดํธ์ ์๊ฒฌ ๋ฐ ํ๊ฐ๊ธฐ์ค์ ๋ฐ๋ผ ์ถ๊ฐ ๋ณด์์ฌํญ์ ์ผ๋ง๋ ์ง ์์ ๊ฐ๋ฅํฉ๋๋ค. ๊ธฐ๊ด์ ์ํฉ์ ๋ง๊ฒ ํ์ฉํ์๊ธฐ ๋ฐ๋๋๋ค.
|
| 68 |
+
</div>
|
| 69 |
+
""",
|
| 70 |
+
unsafe_allow_html=True,
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
RESTRICTED_REPLACEMENTS = {
|
| 75 |
+
"์ํ ์ํธ": "์ ์ฒดยท์ธ์งยท์ ์ ์ํ๊ฐ ๋น๊ต์ ์์ ์ ์ผ๋ก ์ ์ง๋๋ ์ ๊ธฐ ๊ด์ฐฐ์ด ์๊ตฌ๋จ",
|
| 76 |
+
"ํน์ด์ฌํญ ์์": "์ฆ์ ๊ฐ์
์ด ํ์ํ ๋๋ฐ ์ํฉ์ ํ์ธ๋์ง ์์์ผ๋ ์ํ๋ณํ ๊ด์ฐฐ์ ์ง์ํจ",
|
| 77 |
+
"์ด์ ๊ณผ ๋์ผ": "๊ธฐ์กด ์ํ์ ๊ธ๊ฒฉํ ์
ํ๋ ์ ํ์ ์ด๋ ๊ธฐ๋ฅ ์ ์ง ์ฌ๋ถ๋ฅผ ๊ตฌ์ฒด์ ์ผ๋ก ํ์ธํจ",
|
| 78 |
+
"๋ฌธ์ ์์": "ํ์ฌ ํ์ธ๋ ์ํ์์ธ์ ์ ํ์ ์ด๋ ๊ธ์ฌ์ ๊ณต ๊ณผ์ ์์ ์ฌํ์ธ์ด ํ์ํจ",
|
| 79 |
+
"๋ฌธ์ ์์": "ํ์ฌ ํ์ธ๋ ์ํ์์ธ์ ์ ํ์ ์ด๋ ๊ธ์ฌ์ ๊ณต ๊ณผ์ ์์ ์ฌํ์ธ์ด ํ์ํจ",
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
DOMAIN_KEYWORDS = {
|
| 83 |
+
"์ ์ฒด": ["ํต์ฆ", "๋์", "์ด์ง", "ํ์ฒญ", "๋ณดํ", "์์ฌ", "์์", "์ฒด์ค", "์ฌ๋ ", "์ฐํ", "๋ฐฐ๋ณ", "๋ฐฐ๋จ", "์ค๊ธ", "๊ธฐ์ ๊ท", "์์ฐฝ", "๋ฐ์ ", "์์ฒ", "ํผ๋ถ", "์๋ฉด", "์
์", "ํด์"],
|
| 84 |
+
"์ธ์ง": ["์น๋งค", "์ธ์ง", "๊ธฐ์ต", "๋ฐ๋ณต", "ํผ๋", "์ฌ๋ง", "์ง๋จ๋ ฅ", "๋ฐฐํ", "๋ง์", "๋๋", "ํ๊ฐ", "๊ท๊ฐ", "์ง์"],
|
| 85 |
+
"๊ฐ์ ": ["์ฐ์ธ", "๋๋ฌผ", "๋ฌด๊ธฐ๋ ฅ", "๋ถ์", "์ด์กฐ", "์ง์ฆ", "ํ", "๊ฑฐ๋ถ", "์ด๊ธฐ ์ซ", "๊ท์ฐฎ"],
|
| 86 |
+
"๊ด๊ณ": ["๋คํผ", "๊ฐ๋ฑ", "ํญ์ธ", "๊ณต๊ฒฉ", "๋ณดํธ์", "๊ฐ์กฑ", "์ข
์ฌ์", "ํ ์๊ธ์", "๋ง๋คํผ", "๊ฑฐ๋ถ"],
|
| 87 |
+
"์ง์ญ์์์ฐ๊ณ": ["๋
๊ฑฐ", "๊ฒฐ์", "๊ฒฝ์ ", "์ฃผ๊ฑฐ", "๋ณต์ฝ", "๋ณ์", "์ง๋ฃ", "๋ณด๊ฑด์", "๋ณต์ง๊ด", "ํ์ ๋ณต์ง์ผํฐ", "์น๋งค์์ฌ์ผํฐ", "๋ฐฉ๋ฌธ๊ฐํธ"],
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
BPSD_KEYWORDS = ["๋๋", "๋ง์", "์์", "๋ฐฐํ", "๊ณต๊ฒฉ", "ํญ์ธ", "์ผ๊ฐ์ฌ๋ง", "ํ๊ฐ", "๊ท๊ฐ", "์ง์", "๊ฑฐ๋ถ"]
|
| 91 |
+
DEPRESSION_KEYWORDS = ["์ฐ์ธ", "๋๋ฌผ", "์์ฌ๊ฑฐ๋ถ", "๋ฌด๊ธฐ๋ ฅ", "์ด๊ธฐ ์ซ", "๊ท์ฐฎ", "์ธ๋ก"]
|
| 92 |
+
COMMUNITY_KEYWORDS = ["๋ณต์ฝ", "๊ฒฐ์", "๋
๊ฑฐ", "์ฃผ๊ฑฐ", "๊ฒฝ์ ", "๋ณ์", "์น๋งค", "๋ฐฉ๋ฌธ๊ฐํธ"]
|
| 93 |
+
HIGH_RISK_KEYWORDS = ["์๊ธ", "์
์", "๋์", "์์ฐฝ", "์์ฒ", "๊ฐ์ผ", "๊ณต๊ฒฉ", "๋ฐฐํ", "๋ง์", "์์ฌ๊ฑฐ๋ถ", "์ํด", "ํ๋", "๋ฐฉ์"]
|
| 94 |
+
WARNING_KEYWORDS = ["์ด์ง", "ํต์ฆ", "์์ฌ๋", "์ค๊ธ", "๋ฐ๋ณต", "๋ถ์", "์ฐ์ธ", "๊ฐ๋ฑ", "๊ฑฐ๋ถ", "๋ฐ์ ", "๋ณดํ"]
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def normalize_text(text):
|
| 98 |
+
value = str(text or "").strip()
|
| 99 |
+
for bad, good in RESTRICTED_REPLACEMENTS.items():
|
| 100 |
+
value = value.replace(bad, good)
|
| 101 |
+
return value
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def has_keyword(text, keywords):
|
| 105 |
+
source = str(text or "")
|
| 106 |
+
return any(keyword in source for keyword in keywords)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def pick(data, *keys, default=""):
|
| 110 |
+
for key in keys:
|
| 111 |
+
value = data.get(key, "")
|
| 112 |
+
if value is None:
|
| 113 |
+
continue
|
| 114 |
+
value = str(value).strip()
|
| 115 |
+
if value:
|
| 116 |
+
return value
|
| 117 |
+
return default
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def formal_sentence(text, fallback="์ง์ ๊ด์ฐฐ์ด ์๊ตฌ๋จ"):
|
| 121 |
+
value = normalize_text(text)
|
| 122 |
+
if not value:
|
| 123 |
+
value = fallback
|
| 124 |
+
if value.endswith(("ํ์ธ๋จ", "๊ด์ฐฐ๋จ", "์ฌ์ ๋จ", "ํ๋จ๋จ", "๊ณํํจ", "์ค์ํจ", "์๊ตฌ๋จ", "ํ์ํจ", "์์", "์์", "๋จ", "ํจ")):
|
| 125 |
+
return value
|
| 126 |
+
last = value[-1]
|
| 127 |
+
if "๊ฐ" <= last <= "ํฃ" and (ord(last) - ord("๊ฐ")) % 28:
|
| 128 |
+
return f"{value}์ผ๋ก ํ์ธ๋จ"
|
| 129 |
+
return f"{value}๋ก ํ์ธ๋จ"
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def load_clients():
|
| 133 |
+
if not DB_PATH:
|
| 134 |
+
return pd.DataFrame()
|
| 135 |
+
try:
|
| 136 |
+
conn = sqlite3.connect(DB_PATH)
|
| 137 |
+
cols = pd.read_sql_query("PRAGMA table_info(clients)", conn)["name"].tolist()
|
| 138 |
+
wanted = [
|
| 139 |
+
"id", "name", "masked_name", "gender", "birth_year", "care_grade",
|
| 140 |
+
"recognition_no", "recognition_number", "recognition_start_date", "recognition_end_date",
|
| 141 |
+
"institution_type", "institution_name", "main_condition", "cognitive_status",
|
| 142 |
+
"mobility_status", "diet_status", "toileting_status", "guardian_name", "guardian_phone",
|
| 143 |
+
"notes", "status",
|
| 144 |
+
]
|
| 145 |
+
select_cols = [c for c in wanted if c in cols]
|
| 146 |
+
if not select_cols:
|
| 147 |
+
conn.close()
|
| 148 |
+
return pd.DataFrame()
|
| 149 |
+
df = pd.read_sql_query("SELECT " + ", ".join(select_cols) + " FROM clients ORDER BY id DESC LIMIT 300", conn)
|
| 150 |
+
conn.close()
|
| 151 |
+
for col in wanted:
|
| 152 |
+
if col not in df.columns:
|
| 153 |
+
df[col] = ""
|
| 154 |
+
df["recognition_no"] = df["recognition_no"].where(df["recognition_no"].astype(str).str.strip() != "", df["recognition_number"])
|
| 155 |
+
return df
|
| 156 |
+
except Exception:
|
| 157 |
+
return pd.DataFrame()
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def safe(row, key, default=""):
|
| 161 |
+
try:
|
| 162 |
+
value = row.get(key, default)
|
| 163 |
+
if pd.isna(value):
|
| 164 |
+
return default
|
| 165 |
+
return str(value)
|
| 166 |
+
except Exception:
|
| 167 |
+
return default
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def mask_name(name):
|
| 171 |
+
name = str(name or "").strip()
|
| 172 |
+
if len(name) >= 3:
|
| 173 |
+
return name[0] + "โ" + name[2:]
|
| 174 |
+
if len(name) == 2:
|
| 175 |
+
return name[0] + "โ"
|
| 176 |
+
return name or "๋ฏธ์
๋ ฅ"
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def determine_plan_change(analysis):
|
| 180 |
+
if analysis["risk_level"] == "๊ณ ์ํ(์
ํ)":
|
| 181 |
+
return "๊ธ์ฌ์ ๊ณต๊ณํ ๋ณ๊ฒฝ ๊ฒํ ํ์ํจ"
|
| 182 |
+
if analysis["risk_level"] == "๊ฒฝ๊ณ (์ฃผ์)" and (analysis["bpsd"] or analysis["community_needed"]):
|
| 183 |
+
return "๊ธ์ฌ์ ๊ณต๊ณํ ๋ถ๋ถ ์กฐ์ ๊ฒํ ํ์ํจ"
|
| 184 |
+
return "ํ ๊ธ์ฌ์ ๊ณต๊ณํ ์ ์ง ๊ฐ๋ฅํ๋ ๋ค์ ์ ๊ณต ์ ์ฌํ์ธ ํ์ํจ"
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def analyze_status_change(data):
|
| 188 |
+
combined = " ".join([
|
| 189 |
+
pick(data, "main_condition", "์ฃผ์์ํ", "์ฃผ์ ์งํ / ๊ธฐ์กด ์ํ"),
|
| 190 |
+
pick(data, "physical_note", "์ ์ฒด์ํ", "์ ์ฒด์์ญ ๋ณํ"),
|
| 191 |
+
pick(data, "cognitive_note", "์ธ์ง์ํ", "์ธ์ง์์ญ ๋ณํ"),
|
| 192 |
+
pick(data, "emotion_note", "๊ฐ์ ์ํ", "๊ฐ์ ์์ญ ๋ณํ"),
|
| 193 |
+
pick(data, "relation_note", "๊ด๊ณ์ํ", "๊ด๊ณ์์ญ ๋ณํ"),
|
| 194 |
+
pick(data, "resource_note", "์ง์ญ์์", "์ง์ญ์์์ฐ๊ณ", "์ง์ญ์์์ฐ๊ณ ํ์"),
|
| 195 |
+
pick(data, "field_memo", "ํ์ฅ๋ฉ๋ชจ", "ํ์ฅ ๋จ์ ๋ฉ๋ชจ"),
|
| 196 |
+
pick(data, "guardian_opinion", "๋ณดํธ์์๊ฒฌ", "๋ณดํธ์ ์๊ฒฌ"),
|
| 197 |
+
])
|
| 198 |
+
|
| 199 |
+
domain_results = {}
|
| 200 |
+
for domain, keywords in DOMAIN_KEYWORDS.items():
|
| 201 |
+
if has_keyword(combined, keywords):
|
| 202 |
+
domain_results[domain] = True
|
| 203 |
+
|
| 204 |
+
bpsd = has_keyword(combined, BPSD_KEYWORDS)
|
| 205 |
+
depression = has_keyword(combined, DEPRESSION_KEYWORDS)
|
| 206 |
+
community_needed = has_keyword(combined, COMMUNITY_KEYWORDS)
|
| 207 |
+
|
| 208 |
+
high = has_keyword(combined, HIGH_RISK_KEYWORDS) and has_keyword(combined, ["์
ํ", "๋ฐ๋ณต", "์ง์", "์๊ธ", "์
์", "๊ฐ์ผ", "๊ณต๊ฒฉ", "๋ฐฐํ", "์์ฌ๊ฑฐ๋ถ"])
|
| 209 |
+
if high or (bpsd and has_keyword(combined, ["๊ณต๊ฒฉ", "๋ฐฐํ", "๋ง์", "์ผ๊ฐ"])):
|
| 210 |
+
risk_level = "๊ณ ์ํ(์
ํ)"
|
| 211 |
+
elif has_keyword(combined, WARNING_KEYWORDS) or bpsd or depression or community_needed:
|
| 212 |
+
risk_level = "๊ฒฝ๊ณ (์ฃผ์)"
|
| 213 |
+
else:
|
| 214 |
+
risk_level = "์์ (์ ์ง)"
|
| 215 |
+
|
| 216 |
+
flags = {
|
| 217 |
+
"์๊ตฌ์ฌ์ ์ฌ์ค์ ํ์": risk_level == "๊ณ ์ํ(์
ํ)" or depression,
|
| 218 |
+
"์ฌ๋ก๊ด๋ฆฌ ์ฐ๊ณ ํ์": risk_level == "๊ณ ์ํ(์
ํ)" or bpsd,
|
| 219 |
+
"๊ธ์ฌ์ ๊ณต๊ณํ ๋ณ๊ฒฝ ํ์": risk_level != "์์ (์ ์ง)",
|
| 220 |
+
"๋ณดํธ์ ์๋ด ํ์": bool(pick(data, "guardian_opinion", "๋ณดํธ์์๊ฒฌ", "๋ณดํธ์ ์๊ฒฌ")) or risk_level != "์์ (์ ์ง)",
|
| 221 |
+
}
|
| 222 |
+
return {
|
| 223 |
+
"combined": combined,
|
| 224 |
+
"domains": domain_results,
|
| 225 |
+
"bpsd": bpsd,
|
| 226 |
+
"depression": depression,
|
| 227 |
+
"community_needed": community_needed,
|
| 228 |
+
"risk_level": risk_level,
|
| 229 |
+
"flags": flags,
|
| 230 |
+
"plan_change": "",
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def build_community_plan(analysis):
|
| 235 |
+
if not analysis["community_needed"]:
|
| 236 |
+
return "์ง์ญ์์ ์ฐ๊ณ๋ ์ฆ์ ํ์์ฑ์ด ๋ฎ์ผ๋ ๋
๊ฑฐ, ๊ฒฐ์, ๋ณต์ฝ ๋ถ์ดํ, ์ฃผ๊ฑฐํ๊ฒฝ ์ํ ๋ฐ์ ์ ์ฌ๊ฒํ ๊ณํํจ"
|
| 237 |
+
return "๋ณด๊ฑด์, ์น๋งค์์ฌ์ผํฐ, ํ์ ๋ณต์ง์ผํฐ, ๋ณต์ง๊ด, ๋ฐฉ๋ฌธ๊ฐํธ ๋ฑ ์ง์ญ์์ ์ฐ๊ณ๋ฅผ ๊ฒํ ํ๊ณ ๋ณดํธ์ ๋ฐ ๋ด๋น์์ ๊ณต์ ๊ณํํจ"
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def build_status_text(data):
|
| 241 |
+
analysis = analyze_status_change(data)
|
| 242 |
+
analysis["plan_change"] = determine_plan_change(analysis)
|
| 243 |
+
|
| 244 |
+
domain_lines = []
|
| 245 |
+
labels = {
|
| 246 |
+
"์ ์ฒด": pick(data, "physical_note", "์ ์ฒด์ํ", "์ ์ฒด์์ญ ๋ณํ"),
|
| 247 |
+
"์ธ์ง": pick(data, "cognitive_note", "์ธ์ง์ํ", "์ธ์ง์์ญ ๋ณํ"),
|
| 248 |
+
"๊ฐ์ ": pick(data, "emotion_note", "๊ฐ์ ์ํ", "๊ฐ์ ์์ญ ๋ณํ"),
|
| 249 |
+
"๊ด๊ณ": pick(data, "relation_note", "๊ด๊ณ์ํ", "๊ด๊ณ์์ญ ๋ณํ"),
|
| 250 |
+
"์ง์ญ์์์ฐ๊ณ": pick(data, "resource_note", "์ง์ญ์์", "์ง์ญ์์์ฐ๊ณ", "์ง์ญ์์์ฐ๊ณ ํ์"),
|
| 251 |
+
}
|
| 252 |
+
for domain, note in labels.items():
|
| 253 |
+
if analysis["domains"].get(domain) or note:
|
| 254 |
+
domain_lines.append(f"- {domain}์์ญ: {formal_sentence(note, '๊ด๋ จ ๋ณํ ๊ฐ๋ฅ์ฑ์ด ํ์ธ๋์ด ๊ด์ฐฐ์ด ์๊ตฌ๋จ')}")
|
| 255 |
+
if not domain_lines:
|
| 256 |
+
domain_lines.append("- ์ ์ฒดยท์ธ์งยท์ ์ ์ ๋ฐ: ๊ธ๊ฒฉํ ์
ํ ๋จ์๋ ์ ํ์ ์ด๋ ์ ๊ธฐ ๊ด์ฐฐ์ด ์๊ตฌ๋จ")
|
| 257 |
+
|
| 258 |
+
bpsd_text = "BPSD ๊ด๋ จ ๋จ์๊ฐ ํ์ธ๋์ด ์ ๋ฉด ๋ฐ๋ฐ์ ์ง์ํ๊ณ ๊ฐ์ ๊ณต๊ฐ, ์งง์ ์ค๋ช
, ํ์ ์ ํ, ์ ์์์ ์ง์์ ์ค์ํจ" if analysis["bpsd"] else "BPSD ๊ณ ์ํ ๋จ์๋ ์ ํ์ ์ด๋ ์ธ์งยท์ ์ ๋ณํ ์ฌ๋ถ๋ฅผ ์ง์ ๊ด์ฐฐํจ"
|
| 259 |
+
depression_text = "์ฐ์ธ ์ํ ๋จ์๊ฐ ํ์ธ๋์ด ์ฌํ์ ๊ณ ๋ฆฝ๊ฐ, ์์ฌ๊ฑฐ๋ถ, ๋ฌด๊ธฐ๋ ฅ ์ง์ ์ฌ๋ถ๋ฅผ ํ์ธํ๊ณ ์ ์์ง์ ๊ฐํ๊ฐ ์๊ตฌ๋จ" if analysis["depression"] else "์ฐ์ธ ๊ณ ์ํ ๋จ์๋ ์ ํ์ ์ด๋ ์ ์ํํ ๋ณํ ์ฌ๋ถ๋ฅผ ๊ด์ฐฐํจ"
|
| 260 |
+
community_text = build_community_plan(analysis)
|
| 261 |
+
flag_text = " / ".join([f"โก {name}" for name, enabled in analysis["flags"].items() if enabled]) or "โก ์ ๊ธฐ ๊ด์ฐฐ ์ ์ง"
|
| 262 |
+
|
| 263 |
+
soap = f"""
|
| 264 |
+
[SOAP ๊ตฌ์กฐ ๊ธฐ๋ก]
|
| 265 |
+
S(์ฃผ๊ด์ ์ ๋ณด): {formal_sentence(pick(data, 'guardian_opinion', '๋ณดํธ์์๊ฒฌ', '๋ณดํธ์ ์๊ฒฌ') or pick(data, 'field_memo', 'ํ์ฅ๋ฉ๋ชจ', 'ํ์ฅ ๋จ์ ๋ฉ๋ชจ'), '์๊ธ์ ๋ฐ ๋ณดํธ์ ํธ์๋ ์ถ๊ฐ ํ์ธ ์์ ์')}
|
| 266 |
+
O(๊ฐ๊ด์ ๊ด์ฐฐ): {formal_sentence(pick(data, 'field_memo', 'ํ์ฅ๋ฉ๋ชจ', 'ํ์ฅ ๋จ์ ๋ฉ๋ชจ'), '์๋น์ค ์ ๊ณต ์ค ํ๋, ํ์ , ์ด๋, ์์ฌ, ๋ฐฐ๋ณ ๋ฑ ์ํ ๊ด์ฐฐ์ด ์๊ตฌ๋จ')}
|
| 267 |
+
A(์ ๋ฌธ์ ์ํ๋ถ์): ์๋ํ์ ๊ฒฐ๊ณผ {analysis['risk_level']} ๋จ๊ณ๋ก ์ฌ์ ๋จ. {bpsd_text} {depression_text}
|
| 268 |
+
P(์กฐ์น ๋ฐ ๊ณํ): {analysis['plan_change']} {community_text}
|
| 269 |
+
""".strip()
|
| 270 |
+
|
| 271 |
+
content = f"""
|
| 272 |
+
[์ํ๋ณํ ์๋ํ์ ]
|
| 273 |
+
ํ์ : {analysis['risk_level']}
|
| 274 |
+
๊ทผ๊ฑฐ: ์
๋ ฅ๋ ํ์ฅ ๋ฉ๋ชจ, ๋ณดํธ์ ์๊ฒฌ, ์๊ธ์ ๊ธฐ๋ณธ์ํ๋ฅผ ์ข
ํฉํ์ฌ ์ ์ฒดยท์ธ์งยท๊ฐ์ ยท๊ด๊ณยท์ง์ญ์์์ฐ๊ณ ์์ญ์ผ๋ก ๋ถ์ํจ.
|
| 275 |
+
|
| 276 |
+
[5๋ ์์ญ ๋ถ์]
|
| 277 |
+
{chr(10).join(domain_lines)}
|
| 278 |
+
|
| 279 |
+
[BPSD ๋ฐ ์ฐ์ธ ์ํ ๋ถ์]
|
| 280 |
+
- ์น๋งคํ๋์ฌ๋ฆฌ์ฆ์: {bpsd_text}
|
| 281 |
+
- ์ฐ์ธ ์ํ: {depression_text}
|
| 282 |
+
|
| 283 |
+
[์ง์ญ์์ ์ฐ๊ณ๊ณํ]
|
| 284 |
+
{community_text}
|
| 285 |
+
|
| 286 |
+
{soap}
|
| 287 |
+
|
| 288 |
+
[ํ๊ฐ ์ฐ๊ณ]
|
| 289 |
+
{flag_text}
|
| 290 |
+
๊ธ์ฌ์ ๊ณต๊ณํ ํ๋จ: {analysis['plan_change']}
|
| 291 |
+
""".strip()
|
| 292 |
+
return normalize_text(content), analysis
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def evaluate_record(content, analysis, photo_count):
|
| 296 |
+
required = {
|
| 297 |
+
"์๋ํ์ ": "ํ์ :" in content,
|
| 298 |
+
"5๋ ์์ญ": "5๋ ์์ญ ๋ถ์" in content,
|
| 299 |
+
"SOAP": "SOAP ๊ตฌ์กฐ ๊ธฐ๋ก" in content,
|
| 300 |
+
"BPSD": "BPSD" in content,
|
| 301 |
+
"์ง์ญ์์": "์ง์ญ์์" in content,
|
| 302 |
+
"ํ๊ฐ ์ฐ๊ณ": "ํ๊ฐ ์ฐ๊ณ" in content,
|
| 303 |
+
"์ฌ์ง์ฒจ๋ถ ํ์ธ": photo_count >= 0,
|
| 304 |
+
}
|
| 305 |
+
score = int(sum(required.values()) / len(required) * 100)
|
| 306 |
+
missing = [k for k, v in required.items() if not v]
|
| 307 |
+
if score >= 90:
|
| 308 |
+
comment = "ํ๊ฐ ์ ํฉ๋๊ฐ ๋์ต๋๋ค. ์ํํ์ , ์์ญ๋ถ์, SOAP, ํ์์กฐ์น๊ฐ ์ฐ๊ฒฐ๋์ด ์์ต๋๋ค."
|
| 309 |
+
elif score >= 75:
|
| 310 |
+
comment = "๋์ฒด๋ก ์ ํฉํ๋ ์ผ๋ถ ๋ณด์์ด ํ์ํฉ๋๋ค."
|
| 311 |
+
else:
|
| 312 |
+
comment = "๋ณด์์ด ํ์ํฉ๋๋ค. ์ํ๋ณํ ๊ทผ๊ฑฐ์ ํ์์กฐ์น๋ฅผ ๋ ๊ตฌ์ฒดํํด ์ฃผ์ธ์."
|
| 313 |
+
return score, missing, comment
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def style_range(ws, cell_range, fill=None, font=None, alignment=None):
|
| 317 |
+
thin = Side(style="thin", color="000000")
|
| 318 |
+
border = Border(left=thin, right=thin, top=thin, bottom=thin)
|
| 319 |
+
for row in ws[cell_range]:
|
| 320 |
+
for cell in row:
|
| 321 |
+
cell.border = border
|
| 322 |
+
if fill:
|
| 323 |
+
cell.fill = fill
|
| 324 |
+
if font:
|
| 325 |
+
cell.font = font
|
| 326 |
+
if alignment:
|
| 327 |
+
cell.alignment = alignment
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
def generate_excel(data):
|
| 331 |
+
wb = Workbook()
|
| 332 |
+
ws = wb.active
|
| 333 |
+
ws.title = "์ํ๋ณํ๊ธฐ๋ก์ง"
|
| 334 |
+
ws.sheet_view.showGridLines = False
|
| 335 |
+
ws.page_setup.orientation = "portrait"
|
| 336 |
+
ws.page_setup.fitToWidth = 1
|
| 337 |
+
ws.page_setup.fitToHeight = 0
|
| 338 |
+
ws.sheet_properties.pageSetUpPr.fitToPage = True
|
| 339 |
+
ws.page_margins.left = 0.3
|
| 340 |
+
ws.page_margins.right = 0.3
|
| 341 |
+
ws.page_margins.top = 0.4
|
| 342 |
+
ws.page_margins.bottom = 0.4
|
| 343 |
+
|
| 344 |
+
title_fill = PatternFill("solid", fgColor="DBEAFE")
|
| 345 |
+
header_fill = PatternFill("solid", fgColor="F3F4F6")
|
| 346 |
+
for col in range(1, 10):
|
| 347 |
+
ws.column_dimensions[get_column_letter(col)].width = 12
|
| 348 |
+
|
| 349 |
+
ws.merge_cells("A1:G2")
|
| 350 |
+
ws["A1"] = "์ ํ ๋ณ ํ ๊ธฐ ๋ก ์ง"
|
| 351 |
+
ws["A1"].font = Font(name="Malgun Gothic", size=24, bold=True)
|
| 352 |
+
ws["A1"].alignment = Alignment(horizontal="center", vertical="center")
|
| 353 |
+
ws["A1"].fill = title_fill
|
| 354 |
+
ws["H1"] = "๋ด๋น์"
|
| 355 |
+
ws["I1"] = "์์ค์ฅ"
|
| 356 |
+
ws["H2"] = ""
|
| 357 |
+
ws["I2"] = ""
|
| 358 |
+
for cell in ["H1", "I1"]:
|
| 359 |
+
ws[cell].fill = header_fill
|
| 360 |
+
ws[cell].font = Font(name="Malgun Gothic", size=11, bold=True)
|
| 361 |
+
ws[cell].alignment = Alignment(horizontal="center", vertical="center")
|
| 362 |
+
style_range(ws, "A1:I2")
|
| 363 |
+
ws.row_dimensions[1].height = 28
|
| 364 |
+
ws.row_dimensions[2].height = 45
|
| 365 |
+
|
| 366 |
+
def info_row(row, a, b, c, d, e, f):
|
| 367 |
+
ws.cell(row, 1).value = a
|
| 368 |
+
ws.merge_cells(start_row=row, start_column=2, end_row=row, end_column=3)
|
| 369 |
+
ws.cell(row, 2).value = b
|
| 370 |
+
ws.cell(row, 4).value = c
|
| 371 |
+
ws.merge_cells(start_row=row, start_column=5, end_row=row, end_column=6)
|
| 372 |
+
ws.cell(row, 5).value = d
|
| 373 |
+
ws.cell(row, 7).value = e
|
| 374 |
+
ws.merge_cells(start_row=row, start_column=8, end_row=row, end_column=9)
|
| 375 |
+
ws.cell(row, 8).value = f
|
| 376 |
+
for col in [1, 4, 7]:
|
| 377 |
+
ws.cell(row, col).fill = header_fill
|
| 378 |
+
ws.cell(row, col).font = Font(name="Malgun Gothic", size=10, bold=True)
|
| 379 |
+
ws.cell(row, col).alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 380 |
+
for col in [2, 5, 8]:
|
| 381 |
+
ws.cell(row, col).font = Font(name="Malgun Gothic", size=10)
|
| 382 |
+
ws.cell(row, col).alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 383 |
+
style_range(ws, f"A{row}:I{row}")
|
| 384 |
+
ws.row_dimensions[row].height = 30
|
| 385 |
+
|
| 386 |
+
r = 3
|
| 387 |
+
info_row(r, "๊ธฐ๊ด๋ช
", data["institution_name"], "๊ธฐ๊ด์ ํ", data["institution_type"], "์์ฑ์ผ์", data["record_date"]); r += 1
|
| 388 |
+
info_row(r, "์๊ธ์", data["masked_name"], "์ฅ๊ธฐ์์๋ฑ๊ธ", data["care_grade"], "ํ์ ", data["risk_level"]); r += 1
|
| 389 |
+
info_row(r, "์ธ์ ๋ฒํธ", data["recognition_no"], "์ธ์ ๊ธฐ๊ฐ", data["recognition_period"], "์ฌ์ง์ฒจ๋ถ", data["photo_names"]); r += 1
|
| 390 |
+
|
| 391 |
+
sections = [
|
| 392 |
+
("์ํ๋ณํ ๊ธฐ๋ก๋ด์ฉ", data["content"], 180),
|
| 393 |
+
("ํ๊ฐ ์ ํฉ๋ ์ ๊ฒ", data["compliance_result"], 55),
|
| 394 |
+
("๋ถ์กฑํ ํญ๋ชฉ", data["missing_items"], 45),
|
| 395 |
+
]
|
| 396 |
+
for title, body, min_height in sections:
|
| 397 |
+
ws.cell(r, 1).value = title
|
| 398 |
+
ws.cell(r, 1).fill = header_fill
|
| 399 |
+
ws.cell(r, 1).font = Font(name="Malgun Gothic", size=11, bold=True)
|
| 400 |
+
ws.cell(r, 1).alignment = Alignment(horizontal="center", vertical="center", wrap_text=True)
|
| 401 |
+
ws.merge_cells(start_row=r, start_column=2, end_row=r, end_column=9)
|
| 402 |
+
ws.cell(r, 2).value = body
|
| 403 |
+
ws.cell(r, 2).font = Font(name="Malgun Gothic", size=10)
|
| 404 |
+
ws.cell(r, 2).alignment = Alignment(horizontal="left", vertical="top", wrap_text=True)
|
| 405 |
+
lines = sum(max(1, len(line) // 55 + 1) for line in str(body).splitlines())
|
| 406 |
+
ws.row_dimensions[r].height = max(min_height, min(360, lines * 19 + 20))
|
| 407 |
+
style_range(ws, f"A{r}:I{r}")
|
| 408 |
+
r += 1
|
| 409 |
+
|
| 410 |
+
# ๊ณตํต ์๋ด๋ฌธ๊ตฌ ์ถ๊ฐ
|
| 411 |
+
ws.merge_cells(start_row=r, start_column=1, end_row=r, end_column=9)
|
| 412 |
+
ws.cell(r, 1).value = "โป ์์ฑ๋ ๋ฌธ์๋ ๊ทธ๋๋ก ์ฌ์ฉํ์
๋ ๋๋ฉฐ, ๊ธฐ๊ด์ ์ด์๋ฐฉ์นจ, ์๊ธ์ ์ํ, ๋ณดํธ์ ์๊ฒฌ ๋ฐ ํ๊ฐ๊ธฐ์ค์ ๋ฐ๋ผ ์ถ๊ฐ ๋ณด์์ฌํญ์ ์ผ๋ง๋ ์ง ์์ ๊ฐ๋ฅํฉ๋๋ค. ๊ธฐ๊ด์ ์ํฉ์ ๋ง๊ฒ ํ์ฉํ์๊ธฐ ๋ฐ๋๋๋ค."
|
| 413 |
+
style_range(ws, f"A{r}:I{r}",
|
| 414 |
+
font=Font(name="Malgun Gothic", size=8.5, color="595959", italic=True),
|
| 415 |
+
alignment=Alignment(horizontal="left", vertical="center", wrap_text=True))
|
| 416 |
+
ws.row_dimensions[r].height = 36
|
| 417 |
+
r += 1
|
| 418 |
+
|
| 419 |
+
hidden = wb.create_sheet("๋ด๋ถ์ ๊ฒ์๋ฃ_์ถ๋ ฅ์ ์ธ")
|
| 420 |
+
hidden.sheet_state = "hidden"
|
| 421 |
+
hidden["A1"] = "๊ตฌ๋ถ"
|
| 422 |
+
hidden["B1"] = "๋ด์ฉ"
|
| 423 |
+
rows = [
|
| 424 |
+
("ํ๊ฐ์ ํฉ๋", f"{data['evaluation_score']}์ "),
|
| 425 |
+
("๋ถ์กฑํญ๋ชฉ", data["missing_items"]),
|
| 426 |
+
("์๋ํ์ ", data["risk_level"]),
|
| 427 |
+
("์ฌ์ง์ฒจ๋ถ", data["photo_names"]),
|
| 428 |
+
]
|
| 429 |
+
for idx, (a, b) in enumerate(rows, 2):
|
| 430 |
+
hidden.cell(idx, 1).value = a
|
| 431 |
+
hidden.cell(idx, 2).value = b
|
| 432 |
+
hidden.column_dimensions["A"].width = 20
|
| 433 |
+
hidden.column_dimensions["B"].width = 90
|
| 434 |
+
|
| 435 |
+
output = BytesIO()
|
| 436 |
+
wb.save(output)
|
| 437 |
+
output.seek(0)
|
| 438 |
+
return output
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
clients_df = load_clients()
|
| 442 |
+
if DB_PATH:
|
| 443 |
+
st.sidebar.success("Client Center DB ์ฐ๊ฒฐ๋จ")
|
| 444 |
+
st.sidebar.caption(DB_PATH)
|
| 445 |
+
else:
|
| 446 |
+
st.sidebar.warning("Client Center DB๋ฅผ ์ฐพ์ง ๋ชปํด ์ง์ ์
๋ ฅ์ผ๋ก ์คํ๋ฉ๋๋ค.")
|
| 447 |
+
|
| 448 |
+
mode = st.radio("์
๋ ฅ ๋ฐฉ์", ["Client Center์์ ์๊ธ์ ์ ํ", "์ง์ ์
๋ ฅ"], horizontal=True)
|
| 449 |
+
selected_client = None
|
| 450 |
+
if mode == "Client Center์์ ์๊ธ์ ์ ํ" and not clients_df.empty:
|
| 451 |
+
options = clients_df.apply(lambda x: f"{x['id']}๋ฒ - {x['masked_name']} / {x['care_grade']} / {x['institution_type']} / {x['status']}", axis=1).tolist()
|
| 452 |
+
option = st.selectbox("์๊ธ์ ์ ํ", options)
|
| 453 |
+
selected_id = int(option.split("๋ฒ")[0])
|
| 454 |
+
selected_client = clients_df[clients_df["id"] == selected_id].iloc[0]
|
| 455 |
+
elif mode == "Client Center์์ ์๊ธ์ ์ ํ":
|
| 456 |
+
st.warning("๋ฑ๋ก๋ ์๊ธ์ ์ ๋ณด๊ฐ ์๊ฑฐ๋ DB๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค. ์ง์ ์
๋ ฅ์ผ๋ก ์์ฑํ ์ ์์ต๋๋ค.")
|
| 457 |
+
|
| 458 |
+
if selected_client is not None:
|
| 459 |
+
default_name = safe(selected_client, "name")
|
| 460 |
+
default_masked = safe(selected_client, "masked_name") or mask_name(default_name)
|
| 461 |
+
default_grade = safe(selected_client, "care_grade", "3๋ฑ๊ธ")
|
| 462 |
+
default_inst = safe(selected_client, "institution_type", "๋ฐฉ๋ฌธ์์")
|
| 463 |
+
default_inst_name = safe(selected_client, "institution_name")
|
| 464 |
+
default_main = safe(selected_client, "main_condition")
|
| 465 |
+
default_cog = safe(selected_client, "cognitive_status")
|
| 466 |
+
default_mob = safe(selected_client, "mobility_status")
|
| 467 |
+
default_diet = safe(selected_client, "diet_status")
|
| 468 |
+
default_toilet = safe(selected_client, "toileting_status")
|
| 469 |
+
recognition_no = safe(selected_client, "recognition_no") or safe(selected_client, "recognition_number") or "๋ฏธ์
๋ ฅ"
|
| 470 |
+
recognition_period = " ~ ".join([x for x in [safe(selected_client, "recognition_start_date"), safe(selected_client, "recognition_end_date")] if x]) or "๋ฏธ์
๋ ฅ"
|
| 471 |
+
else:
|
| 472 |
+
default_name = "ํ๊ธธ๋"
|
| 473 |
+
default_masked = "ํโ๋"
|
| 474 |
+
default_grade = "3๋ฑ๊ธ"
|
| 475 |
+
default_inst = "๋ฐฉ๋ฌธ์์"
|
| 476 |
+
default_inst_name = ""
|
| 477 |
+
default_main = ""
|
| 478 |
+
default_cog = ""
|
| 479 |
+
default_mob = ""
|
| 480 |
+
default_diet = ""
|
| 481 |
+
default_toilet = ""
|
| 482 |
+
recognition_no = "๋ฏธ์
๋ ฅ"
|
| 483 |
+
recognition_period = "๋ฏธ์
๋ ฅ"
|
| 484 |
+
|
| 485 |
+
st.subheader("1๋จ๊ณ. ๊ธฐ๋ณธ์ ๋ณด")
|
| 486 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 487 |
+
name = col1.text_input("์๊ธ์ ์ฑ๋ช
", default_name)
|
| 488 |
+
masked_name = col2.text_input("๊ฐ๋ช
ํ๊ธฐ", default_masked or mask_name(name))
|
| 489 |
+
care_grade = col3.selectbox("์ฅ๊ธฐ์์๋ฑ๊ธ", ["1๋ฑ๊ธ", "2๋ฑ๊ธ", "3๋ฑ๊ธ", "4๋ฑ๊ธ", "5๋ฑ๊ธ", "์ธ์ง์ง์๋ฑ๊ธ", "๋ฏธ์
๋ ฅ"], index=2 if default_grade not in ["1๋ฑ๊ธ", "2๋ฑ๊ธ", "4๋ฑ๊ธ", "5๋ฑ๊ธ", "์ธ์ง์ง์๋ฑ๊ธ", "๋ฏธ์
๋ ฅ"] else ["1๋ฑ๊ธ", "2๋ฑ๊ธ", "3๋ฑ๊ธ", "4๋ฑ๊ธ", "5๋ฑ๊ธ", "์ธ์ง์ง์๋ฑ๊ธ", "๋ฏธ์
๋ ฅ"].index(default_grade))
|
| 490 |
+
record_date = col4.date_input("์์ฑ์ผ์", value=date.today())
|
| 491 |
+
|
| 492 |
+
col5, col6 = st.columns(2)
|
| 493 |
+
institution_type = col5.selectbox("๊ธฐ๊ด์ ํ", ["๋ฐฉ๋ฌธ์์", "๋ฐฉ๋ฌธ๋ชฉ์", "๋ฐฉ๋ฌธ๊ฐํธ", "์ฃผ๊ฐ๋ณดํธ", "์์์", "๊ณต๋์ํ๊ฐ์ "], index=["๋ฐฉ๋ฌธ์์", "๋ฐฉ๋ฌธ๋ชฉ์", "๋ฐฉ๋ฌธ๊ฐํธ", "์ฃผ๊ฐ๋ณดํธ", "์์์", "๊ณต๋์ํ๊ฐ์ "].index(default_inst) if default_inst in ["๋ฐฉ๋ฌธ์์", "๋ฐฉ๋ฌธ๋ชฉ์", "๋ฐฉ๋ฌธ๊ฐํธ", "์ฃผ๊ฐ๋ณดํธ", "์์์", "๊ณต๋์ํ๊ฐ์ "] else 0)
|
| 494 |
+
institution_name = col6.text_input("๊ธฐ๊ด๋ช
", default_inst_name)
|
| 495 |
+
|
| 496 |
+
st.subheader("2๋จ๊ณ. ์ํ๋ณํ ์
๋ ฅ")
|
| 497 |
+
c1, c2 = st.columns(2)
|
| 498 |
+
main_condition = c1.text_area("์ฃผ์ ์งํ / ๊ธฐ์กด ์ํ", value=default_main, height=85)
|
| 499 |
+
physical_note = c2.text_area("์ ์ฒด์์ญ ๋ณํ", value=f"{default_mob} {default_diet} {default_toilet}".strip(), height=85, placeholder="์: ๋ณดํ ์ ํ์ฒญ๊ฑฐ๋ฆผ, ์์ฌ๋ ๊ฐ์, ์์ค๊ธ ์ฆ๊ฐ")
|
| 500 |
+
c3, c4 = st.columns(2)
|
| 501 |
+
cognitive_note = c3.text_area("์ธ์ง์์ญ ๋ณํ", value=default_cog, height=85, placeholder="์: ๋ฐ๋ณต์ง๋ฌธ, ๊ท๊ฐ์๊ตฌ, ๋๋๋ง์, ๋ฐฐํ")
|
| 502 |
+
emotion_note = c4.text_area("๊ฐ์ ์์ญ ๋ณํ", height=85, placeholder="์: ์ฐ์ธ, ๋๋ฌผ, ๋ฌด๊ธฐ๋ ฅ, ๋ถ์")
|
| 503 |
+
c5, c6 = st.columns(2)
|
| 504 |
+
relation_note = c5.text_area("๊ด๊ณ์์ญ ๋ณํ", height=85, placeholder="์: ํ ์๊ธ์์ ๋ง๋คํผ, ๋ณดํธ์ ๊ฐ๋ฑ")
|
| 505 |
+
resource_note = c6.text_area("์ง์ญ์์์ฐ๊ณ ํ์", height=85, placeholder="์: ๋
๊ฑฐ, ๊ฒฐ์, ๋ณต์ฝ ๋ถ์ดํ, ๊ฒฝ์ ์ ์ด๋ ค์")
|
| 506 |
+
field_memo = st.text_area("ํ์ฅ ๋จ์ ๋ฉ๋ชจ", height=100, placeholder="์: ์คํ์ ๋๋๋
์ด๋ผ๊ณ ์ํ๊ณ ํ๋. ์์ฌ ์ ๋ฐ๋ง ๋์ฌ.")
|
| 507 |
+
guardian_opinion = st.text_area("๋ณดํธ์ ์๊ฒฌ", height=85, placeholder="์: ์ต๊ทผ ๋ฐค์ ์ ์ ๋ชป ์๊ณ ๋ฐฐํ๊ฐ ๋์ด ๊ฑฑ์ ๋๋ค๊ณ ํจ")
|
| 508 |
+
|
| 509 |
+
photo_files = st.file_uploader("์ฌ์ง์ฒจ๋ถ", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
| 510 |
+
photo_names = ", ".join([f.name for f in photo_files]) if photo_files else "์ฒจ๋ถ ์์"
|
| 511 |
+
|
| 512 |
+
if st.button("๐ ์ํ๋ณํ๊ธฐ๋ก์ง ์์ฑ", use_container_width=True):
|
| 513 |
+
input_data = {
|
| 514 |
+
"main_condition": main_condition,
|
| 515 |
+
"physical_note": physical_note,
|
| 516 |
+
"cognitive_note": cognitive_note,
|
| 517 |
+
"emotion_note": emotion_note,
|
| 518 |
+
"relation_note": relation_note,
|
| 519 |
+
"resource_note": resource_note,
|
| 520 |
+
"field_memo": field_memo,
|
| 521 |
+
"guardian_opinion": guardian_opinion,
|
| 522 |
+
}
|
| 523 |
+
content, analysis = build_status_text(input_data)
|
| 524 |
+
score, missing, result = evaluate_record(content, analysis, len(photo_files or []))
|
| 525 |
+
st.session_state["status_change_data"] = {
|
| 526 |
+
"name": name,
|
| 527 |
+
"masked_name": masked_name,
|
| 528 |
+
"care_grade": care_grade,
|
| 529 |
+
"institution_type": institution_type,
|
| 530 |
+
"institution_name": institution_name,
|
| 531 |
+
"record_date": str(record_date),
|
| 532 |
+
"recognition_no": recognition_no,
|
| 533 |
+
"recognition_period": recognition_period,
|
| 534 |
+
"risk_level": analysis["risk_level"],
|
| 535 |
+
"content": content,
|
| 536 |
+
"evaluation_score": score,
|
| 537 |
+
"missing_items": ", ".join(missing) if missing else "๋ถ์กฑ ํญ๋ชฉ ์์",
|
| 538 |
+
"compliance_result": result,
|
| 539 |
+
"photo_names": photo_names,
|
| 540 |
+
}
|
| 541 |
+
st.session_state.pop("status_change_excel", None)
|
| 542 |
+
|
| 543 |
+
if "status_change_data" in st.session_state:
|
| 544 |
+
data = st.session_state["status_change_data"]
|
| 545 |
+
st.markdown("---")
|
| 546 |
+
st.subheader("3๋จ๊ณ. ์์ฑ ๊ฒฐ๊ณผ ํ์ธ/์์ ")
|
| 547 |
+
data["content"] = st.text_area("์ํ๋ณํ ๊ธฐ๋ก๋ด์ฉ", value=data["content"], height=340)
|
| 548 |
+
a, b, c = st.columns(3)
|
| 549 |
+
a.metric("์๋ํ์ ", data["risk_level"])
|
| 550 |
+
b.metric("ํ๊ฐ ์ ํฉ๋", f"{data['evaluation_score']}์ ")
|
| 551 |
+
c.metric("๊ฒฐ์ฌ๋ผ์ธ", "๋ด๋น์/์์ค์ฅ 2์นธ")
|
| 552 |
+
if data["evaluation_score"] >= 90:
|
| 553 |
+
st.markdown(f'<div class="okbox">{data["compliance_result"]}</div>', unsafe_allow_html=True)
|
| 554 |
+
else:
|
| 555 |
+
st.markdown(f'<div class="warnbox">{data["compliance_result"]}</div>', unsafe_allow_html=True)
|
| 556 |
+
|
| 557 |
+
if st.button("๐ฆ ์์
ํ์ผ ์ค๋นํ๊ธฐ", use_container_width=True):
|
| 558 |
+
st.session_state["status_change_excel"] = generate_excel(data)
|
| 559 |
+
st.success("์์
ํ์ผ์ด ์ค๋น๋์์ต๋๋ค.")
|
| 560 |
+
|
| 561 |
+
if "status_change_excel" in st.session_state:
|
| 562 |
+
filename = f"์ํ๋ณํ๊ธฐ๋ก์ง_{data['masked_name']}_{datetime.now().strftime('%Y%m%d')}.xlsx"
|
| 563 |
+
st.download_button(
|
| 564 |
+
"๐ฅ ์ํ๋ณํ๊ธฐ๋ก์ง ์์
๋ค์ด๋ก๋",
|
| 565 |
+
data=st.session_state["status_change_excel"],
|
| 566 |
+
file_name=filename,
|
| 567 |
+
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
| 568 |
+
use_container_width=True,
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
st.caption("์ํ๋ณํ๊ธฐ๋ก์ง ์ต์ข
๋ณธ: Client Center ์ฐ๋, ์ง์ ์
๋ ฅ, ์ฌ์ง์ฒจ๋ถ, ์์
๋ค์ด๋ก๋, ๊ฒฐ์ฌ๋ผ์ธ 2์นธ, ๋ด๋ถ์ ๊ฒ ์จ๊น์ํธ๋ฅผ ํฌํจํฉ๋๋ค.")
|