Skip to content

Commit

Permalink
chore: updated z-index and use float instead of decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Nov 3, 2023
1 parent c9b4ae8 commit d61dd52
Show file tree
Hide file tree
Showing 23 changed files with 291 additions and 300 deletions.
4 changes: 2 additions & 2 deletions src/Informedica.GenForm.Lib/DoseRule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ module DoseRule =
Substance = ""
DoseUnit = rsu.DoseUnit
Quantity =
let min = rsu.MinDoseQty |> Option.map BigRational.fromDecimal
let max = rsu.MaxDoseQty |> Option.map BigRational.fromDecimal
let min = rsu.MinDoseQty |> Option.bind BigRational.fromFloat
let max = rsu.MaxDoseQty |> Option.bind BigRational.fromFloat
(min, max) |> MinMax.fromTuple
}
)
Expand Down
6 changes: 3 additions & 3 deletions src/Informedica.GenForm.Lib/Mapping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ module Mapping =
|> Array.tail
|> Array.map (fun r ->
let getStr = getColumn Csv.getStringColumn r
let getDec = getColumn Csv.getDecimalOptionColumn r
let getFlt = getColumn Csv.getFloatOptionColumn r

{
Route = getStr "Route"
Shape = getStr "Shape"
Unit = getStr "Unit"
DoseUnit = getStr "Unit"
MinDoseQty = getDec "MinDoseQty"
MaxDoseQty = getDec "MaxDoseQty"
MinDoseQty = getFlt "MinDoseQty"
MaxDoseQty = getFlt "MaxDoseQty"
Timed = getStr "Timed" |> String.equalsCapInsens "true"
Reconstitute = getStr "Reconstitute" |> String.equalsCapInsens "true"
IsSolution = getStr "IsSolution" |> String.equalsCapInsens "true"
Expand Down
6 changes: 3 additions & 3 deletions src/Informedica.GenForm.Lib/Product.fs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ module Product =
|> Array.collect (fun gp ->
gp.PrescriptionProducts
|> Array.map (fun pp -> pp.Quantity)
|> Array.map BigRational.fromDecimal
|> Array.choose BigRational.fromFloat

)
|> Array.filter (fun br -> br > 0N)
|> Array.distinct
Expand Down Expand Up @@ -375,8 +376,7 @@ module Product =
|> String.toLower
Quantity =
s.SubstanceQuantity
|> BigRational.fromDecimal
|> Some
|> BigRational.fromFloat
Unit =
s.SubstanceUnit
|> Mapping.mapUnit
Expand Down
4 changes: 2 additions & 2 deletions src/Informedica.GenForm.Lib/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module Types =
Shape : string
Unit : string
DoseUnit : string
MinDoseQty : decimal option
MaxDoseQty : decimal option
MinDoseQty : float option
MaxDoseQty : float option
Timed : bool
Reconstitute : bool
IsSolution : bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<ProjectReference Include="..\Informedica.GenForm.Lib\Informedica.GenForm.Lib.fsproj" />
<ProjectReference Include="..\Informedica.GenSolver.Lib\Informedica.GenSolver.Lib.fsproj" />
<ProjectReference Include="..\Informedica.GenUnits.Lib\Informedica.GenUnits.Lib.fsproj" />
<ProjectReference Include="..\Informedica.MetaVision.Lib\Informedica.MetaVision.Lib.fsproj" />
<ProjectReference Include="..\Informedica.Utils.Lib\Informedica.Utils.Lib.fsproj" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
Expand Down
8 changes: 4 additions & 4 deletions src/Informedica.GenOrder.Lib/Scripts/Api2.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ Patient.teenager
)
|> Array.item 0 //|> Api.evaluate (OrderLogger.logger.Logger)
|> fun pr -> pr |> Api.createDrugOrder (pr.SolutionRules[0] |> Some) //|> printfn "%A"
|> DrugOrder.toOrder
|> DrugOrder.toOrderDto
|> Order.Dto.fromDto //|> Order.toString |> List.iter (printfn "%s")
|> Order.applyConstraints //|> Order.toString |> List.iter (printfn "%s")

|> Order.solveMinMax true OrderLogger.noLogger
|> Result.bind (Api.increaseIncrement OrderLogger.logger.Logger)
|> Result.bind (Api.increaseIncrements OrderLogger.logger.Logger)
|> function
| Error (ord, msgs) ->
printfn "oeps error"
Expand Down Expand Up @@ -186,7 +186,7 @@ Patient.teenager
// |> printfn "%s"
| Ok ord ->
ord
|> Order.Print.printOrderToString [|"gentamincine"|]
|> Order.Print.printOrderToString [|"benzylpenicilline"|]
|> fun (prs, prep, adm) -> printfn $"{prs}"
// ord
// |> Order.toString
Expand Down Expand Up @@ -260,7 +260,7 @@ let testDto =
)
|> Array.item 0 //|> Api.evaluate (OrderLogger.logger.Logger)
|> fun pr -> pr |> Api.createDrugOrder None //(pr.SolutionRules[0] |> Some) //|> printfn "%A"
|> DrugOrder.toOrder
|> DrugOrder.toOrderDto


