rustio-admin-cli 0.27.2

Command-line tools for rustio-admin: project scaffolding, migrations, user management.
//! `Patient` model — the heart of your clinic admin.
//!
//! - `#[derive(RustioAdmin)]` produces the `AdminModel` impl that
//!   drives every list / form / cell rendering.
//! - The hand-written `impl Model` is the contract with the Postgres
//!   schema (table name, columns, row decoder, insert binder).
//! - `impl ModelAdmin for Patient { … }` opts into Django-style
//!   customisation. Override only the methods you care about; the
//!   rest inherit framework defaults.
//!
//! Rename, extend, or delete this freely — it is your project's code.

use chrono::{DateTime, NaiveDate, Utc};
use rustio_admin::{Error, Model, ModelAdmin, Row, RustioAdmin, Value};

#[derive(RustioAdmin)]
pub struct Patient {
    pub id: i64,
    pub full_name: String,
    pub date_of_birth: NaiveDate,
    pub phone: String,
    pub email: String,
    pub created_at: DateTime<Utc>,
}

impl Model for Patient {
    const TABLE: &'static str = "patients";
    const COLUMNS: &'static [&'static str] =
        &["id", "full_name", "date_of_birth", "phone", "email", "created_at"];
    const INSERT_COLUMNS: &'static [&'static str] =
        &["full_name", "date_of_birth", "phone", "email", "created_at"];

    fn id(&self) -> i64 {
        self.id
    }

    fn from_row(row: Row<'_>) -> Result<Self, Error> {
        Ok(Self {
            id: row.get_i64("id")?,
            full_name: row.get_string("full_name")?,
            date_of_birth: row.get_date("date_of_birth")?,
            phone: row.get_string("phone")?,
            email: row.get_string("email")?,
            created_at: row.get_datetime("created_at")?,
        })
    }

    fn insert_values(&self) -> Vec<Value> {
        vec![
            self.full_name.clone().into(),
            self.date_of_birth.into(),
            self.phone.clone().into(),
            self.email.clone().into(),
            self.created_at.into(),
        ]
    }
}

impl ModelAdmin for Patient {
    fn list_display() -> &'static [&'static str] {
        &["full_name", "date_of_birth", "phone", "created_at"]
    }
    fn search_fields() -> &'static [&'static str] {
        &["full_name", "phone", "email"]
    }
    fn ordering() -> &'static [&'static str] {
        &["full_name"]
    }
}