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)

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 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 = None, 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", "string_list", "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, required: Optional[bool] = True, comparison_column: Optional[str] = None) -> ReportParameter

Create a report parameter consisting of predefined codes.

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

The Roter 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 systems=["rxnorm"] could type "aspirin" to see the drug codes for various types of aspirin. The user of code parameter with systems=["icd9_cm", "icd10_cm"] could type into the UI field "heart" to see diagnostic codes for various heart diseases.

The query template must include a specific set of tags that allow correctly expanding a list of user-inputted codes. These are the tags: {{param_name}} (this is the name parameters) is the parent tag for the entire section replicated for each code-list entry. {{_VALUE}} is the child tag where individual list entries will be placed. {{_FIRST}} (optional) which will be automatically Truthy exactly only for the first of the user-selected codes. {{_LAST}} (optional) which will be automatically Truthy exactly only for the last of the user-selected codes.

For example, a query_template for an SQL query may look like this ... {{#codes}} {{#_FIRST}} WHERE {{/_FIRST}} {{^_FIRST}} OR {{/_FIRST}} codeColumn = {{_VALUE}} {{/codes}} ... where the _first tag is used to change the keyword for the first code.

For another example, a query_template for elasticsearch may look like this ... {{#codes}} { "match": { "ICDcodesColumn": { "query": "{{_VALUE}}", "operator": "OR" } } } {{^_LAST}} , {{/_LAST}} {{/codes}} ... where the _last tag is used to generate valid json without trailing comma.

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_cm", "icd10_cm", "icd9_pcs", "icd10_pcs", "cpt", "snomed"
description : str
Optional. Detailed description when displayed in the UI.
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}}
comparison_column : str, optional
This parameter has been deprecated. Please refer to the documentation to understand the new system.

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
The comparison_column parameter has been deprecated as the code parameter behavior changed. This value should now be a part of your template. Please refer to the documentation for details.

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 create_string_list(name: str, display: str, description: Optional[str] = None, default_value: Union[str, List[str], ForwardRef(None)] = None, required: Optional[bool] = True) -> ReportParameter

Creates a report parameter for a free-form list of strings field.

The parameter only accepts alphanumeric "phrases" separated by commas. As a freeform, be vigilant about how it's being used in the report template.

The query template must include a specific set of tags that allow correctly expanding a list of user-enteres values. These are the tags: {{param_name}} (this is the name parameters) is the parent tag for the entire section replicated for each list entry. {{_VALUE}} is the child tag where individual list entries will be placed. {{_FIRST}} (optional) which will be automatically Truthy exactly only for the first of the user-entered values. {{_LAST}} (optional) which will be automatically Truthy exactly only for the last of the user-entered values.

End-user values will be provided as a nested context to mustache/chevron. For example, end-user typing ["medicine 1", "medicine 2"] for {{med}} will be expanded into the following context: "med": [ {"_VALUE": "medicine 1", "_FIRST": True, "_LAST": False} {"_VALUE": "medicine 2", "_FIRST": False, "_LAST": True} ]

An appropriate template to handle this could be: ... WHERE {{#med}} medcol = '{{_VALUE}}' {{^_LAST}} OR {{/_LAST}} {{/med}} ... which when populated with the above values would become ... WHERE medcol = 'medicine 1' OR medcol = 'medicine 2' ...

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.
default_value
The value this field should default to when showing a form to the user and/or if required and left blank.
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 {{_VALUE}}…{{/name}} and/or {{^name}}…no value provided…{{/name}}

Raises

Exception
If specified, the default_value must not be blank.

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