Module preprocessor.report_parameters

Classes

class ParameterConstraint (options: Optional[List[ParameterOption]] = None, min_value: Union[int, float, ForwardRef(None)] = None, max_value: Union[int, float, ForwardRef(None)] = None, datetime_format: Optional[str] = None, code_systems: List[str] = None, column: str = None)

Represents the constraints for a specific report query parameter.

Class variables

var code_systems : List[str]

For what code systems are to be used by the parameter field.

var column : str

The name of the column that will be used during code expansion.

var datetime_format : Optional[str]

For date type parameters, defines the format of the date.

var max_value : Union[int, float, ForwardRef(None)]

For int or float type parameters, defines maximum allowable value for the query parameter.

var min_value : Union[int, float, ForwardRef(None)]

For int or float type parameters, defines minimum allowable value for the query parameter.

var options : Optional[List[ParameterOption]]

Optional list of allowable query parameter values.

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) -> ~A
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) -> ~A
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) -> dataclasses_json.mm.SchemaF[~A]

Methods

def to_dict(self, encode_json=False) -> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) -> str
class ParameterOption (value: Union[str, float, int], display: str = '', desc: str = '')

Represents a specific allowable option for a parameter.

Class variables

var desc : str

Description of this parameter option.

var display : str

Display for this value, what consumers of this report will see.

var value : Union[str, float, int]

Allowed parameter value inserted into the query template.

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) -> ~A
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) -> ~A
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) -> dataclasses_json.mm.SchemaF[~A]

Methods

def to_dict(self, encode_json=False) -> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) -> str
class ReportParameter (constraint: ParameterConstraint, name: str = '', display: str = '', description: str = '', required: bool = True, param_type: str = 'string', default_value: Union[int, float, str, ForwardRef(None)] = None)

Represents a configurable parameter defined in the query template.

Use the provided static create methods for creating report parameters: * create_string * create_float * create_int * create_datetime * create_code

A ReportParameter's name can later be used in a report query template as a replaceable value. For example, in the template: select item, cost from {{table}} A parameter named "table" could be replace by as String parameter which has possible values of "usa_prices", "canadian_prices" to allow unique reports to be generated from each country.

