diff --git a/Dockerfile b/Dockerfile index e5fdce4..8776c6d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,7 +40,7 @@ COPY --from=client-build /workspace/deploy /app/public COPY src/Server/data /app/data # setting this env variable disables file logging -ENV GENPRES_PROD="" +ENV GENPRES_PROD="1" WORKDIR /app EXPOSE 8085 ENTRYPOINT [ "dotnet", "Server.dll" ] diff --git a/src/Informedica.ZIndex.Lib/ATCGroup.fs b/src/Informedica.ZIndex.Lib/ATCGroup.fs index daeef37..8de7091 100644 --- a/src/Informedica.ZIndex.Lib/ATCGroup.fs +++ b/src/Informedica.ZIndex.Lib/ATCGroup.fs @@ -144,14 +144,21 @@ module ATCGroup = let _get () = + let useDemo = FilePath.useDemo() + fun () -> - if (FilePath.groupCache true) |> File.exists then - FilePath.groupCache true + if (FilePath.groupCache useDemo) |> File.exists then + FilePath.groupCache useDemo |> Json.getCache else - ConsoleWriter.writeInfoMessage "No cache creating group.cache" true false + let p = FilePath.groupCache useDemo + ConsoleWriter.writeInfoMessage + $"No {p} creating group.cache" true false let grps = GenPresProduct.getGPKS [] |> parse - grps |> Json.cache (FilePath.groupCache false) + ConsoleWriter.writeInfoMessage + $"Created {grps |> Array.length} ATC Groups" true false + + grps |> Json.cache (FilePath.groupCache useDemo) grps |> StopWatch.clockFunc "Getting ATC groups" diff --git a/src/Informedica.ZIndex.Lib/DoseRule.fs b/src/Informedica.ZIndex.Lib/DoseRule.fs index 1afa79f..8c29e38 100644 --- a/src/Informedica.ZIndex.Lib/DoseRule.fs +++ b/src/Informedica.ZIndex.Lib/DoseRule.fs @@ -457,15 +457,22 @@ module DoseRule = let _get gpks = + let useDemo = FilePath.useDemo() + fun () -> - if FilePath.ruleCache true |> File.exists then - FilePath.ruleCache true + if FilePath.ruleCache useDemo |> File.exists then + FilePath.ruleCache useDemo |> Json.getCache else - ConsoleWriter.writeInfoMessage "No cache creating DoseRule" true false - let rules = GenPresProduct.getGPKS gpks |> parse - rules |> Json.cache (FilePath.ruleCache false) - rules + let p = FilePath.ruleCache useDemo + ConsoleWriter.writeInfoMessage + $"No {p}, creating DoseRule" true false + let rules = GenPresProduct.getGPKS gpks |> parse + ConsoleWriter.writeInfoMessage + $"Created {rules |> Array.length} Rules" true false + + rules |> Json.cache p + rules |> StopWatch.clockFunc "Getting DoseRules" diff --git a/src/Informedica.ZIndex.Lib/FilePath.fs b/src/Informedica.ZIndex.Lib/FilePath.fs index 347bbec..6cde3fb 100644 --- a/src/Informedica.ZIndex.Lib/FilePath.fs +++ b/src/Informedica.ZIndex.Lib/FilePath.fs @@ -13,20 +13,28 @@ module FilePath = let GStandPath = data + "zindex/" let substanceCache useDemo = - if File.exists (data + "cache/substance.cache") || not useDemo then data + "cache/substance.cache" + if not useDemo then data + "cache/substance.cache" else data + "cache/substance.demo" let productCache useDemo = - if File.exists (data + "cache/product.cache")|| not useDemo then data + "cache/product.cache" + if not useDemo then data + "cache/product.cache" else data + "cache/product.demo" let ruleCache useDemo = - if File.exists (data + "cache/rule.cache")|| not useDemo then data + "cache/rule.cache" + if not useDemo then data + "cache/rule.cache" else data + "cache/rule.demo" let groupCache useDemo = - if File.exists (data + "cache/group.cache")|| not useDemo then data + "cache/group.cache" + if not useDemo then data + "cache/group.cache" else data + "cache/group.demo" //https://docs.google.com/spreadsheets/d/1AEVYnqjAbVniu3VuczeoYvMu3RRBu930INhr3QzSDYQ/edit?usp=sharing let [] genpres = "1AEVYnqjAbVniu3VuczeoYvMu3RRBu930INhr3QzSDYQ" + + + let [] GENPRES_PROD = "GENPRES_PROD" + + let useDemo () = + Env.getItem GENPRES_PROD + |> Option.map ((<>) "1") + |> Option.defaultValue true diff --git a/src/Informedica.ZIndex.Lib/GenPresProduct.fs b/src/Informedica.ZIndex.Lib/GenPresProduct.fs index c7a43e6..ec97bc6 100644 --- a/src/Informedica.ZIndex.Lib/GenPresProduct.fs +++ b/src/Informedica.ZIndex.Lib/GenPresProduct.fs @@ -86,9 +86,11 @@ module GenPresProduct = let private _get gpks = + let useDemo = FilePath.useDemo() + fun () -> - if (FilePath.productCache true) |> File.exists then - FilePath.productCache true + if (FilePath.productCache useDemo) |> File.exists then + FilePath.productCache useDemo |> Json.getCache |> (fun gpps -> if gpks |> List.isEmpty then gpps @@ -103,10 +105,15 @@ module GenPresProduct = ) ) else - ConsoleWriter.writeInfoMessage "No cache creating GenPresProduct" true false - let gsps = parse gpks - gsps |> Json.cache (FilePath.productCache false) - gsps + let p = FilePath.productCache useDemo + ConsoleWriter.writeInfoMessage + $"No {p}, creating GenPresProduct" true false + let gpps = parse gpks + ConsoleWriter.writeInfoMessage + $"Created {gpps |> Array.length} GenPres Products" true false + + gpps |> Json.cache p + gpps |> StopWatch.clockFunc "Getting GenPresProducts" diff --git a/src/Informedica.ZIndex.Lib/Json.fs b/src/Informedica.ZIndex.Lib/Json.fs index 7070b32..eb62d91 100644 --- a/src/Informedica.ZIndex.Lib/Json.fs +++ b/src/Informedica.ZIndex.Lib/Json.fs @@ -21,11 +21,11 @@ module Json = |> serialize |> File.writeTextToFile p - let clearCache () = - File.Delete(FilePath.groupCache false) - File.Delete(FilePath.substanceCache false) - File.Delete(FilePath.productCache false) - File.Delete(FilePath.ruleCache false) + let clearCache useDemo = + File.Delete(FilePath.groupCache useDemo) + File.Delete(FilePath.substanceCache useDemo) + File.Delete(FilePath.productCache useDemo) + File.Delete(FilePath.ruleCache useDemo) let getCache<'T> p = ConsoleWriter.writeInfoMessage $"Reading cache: %s{p}" true false diff --git a/src/Informedica.ZIndex.Lib/Scripts/Script.fsx b/src/Informedica.ZIndex.Lib/Scripts/Script.fsx index 0d6fc33..7ce8ce6 100644 --- a/src/Informedica.ZIndex.Lib/Scripts/Script.fsx +++ b/src/Informedica.ZIndex.Lib/Scripts/Script.fsx @@ -3,23 +3,27 @@ #time -open System.Collections.Generic - +open System open Informedica.Utils.Lib open Informedica.Utils.Lib.BCL open Informedica.ZIndex.Lib +Environment.CurrentDirectory // File File.exists <| FilePath.GStandPath + "BST000T" - -FilePath.productCache true +// Check the product cache +FilePath.productCache false |> File.exists +Environment.SetEnvironmentVariable(FilePath.GENPRES_PROD, "1") +FilePath.useDemo() + +// Clear the cache +Json.clearCache (FilePath.useDemo ()) -Json.clearCache () // Load all printfn "Loading GenPresProduct ..." GenPresProduct.load [] @@ -42,6 +46,15 @@ DoseRule.routes () // load demo cache +Environment.SetEnvironmentVariable(FilePath.GENPRES_PROD, "0") +FilePath.useDemo() + +// Check the demo cache +FilePath.productCache (FilePath.useDemo ()) +|> File.exists +Json.clearCache (FilePath.useDemo ()) + +// Load demo let gpks = [ @@ -305,7 +318,6 @@ let gpks = 175552 // argipressine ] -// Load demo printfn "Loading GenPresProduct ..." GenPresProduct.load gpks printfn "Loading ATCGroup ..." @@ -316,4 +328,4 @@ printfn "Loading Substance" Substance.load () -GenPresProduct.search "amikacine" \ No newline at end of file +GenPresProduct.search "amikacine" diff --git a/src/Informedica.ZIndex.Lib/Substance.fs b/src/Informedica.ZIndex.Lib/Substance.fs index 4fa841d..98f0db6 100644 --- a/src/Informedica.ZIndex.Lib/Substance.fs +++ b/src/Informedica.ZIndex.Lib/Substance.fs @@ -37,14 +37,21 @@ module Substance = let _get _ = + let useDemo = FilePath.useDemo() + fun () -> - if FilePath.substanceCache true |> File.exists then - FilePath.substanceCache true + if FilePath.substanceCache useDemo |> File.exists then + FilePath.substanceCache useDemo |> Json.getCache else - ConsoleWriter.writeInfoMessage "No cache creating Substance" true false + let p = FilePath.substanceCache useDemo + ConsoleWriter.writeInfoMessage + $"No {p}, creating Substance" true false let substs = parse () - substs |> Json.cache (FilePath.substanceCache false) + ConsoleWriter.writeInfoMessage + $"Created {substs |> Array.length} Substances" true false + + substs |> Json.cache p substs |> StopWatch.clockFunc "Getting Substances"