ClinicianFOCUS / FreeScribe

A medical scribe capable of creating SOAP notes running Whisper and Kobold based on conversation with a patient
GNU General Public License v3.0
0 stars 0 forks source link

**issue (complexity):** Consider extracting post-processing logic into a separate helper function and flattening the control flow #30

Open ItsSimko opened 2 days ago

ItsSimko commented 2 days ago
          **issue (complexity):** Consider extracting post-processing logic into a separate helper function and flattening the control flow

The on_proceed() function has become overly nested with duplicated post-processing logic. We can simplify this without losing functionality by:

  1. Extracting post-processing into a helper function
  2. Flattening the control flow

Here's how:

def post_process_note(note, facts=None):
    if not app_settings.editable_settings["Post-Processing"]:
        return note

    if facts:
        return send_text_to_chatgpt(f"{app_settings.editable_settings['Post-Processing']}\nFacts:{facts}\nNotes:{note}")
    return send_text_to_chatgpt(f"{app_settings.editable_settings['Post-Processing']}\nNotes:{note}")

def on_proceed():
    global use_aiscribe
    edited_text = text_area.get("1.0", tk.END).strip()
    popup.destroy()

    if not use_aiscribe:
        ai_response = send_text_to_chatgpt(edited_text)
        update_gui_with_response(ai_response)
        return

    # Generate note with optional pre-processing
    list_of_facts = None
    if app_settings.editable_settings["Pre-Processing"]:
        list_of_facts = send_text_to_chatgpt(f"{app_settings.editable_settings['Pre-Processing']} {edited_text}")
        medical_note = send_text_to_chatgpt(f"{app_settings.AISCRIBE} {list_of_facts} {app_settings.AISCRIBE2}")
    else:
        medical_note = send_text_to_chatgpt(f"{app_settings.AISCRIBE} {edited_text} {app_settings.AISCRIBE2}")

    # Apply post-processing if enabled
    final_note = post_process_note(medical_note, list_of_facts)
    update_gui_with_response(final_note)

This refactoring:

_Originally posted by @sourcery-ai[bot] in https://github.com/ClinicianFOCUS/FreeScribe/pull/28#discussion_r1822703900_