module
JosieHealth::Utils::Dosage
Defined in:
dosage.crClass Method Summary
-
.extract_from_text(text : String) : NamedTuple(dosage: String, unit: String, substance: String, route: String | Nil) | Nil
Extract medication data from natural language text Pattern: [verb]
[route] Examples: "50mg caffeine", "took 2g kratom oral" Returns nil if no match found -
.format(amount : String, unit : String) : String
Format dosage for display (amount + unit)
-
.looks_like_dosage?(text : String) : Bool
Check if a string looks like a dosage Matches: 100mg, 2.5g, 0.5ml, 47.5mg/2, 10mg/25mg, 100, etc.
-
.looks_like_hhmm_timestamp?(text : String) : Bool
Check if a string looks like an HHMM timestamp (common user error) Only matches bare 4-digit numbers without units: 0005, 0010, 0216, 1544 Does NOT match doses with units like 1200mg, 1500mg (those are valid doses) Used to detect when users confuse timestamp with dosage in ;td commands
-
.parse(dosage : String) : NamedTuple(amount: String, unit: String) | Nil
Parse a dosage string into amount and unit Supports formats: "100mg", "0.5ml", ".38ml", "100" Returns nil if invalid format
-
.parse_any(dosage : String) : NamedTuple(amount: String, unit: String) | Nil
Parse dosage, trying math expression first, then simple format
-
.parse_math(dosage : String) : NamedTuple(amount: String, unit: String) | Nil
Parse dosage with math expressions like "47.5mg/2" or "100mg*0.5" Returns calculated amount and unit, or nil if invalid
-
.validate_dose_substance(dosage : String, substance : String) : NamedTuple(dosage: String, substance: String, swapped: Bool) | Nil
Validate and potentially correct swapped dosage/substance Returns corrected values or nil if can't be corrected
Class Method Detail
Extract medication data from natural language text
Pattern: [verb]
Format dosage for display (amount + unit)
Check if a string looks like a dosage Matches: 100mg, 2.5g, 0.5ml, 47.5mg/2, 10mg/25mg, 100, etc. This is used to detect malformed entries where dosage ended up as substance
Check if a string looks like an HHMM timestamp (common user error) Only matches bare 4-digit numbers without units: 0005, 0010, 0216, 1544 Does NOT match doses with units like 1200mg, 1500mg (those are valid doses) Used to detect when users confuse timestamp with dosage in ;td commands
Parse a dosage string into amount and unit Supports formats: "100mg", "0.5ml", ".38ml", "100" Returns nil if invalid format
Parse dosage, trying math expression first, then simple format
Parse dosage with math expressions like "47.5mg/2" or "100mg*0.5" Returns calculated amount and unit, or nil if invalid
Validate and potentially correct swapped dosage/substance Returns corrected values or nil if can't be corrected