Additional medication to and from string improvements#114
Merged
halcwb merged 3 commits intoinformedica:masterfrom Jan 25, 2026
Merged
Additional medication to and from string improvements#114halcwb merged 3 commits intoinformedica:masterfrom
halcwb merged 3 commits intoinformedica:masterfrom
Conversation
…cation logging, handle once without a dose case order printing, improve dose rule validation depending on schedule
Greptile OverviewGreptile SummaryThis PR enhances medication and dose handling by introducing explicit Key improvements:
The changes are well-structured and improve code maintainability. The new validation logic is more explicit and type-safe. Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Medication
participant DoseLimit
participant Units
participant DoseRule
participant DoseType
User->>Medication: fromString(medicationText)
Medication->>Medication: Parse medication structure
Note over Medication: Process DoseLimit fields
Medication->>DoseLimit: Parse labeled fields ([dun], [qty], etc.)
alt Empty value
Medication->>Medication: Skip field (default/unset)
else DoseUnit field [dun]
Medication->>Units: fromString(doseUnitStr)
Units-->>Medication: Return Unit or None
alt Valid unit
Medication->>DoseLimit: Set DoseUnit
else Invalid unit
Medication->>Medication: Add error
end
else Other labeled field
Medication->>Medication: Use field parser
Medication->>DoseLimit: Update field value
end
Note over Medication: Process SolutionLimit fields
alt qts field
Medication->>Medication: parseValueUnitOpt(valueStr)
Medication->>Medication: Update Quantities
else Other fields
Medication->>Medication: Use existing parsers
end
Medication->>DoseLimit: toString()
DoseLimit->>Units: toStringEngShortWithoutGroup(DoseUnit)
Units-->>DoseLimit: Short unit string
DoseLimit-->>Medication: Formatted string with [dun] label
Note over DoseRule: Validation with dose type awareness
DoseRule->>DoseType: fromString(doseType, doseText)
DoseType-->>DoseRule: Return DoseType variant
alt NoDoseType
DoseRule->>DoseRule: Return false (invalid)
else Once
DoseRule->>DoseRule: Return true (always valid)
else OnceTimed
DoseRule->>DoseRule: Check MaxTime and TimeUnit
else Discontinuous
DoseRule->>DoseRule: Check Frequencies and FreqUnit
else Timed
DoseRule->>DoseRule: Check Frequencies, FreqUnit, MaxTime, TimeUnit
else Continuous
DoseRule->>DoseRule: Check RateUnit and (MaxRate or MaxRateAdj)
end
DoseRule-->>User: Valid dose rules
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements and fixes to the medication and dosing modules, focusing on better handling and representation of dose units, more robust parsing and validation, and enhanced test/demo coverage. The most significant changes include the introduction of a new field label for dose units, improved parsing logic for medication text inputs, stricter dose rule validation, and expanded test scenarios.
Dose Unit Handling and Parsing:
DoseUnit([dun]) inDoseLimit.FieldLabelsand integrated it into both serialization and parsing logic for dose limits and medication. This ensures that dose units are explicitly labeled and correctly processed when converting to and from string representations. [1] [2] [3] [4]toStringEngShortWithoutGroupinUnitsto generate a short English string for units without group annotation, used for displaying dose units.Dose Rule Validation:
doseRuleDataIsValidto use the parsed dose type, enabling stricter and more context-aware validation for different dosing scenarios (e.g., requiring time fields for timed doses, frequency for discontinuous doses, etc.). This prevents invalid or incomplete dose rules from being accepted.Medication Parsing Improvements:
[dun]label, skipping empty/default values and reporting errors for unknown dose units.qts(quantities) with value-units, adding error handling for invalid formats.Testing, Demos, and Output:
Miscellaneous:
Fixing medication from and to string enabling future medication template creation and testing of different scenario's. Includes improvements in depending code, like value unit.
@greptile: review