Skip to content

Commit

Permalink
feat: allow dosetype filter when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Casper Bollen authored and Casper Bollen committed Mar 2, 2024
1 parent 7255214 commit c95469c
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 54 deletions.
52 changes: 51 additions & 1 deletion src/Client/Components/Autocomplete.fs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module Autocomplete =
<Autocomplete
sx={ {| minWidth = 300 |} }
id={props.label}
// disabled={props.isLoading |> not}
value={props.selected |> Option.defaultValue ""}
onChange={handleChange}
options={props.values}
Expand Down Expand Up @@ -100,6 +101,7 @@ module Autocomplete =
<Autocomplete
sx={ {| minWidth = 300 |} }
id={props.label}
// disabled={props.isLoading |> not}
value={props.selected |> Option.defaultValue ""}
onChange={handleChange}
options={props.values}
Expand All @@ -110,7 +112,6 @@ module Autocomplete =




[<JSX.Component>]
let Routes (props :
{|
Expand Down Expand Up @@ -148,6 +149,55 @@ module Autocomplete =
<Autocomplete
sx={ {| minWidth = 300 |} }
id={props.label}
// disabled={props.isLoading |> not}
value={props.selected |> Option.defaultValue ""}
onChange={handleChange}
options={props.values}
renderInput={renderInput}
>
</Autocomplete>
"""



[<JSX.Component>]
let DoseTypes (props :
{|
label : string
selected : string option
values : string []
updateSelected : string option -> unit
isLoading : bool
|}
) =

let handleChange =
fun ev ->
ev?target?innerText
|> string
|> function
| s when s |> String.IsNullOrWhiteSpace ||
s = "undefined" -> None
| s -> s |> Some
|> fun x -> Logging.log "value is none: " x.IsNone; x
|> props.updateSelected

let renderInput pars =
JSX.jsx """
<TextField {...pars} label="Doseer types" />
"""

JSX.jsx
$"""
import InputLabel from '@mui/material/InputLabel';
import TextField from '@mui/material/TextField';
import Autocomplete from '@mui/material/Autocomplete';
import FormControl from '@mui/material/FormControl';
<Autocomplete
sx={ {| minWidth = 300 |} }
id={props.label}
// disabled={props.isLoading |> not}
value={props.selected |> Option.defaultValue ""}
onChange={handleChange}
options={props.values}
Expand Down
83 changes: 74 additions & 9 deletions src/Client/Views/Prescribe.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Prescribe =
Indication: string option
Medication: string option
Route: string option
DoseType : string option
}


Expand All @@ -35,6 +36,8 @@ module Prescribe =
| IndicationChange of string option
| MedicationChange of string option
| RouteChange of string option
| DoseTypeChange of string option
| Clear


let empty =
Expand All @@ -43,6 +46,7 @@ module Prescribe =
Indication = None
Medication = None
Route = None
DoseType = None
}


Expand All @@ -55,6 +59,7 @@ module Prescribe =
Indication = sc.Indication
Medication = sc.Medication
Route = sc.Route
DoseType = sc.DoseType
}
| _ -> empty
state, Cmd.none
Expand All @@ -75,13 +80,11 @@ module Prescribe =

match msg with
| RowClick (i, xs) ->
Logging.log "rowclick:" i
{ state with Dialog = xs }, Cmd.none

| CloseDialog -> { state with Dialog = [] }, Cmd.none

| IndicationChange s ->
printfn $"indication change {s}, is none: {s.IsNone}"
match scenarios with
| Resolved sc ->
if s |> Option.isNone then
Expand All @@ -103,13 +106,9 @@ module Prescribe =
| Resolved sc ->
if s |> Option.isNone then
{ sc with
Indications =
ScenarioResult.empty.Indications
Indication = None
Medications =
ScenarioResult.empty.Medications
Medication = None
Shape = None
Scenarios = [||]
}

Expand All @@ -123,14 +122,52 @@ module Prescribe =
| RouteChange s ->
match scenarios with
| Resolved sc ->
if s |> Option.isNone then ScenarioResult.empty
if s |> Option.isNone then
{ sc with
Routes =
ScenarioResult.empty.Routes
Route = None
Scenarios = [||]
}
else
{ sc with Route = s }
|> updateScenario
| _ -> ()

{ state with Route = s }, Cmd.none

