Skip to content

Commit

Permalink
docs: adding comments for zindex
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Nov 5, 2023
1 parent f740dc8 commit 99546cf
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/Informedica.ZIndex.Lib/BST000T.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module BST000T =
}


/// <summary>
/// Create a BST000T record
/// </summary>
let create mc nm ds rl st ua dl al nw tt =
{
MUTKOD = mc
Expand All @@ -68,6 +71,9 @@ module BST000T =
let pickList = [1] @ [2; 3] @ [5] @ [9..14]


/// <summary>
/// Get all the records from the BST000T file
/// </summary>
let records _ =
Parser.getData name posl pickList
|> Array.map (Array.map String.trim)
Expand All @@ -81,11 +87,20 @@ module BST000T =
create d[0] d[1] d[2] rl d[4] ua dl al nw tt)


/// <summary>
/// Get a specific record from the BST000T file
/// </summary>
/// <param name="n">The name of the table</param>
let table n =
records ()
|> Array.find (fun r -> r.MDBST = n)


/// <summary>
/// Creat a code comment for a table.
/// </summary>
/// <param name="n">The name of the table</param>
/// <param name="pl">The picklist of columns to include in the comment</param>
let commentString n pl =
printfn $"processing: {n} {pl}"
let tab = " "
Expand Down
34 changes: 34 additions & 0 deletions src/Informedica.ZIndex.Lib/BST001T.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ module BST001T =
[<Literal>]
let name = "BST001T"


/// <summary>
/// Position of the fields in the record
/// </summary>
let posl = [ 0004; 0001; 0020; 0003; 0010; 0050; 0008; 0002; 0001; 0004; 0002; 0006; 0017 ]


Expand Down Expand Up @@ -47,6 +51,9 @@ module BST001T =
}


/// <summary>
/// Create a BST001T record
/// </summary>
let create mk tb vn nm bs ke tp ln dc fm =
{
MUTKOD = mk
Expand All @@ -62,6 +69,9 @@ module BST001T =
}


/// <summary>
/// Picklist of fields to use
/// </summary>
let pickList = [1..5] @ [7..11]


Expand Down Expand Up @@ -91,28 +101,46 @@ module BST001T =
let _records = records ()


/// <summary>
/// Get the position of the fields in the record
/// </summary>
/// <param name="name">The name of the file</param>
let getPosl name =
_records
|> Array.toList
|> List.filter (fun d -> d.MDBST = name)
|> List.map (fun d -> d.MDRLEN)


/// <summary>
/// Get the length of the record
/// </summary>
/// <param name="n">The name of the file</param>
let recordLength n =
_records
|> Seq.filter (fun r -> r.MDBST = n)
|> Seq.sumBy (fun r -> r.MDRLEN)


/// <summary>
/// Get the all colums for a file
/// </summary>
let columns n =
_records
|> Seq.filter (fun r -> r.MDBST = n)
|> Seq.filter (fun r -> r.MDRNAM <> "******")


/// Get the column count for a file
let columnCount n = columns n |> Seq.length


/// <summary>
/// Get the column names for a file as a single
/// F# record string.
/// </summary>
/// <param name="n">The name of the file</param>
/// <param name="pl">The picklist of fields to use</param>
let recordString n pl =
let tab = " "
let s = $"type %s{n} =\n"
Expand All @@ -130,6 +158,12 @@ module BST001T =
s + $"%s{tab}%s{tab}%s{tab}}}\n"