module ValueUnit = Informedica.GenUnits.Lib.ValueUnit
Expand Down
1 change: 0 additions & 1 deletion src/Informedica.GenOrder.Lib/Scripts/load.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#load "../DrugOrder.fs"
#load "../Patient.fs"
#load "../Api.fs"
#load "../Demo.fs"


fsi.AddPrinter<System.DateTime> (fun dt -> dt.ToShortDateString())
Expand Down
114 changes: 57 additions & 57 deletions src/Informedica.ZForm.Lib/Dto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ module Dto =
[<CLIMutable>]
type Dto =
{
AgeInMo : decimal
WeightKg : decimal
HeightCm : decimal
BSAInM2 : decimal
AgeInMo : float
WeightKg : float
HeightCm : float
BSAInM2 : float
Gender : string
BirthWeightGram : decimal
BirthWeightGram : float
GestAgeWeeks : int
GestAgeDays : int
GPK : int
Expand All @@ -47,9 +47,9 @@ module Dto =
TradeProduct : string
Shape : string
Label : string
Concentration : decimal
Concentration : float
ConcentrationUnit : string
Multiple : decimal
Multiple : float
MultipleUnit : string
Route : string
Indication : string
Expand All @@ -61,57 +61,57 @@ module Dto =
and Rule =
{
Substance : string
Concentration : decimal
Concentration : float
Unit : string

Frequency : string

NormTotalDose : decimal
MinTotalDose : decimal
MaxTotalDose : decimal
MaxPerDose : decimal
NormTotalDose : float
MinTotalDose : float
MaxTotalDose : float
MaxPerDose : float

NormTotalDosePerKg : decimal
MinTotalDosePerKg : decimal
MaxTotalDosePerKg : decimal
MaxPerDosePerKg : decimal
NormTotalDosePerKg : float
MinTotalDosePerKg : float
MaxTotalDosePerKg : float
MaxPerDosePerKg : float

NormTotalDosePerM2 : decimal
MinTotalDosePerM2 : decimal
MaxTotalDosePerM2 : decimal
MaxPerDosePerM2 : decimal
NormTotalDosePerM2 : float
MinTotalDosePerM2 : float
MaxTotalDosePerM2 : float
MaxPerDosePerM2 : float
}

let rule =
{
Substance = ""
Concentration = 0m
Concentration = 0.
Unit = ""
Frequency = ""
NormTotalDose = 0m
MinTotalDose = 0m
MaxTotalDose = 0m
MaxPerDose = 0m
NormTotalDosePerKg = 0m
MinTotalDosePerKg = 0m
MaxTotalDosePerKg = 0m
MaxPerDosePerKg = 0m
NormTotalDosePerM2 = 0m
MinTotalDosePerM2 = 0m
MaxTotalDosePerM2 = 0m
MaxPerDosePerM2 = 0m
NormTotalDose = 0.
MinTotalDose = 0.
MaxTotalDose = 0.
MaxPerDose = 0.
NormTotalDosePerKg = 0.
MinTotalDosePerKg = 0.
MaxTotalDosePerKg = 0.
MaxPerDosePerKg = 0.
NormTotalDosePerM2 = 0.
MinTotalDosePerM2 = 0.
MaxTotalDosePerM2 = 0.
MaxPerDosePerM2 = 0.
}



let dto =
{
AgeInMo = 0m
WeightKg = 0m
HeightCm = 0m
BSAInM2 = 0m
AgeInMo = 0.
WeightKg = 0.
HeightCm = 0.
BSAInM2 = 0.
Gender = ""
BirthWeightGram = 0m
BirthWeightGram = 0.
GestAgeWeeks = 0
GestAgeDays = 0
GPK = 0
Expand All @@ -122,9 +122,9 @@ module Dto =
TradeProduct = ""
Shape = ""
Label = ""
Concentration = 0m
Concentration = 0.
ConcentrationUnit = ""
Multiple = 0m
Multiple = 0.
MultipleUnit = ""
Route = ""
Indication = ""
Expand Down Expand Up @@ -175,7 +175,7 @@ module Dto =
let conc, unt =
match gp.Substances |> Seq.tryFind (fun s -> s.SubstanceName |> String.equalsCapInsens gpp.Name) with
| Some s -> s.SubstanceQuantity, s.SubstanceUnit
| None -> 0m, ""
| None -> 0., ""

let tps =
gp.PrescriptionProducts
Expand All @@ -191,12 +191,12 @@ module Dto =

| None ->
printfn "Could not find product %s %s %s with GPK: %i" dto.Generic dto.Shape dto.Route dto.GPK
0, "", 0m, "", ""
0, "", 0., "", ""

gpk, gpp.Name, gpp.Shape, lbl, conc, unt, tps
| _ ->
printfn "Could not find product %s %s %s with GPK: %i" dto.Generic dto.Shape dto.Route dto.GPK
0, "", "", "", 0m, "", ""
0, "", "", "", 0., "", ""


let fillRuleWithDosage gpk (d : Dosage) (r : Rule) =
Expand All @@ -207,7 +207,7 @@ module Dto =
|> GPP.getSubstQtyUnit
|> Array.tryFind (fun (n, _, _) -> n |> String.equalsCapInsens d.Name) with
| Some (_, conc, unt) -> conc, unt
| None -> 0m, ""
| None -> 0., ""

let freqsToStr (fr : Frequency) =
fr.Frequencies
Expand All @@ -229,9 +229,9 @@ module Dto =
vu
|> ValueUnit.getValue
|> Array.head
|> BigRational.toDecimal
|> Decimal.fixPrecision 2
| None -> 0m
|> BigRational.toFloat
|> Double.fixPrecision 2
| None -> 0.
)

{
Expand All @@ -255,22 +255,22 @@ module Dto =
MaxTotalDosePerM2 = d |> getValue Dosage.Optics.exclMaxNormBSATotalDosagePrism

MaxPerDose =
if r.MaxPerDose = 0m then
if r.MaxPerDose = 0. then
let d1 = d |> getValue Dosage.Optics.exclMaxNormSingleDosagePrism
let d2 = d |> getValue Dosage.Optics.exclMaxNormStartDosagePrism
if d1 = 0m then d2 else d1
if d1 = 0. then d2 else d1
else r.MaxPerDose
MaxPerDosePerKg =
if r.MaxPerDosePerKg = 0m then
if r.MaxPerDosePerKg = 0. then
let d1 = d |> getValue Dosage.Optics.exclMaxNormWeightSingleDosagePrism
let d2 = d |> getValue Dosage.Optics.exclMaxNormWeightStartDosagePrism
if d1 = 0m then d2 else d1
if d1 = 0. then d2 else d1
else r.MaxPerDosePerKg
MaxPerDosePerM2 =
if r.MaxTotalDosePerM2 = 0m then
if r.MaxTotalDosePerM2 = 0. then
let d1 = d |> getValue Dosage.Optics.exclMaxNormBSASingleDosagePrism
let d2 = d |> getValue Dosage.Optics.exclMaxNormBSAStartDosagePrism
if d1 = 0m then d2 else d1
if d1 = 0. then d2 else d1
else r.MaxTotalDosePerM2
}

Expand All @@ -295,14 +295,14 @@ module Dto =
)

