Type Definitions (types.ts)
Relevant source files
The following files were used as context for generating this wiki page:The types.ts file serves as the central repository for shared TypeScript interfaces within the AI for Thai EMS application. Its primary purpose is to enforce data consistency and provide static type-checking across different modules, from front-end components to data services. By defining common data structures, it ensures that information, especially the structured output from the AI service, is handled predictably throughout the application.
This file defines the core data models for project information, such as the research team and timeline, and most importantly, the expected structure of the AI analysis results. This standardization is crucial for the reliable interaction between the UI components, like the AiDemo and Timeline, and the data sources, such as constants.ts and the geminiService.
Sources: types.ts, constants.ts, components/AiDemo.tsx
Core Interfaces
The types.ts file exports several key interfaces that model the application's data.
Sources: types.ts
Researcher
This interface defines the data structure for a member of the research team. It is used in constants.ts to create a typed array of all team members, which is then rendered in the App.tsx component.
Sources: types.ts:1-5, constants.ts:22-35, App.tsx:55-62
Properties
| Property | Type | Description |
|---|---|---|
name | string | The full name of the researcher. |
organization | string | The organization the researcher belongs to. |
role | string | The researcher's role in the project (e.g., 'Advisor'). |
Sources: types.ts:2-4
Usage Example
// constants.ts
export const researchTeam: Researcher[] = [
{ name: 'ดร.ศักดิ์ เสกขุนทด', organization: 'สพรอ.', role: 'ที่ปรึกษา' },
{ name: 'ผศ.นพ.ศรัทธา ริยาพันธ์', organization: 'ศิริราช', role: 'ที่ปรึกษา' },
// ... more researchers
];
Sources: constants.ts:22-25
TimelineEvent
This interface structures the data for events displayed in the project's timeline. It is used in constants.ts to define the project milestones and is consumed by the Timeline.tsx component to render the visual timeline.
Sources: types.ts:7-11, constants.ts:37-51, components/Timeline.tsx:5-7
Properties
| Property | Type | Description |
|---|---|---|
title | string | The title of the timeline event. |
description | string | A brief description of the event. |
percentage | number | The completion percentage for that project phase. |
Sources: types.ts:8-10
AiAnalysisResult
This is a critical interface that defines the shape of the structured data returned by the Gemini AI service after analyzing an emergency call transcript. It ensures that the raw JSON response from the AI is correctly typed and can be safely accessed within the application, primarily in the AiDemo.tsx component.
The diagram below shows the structure of the AiAnalysisResult interface.
Sources: types.ts:13-22
Properties
| Property | Type | Description |
|---|---|---|
incidentType | string | null | The type of incident (e.g., 'Cardiac Emergency'). |
location | string | null | The full address of the incident. |
severity | 'Critical' | 'Urgent' | 'Non-Urgent' | null | The assessed severity level of the call. |
recommendedAction | string | null | The suggested next step (e.g., 'Dispatch ALS Ambulance'). |
extractedData | object | A nested object containing specific patient details. |
extractedData.name | string | The patient's name. |
extractedData.age | string | The patient's age. |
extractedData.condition | string | A summary of the patient's condition. |
Sources: types.ts:14-21
Data Flow for AI Analysis
The AiAnalysisResult type is central to the AI demonstration feature. The geminiService defines a response schema for the AI model that mirrors this interface. When the AiDemo component requests an analysis, the service calls the Gemini API, receives a JSON response, and casts it to the AiAnalysisResult type before returning it. The component then uses this typed object to update its state and render the analysis dashboard.
This sequence diagram illustrates the data flow for analyzing an emergency call.
Component-Specific Types
While types.ts handles shared types, some components define their own local types for internal state management.
Message (in Chatbot.tsx)
The Chatbot.tsx component defines a local Message type to structure its conversation history. This type is tailored specifically for the chatbot's needs, including distinguishing between user and model messages.
Sources: components/Chatbot.tsx:9-14
Properties
| Property | Type | Description |
|---|---|---|
id | number | A unique identifier for the message. |
text | string | The content of the message. |
sender | 'user' | 'model' | The originator of the message, aligned with Gemini API history roles. |
sources | any[] (optional) | An array of sources returned by the AI for grounding its response. |
Sources: components/Chatbot.tsx:10-14
Conclusion
The type definitions, centralized in types.ts, are fundamental to the architecture of the AI for Thai EMS application. They provide a "single source of truth" for data models, enabling robust, maintainable, and type-safe code. The AiAnalysisResult interface is particularly vital, creating a strong contract between the front-end display logic and the AI service's output, which is essential for the application's core functionality. This use of TypeScript ensures that data flows predictably between components and services, reducing runtime errors and improving developer productivity.
Sources: types.ts, services/geminiService.ts, components/AiDemo.tsx