From cb659d7dc49e1776b99276af7bc670fc7f4414c0 Mon Sep 17 00:00:00 2001 From: Casper Bollen Date: Wed, 1 Nov 2023 12:45:04 +0100 Subject: [PATCH] chore: working on GenOrder added some comments and removed dead code --- src/Informedica.GenOrder.Lib/OrderLogger.fs | 2 +- src/Informedica.GenOrder.Lib/OrderVariable.fs | 4 +- src/Informedica.GenOrder.Lib/Types.fs | 154 +++++++++++------- src/Informedica.GenOrder.Lib/ValueUnit.fs | 18 -- src/Informedica.GenSolver.Lib/Api.fs | 9 + .../Scripts/Pick.fsx | 2 +- .../Scripts/Solver.fsx | 2 +- .../Scripts/Tests.fsx | 2 +- .../SolverLogging.fs | 7 +- tests/Informedica.GenSolver.Tests/Tests.fs | 2 +- 10 files changed, 115 insertions(+), 87 deletions(-) diff --git a/src/Informedica.GenOrder.Lib/OrderLogger.fs b/src/Informedica.GenOrder.Lib/OrderLogger.fs index e48bea8..f82b3f3 100644 --- a/src/Informedica.GenOrder.Lib/OrderLogger.fs +++ b/src/Informedica.GenOrder.Lib/OrderLogger.fs @@ -167,7 +167,7 @@ module OrderLogger = let printLogger : Logger = { Log = (printMsg None >> (printfn "%s")) } - // Create the logger agent + // the logger agent let logger = let write path i t ms m = diff --git a/src/Informedica.GenOrder.Lib/OrderVariable.fs b/src/Informedica.GenOrder.Lib/OrderVariable.fs index 49b1b85..40e520b 100644 --- a/src/Informedica.GenOrder.Lib/OrderVariable.fs +++ b/src/Informedica.GenOrder.Lib/OrderVariable.fs @@ -762,11 +762,11 @@ module OrderVariable = |> Total - /// Turn a `Quantity` to a string + /// Turn a `Total` to a string let toString = toOrdVar >> (toString false) - /// Print a `Quantity` as a value unit string list + /// Print a `Total` as a value unit string list let toValueUnitStringList = toValueUnitStringList toOrdVar diff --git a/src/Informedica.GenOrder.Lib/Types.fs b/src/Informedica.GenOrder.Lib/Types.fs index 1b764de..1704477 100644 --- a/src/Informedica.GenOrder.Lib/Types.fs +++ b/src/Informedica.GenOrder.Lib/Types.fs @@ -4,6 +4,7 @@ namespace Informedica.GenOrder.Lib [] module Types = + open System open MathNet.Numerics @@ -14,11 +15,10 @@ module Types = type Patient = Informedica.GenForm.Lib.Types.Patient - /// A `VariableUnit` is the combination of - /// an `Informedica.GenSolver.Lib.Variable` with - /// an `Informedica.GenUnits.Lib.Unit` - /// The `Variable` stores the base values according - /// to the `Unit` + /// + /// An OrderVariable represents the combination + /// of a Variable and Constraints + /// type OrderVariable = { Constraints : Constraints @@ -34,77 +34,69 @@ module Types = } + /// /// An order equation is either a product equation or a /// sum equation + /// type OrderEquation = | OrderProductEquation of OrderVariable * OrderVariable list | OrderSumEquation of OrderVariable * OrderVariable list - /// Time "tme" /// Type that represents a time type Time = Time of OrderVariable - /// Count "cnt" /// Type that represents a count type Count = Count of OrderVariable - /// Count / Time "frq" /// Type that represents a frequency type Frequency = Frequency of OrderVariable - /// Quantity "qty" /// Type that represents a quantity type Quantity = Quantity of OrderVariable - //// Quantity / Time "ptm" /// Type that represents a quantity per time type PerTime = PerTime of OrderVariable - /// Quantity / Time "rte" /// Type that represents a rate type Rate = Rate of OrderVariable - /// Quantity "tot" /// Type that represents a total type Total = Total of OrderVariable - /// Quantity / Quantity "cnc" /// Type that represents a concentration type Concentration = Concentration of OrderVariable - /// Quantity / Adjust "qty_adj" /// Type that represents a adjusted quantity type QuantityAdjust = QuantityAdjust of OrderVariable - /// Quantity / Adjust / Time "ptm_adj" /// Type that represents a adjusted quantity per time type PerTimeAdjust = PerTimeAdjust of OrderVariable - /// Quantity / Adjust / Time "rte_adj" /// Type that represents a adjusted quantity per time type RateAdjust = RateAdjust of OrderVariable - /// Quantity / Adjust "tot_adj" /// Type that represents a adjusted total type TotalAdjust = TotalAdjust of OrderVariable - /// An Id is represented by a string type Id = Id of string + /// + /// Represents a Dose + /// type Dose = { Quantity : Quantity @@ -121,17 +113,17 @@ module Types = /// Models an `Item` in a `Component` type Item = { - /// The name of the item + // The name of the item Name: Name - /// The quantity of an `Item` in a `Component` + // The quantity of an `Item` in a `Component` ComponentQuantity: Quantity - /// The quantity of an `Item` in an `Orderable` + // The quantity of an `Item` in an `Orderable` OrderableQuantity: Quantity - /// The `Item` concentration in a `Component` + // The `Item` concentration in a `Component` ComponentConcentration: Concentration - /// The `Item` concentration in an `Orderable` + // The `Item` concentration in an `Orderable` OrderableConcentration: Concentration - /// The `Item` `Dose`, i.e. quantity, total and rate of `Item` administered + // The `Item` `Dose` of `Item` administered Dose: Dose } @@ -139,7 +131,7 @@ module Types = /// Models in a `Component` in and `Orderable` type Component = { - Id : Id //TODO: remove + Id : Id /// The name of a `Component` Name: Name // The shape of an component @@ -156,8 +148,7 @@ module Types = OrderCount: Count /// The concentration of a `Component` in an `Orderable` OrderableConcentration: Concentration - // The `Component` `Dose`, - /// i.e. quantity, total and rate of `Component` administered + // The `Component` `Dose` of `Component` administered Dose: Dose /// The `Item`s in a `Component` Items: Item list @@ -200,7 +191,7 @@ module Types = Adjust: Quantity /// That what can be ordered Orderable: Orderable - /// How the orderable is prescribed + /// How the Orderable is prescribed Prescription: Prescription /// The route of administration of the order Route: string // Route @@ -220,6 +211,7 @@ module Types = | Timed of Frequency * Time + /// A string list that represents either a product or sum equation type EquationMapping = | ProductMapping of string list | SumMapping of string list @@ -234,44 +226,48 @@ module Types = | TimedOrder + /// Shorthand for a Informedica.GenForm.Lib.Types.MinMax type MinMax = Informedica.GenForm.Lib.Types.MinMax + /// Shorthand for a Informedica.GenForm.Lib.Types.DoseLimit type DoseLimit = Informedica.GenForm.Lib.Types.DoseLimit + /// Shorthand for a Informedica.GenForm.Lib.Types.SolutionLimit type SolutionLimit = Informedica.GenForm.Lib.Types.SolutionLimit /// The representation of a drug order that /// can be derived by a drug product inventory - /// and the related dose rule + /// and the related dose rule. A DrugOrder maps + /// to an Orderable and a Prescription. type DrugOrder = { - /// Identifies the specific drug order + // Identifies the specific drug order Id: string - /// The name of the order + // The name of the order Name : string - /// The list of drug products that can be used for the order + // The list of drug products that can be used for the order Products : ProductComponent list - /// The quantities of the drug order + // The quantities of the drug order Quantities : BigRational list - /// The unit the `DrugOrder` is measured in, - /// i.e. of the `Quantities` + // The unit the `DrugOrder` is measured in, + // i.e. of the `Quantities` Unit : string - /// The route by which the order is applied + // The route by which the order is applied Route : string // The type of order OrderType : OrderType - /// The list of possible frequency values + // The list of possible frequency values Frequencies : BigRational list - /// The time unit to be used when using a frequency + // The time unit to be used when using a frequency FreqUnit : string - /// The list of possible rate values + // The list of possible rate values Rates : BigRational list - /// The time unit to be used when using a rate + // The time unit to be used when using a rate RateUnit : string - /// The min and/or max time for the infusion time + // The min and/or max time for the infusion time Time : MinMax - /// The time unit for infusion time (duration) + // The time unit for infusion time (duration) TimeUnit : string - /// The dose limits for an drugorder + // The dose limits for an drugorder Dose : DoseLimit option // The amount of orderable that will be given each time DoseCount : BigRational option @@ -280,71 +276,107 @@ module Types = // The adjust unit AdjustUnit : string } - /// The product components that are used by the drug order + /// The product components that are used by the drug order. + /// A product component maps to a Component in an Orderable. and ProductComponent = { - /// The name of the product + // The name of the product Name : string - /// The shape of the product + // The shape of the product Shape : string - /// The quantities of the product - /// Note: measured in the same unit as - /// the `DrugOrder` unit + // The quantities of the product + // Note: measured in the same unit as + // the `DrugOrder` unit Quantities : BigRational list - /// The "divisibility" of the products + // The "divisibility" of the products Divisible : BigRational option - /// The time unit used for frequency + // The time unit used for frequency TimeUnit : string - /// The time unit used for rate + // The time unit used for rate RateUnit : string - /// The list of substances contained in the product + // The list of substances contained in the product Substances: SubstanceItem list } + /// A substance in a product. A substance maps to an Item in a Component. and SubstanceItem = { - /// The name of the substance + // The name of the substance Name : string - /// The possible concentrations of the substance - /// in the products + // The possible concentrations of the substance + // in the products Concentrations : BigRational list - /// The unit by which the substance is - /// measured. + // The unit by which the substance is + // measured. Unit : string - /// The time unit used for the frequency + // The time unit used for the frequency TimeUnit : string - /// The dose limits for a substance + // The dose limits for a substance Dose : DoseLimit option - /// The solution limits for a solution + // The solution limits for a solution Solution : SolutionLimit option } + /// + /// The representation of an order with a + /// + /// Prescription + /// Preparation + /// Administration + /// + /// + /// type Scenario = { + // the id of the scenario No : int + // the indication for the the order Indication : string + // the dose type of the order DoseType : string + // the name of the order Name : string + // the shape of the order Shape : string + // the route of the order Route : string + // the prescription of the order Prescription : string + // the preparation of the order Preparation : string + // the administration of the order Administration : string + // the order itself Order : Order option } + /// + /// The main communication object to transfer the + /// results of the solver to the client. The fields + /// are used to select the correct scenario. + /// type ScenarioResult = { + // the list of indications to select from Indications: string [] + // the list of generics to select from Generics: string [] + // the list of routes to select from Routes: string [] + // the list of shapes to select from Shapes: string [] + // the selected indication Indication: string option + // the selected generic Generic: string option + // the selected route Route: string option + // the selected shape Shape: string option + // the patient Patient: Patient + // the list of scenarios Scenarios: Scenario [] } diff --git a/src/Informedica.GenOrder.Lib/ValueUnit.fs b/src/Informedica.GenOrder.Lib/ValueUnit.fs index 5369485..83f7ae2 100644 --- a/src/Informedica.GenOrder.Lib/ValueUnit.fs +++ b/src/Informedica.GenOrder.Lib/ValueUnit.fs @@ -15,29 +15,11 @@ module ValueUnit = open ValueUnit - let valueToBase u v = - create u v - |> toBaseValue - let unitToString = Units.toString Units.Dutch Units.Short - let calcUnit op u1 u2 = - - match u1, u2 with - | NoUnit, _ - | _, NoUnit -> NoUnit - | u1, u2 -> - let vu1 = 1N |> createSingle u1 - let vu2 = 1N |> createSingle u2 - - vu1 |> op <| vu2 - |> get - |> snd - - let isAdjust (u : Unit) = u |> Group.eqsGroup (Units.Weight.kiloGram) || u |> Group.eqsGroup (Units.BSA.m2) diff --git a/src/Informedica.GenSolver.Lib/Api.fs b/src/Informedica.GenSolver.Lib/Api.fs index 4f2ff93..1bafe86 100644 --- a/src/Informedica.GenSolver.Lib/Api.fs +++ b/src/Informedica.GenSolver.Lib/Api.fs @@ -60,7 +60,16 @@ module Api = |> Some + /// /// Solve an `Equations` list + /// + /// True if only min, incr and max values are to be used + /// The logger to log operations + /// List of equations to solve + /// A result type of the solved equations + /// + /// This function is a wrapper around `Solver.solveAll` + /// let solveAll = Solver.solveAll diff --git a/src/Informedica.GenSolver.Lib/Scripts/Pick.fsx b/src/Informedica.GenSolver.Lib/Scripts/Pick.fsx index be62cec..ac51ce7 100644 --- a/src/Informedica.GenSolver.Lib/Scripts/Pick.fsx +++ b/src/Informedica.GenSolver.Lib/Scripts/Pick.fsx @@ -44,7 +44,7 @@ module Solve = let logger = fun s -> File.AppendAllLines("order.log", [s]) - |> SolverLogging.logger + |> SolverLogging.create let n = n |> Name.createExc try Api.solve b Solver.sortQue logger n p eqs diff --git a/src/Informedica.GenSolver.Lib/Scripts/Solver.fsx b/src/Informedica.GenSolver.Lib/Scripts/Solver.fsx index ab7e238..2bfe530 100644 --- a/src/Informedica.GenSolver.Lib/Scripts/Solver.fsx +++ b/src/Informedica.GenSolver.Lib/Scripts/Solver.fsx @@ -74,7 +74,7 @@ module TestSolver = let logger = fun (s : string) -> printfn $"{s}" - |> SolverLogging.logger + |> SolverLogging.create let solve n p eqs = let n = n |> Name.createExc diff --git a/src/Informedica.GenSolver.Lib/Scripts/Tests.fsx b/src/Informedica.GenSolver.Lib/Scripts/Tests.fsx index 22c2dab..b3b66c3 100644 --- a/src/Informedica.GenSolver.Lib/Scripts/Tests.fsx +++ b/src/Informedica.GenSolver.Lib/Scripts/Tests.fsx @@ -175,7 +175,7 @@ module TestSolver = let logger = fun (_ : string) -> () //File.AppendAllLines("examples.log", [s]) - |> SolverLogging.logger + |> SolverLogging.create let solve n p eqs = let n = n |> Name.createExc diff --git a/src/Informedica.GenSolver.Lib/SolverLogging.fs b/src/Informedica.GenSolver.Lib/SolverLogging.fs index 33296c6..99925a1 100644 --- a/src/Informedica.GenSolver.Lib/SolverLogging.fs +++ b/src/Informedica.GenSolver.Lib/SolverLogging.fs @@ -166,7 +166,12 @@ module SolverLogging = | ConstrainedSolved c -> $"Constraint {c |> Constraint.toString} solved" - let logger f = + /// + /// Create a logger that uses the given function to log + /// + /// The function to process the log string + /// A logger + let create f = { Log = fun { TimeStamp = _; Level = _; Message = msg } -> diff --git a/tests/Informedica.GenSolver.Tests/Tests.fs b/tests/Informedica.GenSolver.Tests/Tests.fs index 26d21ff..dc0ab36 100644 --- a/tests/Informedica.GenSolver.Tests/Tests.fs +++ b/tests/Informedica.GenSolver.Tests/Tests.fs @@ -162,7 +162,7 @@ module TestSolver = let logger = fun (_ : string) -> () //File.AppendAllLines("examples.log", [s]) - |> SolverLogging.logger + |> SolverLogging.create let solve n p eqs = let n = n |> Name.createExc