n8n-docs-datasets / docs-dataset /phase2_industry_specific.jsonl
DavidrPatton's picture
Add docs-dataset dataset
4484c0f verified
{"instruction": "How do I build HIPAA-compliant workflows in n8n?", "output": "**HIPAA-Compliant n8n Workflow Design**\n\n**1. Infrastructure Requirements**\n- Host n8n on HIPAA-compliant infrastructure (AWS, GCP, Azure with BAA)\n- Enable encryption at rest and in transit\n- Use dedicated VPC/VNet for healthcare workloads\n\n**2. Data Handling Rules**\n```javascript\n// Never log PHI (Protected Health Information)\nconst sensitiveFields = ['ssn', 'dob', 'medicalRecordNumber', 'diagnosis'];\n\nfunction sanitizeForLogging(data) {\n const safe = { ...data };\n sensitiveFields.forEach(field => {\n if (safe[field]) safe[field] = '[REDACTED]';\n });\n return safe;\n}\n\nconsole.log('Processing request:', sanitizeForLogging(patientData));\n```\n\n**3. Access Control Pattern**\n```javascript\n// Verify user has clearance for patient data\nconst userRole = $input.first().json.userRole;\nconst allowedRoles = ['physician', 'nurse', 'medical_admin'];\n\nif (!allowedRoles.includes(userRole)) {\n throw new Error('Access denied: Insufficient privileges for PHI');\n}\n```\n\n**4. Audit Trail Implementation**\n```javascript\n// Log every PHI access\nconst auditEntry = {\n timestamp: new Date().toISOString(),\n userId: user.id,\n action: 'PHI_ACCESS',\n patientId: patient.id,\n dataType: 'medical_record',\n ipAddress: request.ip,\n reason: request.accessReason\n};\n\nawait db.insert('hipaa_audit_log', auditEntry);\n```\n\n**5. Data Retention**\n- Implement automatic data expiration\n- Secure deletion with audit trail\n- 6-year minimum retention for medical records", "metadata": {"industry": "healthcare", "compliance": "hipaa", "complexity": "enterprise"}}
{"instruction": "How do I automate patient appointment scheduling with n8n?", "output": "**Patient Appointment Scheduling Automation**\n\n**Workflow Architecture:**\n```\nPatient Request (Form/Portal)\n ↓\nValidate Patient Identity\n ↓\nCheck Provider Availability\n ↓\nCreate Appointment (EHR System)\n ↓\nSend Confirmations (Email/SMS)\n ↓\nAdd to Provider Calendar\n ↓\nSchedule Reminders (24hr, 2hr before)\n```\n\n**1. Patient Intake Form Processing**\n```javascript\n// Webhook receives patient request\nconst { patientId, preferredDate, reason, provider } = $input.first().json;\n\n// Validate patient exists in EHR\nconst patient = await ehrApi.getPatient(patientId);\nif (!patient) {\n return { error: 'Patient not found', code: 'PATIENT_NOT_FOUND' };\n}\n```\n\n**2. Availability Check**\n```javascript\n// Check provider calendar\nconst availability = await calendarApi.getSlots({\n providerId: provider,\n date: preferredDate,\n duration: 30 // minutes\n});\n\n// Filter by patient's insurance\nconst validSlots = availability.filter(slot => \n slot.acceptsInsurance.includes(patient.insuranceProvider)\n);\n\nreturn { availableSlots: validSlots };\n```\n\n**3. Appointment Creation**\n```javascript\n// Create in EHR system\nconst appointment = await ehrApi.createAppointment({\n patientId,\n providerId: provider,\n dateTime: selectedSlot.startTime,\n duration: 30,\n type: reason,\n status: 'scheduled'\n});\n\n// Create calendar event\nawait googleCalendar.createEvent({\n summary: `Patient: ${patient.name}`,\n start: selectedSlot.startTime,\n attendees: [provider.email, patient.email]\n});\n```\n\n**4. Reminder Workflow**\n- 24 hours before: Email with prep instructions\n- 2 hours before: SMS reminder\n- Post-visit: Satisfaction survey", "metadata": {"industry": "healthcare", "use_case": "scheduling", "complexity": "intermediate"}}
{"instruction": "How do I integrate n8n with electronic health record (EHR) systems?", "output": "**EHR Integration Patterns for n8n**\n\n**Common EHR Systems & APIs:**\n| System | API Type | Auth Method |\n|--------|----------|-------------|\n| Epic | FHIR R4 | OAuth2 + JWT |\n| Cerner | FHIR R4 | OAuth2 |\n| Allscripts | REST | API Key |\n| Athenahealth | REST | OAuth2 |\n\n**1. FHIR Patient Query**\n```javascript\n// Fetch patient by MRN\nconst fhirBase = 'https://ehr.hospital.org/fhir/r4';\nconst response = await $http.request({\n method: 'GET',\n url: `${fhirBase}/Patient`,\n qs: { identifier: `MRN|${mrn}` },\n headers: { Authorization: `Bearer ${token}` }\n});\n\nconst patient = response.entry?.[0]?.resource;\n```\n\n**2. Create Clinical Note**\n```javascript\n// FHIR DocumentReference\nconst note = {\n resourceType: 'DocumentReference',\n status: 'current',\n type: {\n coding: [{ system: 'http://loinc.org', code: '11506-3' }]\n },\n subject: { reference: `Patient/${patientId}` },\n content: [{\n attachment: {\n contentType: 'text/plain',\n data: Buffer.from(noteText).toString('base64')\n }\n }]\n};\n\nawait $http.post(`${fhirBase}/DocumentReference`, { body: note });\n```\n\n**3. Lab Results Processing**\n```\nLab System Webhook β†’ Parse HL7/FHIR\n ↓\nMatch to Patient Record\n ↓\nCheck for Critical Values\n ↓\nIF critical β†’ Alert Provider (Urgent)\nELSE β†’ Update Patient Portal\n```\n\n**4. Bi-Directional Sync**\n- Pull: Schedule polling for new orders\n- Push: Webhook for status updates\n- Conflict resolution: EHR is source of truth", "metadata": {"industry": "healthcare", "use_case": "ehr_integration", "complexity": "advanced"}}
{"instruction": "How do I build PCI-DSS compliant payment workflows in n8n?", "output": "**PCI-DSS Compliant Payment Processing in n8n**\n\n**Critical Rule: Never handle raw card data in n8n**\n\n**1. Tokenization Pattern**\n```\nCustomer β†’ Payment Form (Stripe Elements/Square)\n ↓\n Creates Token (client-side)\n ↓\n Token sent to n8n webhook\n ↓\n n8n uses token to charge (never sees card)\n```\n\n**2. Webhook Security**\n```javascript\n// Verify webhook signature\nconst signature = $input.first().json.headers['stripe-signature'];\nconst payload = $input.first().json.body;\nconst secret = $credentials.stripeWebhookSecret;\n\nconst event = stripe.webhooks.constructEvent(payload, signature, secret);\nif (!event) {\n throw new Error('Invalid webhook signature');\n}\n```\n\n**3. Environment Isolation**\n```yaml\n# Production payment workflow in isolated environment\nservices:\n n8n-payments:\n networks:\n - pci-zone # Separate network segment\n environment:\n - N8N_ENCRYPTION_KEY=${PCI_ENCRYPTION_KEY}\n```\n\n**4. Audit Logging**\n```javascript\n// Log all payment operations (without sensitive data)\nconst auditLog = {\n timestamp: new Date().toISOString(),\n transactionId: charge.id,\n amount: charge.amount,\n currency: charge.currency,\n status: charge.status,\n // NEVER LOG: card number, CVV, full account numbers\n};\n\nawait logToSIEM('payment_processed', auditLog);\n```\n\n**5. Data Retention**\n- Transaction records: 7 years minimum\n- Tokenized references only\n- No card data storage ever", "metadata": {"industry": "finance", "compliance": "pci_dss", "complexity": "enterprise"}}
{"instruction": "How do I automate financial reporting with n8n?", "output": "**Automated Financial Reporting Workflow**\n\n**1. Data Collection Pipeline**\n```\nSchedule (Daily 2 AM)\n ↓\nPull from Multiple Sources:\n β†’ Accounting System (QuickBooks/Xero)\n β†’ Payment Processor (Stripe)\n β†’ Bank Accounts (Plaid)\n β†’ Expense System (Expensify)\n ↓\nConsolidate in Data Warehouse\n ↓\nGenerate Reports\n ↓\nDistribute to Stakeholders\n```\n\n**2. Multi-Source Aggregation**\n```javascript\n// Parallel data fetching\nconst [revenue, expenses, bankBalance] = await Promise.all([\n stripe.balanceTransactions.list({ created: { gte: startDate } }),\n quickbooks.expenses.query({ date: { $gte: startDate } }),\n plaid.accounts.getBalance({ access_token: bankToken })\n]);\n\nreturn {\n totalRevenue: revenue.reduce((s, t) => s + t.amount, 0),\n totalExpenses: expenses.reduce((s, e) => s + e.amount, 0),\n cashPosition: bankBalance.accounts[0].balances.current\n};\n```\n\n**3. Report Generation**\n```javascript\n// Create Excel report\nconst workbook = new ExcelJS.Workbook();\nconst sheet = workbook.addWorksheet('Monthly P&L');\n\nsheet.addRow(['Category', 'Amount', 'YoY Change']);\nsheet.addRow(['Revenue', revenue, `${yoyChange}%`]);\nsheet.addRow(['Expenses', expenses, `${expenseChange}%`]);\nsheet.addRow(['Net Income', revenue - expenses, '']);\n\nconst buffer = await workbook.xlsx.writeBuffer();\nreturn { binary: { report: { data: buffer, mimeType: 'application/xlsx' } } };\n```\n\n**4. Executive Dashboard Update**\n- Push KPIs to Google Sheets\n- Update Tableau/Looker extracts\n- Slack summary to finance channel\n\n**5. Variance Alerts**\n```javascript\n// Alert on significant variances\nif (Math.abs(actualVsBudget) > 0.1) {\n await slack.send({\n channel: '#finance-alerts',\n text: `⚠️ Budget variance alert: ${category} is ${variance}% off target`\n });\n}\n```", "metadata": {"industry": "finance", "use_case": "reporting", "complexity": "intermediate"}}
{"instruction": "How do I build fraud detection workflows in n8n?", "output": "**Fraud Detection Automation with n8n**\n\n**1. Real-Time Transaction Scoring**\n```\nPayment Webhook\n ↓\nExtract Transaction Features\n ↓\nCall ML Model (Fraud Score)\n ↓\nDecision Engine:\n - Score < 30: Auto-approve\n - Score 30-70: Queue for review\n - Score > 70: Auto-block + Alert\n```\n\n**2. Feature Extraction**\n```javascript\nconst transaction = $input.first().json;\n\nconst features = {\n amount: transaction.amount,\n isNewDevice: !knownDevices.includes(transaction.deviceId),\n isNewLocation: !usualLocations.includes(transaction.country),\n velocityLast1h: await getTransactionCount(userId, '1h'),\n velocityLast24h: await getTransactionCount(userId, '24h'),\n isUnusualMerchant: !frequentMerchants.includes(transaction.merchantId),\n hourOfDay: new Date().getHours(),\n dayOfWeek: new Date().getDay(),\n accountAge: daysSinceAccountCreation(user.createdAt)\n};\n\nreturn features;\n```\n\n**3. ML Model Integration**\n```javascript\n// Call fraud detection API\nconst score = await $http.post('https://ml.company.com/fraud/score', {\n body: features,\n headers: { 'X-API-Key': $credentials.mlApiKey }\n});\n\nreturn { \n fraudScore: score.probability,\n riskFactors: score.top_factors \n};\n```\n\n**4. Alert & Action Workflow**\n```javascript\nif (fraudScore > 70) {\n // Block transaction\n await paymentGateway.declineTransaction(transactionId);\n \n // Alert fraud team\n await pagerDuty.trigger({\n severity: 'critical',\n summary: `Blocked suspicious transaction: $${amount}`,\n details: { transactionId, userId, riskFactors }\n });\n \n // Lock user account pending review\n await userService.suspendAccount(userId, 'fraud_review');\n}\n```\n\n**5. Feedback Loop**\n- Track false positives/negatives\n- Retrain model monthly\n- Update rules based on new patterns", "metadata": {"industry": "finance", "use_case": "fraud_detection", "complexity": "advanced"}}
{"instruction": "How do I automate contract management with n8n?", "output": "**Contract Management Automation**\n\n**1. Contract Lifecycle Workflow**\n```\nNew Contract Request\n ↓\nGenerate from Template (with variables)\n ↓\nInternal Review Queue\n ↓\nSend for Signature (DocuSign/PandaDoc)\n ↓\nTrack Signature Status\n ↓\nStore Executed Contract\n ↓\nSet Renewal Reminders\n```\n\n**2. Template Generation**\n```javascript\n// Merge template with contract data\nconst template = await getTemplate(contractType);\nconst merged = template\n .replace('{{client_name}}', client.name)\n .replace('{{effective_date}}', effectiveDate)\n .replace('{{term_length}}', termMonths)\n .replace('{{monthly_fee}}', formatCurrency(monthlyFee))\n .replace('{{payment_terms}}', paymentTerms);\n\n// Generate PDF\nconst pdf = await pdfService.htmlToPdf(merged);\nreturn { binary: { contract: { data: pdf } } };\n```\n\n**3. eSignature Integration**\n```javascript\n// Send via DocuSign\nconst envelope = await docusign.createEnvelope({\n emailSubject: `Please sign: ${contractName}`,\n documents: [{ \n documentBase64: contractPdf,\n name: contractName \n }],\n recipients: {\n signers: [\n { email: client.email, name: client.name, routingOrder: 1 },\n { email: company.legalEmail, name: 'Legal Team', routingOrder: 2 }\n ]\n },\n status: 'sent'\n});\n```\n\n**4. Status Tracking**\n```\nDocuSign Webhook (status change)\n ↓\nUpdate CRM Deal Stage\n ↓\nIF signed: \n β†’ Store in Document Management\n β†’ Create recurring billing\n β†’ Notify account team\n```\n\n**5. Renewal Management**\n```javascript\n// 90-day renewal reminder\nconst expiringContracts = await db.query(`\n SELECT * FROM contracts \n WHERE end_date BETWEEN NOW() AND NOW() + INTERVAL '90 days'\n AND renewal_notified = false\n`);\n\nfor (const contract of expiringContracts) {\n await sendRenewalReminder(contract);\n await updateNotificationStatus(contract.id);\n}\n```", "metadata": {"industry": "legal", "use_case": "contracts", "complexity": "intermediate"}}
{"instruction": "How do I implement audit trails and compliance logging in n8n?", "output": "**Audit Trail Implementation for Compliance**\n\n**1. Central Logging Architecture**\n```\nAny Workflow Action\n ↓\nExecute Sub-Workflow: Log Audit Event\n ↓\nWrite to Immutable Log Store\n ↓\nIndex in Search System\n```\n\n**2. Audit Event Structure**\n```javascript\n// Standard audit event format\nconst auditEvent = {\n // WHO\n userId: $execution.customData.userId,\n userEmail: $execution.customData.userEmail,\n userRole: $execution.customData.userRole,\n ipAddress: $input.first().json.headers?.['x-forwarded-for'],\n \n // WHAT\n action: 'RECORD_UPDATED',\n resourceType: 'customer',\n resourceId: customerId,\n \n // WHEN\n timestamp: new Date().toISOString(),\n executionId: $execution.id,\n workflowId: $workflow.id,\n \n // DETAILS\n changes: {\n before: previousState,\n after: newState\n }\n};\n```\n\n**3. Immutable Storage**\n```javascript\n// Write to append-only log\nawait s3.putObject({\n Bucket: 'audit-logs',\n Key: `${date}/${nanoid()}.json`,\n Body: JSON.stringify(auditEvent),\n ObjectLockMode: 'COMPLIANCE',\n ObjectLockRetainUntilDate: futureDate(7, 'years')\n});\n\n// Also index for search\nawait elasticsearch.index({\n index: 'audit-logs',\n body: auditEvent\n});\n```\n\n**4. Compliance Queries**\n```javascript\n// Who accessed this record in last 30 days?\nconst accessLog = await elasticsearch.search({\n index: 'audit-logs',\n body: {\n query: {\n bool: {\n must: [\n { match: { resourceId: recordId } },\n { range: { timestamp: { gte: 'now-30d' } } }\n ]\n }\n }\n }\n});\n```\n\n**5. Compliance Report Generation**\n- Scheduled weekly/monthly reports\n- Export to PDF for auditors\n- Anomaly detection (unusual access patterns)", "metadata": {"industry": "legal", "use_case": "audit_trail", "complexity": "advanced"}}
{"instruction": "How do I automate student enrollment workflows with n8n?", "output": "**Student Enrollment Automation**\n\n**1. Enrollment Pipeline**\n```\nApplication Submission (Form/Portal)\n ↓\nDocument Verification\n ↓\nEligibility Check\n ↓\nAcceptance Decision\n ↓\nCourse Registration\n ↓\nLMS Account Creation\n ↓\nWelcome Communication\n```\n\n**2. Application Processing**\n```javascript\n// Receive application\nconst application = $input.first().json;\n\n// Verify required documents\nconst requiredDocs = ['transcript', 'id_proof', 'photo'];\nconst missingDocs = requiredDocs.filter(doc => !application.documents[doc]);\n\nif (missingDocs.length > 0) {\n await sendEmail({\n to: application.email,\n subject: 'Missing Documents for Your Application',\n body: `Please submit: ${missingDocs.join(', ')}`\n });\n return { status: 'pending_documents', missing: missingDocs };\n}\n\nreturn { status: 'complete', readyForReview: true };\n```\n\n**3. LMS Integration (Canvas/Moodle)**\n```javascript\n// Create student in LMS\nconst lmsUser = await canvas.createUser({\n user: {\n name: `${student.firstName} ${student.lastName}`,\n short_name: student.firstName,\n email: student.email,\n sis_user_id: student.studentId\n }\n});\n\n// Enroll in courses\nfor (const courseId of selectedCourses) {\n await canvas.enrollUser({\n enrollment: {\n user_id: lmsUser.id,\n type: 'StudentEnrollment',\n enrollment_state: 'active'\n }\n }, courseId);\n}\n```\n\n**4. Welcome Sequence**\n```\nDay 0: Welcome email + credentials\nDay 1: Campus tour video\nDay 3: Academic advisor intro\nDay 7: First week check-in\n```\n\n**5. Status Dashboard Update**\n- Push enrollment stats to admin dashboard\n- Update capacity tracking\n- Notify departments of new students", "metadata": {"industry": "education", "use_case": "enrollment", "complexity": "intermediate"}}
{"instruction": "How do I automate grading and notifications for students?", "output": "**Automated Grading & Notification System**\n\n**1. Assignment Submission Pipeline**\n```\nStudent Submits Assignment (LMS)\n ↓\nLMS Webhook to n8n\n ↓\nIF auto-gradeable:\n β†’ Run auto-grader\n β†’ Record score\nELSE:\n β†’ Queue for instructor review\n ↓\nPost grade to LMS\n ↓\nStudent notification\n ↓\nIF grade < passing:\n β†’ Trigger support intervention\n```\n\n**2. Auto-Grading Integration**\n```javascript\n// For coding assignments\nconst submission = $input.first().json;\n\n// Run tests in sandbox\nconst result = await codeRunner.evaluate({\n code: submission.studentCode,\n language: 'python',\n testCases: assignment.testCases,\n timeout: 30000\n});\n\nconst score = (result.passed / result.total) * 100;\n\nreturn {\n score,\n feedback: result.feedback,\n passedTests: result.passed,\n totalTests: result.total\n};\n```\n\n**3. Grade Posting**\n```javascript\n// Post to Canvas gradebook\nawait canvas.postGrade({\n courseId: course.id,\n assignmentId: assignment.id,\n studentId: student.sisId,\n grade: score,\n comment: feedback\n});\n\n// Notify student\nawait sendEmail({\n to: student.email,\n subject: `Grade Posted: ${assignment.name}`,\n body: `Your score: ${score}%\\n\\n${feedback}`\n});\n```\n\n**4. At-Risk Student Detection**\n```javascript\n// Check for struggling students\nconst atRiskStudents = await db.query(`\n SELECT student_id, AVG(score) as avg_score\n FROM grades \n WHERE course_id = $1\n GROUP BY student_id\n HAVING AVG(score) < 70\n`, [courseId]);\n\n// Alert academic advisors\nfor (const student of atRiskStudents) {\n await notifyAdvisor(student.student_id, 'low_performance');\n}\n```\n\n**5. Parent/Guardian Notifications**\n- Weekly progress summaries\n- Alert on failing grades\n- Attendance reports", "metadata": {"industry": "education", "use_case": "grading", "complexity": "intermediate"}}