Optional parameters can also be defined using required=False. In this case, the template can use the mustache conditional format to handle these undefined values, e.g.: SELECT desc, cost FROM orders {{#cat}}WHERE category={{cat}}{{/cat}} or SELECT desc, cost FROM orders WHERE category={{#cat}}{{cat}}{{/cat}}{{^cat}}default{{/cat}}

Class variables

var constraintParameterConstraint

ParameterConstraint representing the constraints for this report parameter.

var default_value : Union[int, float, str, ForwardRef(None)]

(Optional) Value to use if not required or specified by the user.

var description : str

Description of this report parameter. Can be much longer than the name.

var display : str

Name for this report parameter for display to consumers.

var name : str

Name of this report parameter, which is also the token to use in the query template.

var param_type : str

The type of the parameter, one of: "string", "float", "integer", "datetime", or "code".

var required : bool

Is this parameter required? If not and the user doesn't specify the value will be blank.

Static methods

def create_code(name: str, display: str, systems: Union[str, List[str]], description: Optional[str] = None, comparison_column: Optional[str] = None, required: Optional[bool] = True) -> ReportParameter

Create a report parameter consisting of predefined codes.

A "code" parameter is a special text parameter that is tied to a table on the Router which holds predefined code values and their descriptions. The user is able to select one or more codes from the table easily to fill in this parameter.

The code table segregates them by "system". For example, one set of codes might represent procedures based on the ICD-10 system while another set of codes might be medications based on the RxNorm system. The user of code parameter with system="RxNorm" could type "aspirin" to see the drug codes for various types of aspirin. The user of code parameter with system="ICD-10" could type "heart" to see diagnostic codes for various heart diseases.

When the report is run, the given {{name}} in templates is replaced by the code(s) selected by the user.

If a comparison_column is provided, the query_template should contain ... WHERE {{code_param}} ... or similar. This will be expanded into ... WHERE comparison_col = codeA OR comparison_col = codeB OR ....

If no comparison_column is provided, only a single code is allowed. The query_template should be ... WHERE code_col = {{code_param}} ... or similar. This will be expanded into ... WHERE code_col = codeA ....

For example, if the user selects "code1" and "code2" from the "ICD-10" system, and the comparison_column is "procedure_code", the template expansion would be: procedure_code = "code1" OR procedure_code = "code2" If no comparison_column is provided, only a single code is allowed and the value expands to the code itself.

Args

name : str
Name of the field in the template. Must match the field to be replaced in the query template.
display : str
One-line prompt shown for this field in the UI.
system : str or List[str]
The name of the code system(s) represented by this parameter. This can be a single string or a list of strings. When multiple systems are provided, the user will be able to select from any of the systems when running the report. Currently supported: "icd9:base", "icd10:base", "icd9:gc", "icd10:gc"
description : str
Optional. Detailed description when displayed in the UI.
comparison_column : str, optional
The name of the column which will be spelled out when expanded in the query template. This expands to: comparison_column = "code1" OR comparison_column = "code2" … If not specified, only a single code is allowed and the value expands to the code itself.
required : bool
Is the user required to specify this parameter? If not it can be left blank. A template can handle blank values specially using something like this in the template: {{#name}}…use {{name}}…{{/name}} and/or {{^name}}…no value provided…{{/name}}

Raises

ValueError
Systems must contain a string or list of strings
ValueError
System names must be strings.
ValueError
System name can only contain alphanumerics, dashes, periods, underscores or colons.
ValueError
Value of comparison_column must be alphanumeric or underscore characters only.

Returns

ReportParameter
New ReportParameter representing the supplied code field.
def create_datetime(name: str, display: str, datetime_format: str, description: Optional[str] = None, min_value: Optional[str] = None, max_value: Optional[str] = None, default_value: Optional[str] = None, options: Union[List[ParameterOption], List[str], ForwardRef(None)] = None, required: Optional[bool] = True) -> ReportParameter

Create a report parameter for a datetime field.

This defines what values should be allowed for this field when the report is run.

Args

name : str
Name of the field in the template. Must match the field to be replaced in the query template.
display : str
One-line prompt shown for this field in the UI.
datetime_format : str
Format of the datetime provided in strftime format. Example: %Y-%m-%d See formatting codes at https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
description : str
Optional. Detailed description when displayed in the UI.
min_value : str, optional
Represents the minimum allowed value for the query parameter. A value of "now" will be replaced with the current date and time when the report is run. Required if options is not supplied.
max_value : str, optional
Represents the maximum allowed value for the query parameter. A value of "now" will be replaced with the current date and time when the report is run. Required if options is not supplied.
default_value : Optional[str]
The value this field should default to when showing a form to the user. A value of "now" will be replaced with the current date and time when the report is run.
options : list, optional
List of possible parameter values for this field when running the report. If supplied, min and max should not be defined.
required : bool
Is the user required to specify this parameter? If not it can be left blank. A template can handle blank values specially using something like this in the template: {{#name}}…use {{name}}…{{/name}} and/or {{^name}}…no value provided…{{/name}}

Raises

ValueError
min_value must be less than max_value.
ValueError
Must supply min_value and max_value for a datetime parameter without options.
ValueError
Must supply datetime_format for a datetime parameter.
ValueError
If options are populated, must supply at least one option.
ValueError
Invalid option type, must be a str or ParameterOption.
ValueError
The default_value cannot be less than min_value.
ValueError
The default_value cannot be more than max_value.

Returns

ReportParameter
New ReportParameter representing the supplied date field.
def create_float(name: str, display: str, description: Optional[str] = None, min_value: Optional[float] = None, max_value: Optional[float] = None, default_value: Optional[float] = None, options: Union[List[ParameterOption], List[float], ForwardRef(None)] = None, required: Optional[bool] = True) -> ReportParameter

Create a report parameter for a float field.

This defines what values should be allowed for this field when the report is run.

Args

name : str
Name of the field in the template. Must match the field to be replaced in the query template.
display : str
One-line prompt shown for this field in the UI.
description : str
Optional. Detailed description when displayed in the UI.
min_value : float, optional
Represents the minimum allowed value for the query parameter. Required if not populating options.
max_value : float, optional
Represents the maximum allowed value for the query parameter. Required if not populating options.
options : list, optional
List of possible parameter values for this field when running the report. If supplied, you cannot also specify a min or max value.
default_value : Optional[float]
The value this field should default to when showing a form to the user.
required : bool
Is the user required to specify this parameter? If not it can be left blank. A template can handle blank values specially using something like this in the template: {{#name}}…use {{name}}…{{/name}} and/or {{^name}}…no value provided…{{/name}}

Raises

Exception
When specifying 'options', do not specify a minimum or maximum value.
Exception
Must supply at least one option.
Exception
Invalid option type, must be a float or ParameterOption
Exception
If default_value is specified, it must be one of the values in options
Exception
Minimum value must be less than maximum.
Exception
The default_value cannot be less than min_value.
Exception
The default_value cannot be more than max_value.

Returns

ReportParameter
New ReportParameter representing the supplied float field.
def create_int(name: str, display: str, description: Optional[str] = None, min_value: Optional[int] = None, max_value: Optional[int] = None, default_value: Optional[int] = None, options: Union[List[ParameterOption], List[int], ForwardRef(None)] = None, required: Optional[bool] = True) -> ReportParameter

Creates a report parameter for an integer field.

This defines what values should be allowed for this field when the report is run.

Args

name : str
Name of the field in the template. Must match the field to be replaced in the query template.
display : str
One-line prompt shown for this field in the UI.
description : str
Optional. Detailed description when displayed in the UI.
min_value : int, optional
Represents the minimum allowed value for the query parameter. Required if not populating options.
max_value : int, optional
Represents the maximum allowed value for the query parameter. Required if not populating options.
options : list, optional
List of possible parameter values for this field when running the report. If supplied, you cannot also specify a min or max value.
default_value : Optional[int]
The value this field should default to when showing a form to the user.
required : bool
Is the user required to specify this parameter? If not it can be left blank. A template can handle blank values specially using something like this in the template: {{#name}}…use {{name}}…{{/name}} and/or {{^name}}…no value provided…{{/name}}

Raises

Exception
When specifying 'options', do not specify a minimum or maximum value.
Exception
Must supply at least one option.
Exception
Invalid option type, must be an int or ParameterOption
Exception
If default_value is specified, it must be one of the values in options.
Exception
Minimum value must be less than maximum.
Exception
The default_value cannot be less than min_value.
Exception
The default_value cannot be more than max_value.

Returns

ReportParameter
New ReportParameter representing the supplied integer field.
def create_string(name: str, display: str, options: List[ParameterOption], description: Optional[str] = None, default_value: Optional[str] = None, required: Optional[bool] = True) -> ReportParameter

Creates a report parameter for a string field.

This defines what values should be allowed for this field when the report is run.

Args

name : str
Name of the field in the template. Must match the field to be replaced in the query template.
display : str
One-line prompt shown for this field in the UI.
description : str
Optional. Detailed description when displayed in the UI.
options
List of possible parameter values for this field when running the report.
default_value
The value this field should default to when showing a form to the user.
required : bool
Is the user required to specify this parameter? If not it can be left blank. A template can handle blank values specially using something like this in the template: {{#name}}…use {{name}}…{{/name}} and/or {{^name}}…no value provided…{{/name}}

Raises

Exception
Must supply option for a string parameter.
Exception
Invalid option type, must be a str or ParameterOption.
Exception
If specified, the default_value must not be blank.
Exception
If default_value is specified, it must be one of the values in options.

Returns

ReportParameter
New ReportParameter representing the supplied string field.
def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) -> ~A
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) -> ~A
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) -> dataclasses_json.mm.SchemaF[~A]

Methods

def to_dict(self, encode_json=False) -> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) -> str