pat2vec.pat2vec_get_methods.get_method_diagnostics

Functions

calculate_diagnostic_features(...[, batch_mode])

Calculates diagnostic features for each order type.

create_diagnostic_features_dataframe(...)

Creates the final diagnostic features DataFrame.

get_current_pat_diagnostics(...[, ...])

Retrieves diagnostic test features for a patient within a date range.

prepare_diagnostic_datetime(...[, batch_mode])

Prepares the datetime column for diagnostic data processing.

search_diagnostic_orders([...])

Searches for diagnostic order data for patients within a date range.

pat2vec.pat2vec_get_methods.get_method_diagnostics.search_diagnostic_orders(cohort_searcher_with_terms_and_search=None, client_id_codes=None, diagnostic_time_field='order_createdwhen', start_year='1995', start_month='01', start_day='01', end_year='2025', end_month='12', end_day='12', additional_custom_search_string=None)[source]

Searches for diagnostic order data for patients within a date range.

Uses a cohort searcher to find diagnostic orders.

Parameters:
  • cohort_searcher_with_terms_and_search (Optional[Callable]) – The function for cohort searching. Defaults to None.

  • client_id_codes (Optional[Union[str, List[str]]]) – The client ID code(s) of the patient(s). Defaults to None.

  • diagnostic_time_field (str) – The timestamp field for filtering diagnostic orders. Defaults to ‘order_createdwhen’.

  • start_year (str) – Start year for the search. Defaults to ‘1995’.

  • start_month (str) – Start month for the search. Defaults to ‘01’.

  • start_day (str) – Start day for the search. Defaults to ‘01’.

  • end_year (str) – End year for the search. Defaults to ‘2025’.

  • end_month (str) – End month for the search. Defaults to ‘12’.

  • end_day (str) – End day for the search. Defaults to ‘12’.

  • additional_custom_search_string (Optional[str]) – An additional string to append to the search query. Defaults to None.

Returns:

A DataFrame containing the raw diagnostic order data.

Return type:

pd.DataFrame

Raises:

ValueError – If essential arguments are None.

pat2vec.pat2vec_get_methods.get_method_diagnostics.prepare_diagnostic_datetime(diagnostics_data, diagnostic_time_field, batch_mode=False)[source]

Prepares the datetime column for diagnostic data processing.

Creates a ‘datetime’ column by either copying the specified time field (in batch mode) or converting it to datetime objects.

Parameters:
  • diagnostics_data (pd.DataFrame) – Raw diagnostic data.

  • diagnostic_time_field (str) – The name of the time field to process.

  • batch_mode (bool) – Whether the function is running in batch mode. Defaults to False.

Returns:

The input DataFrame with an added ‘datetime’ column.

Return type:

pd.DataFrame

pat2vec.pat2vec_get_methods.get_method_diagnostics.calculate_diagnostic_features(order_name_df_dict, order_name_list, batch_mode=False)[source]

Calculates diagnostic features for each order type.

Computes features like the number of orders, days since the last order, and the time span between the first and last order for each diagnostic test type.

Parameters:
  • order_name_df_dict (Dict[str, pd.DataFrame]) – A dictionary mapping order names to their corresponding DataFrames.

  • order_name_list (List[str]) – A list of unique order names to process.

  • batch_mode (bool) – Whether the function is running in batch mode. Defaults to False.

Returns:

A dictionary of calculated features.

Return type:

Dict

pat2vec.pat2vec_get_methods.get_method_diagnostics.create_diagnostic_features_dataframe(current_pat_client_id_code, diagnostic_features, original_data)[source]

Creates the final diagnostic features DataFrame.

Combines the patient’s ID with the calculated diagnostic features into a single-row DataFrame.

Parameters:
  • current_pat_client_id_code (str) – The patient’s client ID.

  • diagnostic_features (Dict) – The dictionary of calculated features.

  • original_data (pd.DataFrame) – The original diagnostic data, used for reference.

Returns:

A single-row DataFrame containing the final features.

Return type:

pd.DataFrame

pat2vec.pat2vec_get_methods.get_method_diagnostics.get_current_pat_diagnostics(current_pat_client_id_code, target_date_range, pat_batch, config_obj=None, cohort_searcher_with_terms_and_search=None)[source]

Retrieves diagnostic test features for a patient within a date range.

This function fetches diagnostic order data, either from a pre-loaded batch or by searching. It then calculates time-based features for each type of diagnostic order found.

Parameters:
  • current_pat_client_id_code (str) – The client ID code of the patient.

  • target_date_range (Tuple) – A tuple representing the target date range.

  • pat_batch (pd.DataFrame) – The DataFrame containing patient data for batch mode.

  • config_obj (Optional[object]) – Configuration object containing settings like batch_mode and diagnostic_time_field. Defaults to None.

  • cohort_searcher_with_terms_and_search (Optional[Callable]) – The function for cohort searching. Defaults to None.

Returns:

A DataFrame containing diagnostic test features for the

specified patient.

Return type:

pd.DataFrame