RecordFormatter.fs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. module RedCat.RecordFormatter
  2. open RedCat.DrugsDataExtractor
  3. let formatDrugInput (drugRawName: string) =
  4. drugRawName.ToLower().Replace(" ", "").Replace("-", "").Replace(",", "")
  5. let formatDrugInfoResponse (drugData: DrugRecord) =
  6. let toPrettyString (drugInfo: string option) =
  7. match drugInfo with
  8. | Some s when drugInfo = drugData.Summary -> $"📜 {s}" |> Some
  9. | Some s when drugInfo = drugData.Dose -> $"🍽️ {s}" |> Some
  10. | Some s when drugInfo = drugData.TotalDuration -> $"⏳ Durata: {s}" |> Some
  11. | Some s when drugInfo = drugData.OnSet -> $"🤯 Inizio effetti: {s}" |> Some
  12. | _ -> None
  13. let formattedCategories =
  14. drugData.Categories
  15. |> Option.bind(fun catgs -> catgs |> String.concat " | " |> Some)
  16. let mainResponseText =
  17. [drugData.Summary; drugData.Dose; drugData.TotalDuration; drugData.OnSet]
  18. |> List.choose toPrettyString
  19. |> String.concat "\n\n"
  20. match formattedCategories with
  21. | None -> $"~{drugData.Name} \n\n{mainResponseText}"
  22. | Some categories -> $"~{drugData.Name} [ {categories} ]\n\n{mainResponseText}"
  23. let formatComboRecord (comboData: ComboRecord) =
  24. let translate (s: string) =
  25. match s with
  26. | "Dangerous" -> "❌ Molto pericoloso alla vita e alla salute"
  27. | "Unsafe" -> "‼️ Pericoloso"
  28. | "Caution" -> "⚠️ Attenzione"
  29. | "Low Risk & Synergy" -> "➕➕ Rischio basso e amplificazione effetto ➕➕"
  30. | "Low Risk & Decrease" -> "➖➖ Rischio basso e diminuzione effetto ➖➖"
  31. | "Low Risk & No Synergy" -> "🟰🟰 Rischio basso e interazione assente 🟰🟰"
  32. | _ -> failwith "Shouldn't happen here"
  33. let toPrettyString (comboInfo: string option) =
  34. match comboInfo with
  35. | Some s when comboInfo = comboData.Status -> $"{translate s}" |> Some
  36. | Some s when comboInfo = comboData.Note -> $"{s}" |> Some
  37. | _ -> None
  38. let comboText =
  39. [comboData.Status; comboData.Note]
  40. |> List.choose toPrettyString
  41. |> String.concat "\n"
  42. $"[{comboData.DrugA}] ~ [{comboData.DrugB}]\n\n{comboText}"