| DoseTypeChange s ->
match scenarios with
| Resolved sc ->
if s |> Option.isNone then
{ sc with
DoseTypes =
ScenarioResult.empty.DoseTypes
DoseType = None
Scenarios = [||]
}
else
{ sc with DoseType = s }
|> updateScenario
| _ -> ()

{ state with DoseType = s }, Cmd.none

| Clear ->
match scenarios with
| Resolved _ ->
ScenarioResult.empty |> updateScenario
| _ -> ()

{ state with
Indication = None
Medication = None
Route = None
DoseType = None

}, Cmd.none



open Elmish
open Shared
Expand Down Expand Up @@ -198,14 +235,25 @@ module Prescribe =
values = xs
isLoading = isLoading
|})
| _ ->
| _ when lbl = "rts" ->
Components.Autocomplete.Routes({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ when lbl = "dts" ->
Components.Autocomplete.DoseTypes({|
updateSelected = dispatch
label = lbl
selected = selected
values = xs
isLoading = isLoading
|})
| _ ->
$"cannot create autocomplete from {lbl}"
|> failwith

let progress =
match props.scenarios with
Expand Down Expand Up @@ -397,9 +445,26 @@ module Prescribe =
|> autoComplete isLoading "rts" sel (RouteChange >> dispatch)
}
{
match props.scenarios with
| Resolved scrs when scrs.Indication.IsSome &&
scrs.Medication.IsSome &&
scrs.Route.IsSome &&
scrs.DoseTypes |> Array.length > 1 ->
(false, scrs.DoseType, scrs.DoseTypes)
|> fun (isLoading, sel, items) ->
if isMobile then
items
|> Array.map (fun s -> s, s)
|> select isLoading "Doseer types" sel (DoseTypeChange >> dispatch)
else
items
|> autoComplete isLoading "dts" sel (DoseTypeChange >> dispatch)
| _ -> JSX.jsx $"<></>"
}
<Box sx={ {| mt=2 |} }>
<Button variant="text" onClick={fun _ -> None |> RouteChange |> dispatch } fullWidth startIcon={Mui.Icons.Delete} >
<Button variant="text" onClick={fun _ -> Clear |> dispatch } fullWidth startIcon={Mui.Icons.Delete} >
{Terms.Delete |> getTerm "Verwijder"}
</Button>
</Box>
Expand Down
14 changes: 12 additions & 2 deletions src/Informedica.GenForm.Lib/DoseRule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,12 @@ module DoseRule =
fun (dr : DoseRule) -> dr.PatientCategory |> PatientCategory.filter filter
fun (dr : DoseRule) ->
match filter.DoseType, dr.DoseType with
| AnyDoseType, _
| None, _
| _, AnyDoseType -> true
| _ -> filter.DoseType |> DoseType.eqs dr.DoseType
| _ ->
dr.DoseType
|> DoseType.toString
|> eqs filter.DoseType
|]
|> Array.fold (fun (acc : DoseRule[]) pred ->
acc |> Array.filter pred
Expand Down Expand Up @@ -871,6 +874,13 @@ module DoseRule =
let routes = getMember _.Route


let doseTypes =
getMember (fun dr ->
dr.DoseType
|> DoseType.toString
)


/// Extract all the departments from the DoseRules.
let departments = getMember (fun dr -> dr.PatientCategory.Department |> Option.defaultValue "")

Expand Down
1 change: 1 addition & 0 deletions src/Informedica.GenForm.Lib/DoseType.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ module DoseType =
| Discontinuous _ -> "onderhoud"
| Continuous _ -> "continu"
| AnyDoseType -> ""

| AnyDoseType -> ""

2 changes: 1 addition & 1 deletion src/Informedica.GenForm.Lib/Filter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Filter =
Generic = None
Shape = None
Route = None
DoseType = AnyDoseType
DoseType = None
Patient = Patient.patient
}

Expand Down
4 changes: 2 additions & 2 deletions src/Informedica.GenForm.Lib/PrescriptionRule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ module PrescriptionRule =
Generic = dr.Generic |> Some
Shape = dr.Shape |> Some
Route = dr.Route |> Some
DoseType = dr.DoseType
DoseType = dr.DoseType |> DoseType.toString |> Some
}
}
)
|> Array.filter (fun pr ->
// pr.DoseRule.Products |> Array.isEmpty |> not &&
pr.DoseRule.DoseType <> DoseType.AnyDoseType
)
// recalculate adjusted dose limits
Expand Down Expand Up @@ -248,6 +247,7 @@ module PrescriptionRule =
/// Get all routes of an array of PrescriptionRules.
let routes = getDoseRules >> DoseRule.routes

