UX improvements in data views

This commit is contained in:
2026-05-27 09:58:08 +02:00
parent 25851c4b86
commit ff370d0d39
5 changed files with 185 additions and 91 deletions

View File

@ -59,6 +59,80 @@ export function questionGermanLabel(q) {
return '';
}
/** One symptom value from parent glass-scale JSON answer. */
export function glassSymptomAnswerValue(raw, symptomKey) {
if (!raw || !symptomKey) return '';
try {
const o = JSON.parse(raw);
if (o && typeof o === 'object' && !Array.isArray(o)) {
const v = o[symptomKey];
return v != null ? String(v).trim() : '';
}
} catch {
/* ignore */
}
return '';
}
/**
* Flat result/export columns: glass_scale questions → one column per symptom.
*/
export function buildResultColumns(questions) {
const cols = [];
for (const q of questions || []) {
const cfg = parseQuestionConfig(q);
const symptoms = cfg.symptoms;
if (q.type === 'glass_scale_question' && Array.isArray(symptoms) && symptoms.length > 0) {
const parentKey = questionDisplayKey(q);
for (const sk of symptoms) {
const symptomKey = String(sk).trim();
if (!symptomKey) continue;
cols.push({
key: `glass_${q.questionID}_${symptomKey}`,
questionID: q.questionID,
symptomKey,
label: symptomKey,
title: parentKey && parentKey !== symptomKey
? `${parentKey} · ${symptomKey}`
: symptomKey,
isGlassSymptom: true,
question: q,
});
}
continue;
}
const label = questionDisplayKey(q);
cols.push({
key: `q_${q.questionID}`,
questionID: q.questionID,
symptomKey: null,
label,
title: questionGermanLabel(q) || label,
isGlassSymptom: false,
question: q,
});
}
return cols;
}
/** Display text for one results table cell. */
export function resultColumnCellValue(col, answer, optionMap = {}) {
if (!answer) return null;
if (col.isGlassSymptom) {
const v = glassSymptomAnswerValue(answer.freeTextValue, col.symptomKey);
return v || null;
}
const q = col.question;
if (answer.answerOptionID && optionMap[answer.answerOptionID]) {
return optionMap[answer.answerOptionID];
}
if (answer.freeTextValue) return answer.freeTextValue;
if (answer.numericValue !== null && answer.numericValue !== undefined) {
return answer.numericValue;
}
return null;
}
/** header_order.json column id → question key (questionnaire_x-y → y). */
export function headerColumnQuestionKey(headerId) {
const id = String(headerId ?? '');