Prescreening Business Logic
Actors
| Actor | Surface | Primary actions |
|---|---|---|
| Participant | dmind-prescreening-web-frontend | Consent, provide required details, choose an interview method, answer questions, and, when configured, view a result and select follow-up services. |
| Clinical staff | agnos-mental-dashboard-front | Authenticate, search and filter cases, review AI results, record 8Q/9Q assessments, add contact logs, close cases, and export CSV. |
| Corp/partner system | Prescreening backend integration routes | Create or validate sessions, pass participant details, receive progress, and handle redirects. |
| AI platform | AI controller and workers | Accept media/text answers and return depression, suicidal, two-question, and chief-complaint results. |
Participant lifecycle
The exact path is feature-configuration and corp dependent. The frontend reads VITE_CORP_NAME and a JSON feature configuration; the backend reads its application name and Parameter Store feature configuration. The current participant frontend exposes video, audio, and text. CHOICE is deprecated and excluded from configured method selection, but its route and calculation code remain for compatibility. AIMET 9Q is deprecated and its page is not registered in the current route tree; the retained page submits the rating and then navigates to method selection, placing it before the interview in that implementation.
Participant API catalog
| Phase | Endpoints | Maintained invariant |
|---|---|---|
| Entry | POST /interview/start, POST /interview/start/corp | Produces or reuses a session token and creates a case where required. Corp entry requires the corp ingress contract. |
| Session/content | GET /interview/validate-token, GET /interview/session, GET /interview/content | The Redis session determines the current/next question and resume state; content and question paths are cached from S3/configured assets. |
| Participant data | POST /interview/recipient, POST /interview/recipient-info | Stores the configured identity/demographic fields. Final contact info also shortens the session to the end TTL. |
| Assessment | POST /interview/submit-answer, POST /interview/submit-suicidal | Validates the configured question path and method, forwards answers to AI, and records the fallback source. |
| External and compatibility assessment | POST /interview/submit-self-rating, POST /interview/submit-multiple-answers, POST /interview/submit-self-rating-9q | The registered Mental Med/Agnos endpoint accepts external HAMD-7/8Q submissions as a pre-interview entry point; the current participant frontend does not call it, and external runtime use is unverified. Multiple-answer CHOICE and AIMET 9Q remain as deprecated compatibility paths. |
| Result | GET /interview/result | Returns AI, Agnos, fallback, and AIMET self-rating views. It persists a finished AI result and notifies a corp asynchronously when a corp_id exists. |
| Follow-up | GET /interview/terminal-service, POST /interview/select-terminal-service | Resolves currently available services, records the selection/time, and either returns a redirect or invokes the partner handoff. |
| 1323 | POST /interview/verify-alltime, POST /interview/validate-alltime-otp, POST /interview/resend-alltime-otp, POST /interview/alltime1323/progress, POST /interview/alltime1323/related-id | Maintains verification state in the session and progress/relationship data in the interview. Ingress progress/related-ID endpoints use the 1323-specific credential. |
| Surveys | POST /interview/feedback, POST /interview/low-depression-survey, POST /interview/sroi-survey | Stores user-experience, low-depression chatbot, and social-return data on the interview. |
| System | POST /system/refresh-content, POST /system/interview | Protected service-to-service maintenance/import entry points. |
Session lifecycle
The participant session stores prediction_id, interview_id, corp_id, recipient name, current/next question, final-answer timestamp, default redirect, and 1323 phone/national-ID verification state. Default timings are:
- start TTL: 15 minutes
- active/default TTL: 120 minutes
- end TTL: 10 minutes
The interview document is durable; the Redis session is the resumable workflow cursor. A missing/expired session does not imply that the Mongo case was deleted.
Result source precedence
The stored depression_level is selected by source priority whenever a new source arrives:
| Priority | Source | How it is produced |
|---|---|---|
| 4 | AGNOS_SELF_RATING | Partner-supplied Mental Med/Agnos HAMD-7/8Q result; external runtime use is unverified. |
| 3 | FALLBACK | Participant suicidal yes/no maps to SEVERE/LOW. |
| 2 | AI_SERVICE | Finished AI controller result. |
| 1 | AIMET_SELF_RATING | Deprecated, compatibility-retained local 9Q calculation. |
A lower-priority result is still retained in its embedded field but does not replace the higher-priority top-level level/source. The AIMET 9Q thresholds are 0–6 normal/low, 7–12 mild/low, 13–18 moderate, and 19+ severe.
Corp behavior to preserve
The same source code serves multiple branded deployments. Corp-specific behavior includes required participant fields, invalid-token handling, result copy/actions, fallback URLs, available terminal services, analytics dimensions, and backend-to-partner credentials.
Current variants are main, TU/TU UAT, MDCU, CPIRD, THPF, KKU, Thangrath, and TSU. Navy is retained but inactive; Chula and Somdet remain legacy namespaces without a current service identified.
Terminal-service rules
| Service | Eligibility/behavior in current code |
|---|---|
ASA | TU only and requires a corp ID; backend starts an ASA flow and returns its redirect. |
1323_DASHBOARD | TU, THPF, KKU, Thangrath, and TSU; copies the interview to main DMIND. TU/THPF/KKU require corp ID, while Thangrath/TSU use public entry. |
1323_ALLTIME | Main, TU, THPF, KKU, Thangrath, and TSU; requires completed verification, persists the phone, and calls the AllTime validation/handoff. |
HERE_TO_HEAL | Availability is resolved by its API using participant and AI context. |
SATI, EMMIND, DMIND_CHATBOT | Availability/redirect is resolved by the configured client and stored in the interview's available-service snapshot. |
TU additionally notifies its corp system of the chosen service. Feature configuration and frontend copy may narrow what a user sees, so preserve both backend eligibility and frontend configuration.
Staff dashboard lifecycle
The active dashboard is agnos-mental-dashboard-front; its production API base is https://api.prescreening.dmind.app/dashboard.
POST /auth/loginreturns access and refresh tokens for a MongoDBstaffrecord.- The browser sends the bearer access token and uses
POST /auth/refresh-tokenafter unauthorized responses. POST /interviewslists cases with status, province, severity, dates, exact case ID, and exact phone filters.GET /interviews/:case_idreturns participant, AI, staff-assessment, and contact-log detail.POST /interviews/:case_id/result-staffstores the clinical follow-up result and can close a case.- Result-log endpoints create/edit/delete staff contact notes stored inside the interview record.
POST /csvexports the filtered result set.
Statuses are NEW, FOLLOW_UP, and DONE.
Dashboard query and case rules
- The list filters by status, province, severity, and created-date range. Request field
record_idmatches the exact numericcase_id;filter_textmatches the exact phone number. When no phone filter is supplied, records with a missing, null, or empty phone number are excluded. - Results sort by
last_contact_datewhen present, otherwisecreated_at, with pagination applied after filtering/sorting. - A contactable case requires non-negative staff 8Q and 9Q scores/severities. A not-accepted call or invalid phone clears those scores.
- Saving a staff result sets
FOLLOW_UP;is_doneor an invalid phone setsDONE. It updateslast_contact_dateand preserves the first staff-result creation time. - Not-accepted calls increment
not_accept_call_countand append an automatic Thai contact log. Free-form extra information also appends a log. - Log edit increments
is_edited; delete is a soft delete (is_deleted=true) by array index. - Statistics group total/answered/not-answered counts by
LOW,MODERATE, andSEVERE. CSV reuses the list filters without pagination.
Dashboard authentication
The backend validates active Mongo staff records and bcrypt-style stored passwords, issues access/refresh JWTs, and uses Redis refresh-token state for rotation/invalidation. Default access lifetime is 120 minutes and refresh lifetime is 24 hours. Registration is system-protected; case routes and auth-info/password-change require staff authentication.
Historical Agnos backend migration
The former Django backend stored mental records, medical records, and logs in PostgreSQL and linked them to DMIND through request/callback identifiers. Those dashboard responsibilities now live in dmind-prescreening-backend, with interview and staff state in MongoDB. Current-state changes must follow the Go/Mongo implementation; the old backend is reference material only.