GUI_client module¶
- GUI_client.create_output(patient_id: str, patient_name: str, image: str, hr: str) Union[dict, bool] ¶
Takes the inputs and converts it to a POST request format
This function takes the patient_id, patient_name, image, and heart rate (hr) and inserts them into a dictionary to be sent in a POST request to the server. All inputs are required, but because the inputs are tkinter StringVars, any ‘missing’ inputs will be read in as empty strings. If the parameter indicated to be the index is an empty string, this function returns False. Any other parameter that is an empty string will just not be added to the POST request. If the parameter ‘image’ is not empty, that is inserted into a list before it is added to the dictionary.
- Parameters
patient_id (str) – The MRN of the patient
patient_name (str) – The name of the patient
image (str) – The patient’s ECG image, encoded as a base 64 string
hr (str) – The calculated average heart rate of the patient, calculated from the ECG image
- Returns
A POST request compatible dictionary with keys matching the parameter names
- Return type
dict
- GUI_client.data_to_fig(data: pandas.core.frame.DataFrame, img_file: GUI_client.PathLike = 'temp.png')¶
function that saves a matplotlib figure from a two column DataFrame
This function takes a Pandas Dataframe with the columns ‘time’ and ‘voltage’ as well as the name of the image file to write the plot to. It takes this data and saves the figure to the indicated image file. It favors usage of the matplotlib figure object over pyplot due to issues with backend and tkinter when using pyplot.
source: https://stackoverflow.com/questions/37604289
- Parameters
data (DataFrame) – DataFrame with columns “time” and “voltage”
img_file (Pathlike) – Path string for intended file to write the figure image to
- GUI_client.design_window()¶
The function which defines the shape and design of the tkinter GUI
This function lays out and defines placement for all the elements of the graphic user interface. It assigns placement via the tkinter grid functionality, and assigns element functionality via embedded functions. The individual gui elements include a title, top label, a name, ID, and file entry box each with their own labels, a file retrieval combo box with its own label, a browse button that opens the local file browser for the user to select a csv file to upload, a retrieve button that takes the indicated MRN from the retrieval combo box and retrieves the patient data from the server via a GET request, a send button that updates the information on the server side with the current information on the GUI, a cancel button which closes the window, an image label which is updated by either the browse or retrieve commands and has a top label which displays the heart rate of the patient, and lastly a label below the image which displays the server response.
- GUI_client.image_to_b64(img_file: GUI_client.PathLike = 'temp.png') str ¶
function that converts an image file to a base64 encoded string
This function takes a file path to an image (default value ‘temp.png’) and converts that image to a base 64 encoded string. The encoding protocol of the string is utf-8. The file object is read as bytes into the string.
- Parameters
img_file (Pathlike) – Path to the image file, default value is ‘temp.png’
- Returns
Base 64 string of the image file
- Return type
str
- GUI_client.img_from_html(html_str: str) str ¶
Scrubs the string of a html page for the b64 string of in image
This function uses regex to scan the html template described in the render image function. It scans this template for the base 64 string encoded png image and extracts it from the template. This string is then returned.
- Parameters
html_str (str) – The string of the html page to be searched
- Returns
The Base 64 string of the png image
- Return type
str
- GUI_client.photometrics_from_csv(file_name: GUI_client.PathLike) Tuple[str, dict] ¶
Takes a csv ecg file and converts it to a b64 string and heart metrics
This function takes a csv file with two columns and preprocesses that file, assigning those columns to either the ‘time’ or ‘voltage’ column in a DataFrame. That DataFrame is then converted to matplotlib figure which is converted to a b64 string image and a series of relevant metrics for ECGs. The figure conversion step creates a temporary ‘temp.png’ file which the img_to_b64 function uses to generate the b64 string. After this is accomplished, the temporary file is deleted.
- Parameters
file_name (Pathlike) – The file path of the csv data file to be preprocessed
- Returns
The b64 image and relevant heart rhythm metrics
- Return type
Tuple[str, dict]