let dto =
if dto.BSAInM2 > 0m then dto
if dto.BSAInM2 > 0. then dto
else
if dto.HeightCm > 0m && dto.WeightKg > 0m then
if dto.HeightCm > 0. && dto.WeightKg > 0. then
{
dto with
BSAInM2 =
// (w / (l ** 2.)) |> Some
dto.WeightKg / (((dto.HeightCm |> float) ** 2.) |> decimal)
dto.WeightKg / (((dto.HeightCm |> float) ** 2.) |> float)
}
else
dto
Expand Down Expand Up @@ -452,7 +452,7 @@ module Dto =
//TODO: rewrite to new online mapping
//|> Mapping.mapUnit Mapping.ZIndex Mapping.GenPres
Multiple =
if dto.Multiple = 0m then conc
if dto.Multiple = 0. then conc
else dto.Multiple
MultipleUnit =
if dto.MultipleUnit = "" then
Expand Down
11 changes: 7 additions & 4 deletions src/Informedica.ZForm.Lib/GStand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ module GStand =
/// Map GSTand min max float Option values to
/// a `DoseRule` `MinMax`
let mapMinMax<'a>
(setMin: decimal Option -> 'a -> 'a)
(setMax: decimal Option -> 'a -> 'a)
(setMin: float Option -> 'a -> 'a)
(setMax: float Option -> 'a -> 'a)
(minmax: ZIndexTypes.RuleMinMax)
(o: 'a)
=
Expand Down Expand Up @@ -130,7 +130,10 @@ module GStand =
| None -> vu

let s =
fr.Frequency |> BigRational.fromDecimal |> string
fr.Frequency
|> decimal
|> BigRational.fromDecimal
|> string

let s = s + " X[Count]"

Expand Down Expand Up @@ -209,7 +212,7 @@ module GStand =
{|
name = n
time = gstdsr.Freq.Time
isOne = gstdsr.Freq.Frequency = 1m
isOne = gstdsr.Freq.Frequency = 1.
|}
routes = gstdsr.Routes |> Array.toList
indication = gstdsr.Indication
Expand Down
1 change: 0 additions & 1 deletion src/Informedica.ZForm.Lib/Informedica.ZForm.Lib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<None Include="Scripts\load.fsx" />
<None Include="Scripts\loadDLL.fsx" />
<None Include="Scripts\GStand.fsx" />
<None Include="Scripts\GenForm3.fsx" />
<None Include="Scripts\Dto.fsx" />
<None Include="Scripts\Scripts.fsx" />
<None Include="Scripts\Dto.fsx" />
Expand Down
3 changes: 2 additions & 1 deletion src/Informedica.ZForm.Lib/ValueUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ module ValueUnit =

/// Create a `ValueUnit` using a float value
/// `v` and a `Unit` `u`.
let fromDecimal (v: decimal) u =
let fromDecimal (v: float) u =
v
|> decimal
|> BigRational.fromDecimal
|> createSingle u

Expand Down
Loading

0 comments on commit d61dd52

Please sign in to comment.