From 248b330b21315a3899a869eedd94fec6a7fbfba8 Mon Sep 17 00:00:00 2001 From: Casper Bollen Date: Mon, 6 Nov 2023 07:24:45 +0100 Subject: [PATCH] docs: added doserule comments --- src/Informedica.ZForm.Lib/GStand.fs | 4 +- src/Informedica.ZIndex.Lib/Assortment.fs | 15 ++ src/Informedica.ZIndex.Lib/ConsumerProduct.fs | 7 + src/Informedica.ZIndex.Lib/DoseRule.fs | 173 ++++++++++++------ src/Informedica.ZIndex.Lib/GenPresProduct.fs | 97 +++++++--- src/Informedica.ZIndex.Lib/GenericProduct.fs | 26 ++- src/Informedica.ZIndex.Lib/Names.fs | 27 ++- .../PrescriptionProduct.fs | 7 + src/Informedica.ZIndex.Lib/Route.fs | 36 ++-- src/Informedica.ZIndex.Lib/RuleFinder.fs | 2 +- src/Informedica.ZIndex.Lib/Substance.fs | 23 ++- src/Informedica.ZIndex.Lib/TradeProduct.fs | 7 + 12 files changed, 317 insertions(+), 107 deletions(-) diff --git a/src/Informedica.ZForm.Lib/GStand.fs b/src/Informedica.ZForm.Lib/GStand.fs index 587ddee..b4b5799 100644 --- a/src/Informedica.ZForm.Lib/GStand.fs +++ b/src/Informedica.ZForm.Lib/GStand.fs @@ -119,7 +119,7 @@ module GStand = // TODO: rewrite to frequency mapping /// Map GStand frequency string to a valid /// frequency `ValueUnit`. - let mapFreq (fr: DR.Frequency) = + let mapFreq (fr: ZIndexTypes.RuleFrequency) = let map vu = match [ 2N, ValueUnit.freqUnitPerNday 3N, ValueUnit.freqUnitPerNHour 36N @@ -202,7 +202,7 @@ module GStand = vu * x |> Some - let minmax n mapping (mm: DR.MinMax) = + let minmax n mapping (mm: ZIndexTypes.RuleMinMax) = MinIncrMax.empty |> setMin (mm.Min |> Option.bind (toVu n mapping)) |> setMax (mm.Max |> Option.bind (toVu n mapping)) diff --git a/src/Informedica.ZIndex.Lib/Assortment.fs b/src/Informedica.ZIndex.Lib/Assortment.fs index 0ba37f8..23b37b2 100644 --- a/src/Informedica.ZIndex.Lib/Assortment.fs +++ b/src/Informedica.ZIndex.Lib/Assortment.fs @@ -10,6 +10,14 @@ module Assortment = + /// + /// Create an Assortment product, a generic + /// product which is available in the assortment. + /// + /// The GPK code of the product. + /// The generic name of the product. + /// The tall man name of the product. + /// The divisibility of the product. let create gpk gen tall div = { GPK = gpk @@ -49,4 +57,11 @@ module Assortment = ) |> StopWatch.clockFunc "Getting Formulary" + + /// + /// Gets the assortment of products. + /// + /// + /// This is a memoized function. + /// let assortment : unit -> Assortment [] = Memoization.memoize get_ \ No newline at end of file diff --git a/src/Informedica.ZIndex.Lib/ConsumerProduct.fs b/src/Informedica.ZIndex.Lib/ConsumerProduct.fs index f8a0eaf..b9272c3 100644 --- a/src/Informedica.ZIndex.Lib/ConsumerProduct.fs +++ b/src/Informedica.ZIndex.Lib/ConsumerProduct.fs @@ -6,6 +6,7 @@ module ConsumerProduct = open Informedica.Utils.Lib + /// Creates a consumer product. let create id nm lb qt ct br = { Id = id @@ -39,4 +40,10 @@ module ConsumerProduct = ) + /// + /// Gets the consumer products for the given id. + /// + /// + /// This is a memoized function. + /// let get : int -> ConsumerProduct [] = Memoization.memoize _get diff --git a/src/Informedica.ZIndex.Lib/DoseRule.fs b/src/Informedica.ZIndex.Lib/DoseRule.fs index 8c29e38..a12a760 100644 --- a/src/Informedica.ZIndex.Lib/DoseRule.fs +++ b/src/Informedica.ZIndex.Lib/DoseRule.fs @@ -11,9 +11,6 @@ module DoseRule = open Informedica.Utils.Lib.BCL open Informedica.Utils.Lib - type MinMax = RuleMinMax - type Frequency = RuleFrequency - type Product = RuleProduct module Constants = @@ -46,18 +43,29 @@ module DoseRule = let female = "vrouw" + /// + /// Get the most extreme min and max values from an array of MinMax. + /// + /// The array of MinMax + /// The most extreme MinMax as a RuleMinMax let foldMinMax xs = - xs |> Array.fold (fun { Min = min; Max = max} (acc: MinMax) -> + xs |> Array.fold (fun { Min = min; Max = max} (acc: RuleMinMax) -> { Min = Option.min acc.Min min; Max = Option.max acc.Max max } ) { Min = None; Max = None } - let freqToString (freq : Frequency) = + /// Get the string representation of a RuleFrequency. + let freqToString (freq : RuleFrequency) = (string freq.Frequency) + " " + freq.Time - let toString del (r: DoseRule) = - let minMaxToString n u p (mm: MinMax) s = + /// + /// Get the string representation of a DoseRule. + /// + /// A delimiter + /// The DoseRule + let toString del (dr: DoseRule) = + let minMaxToString n u p (mm: RuleMinMax) s = let mms = match mm.Min, mm.Max with | Some min, Some max -> @@ -84,81 +92,87 @@ module DoseRule = s3 + s2 + del let gp = - r.GenericProduct |> Seq.fold(fun a gp -> + dr.GenericProduct |> Seq.fold(fun a gp -> let s' = if a |> String.IsNullOrWhiteSpace then "" else ", " s' + gp.Name) "" let pp = - r.PrescriptionProduct |> Seq.fold(fun a gp -> + dr.PrescriptionProduct |> Seq.fold(fun a gp -> let s' = if a |> String.IsNullOrWhiteSpace then "" else ", " s' + gp.Name) "" let tp = - r.TradeProduct |> Seq.fold(fun a gp -> + dr.TradeProduct |> Seq.fold(fun a gp -> let s' = if a |> String.IsNullOrWhiteSpace then "" else ", " s' + gp.Name) "" - let s = "" + (string r.Id) + del + let s = "" + (string dr.Id) + del let s = s |> adds "" gp let s = s |> adds "" pp let s = s |> adds "" tp - let s = s |> adds "Gebruik" r.Usage - let s = s |> adds "Groep" r.CareGroup - let s = s |> adds "Type" r.DoseType - let s = s |> adds "Route" (r.Routes |> String.concat "/") - let s = s |> adds "Indicatie" r.Indication + let s = s |> adds "Gebruik" dr.Usage + let s = s |> adds "Groep" dr.CareGroup + let s = s |> adds "Type" dr.DoseType + let s = s |> adds "Route" (dr.Routes |> String.concat "/") + let s = s |> adds "Indicatie" dr.Indication - let s = if r.HighRisk then s + "Hig Risk " else s + let s = if dr.HighRisk then s + "Hig Risk " else s - let s = s |> adds "" r.Gender + let s = s |> adds "" dr.Gender - let s = s |> minMaxToString "Leeftijd" "maanden" 1 r.Age - let s = s |> minMaxToString "Gewicht" "kg" 3 r.Weight - let s = s |> minMaxToString "BSA" "m2" 3 r.BSA + let s = s |> minMaxToString "Leeftijd" "maanden" 1 dr.Age + let s = s |> minMaxToString "Gewicht" "kg" 3 dr.Weight + let s = s |> minMaxToString "BSA" "m2" 3 dr.BSA let s = - if r.Freq.Frequency <= 0. then s + if dr.Freq.Frequency <= 0. then s else - s + "Freq: " + (r.Freq |> freqToString) + " " + del + s + "Freq: " + (dr.Freq |> freqToString) + " " + del - let s = s |> minMaxToString "Norm" r.Unit 3 r.Norm - let s = s |> minMaxToString "Norm/Kg" r.Unit 3 r.NormKg - let s = s |> minMaxToString "Abs" r.Unit 3 r.Abs - let s = s |> minMaxToString "Abs/Kg" r.Unit 3 r.AbsKg + let s = s |> minMaxToString "Norm" dr.Unit 3 dr.Norm + let s = s |> minMaxToString "Norm/Kg" dr.Unit 3 dr.NormKg + let s = s |> minMaxToString "Abs" dr.Unit 3 dr.Abs + let s = s |> minMaxToString "Abs/Kg" dr.Unit 3 dr.AbsKg - let s = s |> minMaxToString "Norm/m2" r.Unit 3 r.NormM2 - let s = s |> minMaxToString "Abs/m2" r.Unit 3 r.AbsM2 + let s = s |> minMaxToString "Norm/m2" dr.Unit 3 dr.NormM2 + let s = s |> minMaxToString "Abs/m2" dr.Unit 3 dr.AbsM2 let s = s |> String.subString 0 ((s |> String.length) - (del |> String.length)) s + + /// An empty RuleMinMax. let minmax = { Min = None; Max = None } - let createProduct id nm : Product = { Id = id; Name = nm } + /// Create a RuleProduct. + let createProduct id nm : RuleProduct = { Id = id; Name = nm } + /// Create a RuleGenericProduct. let createGenericProduct id nm rt un sl = { Id = id; Name = nm; Route = rt; Unit = un; Substances = sl } + /// Create a RuleFrequency. let createFrequency fr tm = { Frequency = fr; Time = tm } - let createMinMax mn mx = - - let chkmx = - mx + /// Create a RuleMinMax. + let createMinMax min max = + let check = + max |> string |> String.forall (fun c -> c = '9' || c = '.') - if mx < mn then minmax + if max < min then minmax else - let mn = if mn = 0. then None else Some mn - let mx = if mx = 0. || chkmx then None else Some mx + let mn = if min = 0. then None else Some min + let mx = if max = 0. || check then None else Some max { Min = mn; Max = mx } + /// Create a DoseRule. let create id gr us dt gp pr tr rt ci ic hr sx ag wt bs fr no ab nk ak nm am un = { Id = id @@ -187,6 +201,7 @@ module DoseRule = } + /// An empty DoseRule. let empty = { Id = 0 @@ -216,18 +231,6 @@ module DoseRule = let _getGenericProducts () = - (* ToDo check if this is a problem - GenPresProduct.get true - |> Array.collect (fun gpp -> - gpp.GenericProducts - |> Array.map (fun gp -> gp.Id) - ) - // make distinct necessary? - |> Array.distinct - |> Array.toList - |> GenericProduct.get - *) - GenPresProduct.getGenericProducts () |> Array.map (fun gp -> let unt = @@ -253,6 +256,12 @@ module DoseRule = ) + /// + /// Map all GenericProducts from all GenPresProducts to RuleGenericProducts. + /// + /// + /// This is a memoized function. + /// let getGenericProducts : unit -> RuleGenericProduct[] = Memoization.memoize _getGenericProducts @@ -265,13 +274,20 @@ module DoseRule = where (p.MUTKOD <> 1) select ( - createProduct p.PRKODE - (nm.NMNAAM.Trim()) + createProduct + p.PRKODE + (nm.NMNAAM.Trim()) ) } |> Seq.toArray - let getPresciptionProducts : unit -> Product[] = + /// + /// Map all PrescriptionProducts RuleProducts. + /// + /// + /// This is a memoized function. + /// + let getPresciptionProducts : unit -> RuleProduct[] = Memoization.memoize _getPrescriptionProducts @@ -283,16 +299,24 @@ module DoseRule = where (p.MUTKOD <> 1) select ( - createProduct p.HPKODE - (nm.NMNAAM.Trim()) + createProduct + p.HPKODE + (nm.NMNAAM.Trim()) ) } |> Seq.toArray - let getTradeProducts : unit -> Product[] = + /// + /// Map all TradeProducts to RuleProducts. + /// + /// + /// This is a memoized function. + /// + let getTradeProducts : unit -> RuleProduct[] = Memoization.memoize _getTradeProducts + /// Get all specifid DoseRule routes for a BST642T record. let getICPCRoute (icp : Zindex.BST642T.BST642T) = let r = Names.getThes icp.GPKTWG Names.Route Names.Fifty if r = "TOEDIENINGSWEG NIET INGEVULD" || @@ -303,8 +327,10 @@ module DoseRule = |> String.splitAt ',' |> Array.map String.trim ) + |> Array.distinct + /// Get the DoseType for a BST641T record. let getDoseType (bas : Zindex.BST641T.BST641T) = Zindex.BST902T.records () |> Array.tryFind (fun tx -> @@ -317,6 +343,7 @@ module DoseRule = else r.Value.THNM50.Trim()) + /// Get the dose text for a BST642T record. let getICPCText (icp : Zindex.BST642T.BST642T) = Zindex.BST380T.records () |> Array.tryFind (fun i -> @@ -328,6 +355,7 @@ module DoseRule = ) + /// Get the RuleFrequency for a BST643T record. let getFrequency (cat: Zindex.BST643T.BST643T) = Zindex.BST360T.records () |> Array.tryFind (fun tx -> @@ -476,22 +504,30 @@ module DoseRule = |> StopWatch.clockFunc "Getting DoseRules" + /// + /// Get all DoseRules for a list of GPKS. + /// + /// + /// This is a memoized function. + /// let get : List -> DoseRule [] = Memoization.memoize _get + /// Load all DoseRules in memory. let load = get >> ignore + /// Get the string representation of a DoseRule. let toString2 (dr : DoseRule) = let addString lbl s = if s = "" then "" else lbl + ": " + s + ", " - let freqToString (fr: Frequency) = + let freqToString (fr: RuleFrequency) = (fr.Frequency |> string) + " " + (fr.Time |> string) - let minMaxToString u (mm: MinMax) = + let minMaxToString u (mm: RuleMinMax) = let s = match mm.Min, mm.Max with | None, None -> "" @@ -520,13 +556,19 @@ module DoseRule = let indications_ () = - // Get all distinct indciations + // Get all distinct indications Zindex.BST642T.records () |> Array.map getICPCText |> Array.distinct |> Array.sort + /// + /// Get all DoseRule indications. + /// + /// + /// This is a memoized function. + /// let indications = Memoization.memoize indications_ @@ -537,6 +579,14 @@ module DoseRule = |> Array.sort + + + /// + /// Get all DoseRule routes. + /// + /// + /// This is a memoized function. + /// let routes = Memoization.memoize routes_ @@ -547,6 +597,13 @@ module DoseRule = |> Array.sortBy (fun f -> (f.Time, f.Frequency)) + + /// + /// Get all DoseRule frequencies. + /// + /// + /// This is a memoized function. + /// let frequencies = Memoization.memoize frequencies_ diff --git a/src/Informedica.ZIndex.Lib/GenPresProduct.fs b/src/Informedica.ZIndex.Lib/GenPresProduct.fs index ec97bc6..dbf002a 100644 --- a/src/Informedica.ZIndex.Lib/GenPresProduct.fs +++ b/src/Informedica.ZIndex.Lib/GenPresProduct.fs @@ -7,6 +7,7 @@ module GenPresProduct = open Informedica.Utils.Lib + /// Create a GenPresProduct. let create nm sh rt ph gps dpn unt sns = { Name = nm @@ -120,9 +121,16 @@ module GenPresProduct = let private memGet = Memoization.memoize _get + /// + /// Get all GenPresProducts for the given GenericProduct Ids. + /// + /// + /// This function is memoized + /// let get = memGet + /// Get a list of all GenericProduct Ids. let getGPKS all = get all |> Array.collect (fun gpp -> @@ -132,10 +140,17 @@ module GenPresProduct = |> Array.distinct + /// Get the string representation of a GenPresProduct. let toString (gpp : GenPresProduct) = gpp.Name + " " + gpp.Shape + " " + (gpp.Routes |> String.concat "/") + /// + /// Filter GenPresProducts by name, shape and route. + /// + /// The name + /// The shape + /// The route let filter n s r = get [] |> Array.filter (fun gpp -> @@ -145,6 +160,7 @@ module GenPresProduct = ) + /// Get a Map of GenericProduct Ids to GenPresProducts. let getGPKMap = fun () -> get [] @@ -158,20 +174,18 @@ module GenPresProduct = |> Memoization.memoize + /// Find GenPresProducts by GenericProduct Id. let findByGPK gpk = match (getGPKMap ()) |> Map.tryFind gpk with | Some gpps -> gpps | None -> [||] - // get [] - // |> Array.filter (fun gpp -> - // gpp.GenericProducts - // |> Array.exists (fun gp -> gp.Id = gpk) - // ) + /// Load all GenPresProducts in memory. let load = get >> ignore + /// Get all Routes for all GenPresProducts. let getRoutes = fun () -> get [] @@ -183,6 +197,7 @@ module GenPresProduct = |> Memoization.memoize + /// Get all Shapes for all GenPresProducts. let getShapes = fun () -> get [] @@ -194,6 +209,7 @@ module GenPresProduct = |> Memoization.memoize + /// Get all Units for all GenPresProducts. let getUnits = fun () -> get [] @@ -205,6 +221,12 @@ module GenPresProduct = |> Memoization.memoize + /// + /// Get all ShapeRoutes for all GenPresProducts. + /// + /// + /// An array of tuples of Shape and Routes. + /// let getShapeRoutes = fun () -> get [] @@ -212,9 +234,9 @@ module GenPresProduct = gpp.Shape, gpp.Routes ) |> Array.groupBy fst - |> Array.map (fun (k, vs) -> - k, - vs + |> Array.map (fun (shape, routes) -> + shape, + routes |> Array.collect snd |> Array.distinct ) @@ -222,6 +244,32 @@ module GenPresProduct = |> Array.sort + /// + /// Get all RouteShapes for an array of GenPresProducts. + /// + /// The GenPresProducts + /// + /// An array of tuples of Route and Shape. + /// + let routeShapes (gpps : GenPresProduct[]) = + // route shape + gpps + |> Array.collect (fun gpp -> + gpp.Routes + |> Array.map (fun route -> + route, + gpp.Shape + ) + ) + |> Array.distinct + + + /// + /// Get all ShapeUnits for all GenPresProducts. + /// + /// + /// An array of tuples of Shape and Units. + /// let getShapeUnits = fun () -> get [] @@ -233,6 +281,7 @@ module GenPresProduct = |> Memoization.memoize + /// Get all Substance Units for all GenPresProducts. let getSubstanceUnits = fun () -> get [] @@ -249,6 +298,7 @@ module GenPresProduct = + /// Get all Generic Units for all GenPresProducts. let getGenericUnits = fun () -> get [] @@ -264,6 +314,14 @@ module GenPresProduct = |> Memoization.memoize + /// + /// Get all Substance names, quantities and units + /// all GenPresProducts that contain the given GenericProduct Id. + /// + /// The GenericProduct id + /// + /// An array of tuples of Substance name, quantity and unit. + /// let getSubstQtyUnit gpk = get [] |> Array.collect (fun gpp -> @@ -272,18 +330,24 @@ module GenPresProduct = |> Array.collect (fun gp -> gp.Substances |> Array.map (fun s -> - s.SubstanceName, s.SubstanceQuantity, s.SubstanceUnit + s.SubstanceName, + s.SubstanceQuantity, + s.SubstanceUnit ) ) ) + /// Get all GenericProducts for all GenPresProducts. let getGenericProducts () = get [] |> Array.collect (fun gpp -> gpp.GenericProducts) - // Find a product + /// + /// Find all GenPresProducts that contain the given string. + /// + /// The string let search n = let contains = String.containsCapsInsens @@ -303,16 +367,3 @@ module GenPresProduct = ) ) ) - - - let routeShapes (gpps : GenPresProduct[]) = - // route shape - gpps - |> Array.collect (fun gpp -> - gpp.Routes - |> Array.map (fun r -> - r, - gpp.Shape - ) - ) - |> Array.distinct diff --git a/src/Informedica.ZIndex.Lib/GenericProduct.fs b/src/Informedica.ZIndex.Lib/GenericProduct.fs index 4f168f2..6b4c19a 100644 --- a/src/Informedica.ZIndex.Lib/GenericProduct.fs +++ b/src/Informedica.ZIndex.Lib/GenericProduct.fs @@ -7,6 +7,7 @@ module GenericProduct = open Informedica.Utils.Lib.BCL + /// Creates a ProductSubstance let createSubstance si so sn sq su gi gn gq gu un = { SubstanceId = si @@ -22,6 +23,7 @@ module GenericProduct = } + /// Create a GenericProduct let create id nm lb ac an sh rt ss ps = { Id = id @@ -36,6 +38,7 @@ module GenericProduct = } + /// Get the routes for a GenericProduct let getRoutes (gp : Zindex.BST711T.BST711T) = // try to get the 'enkelvoudige toedieningsweg' let rts = @@ -74,7 +77,8 @@ module GenericProduct = |> Array.distinct - let getSubstances log un (gp : Zindex.BST711T.BST711T) hpks = + /// Get the Substances for a GenericProduct + let getSubstances un (gp : Zindex.BST711T.BST711T) hpks = Zindex.BST715T.records () |> Array.filter (fun gs -> gs.GSKODE = gp.GSKODE && @@ -127,7 +131,7 @@ module GenericProduct = |> Array.sortBy (fun s -> s.SortOrder) - let private _get log gpks = + let private _get gpks = Zindex.BST711T.records () |> Array.filter (fun gp -> gp.MUTKOD <> 1 && @@ -159,18 +163,26 @@ module GenericProduct = pp.TradeProducts |> Array.map (fun tp -> tp.Id) ) - |> getSubstances log un gp + |> getSubstances un gp printfn $"creating: {nm}" create gp.GPKODE nm lb (gp.ATCODE.Trim()) an sh rt ss ps ) - let get : int list -> GenericProduct [] = Memoization.memoize (_get (fun _ -> ())) - - - let getWithLog = _get + /// + /// Get the GenericProducts for the given Ids + /// + /// + /// This function is memoized + /// + let get : int list -> GenericProduct [] = Memoization.memoize _get + /// + /// Get the BarCodes for the given GenericProduct + /// + /// The GenericProduct + /// The GPK, BarCodes array let getBarCodes (gp : GenericProduct) = gp.PrescriptionProducts |> Array.collect (fun pp -> diff --git a/src/Informedica.ZIndex.Lib/Names.fs b/src/Informedica.ZIndex.Lib/Names.fs index a714fee..f715190 100644 --- a/src/Informedica.ZIndex.Lib/Names.fs +++ b/src/Informedica.ZIndex.Lib/Names.fs @@ -8,6 +8,8 @@ module Names = open Types.Names + + /// Map item to TSNR, i.e. the item number in BST902T let mapItem = function | Shape -> 6 | Route -> 7 @@ -17,7 +19,11 @@ module Names = | ConsumerContainer -> 4 - /// Look in BST020T Namen bestand + /// + /// Get the name of a record in BST020T + /// + /// The id of the record + /// The name type let getName id nm = match Zindex.BST020T.records () @@ -34,7 +40,12 @@ module Names = | None -> "" - /// Look in BST902T Therauri totaal + /// + /// Get the name of a record in BST902T + /// + /// The id of the record + /// The item type + /// The name length let getThes id it ln = match Zindex.BST902T.records () @@ -47,6 +58,12 @@ module Names = | None -> "" + /// + /// Get all the name lengths for a record in BST020T + /// + /// The id of the record + /// The item type + /// The name length let getItems itm ln = Zindex.BST902T.records() |> Array.filter (fun r -> @@ -60,6 +77,7 @@ module Names = |> Array.sort + /// All the route names in the thesaurus. let getRoutes = fun () -> getItems Route TwentyFive @@ -74,6 +92,7 @@ module Names = |> Memoization.memoize + /// All the shape names in the thesaurus. let getShapes = fun () -> getItems Shape Fifty @@ -81,6 +100,7 @@ module Names = |> Memoization.memoize + /// All the generic unit names in the thesaurus. let getGenericUnits = fun () -> getItems GenericUnit Fifty @@ -88,6 +108,7 @@ module Names = |> Memoization.memoize + /// All the shape unit names in the thesaurus. let getShapeUnits = fun () -> getItems ShapeUnit TwentyFive @@ -95,6 +116,7 @@ module Names = |> Memoization.memoize + /// All the prescription container names in the thesaurus. let getPrescriptionContainers = fun () -> getItems PrescriptionContainer TwentyFive @@ -102,6 +124,7 @@ module Names = |> Memoization.memoize + /// All the consumer container names in the thesaurus. let getConsumerContainers = fun () -> getItems ConsumerContainer TwentyFive diff --git a/src/Informedica.ZIndex.Lib/PrescriptionProduct.fs b/src/Informedica.ZIndex.Lib/PrescriptionProduct.fs index 3e8956f..87604fe 100644 --- a/src/Informedica.ZIndex.Lib/PrescriptionProduct.fs +++ b/src/Informedica.ZIndex.Lib/PrescriptionProduct.fs @@ -6,6 +6,7 @@ module PrescriptionProduct = open Informedica.Utils.Lib + /// Create a PrescriptionProduct record let create id nm lb qt un ct ps = { Id = id @@ -38,4 +39,10 @@ module PrescriptionProduct = ) + /// + /// Get all PrescriptionProducts for a given Z-Index id + /// + /// + /// This function is memoized. + /// let get : int -> PrescriptionProduct [] = Memoization.memoize _get diff --git a/src/Informedica.ZIndex.Lib/Route.fs b/src/Informedica.ZIndex.Lib/Route.fs index 869e9ea..5392f7d 100644 --- a/src/Informedica.ZIndex.Lib/Route.fs +++ b/src/Informedica.ZIndex.Lib/Route.fs @@ -13,28 +13,28 @@ module Route = let mapping_ () = GoogleSheets.getDataFromSheet FilePath.genpres "Routes" |> fun data -> - data + data |> Array.tryHead - |> function + |> function | None -> Array.empty - | Some cs -> + | Some cs -> let getStr c r = Csv.getStringColumn cs r c - + data |> Array.skip 1 - |> Array.map (fun r -> + |> Array.map (fun r -> {| name = r |> getStr "Route" zindex = r |> getStr "ZIndex" product = r |> getStr "Products" rule = r |> getStr "DoseRules" short = r |> getStr "ShortDutch" - |} + |} ) |> Array.map (fun r -> { - Route = - r.name + Route = + r.name |> Reflection.fromString |> Option.defaultValue Route.NoRoute Name = r.name @@ -42,18 +42,25 @@ module Route = Product = r.product Rule = r.rule Short = r.short - } + } ) + /// + /// Get the route mapping. + /// + /// + /// This function is memoized. + /// let routeMapping = Memoization.memoize mapping_ - let tryFind mapping s = + /// Try find a route in the mapping. + let tryFind mapping s = let eqs = String.equalsCapInsens s - mapping - |> Array.tryFind (fun r -> + mapping + |> Array.tryFind (fun r -> r.Name |> eqs || r.ZIndex |> eqs || r.Short |> eqs @@ -61,6 +68,7 @@ module Route = + /// Get the string representation of a route. let toString mapping r = $"%A{r}" |> tryFind mapping @@ -69,6 +77,7 @@ module Route = | None -> "" + /// Get the route from a string. let fromString mapping s = s |> tryFind mapping @@ -77,7 +86,8 @@ module Route = | None -> NoRoute - let eqsRoute mapping r rs = + /// Check if a route is in a list of routes. + let routeExists mapping r rs = if r = NoRoute || r = NON_SPECIFIED then true else rs diff --git a/src/Informedica.ZIndex.Lib/RuleFinder.fs b/src/Informedica.ZIndex.Lib/RuleFinder.fs index 64f4267..42260ad 100644 --- a/src/Informedica.ZIndex.Lib/RuleFinder.fs +++ b/src/Informedica.ZIndex.Lib/RuleFinder.fs @@ -12,7 +12,7 @@ module RuleFinder = let createRoute = Route.fromString (Route.routeMapping ()) - let eqsRoute = Route.eqsRoute (Route.routeMapping ()) + let eqsRoute = Route.routeExists (Route.routeMapping ()) type AgeInMo = decimal Option diff --git a/src/Informedica.ZIndex.Lib/Substance.fs b/src/Informedica.ZIndex.Lib/Substance.fs index 98f0db6..78209ec 100644 --- a/src/Informedica.ZIndex.Lib/Substance.fs +++ b/src/Informedica.ZIndex.Lib/Substance.fs @@ -7,6 +7,9 @@ module Substance = open Informedica.Utils.Lib + /// + /// Create a Substance + /// let create id pk nm ms mr fm un ds = { Id = id @@ -20,9 +23,18 @@ module Substance = } - let cache (sbs : Substance []) = Json.cache (FilePath.substanceCache false) sbs + /// + /// Write a Substance array to a cache file + /// + /// + let cache (sbs : Substance []) = + let useDemo = FilePath.useDemo() + Json.cache (FilePath.substanceCache useDemo) sbs + /// + /// Parse the Zinc index file to create a Substance array + /// let parse () = Zindex.BST750T.records () |> Array.filter (fun r -> r.MUTKOD <> 1) @@ -56,8 +68,17 @@ module Substance = |> StopWatch.clockFunc "Getting Substances" + /// + /// Get the Substance array + /// + /// + /// This is a memoized function + /// let get : unit -> Substance [] = Memoization.memoize _get + /// + /// Load the Substance array + /// let load () = get () |> ignore diff --git a/src/Informedica.ZIndex.Lib/TradeProduct.fs b/src/Informedica.ZIndex.Lib/TradeProduct.fs index e72d2cd..5d264c1 100644 --- a/src/Informedica.ZIndex.Lib/TradeProduct.fs +++ b/src/Informedica.ZIndex.Lib/TradeProduct.fs @@ -7,6 +7,7 @@ module TradeProduct = open Informedica.Utils.Lib.BCL + /// Creates a new TradeProduct let create id nm lb br cm dn uw rt ps = { Id = id @@ -44,4 +45,10 @@ module TradeProduct = ) + /// + /// Gets the TradeProduct with the specified id + /// + /// + /// This function is memoized + /// let get : int -> TradeProduct [] = Memoization.memoize _get \ No newline at end of file