swarm / companies/starter/work/project/src/sync/load/generator.rs

raw file 1561 bytes
use std::time::{SystemTime, UNIX_EPOCH};

/// A single patient record as it appears in the sync pipeline.
#[derive(Debug, Clone)]
pub struct PatientRecord {
    pub patient_id: u64,
    pub mrn: String,
    pub first_name: String,
    pub last_name: String,
    pub dob: i64, // Unix timestamp
    pub record_type: String,
    pub payload: Vec<u8>,
}

/// Configuration for the load generator.
#[derive(Debug, Clone)]
pub struct LoadConfig {
    pub patient_count: usize,
    pub seed: u64,
    pub records_per_batch: usize,
}

impl Default for LoadConfig {
    fn default() -> Self {
        Self {
            patient_count: 10_000,
            seed: 42,
            records_per_batch: 500,
        }
    }
}

/// Deterministic PRNG (xorshift64) so runs are reproducible.
struct XorShift64 {
    state: u64,
}

impl XorShift64 {
    fn new(seed: u64) -> Self {
        let mut state = seed;
        if state == 0 { state = 0x9E3779B97F4A7C15; }
        Self { state }
    }

    fn next(&mut self) -> u64 {
        let mut x = self.state;
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
        self.state = x;
        x
    }
}

const FIRST_NAMES: &[&str] = &["John", "Jane", "Robert", "Maria", "Wei", "Aisha", "Carlos", "Yuki", "Fatima", "Liam"];
const LAST_NAMES: &[&str] = &["Smith", "Garcia", "Chen", "Nakamura", "Patel", "Okafor", "Vasquez", "Hassan", "Reyes", "Tanaka"];
const RECORD_TYPES: &[&str] = &["ADT", "ORM", "ORU", "SIU", "MDM"];

/// Generate `patient_count` deterministic patient records.
pub fn generate_patients(cfg: &Load