Skip to content

Commit

Permalink
chore: changed printfn to consolewriter
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Mar 7, 2024
1 parent e444d0f commit 4b69d4b
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 147 deletions.
15 changes: 9 additions & 6 deletions src/Informedica.GenForm.Lib/Check.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Informedica.GenForm.Lib
module Check =


open Informedica.Utils.Lib
open MathNet.Numerics
open Informedica.Utils.Lib.BCL
open Informedica.GenUnits.Lib
Expand Down Expand Up @@ -130,9 +131,6 @@ module Check =


let checkInRangeOf sn (refRange : MinMax) (testRange : MinMax) =
//let toStr = MinMax.toString "min incl " "min excl " "max incl " "max excl "
//printfn $"refRange : {refRange |> toStr} testRange : {testRange |> toStr}"

let getTimeUnit mm =
match mm.Min |> Option.map Limit.getValueUnit,
mm.Max |> Option.map Limit.getValueUnit with
Expand Down Expand Up @@ -290,7 +288,7 @@ module Check =
let weight =
pat.Weight = MinMax.empty && pdsg.Patient.Weight = MinMax.empty ||
(pdsg.Patient.Weight |> MinMax.intersect pat.Weight = MinMax.empty |> not)
//printfn $"{pat |> PatientCategory.toString} intersects with {pdsg.Patient |> Informedica.ZForm.Lib.PatientCategory.toString}: {age && weight}"

age && weight


Expand Down Expand Up @@ -498,7 +496,10 @@ module Check =
testRange
with
| e ->
printfn $"{e}"
ConsoleWriter.writeErrorMessage
$"{e}"
true
false
true, $"{gstand.doseLimitTarget}\t{r}\t{p}\t{m}: kan niet worden gechecked vanwege foutmelding"

let toMinMax vuOpt =
Expand Down Expand Up @@ -624,7 +625,9 @@ module Check =
let checkAll (pat : Patient) (drs : DoseRule[]) =
drs
|> Array.mapi (fun i dr ->
printfn $"{i}. checking {dr.Generic}\t{dr.Shape}\t{dr.Route}"
ConsoleWriter.writeInfoMessage
$"{i}. checking {dr.Generic}\t{dr.Shape}\t{dr.Route}"
true false
checkDoseRule pat dr
)
|> Array.filter (fun c ->
Expand Down
11 changes: 8 additions & 3 deletions src/Informedica.GenForm.Lib/DoseRule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,11 @@ module DoseRule =
|> Some
with
| e ->
printfn $"{e}"
printfn $"cannot map {r}"
ConsoleWriter.writeErrorMessage $"""
{e}
cannot map {r}
"""
true false
None


Expand Down Expand Up @@ -599,7 +602,9 @@ module DoseRule =
|> Array.filter (fun p -> r.GPKs |> Array.exists (String.equalsCapInsens p.GPK))

if filtered |> Array.length = 0 then
printfn $"no products for {gen} {rte}"
ConsoleWriter.writeWarningMessage
$"no products for {gen} {rte}"
true false
[|
{| r with
Products =
Expand Down
4 changes: 3 additions & 1 deletion src/Informedica.GenForm.Lib/Product.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ module Product =
|> Mapping.mapUnit
|> function
| None ->
printfn $"cannot map unit: {u}"
ConsoleWriter.writeErrorMessage
$"cannot map unit: {u}"
true false
None
| Some u ->
let u =
Expand Down
5 changes: 3 additions & 2 deletions src/Informedica.GenOrder.Lib/Api.fs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ module Api =
errs
|> List.map string
|> String.concat "\n"
|> printfn "%s"
|> fun s -> ConsoleWriter.writeErrorMessage s true false
None
)
)
Expand Down Expand Up @@ -436,7 +436,8 @@ module Api =
|> Ok
with
| e ->
printfn $"error calculating values from min incr max {e}"
ConsoleWriter.writeErrorMessage $"error calculating values from min incr max {e}"
true false
"error calculating values from min incr max"
|> Error

Expand Down
8 changes: 5 additions & 3 deletions src/Informedica.GenOrder.Lib/DrugOrder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Informedica.GenOrder.Lib
module DrugOrder =

open System
open Informedica.Utils.Lib
open MathNet.Numerics
open Informedica.Utils.Lib.BCL
open Informedica.GenUnits.Lib
Expand Down Expand Up @@ -343,22 +344,23 @@ module DrugOrder =
sr.Solutions
|> Array.tryHead
|> Option.defaultValue "x"
printfn $"try find {s}"

parenteral
|> Array.tryFind (fun p ->
s |> String.notEmpty &&
p.Generic |> String.startsWith s
)
|> function
| Some p ->
printfn $"found {p}"

[|p|]
|> createProductComponent true None [||]
|> List.singleton
|> List.append ps
| None ->
printfn $"couldn't find {s} in parenterals"
ConsoleWriter.writeInfoMessage
$"couldn't find {s} in parenterals"
true false
ps
}

