Skip to content

Commit

Permalink
perf: parallel computation of multiple scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Mar 21, 2024
1 parent 3446b76 commit 2f94ffb
Showing 1 changed file with 49 additions and 43 deletions.
92 changes: 49 additions & 43 deletions src/Informedica.GenOrder.Lib/Api.fs
Original file line number Diff line number Diff line change
Expand Up @@ -325,50 +325,56 @@ module Api =
DoseType = dst
}
|> PrescriptionRule.filter
|> Array.collect (fun pr ->
pr
|> evaluate OrderLogger.logger.Logger
|> Array.mapi (fun i r -> (i, r))
|> Array.choose (function
| i, Ok (ord, pr) ->
let ns =
pr.DoseRule.DoseLimits
|> Array.choose (fun dl ->
match dl.DoseLimitTarget with
| SubstanceLimitTarget s -> Some s
| _ -> None
)
|> Array.distinct

let useAdjust = pr.DoseRule |> DoseRule.useAdjust

let prs, prp, adm =
ord
|> Order.Print.printOrderToMd useAdjust ns

{
No = i
Indication = pr.DoseRule.Indication
DoseType = pr.DoseRule.DoseType |> DoseType.toString
Name = pr.DoseRule.Generic
Shape = pr.DoseRule.Shape
Route = pr.DoseRule.Route
Prescription = prs |> replace
Preparation =prp |> replace
Administration = adm |> replace
Order = Some ord
UseAdjust = useAdjust
}
|> Some

| _, Error (_, _, errs) ->
errs
|> List.map string
|> String.concat "\n"
|> fun s -> ConsoleWriter.writeErrorMessage s true false
None
)
|> Array.map (fun pr ->
async {
return
pr
|> evaluate OrderLogger.logger.Logger
|> Array.mapi (fun i r -> (i, r))
|> Array.choose (function
| i, Ok (ord, pr) ->
let ns =
pr.DoseRule.DoseLimits
|> Array.choose (fun dl ->
match dl.DoseLimitTarget with
| SubstanceLimitTarget s -> Some s
| _ -> None
)
|> Array.distinct

let useAdjust = pr.DoseRule |> DoseRule.useAdjust

let prs, prp, adm =
ord
|> Order.Print.printOrderToMd useAdjust ns

{
No = i
Indication = pr.DoseRule.Indication
DoseType = pr.DoseRule.DoseType |> DoseType.toString
Name = pr.DoseRule.Generic
Shape = pr.DoseRule.Shape
Route = pr.DoseRule.Route
Prescription = prs |> replace
Preparation =prp |> replace
Administration = adm |> replace
Order = Some ord
UseAdjust = useAdjust
}
|> Some

| _, Error (_, _, errs) ->
errs
|> List.map string
|> String.concat "\n"
|> fun s -> ConsoleWriter.writeErrorMessage s true false
None
)
}
)
|> Async.Parallel
|> Async.RunSynchronously
|> Array.collect id
|> Array.distinctBy (fun pr ->
pr.DoseType,
pr.Preparation,
Expand Down

0 comments on commit 2f94ffb

Please sign in to comment.