/// <summary>
/// Get the column names for a file as a single
/// F# create function string.
/// </summary>
/// <param name="n">The name of the file</param>
/// <param name="pl">The picklist of fields to use</param>
let createString n pl =
let tab = " "
let cs =
Expand Down
10 changes: 10 additions & 0 deletions src/Informedica.ZIndex.Lib/CodeGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ module Zindex =
"""


/// <summary>
/// Generates the code for a single table.
/// </summary>
/// <param name="n">The name of the table.</param>
/// <param name="pl">The picklist of the table.</param>
let generate n pl =
let cm = BST000T.commentString n pl
let rc = BST001T.recordString n pl
Expand Down Expand Up @@ -112,6 +118,10 @@ module Zindex =
]


/// <summary>
/// Generates the Z-Index file.
/// </summary>
/// <param name="tl">The table list.</param>
let generateZIndex tl =
let code =
tl
Expand Down
11 changes: 11 additions & 0 deletions src/Informedica.ZIndex.Lib/FilePath.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,39 @@ module FilePath =
[<Literal>]
let GStandPath = data + "zindex/"


/// Get the path to the Substance cache file
let substanceCache useDemo =
if not useDemo then data + "cache/substance.cache"
else data + "cache/substance.demo"


/// Get the path to the Product cache file
let productCache useDemo =
if not useDemo then data + "cache/product.cache"
else data + "cache/product.demo"


/// Get the path to the Rule cache file
let ruleCache useDemo =
if not useDemo then data + "cache/rule.cache"
else data + "cache/rule.demo"


/// Get the path to the Group cache file
let groupCache useDemo =
if not useDemo then data + "cache/group.cache"
else data + "cache/group.demo"


//https://docs.google.com/spreadsheets/d/1AEVYnqjAbVniu3VuczeoYvMu3RRBu930INhr3QzSDYQ/edit?usp=sharing
let [<Literal>] genpres = "1AEVYnqjAbVniu3VuczeoYvMu3RRBu930INhr3QzSDYQ"


let [<Literal>] GENPRES_PROD = "GENPRES_PROD"

/// Check whether the demo version of
/// the cache files should be used.
let useDemo () =
Env.getItem GENPRES_PROD
|> Option.map ((<>) "1")
Expand Down
27 changes: 26 additions & 1 deletion src/Informedica.ZIndex.Lib/Json.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,50 @@ module Json =

open Informedica.Utils.Lib

///
/// <summary>
/// Serializes an object to a JSON string
/// </summary>
/// <param name="x">The object to serialize</param>
let serialize x =
JsonConvert.SerializeObject(x)


/// <summary>
/// Deserializes a JSON string to an object
/// </summary>
/// <param name="s">The JSON string to deserialize</param>
let deSerialize<'T> (s: string) =
JsonConvert.DeserializeObject<'T>(s)


/// <summary>
/// Serialize an object to a JSON string
/// and write it to a file
/// </summary>
/// <param name="p">The path to the file</param>
/// <param name="o">The object to serialize</param>
let cache p o =
o
|> serialize
|> File.writeTextToFile p


/// <summary>
/// Clear the cache files for either a product
/// or a demo version of the cache.
/// </summary>
/// <param name="useDemo">Whether to clear the demo cache files</param>
let clearCache useDemo =
File.Delete(FilePath.groupCache useDemo)
File.Delete(FilePath.substanceCache useDemo)
File.Delete(FilePath.productCache useDemo)
File.Delete(FilePath.ruleCache useDemo)


/// <summary>
/// Read a cache file and deserialize it to an object
/// </summary>
/// <param name="p">The path to the file</param>
let getCache<'T> p =
ConsoleWriter.writeInfoMessage $"Reading cache: %s{p}" true false

Expand Down
24 changes: 24 additions & 0 deletions src/Informedica.ZIndex.Lib/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@ module Parser =
open Informedica.Utils.Lib.BCL
open Informedica.Utils.Lib


/// <summary>
/// Split a string into an array of strings, based on the given positions.
/// </summary>
/// <param name="pl">The given positions.</param>
/// <param name="s">The string</param>
let splitRecord pl (s: string) =
pl
|> List.mapi (fun i p ->
let start = pl |> List.take i |> List.sum
s.Substring(start, p))
|> List.toArray


/// <summary>
/// Get the data from a file.
/// </summary>
/// <param name="name">The name of the file.</param>
/// <param name="posl">The positions of the fields.</param>
/// <param name="pick">The fields to pick.</param>
let getData name posl pick =
let data =
FilePath.GStandPath + "/" + name
Expand All @@ -25,6 +38,10 @@ module Parser =
data
|> Array.map (Array.pickArray pick)


/// <summary>
/// Check wether a string is a decimal format.
/// </summary>
let isDecimalFormat s =
let s = s |> String.replace "(" "" |> String.replace ")" ""
if s |> String.contains "," then
Expand All @@ -33,6 +50,13 @@ module Parser =
| _ -> false
else false


/// <summary>
/// Parse a string to a decimal a return as a string
/// </summary>
/// <param name="st">String that is 'N'if numerical</param>
/// <param name="sf">The format of the numerical string</param>
/// <param name="s">The string to format</param>
let parseValue st sf (s: string) =
if st = "N" then
let vf = sf |> String.replace "(" "" |> String.replace ")" ""
Expand Down
5 changes: 4 additions & 1 deletion src/Informedica.ZIndex.Lib/Scripts/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,7 @@ printfn "Loading Substance"
Substance.load ()


GenPresProduct.search "amikacine"
GenPresProduct.search "adrenaline"
|> Array.head
|> fun gpp -> gpp.GenericProducts |> Array.head

Loading

0 comments on commit 99546cf

Please sign in to comment.