Expand Down
9 changes: 6 additions & 3 deletions src/Informedica.GenOrder.Lib/Order.fs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ module Order =
|> String.concat " + "
|> fun s -> $"{lv} = {s}"
| _ ->
printfn $"could not match {e}"
ConsoleWriter.writeErrorMessage
$"could not match {e}"
true false
""
)
|> List.filter (String.isNullOrWhiteSpace >> not)
Expand Down Expand Up @@ -1128,7 +1130,6 @@ module Order =
| incrs ->
if incrs |> List.length <> ((orb.Components |> List.length) + 1) then orb
else
printfn $"increments: {incrs}"
let incr =
incrs
|> List.minBy (fun i ->
Expand Down Expand Up @@ -1706,7 +1707,9 @@ module Order =
with
| _ ->
let s = ord |> toString |> String.concat "\n"
printfn $"couldn't apply constraints:\n{s}"
ConsoleWriter.writeErrorMessage
$"couldn't apply constraints:\n{s}"
true false
reraise()


Expand Down
12 changes: 8 additions & 4 deletions src/Informedica.GenOrder.Lib/OrderLogger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module OrderLogger =

with
| e ->
printfn $"error printing: {e.ToString()}"
ConsoleWriter.writeErrorMessage $"error printing: {e.ToString()}" true false
""


Expand All @@ -98,8 +98,12 @@ module OrderLogger =
| _ -> ""

| Logging.OrderException (Exceptions.OrderCouldNotBeSolved(s, o)) ->
printfn $"printing error for order {o.Orderable.Name}"
printfn $"messages: {msgs.Value.Count}"
ConsoleWriter.writeErrorMessage $"""
printing error for order {o.Orderable.Name}
messages: {msgs.Value.Count}
"""
true false

let eqs =
match msgs with
| Some msgs ->
Expand Down Expand Up @@ -140,7 +144,7 @@ module OrderLogger =
| :? SolverMessage as m -> m |> SolverLogging.printMsg
| :? OrderMessage as m -> m |> printOrderMsg msgs
| _ ->
printfn $"printMsg cannot handle {msg}"
ConsoleWriter.writeErrorMessage $"printMsg cannot handle {msg}" true false
""

// A message to send to the order logger agent
Expand Down
6 changes: 5 additions & 1 deletion src/Informedica.GenOrder.Lib/OrderVariable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ module OrderVariable =

module Dto =

open Newtonsoft.Json


/// The `Dto` data transfer type for an OrderVariable
type Dto () =
Expand Down Expand Up @@ -465,7 +467,9 @@ module OrderVariable =
create n min incr max vals cs
with
| e ->
printfn $"cannot fromDto: {dto.Name}"
ConsoleWriter.writeErrorMessage
$"cannot create OrderVariable fromDto: {dto.Name |> JsonConvert.DeserializeObject}"
true false
e |> raise


Expand Down
5 changes: 4 additions & 1 deletion src/Informedica.GenOrder.Lib/Variable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Variable =
module ValueRange =

open Informedica.GenSolver.Lib.Variable.ValueRange
open Informedica.Utils.Lib


let inline private setOpt aOption set vr =
Expand All @@ -16,7 +17,9 @@ module Variable =
| None -> vr
with
| e ->
printfn $"couldn't set {aOption} to {vr}"
ConsoleWriter.writeErrorMessage
$"couldn't set {aOption} to {vr}"
true false
vr // TODO: ugly fix need to refactor


Expand Down
5 changes: 3 additions & 2 deletions src/Informedica.GenSolver.Lib/Equation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ module Equation =
y.Values
|> ValueRange.isSubSetOf (xs |> List.reduce op).Values
if not b then
$"not a subset: {y.Values |> toStr} {(xs |> List.reduce op).Values |> toStr}"
|> printfn "%s"
ConsoleWriter.writeErrorMessage
$"not a subset: {y.Values |> toStr} {(xs |> List.reduce op).Values |> toStr}"
true false
b
else true

Expand Down
10 changes: 6 additions & 4 deletions src/Informedica.GenSolver.Lib/Solver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Informedica.GenSolver.Lib
module Solver =

open System.Runtime.CompilerServices
open Informedica.Utils.Lib

module EQD = Equation.Dto
module Name = Variable.Name
Expand Down Expand Up @@ -123,7 +124,8 @@ module Solver =
|> Exceptions.raiseExc (Some log) errs
| e ->
let msg = $"didn't catch {e}"
printfn $"{msg}"
ConsoleWriter.writeErrorMessage msg true false

msg |> failwith

let rec loop n que acc =
Expand All @@ -132,7 +134,7 @@ module Solver =
| Ok acc ->
let n = n + 1
if n > ((que @ acc |> List.length) * Constants.MAX_LOOP_COUNT) then
printfn $"too many loops: {n}"
ConsoleWriter.writeErrorMessage $"too many loops: {n}" true false
(n, que @ acc)
|> Exceptions.SolverTooManyLoops
|> Exceptions.raiseExc (Some log) []
Expand All @@ -148,7 +150,7 @@ module Solver =
match acc |> List.filter (Equation.check >> not) with
| [] -> acc |> Ok
| invalid ->
printfn "invalid equations"
ConsoleWriter.writeErrorMessage "invalid equations" true false
invalid
|> Exceptions.SolverInvalidEquations
|> Exceptions.raiseExc (Some log) []
Expand Down Expand Up @@ -226,7 +228,7 @@ module Solver =
Error (rpl @ rst, errs)
| e ->
let msg = $"something unexpected happened, didn't catch {e}"
printfn $"{msg}"
ConsoleWriter.writeErrorMessage msg true false
msg |> failwith

|> function
Expand Down
2 changes: 1 addition & 1 deletion src/Informedica.Utils.Lib/Scripts/AI.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ that have a child admitted to a pediatric critical care unit.
Explain to the parents that there child as to be put on a ventilator and has to
be intubated.
"""
>>? "translate the previous message to Dutch"
//>>? "translate the previous message to Dutch"
|> Ollama.Conversation.print


Expand Down
Loading

0 comments on commit 4b69d4b

Please sign in to comment.