Step-By-Step Implementation Walk Through:

Step 5: Execute and Evaluate the Workflow Demo

With Microsoft Entra External ID configured (Step 1), the Flask application built (Step 2), Google Sheets integrated (Step 3), and the n8n workflow designed (Step 4), you are now ready to execute the entire workflow end-to-end and evaluate its performance.

1. Launch the Required Services

Before testing, ensure all components are running:

  • Flask Application

    Start the Flask server:

C:\>cd RefillApp
C:\RefillApp>.venv\Scripts\activate
(.venv) C:\RefillApp>python app.py

This will run the Flask server at http://localhost:5000.

  • n8n Workflow

    Start n8n locally:

npx n8n

This will run the n8n server at http://localhost:5678.

Access the workflow editor at http://localhost:5678 or press "o" to open in your browser. Verify that your workflow Medication Refill Automation with GPT-5 Classification is active.

Please ensure the following:

  1. Your Microsoft Entra credential account is properly connected and authenticated

  2. The OpenAI API connection has been configured with valid credentials

  3. You have successfully authenticated with your Google account to enable Google Sheets integration

  4. Select "Execute Workflow" to activate the webhook trigger and prepare the system to process incoming requests

2. Execute a Demo Submission

  1. Navigate to http://localhost:5000/.

    You’ll see the welcome page (home.html) with a Sign in link.

  1. Click Sign in.

  • Authenticate using Microsoft Entra External ID.

  • If you don't have a user account, you may create one.

  • After successful login, you’ll be redirected to /form.

  1. Complete the Refill Form (form.html):

    Example:

  • Date of Birth → 1990-01-01

  • Hospital Number → HN11115

  • Medication → Paracetamol 500mg tablet

  1. Submit the form.

Flask (app.py) sends the payload to n8n’s webhook endpoint:

{
  "dob": "1990-01-01",
  "hn": "HN11115",
  "medication": "Paracetamol 500mg tablet",
  "user": {
    "name": "Jim",
    "email": "[email protected]",
    "oid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  }

3. Observe the Workflow Execution

Once the request is submitted, n8n executes the workflow successfully:

  1. Webhook receives the JSON payload.

  1. Verify User (Graph API) checks DOB, HN, and gender against Entra records.

  1. Edit Fields to normalize and clean the patient data.

  1. Classify Medication (GPT-5) interprets and normalizes the free-text input into structured JSON (e.g., generic_name: paracetamol, form: tablet).

  1. Extract GPT JSON String to parse the structured response from OpenAI.

  1. Merge Classification combines patient data + AI classification.

  1. Build Final Row maps all 13 fields to format data for Google Sheets integration.

  1. Add to Google Sheets appends a row into the spreadsheet.

4. Verify Output in Google Sheets

Check your Google Sheet. A new row should appear like this:

5. Evaluate Workflow Performance

When evaluating, focus on the following aspects:

  • Authentication Integrity

    Confirm only authenticated Entra users can submit. Try logging out and accessing /form → it should redirect back to /login.

  • Data Validation

    Test mismatched DOB or HN values. The Graph API should detect inconsistencies and prevent incorrect records.

  • Medication Classification

    Try multiple medication formats:

    • Tylenol

    • PCM 500 tab

    • Euthyrox 10ug

      Verify GPT-5 consistently outputs normalized JSON.

  • Error Handling

    Disconnect your OpenAI credential or misconfigure Google Sheets to ensure the workflow gracefully reports errors.

  • Audit Trail

    Verify timestamps (Asia/Bangkok) and that every row appends sequentially without overwriting existing entries.

6. Success Criteria

Your workflow demo is successful if:

  • Users can sign in securely via Microsoft Entra.

  • The form submits and triggers the n8n workflow without errors.

  • Medication entries are classified correctly by GPT-5.

  • Patient records are persisted in Google Sheets with all 13 fields populated.

  • Errors (wrong DOB/HN, invalid medication string) are handled gracefully.

✅ At this stage, you have a fully functional proof-of-concept:

A secure, automated medication refill system that validates patient identity, normalizes free-text prescriptions using AI, and stores results in a structured, auditable format for healthcare teams.