{
  "version": "1.0.0",
  "exportedAt": "2026-06-09T06:25:52.560Z",
  "workflow": {
    "name": "AI FHIR Agent (Demo)",
    "description": "Enhanced AI FHIR Agent flow for Customer Demo"
  },
  "flow": {
    "tab": {
      "id": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
      "type": "tab",
      "label": "AI FHIR Agent (Demo)",
      "disabled": true,
      "info": "Enhanced AI FHIR Agent flow for Customer Demo",
      "env": []
    },
    "nodes": [
      {
        "id": "fd0c4e1363e0b2f6",
        "type": "group",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "name": "🔧 AI FHIR Search Tool",
        "style": {
          "stroke": "#28a745",
          "stroke-opacity": "1",
          "fill": "#d4edda",
          "fill-opacity": "0.5",
          "label": true,
          "label-position": "nw",
          "color": "#28a745"
        },
        "nodes": [
          "78084eef590a8eb6",
          "281e8c592432c3ea",
          "adfd8940361f4509",
          "b80b4ab250078e1f",
          "6b3519da9aa26644",
          "8db1fc807b6ddc1d",
          "f76b0523a2514f30",
          "e585ecc8ab43bc47",
          "58509ecfa86ac037"
        ],
        "x": 1188,
        "y": 379,
        "w": 1378,
        "h": 402
      },
      {
        "id": "e809d5e92c10b34d",
        "type": "group",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "name": "🤖 Main AI Orchestration Flow",
        "style": {
          "stroke": "#3b78e7",
          "stroke-opacity": "1",
          "fill": "#e8f0fe",
          "fill-opacity": "0.5",
          "label": true,
          "label-position": "nw",
          "color": "#3b78e7"
        },
        "nodes": [
          "7cf8c9af233bfc3b",
          "d7507e50c1035a43",
          "1fb413846f5451a3",
          "b7205893a5f1f91f",
          "8bf0af2f4ad4500e",
          "403914c18b4bbca5",
          "6650258e3933e023",
          "624dd9c399891f23",
          "a33eab9422cad496",
          "436e9fae96a48143",
          "d1f985f006c83a8d",
          "71f25d780442d2a5",
          "015c4ee488f0de89"
        ],
        "x": 4,
        "y": 99,
        "w": 2002,
        "h": 202
      },
      {
        "id": "58509ecfa86ac037",
        "type": "group",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "FHIR Query Check Guardrail",
        "style": {
          "stroke": "#9363b7",
          "fill": "#b797cf",
          "label": true,
          "color": "#6f2fa0"
        },
        "nodes": [
          "cf0d716a7f4673ae",
          "0650897d03b36717"
        ],
        "x": 1214,
        "y": 519,
        "w": 472,
        "h": 82
      },
      {
        "id": "015c4ee488f0de89",
        "type": "junction",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "x": 1713.99995803833,
        "y": 168.00000190734863,
        "wires": [
          [
            "6650258e3933e023",
            "d1f985f006c83a8d"
          ]
        ]
      },
      {
        "id": "8bf0af2f4ad4500e",
        "type": "ai-agent",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "AI Agent",
        "systemPrompt": "You are an AI Medical Assistant. Your primary role is to provide accurate and concise answers to user questions based on FHIR data retrieved from the medical records system using the `getFHIRResource` tool.\nYou are talking to a patient, so you should be friendly and professional. Never mention any IDs for the FHIR resources.\n**Context:**\n*   **Today's Date:** The current date will be provided at the beginning of the conversation context in the format YYYY-MM-DD. Use this to resolve relative date references like \"tomorrow\", \"next week\", \"yesterday\".\n\n**Workflow:**\n1.  **Analyze Request & Detect Intent:** Determine if the user query:\n    *   Mentions a specific patient **name** (e.g., \"Camila Maria Lopez\", \"appointments for John Doe\").\n    *   Mentions a specific **Patient ID**.\n    *   Is a **general query** potentially using pronouns (\"my\", \"their\") but without an explicit name/ID.\n2.  **Patient Identification Step (If Name Mentioned):**\n    *   If a patient **name** is mentioned, **first perform a Patient search** using the `getFHIRResource` tool:\n        *   `resourceType='Patient'`\n        *   `searchParams`: Use the generic **'name'** parameter (e.g., `{\"name\": \"Camila Maria Lopez\"}`) instead of splitting into 'family'/'given', as this is more reliable for fuzzy matching.\n        *   **Important:** Use **lowercase** `birthdate` for Date of Birth search (e.g., `{\"birthdate\": \"1980-01-01\"}`). Do NOT use `birthDate`.\n    *   **Handle Patient Search Results:**\n        *   **One Match:** Extract the `Patient.id`. **Remember this ID** for the next step.\n        *   **No Match:** Inform the user \"Patient [Name] not found.\"\n        *   **Multiple Matches:** Ask for clarification.\n3.  **Execute Primary Query:**\n    *   If a **Patient ID** was retrieved or provided:\n        *   Determine the target `resourceType` and `searchParams` for the actual request.\n        *   **Include the Patient ID** (e.g., `\"patient\": \"Patient/[ID]\"`).\n        *   **Important: Date Searching**: usage FHIR prefixes. For \"appointments tomorrow\", use [ge] (start of day) AND [le] (end of day). For \"upcoming\", use [ge].\n        *   **Important: Conditions**: Use `\"category\": \"problem-list-item\"` or `\"category\": \"encounter-diagnosis\"`.\n    *   If **no Patient Name/ID** context: Perform a general search if appropriate.\n4.  **Formatting Response:**\n    *   Provide answers in **HTML** and wrap important keywords with <span> tags:\n    - <span style=\"color: red\">: urgent issues\n    - <span style=\"color: orange\">: important info\n    - <span style=\"color: blue\">: medications\n    - <span style=\"color: green\">: positive status\n    *   Use <BR> for line breaks.\n    *   **DO NOT USE Markdown.**\n\nKeep your responses focused on answering the user's query based *only* on the retrieved information.",
        "responseType": "object",
        "maxRecursionDepth": "10",
        "x": 1366.00004196167,
        "y": 171.99999809265137,
        "wires": [
          [
            "a33eab9422cad496",
            "015c4ee488f0de89"
          ]
        ]
      },
      {
        "id": "7cf8c9af233bfc3b",
        "type": "inject",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "▶ User Query (John Central)",
        "props": [
          {
            "p": "payload.message",
            "v": "Find patient with MRN EXAMPLE-MRN. Summarize their active Conditions and Allergies.",
            "vt": "str"
          },
          {
            "p": "topic",
            "vt": "str"
          }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 180,
        "y": 180,
        "wires": [
          [
            "71f25d780442d2a5"
          ]
        ]
      },
      {
        "id": "b7205893a5f1f91f",
        "type": "ai-tool-adapter",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "FHIR Search Tool",
        "toolIdentifier": "getFHIRResource",
        "toolDescription": "  Fetches a FHIR resource (or searches for resources) from EHR using REST API.\n    Authenticates using client credentials for each call.\n    Search parameters must be provided. ",
        "parameters": [
          {
            "name": "searchParams",
            "type": "object",
            "description": "search params for the fhir search query - {",
            "required": true
          },
          {
            "name": "resourceType",
            "type": "string",
            "description": "fhir resource type to search for",
            "required": true
          }
        ],
        "timeout": 30000,
        "validationCode": "",
        "x": 1090,
        "y": 180,
        "wires": [
          [
            "8bf0af2f4ad4500e"
          ],
          [
            "0650897d03b36717"
          ]
        ]
      },
      {
        "id": "1fb413846f5451a3",
        "type": "ai-model",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "Bedrock LLM",
        "provider": "bedrock",
        "model": "amazon.nova-lite-v1:0",
        "temperature": 0.7,
        "maxTokens": 1000,
        "vertexProjectId": "",
        "vertexLocation": "us-central1",
        "awsRegion": "us-east-2",
        "bedrockAuthMethod": "apiKey",
        "x": 880,
        "y": 180,
        "wires": [
          [
            "b7205893a5f1f91f"
          ]
        ]
      },
      {
        "id": "6650258e3933e023",
        "type": "debug",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "📤 AI Final Response",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1860,
        "y": 140,
        "wires": []
      },
      {
        "id": "d7507e50c1035a43",
        "type": "change",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "Add Access Token",
        "rules": [
          {
            "t": "set",
            "p": "access_token",
            "pt": "flow",
            "to": "payload.access_token",
            "tot": "msg"
          }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 670,
        "y": 180,
        "wires": [
          [
            "1fb413846f5451a3"
          ]
        ]
      },
      {
        "id": "281e8c592432c3ea",
        "type": "ec-fhir-search",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "FHIR Search",
        "integrationId": "",
        "integrationMetadata": {
          "ehr": "epic",
          "type": "backend",
          "scopes": "patient/*.* user/*.* launch profile fhirUser openid"
        },
        "resourceType": "",
        "searchFilter": "",
        "outputField": "",
        "outputFieldType": "msg",
        "x": 2130,
        "y": 560,
        "wires": [
          [
            "adfd8940361f4509",
            "b80b4ab250078e1f"
          ]
        ]
      },
      {
        "id": "adfd8940361f4509",
        "type": "ai-tool-terminate",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "Return to AI",
        "x": 2450,
        "y": 560,
        "wires": [],
        "icon": "font-awesome/fa-retweet"
      },
      {
        "id": "b80b4ab250078e1f",
        "type": "debug",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "📋 FHIR Result",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 2440,
        "y": 640,
        "wires": []
      },
      {
        "id": "78084eef590a8eb6",
        "type": "change",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "Prepare Input",
        "rules": [
          {
            "t": "set",
            "p": "payload",
            "pt": "msg",
            "to": "toolInput",
            "tot": "msg"
          },
          {
            "t": "set",
            "p": "payload.access_token",
            "pt": "msg",
            "to": "access_token",
            "tot": "flow"
          }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1880,
        "y": 560,
        "wires": [
          [
            "281e8c592432c3ea",
            "e585ecc8ab43bc47"
          ]
        ]
      },
      {
        "id": "6b3519da9aa26644",
        "type": "comment",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "Executes when AI calls getFHIRResource",
        "info": "",
        "x": 1420,
        "y": 740,
        "wires": []
      },
      {
        "id": "8db1fc807b6ddc1d",
        "type": "catch",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "Error Handler",
        "scope": null,
        "uncaught": false,
        "x": 2131,
        "y": 487,
        "wires": [
          [
            "adfd8940361f4509",
            "b80b4ab250078e1f"
          ]
        ]
      },
      {
        "id": "403914c18b4bbca5",
        "type": "ai-output-guardrails",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "Guardrails",
        "mode": "ai",
        "inputProperty": "",
        "rules": [],
        "actionOnViolation": "redact",
        "enablePhiRedaction": true,
        "phiPatterns": [
          "mrn",
          "npi",
          "fhirId",
          "accountNumber",
          "healthPlanNumber",
          "name",
          "ssn",
          "dob",
          "address",
          "zipCode",
          "email",
          "phone"
        ],
        "enableCustomFiltering": false,
        "customFilterPatterns": "",
        "passthrough": false,
        "x": 1536.00004196167,
        "y": 171.99999809265137,
        "wires": [
          [
            "015c4ee488f0de89"
          ],
          [
            "624dd9c399891f23"
          ]
        ]
      },
      {
        "id": "624dd9c399891f23",
        "type": "debug",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "Fail",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1830,
        "y": 260,
        "wires": []
      },
      {
        "id": "a33eab9422cad496",
        "type": "debug",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "Before Guardrails",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1570,
        "y": 260,
        "wires": []
      },
      {
        "id": "436e9fae96a48143",
        "type": "http in",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "Clinical Assistant API",
        "url": "/clinical-assistant-agent",
        "method": "post",
        "upload": false,
        "skipBodyParsing": false,
        "swaggerDoc": "",
        "x": 420,
        "y": 260,
        "wires": [
          [
            "d7507e50c1035a43"
          ]
        ]
      },
      {
        "id": "d1f985f006c83a8d",
        "type": "http response",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "API Response",
        "statusCode": "200",
        "headers": {},
        "x": 1860,
        "y": 200,
        "wires": []
      },
      {
        "id": "cf0d716a7f4673ae",
        "type": "ai-output-guardrails",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "58509ecfa86ac037",
        "name": "Resource Guardrail Agent",
        "mode": "ai",
        "inputProperty": "",
        "rules": [
          {
            "type": "custom",
            "value": "Only Block resources that are NOT -  Patient, AllergyIntolerance, Condition."
          }
        ],
        "actionOnViolation": "block",
        "enablePhiRedaction": true,
        "phiPatterns": [],
        "enableCustomFiltering": false,
        "customFilterPatterns": "",
        "passthrough": false,
        "x": 1540,
        "y": 560,
        "wires": [
          [
            "78084eef590a8eb6"
          ],
          [
            "f76b0523a2514f30"
          ]
        ]
      },
      {
        "id": "0650897d03b36717",
        "type": "ai-model",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "58509ecfa86ac037",
        "name": "Bedrock LLM",
        "provider": "bedrock",
        "model": "amazon.nova-lite-v1:0",
        "temperature": 0.7,
        "maxTokens": 1000,
        "vertexProjectId": "",
        "vertexLocation": "us-central1",
        "awsRegion": "us-east-2",
        "bedrockAuthMethod": "apiKey",
        "x": 1320,
        "y": 560,
        "wires": [
          [
            "cf0d716a7f4673ae"
          ]
        ]
      },
      {
        "id": "f76b0523a2514f30",
        "type": "ai-tool-terminate",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "Return to AI with Error",
        "x": 1910,
        "y": 640,
        "wires": [],
        "icon": "font-awesome/fa-retweet"
      },
      {
        "id": "71f25d780442d2a5",
        "type": "ec-auth-backend",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "e809d5e92c10b34d",
        "name": "Get Epic Backend Auth",
        "integrationId": "",
        "integrationMetadata": {
          "ehr": "epic",
          "type": "backend",
          "scopes": "patient/*.* user/*.* launch profile fhirUser openid"
        },
        "customScopes": "",
        "outputFormat": "token_only",
        "outputField": "",
        "outputFieldType": "msg",
        "x": 430,
        "y": 180,
        "wires": [
          [
            "d7507e50c1035a43"
          ]
        ]
      },
      {
        "id": "e585ecc8ab43bc47",
        "type": "debug",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "g": "fd0c4e1363e0b2f6",
        "name": "Input Check",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 2130,
        "y": 420,
        "wires": []
      },
      {
        "id": "fc2e9687fb9a5c3e",
        "type": "ec-fhir-create",
        "z": "workflow_e551369e-01d0-4100-a35f-6c1ab9100885",
        "name": "Create Encounter",
        "integrationId": "",
        "integrationMetadata": {
          "ehr": "epic",
          "type": "backend",
          "scopes": "patient/*.* user/*.* launch profile fhirUser openid"
        },
        "resourceType": "Encounter",
        "resource": "",
        "outputField": "",
        "outputFieldType": "msg",
        "x": 270,
        "y": 60,
        "wires": [
          [
            "d7507e50c1035a43"
          ]
        ]
      }
    ]
  },
  "requirements": [
    {
      "ehr": "epic",
      "type": "backend",
      "scopes": "patient/*.* user/*.* launch profile fhirUser openid"
    }
  ]
}