Przejdź do głównej zawartości

Command Handlers

Na tej stronie

Vista eksponuje 250 komend Tauri zorganizowanych domenowo:

src-tauri/src/commands/
├── mod.rs # Re-exports
├── auth.rs # 6 komend auth
├── patients.rs # 8 komend pacjentów
├── visits.rs # 10 komend wizyt
├── appointments.rs # 7 komend kalendarza
├── tasks.rs # 5 komend zadań
├── reminders.rs # 4 komendy przypomnień
├── settings.rs # 5 komend ustawień
├── audio/
│ ├── mod.rs
│ ├── recording.rs # 4 komendy nagrywania
│ └── stt/
│ └── api.rs # 3 komendy STT
├── ai/
│ ├── mod.rs
│ ├── chat.rs # 3 komendy czatu
│ └── soap.rs # 2 komendy SOAP
└── mlx_commands.rs # 3 komendy MLX

#[tauri::command]
pub async fn login(
db: State<'_, Database>,
email: String,
password: String,
) -> Result<LoginResponse, String>
ParamTypeDescription
emailStringEmail użytkownika
passwordStringHasło (plain text → bcrypt verify)

Returns: LoginResponse z user data i session token.

#[tauri::command]
pub async fn logout(
db: State<'_, Database>,
session_id: String,
) -> Result<(), String>
#[tauri::command]
pub async fn login_biometric(
db: State<'_, Database>,
user_id: String,
) -> Result<LoginResponse, String>
#[tauri::command]
pub async fn get_active_session(
db: State<'_, Database>,
) -> Result<Option<Session>, String>
#[tauri::command]
pub async fn refresh_session(
db: State<'_, Database>,
session_id: String,
) -> Result<Session, String>
#[tauri::command]
pub async fn change_password(
db: State<'_, Database>,
user_id: String,
current_password: String,
new_password: String,
) -> Result<(), String>

#[tauri::command]
pub async fn get_patient(
db: State<'_, Database>,
patient_id: String,
) -> Result<Patient, String>
#[tauri::command]
pub async fn list_patients(
db: State<'_, Database>,
page: i64,
limit: i64,
sort_by: Option<String>,
sort_order: Option<String>,
) -> Result<PaginatedPatients, String>
#[tauri::command]
pub async fn search_patients(
db: State<'_, Database>,
query: String,
) -> Result<Vec<Patient>, String>

Search logic:

  • Szuka w name, owner_name, chip_number
  • Case-insensitive
  • Minimum 2 znaki
#[tauri::command]
pub async fn create_patient(
db: State<'_, Database>,
data: CreatePatientRequest,
) -> Result<Patient, String>
FieldTypeRequired
nameString
speciesString
breedOption<String>
owner_nameOption<String>
owner_phoneOption<String>
chip_numberOption<String>
#[tauri::command]
pub async fn update_patient(
db: State<'_, Database>,
patient_id: String,
updates: PatientUpdate,
) -> Result<Patient, String>
#[tauri::command]
pub async fn delete_patient(
db: State<'_, Database>,
patient_id: String,
) -> Result<(), String>
#[tauri::command]
pub async fn get_patient_visits(
db: State<'_, Database>,
patient_id: String,
) -> Result<Vec<Visit>, String>
#[tauri::command]
pub async fn find_duplicate_patients(
db: State<'_, Database>,
identity: PatientIdentity,
) -> Result<Vec<Patient>, String>

#[tauri::command]
pub async fn get_visit(
db: State<'_, Database>,
visit_id: String,
) -> Result<Visit, String>
#[tauri::command]
pub async fn list_user_visits(
db: State<'_, Database>,
user_id: String,
filters: Option<VisitFilters>,
) -> Result<Vec<Visit>, String>

Filters:

FieldTypeDescription
visit_typeOption<String>consultation, emergency, etc.
visit_statusOption<String>draft, finalized, sent
start_dateOption<String>ISO date
end_dateOption<String>ISO date
#[tauri::command]
pub async fn create_visit(
db: State<'_, Database>,
patient_id: String,
user_id: String,
visit_data: CreateVisitRequest,
) -> Result<Visit, String>
#[tauri::command]
pub async fn update_visit_soap(
db: State<'_, Database>,
visit_id: String,
soap_data: SOAPUpdate,
expected_version: i32,
) -> Result<Visit, String>
#[tauri::command]
pub async fn finalize_visit(
db: State<'_, Database>,
visit_id: String,
) -> Result<Visit, String>

Zmienia visit_status z draftfinalized.

#[tauri::command]
pub async fn delete_visit(
db: State<'_, Database>,
visit_id: String,
) -> Result<(), String>
#[tauri::command]
pub async fn export_visit_pdf(
db: State<'_, Database>,
visit_id: String,
) -> Result<String, String> // Returns file path
#[tauri::command]
pub async fn send_visit_email(
db: State<'_, Database>,
visit_id: String,
recipient_email: String,
) -> Result<(), String>
#[tauri::command]
pub async fn get_visit_with_patient(
db: State<'_, Database>,
visit_id: String,
) -> Result<VisitWithPatient, String>
#[tauri::command]
pub async fn share_visit(
db: State<'_, Database>,
visit_id: String,
shared_with_user_id: String,
permissions: SharePermissions,
) -> Result<VisitShare, String>