let doseTypes = getDoseRules >> DoseRule.doseTypes

/// Get all departments of an array of PrescriptionRules.
let departments = getDoseRules >> DoseRule.departments
Expand Down
27 changes: 1 addition & 26 deletions src/Informedica.GenForm.Lib/Product.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ module Product =
{|
GPK = get "GPK"
Route = get "Route"
Location =
match get "CVL", get "PVL" with
| s1, _ when s1 |> String.isNullOrWhiteSpace |> not -> CVL
| _, s2 when s2 |> String.isNullOrWhiteSpace |> not -> PVL
| _ -> AnyAccess
DoseType = DoseType.fromString (get "DoseType") ""
Dep = get "Dep"
DiluentVol = get "DiluentVol" |> toBrOpt
ExpansionVol = get "ExpansionVol" |> toBrOpt
Expand Down Expand Up @@ -118,22 +112,7 @@ module Product =

[|
fun (r : Reconstitution) -> r.Route |> Mapping.eqsRoute filter.Route
fun (r : Reconstitution) ->
if filter.Patient.VenousAccess = [AnyAccess] ||
filter.Patient.VenousAccess |> List.isEmpty then true
else
match filter.DoseType with
| AnyDoseType -> true
| _ -> filter.DoseType |> DoseType.eqs r.DoseType
fun (r : Reconstitution) -> r.Department |> eqs filter.Patient.Department
fun (r : Reconstitution) ->
match r.Location, filter.Patient.VenousAccess with
| AnyAccess, _
| _, []
| _, [ AnyAccess ] -> true
| _ ->
filter.Patient.VenousAccess
|> List.exists ((=) r.Location)
|]
|> Array.fold (fun (acc : Reconstitution[]) pred ->
acc |> Array.filter pred
Expand Down Expand Up @@ -378,9 +357,7 @@ module Product =
|> Array.map (fun r ->
{
Route = r.Route
DoseType = r.DoseType
Department = r.Dep
Location = r.Location
DiluentVolume =
r.DiluentVol.Value
|> ValueUnit.singleWithUnit Units.Volume.milliLiter
Expand Down Expand Up @@ -557,9 +534,7 @@ module Product =
prod.Reconstitution
|> Array.filter (fun r ->
(rte |> String.isNullOrWhiteSpace || r.Route |> Mapping.eqsRoute (Some rte)) &&
(r.DoseType = AnyDoseType || r.DoseType = dtp) &&
(dep |> Option.map (fun dep -> r.Department |> String.isNullOrWhiteSpace || r.Department |> String.equalsCapInsens dep) |> Option.defaultValue true) &&
(loc |> List.isEmpty || loc |> List.exists ((=) r.Location) || r.Location = AnyAccess)
(dep |> Option.map (fun dep -> r.Department |> String.isNullOrWhiteSpace || r.Department |> String.equalsCapInsens dep) |> Option.defaultValue true)
)
|> Array.map (fun r ->
{ prod with
Expand Down
11 changes: 7 additions & 4 deletions src/Informedica.GenForm.Lib/SolutionRule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@ module SolutionRule =
fun (sr : SolutionRule) -> filter.Route |> Option.isNone || sr.Route |> Mapping.eqsRoute filter.Route
fun (sr : SolutionRule) -> sr.Department |> Option.map (eqs filter.Patient.Department) |> Option.defaultValue true
fun (sr : SolutionRule) ->
match filter.DoseType, sr.DoseType with
| AnyDoseType, _
| _, AnyDoseType -> true
| _ -> filter.DoseType |> DoseType.eqs sr.DoseType
match filter.DoseType, sr.DoseType with
| None, _
| _, AnyDoseType -> true
| _ ->
sr.DoseType
|> DoseType.toString
|> eqs filter.DoseType
fun (sr : SolutionRule) -> filter.Patient.Weight |> Utils.MinMax.inRange sr.Weight
fun (sr : SolutionRule) ->
match sr.Location with
Expand Down
Loading

0 comments on commit c95469c

Please sign in to comment.