Pflegepilot v3 Phase 0: FastAPI+PostgreSQL+Next.js-Grundgeruest
Kompletter Parallel-Neubau (open.md Punkt 6) neben der unveraenderten Flask/SQLite-App, verifiziert per docker compose: Auth Ende-zu-Ende (Login/Registrierung/Logout/Demo-Login), alle 11 Tabellen per Alembic migriert, WeasyPrint-PDF-Smoke-Test, Admin-Konto gemeinsam angelegt. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
559d606d4f
commit
47f1665f0f
53 files changed
+8517
No files matched your search
@@ -19,3 +19,12 @@ pflegepilot_alpha_v2/pflegepilot/.env
|
||||
|
||||
# graphify output - regeneratable
|
||||
graphify-out/
|
||||
|
||||
# pflegepilot_v3 (React/FastAPI/PostgreSQL-Neubau)
|
||||
pflegepilot_v3/backend/app/uploads/*
|
||||
!pflegepilot_v3/backend/app/uploads/.gitkeep
|
||||
pflegepilot_v3/backend/.env
|
||||
pflegepilot_v3/backend/.venv*/
|
||||
pflegepilot_v3/frontend/node_modules/
|
||||
pflegepilot_v3/frontend/.next/
|
||||
pflegepilot_v3/.env
|
||||
@@ -0,0 +1,18 @@
|
||||
# Kopieren nach .env und Werte anpassen. .env selbst ist gitignored.
|
||||
|
||||
# --- Postgres ---
|
||||
POSTGRES_USER=pflegepilot
|
||||
POSTGRES_PASSWORD=change-me
|
||||
POSTGRES_DB=pflegepilot
|
||||
POSTGRES_PORT=5532
|
||||
DATABASE_URL=postgresql+psycopg://pflegepilot:change-me@db:5432/pflegepilot
|
||||
|
||||
# --- Backend (FastAPI) ---
|
||||
# Neu generieren mit: python -c "import secrets; print(secrets.token_hex(32))"
|
||||
SECRET_KEY=change-me
|
||||
API_PORT=8100
|
||||
WEB_ORIGIN=http://localhost:3100
|
||||
|
||||
# --- Frontend (Next.js) ---
|
||||
WEB_PORT=3100
|
||||
NEXT_PUBLIC_API_URL=http://localhost:8100
|
||||
@@ -0,0 +1,28 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
# WeasyPrint braucht diese nativen Libs zum PDF-Rendern (Pango/Cairo/GDK-Pixbuf)
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libpango-1.0-0 \
|
||||
libpangocairo-1.0-0 \
|
||||
libcairo2 \
|
||||
libgdk-pixbuf-2.0-0 \
|
||||
libffi8 \
|
||||
shared-mime-info \
|
||||
fonts-dejavu-core \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN useradd --create-home appuser \
|
||||
&& mkdir -p /app/app/uploads \
|
||||
&& chown -R appuser:appuser /app
|
||||
USER appuser
|
||||
|
||||
EXPOSE 5050
|
||||
|
||||
CMD ["sh", "-c", "alembic upgrade head && gunicorn app.main:app -k uvicorn.workers.UvicornWorker -w ${GUNICORN_WORKERS:-2} -b 0.0.0.0:5050"]
|
||||
@@ -0,0 +1,38 @@
|
||||
[alembic]
|
||||
script_location = migrations
|
||||
prepend_sys_path = .
|
||||
version_path_separator = os
|
||||
|
||||
[loggers]
|
||||
keys = root,sqlalchemy,alembic
|
||||
|
||||
[handlers]
|
||||
keys = console
|
||||
|
||||
[formatters]
|
||||
keys = generic
|
||||
|
||||
[logger_root]
|
||||
level = WARN
|
||||
handlers = console
|
||||
qualname =
|
||||
|
||||
[logger_sqlalchemy]
|
||||
level = WARN
|
||||
handlers =
|
||||
qualname = sqlalchemy.engine
|
||||
|
||||
[logger_alembic]
|
||||
level = INFO
|
||||
handlers =
|
||||
qualname = alembic
|
||||
|
||||
[handler_console]
|
||||
class = StreamHandler
|
||||
args = (sys.stderr,)
|
||||
level = NOTSET
|
||||
formatter = generic
|
||||
|
||||
[formatter_generic]
|
||||
format = %(levelname)-5.5s [%(name)s] %(message)s
|
||||
datefmt = %H:%M:%S
|
||||
Whitespace-only changes.
@@ -0,0 +1,29 @@
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models import AdminAuditLog, Nutzer
|
||||
|
||||
|
||||
def log_admin_aktion(
|
||||
db: Session,
|
||||
admin: Nutzer,
|
||||
aktion: str,
|
||||
ziel_typ: str,
|
||||
ziel_id: int | None,
|
||||
ziel_bezeichnung: str | None,
|
||||
begruendung: str,
|
||||
) -> None:
|
||||
"""Unveraenderlicher Audit-Trail fuer Admin-Aktionen (Sperren/Loeschen/
|
||||
Export/...). Bewusst kein FK auf nutzer.id, damit der Log-Eintrag eine
|
||||
spaetere Nutzer-Loeschung ueberlebt. Wird ab Phase 4 (Admin-Dashboard)
|
||||
aktiv genutzt; Gruest bereits in Phase 0 angelegt."""
|
||||
db.add(
|
||||
AdminAuditLog(
|
||||
admin_id=admin.id,
|
||||
admin_name=admin.name or admin.benutzername,
|
||||
aktion=aktion,
|
||||
ziel_typ=ziel_typ,
|
||||
ziel_id=ziel_id,
|
||||
ziel_bezeichnung=ziel_bezeichnung,
|
||||
begruendung=begruendung,
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
|
||||
|
||||
database_url: str
|
||||
secret_key: str
|
||||
web_origin: str = "http://localhost:3100"
|
||||
uploads_dir: str = "app/uploads"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
@@ -0,0 +1,21 @@
|
||||
from collections.abc import Generator
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker
|
||||
|
||||
from app.config import settings
|
||||
|
||||
engine = create_engine(settings.database_url, pool_pre_ping=True)
|
||||
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
def get_db() -> Generator[Session, None, None]:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
@@ -0,0 +1,32 @@
|
||||
from fastapi import Depends, HTTPException, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import get_db
|
||||
from app.models import Nutzer
|
||||
|
||||
# Phase 0: nur Login/Rollen-Grundbausteine. get_owned_patient/
|
||||
# scoped_patienten_query, require_active_access und require_paid_access
|
||||
# kommen in Phase 1 bzw. Phase 3/5 dazu (siehe Plan-Datei) - erst dort gibt
|
||||
# es ueberhaupt Patienten- bzw. Abo-Daten, gegen die man pruefen koennte.
|
||||
|
||||
|
||||
def get_current_user(request: Request, db: Session = Depends(get_db)) -> Nutzer | None:
|
||||
uid = request.session.get("nutzer_id")
|
||||
if not uid:
|
||||
return None
|
||||
user = db.get(Nutzer, uid)
|
||||
if user is None or not user.aktiv:
|
||||
return None
|
||||
return user
|
||||
|
||||
|
||||
def require_login(user: Nutzer | None = Depends(get_current_user)) -> Nutzer:
|
||||
if user is None:
|
||||
raise HTTPException(status_code=401, detail="Nicht angemeldet")
|
||||
return user
|
||||
|
||||
|
||||
def require_admin(user: Nutzer = Depends(require_login)) -> Nutzer:
|
||||
if user.rolle != "admin":
|
||||
raise HTTPException(status_code=403, detail="Kein Zugriff")
|
||||
return user
|
||||
@@ -0,0 +1,52 @@
|
||||
import datetime
|
||||
|
||||
from fastapi import FastAPI, Response
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
|
||||
from app.config import settings
|
||||
from app.pdf import render_pdf
|
||||
from app.routers import auth
|
||||
|
||||
app = FastAPI(title="Pflegepilot API")
|
||||
|
||||
app.add_middleware(
|
||||
SessionMiddleware,
|
||||
secret_key=settings.secret_key,
|
||||
session_cookie="pp_session",
|
||||
same_site="lax",
|
||||
https_only=False, # wird in Phase 7 mit TLS/Reverse-Proxy auf True gesetzt
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[settings.web_origin],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def security_headers(request, call_next):
|
||||
response = await call_next(request)
|
||||
response.headers["X-Frame-Options"] = "SAMEORIGIN"
|
||||
response.headers["X-Content-Type-Options"] = "nosniff"
|
||||
response.headers["Content-Security-Policy"] = "default-src 'self'"
|
||||
return response
|
||||
|
||||
|
||||
app.include_router(auth.router)
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
def health():
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@app.get("/api/dev/hello-pdf")
|
||||
def hello_pdf():
|
||||
"""Temporaerer WeasyPrint-Smoke-Test fuer Phase 0 - wird vor Phase 3
|
||||
wieder entfernt, sobald die echten PDF-Templates existieren."""
|
||||
pdf_bytes = render_pdf("smoke.html", zeitpunkt=datetime.datetime.now().isoformat())
|
||||
return Response(content=pdf_bytes, media_type="application/pdf")
|
||||
@@ -0,0 +1,284 @@
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
CheckConstraint,
|
||||
Date,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Numeric,
|
||||
String,
|
||||
Text,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.db import Base
|
||||
|
||||
|
||||
class Nutzer(Base):
|
||||
__tablename__ = "nutzer"
|
||||
__table_args__ = (CheckConstraint("rolle IN ('nutzer','admin')", name="ck_nutzer_rolle"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
benutzername: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
|
||||
passwort_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
name: Mapped[str | None] = mapped_column(String(200))
|
||||
rolle: Mapped[str] = mapped_column(String(20), nullable=False, default="nutzer")
|
||||
aktiv: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
||||
abo_bis: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
abo_typ: Mapped[str | None] = mapped_column(String(50))
|
||||
ist_demo: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
letzte_gesehene_version: Mapped[str | None] = mapped_column(String(20))
|
||||
letzter_login: Mapped[datetime.datetime | None] = mapped_column(DateTime(timezone=True))
|
||||
letzte_ip: Mapped[str | None] = mapped_column(String(45))
|
||||
rg_name: Mapped[str | None] = mapped_column(String(200))
|
||||
rg_strasse: Mapped[str | None] = mapped_column(String(200))
|
||||
rg_plz: Mapped[str | None] = mapped_column(String(20))
|
||||
rg_ort: Mapped[str | None] = mapped_column(String(100))
|
||||
selbst_registriert: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
patienten: Mapped[list["Patient"]] = relationship(back_populates="nutzer")
|
||||
|
||||
|
||||
class Patient(Base):
|
||||
__tablename__ = "patienten"
|
||||
__table_args__ = (
|
||||
CheckConstraint("versicherungsart IN ('GKV','PKV')", name="ck_patient_versicherungsart"),
|
||||
CheckConstraint("pflegegrad BETWEEN 0 AND 5", name="ck_patient_pflegegrad"),
|
||||
CheckConstraint(
|
||||
"zielgruppe IN ('alterspflege','beduerftige','behinderte')",
|
||||
name="ck_patient_zielgruppe",
|
||||
),
|
||||
CheckConstraint(
|
||||
"patient_status IN ('aktiv','archiviert','verstorben')",
|
||||
name="ck_patient_status",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
vorname: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
nachname: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
geburtsdatum: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
strasse: Mapped[str | None] = mapped_column(String(200))
|
||||
plz: Mapped[str | None] = mapped_column(String(20))
|
||||
ort: Mapped[str | None] = mapped_column(String(100))
|
||||
telefon: Mapped[str | None] = mapped_column(String(50))
|
||||
email: Mapped[str | None] = mapped_column(String(200))
|
||||
krankenkasse: Mapped[str | None] = mapped_column(String(200))
|
||||
versichertennummer: Mapped[str | None] = mapped_column(String(50))
|
||||
versicherungsart: Mapped[str] = mapped_column(String(10), nullable=False, default="GKV")
|
||||
pflegegrad: Mapped[int] = mapped_column(nullable=False, default=0)
|
||||
pflegeperson: Mapped[str | None] = mapped_column(String(200))
|
||||
zielgruppe: Mapped[str] = mapped_column(String(20), nullable=False, default="alterspflege")
|
||||
notizen: Mapped[str | None] = mapped_column(Text)
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
geaendert_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
patient_status: Mapped[str] = mapped_column(String(20), nullable=False, default="aktiv")
|
||||
status_datum: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
archiv_frist: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
archiv_hinweis: Mapped[str | None] = mapped_column(Text)
|
||||
foto_pfad: Mapped[str | None] = mapped_column(String(500))
|
||||
nutzer_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("nutzer.id", ondelete="RESTRICT"), nullable=False
|
||||
)
|
||||
|
||||
nutzer: Mapped["Nutzer"] = relationship(back_populates="patienten")
|
||||
antraege: Mapped[list["Antrag"]] = relationship(
|
||||
back_populates="patient", cascade="all, delete-orphan"
|
||||
)
|
||||
leistungen: Mapped[list["Leistung"]] = relationship(
|
||||
back_populates="patient", cascade="all, delete-orphan"
|
||||
)
|
||||
aufgaben: Mapped[list["Aufgabe"]] = relationship(back_populates="patient")
|
||||
tagebuch: Mapped[list["PflegetagebuchEintrag"]] = relationship(
|
||||
back_populates="patient", cascade="all, delete-orphan"
|
||||
)
|
||||
dokumente: Mapped[list["Dokument"]] = relationship(
|
||||
back_populates="patient", cascade="all, delete-orphan"
|
||||
)
|
||||
notizen_verlauf: Mapped[list["NotizVerlauf"]] = relationship(
|
||||
back_populates="patient", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
class Antrag(Base):
|
||||
__tablename__ = "antraege"
|
||||
__table_args__ = (
|
||||
CheckConstraint(
|
||||
"typ IN ('erstantrag','widerspruch','hoeherst')", name="ck_antrag_typ"
|
||||
),
|
||||
CheckConstraint(
|
||||
"status IN ('offen','eingereicht','in_pruefung','genehmigt','abgelehnt')",
|
||||
name="ck_antrag_status",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
patient_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("patienten.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
typ: Mapped[str] = mapped_column(String(20), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(20), nullable=False, default="offen")
|
||||
antragsdatum: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
bescheid_datum: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
widerspruch_frist: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
gutachter_termin: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
beantragter_pflegegrad: Mapped[int | None]
|
||||
zugeteilter_pflegegrad: Mapped[int | None]
|
||||
notizen: Mapped[str | None] = mapped_column(Text)
|
||||
brief_text: Mapped[str | None] = mapped_column(Text)
|
||||
pdf_pfad: Mapped[str | None] = mapped_column(String(500))
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
patient: Mapped["Patient"] = relationship(back_populates="antraege")
|
||||
|
||||
|
||||
class Leistung(Base):
|
||||
__tablename__ = "leistungen"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
patient_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("patienten.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
typ: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
bezeichnung: Mapped[str] = mapped_column(String(300), nullable=False)
|
||||
betrag: Mapped[decimal.Decimal | None] = mapped_column(Numeric(10, 2))
|
||||
einheit: Mapped[str] = mapped_column(String(20), nullable=False, default="monatlich")
|
||||
aktiv: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
||||
seit: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
katalog_id: Mapped[str | None] = mapped_column(String(50))
|
||||
notizen: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
patient: Mapped["Patient"] = relationship(back_populates="leistungen")
|
||||
|
||||
|
||||
class Aufgabe(Base):
|
||||
__tablename__ = "aufgaben"
|
||||
__table_args__ = (
|
||||
CheckConstraint("prioritaet IN ('hoch','mittel','normal')", name="ck_aufgabe_prioritaet"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
patient_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("patienten.id", ondelete="CASCADE")
|
||||
)
|
||||
titel: Mapped[str] = mapped_column(String(300), nullable=False)
|
||||
beschreibung: Mapped[str | None] = mapped_column(Text)
|
||||
faellig_am: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
prioritaet: Mapped[str] = mapped_column(String(20), nullable=False, default="normal")
|
||||
erledigt: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
patient: Mapped["Patient | None"] = relationship(back_populates="aufgaben")
|
||||
|
||||
|
||||
class PflegetagebuchEintrag(Base):
|
||||
__tablename__ = "pflegetagebuch"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
patient_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("patienten.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
datum: Mapped[datetime.date] = mapped_column(Date, nullable=False)
|
||||
koerperpflege: Mapped[str | None] = mapped_column(Text)
|
||||
anziehen: Mapped[str | None] = mapped_column(Text)
|
||||
ernaehrung: Mapped[str | None] = mapped_column(Text)
|
||||
mobilitaet: Mapped[str | None] = mapped_column(Text)
|
||||
orientierung: Mapped[str | None] = mapped_column(Text)
|
||||
medikamente: Mapped[str | None] = mapped_column(Text)
|
||||
soziales: Mapped[str | None] = mapped_column(Text)
|
||||
allgemein: Mapped[str | None] = mapped_column(Text)
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
patient: Mapped["Patient"] = relationship(back_populates="tagebuch")
|
||||
|
||||
|
||||
class Einstellung(Base):
|
||||
__tablename__ = "einstellungen"
|
||||
|
||||
schluessel: Mapped[str] = mapped_column(String(100), primary_key=True)
|
||||
wert: Mapped[str | None] = mapped_column(Text)
|
||||
|
||||
|
||||
class Dokument(Base):
|
||||
__tablename__ = "dokumente"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
patient_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("patienten.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
typ: Mapped[str] = mapped_column(String(50), nullable=False, default="sonstiges")
|
||||
bezeichnung: Mapped[str] = mapped_column(String(300), nullable=False)
|
||||
dateiname: Mapped[str] = mapped_column(String(300), nullable=False)
|
||||
pfad: Mapped[str] = mapped_column(String(500), nullable=False)
|
||||
datum: Mapped[datetime.date | None] = mapped_column(Date)
|
||||
notizen: Mapped[str | None] = mapped_column(Text)
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
patient: Mapped["Patient"] = relationship(back_populates="dokumente")
|
||||
|
||||
|
||||
class AdminAuditLog(Base):
|
||||
__tablename__ = "admin_audit_log"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
# Bewusst KEIN ForeignKey: der Audit-Trail muss eine Nutzer-Loeschung ueberleben.
|
||||
admin_id: Mapped[int | None]
|
||||
admin_name: Mapped[str | None] = mapped_column(String(200))
|
||||
aktion: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
ziel_typ: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
ziel_id: Mapped[int | None]
|
||||
ziel_bezeichnung: Mapped[str | None] = mapped_column(String(300))
|
||||
begruendung: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
|
||||
class NotizVerlauf(Base):
|
||||
__tablename__ = "notizen_verlauf"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
patient_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("patienten.id", ondelete="CASCADE"), nullable=False
|
||||
)
|
||||
notizen_alt: Mapped[str | None] = mapped_column(Text)
|
||||
notizen_neu: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
aenderungsgrund: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
geaendert_von: Mapped[str] = mapped_column(String(200), nullable=False, default="Nutzer")
|
||||
geaendert_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
patient: Mapped["Patient"] = relationship(back_populates="notizen_verlauf")
|
||||
|
||||
|
||||
class ChangelogEintrag(Base):
|
||||
__tablename__ = "changelog_eintraege"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
version: Mapped[str] = mapped_column(String(20), nullable=False)
|
||||
datum: Mapped[datetime.date] = mapped_column(Date, nullable=False)
|
||||
titel: Mapped[str] = mapped_column(String(300), nullable=False)
|
||||
punkte: Mapped[list[str]] = mapped_column(JSONB, nullable=False)
|
||||
erstellt_am: Mapped[datetime.datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
@@ -0,0 +1,9 @@
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from weasyprint import HTML
|
||||
|
||||
_env = Environment(loader=FileSystemLoader("app/pdf_templates"))
|
||||
|
||||
|
||||
def render_pdf(template_name: str, **context) -> bytes:
|
||||
html = _env.get_template(template_name).render(**context)
|
||||
return HTML(string=html).write_pdf()
|
||||
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
body { font-family: sans-serif; padding: 40px; }
|
||||
h1 { color: #2c3e50; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Pflegepilot v3 – WeasyPrint-Smoke-Test</h1>
|
||||
<p>Wenn du dieses PDF siehst, funktioniert die serverseitige PDF-Erzeugung im Docker-Image.</p>
|
||||
<p>Erzeugt am: {{ zeitpunkt }}</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
import time
|
||||
|
||||
# Einfaches In-Memory-Rate-Limiting pro IP+Zweck, wie im Sicherheits-Audit der
|
||||
# alten App (kein Redis/externer Store noetig fuer ein Solo-Projekt). Gilt
|
||||
# pro Gunicorn-Worker, nicht global ueber alle Worker hinweg - fuer die
|
||||
# aktuelle Groessenordnung ausreichend.
|
||||
_hits: dict[tuple[str, str], list[float]] = {}
|
||||
|
||||
|
||||
def is_rate_limited(zweck: str, ip: str, max_versuche: int, fenster_sekunden: int) -> bool:
|
||||
key = (zweck, ip)
|
||||
now = time.time()
|
||||
versuche = [t for t in _hits.get(key, []) if now - t < fenster_sekunden]
|
||||
versuche.append(now)
|
||||
_hits[key] = versuche
|
||||
return len(versuche) > max_versuche
|
||||
Whitespace-only changes.
@@ -0,0 +1,95 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db import get_db
|
||||
from app.deps import get_current_user
|
||||
from app.models import Nutzer
|
||||
from app.ratelimit import is_rate_limited
|
||||
from app.schemas import AuthResponse, LoginRequest, MeResponse, RegistrierenRequest
|
||||
from app.security import client_ip, hash_password, verify_password
|
||||
|
||||
router = APIRouter(prefix="/api/auth", tags=["auth"])
|
||||
|
||||
|
||||
def _stempel_login(db: Session, user: Nutzer, request: Request) -> None:
|
||||
user.letzter_login = datetime.now(timezone.utc)
|
||||
user.letzte_ip = client_ip(request)
|
||||
db.commit()
|
||||
|
||||
|
||||
@router.post("/login", response_model=AuthResponse)
|
||||
def login(payload: LoginRequest, request: Request, db: Session = Depends(get_db)):
|
||||
if is_rate_limited("login", client_ip(request), max_versuche=10, fenster_sekunden=300):
|
||||
raise HTTPException(status_code=429, detail="Zu viele Versuche, bitte später erneut versuchen.")
|
||||
|
||||
user = (
|
||||
db.query(Nutzer)
|
||||
.filter(Nutzer.benutzername == payload.benutzername.strip(), Nutzer.aktiv.is_(True))
|
||||
.first()
|
||||
)
|
||||
if not user or not verify_password(payload.passwort, user.passwort_hash):
|
||||
raise HTTPException(status_code=401, detail="Ungültige Zugangsdaten")
|
||||
|
||||
request.session["nutzer_id"] = user.id
|
||||
_stempel_login(db, user, request)
|
||||
return AuthResponse(name=user.name or user.benutzername, rolle=user.rolle, ist_demo=user.ist_demo)
|
||||
|
||||
|
||||
@router.post("/registrieren", response_model=AuthResponse)
|
||||
def registrieren(payload: RegistrierenRequest, request: Request, db: Session = Depends(get_db)):
|
||||
if is_rate_limited("registrieren", client_ip(request), max_versuche=5, fenster_sekunden=600):
|
||||
raise HTTPException(status_code=429, detail="Zu viele Versuche, bitte später erneut versuchen.")
|
||||
|
||||
benutzername = payload.benutzername.strip()
|
||||
if not benutzername or not payload.passwort or not payload.name.strip():
|
||||
raise HTTPException(status_code=400, detail="Benutzername, Passwort und Name erforderlich")
|
||||
if len(payload.passwort) < 6:
|
||||
raise HTTPException(status_code=400, detail="Passwort muss mindestens 6 Zeichen lang sein")
|
||||
if not (payload.rg_name and payload.rg_strasse and payload.rg_plz and payload.rg_ort):
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Rechnungsanschrift (Name, Straße, PLZ, Ort) ist erforderlich"
|
||||
)
|
||||
|
||||
if db.query(Nutzer).filter(Nutzer.benutzername == benutzername).first():
|
||||
raise HTTPException(status_code=409, detail="Benutzername bereits vergeben")
|
||||
|
||||
user = Nutzer(
|
||||
benutzername=benutzername,
|
||||
passwort_hash=hash_password(payload.passwort),
|
||||
name=payload.name.strip(),
|
||||
rolle="nutzer",
|
||||
rg_name=payload.rg_name,
|
||||
rg_strasse=payload.rg_strasse,
|
||||
rg_plz=payload.rg_plz,
|
||||
rg_ort=payload.rg_ort,
|
||||
selbst_registriert=True,
|
||||
)
|
||||
db.add(user)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
|
||||
request.session["nutzer_id"] = user.id
|
||||
_stempel_login(db, user, request)
|
||||
return AuthResponse(name=user.name or user.benutzername, rolle="nutzer", ist_demo=False)
|
||||
|
||||
|
||||
@router.post("/logout")
|
||||
def logout(request: Request):
|
||||
request.session.clear()
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/me", response_model=MeResponse)
|
||||
def me(user: Nutzer | None = Depends(get_current_user)):
|
||||
if user is None:
|
||||
raise HTTPException(status_code=401, detail="Nicht angemeldet")
|
||||
return MeResponse(
|
||||
id=user.id,
|
||||
benutzername=user.benutzername,
|
||||
name=user.name,
|
||||
rolle=user.rolle,
|
||||
ist_demo=user.ist_demo,
|
||||
selbst_registriert=user.selbst_registriert,
|
||||
)
|
||||
@@ -0,0 +1,32 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class LoginRequest(BaseModel):
|
||||
benutzername: str
|
||||
passwort: str
|
||||
|
||||
|
||||
class RegistrierenRequest(BaseModel):
|
||||
benutzername: str
|
||||
passwort: str
|
||||
name: str
|
||||
rg_name: str
|
||||
rg_strasse: str
|
||||
rg_plz: str
|
||||
rg_ort: str
|
||||
|
||||
|
||||
class AuthResponse(BaseModel):
|
||||
ok: bool = True
|
||||
name: str
|
||||
rolle: str
|
||||
ist_demo: bool
|
||||
|
||||
|
||||
class MeResponse(BaseModel):
|
||||
id: int
|
||||
benutzername: str
|
||||
name: str | None
|
||||
rolle: str
|
||||
ist_demo: bool
|
||||
selbst_registriert: bool
|
||||
@@ -0,0 +1,25 @@
|
||||
import re
|
||||
|
||||
from fastapi import Request
|
||||
from passlib.context import CryptContext
|
||||
|
||||
_pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
return _pwd_context.hash(password)
|
||||
|
||||
|
||||
def verify_password(password: str, password_hash: str) -> bool:
|
||||
return _pwd_context.verify(password, password_hash)
|
||||
|
||||
|
||||
def client_ip(request: Request) -> str:
|
||||
"""Client-IP aus X-Forwarded-For (erster Hop) oder direkter Verbindung,
|
||||
serverseitig auf IPv4/IPv6-Zeichen beschraenkt bevor sie je gespeichert
|
||||
wird (Stored-XSS-Vorbeugung, siehe Sicherheits-Audit der alten App)."""
|
||||
forwarded = request.headers.get("x-forwarded-for", "")
|
||||
ip = forwarded.split(",")[0].strip() if forwarded else ""
|
||||
if not ip and request.client:
|
||||
ip = request.client.host
|
||||
return re.sub(r"[^0-9a-fA-F.:]", "", ip)[:45]
|
||||
@@ -0,0 +1,108 @@
|
||||
"""Anlegen des Admin-Kontos + Demo-Konto/-Patient.
|
||||
|
||||
Bewusst NICHT automatisch beim Container-Start ausgefuehrt (anders als das
|
||||
alte init_db(), das admin/admin hartkodiert anlegte) - Admin-Zugangsdaten
|
||||
werden gemeinsam mit dem Betreiber festgelegt, nie hartkodiert im Code.
|
||||
|
||||
Zwei Aufrufarten:
|
||||
- Interaktiv (echtes Terminal, z.B. bei einem spaeteren echten Deployment):
|
||||
docker compose exec -it api python -m app.seed
|
||||
- Nicht-interaktiv (Werte vorher gemeinsam festgelegt, z.B. ueber die
|
||||
Shell einer Automatisierung ohne TTY-Weiterleitung):
|
||||
ADMIN_BENUTZERNAME=... ADMIN_PASSWORT=... ADMIN_NAME=... \\
|
||||
docker compose exec -T api python -m app.seed
|
||||
"""
|
||||
|
||||
import getpass
|
||||
import os
|
||||
import sys
|
||||
|
||||
from app.db import SessionLocal
|
||||
from app.models import Nutzer, Patient
|
||||
from app.security import hash_password
|
||||
|
||||
|
||||
def _seed_admin(db):
|
||||
if db.query(Nutzer).filter(Nutzer.rolle == "admin").first():
|
||||
print("Admin-Konto existiert bereits - übersprungen.")
|
||||
return
|
||||
|
||||
env_benutzername = os.environ.get("ADMIN_BENUTZERNAME")
|
||||
env_passwort = os.environ.get("ADMIN_PASSWORT")
|
||||
|
||||
if env_benutzername and env_passwort:
|
||||
benutzername = env_benutzername.strip()
|
||||
passwort = env_passwort
|
||||
name = os.environ.get("ADMIN_NAME", "Administrator").strip() or "Administrator"
|
||||
if len(passwort) < 6:
|
||||
print("ADMIN_PASSWORT muss mindestens 6 Zeichen lang sein.")
|
||||
sys.exit(1)
|
||||
elif sys.stdin.isatty():
|
||||
print("--- Admin-Konto anlegen ---")
|
||||
benutzername = input("Benutzername: ").strip()
|
||||
while True:
|
||||
passwort = getpass.getpass("Passwort (min. 6 Zeichen): ")
|
||||
if len(passwort) >= 6:
|
||||
break
|
||||
print("Zu kurz, bitte erneut.")
|
||||
name = input("Anzeigename [Administrator]: ").strip() or "Administrator"
|
||||
else:
|
||||
print(
|
||||
"Kein Terminal verfügbar. Entweder interaktiv ausführen "
|
||||
"(docker compose exec -it api python -m app.seed) oder "
|
||||
"ADMIN_BENUTZERNAME/ADMIN_PASSWORT/ADMIN_NAME als Env-Var setzen."
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
db.add(
|
||||
Nutzer(
|
||||
benutzername=benutzername,
|
||||
passwort_hash=hash_password(passwort),
|
||||
name=name,
|
||||
rolle="admin",
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
print(f"Admin-Konto '{benutzername}' angelegt.")
|
||||
|
||||
|
||||
def _seed_demo(db):
|
||||
demo = db.query(Nutzer).filter(Nutzer.benutzername == "demo").first()
|
||||
if demo:
|
||||
print("Demo-Konto existiert bereits - übersprungen.")
|
||||
return
|
||||
|
||||
demo = Nutzer(
|
||||
benutzername="demo",
|
||||
passwort_hash=hash_password("demo"),
|
||||
name="Demo",
|
||||
rolle="nutzer",
|
||||
ist_demo=True,
|
||||
)
|
||||
db.add(demo)
|
||||
db.flush()
|
||||
|
||||
db.add(
|
||||
Patient(
|
||||
vorname="Grete",
|
||||
nachname="Musterfrau",
|
||||
pflegegrad=3,
|
||||
zielgruppe="alterspflege",
|
||||
nutzer_id=demo.id,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
print("Demo-Konto 'demo'/'demo' + Demo-Patient angelegt.")
|
||||
|
||||
|
||||
def main():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
_seed_admin(db)
|
||||
_seed_demo(db)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,46 @@
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from app import models # noqa: F401 - Modelle registrieren sich an Base.metadata
|
||||
from app.config import settings
|
||||
from app.db import Base
|
||||
|
||||
config = context.config
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
config.set_main_option("sqlalchemy.url", settings.database_url)
|
||||
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url,
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
with connectable.connect() as connection:
|
||||
context.configure(connection=connection, target_metadata=target_metadata)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
@@ -0,0 +1,24 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = ${repr(up_revision)}
|
||||
down_revision = ${repr(down_revision)}
|
||||
branch_labels = ${repr(branch_labels)}
|
||||
depends_on = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,205 @@
|
||||
"""initial schema
|
||||
|
||||
Revision ID: e5123d08fdb6
|
||||
Revises:
|
||||
Create Date: 2026-07-19 13:19:03.907546
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'e5123d08fdb6'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('admin_audit_log',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('admin_id', sa.Integer(), nullable=True),
|
||||
sa.Column('admin_name', sa.String(length=200), nullable=True),
|
||||
sa.Column('aktion', sa.String(length=100), nullable=False),
|
||||
sa.Column('ziel_typ', sa.String(length=50), nullable=False),
|
||||
sa.Column('ziel_id', sa.Integer(), nullable=True),
|
||||
sa.Column('ziel_bezeichnung', sa.String(length=300), nullable=True),
|
||||
sa.Column('begruendung', sa.Text(), nullable=False),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('changelog_eintraege',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('version', sa.String(length=20), nullable=False),
|
||||
sa.Column('datum', sa.Date(), nullable=False),
|
||||
sa.Column('titel', sa.String(length=300), nullable=False),
|
||||
sa.Column('punkte', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('einstellungen',
|
||||
sa.Column('schluessel', sa.String(length=100), nullable=False),
|
||||
sa.Column('wert', sa.Text(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('schluessel')
|
||||
)
|
||||
op.create_table('nutzer',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('benutzername', sa.String(length=100), nullable=False),
|
||||
sa.Column('passwort_hash', sa.String(length=255), nullable=False),
|
||||
sa.Column('name', sa.String(length=200), nullable=True),
|
||||
sa.Column('rolle', sa.String(length=20), nullable=False),
|
||||
sa.Column('aktiv', sa.Boolean(), nullable=False),
|
||||
sa.Column('abo_bis', sa.Date(), nullable=True),
|
||||
sa.Column('abo_typ', sa.String(length=50), nullable=True),
|
||||
sa.Column('ist_demo', sa.Boolean(), nullable=False),
|
||||
sa.Column('letzte_gesehene_version', sa.String(length=20), nullable=True),
|
||||
sa.Column('letzter_login', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('letzte_ip', sa.String(length=45), nullable=True),
|
||||
sa.Column('rg_name', sa.String(length=200), nullable=True),
|
||||
sa.Column('rg_strasse', sa.String(length=200), nullable=True),
|
||||
sa.Column('rg_plz', sa.String(length=20), nullable=True),
|
||||
sa.Column('rg_ort', sa.String(length=100), nullable=True),
|
||||
sa.Column('selbst_registriert', sa.Boolean(), nullable=False),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.CheckConstraint("rolle IN ('nutzer','admin')", name='ck_nutzer_rolle'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('benutzername')
|
||||
)
|
||||
op.create_table('patienten',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('vorname', sa.String(length=100), nullable=False),
|
||||
sa.Column('nachname', sa.String(length=100), nullable=False),
|
||||
sa.Column('geburtsdatum', sa.Date(), nullable=True),
|
||||
sa.Column('strasse', sa.String(length=200), nullable=True),
|
||||
sa.Column('plz', sa.String(length=20), nullable=True),
|
||||
sa.Column('ort', sa.String(length=100), nullable=True),
|
||||
sa.Column('telefon', sa.String(length=50), nullable=True),
|
||||
sa.Column('email', sa.String(length=200), nullable=True),
|
||||
sa.Column('krankenkasse', sa.String(length=200), nullable=True),
|
||||
sa.Column('versichertennummer', sa.String(length=50), nullable=True),
|
||||
sa.Column('versicherungsart', sa.String(length=10), nullable=False),
|
||||
sa.Column('pflegegrad', sa.Integer(), nullable=False),
|
||||
sa.Column('pflegeperson', sa.String(length=200), nullable=True),
|
||||
sa.Column('zielgruppe', sa.String(length=20), nullable=False),
|
||||
sa.Column('notizen', sa.Text(), nullable=True),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('geaendert_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('patient_status', sa.String(length=20), nullable=False),
|
||||
sa.Column('status_datum', sa.Date(), nullable=True),
|
||||
sa.Column('archiv_frist', sa.Date(), nullable=True),
|
||||
sa.Column('archiv_hinweis', sa.Text(), nullable=True),
|
||||
sa.Column('foto_pfad', sa.String(length=500), nullable=True),
|
||||
sa.Column('nutzer_id', sa.Integer(), nullable=False),
|
||||
sa.CheckConstraint("patient_status IN ('aktiv','archiviert','verstorben')", name='ck_patient_status'),
|
||||
sa.CheckConstraint("versicherungsart IN ('GKV','PKV')", name='ck_patient_versicherungsart'),
|
||||
sa.CheckConstraint("zielgruppe IN ('alterspflege','beduerftige','behinderte')", name='ck_patient_zielgruppe'),
|
||||
sa.CheckConstraint('pflegegrad BETWEEN 0 AND 5', name='ck_patient_pflegegrad'),
|
||||
sa.ForeignKeyConstraint(['nutzer_id'], ['nutzer.id'], ondelete='RESTRICT'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('antraege',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||||
sa.Column('typ', sa.String(length=20), nullable=False),
|
||||
sa.Column('status', sa.String(length=20), nullable=False),
|
||||
sa.Column('antragsdatum', sa.Date(), nullable=True),
|
||||
sa.Column('bescheid_datum', sa.Date(), nullable=True),
|
||||
sa.Column('widerspruch_frist', sa.Date(), nullable=True),
|
||||
sa.Column('gutachter_termin', sa.Date(), nullable=True),
|
||||
sa.Column('beantragter_pflegegrad', sa.Integer(), nullable=True),
|
||||
sa.Column('zugeteilter_pflegegrad', sa.Integer(), nullable=True),
|
||||
sa.Column('notizen', sa.Text(), nullable=True),
|
||||
sa.Column('brief_text', sa.Text(), nullable=True),
|
||||
sa.Column('pdf_pfad', sa.String(length=500), nullable=True),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.CheckConstraint("status IN ('offen','eingereicht','in_pruefung','genehmigt','abgelehnt')", name='ck_antrag_status'),
|
||||
sa.CheckConstraint("typ IN ('erstantrag','widerspruch','hoeherst')", name='ck_antrag_typ'),
|
||||
sa.ForeignKeyConstraint(['patient_id'], ['patienten.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('aufgaben',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('patient_id', sa.Integer(), nullable=True),
|
||||
sa.Column('titel', sa.String(length=300), nullable=False),
|
||||
sa.Column('beschreibung', sa.Text(), nullable=True),
|
||||
sa.Column('faellig_am', sa.Date(), nullable=True),
|
||||
sa.Column('prioritaet', sa.String(length=20), nullable=False),
|
||||
sa.Column('erledigt', sa.Boolean(), nullable=False),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.CheckConstraint("prioritaet IN ('hoch','mittel','normal')", name='ck_aufgabe_prioritaet'),
|
||||
sa.ForeignKeyConstraint(['patient_id'], ['patienten.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('dokumente',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||||
sa.Column('typ', sa.String(length=50), nullable=False),
|
||||
sa.Column('bezeichnung', sa.String(length=300), nullable=False),
|
||||
sa.Column('dateiname', sa.String(length=300), nullable=False),
|
||||
sa.Column('pfad', sa.String(length=500), nullable=False),
|
||||
sa.Column('datum', sa.Date(), nullable=True),
|
||||
sa.Column('notizen', sa.Text(), nullable=True),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['patient_id'], ['patienten.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('leistungen',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||||
sa.Column('typ', sa.String(length=50), nullable=False),
|
||||
sa.Column('bezeichnung', sa.String(length=300), nullable=False),
|
||||
sa.Column('betrag', sa.Numeric(precision=10, scale=2), nullable=True),
|
||||
sa.Column('einheit', sa.String(length=20), nullable=False),
|
||||
sa.Column('aktiv', sa.Boolean(), nullable=False),
|
||||
sa.Column('seit', sa.Date(), nullable=True),
|
||||
sa.Column('katalog_id', sa.String(length=50), nullable=True),
|
||||
sa.Column('notizen', sa.Text(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['patient_id'], ['patienten.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('notizen_verlauf',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||||
sa.Column('notizen_alt', sa.Text(), nullable=True),
|
||||
sa.Column('notizen_neu', sa.Text(), nullable=False),
|
||||
sa.Column('aenderungsgrund', sa.Text(), nullable=False),
|
||||
sa.Column('geaendert_von', sa.String(length=200), nullable=False),
|
||||
sa.Column('geaendert_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['patient_id'], ['patienten.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('pflegetagebuch',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('patient_id', sa.Integer(), nullable=False),
|
||||
sa.Column('datum', sa.Date(), nullable=False),
|
||||
sa.Column('koerperpflege', sa.Text(), nullable=True),
|
||||
sa.Column('anziehen', sa.Text(), nullable=True),
|
||||
sa.Column('ernaehrung', sa.Text(), nullable=True),
|
||||
sa.Column('mobilitaet', sa.Text(), nullable=True),
|
||||
sa.Column('orientierung', sa.Text(), nullable=True),
|
||||
sa.Column('medikamente', sa.Text(), nullable=True),
|
||||
sa.Column('soziales', sa.Text(), nullable=True),
|
||||
sa.Column('allgemein', sa.Text(), nullable=True),
|
||||
sa.Column('erstellt_am', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['patient_id'], ['patienten.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('pflegetagebuch')
|
||||
op.drop_table('notizen_verlauf')
|
||||
op.drop_table('leistungen')
|
||||
op.drop_table('dokumente')
|
||||
op.drop_table('aufgaben')
|
||||
op.drop_table('antraege')
|
||||
op.drop_table('patienten')
|
||||
op.drop_table('nutzer')
|
||||
op.drop_table('einstellungen')
|
||||
op.drop_table('changelog_eintraege')
|
||||
op.drop_table('admin_audit_log')
|
||||
# ### end Alembic commands ###
|
||||
@@ -0,0 +1,16 @@
|
||||
fastapi>=0.115,<1
|
||||
uvicorn[standard]>=0.32,<1
|
||||
gunicorn>=23,<24
|
||||
sqlalchemy>=2.0,<3
|
||||
alembic>=1.13,<2
|
||||
psycopg[binary]>=3.2,<4
|
||||
pydantic-settings>=2.6,<3
|
||||
passlib[bcrypt]>=1.7,<2
|
||||
# passlibs interne bcrypt-Selbsttest-Routine bricht mit bcrypt>=4.1 (siehe
|
||||
# https://github.com/pyca/bcrypt/issues/684) - bewusst gepinnt statt auf einen
|
||||
# passlib-Fix zu warten (Projekt wirkt unmaintained, letzter Release 2020)
|
||||
bcrypt<4.1
|
||||
python-multipart>=0.0.12
|
||||
jinja2>=3.1,<4
|
||||
weasyprint>=63,<64
|
||||
itsdangerous>=2.2,<3
|
||||
@@ -0,0 +1,43 @@
|
||||
services:
|
||||
db:
|
||||
image: postgres:16
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
ports:
|
||||
- "${POSTGRES_PORT:-5532}:5432"
|
||||
volumes:
|
||||
- pflegepilot_v3_db:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
api:
|
||||
build: ./backend
|
||||
environment:
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
SECRET_KEY: ${SECRET_KEY}
|
||||
WEB_ORIGIN: ${WEB_ORIGIN}
|
||||
ports:
|
||||
- "${API_PORT:-8100}:5050"
|
||||
volumes:
|
||||
- pflegepilot_v3_uploads:/app/app/uploads
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
web:
|
||||
build: ./frontend
|
||||
environment:
|
||||
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL}
|
||||
ports:
|
||||
- "${WEB_PORT:-3100}:3000"
|
||||
depends_on:
|
||||
- api
|
||||
|
||||
volumes:
|
||||
pflegepilot_v3_db:
|
||||
pflegepilot_v3_uploads:
|
||||
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
.next
|
||||
.env*
|
||||
@@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
@@ -0,0 +1,5 @@
|
||||
<!-- BEGIN:nextjs-agent-rules -->
|
||||
# This is NOT the Next.js you know
|
||||
|
||||
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` before writing any code. Heed deprecation notices.
|
||||
<!-- END:nextjs-agent-rules -->
|
||||
@@ -0,0 +1 @@
|
||||
@AGENTS.md
|
||||
@@ -0,0 +1,14 @@
|
||||
# Entwicklungs-Image (next dev). Produktions-Build (Next standalone) folgt
|
||||
# in Phase 7, siehe Plan-Datei - fuer die fruehen Phasen reicht der Dev-Server.
|
||||
FROM node:22-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["npm", "run", "dev", "--", "--hostname", "0.0.0.0"]
|
||||
@@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
||||
@@ -0,0 +1,18 @@
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||
import nextTs from "eslint-config-next/typescript";
|
||||
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
".next/**",
|
||||
"out/**",
|
||||
"build/**",
|
||||
"next-env.d.ts",
|
||||
]),
|
||||
]);
|
||||
|
||||
export default eslintConfig;
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
/* config options here */
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
+6731
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "eslint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.101.2",
|
||||
"next": "16.2.10",
|
||||
"react": "19.2.4",
|
||||
"react-dom": "19.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "16.2.10",
|
||||
"tailwindcss": "^4",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||
|
After Width: | Height: | Size: 391 B |
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||
|
After Width: | Height: | Size: 128 B |
@@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||
|
After Width: | Height: | Size: 385 B |
@@ -0,0 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { useAuth } from "@/lib/auth";
|
||||
|
||||
export default function DashboardPage() {
|
||||
const { meQuery, logout } = useAuth();
|
||||
const me = meQuery.data;
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-2xl p-8">
|
||||
<h1 className="text-2xl font-semibold text-slate-800">Dashboard</h1>
|
||||
<p className="mt-2 text-slate-600">
|
||||
Eingeloggt als <strong>{me?.name ?? me?.benutzername}</strong> ({me?.rolle})
|
||||
{me?.ist_demo && " · Demo-Konto"}
|
||||
</p>
|
||||
<button
|
||||
onClick={() => logout.mutate()}
|
||||
className="mt-6 rounded-lg border border-slate-300 px-3 py-2 text-sm text-slate-700"
|
||||
>
|
||||
Abmelden
|
||||
</button>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import { AuthOverlay } from "@/components/AuthOverlay";
|
||||
|
||||
export default function AppLayout({ children }: { children: React.ReactNode }) {
|
||||
const { meQuery } = useAuth();
|
||||
|
||||
if (meQuery.isLoading) {
|
||||
return <div className="flex min-h-screen items-center justify-center text-slate-400">Lädt…</div>;
|
||||
}
|
||||
|
||||
if (!meQuery.data) {
|
||||
return <AuthOverlay />;
|
||||
}
|
||||
|
||||
return <div className="min-h-screen bg-slate-50">{children}</div>;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import Link from "next/link";
|
||||
|
||||
export default function LandingPage() {
|
||||
return (
|
||||
<main className="mx-auto flex max-w-3xl flex-1 flex-col items-center justify-center gap-6 p-8 text-center">
|
||||
<h1 className="text-3xl font-semibold text-slate-800">Pflegepilot</h1>
|
||||
<p className="max-w-md text-slate-600">
|
||||
Pflegeplanung für pflegende Angehörige – Anträge, Leistungen und Fristen im Blick.
|
||||
</p>
|
||||
<Link
|
||||
href="/dashboard"
|
||||
className="rounded-lg bg-slate-800 px-5 py-2.5 text-sm font-medium text-white"
|
||||
>
|
||||
Zur App
|
||||
</Link>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@@ -0,0 +1,26 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
--background: #ffffff;
|
||||
--foreground: #171717;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
--color-background: var(--background);
|
||||
--color-foreground: var(--foreground);
|
||||
--font-sans: var(--font-geist-sans);
|
||||
--font-mono: var(--font-geist-mono);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--background: #0a0a0a;
|
||||
--foreground: #ededed;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--background);
|
||||
color: var(--foreground);
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import { Providers } from "./providers";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Pflegepilot",
|
||||
description: "Pflegeplanung für pflegende Angehörige",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html
|
||||
lang="de"
|
||||
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
|
||||
>
|
||||
<body className="min-h-full flex flex-col">
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useState } from "react";
|
||||
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
const [queryClient] = useState(() => new QueryClient());
|
||||
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import { ApiError } from "@/lib/api";
|
||||
|
||||
export function AuthOverlay() {
|
||||
const [mode, setMode] = useState<"login" | "register">("login");
|
||||
const { login, registrieren } = useAuth();
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 p-4">
|
||||
<div className="w-full max-w-sm rounded-2xl bg-white p-8 shadow-xl">
|
||||
<h1 className="mb-1 text-xl font-semibold text-slate-800">Pflegepilot</h1>
|
||||
<p className="mb-6 text-sm text-slate-500">
|
||||
{mode === "login" ? "Bitte melde dich an." : "Neues Konto anlegen."}
|
||||
</p>
|
||||
|
||||
{mode === "login" ? (
|
||||
<LoginForm
|
||||
onSwitch={() => setMode("register")}
|
||||
onLogin={(payload) => login.mutate(payload)}
|
||||
error={login.isError ? (login.error as ApiError).message : null}
|
||||
pending={login.isPending}
|
||||
/>
|
||||
) : (
|
||||
<RegisterForm
|
||||
onSwitch={() => setMode("login")}
|
||||
onRegister={(payload) => registrieren.mutate(payload)}
|
||||
error={registrieren.isError ? (registrieren.error as ApiError).message : null}
|
||||
pending={registrieren.isPending}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LoginForm({
|
||||
onSwitch,
|
||||
onLogin,
|
||||
error,
|
||||
pending,
|
||||
}: {
|
||||
onSwitch: () => void;
|
||||
onLogin: (payload: { benutzername: string; passwort: string }) => void;
|
||||
error: string | null;
|
||||
pending: boolean;
|
||||
}) {
|
||||
const [benutzername, setBenutzername] = useState("");
|
||||
const [passwort, setPasswort] = useState("");
|
||||
const { login } = useAuth();
|
||||
|
||||
return (
|
||||
<form
|
||||
className="flex flex-col gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
onLogin({ benutzername, passwort });
|
||||
}}
|
||||
>
|
||||
<input
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Benutzername"
|
||||
value={benutzername}
|
||||
onChange={(e) => setBenutzername(e.target.value)}
|
||||
autoComplete="username"
|
||||
/>
|
||||
<input
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Passwort"
|
||||
type="password"
|
||||
value={passwort}
|
||||
onChange={(e) => setPasswort(e.target.value)}
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={pending}
|
||||
className="rounded-lg bg-slate-800 px-3 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
Anmelden
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => login.mutate({ benutzername: "demo", passwort: "demo" })}
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm font-medium text-slate-700"
|
||||
>
|
||||
Demo ausprobieren
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSwitch}
|
||||
className="mt-2 text-sm text-slate-500 underline underline-offset-2"
|
||||
>
|
||||
Noch kein Konto? Jetzt registrieren
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function RegisterForm({
|
||||
onSwitch,
|
||||
onRegister,
|
||||
error,
|
||||
pending,
|
||||
}: {
|
||||
onSwitch: () => void;
|
||||
onRegister: (payload: {
|
||||
benutzername: string;
|
||||
passwort: string;
|
||||
name: string;
|
||||
rg_name: string;
|
||||
rg_strasse: string;
|
||||
rg_plz: string;
|
||||
rg_ort: string;
|
||||
}) => void;
|
||||
error: string | null;
|
||||
pending: boolean;
|
||||
}) {
|
||||
const [form, setForm] = useState({
|
||||
benutzername: "",
|
||||
passwort: "",
|
||||
name: "",
|
||||
rg_name: "",
|
||||
rg_strasse: "",
|
||||
rg_plz: "",
|
||||
rg_ort: "",
|
||||
});
|
||||
|
||||
const set = (key: keyof typeof form) => (e: React.ChangeEvent<HTMLInputElement>) =>
|
||||
setForm((f) => ({ ...f, [key]: e.target.value }));
|
||||
|
||||
return (
|
||||
<form
|
||||
className="flex flex-col gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
onRegister(form);
|
||||
}}
|
||||
>
|
||||
<input
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Name"
|
||||
value={form.name}
|
||||
onChange={set("name")}
|
||||
/>
|
||||
<input
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Benutzername"
|
||||
value={form.benutzername}
|
||||
onChange={set("benutzername")}
|
||||
autoComplete="username"
|
||||
/>
|
||||
<input
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Passwort (min. 6 Zeichen)"
|
||||
type="password"
|
||||
value={form.passwort}
|
||||
onChange={set("passwort")}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
<p className="mt-1 text-xs font-medium text-slate-500">Rechnungsanschrift</p>
|
||||
<input
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Name"
|
||||
value={form.rg_name}
|
||||
onChange={set("rg_name")}
|
||||
/>
|
||||
<input
|
||||
className="rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Straße"
|
||||
value={form.rg_strasse}
|
||||
onChange={set("rg_strasse")}
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
className="w-1/3 rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="PLZ"
|
||||
value={form.rg_plz}
|
||||
onChange={set("rg_plz")}
|
||||
/>
|
||||
<input
|
||||
className="flex-1 rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
placeholder="Ort"
|
||||
value={form.rg_ort}
|
||||
onChange={set("rg_ort")}
|
||||
/>
|
||||
</div>
|
||||
{error && <p className="text-sm text-red-600">{error}</p>}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={pending}
|
||||
className="rounded-lg bg-slate-800 px-3 py-2 text-sm font-medium text-white disabled:opacity-50"
|
||||
>
|
||||
Registrieren
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSwitch}
|
||||
className="mt-2 text-sm text-slate-500 underline underline-offset-2"
|
||||
>
|
||||
Schon ein Konto? Anmelden
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8100";
|
||||
|
||||
export class ApiError extends Error {
|
||||
status: number;
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
export async function api<T>(path: string, options: RequestInit = {}): Promise<T> {
|
||||
const res = await fetch(`${API_URL}${path}`, {
|
||||
...options,
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options.headers,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
let detail = res.statusText;
|
||||
try {
|
||||
const body = await res.json();
|
||||
detail = body.detail ?? detail;
|
||||
} catch {
|
||||
// Response hat keinen JSON-Body - Statustext reicht als Fehlermeldung.
|
||||
}
|
||||
throw new ApiError(res.status, detail);
|
||||
}
|
||||
|
||||
if (res.status === 204) return undefined as T;
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { api, ApiError } from "./api";
|
||||
|
||||
export type Me = {
|
||||
id: number;
|
||||
benutzername: string;
|
||||
name: string | null;
|
||||
rolle: "nutzer" | "admin";
|
||||
ist_demo: boolean;
|
||||
selbst_registriert: boolean;
|
||||
};
|
||||
|
||||
export function useAuth() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const meQuery = useQuery<Me | null>({
|
||||
queryKey: ["auth", "me"],
|
||||
queryFn: async () => {
|
||||
try {
|
||||
return await api<Me>("/api/auth/me");
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.status === 401) return null;
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
retry: false,
|
||||
});
|
||||
|
||||
const invalidateMe = () => queryClient.invalidateQueries({ queryKey: ["auth", "me"] });
|
||||
|
||||
const login = useMutation({
|
||||
mutationFn: (payload: { benutzername: string; passwort: string }) =>
|
||||
api("/api/auth/login", { method: "POST", body: JSON.stringify(payload) }),
|
||||
onSuccess: invalidateMe,
|
||||
});
|
||||
|
||||
const registrieren = useMutation({
|
||||
mutationFn: (payload: {
|
||||
benutzername: string;
|
||||
passwort: string;
|
||||
name: string;
|
||||
rg_name: string;
|
||||
rg_strasse: string;
|
||||
rg_plz: string;
|
||||
rg_ort: string;
|
||||
}) => api("/api/auth/registrieren", { method: "POST", body: JSON.stringify(payload) }),
|
||||
onSuccess: invalidateMe,
|
||||
});
|
||||
|
||||
const logout = useMutation({
|
||||
mutationFn: () => api("/api/auth/logout", { method: "POST" }),
|
||||
onSuccess: invalidateMe,
|
||||
});
|
||||
|
||||
return { meQuery, login, registrieren, logout };
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts",
|
||||
"**/*.mts"
|
||||
],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in new issue
Block a user