#[tauri::command]
pub async fn save_audio_file(
db: State<'_, Database>,
visit_id: String,
audio_data: String, // Base64 encoded
format: String, // "audio/webm", "audio/wav"
) -> Result<RecordingMetadata, String>
#[tauri::command]
pub async fn get_audio_file(
db: State<'_, Database>,
recording_id: String,
) -> Result<Vec<u8>, String>
#[tauri::command]
pub async fn delete_recording(
db: State<'_, Database>,
recording_id: String,
) -> Result<(), String>
#[tauri::command]
pub async fn list_visit_recordings(
db: State<'_, Database>,
visit_id: String,
) -> Result<Vec<Recording>, String>

#[tauri::command]
pub async fn start_transcription(
db: State<'_, Database>,
recording_id: String,
provider: String, // "auto", "libraxis", "mlx", "openai"
language: String, // "pl", "en"
) -> Result<TranscriptionJob, String>
#[tauri::command]
pub async fn get_transcription_status(
db: State<'_, Database>,
job_id: String,
) -> Result<TranscriptionStatus, String>

Status values:

StatusDescription
queuedW kolejce
processingPrzetwarzanie
completedGotowe
failedBłąd
#[tauri::command]
pub async fn detect_best_stt_endpoint() -> Result<SttEndpoint, String>

Testuje dostępność providerów w kolejności: LibraxisAI → MLX → OpenAI.


#[tauri::command]
pub async fn chat_completion(
db: State<'_, Database>,
messages: Vec<ChatMessage>,
model: Option<String>,
temperature: Option<f32>,
) -> Result<ChatResponse, String>
#[tauri::command]
pub async fn generate_soap(
db: State<'_, Database>,
visit_id: String,
transcript: String,
patient_context: PatientContext,
preferences: UserPreferences,
) -> Result<SOAPNote, String>
#[tauri::command]
pub async fn get_ai_suggestions(
db: State<'_, Database>,
visit_id: String,
) -> Result<Vec<AISuggestion>, String>

#[tauri::command]
pub async fn list_vet_appointments(
db: State<'_, Database>,
vet_id: String,
start_date: String,
end_date: String,
) -> Result<Vec<Appointment>, String>
#[tauri::command]
pub async fn create_appointment(
db: State<'_, Database>,
data: CreateAppointmentRequest,
) -> Result<Appointment, String>
#[tauri::command]
pub async fn update_appointment_status(
db: State<'_, Database>,
appointment_id: String,
status: String, // "scheduled", "confirmed", "completed", "cancelled"
) -> Result<Appointment, String>
#[tauri::command]
pub async fn check_comprehensive_staff_conflicts(
db: State<'_, Database>,
veterinarian_id: String,
date: String,
start_time: String,
duration_minutes: i32,
) -> Result<ConflictResult, String>

Conflict detection:

  1. Sprawdza istniejące appointments
  2. Sprawdza working hours
  3. Sprawdza time blocks (spotkania, przerwy)
  4. Sugeruje alternatywne sloty
#[tauri::command]
pub async fn convert_appointment_to_visit(
db: State<'_, Database>,
appointment_id: String,
) -> Result<Visit, String>
#[tauri::command]
pub async fn get_user_working_hours(
db: State<'_, Database>,
user_id: String,
) -> Result<Vec<WorkingHours>, String>
#[tauri::command]
pub async fn update_user_working_hours(
db: State<'_, Database>,
user_id: String,
hours: Vec<WorkingHoursUpdate>,
) -> Result<(), String>

#[tauri::command]
pub async fn get_mlx_health_detailed() -> Result<MLXHealthReport, String>

Returns:

struct MLXHealthReport {
llm_status: ServiceStatus,
llm_response_time: Option<u64>,
llm_model: Option<String>,
stt_status: ServiceStatus,
stt_response_time: Option<u64>,
tts_status: ServiceStatus,
tts_response_time: Option<u64>,
overall_health: bool,
}
#[tauri::command]
pub async fn check_mlx_llm() -> Result<bool, String>
#[tauri::command]
pub async fn check_mlx_stt() -> Result<bool, String>

#[tauri::command]
pub async fn get_user_preferences(
db: State<'_, Database>,
user_id: String,
) -> Result<UserPreferences, String>
#[tauri::command]
pub async fn update_user_preferences(
db: State<'_, Database>,
user_id: String,
updates: UserPreferencesUpdate,
) -> Result<UserPreferences, String>
#[tauri::command]
pub async fn batch_update_user_preferences_session(
db: State<'_, Database>,
user_id: String,
preferences: BatchPreferencesUpdate,
) -> Result<(), String>

Używane przy onboardingu - zapisuje wszystkie preferencje naraz.

#[tauri::command]
pub async fn get_clinic_settings(
db: State<'_, Database>,
) -> Result<ClinicSettings, String>
#[tauri::command]
pub async fn update_clinic_settings(
db: State<'_, Database>,
settings: ClinicSettingsUpdate,
) -> Result<ClinicSettings, String>

Wszystkie komendy używają spójnego wzorca obsługi błędów:

#[tauri::command]
pub async fn example_command(
db: State<'_, Database>,
param: String,
) -> Result<ResponseType, String> {
// 1. Validation
if param.is_empty() {
return Err("Parameter cannot be empty".to_string());
}
// 2. Database operation with error mapping
let result = sqlx::query_as!(/* ... */)
.fetch_one(&db.pool)
.await
.map_err(|e| match e {
sqlx::Error::RowNotFound => "Record not found".to_string(),
_ => format!("Database error: {}", e),
})?;
// 3. Return success
Ok(result)
}