feat: Enhance reference value types management with validation rules and metadata
- Updated the backend to include new fields for validation rules and metadata in reference value types. - Enhanced the AdminReferenceValueTypesPage to support new validation rules for different data types. - Improved the ProfileReferenceValuesPage to handle validation and metadata for profile reference values. - Added API endpoint for fetching reference value metadata enums to support frontend validation. - Refactored frontend forms to incorporate new fields and validation logic for a better user experience.
This commit is contained in:
1 parent
f04318f76a
commit
45e4e64f15
9 files changed
+864
-137
No files matched your search
@@ -2,12 +2,51 @@ import { useState, useEffect, useCallback } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Gauge, Plus, Pencil, Trash2, Save, X } from 'lucide-react'
|
||||
import { api } from '../utils/api'
|
||||
import { VALUE_DATA_TYPE_LABELS } from '../utils/referenceValueMeta'
|
||||
|
||||
const VALUE_TYPES = ['integer', 'decimal', 'percentage', 'text', 'enum']
|
||||
|
||||
function buildValidationRules(form) {
|
||||
const t = form.value_data_type
|
||||
if (t === 'integer' || t === 'decimal') {
|
||||
const r = { positive_only: !!form.vr_positive_only }
|
||||
if (form.vr_min !== '' && !Number.isNaN(Number(form.vr_min))) r.min = Number(form.vr_min)
|
||||
if (form.vr_max !== '' && !Number.isNaN(Number(form.vr_max))) r.max = Number(form.vr_max)
|
||||
return r
|
||||
}
|
||||
if (t === 'percentage') {
|
||||
const r = { positive_only: !!form.vr_positive_only }
|
||||
if (form.vr_min !== '' && !Number.isNaN(Number(form.vr_min))) r.min = Number(form.vr_min)
|
||||
if (form.vr_max !== '' && !Number.isNaN(Number(form.vr_max))) r.max = Number(form.vr_max)
|
||||
return r
|
||||
}
|
||||
if (t === 'text') {
|
||||
const r = { not_empty: !!form.vr_not_empty }
|
||||
if (form.vr_max_length !== '' && !Number.isNaN(parseInt(form.vr_max_length, 10))) {
|
||||
r.max_length = parseInt(form.vr_max_length, 10)
|
||||
}
|
||||
return r
|
||||
}
|
||||
if (t === 'enum') {
|
||||
const parts = form.vr_enum_list.split(',').map((s) => s.trim()).filter(Boolean)
|
||||
return { allowed_values: parts }
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
const emptyForm = () => ({
|
||||
key: '',
|
||||
label: '',
|
||||
category: '',
|
||||
description: '',
|
||||
default_unit: '',
|
||||
value_data_type: 'decimal',
|
||||
vr_min: '',
|
||||
vr_max: '',
|
||||
vr_positive_only: false,
|
||||
vr_max_length: '',
|
||||
vr_not_empty: true,
|
||||
vr_enum_list: '',
|
||||
sort_order: 0,
|
||||
active: true,
|
||||
metadata_json: '{}',
|
||||
@@ -51,17 +90,25 @@ export default function AdminReferenceValueTypesPage() {
|
||||
}
|
||||
|
||||
const openEdit = (r) => {
|
||||
const vr = r.validation_rules && typeof r.validation_rules === 'object' ? r.validation_rules : {}
|
||||
const allowed = Array.isArray(vr.allowed_values) ? vr.allowed_values.join(', ') : ''
|
||||
setEditingId(r.id)
|
||||
setForm({
|
||||
key: r.key || '',
|
||||
label: r.label || '',
|
||||
category: r.category || '',
|
||||
description: r.description || '',
|
||||
default_unit: r.default_unit || '',
|
||||
value_data_type: r.value_data_type || 'decimal',
|
||||
vr_min: vr.min != null ? String(vr.min) : '',
|
||||
vr_max: vr.max != null ? String(vr.max) : '',
|
||||
vr_positive_only: !!vr.positive_only,
|
||||
vr_max_length: vr.max_length != null ? String(vr.max_length) : '',
|
||||
vr_not_empty: vr.not_empty !== false,
|
||||
vr_enum_list: allowed,
|
||||
sort_order: r.sort_order ?? 0,
|
||||
active: !!r.active,
|
||||
metadata_json: r.metadata && typeof r.metadata === 'object'
|
||||
? JSON.stringify(r.metadata, null, 2)
|
||||
: '{}',
|
||||
metadata_json: r.metadata && typeof r.metadata === 'object' ? JSON.stringify(r.metadata, null, 2) : '{}',
|
||||
})
|
||||
setShowForm(true)
|
||||
}
|
||||
@@ -77,23 +124,37 @@ export default function AdminReferenceValueTypesPage() {
|
||||
setError('Bitte einen Anzeigenamen (label) angeben.')
|
||||
return
|
||||
}
|
||||
if (!form.default_unit.trim()) {
|
||||
setError('Standard-Einheit ist erforderlich (bei Nutzern nicht änderbar).')
|
||||
return
|
||||
}
|
||||
if (form.value_data_type === 'enum' && !form.vr_enum_list.trim()) {
|
||||
setError('Bei Datentyp „Auswahl (ENUM)“ bitte erlaubte Werte (kommagetrennt) eintragen.')
|
||||
return
|
||||
}
|
||||
|
||||
let metadata = {}
|
||||
try {
|
||||
const mj = form.metadata_json.trim() || '{}'
|
||||
metadata = JSON.parse(mj)
|
||||
if (metadata === null || typeof metadata !== 'object' || Array.isArray(metadata)) {
|
||||
setError('Metadaten müssen ein JSON-Objekt sein.')
|
||||
setError('Zusatz-Metadaten müssen ein JSON-Objekt sein.')
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
setError('Metadaten: ungültiges JSON.')
|
||||
setError('Zusatz-Metadaten: ungültiges JSON.')
|
||||
return
|
||||
}
|
||||
|
||||
const validation_rules = buildValidationRules(form)
|
||||
|
||||
const payload = {
|
||||
label: form.label.trim(),
|
||||
category: form.category.trim() || null,
|
||||
description: form.description.trim() || null,
|
||||
default_unit: form.default_unit.trim() || null,
|
||||
default_unit: form.default_unit.trim(),
|
||||
value_data_type: form.value_data_type,
|
||||
validation_rules,
|
||||
sort_order: Number(form.sort_order) || 0,
|
||||
active: !!form.active,
|
||||
metadata,
|
||||
@@ -140,6 +201,108 @@ export default function AdminReferenceValueTypesPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const plausibilisierungBlock = () => {
|
||||
const t = form.value_data_type
|
||||
if (t === 'integer' || t === 'decimal' || t === 'percentage') {
|
||||
return (
|
||||
<>
|
||||
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
|
||||
<div className="settings-page__field" style={{ flex: '1 1 200px', border: 'none', padding: 0 }}>
|
||||
<label className="settings-page__field-label" htmlFor="ref-vr-min">
|
||||
Minimum (optional)
|
||||
</label>
|
||||
<input
|
||||
id="ref-vr-min"
|
||||
type="number"
|
||||
step="any"
|
||||
className="form-input"
|
||||
value={form.vr_min}
|
||||
onChange={(e) => setForm((f) => ({ ...f, vr_min: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field" style={{ flex: '1 1 200px', border: 'none', padding: 0 }}>
|
||||
<label className="settings-page__field-label" htmlFor="ref-vr-max">
|
||||
Maximum (optional){t === 'percentage' ? ' · global max. 100' : ''}
|
||||
</label>
|
||||
<input
|
||||
id="ref-vr-max"
|
||||
type="number"
|
||||
step="any"
|
||||
className="form-input"
|
||||
value={form.vr_max}
|
||||
onChange={(e) => setForm((f) => ({ ...f, vr_max: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="settings-page__field" style={{ border: 'none', padding: '8px 0 0' }}>
|
||||
<span className="settings-page__field-label">Optionen</span>
|
||||
<label
|
||||
htmlFor="ref-vr-pos"
|
||||
style={{ display: 'flex', alignItems: 'center', gap: 10, cursor: 'pointer', fontSize: 14 }}
|
||||
>
|
||||
<input
|
||||
id="ref-vr-pos"
|
||||
type="checkbox"
|
||||
checked={form.vr_positive_only}
|
||||
onChange={(e) => setForm((f) => ({ ...f, vr_positive_only: e.target.checked }))}
|
||||
/>
|
||||
Nur positive Zahlen (> 0)
|
||||
</label>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
if (t === 'text') {
|
||||
return (
|
||||
<>
|
||||
<div className="settings-page__field" style={{ border: 'none', padding: 0 }}>
|
||||
<label className="settings-page__field-label" htmlFor="ref-vr-maxlen">
|
||||
Max. Zeichenzahl (optional)
|
||||
</label>
|
||||
<input
|
||||
id="ref-vr-maxlen"
|
||||
type="number"
|
||||
min={1}
|
||||
className="form-input"
|
||||
value={form.vr_max_length}
|
||||
onChange={(e) => setForm((f) => ({ ...f, vr_max_length: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field" style={{ border: 'none', padding: '8px 0 0' }}>
|
||||
<label htmlFor="ref-vr-ne" style={{ display: 'flex', alignItems: 'center', gap: 10, cursor: 'pointer', fontSize: 14 }}>
|
||||
<input
|
||||
id="ref-vr-ne"
|
||||
type="checkbox"
|
||||
checked={form.vr_not_empty}
|
||||
onChange={(e) => setForm((f) => ({ ...f, vr_not_empty: e.target.checked }))}
|
||||
/>
|
||||
Nicht leer erlauben
|
||||
</label>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
if (t === 'enum') {
|
||||
return (
|
||||
<div className="settings-page__field" style={{ border: 'none', padding: 0 }}>
|
||||
<label className="settings-page__field-label" htmlFor="ref-vr-enum">
|
||||
Erlaubte Werte (kommagetrennt)
|
||||
</label>
|
||||
<textarea
|
||||
id="ref-vr-enum"
|
||||
className="form-input"
|
||||
rows={3}
|
||||
value={form.vr_enum_list}
|
||||
onChange={(e) => setForm((f) => ({ ...f, vr_enum_list: e.target.value }))}
|
||||
placeholder="z. B. niedrig, mittel, hoch"
|
||||
spellCheck={false}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return <p style={{ fontSize: 13, color: 'var(--text3)', margin: 0 }}>Keine zusätzlichen Regeln für diesen Typ.</p>
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: 48 }}>
|
||||
@@ -156,8 +319,8 @@ export default function AdminReferenceValueTypesPage() {
|
||||
Referenz-Kennwerte (Typen)
|
||||
</h1>
|
||||
<p style={{ fontSize: 13, color: 'var(--text2)', marginTop: 8, lineHeight: 1.6 }}>
|
||||
Hier definierst du die verfügbaren Kennwert-Typen für Nutzer (Einstellungen → Referenzwerte).
|
||||
Schlüssel sind nach Anlage fest; Nutzer können nur Werte zu diesen Typen erfassen.
|
||||
Kategorie, Datentyp und Plausibilisierung steuern die Nutzererfassung. Die Standard-Einheit ist bei der
|
||||
Eingabe fix; Prozentwerte liegen grundsätzlich zwischen 0 und 100.
|
||||
</p>
|
||||
<div style={{ marginTop: 12, display: 'flex', flexWrap: 'wrap', gap: 8 }}>
|
||||
<Link to="/admin/g/goals" className="btn btn-secondary" style={{ fontSize: 13 }}>
|
||||
@@ -229,6 +392,18 @@ export default function AdminReferenceValueTypesPage() {
|
||||
placeholder="z. B. Maximale Herzfrequenz"
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-admin-cat">
|
||||
Kategorie (Freitext)
|
||||
</label>
|
||||
<input
|
||||
id="ref-admin-cat"
|
||||
className="form-input"
|
||||
value={form.category}
|
||||
onChange={(e) => setForm((f) => ({ ...f, category: e.target.value }))}
|
||||
placeholder="z. B. Herz-Kreislauf"
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-admin-desc">
|
||||
Beschreibung
|
||||
@@ -242,16 +417,37 @@ export default function AdminReferenceValueTypesPage() {
|
||||
placeholder="Kurze Erklärung für Nutzer und Admins"
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-admin-vdt">
|
||||
Datentyp des Werts
|
||||
</label>
|
||||
<select
|
||||
id="ref-admin-vdt"
|
||||
className="form-input"
|
||||
value={form.value_data_type}
|
||||
onChange={(e) => setForm((f) => ({ ...f, value_data_type: e.target.value }))}
|
||||
>
|
||||
{VALUE_TYPES.map((k) => (
|
||||
<option key={k} value={k}>
|
||||
{VALUE_DATA_TYPE_LABELS[k] || k}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label">Plausibilisierung (je Datentyp)</label>
|
||||
{plausibilisierungBlock()}
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-admin-unit">
|
||||
Standard-Einheit
|
||||
Standard-Einheit (fix bei Nutzererfassung)
|
||||
</label>
|
||||
<input
|
||||
id="ref-admin-unit"
|
||||
className="form-input"
|
||||
value={form.default_unit}
|
||||
onChange={(e) => setForm((f) => ({ ...f, default_unit: e.target.value }))}
|
||||
placeholder="bpm, Stufe, …"
|
||||
placeholder="bpm, %, Stufe, …"
|
||||
/>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
@@ -292,12 +488,12 @@ export default function AdminReferenceValueTypesPage() {
|
||||
</div>
|
||||
<div className="settings-page__field" style={{ borderBottom: 'none' }}>
|
||||
<label className="settings-page__field-label" htmlFor="ref-admin-meta">
|
||||
Metadaten (JSON-Objekt)
|
||||
Zusatz-Metadaten (JSON-Objekt, optional)
|
||||
</label>
|
||||
<textarea
|
||||
id="ref-admin-meta"
|
||||
className="form-input"
|
||||
rows={5}
|
||||
rows={4}
|
||||
value={form.metadata_json}
|
||||
onChange={(e) => setForm((f) => ({ ...f, metadata_json: e.target.value }))}
|
||||
placeholder="{}"
|
||||
@@ -325,6 +521,8 @@ export default function AdminReferenceValueTypesPage() {
|
||||
<tr style={{ textAlign: 'left', borderBottom: '1px solid var(--border)', color: 'var(--text2)' }}>
|
||||
<th style={{ padding: '8px 6px' }}>Key</th>
|
||||
<th style={{ padding: '8px 6px' }}>Name</th>
|
||||
<th style={{ padding: '8px 6px' }}>Kategorie</th>
|
||||
<th style={{ padding: '8px 6px' }}>Typ</th>
|
||||
<th style={{ padding: '8px 6px' }}>Einheit</th>
|
||||
<th style={{ padding: '8px 6px' }}>Sort.</th>
|
||||
<th style={{ padding: '8px 6px' }}>Aktiv</th>
|
||||
@@ -336,6 +534,10 @@ export default function AdminReferenceValueTypesPage() {
|
||||
<tr key={r.id} style={{ borderBottom: '1px solid var(--border)' }}>
|
||||
<td style={{ padding: '10px 6px', fontFamily: 'monospace', fontSize: 13 }}>{r.key}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{r.label}</td>
|
||||
<td style={{ padding: '10px 6px', color: 'var(--text2)' }}>{r.category || '–'}</td>
|
||||
<td style={{ padding: '10px 6px' }}>
|
||||
{VALUE_DATA_TYPE_LABELS[r.value_data_type] || r.value_data_type || '–'}
|
||||
</td>
|
||||
<td style={{ padding: '10px 6px', color: 'var(--text2)' }}>{r.default_unit || '–'}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{r.sort_order}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{r.active ? '✓' : '–'}</td>
|
||||
|
||||
@@ -2,16 +2,17 @@ import { useState, useEffect, useCallback } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { ArrowLeft, Gauge, Pencil, Trash2, Plus } from 'lucide-react'
|
||||
import { api } from '../utils/api'
|
||||
import {
|
||||
labelSource,
|
||||
labelMethod,
|
||||
labelConfidence,
|
||||
VALUE_DATA_TYPE_LABELS,
|
||||
} from '../utils/referenceValueMeta'
|
||||
|
||||
function splitValueInput(raw) {
|
||||
const s = String(raw).trim()
|
||||
if (!s) return { value_numeric: null, value_text: null }
|
||||
const normalized = s.replace(',', '.')
|
||||
if (/^-?\d+(\.\d+)?$/.test(normalized)) {
|
||||
const n = Number(normalized)
|
||||
if (!Number.isNaN(n)) return { value_numeric: n, value_text: null }
|
||||
}
|
||||
return { value_numeric: null, value_text: s }
|
||||
const DEFAULT_FORM_META = {
|
||||
source: 'manual_user',
|
||||
method: 'direct_measurement',
|
||||
confidence: 'medium',
|
||||
}
|
||||
|
||||
function formatEntryValue(row) {
|
||||
@@ -22,8 +23,31 @@ function formatEntryValue(row) {
|
||||
return row.value_text != null ? String(row.value_text) : '–'
|
||||
}
|
||||
|
||||
function buildValuePayload(selectedType, rawStr) {
|
||||
const vdt = (selectedType?.value_data_type || 'decimal').toLowerCase()
|
||||
const s = String(rawStr ?? '').trim()
|
||||
if (vdt === 'integer' || vdt === 'decimal' || vdt === 'percentage') {
|
||||
if (!s) {
|
||||
return { error: 'Bitte einen Wert eingeben.', value_numeric: null, value_text: null }
|
||||
}
|
||||
const n = Number(s.replace(',', '.'))
|
||||
if (Number.isNaN(n)) {
|
||||
return { error: 'Bitte eine gültige Zahl eingeben.', value_numeric: null, value_text: null }
|
||||
}
|
||||
if (vdt === 'integer' && Math.abs(n - Math.round(n)) > 1e-9) {
|
||||
return { error: 'Bitte eine ganze Zahl eingeben.', value_numeric: null, value_text: null }
|
||||
}
|
||||
return { error: null, value_numeric: n, value_text: null }
|
||||
}
|
||||
if (vdt === 'text' || vdt === 'enum') {
|
||||
return { error: null, value_numeric: null, value_text: s }
|
||||
}
|
||||
return { error: null, value_numeric: null, value_text: s }
|
||||
}
|
||||
|
||||
export default function ProfileReferenceValuesPage() {
|
||||
const [types, setTypes] = useState([])
|
||||
const [metaEnums, setMetaEnums] = useState({ sources: [], methods: [], confidence_levels: [] })
|
||||
const [selectedKey, setSelectedKey] = useState('')
|
||||
const [entries, setEntries] = useState([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
@@ -33,8 +57,8 @@ export default function ProfileReferenceValuesPage() {
|
||||
const [form, setForm] = useState({
|
||||
effective_date: new Date().toISOString().split('T')[0],
|
||||
value: '',
|
||||
unit: '',
|
||||
notes: '',
|
||||
...DEFAULT_FORM_META,
|
||||
})
|
||||
|
||||
const selectedType = types.find((t) => t.key === selectedKey)
|
||||
@@ -42,8 +66,16 @@ export default function ProfileReferenceValuesPage() {
|
||||
const loadTypes = useCallback(async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
const data = await api.listReferenceValueTypes()
|
||||
const [data, enums] = await Promise.all([
|
||||
api.listReferenceValueTypes(),
|
||||
api.listReferenceValueMetaEnums(),
|
||||
])
|
||||
setTypes(Array.isArray(data) ? data : [])
|
||||
setMetaEnums(
|
||||
enums && typeof enums === 'object'
|
||||
? enums
|
||||
: { sources: [], methods: [], confidence_levels: [] },
|
||||
)
|
||||
setError(null)
|
||||
} catch (e) {
|
||||
setError(e.message || 'Typen konnten nicht geladen werden')
|
||||
@@ -88,41 +120,127 @@ export default function ProfileReferenceValuesPage() {
|
||||
setForm({
|
||||
effective_date: new Date().toISOString().split('T')[0],
|
||||
value: '',
|
||||
unit: selectedType?.default_unit || '',
|
||||
notes: '',
|
||||
...DEFAULT_FORM_META,
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedType && !editingId) {
|
||||
setForm((f) => ({
|
||||
...f,
|
||||
unit: selectedType.default_unit || f.unit || '',
|
||||
}))
|
||||
const rules = selectedType?.validation_rules && typeof selectedType.validation_rules === 'object'
|
||||
? selectedType.validation_rules
|
||||
: {}
|
||||
const allowedEnum = Array.isArray(rules.allowed_values)
|
||||
? rules.allowed_values.map((x) => String(x).trim()).filter(Boolean)
|
||||
: []
|
||||
const textMaxLen = rules.max_length != null ? parseInt(String(rules.max_length), 10) : null
|
||||
const vdt = (selectedType?.value_data_type || 'decimal').toLowerCase()
|
||||
|
||||
const renderValueField = () => {
|
||||
if (!selectedType) return null
|
||||
if (vdt === 'enum') {
|
||||
if (!allowedEnum.length) {
|
||||
return (
|
||||
<p style={{ fontSize: 13, color: '#B45309', margin: 0 }}>
|
||||
Für diesen Typ sind keine ENUM-Werte konfiguriert. Bitte einen Administrator informieren.
|
||||
</p>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<select
|
||||
id="ref-value"
|
||||
className="form-input"
|
||||
required
|
||||
value={form.value}
|
||||
onChange={(e) => setForm((f) => ({ ...f, value: e.target.value }))}
|
||||
>
|
||||
<option value="">— bitte wählen —</option>
|
||||
{allowedEnum.map((opt) => (
|
||||
<option key={opt} value={opt}>
|
||||
{opt}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)
|
||||
}
|
||||
}, [selectedType, editingId])
|
||||
if (vdt === 'integer') {
|
||||
return (
|
||||
<input
|
||||
id="ref-value"
|
||||
type="number"
|
||||
step={1}
|
||||
className="form-input"
|
||||
required
|
||||
value={form.value}
|
||||
onChange={(e) => setForm((f) => ({ ...f, value: e.target.value }))}
|
||||
placeholder="Ganze Zahl"
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (vdt === 'decimal' || vdt === 'percentage') {
|
||||
return (
|
||||
<input
|
||||
id="ref-value"
|
||||
type="number"
|
||||
step="any"
|
||||
className="form-input"
|
||||
required
|
||||
value={form.value}
|
||||
onChange={(e) => setForm((f) => ({ ...f, value: e.target.value }))}
|
||||
placeholder={vdt === 'percentage' ? 'z. B. 72.5' : 'Zahl'}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<textarea
|
||||
id="ref-value"
|
||||
className="form-input"
|
||||
rows={3}
|
||||
required={!!rules.not_empty}
|
||||
maxLength={Number.isFinite(textMaxLen) && textMaxLen > 0 ? textMaxLen : undefined}
|
||||
value={form.value}
|
||||
onChange={(e) => setForm((f) => ({ ...f, value: e.target.value }))}
|
||||
placeholder="Freitext"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault()
|
||||
if (!selectedKey) return
|
||||
const parts = splitValueInput(form.value)
|
||||
if (parts.value_numeric == null && !parts.value_text) {
|
||||
setError('Bitte einen Wert eingeben.')
|
||||
if (!selectedKey || !selectedType) return
|
||||
|
||||
const built = buildValuePayload(selectedType, form.value)
|
||||
if (built.error) {
|
||||
setError(built.error)
|
||||
return
|
||||
}
|
||||
const unit = (form.unit || '').trim() || (selectedType?.default_unit || '').trim()
|
||||
if (!unit) {
|
||||
setError('Bitte eine Einheit angeben.')
|
||||
if (
|
||||
(vdt === 'text' || vdt === 'enum') &&
|
||||
rules.not_empty &&
|
||||
!(built.value_text && String(built.value_text).trim())
|
||||
) {
|
||||
setError('Bitte einen Text eingeben.')
|
||||
return
|
||||
}
|
||||
if (
|
||||
vdt === 'text' &&
|
||||
Number.isFinite(textMaxLen) &&
|
||||
textMaxLen > 0 &&
|
||||
built.value_text &&
|
||||
built.value_text.length > textMaxLen
|
||||
) {
|
||||
setError(`Text zu lang (max. ${textMaxLen} Ze).`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
setError(null)
|
||||
const payload = {
|
||||
reference_value_type_key: selectedKey,
|
||||
effective_date: form.effective_date,
|
||||
value_numeric: parts.value_numeric,
|
||||
value_text: parts.value_text,
|
||||
unit,
|
||||
value_numeric: built.value_numeric,
|
||||
value_text: built.value_text,
|
||||
source: form.source,
|
||||
method: form.method,
|
||||
confidence: form.confidence,
|
||||
notes: form.notes.trim() || null,
|
||||
}
|
||||
if (editingId) {
|
||||
@@ -130,7 +248,9 @@ export default function ProfileReferenceValuesPage() {
|
||||
effective_date: payload.effective_date,
|
||||
value_numeric: payload.value_numeric,
|
||||
value_text: payload.value_text,
|
||||
unit: payload.unit,
|
||||
source: payload.source,
|
||||
method: payload.method,
|
||||
confidence: payload.confidence,
|
||||
notes: payload.notes,
|
||||
})
|
||||
} else {
|
||||
@@ -148,8 +268,10 @@ export default function ProfileReferenceValuesPage() {
|
||||
setForm({
|
||||
effective_date: String(row.effective_date || '').slice(0, 10),
|
||||
value: formatEntryValue(row),
|
||||
unit: row.unit || selectedType?.default_unit || '',
|
||||
notes: row.notes || '',
|
||||
source: row.source || DEFAULT_FORM_META.source,
|
||||
method: row.method || DEFAULT_FORM_META.method,
|
||||
confidence: row.confidence || DEFAULT_FORM_META.confidence,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -188,8 +310,8 @@ export default function ProfileReferenceValuesPage() {
|
||||
Referenzwerte
|
||||
</h1>
|
||||
<p style={{ fontSize: 14, color: 'var(--text2)', lineHeight: 1.6, marginTop: 8 }}>
|
||||
Persönliche Kennwerte für das aktive Profil – historisch gespeichert, typgesteuert. Neue Typen
|
||||
erscheinen automatisch, sobald sie im System ergänzt werden.
|
||||
Persönliche Kennwerte für das aktive Profil – historisch gespeichert. Der Datentyp und die Plausibilität
|
||||
werden vom Administrator festgelegt; die Einheit ist fest und nicht änderbar.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -241,6 +363,18 @@ export default function ProfileReferenceValuesPage() {
|
||||
{selectedType.description}
|
||||
</p>
|
||||
)}
|
||||
{selectedType && (
|
||||
<p style={{ fontSize: 12, color: 'var(--text3)', marginTop: 8 }}>
|
||||
Datentyp:{' '}
|
||||
<strong>{VALUE_DATA_TYPE_LABELS[vdt] || vdt}</strong>
|
||||
{selectedType.category ? (
|
||||
<>
|
||||
{' '}
|
||||
· Kategorie: <strong>{selectedType.category}</strong>
|
||||
</>
|
||||
) : null}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="card section-gap">
|
||||
@@ -266,27 +400,74 @@ export default function ProfileReferenceValuesPage() {
|
||||
<label className="settings-page__field-label" htmlFor="ref-value">
|
||||
Wert
|
||||
</label>
|
||||
<input
|
||||
id="ref-value"
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="Zahl oder Text (z. B. 178 oder mittel)"
|
||||
value={form.value}
|
||||
onChange={(e) => setForm((f) => ({ ...f, value: e.target.value }))}
|
||||
/>
|
||||
{renderValueField()}
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-unit">
|
||||
Einheit
|
||||
</label>
|
||||
<input
|
||||
id="ref-unit"
|
||||
type="text"
|
||||
<span className="settings-page__field-label">Einheit (vom Typ, nicht änderbar)</span>
|
||||
<div
|
||||
className="form-input"
|
||||
placeholder={selectedType?.default_unit || 'z. B. bpm'}
|
||||
value={form.unit}
|
||||
onChange={(e) => setForm((f) => ({ ...f, unit: e.target.value }))}
|
||||
/>
|
||||
style={{
|
||||
background: 'var(--surface)',
|
||||
color: 'var(--text2)',
|
||||
cursor: 'default',
|
||||
}}
|
||||
>
|
||||
{selectedType?.default_unit?.trim() ? selectedType.default_unit : '— nicht gesetzt —'}
|
||||
</div>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-source">
|
||||
Quelle
|
||||
</label>
|
||||
<select
|
||||
id="ref-source"
|
||||
className="form-input"
|
||||
required
|
||||
value={form.source}
|
||||
onChange={(e) => setForm((f) => ({ ...f, source: e.target.value }))}
|
||||
>
|
||||
{(metaEnums.sources || []).map((k) => (
|
||||
<option key={k} value={k}>
|
||||
{labelSource(k)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-method">
|
||||
Methode
|
||||
</label>
|
||||
<select
|
||||
id="ref-method"
|
||||
className="form-input"
|
||||
required
|
||||
value={form.method}
|
||||
onChange={(e) => setForm((f) => ({ ...f, method: e.target.value }))}
|
||||
>
|
||||
{(metaEnums.methods || []).map((k) => (
|
||||
<option key={k} value={k}>
|
||||
{labelMethod(k)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="settings-page__field">
|
||||
<label className="settings-page__field-label" htmlFor="ref-confidence">
|
||||
Vertrauensgrad
|
||||
</label>
|
||||
<select
|
||||
id="ref-confidence"
|
||||
className="form-input"
|
||||
required
|
||||
value={form.confidence}
|
||||
onChange={(e) => setForm((f) => ({ ...f, confidence: e.target.value }))}
|
||||
>
|
||||
{(metaEnums.confidence_levels || []).map((k) => (
|
||||
<option key={k} value={k}>
|
||||
{labelConfidence(k)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="settings-page__field" style={{ borderBottom: 'none' }}>
|
||||
<label className="settings-page__field-label" htmlFor="ref-notes">
|
||||
@@ -298,11 +479,11 @@ export default function ProfileReferenceValuesPage() {
|
||||
rows={3}
|
||||
value={form.notes}
|
||||
onChange={(e) => setForm((f) => ({ ...f, notes: e.target.value }))}
|
||||
placeholder="Kontext, Messmethode …"
|
||||
placeholder="Zusatzkontext …"
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginTop: 8 }}>
|
||||
<button type="submit" className="btn btn-primary btn-full">
|
||||
<button type="submit" className="btn btn-primary btn-full" disabled={vdt === 'enum' && !allowedEnum.length}>
|
||||
{editingId ? 'Speichern' : 'Hinzufügen'}
|
||||
</button>
|
||||
{editingId && (
|
||||
@@ -326,13 +507,16 @@ export default function ProfileReferenceValuesPage() {
|
||||
</p>
|
||||
) : (
|
||||
<div style={{ overflowX: 'auto' }}>
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 14 }}>
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 13 }}>
|
||||
<thead>
|
||||
<tr style={{ textAlign: 'left', borderBottom: '1px solid var(--border)', color: 'var(--text2)' }}>
|
||||
<th style={{ padding: '8px 6px' }}>Datum</th>
|
||||
<th style={{ padding: '8px 6px' }}>Wert</th>
|
||||
<th style={{ padding: '8px 6px' }}>Einheit</th>
|
||||
<th style={{ padding: '8px 6px', width: 100 }} />
|
||||
<th style={{ padding: '8px 6px' }}>Einh.</th>
|
||||
<th style={{ padding: '8px 6px' }}>Quelle</th>
|
||||
<th style={{ padding: '8px 6px' }}>Methode</th>
|
||||
<th style={{ padding: '8px 6px' }}>Vertr.</th>
|
||||
<th style={{ padding: '8px 6px', width: 96 }} />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -343,6 +527,9 @@ export default function ProfileReferenceValuesPage() {
|
||||
</td>
|
||||
<td style={{ padding: '10px 6px' }}>{formatEntryValue(row)}</td>
|
||||
<td style={{ padding: '10px 6px', color: 'var(--text2)' }}>{row.unit}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{labelSource(row.source)}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{labelMethod(row.method)}</td>
|
||||
<td style={{ padding: '10px 6px' }}>{labelConfidence(row.confidence)}</td>
|
||||
<td style={{ padding: '6px', textAlign: 'right' }}>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -42,6 +42,7 @@ export const api = {
|
||||
|
||||
// Persönliche Referenzwerte (Profil, historisch)
|
||||
listReferenceValueTypes: () => req('/reference-value-types'),
|
||||
listReferenceValueMetaEnums: () => req('/reference-value-meta/enums'),
|
||||
listProfileReferenceValues: (typeKey) =>
|
||||
req(`/profile-reference-values?type_key=${encodeURIComponent(typeKey)}`),
|
||||
createProfileReferenceValue: (d) => req('/profile-reference-values', json(d)),
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/** Labels für Referenzwert-Metadaten (Erfassung). */
|
||||
|
||||
export const REF_SOURCE_LABELS = {
|
||||
manual_user: 'Manuell (Nutzer)',
|
||||
manual_admin: 'Manuell (Admin)',
|
||||
import_device: 'Import Gerät',
|
||||
import_app: 'Import App',
|
||||
derived_system: 'Abgeleitet (System)',
|
||||
estimated_system: 'Geschätzt (System)',
|
||||
test_entry: 'Testeintrag',
|
||||
}
|
||||
|
||||
export const REF_METHOD_LABELS = {
|
||||
direct_measurement: 'Direkte Messung',
|
||||
lab_test: 'Labortest',
|
||||
field_test: 'Feldtest',
|
||||
questionnaire: 'Fragebogen',
|
||||
formula_estimation: 'Formel-Schätzung',
|
||||
trend_analysis: 'Trendanalyse',
|
||||
device_algorithm: 'Geräte-Algorithmus',
|
||||
manual_assessment: 'Manuelle Einschätzung',
|
||||
imported_external: 'Extern importiert',
|
||||
unknown: 'Unbekannt',
|
||||
}
|
||||
|
||||
export const REF_CONFIDENCE_LABELS = {
|
||||
high: 'Hoch',
|
||||
medium: 'Mittel',
|
||||
low: 'Niedrig',
|
||||
unknown: 'Unbekannt',
|
||||
}
|
||||
|
||||
export function labelSource(k) {
|
||||
return REF_SOURCE_LABELS[k] || k || '–'
|
||||
}
|
||||
export function labelMethod(k) {
|
||||
return REF_METHOD_LABELS[k] || k || '–'
|
||||
}
|
||||
export function labelConfidence(k) {
|
||||
return REF_CONFIDENCE_LABELS[k] || k || '–'
|
||||
}
|
||||
|
||||
export const VALUE_DATA_TYPE_LABELS = {
|
||||
integer: 'Ganzzahl',
|
||||
decimal: 'Dezimalzahl',
|
||||
percentage: 'Prozent',
|
||||
text: 'Text',
|
||||
enum: 'Auswahl (ENUM)',
|
||||
}
|
||||
Reference in new issue
Block a user