OrderContext Module
Declares the commands on an order context, creates an order context for patient data and evaluates a command on the context: looks up rules, makes the scenarios and changes the medication order of a scenario.
Types and nested modules
| Type/Module | Description |
|
Returns the order context that a command carries and the command as text. |
|
|
Holds the serializable shape of an order context and converts a context to and from the Dto. Reading returns the errors of the filter, the patient data and every scenario. |
|
|
Splits prescription rules by the Divisible of their products, makes and calculates the orders of the rules and turns the calculated orders into scenarios. |
|
|
|
Functions and values
| Function or value |
Description
|
Full Usage:
adjustOfPatient patientData ord
Parameters:
PatientData
ord : Order
Returns: ValueUnit option
|
The value of the patient the order is adjusted with, in the unit of the order. None when the patient does not have that value, or the order holds no adjust value.
|
|
|
Full Usage:
applyChange category field clearOwn write ctx
Parameters:
OrderCategory
field : FilterField
clearOwn : bool
write : Filter -> Filter
ctx : OrderContext
Returns: OrderContext
|
Applies a change to one filter choice and removes the scenarios and the picked products. Emptying a choice also clears its options and the choices in the later steps; when no choice is left, the options of all lookup fields are cleared. A change to a field the rule lookup reads can give another dose rule, so it also clears the components, the dose rule components and the component selection.
|
Full Usage:
applyToOrderScenario scenarioF ctx
Parameters:
OrderScenario -> OrderScenario
ctx : OrderContext
Returns: OrderContext
|
|
Full Usage:
applyingToDepartment provider patientData drs
Parameters:
IResourceProvider
patientData : CorePatientData
drs : DoseRule array
Returns: DoseRule array
|
The dose rules applying to the department of the patient: every rule with limits, and a dose rule without limits only when a solution rule for the department limits every component of it.
|
|
The order in which the filter choices are made, as steps. Emptying a choice clears the choices in the later steps, not the other choices in its own step. For a medication the indication and the generic share one step and narrow each other; for a nutrition order the generic comes first and the indication follows from it.
|
Full Usage:
change category field chosen dt ctx
Parameters:
OrderCategory
field : FilterField
chosen : string option
dt : DoseType option
ctx : OrderContext
Returns: OrderContext
|
Sets or empties the choice of a filter field. Returns the context unchanged when the field already has that choice.
|
Full Usage:
changeDiluent n ctx
Parameters:
int option
ctx : OrderContext
Returns: Result<OrderContext, string>
|
The diluent set to its nth option, or emptied with None.
|
Full Usage:
changeFilter category field n ctx
Parameters:
OrderCategory
field : FilterField
n : int option
ctx : OrderContext
Returns: Result<OrderContext, string>
|
Sets a filter field to its nth option, counted from 0, or empties it with None. A diluent or a component change does not clear other choices, because the rule lookup does not read them. A component pick selects one component; setNthComponents selects several.
|
Full Usage:
changeOrder logger change ctx
Parameters:
Logger
change : ChangePropertyCommand
ctx : OrderContext
Returns: OrderContext
|
Changes the order of the single scenario with the property command, without solving it.
|
|
Whether the change sets or recalculates a dose per kg or per m2. A new change of a dose per kg or per m2 must be added here; the last case answers false for every change not listed.
|
|
Whether the rule lookup would read a choice that the filter does not have: a list with one option and no choice.
|
|
Empties the filter, the scenarios and the argumentation; the patient data stays.
|
|
Clears the choice of one filter field and leaves its options.
|
|
Clears the choice and the options of one filter field. The options are cleared too because the rule lookup reads a single option as a choice, so the field would come back chosen. The next evaluation fills the options again.
|
|
|
Full Usage:
contextTotals routeMapping formRoutes totalsData norms ctx
Parameters:
RouteMapping array
formRoutes : FormRoute[]
totalsData : TotalsData array
norms : TotalNorm array
ctx : OrderContext
Returns: Totals
|
The totals over the orders of the context's scenarios, for its patient's age, weight and gestational age. Each total is checked against the norm in norms with the name of its Totals row, or else against the standard norm of the row.
|
Full Usage:
contextTotalsFor routeMapping formRoutes totalsData norms patientData ctx
Parameters:
RouteMapping array
formRoutes : FormRoute[]
totalsData : TotalsData array
norms : TotalNorm array
patientData : PatientData
ctx : OrderContext
Returns: Totals
|
The totals over the orders of the context's scenarios, for the age, weight and gestational age of the patient. Each total is checked against the norm in norms with the name of its Totals row, or else against the standard norm of the row.
|
|
Returns the scenario of a context with exactly one scenario, the order it adds to the plan. Returns None for several scenarios or none.
|
Full Usage:
create logger provider patientData
Parameters:
Logger
provider : IResourceProvider
patientData : PatientData
Returns: OrderContext
|
Creates a context for the patient data with the pick lists of the rules that can be prescribed for the patient. The pick lists are empty for a child without a weight.
|
Full Usage:
doseFilterFor patientData ctx
Parameters:
PatientData
ctx : OrderContext
Returns: DoseFilter
|
Returns the dose filter for the picks, the diluent and the selected components of the context, with the given patient data.
|
Full Usage:
doseRulesOf provider ctx
Parameters:
IResourceProvider
ctx : OrderContext
Returns: DoseRule array
|
Returns the dose rules for the context as it is, before a command changes it: the stand-alone dose rules, plus the dose rules that need a main order when the context selects them. The context selects them with a picked indication and generic, where a single-option list counts as picked, and a dose type list of exactly one. Only a linked offer, whose dose types are narrowed to the link side, has such a list, because a pick or a seed does not change the lists of an evaluated context. Prescribing still refuses an order that needs a main order and has none. Returns an empty array when a resource is missing from the provider.
|
|
The filter with no options and no choices.
|
|
|
|
Evaluates a command and returns the outcome. A command that looks up the rules is refused when no rule fits the picks or every medication lacks its diluent. A command on the scenario order is refused when the order cannot be solved, or when it changes a dose per kg or per m2 that the order does not have. Returns an error when the rule lookup fails or an index is past the options.
|
|
The filter fields the rule lookup reads. The diluent and the components belong to the scenario, not to the lookup.
|
|
Returns the five filter picks as the rule lookup reads them: the choice of a filter field, or else the only option of that field. The patient data of the dose filter is not set.
|
Full Usage:
filterScenariosByPreparation scs
Parameters:
OrderScenario[]
Returns: OrderScenario array
|
The scenarios per dose type: only the preparable ones when there are any, otherwise all.
|
Full Usage:
getRules logger provider ctx
Parameters:
Logger
provider : IResourceProvider
ctx : OrderContext
Returns: OrderContext * Result<PrescriptionRule array, Message list>
|
Returns the context with its pick lists narrowed to the options of the prescribable rules, and the rules themselves. A list with one option sets its choice. The rules are only returned when the indication, the generic, the dose type and the route or the form are picked. For a child without a weight the context is made afresh and there are no rules.
|
Full Usage:
getScenarios start logger provider sent
Parameters:
DateTime
logger : Logger
provider : IResourceProvider
sent : OrderContext
Returns: Result<Outcome<OrderContext>, Message list>
|
Looks up the rules for the context and makes its scenarios. Picks that match no rule are refused with the context as it was sent. When every medication lacks a needed diluent, the context with the narrowed picks is refused with NoDiluent. Returns the error when the rule lookup fails.
|
|
Whether the one scenario of the context holds an order without a dose per kg or per m2.
|
|
|
|
Returns the patient data of the context without its diagnoses, as the rule lookup takes it.
|
Full Usage:
matchesLinkSide routeMapping side ctx
Parameters:
RouteMapping array
side : LinkSide
ctx : OrderContext
Returns: bool
|
Whether the order context matches a side of a link rule, by the order it is narrowed to: the generic label, the indication, the route and the dose type of its scenario. A context that is not narrowed to one order matches no side.
|
Full Usage:
measurementMissing patientData prs
Parameters:
PatientData
prs : PrescriptionRule array
Returns: bool
|
Whether the patient lacks a measurement for every prescription rule: at least one rule, and none of them can be prescribed for the patient. No rules at all is not a missing measurement.
|
Full Usage:
narrowToLinkSide side ctx
Parameters:
LinkSide
ctx : OrderContext
Returns: OrderContext
|
The context's dose types narrowed to the dose types the side matches.
|
Full Usage:
narrowToRuleSet set ctx
Parameters:
RuleSet
ctx : OrderContext
Returns: OrderContext
|
Narrows the indication and generic lists of the context filter to the names the rule set allows. The other lists and the picks do not change.
|
Full Usage:
noDoseRulesMessage
Returns: string
|
The error message that ofOutcome returns for a refusal without a context.
|
Full Usage:
nth what n xs
Parameters:
string
n : int
xs : 'a[]
Returns: Result<'a, string>
Type parameters: 'a |
Returns the nth item of the options, or an error when the index is out of range.
|
Full Usage:
ofLinkSide side patientData
Parameters:
LinkSide
patientData : PatientData
Returns: OrderContext
|
The order context a side of a link rule offers for the patient, before it is evaluated: the indication, the generic and the route set when the side gives them; a blank field is left open.
|
|
|
Full Usage:
orderOfRule start logger orderId rules
Parameters:
DateTime
logger : Logger
orderId : string
rules : PrescriptionRule[]
Returns: Order option
|
Builds the order of a single rule with the given order id. Returns None when there is not exactly one rule, when the rule gives more than one medication, or when the medication gives no order.
|
Full Usage:
orderOnPatientData logger provider patientData sc ctx
Parameters:
Logger
provider : IResourceProvider
patientData : CorePatientData
sc : OrderScenario
ctx : OrderContext
Returns: Outcome<OrderContext>
|
Updates the single order of the context for new patient data. The scenario gets the notice when the rules for the new patient data differ from the rules for the patient data of the context; a failed lookup leaves the notice unchanged. When the rules are the same, the limits that depend on the patient come from the current rule; without a single current rule the limits stay and a warning is logged. The order is calculated again when its adjust value or its limits changed; the dose the patient gets stays. The context keeps the patient data its rules were chosen for, so the rules can always be compared. An order that cannot be solved is refused unchanged and marked as not recalculated. The mark is removed when the new patient data has an adjust value and either the current rule is known or the adjust value changed.
|
Full Usage:
processScenarioOrder logger f ctx
Parameters:
Logger
f : Order -> Result<Order, 'a>
ctx : OrderContext
Returns: Outcome<OrderContext>
Type parameters: 'a |
Processes the order of the single scenario with f. Refuses the context as it was sent with NotSolved when f fails. Logs a context without exactly one scenario and returns it unchanged.
|
Full Usage:
reconcile logger provider ctx
Parameters:
Logger
provider : IResourceProvider
ctx : OrderContext
Returns: OrderContext
|
Matches the filter choices of the context against the pick lists that the rules give for its patient data; a choice that is not in its list is removed. The scenarios are not changed.
|
Full Usage:
refusal provider ctx
Parameters:
IResourceProvider
ctx : OrderContext
Returns: Refusal
|
Returns the refusal for the context from the dose rules of the provider, see refusalOf. For a child without a weight no rule fits the patient. A dose rule without limits counts for the picks only when a solution rule of the department limits it. It counts for the patient only when a solution rule for the patient limits it, or when it has no products, which gives NoProducts.
|
Full Usage:
refusalOf forPicks forPatient measurementMissing
Parameters:
'a[]
forPatient : 'a[]
measurementMissing : bool
Returns: Refusal
Type parameters: 'a |
Returns the refusal for an empty result: NoDoseRules when no dose rule fits the picks in the department of the patient, NoDoseRulesForPatient when none fits the patient, MeasurementMissing when the patient lacks a measurement for every prescription rule, and otherwise NoProducts, when the rule lookup dropped the rules for having no product or no dose type.
|
|
|
Full Usage:
reloadResources start logger provider ctx
Parameters:
DateTime
logger : Logger
provider : IResourceProvider
ctx : OrderContext
Returns: Result<Outcome<OrderContext>, Message list>
|
|
Full Usage:
resolveChange cmd
Parameters:
Command
Returns: Result<(OrderContext * (OrderContext -> Command)), string> option
|
Applies a filter change, a component or scenario selection, or a seed to its context. Returns the changed context with the command it is evaluated as, or an error when an index is past the options. Returns None for any other command.
|
|
Sets the component quantities of the context as sent on the evaluated context after a component selection or a diluent choice. Any other command returns the context unchanged.
|
Full Usage:
ruleOfScenario provider sc ctx rules
Parameters:
IResourceProvider
sc : OrderScenario
ctx : OrderContext
rules : PrescriptionRule array
Returns: PrescriptionRule array
|
Returns the rules the scenario was made from: split by Divisible to the groups of the picked products, or with the Divisible removed when the order fits only without it.
|
Full Usage:
rulesByDivisible provider rules
Parameters:
IResourceProvider
rules : PrescriptionRule array
Returns: PrescriptionRule[] array
|
Splits each rule into one rule per group of products with the same Divisible, as the scenarios are made.
|
Full Usage:
rulesFor logger provider patientData ctx
Parameters:
Logger
provider : IResourceProvider
patientData : CorePatientData
ctx : OrderContext
Returns: Result<PrescriptionRule array, Message list>
|
The prescribable rules for the picks of the context and the patient. A child without a weight has none.
|
Full Usage:
rulesForMainOrder routeMapping rules ctx
Parameters:
RouteMapping array
rules : LinkRule[]
ctx : OrderContext
Returns: LinkRule array
|
The link rules for which the order context is the main order, when the context is narrowed to one order; none otherwise. Their linked sides are the orders that can be linked to it.
|
Full Usage:
rulesVerdict logger ord atContext current
Parameters:
Logger
ord : Order
atContext : Result<PrescriptionRule array, Message list>
current : Result<PrescriptionRule array, Message list>
Returns: bool option
|
Whether the rules no longer apply to the order: compares the rules for the patient data of the context with the rules for the current patient data. Logs the error and returns None when a lookup failed.
|
Full Usage:
seedFilter source ind gen rte frm dt ctx
Parameters:
SeedSource
ind : string option
gen : string option
rte : string option
frm : string option
dt : DoseType option
ctx : OrderContext
Returns: OrderContext
|
Sets the filter choices from a seed source. A Formulary or Parenteralia seed removes the scenarios and keeps the diluent only when the generic, the route and the form are unchanged, for Formulary also the indication. A Url seed keeps the diluent and the scenarios. A Reload changes nothing. The picked products and the components stay only when all five choices are unchanged.
|
Full Usage:
selectNthScenario n ctx
Parameters:
int
ctx : OrderContext
Returns: Result<OrderContext, string>
|
Narrows the context to its nth scenario and sets the form of that scenario as the filter form.
|
|
Whether the rules are looked up for the patient data: always for an adult, for a child only with a weight. A height is not needed; a rule that needs a height is left out because it cannot be prescribed.
|
Full Usage:
setComponentQuantities logger previous ctx
Parameters:
Logger
previous : OrderContext
ctx : OrderContext
Returns: OrderContext
|
Sets the component quantities of the previous context again on a context rebuilt after a component selection or a diluent choice: each component by name, and the quantity of the previous diluent on the new diluent. Nothing is set when a component of the previous order has no single quantity, or when solving fails.
|
Full Usage:
setFilter filter ctx
Parameters:
Filter
ctx : OrderContext
Returns: OrderContext
|
|
|
|
Full Usage:
setFilterGeneric gen ctx
Parameters:
string
ctx : OrderContext
Returns: OrderContext
|
|
Full Usage:
setFilterIndication ind ctx
Parameters:
string
ctx : OrderContext
Returns: OrderContext
|
|
Full Usage:
setFilterRoute rte ctx
Parameters:
string
ctx : OrderContext
Returns: OrderContext
|
|
Full Usage:
setNthComponents ns ctx
Parameters:
int[]
ctx : OrderContext
Returns: Result<OrderContext, string>
|
Selects the components at these positions of the options. Returns an error when an index is out of range.
|
Full Usage:
settle contextOf narrow evaluate answer
Parameters:
'a -> OrderContext
narrow : 'a -> 'a
evaluate : 'a -> Result<'a, 'e>
answer : 'a
Returns: Result<'a, 'e>
Type parameters: 'a, 'e |
Narrows the answer and evaluates it again while a pick list with one entry has no pick, at most five times, once for each list that can be left open. Stops when an evaluation does not change the narrowed filter. Returns the error of a failed evaluation.
|
Full Usage:
toString stage ctx
Parameters:
'a
ctx : OrderContext
Returns: string
Type parameters: 'a |
|
Full Usage:
totalsFor routeMapping formRoutes totalsData norms patientData orders
Parameters:
RouteMapping array
formRoutes : FormRoute[]
totalsData : TotalsData array
norms : TotalNorm array
patientData : PatientData
orders : Order array
Returns: Totals
|
The totals over the orders whose route and form are marked Totals, for the age, weight and gestational age of the patient. Each total is checked against the norm in norms with the name of its Totals row, or else against the standard norm of the row.
|
|
|
Full Usage:
withDoseRulesOf ctx provider
Parameters:
OrderContext
provider : IResourceProvider
Returns: IResourceProvider
|
Wraps the provider so its dose rules are the dose rules of the context from doseRulesOf. Every dose rule lookup of an evaluation with the wrapped provider reads them: the pick lists, the scenarios and the refusal.
|
|
Sets each filter choice to its pick from filterPicks. A choice that is made stays, a list with one option sets that option as the choice, and a list of more options stays without a choice.
|
Full Usage:
withListsOfOtherPicks logger provider ctx
Parameters:
Logger
provider : IResourceProvider
ctx : OrderContext
Returns: OrderContext
|
Sets each pick list of a refused context to the options the rules for the patient give with all the other picks, so a pick that does not fit can be changed. The picks are not changed. For a child without a weight the lists are not changed.
|
Full Usage:
withScenarios ctx meds scenarios
Parameters:
OrderContext
meds : unit -> Medication[]
scenarios : OrderScenario[]
Returns: Outcome<OrderContext>
|
Sets the scenarios on the context. Refuses with NoDiluent when there are no scenarios and every medication lacks a needed diluent. The medications are only made when there are no scenarios.
|
GenPRES