Struct SubjectBuilder
pub struct SubjectBuilder { /* private fields */ }
Expand description
Builder for creating Subject instances with a fluent API
The SubjectBuilder allows for constructing complex subject data with a chainable, readable syntax. Events like doses and observations can be added sequentially, and the builder handles organizing them into occasions.
Implementations§
§impl SubjectBuilder
impl SubjectBuilder
pub fn event(self, event: Event) -> SubjectBuilder
pub fn event(self, event: Event) -> SubjectBuilder
pub fn bolus(self, time: f64, amount: f64, input: usize) -> SubjectBuilder
pub fn bolus(self, time: f64, amount: f64, input: usize) -> SubjectBuilder
Add a bolus dosing event
§Arguments
time
- Time of the bolus doseamount
- Amount of drug administeredinput
- The compartment number (zero-indexed) receiving the dose
pub fn infusion(
self,
time: f64,
amount: f64,
input: usize,
duration: f64,
) -> SubjectBuilder
pub fn infusion( self, time: f64, amount: f64, input: usize, duration: f64, ) -> SubjectBuilder
Add an infusion event
§Arguments
time
- Start time of the infusionamount
- Total amount of drug to be administeredinput
- The compartment number (zero-indexed) receiving the doseduration
- Duration of the infusion in time units
pub fn observation(self, time: f64, value: f64, outeq: usize) -> SubjectBuilder
pub fn observation(self, time: f64, value: f64, outeq: usize) -> SubjectBuilder
Add an observation event
§Arguments
time
- Time of the observationvalue
- Observed value (e.g., drug concentration)outeq
- Output equation number (zero-indexed) corresponding to this observation
pub fn observation_with_error(
self,
time: f64,
value: f64,
outeq: usize,
errorpoly: Option<ErrorPoly>,
ignore: bool,
) -> SubjectBuilder
pub fn observation_with_error( self, time: f64, value: f64, outeq: usize, errorpoly: Option<ErrorPoly>, ignore: bool, ) -> SubjectBuilder
Add an observation with error model parameters and ignore flag
§Arguments
time
- Time of the observationvalue
- Observed value (e.g., drug concentration)outeq
- Output equation number (zero-indexed) corresponding to this observationerrorpoly
- Error polynomial coefficients (c0, c1, c2, c3)ignore
- Whether to ignore this observation in calculations
pub fn repeat(self, n: usize, delta: f64) -> SubjectBuilder
pub fn repeat(self, n: usize, delta: f64) -> SubjectBuilder
Repeat the last event n
times, separated by some interval delta
§Arguments
n
- Number of repetitionsdelta
- Time increment between repetitions
§Example
use pharmsol::*;
let subject = Subject::builder("patient_001")
.bolus(0.0, 100.0, 0) // First dose at time 0
.repeat(3, 24.0) // Repeat the dose at times 24, 48, and 72
.build();
pub fn reset(self) -> SubjectBuilder
pub fn reset(self) -> SubjectBuilder
Complete the current occasion and start a new one
This finalizes the current occasion, adds it to the subject, and creates a new occasion for subsequent events. This is useful if a patient has new observations at some other occasion. Note that all states are reset!
pub fn covariate(
self,
name: impl Into<String>,
time: f64,
value: f64,
) -> SubjectBuilder
pub fn covariate( self, name: impl Into<String>, time: f64, value: f64, ) -> SubjectBuilder
Add a covariate value at a specific time
Multiple calls for the same covariate at different times will create linear interpolation between the time points.
§Arguments
name
- Name of the covariatetime
- Time point for this covariate valuevalue
- Value of the covariate at this time
§Example
use pharmsol::*;
let subject = Subject::builder("patient_001")
.covariate("weight", 0.0, 70.0) // Weight at baseline
.covariate("weight", 30.0, 68.5) // Weight at day 30
.build();
Trait Implementations§
§impl Clone for SubjectBuilder
impl Clone for SubjectBuilder
§fn clone(&self) -> SubjectBuilder
fn clone(&self) -> SubjectBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for SubjectBuilder
impl RefUnwindSafe for SubjectBuilder
impl Send for SubjectBuilder
impl Sync for SubjectBuilder
impl Unpin for SubjectBuilder
impl UnwindSafe for SubjectBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.