added categoryKey to questionnaire schema and updated related functions for questionnaire handling; enhanced API to fetch client answers

This commit is contained in:
2026-05-27 19:38:49 +02:00
parent 9c887537e8
commit 36b6d63266
9 changed files with 424 additions and 17 deletions

View File

@ -149,6 +149,7 @@ Fields:
- `name`: display/admin name.
- `showPoints`: whether the app may show the points result.
- `condition`: JSON condition object. Empty conditions are returned as `{}`.
- `categoryKey` (optional): grouping key for the opening screen; labels come from app UI strings (e.g. `questionnaire_group_health_interview`).
Only questionnaires with `state = "active"` are returned, ordered by server `orderIndex`.
@ -207,6 +208,57 @@ Question fields:
Important ID rule: the fetch response returns short question IDs such as `q1`. The server resolves these back to full database IDs during upload, so the Android app should upload the same short IDs it received.
## Download Client Answers (restore on device)
`GET /api/app_questionnaires?clientCode=<code>&answers=1`
Allowed roles: `coach`, `supervisor`, `admin` (coach must be assigned to the client).
Headers:
```http
Authorization: Bearer <token>
```
Success (encrypted envelope, same as `?clients=1`):
```json
{
"ok": true,
"data": {
"encrypted": true,
"payload": { "...": "..." }
}
}
```
Decrypted `data`:
```json
{
"clientCode": "K008",
"questionnaires": [
{
"questionnaireID": "questionnaire_2_rhs",
"completedAt": 1710000000,
"sumPoints": 12,
"answers": [
{ "questionID": "q1", "answerOptionKey": "consent_signed" },
{ "questionID": "languages_spoken", "answerOptionKey": "language_arabic" },
{ "questionID": "languages_spoken", "answerOptionKey": "language_english" }
]
}
]
}
```
Notes:
- Returns all `completed_questionnaire` rows for the client.
- `answers` mirrors the POST submit shape (short `questionID`, glass-scale symptoms as separate entries, multi-checkbox as multiple rows with the same `questionID`).
- On the server, multi-checkbox answers are stored in one `client_answer` row (`freeTextValue` JSON array); export expands them for the app importer.
- Use on **client load** to restore answers after upload or on a fresh install.
## Fetch Assigned Clients
`GET /api/app_questionnaires?clients=1`