pat2vec.util.pre_get_drug_treatment_docs

Functions

get_treatment_records_by_drug_order_name(...)

Retrieves drug order records from Elasticsearch that match a search term.

iterative_drug_treatment_search(pat2vec_obj, ...)

Iteratively searches for drug records and saves them to a CSV file.

pat2vec.util.pre_get_drug_treatment_docs.get_treatment_records_by_drug_order_name(pat2vec_obj, term, verbose=0, all_fields=False, column_fields_to_match=['order_summaryline', 'order_name', 'order_holdreasontext'])[source]

Retrieves drug order records from Elasticsearch that match a search term.

This function performs a fuzzy search for a given term within the ‘order’ index, specifically for records where order_typecode is “medication”. The fuzzy matching is applied to the columns specified in column_fields_to_match.

Parameters:
  • pat2vec_obj (Any) – The main pat2vec object, containing configuration settings.

  • term (str) – A single drug name or keyword to search for.

  • verbose (int) – Verbosity level for logging/debugging.

  • all_fields (bool) – If True, retrieves all available fields from the database. If False, retrieves only essential fields.

  • column_fields_to_match (List[str]) – List of columns to check for fuzzy matching.

Return type:

DataFrame

Returns:

A DataFrame containing treatment records that match the search term. An additional column, matched_{term}, is added to indicate which fields matched the term. Returns an empty DataFrame if no records are found.

Raises:

ValueError – If pat2vec_obj is None or term is not a string.

Iteratively searches for drug records and saves them to a CSV file.

This function loops through a list of search_terms, retrieves matching drug order records for each, and appends the results to a single CSV file. It can handle deduplication based on ‘order_guid’.

Parameters:
  • pat2vec_obj (Any) – The main pat2vec object containing configuration settings.

  • search_terms (List[str]) – A list of drug names or keywords to search for.

  • output_file_path (str) – Path to the CSV file where results will be stored. Appends to the file if it exists.

  • verbose (int) – Verbosity level for logging/debugging.

  • all_fields (bool) – Whether to retrieve all available fields.

  • column_fields_to_match (List[str]) – List of columns to check for fuzzy matching.

  • drop_duplicates (bool) – If True, drops duplicate records based on ‘order_guid’, while merging search term info.

  • overwrite (bool) – If True, overwrite the output file if it exists.

Return type:

DataFrame

Returns:

A merged DataFrame of the search results.